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

Commit 8b7b9fb2 authored by Behnam Heydarshahi's avatar Behnam Heydarshahi
Browse files

Load tile icons while mapping state

Previously we provided code to load icon instead of actually doing the
loading in the mapper. This CL reduces thread contention among
tiles by moving the mapping to UiBackground thread. The QSTileState no
longer needs icon suppliers. Just icons.

Flag: com.android.systemui.qs_new_tiles
Fixes: 376115950
Test: atest AirplaneModeMapperTest
Test: atest AlarmTileMapperTest
Test: atest BatterySaverTileMapperTest
Test: atest FlashlightMapperTest
Test: atest FontScalingTileMapperTest
Test: atest InternetTileMapperTest
Test: atest IssueRecordingMapperTest
Test: atest LocationTileMapperTest
Test: atest OneHandedModeTileMapperTest
Test: atest QRCodeScannerTileMapperTest
Test: atest ReduceBrightColorsTileMapperTest
Test: atest RotationLockTileMapperTest
Test: atest SensorPrivacyToggleTileMapperTest
Test: atest WorkModeTileMapperTest
Change-Id: Iff35ce6687e96aff12301667a045d8e604df2199
parent 8e5e69ab
Loading
Loading
Loading
Loading
+4 −8
Original line number Original line Diff line number Diff line
@@ -115,7 +115,7 @@ class QSTileLoggerTest : SysuiTestCase() {
        underTest.logUserActionPipeline(
        underTest.logUserActionPipeline(
            TileSpec.create("test_spec"),
            TileSpec.create("test_spec"),
            QSTileUserAction.Click(null),
            QSTileUserAction.Click(null),
            QSTileState.build({ Icon.Resource(0, ContentDescription.Resource(0)) }, "") {},
            QSTileState.build(Icon.Resource(0, ContentDescription.Resource(0)), "") {},
            "test_data",
            "test_data",
        )
        )


@@ -141,7 +141,7 @@ class QSTileLoggerTest : SysuiTestCase() {
    fun testLogStateUpdate() {
    fun testLogStateUpdate() {
        underTest.logStateUpdate(
        underTest.logStateUpdate(
            TileSpec.create("test_spec"),
            TileSpec.create("test_spec"),
            QSTileState.build({ Icon.Resource(0, ContentDescription.Resource(0)) }, "") {},
            QSTileState.build(Icon.Resource(0, ContentDescription.Resource(0)), "") {},
            "test_data",
            "test_data",
        )
        )


@@ -162,18 +162,14 @@ class QSTileLoggerTest : SysuiTestCase() {


    @Test
    @Test
    fun testLogForceUpdate() {
    fun testLogForceUpdate() {
        underTest.logForceUpdate(
        underTest.logForceUpdate(TileSpec.create("test_spec"))
            TileSpec.create("test_spec"),
        )


        assertThat(logBuffer.getStringBuffer()).contains("tile data force update")
        assertThat(logBuffer.getStringBuffer()).contains("tile data force update")
    }
    }


    @Test
    @Test
    fun testLogInitialUpdate() {
    fun testLogInitialUpdate() {
        underTest.logInitialRequest(
        underTest.logInitialRequest(TileSpec.create("test_spec"))
            TileSpec.create("test_spec"),
        )


        assertThat(logBuffer.getStringBuffer()).contains("tile data initial update")
        assertThat(logBuffer.getStringBuffer()).contains("tile data initial update")
    }
    }
+3 −3
Original line number Original line Diff line number Diff line
@@ -85,8 +85,8 @@ class QSTileViewModelImplTest : SysuiTestCase() {
                    object : QSTileDataToStateMapper<Any> {
                    object : QSTileDataToStateMapper<Any> {
                        override fun map(config: QSTileConfig, data: Any): QSTileState =
                        override fun map(config: QSTileConfig, data: Any): QSTileState =
                            QSTileState.build(
                            QSTileState.build(
                                { Icon.Resource(0, ContentDescription.Resource(0)) },
                                Icon.Resource(0, ContentDescription.Resource(0)),
                                data.toString()
                                data.toString(),
                            ) {}
                            ) {}
                    }
                    }
                },
                },
@@ -116,7 +116,7 @@ class QSTileViewModelImplTest : SysuiTestCase() {
                .isEqualTo(
                .isEqualTo(
                    "test_spec:\n" +
                    "test_spec:\n" +
                        "    QSTileState(" +
                        "    QSTileState(" +
                        "icon=() -> com.android.systemui.common.shared.model.Icon?, " +
                        "icon=Resource(res=0, contentDescription=Resource(res=0)), " +
                        "iconRes=null, " +
                        "iconRes=null, " +
                        "label=test_data, " +
                        "label=test_data, " +
                        "activationState=INACTIVE, " +
                        "activationState=INACTIVE, " +
+5 −5
Original line number Original line Diff line number Diff line
@@ -66,7 +66,7 @@ class AirplaneModeMapperTest : SysuiTestCase() {
            createAirplaneModeState(
            createAirplaneModeState(
                QSTileState.ActivationState.ACTIVE,
                QSTileState.ActivationState.ACTIVE,
                context.resources.getStringArray(R.array.tile_states_airplane)[Tile.STATE_ACTIVE],
                context.resources.getStringArray(R.array.tile_states_airplane)[Tile.STATE_ACTIVE],
                R.drawable.qs_airplane_icon_on
                R.drawable.qs_airplane_icon_on,
            )
            )
        QSTileStateSubject.assertThat(outputState).isEqualTo(expectedState)
        QSTileStateSubject.assertThat(outputState).isEqualTo(expectedState)
    }
    }
@@ -81,7 +81,7 @@ class AirplaneModeMapperTest : SysuiTestCase() {
            createAirplaneModeState(
            createAirplaneModeState(
                QSTileState.ActivationState.INACTIVE,
                QSTileState.ActivationState.INACTIVE,
                context.resources.getStringArray(R.array.tile_states_airplane)[Tile.STATE_INACTIVE],
                context.resources.getStringArray(R.array.tile_states_airplane)[Tile.STATE_INACTIVE],
                R.drawable.qs_airplane_icon_off
                R.drawable.qs_airplane_icon_off,
            )
            )
        QSTileStateSubject.assertThat(outputState).isEqualTo(expectedState)
        QSTileStateSubject.assertThat(outputState).isEqualTo(expectedState)
    }
    }
@@ -89,11 +89,11 @@ class AirplaneModeMapperTest : SysuiTestCase() {
    private fun createAirplaneModeState(
    private fun createAirplaneModeState(
        activationState: QSTileState.ActivationState,
        activationState: QSTileState.ActivationState,
        secondaryLabel: String,
        secondaryLabel: String,
        iconRes: Int
        iconRes: Int,
    ): QSTileState {
    ): QSTileState {
        val label = context.getString(R.string.airplane_mode)
        val label = context.getString(R.string.airplane_mode)
        return QSTileState(
        return QSTileState(
            { Icon.Loaded(context.getDrawable(iconRes)!!, null) },
            Icon.Loaded(context.getDrawable(iconRes)!!, null),
            iconRes,
            iconRes,
            label,
            label,
            activationState,
            activationState,
@@ -103,7 +103,7 @@ class AirplaneModeMapperTest : SysuiTestCase() {
            null,
            null,
            QSTileState.SideViewIcon.None,
            QSTileState.SideViewIcon.None,
            QSTileState.EnabledState.ENABLED,
            QSTileState.EnabledState.ENABLED,
            Switch::class.qualifiedName
            Switch::class.qualifiedName,
        )
        )
    }
    }
}
}
+10 −10
Original line number Original line Diff line number Diff line
@@ -51,7 +51,7 @@ class AlarmTileMapperTest : SysuiTestCase() {
                .apply { addOverride(R.drawable.ic_alarm, TestStubDrawable()) }
                .apply { addOverride(R.drawable.ic_alarm, TestStubDrawable()) }
                .resources,
                .resources,
            context.theme,
            context.theme,
            fakeClock
            fakeClock,
        )
        )
    }
    }


@@ -69,7 +69,7 @@ class AlarmTileMapperTest : SysuiTestCase() {
        val expectedState =
        val expectedState =
            createAlarmTileState(
            createAlarmTileState(
                QSTileState.ActivationState.INACTIVE,
                QSTileState.ActivationState.INACTIVE,
                context.getString(R.string.qs_alarm_tile_no_alarm)
                context.getString(R.string.qs_alarm_tile_no_alarm),
            )
            )
        QSTileStateSubject.assertThat(outputState).isEqualTo(expectedState)
        QSTileStateSubject.assertThat(outputState).isEqualTo(expectedState)
    }
    }
@@ -85,7 +85,7 @@ class AlarmTileMapperTest : SysuiTestCase() {
        val localDateTime =
        val localDateTime =
            LocalDateTime.ofInstant(
            LocalDateTime.ofInstant(
                Instant.ofEpochMilli(triggerTime),
                Instant.ofEpochMilli(triggerTime),
                TimeZone.getDefault().toZoneId()
                TimeZone.getDefault().toZoneId(),
            )
            )
        val expectedSecondaryLabel = AlarmTileMapper.formatter24Hour.format(localDateTime)
        val expectedSecondaryLabel = AlarmTileMapper.formatter24Hour.format(localDateTime)
        val expectedState =
        val expectedState =
@@ -104,7 +104,7 @@ class AlarmTileMapperTest : SysuiTestCase() {
        val localDateTime =
        val localDateTime =
            LocalDateTime.ofInstant(
            LocalDateTime.ofInstant(
                Instant.ofEpochMilli(triggerTime),
                Instant.ofEpochMilli(triggerTime),
                TimeZone.getDefault().toZoneId()
                TimeZone.getDefault().toZoneId(),
            )
            )
        val expectedSecondaryLabel = AlarmTileMapper.formatter12Hour.format(localDateTime)
        val expectedSecondaryLabel = AlarmTileMapper.formatter12Hour.format(localDateTime)
        val expectedState =
        val expectedState =
@@ -124,7 +124,7 @@ class AlarmTileMapperTest : SysuiTestCase() {
        val localDateTime =
        val localDateTime =
            LocalDateTime.ofInstant(
            LocalDateTime.ofInstant(
                Instant.ofEpochMilli(triggerTime),
                Instant.ofEpochMilli(triggerTime),
                TimeZone.getDefault().toZoneId()
                TimeZone.getDefault().toZoneId(),
            )
            )
        val expectedSecondaryLabel = AlarmTileMapper.formatterDateOnly.format(localDateTime)
        val expectedSecondaryLabel = AlarmTileMapper.formatterDateOnly.format(localDateTime)
        val expectedState =
        val expectedState =
@@ -144,7 +144,7 @@ class AlarmTileMapperTest : SysuiTestCase() {
        val localDateTime =
        val localDateTime =
            LocalDateTime.ofInstant(
            LocalDateTime.ofInstant(
                Instant.ofEpochMilli(triggerTime),
                Instant.ofEpochMilli(triggerTime),
                TimeZone.getDefault().toZoneId()
                TimeZone.getDefault().toZoneId(),
            )
            )
        val expectedSecondaryLabel = AlarmTileMapper.formatter12Hour.format(localDateTime)
        val expectedSecondaryLabel = AlarmTileMapper.formatter12Hour.format(localDateTime)
        val expectedState =
        val expectedState =
@@ -164,7 +164,7 @@ class AlarmTileMapperTest : SysuiTestCase() {
        val localDateTime =
        val localDateTime =
            LocalDateTime.ofInstant(
            LocalDateTime.ofInstant(
                Instant.ofEpochMilli(triggerTime),
                Instant.ofEpochMilli(triggerTime),
                TimeZone.getDefault().toZoneId()
                TimeZone.getDefault().toZoneId(),
            )
            )
        val expectedSecondaryLabel = AlarmTileMapper.formatterDateOnly.format(localDateTime)
        val expectedSecondaryLabel = AlarmTileMapper.formatterDateOnly.format(localDateTime)
        val expectedState =
        val expectedState =
@@ -174,11 +174,11 @@ class AlarmTileMapperTest : SysuiTestCase() {


    private fun createAlarmTileState(
    private fun createAlarmTileState(
        activationState: QSTileState.ActivationState,
        activationState: QSTileState.ActivationState,
        secondaryLabel: String
        secondaryLabel: String,
    ): QSTileState {
    ): QSTileState {
        val label = context.getString(R.string.status_bar_alarm)
        val label = context.getString(R.string.status_bar_alarm)
        return QSTileState(
        return QSTileState(
            { Icon.Loaded(context.getDrawable(R.drawable.ic_alarm)!!, null) },
            Icon.Loaded(context.getDrawable(R.drawable.ic_alarm)!!, null),
            R.drawable.ic_alarm,
            R.drawable.ic_alarm,
            label,
            label,
            activationState,
            activationState,
@@ -188,7 +188,7 @@ class AlarmTileMapperTest : SysuiTestCase() {
            null,
            null,
            QSTileState.SideViewIcon.Chevron,
            QSTileState.SideViewIcon.Chevron,
            QSTileState.EnabledState.ENABLED,
            QSTileState.EnabledState.ENABLED,
            Switch::class.qualifiedName
            Switch::class.qualifiedName,
        )
        )
    }
    }
}
}
+2 −2
Original line number Original line Diff line number Diff line
@@ -253,7 +253,7 @@ class BatterySaverTileMapperTest : SysuiTestCase() {
    ): QSTileState {
    ): QSTileState {
        val label = context.getString(R.string.battery_detail_switch_title)
        val label = context.getString(R.string.battery_detail_switch_title)
        return QSTileState(
        return QSTileState(
            { Icon.Loaded(context.getDrawable(iconRes)!!, null) },
            Icon.Loaded(context.getDrawable(iconRes)!!, null),
            iconRes,
            iconRes,
            label,
            label,
            activationState,
            activationState,
@@ -265,7 +265,7 @@ class BatterySaverTileMapperTest : SysuiTestCase() {
            stateDescription,
            stateDescription,
            QSTileState.SideViewIcon.None,
            QSTileState.SideViewIcon.None,
            QSTileState.EnabledState.ENABLED,
            QSTileState.EnabledState.ENABLED,
            Switch::class.qualifiedName
            Switch::class.qualifiedName,
        )
        )
    }
    }
}
}
Loading