Builder
class Builder
kotlin.Any | |
↳ | android.service.autofill.FillResponse.Builder |
Builder for FillResponse
objects. You must to provide at least one dataset or set an authentication intent with a presentation view.
Summary
Public constructors | |
---|---|
Builder() |
Public methods | |
---|---|
FillResponse.Builder |
addDataset(dataset: Dataset?) Adds a new |
FillResponse |
build() Builds a new |
FillResponse.Builder |
disableAutofill(duration: Long) Disables autofill for the app or activity. |
FillResponse.Builder |
setAuthentication(ids: Array<AutofillId!>, authentication: IntentSender?, presentation: RemoteViews?) Triggers a custom UI before autofilling the screen with any data set in this response. |
FillResponse.Builder |
setAuthentication(ids: Array<AutofillId!>, authentication: IntentSender?, presentation: RemoteViews?, inlinePresentation: InlinePresentation?) Triggers a custom UI before autofilling the screen with any data set in this response. |
FillResponse.Builder |
setAuthentication(ids: Array<AutofillId!>, authentication: IntentSender?, presentation: RemoteViews?, inlinePresentation: InlinePresentation?, inlineTooltipPresentation: InlinePresentation?) Triggers a custom UI before autofilling the screen with any data set in this response. |
FillResponse.Builder |
setAuthentication(ids: Array<AutofillId!>, authentication: IntentSender?, presentations: Presentations?) Triggers a custom UI before autofilling the screen with any data set in this response. |
FillResponse.Builder |
setClientState(clientState: Bundle?) Sets a bundle with state that is passed to subsequent APIs that manipulate this response. |
FillResponse.Builder |
setDetectedFieldClassifications(fieldInfos: MutableSet<FieldClassification!>) Adds a new |
FillResponse.Builder |
setDialogHeader(header: RemoteViews) Sets the presentation of header in fill dialog UI. |
FillResponse.Builder |
setFieldClassificationIds(vararg ids: AutofillId!) Sets which fields are used for field classification |
FillResponse.Builder |
setFillDialogTriggerIds(vararg ids: AutofillId!) Sets which fields are used for the fill dialog UI. |
FillResponse.Builder |
Sets flags changing the response behavior. |
FillResponse.Builder |
Sets a footer to be shown as the last element in the list of datasets. |
FillResponse.Builder |
setHeader(header: RemoteViews) Sets a header to be shown as the first element in the list of datasets. |
FillResponse.Builder |
setIconResourceId(id: Int) Overwrites Save/Fill dialog header icon with a specific one specified by resource id. |
FillResponse.Builder |
setIgnoredIds(vararg ids: AutofillId!) Specifies views that should not trigger new |
FillResponse.Builder |
setPresentationCancelIds(ids: IntArray?) Sets target resource IDs of the child view in |
FillResponse.Builder |
setSaveInfo(saveInfo: SaveInfo) Sets the |
FillResponse.Builder |
Overrides the service name in the Save Dialog header with a specific string defined in the service provider's manifest. |
FillResponse.Builder |
setShowFillDialogIcon(show: Boolean) Whether or not to show the Autofill provider icon inside of the Fill Dialog |
FillResponse.Builder |
setShowSaveDialogIcon(show: Boolean) Whether or not to show the Autofill provider icon inside of the Save Dialog |
FillResponse.Builder |
setUserData(userData: UserData) Sets a specific |
Public constructors
Builder
Builder()
Public methods
addDataset
fun addDataset(dataset: Dataset?): FillResponse.Builder
Adds a new Dataset
to this response.
Note: on Android android.os.Build.VERSION_CODES#O
, the total number of datasets is limited by the Binder transaction size, so it's recommended to keep it small (in the range of 10-20 at most) and use pagination by adding a fake authenticated dataset
at the end with a presentation string like "Next 10" that would return a new FillResponse
with the next 10 datasets, and so on. This limitation was lifted on Android android.os.Build.VERSION_CODES#O_MR1
, although the Binder transaction size can still be reached if each dataset itself is too big.
Parameters | |
---|---|
dataset |
Dataset?: This value may be null . |
Return | |
---|---|
FillResponse.Builder |
This builder. This value cannot be null . |
build
fun build(): FillResponse
Builds a new FillResponse
instance.
Return | |
---|---|
FillResponse |
A built response. This value cannot be null . |
Exceptions | |
---|---|
java.lang.IllegalStateException |
if any of the following conditions occur:
|
disableAutofill
fun disableAutofill(duration: Long): FillResponse.Builder
Disables autofill for the app or activity.
This method is useful to optimize performance in cases where the service knows it can not autofill an app—for example, when the service has a list of "denylisted" apps such as office suites.
By default, it disables autofill for all activities in the app, unless the response is flagged
with FLAG_DISABLE_ACTIVITY_ONLY
.
Autofill for the app or activity is automatically re-enabled after any of the following conditions:
duration
milliseconds have passed.- The autofill service for the user has changed.
- The device has rebooted.
Note: Activities that are running when autofill is re-enabled remain disabled for autofill until they finish and restart.
Parameters | |
---|---|
duration |
Long: duration to disable autofill, in milliseconds. |
Return | |
---|---|
FillResponse.Builder |
this builder This value cannot be null . |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if duration is not a positive number. |
java.lang.IllegalStateException |
if either addDataset(android.service.autofill.Dataset) , setAuthentication(android.view.autofill.AutofillId[],android.content.IntentSender,android.service.autofill.Presentations) , setSaveInfo(android.service.autofill.SaveInfo) , setClientState(android.os.Bundle) , or setFieldClassificationIds(android.view.autofill.AutofillId...) was already called. |
setAuthentication
funsetAuthentication(
ids: Array<AutofillId!>,
authentication: IntentSender?,
presentation: RemoteViews?
): FillResponse.Builder
Deprecated: Deprecated in Java.
Triggers a custom UI before autofilling the screen with any data set in this response.
Note: Although the name of this method suggests that it should be used just for authentication flow, it can be used for other advanced flows; see AutofillService
for examples.
This is typically useful when a user interaction is required to unlock their data vault if you encrypt the data set labels and data set data. It is recommended to encrypt only the sensitive data and not the data set labels which would allow auth on the data set level leading to a better user experience. Note that if you use sensitive data as a label, for example an email address, then it should also be encrypted. The provided intent
must be an Activity
which implements your authentication flow. Also if you provide an auth intent you also need to specify the presentation view to be shown in the fill UI for the user to trigger your authentication flow.
When a user triggers autofill, the system launches the provided intent whose extras will have the screen
and your client state
. Once you complete your authentication flow you should set the Activity
result to android.app.Activity#RESULT_OK
and set the android.view.autofill.AutofillManager#EXTRA_AUTHENTICATION_RESULT
extra with the fully populated response
(or null
if the screen cannot be autofilled).
IMPORTANT: Extras must be non-null on the intent being set for Android 12 otherwise it will cause a crash. Do not use Activity#setResult(int)
, instead use Activity#setResult(int, Intent)
setAuthentication
funsetAuthentication(
ids: Array<AutofillId!>,
authentication: IntentSender?,
presentation: RemoteViews?,
inlinePresentation: InlinePresentation?
): FillResponse.Builder
Deprecated: Use setAuthentication(android.view.autofill.AutofillId[],android.content.IntentSender,android.service.autofill.Presentations)
instead.
Triggers a custom UI before autofilling the screen with any data set in this response.
Note: Although the name of this method suggests that it should be used just for authentication flow, it can be used for other advanced flows; see AutofillService
for examples.
This method is similar to setAuthentication(android.view.autofill.AutofillId[],android.content.IntentSender,android.widget.RemoteViews)
, but also accepts an InlinePresentation
presentation which is required for authenticating through the inline autofill flow.
Note: setHeader(android.widget.RemoteViews)
or setFooter(android.widget.RemoteViews)
does not work with InlinePresentation
.
Parameters | |
---|---|
authentication |
IntentSender?: Intent to an activity with your authentication flow. This value may be null . |
presentation |
RemoteViews?: The presentation to visualize the response. This value may be null . |
inlinePresentation |
InlinePresentation?: The inlinePresentation to visualize the response inline. This value may be null . |
ids |
Array<AutofillId!>: id of Views that when focused will display the authentication UI. This value cannot be null . |
Return | |
---|---|
FillResponse.Builder |
This builder. This value cannot be null . |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if any of the following occurs:
|
java.lang.IllegalStateException |
if a header or a footer are already set for this builder. |
setAuthentication
funsetAuthentication(
ids: Array<AutofillId!>,
authentication: IntentSender?,
presentation: RemoteViews?,
inlinePresentation: InlinePresentation?,
inlineTooltipPresentation: InlinePresentation?
): FillResponse.Builder
Deprecated: Use setAuthentication(android.view.autofill.AutofillId[],android.content.IntentSender,android.service.autofill.Presentations)
instead.
Triggers a custom UI before autofilling the screen with any data set in this response.
This method like setAuthentication(android.view.autofill.AutofillId[],android.content.IntentSender,android.widget.RemoteViews,android.service.autofill.InlinePresentation)
but allows setting an InlinePresentation
for the inline suggestion tooltip.
Parameters | |
---|---|
ids |
Array<AutofillId!>: This value cannot be null . |
authentication |
IntentSender?: This value may be null . |
presentation |
RemoteViews?: This value may be null . |
inlinePresentation |
InlinePresentation?: This value may be null . |
inlineTooltipPresentation |
InlinePresentation?: This value may be null . |
Return | |
---|---|
FillResponse.Builder |
This value cannot be null . |
setAuthentication
fun setAuthentication(
ids: Array<AutofillId!>,
authentication: IntentSender?,
presentations: Presentations?
): FillResponse.Builder
Triggers a custom UI before autofilling the screen with any data set in this response.
Note: Although the name of this method suggests that it should be used just for authentication flow, it can be used for other advanced flows; see AutofillService
for examples.
This is typically useful when a user interaction is required to unlock their data vault if you encrypt the data set labels and data set data. It is recommended to encrypt only the sensitive data and not the data set labels which would allow auth on the data set level leading to a better user experience. Note that if you use sensitive data as a label, for example an email address, then it should also be encrypted. The provided intent
must be an Activity
which implements your authentication flow. Also if you provide an auth intent you also need to specify the presentation view to be shown in the fill UI for the user to trigger your authentication flow.
When a user triggers autofill, the system launches the provided intent whose extras will have the screen
and your client state
. Once you complete your authentication flow you should set the Activity
result to android.app.Activity#RESULT_OK
and set the android.view.autofill.AutofillManager#EXTRA_AUTHENTICATION_RESULT
extra with the fully populated response
(or null
if the screen cannot be autofilled).
For example, if you provided an empty response
because the user's data was locked and marked that the response needs an authentication then in the response returned if authentication succeeds you need to provide all available data sets some of which may need to be further authenticated, for example a credit card whose CVV needs to be entered.
If you provide an authentication intent you must also provide a presentation which is used to visualize the response for triggering the authentication flow.
Note: Do not make the provided pending intent immutable by using android.app.PendingIntent#FLAG_IMMUTABLE
as the platform needs to fill in the authentication arguments.
Note: setHeader(android.widget.RemoteViews)
or setFooter(android.widget.RemoteViews)
does not work with InlinePresentation
.
Parameters | |
---|---|
ids |
Array<AutofillId!>: id of Views that when focused will display the authentication UI. This value cannot be null . |
authentication |
IntentSender?: Intent to an activity with your authentication flow. This value may be null . |
presentations |
Presentations?: The presentations to visualize the response. This value may be null . |
Return | |
---|---|
FillResponse.Builder |
This builder. |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if any of the following occurs:
|
java.lang.IllegalStateException |
if a header or a footer are already set for this builder. |
setClientState
fun setClientState(clientState: Bundle?): FillResponse.Builder
Sets a bundle with state that is passed to subsequent APIs that manipulate this response.
You can use this bundle to store intermediate state that is passed to subsequent calls to AutofillService#onFillRequest(FillRequest, android.os.CancellationSignal,
and AutofillService#onSaveRequest(SaveRequest, SaveCallback)
, and you can also retrieve it by calling FillEventHistory.Event#getClientState()
.
If this method is called on multiple FillResponse
objects for the same screen, just the latest bundle is passed back to the service.
Parameters | |
---|---|
clientState |
Bundle?: The custom client state. This value may be null . |
Return | |
---|---|
FillResponse.Builder |
This builder. This value cannot be null . |
setDetectedFieldClassifications
fun setDetectedFieldClassifications(fieldInfos: MutableSet<FieldClassification!>): FillResponse.Builder
Adds a new FieldClassification
to this response, to help the platform provide more accurate detection results. Call this when a field has been detected with a type. Altough similiarly named with setFieldClassificationIds
, it provides a different functionality - setFieldClassificationIds should be used when a field is only suspected to be Autofillable. This method should be used when a field is certainly Autofillable with a certain type.
Parameters | |
---|---|
fieldInfos |
MutableSet<FieldClassification!>: This value cannot be null . |
Return | |
---|---|
FillResponse.Builder |
This value cannot be null . |
setDialogHeader
fun setDialogHeader(header: RemoteViews): FillResponse.Builder
Sets the presentation of header in fill dialog UI. The header should have a prompt for what datasets are shown in the dialog. If this is not set, the dialog only shows your application icon. More details about the fill dialog, see fill dialog UI
Parameters | |
---|---|
header |
RemoteViews: This value cannot be null . |
Return | |
---|---|
FillResponse.Builder |
This value cannot be null . |
setFieldClassificationIds
fun setFieldClassificationIds(vararg ids: AutofillId!): FillResponse.Builder
Sets which fields are used for field classification
Note: This method automatically adds the FillResponse#FLAG_TRACK_CONTEXT_COMMITED
to the flags
.
Parameters | |
---|---|
ids |
AutofillId!: This value cannot be null . |
Return | |
---|---|
FillResponse.Builder |
This value cannot be null . |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
is length of ids args is more than UserData#getMaxFieldClassificationIdsSize() . |
java.lang.IllegalStateException |
if build() or disableAutofill(long) was already called. |
java.lang.NullPointerException |
if ids or any element on it is null . |
setFillDialogTriggerIds
fun setFillDialogTriggerIds(vararg ids: AutofillId!): FillResponse.Builder
Sets which fields are used for the fill dialog UI. More details about the fill dialog, see fill dialog UI
Parameters | |
---|---|
ids |
AutofillId!: This value cannot be null . |
Return | |
---|---|
FillResponse.Builder |
This value cannot be null . |
Exceptions | |
---|---|
java.lang.IllegalStateException |
if build() was already called. |
java.lang.NullPointerException |
if ids or any element on it is null . |
setFlags
fun setFlags(flags: Int): FillResponse.Builder
Sets flags changing the response behavior.
Parameters | |
---|---|
flags |
Int: a combination of FLAG_TRACK_CONTEXT_COMMITED and FLAG_DISABLE_ACTIVITY_ONLY , or 0 . Value is either 0 or a combination of android.service.autofill.FillResponse#FLAG_TRACK_CONTEXT_COMMITED , android.service.autofill.FillResponse#FLAG_DISABLE_ACTIVITY_ONLY , android.service.autofill.FillResponse#FLAG_DELAY_FILL , and android.service.autofill.FillResponse.FLAG_CREDENTIAL_MANAGER_RESPONSE |
Return | |
---|---|
FillResponse.Builder |
This builder. This value cannot be null . |
setFooter
fun setFooter(: RemoteViews): FillResponse.Builder
Sets a footer to be shown as the last element in the list of datasets.
When this method is called, you must also add a dataset
, otherwise build()
throws an IllegalStateException
. Similarly, this method should only be used on FillResponses
that do not require authentication (as the footer could have been set directly in the main presentation in these cases).
Theme does not work with RemoteViews layout. Avoid hardcoded text color or background color: Autofill on different platforms may have different themes.
Parameters | |
---|---|
footer |
RemoteViews: a presentation to represent the footer. This presentation is not clickable —calling RemoteViews#setOnClickPendingIntent(int, android.app.PendingIntent) on it would have no effect. This value cannot be null . |
Return | |
---|---|
FillResponse.Builder |
this builder This value cannot be null . |
Exceptions | |
---|---|
java.lang.IllegalStateException |
if the FillResponse requires authentication . |
setHeader
fun setHeader(header: RemoteViews): FillResponse.Builder
Sets a header to be shown as the first element in the list of datasets.
When this method is called, you must also add a dataset
, otherwise build()
throws an IllegalStateException
. Similarly, this method should only be used on FillResponses
that do not require authentication (as the header could have been set directly in the main presentation in these cases).
Theme does not work with RemoteViews layout. Avoid hardcoded text color or background color: Autofill on different platforms may have different themes.
Parameters | |
---|---|
header |
RemoteViews: a presentation to represent the header. This presentation is not clickable —calling RemoteViews#setOnClickPendingIntent(int, android.app.PendingIntent) on it would have no effect. This value cannot be null . |
Return | |
---|---|
FillResponse.Builder |
this builder This value cannot be null . |
Exceptions | |
---|---|
java.lang.IllegalStateException |
if an authentication was already set for this builder. |
setIconResourceId
fun setIconResourceId(id: Int): FillResponse.Builder
Overwrites Save/Fill dialog header icon with a specific one specified by resource id. The image is pulled from the package, so id should be defined in the manifest.
Parameters | |
---|---|
id |
Int: android.graphics.drawable.Drawable resource id of the icon to be used. A value of 0 indicates to use the default header icon. |
Return | |
---|---|
FillResponse.Builder |
this builder This value cannot be null . |
setIgnoredIds
fun setIgnoredIds(vararg ids: AutofillId!): FillResponse.Builder
Specifies views that should not trigger new AutofillService#onFillRequest(FillRequest, android.os.CancellationSignal,
requests.
This is typically used when the service cannot autofill the view; for example, a text field representing the result of a Captcha challenge.
Return | |
---|---|
FillResponse.Builder |
This value cannot be null . |
setPresentationCancelIds
fun setPresentationCancelIds(ids: IntArray?): FillResponse.Builder
Sets target resource IDs of the child view in Presentation Template
which will cancel the session when clicked. Those targets will be respectively applied to a child of the header, footer and each Dataset
.
Parameters | |
---|---|
ids |
IntArray?: array of the resource id. Empty list or non-existing id has no effect. This value may be null . |
Return | |
---|---|
FillResponse.Builder |
this builder This value cannot be null . |
Exceptions | |
---|---|
java.lang.IllegalStateException |
if build() was already called. |
setSaveInfo
fun setSaveInfo(saveInfo: SaveInfo): FillResponse.Builder
Sets the SaveInfo
associated with this response.
Parameters | |
---|---|
saveInfo |
SaveInfo: This value cannot be null . |
Return | |
---|---|
FillResponse.Builder |
This builder. This value cannot be null . |
setServiceDisplayNameResourceId
fun setServiceDisplayNameResourceId(id: Int): FillResponse.Builder
Overrides the service name in the Save Dialog header with a specific string defined in the service provider's manifest.xml
Parameters | |
---|---|
id |
Int: Resoure Id of the custom string defined in the provider's manifest. If set to 0, the default name will be used. |
Return | |
---|---|
FillResponse.Builder |
this builder This value cannot be null . |
setShowFillDialogIcon
fun setShowFillDialogIcon(show: Boolean): FillResponse.Builder
Whether or not to show the Autofill provider icon inside of the Fill Dialog
Parameters | |
---|---|
show |
Boolean: True to show, false to hide. Defaults to true. |
Return | |
---|---|
FillResponse.Builder |
this builder This value cannot be null . |
setShowSaveDialogIcon
fun setShowSaveDialogIcon(show: Boolean): FillResponse.Builder
Whether or not to show the Autofill provider icon inside of the Save Dialog
Parameters | |
---|---|
show |
Boolean: True to show, false to hide. Defaults to true. |
Return | |
---|---|
FillResponse.Builder |
this builder This value cannot be null . |
setUserData
fun setUserData(userData: UserData): FillResponse.Builder
Sets a specific UserData
for field classification for this request only.
Any fields in this UserData will override corresponding fields in the generic UserData object
Parameters | |
---|---|
userData |
UserData: This value cannot be null . |
Return | |
---|---|
FillResponse.Builder |
this builder This value cannot be null . |
Exceptions | |
---|---|
java.lang.IllegalStateException |
if the FillResponse requires authentication . |