@@ -126,6 +126,16 @@ public void run(String[] args) {
126126 return ;
127127 }
128128
129+ if ("grant" .equals (op )) {
130+ runGrantRevokePermission (true );
131+ return ;
132+ }
133+
134+ if ("revoke" .equals (op )) {
135+ runGrantRevokePermission (false );
136+ return ;
137+ }
138+
129139 if ("set-install-location" .equals (op )) {
130140 runSetInstallLocation ();
131141 return ;
@@ -596,8 +606,9 @@ private void doListPermissions(ArrayList<String> groupList,
596606 if (groups && groupName == null && pi .group != null ) {
597607 continue ;
598608 }
599- if (pi .protectionLevel < startProtectionLevel
600- || pi .protectionLevel > endProtectionLevel ) {
609+ final int base = pi .protectionLevel & PermissionInfo .PROTECTION_MASK_BASE ;
610+ if (base < startProtectionLevel
611+ || base > endProtectionLevel ) {
601612 continue ;
602613 }
603614 if (summary ) {
@@ -627,22 +638,8 @@ private void doListPermissions(ArrayList<String> groupList,
627638 + loadText (pi , pi .descriptionRes ,
628639 pi .nonLocalizedDescription ));
629640 }
630- String protLevel = "unknown" ;
631- switch (pi .protectionLevel ) {
632- case PermissionInfo .PROTECTION_DANGEROUS :
633- protLevel = "dangerous" ;
634- break ;
635- case PermissionInfo .PROTECTION_NORMAL :
636- protLevel = "normal" ;
637- break ;
638- case PermissionInfo .PROTECTION_SIGNATURE :
639- protLevel = "signature" ;
640- break ;
641- case PermissionInfo .PROTECTION_SIGNATURE_OR_SYSTEM :
642- protLevel = "signatureOrSystem" ;
643- break ;
644- }
645- System .out .println (prefix + " protectionLevel:" + protLevel );
641+ System .out .println (prefix + " protectionLevel:"
642+ + PermissionInfo .protectionToString (pi .protectionLevel ));
646643 }
647644 }
648645 }
@@ -1063,6 +1060,36 @@ private void runSetEnabledSetting(int state) {
10631060 }
10641061 }
10651062
1063+ private void runGrantRevokePermission (boolean grant ) {
1064+ String pkg = nextArg ();
1065+ if (pkg == null ) {
1066+ System .err .println ("Error: no package specified" );
1067+ showUsage ();
1068+ return ;
1069+ }
1070+ String perm = nextArg ();
1071+ if (perm == null ) {
1072+ System .err .println ("Error: no permission specified" );
1073+ showUsage ();
1074+ return ;
1075+ }
1076+ try {
1077+ if (grant ) {
1078+ mPm .grantPermission (pkg , perm );
1079+ } else {
1080+ mPm .revokePermission (pkg , perm );
1081+ }
1082+ } catch (RemoteException e ) {
1083+ System .err .println (e .toString ());
1084+ System .err .println (PM_NOT_RUNNING_ERR );
1085+ } catch (IllegalArgumentException e ) {
1086+ System .err .println ("Bad argument: " + e .toString ());
1087+ showUsage ();
1088+ } catch (SecurityException e ) {
1089+ System .err .println ("Operation not allowed: " + e .toString ());
1090+ }
1091+ }
1092+
10661093 /**
10671094 * Displays the package file for a package.
10681095 * @param pckg
@@ -1158,6 +1185,8 @@ private static void showUsage() {
11581185 System .err .println (" pm enable PACKAGE_OR_COMPONENT" );
11591186 System .err .println (" pm disable PACKAGE_OR_COMPONENT" );
11601187 System .err .println (" pm disable-user PACKAGE_OR_COMPONENT" );
1188+ System .err .println (" pm grant PACKAGE PERMISSION" );
1189+ System .err .println (" pm revoke PACKAGE PERMISSION" );
11611190 System .err .println (" pm set-install-location [0/auto] [1/internal] [2/external]" );
11621191 System .err .println (" pm get-install-location" );
11631192 System .err .println (" pm create-profile USER_NAME" );
@@ -1208,6 +1237,10 @@ private static void showUsage() {
12081237 System .err .println ("pm enable, disable, disable-user: these commands change the enabled state" );
12091238 System .err .println (" of a given package or component (written as \" package/class\" )." );
12101239 System .err .println ("" );
1240+ System .err .println ("pm grant, revoke: these commands either grant or revoke permissions" );
1241+ System .err .println (" to applications. Only optional permissions the application has" );
1242+ System .err .println (" declared can be granted or revoked." );
1243+ System .err .println ("" );
12111244 System .err .println ("pm get-install-location: returns the current install location." );
12121245 System .err .println (" 0 [auto]: Let system decide the best location" );
12131246 System .err .println (" 1 [internal]: Install on internal device storage" );
0 commit comments