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

Commit d0d9fbe3 authored by Caitlin Shkuratov's avatar Caitlin Shkuratov
Browse files

[SB Refactor] Supprt activity in/out for carrier merged connections.

Bug: 238425913
Bug: 264684296
Test: manual: `adb shell am broadcast -a com.android.systemui.demo
-e command network -e wifi carriermerged -e level 2 -e activity out` ->
shows carrier merged connection with activity arrows
Test: atest CarrierMergedConnectionRepositoryTest

Change-Id: If3e00d82c0278bba68da08f972da002729f1a5a3
parent d13a04f7
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -258,6 +258,9 @@ 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
@@ -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 {
+13 −18
Original line number Diff line number Diff line
@@ -87,8 +87,13 @@ 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.
@@ -112,32 +117,22 @@ 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,
                resolvedNetworkType = ResolvedNetworkType.CarrierMergedNetworkType,
                // Carrier merged is never roaming
                isRoaming = false,
+2 −1
Original line number Diff line number Diff line
@@ -69,8 +69,9 @@ constructor(
        val subId = getString("slot")?.toInt() ?: DEFAULT_CARRIER_MERGED_SUB_ID
        val level = getString("level")?.toInt() ?: 0
        val numberOfLevels = getString("numlevels")?.toInt() ?: DEFAULT_NUM_LEVELS
        val activity = getString("activity").toActivity()

        return FakeWifiEventModel.CarrierMerged(subId, level, numberOfLevels)
        return FakeWifiEventModel.CarrierMerged(subId, level, numberOfLevels, activity)
    }

    private fun String?.toActivity(): Int =
+1 −2
Original line number Diff line number Diff line
@@ -87,8 +87,7 @@ constructor(
    private fun processCarrierMergedWifiState(event: FakeWifiEventModel.CarrierMerged) {
        _isWifiEnabled.value = true
        _isWifiDefault.value = true
        // TODO(b/238425913): Support activity in demo mode.
        _wifiActivity.value = DataActivityModel(hasActivityIn = false, hasActivityOut = false)
        _wifiActivity.value = event.activity.toWifiDataActivityModel()
        _wifiNetwork.value = event.toCarrierMergedModel()
    }

+1 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ sealed interface FakeWifiEventModel {
        val subscriptionId: Int,
        val level: Int,
        val numberOfLevels: Int,
        @Annotation.DataActivityType val activity: Int,
    ) : FakeWifiEventModel

    object WifiDisabled : FakeWifiEventModel
Loading