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

Commit 0692fa9e authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Avoid using UserHandle.isSameApp() in package check" into main

parents 1983f93c 3ad5380b
Loading
Loading
Loading
Loading
+4 −13
Original line number Diff line number Diff line
@@ -30,7 +30,6 @@ import android.annotation.Nullable;
import android.annotation.UserIdInt;
import android.annotation.WorkerThread;
import android.app.ActivityManagerInternal;
import android.app.AppGlobals;
import android.app.AppOpsManager;
import android.app.IUriGrantsManager;
import android.app.KeyguardManager;
@@ -48,9 +47,8 @@ import android.content.IClipboard;
import android.content.IOnPrimaryClipChangedListener;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.IPackageManager;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManagerInternal;
import android.content.pm.UserInfo;
import android.graphics.drawable.Drawable;
import android.hardware.display.DisplayManager;
@@ -1247,20 +1245,13 @@ public class ClipboardService extends SystemService {

    @GuardedBy("mLock")
    private void addActiveOwnerLocked(int uid, int deviceId, String pkg) {
        final IPackageManager pm = AppGlobals.getPackageManager();
        final PackageManagerInternal pm = LocalServices.getService(PackageManagerInternal.class);
        final int targetUserHandle = UserHandle.getCallingUserId();
        final long oldIdentity = Binder.clearCallingIdentity();
        try {
            PackageInfo pi = pm.getPackageInfo(pkg, 0, targetUserHandle);
            if (pi == null) {
                throw new IllegalArgumentException("Unknown package " + pkg);
            if (!pm.isSameApp(pkg, 0, uid, targetUserHandle)) {
                throw new SecurityException("Calling uid " + uid + " does not own package " + pkg);
            }
            if (!UserHandle.isSameApp(pi.applicationInfo.uid, uid)) {
                throw new SecurityException("Calling uid " + uid
                        + " does not own package " + pkg);
            }
        } catch (RemoteException e) {
            // Can't happen; the package manager is in the same process
        } finally {
            Binder.restoreCallingIdentity(oldIdentity);
        }