Merge "Controls UI - Do not clear callbacks on user change" into rvc-dev

This commit is contained in:
Matt Pietal
2020-05-13 00:46:25 +00:00
committed by Android (Google) Code Review
2 changed files with 36 additions and 3 deletions

View File

@@ -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)

View File

@@ -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)
}
}