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

Commit 833017df authored by Evan Laird's avatar Evan Laird Committed by Android (Google) Code Review
Browse files

Merge "[Sat] Split out icon levels in mobile interactor" into main

parents c0ff9ea6 8e64d671
Loading
Loading
Loading
Loading
+10 −6
Original line number Diff line number Diff line
@@ -325,7 +325,7 @@ class MobileIconInteractorImpl(
            }
            .stateIn(scope, SharingStarted.WhileSubscribed(), true)

    private val shownLevel: StateFlow<Int> =
    private val cellularShownLevel: StateFlow<Int> =
        combine(
                level,
                isInService,
@@ -337,15 +337,19 @@ class MobileIconInteractorImpl(
            }
            .stateIn(scope, SharingStarted.WhileSubscribed(), 0)

    // Satellite level is unaffected by the isInService or inflateSignalStrength properties
    // See b/346904529 for details
    private val satelliteShownLevel: StateFlow<Int> = level

    private val cellularIcon: Flow<SignalIconModel.Cellular> =
        combine(
            shownLevel,
            cellularShownLevel,
            numberOfLevels,
            showExclamationMark,
            carrierNetworkChangeActive,
        ) { shownLevel, numberOfLevels, showExclamationMark, carrierNetworkChange ->
        ) { cellularShownLevel, numberOfLevels, showExclamationMark, carrierNetworkChange ->
            SignalIconModel.Cellular(
                shownLevel,
                cellularShownLevel,
                numberOfLevels,
                showExclamationMark,
                carrierNetworkChange,
@@ -353,7 +357,7 @@ class MobileIconInteractorImpl(
        }

    private val satelliteIcon: Flow<SignalIconModel.Satellite> =
        shownLevel.map {
        satelliteShownLevel.map {
            SignalIconModel.Satellite(
                level = it,
                icon =
@@ -365,7 +369,7 @@ class MobileIconInteractorImpl(
    override val signalLevelIcon: StateFlow<SignalIconModel> = run {
        val initial =
            SignalIconModel.Cellular(
                shownLevel.value,
                cellularShownLevel.value,
                numberOfLevels.value,
                showExclamationMark.value,
                carrierNetworkChangeActive.value,
+22 −0
Original line number Diff line number Diff line
@@ -738,6 +738,28 @@ class MobileIconInteractorTest : SysuiTestCase() {
            assertThat(latest).isInstanceOf(SignalIconModel.Satellite::class.java)
        }

    @EnableFlags(com.android.internal.telephony.flags.Flags.FLAG_CARRIER_ENABLED_SATELLITE_FLAG)
    @Test
    // See b/346904529 for more context
    fun satBasedIcon_doesNotInflateSignalStrength() =
        testScope.runTest {
            val latest by collectLastValue(underTest.signalLevelIcon)

            // GIVEN a satellite connection
            connectionRepository.isNonTerrestrial.value = true
            // GIVEN this carrier has set INFLATE_SIGNAL_STRENGTH
            connectionRepository.inflateSignalStrength.value = true

            connectionRepository.primaryLevel.value = 4
            assertThat(latest!!.level).isEqualTo(4)

            connectionRepository.inflateSignalStrength.value = true
            connectionRepository.primaryLevel.value = 4

            // Icon level is unaffected
            assertThat(latest!!.level).isEqualTo(4)
        }

    private fun createInteractor(
        overrides: MobileIconCarrierIdOverrides = MobileIconCarrierIdOverridesImpl()
    ) =
+32 −0
Original line number Diff line number Diff line
@@ -862,6 +862,38 @@ class MobileIconViewModelTest : SysuiTestCase() {
            assertThat(latest!!.icon.res).isEqualTo(R.drawable.ic_satellite_connected_2)
        }

    @EnableFlags(com.android.internal.telephony.flags.Flags.FLAG_CARRIER_ENABLED_SATELLITE_FLAG)
    @Test
    fun satelliteIcon_ignoresInflateSignalStrength() =
        testScope.runTest {
            // Note that this is the exact same test as above, but with inflateSignalStrength set to
            // true we note that the level is unaffected by inflation
            repository.inflateSignalStrength.value = true
            repository.isNonTerrestrial.value = true
            repository.setAllLevels(0)

            val latest by
                collectLastValue(underTest.icon.filterIsInstance(SignalIconModel.Satellite::class))

            // Level 0 -> no connection
            assertThat(latest).isNotNull()
            assertThat(latest!!.icon.res).isEqualTo(R.drawable.ic_satellite_connected_0)

            // 1-2 -> 1 bar
            repository.setAllLevels(1)
            assertThat(latest!!.icon.res).isEqualTo(R.drawable.ic_satellite_connected_1)

            repository.setAllLevels(2)
            assertThat(latest!!.icon.res).isEqualTo(R.drawable.ic_satellite_connected_1)

            // 3-4 -> 2 bars
            repository.setAllLevels(3)
            assertThat(latest!!.icon.res).isEqualTo(R.drawable.ic_satellite_connected_2)

            repository.setAllLevels(4)
            assertThat(latest!!.icon.res).isEqualTo(R.drawable.ic_satellite_connected_2)
        }

    private fun createAndSetViewModel() {
        underTest =
            MobileIconViewModel(