Add a guard on UserController to avoid user switches when not ready.

UserController defines some internal variables (such as
mUserSwitchUiEnabled) which are set by setInitialConfig(), which in
turn is called by ActivityManagerService.systemReady().

Under normal circumstances, UserController.switch() is never called
before setInitialConfig(), but it could through adb (for example, when
calling 'adb shell am switch-user'). In particular,
CtsDevicePolicyManagerTestCases uses switch-user to switch users, and
it retries on failure. So, if the system crashes while it retries,
the next call might happen before setInitialConfig() is called, which
could leave the system in a bad state (for example, if the OEM overrides
config_customUserSwitchUi with true, it might end up in a state where
mTargetUserId is not reset, so the user could never be switched again).

Test: atest CtsDevicePolicyManagerTestCases:com.android.cts.devicepolicy.MixedDeviceOwnerTest
Fixes: 153115123

Change-Id: I9ea2062d32cd2b4f328ca877649a94d670b0b1b1
1 file changed