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

Commit c28711c5 authored by Felipe Leme's avatar Felipe Leme Committed by Winson Chung
Browse files

Refactored ServiceNameResolver to take userId.

This object is used to bind to the AbstractRemoteInstance and was initially used by
AbstractPerUserSystemService, as the concrete implementations (for Autofill and ContentCapture)
were binding when sessions were created.

But we also need to support binding when the service is created, which was not possible using this
approach; instead, we need to make this object to take the userId on each call, and move it to the
AbstractMasterSystemService.

This change also removed the shared lock from FrameworkResourcesServiceNameResolver.

Bug: 117779333
Test: atest CtsContentCaptureServiceTestCases CtsAutoFillServiceTestCases

Change-Id: I097c226c9b00ddf7827e4f2f99d0adba978f29a2
parent 0d4da83e
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -74,6 +74,7 @@ import com.android.server.FgThread;
import com.android.server.LocalServices;
import com.android.server.autofill.ui.AutoFillUI;
import com.android.server.infra.AbstractMasterSystemService;
import com.android.server.infra.SecureSettingsServiceNameResolver;

import java.io.FileDescriptor;
import java.io.PrintWriter;
@@ -182,7 +183,9 @@ public final class AutofillManagerService
    private int mSupportedSmartSuggestionModes;

    public AutofillManagerService(Context context) {
        super(context, UserManager.DISALLOW_AUTOFILL);
        super(context,
                new SecureSettingsServiceNameResolver(context, Settings.Secure.AUTOFILL_SERVICE),
                UserManager.DISALLOW_AUTOFILL);
        mUi = new AutoFillUI(ActivityThread.currentActivityThread().getSystemUiContext());
        mAm = LocalServices.getService(ActivityManagerInternal.class);

@@ -523,7 +526,7 @@ public final class AutofillManagerService
        synchronized (mLock) {
            final AutofillManagerServiceImpl service = getServiceForUserLocked(userId);
            if (service != null) {
                service.mAugmentedAutofillResolver.setTemporaryServiceLocked(serviceName,
                service.mAugmentedAutofillResolver.setTemporaryService(userId, serviceName,
                        durationMs);
            }
        }
@@ -535,7 +538,7 @@ public final class AutofillManagerService
        synchronized (mLock) {
            final AutofillManagerServiceImpl service = getServiceForUserLocked(userId);
            if (service != null) {
                service.mAugmentedAutofillResolver.resetTemporaryServiceLocked();
                service.mAugmentedAutofillResolver.resetTemporaryService(userId);
            }
        }
    }
+7 −9
Original line number Diff line number Diff line
@@ -77,7 +77,6 @@ import com.android.server.autofill.RemoteAugmentedAutofillService.RemoteAugmente
import com.android.server.autofill.ui.AutoFillUI;
import com.android.server.infra.AbstractPerUserSystemService;
import com.android.server.infra.FrameworkResourcesServiceNameResolver;
import com.android.server.infra.SecureSettingsServiceNameResolver;

import java.io.PrintWriter;
import java.util.ArrayList;
@@ -170,8 +169,7 @@ final class AutofillManagerServiceImpl
    AutofillManagerServiceImpl(AutofillManagerService master, Object lock, LocalLog requestsHistory,
            LocalLog uiLatencyHistory, LocalLog wtfHistory, int userId, AutoFillUI ui,
            AutofillCompatState autofillCompatState, boolean disabled) {
        super(master, new SecureSettingsServiceNameResolver(master.getContext(), userId,
                Settings.Secure.AUTOFILL_SERVICE), lock, userId);
        super(master, lock, userId);

        mRequestsHistory = requestsHistory;
        mUiLatencyHistory = uiLatencyHistory;
@@ -181,9 +179,9 @@ final class AutofillManagerServiceImpl
        mAutofillCompatState = autofillCompatState;

        mAugmentedAutofillResolver = new FrameworkResourcesServiceNameResolver(master.getContext(),
                userId, lock, com.android.internal.R.string.config_defaultAugmentedAutofillService);
                com.android.internal.R.string.config_defaultAugmentedAutofillService);
        mAugmentedAutofillResolver.setOnTemporaryServiceNameChangedCallback(
                () -> updateRemoteAugmentedAutofillService());
                (u, s) -> updateRemoteAugmentedAutofillService());

        updateLocked(disabled);
    }
@@ -873,7 +871,7 @@ final class AutofillManagerServiceImpl
        pw.print(prefix); pw.print("Default component: "); pw.println(getContext()
                .getString(R.string.config_defaultAutofillService));
        pw.print(prefix); pw.print("mAugmentedAutofillNamer: ");
        mAugmentedAutofillResolver.dumpShortLocked(pw); pw.println();
        mAugmentedAutofillResolver.dumpShort(pw); pw.println();
        if (mRemoteAugmentedAutofillService != null) {
            pw.print(prefix); pw.println("RemoteAugmentedAutofillService: ");
            mRemoteAugmentedAutofillService.dump(prefix2, pw);
@@ -1022,7 +1020,7 @@ final class AutofillManagerServiceImpl
    @GuardedBy("mLock")
    @Nullable RemoteAugmentedAutofillService getRemoteAugmentedAutofillServiceLocked() {
        if (mRemoteAugmentedAutofillService == null) {
            final String serviceName = mAugmentedAutofillResolver.getServiceNameLocked();
            final String serviceName = mAugmentedAutofillResolver.getServiceName(mUserId);
            if (serviceName == null) {
                if (mMaster.verbose) {
                    Slog.v(TAG, "getRemoteAugmentedAutofillServiceLocked(): not set");
@@ -1030,7 +1028,7 @@ final class AutofillManagerServiceImpl
                return null;
            }
            final ComponentName componentName = RemoteAugmentedAutofillService.getComponentName(
                    serviceName, mUserId, mAugmentedAutofillResolver.isTemporaryLocked());
                    serviceName, mUserId, mAugmentedAutofillResolver.isTemporary(mUserId));
            if (componentName == null) return null;
            if (sVerbose) {
                Slog.v(TAG, "getRemoteAugmentedAutofillServiceLocked(): " + componentName);
@@ -1053,7 +1051,7 @@ final class AutofillManagerServiceImpl
     * Called when the {@link #mAugmentedAutofillResolver} changed (among other places).
     */
    private void updateRemoteAugmentedAutofillService() {
        final String serviceName = mAugmentedAutofillResolver.getServiceNameLocked();
        final String serviceName = mAugmentedAutofillResolver.getServiceName(mUserId);
        if (serviceName == null) {
            if (sVerbose) Slog.v(TAG, "updateRemoteAugmentedAutofillService(): time's up!");
            if (mRemoteAugmentedAutofillService != null) {
+5 −2
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import com.android.internal.util.DumpUtils;
import com.android.internal.util.Preconditions;
import com.android.server.LocalServices;
import com.android.server.infra.AbstractMasterSystemService;
import com.android.server.infra.FrameworkResourcesServiceNameResolver;

import java.io.FileDescriptor;
import java.io.PrintWriter;
@@ -66,8 +67,10 @@ public final class ContentCaptureManagerService extends

    private final LocalService mLocalService = new LocalService();

    public ContentCaptureManagerService(Context context) {
        super(context, UserManager.DISALLOW_CONTENT_CAPTURE);
    public ContentCaptureManagerService(@NonNull Context context) {
        super(context, new FrameworkResourcesServiceNameResolver(context,
                com.android.internal.R.string.config_defaultContentCaptureService),
                UserManager.DISALLOW_CONTENT_CAPTURE);
    }

    @Override // from AbstractMasterSystemService
+1 −3
Original line number Diff line number Diff line
@@ -43,7 +43,6 @@ import android.view.contentcapture.ContentCaptureSession;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.os.IResultReceiver;
import com.android.server.infra.AbstractPerUserSystemService;
import com.android.server.infra.FrameworkResourcesServiceNameResolver;

import java.io.PrintWriter;
import java.util.ArrayList;
@@ -65,8 +64,7 @@ final class ContentCapturePerUserService

    protected ContentCapturePerUserService(
            ContentCaptureManagerService master, Object lock, @UserIdInt int userId) {
        super(master, new FrameworkResourcesServiceNameResolver(master.getContext(), userId, lock,
                com.android.internal.R.string.config_defaultContentCaptureService), lock, userId);
        super(master, lock, userId);
    }

    @Override // from PerUserSystemService
+24 −0
Original line number Diff line number Diff line
@@ -85,14 +85,23 @@ public abstract class AbstractMasterSystemService<M extends AbstractMasterSystem
     */
    protected final Object mLock = new Object();

    /**
     * Object used to define the name of the service component used to create
     * {@link com.android.internal.infra.AbstractRemoteService} instances.
     */
    @Nullable
    protected final ServiceNameResolver mServiceNameResolver;

    /**
     * Whether the service should log debug statements.
     */
    //TODO(b/117779333): consider using constants for these guards
    public boolean verbose = false;

    /**
     * Whether the service should log verbose statements.
     */
    //TODO(b/117779333): consider using constants for these guards
    public boolean debug = false;

    /**
@@ -119,13 +128,24 @@ public abstract class AbstractMasterSystemService<M extends AbstractMasterSystem
     * Default constructor.
     *
     * @param context system context.
     * @param serviceNameResolver resolver for
     * {@link com.android.internal.infra.AbstractRemoteService} instances, or
     * {@code null} when the service doesn't bind to remote services.
     * @param disallowProperty when not {@code null}, defines a {@link UserManager} restriction that
     *        disables the service.
     */
    protected AbstractMasterSystemService(@NonNull Context context,
            @Nullable ServiceNameResolver serviceNameResolver,
            @Nullable String disallowProperty) {
        super(context);

        mServiceNameResolver = serviceNameResolver;
        if (mServiceNameResolver != null) {
            mServiceNameResolver
                    .setOnTemporaryServiceNameChangedCallback(
                            (u, s) -> updateCachedServiceLocked(u));

        }
        if (disallowProperty == null) {
            mDisabledUsers = null;
        } else {
@@ -471,6 +491,10 @@ public abstract class AbstractMasterSystemService<M extends AbstractMasterSystem
            final int size = mServicesCache.size();
            pw.print(prefix); pw.print("Debug: "); pw.print(realDebug);
            pw.print(" Verbose: "); pw.println(realVerbose);
            if (mServiceNameResolver != null) {
                pw.print(prefix); pw.print("Name resolver: ");
                mServiceNameResolver.dumpShort(pw); pw.println();
            }
            pw.print(prefix); pw.print("Disabled users: "); pw.println(mDisabledUsers);
            pw.print(prefix); pw.print("Allow instant service: "); pw.println(mAllowInstantService);
            final String settingsProperty = getServiceSettingsProperty();
Loading