summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Nikhil Kumar <nykkumar@google.com> 2023-11-01 15:44:01 +0000
committer Nikhil Kumar <nykkumar@google.com> 2023-11-13 16:58:11 +0000
commit1e3d4f48ab24593ec401ccbc968efbc0a82fea40 (patch)
tree0c0957e64aef248e88203ceb2ebd9152831ae4e0
parentcac4682a8de8168f0963fb8bd00c362d7d72d854 (diff)
Refactored switchUSer to handle user switch back to the current user
The existing implementation of user switching puts subsequent user switches into a queue if there is already a user switch in progress. For example, if the current user is A and there is a user switch sequence to switch to user B and then to user C, the UserController#switchUser method will put the user switch to C into a pending user switch list and perform it once the existing user switch to B is finished. However, if the sequence is to switch from user A to user B and then back to user A, and when switch to user A reaches the UserController#switchUser method before the switch to user B is completed, the method will think that the current user is A and that there is no need to switch to user A, and will therefore skip that switch. The refactored code handles this scenario by adding an extra condition which additionally verifies that there are no further switches scheduled in case the target user is equal to the current user and the switch is going to be skipped. Bug: 303743201 Test: tested manually with switch user scenario current user is 0 switch to user 10 and then switch back to user 0. Change-Id: Ia40cfacbee6fc174c90db8e3687838ae01e2858b Merged-In: Ia40cfacbee6fc174c90db8e3687838ae01e2858b
-rw-r--r--services/core/java/com/android/server/am/UserController.java34
1 files changed, 18 insertions, 16 deletions
diff --git a/services/core/java/com/android/server/am/UserController.java b/services/core/java/com/android/server/am/UserController.java
index 99c2f8a5cc56..a73fdee2e050 100644
--- a/services/core/java/com/android/server/am/UserController.java
+++ b/services/core/java/com/android/server/am/UserController.java
@@ -1928,24 +1928,26 @@ class UserController implements Handler.Callback {
EventLog.writeEvent(EventLogTags.UC_SWITCH_USER, targetUserId);
int currentUserId = getCurrentUserId();
UserInfo targetUserInfo = getUserInfo(targetUserId);
- if (targetUserId == currentUserId) {
- Slogf.i(TAG, "user #" + targetUserId + " is already the current user");
- return true;
- }
- if (targetUserInfo == null) {
- Slogf.w(TAG, "No user info for user #" + targetUserId);
- return false;
- }
- if (!targetUserInfo.supportsSwitchTo()) {
- Slogf.w(TAG, "Cannot switch to User #" + targetUserId + ": not supported");
- return false;
- }
- if (FactoryResetter.isFactoryResetting()) {
- Slogf.w(TAG, "Cannot switch to User #" + targetUserId + ": factory reset in progress");
- return false;
- }
boolean userSwitchUiEnabled;
synchronized (mLock) {
+ if (targetUserId == currentUserId && mTargetUserId == UserHandle.USER_NULL) {
+ Slogf.i(TAG, "user #" + targetUserId + " is already the current user");
+ return true;
+ }
+ if (targetUserInfo == null) {
+ Slogf.w(TAG, "No user info for user #" + targetUserId);
+ return false;
+ }
+ if (!targetUserInfo.supportsSwitchTo()) {
+ Slogf.w(TAG, "Cannot switch to User #" + targetUserId + ": not supported");
+ return false;
+ }
+ if (FactoryResetter.isFactoryResetting()) {
+ Slogf.w(TAG, "Cannot switch to User #" + targetUserId
+ + ": factory reset in progress");
+ return false;
+ }
+
if (!mInitialized) {
Slogf.e(TAG, "Cannot switch to User #" + targetUserId
+ ": UserController not ready yet");