summaryrefslogtreecommitdiffstats
path: root/cmds
diff options
context:
space:
mode:
authorKenny Guy <kennyguy@google.com>2015-07-22 13:49:20 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2015-07-22 13:49:20 +0000
commit2ba3fec6e0222754d93ed7a491354164d113ad6e (patch)
tree4f66a67081af17f2a561a8c2f83804c7c2cc901d /cmds
parent41cfd3f8c0df036345807f87b828b4b68bdaffdf (diff)
parent2c7836befce222e501299520bb2b15a63e5a7503 (diff)
downloadframeworks_base-2ba3fec6e0222754d93ed7a491354164d113ad6e.zip
frameworks_base-2ba3fec6e0222754d93ed7a491354164d113ad6e.tar.gz
frameworks_base-2ba3fec6e0222754d93ed7a491354164d113ad6e.tar.bz2
Merge "Support waiting for adb shell am stop-user to complete." into mnc-dev
Diffstat (limited to 'cmds')
-rw-r--r--cmds/am/src/com/android/commands/am/Am.java46
1 files changed, 43 insertions, 3 deletions
diff --git a/cmds/am/src/com/android/commands/am/Am.java b/cmds/am/src/com/android/commands/am/Am.java
index 9f4bc52..d952dfc 100644
--- a/cmds/am/src/com/android/commands/am/Am.java
+++ b/cmds/am/src/com/android/commands/am/Am.java
@@ -26,6 +26,7 @@ import android.app.IActivityController;
import android.app.IActivityManager;
import android.app.IInstrumentationWatcher;
import android.app.Instrumentation;
+import android.app.IStopUserCallback;
import android.app.ProfilerInfo;
import android.app.UiAutomationConnection;
import android.app.usage.ConfigurationStats;
@@ -133,7 +134,7 @@ public class Am extends BaseCommand {
" am to-app-uri [INTENT]\n" +
" am switch-user <USER_ID>\n" +
" am start-user <USER_ID>\n" +
- " am stop-user <USER_ID>\n" +
+ " am stop-user [-w] <USER_ID>\n" +
" am stack start <DISPLAY_ID> <INTENT>\n" +
" am stack movetask <TASK_ID> <STACK_ID> [true|false]\n" +
" am stack resize <STACK_ID> <LEFT,TOP,RIGHT,BOTTOM>\n" +
@@ -257,6 +258,7 @@ public class Am extends BaseCommand {
"\n" +
"am stop-user: stop execution of USER_ID, not allowing it to run any\n" +
" code until a later explicit start or switch to it.\n" +
+ " -w: wait for stop-user to complete.\n" +
"\n" +
"am stack start: start a new activity on <DISPLAY_ID> using <INTENT>.\n" +
"\n" +
@@ -1303,9 +1305,45 @@ public class Am extends BaseCommand {
}
}
+ private static class StopUserCallback extends IStopUserCallback.Stub {
+ private boolean mFinished = false;
+
+ public synchronized void waitForFinish() {
+ try {
+ while (!mFinished) wait();
+ } catch (InterruptedException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ @Override
+ public synchronized void userStopped(int userId) {
+ mFinished = true;
+ notifyAll();
+ }
+
+ @Override
+ public synchronized void userStopAborted(int userId) {
+ mFinished = true;
+ notifyAll();
+ }
+ }
+
private void runStopUser() throws Exception {
- String user = nextArgRequired();
- int res = mAm.stopUser(Integer.parseInt(user), null);
+ boolean wait = false;
+ String opt = null;
+ while ((opt = nextOption()) != null) {
+ if ("-w".equals(opt)) {
+ wait = true;
+ } else {
+ System.err.println("Error: unknown option: " + opt);
+ return;
+ }
+ }
+ int user = Integer.parseInt(nextArgRequired());
+ StopUserCallback callback = wait ? new StopUserCallback() : null;
+
+ int res = mAm.stopUser(user, callback);
if (res != ActivityManager.USER_OP_SUCCESS) {
String txt = "";
switch (res) {
@@ -1317,6 +1355,8 @@ public class Am extends BaseCommand {
break;
}
System.err.println("Switch failed: " + res + txt);
+ } else if (callback != null) {
+ callback.waitForFinish();
}
}