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

Commit 8bb53fda authored by Evan Laird's avatar Evan Laird
Browse files

[sb] fallback from data_spn to spn

This is a tweak on recent changed behavior to move to SPN from DATA_SPN.
Instead of picking just one field from the intent, we implement a
fallback. This allows for carrier customization on the DATA_SPN field,
while still not failing in the case where DATA_SPN is null.

Test: MobileConnectionRepositoryTest
Flag: com.android.systemui.status_bar_switch_to_spn_from_data_spn
Bug: 358669494
Change-Id: I3cdf3566b2f3ee7359aa2f67d05535ec880ef6c0
parent cdda826a
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -100,7 +100,14 @@ fun Intent.toNetworkNameModel(separator: String): NetworkNameModel? {
    val showSpn = getBooleanExtra(EXTRA_SHOW_SPN, false)
    val spn =
        if (statusBarSwitchToSpnFromDataSpn()) {
            // Context: b/358669494. Use DATA_SPN if it exists, since that allows carriers to
            // customize the display name. Otherwise, fall back to the SPN
            val dataSpn = getStringExtra(EXTRA_DATA_SPN)
            if (dataSpn.isNullOrEmpty()) {
                getStringExtra(EXTRA_SPN)
            } else {
                dataSpn
            }
        } else {
            getStringExtra(EXTRA_DATA_SPN)
        }
@@ -109,10 +116,8 @@ fun Intent.toNetworkNameModel(separator: String): NetworkNameModel? {
    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()) {
+88 −7
Original line number Diff line number Diff line
@@ -821,7 +821,7 @@ class MobileConnectionRepositoryTest : SysuiTestCase() {
            captor.lastValue.onReceive(context, intent)

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

            job.cancel()
        }
@@ -856,7 +856,7 @@ class MobileConnectionRepositoryTest : SysuiTestCase() {
            verify(context).registerReceiver(captor.capture(), any())
            captor.lastValue.onReceive(context, intent)

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

            // WHEN an intent with a different subId is sent
            val wrongSubIntent = spnIntent(subId = 101)
@@ -864,7 +864,7 @@ class MobileConnectionRepositoryTest : SysuiTestCase() {
            captor.lastValue.onReceive(context, wrongSubIntent)

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

            job.cancel()
        }
@@ -906,7 +906,7 @@ class MobileConnectionRepositoryTest : SysuiTestCase() {
            verify(context).registerReceiver(captor.capture(), any())
            captor.lastValue.onReceive(context, intent)

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

            val intentWithoutInfo =
                spnIntent(
@@ -965,7 +965,7 @@ class MobileConnectionRepositoryTest : SysuiTestCase() {

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

    @Test
@@ -990,7 +990,7 @@ class MobileConnectionRepositoryTest : SysuiTestCase() {

    @Test
    @EnableFlags(Flags.FLAG_STATUS_BAR_SWITCH_TO_SPN_FROM_DATA_SPN)
    fun networkName_allFieldsSet_doesNotUseDataSpn() =
    fun networkName_allFieldsSet_prioritizesDataSpnOverSpn() =
        testScope.runTest {
            val latest by collectLastValue(underTest.networkName)
            val captor = argumentCaptor<BroadcastReceiver>()
@@ -1006,6 +1006,27 @@ class MobileConnectionRepositoryTest : SysuiTestCase() {
                    plmn = PLMN,
                )
            captor.lastValue.onReceive(context, intent)
            assertThat(latest).isEqualTo(NetworkNameModel.IntentDerived("$PLMN$SEP$DATA_SPN"))
        }

    @Test
    @EnableFlags(Flags.FLAG_STATUS_BAR_SWITCH_TO_SPN_FROM_DATA_SPN)
    fun networkName_spnAndPlmn_fallbackToSpnWhenNullDataSpn() =
        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"))
        }

@@ -1047,7 +1068,27 @@ class MobileConnectionRepositoryTest : SysuiTestCase() {
                    plmn = PLMN,
                )
            captor.lastValue.onReceive(context, intent)
            assertThat(latest).isEqualTo(NetworkNameModel.IntentDerived("$PLMN"))
            assertThat(latest).isEqualTo(NetworkNameModel.IntentDerived("$PLMN$SEP$DATA_SPN"))
        }

    @Test
    @EnableFlags(Flags.FLAG_STATUS_BAR_SWITCH_TO_SPN_FROM_DATA_SPN)
    fun networkName_showPlmn_plmnNotNull_showSpn_spnNotNull_dataSpnNull() =
        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
@@ -1106,9 +1147,49 @@ class MobileConnectionRepositoryTest : SysuiTestCase() {
                    plmn = null,
                )
            captor.lastValue.onReceive(context, intent)
            assertThat(latest).isEqualTo(NetworkNameModel.IntentDerived("$DATA_SPN"))
        }

    @Test
    @EnableFlags(Flags.FLAG_STATUS_BAR_SWITCH_TO_SPN_FROM_DATA_SPN)
    fun networkName_showPlmn_plmnNull_showSpn_dataSpnNull() =
        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 = null,
                )
            captor.lastValue.onReceive(context, intent)
            assertThat(latest).isEqualTo(NetworkNameModel.IntentDerived("$SPN"))
        }

    @Test
    @EnableFlags(Flags.FLAG_STATUS_BAR_SWITCH_TO_SPN_FROM_DATA_SPN)
    fun networkName_showPlmn_plmnNull_showSpn_bothSpnNull() =
        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 = null,
                    showPlmn = true,
                    plmn = null,
                )
            captor.lastValue.onReceive(context, intent)
            assertThat(latest).isEqualTo(DEFAULT_NAME_MODEL)
        }

    @Test
    @DisableFlags(Flags.FLAG_STATUS_BAR_SWITCH_TO_SPN_FROM_DATA_SPN)
    fun networkName_showPlmn_plmnNull_showSpn_flagOff() =