summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Alejandro Nijamkin <nijamkin@google.com> 2022-10-31 09:04:09 -0700
committer Alejandro Nijamkin <nijamkin@google.com> 2022-10-31 09:12:16 -0700
commit8d6a7a10e6b64c6b84fdf560f2840d1c43a49870 (patch)
tree9469762bbc8ee1a797eb540a123e4f9c8cd79590
parent08dbdfc508c33f39b14fec498416697bdd0e1a19 (diff)
Blind fix for user switcher instant crash.
There is an instant crash stemming from a premature optimization done in the newly refactored code for the user switcher system. I am unable to reproduce this locally, so this is a blind fix. What follows is the rationale behind it. It appears to be a race condition. UserRepositoryImpl#isSimpleUserSwitcher asserts that we have loaded the settings but the settings are only loaded in a background coroutine job that's kicked off when the repository class is instantiated. From the looks of it, the former path is triggered before the latter is. The fix, therefore, is to always make sure that there is a non-null value for user settings. This is achieved in this CL using an expensive runBlocking call at class instantiation time. Delaying that was an optimization that attempted to do better than the original pre-refactor code, where the same approach is taken (settings are accessed on the main thread in a blocking fashion). Fix: 255916597, 254764031 Test: unable to reproduce locally but made sure that, with the new changes, there is no instant crash nor a crash when entering the full-screen user switcher on one of the affected device models - used adb reboot to trigger restarts. Change-Id: I970a416ae7eaf2d2a366b12b3d7c6b98ebc52011
-rw-r--r--packages/SystemUI/src/com/android/systemui/user/data/repository/UserRepository.kt5
1 files changed, 3 insertions, 2 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/user/data/repository/UserRepository.kt b/packages/SystemUI/src/com/android/systemui/user/data/repository/UserRepository.kt
index b16dc5403a57..6a2326036ec0 100644
--- a/packages/SystemUI/src/com/android/systemui/user/data/repository/UserRepository.kt
+++ b/packages/SystemUI/src/com/android/systemui/user/data/repository/UserRepository.kt
@@ -62,6 +62,7 @@ import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.launch
+import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
/**
@@ -136,7 +137,7 @@ constructor(
private val isNewImpl: Boolean
get() = !featureFlags.isEnabled(Flags.USER_INTERACTOR_AND_REPO_USE_CONTROLLER)
- private val _userSwitcherSettings = MutableStateFlow<UserSwitcherSettingsModel?>(null)
+ private val _userSwitcherSettings = MutableStateFlow(runBlocking { getSettings() })
override val userSwitcherSettings: Flow<UserSwitcherSettingsModel> =
_userSwitcherSettings.asStateFlow().filterNotNull()
@@ -235,7 +236,7 @@ constructor(
}
override fun isSimpleUserSwitcher(): Boolean {
- return checkNotNull(_userSwitcherSettings.value?.isSimpleUserSwitcher)
+ return _userSwitcherSettings.value.isSimpleUserSwitcher
}
private fun observeSelectedUser() {