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

Commit 84018010 authored by Mark Kim's avatar Mark Kim Committed by Android (Google) Code Review
Browse files

Merge "Check permission of the calling process" into main

parents 0314fa49 e0b41996
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -195,6 +195,7 @@ public class PackageArchiver {
        Computer snapshot = mPm.snapshotComputer();
        int userId = userHandle.getIdentifier();
        int binderUid = Binder.getCallingUid();
        int binderPid = Binder.getCallingPid();
        if (!PackageManagerServiceUtils.isSystemOrRootOrShell(binderUid)) {
            verifyCaller(snapshot.getPackageUid(callerPackageName, 0, userId), binderUid);
        }
@@ -229,7 +230,8 @@ public class PackageArchiver {
                                    DELETE_ARCHIVE | DELETE_KEEP_DATA,
                                    intentSender,
                                    userId,
                                    binderUid);
                                    binderUid,
                                    binderPid);
                        })
                .exceptionally(
                        e -> {
+6 −5
Original line number Diff line number Diff line
@@ -1405,11 +1405,12 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
                flags,
                statusReceiver,
                userId,
                Binder.getCallingUid());
                Binder.getCallingUid(),
                Binder.getCallingPid());
    }

    void uninstall(VersionedPackage versionedPackage, String callerPackageName, int flags,
            IntentSender statusReceiver, int userId, int callingUid) {
            IntentSender statusReceiver, int userId, int callingUid, int callingPid) {
        final Computer snapshot = mPm.snapshotComputer();
        snapshot.enforceCrossUserPermission(callingUid, userId, true, true, "uninstall");
        if (!PackageManagerServiceUtils.isRootOrShell(callingUid)) {
@@ -1426,7 +1427,7 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
        final PackageDeleteObserverAdapter adapter = new PackageDeleteObserverAdapter(mContext,
                statusReceiver, versionedPackage.getPackageName(),
                canSilentlyInstallPackage, userId, mPackageArchiver, flags);
        if (mContext.checkCallingOrSelfPermission(Manifest.permission.DELETE_PACKAGES)
        if (mContext.checkPermission(Manifest.permission.DELETE_PACKAGES, callingPid, callingUid)
                == PackageManager.PERMISSION_GRANTED) {
            // Sweet, call straight through!
            mPm.deletePackageVersioned(versionedPackage, adapter.getBinder(), userId, flags);
@@ -1446,8 +1447,8 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
        } else {
            ApplicationInfo appInfo = snapshot.getApplicationInfo(callerPackageName, 0, userId);
            if (appInfo.targetSdkVersion >= Build.VERSION_CODES.P) {
                mContext.enforceCallingOrSelfPermission(Manifest.permission.REQUEST_DELETE_PACKAGES,
                        null);
                mContext.enforcePermission(Manifest.permission.REQUEST_DELETE_PACKAGES, callingPid,
                        callingUid, null);
            }

            // Take a short detour to confirm with user
+2 −2
Original line number Diff line number Diff line
@@ -367,7 +367,7 @@ public class PackageArchiverTest {
        verify(mInstallerService).uninstall(
                eq(new VersionedPackage(PACKAGE, PackageManager.VERSION_CODE_HIGHEST)),
                eq(CALLER_PACKAGE), eq(DELETE_ARCHIVE | DELETE_KEEP_DATA), eq(mIntentSender),
                eq(UserHandle.CURRENT.getIdentifier()), anyInt());
                eq(UserHandle.CURRENT.getIdentifier()), anyInt(), anyInt());

        ArchiveState expectedArchiveState = createArchiveState();
        ArchiveState actualArchiveState = mPackageSetting.readUserState(
@@ -391,7 +391,7 @@ public class PackageArchiverTest {
                eq(CALLER_PACKAGE),
                eq(DELETE_ARCHIVE | DELETE_KEEP_DATA),
                eq(mIntentSender),
                eq(UserHandle.CURRENT.getIdentifier()), anyInt());
                eq(UserHandle.CURRENT.getIdentifier()), anyInt(), anyInt());

        ArchiveState expectedArchiveState = createArchiveState();
        ArchiveState actualArchiveState = mPackageSetting.readUserState(