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

Commit 3ad5380b authored by Sanjana Sunil's avatar Sanjana Sunil
Browse files

Avoid using UserHandle.isSameApp() in package check

SDK sandbox processes created from the sandbox package do not have the
uid of the package - they use a separate uid range instead.
UserHandle.isSameApp() does not take this account when run for the
sandbox. This causes clipboard tests that use this API to fail when run
in the sandbox.

Instead, use the API PackageManagerService.isSameApp() that takes into
account the differences between sandbox package uid and sandbox process
uid.

Bug: 344805434
Test: atest TextViewReceiveContentTest -- --enable-optional-parameterization --enable-parameterized-modules --module-parameter run_on_sdk_sandbox
Change-Id: I08ae3027b2b9fb64a3d88539dc8150a76be881bd
parent 15bedcc3
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);
        }