Make ListingController always listening
The controller will always be listening after it's constructed (except while switching users). In this way, GlobalActionsDialog does not have to wait to get updated information about available services. Also, fixed a small multi user switching issue in CLC. Fixes: 150956595 Test: atest Test: manual after reboot Change-Id: I5aee79a537d577f2fca027495dfce2e426e48ef6
This commit is contained in:
@@ -88,6 +88,8 @@ class ControlsListingControllerImpl @VisibleForTesting constructor(
|
||||
|
||||
init {
|
||||
serviceListing.addCallback(serviceListingCallback)
|
||||
serviceListing.setListening(true)
|
||||
serviceListing.reload()
|
||||
}
|
||||
|
||||
override fun changeUser(newUser: UserHandle) {
|
||||
@@ -95,11 +97,12 @@ class ControlsListingControllerImpl @VisibleForTesting constructor(
|
||||
callbacks.clear()
|
||||
availableServices = emptyList()
|
||||
serviceListing.setListening(false)
|
||||
serviceListing.removeCallback(serviceListingCallback)
|
||||
currentUserId = newUser.identifier
|
||||
val contextForUser = context.createContextAsUser(newUser, 0)
|
||||
serviceListing = serviceListingBuilder(contextForUser)
|
||||
serviceListing.addCallback(serviceListingCallback)
|
||||
serviceListing.setListening(true)
|
||||
serviceListing.reload()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,12 +121,7 @@ class ControlsListingControllerImpl @VisibleForTesting constructor(
|
||||
backgroundExecutor.execute {
|
||||
Log.d(TAG, "Subscribing callback")
|
||||
callbacks.add(listener)
|
||||
if (callbacks.size == 1) {
|
||||
serviceListing.setListening(true)
|
||||
serviceListing.reload()
|
||||
} else {
|
||||
listener.onServicesUpdated(getCurrentServices())
|
||||
}
|
||||
listener.onServicesUpdated(getCurrentServices())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,9 +134,6 @@ class ControlsListingControllerImpl @VisibleForTesting constructor(
|
||||
backgroundExecutor.execute {
|
||||
Log.d(TAG, "Unsubscribing callback")
|
||||
callbacks.remove(listener)
|
||||
if (callbacks.size == 0) {
|
||||
serviceListing.setListening(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,6 @@ import com.android.systemui.util.concurrency.FakeExecutor
|
||||
import com.android.systemui.util.time.FakeSystemClock
|
||||
import org.junit.After
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
@@ -38,6 +37,7 @@ import org.mockito.ArgumentCaptor
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito
|
||||
import org.mockito.Mockito.`when`
|
||||
import org.mockito.Mockito.inOrder
|
||||
import org.mockito.Mockito.never
|
||||
import org.mockito.Mockito.reset
|
||||
import org.mockito.Mockito.verify
|
||||
@@ -97,75 +97,19 @@ class ControlsListingControllerImplTest : SysuiTestCase() {
|
||||
executor.runAllReady()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testInitialStateListening() {
|
||||
verify(mockSL).setListening(true)
|
||||
verify(mockSL).reload()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testStartsOnUser() {
|
||||
assertEquals(user, controller.currentUserId)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testNoServices_notListening() {
|
||||
assertTrue(controller.getCurrentServices().isEmpty())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testStartListening_onFirstCallback() {
|
||||
controller.addCallback(mockCallback)
|
||||
executor.runAllReady()
|
||||
|
||||
verify(mockSL).setListening(true)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testStartListening_onlyOnce() {
|
||||
controller.addCallback(mockCallback)
|
||||
controller.addCallback(mockCallbackOther)
|
||||
|
||||
executor.runAllReady()
|
||||
|
||||
verify(mockSL).setListening(true)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testStopListening_callbackRemoved() {
|
||||
controller.addCallback(mockCallback)
|
||||
|
||||
executor.runAllReady()
|
||||
|
||||
controller.removeCallback(mockCallback)
|
||||
|
||||
executor.runAllReady()
|
||||
|
||||
verify(mockSL).setListening(false)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testStopListening_notWhileRemainingCallbacks() {
|
||||
controller.addCallback(mockCallback)
|
||||
controller.addCallback(mockCallbackOther)
|
||||
|
||||
executor.runAllReady()
|
||||
|
||||
controller.removeCallback(mockCallback)
|
||||
|
||||
executor.runAllReady()
|
||||
|
||||
verify(mockSL, never()).setListening(false)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testReloadOnFirstCallbackAdded() {
|
||||
controller.addCallback(mockCallback)
|
||||
executor.runAllReady()
|
||||
|
||||
verify(mockSL).reload()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCallbackCalledWhenAdded() {
|
||||
`when`(mockSL.reload()).then {
|
||||
serviceListingCallbackCaptor.value.onServicesReloaded(emptyList())
|
||||
}
|
||||
|
||||
controller.addCallback(mockCallback)
|
||||
executor.runAllReady()
|
||||
verify(mockCallback).onServicesUpdated(any())
|
||||
@@ -209,5 +153,11 @@ class ControlsListingControllerImplTest : SysuiTestCase() {
|
||||
controller.changeUser(UserHandle.of(otherUser))
|
||||
executor.runAllReady()
|
||||
assertEquals(otherUser, controller.currentUserId)
|
||||
|
||||
val inOrder = inOrder(mockSL)
|
||||
inOrder.verify(mockSL).setListening(false)
|
||||
inOrder.verify(mockSL).addCallback(any()) // We add a callback because we replaced the SL
|
||||
inOrder.verify(mockSL).setListening(true)
|
||||
inOrder.verify(mockSL).reload()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user