Improved 'am switch' to handle errors. am: 2d950c12b5
Change-Id: I70e41611749d9d2f83896188d05dbbd5cd298a12
This commit is contained in:
@@ -1709,7 +1709,7 @@ final class ActivityManagerShellCommand extends ShellCommand {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void switchUserAndWaitForComplete(int userId) throws RemoteException {
|
private boolean switchUserAndWaitForComplete(int userId) throws RemoteException {
|
||||||
// Register switch observer.
|
// Register switch observer.
|
||||||
final CountDownLatch switchLatch = new CountDownLatch(1);
|
final CountDownLatch switchLatch = new CountDownLatch(1);
|
||||||
mInterface.registerUserSwitchObserver(
|
mInterface.registerUserSwitchObserver(
|
||||||
@@ -1723,7 +1723,7 @@ final class ActivityManagerShellCommand extends ShellCommand {
|
|||||||
}, ActivityManagerShellCommand.class.getName());
|
}, ActivityManagerShellCommand.class.getName());
|
||||||
|
|
||||||
// Switch.
|
// Switch.
|
||||||
mInterface.switchUser(userId);
|
boolean switched = mInterface.switchUser(userId);
|
||||||
|
|
||||||
// Wait.
|
// Wait.
|
||||||
try {
|
try {
|
||||||
@@ -1731,6 +1731,7 @@ final class ActivityManagerShellCommand extends ShellCommand {
|
|||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
getErrPrintWriter().println("Thread interrupted unexpectedly.");
|
getErrPrintWriter().println("Thread interrupted unexpectedly.");
|
||||||
}
|
}
|
||||||
|
return switched;
|
||||||
}
|
}
|
||||||
|
|
||||||
int runSwitchUser(PrintWriter pw) throws RemoteException {
|
int runSwitchUser(PrintWriter pw) throws RemoteException {
|
||||||
@@ -1752,12 +1753,18 @@ final class ActivityManagerShellCommand extends ShellCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int userId = Integer.parseInt(getNextArgRequired());
|
int userId = Integer.parseInt(getNextArgRequired());
|
||||||
|
boolean switched;
|
||||||
if (wait) {
|
if (wait) {
|
||||||
switchUserAndWaitForComplete(userId);
|
switched = switchUserAndWaitForComplete(userId);
|
||||||
} else {
|
} else {
|
||||||
mInterface.switchUser(userId);
|
switched = mInterface.switchUser(userId);
|
||||||
|
}
|
||||||
|
if (switched) {
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
pw.printf("Failed to switch to user %d\n", userId);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int runGetCurrentUser(PrintWriter pw) throws RemoteException {
|
int runGetCurrentUser(PrintWriter pw) throws RemoteException {
|
||||||
|
|||||||
Reference in New Issue
Block a user