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

Commit 698a80bf authored by Caitlin Shkuratov's avatar Caitlin Shkuratov
Browse files

[SB Refactor] Support network names for carrier merged.

Bug: 264684296
Bug: 238425913
Test: atest CarrierMergedConnectionRepositoryTest
Change-Id: I6a6916fd5826bf0b1b412a3d95ba864e6dd5d64e
parent e56123b6
Loading
Loading
Loading
Loading
+21 −5
Original line number Diff line number Diff line
@@ -48,15 +48,31 @@ sealed interface NetworkNameModel : Diffable<NetworkNameModel> {
     * This name has been derived from telephony intents. see
     * [android.telephony.TelephonyManager.ACTION_SERVICE_PROVIDERS_UPDATED]
     */
    data class Derived(override val name: String) : NetworkNameModel {
    data class IntentDerived(override val name: String) : NetworkNameModel {
        override fun logDiffs(prevVal: NetworkNameModel, row: TableRowLogger) {
            if (prevVal !is Derived || prevVal.name != name) {
                row.logChange(COL_NETWORK_NAME, "Derived($name)")
            if (prevVal !is IntentDerived || prevVal.name != name) {
                row.logChange(COL_NETWORK_NAME, "IntentDerived($name)")
            }
        }

        override fun logFull(row: TableRowLogger) {
            row.logChange(COL_NETWORK_NAME, "Derived($name)")
            row.logChange(COL_NETWORK_NAME, "IntentDerived($name)")
        }
    }

    /**
     * This name has been derived from the sim via
     * [android.telephony.TelephonyManager.getSimOperatorName].
     */
    data class SimDerived(override val name: String) : NetworkNameModel {
        override fun logDiffs(prevVal: NetworkNameModel, row: TableRowLogger) {
            if (prevVal !is SimDerived || prevVal.name != name) {
                row.logChange(COL_NETWORK_NAME, "SimDerived($name)")
            }
        }

        override fun logFull(row: TableRowLogger) {
            row.logChange(COL_NETWORK_NAME, "SimDerived($name)")
        }
    }

@@ -84,5 +100,5 @@ fun Intent.toNetworkNameModel(separator: String): NetworkNameModel? {
        str.append(spn)
    }

    return if (str.isNotEmpty()) NetworkNameModel.Derived(str.toString()) else null
    return if (str.isNotEmpty()) NetworkNameModel.IntentDerived(str.toString()) else null
}
+3 −3
Original line number Diff line number Diff line
@@ -240,7 +240,7 @@ constructor(

        // This is always true here, because we split out disabled states at the data-source level
        connection.dataEnabled.value = true
        connection.networkName.value = NetworkNameModel.Derived(state.name)
        connection.networkName.value = NetworkNameModel.IntentDerived(state.name)

        connection.cdmaRoaming.value = state.roaming
        connection.connectionInfo.value = state.toMobileConnectionModel()
@@ -264,7 +264,7 @@ constructor(
        val connection = getRepoForSubId(subId)
        // This is always true here, because we split out disabled states at the data-source level
        connection.dataEnabled.value = true
        connection.networkName.value = NetworkNameModel.Derived(CARRIER_MERGED_NAME)
        connection.networkName.value = NetworkNameModel.IntentDerived(CARRIER_MERGED_NAME)
        connection.numberOfLevels.value = event.numberOfLevels
        connection.cdmaRoaming.value = false
        connection.connectionInfo.value = event.toMobileConnectionModel()
@@ -377,5 +377,5 @@ class DemoMobileConnectionRepository(

    override val cdmaRoaming = MutableStateFlow(false)

    override val networkName = MutableStateFlow(NetworkNameModel.Derived("demo network"))
    override val networkName = MutableStateFlow(NetworkNameModel.IntentDerived("demo network"))
}
+22 −7
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.statusbar.pipeline.mobile.data.repository.prod

import android.telephony.TelephonyManager
import android.util.Log
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
@@ -37,7 +38,6 @@ import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn

@@ -54,10 +54,18 @@ import kotlinx.coroutines.flow.stateIn
class CarrierMergedConnectionRepository(
    override val subId: Int,
    override val tableLogBuffer: TableLogBuffer,
    defaultNetworkName: NetworkNameModel,
    private val telephonyManager: TelephonyManager,
    @Application private val scope: CoroutineScope,
    val wifiRepository: WifiRepository,
) : MobileConnectionRepository {
    init {
        if (telephonyManager.subscriptionId != subId) {
            throw IllegalStateException(
                "CarrierMergedRepo: TelephonyManager should be created with subId($subId). " +
                    "Found ${telephonyManager.subscriptionId} instead."
            )
        }
    }

    /**
     * Outputs the carrier merged network to use, or null if we don't have a valid carrier merged
@@ -98,10 +106,17 @@ class CarrierMergedConnectionRepository(

    override val cdmaRoaming: StateFlow<Boolean> = MutableStateFlow(ROAMING).asStateFlow()

    // TODO(b/238425913): Fetch the carrier merged network name.
    override val networkName: StateFlow<NetworkNameModel> =
        flowOf(defaultNetworkName)
            .stateIn(scope, SharingStarted.WhileSubscribed(), defaultNetworkName)
        network
            // The SIM operator name should be the same throughout the lifetime of a subId, **but**
            // it may not be available when this repo is created because it takes time to load. To
            // be safe, we re-fetch it each time the network has changed.
            .map { NetworkNameModel.SimDerived(telephonyManager.simOperatorName) }
            .stateIn(
                scope,
                SharingStarted.WhileSubscribed(),
                NetworkNameModel.SimDerived(telephonyManager.simOperatorName),
            )

    override val numberOfLevels: StateFlow<Int> =
        wifiRepository.wifiNetwork
@@ -150,18 +165,18 @@ class CarrierMergedConnectionRepository(
    class Factory
    @Inject
    constructor(
        private val telephonyManager: TelephonyManager,
        @Application private val scope: CoroutineScope,
        private val wifiRepository: WifiRepository,
    ) {
        fun build(
            subId: Int,
            mobileLogger: TableLogBuffer,
            defaultNetworkName: NetworkNameModel,
        ): MobileConnectionRepository {
            return CarrierMergedConnectionRepository(
                subId,
                mobileLogger,
                defaultNetworkName,
                telephonyManager.createForSubscriptionId(subId),
                scope,
                wifiRepository,
            )
+1 −1
Original line number Diff line number Diff line
@@ -86,7 +86,7 @@ class FullMobileConnectionRepository(
    }

    private val carrierMergedRepo: MobileConnectionRepository by lazy {
        carrierMergedRepoFactory.build(subId, tableLogBuffer, defaultNetworkName)
        carrierMergedRepoFactory.build(subId, tableLogBuffer)
    }

    @VisibleForTesting
+1 −1
Original line number Diff line number Diff line
@@ -92,7 +92,7 @@ class MobileConnectionRepositoryImpl(
    init {
        if (telephonyManager.subscriptionId != subId) {
            throw IllegalStateException(
                "TelephonyManager should be created with subId($subId). " +
                "MobileRepo: TelephonyManager should be created with subId($subId). " +
                    "Found ${telephonyManager.subscriptionId} instead."
            )
        }
Loading