From c01499bd24453ce26aad556753df2edd56f70f1d Mon Sep 17 00:00:00 2001 From: Matt Pietal Date: Tue, 15 Mar 2022 14:35:00 -0400 Subject: [PATCH] Use new DevicePolicyManager#logoutUser() methods This replaces the series of steps (that were easy to get wrong) required to properly logout and switch users. Fixes: 215583276 Test: manual Change-Id: I2d8c34f184a72fdea71dcf549d1a31133a5155ec --- core/java/android/app/ActivityManager.java | 17 ----------------- .../globalactions/GlobalActionsDialogLite.java | 8 +------- .../statusbar/KeyguardIndicationController.java | 8 +------- .../policy/UserSwitcherController.java | 8 -------- 4 files changed, 2 insertions(+), 39 deletions(-) diff --git a/core/java/android/app/ActivityManager.java b/core/java/android/app/ActivityManager.java index 9f1510526bae8..89eb6dd43fdf2 100644 --- a/core/java/android/app/ActivityManager.java +++ b/core/java/android/app/ActivityManager.java @@ -4354,23 +4354,6 @@ public class ActivityManager { } } - /** - * Logs out current current foreground user by switching to the system user and stopping the - * user being switched from. - * @hide - */ - public static void logoutCurrentUser() { - int currentUser = ActivityManager.getCurrentUser(); - if (currentUser != UserHandle.USER_SYSTEM) { - try { - getService().switchUser(UserHandle.USER_SYSTEM); - getService().stopUser(currentUser, /* force= */ false, null); - } catch (RemoteException e) { - e.rethrowFromSystemServer(); - } - } - } - /** * Stops the given {@code userId}. * diff --git a/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialogLite.java b/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialogLite.java index af553c7443117..acb080a2eaaab 100644 --- a/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialogLite.java +++ b/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialogLite.java @@ -1067,13 +1067,7 @@ public class GlobalActionsDialogLite implements DialogInterface.OnDismissListene // Add a little delay before executing, to give the dialog a chance to go away before // switching user mHandler.postDelayed(() -> { - try { - int currentUserId = getCurrentUser().id; - mIActivityManager.switchUser(UserHandle.USER_SYSTEM); - mIActivityManager.stopUser(currentUserId, true /*force*/, null); - } catch (RemoteException re) { - Log.e(TAG, "Couldn't logout user " + re); - } + mDevicePolicyManager.logoutUser(); }, mDialogPressDelay); } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java b/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java index 16ddb0a7e1a82..6bca351c127ee 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java @@ -575,13 +575,7 @@ public class KeyguardIndicationController { return; } int currentUserId = KeyguardUpdateMonitor.getCurrentUser(); - try { - mIActivityManager.switchUser(UserHandle.USER_SYSTEM); - mIActivityManager.stopUser(currentUserId, true /* force */, - null); - } catch (RemoteException re) { - Log.e(TAG, "Failed to logout user", re); - } + mDevicePolicyManager.logoutUser(); }) .build(), false); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/UserSwitcherController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/UserSwitcherController.java index 763f0417cac81..4cb0a94e25851 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/UserSwitcherController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/UserSwitcherController.java @@ -447,14 +447,6 @@ public class UserSwitcherController implements Dumpable { mResumeUserOnGuestLogout = resume; } - public void logoutCurrentUser() { - int currentUser = mUserTracker.getUserId(); - if (currentUser != UserHandle.USER_SYSTEM) { - pauseRefreshUsers(); - ActivityManager.logoutCurrentUser(); - } - } - /** * Returns whether the current user is a system user. */