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

Commit ed434b4a authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Remove scheduled timeout onError or onComplete" into rvc-dev

parents 4b705f50 8b14c301
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -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))
            }
        }
+5 −0
Original line number Diff line number Diff line
@@ -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]
     *
+39 −1
Original line number Diff line number Diff line
@@ -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>
@@ -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 {
+14 −0
Original line number Diff line number Diff line
@@ -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

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