Merge "Allow autofill auth intent result to specify whether the new dataset is ephemeral or not" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
325e0f94eb
@@ -50687,6 +50687,7 @@ package android.view.autofill {
|
||||
method public void unregisterCallback(@Nullable android.view.autofill.AutofillManager.AutofillCallback);
|
||||
field public static final String EXTRA_ASSIST_STRUCTURE = "android.view.autofill.extra.ASSIST_STRUCTURE";
|
||||
field public static final String EXTRA_AUTHENTICATION_RESULT = "android.view.autofill.extra.AUTHENTICATION_RESULT";
|
||||
field public static final String EXTRA_AUTHENTICATION_RESULT_EPHEMERAL_DATASET = "android.view.autofill.extra.AUTHENTICATION_RESULT_EPHEMERAL_DATASET";
|
||||
field public static final String EXTRA_CLIENT_STATE = "android.view.autofill.extra.CLIENT_STATE";
|
||||
}
|
||||
|
||||
|
||||
@@ -199,6 +199,34 @@ public final class AutofillManager {
|
||||
public static final String EXTRA_AUTHENTICATION_RESULT =
|
||||
"android.view.autofill.extra.AUTHENTICATION_RESULT";
|
||||
|
||||
/**
|
||||
* Intent extra: The optional boolean extra field provided by the
|
||||
* {@link android.service.autofill.AutofillService} accompanying the {@link
|
||||
* android.service.autofill.Dataset} result of an authentication operation.
|
||||
*
|
||||
* <p> Before {@link android.os.Build.VERSION_CODES#R}, if the authentication result is a
|
||||
* {@link android.service.autofill.Dataset}, it'll be used to autofill the fields, and also
|
||||
* replace the existing dataset in the cached {@link android.service.autofill.FillResponse}.
|
||||
* That means if the user clears the field values, the autofill suggestion will show up again
|
||||
* with the new authenticated Dataset.
|
||||
*
|
||||
* <p> In {@link android.os.Build.VERSION_CODES#R}, we added an exception to this behavior
|
||||
* that if the Dataset being authenticated is a pinned dataset (see
|
||||
* {@link android.service.autofill.InlinePresentation#isPinned()}), the old Dataset will not be
|
||||
* replaced.
|
||||
*
|
||||
* <p> In {@link android.os.Build.VERSION_CODES#S}, we added this boolean extra field to
|
||||
* allow the {@link android.service.autofill.AutofillService} to explicitly specify whether
|
||||
* the returned authenticated Dataset is ephemeral. An ephemeral Dataset will be used to
|
||||
* autofill once and then thrown away. Therefore, when the boolean extra is set to true, the
|
||||
* returned Dataset will not replace the old dataset from the existing
|
||||
* {@link android.service.autofill.FillResponse}. When it's set to false, it will. When it's not
|
||||
* set, the old dataset will be replaced, unless it is a pinned inline suggestion, which is
|
||||
* consistent with the behavior in {@link android.os.Build.VERSION_CODES#R}.
|
||||
*/
|
||||
public static final String EXTRA_AUTHENTICATION_RESULT_EPHEMERAL_DATASET =
|
||||
"android.view.autofill.extra.AUTHENTICATION_RESULT_EPHEMERAL_DATASET";
|
||||
|
||||
/**
|
||||
* Intent extra: The optional extras provided by the
|
||||
* {@link android.service.autofill.AutofillService}.
|
||||
@@ -1755,6 +1783,11 @@ public final class AutofillManager {
|
||||
if (newClientState != null) {
|
||||
responseData.putBundle(EXTRA_CLIENT_STATE, newClientState);
|
||||
}
|
||||
if (data.getExtras().containsKey(EXTRA_AUTHENTICATION_RESULT_EPHEMERAL_DATASET)) {
|
||||
responseData.putBoolean(EXTRA_AUTHENTICATION_RESULT_EPHEMERAL_DATASET,
|
||||
data.getBooleanExtra(EXTRA_AUTHENTICATION_RESULT_EPHEMERAL_DATASET,
|
||||
false));
|
||||
}
|
||||
try {
|
||||
mService.setAuthenticationResult(responseData, mSessionId, authenticationId,
|
||||
mContext.getUserId());
|
||||
|
||||
@@ -1492,7 +1492,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
|
||||
}
|
||||
final Dataset dataset = (Dataset) result;
|
||||
final Dataset oldDataset = authenticatedResponse.getDatasets().get(datasetIdx);
|
||||
if (!isPinnedDataset(oldDataset)) {
|
||||
if (!isAuthResultDatasetEphemeral(oldDataset, data)) {
|
||||
authenticatedResponse.getDatasets().set(datasetIdx, dataset);
|
||||
}
|
||||
autoFill(requestId, datasetIdx, dataset, false);
|
||||
@@ -1512,6 +1512,21 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the dataset returned from the authentication result is ephemeral or not.
|
||||
* See {@link AutofillManager#EXTRA_AUTHENTICATION_RESULT_EPHEMERAL_DATASET} for more
|
||||
* information.
|
||||
*/
|
||||
private static boolean isAuthResultDatasetEphemeral(@Nullable Dataset oldDataset,
|
||||
@NonNull Bundle authResultData) {
|
||||
if (authResultData.containsKey(
|
||||
AutofillManager.EXTRA_AUTHENTICATION_RESULT_EPHEMERAL_DATASET)) {
|
||||
return authResultData.getBoolean(
|
||||
AutofillManager.EXTRA_AUTHENTICATION_RESULT_EPHEMERAL_DATASET);
|
||||
}
|
||||
return isPinnedDataset(oldDataset);
|
||||
}
|
||||
|
||||
/**
|
||||
* A dataset can potentially have multiple fields, and it's possible that some of the fields'
|
||||
* has inline presentation and some don't. It's also possible that some of the fields'
|
||||
|
||||
Reference in New Issue
Block a user