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

Commit 2ac463e3 authored by Felipe Leme's avatar Felipe Leme
Browse files

Allow users to manually request Autofill.

- Added a requestAutofill(view,flags) method, that when passed with
  FLAG_MANUAL_AUTOFILL triggers a manual request.
- Added same method for virtual views
- Overloaded existing AutofillService request methods to take a flag.
- Added an AUTOFILL context menu option on TextViews.
- Added a canRequestAutofill() that is used to enable the context menu.

BUG: 35708229
Test: manual verification
Test: existing CtsAutoFillServiceTestCases pass
Test: android.autofillservice.cts.LoginActivityTest#testManualAutofill pass

Change-Id: I1a64d40da3373774451d178b1cabf20f11120e9d
parent a98767ab
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -1790,6 +1790,7 @@ package android {
    field public static final int accessibilityActionSetProgress = 16908349; // 0x102003d
    field public static final int accessibilityActionShowOnScreen = 16908342; // 0x1020036
    field public static final int addToDictionary = 16908330; // 0x102002a
    field public static final int autofill = 16908355; // 0x1020043
    field public static final int background = 16908288; // 0x1020000
    field public static final int button1 = 16908313; // 0x1020019
    field public static final int button2 = 16908314; // 0x102001a
@@ -36742,7 +36743,7 @@ package android.service.autofill {
    method public final android.os.IBinder onBind(android.content.Intent);
    method public void onConnected();
    method public void onDisconnected();
    method public abstract void onFillRequest(android.app.assist.AssistStructure, android.os.Bundle, android.os.CancellationSignal, android.service.autofill.FillCallback);
    method public void onFillRequest(android.app.assist.AssistStructure, android.os.Bundle, int, android.os.CancellationSignal, android.service.autofill.FillCallback);
    method public abstract void onSaveRequest(android.app.assist.AssistStructure, android.os.Bundle, android.service.autofill.SaveCallback);
    field public static final java.lang.String SERVICE_INTERFACE = "android.service.autofill.AutofillService";
    field public static final java.lang.String SERVICE_META_DATA = "android.autofill";
@@ -45424,7 +45425,7 @@ package android.view {
    method public void setActivated(boolean);
    method public void setAlpha(float);
    method public void setAnimation(android.view.animation.Animation);
    method public void setAutofillHint(java.lang.String[]);
    method public void setAutofillHint(java.lang.String...);
    method public void setAutofillMode(int);
    method public void setBackground(android.graphics.drawable.Drawable);
    method public void setBackgroundColor(int);
@@ -47507,6 +47508,7 @@ package android.view.autofill {
  public final class AutofillManager {
    method public void cancel();
    method public void commit();
    method public boolean isEnabled();
    method public void notifyValueChanged(android.view.View);
    method public void notifyViewEntered(android.view.View);
    method public void notifyViewExited(android.view.View);
@@ -47514,9 +47516,12 @@ package android.view.autofill {
    method public void notifyVirtualViewEntered(android.view.View, int, android.graphics.Rect);
    method public void notifyVirtualViewExited(android.view.View, int);
    method public void registerCallback(android.view.autofill.AutofillManager.AutofillCallback);
    method public void requestAutofill(android.view.View);
    method public void requestAutofill(android.view.View, int, android.graphics.Rect);
    method public void unregisterCallback(android.view.autofill.AutofillManager.AutofillCallback);
    field public static final java.lang.String EXTRA_ASSIST_STRUCTURE = "android.view.autofill.extra.ASSIST_STRUCTURE";
    field public static final java.lang.String EXTRA_AUTHENTICATION_RESULT = "android.view.autofill.extra.AUTHENTICATION_RESULT";
    field public static final int FLAG_MANUAL_REQUEST = 1; // 0x1
  }
  public static abstract class AutofillManager.AutofillCallback {
+7 −2
Original line number Diff line number Diff line
@@ -1907,6 +1907,7 @@ package android {
    field public static final int accessibilityActionSetProgress = 16908349; // 0x102003d
    field public static final int accessibilityActionShowOnScreen = 16908342; // 0x1020036
    field public static final int addToDictionary = 16908330; // 0x102002a
    field public static final int autofill = 16908355; // 0x1020043
    field public static final int background = 16908288; // 0x1020000
    field public static final int button1 = 16908313; // 0x1020019
    field public static final int button2 = 16908314; // 0x102001a
@@ -39774,7 +39775,7 @@ package android.service.autofill {
    method public final android.os.IBinder onBind(android.content.Intent);
    method public void onConnected();
    method public void onDisconnected();
    method public abstract void onFillRequest(android.app.assist.AssistStructure, android.os.Bundle, android.os.CancellationSignal, android.service.autofill.FillCallback);
    method public void onFillRequest(android.app.assist.AssistStructure, android.os.Bundle, int, android.os.CancellationSignal, android.service.autofill.FillCallback);
    method public abstract void onSaveRequest(android.app.assist.AssistStructure, android.os.Bundle, android.service.autofill.SaveCallback);
    field public static final java.lang.String SERVICE_INTERFACE = "android.service.autofill.AutofillService";
    field public static final java.lang.String SERVICE_META_DATA = "android.autofill";
@@ -48883,7 +48884,7 @@ package android.view {
    method public void setActivated(boolean);
    method public void setAlpha(float);
    method public void setAnimation(android.view.animation.Animation);
    method public void setAutofillHint(java.lang.String[]);
    method public void setAutofillHint(java.lang.String...);
    method public void setAutofillMode(int);
    method public void setBackground(android.graphics.drawable.Drawable);
    method public void setBackgroundColor(int);
@@ -50969,6 +50970,7 @@ package android.view.autofill {
  public final class AutofillManager {
    method public void cancel();
    method public void commit();
    method public boolean isEnabled();
    method public void notifyValueChanged(android.view.View);
    method public void notifyViewEntered(android.view.View);
    method public void notifyViewExited(android.view.View);
@@ -50976,9 +50978,12 @@ package android.view.autofill {
    method public void notifyVirtualViewEntered(android.view.View, int, android.graphics.Rect);
    method public void notifyVirtualViewExited(android.view.View, int);
    method public void registerCallback(android.view.autofill.AutofillManager.AutofillCallback);
    method public void requestAutofill(android.view.View);
    method public void requestAutofill(android.view.View, int, android.graphics.Rect);
    method public void unregisterCallback(android.view.autofill.AutofillManager.AutofillCallback);
    field public static final java.lang.String EXTRA_ASSIST_STRUCTURE = "android.view.autofill.extra.ASSIST_STRUCTURE";
    field public static final java.lang.String EXTRA_AUTHENTICATION_RESULT = "android.view.autofill.extra.AUTHENTICATION_RESULT";
    field public static final int FLAG_MANUAL_REQUEST = 1; // 0x1
  }
  public static abstract class AutofillManager.AutofillCallback {
+7 −2
Original line number Diff line number Diff line
@@ -1790,6 +1790,7 @@ package android {
    field public static final int accessibilityActionSetProgress = 16908349; // 0x102003d
    field public static final int accessibilityActionShowOnScreen = 16908342; // 0x1020036
    field public static final int addToDictionary = 16908330; // 0x102002a
    field public static final int autofill = 16908355; // 0x1020043
    field public static final int background = 16908288; // 0x1020000
    field public static final int button1 = 16908313; // 0x1020019
    field public static final int button2 = 16908314; // 0x102001a
@@ -36886,7 +36887,7 @@ package android.service.autofill {
    method public final android.os.IBinder onBind(android.content.Intent);
    method public void onConnected();
    method public void onDisconnected();
    method public abstract void onFillRequest(android.app.assist.AssistStructure, android.os.Bundle, android.os.CancellationSignal, android.service.autofill.FillCallback);
    method public void onFillRequest(android.app.assist.AssistStructure, android.os.Bundle, int, android.os.CancellationSignal, android.service.autofill.FillCallback);
    method public abstract void onSaveRequest(android.app.assist.AssistStructure, android.os.Bundle, android.service.autofill.SaveCallback);
    field public static final java.lang.String SERVICE_INTERFACE = "android.service.autofill.AutofillService";
    field public static final java.lang.String SERVICE_META_DATA = "android.autofill";
@@ -45787,7 +45788,7 @@ package android.view {
    method public void setActivated(boolean);
    method public void setAlpha(float);
    method public void setAnimation(android.view.animation.Animation);
    method public void setAutofillHint(java.lang.String[]);
    method public void setAutofillHint(java.lang.String...);
    method public void setAutofillMode(int);
    method public void setBackground(android.graphics.drawable.Drawable);
    method public void setBackgroundColor(int);
@@ -47876,6 +47877,7 @@ package android.view.autofill {
  public final class AutofillManager {
    method public void cancel();
    method public void commit();
    method public boolean isEnabled();
    method public void notifyValueChanged(android.view.View);
    method public void notifyViewEntered(android.view.View);
    method public void notifyViewExited(android.view.View);
@@ -47883,9 +47885,12 @@ package android.view.autofill {
    method public void notifyVirtualViewEntered(android.view.View, int, android.graphics.Rect);
    method public void notifyVirtualViewExited(android.view.View, int);
    method public void registerCallback(android.view.autofill.AutofillManager.AutofillCallback);
    method public void requestAutofill(android.view.View);
    method public void requestAutofill(android.view.View, int, android.graphics.Rect);
    method public void unregisterCallback(android.view.autofill.AutofillManager.AutofillCallback);
    field public static final java.lang.String EXTRA_ASSIST_STRUCTURE = "android.view.autofill.extra.ASSIST_STRUCTURE";
    field public static final java.lang.String EXTRA_AUTHENTICATION_RESULT = "android.view.autofill.extra.AUTHENTICATION_RESULT";
    field public static final int FLAG_MANUAL_REQUEST = 1; // 0x1
  }
  public static abstract class AutofillManager.AutofillCallback {
+21 −5
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.os.IBinder;
import android.os.ICancellationSignal;
import android.os.Looper;
import android.util.Log;
import android.view.autofill.AutofillManager;

import com.android.internal.os.SomeArgs;

@@ -90,6 +91,8 @@ public abstract class AutofillService extends Service {
    private static final int MSG_ON_FILL_REQUEST = 3;
    private static final int MSG_ON_SAVE_REQUEST = 4;

    private static final int UNUSED_ARG = -1;

    private final IAutoFillService mInterface = new IAutoFillService.Stub() {
        @Override
        public void onInit(IAutoFillServiceConnection connection) {
@@ -102,14 +105,14 @@ public abstract class AutofillService extends Service {

        @Override
        public void onFillRequest(AssistStructure structure, Bundle extras,
                IFillCallback callback) {
                IFillCallback callback, int flags) {
            ICancellationSignal transport = CancellationSignal.createTransport();
            try {
                callback.onCancellable(transport);
            } catch (RemoteException e) {
                e.rethrowFromSystemServer();
            }
            mHandlerCaller.obtainMessageOOOO(MSG_ON_FILL_REQUEST, structure,
            mHandlerCaller.obtainMessageIIOOOO(MSG_ON_FILL_REQUEST, flags, UNUSED_ARG, structure,
                    CancellationSignal.fromTransport(transport), extras, callback)
                    .sendToTarget();
        }
@@ -135,8 +138,9 @@ public abstract class AutofillService extends Service {
                final Bundle extras = (Bundle) args.arg3;
                final IFillCallback callback = (IFillCallback) args.arg4;
                final FillCallback fillCallback = new FillCallback(callback);
                final int flags = msg.arg1;
                args.recycle();
                onFillRequest(structure, extras, cancellation, fillCallback);
                onFillRequest(structure, extras, flags, cancellation, fillCallback);
                break;
            } case MSG_ON_SAVE_REQUEST: {
                final SomeArgs args = (SomeArgs) msg.obj;
@@ -188,7 +192,6 @@ public abstract class AutofillService extends Service {
     * <p>You should generally do initialization here rather than in {@link #onCreate}.
     */
    public void onConnected() {
        //TODO(b/33197203): is not called anymore, fix it!
    }

    /**
@@ -206,11 +209,25 @@ public abstract class AutofillService extends Service {
     *     as well as when filling different sections of the UI as the system will try to
     *     aggressively unbind from the service to conserve resources. See {@link
     *     FillResponse} Javadoc for examples of multiple-sections requests.
     * @param flags either {@code 0} or {@link AutofillManager#FLAG_MANUAL_REQUEST}.
     * @param cancellationSignal signal for observing cancellation requests. The system will use
     *     this to notify you that the fill result is no longer needed and you should stop
     *     handling this fill request in order to save resources.
     * @param callback object used to notify the result of the request.
     */
    public void onFillRequest(@NonNull AssistStructure structure, @Nullable Bundle data, int flags,
            @NonNull CancellationSignal cancellationSignal, @NonNull FillCallback callback) {
        //TODO(b/33197203): make non-abstract once older method is removed
        onFillRequest(structure, data, cancellationSignal, callback);
    }

    /**
     * @hide
     * @deprecated - use {@link #onFillRequest(AssistStructure, Bundle, int,
     * CancellationSignal, FillCallback)} instead
     */
    //TODO(b/33197203): remove once clients are not using anymore
    @Deprecated
    public abstract void onFillRequest(@NonNull AssistStructure structure, @Nullable Bundle data,
            @NonNull CancellationSignal cancellationSignal, @NonNull FillCallback callback);

@@ -238,7 +255,6 @@ public abstract class AutofillService extends Service {
     * <p> At this point this service may no longer be an active {@link AutofillService}.
     */
    public void onDisconnected() {
        //TODO(b/33197203): is not called anymore, fix it!
    }

    /**
+2 −2
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ public final class FillCallback {
    /**
     * Notifies the Android System that an
     * {@link AutofillService#onFillRequest(android.app.assist.AssistStructure, Bundle,
     * android.os.CancellationSignal, FillCallback)} was successfully fulfilled by the service.
     * int, android.os.CancellationSignal, FillCallback)} was successfully fulfilled by the service.
     *
     * @param response autofill information for that activity, or {@code null} when the activity
     * cannot be autofilled (for example, if it only contains read-only fields). See
@@ -56,7 +56,7 @@ public final class FillCallback {
    /**
     * Notifies the Android System that an
     * {@link AutofillService#onFillRequest(android.app.assist.AssistStructure,
     * Bundle, android.os.CancellationSignal, FillCallback)}
     * Bundle, int, android.os.CancellationSignal, FillCallback)}
     * could not be fulfilled by the service.
     *
     * @param message error message to be displayed to the user.
Loading