Skip to content
Commit 85da667c authored by Yasin Kilicdere's avatar Yasin Kilicdere
Browse files

Prevent removing the current user or the target user of user switch.

UserController.switchUser and UserController.startUserInternal both
share a validation check logic but the validation code is duplicated.

When switching a user, switchUser runs the validation checks, and if
they pass, it sets mTargetUserId and starts a call chain that
eventually calls startUserInternal.

Currently the validation checks are in sync, but if some other
validation would be added to startUserInternal but not in switchUser,
then even though switchUser returns true, it can fail asynchronously
while starting the user in startUserInternal. So it's not safe to
remove the current user after starting a switch.

Also currently it is possible to remove the target user during an
ongoing switch, which is also wrong.

This CL prevents removing the current user, or both current and target
users in case there is an ongoing user switch.
This CL also changes exiting tests to work with these new rules and
also adds new tests for coverage.

Bug: 264667155
Test: atest FrameworksServicesTests:com.android.server.pm.UserLifecycleStressTest#switchToExistingGuestAndStartOverStressTest
Test: atest FrameworksMockingServicesTests:com.android.server.pm.UserManagerServiceTest#testGetCurrentAndTargetUserIds
Test: atest FrameworksServicesTests:com.android.server.pm.UserManagerTest#testRemoveUserShouldNotRemoveCurrentUser
Test: atest FrameworksServicesTests:com.android.server.pm.UserManagerTest#testRemoveUserShouldNotRemoveCurrentUser_DuringUserSwitch
Test: atest FrameworksServicesTests:com.android.server.pm.UserManagerTest#testRemoveUserShouldNotRemoveTargetUser_DuringUserSwitch
Test: atest FrameworksServicesTests:com.android.server.pm.UserManagerTest#testRemoveUserWhenPossible_currentUserSetEphemeral_duringUserSwitch
Test: atest FrameworksServicesTests:com.android.server.pm.UserManagerTest#testRemoveUserWhenPossible_targetUserSetEphemeral_duringUserSwitch
Change-Id: I8db44b6bbc3c1c57b9bebe0d27be068ea2b654ed
parent c1de6541
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment