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

Commit 08fc0a67 authored by Evan Laird's avatar Evan Laird
Browse files

Partial revert of "[SB Refactor] Remove unused `isDefaultDataSubscription` flow."

Reference commit 3747a472.

The reverted commit removed MobileConnectionsRepository.defaultDataSubId
and MobileConnectionRepository.isDefaultDataSubscription, the latter of
which was truly unused and incorrectly defined. The former, however, is
the one needed for NOT_DEFAULT_DATA

Test: MobileConnectionsRepositoryTest
Bug: 238425913
Change-Id: I0945a29d50e42ae8f0a09fd54fcfc5d4b4e4affe
parent 7f894afe
Loading
Loading
Loading
Loading
+4 −0
Original line number Original line Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.systemui.statusbar.pipeline.mobile.data.repository


import android.provider.Settings
import android.provider.Settings
import android.telephony.CarrierConfigManager
import android.telephony.CarrierConfigManager
import android.telephony.SubscriptionManager
import com.android.settingslib.SignalIcon.MobileIconGroup
import com.android.settingslib.SignalIcon.MobileIconGroup
import com.android.settingslib.mobile.MobileMappings
import com.android.settingslib.mobile.MobileMappings
import com.android.settingslib.mobile.MobileMappings.Config
import com.android.settingslib.mobile.MobileMappings.Config
@@ -43,6 +44,9 @@ interface MobileConnectionsRepository {
     */
     */
    val activeSubChangedInGroupEvent: Flow<Unit>
    val activeSubChangedInGroupEvent: Flow<Unit>


    /** Tracks [SubscriptionManager.getDefaultDataSubscriptionId] */
    val defaultDataSubId: StateFlow<Int>

    /** The current connectivity status for the default mobile network connection */
    /** The current connectivity status for the default mobile network connection */
    val defaultMobileNetworkConnectivity: StateFlow<MobileConnectivityModel>
    val defaultMobileNetworkConnectivity: StateFlow<MobileConnectivityModel>


+5 −0
Original line number Original line Diff line number Diff line
@@ -142,6 +142,11 @@ constructor(
    override val defaultMobileIconGroup: Flow<SignalIcon.MobileIconGroup> =
    override val defaultMobileIconGroup: Flow<SignalIcon.MobileIconGroup> =
        activeRepo.flatMapLatest { it.defaultMobileIconGroup }
        activeRepo.flatMapLatest { it.defaultMobileIconGroup }


    override val defaultDataSubId: StateFlow<Int> =
        activeRepo
            .flatMapLatest { it.defaultDataSubId }
            .stateIn(scope, SharingStarted.WhileSubscribed(), realRepository.defaultDataSubId.value)

    override val defaultMobileNetworkConnectivity: StateFlow<MobileConnectivityModel> =
    override val defaultMobileNetworkConnectivity: StateFlow<MobileConnectivityModel> =
        activeRepo
        activeRepo
            .flatMapLatest { it.defaultMobileNetworkConnectivity }
            .flatMapLatest { it.defaultMobileNetworkConnectivity }
+6 −0
Original line number Original line Diff line number Diff line
@@ -152,6 +152,9 @@ constructor(


    private fun <K, V> Map<K, V>.reverse() = entries.associateBy({ it.value }) { it.key }
    private fun <K, V> Map<K, V>.reverse() = entries.associateBy({ it.value }) { it.key }


    // TODO(b/261029387): add a command for this value
    override val defaultDataSubId = MutableStateFlow(INVALID_SUBSCRIPTION_ID)

    // TODO(b/261029387): not yet supported
    // TODO(b/261029387): not yet supported
    override val defaultMobileNetworkConnectivity = MutableStateFlow(MobileConnectivityModel())
    override val defaultMobileNetworkConnectivity = MutableStateFlow(MobileConnectivityModel())


@@ -233,6 +236,9 @@ constructor(
        val connection = getRepoForSubId(subId)
        val connection = getRepoForSubId(subId)
        connectionRepoCache[subId]?.lastMobileState = state
        connectionRepoCache[subId]?.lastMobileState = state


        // TODO(b/261029387): until we have a command, use the most recent subId
        defaultDataSubId.value = subId

        // This is always true here, because we split out disabled states at the data-source level
        // This is always true here, because we split out disabled states at the data-source level
        connection.dataEnabled.value = true
        connection.dataEnabled.value = true
        connection.networkName.value = NetworkNameModel.Derived(state.name)
        connection.networkName.value = NetworkNameModel.Derived(state.name)
+19 −3
Original line number Original line Diff line number Diff line
@@ -35,6 +35,7 @@ import android.telephony.TelephonyCallback
import android.telephony.TelephonyCallback.ActiveDataSubscriptionIdListener
import android.telephony.TelephonyCallback.ActiveDataSubscriptionIdListener
import android.telephony.TelephonyManager
import android.telephony.TelephonyManager
import androidx.annotation.VisibleForTesting
import androidx.annotation.VisibleForTesting
import com.android.internal.telephony.PhoneConstants
import com.android.settingslib.SignalIcon.MobileIconGroup
import com.android.settingslib.SignalIcon.MobileIconGroup
import com.android.settingslib.mobile.MobileMappings.Config
import com.android.settingslib.mobile.MobileMappings.Config
import com.android.systemui.R
import com.android.systemui.R
@@ -61,6 +62,7 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.asExecutor
import kotlinx.coroutines.asExecutor
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.distinctUntilChanged
@@ -162,10 +164,24 @@ constructor(
            .logInputChange(logger, "onActiveDataSubscriptionIdChanged")
            .logInputChange(logger, "onActiveDataSubscriptionIdChanged")
            .stateIn(scope, started = SharingStarted.WhileSubscribed(), INVALID_SUBSCRIPTION_ID)
            .stateIn(scope, started = SharingStarted.WhileSubscribed(), INVALID_SUBSCRIPTION_ID)


    private val defaultDataSubIdChangedEvent =
    private val defaultDataSubIdChangeEvent: MutableSharedFlow<Unit> =
        MutableSharedFlow(extraBufferCapacity = 1)

    override val defaultDataSubId: StateFlow<Int> =
        broadcastDispatcher
        broadcastDispatcher
            .broadcastFlow(IntentFilter(TelephonyManager.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED))
            .broadcastFlow(
                IntentFilter(TelephonyManager.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED)
            ) { intent, _ ->
                intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY, INVALID_SUBSCRIPTION_ID)
            }
            .distinctUntilChanged()
            .logInputChange(logger, "ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED")
            .logInputChange(logger, "ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED")
            .onEach { defaultDataSubIdChangeEvent.tryEmit(Unit) }
            .stateIn(
                scope,
                SharingStarted.WhileSubscribed(),
                SubscriptionManager.getDefaultDataSubscriptionId()
            )


    private val carrierConfigChangedEvent =
    private val carrierConfigChangedEvent =
        broadcastDispatcher
        broadcastDispatcher
@@ -173,7 +189,7 @@ constructor(
            .logInputChange(logger, "ACTION_CARRIER_CONFIG_CHANGED")
            .logInputChange(logger, "ACTION_CARRIER_CONFIG_CHANGED")


    override val defaultDataSubRatConfig: StateFlow<Config> =
    override val defaultDataSubRatConfig: StateFlow<Config> =
        merge(defaultDataSubIdChangedEvent, carrierConfigChangedEvent)
        merge(defaultDataSubIdChangeEvent, carrierConfigChangedEvent)
            .mapLatest { Config.readConfig(context) }
            .mapLatest { Config.readConfig(context) }
            .distinctUntilChanged()
            .distinctUntilChanged()
            .logInputChange(logger, "defaultDataSubRatConfig")
            .logInputChange(logger, "defaultDataSubRatConfig")
+7 −0
Original line number Original line Diff line number Diff line
@@ -59,6 +59,9 @@ class FakeMobileConnectionsRepository(
    override val activeMobileDataSubscriptionId = _activeMobileDataSubscriptionId
    override val activeMobileDataSubscriptionId = _activeMobileDataSubscriptionId
    override val activeSubChangedInGroupEvent: MutableSharedFlow<Unit> = MutableSharedFlow()
    override val activeSubChangedInGroupEvent: MutableSharedFlow<Unit> = MutableSharedFlow()


    private val _defaultDataSubId = MutableStateFlow(INVALID_SUBSCRIPTION_ID)
    override val defaultDataSubId = _defaultDataSubId

    private val _mobileConnectivity = MutableStateFlow(MobileConnectivityModel())
    private val _mobileConnectivity = MutableStateFlow(MobileConnectivityModel())
    override val defaultMobileNetworkConnectivity = _mobileConnectivity
    override val defaultMobileNetworkConnectivity = _mobileConnectivity


@@ -83,6 +86,10 @@ class FakeMobileConnectionsRepository(
        _subscriptions.value = subs
        _subscriptions.value = subs
    }
    }


    fun setDefaultDataSubId(id: Int) {
        _defaultDataSubId.value = id
    }

    fun setMobileConnectivity(model: MobileConnectivityModel) {
    fun setMobileConnectivity(model: MobileConnectivityModel) {
        _mobileConnectivity.value = model
        _mobileConnectivity.value = model
    }
    }
Loading