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

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

Merge "Grant clipboard access to the Augmented Autofill service." into qt-dev

parents 83ee7d1f c7436341
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -45,4 +45,12 @@ public abstract class AutofillManagerInternal {
    @Nullable
    public abstract AutofillOptions getAutofillOptions(@NonNull String packageName,
            long versionCode, @UserIdInt int userId);

    /**
     * Checks whether the given {@code uid} owns the
     * {@link android.service.autofill.augmented.AugmentedAutofillService} implementation associated
     * with the given {@code userId}.
     */
    public abstract boolean isAugmentedAutofillServiceForUser(@NonNull int callingUid,
            @UserIdInt int userId);
}
+11 −0
Original line number Diff line number Diff line
@@ -806,6 +806,17 @@ public final class AutofillManagerService
            mAugmentedAutofillState.injectAugmentedAutofillInfo(options, userId, packageName);
            return options;
        }

        @Override
        public boolean isAugmentedAutofillServiceForUser(int callingUid, int userId) {
            synchronized (mLock) {
                final AutofillManagerServiceImpl service = peekServiceForUserLocked(userId);
                if (service != null) {
                    return service.isAugmentedAutofillServiceForUserLocked(callingUid);
                }
            }
            return false;
        }
    }

    /**
+5 −0
Original line number Diff line number Diff line
@@ -1165,6 +1165,11 @@ final class AutofillManagerServiceImpl
        return true;
    }

    boolean isAugmentedAutofillServiceForUserLocked(int callingUid) {
        return mRemoteAugmentedAutofillServiceInfo != null
                && mRemoteAugmentedAutofillServiceInfo.applicationInfo.uid == callingUid;
    }

    /**
     * Sets which packages and activities can trigger augmented autofill.
     *
+10 −2
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ import android.provider.Settings;
import android.text.TextUtils;
import android.util.Slog;
import android.util.SparseArray;
import android.view.autofill.AutofillManagerInternal;

import com.android.server.LocalServices;
import com.android.server.SystemService;
@@ -159,6 +160,7 @@ public class ClipboardService extends SystemService {
    private final PackageManager mPm;
    private final AppOpsManager mAppOps;
    private final ContentCaptureManagerInternal mContentCaptureInternal;
    private final AutofillManagerInternal mAutofillInternal;
    private final IBinder mPermissionOwner;
    private HostClipboardMonitor mHostClipboardMonitor = null;
    private Thread mHostMonitorThread = null;
@@ -179,6 +181,7 @@ public class ClipboardService extends SystemService {
        mUm = (IUserManager) ServiceManager.getService(Context.USER_SERVICE);
        mAppOps = (AppOpsManager) getContext().getSystemService(Context.APP_OPS_SERVICE);
        mContentCaptureInternal = LocalServices.getService(ContentCaptureManagerInternal.class);
        mAutofillInternal = LocalServices.getService(AutofillManagerInternal.class);
        final IBinder permOwner = mUgmInternal.newUriPermissionOwner("clipboard");
        mPermissionOwner = permOwner;
        if (IS_EMULATOR) {
@@ -653,13 +656,18 @@ public class ClipboardService extends SystemService {
                // Clipboard can only be read by applications with focus..
                boolean allowed = mWm.isUidFocused(callingUid);
                if (!allowed && mContentCaptureInternal != null) {
                    // ...or the Intelligence Service
                    // ...or the Content Capture Service
                    allowed = mContentCaptureInternal.isContentCaptureServiceForUser(callingUid,
                            userId);
                }
                if (!allowed && mAutofillInternal != null) {
                    // ...or the Augmented Autofill Service
                    allowed = mAutofillInternal.isAugmentedAutofillServiceForUser(callingUid,
                            userId);
                }
                if (!allowed) {
                    Slog.e(TAG, "Denying clipboard access to " + callingPackage
                            + ", application is not in focus neither is the IntelligeService for "
                            + ", application is not in focus neither is a system service for "
                            + "user " + userId);
                }
                return allowed;
+5 −6
Original line number Diff line number Diff line
@@ -32,7 +32,6 @@ import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageItemInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManagerInternal;
import android.content.res.Configuration;
import android.content.res.Resources.Theme;
import android.database.sqlite.SQLiteCompatibilityWalFlags;
@@ -1248,11 +1247,6 @@ public final class SystemServer {
            mSystemServiceManager.startService(CONTENT_SUGGESTIONS_SERVICE_CLASS);
            traceEnd();

            // NOTE: ClipboardService indirectly depends on IntelligenceService
            traceBeginAndSlog("StartClipboardService");
            mSystemServiceManager.startService(ClipboardService.class);
            traceEnd();

            traceBeginAndSlog("InitNetworkStackClient");
            try {
                NetworkStackClient.getInstance().init();
@@ -1887,6 +1881,11 @@ public final class SystemServer {
            traceEnd();
        }

        // NOTE: ClipboardService depends on ContentCapture and Autofill
        traceBeginAndSlog("StartClipboardService");
        mSystemServiceManager.startService(ClipboardService.class);
        traceEnd();

        traceBeginAndSlog("AppServiceManager");
        mSystemServiceManager.startService(AppBindingService.Lifecycle.class);
        traceEnd();