Merge "Prevent Sysui crash when user is deleted." into udc-qpr-dev
diff --git a/packages/SystemUI/src/com/android/systemui/user/domain/interactor/UserInteractor.kt b/packages/SystemUI/src/com/android/systemui/user/domain/interactor/UserInteractor.kt
index 4d506f0..69e51294 100644
--- a/packages/SystemUI/src/com/android/systemui/user/domain/interactor/UserInteractor.kt
+++ b/packages/SystemUI/src/com/android/systemui/user/domain/interactor/UserInteractor.kt
@@ -641,6 +641,11 @@
}
private fun restartSecondaryService(@UserIdInt userId: Int) {
+ // Do not start service for user that is marked for deletion.
+ if (!manager.aliveUsers.map { it.id }.contains(userId)) {
+ return
+ }
+
val intent = Intent(applicationContext, SystemUISecondaryUserService::class.java)
// Disconnect from the old secondary user's service
val secondaryUserId = repository.secondaryUserId
@@ -654,6 +659,7 @@
// Connect to the new secondary user's service (purely to ensure that a persistent
// SystemUI application is created for that user)
+
if (userId != Process.myUserHandle().identifier) {
applicationContext.startServiceAsUser(
intent,
diff --git a/packages/SystemUI/tests/src/com/android/systemui/user/domain/interactor/UserInteractorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/user/domain/interactor/UserInteractorTest.kt
index 5a54aff..60dcdae 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/user/domain/interactor/UserInteractorTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/user/domain/interactor/UserInteractorTest.kt
@@ -155,6 +155,9 @@
@Test
fun createUserInteractor_nonProcessUser_startsSecondaryService() {
+ val userId = Process.myUserHandle().identifier + 1
+ whenever(manager.aliveUsers).thenReturn(listOf(createUserInfo(userId, "abc")))
+
createUserInteractor(false /* startAsProcessUser */)
verify(spyContext).startServiceAsUser(any(), any())
}
@@ -655,9 +658,10 @@
@Test
fun userSwitchedBroadcast() {
- createUserInteractor()
testScope.runTest {
val userInfos = createUserInfos(count = 2, includeGuest = false)
+ whenever(manager.aliveUsers).thenReturn(userInfos)
+ createUserInteractor()
userRepository.setUserInfos(userInfos)
userRepository.setSelectedUserInfo(userInfos[0])
userRepository.setSettings(UserSwitcherSettingsModel(isUserSwitcherEnabled = true))
@@ -985,6 +989,13 @@
}
}
+ @Test
+ fun initWithNoAliveUsers() {
+ whenever(manager.aliveUsers).thenReturn(listOf())
+ createUserInteractor()
+ verify(spyContext, never()).startServiceAsUser(any(), any())
+ }
+
private fun assertUsers(
models: List<UserModel>?,
count: Int,