diff options
| author | 2022-08-12 16:19:53 +0000 | |
|---|---|---|
| committer | 2022-08-12 16:19:53 +0000 | |
| commit | cb8ec0cf4d2bfcc4f21d68a43c900f214e34ec5b (patch) | |
| tree | 9e1419427063b9c9bab124a4f6c4bafc643d14e1 | |
| parent | fbd33daf1059a69fd9171a5d40f8b3d46370ec27 (diff) | |
| parent | 0c54aa175ed52c6c30a758bb527987513a308893 (diff) | |
Merge "Unregister user switch observer in ActivityManagerShellCommand."
| -rw-r--r-- | services/core/java/com/android/server/am/ActivityManagerShellCommand.java | 50 |
1 files changed, 28 insertions, 22 deletions
diff --git a/services/core/java/com/android/server/am/ActivityManagerShellCommand.java b/services/core/java/com/android/server/am/ActivityManagerShellCommand.java index dbabe99c79d5..4bbfa3eec67d 100644 --- a/services/core/java/com/android/server/am/ActivityManagerShellCommand.java +++ b/services/core/java/com/android/server/am/ActivityManagerShellCommand.java @@ -51,6 +51,7 @@ import android.app.IActivityManager; import android.app.IActivityTaskManager; import android.app.IStopUserCallback; import android.app.IUidObserver; +import android.app.IUserSwitchObserver; import android.app.KeyguardManager; import android.app.ProfilerInfo; import android.app.RemoteServiceException.CrashedByAdbException; @@ -1951,31 +1952,36 @@ final class ActivityManagerShellCommand extends ShellCommand { // Register switch observer. final CountDownLatch switchLatch = new CountDownLatch(1); - mInterface.registerUserSwitchObserver( - new UserSwitchObserver() { - @Override - public void onUserSwitchComplete(int newUserId) { - if (userId == newUserId) { - switchLatch.countDown(); - } - } - }, ActivityManagerShellCommand.class.getName()); + final IUserSwitchObserver userSwitchObserver = new UserSwitchObserver() { + @Override + public void onUserSwitchComplete(int newUserId) { + if (userId == newUserId) { + switchLatch.countDown(); + } + } + }; + try { + mInterface.registerUserSwitchObserver(userSwitchObserver, + ActivityManagerShellCommand.class.getName()); - // Switch. - boolean switched = mInterface.switchUser(userId); - if (!switched) { - // Switching failed, don't wait for the user switch observer. - return false; - } + // Switch. + boolean switched = mInterface.switchUser(userId); + if (!switched) { + // Switching failed, don't wait for the user switch observer. + return false; + } - // Wait. - try { - switched = switchLatch.await(USER_OPERATION_TIMEOUT_MS, TimeUnit.MILLISECONDS); - } catch (InterruptedException e) { - getErrPrintWriter().println("Error: Thread interrupted unexpectedly."); - } + // Wait. + try { + switched = switchLatch.await(USER_OPERATION_TIMEOUT_MS, TimeUnit.MILLISECONDS); + } catch (InterruptedException e) { + getErrPrintWriter().println("Error: Thread interrupted unexpectedly."); + } - return switched; + return switched; + } finally { + mInterface.unregisterUserSwitchObserver(userSwitchObserver); + } } int runSwitchUser(PrintWriter pw) throws RemoteException { |