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

Commit 172b95c2 authored by Evan Laird's avatar Evan Laird
Browse files

[SB refactor] Wire up DataConnectionState to the view model

DataConnectionState is used to help decide whether or not to show the
RAT icon. This CL wires it up to the interactor + view model

Test: atest packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/*
Bug: 240492102
Change-Id: I37ab77674319757b954c469da6b73a4a2876dadd
parent 09c154b2
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.systemui.statusbar.pipeline.mobile.domain.interactor
import android.telephony.CarrierConfigManager
import com.android.settingslib.SignalIcon.MobileIconGroup
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.statusbar.pipeline.mobile.data.model.DataConnectionState.Connected
import com.android.systemui.statusbar.pipeline.mobile.data.model.DefaultNetworkType
import com.android.systemui.statusbar.pipeline.mobile.data.model.OverrideNetworkType
import com.android.systemui.statusbar.pipeline.mobile.data.repository.MobileConnectionRepository
@@ -37,6 +38,9 @@ interface MobileIconInteractor {
    /** Only true if mobile is the default transport but is not validated, otherwise false */
    val isDefaultConnectionFailed: StateFlow<Boolean>

    /** True when telephony tells us that the data state is CONNECTED */
    val isDataConnected: 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>
@@ -114,4 +118,9 @@ class MobileIconInteractorImpl(
     * once it's wired up inside of [CarrierConfigTracker]
     */
    override val numberOfLevels: StateFlow<Int> = MutableStateFlow(4)

    override val isDataConnected: StateFlow<Boolean> =
        mobileStatusInfo
            .mapLatest { subscriptionModel -> subscriptionModel.dataConnectionState == Connected }
            .stateIn(scope, SharingStarted.WhileSubscribed(), false)
}
+4 −3
Original line number Diff line number Diff line
@@ -68,10 +68,11 @@ constructor(
    val networkTypeIcon: Flow<Icon?> =
        combine(
            iconInteractor.networkTypeIconGroup,
            iconInteractor.isDataConnected,
            iconInteractor.isDataEnabled,
            iconInteractor.isDefaultConnectionFailed
        ) { networkTypeIconGroup, isDataEnabled, isFailedConnection ->
            if (!isDataEnabled || isFailedConnection) {
            iconInteractor.isDefaultConnectionFailed,
        ) { networkTypeIconGroup, dataConnected, dataEnabled, failedConnection ->
            if (!dataConnected || !dataEnabled || failedConnection) {
                null
            } else {
                val desc =
+2 −0
Original line number Diff line number Diff line
@@ -31,6 +31,8 @@ class FakeMobileIconInteractor : MobileIconInteractor {
    private val _isFailedConnection = MutableStateFlow(false)
    override val isDefaultConnectionFailed = _isFailedConnection

    override val isDataConnected = MutableStateFlow(true)

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

+32 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import androidx.test.filters.SmallTest
import com.android.settingslib.SignalIcon.MobileIconGroup
import com.android.settingslib.mobile.TelephonyIcons
import com.android.systemui.SysuiTestCase
import com.android.systemui.statusbar.pipeline.mobile.data.model.DataConnectionState
import com.android.systemui.statusbar.pipeline.mobile.data.model.DefaultNetworkType
import com.android.systemui.statusbar.pipeline.mobile.data.model.MobileSubscriptionModel
import com.android.systemui.statusbar.pipeline.mobile.data.model.OverrideNetworkType
@@ -231,6 +232,37 @@ class MobileIconInteractorTest : SysuiTestCase() {
            job.cancel()
        }

    @Test
    fun dataState_connected() =
        runBlocking(IMMEDIATE) {
            var latest: Boolean? = null
            val job = underTest.isDataConnected.onEach { latest = it }.launchIn(this)

            connectionRepository.setMobileSubscriptionModel(
                MobileSubscriptionModel(dataConnectionState = DataConnectionState.Connected)
            )
            yield()

            assertThat(latest).isTrue()

            job.cancel()
        }

    @Test
    fun dataState_notConnected() =
        runBlocking(IMMEDIATE) {
            var latest: Boolean? = null
            val job = underTest.isDataConnected.onEach { latest = it }.launchIn(this)

            connectionRepository.setMobileSubscriptionModel(
                MobileSubscriptionModel(dataConnectionState = DataConnectionState.Disconnected)
            )

            assertThat(latest).isFalse()

            job.cancel()
        }

    companion object {
        private val IMMEDIATE = Dispatchers.Main.immediate

+25 −0
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ class MobileIconViewModelTest : SysuiTestCase() {
            setIconGroup(THREE_G)
            setIsEmergencyOnly(false)
            setNumberOfLevels(4)
            isDataConnected.value = true
        }
        underTest = MobileIconViewModel(SUB_1_ID, interactor, logger)
    }
@@ -126,6 +127,30 @@ class MobileIconViewModelTest : SysuiTestCase() {
            job.cancel()
        }

    @Test
    fun networkType_nullWhenDataDisconnects() =
        runBlocking(IMMEDIATE) {
            val initial =
                Icon.Resource(
                    THREE_G.dataType,
                    ContentDescription.Resource(THREE_G.dataContentDescription)
                )

            interactor.setIconGroup(THREE_G)
            var latest: Icon? = null
            val job = underTest.networkTypeIcon.onEach { latest = it }.launchIn(this)

            interactor.setIconGroup(THREE_G)
            assertThat(latest).isEqualTo(initial)

            interactor.isDataConnected.value = false
            yield()

            assertThat(latest).isNull()

            job.cancel()
        }

    @Test
    fun networkType_null_changeToDisabled() =
        runBlocking(IMMEDIATE) {