IntentSanitizer.Builder
class IntentSanitizer.Builder
General strategy of building is to only offer additive “or” operations that are chained together. Any more complex operations can be performed by the developer providing their own custom Predicate.
Summary
Public constructors |
|---|
Builder() |
Public functions |
|
|---|---|
IntentSanitizer.Builder |
allowAction(action: String)Add an action to the list of allowed actions. |
IntentSanitizer.Builder |
allowAction(filter: Predicate<String!>)Add a filter for allowed actions. |
IntentSanitizer.Builder |
Allow any components. |
IntentSanitizer.Builder |
allowCategory(category: String)Add a category to the allowed category list. |
IntentSanitizer.Builder |
allowCategory(filter: Predicate<String!>)Add a filter for allowed categories. |
IntentSanitizer.Builder |
allowClipData(filter: Predicate<ClipData!>)Allows clipData that passes the given filter. |
IntentSanitizer.Builder |
Allows clipData that contains text. overwrite each other. |
IntentSanitizer.Builder |
allowClipDataUri(filter: Predicate<Uri!>)Allows clipData whose items URIs pass the given URI filter. |
IntentSanitizer.Builder |
allowClipDataUriWithAuthority(authority: String)Allows clipData whose items URIs authorities match the given authority. |
IntentSanitizer.Builder |
allowComponent(component: ComponentName)Add a component to the allowed components list. |
IntentSanitizer.Builder |
allowComponent(filter: Predicate<ComponentName!>)Add a filter for allowed components. |
IntentSanitizer.Builder |
allowComponentWithPackage(packageName: String)Allow any component under the specified package. |
IntentSanitizer.Builder |
Allow data that passes the filter test. |
IntentSanitizer.Builder |
allowDataWithAuthority(authority: String)Convenient method to allow all data whose URI authority equals to the given. |
IntentSanitizer.Builder |
allowExtra(key: String, clazz: Class<Any!>)Allows an extra member whose key and type of value matches the given. |
IntentSanitizer.Builder |
allowExtra(key: String, filter: Predicate<Any!>)Allows an extra member whose key matches the given key and whose value passes the filter test. |
IntentSanitizer.Builder |
<T> allowExtra(key: String, clazz: Class<T!>, valueFilter: Predicate<T!>)Allows an extra member whose key matches the given key and whose value is of the type of the given clazz and passes the value filter. |
IntentSanitizer.Builder |
allowExtraOutput(filter: Predicate<Uri!>)Allows an extra member with the key MediaStore.EXTRA_OUTPUT. |
IntentSanitizer.Builder |
allowExtraOutput(uriAuthority: String)Allows an extra member with the key MediaStore.EXTRA_OUTPUT. |
IntentSanitizer.Builder |
allowExtraStream(filter: Predicate<Uri!>)Allows an extra member with the key Intent.EXTRA_STREAM. |
IntentSanitizer.Builder |
allowExtraStreamUriWithAuthority(uriAuthority: String)Allows an extra member with the key Intent.EXTRA_STREAM. |
IntentSanitizer.Builder |
allowFlags(flags: Int)Sets allowed flags. |
IntentSanitizer.Builder |
Adds all history stack flags into the allowed flags set. |
IntentSanitizer.Builder |
Allows any identifier. |
IntentSanitizer.Builder |
allowPackage(filter: Predicate<String!>)Add a filter for allowed packages. |
IntentSanitizer.Builder |
allowPackage(packageName: String)Add a package to the allowed packages. |
IntentSanitizer.Builder |
Adds all receiver flags into the allowed flags set. |
IntentSanitizer.Builder |
Allow any selector. |
IntentSanitizer.Builder |
Allow any source bounds. |
IntentSanitizer.Builder |
Add a filter for allowed data types. |
IntentSanitizer.Builder |
Add a data type to the allowed type list. |
IntentSanitizer |
build()Build the IntentSanitizer. |
Public constructors
Public functions
allowAction
fun allowAction(action: String): IntentSanitizer.Builder
Add an action to the list of allowed actions. This method can be called multiple times and the result is additive. They will not overwrite each other.
| Parameters | |
|---|---|
action: String |
the name of an action. |
| Returns | |
|---|---|
IntentSanitizer.Builder |
this builder. |
allowAction
fun allowAction(filter: Predicate<String!>): IntentSanitizer.Builder
Add a filter for allowed actions. This method can be called multiple times and the result is additive. They will not overwrite each other.
| Returns | |
|---|---|
IntentSanitizer.Builder |
this builder. |
allowAnyComponent
fun allowAnyComponent(): IntentSanitizer.Builder
Allow any components. Be cautious to call this method. When this method is called, you should definitely disallow the 4 grant URI permission flags. This method is useful in case the redirected intent is designed to support implicit intent. This method is made mutually exclusive to the 4 methods that allow components or packages.
| Returns | |
|---|---|
IntentSanitizer.Builder |
this builder. |
allowCategory
fun allowCategory(category: String): IntentSanitizer.Builder
Add a category to the allowed category list. This method can be called multiple times and the result is additive. They will not overwrite each other.
| Parameters | |
|---|---|
category: String |
the allowed category. |
| Returns | |
|---|---|
IntentSanitizer.Builder |
this builder. |
allowCategory
fun allowCategory(filter: Predicate<String!>): IntentSanitizer.Builder
Add a filter for allowed categories. This method can be called multiple times and the result is additive. They will not overwrite each other.
| Returns | |
|---|---|
IntentSanitizer.Builder |
this builder. |
allowClipData
fun allowClipData(filter: Predicate<ClipData!>): IntentSanitizer.Builder
Allows clipData that passes the given filter. This method can be called multiple times and the result is additive. They will not overwrite each other.
| Returns | |
|---|---|
IntentSanitizer.Builder |
this builder. |
allowClipDataText
fun allowClipDataText(): IntentSanitizer.Builder
Allows clipData that contains text. overwrite each other.
| Returns | |
|---|---|
IntentSanitizer.Builder |
this builder. |
allowClipDataUri
fun allowClipDataUri(filter: Predicate<Uri!>): IntentSanitizer.Builder
Allows clipData whose items URIs pass the given URI filter. This method can be called multiple times and the result is additive. They will not overwrite each other.
| Returns | |
|---|---|
IntentSanitizer.Builder |
this builder. |
allowClipDataUriWithAuthority
fun allowClipDataUriWithAuthority(authority: String): IntentSanitizer.Builder
Allows clipData whose items URIs authorities match the given authority. This method can be called multiple times and the result is additive. They will not overwrite each other.
| Parameters | |
|---|---|
authority: String |
the given authority. |
| Returns | |
|---|---|
IntentSanitizer.Builder |
this builder. |
allowComponent
fun allowComponent(component: ComponentName): IntentSanitizer.Builder
Add a component to the allowed components list. This method can be called multiple times and the result is additive. They will not overwrite each other.
| Parameters | |
|---|---|
component: ComponentName |
the allowed component. |
| Returns | |
|---|---|
IntentSanitizer.Builder |
this builder. |
allowComponent
fun allowComponent(filter: Predicate<ComponentName!>): IntentSanitizer.Builder
Add a filter for allowed components. This method can be called multiple times and the result is additive. They will not overwrite each other.
| Parameters | |
|---|---|
filter: Predicate<ComponentName!> |
the component filter. |
| Returns | |
|---|---|
IntentSanitizer.Builder |
this builder. |
allowComponentWithPackage
fun allowComponentWithPackage(packageName: String): IntentSanitizer.Builder
Allow any component under the specified package. Note this does not allow the package itself. If the intent contains a package, call allowPackage method. This method can be called multiple times and the result is additive. They will not overwrite each other.
| Returns | |
|---|---|
IntentSanitizer.Builder |
this builder. |
allowData
fun allowData(filter: Predicate<Uri!>): IntentSanitizer.Builder
Allow data that passes the filter test. This method can be called multiple times and the result is additive. They will not overwrite each other.
allowDataWithAuthority
fun allowDataWithAuthority(authority: String): IntentSanitizer.Builder
Convenient method to allow all data whose URI authority equals to the given. This method can be called multiple times and the result is additive. They will not overwrite each other.
| Parameters | |
|---|---|
authority: String |
the URI's authority. |
| Returns | |
|---|---|
IntentSanitizer.Builder |
this builder |
allowExtra
fun allowExtra(key: String, clazz: Class<Any!>): IntentSanitizer.Builder
Allows an extra member whose key and type of value matches the given. This method can be called multiple times and the result is additive. They will not overwrite each other.
| Returns | |
|---|---|
IntentSanitizer.Builder |
this builder. |
allowExtra
fun allowExtra(key: String, filter: Predicate<Any!>): IntentSanitizer.Builder
Allows an extra member whose key matches the given key and whose value passes the filter test. This method can be called multiple times and the result is additive. They will not overwrite each other.
| Returns | |
|---|---|
IntentSanitizer.Builder |
this builder. |
allowExtra
fun <T> allowExtra(key: String, clazz: Class<T!>, valueFilter: Predicate<T!>): IntentSanitizer.Builder
Allows an extra member whose key matches the given key and whose value is of the type of the given clazz and passes the value filter. This method can be called multiple times and the result is additive. They will not overwrite each other.
| Parameters | |
|---|---|
key: String |
given extra key. |
clazz: Class<T!> |
given type of the extra value. |
valueFilter: Predicate<T!> |
the extra value filter. |
| Returns | |
|---|---|
IntentSanitizer.Builder |
this builder. |
allowExtraOutput
fun allowExtraOutput(filter: Predicate<Uri!>): IntentSanitizer.Builder
Allows an extra member with the key MediaStore.EXTRA_OUTPUT. The value type has to be URI and the value also passes the given filter test. In order to use this method, user has to be explicitly allow the FLAG_GRANT_READ_URI_PERMISSION and FLAG_GRANT_WRITE_URI_PERMISSION flags. Otherwise, it will trigger penalty during sanitization. This method can be called multiple times and the result is additive. They will not overwrite each other.
| Returns | |
|---|---|
IntentSanitizer.Builder |
this builder. |
allowExtraOutput
fun allowExtraOutput(uriAuthority: String): IntentSanitizer.Builder
Allows an extra member with the key MediaStore.EXTRA_OUTPUT. The value type has to be URI and the authority matches the given parameter. In order to use this method, user has to be explicitly allow the FLAG_GRANT_READ_URI_PERMISSION and FLAG_GRANT_WRITE_URI_PERMISSION flags. Otherwise, it will trigger penalty during sanitization. This method can be called multiple times and the result is additive. They will not overwrite each other.
| Parameters | |
|---|---|
uriAuthority: String |
the given URI authority. |
| Returns | |
|---|---|
IntentSanitizer.Builder |
this builder. |
allowExtraStream
fun allowExtraStream(filter: Predicate<Uri!>): IntentSanitizer.Builder
Allows an extra member with the key Intent.EXTRA_STREAM. The value type has to be URI and the value also passes the given filter test. In order to use this method, user has to be explicitly allow the FLAG_GRANT_READ_URI_PERMISSION flag. Otherwise, it will trigger penalty during sanitization. This method can be called multiple times and the result is additive. They will not overwrite each other.
| Returns | |
|---|---|
IntentSanitizer.Builder |
this builder. |
allowExtraStreamUriWithAuthority
fun allowExtraStreamUriWithAuthority(uriAuthority: String): IntentSanitizer.Builder
Allows an extra member with the key Intent.EXTRA_STREAM. The value type has to be URI and the authority matches the given parameter. In order to use this method, user has to be explicitly allow the FLAG_GRANT_READ_URI_PERMISSION flag. Otherwise, it will trigger penalty during sanitization. This method can be called multiple times and the result is additive. They will not overwrite each other.
| Parameters | |
|---|---|
uriAuthority: String |
the given URI authority. |
| Returns | |
|---|---|
IntentSanitizer.Builder |
this builder. |
allowFlags
fun allowFlags(flags: Int): IntentSanitizer.Builder
Sets allowed flags. This method can be called multiple times and the result is additive. They will not overwrite each other. In most cases following grant URI permission related flags should not be allowed:
- FLAG_GRANT_PERSISTABLE_URI_PERMISSION
- FLAG_GRANT_PREFIX_URI_PERMISSION
- FLAG_GRANT_READ_URI_PERMISSION
- FLAG_GRANT_WRITE_URI_PERMISSION
EXTRA_STREAM or EXTRA_OUTPUT. When these flags are allowed, you should sanitize URIs. See allowDataWithAuthority, allowData, allowClipDataUriWithAuthority, allowClipDataUri, allowExtraStreamUriWithAuthority, allowExtraStream, allowExtraOutput, allowExtraOutput
| Parameters | |
|---|---|
flags: Int |
allowed flags. |
| Returns | |
|---|---|
IntentSanitizer.Builder |
this builder. |
allowHistoryStackFlags
fun allowHistoryStackFlags(): IntentSanitizer.Builder
Adds all history stack flags into the allowed flags set. They are:
- FLAG_ACTIVITY_BROUGHT_TO_FRONT
- FLAG_ACTIVITY_CLEAR_TASK
- FLAG_ACTIVITY_CLEAR_TOP
- FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET
- FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
- FLAG_ACTIVITY_LAUNCH_ADJACENT
- FLAG_ACTIVITY_MULTIPLE_TASK
- FLAG_ACTIVITY_NEW_DOCUMENT
- FLAG_ACTIVITY_NEW_TASK
- FLAG_ACTIVITY_NO_ANIMATION
- FLAG_ACTIVITY_NO_HISTORY
- FLAG_ACTIVITY_PREVIOUS_IS_TOP
- FLAG_ACTIVITY_REORDER_TO_FRONT
- FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
- FLAG_ACTIVITY_RETAIN_IN_RECENTS
- FLAG_ACTIVITY_SINGLE_TOP
- FLAG_ACTIVITY_TASK_ON_HOME
| Returns | |
|---|---|
IntentSanitizer.Builder |
this builder. |
allowIdentifier
fun allowIdentifier(): IntentSanitizer.Builder
Allows any identifier.
| Returns | |
|---|---|
IntentSanitizer.Builder |
this builder. |
allowPackage
fun allowPackage(filter: Predicate<String!>): IntentSanitizer.Builder
Add a filter for allowed packages. This does not imply the intent can contain a component from the allowed package; instead, this value will be compared against the result returned from the Intent's getPackage method. This method can be called multiple times and the result is additive. They will not overwrite each other.
| Returns | |
|---|---|
IntentSanitizer.Builder |
this builder. |
allowPackage
fun allowPackage(packageName: String): IntentSanitizer.Builder
Add a package to the allowed packages. This does not imply the intent can contain a component from the allowed package; instead, this value will be compared against the result returned from the Intent's getPackage method. This method can be called multiple times and the result is additive. They will not overwrite each other.
| Returns | |
|---|---|
IntentSanitizer.Builder |
this builder. |
allowReceiverFlags
fun allowReceiverFlags(): IntentSanitizer.Builder
Adds all receiver flags into the allowed flags set. They are
- FLAG_RECEIVER_FOREGROUND
- FLAG_RECEIVER_NO_ABORT
- FLAG_RECEIVER_REGISTERED_ONLY
- FLAG_RECEIVER_REPLACE_PENDING
- FLAG_RECEIVER_VISIBLE_TO_INSTANT_APPS
| Returns | |
|---|---|
IntentSanitizer.Builder |
this builder. |
allowSelector
fun allowSelector(): IntentSanitizer.Builder
Allow any selector.
| Returns | |
|---|---|
IntentSanitizer.Builder |
this builder. |
allowSourceBounds
fun allowSourceBounds(): IntentSanitizer.Builder
Allow any source bounds.
| Returns | |
|---|---|
IntentSanitizer.Builder |
this builder. |
allowType
fun allowType(filter: Predicate<String!>): IntentSanitizer.Builder
Add a filter for allowed data types. This method can be called multiple times and the result is additive. They will not overwrite each other.
allowType
fun allowType(type: String): IntentSanitizer.Builder
Add a data type to the allowed type list. Exact match is used to check the allowed types. For example, if you pass in "image/*" here, it won't allow an intent with type of "image/png". This method can be called multiple times and the result is additive. They will not overwrite each other.
| Parameters | |
|---|---|
type: String |
the data type that is allowed |
| Returns | |
|---|---|
IntentSanitizer.Builder |
this builder |
build
fun build(): IntentSanitizer
Build the IntentSanitizer.
| Returns | |
|---|---|
IntentSanitizer |
the IntentSanitizer |