Loading packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/FullMobileConnectionRepository.kt +2 −2 Original line number Diff line number Diff line Loading @@ -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) Loading @@ -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) Loading packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionRepositoryImpl.kt +8 −2 Original line number Diff line number Diff line Loading @@ -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 { Loading Loading @@ -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 Loading packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionRepositoryTest.kt +18 −0 Original line number Diff line number Diff line Loading @@ -867,6 +867,24 @@ class MobileConnectionRepositoryTest : SysuiTestCase() { job.cancel() } @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 { Loading Loading
packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/FullMobileConnectionRepository.kt +2 −2 Original line number Diff line number Diff line Loading @@ -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) Loading @@ -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) Loading
packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionRepositoryImpl.kt +8 −2 Original line number Diff line number Diff line Loading @@ -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 { Loading Loading @@ -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 Loading
packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionRepositoryTest.kt +18 −0 Original line number Diff line number Diff line Loading @@ -867,6 +867,24 @@ class MobileConnectionRepositoryTest : SysuiTestCase() { job.cancel() } @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 { Loading