diff options
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/android/service/autofill/augmented/AugmentedAutofillService.java | 12 | ||||
| -rw-r--r-- | core/java/android/view/autofill/AutofillManager.java | 23 |
2 files changed, 28 insertions, 7 deletions
diff --git a/core/java/android/service/autofill/augmented/AugmentedAutofillService.java b/core/java/android/service/autofill/augmented/AugmentedAutofillService.java index cca45f572489..c2234bad3803 100644 --- a/core/java/android/service/autofill/augmented/AugmentedAutofillService.java +++ b/core/java/android/service/autofill/augmented/AugmentedAutofillService.java @@ -163,14 +163,18 @@ public abstract class AugmentedAutofillService extends Service { } /** - * The child class of the service can call this method to initiate an Autofill flow. + * The child class of the service can call this method to initiate a new Autofill flow. If all + * conditions are met, it will make a request to the client app process to explicitly cancel + * the current autofill session and create a new session. For example, an augmented autofill + * service may notice some events which make it think a good time to provide updated + * augmented autofill suggestions. * * <p> The request would be respected only if the previous augmented autofill request was * made for the same {@code activityComponent} and {@code autofillId}, and the field is * currently on focus. * - * <p> The request would start a new autofill flow. It doesn't guarantee that the - * {@link AutofillManager} will proceed with the request. + * <p> The request would cancel the current session and start a new autofill flow. + * It doesn't guarantee that the {@link AutofillManager} will proceed with the request. * * @param activityComponent the client component for which the autofill is requested for * @param autofillId the client field id for which the autofill is requested for @@ -179,8 +183,6 @@ public abstract class AugmentedAutofillService extends Service { */ public final boolean requestAutofill(@NonNull ComponentName activityComponent, @NonNull AutofillId autofillId) { - // TODO(b/149531989): revisit this. The request should start a new autofill session - // rather than reusing the existing session. final AutofillProxy proxy = mAutofillProxyForLastRequest; if (proxy == null || !proxy.mComponentName.equals(activityComponent) || !proxy.mFocusedId.equals(autofillId)) { diff --git a/core/java/android/view/autofill/AutofillManager.java b/core/java/android/view/autofill/AutofillManager.java index 6d3dbfe16b78..1773ec2b17ee 100644 --- a/core/java/android/view/autofill/AutofillManager.java +++ b/core/java/android/view/autofill/AutofillManager.java @@ -883,6 +883,25 @@ public final class AutofillManager { } /** + * Explicitly cancels the current session and requests a new autofill context. + * + * <p>Normally, the autofill context is automatically started if necessary when + * {@link #notifyViewEntered(View)} is called, but this method should be used in + * cases where it must be explicitly started or restarted. Currently, this method should only + * be called by + * {@link android.service.autofill.augmented.AugmentedAutofillService#requestAutofill( + * ComponentName, AutofillId)} to cancel the current session and trigger the autofill flow in + * a new session, giving the autofill service or the augmented autofill service a chance to + * send updated suggestions. + * + * @param view view requesting the new autofill context. + */ + void requestAutofillFromNewSession(@NonNull View view) { + cancel(); + notifyViewEntered(view); + } + + /** * Explicitly requests a new autofill context for virtual views. * * <p>Normally, the autofill context is automatically started if necessary when @@ -1403,7 +1422,7 @@ public final class AutofillManager { * methods such as {@link android.app.Activity#finish()}. */ public void cancel() { - if (sVerbose) Log.v(TAG, "cancel() called by app"); + if (sVerbose) Log.v(TAG, "cancel() called by app or augmented autofill service"); if (!hasAutofillFeature()) { return; } @@ -3484,7 +3503,7 @@ public final class AutofillManager { if (sVerbose) { Log.v(TAG, "requestAutofill() by AugmentedAutofillService."); } - afm.post(() -> afm.requestAutofill(view)); + afm.post(() -> afm.requestAutofillFromNewSession(view)); return true; } |
