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

Commit 5ceb454c authored by Evan Laird's avatar Evan Laird
Browse files

[Sb refactor] Add the default network's connectivity to the view model

Part of the criteria of whether or not to show the RAT indicator is
whether or not `mobile` is a connected transport. The way the old
pipeline does this is by keeping track of the default network
capabilities (via `ConnectivityManager`) and letting those be known by
all mobile connections.

The equivalent in the new pipeline is to expose the default network
capabilities via the MobileIconsInteractor, and pass it down to each
individual icon interactor.

Finally, the reason this is sensible to do in the new pipeline is that
we can track when the data subscription changes and thus we can avoid
icon flickering (see following CL)

Test: MobileIconViewModelTest
Test: MobileIconInteractorTest
Test: MobileIconsInteractorTest
Bug: 264683083
Bug: 238425913
Change-Id: Ib3a4f14ba3cb403f342090b7394d271309a3a7f5
parent 1b65eb52
Loading
Loading
Loading
Loading
+24 −3
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import com.android.settingslib.SignalIcon.MobileIconGroup
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.log.table.TableLogBuffer
import com.android.systemui.statusbar.pipeline.mobile.data.model.DataConnectionState.Connected
import com.android.systemui.statusbar.pipeline.mobile.data.model.MobileConnectivityModel
import com.android.systemui.statusbar.pipeline.mobile.data.model.NetworkNameModel
import com.android.systemui.statusbar.pipeline.mobile.data.model.ResolvedNetworkType
import com.android.systemui.statusbar.pipeline.mobile.data.repository.MobileConnectionRepository
@@ -41,12 +42,29 @@ interface MobileIconInteractor {
    /** The current mobile data activity */
    val activity: Flow<DataActivityModel>

    /** Only true if mobile is the default transport but is not validated, otherwise false */
    val isDefaultConnectionFailed: StateFlow<Boolean>
    /**
     * This bit is meant to be `true` if and only if the default network capabilities (see
     * [android.net.ConnectivityManager.registerDefaultNetworkCallback]) result in a network that
     * has the [android.net.NetworkCapabilities.TRANSPORT_CELLULAR] represented.
     *
     * Note that this differs from [isDataConnected], which is tracked by telephony and has to do
     * with the state of using this mobile connection for data as opposed to just voice. It is
     * possible for a mobile subscription to be connected but not be in a connected data state, and
     * thus we wouldn't want to show the network type icon.
     */
    val isConnected: Flow<Boolean>

    /** True when telephony tells us that the data state is CONNECTED */
    /**
     * True when telephony tells us that the data state is CONNECTED. See
     * [android.telephony.TelephonyCallback.DataConnectionStateListener] for more details. We
     * consider this connection to be serving data, and thus want to show a network type icon, when
     * data is connected. Other data connection states would typically cause us not to show the icon
     */
    val isDataConnected: StateFlow<Boolean>

    /** Only true if mobile is the default transport but is not validated, otherwise false */
    val isDefaultConnectionFailed: StateFlow<Boolean>

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

@@ -100,6 +118,7 @@ class MobileIconInteractorImpl(
    defaultSubscriptionHasDataEnabled: StateFlow<Boolean>,
    override val alwaysShowDataRatIcon: StateFlow<Boolean>,
    override val alwaysUseCdmaLevel: StateFlow<Boolean>,
    defaultMobileConnectivity: StateFlow<MobileConnectivityModel>,
    defaultMobileIconMapping: StateFlow<Map<String, MobileIconGroup>>,
    defaultMobileIconGroup: StateFlow<MobileIconGroup>,
    override val isDefaultConnectionFailed: StateFlow<Boolean>,
@@ -111,6 +130,8 @@ class MobileIconInteractorImpl(

    override val activity = connectionInfo.mapLatest { it.dataActivityDirection }

    override val isConnected: Flow<Boolean> = defaultMobileConnectivity.mapLatest { it.isConnected }

    override val isDataEnabled: StateFlow<Boolean> = connectionRepository.dataEnabled

    override val isDefaultDataEnabled = defaultSubscriptionHasDataEnabled
+13 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import com.android.settingslib.SignalIcon.MobileIconGroup
import com.android.settingslib.mobile.TelephonyIcons
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.statusbar.pipeline.mobile.data.model.MobileConnectivityModel
import com.android.systemui.statusbar.pipeline.mobile.data.model.SubscriptionModel
import com.android.systemui.statusbar.pipeline.mobile.data.repository.MobileConnectionRepository
import com.android.systemui.statusbar.pipeline.mobile.data.repository.MobileConnectionsRepository
@@ -62,6 +63,14 @@ interface MobileIconsInteractor {
    /** True if the CDMA level should be preferred over the primary level. */
    val alwaysUseCdmaLevel: StateFlow<Boolean>

    /**
     * The connectivity of the default mobile network. Note that this can differ from what is
     * reported from [MobileConnectionsRepository] in some cases. E.g., when the active subscription
     * changes but the groupUuid remains the same, we keep the old validation information for 2
     * seconds to avoid icon flickering.
     */
    val defaultMobileNetworkConnectivity: StateFlow<MobileConnectivityModel>

    /** The icon mapping from network type to [MobileIconGroup] for the default subscription */
    val defaultMobileIconMapping: StateFlow<Map<String, MobileIconGroup>>
    /** Fallback [MobileIconGroup] in the case where there is no icon in the mapping */
@@ -154,6 +163,9 @@ constructor(
            }
        }

    override val defaultMobileNetworkConnectivity: StateFlow<MobileConnectivityModel> =
        mobileConnectionsRepo.defaultMobileNetworkConnectivity

    /**
     * Mapping from network type to [MobileIconGroup] using the config generated for the default
     * subscription Id. This mapping is the same for every subscription.
@@ -207,6 +219,7 @@ constructor(
            activeDataConnectionHasDataEnabled,
            alwaysShowDataRatIcon,
            alwaysUseCdmaLevel,
            defaultMobileNetworkConnectivity,
            defaultMobileIconMapping,
            defaultMobileIconGroup,
            isDefaultConnectionFailed,
+14 −9
Original line number Diff line number Diff line
@@ -102,24 +102,29 @@ constructor(
            .stateIn(scope, SharingStarted.WhileSubscribed(), initial)
    }

    override val networkTypeIcon: Flow<Icon?> =
    private val showNetworkTypeIcon: Flow<Boolean> =
        combine(
                iconInteractor.networkTypeIconGroup,
            iconInteractor.isDataConnected,
            iconInteractor.isDataEnabled,
            iconInteractor.isDefaultConnectionFailed,
            iconInteractor.alwaysShowDataRatIcon,
            ) { networkTypeIconGroup, dataConnected, dataEnabled, failedConnection, alwaysShow ->
            iconInteractor.isConnected,
        ) { dataConnected, dataEnabled, failedConnection, alwaysShow, connected ->
            alwaysShow || (dataConnected && dataEnabled && !failedConnection && connected)
        }

    override val networkTypeIcon: Flow<Icon?> =
        combine(
                iconInteractor.networkTypeIconGroup,
                showNetworkTypeIcon,
            ) { networkTypeIconGroup, shouldShow ->
                val desc =
                    if (networkTypeIconGroup.dataContentDescription != 0)
                        ContentDescription.Resource(networkTypeIconGroup.dataContentDescription)
                    else null
                val icon = Icon.Resource(networkTypeIconGroup.dataType, desc)
                return@combine when {
                    alwaysShow -> icon
                    !dataConnected -> null
                    !dataEnabled -> null
                    failedConnection -> null
                    !shouldShow -> null
                    else -> icon
                }
            }
+2 −0
Original line number Diff line number Diff line
@@ -40,6 +40,8 @@ class FakeMobileIconInteractor(
            )
        )

    override val isConnected = MutableStateFlow(true)

    private val _iconGroup = MutableStateFlow<SignalIcon.MobileIconGroup>(TelephonyIcons.THREE_G)
    override val networkTypeIconGroup = _iconGroup

+3 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.telephony.TelephonyManager.NETWORK_TYPE_UMTS
import com.android.settingslib.SignalIcon.MobileIconGroup
import com.android.settingslib.mobile.TelephonyIcons
import com.android.systemui.log.table.TableLogBuffer
import com.android.systemui.statusbar.pipeline.mobile.data.model.MobileConnectivityModel
import com.android.systemui.statusbar.pipeline.mobile.data.model.SubscriptionModel
import com.android.systemui.statusbar.pipeline.mobile.util.MobileMappingsProxy
import kotlinx.coroutines.flow.MutableStateFlow
@@ -60,6 +61,8 @@ class FakeMobileIconsInteractor(

    override val alwaysUseCdmaLevel = MutableStateFlow(false)

    override val defaultMobileNetworkConnectivity = MutableStateFlow(MobileConnectivityModel())

    private val _defaultMobileIconMapping = MutableStateFlow(TEST_MAPPING)
    override val defaultMobileIconMapping = _defaultMobileIconMapping

Loading