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

Commit c4967e71 authored by Fyodor Kupolov's avatar Fyodor Kupolov
Browse files

Fixed handling of blockUninstall setting

Previously, if one user has blockUninstall, it will block uninstalling
the package for all users. Now the package is uninstalled for all users,
excluding the ones that have blockUninstall setting.

Bug: 24616123
Change-Id: Ie4a68ef97fbef4711b18ccd311e39f32ab4b8efe
parent 0a04ab24
Loading
Loading
Loading
Loading
+43 −10
Original line number Diff line number Diff line
@@ -14126,8 +14126,7 @@ public class PackageManagerService extends IPackageManager.Stub {
            return;
        }
        for (int currentUserId : users) {
            if (getBlockUninstallForUser(packageName, currentUserId)) {
        if (!deleteAllUsers && getBlockUninstallForUser(packageName, userId)) {
            try {
                observer.onPackageDeleted(packageName,
                        PackageManager.DELETE_FAILED_OWNER_BLOCKED, null);
@@ -14135,16 +14134,40 @@ public class PackageManagerService extends IPackageManager.Stub {
            }
            return;
        }
        }
        if (DEBUG_REMOVE) {
            Slog.d(TAG, "deletePackageAsUser: pkg=" + packageName + " user=" + userId);
            Slog.d(TAG, "deletePackageAsUser: pkg=" + packageName + " user=" + userId
                    + " deleteAllUsers: " + deleteAllUsers );
        }
        // Queue up an async operation since the package deletion may take a little while.
        mHandler.post(new Runnable() {
            public void run() {
                mHandler.removeCallbacks(this);
                final int returnCode = deletePackageX(packageName, userId, flags);
                int returnCode;
                if (!deleteAllUsers) {
                    returnCode = deletePackageX(packageName, userId, flags);
                } else {
                    int[] blockUninstallUserIds = getBlockUninstallForUsers(packageName, users);
                    // If nobody is blocking uninstall, proceed with delete for all users
                    if (ArrayUtils.isEmpty(blockUninstallUserIds)) {
                        returnCode = deletePackageX(packageName, userId, flags);
                    } else {
                        // Otherwise uninstall individually for users with blockUninstalls=false
                        final int userFlags = flags & ~PackageManager.DELETE_ALL_USERS;
                        for (int userId : users) {
                            if (!ArrayUtils.contains(blockUninstallUserIds, userId)) {
                                returnCode = deletePackageX(packageName, userId, userFlags);
                                if (returnCode != PackageManager.DELETE_SUCCEEDED) {
                                    Slog.w(TAG, "Package delete failed for user " + userId
                                            + ", returnCode " + returnCode);
                                }
                            }
                        }
                        // The app has only been marked uninstalled for certain users.
                        // We still need to report that delete was blocked
                        returnCode = PackageManager.DELETE_FAILED_OWNER_BLOCKED;
                    }
                }
                try {
                    observer.onPackageDeleted(packageName, returnCode, null);
                } catch (RemoteException e) {
@@ -14154,6 +14177,16 @@ public class PackageManagerService extends IPackageManager.Stub {
        });
    }
    private int[] getBlockUninstallForUsers(String packageName, int[] userIds) {
        int[] result = EMPTY_INT_ARRAY;
        for (int userId : userIds) {
            if (getBlockUninstallForUser(packageName, userId)) {
                result = ArrayUtils.appendInt(result, userId);
            }
        }
        return result;
    }
    @Override
    public boolean isPackageDeviceAdminOnAnyUser(String packageName) {
        return isPackageDeviceAdmin(packageName, UserHandle.USER_ALL);