@@ -95,6 +95,8 @@ final class ShellCommand {
95
95
private static final String CMD_GET_LOCK_TASK_FEATURES = "get-lock-task-features" ;
96
96
private static final String CMD_SET_APP_RESTRICTIONS = "set-app-restrictions" ;
97
97
private static final String CMD_GET_APP_RESTRICTIONS = "get-app-restrictions" ;
98
+ private static final String CMD_SET_PERMISSION_GRANT_STATE = "set-permission-grant-state" ;
99
+ private static final String CMD_GET_PERMISSION_GRANT_STATE = "get-permission-grant-state" ;
98
100
99
101
// Commands for APIs added on Android S
100
102
private static final String CMD_SET_PERMITTED_INPUT_METHODS_PARENT =
@@ -269,6 +271,12 @@ public void run() {
269
271
case CMD_GET_APP_RESTRICTIONS :
270
272
execute (() -> getAppRestrictions ());
271
273
break ;
274
+ case CMD_SET_PERMISSION_GRANT_STATE :
275
+ execute (() -> setPermissionGrantState ());
276
+ break ;
277
+ case CMD_GET_PERMISSION_GRANT_STATE :
278
+ execute (() -> getPermissionGrantState ());
279
+ break ;
272
280
default :
273
281
mWriter .printf ("Invalid command: %s\n \n " , cmd );
274
282
showUsage ();
@@ -369,6 +377,13 @@ private void showUsage() {
369
377
mWriter .printf ("\t %s [PKG1] [PKGNn] - get the application restrictions for the given apps, "
370
378
+ "or for TestDPC itself (using UserManager) when PKG is not passed\n " ,
371
379
CMD_GET_APP_RESTRICTIONS );
380
+ mWriter .printf ("\t %s <PKG> <PERMISSION> <STATE> - set the grant state for the given "
381
+ + "package / permission\n " ,
382
+ CMD_SET_PERMISSION_GRANT_STATE );
383
+ mWriter .printf ("\t %s <PKG> <PERMISSION> - get the grant state for the given permission / "
384
+ + "package\n " , CMD_GET_PERMISSION_GRANT_STATE );
385
+
386
+ // Separator for S / pre-S commands - do NOT remove line to avoid cherry-pick conflicts
372
387
373
388
if (Util .isAtLeastS ()) {
374
389
mWriter .printf ("\t %s <true|false> - enable / disable USB data signaling\n " ,
@@ -853,6 +868,29 @@ private void printAppRestrictions(String packageName, Bundle settings) {
853
868
}
854
869
}
855
870
871
+ private void setPermissionGrantState () {
872
+ // TODO(b/171350084): check args
873
+ String packageName = mArgs [1 ];
874
+ String permission = mArgs [2 ];
875
+ int grantState = getIntArg (3 );
876
+ String grantName = Util .grantStateToString (grantState );
877
+
878
+ mDevicePolicyManagerGateway .setPermissionGrantState (packageName , permission , grantState ,
879
+ (v ) -> onSuccess ("Set %s state on %s to %s" , permission , packageName , grantName ),
880
+ (e ) -> onError (e , "Error setting %s state on %s to %s" , packageName , permission ,
881
+ grantName ));
882
+ }
883
+
884
+ private void getPermissionGrantState () {
885
+ // TODO(b/171350084): check args
886
+ String packageName = mArgs [1 ];
887
+ String permission = mArgs [2 ];
888
+ int grantState = mDevicePolicyManagerGateway .getPermissionGrantState (packageName ,
889
+ permission );
890
+ mWriter .printf ("%s state for %s: %s\n " , permission , packageName ,
891
+ Util .grantStateToString (grantState ));
892
+ }
893
+
856
894
private static String permittedToString (boolean permitted ) {
857
895
return permitted ? "PERMITTED" : "NOT PERMITTED" ;
858
896
}
0 commit comments