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

Commit 6d5eb8dc authored by Jackal Guo's avatar Jackal Guo
Browse files

Fix getAppStandbyBucket(s)

An instant app should be able to get its own standby bucket.

Fix: 237446222
Test: atest CtsUsageStatsTestCases
Test: atest CtsUsageStatsTestCases --module-parameter instant_app
Change-Id: I00ec091f3d6d51283d3a230f3bcfe2185763ac9d
parent 0ac7eb80
Loading
Loading
Loading
Loading
+12 −7
Original line number Diff line number Diff line
@@ -639,6 +639,11 @@ public class UsageStatsService extends SystemService implements
        mAppStandby.initializeDefaultsForSystemApps(userId);
    }

    private boolean sameApp(int callingUid, @UserIdInt int userId, String packageName) {
        return mPackageManagerInternal.getPackageUid(packageName, 0 /* flags */, userId)
                == callingUid;
    }

    private boolean isInstantApp(String packageName, int userId) {
        return mPackageManagerInternal.isPackageEphemeral(userId, packageName);
    }
@@ -2354,17 +2359,15 @@ public class UsageStatsService extends SystemService implements
            }
            final int packageUid = mPackageManagerInternal.getPackageUid(packageName, 0, userId);
            // If the calling app is asking about itself, continue, else check for permission.
            if (packageUid != callingUid) {
                if (!hasPermission(callingPackage)) {
                    throw new SecurityException(
                            "Don't have permission to query app standby bucket");
                }
            final boolean sameApp = packageUid == callingUid;
            if (!sameApp && !hasPermission(callingPackage)) {
                throw new SecurityException("Don't have permission to query app standby bucket");
            }

            final boolean isInstantApp = isInstantApp(packageName, userId);
            final boolean cannotAccessInstantApps = shouldObfuscateInstantAppsForCaller(callingUid,
                    userId);
            if (packageUid < 0 || (isInstantApp && cannotAccessInstantApps)) {
            if (packageUid < 0 || (!sameApp && isInstantApp && cannotAccessInstantApps)) {
                throw new IllegalArgumentException(
                        "Cannot get standby bucket for non existent package (" + packageName + ")");
            }
@@ -2418,7 +2421,9 @@ public class UsageStatsService extends SystemService implements
                }
                final int targetUserId = userId;
                standbyBucketList.removeIf(
                        i -> cannotAccessInstantApps && isInstantApp(i.mPackageName, targetUserId));
                        i -> !sameApp(callingUid, targetUserId, i.mPackageName)
                                && isInstantApp(i.mPackageName, targetUserId)
                                && cannotAccessInstantApps);
                return new ParceledListSlice<>(standbyBucketList);
            } finally {
                Binder.restoreCallingIdentity(token);