diff options
author | 2024-09-05 14:49:45 -0400 | |
---|---|---|
committer | 2024-09-06 16:58:24 +0000 | |
commit | 8bb53fdae8ed19c988e66abb02d940b3c17a7029 (patch) | |
tree | fd202ac0d8983bbbe7a6a60563e7d7e058471607 | |
parent | cdda826a42d72a269b3886d42d5b80bd13ff81dd (diff) |
[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
2 files changed, 96 insertions, 10 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/model/NetworkNameModel.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/model/NetworkNameModel.kt index 85bbe7e53493..d6013192f55e 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/model/NetworkNameModel.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/model/NetworkNameModel.kt @@ -100,7 +100,14 @@ fun Intent.toNetworkNameModel(separator: String): NetworkNameModel? { val showSpn = getBooleanExtra(EXTRA_SHOW_SPN, false) val spn = if (statusBarSwitchToSpnFromDataSpn()) { - getStringExtra(EXTRA_SPN) + // 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()) { diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionRepositoryTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionRepositoryTest.kt index 171520f72269..0750505fd57b 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionRepositoryTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionRepositoryTest.kt @@ -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,10 +1147,50 @@ 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() = testScope.runTest { |