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

Commit e870d022 authored by Anton Hansson's avatar Anton Hansson
Browse files

Revoke all relevant shared permission on uninstall

The for-loop over the uninstalled app's permissions would
previously return immediately after successfully revoking
a shared permission, preventing the loop to run to the end.

Instead, always loop through all the permission and return
the "widest" matching user id.

Bug: 36899497
Test: manual, using provided test apks
Test: atest CtsPermissionTestCases:SharedUidPermissionsTest
Change-Id: I1f8fad77123c8affa2d825bce1edc2bcd8f60f12
parent 2384444f
Loading
Loading
Loading
Loading
+16 −9
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import static com.android.server.pm.PackageManagerService.PLATFORM_PACKAGE_NAME;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.UserIdInt;
import android.content.ComponentName;
import android.content.Intent;
import android.content.IntentFilter;
@@ -916,13 +917,13 @@ public final class Settings {
    }

    /*
     * Update the shared user setting when a package using
     * specifying the shared user id is removed. The gids
     * associated with each permission of the deleted package
     * are removed from the shared user's gid list only if its
     * not in use by other permissions of packages in the
     * shared user setting.
     * Update the shared user setting when a package with a shared user id is removed. The gids
     * associated with each permission of the deleted package are removed from the shared user'
     * gid list only if its not in use by other permissions of packages in the shared user setting.
     *
     * @return the affected user id
     */
    @UserIdInt
    int updateSharedUserPermsLPw(PackageSetting deletedPs, int userId) {
        if ((deletedPs == null) || (deletedPs.pkg == null)) {
            Slog.i(PackageManagerService.TAG,
@@ -937,6 +938,7 @@ public final class Settings {

        SharedUserSetting sus = deletedPs.sharedUser;

        int affectedUserId = UserHandle.USER_NULL;
        // Update permissions
        for (String eachPerm : deletedPs.pkg.requestedPermissions) {
            BasePermission bp = mPermissions.getPermission(eachPerm);
@@ -983,17 +985,22 @@ public final class Settings {

            if (permissionsState.revokeInstallPermission(bp) ==
                    PermissionsState.PERMISSION_OPERATION_SUCCESS_GIDS_CHANGED) {
                return UserHandle.USER_ALL;
                affectedUserId = UserHandle.USER_ALL;
            }

            // Try to revoke as an install permission which is per user.
            if (permissionsState.revokeRuntimePermission(bp, userId) ==
                    PermissionsState.PERMISSION_OPERATION_SUCCESS_GIDS_CHANGED) {
                return userId;
                if (affectedUserId == UserHandle.USER_NULL) {
                    affectedUserId = userId;
                } else if (affectedUserId != userId) {
                    // Multiple users affected.
                    affectedUserId = UserHandle.USER_ALL;
                }
            }
        }

        return UserHandle.USER_NULL;
        return affectedUserId;
    }

    int removePackageLPw(String name) {