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

Commit 61311b3a authored by Beverly's avatar Beverly Committed by Beverly Tai
Browse files

Only startSecondaryService for users that are running

If the user is not running, don't start service
for the user.

Fixes: 399688129
Bug: 296305878
Flag: EXEMPT bugfix
Test: atest UserSwitcherInteractorTest
Test: verify that deleting a user (still) doesn't crash

Change-Id: Iac64575f7033f2c2f5665951993f432f3ae4468c
parent 2723c553
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -157,8 +157,7 @@ class UserSwitcherInteractorTest : SysuiTestCase() {

    @Test
    fun createUserInteractor_nonProcessUser_startsSecondaryService() {
        val userId = Process.myUserHandle().identifier + 1
        whenever(manager.aliveUsers).thenReturn(listOf(createUserInfo(userId, "abc")))
        whenever(manager.isUserRunning(anyInt())).thenReturn(true)

        createUserInteractor(false /* startAsProcessUser */)
        verify(spyContext).startServiceAsUser(any(), any())
@@ -710,7 +709,9 @@ class UserSwitcherInteractorTest : SysuiTestCase() {
    fun userSwitchedBroadcast() {
        testScope.runTest {
            val userInfos = createUserInfos(count = 2, includeGuest = false)
            whenever(manager.aliveUsers).thenReturn(userInfos)
            for (userInfo in userInfos) {
                whenever(manager.isUserRunning(eq(userInfo.id))).thenReturn(true)
            }
            createUserInteractor()
            userRepository.setUserInfos(userInfos)
            userRepository.setSelectedUserInfo(userInfos[0])
@@ -1147,8 +1148,8 @@ class UserSwitcherInteractorTest : SysuiTestCase() {
    }

    @Test
    fun initWithNoAliveUsers() {
        whenever(manager.aliveUsers).thenReturn(listOf())
    fun initWithNoRunningUsers() {
        whenever(manager.isUserRunning(anyInt())).thenReturn(false)
        createUserInteractor()
        verify(spyContext, never()).startServiceAsUser(any(), any())
    }
+2 −2
Original line number Diff line number Diff line
@@ -659,8 +659,8 @@ 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)) {
        // Do not start service for user that isn't running
        if (!manager.isUserRunning(userId)) {
            return
        }