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

Commit c5d0555f authored by Jeongsik Mun's avatar Jeongsik Mun Committed by Patrick Baumann
Browse files

Fix an issue where a custom permission is revoked

A normal permission declared by a system app could be revoked when
the updated system app is uninstalled. Assume that there are an apk
on /system and its updated apk on /data. And both declares the same
normal permission and it's granted to non-system apps. At this point,
If the updated system is uninstalled, That normal permission will be
revoked by uninstalling, but, it won't be granted to non-system apps
which had been had the permission when installing the apk on /system.
Because install permisisons were already fixed at install time.

This fix dosen't revoke normal permissions declared by the disabled
system app from apps while uninstalling the updated system app.

Bug: 182828078
Test: 1) Add a system app declares A, B permissions
      2) Update the system app declares A, B, C, D permissions
      3) Install a non-system app requesting A, B, C, D permissions
      4) Uninstall the updated system app
      5) Verify the non-system app has A, B permissions
Change-Id: I866934576dcc8103b123c10b0deb6144a85c67f5
parent 4e0f53a7
Loading
Loading
Loading
Loading
+42 −24
Original line number Diff line number Diff line
@@ -4213,6 +4213,7 @@ public class PermissionManagerService extends IPermissionManager.Stub {
                // If the target package is being uninstalled, we need to revoke this permission
                // From all other packages
                if (pkg == null || !hasPermission(pkg, bp.getName())) {
                    if (!isPermissionDeclaredByDisabledSystemPkg(bp)) {
                        Slog.i(TAG, "Removing permission " + bp.getName()
                                + " that used to be declared by " + bp.getPackageName());
                        if (bp.isRuntime()) {
@@ -4241,6 +4242,7 @@ public class PermissionManagerService extends IPermissionManager.Stub {
                                }
                            });
                        }
                    }
                    synchronized (mLock) {
                        mRegistry.removePermission(bp.getName());
                    }
@@ -4264,6 +4266,22 @@ public class PermissionManagerService extends IPermissionManager.Stub {
        return changed;
    }

    private boolean isPermissionDeclaredByDisabledSystemPkg(@NonNull Permission permission) {
        final PackageSetting disabledSourcePs = mPackageManagerInt.getDisabledSystemPackage(
                    permission.getPackageName());
        if (disabledSourcePs != null && disabledSourcePs.getPkg() != null) {
            final String permissionName = permission.getName();
            final List<ParsedPermission> sourcePerms = disabledSourcePs.getPkg().getPermissions();
            for (ParsedPermission sourcePerm : sourcePerms) {
                if (TextUtils.equals(permissionName, sourcePerm.getName())
                        && permission.getProtectionLevel() == sourcePerm.getProtectionLevel()) {
                    return true;
                }
            }
        }
        return false;
    }

    /**
     * Revoke a runtime permission from a package for a given user ID.
     */