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

Commit 6acee7b1 authored by Evan Laird's avatar Evan Laird
Browse files

[Sb refactor] Support NetworkName in new mobile pipeline

The network name can come from one of 3 places:
1. TelephonyManager.ACTION_SERVICE_PROVIDERS_UPDATED, which passes an
   intent containing a network name which we can derive
2. ServiceState.getOperatorAlphaShort(), from the service state changed
   telephony callback
3. A default value, set in the framework config
   `lockscreen_carrier_default`

Based on the implementation that currently lives in
`MobileSignalController`, we were only using `NetworkName` a.k.a.
`EXTRA_SPN`, and not `NetworkNameData` a.k.a. `EXTRA_DATA_SPN`.
Therefore this CL only adds support for the former.

The front end does not consume this piece of data yet, since it is only
needed for QuickSettings. Future CLs will add support for a
LocationBasedMobileViewModel (similar to Wi-Fi), which can then start
consuming the values.

Test: MobileConnectionRepositoryTest
Test: DemoMobileConnectionsRepositoryTest
Test: MobileIconInteractorTest
Bug: 238425913
Change-Id: I04fa90bf7b52aa992f9721c7301f541f6085cf68
parent 0fb69e95
Loading
Loading
Loading
Loading
+16 −7
Original line number Diff line number Diff line
@@ -39,33 +39,42 @@ import com.android.systemui.statusbar.pipeline.shared.data.model.DataActivityMod
 * threading complex system objects through the pipeline.
 */
data class MobileConnectionModel(
    /** From [ServiceStateListener.onServiceStateChanged] */
    /** Fields below are from [ServiceStateListener.onServiceStateChanged] */
    val isEmergencyOnly: Boolean = false,
    val isRoaming: Boolean = false,
    /**
     * See [android.telephony.ServiceState.getOperatorAlphaShort], this value is defined as the
     * current registered operator name in short alphanumeric format. In some cases this name might
     * be preferred over other methods of calculating the network name
     */
    val operatorAlphaShort: String? = null,

    /** From [SignalStrengthsListener.onSignalStrengthsChanged] */
    /** Fields below from [SignalStrengthsListener.onSignalStrengthsChanged] */
    val isGsm: Boolean = false,
    @IntRange(from = 0, to = 4)
    val cdmaLevel: Int = CellSignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN,
    @IntRange(from = 0, to = 4)
    val primaryLevel: Int = CellSignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN,

    /** Mapped from [DataConnectionStateListener.onDataConnectionStateChanged] */
    /** Fields below from [DataConnectionStateListener.onDataConnectionStateChanged] */
    val dataConnectionState: DataConnectionState = Disconnected,

    /** From [DataActivityListener.onDataActivity]. See [TelephonyManager] for the values */
    /**
     * Fields below from [DataActivityListener.onDataActivity]. See [TelephonyManager] for the
     * values
     */
    val dataActivityDirection: DataActivityModel =
        DataActivityModel(
            hasActivityIn = false,
            hasActivityOut = false,
        ),

    /** From [CarrierNetworkListener.onCarrierNetworkChange] */
    /** Fields below from [CarrierNetworkListener.onCarrierNetworkChange] */
    val carrierNetworkChangeActive: Boolean = false,

    /** Fields below from [DisplayInfoListener.onDisplayInfoChanged]. */

    /**
     * From [DisplayInfoListener.onDisplayInfoChanged].
     *
     * [resolvedNetworkType] is the [TelephonyDisplayInfo.getOverrideNetworkType] if it exists or
     * [TelephonyDisplayInfo.getNetworkType]. This is used to look up the proper network type icon
     */
+62 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.statusbar.pipeline.mobile.data.model

import android.content.Intent
import android.telephony.TelephonyManager.EXTRA_DATA_SPN
import android.telephony.TelephonyManager.EXTRA_PLMN
import android.telephony.TelephonyManager.EXTRA_SHOW_PLMN
import android.telephony.TelephonyManager.EXTRA_SHOW_SPN

/**
 * Encapsulates the data needed to show a network name for a mobile network. The data is parsed from
 * the intent sent by [android.telephony.TelephonyManager.ACTION_SERVICE_PROVIDERS_UPDATED].
 */
sealed interface NetworkNameModel {
    val name: String

    /** The default name is read from [com.android.internal.R.string.lockscreen_carrier_default] */
    data class Default(override val name: String) : 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
}

fun Intent.toNetworkNameModel(separator: String): NetworkNameModel? {
    val showSpn = getBooleanExtra(EXTRA_SHOW_SPN, false)
    val spn = getStringExtra(EXTRA_DATA_SPN)
    val showPlmn = getBooleanExtra(EXTRA_SHOW_PLMN, false)
    val plmn = getStringExtra(EXTRA_PLMN)

    val str = StringBuilder()
    val strData = StringBuilder()
    if (showPlmn && plmn != null) {
        str.append(plmn)
        strData.append(plmn)
    }
    if (showSpn && spn != null) {
        if (str.isNotEmpty()) {
            str.append(separator)
        }
        str.append(spn)
    }

    return if (str.isNotEmpty()) NetworkNameModel.Derived(str.toString()) else null
}
+4 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.telephony.SubscriptionManager
import android.telephony.TelephonyCallback
import android.telephony.TelephonyManager
import com.android.systemui.statusbar.pipeline.mobile.data.model.MobileConnectionModel
import com.android.systemui.statusbar.pipeline.mobile.data.model.NetworkNameModel
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.StateFlow

@@ -58,4 +59,7 @@ interface MobileConnectionRepository {
     * True if the Enhanced Roaming Indicator (ERI) display number is not [TelephonyManager.ERI_OFF]
     */
    val cdmaRoaming: StateFlow<Boolean>

    /** The service provider name for this network connection, or the default name */
    val networkName: StateFlow<NetworkNameModel>
}
+4 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.statusbar.pipeline.mobile.data.model.DataConnectionState
import com.android.systemui.statusbar.pipeline.mobile.data.model.MobileConnectionModel
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.model.ResolvedNetworkType.DefaultNetworkType
import com.android.systemui.statusbar.pipeline.mobile.data.model.SubscriptionModel
@@ -187,6 +188,7 @@ constructor(
        // This is always true here, because we split out disabled states at the data-source level
        connection.dataEnabled.value = true
        connection.isDefaultDataSubscription.value = state.dataType != null
        connection.networkName.value = NetworkNameModel.Derived(state.name)

        connection.cdmaRoaming.value = state.roaming
        connection.connectionInfo.value = state.toMobileConnectionModel()
@@ -266,4 +268,6 @@ class DemoMobileConnectionRepository(override val subId: Int) : MobileConnection
    override val isDefaultDataSubscription = MutableStateFlow(true)

    override val cdmaRoaming = MutableStateFlow(false)

    override val networkName = MutableStateFlow(NetworkNameModel.Derived("demo network"))
}
+2 −0
Original line number Diff line number Diff line
@@ -99,6 +99,7 @@ constructor(
        val activity = getString("activity")?.toActivity()
        val carrierNetworkChange = getString("carriernetworkchange") == "show"
        val roaming = getString("roam") == "show"
        val name = getString("networkname") ?: "demo mode"

        return Mobile(
            level = level,
@@ -109,6 +110,7 @@ constructor(
            activity = activity,
            carrierNetworkChange = carrierNetworkChange,
            roaming = roaming,
            name = name,
        )
    }
}
Loading