diff options
2 files changed, 111 insertions, 17 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 99ed2d99c749..cd442cf4ec9c 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 @@ -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 } 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 8fd0b31b82f3..9d83d5fbaed9 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 @@ -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 @@ -85,7 +86,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 @@ -93,8 +93,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 @@ -112,6 +110,8 @@ import org.junit.runner.RunWith 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) @@ -815,9 +815,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() } @@ -831,17 +833,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() } @@ -855,9 +859,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( @@ -865,7 +870,7 @@ class MobileConnectionRepositoryTest : SysuiTestCase() { showPlmn = false, ) - captor.value!!.onReceive(context, intentWithoutInfo) + captor.lastValue.onReceive(context, intentWithoutInfo) assertThat(latest).isEqualTo(DEFAULT_NAME_MODEL) @@ -884,10 +889,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 @@ -1128,14 +1211,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) } @@ -1148,6 +1233,7 @@ class MobileConnectionRepositoryTest : SysuiTestCase() { private const val SEP = "-" private const val SPN = "testSpn" + private const val DATA_SPN = "testDataSpn" private const val PLMN = "testPlmn" } } |