Merge "[SB Refactor] Migrate alwaysShowCdmaRssi to the new pipeline." into tm-qpr-dev am: e878d24b0b am: 5822df0a5c

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/20748766

Change-Id: I0e683eeccb70ee4dd8dfff2af7821e7be93c8bbf
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Caitlin Shkuratov
2022-12-28 19:13:32 +00:00
committed by Automerger Merge Worker
6 changed files with 116 additions and 9 deletions

View File

@@ -61,6 +61,9 @@ interface MobileIconInteractor {
/** True if the RAT icon should always be displayed and false otherwise. */
val alwaysShowDataRatIcon: StateFlow<Boolean>
/** True if the CDMA level should be preferred over the primary level. */
val alwaysUseCdmaLevel: StateFlow<Boolean>
/** Observable for RAT type (network type) indicator */
val networkTypeIconGroup: StateFlow<MobileIconGroup>
@@ -97,6 +100,7 @@ class MobileIconInteractorImpl(
@Application scope: CoroutineScope,
defaultSubscriptionHasDataEnabled: StateFlow<Boolean>,
override val alwaysShowDataRatIcon: StateFlow<Boolean>,
override val alwaysUseCdmaLevel: StateFlow<Boolean>,
defaultMobileIconMapping: StateFlow<Map<String, MobileIconGroup>>,
defaultMobileIconGroup: StateFlow<MobileIconGroup>,
override val isDefaultConnectionFailed: StateFlow<Boolean>,
@@ -157,13 +161,12 @@ class MobileIconInteractorImpl(
.stateIn(scope, SharingStarted.WhileSubscribed(), false)
override val level: StateFlow<Int> =
connectionInfo
.mapLatest { connection ->
// TODO: incorporate [MobileMappings.Config.alwaysShowCdmaRssi]
if (connection.isGsm) {
connection.primaryLevel
} else {
connection.cdmaLevel
combine(connectionInfo, alwaysUseCdmaLevel) { connection, alwaysUseCdmaLevel ->
when {
// GSM connections should never use the CDMA level
connection.isGsm -> connection.primaryLevel
alwaysUseCdmaLevel -> connection.cdmaLevel
else -> connection.primaryLevel
}
}
.stateIn(scope, SharingStarted.WhileSubscribed(), 0)

View File

@@ -55,8 +55,13 @@ interface MobileIconsInteractor {
val filteredSubscriptions: Flow<List<SubscriptionModel>>
/** True if the active mobile data subscription has data enabled */
val activeDataConnectionHasDataEnabled: StateFlow<Boolean>
/** True if the RAT icon should always be displayed and false otherwise. */
val alwaysShowDataRatIcon: StateFlow<Boolean>
/** True if the CDMA level should be preferred over the primary level. */
val alwaysUseCdmaLevel: StateFlow<Boolean>
/** The icon mapping from network type to [MobileIconGroup] for the default subscription */
val defaultMobileIconMapping: StateFlow<Map<String, MobileIconGroup>>
/** Fallback [MobileIconGroup] in the case where there is no icon in the mapping */
@@ -165,6 +170,11 @@ constructor(
.mapLatest { it.alwaysShowDataRatIcon }
.stateIn(scope, SharingStarted.WhileSubscribed(), false)
override val alwaysUseCdmaLevel: StateFlow<Boolean> =
mobileConnectionsRepo.defaultDataSubRatConfig
.mapLatest { it.alwaysShowCdmaRssi }
.stateIn(scope, SharingStarted.WhileSubscribed(), false)
/** If there is no mapping in [defaultMobileIconMapping], then use this default icon group */
override val defaultMobileIconGroup: StateFlow<MobileIconGroup> =
mobileConnectionsRepo.defaultMobileIconGroup.stateIn(
@@ -196,6 +206,7 @@ constructor(
scope,
activeDataConnectionHasDataEnabled,
alwaysShowDataRatIcon,
alwaysUseCdmaLevel,
defaultMobileIconMapping,
defaultMobileIconGroup,
isDefaultConnectionFailed,

View File

@@ -29,6 +29,8 @@ class FakeMobileIconInteractor(
) : MobileIconInteractor {
override val alwaysShowDataRatIcon = MutableStateFlow(false)
override val alwaysUseCdmaLevel = MutableStateFlow(false)
override val activity =
MutableStateFlow(
DataActivityModel(

View File

@@ -58,6 +58,8 @@ class FakeMobileIconsInteractor(
override val alwaysShowDataRatIcon = MutableStateFlow(false)
override val alwaysUseCdmaLevel = MutableStateFlow(false)
private val _defaultMobileIconMapping = MutableStateFlow(TEST_MAPPING)
override val defaultMobileIconMapping = _defaultMobileIconMapping

View File

@@ -61,6 +61,7 @@ class MobileIconInteractorTest : SysuiTestCase() {
scope,
mobileIconsInteractor.activeDataConnectionHasDataEnabled,
mobileIconsInteractor.alwaysShowDataRatIcon,
mobileIconsInteractor.alwaysUseCdmaLevel,
mobileIconsInteractor.defaultMobileIconMapping,
mobileIconsInteractor.defaultMobileIconGroup,
mobileIconsInteractor.isDefaultConnectionFailed,
@@ -103,7 +104,27 @@ class MobileIconInteractorTest : SysuiTestCase() {
}
@Test
fun cdma_level_default_unknown() =
fun gsm_alwaysShowCdmaTrue_stillUsesGsmLevel() =
runBlocking(IMMEDIATE) {
connectionRepository.setConnectionInfo(
MobileConnectionModel(
isGsm = true,
primaryLevel = GSM_LEVEL,
cdmaLevel = CDMA_LEVEL,
),
)
mobileIconsInteractor.alwaysUseCdmaLevel.value = true
var latest: Int? = null
val job = underTest.level.onEach { latest = it }.launchIn(this)
assertThat(latest).isEqualTo(GSM_LEVEL)
job.cancel()
}
@Test
fun notGsm_level_default_unknown() =
runBlocking(IMMEDIATE) {
connectionRepository.setConnectionInfo(
MobileConnectionModel(isGsm = false),
@@ -117,7 +138,7 @@ class MobileIconInteractorTest : SysuiTestCase() {
}
@Test
fun cdma_usesCdmaLevel() =
fun notGsm_alwaysShowCdmaTrue_usesCdmaLevel() =
runBlocking(IMMEDIATE) {
connectionRepository.setConnectionInfo(
MobileConnectionModel(
@@ -126,6 +147,7 @@ class MobileIconInteractorTest : SysuiTestCase() {
cdmaLevel = CDMA_LEVEL
),
)
mobileIconsInteractor.alwaysUseCdmaLevel.value = true
var latest: Int? = null
val job = underTest.level.onEach { latest = it }.launchIn(this)
@@ -135,6 +157,26 @@ class MobileIconInteractorTest : SysuiTestCase() {
job.cancel()
}
@Test
fun notGsm_alwaysShowCdmaFalse_usesPrimaryLevel() =
runBlocking(IMMEDIATE) {
connectionRepository.setConnectionInfo(
MobileConnectionModel(
isGsm = false,
primaryLevel = GSM_LEVEL,
cdmaLevel = CDMA_LEVEL,
),
)
mobileIconsInteractor.alwaysUseCdmaLevel.value = false
var latest: Int? = null
val job = underTest.level.onEach { latest = it }.launchIn(this)
assertThat(latest).isEqualTo(GSM_LEVEL)
job.cancel()
}
@Test
fun iconGroup_three_g() =
runBlocking(IMMEDIATE) {
@@ -239,6 +281,21 @@ class MobileIconInteractorTest : SysuiTestCase() {
job.cancel()
}
@Test
fun alwaysUseCdmaLevel_matchesParent() =
runBlocking(IMMEDIATE) {
var latest: Boolean? = null
val job = underTest.alwaysUseCdmaLevel.onEach { latest = it }.launchIn(this)
mobileIconsInteractor.alwaysUseCdmaLevel.value = true
assertThat(latest).isTrue()
mobileIconsInteractor.alwaysUseCdmaLevel.value = false
assertThat(latest).isFalse()
job.cancel()
}
@Test
fun test_isDefaultDataEnabled_matchesParent() =
runBlocking(IMMEDIATE) {

View File

@@ -291,6 +291,38 @@ class MobileIconsInteractorTest : SysuiTestCase() {
job.cancel()
}
@Test
fun alwaysUseCdmaLevel_configHasTrue() =
runBlocking(IMMEDIATE) {
var latest: Boolean? = null
val job = underTest.alwaysUseCdmaLevel.onEach { latest = it }.launchIn(this)
val config = MobileMappings.Config()
config.alwaysShowCdmaRssi = true
connectionsRepository.defaultDataSubRatConfig.value = config
yield()
assertThat(latest).isTrue()
job.cancel()
}
@Test
fun alwaysUseCdmaLevel_configHasFalse() =
runBlocking(IMMEDIATE) {
var latest: Boolean? = null
val job = underTest.alwaysUseCdmaLevel.onEach { latest = it }.launchIn(this)
val config = MobileMappings.Config()
config.alwaysShowCdmaRssi = false
connectionsRepository.defaultDataSubRatConfig.value = config
yield()
assertThat(latest).isFalse()
job.cancel()
}
companion object {
private val IMMEDIATE = Dispatchers.Main.immediate
private val tableLogBuffer =