diff options
author | Zoltan Szatmary-Ban <szatmz@google.com> | 2014-10-28 12:28:57 +0000 |
---|---|---|
committer | Zoltan Szatmary-Ban <szatmz@google.com> | 2014-11-19 13:47:11 +0000 |
commit | e9119876a21575ee7a7d058da85d04c4c4b8a971 (patch) | |
tree | 6e2feda16426b48d9c9dd3c2d3512a7e5ed2330c /cmds/dpm | |
parent | b30d902ed404e5646bced27bdd2ca4006af802bf (diff) | |
download | frameworks_base-e9119876a21575ee7a7d058da85d04c4c4b8a971.zip frameworks_base-e9119876a21575ee7a7d058da85d04c4c4b8a971.tar.gz frameworks_base-e9119876a21575ee7a7d058da85d04c4c4b8a971.tar.bz2 |
Add new subcommand 'set-active-admin' to the dpm command.
Bug: 18002490
Change-Id: I91746032df08ef0fdef05711114691da18796a0a
Diffstat (limited to 'cmds/dpm')
-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); |