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

Commit 0a741156 authored by Anton Potapov's avatar Anton Potapov
Browse files

Add setIsAirplaneMode to AirplaneModeRepository

MobileConnectionsRepository now checks isInEcmMode of all active
MobileConnectionRepositories.

Test: atest AirplaneModeRepositoryImplTest
Bug: 301056365
Flag: LEGACY QS_PIPELINE_NEW_TILES DISABLED
Change-Id: I925b7d0522d2671b314acdc88681ddfd58a0521f
parent 930a7c70
Loading
Loading
Loading
Loading
+12 −3
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.statusbar.pipeline.airplane.data.repository

import android.net.ConnectivityManager
import android.os.Handler
import android.provider.Settings.Global
import com.android.systemui.common.coroutine.ConflatedCallbackFlow.conflatedCallbackFlow
@@ -28,13 +29,14 @@ import com.android.systemui.qs.SettingObserver
import com.android.systemui.statusbar.pipeline.dagger.AirplaneTableLog
import com.android.systemui.util.settings.GlobalSettings
import javax.inject.Inject
import kotlin.coroutines.CoroutineContext
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.withContext

/**
 * Provides data related to airplane mode.
@@ -48,15 +50,19 @@ import kotlinx.coroutines.flow.stateIn
interface AirplaneModeRepository {
    /** Observable for whether the device is currently in airplane mode. */
    val isAirplaneMode: StateFlow<Boolean>

    /** Sets airplane mode state. */
    suspend fun setIsAirplaneMode(isEnabled: Boolean)
}

@SysUISingleton
@Suppress("EXPERIMENTAL_IS_NOT_ENABLED")
@OptIn(ExperimentalCoroutinesApi::class)
class AirplaneModeRepositoryImpl
@Inject
constructor(
    @Background private val bgHandler: Handler,
    private val connectivityManager: ConnectivityManager,
    @Background private val bgHandler: Handler?,
    @Background private val backgroundContext: CoroutineContext,
    private val globalSettings: GlobalSettings,
    @AirplaneTableLog logger: TableLogBuffer,
    @Application scope: CoroutineScope,
@@ -89,4 +95,7 @@ constructor(
                // initialValue here is irrelevant.
                initialValue = false,
            )

    override suspend fun setIsAirplaneMode(isEnabled: Boolean) =
        withContext(backgroundContext) { connectivityManager.setAirplaneMode(isEnabled) }
}
+17 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.systemui.statusbar.pipeline.airplane.domain.interactor

import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.statusbar.pipeline.airplane.data.repository.AirplaneModeRepository
import com.android.systemui.statusbar.pipeline.mobile.data.repository.MobileConnectionsRepository
import com.android.systemui.statusbar.pipeline.shared.data.model.ConnectivitySlot
import com.android.systemui.statusbar.pipeline.shared.data.repository.ConnectivityRepository
import javax.inject.Inject
@@ -34,8 +35,9 @@ import kotlinx.coroutines.flow.map
class AirplaneModeInteractor
@Inject
constructor(
    airplaneModeRepository: AirplaneModeRepository,
    private val airplaneModeRepository: AirplaneModeRepository,
    connectivityRepository: ConnectivityRepository,
    private val mobileConnectionsRepository: MobileConnectionsRepository,
) {
    /** True if the device is currently in airplane mode. */
    val isAirplaneMode: Flow<Boolean> = airplaneModeRepository.isAirplaneMode
@@ -43,4 +45,18 @@ constructor(
    /** True if we're configured to force-hide the airplane mode icon and false otherwise. */
    val isForceHidden: Flow<Boolean> =
        connectivityRepository.forceHiddenSlots.map { it.contains(ConnectivitySlot.AIRPLANE) }

    /** Sets airplane mode state returning the result of the operation. */
    suspend fun setIsAirplaneMode(isInAirplaneMode: Boolean): SetResult =
        if (mobileConnectionsRepository.isInEcmMode()) {
            SetResult.BLOCKED_BY_ECM
        } else {
            airplaneModeRepository.setIsAirplaneMode(isInAirplaneMode)
            SetResult.SUCCESS
        }

    enum class SetResult {
        SUCCESS,
        BLOCKED_BY_ECM,
    }
}
+7 −0
Original line number Diff line number Diff line
@@ -137,6 +137,13 @@ interface MobileConnectionRepository {
     */
    val hasPrioritizedNetworkCapabilities: StateFlow<Boolean>

    /**
     * True if this connection is in emergency callback mode.
     *
     * @see [TelephonyManager.getEmergencyCallbackMode]
     */
    suspend fun isInEcmMode(): Boolean

    companion object {
        /** The default number of levels to use for [numberOfLevels]. */
        const val DEFAULT_NUM_LEVELS = 4
+6 −0
Original line number Diff line number Diff line
@@ -98,4 +98,10 @@ interface MobileConnectionsRepository {
     * [android.telephony.TelephonyManager.SIM_STATE_PERM_DISABLED]
     */
    val isAnySimSecure: Flow<Boolean>

    /**
     * Checks if any subscription has [android.telephony.TelephonyManager.getEmergencyCallbackMode]
     * == true
     */
    suspend fun isInEcmMode(): Boolean
}
+7 −0
Original line number Diff line number Diff line
@@ -187,4 +187,11 @@ constructor(
        }
        return realRepository.getRepoForSubId(subId)
    }

    override suspend fun isInEcmMode(): Boolean =
        if (isDemoMode.value) {
            demoMobileConnectionsRepository.isInEcmMode()
        } else {
            realRepository.isInEcmMode()
        }
}
Loading