Move UserController.dispatchOnBeforeUserSwitching to mHandler thread.
In HSUM, during the boot we start the system user in background and the main user in foreground at the same time. After submitting ag/29485765 and ag/29690065 this flow started causing a race condition when UserSwitchObservers were informed about the various stages of the user switch/start. Sometimes system user's dispatchLockedBootComplete was colliding with main user's onBeforeUserSwitching UserSwitchObservers calls and causing a system crash during the boot.
This issue is only visible during the boot with an HSUM build. It doesn't happen during a regular user switch whether the build is HSUM or not.
This CL makes sure onBeforeUserSwitching calls are made on the mHandler thread (Process: system_server, Thread: ActivityManager) as the rest of the UserSwitchObserver calls, by posting the last part of UserController.startUserInternal method to the mHandler. Earlier part still needs to be on the caller's thread since the method needs to return a boolean stating whether the start of the user is successful or not.
Bug: 371468459
Test: atest UserControllerTest
Flag: EXEMPT bugfix
(cherry picked from commit a1d0c42cf07fc68656a398794e8846b886b6f7c2)
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:66a279ee4cc34c0fbbf7d19ae09bf7c2f4816493)
Merged-In: I3b9de74fc74fc586656ea962b4efafc2442cf5d1
Change-Id: I3b9de74fc74fc586656ea962b4efafc2442cf5d1
2 files changed