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

Commit 0b3cf692 authored by Sudheer Shanka's avatar Sudheer Shanka Committed by Android (Google) Code Review
Browse files

Merge "Add installer app check in PM.deletePackage." into nyc-mr1-dev

parents 4cd7a8c6 72de4ddb
Loading
Loading
Loading
Loading
+2 −7
Original line number Diff line number Diff line
@@ -870,13 +870,8 @@ public class PackageInstallerService extends IPackageInstaller.Stub {
                IntentSender statusReceiver, int userId) {
        final int callingUid = Binder.getCallingUid();
        mPm.enforceCrossUserPermission(callingUid, userId, true, true, "uninstall");
        boolean allowSilentUninstall = true;
        if ((callingUid != Process.SHELL_UID) && (callingUid != Process.ROOT_UID)) {
            mAppOps.checkPackage(callingUid, callerPackageName);
            final String installerPackageName = mPm.getInstallerPackageName(packageName);
            allowSilentUninstall = mPm.isOrphaned(packageName) ||
                    (installerPackageName != null
                            && installerPackageName.equals(callerPackageName));
        }

        // Check whether the caller is device owner, in which case we do it silently.
@@ -887,8 +882,8 @@ public class PackageInstallerService extends IPackageInstaller.Stub {

        final PackageDeleteObserverAdapter adapter = new PackageDeleteObserverAdapter(mContext,
                statusReceiver, packageName, isDeviceOwner, userId);
        if (allowSilentUninstall && mContext.checkCallingOrSelfPermission(
                android.Manifest.permission.DELETE_PACKAGES) == PackageManager.PERMISSION_GRANTED) {
        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DELETE_PACKAGES)
                    == PackageManager.PERMISSION_GRANTED) {
            // Sweet, call straight through!
            mPm.deletePackage(packageName, adapter.getBinder(), userId, flags);
        } else if (isDeviceOwner) {
+23 −0
Original line number Diff line number Diff line
@@ -8366,6 +8366,10 @@ public class PackageManagerService extends IPackageManager.Stub {
            pkg.applicationInfo.flags |= ApplicationInfo.FLAG_FACTORY_TEST;
        }
        if (isSystemApp(pkg)) {
            pkgSetting.isOrphaned = true;
        }
        ArrayList<PackageParser.Package> clientLibPkgs = null;
        if ((scanFlags & SCAN_CHECK_ONLY) != 0) {
@@ -15315,6 +15319,19 @@ public class PackageManagerService extends IPackageManager.Stub {
        Preconditions.checkNotNull(packageName);
        Preconditions.checkNotNull(observer);
        final int uid = Binder.getCallingUid();
        if (uid != Process.SHELL_UID && uid != Process.ROOT_UID && uid != Process.SYSTEM_UID
                && uid != getPackageUid(mRequiredInstallerPackage, 0, UserHandle.getUserId(uid))
                && !isOrphaned(packageName)
                && !isCallerSameAsInstaller(uid, packageName)) {
            try {
                final Intent intent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE);
                intent.setData(Uri.fromParts("package", packageName, null));
                intent.putExtra(PackageInstaller.EXTRA_CALLBACK, observer.asBinder());
                observer.onUserActionRequired(intent);
            } catch (RemoteException re) {
            }
            return;
        }
        final boolean deleteAllUsers = (deleteFlags & PackageManager.DELETE_ALL_USERS) != 0;
        final int[] users = deleteAllUsers ? sUserManager.getUserIds() : new int[]{ userId };
        if (UserHandle.getUserId(uid) != userId || (deleteAllUsers && users.length > 1)) {
@@ -15383,6 +15400,12 @@ public class PackageManagerService extends IPackageManager.Stub {
        });
    }
    private boolean isCallerSameAsInstaller(int callingUid, String pkgName) {
        final int installerPkgUid = getPackageUid(getInstallerPackageName(pkgName),
                0 /* flags */, UserHandle.getUserId(callingUid));
        return installerPkgUid == callingUid;
    }
    private int[] getBlockUninstallForUsers(String packageName, int[] userIds) {
        int[] result = EMPTY_INT_ARRAY;
        for (int userId : userIds) {