public final class

IntentSanitizer.Builder

extends java.lang.Object

 java.lang.Object

↳androidx.core.content.IntentSanitizer.Builder

Overview

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

Constructors
publicBuilder()

Methods
public IntentSanitizer.BuilderallowAction(Predicate<java.lang.String> filter)

Add a filter for allowed actions.

public IntentSanitizer.BuilderallowAction(java.lang.String action)

Add an action to the list of allowed actions.

public IntentSanitizer.BuilderallowAnyComponent()

Allow any components.

public IntentSanitizer.BuilderallowCategory(Predicate<java.lang.String> filter)

Add a filter for allowed categories.

public IntentSanitizer.BuilderallowCategory(java.lang.String category)

Add a category to the allowed category list.

public IntentSanitizer.BuilderallowClipData(Predicate<ClipData> filter)

Allows clipData that passes the given filter.

public IntentSanitizer.BuilderallowClipDataText()

Allows clipData that contains text.

public IntentSanitizer.BuilderallowClipDataUri(Predicate<Uri> filter)

Allows clipData whose items URIs pass the given URI filter.

public IntentSanitizer.BuilderallowClipDataUriWithAuthority(java.lang.String authority)

Allows clipData whose items URIs authorities match the given authority.

public IntentSanitizer.BuilderallowComponent(ComponentName component)

Add a component to the allowed components list.

public IntentSanitizer.BuilderallowComponent(Predicate<ComponentName> filter)

Add a filter for allowed components.

public IntentSanitizer.BuilderallowComponentWithPackage(java.lang.String packageName)

Allow any component under the specified package.

public IntentSanitizer.BuilderallowData(Predicate<Uri> filter)

Allow data that passes the filter test.

public IntentSanitizer.BuilderallowDataWithAuthority(java.lang.String authority)

Convenient method to allow all data whose URI authority equals to the given.

public IntentSanitizer.BuilderallowExtra(java.lang.String key, java.lang.Class<java.lang.Object> clazz)

Allows an extra member whose key and type of value matches the given.

public IntentSanitizer.BuilderallowExtra(java.lang.String key, java.lang.Class<java.lang.Object> clazz, Predicate<java.lang.Object> valueFilter)

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.

public IntentSanitizer.BuilderallowExtra(java.lang.String key, Predicate<java.lang.Object> filter)

Allows an extra member whose key matches the given key and whose value passes the filter test.

public IntentSanitizer.BuilderallowExtraOutput(Predicate<Uri> filter)

Allows an extra member with the key MediaStore.EXTRA_OUTPUT.

public IntentSanitizer.BuilderallowExtraOutput(java.lang.String uriAuthority)

Allows an extra member with the key MediaStore.EXTRA_OUTPUT.

public IntentSanitizer.BuilderallowExtraStream(Predicate<Uri> filter)

Allows an extra member with the key Intent.EXTRA_STREAM.

public IntentSanitizer.BuilderallowExtraStreamUriWithAuthority(java.lang.String uriAuthority)

Allows an extra member with the key Intent.EXTRA_STREAM.

public IntentSanitizer.BuilderallowFlags(int flags)

Sets allowed flags.

public IntentSanitizer.BuilderallowHistoryStackFlags()

Adds all history stack flags into the allowed flags set.

public IntentSanitizer.BuilderallowIdentifier()

Allows any identifier.

public IntentSanitizer.BuilderallowPackage(Predicate<java.lang.String> filter)

Add a filter for allowed packages.

public IntentSanitizer.BuilderallowPackage(java.lang.String packageName)

Add a package to the allowed packages.

public IntentSanitizer.BuilderallowReceiverFlags()

Adds all receiver flags into the allowed flags set.

public IntentSanitizer.BuilderallowSelector()

Allow any selector.

public IntentSanitizer.BuilderallowSourceBounds()

Allow any source bounds.

public IntentSanitizer.BuilderallowType(Predicate<java.lang.String> filter)

Add a filter for allowed data types.

public IntentSanitizer.BuilderallowType(java.lang.String type)

Add a data type to the allowed type list.

public IntentSanitizerbuild()

Build the IntentSanitizer.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public Builder()

Methods

public IntentSanitizer.Builder allowFlags(int flags)

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
Setting these flags would allow others to access URIs only your app has permission to access. These URIs could be set in intent's data, clipData and/or, in certain circumstances, extras with key of or . When these flags are allowed, you should sanitize URIs. See IntentSanitizer.Builder.allowDataWithAuthority(String), IntentSanitizer.Builder.allowData(Predicate), IntentSanitizer.Builder.allowClipDataUriWithAuthority(String), IntentSanitizer.Builder.allowClipDataUri(Predicate), IntentSanitizer.Builder.allowExtraStreamUriWithAuthority(String), IntentSanitizer.Builder.allowExtraStream(Predicate), IntentSanitizer.Builder.allowExtraOutput(String), IntentSanitizer.Builder.allowExtraOutput(Predicate)

Parameters:

flags: allowed flags.

Returns:

this builder.

public IntentSanitizer.Builder allowHistoryStackFlags()

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:

this builder.

public IntentSanitizer.Builder allowReceiverFlags()

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:

this builder.

public IntentSanitizer.Builder allowAction(java.lang.String action)

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: the name of an action.

Returns:

this builder.

public IntentSanitizer.Builder allowAction(Predicate<java.lang.String> filter)

Add a filter for allowed actions. This method can be called multiple times and the result is additive. They will not overwrite each other.

Parameters:

filter: a filter that tests if an action is allowed.

Returns:

this builder.

public IntentSanitizer.Builder allowDataWithAuthority(java.lang.String authority)

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: the URI's authority.

Returns:

this builder

public IntentSanitizer.Builder allowData(Predicate<Uri> filter)

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.

Parameters:

filter: data filter.

public IntentSanitizer.Builder allowType(java.lang.String type)

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: the data type that is allowed

Returns:

this builder

public IntentSanitizer.Builder allowType(Predicate<java.lang.String> filter)

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.

Parameters:

filter: the data type filter.

public IntentSanitizer.Builder allowCategory(java.lang.String category)

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: the allowed category.

Returns:

this builder.

public IntentSanitizer.Builder allowCategory(Predicate<java.lang.String> filter)

Add a filter for allowed categories. This method can be called multiple times and the result is additive. They will not overwrite each other.

Parameters:

filter: the category filter.

Returns:

this builder.

public IntentSanitizer.Builder allowPackage(java.lang.String packageName)

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 method. This method can be called multiple times and the result is additive. They will not overwrite each other.

Returns:

this builder.

public IntentSanitizer.Builder allowPackage(Predicate<java.lang.String> filter)

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 method. This method can be called multiple times and the result is additive. They will not overwrite each other.

Parameters:

filter: the package name filter.

Returns:

this builder.

public IntentSanitizer.Builder allowComponent(ComponentName component)

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: the allowed component.

Returns:

this builder.

public IntentSanitizer.Builder allowComponent(Predicate<ComponentName> filter)

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: the component filter.

Returns:

this builder.

public IntentSanitizer.Builder allowComponentWithPackage(java.lang.String packageName)

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:

this builder.

public IntentSanitizer.Builder allowAnyComponent()

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:

this builder.

public IntentSanitizer.Builder allowClipDataText()

Allows clipData that contains text. overwrite each other.

Returns:

this builder.

public IntentSanitizer.Builder allowClipDataUriWithAuthority(java.lang.String authority)

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: the given authority.

Returns:

this builder.

public IntentSanitizer.Builder allowClipDataUri(Predicate<Uri> filter)

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.

Parameters:

filter: the given URI filter.

Returns:

this builder.

public IntentSanitizer.Builder allowClipData(Predicate<ClipData> filter)

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.

Parameters:

filter: the given clipData filter.

Returns:

this builder.

public IntentSanitizer.Builder allowExtra(java.lang.String key, java.lang.Class<java.lang.Object> clazz)

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.

Parameters:

key: the given extra key.
clazz: the given class of the extra value.

Returns:

this builder.

public IntentSanitizer.Builder allowExtra(java.lang.String key, java.lang.Class<java.lang.Object> clazz, Predicate<java.lang.Object> valueFilter)

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: given extra key.
clazz: given type of the extra value.
valueFilter: the extra value filter.

Returns:

this builder.

public IntentSanitizer.Builder allowExtra(java.lang.String key, Predicate<java.lang.Object> filter)

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.

Parameters:

key: the extra key.
filter: the filter for the extra value.

Returns:

this builder.

public IntentSanitizer.Builder allowExtraStreamUriWithAuthority(java.lang.String uriAuthority)

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. 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: the given URI authority.

Returns:

this builder.

public IntentSanitizer.Builder allowExtraStream(Predicate<Uri> filter)

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. 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:

filter: the given URI authority.

Returns:

this builder.

public IntentSanitizer.Builder allowExtraOutput(java.lang.String uriAuthority)

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 and 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: the given URI authority.

Returns:

this builder.

public IntentSanitizer.Builder allowExtraOutput(Predicate<Uri> filter)

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 and 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:

filter: the given URI authority.

Returns:

this builder.

public IntentSanitizer.Builder allowIdentifier()

Allows any identifier.

Returns:

this builder.

public IntentSanitizer.Builder allowSelector()

Allow any selector.

Returns:

this builder.

public IntentSanitizer.Builder allowSourceBounds()

Allow any source bounds.

Returns:

this builder.

public IntentSanitizer build()

Build the IntentSanitizer.

Returns:

the IntentSanitizer