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

Commit 18b730cb authored by Caitlin Shkuratov's avatar Caitlin Shkuratov Committed by Android (Google) Code Review
Browse files

Merge changes I6a6916fd,Ia7fdd0c8,Id2e73b83,If3e00d82,Ia7eb62d6 into tm-qpr-dev

* changes:
  [SB Refactor] Support network names for carrier merged.
  [SB Refactor] Cleanups in the carrier merged connection repo.
  [SB Refactor] Don't update the network name if the subId doesn't match.
  [SB Refactor] Supprt activity in/out for carrier merged connections.
  [SB Refactor] Make demo wifi's activity always non-null.
parents cf12ebac 698a80bf
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
}
+10 −4
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()
@@ -258,10 +258,13 @@ constructor(
        maybeCreateSubscription(subId)
        carrierMergedSubId = subId

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

        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()
@@ -336,7 +339,10 @@ constructor(
    }

    private fun FakeWifiEventModel.CarrierMerged.toMobileConnectionModel(): MobileConnectionModel {
        return createCarrierMergedConnectionModel(this.level)
        return createCarrierMergedConnectionModel(
            this.level,
            activity.toMobileDataActivityModel(),
        )
    }

    private fun SignalIcon.MobileIconGroup?.toResolvedNetworkType(): ResolvedNetworkType {
@@ -371,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"))
}
+43 −34
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
@@ -87,17 +95,28 @@ class CarrierMergedConnectionRepository(
        }

    override val connectionInfo: StateFlow<MobileConnectionModel> =
        network
            .map { it.toMobileConnectionModel() }
        combine(network, wifiRepository.wifiActivity) { network, activity ->
                if (network == null) {
                    MobileConnectionModel()
                } else {
                    createCarrierMergedConnectionModel(network.level, activity)
                }
            }
            .stateIn(scope, SharingStarted.WhileSubscribed(), MobileConnectionModel())

    // Carrier merged is never roaming.
    override val cdmaRoaming: StateFlow<Boolean> = MutableStateFlow(false).asStateFlow()
    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
@@ -112,37 +131,24 @@ class CarrierMergedConnectionRepository(

    override val dataEnabled: StateFlow<Boolean> = wifiRepository.isWifiEnabled

    private fun WifiNetworkModel.CarrierMerged?.toMobileConnectionModel(): MobileConnectionModel {
        if (this == null) {
            return MobileConnectionModel()
        }

        return createCarrierMergedConnectionModel(level)
    }

    companion object {
        /**
         * Creates an instance of [MobileConnectionModel] that represents a carrier merged network
         * with the given [level].
         * with the given [level] and [activity].
         */
        fun createCarrierMergedConnectionModel(level: Int): MobileConnectionModel {
        fun createCarrierMergedConnectionModel(
            level: Int,
            activity: DataActivityModel,
        ): MobileConnectionModel {
            return MobileConnectionModel(
                primaryLevel = level,
                cdmaLevel = level,
                // A [WifiNetworkModel.CarrierMerged] instance is always connected.
                // (A [WifiNetworkModel.Inactive] represents a disconnected network.)
                dataConnectionState = DataConnectionState.Connected,
                // TODO(b/238425913): This should come from [WifiRepository.wifiActivity].
                dataActivityDirection =
                    DataActivityModel(
                        hasActivityIn = false,
                        hasActivityOut = false,
                    ),
                dataActivityDirection = activity,
                // Here and below: These values are always the same for every carrier-merged
                // connection.
                resolvedNetworkType = ResolvedNetworkType.CarrierMergedNetworkType,
                // Carrier merged is never roaming
                isRoaming = false,

                // TODO(b/238425913): Verify that these fields never change for carrier merged.
                dataConnectionState = DataConnectionState.Connected,
                isRoaming = ROAMING,
                isEmergencyOnly = false,
                operatorAlphaShort = null,
                isInService = true,
@@ -150,24 +156,27 @@ class CarrierMergedConnectionRepository(
                carrierNetworkChangeActive = false,
            )
        }

        // Carrier merged is never roaming
        private const val ROAMING = false
    }

    @SysUISingleton
    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
+9 −9
Original line number Diff line number Diff line
@@ -61,6 +61,7 @@ import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.mapLatest
import kotlinx.coroutines.flow.mapNotNull
@@ -91,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."
            )
        }
@@ -267,15 +268,14 @@ class MobileConnectionRepositoryImpl(

    override val networkName: StateFlow<NetworkNameModel> =
        broadcastDispatcher
            .broadcastFlow(IntentFilter(TelephonyManager.ACTION_SERVICE_PROVIDERS_UPDATED)) {
                intent,
                _ ->
                if (intent.getIntExtra(EXTRA_SUBSCRIPTION_ID, INVALID_SUBSCRIPTION_ID) != subId) {
                    defaultNetworkName
                } else {
                    intent.toNetworkNameModel(networkNameSeparator) ?: defaultNetworkName
                }
            .broadcastFlow(
                filter = IntentFilter(TelephonyManager.ACTION_SERVICE_PROVIDERS_UPDATED),
                map = { intent, _ -> intent },
            )
            .filter { intent ->
                intent.getIntExtra(EXTRA_SUBSCRIPTION_ID, INVALID_SUBSCRIPTION_ID) == subId
            }
            .map { intent -> intent.toNetworkNameModel(networkNameSeparator) ?: defaultNetworkName }
            .stateIn(scope, SharingStarted.WhileSubscribed(), defaultNetworkName)

    override val dataEnabled = run {
Loading