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

Commit ceb015e7 authored by Evan Laird's avatar Evan Laird Committed by Android Build Coastguard Worker
Browse files

[Mobile] Add SPN to network name calculation

An oversight from the initial migration away from
MobileSignalController; NetworkNameModel was only considering the
DATA_SPN when calculating the network name, but it needed to consider
_both_ the SPN and the DATA_SPN.

Also addressed the fact that the tests were calling the same function
and wouldn't catch this issue.

Test: MobileConnectionRepositoryTest
Bug: 350812372
Flag: NONE bugfix
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:73f375e27b973cd2bee5b60c0c2f7dfce40ff7d9)
Merged-In: I492ab0d77c93f371589abc56a3faca9bc516a407
Change-Id: I492ab0d77c93f371589abc56a3faca9bc516a407
parent 8f63e454
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ 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
import android.telephony.TelephonyManager.EXTRA_SPN
import com.android.systemui.log.table.Diffable
import com.android.systemui.log.table.TableRowLogger

@@ -96,7 +97,8 @@ sealed interface NetworkNameModel : Diffable<NetworkNameModel> {

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

@@ -112,6 +114,12 @@ fun Intent.toNetworkNameModel(separator: String): NetworkNameModel? {
        }
        str.append(spn)
    }
    if (showSpn && dataSpn != null) {
        if (str.isNotEmpty()) {
            str.append(separator)
        }
        str.append(dataSpn)
    }

    return if (str.isNotEmpty()) NetworkNameModel.IntentDerived(str.toString()) else null
}
+102 −16
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ import android.telephony.TelephonyManager.DATA_UNKNOWN
import android.telephony.TelephonyManager.ERI_OFF
import android.telephony.TelephonyManager.ERI_ON
import android.telephony.TelephonyManager.EXTRA_CARRIER_ID
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
@@ -84,7 +85,6 @@ import com.android.systemui.statusbar.pipeline.mobile.data.model.SubscriptionMod
import com.android.systemui.statusbar.pipeline.mobile.data.model.SystemUiCarrierConfig
import com.android.systemui.statusbar.pipeline.mobile.data.model.SystemUiCarrierConfigTest.Companion.configWithOverride
import com.android.systemui.statusbar.pipeline.mobile.data.model.SystemUiCarrierConfigTest.Companion.createTestConfig
import com.android.systemui.statusbar.pipeline.mobile.data.model.toNetworkNameModel
import com.android.systemui.statusbar.pipeline.mobile.data.repository.FakeMobileConnectionsRepository
import com.android.systemui.statusbar.pipeline.mobile.data.repository.MobileConnectionRepository.Companion.DEFAULT_NUM_LEVELS
import com.android.systemui.statusbar.pipeline.mobile.data.repository.prod.MobileTelephonyHelpers.signalStrength
@@ -92,8 +92,6 @@ import com.android.systemui.statusbar.pipeline.mobile.data.repository.prod.Mobil
import com.android.systemui.statusbar.pipeline.mobile.util.FakeMobileMappingsProxy
import com.android.systemui.statusbar.pipeline.shared.data.model.DataActivityModel
import com.android.systemui.statusbar.pipeline.shared.data.model.toMobileDataActivityModel
import com.android.systemui.util.mockito.any
import com.android.systemui.util.mockito.argumentCaptor
import com.android.systemui.util.mockito.mock
import com.android.systemui.util.mockito.whenever
import com.android.systemui.util.mockito.withArgCaptor
@@ -110,6 +108,8 @@ import org.junit.Test
import org.mockito.Mock
import org.mockito.Mockito.verify
import org.mockito.MockitoAnnotations
import org.mockito.kotlin.any
import org.mockito.kotlin.argumentCaptor

@Suppress("EXPERIMENTAL_IS_NOT_ENABLED")
@OptIn(ExperimentalCoroutinesApi::class)
@@ -812,9 +812,11 @@ class MobileConnectionRepositoryTest : SysuiTestCase() {
            val intent = spnIntent()
            val captor = argumentCaptor<BroadcastReceiver>()
            verify(context).registerReceiver(captor.capture(), any())
            captor.value!!.onReceive(context, intent)
            captor.lastValue.onReceive(context, intent)

            assertThat(latest).isEqualTo(intent.toNetworkNameModel(SEP))
            // spnIntent() sets all values to true and test strings
            assertThat(latest)
                .isEqualTo(NetworkNameModel.IntentDerived("$PLMN$SEP$SPN$SEP$DATA_SPN"))

            job.cancel()
        }
@@ -828,17 +830,19 @@ class MobileConnectionRepositoryTest : SysuiTestCase() {
            val intent = spnIntent()
            val captor = argumentCaptor<BroadcastReceiver>()
            verify(context).registerReceiver(captor.capture(), any())
            captor.value!!.onReceive(context, intent)
            captor.lastValue.onReceive(context, intent)

            assertThat(latest).isEqualTo(intent.toNetworkNameModel(SEP))
            assertThat(latest)
                .isEqualTo(NetworkNameModel.IntentDerived("$PLMN$SEP$SPN$SEP$DATA_SPN"))

            // WHEN an intent with a different subId is sent
            val wrongSubIntent = spnIntent(subId = 101)

            captor.value!!.onReceive(context, wrongSubIntent)
            captor.lastValue.onReceive(context, wrongSubIntent)

            // THEN the previous intent's name is still used
            assertThat(latest).isEqualTo(intent.toNetworkNameModel(SEP))
            assertThat(latest)
                .isEqualTo(NetworkNameModel.IntentDerived("$PLMN$SEP$SPN$SEP$DATA_SPN"))

            job.cancel()
        }
@@ -852,9 +856,10 @@ class MobileConnectionRepositoryTest : SysuiTestCase() {
            val intent = spnIntent()
            val captor = argumentCaptor<BroadcastReceiver>()
            verify(context).registerReceiver(captor.capture(), any())
            captor.value!!.onReceive(context, intent)
            captor.lastValue.onReceive(context, intent)

            assertThat(latest).isEqualTo(intent.toNetworkNameModel(SEP))
            assertThat(latest)
                .isEqualTo(NetworkNameModel.IntentDerived("$PLMN$SEP$SPN$SEP$DATA_SPN"))

            val intentWithoutInfo =
                spnIntent(
@@ -862,7 +867,7 @@ class MobileConnectionRepositoryTest : SysuiTestCase() {
                    showPlmn = false,
                )

            captor.value!!.onReceive(context, intentWithoutInfo)
            captor.lastValue.onReceive(context, intentWithoutInfo)

            assertThat(latest).isEqualTo(DEFAULT_NAME_MODEL)

@@ -881,10 +886,88 @@ class MobileConnectionRepositoryTest : SysuiTestCase() {
            val intent = spnIntent()
            val captor = argumentCaptor<BroadcastReceiver>()
            verify(context).registerReceiver(captor.capture(), any())
            captor.value!!.onReceive(context, intent)
            captor.lastValue.onReceive(context, intent)

            // The value is still there despite no active subscribers
            assertThat(underTest.networkName.value).isEqualTo(intent.toNetworkNameModel(SEP))
            assertThat(underTest.networkName.value)
                .isEqualTo(NetworkNameModel.IntentDerived("$PLMN$SEP$SPN$SEP$DATA_SPN"))
        }

    @Test
    fun networkName_allFieldsSet() =
        testScope.runTest {
            val latest by collectLastValue(underTest.networkName)
            val captor = argumentCaptor<BroadcastReceiver>()
            verify(context).registerReceiver(captor.capture(), any())

            val intent =
                spnIntent(
                    subId = SUB_1_ID,
                    showSpn = true,
                    spn = SPN,
                    dataSpn = null,
                    showPlmn = true,
                    plmn = PLMN,
                )
            captor.lastValue.onReceive(context, intent)
            assertThat(latest).isEqualTo(NetworkNameModel.IntentDerived("$PLMN$SEP$SPN"))
        }

    @Test
    fun networkName_showPlmn_plmnNotNull_showSpn_spnNull_dataSpnNotNull() =
        testScope.runTest {
            val latest by collectLastValue(underTest.networkName)
            val captor = argumentCaptor<BroadcastReceiver>()
            verify(context).registerReceiver(captor.capture(), any())
            val intent =
                spnIntent(
                    subId = SUB_1_ID,
                    showSpn = true,
                    spn = null,
                    dataSpn = DATA_SPN,
                    showPlmn = true,
                    plmn = PLMN,
                )
            captor.lastValue.onReceive(context, intent)
            assertThat(latest).isEqualTo(NetworkNameModel.IntentDerived("$PLMN$SEP$DATA_SPN"))
        }

    @Test
    fun networkName_showPlmn_noShowSPN() =
        testScope.runTest {
            val latest by collectLastValue(underTest.networkName)
            val captor = argumentCaptor<BroadcastReceiver>()
            verify(context).registerReceiver(captor.capture(), any())
            val intent =
                spnIntent(
                    subId = SUB_1_ID,
                    showSpn = false,
                    spn = SPN,
                    dataSpn = DATA_SPN,
                    showPlmn = true,
                    plmn = PLMN,
                )
            captor.lastValue.onReceive(context, intent)
            assertThat(latest).isEqualTo(NetworkNameModel.IntentDerived("$PLMN"))
        }

    @Test
    fun networkName_showPlmn_plmnNull_showSpn() =
        testScope.runTest {
            val latest by collectLastValue(underTest.networkName)
            val captor = argumentCaptor<BroadcastReceiver>()
            verify(context).registerReceiver(captor.capture(), any())
            val intent =
                spnIntent(
                    subId = SUB_1_ID,
                    showSpn = true,
                    spn = SPN,
                    dataSpn = DATA_SPN,
                    showPlmn = true,
                    plmn = null,
                )
            captor.lastValue.onReceive(context, intent)
            assertThat(latest).isEqualTo(NetworkNameModel.IntentDerived("$SPN$SEP$DATA_SPN"))
        }

    @Test
@@ -1125,14 +1208,16 @@ class MobileConnectionRepositoryTest : SysuiTestCase() {
    private fun spnIntent(
        subId: Int = SUB_1_ID,
        showSpn: Boolean = true,
        spn: String = SPN,
        spn: String? = SPN,
        dataSpn: String? = DATA_SPN,
        showPlmn: Boolean = true,
        plmn: String = PLMN,
        plmn: String? = PLMN,
    ): Intent =
        Intent(TelephonyManager.ACTION_SERVICE_PROVIDERS_UPDATED).apply {
            putExtra(EXTRA_SUBSCRIPTION_INDEX, subId)
            putExtra(EXTRA_SHOW_SPN, showSpn)
            putExtra(EXTRA_SPN, spn)
            putExtra(EXTRA_DATA_SPN, dataSpn)
            putExtra(EXTRA_SHOW_PLMN, showPlmn)
            putExtra(EXTRA_PLMN, plmn)
        }
@@ -1145,6 +1230,7 @@ class MobileConnectionRepositoryTest : SysuiTestCase() {
        private const val SEP = "-"

        private const val SPN = "testSpn"
        private const val DATA_SPN = "testDataSpn"
        private const val PLMN = "testPlmn"
    }
}