diff options
| author | 2023-02-08 17:09:29 +0000 | |
|---|---|---|
| committer | 2023-02-08 17:17:12 +0000 | |
| commit | f57212f00b50f0f289ee274f9631d96e4c53b80c (patch) | |
| tree | fa04c1ed226d9a77fa083e28577a25e069298ad9 | |
| parent | d0d9fbe3cbf3d8f45cdeceb3aa53c1c587ddfb5e (diff) | |
[SB Refactor] Don't update the network name if the subId doesn't match.
Fixes: 268340701
Bug: 238425913
Test: atest MobileConnectionRepositoryTest
Change-Id: Id2e73b834a1dc1bcffc7c62596b1f41c9612e649
2 files changed, 46 insertions, 14 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionRepositoryImpl.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionRepositoryImpl.kt index cfc4cc4ba947..40225f53da1f 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionRepositoryImpl.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionRepositoryImpl.kt @@ -61,6 +61,7 @@ import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.SharedFlow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.mapLatest import kotlinx.coroutines.flow.mapNotNull @@ -267,15 +268,14 @@ class MobileConnectionRepositoryImpl( override val networkName: StateFlow<NetworkNameModel> = broadcastDispatcher - .broadcastFlow(IntentFilter(TelephonyManager.ACTION_SERVICE_PROVIDERS_UPDATED)) { - intent, - _ -> - if (intent.getIntExtra(EXTRA_SUBSCRIPTION_ID, INVALID_SUBSCRIPTION_ID) != subId) { - defaultNetworkName - } else { - intent.toNetworkNameModel(networkNameSeparator) ?: defaultNetworkName - } + .broadcastFlow( + filter = IntentFilter(TelephonyManager.ACTION_SERVICE_PROVIDERS_UPDATED), + map = { intent, _ -> intent }, + ) + .filter { intent -> + intent.getIntExtra(EXTRA_SUBSCRIPTION_ID, INVALID_SUBSCRIPTION_ID) == subId } + .map { intent -> intent.toNetworkNameModel(networkNameSeparator) ?: defaultNetworkName } .stateIn(scope, SharingStarted.WhileSubscribed(), defaultNetworkName) override val dataEnabled = run { 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 1a5cc9abd9b6..a294088a41c0 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 @@ -24,7 +24,6 @@ import android.telephony.ServiceState import android.telephony.ServiceState.STATE_IN_SERVICE import android.telephony.ServiceState.STATE_OUT_OF_SERVICE import android.telephony.SignalStrength -import android.telephony.SubscriptionInfo import android.telephony.TelephonyCallback import android.telephony.TelephonyCallback.DataActivityListener import android.telephony.TelephonyCallback.ServiceStateListener @@ -556,16 +555,51 @@ class MobileConnectionRepositoryTest : SysuiTestCase() { } @Test - fun `network name - broadcast not for this sub id - returns default`() = + fun `network name - broadcast not for this sub id - keeps old value`() = runBlocking(IMMEDIATE) { var latest: NetworkNameModel? = null val job = underTest.networkName.onEach { latest = it }.launchIn(this) - val intent = spnIntent(subId = 101) + val intent = spnIntent() + fakeBroadcastDispatcher.registeredReceivers.forEach { receiver -> + receiver.onReceive(context, intent) + } + assertThat(latest).isEqualTo(intent.toNetworkNameModel(SEP)) + + // WHEN an intent with a different subId is sent + val wrongSubIntent = spnIntent(subId = 101) fakeBroadcastDispatcher.registeredReceivers.forEach { receiver -> + receiver.onReceive(context, wrongSubIntent) + } + + // THEN the previous intent's name is still used + assertThat(latest).isEqualTo(intent.toNetworkNameModel(SEP)) + + job.cancel() + } + + @Test + fun `network name - broadcast has no data - updates to default`() = + runBlocking(IMMEDIATE) { + var latest: NetworkNameModel? = null + val job = underTest.networkName.onEach { latest = it }.launchIn(this) + + val intent = spnIntent() + fakeBroadcastDispatcher.registeredReceivers.forEach { receiver -> receiver.onReceive(context, intent) } + assertThat(latest).isEqualTo(intent.toNetworkNameModel(SEP)) + + val intentWithoutInfo = + spnIntent( + showSpn = false, + showPlmn = false, + ) + + fakeBroadcastDispatcher.registeredReceivers.forEach { receiver -> + receiver.onReceive(context, intentWithoutInfo) + } assertThat(latest).isEqualTo(DEFAULT_NAME) @@ -573,7 +607,7 @@ class MobileConnectionRepositoryTest : SysuiTestCase() { } @Test - fun `network name - operatorAlphaShort - tracked`() = + fun `operatorAlphaShort - tracked`() = runBlocking(IMMEDIATE) { var latest: String? = null @@ -703,8 +737,6 @@ class MobileConnectionRepositoryTest : SysuiTestCase() { companion object { private val IMMEDIATE = Dispatchers.Main.immediate private const val SUB_1_ID = 1 - private val SUB_1 = - mock<SubscriptionInfo>().also { whenever(it.subscriptionId).thenReturn(SUB_1_ID) } private val DEFAULT_NAME = NetworkNameModel.Default("default name") private const val SEP = "-" |