Skip to content

Commit 719a632

Browse files
committed
Change permission enforcement through pm command.
Add "set-permission-enforced", which can currently only mutate enforcement of READ_EXTERNAL_STORAGE. Bug: 6363043 Change-Id: I3f7929738c8c36b0a54fbf171c03fe16c09b5d99
1 parent 263d044 commit 719a632

File tree

1 file changed

+33
-0
lines changed
  • cmds/pm/src/com/android/commands/pm

1 file changed

+33
-0
lines changed

cmds/pm/src/com/android/commands/pm/Pm.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ public void run(String[] args) {
136136
return;
137137
}
138138

139+
if ("set-permission-enforced".equals(op)) {
140+
runSetPermissionEnforced();
141+
return;
142+
}
143+
139144
if ("set-install-location".equals(op)) {
140145
runSetInstallLocation();
141146
return;
@@ -1114,6 +1119,33 @@ private void runGrantRevokePermission(boolean grant) {
11141119
}
11151120
}
11161121

1122+
private void runSetPermissionEnforced() {
1123+
final String permission = nextArg();
1124+
if (permission == null) {
1125+
System.err.println("Error: no permission specified");
1126+
showUsage();
1127+
return;
1128+
}
1129+
final String enforcedRaw = nextArg();
1130+
if (enforcedRaw == null) {
1131+
System.err.println("Error: no enforcement specified");
1132+
showUsage();
1133+
return;
1134+
}
1135+
final boolean enforced = Boolean.parseBoolean(enforcedRaw);
1136+
try {
1137+
mPm.setPermissionEnforced(permission, enforced);
1138+
} catch (RemoteException e) {
1139+
System.err.println(e.toString());
1140+
System.err.println(PM_NOT_RUNNING_ERR);
1141+
} catch (IllegalArgumentException e) {
1142+
System.err.println("Bad argument: " + e.toString());
1143+
showUsage();
1144+
} catch (SecurityException e) {
1145+
System.err.println("Operation not allowed: " + e.toString());
1146+
}
1147+
}
1148+
11171149
/**
11181150
* Displays the package file for a package.
11191151
* @param pckg
@@ -1214,6 +1246,7 @@ private static void showUsage() {
12141246
System.err.println(" pm revoke PACKAGE PERMISSION");
12151247
System.err.println(" pm set-install-location [0/auto] [1/internal] [2/external]");
12161248
System.err.println(" pm get-install-location");
1249+
System.err.println(" pm set-permission-enforced PERMISSION [true|false]");
12171250
System.err.println(" pm create-user USER_NAME");
12181251
System.err.println(" pm remove-user USER_ID");
12191252
System.err.println("");

0 commit comments

Comments
 (0)