diff options
author | Adam Lesinski <adamlesinski@google.com> | 2014-07-21 11:27:58 -0700 |
---|---|---|
committer | Adam Lesinski <adamlesinski@google.com> | 2014-07-21 13:20:25 -0700 |
commit | 53ab92d89069fb0178ba98eb641a6fc87145543a (patch) | |
tree | 92c6b2ff5b88ab75adc68ddeca2eca72a3c053c2 /services/usage/java/com/android/server | |
parent | 8207c58490e977e87079cc6ca85c85b673f5cf50 (diff) | |
download | frameworks_base-53ab92d89069fb0178ba98eb641a6fc87145543a.zip frameworks_base-53ab92d89069fb0178ba98eb641a6fc87145543a.tar.gz frameworks_base-53ab92d89069fb0178ba98eb641a6fc87145543a.tar.bz2 |
Change UsageStatsService to check uses-permission
Have UsageStatsService check permission grants when AppOps
returns the default MODE_IGNORED mode for a package.
Change-Id: I784a708451a56863b13fc5f178e10bba6ce37a2f
Diffstat (limited to 'services/usage/java/com/android/server')
-rw-r--r-- | services/usage/java/com/android/server/usage/UsageStatsService.java | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/services/usage/java/com/android/server/usage/UsageStatsService.java b/services/usage/java/com/android/server/usage/UsageStatsService.java index 13cbf8a..475824a 100644 --- a/services/usage/java/com/android/server/usage/UsageStatsService.java +++ b/services/usage/java/com/android/server/usage/UsageStatsService.java @@ -16,6 +16,7 @@ package com.android.server.usage; +import android.Manifest; import android.app.AppOpsManager; import android.app.usage.IUsageStatsManager; import android.app.usage.PackageUsageStats; @@ -25,6 +26,7 @@ import android.app.usage.UsageStatsManager; import android.app.usage.UsageStatsManagerInternal; import android.content.ComponentName; import android.content.Context; +import android.content.pm.PackageManager; import android.os.Binder; import android.os.Environment; import android.os.Handler; @@ -381,10 +383,21 @@ public class UsageStatsService extends SystemService { private class BinderService extends IUsageStatsManager.Stub { + private boolean hasPermission(String callingPackage) { + final int mode = mAppOps.checkOp(AppOpsManager.OP_GET_USAGE_STATS, + Binder.getCallingUid(), callingPackage); + if (mode == AppOpsManager.MODE_IGNORED) { + // If AppOpsManager ignores this, still allow if we have the system level + // permission. + return getContext().checkCallingPermission(Manifest.permission.PACKAGE_USAGE_STATS) + == PackageManager.PERMISSION_GRANTED; + } + return mode == AppOpsManager.MODE_ALLOWED; + } + @Override public UsageStats[] getStatsSince(int bucketType, long time, String callingPackage) { - if (mAppOps.checkOp(AppOpsManager.OP_GET_USAGE_STATS, Binder.getCallingUid(), - callingPackage) != AppOpsManager.MODE_ALLOWED) { + if (!hasPermission(callingPackage)) { return UsageStats.EMPTY_STATS; } @@ -398,8 +411,7 @@ public class UsageStatsService extends SystemService { @Override public UsageStats.Event[] getEventsSince(long time, String callingPackage) { - if (mAppOps.checkOp(AppOpsManager.OP_GET_USAGE_STATS, Binder.getCallingUid(), - callingPackage) != AppOpsManager.MODE_ALLOWED) { + if (!hasPermission(callingPackage)) { return UsageStats.Event.EMPTY_EVENTS; } |