Add appops shell cmd for start/stop op
Bug: 64085448
Test: run commands
Change-Id: Iab1ba88d21683d603dcc0654636f062942d59787
diff --git a/services/core/java/com/android/server/AppOpsService.java b/services/core/java/com/android/server/AppOpsService.java
index 53c9ecb..15f3a23 100644
--- a/services/core/java/com/android/server/AppOpsService.java
+++ b/services/core/java/com/android/server/AppOpsService.java
@@ -61,8 +61,8 @@
import com.android.internal.util.FastXmlSerializer;
import com.android.internal.util.Preconditions;
import com.android.internal.util.XmlUtils;
-
import com.android.internal.util.function.pooled.PooledLambda;
+
import libcore.util.EmptyArray;
import org.xmlpull.v1.XmlPullParser;
@@ -1961,10 +1961,16 @@
int mode;
int packageUid;
int nonpackageUid;
+ final static Binder sBinder = new Binder();
+ IBinder mToken;
Shell(IAppOpsService iface, AppOpsService internal) {
mInterface = iface;
mInternal = internal;
+ try {
+ mToken = mInterface.getToken(sBinder);
+ } catch (RemoteException e) {
+ }
}
@Override
@@ -2149,6 +2155,10 @@
pw.println("AppOps service (appops) commands:");
pw.println(" help");
pw.println(" Print this help text.");
+ pw.println(" start [--user <USER_ID>] <PACKAGE | UID> <OP> ");
+ pw.println(" Starts a given operation for a particular application.");
+ pw.println(" stop [--user <USER_ID>] <PACKAGE | UID> <OP> ");
+ pw.println(" Stops a given operation for a particular application.");
pw.println(" set [--user <USER_ID>] <PACKAGE | UID> <OP> <MODE>");
pw.println(" Set the mode for a particular application and operation.");
pw.println(" get [--user <USER_ID>] <PACKAGE | UID> [<OP>]");
@@ -2347,6 +2357,34 @@
}
return 0;
}
+ case "start": {
+ int res = shell.parseUserPackageOp(true, err);
+ if (res < 0) {
+ return res;
+ }
+
+ if (shell.packageName != null) {
+ shell.mInterface.startOperation(shell.mToken,
+ shell.op, shell.packageUid, shell.packageName, true);
+ } else {
+ return -1;
+ }
+ return 0;
+ }
+ case "stop": {
+ int res = shell.parseUserPackageOp(true, err);
+ if (res < 0) {
+ return res;
+ }
+
+ if (shell.packageName != null) {
+ shell.mInterface.finishOperation(shell.mToken,
+ shell.op, shell.packageUid, shell.packageName);
+ } else {
+ return -1;
+ }
+ return 0;
+ }
default:
return shell.handleDefaultCommands(cmd);
}