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

Commit f72fe345 authored by Ahmed Mehfooz's avatar Ahmed Mehfooz Committed by Android (Google) Code Review
Browse files

Merge "[SB][ComposeIcons] Add support for custom SystemStatusIconViewModels" into main

parents a770e5d7 8b7864f1
Loading
Loading
Loading
Loading
+27 −32
Original line number Diff line number Diff line
@@ -56,73 +56,68 @@ class AirplaneModeIconViewModelTest : SysuiTestCase() {
        }

    @Test
    fun icon_notAirplaneMode_outputsNull() =
        kosmos.runTest {
            fakeConnectivityRepository.setForceHiddenIcons(setOf())
            airplaneModeRepository.setIsAirplaneMode(false)
    fun visible_isFalse_byDefault() = kosmos.runTest { assertThat(underTest.visible).isFalse() }

            assertThat(underTest.icon).isNull()
        }
    @Test fun icon_notVisible_isNull() = kosmos.runTest { assertThat(underTest.icon).isNull() }

    @Test
    fun icon_forceHidden_outputsNull() =
    fun visible_airplaneModeOnAndNotForceHidden_isTrue() =
        kosmos.runTest {
            fakeConnectivityRepository.setForceHiddenIcons(setOf(ConnectivitySlot.AIRPLANE))
            airplaneModeRepository.setIsAirplaneMode(true)
            fakeConnectivityRepository.setForceHiddenIcons(setOf())

            assertThat(underTest.icon).isNull()
            assertThat(underTest.visible).isTrue()
        }

    @Test
    fun icon_isAirplaneModeAndNotForceHidden_outputsIcon() =
    fun visible_forceHidden_isFalse() =
        kosmos.runTest {
            fakeConnectivityRepository.setForceHiddenIcons(setOf())
            airplaneModeRepository.setIsAirplaneMode(true)
            fakeConnectivityRepository.setForceHiddenIcons(setOf(ConnectivitySlot.AIRPLANE))

            val expectedIcon =
                Icon.Resource(
                    res = com.android.internal.R.drawable.ic_qs_airplane,
                    contentDescription =
                        ContentDescription.Resource(R.string.accessibility_airplane_mode),
                )
            assertThat(underTest.icon).isEqualTo(expectedIcon)
            assertThat(underTest.visible).isFalse()
        }

    @Test
    fun icon_updatesWhenAirplaneModeChanges() =
    fun visible_airplaneModeChanges_flips() =
        kosmos.runTest {
            fakeConnectivityRepository.setForceHiddenIcons(setOf())

            // Start not in airplane mode
            airplaneModeRepository.setIsAirplaneMode(false)
            assertThat(underTest.icon).isNull()
            assertThat(underTest.visible).isFalse()

            // Turn on airplane mode
            airplaneModeRepository.setIsAirplaneMode(true)

            assertThat(underTest.icon).isEqualTo(expectedAirplaneIcon)
            assertThat(underTest.visible).isTrue()

            // Turn off airplane mode
            airplaneModeRepository.setIsAirplaneMode(false)
            assertThat(underTest.icon).isNull()

            assertThat(underTest.visible).isFalse()
        }

    @Test
    fun icon_updatesWhenForceHiddenChanges() =
    fun visible_forceHiddenChanges_flips() =
        kosmos.runTest {
            airplaneModeRepository.setIsAirplaneMode(true)

            // Start not hidden
            fakeConnectivityRepository.setForceHiddenIcons(setOf())
            assertThat(underTest.visible).isTrue()

            assertThat(underTest.icon).isEqualTo(expectedAirplaneIcon)

            // Force hide
            fakeConnectivityRepository.setForceHiddenIcons(setOf(ConnectivitySlot.AIRPLANE))
            assertThat(underTest.icon).isNull()

            // Un-hide
            assertThat(underTest.visible).isFalse()

            fakeConnectivityRepository.setForceHiddenIcons(setOf())

            assertThat(underTest.visible).isTrue()
        }

    @Test
    fun icon_visible_isCorrect() =
        kosmos.runTest {
            airplaneModeRepository.setIsAirplaneMode(true)
            fakeConnectivityRepository.setForceHiddenIcons(setOf())

            assertThat(underTest.icon).isEqualTo(expectedAirplaneIcon)
        }
}
+25 −8
Original line number Diff line number Diff line
@@ -49,33 +49,50 @@ class NextAlarmIconViewModelTest : SysuiTestCase() {
        kosmos.nextAlarmIconViewModelFactory.create(context).apply { activateIn(testScope) }

    @Test
    fun icon_alarmNotSet_outputsNull() =
    fun icon_visible_isCorrect() =
        kosmos.runTest {
            val alarmClockInfo = AlarmManager.AlarmClockInfo(1L, mock<PendingIntent>())
            fakeNextAlarmController.setNextAlarm(alarmClockInfo)

            assertThat(underTest.icon).isEqualTo(EXPECTED_ALARM_ICON)
        }

    @Test
    fun icon_notVisible_isNull() =
        kosmos.runTest {
            fakeNextAlarmController.setNextAlarm(null)

            assertThat(underTest.icon).isNull()
        }

    @Test
    fun icon_alarmSet_outputsIcon() =
    fun visible_isFalse_byDefault() =
        kosmos.runTest {
            fakeNextAlarmController.setNextAlarm(null)

            assertThat(underTest.visible).isFalse()
        }

    @Test
    fun visible_alarmIsSet_isTrue() =
        kosmos.runTest {
            val alarmClockInfo = AlarmManager.AlarmClockInfo(1L, mock<PendingIntent>())
            fakeNextAlarmController.setNextAlarm(alarmClockInfo)

            assertThat(underTest.icon).isEqualTo(EXPECTED_ALARM_ICON)
            assertThat(underTest.visible).isTrue()
        }

    @Test
    fun icon_updatesWhenAlarmChanges() =
    fun visible_alarmChanges_flips() =
        kosmos.runTest {
            assertThat(underTest.icon).isNull()
            assertThat(underTest.visible).isFalse()

            val alarmInfo = AlarmManager.AlarmClockInfo(1L, mock<PendingIntent>())
            fakeNextAlarmController.setNextAlarm(alarmInfo)

            assertThat(underTest.icon).isEqualTo(EXPECTED_ALARM_ICON)
            assertThat(underTest.visible).isTrue()

            fakeNextAlarmController.setNextAlarm(null)
            assertThat(underTest.icon).isNull()
            assertThat(underTest.visible).isFalse()
        }

    companion object {
+19 −14
Original line number Diff line number Diff line
@@ -57,32 +57,37 @@ class BluetoothIconViewModelTest : SysuiTestCase() {
        }

    @Test
    fun icon_bluetoothNotConnected_outputsNull() =
        kosmos.runTest { assertThat(underTest.icon).isNull() }
    fun visible_isFalse_byDefault() = kosmos.runTest { assertThat(underTest.visible).isFalse() }

    @Test
    fun icon_bluetoothConnected_outputsIcon() =
    fun visible_deviceIsConnected_isTrue() =
        kosmos.runTest {
            // Simulate device connecting
            bluetoothRepository.setConnectedDevices(listOf(cachedDevice))
            kosmos.bluetoothRepository.setConnectedDevices(listOf(cachedDevice))

            assertThat(underTest.icon).isEqualTo(expectedBluetoothIcon)
            assertThat(underTest.visible).isTrue()
        }

    @Test
    fun icon_updatesWhenBluetoothConnectionChanges() =
    fun visible_connectionStateChanges_flips() =
        kosmos.runTest {
            assertThat(underTest.icon).isNull()
            assertThat(underTest.visible).isFalse()

            // Simulate device connecting
            bluetoothRepository.setConnectedDevices(listOf(cachedDevice))
            assertThat(underTest.icon).isEqualTo(expectedBluetoothIcon)
            kosmos.bluetoothRepository.setConnectedDevices(listOf(cachedDevice))
            assertThat(underTest.visible).isTrue()

            kosmos.bluetoothRepository.setConnectedDevices(emptyList())
            assertThat(underTest.visible).isFalse()
        }

            // Simulate device disconnecting
            bluetoothRepository.setConnectedDevices(emptyList())
            assertThat(underTest.icon).isNull()
    @Test
    fun icon_visible_isCorrect() =
        kosmos.runTest {
            kosmos.bluetoothRepository.setConnectedDevices(listOf(cachedDevice))
            assertThat(underTest.icon).isEqualTo(expectedBluetoothIcon)
        }

    @Test fun icon_notVisible_isNull() = kosmos.runTest { assertThat(underTest.icon).isNull() }

    companion object {
        private val expectedBluetoothIcon =
            Icon.Resource(
+19 −26
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@ import com.android.systemui.common.shared.model.ContentDescription
import com.android.systemui.common.shared.model.Icon
import com.android.systemui.display.data.repository.display
import com.android.systemui.display.data.repository.displayRepository
import com.android.systemui.keyguard.data.repository.fakeKeyguardRepository
import com.android.systemui.kosmos.runTest
import com.android.systemui.kosmos.testScope
import com.android.systemui.kosmos.useUnconfinedTestDispatcher
@@ -46,7 +45,6 @@ import org.junit.runner.RunWith
class ConnectedDisplayIconViewModelTest : SysuiTestCase() {

    private val kosmos = testKosmos().useUnconfinedTestDispatcher()
    private val keyguardRepository = kosmos.fakeKeyguardRepository

    private val underTest =
        kosmos.connectedDisplayIconViewModelFactory.create(kosmos.testableContext).apply {
@@ -54,49 +52,44 @@ class ConnectedDisplayIconViewModelTest : SysuiTestCase() {
        }

    @Test
    fun icon_displayDisconnected_outputsNull() =
        kosmos.runTest { assertThat(underTest.icon).isNull() }
    fun icon_visible_isCorrect() =
        kosmos.runTest {
            displayRepository.addDisplay(display(type = TYPE_EXTERNAL, id = 1))

            assertThat(underTest.icon).isEqualTo(expectedConnectedDisplayIcon)
        }

    @Test fun icon_notVisible_isNull() = kosmos.runTest { assertThat(underTest.icon).isNull() }

    @Test
    fun visible_isFalse_byDefault() = kosmos.runTest { assertThat(underTest.visible).isFalse() }

    @Test
    fun icon_displayConnected_outputsIcon() =
    fun visible_externalDisplayIsConnected_isTrue() =
        kosmos.runTest {
            keyguardRepository.setKeyguardShowing(true)
            displayRepository.setDefaultDisplayOff(false)
            displayRepository.addDisplay(display(type = TYPE_EXTERNAL, id = 1))

            assertThat(underTest.icon).isEqualTo(expectedConnectedDisplayIcon)
            assertThat(underTest.visible).isTrue()
        }

    @Test
    fun icon_displayConnectedSecure_outputsIcon() =
    fun visible_secureExternalDisplayIsConnected_isTrue() =
        kosmos.runTest {
            keyguardRepository.setKeyguardShowing(false)
            displayRepository.setDefaultDisplayOff(false)
            displayRepository.addDisplay(display(type = TYPE_EXTERNAL, flags = FLAG_SECURE, id = 1))

            assertThat(underTest.icon).isEqualTo(expectedConnectedDisplayIcon)
            assertThat(underTest.visible).isTrue()
        }

    @Test
    fun icon_updatesWhenDisplayConnectionChanges() =
    fun visible_displayConnectionChanges_flips() =
        kosmos.runTest {
            displayRepository.setDefaultDisplayOff(false)
            assertThat(underTest.icon).isNull()
            assertThat(underTest.visible).isFalse()

            keyguardRepository.setKeyguardShowing(true)
            displayRepository.addDisplay(display(type = TYPE_EXTERNAL, id = 1))

            assertThat(underTest.icon).isEqualTo(expectedConnectedDisplayIcon)
            assertThat(underTest.visible).isTrue()

            displayRepository.removeDisplay(1)
            assertThat(underTest.icon).isNull()

            keyguardRepository.setKeyguardShowing(false)
            displayRepository.addDisplay(display(type = TYPE_EXTERNAL, flags = FLAG_SECURE, id = 2))
            assertThat(underTest.icon).isEqualTo(expectedConnectedDisplayIcon)

            displayRepository.removeDisplay(2)
            assertThat(underTest.icon).isNull()
            assertThat(underTest.visible).isFalse()
        }

    companion object {
+1 −1
Original line number Diff line number Diff line
@@ -108,7 +108,7 @@ class EthernetIconViewModelTest : SysuiTestCase() {
        }

    @Test
    fun icon_updatesWhenConnectivityChanges() =
    fun icon_connectivityChanges_updates() =
        kosmos.runTest {
            // Start default and validated
            fakeConnectivityRepository.setEthernetConnected(default = true, validated = true)
Loading