Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e878d24b authored by Caitlin Shkuratov's avatar Caitlin Shkuratov Committed by Android (Google) Code Review
Browse files

Merge "[SB Refactor] Migrate alwaysShowCdmaRssi to the new pipeline." into tm-qpr-dev

parents 933c12ef c634d1ae
Loading
Loading
Loading
Loading
+10 −7
Original line number Diff line number Diff line
@@ -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)
+11 −0
Original line number Diff line number Diff line
@@ -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,
+2 −0
Original line number Diff line number Diff line
@@ -29,6 +29,8 @@ class FakeMobileIconInteractor(
) : MobileIconInteractor {
    override val alwaysShowDataRatIcon = MutableStateFlow(false)

    override val alwaysUseCdmaLevel = MutableStateFlow(false)

    override val activity =
        MutableStateFlow(
            DataActivityModel(
+2 −0
Original line number Diff line number Diff line
@@ -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

+59 −2
Original line number Diff line number Diff line
@@ -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) {
Loading