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

Commit b55cd8ec authored by Felipe Leme's avatar Felipe Leme
Browse files

Added support to run autofill service from instant apps.

Bug: 79422318
Test: m -j CtsAutoFillServiceTestCases && \
      cts-tradefed run commandAndExit cts-instant-dev \
      -m CtsAutoFillServiceTestCases
Test: cts-tradefed run commandAndExit cts-dev -m CtsAutoFillServiceTestCases

Change-Id: I1e885fe7edcbc0ace3a0f60abacb9cea9b6c03e7
parent 8003f88b
Loading
Loading
Loading
Loading
+23 −1
Original line number Diff line number Diff line
@@ -157,6 +157,9 @@ public final class AutofillManagerService extends SystemService {
        }
    };

    @GuardedBy("mLock")
    private boolean mAllowInstantService;

    public AutofillManagerService(Context context) {
        super(context);
        mContext = context;
@@ -518,6 +521,23 @@ public final class AutofillManagerService extends SystemService {
        sFullScreenMode = mode;
    }

    // Called by Shell command.
    boolean getAllowInstantService() {
        mContext.enforceCallingPermission(MANAGE_AUTO_FILL, TAG);
        synchronized (mLock) {
            return mAllowInstantService;
        }
    }

    // Called by Shell command.
    void setAllowInstantService(boolean mode) {
        mContext.enforceCallingPermission(MANAGE_AUTO_FILL, TAG);
        Slog.i(TAG, "setAllowInstantService(): " + mode);
        synchronized (mLock) {
            mAllowInstantService = mode;
        }
    }

    private void setDebugLocked(boolean debug) {
        com.android.server.autofill.Helper.sDebug = debug;
        android.view.autofill.Helper.sDebug = debug;
@@ -866,7 +886,8 @@ public final class AutofillManagerService extends SystemService {
            synchronized (mLock) {
                final AutofillManagerServiceImpl service = getServiceForUserLocked(userId);
                return service.startSessionLocked(activityToken, getCallingUid(), appCallback,
                        autofillId, bounds, value, hasCallback, flags, componentName, compatMode);
                        autofillId, bounds, value, hasCallback, componentName, compatMode,
                        mAllowInstantService, flags);
            }
        }

@@ -1202,6 +1223,7 @@ public final class AutofillManagerService extends SystemService {
                    mAutofillCompatState.dump(prefix2, pw);
                    pw.print(prefix2); pw.print("from settings: ");
                    pw.println(getWhitelistedCompatModePackagesFromSettings());
                    pw.print("Allow instant service: "); pw.println(mAllowInstantService);
                }
                if (showHistory) {
                    pw.println(); pw.println("Requests history:"); pw.println();
+6 −4
Original line number Diff line number Diff line
@@ -342,7 +342,8 @@ final class AutofillManagerServiceImpl {
    int startSessionLocked(@NonNull IBinder activityToken, int uid,
            @NonNull IBinder appCallbackToken, @NonNull AutofillId autofillId,
            @NonNull Rect virtualBounds, @Nullable AutofillValue value, boolean hasCallback,
            int flags, @NonNull ComponentName componentName, boolean compatMode) {
            @NonNull ComponentName componentName, boolean compatMode,
            boolean bindInstantServiceAllowed, int flags) {
        if (!isEnabledLocked()) {
            return 0;
        }
@@ -372,7 +373,7 @@ final class AutofillManagerServiceImpl {
        pruneAbandonedSessionsLocked();

        final Session newSession = createSessionByTokenLocked(activityToken, uid, appCallbackToken,
                hasCallback, componentName, compatMode, flags);
                hasCallback, componentName, compatMode, bindInstantServiceAllowed, flags);
        if (newSession == null) {
            return NO_SESSION;
        }
@@ -491,7 +492,8 @@ final class AutofillManagerServiceImpl {
    @GuardedBy("mLock")
    private Session createSessionByTokenLocked(@NonNull IBinder activityToken, int uid,
            @NonNull IBinder appCallbackToken, boolean hasCallback,
            @NonNull ComponentName componentName, boolean compatMode, int flags) {
            @NonNull ComponentName componentName, boolean compatMode,
            boolean bindInstantServiceAllowed, int flags) {
        // use random ids so that one app cannot know that another app creates sessions
        int sessionId;
        int tries = 0;
@@ -510,7 +512,7 @@ final class AutofillManagerServiceImpl {
        final Session newSession = new Session(this, mUi, mContext, mHandler, mUserId, mLock,
                sessionId, uid, activityToken, appCallbackToken, hasCallback, mUiLatencyHistory,
                mWtfHistory, mInfo.getServiceInfo().getComponentName(), componentName, compatMode,
                flags);
                bindInstantServiceAllowed, flags);
        mSessions.put(newSession.id, newSession);

        return newSession;
+34 −0
Original line number Diff line number Diff line
@@ -86,6 +86,9 @@ public final class AutofillManagerServiceShellCommand extends ShellCommand {
            pw.println("  get fc_score [--algorithm ALGORITHM] value1 value2");
            pw.println("    Gets the field classification score for 2 fields.");
            pw.println("");
            pw.println("  get bind-instant-service-allowed");
            pw.println("    Gets whether binding to services provided by instant apps is allowed");
            pw.println("");
            pw.println("  set log_level [off | debug | verbose]");
            pw.println("    Sets the Autofill log level.");
            pw.println("");
@@ -98,6 +101,9 @@ public final class AutofillManagerServiceShellCommand extends ShellCommand {
            pw.println("  set full_screen_mode [true | false | default]");
            pw.println("    Sets the Fill UI full screen mode");
            pw.println("");
            pw.println("  set bind-instant-service-allowed [true | false]");
            pw.println("    Sets whether binding to services provided by instant apps is allowed");
            pw.println("");
            pw.println("  list sessions [--user USER_ID]");
            pw.println("    Lists all pending sessions.");
            pw.println("");
@@ -123,6 +129,8 @@ public final class AutofillManagerServiceShellCommand extends ShellCommand {
                return getFieldClassificationScore(pw);
            case "full_screen_mode":
                return getFullScreenMode(pw);
            case "bind-instant-service-allowed":
                return getBindInstantService(pw);
            default:
                pw.println("Invalid set: " + what);
                return -1;
@@ -141,6 +149,8 @@ public final class AutofillManagerServiceShellCommand extends ShellCommand {
                return setMaxVisibileDatasets();
            case "full_screen_mode":
                return setFullScreenMode(pw);
            case "bind-instant-service-allowed":
                return setBindInstantService(pw);
            default:
                pw.println("Invalid set: " + what);
                return -1;
@@ -259,6 +269,30 @@ public final class AutofillManagerServiceShellCommand extends ShellCommand {
        }
    }

    private int getBindInstantService(PrintWriter pw) {
        if (mService.getAllowInstantService()) {
            pw.println("true");
        } else {
            pw.println("false");
        }
        return 0;
    }

    private int setBindInstantService(PrintWriter pw) {
        final String mode = getNextArgRequired();
        switch (mode.toLowerCase()) {
            case "true":
                mService.setAllowInstantService(true);
                return 0;
            case "false":
                mService.setAllowInstantService(false);
                return 0;
            default:
                pw.println("Invalid mode: " + mode);
                return -1;
        }
    }

    private int requestDestroy(PrintWriter pw) {
        if (!isNextArgSessions(pw)) {
            return -1;
+0 −4
Original line number Diff line number Diff line
@@ -15,8 +15,6 @@
 */
package com.android.server.autofill;

import static android.view.autofill.AutofillManager.FC_SERVICE_TIMEOUT;

import static com.android.server.autofill.Helper.sDebug;
import static com.android.server.autofill.Helper.sVerbose;
import static android.service.autofill.AutofillFieldClassificationService.SERVICE_META_DATA_KEY_AVAILABLE_ALGORITHMS;
@@ -52,8 +50,6 @@ import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

/**
 * Strategy used to bridge the field classification algorithms provided by a service in an external
+3 −0
Original line number Diff line number Diff line
@@ -68,6 +68,9 @@ public final class Helper {

    /**
     * When non-null, overrides whether the UI should be shown on full-screen mode.
     *
     * <p>Note: access to this variable is not synchronized because it's "final" on real usage -
     * it's only set by Shell cmd, for development purposes.
     */
    public static Boolean sFullScreenMode = null;

Loading