diff options
3 files changed, 28 insertions, 4 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/FullMobileConnectionRepository.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/FullMobileConnectionRepository.kt index 60b8599ecabd..b085d8046b12 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/FullMobileConnectionRepository.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/FullMobileConnectionRepository.kt @@ -301,7 +301,7 @@ class FullMobileConnectionRepository( .flatMapLatest { it.networkName } .logDiffsForTable( tableLogBuffer, - columnPrefix = "", + columnPrefix = "intent", initialValue = activeRepo.value.networkName.value, ) .stateIn(scope, SharingStarted.WhileSubscribed(), activeRepo.value.networkName.value) @@ -311,7 +311,7 @@ class FullMobileConnectionRepository( .flatMapLatest { it.carrierName } .logDiffsForTable( tableLogBuffer, - columnPrefix = "", + columnPrefix = "sub", initialValue = activeRepo.value.carrierName.value, ) .stateIn(scope, SharingStarted.WhileSubscribed(), activeRepo.value.carrierName.value) 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 f01ac0e0a677..5ab2ae899370 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 @@ -358,7 +358,13 @@ class MobileConnectionRepositoryImpl( } .stateIn(scope, SharingStarted.WhileSubscribed(), telephonyManager.simCarrierId) - /** BroadcastDispatcher does not handle sticky broadcasts, so we can't use it here */ + /** + * BroadcastDispatcher does not handle sticky broadcasts, so we can't use it here. Note that we + * now use the [SharingStarted.Eagerly] strategy, because there have been cases where the sticky + * broadcast does not represent the correct state. + * + * See b/322432056 for context. + */ @SuppressLint("RegisterReceiverViaContext") override val networkName: StateFlow<NetworkNameModel> = conflatedCallbackFlow { @@ -388,7 +394,7 @@ class MobileConnectionRepositoryImpl( awaitClose { context.unregisterReceiver(receiver) } } .flowOn(bgDispatcher) - .stateIn(scope, SharingStarted.WhileSubscribed(), defaultNetworkName) + .stateIn(scope, SharingStarted.Eagerly, defaultNetworkName) override val dataEnabled = run { val initial = telephonyManager.isDataConnectionAllowed 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 98556514f8ec..f761bcfe63d6 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 @@ -868,6 +868,24 @@ class MobileConnectionRepositoryTest : SysuiTestCase() { } @Test + fun networkName_usingEagerStrategy_retainsNameBetweenSubscribers() = + testScope.runTest { + // Use the [StateFlow.value] getter so we can prove that the collection happens + // even when there is no [Job] + + // Starts out default + assertThat(underTest.networkName.value).isEqualTo(DEFAULT_NAME_MODEL) + + val intent = spnIntent() + val captor = argumentCaptor<BroadcastReceiver>() + verify(context).registerReceiver(captor.capture(), any()) + captor.value!!.onReceive(context, intent) + + // The value is still there despite no active subscribers + assertThat(underTest.networkName.value).isEqualTo(intent.toNetworkNameModel(SEP)) + } + + @Test fun operatorAlphaShort_tracked() = testScope.runTest { var latest: String? = null |