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

Commit 51e29da6 authored by Felipe Leme's avatar Felipe Leme
Browse files

Improvements on autofill debugging.

- Sets the client-side sDebug and sVerbose in the application being autofilled
  before it was only set in the service's application
- Logs client class on AutofillManager - useful to detect cases where it's not
  an Activity.

Bug: 67742064
Test: cts-tradefed run commandAndExit cts-dev -m CtsAutoFillServiceTestCases
Test: manual verification of logs

Change-Id: I1f04b90bae89fd942e5849b4a382f1f54df20e38
parent 9cc350e9
Loading
Loading
Loading
Loading
+23 −6
Original line number Diff line number Diff line
@@ -1272,18 +1272,32 @@ public final class AutofillManager {
        }
    }

    private void setState(boolean enabled, boolean resetSession, boolean resetClient) {
    /** @hide */
    public static final int SET_STATE_FLAG_ENABLED = 0x01;
    /** @hide */
    public static final int SET_STATE_FLAG_RESET_SESSION = 0x02;
    /** @hide */
    public static final int SET_STATE_FLAG_RESET_CLIENT = 0x04;
    /** @hide */
    public static final int SET_STATE_FLAG_DEBUG = 0x08;
    /** @hide */
    public static final int SET_STATE_FLAG_VERBOSE = 0x10;

    private void setState(int flags) {
        if (sVerbose) Log.v(TAG, "setState(" + flags + ")");
        synchronized (mLock) {
            mEnabled = enabled;
            if (!mEnabled || resetSession) {
            mEnabled = (flags & SET_STATE_FLAG_ENABLED) != 0;
            if (!mEnabled || (flags & SET_STATE_FLAG_RESET_SESSION) != 0) {
                // Reset the session state
                resetSessionLocked();
            }
            if (resetClient) {
            if ((flags & SET_STATE_FLAG_RESET_CLIENT) != 0) {
                // Reset connection to system
                mServiceClient = null;
            }
        }
        sDebug = (flags & SET_STATE_FLAG_DEBUG) != 0;
        sVerbose = (flags & SET_STATE_FLAG_VERBOSE) != 0;
    }

    /**
@@ -1609,6 +1623,7 @@ public final class AutofillManager {
        pw.print(pfx); pw.print("sessionId: "); pw.println(mSessionId);
        pw.print(pfx); pw.print("state: "); pw.println(getStateAsStringLocked());
        pw.print(pfx); pw.print("context: "); pw.println(mContext);
        pw.print(pfx); pw.print("client: "); pw.println(getClientLocked());
        pw.print(pfx); pw.print("enabled: "); pw.println(mEnabled);
        pw.print(pfx); pw.print("hasService: "); pw.println(mService != null);
        pw.print(pfx); pw.print("hasCallback: "); pw.println(mCallback != null);
@@ -1625,6 +1640,8 @@ public final class AutofillManager {
        pw.print(pfx); pw.print("fillable ids: "); pw.println(mFillableIds);
        pw.print(pfx); pw.print("save trigger id: "); pw.println(mSaveTriggerId);
        pw.print(pfx); pw.print("save on finish(): "); pw.println(mSaveOnFinish);
        pw.print(pfx); pw.print("debug: "); pw.print(sDebug);
        pw.print(" verbose: "); pw.println(sVerbose);
    }

    private String getStateAsStringLocked() {
@@ -1940,10 +1957,10 @@ public final class AutofillManager {
        }

        @Override
        public void setState(boolean enabled, boolean resetSession, boolean resetClient) {
        public void setState(int flags) {
            final AutofillManager afm = mAfm.get();
            if (afm != null) {
                afm.post(() -> afm.setState(enabled, resetSession, resetClient));
                afm.post(() -> afm.setState(flags));
            }
        }

+1 −1
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@ oneway interface IAutoFillManagerClient {
    /**
     * Notifies the client when the autofill enabled state changed.
     */
    void setState(boolean enabled, boolean resetSession, boolean resetClient);
    void setState(int flags);

    /**
      * Autofills the activity with the contents of a dataset.
+0 −1
Original line number Diff line number Diff line
@@ -447,7 +447,6 @@ public final class AutofillManagerService extends SystemService {
        android.view.autofill.Helper.sDebug = debug;
    }


    private void setVerboseLocked(boolean verbose) {
        com.android.server.autofill.Helper.sVerbose = verbose;
        android.view.autofill.Helper.sVerbose = verbose;
+17 −1
Original line number Diff line number Diff line
@@ -813,7 +813,23 @@ final class AutofillManagerServiceImpl {
                    synchronized (mLock) {
                        resetSession = resetClient || isClientSessionDestroyedLocked(client);
                    }
                    client.setState(isEnabled(), resetSession, resetClient);
                    int flags = 0;
                    if (isEnabled()) {
                        flags |= AutofillManager.SET_STATE_FLAG_ENABLED;
                    }
                    if (resetSession) {
                        flags |= AutofillManager.SET_STATE_FLAG_RESET_SESSION;
                    }
                    if (resetClient) {
                        flags |= AutofillManager.SET_STATE_FLAG_RESET_CLIENT;
                    }
                    if (sDebug) {
                        flags |= AutofillManager.SET_STATE_FLAG_DEBUG;
                    }
                    if (sVerbose) {
                        flags |= AutofillManager.SET_STATE_FLAG_VERBOSE;
                    }
                    client.setState(flags);
                } catch (RemoteException re) {
                    /* ignore */
                }