[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
This commit is contained in:
Evan Laird
2022-12-20 16:27:12 -05:00
parent cf01bebb3f
commit eadd94c59c
5 changed files with 64 additions and 5 deletions

View File

@@ -48,6 +48,9 @@ interface MobileIconInteractor {
/** True when telephony tells us that the data state is CONNECTED */
val isDataConnected: StateFlow<Boolean>
/** True if we consider this connection to be in service, i.e. can make calls */
val isInService: StateFlow<Boolean>
// TODO(b/256839546): clarify naming of default vs active
/** True if we want to consider the data connection enabled */
val isDefaultDataEnabled: StateFlow<Boolean>
@@ -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)
}

View File

@@ -80,11 +80,17 @@ constructor(
override val iconId: Flow<Int> = 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(

View File

@@ -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

View File

@@ -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) {

View File

@@ -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)
}
}