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

Commit d6f325fa authored by Matt Pietal's avatar Matt Pietal Committed by Automerger Merge Worker
Browse files

Merge "Controls Ui - Do not update controls without STATUS_OK" into rvc-dev...

Merge "Controls Ui - Do not update controls without STATUS_OK" into rvc-dev am: ad9c1a88 am: 505418d8 am: 3543840c

Change-Id: I78da1cd92dad913a6cb33ed9520b4b27c65f9be1
parents 48530d46 3543840c
Loading
Loading
Loading
Loading
+8 −7
Original line number Diff line number Diff line
@@ -439,15 +439,16 @@ class ControlsControllerImpl @Inject constructor (
            Log.d(TAG, "Controls not available")
            return
        }

        // Assume that non STATUS_OK responses may contain incomplete or invalid information about
        // the control, and do not attempt to update it
        if (control.getStatus() == Control.STATUS_OK) {
            executor.execute {
            val changed = Favorites.updateControls(
                componentName,
                listOf(control)
            )
            if (changed) {
                if (Favorites.updateControls(componentName, listOf(control))) {
                    persistenceWrapper.storeFavorites(Favorites.getAllStructures())
                }
            }
        }
        uiController.onRefreshState(componentName, listOf(control))
    }

+37 −9
Original line number Diff line number Diff line
@@ -161,7 +161,7 @@ class ControlsControllerImplTest : SysuiTestCase() {
        verify(listingController).addCallback(capture(listingCallbackCaptor))
    }

    private fun builderFromInfo(
    private fun statelessBuilderFromInfo(
        controlInfo: ControlInfo,
        structure: CharSequence = ""
    ): Control.StatelessBuilder {
@@ -170,6 +170,15 @@ class ControlsControllerImplTest : SysuiTestCase() {
                .setSubtitle(controlInfo.controlSubtitle).setStructure(structure)
    }

    private fun statefulBuilderFromInfo(
        controlInfo: ControlInfo,
        structure: CharSequence = ""
    ): Control.StatefulBuilder {
        return Control.StatefulBuilder(controlInfo.controlId, pendingIntent)
                .setDeviceType(controlInfo.deviceType).setTitle(controlInfo.controlTitle)
                .setSubtitle(controlInfo.controlSubtitle).setStructure(structure)
    }

    @Test
    fun testStartOnUser() {
        assertEquals(user, controller.currentUserId)
@@ -236,7 +245,7 @@ class ControlsControllerImplTest : SysuiTestCase() {
    @Test
    fun testLoadForComponent_noFavorites() {
        var loaded = false
        val control = builderFromInfo(TEST_CONTROL_INFO).build()
        val control = statelessBuilderFromInfo(TEST_CONTROL_INFO).build()

        controller.loadForComponent(TEST_COMPONENT, Consumer { data ->
            val controls = data.allControls
@@ -263,8 +272,8 @@ class ControlsControllerImplTest : SysuiTestCase() {
    @Test
    fun testLoadForComponent_favorites() {
        var loaded = false
        val control = builderFromInfo(TEST_CONTROL_INFO).build()
        val control2 = builderFromInfo(TEST_CONTROL_INFO_2).build()
        val control = statelessBuilderFromInfo(TEST_CONTROL_INFO).build()
        val control2 = statelessBuilderFromInfo(TEST_CONTROL_INFO_2).build()
        controller.replaceFavoritesForStructure(TEST_STRUCTURE_INFO)
        controller.replaceFavoritesForStructure(TEST_STRUCTURE_INFO_2)
        delayableExecutor.runAllReady()
@@ -445,7 +454,7 @@ class ControlsControllerImplTest : SysuiTestCase() {
        delayableExecutor.runAllReady()

        val newControlInfo = TEST_CONTROL_INFO.copy(controlTitle = TEST_CONTROL_TITLE_2)
        val control = builderFromInfo(newControlInfo).build()
        val control = statelessBuilderFromInfo(newControlInfo).build()

        controller.loadForComponent(TEST_COMPONENT, Consumer {})

@@ -461,11 +470,11 @@ class ControlsControllerImplTest : SysuiTestCase() {
    }

    @Test
    fun testFavoriteInformationModifiedOnRefresh() {
    fun testFavoriteInformationModifiedOnRefreshWithOkStatus() {
        controller.replaceFavoritesForStructure(TEST_STRUCTURE_INFO)

        val newControlInfo = TEST_CONTROL_INFO.copy(controlTitle = TEST_CONTROL_TITLE_2)
        val control = builderFromInfo(newControlInfo).build()
        val control = statefulBuilderFromInfo(newControlInfo).setStatus(Control.STATUS_OK).build()

        controller.refreshStatus(TEST_COMPONENT, control)

@@ -476,6 +485,23 @@ class ControlsControllerImplTest : SysuiTestCase() {
        assertEquals(newControlInfo, favorites[0])
    }

    @Test
    fun testFavoriteInformationNotModifiedOnRefreshWithNonOkStatus() {
        controller.replaceFavoritesForStructure(TEST_STRUCTURE_INFO)

        val newControlInfo = TEST_CONTROL_INFO.copy(controlTitle = TEST_CONTROL_TITLE_2)
        val control = statefulBuilderFromInfo(newControlInfo).setStatus(Control.STATUS_ERROR)
            .build()

        controller.refreshStatus(TEST_COMPONENT, control)

        delayableExecutor.runAllReady()

        val favorites = controller.getFavorites().flatMap { it.controls }
        assertEquals(1, favorites.size)
        assertEquals(TEST_CONTROL_INFO, favorites[0])
    }

    @Test
    fun testSwitchUsers() {
        controller.replaceFavoritesForStructure(TEST_STRUCTURE_INFO)
@@ -762,7 +788,8 @@ class ControlsControllerImplTest : SysuiTestCase() {
    @Test
    fun testSeedFavoritesForComponent() {
        var succeeded = false
        val control = builderFromInfo(TEST_CONTROL_INFO, TEST_STRUCTURE_INFO.structure).build()
        val control = statelessBuilderFromInfo(TEST_CONTROL_INFO, TEST_STRUCTURE_INFO.structure)
            .build()

        controller.seedFavoritesForComponent(TEST_COMPONENT, Consumer { accepted ->
            succeeded = accepted
@@ -803,7 +830,8 @@ class ControlsControllerImplTest : SysuiTestCase() {
    fun testSeedFavoritesForComponent_inProgressCallback() {
        var succeeded = false
        var seeded = false
        val control = builderFromInfo(TEST_CONTROL_INFO, TEST_STRUCTURE_INFO.structure).build()
        val control = statelessBuilderFromInfo(TEST_CONTROL_INFO, TEST_STRUCTURE_INFO.structure)
            .build()

        controller.seedFavoritesForComponent(TEST_COMPONENT, Consumer { accepted ->
            succeeded = accepted