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

Commit 4cb3c716 authored by Caitlin Shkuratov's avatar Caitlin Shkuratov
Browse files

[SB Refactor] Use carrierMergedSubId for the mobile default calculation.

Bug: 272586234
Test: atest MobileConnectionsRepositoryTest MobileIconsInteractorTest
Change-Id: I05fa65f3379b2d8bb197d49a47e894ee160138f3
parent ca5ed2ce
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -60,6 +60,13 @@ interface MobileConnectionsRepository {
     */
    val mobileIsDefault: StateFlow<Boolean>

    /**
     * True if the device currently has a carrier merged connection.
     *
     * See [CarrierMergedConnectionRepository] for more info.
     */
    val hasCarrierMergedConnection: Flow<Boolean>

    /** True if the default network connection is validated and false otherwise. */
    val defaultConnectionIsValidated: StateFlow<Boolean>

+9 −0
Original line number Diff line number Diff line
@@ -159,6 +159,15 @@ constructor(
            .flatMapLatest { it.mobileIsDefault }
            .stateIn(scope, SharingStarted.WhileSubscribed(), realRepository.mobileIsDefault.value)

    override val hasCarrierMergedConnection: StateFlow<Boolean> =
        activeRepo
            .flatMapLatest { it.hasCarrierMergedConnection }
            .stateIn(
                scope,
                SharingStarted.WhileSubscribed(),
                realRepository.hasCarrierMergedConnection.value,
            )

    override val defaultConnectionIsValidated: StateFlow<Boolean> =
        activeRepo
            .flatMapLatest { it.defaultConnectionIsValidated }
+3 −0
Original line number Diff line number Diff line
@@ -159,6 +159,9 @@ constructor(
    // TODO(b/261029387): not yet supported
    override val mobileIsDefault: StateFlow<Boolean> = MutableStateFlow(true)

    // TODO(b/261029387): not yet supported
    override val hasCarrierMergedConnection = MutableStateFlow(false)

    // TODO(b/261029387): not yet supported
    override val defaultConnectionIsValidated: StateFlow<Boolean> = MutableStateFlow(true)

+19 −4
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.map
@@ -257,18 +258,32 @@ constructor(

    override val mobileIsDefault: StateFlow<Boolean> =
        connectivityRepository.defaultConnections
            // Because carrier merged networks are displayed as mobile networks, they're
            // part of the `isDefault` calculation. See b/272586234.
            .map { it.mobile.isDefault || it.carrierMerged.isDefault }
            .map { it.mobile.isDefault }
            .distinctUntilChanged()
            .logDiffsForTable(
                tableLogger,
                columnPrefix = "",
                columnPrefix = LOGGING_PREFIX,
                columnName = "mobileIsDefault",
                initialValue = false,
            )
            .stateIn(scope, SharingStarted.WhileSubscribed(), false)

    override val hasCarrierMergedConnection: StateFlow<Boolean> =
        combine(
                connectivityRepository.defaultConnections,
                carrierMergedSubId,
            ) { defaultConnections, carrierMergedSubId ->
                defaultConnections.carrierMerged.isDefault || carrierMergedSubId != null
            }
            .distinctUntilChanged()
            .logDiffsForTable(
                tableLogger,
                columnPrefix = LOGGING_PREFIX,
                columnName = "hasCarrierMergedConnection",
                initialValue = false,
            )
            .stateIn(scope, SharingStarted.WhileSubscribed(), false)

    override val defaultConnectionIsValidated: StateFlow<Boolean> =
        connectivityRepository.defaultConnections
            .map { it.isValidated }
+16 −1
Original line number Diff line number Diff line
@@ -114,7 +114,22 @@ constructor(
    @Application private val scope: CoroutineScope,
) : MobileIconsInteractor {

    override val mobileIsDefault = mobileConnectionsRepo.mobileIsDefault
    override val mobileIsDefault =
        combine(
                mobileConnectionsRepo.mobileIsDefault,
                mobileConnectionsRepo.hasCarrierMergedConnection,
            ) { mobileIsDefault, hasCarrierMergedConnection ->
                // Because carrier merged networks are displayed as mobile networks, they're part of
                // the `isDefault` calculation. See b/272586234.
                mobileIsDefault || hasCarrierMergedConnection
            }
            .logDiffsForTable(
                tableLogger,
                LOGGING_PREFIX,
                columnName = "mobileIsDefault",
                initialValue = false,
            )
            .stateIn(scope, SharingStarted.WhileSubscribed(), false)

    override val activeDataConnectionHasDataEnabled: StateFlow<Boolean> =
        mobileConnectionsRepo.activeMobileDataRepository
Loading