Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2d950c12 authored by Felipe Leme's avatar Felipe Leme Committed by Jovana Knezevic
Browse files

Improved 'am switch' to handle errors.

Bug: 146207078
Test: adb shell am switch-user 42 ; echo $?

Change-Id: I005c76652be1fd0908f5c2b40e2513362b5ce5ac
Merged-In: I005c76652be1fd0908f5c2b40e2513362b5ce5ac
parent fddf07e8
Loading
Loading
Loading
Loading
+12 −5
Original line number Diff line number Diff line
@@ -1709,7 +1709,7 @@ final class ActivityManagerShellCommand extends ShellCommand {
        return 0;
    }

    private void switchUserAndWaitForComplete(int userId) throws RemoteException {
    private boolean switchUserAndWaitForComplete(int userId) throws RemoteException {
        // Register switch observer.
        final CountDownLatch switchLatch = new CountDownLatch(1);
        mInterface.registerUserSwitchObserver(
@@ -1723,7 +1723,7 @@ final class ActivityManagerShellCommand extends ShellCommand {
                }, ActivityManagerShellCommand.class.getName());

        // Switch.
        mInterface.switchUser(userId);
        boolean switched = mInterface.switchUser(userId);

        // Wait.
        try {
@@ -1731,6 +1731,7 @@ final class ActivityManagerShellCommand extends ShellCommand {
        } catch (InterruptedException e) {
            getErrPrintWriter().println("Thread interrupted unexpectedly.");
        }
        return switched;
    }

    int runSwitchUser(PrintWriter pw) throws RemoteException {
@@ -1752,12 +1753,18 @@ final class ActivityManagerShellCommand extends ShellCommand {
        }

        int userId = Integer.parseInt(getNextArgRequired());
        boolean switched;
        if (wait) {
            switchUserAndWaitForComplete(userId);
            switched = switchUserAndWaitForComplete(userId);
        } 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;
        }
    }

    int runGetCurrentUser(PrintWriter pw) throws RemoteException {