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

Commit b5857c74 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Initial implementation of Intelligence Service Shell commands."

parents b03bf399 5933efbd
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -108,6 +108,7 @@ package android {
    field public static final java.lang.String MANAGE_DEVICE_ADMINS = "android.permission.MANAGE_DEVICE_ADMINS";
    field public static final java.lang.String MANAGE_IPSEC_TUNNELS = "android.permission.MANAGE_IPSEC_TUNNELS";
    field public static final java.lang.String MANAGE_ROLE_HOLDERS = "android.permission.MANAGE_ROLE_HOLDERS";
    field public static final java.lang.String MANAGE_SMART_SUGGESTIONS = "android.permission.MANAGE_SMART_SUGGESTIONS";
    field public static final java.lang.String MANAGE_SOUND_TRIGGER = "android.permission.MANAGE_SOUND_TRIGGER";
    field public static final java.lang.String MANAGE_SUBSCRIPTION_PLANS = "android.permission.MANAGE_SUBSCRIPTION_PLANS";
    field public static final java.lang.String MANAGE_USB = "android.permission.MANAGE_USB";
+5 −0
Original line number Diff line number Diff line
@@ -4170,6 +4170,11 @@
    <permission android:name="android.permission.MANAGE_AUTO_FILL"
        android:protectionLevel="signature" />

    <!-- @SystemApi Allows an application to manage the smart suggestions service.
         @hide  <p>Not for use by third-party applications.</p> -->
    <permission android:name="android.permission.MANAGE_SMART_SUGGESTIONS"
        android:protectionLevel="signature" />

    <!-- Allows an app to set the theme overlay in /vendor/overlay
         being used.
         @hide  <p>Not for use by third-party applications.</p> -->
+1 −0
Original line number Diff line number Diff line
@@ -130,6 +130,7 @@
    <uses-permission android:name="android.permission.CONNECTIVITY_INTERNAL" />
    <uses-permission android:name="android.permission.CHANGE_COMPONENT_ENABLED_STATE" />
    <uses-permission android:name="android.permission.MANAGE_AUTO_FILL" />
    <uses-permission android:name="android.permission.MANAGE_SMART_SUGGESTIONS" />
    <uses-permission android:name="android.permission.NETWORK_SETTINGS" />
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
    <uses-permission android:name="android.permission.SET_TIME" />
+17 −34
Original line number Diff line number Diff line
@@ -175,10 +175,6 @@ public final class AutofillManagerService
        }
    };

    // TODO(b/117779333): move to superclass / create super-class for ShellCommand
    @GuardedBy("mLock")
    private boolean mAllowInstantService;

    /**
     * Supported modes for Augmented Autofill Smart Suggestions.
     */
@@ -271,6 +267,11 @@ public final class AutofillManagerService
        addCompatibilityModeRequestsLocked(service, userId);
    }

    @Override // from AbstractMasterSystemService
    protected void enforceCallingPermissionForManagement() {
        getContext().enforceCallingPermission(MANAGE_AUTO_FILL, TAG);
    }

    @Override // from SystemService
    public void onStart() {
        publishBinderService(AUTOFILL_MANAGER_SERVICE, new AutoFillManagerServiceStub());
@@ -290,7 +291,7 @@ public final class AutofillManagerService
    // Called by Shell command.
    void destroySessions(@UserIdInt int userId, IResultReceiver receiver) {
        Slog.i(TAG, "destroySessions() for userId " + userId);
        getContext().enforceCallingPermission(MANAGE_AUTO_FILL, TAG);
        enforceCallingPermissionForManagement();

        synchronized (mLock) {
            if (userId != UserHandle.USER_ALL) {
@@ -313,7 +314,7 @@ public final class AutofillManagerService
    // Called by Shell command.
    void listSessions(int userId, IResultReceiver receiver) {
        Slog.i(TAG, "listSessions() for userId " + userId);
        getContext().enforceCallingPermission(MANAGE_AUTO_FILL, TAG);
        enforceCallingPermissionForManagement();

        final Bundle resultData = new Bundle();
        final ArrayList<String> sessions = new ArrayList<>();
@@ -340,7 +341,7 @@ public final class AutofillManagerService
    // Called by Shell command.
    void reset() {
        Slog.i(TAG, "reset()");
        getContext().enforceCallingPermission(MANAGE_AUTO_FILL, TAG);
        enforceCallingPermissionForManagement();

        synchronized (mLock) {
            visitServicesLocked((s) -> s.destroyLocked());
@@ -351,7 +352,7 @@ public final class AutofillManagerService
    // Called by Shell command.
    void setLogLevel(int level) {
        Slog.i(TAG, "setLogLevel(): " + level);
        getContext().enforceCallingPermission(MANAGE_AUTO_FILL, TAG);
        enforceCallingPermissionForManagement();

        final long token = Binder.clearCallingIdentity();
        try {
@@ -388,7 +389,7 @@ public final class AutofillManagerService

    // Called by Shell command.
    int getLogLevel() {
        getContext().enforceCallingPermission(MANAGE_AUTO_FILL, TAG);
        enforceCallingPermissionForManagement();

        synchronized (mLock) {
            if (sVerbose) return AutofillManager.FLAG_ADD_CLIENT_VERBOSE;
@@ -399,7 +400,7 @@ public final class AutofillManagerService

    // Called by Shell command.
    int getMaxPartitions() {
        getContext().enforceCallingPermission(MANAGE_AUTO_FILL, TAG);
        enforceCallingPermissionForManagement();

        synchronized (mLock) {
            return sPartitionMaxCount;
@@ -408,8 +409,8 @@ public final class AutofillManagerService

    // Called by Shell command.
    void setMaxPartitions(int max) {
        getContext().enforceCallingPermission(MANAGE_AUTO_FILL, TAG);
        Slog.i(TAG, "setMaxPartitions(): " + max);
        enforceCallingPermissionForManagement();

        final long token = Binder.clearCallingIdentity();
        try {
@@ -433,7 +434,7 @@ public final class AutofillManagerService

    // Called by Shell command.
    int getMaxVisibleDatasets() {
        getContext().enforceCallingPermission(MANAGE_AUTO_FILL, TAG);
        enforceCallingPermissionForManagement();

        synchronized (sLock) {
            return sVisibleDatasetsMaxCount;
@@ -442,8 +443,8 @@ public final class AutofillManagerService

    // Called by Shell command.
    void setMaxVisibleDatasets(int max) {
        getContext().enforceCallingPermission(MANAGE_AUTO_FILL, TAG);
        Slog.i(TAG, "setMaxVisibleDatasets(): " + max);
        enforceCallingPermissionForManagement();

        final long token = Binder.clearCallingIdentity();
        try {
@@ -480,7 +481,7 @@ public final class AutofillManagerService
    // Called by Shell command.
    void getScore(@Nullable String algorithmName, @NonNull String value1,
            @NonNull String value2, @NonNull RemoteCallback callback) {
        getContext().enforceCallingPermission(MANAGE_AUTO_FILL, TAG);
        enforceCallingPermissionForManagement();

        final FieldClassificationStrategy strategy =
                new FieldClassificationStrategy(getContext(), UserHandle.USER_CURRENT);
@@ -491,33 +492,16 @@ public final class AutofillManagerService

    // Called by Shell command.
    Boolean getFullScreenMode() {
        getContext().enforceCallingPermission(MANAGE_AUTO_FILL, TAG);
        enforceCallingPermissionForManagement();
        return sFullScreenMode;
    }

    // Called by Shell command.
    void setFullScreenMode(@Nullable Boolean mode) {
        getContext().enforceCallingPermission(MANAGE_AUTO_FILL, TAG);
        enforceCallingPermissionForManagement();
        sFullScreenMode = mode;
    }

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

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

    private void setLoggingLevelsLocked(boolean debug, boolean verbose) {
        com.android.server.autofill.Helper.sDebug = debug;
        android.view.autofill.Helper.sDebug = debug;
@@ -1218,7 +1202,6 @@ public final class AutofillManagerService
                    mAutofillCompatState.dump(prefix, pw);
                    pw.print("from settings: ");
                    pw.println(getWhitelistedCompatModePackagesFromSettings());
                    pw.print("Allow instant service: "); pw.println(mAllowInstantService);
                    if (mSupportedSmartSuggestionModes != 0) {
                        pw.print("Smart Suggestion modes: ");
                        pw.println(smartSuggestionFlagsToString(mSupportedSmartSuggestionModes));
+48 −0
Original line number Diff line number Diff line
@@ -92,6 +92,12 @@ public abstract class AbstractMasterSystemService<M extends AbstractMasterSystem
     */
    public boolean debug = false;

    /**
     * Whether the service is allowed to bind to an instant-app.
     */
    @GuardedBy("mLock")
    protected boolean mAllowInstantService;

    /**
     * Users disabled due to {@link UserManager} restrictions, or {@code null} if the service cannot
     * be disabled through {@link UserManager}.
@@ -175,6 +181,47 @@ public abstract class AbstractMasterSystemService<M extends AbstractMasterSystem
        }
    }

    /**
     * Gets whether the service is allowed to bind to an instant-app.
     *
     * <p>Typically called by {@code ShellCommand} during CTS tests.
     *
     * @throws SecurityException if caller is not allowed to manage this service's settings.
     */
    public final boolean getAllowInstantService() {
        enforceCallingPermissionForManagement();
        synchronized (mLock) {
            return mAllowInstantService;
        }
    }

    /**
     * Sets whether the service is allowed to bind to an instant-app.
     *
     * <p>Typically called by {@code ShellCommand} during CTS tests.
     *
     * @throws SecurityException if caller is not allowed to manage this service's settings.
     */
    public final void setAllowInstantService(boolean mode) {
        Slog.i(mTag, "setAllowInstantService(): " + mode);
        enforceCallingPermissionForManagement();
        synchronized (mLock) {
            mAllowInstantService = mode;
        }
    }

    /**
     * Asserts that the caller has permissions to manage this service.
     *
     * <p>Typically called by {@code ShellCommand} implementations.
     *
     * @throws UnsupportedOperationException if subclass doesn't override it.
     * @throws SecurityException if caller is not allowed to manage this service's settings.
     */
    protected void enforceCallingPermissionForManagement() {
        throw new UnsupportedOperationException("Not implemented by " + getClass());
    }

    /**
     * Creates a new service that will be added to the cache.
     *
@@ -362,6 +409,7 @@ public abstract class AbstractMasterSystemService<M extends AbstractMasterSystem
            pw.print(prefix); pw.print("Debug: "); pw.print(realDebug);
            pw.print(" Verbose: "); pw.println(realVerbose);
            pw.print(prefix); pw.print("Disabled users: "); pw.println(mDisabledUsers);
            pw.print(prefix); pw.print("Allow instant service: "); pw.println(mAllowInstantService);
            pw.print(prefix); pw.print("Settings property: "); pw.println(
                    getServiceSettingsProperty());
            pw.print(prefix); pw.print("Cached services: ");
Loading