From eadd94c59c3b08deb5f787c7aa54ea21c8c62433 Mon Sep 17 00:00:00 2001 From: Evan Laird Date: Tue, 20 Dec 2022 16:27:12 -0500 Subject: [PATCH] [Sb refactor] Consume isInService in mobile view model This implementation matches what was in MobileSignalController. If isInService() reports false, then we show the empty mobile icon. Otherwise use the regular icon id logic Test: MobileIconViewModelTest Test: MobileIconInteractorTest Bug: 263167683 Bug: 238425913 Change-Id: Ie0da01439e79267a6842e096ec6924b3ccebce7d --- .../domain/interactor/MobileIconInteractor.kt | 8 ++++++ .../ui/viewmodel/MobileIconViewModel.kt | 16 ++++++++---- .../interactor/FakeMobileIconInteractor.kt | 2 ++ .../interactor/MobileIconInteractorTest.kt | 17 ++++++++++++ .../ui/viewmodel/MobileIconViewModelTest.kt | 26 +++++++++++++++++++ 5 files changed, 64 insertions(+), 5 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconInteractor.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconInteractor.kt index e6686dce7bbc7..675760533d97b 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconInteractor.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconInteractor.kt @@ -48,6 +48,9 @@ interface MobileIconInteractor { /** True when telephony tells us that the data state is CONNECTED */ val isDataConnected: StateFlow + /** True if we consider this connection to be in service, i.e. can make calls */ + val isInService: StateFlow + // TODO(b/256839546): clarify naming of default vs active /** True if we want to consider the data connection enabled */ val isDefaultDataEnabled: StateFlow @@ -175,4 +178,9 @@ class MobileIconInteractorImpl( connectionInfo .mapLatest { connection -> connection.dataConnectionState == Connected } .stateIn(scope, SharingStarted.WhileSubscribed(), false) + + override val isInService = + connectionRepository.connectionInfo + .mapLatest { it.isInService } + .stateIn(scope, SharingStarted.WhileSubscribed(), false) } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/ui/viewmodel/MobileIconViewModel.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/ui/viewmodel/MobileIconViewModel.kt index 2d6ac4efd5128..a2117c7df188e 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/ui/viewmodel/MobileIconViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/ui/viewmodel/MobileIconViewModel.kt @@ -80,11 +80,17 @@ constructor( override val iconId: Flow = run { val initial = SignalDrawable.getEmptyState(iconInteractor.numberOfLevels.value) - combine(iconInteractor.level, iconInteractor.numberOfLevels, showExclamationMark) { - level, - numberOfLevels, - showExclamationMark -> - SignalDrawable.getState(level, numberOfLevels, showExclamationMark) + combine( + iconInteractor.level, + iconInteractor.numberOfLevels, + showExclamationMark, + iconInteractor.isInService, + ) { level, numberOfLevels, showExclamationMark, isInService -> + if (!isInService) { + SignalDrawable.getEmptyState(numberOfLevels) + } else { + SignalDrawable.getState(level, numberOfLevels, showExclamationMark) + } } .distinctUntilChanged() .logDiffsForTable( diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/FakeMobileIconInteractor.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/FakeMobileIconInteractor.kt index c49458909c78b..5889ec885e1f5 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/FakeMobileIconInteractor.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/FakeMobileIconInteractor.kt @@ -52,6 +52,8 @@ class FakeMobileIconInteractor( override val isDataConnected = MutableStateFlow(true) + override val isInService = MutableStateFlow(true) + private val _isDataEnabled = MutableStateFlow(true) override val isDataEnabled = _isDataEnabled diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconInteractorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconInteractorTest.kt index 83c5055a6edae..cb2ee9940c38f 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconInteractorTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconInteractorTest.kt @@ -299,6 +299,23 @@ class MobileIconInteractorTest : SysuiTestCase() { job.cancel() } + @Test + fun `isInService - uses repository value`() = + runBlocking(IMMEDIATE) { + var latest: Boolean? = null + val job = underTest.isInService.onEach { latest = it }.launchIn(this) + + connectionRepository.setConnectionInfo(MobileConnectionModel(isInService = true)) + + assertThat(latest).isTrue() + + connectionRepository.setConnectionInfo(MobileConnectionModel(isInService = false)) + + assertThat(latest).isFalse() + + job.cancel() + } + @Test fun `roaming - is gsm - uses connection model`() = runBlocking(IMMEDIATE) { diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/ui/viewmodel/MobileIconViewModelTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/ui/viewmodel/MobileIconViewModelTest.kt index 50221bc97badb..2a8d42ff69975 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/ui/viewmodel/MobileIconViewModelTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/ui/viewmodel/MobileIconViewModelTest.kt @@ -97,6 +97,30 @@ class MobileIconViewModelTest : SysuiTestCase() { job.cancel() } + @Test + fun `icon - uses empty state - when not in service`() = + testScope.runTest { + var latest: Int? = null + val job = underTest.iconId.onEach { latest = it }.launchIn(this) + + interactor.isInService.value = false + + var expected = emptySignal() + + assertThat(latest).isEqualTo(expected) + + // Changing the level doesn't overwrite the disabled state + interactor.level.value = 2 + assertThat(latest).isEqualTo(expected) + + // Once back in service, the regular icon appears + interactor.isInService.value = true + expected = defaultSignal(level = 2) + assertThat(latest).isEqualTo(expected) + + job.cancel() + } + @Test fun networkType_dataEnabled_groupIsRepresented() = testScope.runTest { @@ -375,5 +399,7 @@ class MobileIconViewModelTest : SysuiTestCase() { ): Int { return SignalDrawable.getState(level, /* numLevels */ 4, !connected) } + + fun emptySignal(): Int = SignalDrawable.getEmptyState(4) } }