diff options
author | Zoltan Szatmary-Ban <szatmz@google.com> | 2014-11-24 12:08:17 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-11-24 12:08:20 +0000 |
commit | 604aec9574212aabb3391585799a72e6820466cd (patch) | |
tree | 1b0e7e32517c254e3a63edf972277ac8f058b5d3 /cmds | |
parent | 962b06f9a02f08392b6f87225a314ebf39dd7a07 (diff) | |
parent | e9119876a21575ee7a7d058da85d04c4c4b8a971 (diff) | |
download | frameworks_base-604aec9574212aabb3391585799a72e6820466cd.zip frameworks_base-604aec9574212aabb3391585799a72e6820466cd.tar.gz frameworks_base-604aec9574212aabb3391585799a72e6820466cd.tar.bz2 |
Merge "Add new subcommand 'set-active-admin' to the dpm command." into lmp-mr1-dev
Diffstat (limited to 'cmds')
-rw-r--r-- | cmds/dpm/src/com/android/commands/dpm/Dpm.java | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/cmds/dpm/src/com/android/commands/dpm/Dpm.java b/cmds/dpm/src/com/android/commands/dpm/Dpm.java index 3b9a785..781fb96 100644 --- a/cmds/dpm/src/com/android/commands/dpm/Dpm.java +++ b/cmds/dpm/src/com/android/commands/dpm/Dpm.java @@ -38,18 +38,25 @@ public final class Dpm extends BaseCommand { (new Dpm()).run(args); } + private static final String COMMAND_SET_ACTIVE_ADMIN = "set-active-admin"; private static final String COMMAND_SET_DEVICE_OWNER = "set-device-owner"; private static final String COMMAND_SET_PROFILE_OWNER = "set-profile-owner"; private IDevicePolicyManager mDevicePolicyManager; + private int mUserId = UserHandle.USER_OWNER; + private ComponentName mComponent = null; @Override public void onShowUsage(PrintStream out) { out.println( "usage: dpm [subcommand] [options]\n" + + "usage: dpm set-active-admin [ --user <USER_ID> ] <COMPONENT>\n" + "usage: dpm set-device-owner <COMPONENT>\n" + "usage: dpm set-profile-owner <COMPONENT> <USER_ID>\n" + "\n" + + "dpm set-active-admin: Sets the given component as active admin" + + " for an existing user.\n" + + "\n" + "dpm set-device-owner: Sets the given component as active admin, and its\n" + " package as device owner.\n" + "\n" + @@ -68,6 +75,9 @@ public final class Dpm extends BaseCommand { String command = nextArgRequired(); switch (command) { + case COMMAND_SET_ACTIVE_ADMIN: + runSetActiveAdmin(); + break; case COMMAND_SET_DEVICE_OWNER: runSetDeviceOwner(); break; @@ -79,6 +89,22 @@ public final class Dpm extends BaseCommand { } } + private void parseArgs(boolean canHaveUser) { + String nextArg = nextArgRequired(); + if (canHaveUser && "--user".equals(nextArg)) { + mUserId = parseInt(nextArgRequired()); + nextArg = nextArgRequired(); + } + mComponent = parseComponentName(nextArg); + } + + private void runSetActiveAdmin() throws RemoteException { + parseArgs(true); + mDevicePolicyManager.setActiveAdmin(mComponent, true /*refreshing*/, mUserId); + + System.out.println("Success: Active admin set to component " + mComponent.toShortString()); + } + private void runSetDeviceOwner() throws RemoteException { ComponentName component = parseComponentName(nextArgRequired()); mDevicePolicyManager.setActiveAdmin(component, true /*refreshing*/, UserHandle.USER_OWNER); @@ -99,6 +125,7 @@ public final class Dpm extends BaseCommand { } private void runSetProfileOwner() throws RemoteException { + // To be refactored later to use parseArgs(boolean). Currently in use by existing tests. ComponentName component = parseComponentName(nextArgRequired()); int userId = parseInt(nextArgRequired()); mDevicePolicyManager.setActiveAdmin(component, true /*refreshing*/, userId); |