Merge "New API to get app op information about a single package."
This commit is contained in:
committed by
Android (Google) Code Review
commit
cc7433470f
@@ -187,6 +187,14 @@ public class AppOpsManager {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<AppOpsManager.PackageOps> getOpsForPackage(int uid, String packageName, int[] ops) {
|
||||||
|
try {
|
||||||
|
return mService.getOpsForPackage(uid, packageName, ops);
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public int checkOp(int op, int uid, String packageName) {
|
public int checkOp(int op, int uid, String packageName) {
|
||||||
try {
|
try {
|
||||||
int mode = mService.checkOperation(op, uid, packageName);
|
int mode = mService.checkOperation(op, uid, packageName);
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import android.app.AppOpsManager;
|
|||||||
|
|
||||||
interface IAppOpsService {
|
interface IAppOpsService {
|
||||||
List<AppOpsManager.PackageOps> getPackagesForOps(in int[] ops);
|
List<AppOpsManager.PackageOps> getPackagesForOps(in int[] ops);
|
||||||
|
List<AppOpsManager.PackageOps> getOpsForPackage(int uid, String packageName, in int[] ops);
|
||||||
int checkOperation(int code, int uid, String packageName);
|
int checkOperation(int code, int uid, String packageName);
|
||||||
int noteOperation(int code, int uid, String packageName);
|
int noteOperation(int code, int uid, String packageName);
|
||||||
int startOperation(int code, int uid, String packageName);
|
int startOperation(int code, int uid, String packageName);
|
||||||
|
|||||||
@@ -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
|
@Override
|
||||||
public List<AppOpsManager.PackageOps> getPackagesForOps(int[] ops) {
|
public List<AppOpsManager.PackageOps> getPackagesForOps(int[] ops) {
|
||||||
mContext.enforcePermission(android.Manifest.permission.GET_APP_OPS_STATS,
|
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++) {
|
for (int i=0; i<mUidOps.size(); i++) {
|
||||||
HashMap<String, Ops> packages = mUidOps.valueAt(i);
|
HashMap<String, Ops> packages = mUidOps.valueAt(i);
|
||||||
for (Ops pkgOps : packages.values()) {
|
for (Ops pkgOps : packages.values()) {
|
||||||
ArrayList<AppOpsManager.OpEntry> resOps = null;
|
ArrayList<AppOpsManager.OpEntry> resOps = collectOps(pkgOps, ops);
|
||||||
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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (resOps != null) {
|
if (resOps != null) {
|
||||||
if (res == null) {
|
if (res == null) {
|
||||||
res = new ArrayList<AppOpsManager.PackageOps>();
|
res = new ArrayList<AppOpsManager.PackageOps>();
|
||||||
@@ -170,6 +175,28 @@ public class AppOpsService extends IAppOpsService.Stub {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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
|
@Override
|
||||||
public int checkOperation(int code, int uid, String packageName) {
|
public int checkOperation(int code, int uid, String packageName) {
|
||||||
uid = handleIncomingUid(uid);
|
uid = handleIncomingUid(uid);
|
||||||
@@ -252,7 +279,7 @@ public class AppOpsService extends IAppOpsService.Stub {
|
|||||||
return uid;
|
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);
|
HashMap<String, Ops> pkgOps = mUidOps.get(uid);
|
||||||
if (pkgOps == null) {
|
if (pkgOps == null) {
|
||||||
if (!edit) {
|
if (!edit) {
|
||||||
@@ -289,6 +316,14 @@ public class AppOpsService extends IAppOpsService.Stub {
|
|||||||
ops = new Ops(packageName, uid);
|
ops = new Ops(packageName, uid);
|
||||||
pkgOps.put(packageName, ops);
|
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);
|
Op op = ops.get(code);
|
||||||
if (op == null) {
|
if (op == null) {
|
||||||
if (!edit) {
|
if (!edit) {
|
||||||
|
|||||||
Reference in New Issue
Block a user