Loading packages/SystemUI/src/com/android/systemui/controls/controller/ControlsBindingControllerImpl.kt +2 −0 Original line number Diff line number Diff line Loading @@ -255,12 +255,14 @@ open class ControlsBindingControllerImpl @Inject constructor( override fun onError(token: IBinder, s: String) { hasError = true _loadCancelInternal = {} currentProvider?.cancelLoadTimeout() backgroundExecutor.execute(OnLoadErrorRunnable(token, s, callback)) } override fun onComplete(token: IBinder) { _loadCancelInternal = {} if (!hasError) { currentProvider?.cancelLoadTimeout() backgroundExecutor.execute(OnLoadRunnable(token, loadedControls, callback)) } } Loading packages/SystemUI/src/com/android/systemui/controls/controller/ControlsProviderLifecycleManager.kt +5 −0 Original line number Diff line number Diff line Loading @@ -228,6 +228,11 @@ class ControlsProviderLifecycleManager( invokeOrQueue({ load(subscriber) }, Message.Load(subscriber)) } fun cancelLoadTimeout() { onLoadCanceller?.run() onLoadCanceller = null } /** * Request a subscription to the [Publisher] returned by [ControlsProviderService.publisherFor] * Loading packages/SystemUI/tests/src/com/android/systemui/controls/controller/ControlsBindingControllerImplTest.kt +39 −1 Original line number Diff line number Diff line Loading @@ -63,7 +63,7 @@ class ControlsBindingControllerImplTest : SysuiTestCase() { private lateinit var mockControlsController: ControlsController @Captor private lateinit var subscriberCaptor: ArgumentCaptor<IControlsSubscriber> private lateinit var subscriberCaptor: ArgumentCaptor<IControlsSubscriber.Stub> @Captor private lateinit var loadSubscriberCaptor: ArgumentCaptor<IControlsSubscriber.Stub> Loading Loading @@ -148,6 +148,44 @@ class ControlsBindingControllerImplTest : SysuiTestCase() { verify(subscription, never()).cancel() } @Test fun testLoad_onCompleteRemovesTimeout() { val callback = object : ControlsBindingController.LoadCallback { override fun error(message: String) {} override fun accept(t: List<Control>) {} } val subscription = mock(IControlsSubscription::class.java) val canceller = controller.bindAndLoad(TEST_COMPONENT_NAME_1, callback) verify(providers[0]).maybeBindAndLoad(capture(subscriberCaptor)) val b = Binder() subscriberCaptor.value.onSubscribe(b, subscription) subscriberCaptor.value.onComplete(b) verify(providers[0]).cancelLoadTimeout() } @Test fun testLoad_onErrorRemovesTimeout() { val callback = object : ControlsBindingController.LoadCallback { override fun error(message: String) {} override fun accept(t: List<Control>) {} } val subscription = mock(IControlsSubscription::class.java) val canceller = controller.bindAndLoad(TEST_COMPONENT_NAME_1, callback) verify(providers[0]).maybeBindAndLoad(capture(subscriberCaptor)) val b = Binder() subscriberCaptor.value.onSubscribe(b, subscription) subscriberCaptor.value.onError(b, "") verify(providers[0]).cancelLoadTimeout() } @Test fun testBindAndLoad_noCancelAfterOnError() { val callback = object : ControlsBindingController.LoadCallback { Loading packages/SystemUI/tests/src/com/android/systemui/controls/controller/ControlsProviderLifecycleManagerTest.kt +14 −0 Original line number Diff line number Diff line Loading @@ -43,6 +43,7 @@ import org.mockito.ArgumentMatchers.eq import org.mockito.Captor import org.mockito.Mock import org.mockito.Mockito.`when` import org.mockito.Mockito.never import org.mockito.Mockito.verify import org.mockito.MockitoAnnotations Loading Loading @@ -142,6 +143,19 @@ class ControlsProviderLifecycleManagerTest : SysuiTestCase() { verify(subscriberService).onError(any(), anyString()) } @Test fun testMaybeBindAndLoad_timeoutCancelled() { manager.maybeBindAndLoad(subscriberService) executor.runAllReady() manager.cancelLoadTimeout() executor.advanceClockToLast() executor.runAllReady() verify(subscriberService, never()).onError(any(), anyString()) } @Test fun testMaybeBindAndSubscribe() { val list = listOf("TEST_ID") Loading Loading
packages/SystemUI/src/com/android/systemui/controls/controller/ControlsBindingControllerImpl.kt +2 −0 Original line number Diff line number Diff line Loading @@ -255,12 +255,14 @@ open class ControlsBindingControllerImpl @Inject constructor( override fun onError(token: IBinder, s: String) { hasError = true _loadCancelInternal = {} currentProvider?.cancelLoadTimeout() backgroundExecutor.execute(OnLoadErrorRunnable(token, s, callback)) } override fun onComplete(token: IBinder) { _loadCancelInternal = {} if (!hasError) { currentProvider?.cancelLoadTimeout() backgroundExecutor.execute(OnLoadRunnable(token, loadedControls, callback)) } } Loading
packages/SystemUI/src/com/android/systemui/controls/controller/ControlsProviderLifecycleManager.kt +5 −0 Original line number Diff line number Diff line Loading @@ -228,6 +228,11 @@ class ControlsProviderLifecycleManager( invokeOrQueue({ load(subscriber) }, Message.Load(subscriber)) } fun cancelLoadTimeout() { onLoadCanceller?.run() onLoadCanceller = null } /** * Request a subscription to the [Publisher] returned by [ControlsProviderService.publisherFor] * Loading
packages/SystemUI/tests/src/com/android/systemui/controls/controller/ControlsBindingControllerImplTest.kt +39 −1 Original line number Diff line number Diff line Loading @@ -63,7 +63,7 @@ class ControlsBindingControllerImplTest : SysuiTestCase() { private lateinit var mockControlsController: ControlsController @Captor private lateinit var subscriberCaptor: ArgumentCaptor<IControlsSubscriber> private lateinit var subscriberCaptor: ArgumentCaptor<IControlsSubscriber.Stub> @Captor private lateinit var loadSubscriberCaptor: ArgumentCaptor<IControlsSubscriber.Stub> Loading Loading @@ -148,6 +148,44 @@ class ControlsBindingControllerImplTest : SysuiTestCase() { verify(subscription, never()).cancel() } @Test fun testLoad_onCompleteRemovesTimeout() { val callback = object : ControlsBindingController.LoadCallback { override fun error(message: String) {} override fun accept(t: List<Control>) {} } val subscription = mock(IControlsSubscription::class.java) val canceller = controller.bindAndLoad(TEST_COMPONENT_NAME_1, callback) verify(providers[0]).maybeBindAndLoad(capture(subscriberCaptor)) val b = Binder() subscriberCaptor.value.onSubscribe(b, subscription) subscriberCaptor.value.onComplete(b) verify(providers[0]).cancelLoadTimeout() } @Test fun testLoad_onErrorRemovesTimeout() { val callback = object : ControlsBindingController.LoadCallback { override fun error(message: String) {} override fun accept(t: List<Control>) {} } val subscription = mock(IControlsSubscription::class.java) val canceller = controller.bindAndLoad(TEST_COMPONENT_NAME_1, callback) verify(providers[0]).maybeBindAndLoad(capture(subscriberCaptor)) val b = Binder() subscriberCaptor.value.onSubscribe(b, subscription) subscriberCaptor.value.onError(b, "") verify(providers[0]).cancelLoadTimeout() } @Test fun testBindAndLoad_noCancelAfterOnError() { val callback = object : ControlsBindingController.LoadCallback { Loading
packages/SystemUI/tests/src/com/android/systemui/controls/controller/ControlsProviderLifecycleManagerTest.kt +14 −0 Original line number Diff line number Diff line Loading @@ -43,6 +43,7 @@ import org.mockito.ArgumentMatchers.eq import org.mockito.Captor import org.mockito.Mock import org.mockito.Mockito.`when` import org.mockito.Mockito.never import org.mockito.Mockito.verify import org.mockito.MockitoAnnotations Loading Loading @@ -142,6 +143,19 @@ class ControlsProviderLifecycleManagerTest : SysuiTestCase() { verify(subscriberService).onError(any(), anyString()) } @Test fun testMaybeBindAndLoad_timeoutCancelled() { manager.maybeBindAndLoad(subscriberService) executor.runAllReady() manager.cancelLoadTimeout() executor.advanceClockToLast() executor.runAllReady() verify(subscriberService, never()).onError(any(), anyString()) } @Test fun testMaybeBindAndSubscribe() { val list = listOf("TEST_ID") Loading