diff options
author | Kenny Guy <kennyguy@google.com> | 2014-02-14 17:35:05 +0000 |
---|---|---|
committer | Kenny Guy <kennyguy@google.com> | 2014-02-14 19:12:03 +0000 |
commit | 31d6776a9225be5d4ae521a5b551f413c9481aa3 (patch) | |
tree | 15520427eba6bc390353fb5fb340c0132c909982 /cmds | |
parent | a9f387bdf0a836de8bcb12a46a5cdfcb544fbb1a (diff) | |
download | frameworks_base-31d6776a9225be5d4ae521a5b551f413c9481aa3.zip frameworks_base-31d6776a9225be5d4ae521a5b551f413c9481aa3.tar.gz frameworks_base-31d6776a9225be5d4ae521a5b551f413c9481aa3.tar.bz2 |
Extend pm create-user to handle related and managed users.
Change-Id: I0a290b9debdc8ddf23b72a84bf98908ab7fa7c0d
Diffstat (limited to 'cmds')
-rw-r--r-- | cmds/pm/src/com/android/commands/pm/Pm.java | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/cmds/pm/src/com/android/commands/pm/Pm.java b/cmds/pm/src/com/android/commands/pm/Pm.java index d1ded10..9ad2e76 100644 --- a/cmds/pm/src/com/android/commands/pm/Pm.java +++ b/cmds/pm/src/com/android/commands/pm/Pm.java @@ -39,6 +39,7 @@ import android.content.res.AssetManager; import android.content.res.Resources; import android.net.Uri; import android.os.IUserManager; +import android.os.Process; import android.os.RemoteException; import android.os.ServiceManager; import android.os.UserHandle; @@ -1011,6 +1012,27 @@ public final class Pm { public void runCreateUser() { String name; + int relatedUserId = -1; + int flags = 0; + String opt; + while ((opt = nextOption()) != null) { + if ("--relatedTo".equals(opt)) { + String optionData = nextOptionData(); + if (optionData == null || !isNumber(optionData)) { + System.err.println("Error: no USER_ID specified"); + showUsage(); + return; + } else { + relatedUserId = Integer.parseInt(optionData); + } + } else if ("--managed".equals(opt)) { + flags |= UserInfo.FLAG_MANAGED_PROFILE; + } else { + System.err.println("Error: unknown option " + opt); + showUsage(); + return; + } + } String arg = nextArg(); if (arg == null) { System.err.println("Error: no user name specified."); @@ -1018,7 +1040,16 @@ public final class Pm { } name = arg; try { - final UserInfo info = mUm.createUser(name, 0); + UserInfo info = null; + if (relatedUserId < 0) { + info = mUm.createUser(name, flags); + } else { + if (Process.myUid() != 0) { + System.err.println("Error: not running as root."); + return; + } + info = mUm.createRelatedUser(name, flags, relatedUserId); + } if (info != null) { System.out.println("Success: created user id " + info.id); } else { @@ -1530,7 +1561,7 @@ public final class Pm { System.err.println(" pm get-install-location"); System.err.println(" pm set-permission-enforced PERMISSION [true|false]"); System.err.println(" pm trim-caches DESIRED_FREE_SPACE"); - System.err.println(" pm create-user USER_NAME"); + System.err.println(" pm create-user [--relatedTo USER_ID] [--managed] USER_NAME"); System.err.println(" pm remove-user USER_ID"); System.err.println(" pm get-max-users"); System.err.println(""); |