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

Commit bb323058 authored by Jing Ji's avatar Jing Ji
Browse files

Throw SecurityException as if no CLEAR_APP_USER_DATA permission

...if the target package is protected for caller w/o MANAGE_USERS
in clearApplicationUserData.

Bug: 187956596
Test: Manual - see b/187956596#comment1
Change-Id: I9216201c753b1a5a954202cbde27f1d675cbf839
parent a94fdfae
Loading
Loading
Loading
Loading
+21 −12
Original line number Diff line number Diff line
@@ -3458,30 +3458,39 @@ public class ActivityManagerService extends IActivityManager.Stub
        final long callingId = Binder.clearCallingIdentity();
        try {
            IPackageManager pm = AppGlobals.getPackageManager();
            boolean permitted = true;
            // Instant packages are not protected
            if (getPackageManagerInternal().isPackageDataProtected(
                    resolvedUserId, packageName)) {
                if (ActivityManager.checkUidPermission(android.Manifest.permission.MANAGE_USERS,
                        uid) == PERMISSION_GRANTED) {
                    // The caller has the MANAGE_USERS permission, tell them what's going on.
                    throw new SecurityException(
                            "Cannot clear data for a protected package: " + packageName);
                } else {
                    permitted = false; // fall through and throw the SecurityException below.
                }
            }
            ApplicationInfo applicationInfo = null;
            if (permitted) {
                try {
                    applicationInfo = pm.getApplicationInfo(packageName,
                            MATCH_UNINSTALLED_PACKAGES, resolvedUserId);
                } catch (RemoteException e) {
                    /* ignore */
                }
            appInfo = applicationInfo;
            final boolean clearingOwnUidData = appInfo != null && appInfo.uid == uid;
                permitted = (applicationInfo != null && applicationInfo.uid == uid) // own uid data
                        || (checkComponentPermission(permission.CLEAR_APP_USER_DATA,
                                pid, uid, -1, true) == PackageManager.PERMISSION_GRANTED);
            }
            if (!clearingOwnUidData && checkComponentPermission(permission.CLEAR_APP_USER_DATA,
                        pid, uid, -1, true) != PackageManager.PERMISSION_GRANTED) {
            if (!permitted) {
                throw new SecurityException("PID " + pid + " does not have permission "
                        + android.Manifest.permission.CLEAR_APP_USER_DATA + " to clear data"
                        + " of package " + packageName);
            }
            appInfo = applicationInfo;
            final boolean hasInstantMetadata = getPackageManagerInternal()
                    .hasInstantApplicationMetadata(packageName, resolvedUserId);