OSDN Git Service

DO NOT MERGE: Add pm operation to set user restrictions.
authorSudheer Shanka <sudheersai@google.com>
Thu, 16 Jun 2016 15:58:00 +0000 (08:58 -0700)
committerSudheer Shanka <sudheersai@google.com>
Tue, 12 Jul 2016 01:58:39 +0000 (01:58 +0000)
Bug: 29189712
Change-Id: I6fdb3b68dfe3f51119e5ce8008880fc7d9c793df

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

index 0a573ca..774c0cf 100644 (file)
@@ -235,6 +235,10 @@ public final class Pm {
             return runForceDexOpt();
         }
 
+        if ("set-user-restriction".equals(op)) {
+            return runSetUserRestriction();
+        }
+
         try {
             if (args.length == 1) {
                 if (args[0].equalsIgnoreCase("-l")) {
@@ -1274,6 +1278,40 @@ public final class Pm {
         }
     }
 
+    public int runSetUserRestriction() {
+        int userId = UserHandle.USER_OWNER;
+        String opt = nextOption();
+        if (opt != null && "--user".equals(opt)) {
+            String arg = nextArg();
+            if (arg == null || !isNumber(arg)) {
+                System.err.println("Error: valid userId not specified");
+                return 1;
+            }
+            userId = Integer.parseInt(arg);
+        }
+
+        String restriction = nextArg();
+        String arg = nextArg();
+        boolean value;
+        if ("1".equals(arg)) {
+            value = true;
+        } else if ("0".equals(arg)) {
+            value = false;
+        } else {
+            System.err.println("Error: valid value not specified");
+            return 1;
+        }
+        try {
+            Bundle restrictions = new Bundle();
+            restrictions.putBoolean(restriction, value);
+            mUm.setUserRestrictions(restrictions, userId);
+            return 0;
+        } catch (RemoteException e) {
+            System.err.println(e.toString());
+            return 1;
+        }
+    }
+
     private int runUninstall() throws RemoteException {
         int flags = 0;
         int userId = UserHandle.USER_ALL;