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

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

Merge changes I43386a3f,I097c226c

* changes:
  Refactored ContentCaptureService (and infra) to have just one RemoteService.
  Refactored ServiceNameResolver to take userId.
parents 2232e861 50b33dce
Loading
Loading
Loading
Loading
+38 −6
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import android.os.RemoteException;
import android.os.SystemClock;
import android.os.UserHandle;
import android.util.Slog;
import android.util.TimeUtils;

import com.android.internal.annotations.GuardedBy;

@@ -64,6 +65,8 @@ public abstract class AbstractRemoteService<S extends AbstractRemoteService<S, I
        I extends IInterface> implements DeathRecipient {
    private static final int MSG_UNBIND = 1;

    protected static final long PERMANENT_BOUND_TIMEOUT_MS = 0;

    protected static final int LAST_PRIVATE_MSG = MSG_UNBIND;

    // TODO(b/117779333): convert all booleans into an integer / flags
@@ -86,6 +89,9 @@ public abstract class AbstractRemoteService<S extends AbstractRemoteService<S, I
    private boolean mServiceDied;
    private boolean mCompleted;

    // Used just for debugging purposes (on dump)
    private long mNextUnbind;

    /**
     * Callback called when the service dies.
     *
@@ -156,7 +162,9 @@ public abstract class AbstractRemoteService<S extends AbstractRemoteService<S, I
    protected abstract I getServiceInterface(@NonNull IBinder service);

    /**
     * Defines How long after the last interaction with the service we would unbind.
     * Defines how long after the last interaction with the service we would unbind.
     *
     * @return time to unbind (in millis), or {@link #PERMANENT_BOUND_TIMEOUT_MS} to not unbind.
     */
    protected abstract long getTimeoutIdleBindMillis();

@@ -220,11 +228,23 @@ public abstract class AbstractRemoteService<S extends AbstractRemoteService<S, I
                .append(mComponentName.flattenToString()).println();
        pw.append(prefix).append(tab).append("destroyed=")
                .append(String.valueOf(mDestroyed)).println();
        final boolean bound = handleIsBound();
        pw.append(prefix).append(tab).append("bound=")
                .append(String.valueOf(handleIsBound())).println();
                .append(String.valueOf(bound));
        final long idleTimeout = getTimeoutIdleBindMillis();
        if (bound) {
            if (idleTimeout > 0) {
                pw.append(" (unbind in : ");
                TimeUtils.formatDuration(mNextUnbind - SystemClock.elapsedRealtime(), pw);
                pw.append(")");
            } else {
                pw.append(" (permanently bound)");
            }
        }
        pw.println();
        pw.append(prefix).append("mBindInstantServiceAllowed=").println(mBindInstantServiceAllowed);
        pw.append(prefix).append("idleTimeout=")
            .append(Long.toString(getTimeoutIdleBindMillis() / 1000)).append("s").println();
            .append(Long.toString(idleTimeout / 1000)).append("s").println();
        pw.append(prefix).append("requestTimeout=")
            .append(Long.toString(getRemoteRequestMillis() / 1000)).append("s").println();
        pw.println();
@@ -236,6 +256,8 @@ public abstract class AbstractRemoteService<S extends AbstractRemoteService<S, I
     * <p>This request must be responded by the service somehow (typically using a callback),
     * othewise it will trigger a {@link PendingRequest#onTimeout(AbstractRemoteService)} if the
     * service doesn't respond.
     *
     * <p><b>NOTE: </b>this request is responsible for calling {@link #scheduleUnbind()}.
     */
    protected void scheduleRequest(@NonNull PendingRequest<S, I> pendingRequest) {
        cancelScheduledUnbind();
@@ -250,7 +272,7 @@ public abstract class AbstractRemoteService<S extends AbstractRemoteService<S, I
     * a simple {@link Runnable}.
     */
    protected void scheduleAsyncRequest(@NonNull AsyncRequest<I> request) {
        cancelScheduledUnbind();
        scheduleUnbind();
        // TODO(b/117779333): fix generics below
        @SuppressWarnings({"unchecked", "rawtypes"})
        final MyAsyncPendingRequest<S, I> asyncRequest = new MyAsyncPendingRequest(this, request);
@@ -263,12 +285,21 @@ public abstract class AbstractRemoteService<S extends AbstractRemoteService<S, I
    }

    protected void scheduleUnbind() {
        final long unbindDelay = getTimeoutIdleBindMillis();

        if (unbindDelay <= 0) {
            if (mVerbose) Slog.v(mTag, "not scheduling unbind when value is " + unbindDelay);
            return;
        }

        cancelScheduledUnbind();
        // TODO(b/111276913): implement "permanent binding"
        // TODO(b/117779333): make sure it's unbound if the service settings changing (right now
        // it's not)

        mNextUnbind = SystemClock.elapsedRealtime() + unbindDelay;
        if (mVerbose) Slog.v(mTag, "unbinding in " + unbindDelay + "ms: " + mNextUnbind);
        mHandler.sendMessageDelayed(obtainMessage(AbstractRemoteService::handleUnbind, this)
                .setWhat(MSG_UNBIND), getTimeoutIdleBindMillis());
                .setWhat(MSG_UNBIND), unbindDelay);
    }

    private void handleUnbind() {
@@ -342,6 +373,7 @@ public abstract class AbstractRemoteService<S extends AbstractRemoteService<S, I
                mService = null;
            }
        }
        mNextUnbind = 0;
        mContext.unbindService(mServiceConnection);
    }

+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);
            }
        }
    }
+8 −10
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);
    }
@@ -207,7 +205,7 @@ final class AutofillManagerServiceImpl
    }

    @Override // from PerUserSystemService
    protected ServiceInfo newServiceInfo(@NonNull ComponentName serviceComponent)
    protected ServiceInfo newServiceInfoLocked(@NonNull ComponentName serviceComponent)
            throws NameNotFoundException {
        mInfo = new AutofillServiceInfo(getContext(), serviceComponent, mUserId);
        return mInfo.getServiceInfo();
@@ -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) {
+1 −3
Original line number Diff line number Diff line
@@ -47,8 +47,6 @@ final class RemoteAugmentedAutofillService

    private static final String TAG = RemoteAugmentedAutofillService.class.getSimpleName();

    // TODO(b/117779333): changed it so it's permanentely bound
    private static final long TIMEOUT_IDLE_BIND_MILLIS = 2 * DateUtils.MINUTE_IN_MILLIS;
    private static final long TIMEOUT_REMOTE_REQUEST_MILLIS = 2 * DateUtils.SECOND_IN_MILLIS;

    RemoteAugmentedAutofillService(Context context, ComponentName serviceName,
@@ -90,7 +88,7 @@ final class RemoteAugmentedAutofillService

    @Override // from AbstractRemoteService
    protected long getTimeoutIdleBindMillis() {
        return TIMEOUT_IDLE_BIND_MILLIS;
        return PERMANENT_BOUND_TIMEOUT_MS;
    }

    @Override // from AbstractRemoteService
+7 −4
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,14 +67,16 @@ 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
    protected ContentCapturePerUserService newServiceLocked(@UserIdInt int resolvedUserId,
            boolean disabled) {
        return new ContentCapturePerUserService(this, mLock, resolvedUserId);
        return new ContentCapturePerUserService(this, mLock, disabled, resolvedUserId);
    }

    @Override // from SystemService
@@ -178,7 +181,7 @@ public final class ContentCaptureManagerService extends
            synchronized (mLock) {
                final ContentCapturePerUserService service = getServiceForUserLocked(userId);
                service.startSessionLocked(activityToken, componentName, taskId, displayId,
                        sessionId, Binder.getCallingUid(), flags, mAllowInstantService, result);
                        sessionId, Binder.getCallingUid(), flags, result);
            }
        }

Loading