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

Commit da734e4c authored by Matt Pietal's avatar Matt Pietal Committed by Automerger Merge Worker
Browse files

Merge "Controls UI - Do not clear callbacks on user change" into rvc-dev am: 735b2fd3

Change-Id: I3afa56082a4eb2d56e083fbe42b550f30c74661a
parents b08c0e48 735b2fd3
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -106,9 +106,15 @@ class ControlsListingControllerImpl @VisibleForTesting constructor(

    override fun changeUser(newUser: UserHandle) {
        backgroundExecutor.execute {
            callbacks.clear()
            availableServices = emptyList()
            serviceListing.setListening(false)

            // Notify all callbacks in order to clear their existing state prior to attaching
            // a new listener
            availableServices = emptyList()
            callbacks.forEach {
                it.onServicesUpdated(emptyList())
            }

            currentUserId = newUser.identifier
            val contextForUser = context.createContextAsUser(newUser, 0)
            serviceListing = serviceListingBuilder(contextForUser)
+28 −1
Original line number Diff line number Diff line
@@ -177,4 +177,31 @@ class ControlsListingControllerImplTest : SysuiTestCase() {
        inOrder.verify(mockSL).setListening(true)
        inOrder.verify(mockSL).reload()
    }

    @Test
    fun testChangeUserResetsExistingCallbackServices() {
        val list = listOf(serviceInfo)
        controller.addCallback(mockCallback)

        @Suppress("unchecked_cast")
        val captor: ArgumentCaptor<List<ControlsServiceInfo>> =
                ArgumentCaptor.forClass(List::class.java)
                        as ArgumentCaptor<List<ControlsServiceInfo>>
        executor.runAllReady()
        reset(mockCallback)

        serviceListingCallbackCaptor.value.onServicesReloaded(list)

        executor.runAllReady()
        verify(mockCallback).onServicesUpdated(capture(captor))
        assertEquals(1, captor.value.size)

        reset(mockCallback)
        controller.changeUser(UserHandle.of(otherUser))
        executor.runAllReady()
        assertEquals(otherUser, controller.currentUserId)

        verify(mockCallback).onServicesUpdated(capture(captor))
        assertEquals(0, captor.value.size)
    }
}