summaryrefslogtreecommitdiff
path: root/services/usage
diff options
context:
space:
mode:
authorMichael Wachenschwanz <mwachens@google.com>2020-04-01 16:28:46 -0700
committerMichael Wachenschwanz <mwachens@google.com>2020-04-06 16:02:33 -0700
commitd2b132fac44c38aea685db9170f24cf93a25ca99 (patch)
tree77ef7a9a75e74c31f21e26139cd598fd58d92ac9 /services/usage
parent969e1e2759c0fad8862df2a9b4467e2e0bfb4594 (diff)
Add permission check to UsageStatsManager#isAppInactive
UsageStatsManager#isAppInactive provides usage information that is usually gated by the PACKAGE_USAGE_STATS permission in similar API. This updates isAppInactive to also check for the PACKAGE_USAGE_STATS permission. Test: atest android.app.usage.cts android.app.usage.cts.UsageStatsTest#testIsAppInactive Fixes: 148991455 Change-Id: I8ff8eb5d2e887bc164095f38d374e3992808fe79
Diffstat (limited to 'services/usage')
-rw-r--r--services/usage/java/com/android/server/usage/UsageStatsService.java18
1 files changed, 15 insertions, 3 deletions
diff --git a/services/usage/java/com/android/server/usage/UsageStatsService.java b/services/usage/java/com/android/server/usage/UsageStatsService.java
index 0d1b3523bf9b..a2b15f323e18 100644
--- a/services/usage/java/com/android/server/usage/UsageStatsService.java
+++ b/services/usage/java/com/android/server/usage/UsageStatsService.java
@@ -1578,15 +1578,27 @@ public class UsageStatsService extends SystemService implements
}
@Override
- public boolean isAppInactive(String packageName, int userId) {
+ public boolean isAppInactive(String packageName, int userId, String callingPackage) {
+ final int callingUid = Binder.getCallingUid();
try {
userId = ActivityManager.getService().handleIncomingUser(Binder.getCallingPid(),
- Binder.getCallingUid(), userId, false, false, "isAppInactive", null);
+ callingUid, userId, false, false, "isAppInactive", null);
} catch (RemoteException re) {
throw re.rethrowFromSystemServer();
}
+
+ // If the calling app is asking about itself, continue, else check for permission.
+ if (packageName.equals(callingPackage)) {
+ final int actualCallingUid = mPackageManagerInternal.getPackageUidInternal(
+ callingPackage, 0, userId);
+ if (actualCallingUid != callingUid) {
+ return false;
+ }
+ } else if (!hasPermission(callingPackage)) {
+ return false;
+ }
final boolean obfuscateInstantApps = shouldObfuscateInstantAppsForCaller(
- Binder.getCallingUid(), userId);
+ callingUid, userId);
final long token = Binder.clearCallingIdentity();
try {
return mAppStandby.isAppIdleFiltered(