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

Commit eadd94c5 authored by Evan Laird's avatar Evan Laird
Browse files

[Sb refactor] Consume isInService in mobile view model

This implementation matches what was in MobileSignalController. If
isInService() reports false, then we show the empty mobile icon.
Otherwise use the regular icon id logic

Test: MobileIconViewModelTest
Test: MobileIconInteractorTest
Bug: 263167683
Bug: 238425913
Change-Id: Ie0da01439e79267a6842e096ec6924b3ccebce7d
parent cf01bebb
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -48,6 +48,9 @@ interface MobileIconInteractor {
    /** True when telephony tells us that the data state is CONNECTED */
    val isDataConnected: StateFlow<Boolean>

    /** True if we consider this connection to be in service, i.e. can make calls */
    val isInService: StateFlow<Boolean>

    // TODO(b/256839546): clarify naming of default vs active
    /** True if we want to consider the data connection enabled */
    val isDefaultDataEnabled: StateFlow<Boolean>
@@ -175,4 +178,9 @@ class MobileIconInteractorImpl(
        connectionInfo
            .mapLatest { connection -> connection.dataConnectionState == Connected }
            .stateIn(scope, SharingStarted.WhileSubscribed(), false)

    override val isInService =
        connectionRepository.connectionInfo
            .mapLatest { it.isInService }
            .stateIn(scope, SharingStarted.WhileSubscribed(), false)
}
+11 −5
Original line number Diff line number Diff line
@@ -80,12 +80,18 @@ constructor(

    override val iconId: Flow<Int> = run {
        val initial = SignalDrawable.getEmptyState(iconInteractor.numberOfLevels.value)
        combine(iconInteractor.level, iconInteractor.numberOfLevels, showExclamationMark) {
                level,
                numberOfLevels,
                showExclamationMark ->
        combine(
                iconInteractor.level,
                iconInteractor.numberOfLevels,
                showExclamationMark,
                iconInteractor.isInService,
            ) { level, numberOfLevels, showExclamationMark, isInService ->
                if (!isInService) {
                    SignalDrawable.getEmptyState(numberOfLevels)
                } else {
                    SignalDrawable.getState(level, numberOfLevels, showExclamationMark)
                }
            }
            .distinctUntilChanged()
            .logDiffsForTable(
                iconInteractor.tableLogBuffer,
+2 −0
Original line number Diff line number Diff line
@@ -52,6 +52,8 @@ class FakeMobileIconInteractor(

    override val isDataConnected = MutableStateFlow(true)

    override val isInService = MutableStateFlow(true)

    private val _isDataEnabled = MutableStateFlow(true)
    override val isDataEnabled = _isDataEnabled

+17 −0
Original line number Diff line number Diff line
@@ -299,6 +299,23 @@ class MobileIconInteractorTest : SysuiTestCase() {
            job.cancel()
        }

    @Test
    fun `isInService - uses repository value`() =
        runBlocking(IMMEDIATE) {
            var latest: Boolean? = null
            val job = underTest.isInService.onEach { latest = it }.launchIn(this)

            connectionRepository.setConnectionInfo(MobileConnectionModel(isInService = true))

            assertThat(latest).isTrue()

            connectionRepository.setConnectionInfo(MobileConnectionModel(isInService = false))

            assertThat(latest).isFalse()

            job.cancel()
        }

    @Test
    fun `roaming - is gsm - uses connection model`() =
        runBlocking(IMMEDIATE) {
+26 −0
Original line number Diff line number Diff line
@@ -97,6 +97,30 @@ class MobileIconViewModelTest : SysuiTestCase() {
            job.cancel()
        }

    @Test
    fun `icon - uses empty state - when not in service`() =
        testScope.runTest {
            var latest: Int? = null
            val job = underTest.iconId.onEach { latest = it }.launchIn(this)

            interactor.isInService.value = false

            var expected = emptySignal()

            assertThat(latest).isEqualTo(expected)

            // Changing the level doesn't overwrite the disabled state
            interactor.level.value = 2
            assertThat(latest).isEqualTo(expected)

            // Once back in service, the regular icon appears
            interactor.isInService.value = true
            expected = defaultSignal(level = 2)
            assertThat(latest).isEqualTo(expected)

            job.cancel()
        }

    @Test
    fun networkType_dataEnabled_groupIsRepresented() =
        testScope.runTest {
@@ -375,5 +399,7 @@ class MobileIconViewModelTest : SysuiTestCase() {
        ): Int {
            return SignalDrawable.getState(level, /* numLevels */ 4, !connected)
        }

        fun emptySignal(): Int = SignalDrawable.getEmptyState(4)
    }
}