Merge "Fixes switch-user -w command." into rvc-dev am: a0eed34ecb
Change-Id: I36ea212edd7067dd056d3b9560e8eb019eb6fba7
This commit is contained in:
@@ -1763,6 +1763,12 @@ final class ActivityManagerShellCommand extends ShellCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean switchUserAndWaitForComplete(int userId) throws RemoteException {
|
private boolean switchUserAndWaitForComplete(int userId) throws RemoteException {
|
||||||
|
UserInfo currentUser = mInterface.getCurrentUser();
|
||||||
|
if (currentUser != null && userId == currentUser.id) {
|
||||||
|
// Already switched to the correct user, exit early.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Register switch observer.
|
// Register switch observer.
|
||||||
final CountDownLatch switchLatch = new CountDownLatch(1);
|
final CountDownLatch switchLatch = new CountDownLatch(1);
|
||||||
mInterface.registerUserSwitchObserver(
|
mInterface.registerUserSwitchObserver(
|
||||||
@@ -1777,13 +1783,18 @@ final class ActivityManagerShellCommand extends ShellCommand {
|
|||||||
|
|
||||||
// Switch.
|
// Switch.
|
||||||
boolean switched = mInterface.switchUser(userId);
|
boolean switched = mInterface.switchUser(userId);
|
||||||
|
if (!switched) {
|
||||||
|
// Switching failed, don't wait for the user switch observer.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Wait.
|
// Wait.
|
||||||
try {
|
try {
|
||||||
switchLatch.await(USER_OPERATION_TIMEOUT_MS, TimeUnit.MILLISECONDS);
|
switched = switchLatch.await(USER_OPERATION_TIMEOUT_MS, TimeUnit.MILLISECONDS);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
getErrPrintWriter().println("Thread interrupted unexpectedly.");
|
getErrPrintWriter().println("Error: Thread interrupted unexpectedly.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return switched;
|
return switched;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1815,7 +1826,7 @@ final class ActivityManagerShellCommand extends ShellCommand {
|
|||||||
if (switched) {
|
if (switched) {
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
pw.printf("Failed to switch to user %d\n", userId);
|
pw.printf("Error: Failed to switch to user %d\n", userId);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user