Skip to content

Commit 75c33d9

Browse files
alexgherghinaAndroid (Google) Code Review
authored andcommitted
Merge "Adds the ability to start a user in background" into lmp-dev
2 parents c3014c8 + 979e40e commit 75c33d9

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

  • cmds/am/src/com/android/commands/am

cmds/am/src/com/android/commands/am/Am.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ public void onShowUsage(PrintStream out) {
132132
" am to-uri [INTENT]\n" +
133133
" am to-intent-uri [INTENT]\n" +
134134
" am switch-user <USER_ID>\n" +
135+
" am start-user <USER_ID>\n" +
135136
" am stop-user <USER_ID>\n" +
136137
" am stack start <DISPLAY_ID> <INTENT>\n" +
137138
" am stack movetask <TASK_ID> <STACK_ID> [true|false]\n" +
@@ -233,8 +234,11 @@ public void onShowUsage(PrintStream out) {
233234
"am switch-user: switch to put USER_ID in the foreground, starting\n" +
234235
" execution of that user if it is currently stopped.\n" +
235236
"\n" +
237+
"am start-user: start USER_ID in background if it is currently stopped,\n" +
238+
" use switch-user if you want to start the user in foreground.\n" +
239+
"\n" +
236240
"am stop-user: stop execution of USER_ID, not allowing it to run any\n" +
237-
" code until a later explicit switch to it.\n" +
241+
" code until a later explicit start or switch to it.\n" +
238242
"\n" +
239243
"am stack start: start a new activity on <DISPLAY_ID> using <INTENT>.\n" +
240244
"\n" +
@@ -340,6 +344,8 @@ public void onRun() throws Exception {
340344
runToUri(true);
341345
} else if (op.equals("switch-user")) {
342346
runSwitchUser();
347+
} else if (op.equals("start-user")) {
348+
runStartUserInBackground();
343349
} else if (op.equals("stop-user")) {
344350
runStopUser();
345351
} else if (op.equals("stack")) {
@@ -1133,6 +1139,16 @@ private void runSwitchUser() throws Exception {
11331139
mAm.switchUser(Integer.parseInt(user));
11341140
}
11351141

1142+
private void runStartUserInBackground() throws Exception {
1143+
String user = nextArgRequired();
1144+
boolean success = mAm.startUserInBackground(Integer.parseInt(user));
1145+
if (success) {
1146+
System.out.println("Success: user started");
1147+
} else {
1148+
System.err.println("Error: could not start user");
1149+
}
1150+
}
1151+
11361152
private void runStopUser() throws Exception {
11371153
String user = nextArgRequired();
11381154
int res = mAm.stopUser(Integer.parseInt(user), null);

0 commit comments

Comments
 (0)