From 3508673578d1fd0050586c3f0b630fb3d52f8e97 Mon Sep 17 00:00:00 2001 From: Fabian Kozynski Date: Tue, 10 Mar 2020 14:25:32 -0400 Subject: [PATCH] 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 --- .../ControlsListingControllerImpl.kt | 15 ++-- .../ControlsListingControllerImplTest.kt | 76 ++++--------------- 2 files changed, 18 insertions(+), 73 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/controls/management/ControlsListingControllerImpl.kt b/packages/SystemUI/src/com/android/systemui/controls/management/ControlsListingControllerImpl.kt index 9b108cf3e34ba..94487e5a584a1 100644 --- a/packages/SystemUI/src/com/android/systemui/controls/management/ControlsListingControllerImpl.kt +++ b/packages/SystemUI/src/com/android/systemui/controls/management/ControlsListingControllerImpl.kt @@ -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) - } } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/controls/management/ControlsListingControllerImplTest.kt b/packages/SystemUI/tests/src/com/android/systemui/controls/management/ControlsListingControllerImplTest.kt index 85e937e40acd4..13a77083255c6 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/controls/management/ControlsListingControllerImplTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/controls/management/ControlsListingControllerImplTest.kt @@ -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() } } \ No newline at end of file