Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 08abd46f authored by Feng Cao's avatar Feng Cao
Browse files

Make autofill requested by augmented autofill service non-manual

* The use case of this API was for augmented autofill service to send
  updated suggestions
* Before this change, the dynamic autofill request by the augmented
  autofill service only triggers a manual request, but this has caused
  some regular autofill providers to always some suggestion due to
  their special handling for the manual request. Thus the augmented
  autofill service will not receive the request.
* With this cahnge, the request cancels the previous session to start a
  new session, and also it triggers a regular request (non-manual) so
  the autofill provider will not special handle the request.

Test: atest CtsAutoFillServiceTestCases
Bug: 154543563

Change-Id: I233125a6070394a102ad40b9a50b98a43d952b9f
parent 7291aad9
Loading
Loading
Loading
Loading
+7 −5
Original line number Diff line number Diff line
@@ -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)) {
+21 −2
Original line number Diff line number Diff line
@@ -882,6 +882,25 @@ public final class AutofillManager {
        notifyViewEntered(view, FLAG_MANUAL_REQUEST);
    }

    /**
     * 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.
     *
@@ -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;
        }