Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2f75500d authored by Aaron Liu's avatar Aaron Liu Committed by Android (Google) Code Review
Browse files

Merge "Prevent Sysui crash when user is deleted." into udc-qpr-dev

parents 1c8c0324 dcfa465f
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -641,6 +641,11 @@ constructor(
    }

    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 @@ constructor(

        // 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,
+12 −1
Original line number Diff line number Diff line
@@ -155,6 +155,9 @@ class UserInteractorTest : SysuiTestCase() {

    @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 @@ class UserInteractorTest : SysuiTestCase() {

    @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 @@ class UserInteractorTest : SysuiTestCase() {
        }
    }

    @Test
    fun initWithNoAliveUsers() {
        whenever(manager.aliveUsers).thenReturn(listOf())
        createUserInteractor()
        verify(spyContext, never()).startServiceAsUser(any(), any())
    }

    private fun assertUsers(
        models: List<UserModel>?,
        count: Int,