diff options
author | Dianne Hackborn <hackbod@google.com> | 2013-01-18 18:36:09 -0800 |
---|---|---|
committer | Dianne Hackborn <hackbod@google.com> | 2013-01-18 18:36:09 -0800 |
commit | 72e3983d38f656cfa8c7a038eb80bdd9ea06768e (patch) | |
tree | 6bde32531354a8b09058b60bc702a9ec3c6f6b6b /services/java/com/android/server/AppOpsService.java | |
parent | e95724aebec3a4a121fde3dfba761b80d2cd6922 (diff) |
New API to get app op information about a single package.
Change-Id: I986453d9bb4161da467fb820b12502464e936483
Diffstat (limited to 'services/java/com/android/server/AppOpsService.java')
-rw-r--r-- | services/java/com/android/server/AppOpsService.java | 77 |
1 files changed, 56 insertions, 21 deletions
diff --git a/services/java/com/android/server/AppOpsService.java b/services/java/com/android/server/AppOpsService.java index 17128062b0a1..3d9ddaebf2d1 100644 --- a/services/java/com/android/server/AppOpsService.java +++ b/services/java/com/android/server/AppOpsService.java @@ -127,6 +127,30 @@ public class AppOpsService extends IAppOpsService.Stub { } } + private ArrayList<AppOpsManager.OpEntry> collectOps(Ops pkgOps, int[] ops) { + ArrayList<AppOpsManager.OpEntry> resOps = null; + if (ops == null) { + resOps = new ArrayList<AppOpsManager.OpEntry>(); + for (int j=0; j<pkgOps.size(); j++) { + Op curOp = pkgOps.valueAt(j); + resOps.add(new AppOpsManager.OpEntry(curOp.op, curOp.time, + curOp.duration)); + } + } else { + for (int j=0; j<ops.length; j++) { + Op curOp = pkgOps.get(ops[j]); + if (curOp != null) { + if (resOps == null) { + resOps = new ArrayList<AppOpsManager.OpEntry>(); + } + resOps.add(new AppOpsManager.OpEntry(curOp.op, curOp.time, + curOp.duration)); + } + } + } + return resOps; + } + @Override public List<AppOpsManager.PackageOps> getPackagesForOps(int[] ops) { mContext.enforcePermission(android.Manifest.permission.GET_APP_OPS_STATS, @@ -136,26 +160,7 @@ public class AppOpsService extends IAppOpsService.Stub { for (int i=0; i<mUidOps.size(); i++) { HashMap<String, Ops> packages = mUidOps.valueAt(i); for (Ops pkgOps : packages.values()) { - ArrayList<AppOpsManager.OpEntry> resOps = null; - if (ops == null) { - resOps = new ArrayList<AppOpsManager.OpEntry>(); - for (int j=0; j<pkgOps.size(); j++) { - Op curOp = pkgOps.valueAt(j); - resOps.add(new AppOpsManager.OpEntry(curOp.op, curOp.time, - curOp.duration)); - } - } else { - for (int j=0; j<ops.length; j++) { - Op curOp = pkgOps.get(ops[j]); - if (curOp != null) { - if (resOps == null) { - resOps = new ArrayList<AppOpsManager.OpEntry>(); - } - resOps.add(new AppOpsManager.OpEntry(curOp.op, curOp.time, - curOp.duration)); - } - } - } + ArrayList<AppOpsManager.OpEntry> resOps = collectOps(pkgOps, ops); if (resOps != null) { if (res == null) { res = new ArrayList<AppOpsManager.PackageOps>(); @@ -171,6 +176,28 @@ public class AppOpsService extends IAppOpsService.Stub { } @Override + public List<AppOpsManager.PackageOps> getOpsForPackage(int uid, String packageName, + int[] ops) { + mContext.enforcePermission(android.Manifest.permission.GET_APP_OPS_STATS, + Binder.getCallingPid(), Binder.getCallingUid(), null); + synchronized (this) { + Ops pkgOps = getOpsLocked(uid, packageName, false); + if (pkgOps == null) { + return null; + } + ArrayList<AppOpsManager.OpEntry> resOps = collectOps(pkgOps, ops); + if (resOps == null) { + return null; + } + ArrayList<AppOpsManager.PackageOps> res = new ArrayList<AppOpsManager.PackageOps>(); + AppOpsManager.PackageOps resPackage = new AppOpsManager.PackageOps( + pkgOps.packageName, pkgOps.uid, resOps); + res.add(resPackage); + return res; + } + } + + @Override public int checkOperation(int code, int uid, String packageName) { uid = handleIncomingUid(uid); synchronized (this) { @@ -252,7 +279,7 @@ public class AppOpsService extends IAppOpsService.Stub { return uid; } - private Op getOpLocked(int code, int uid, String packageName, boolean edit) { + private Ops getOpsLocked(int uid, String packageName, boolean edit) { HashMap<String, Ops> pkgOps = mUidOps.get(uid); if (pkgOps == null) { if (!edit) { @@ -289,6 +316,14 @@ public class AppOpsService extends IAppOpsService.Stub { ops = new Ops(packageName, uid); pkgOps.put(packageName, ops); } + return ops; + } + + private Op getOpLocked(int code, int uid, String packageName, boolean edit) { + Ops ops = getOpsLocked(uid, packageName, edit); + if (ops == null) { + return null; + } Op op = ops.get(code); if (op == null) { if (!edit) { |