Loading packages/SystemUI/src/com/android/systemui/statusbar/pipeline/airplane/data/repository/AirplaneModeRepository.kt +12 −3 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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. Loading @@ -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, Loading Loading @@ -89,4 +95,7 @@ constructor( // initialValue here is irrelevant. initialValue = false, ) override suspend fun setIsAirplaneMode(isEnabled: Boolean) = withContext(backgroundContext) { connectivityManager.setAirplaneMode(isEnabled) } } packages/SystemUI/src/com/android/systemui/statusbar/pipeline/airplane/domain/interactor/AirplaneModeInteractor.kt +17 −1 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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 Loading @@ -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, } } packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/MobileConnectionRepository.kt +7 −0 Original line number Diff line number Diff line Loading @@ -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 Loading packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/MobileConnectionsRepository.kt +6 −0 Original line number Diff line number Diff line Loading @@ -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 } packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/MobileRepositorySwitcher.kt +7 −0 Original line number Diff line number Diff line Loading @@ -187,4 +187,11 @@ constructor( } return realRepository.getRepoForSubId(subId) } override suspend fun isInEcmMode(): Boolean = if (isDemoMode.value) { demoMobileConnectionsRepository.isInEcmMode() } else { realRepository.isInEcmMode() } } Loading
packages/SystemUI/src/com/android/systemui/statusbar/pipeline/airplane/data/repository/AirplaneModeRepository.kt +12 −3 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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. Loading @@ -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, Loading Loading @@ -89,4 +95,7 @@ constructor( // initialValue here is irrelevant. initialValue = false, ) override suspend fun setIsAirplaneMode(isEnabled: Boolean) = withContext(backgroundContext) { connectivityManager.setAirplaneMode(isEnabled) } }
packages/SystemUI/src/com/android/systemui/statusbar/pipeline/airplane/domain/interactor/AirplaneModeInteractor.kt +17 −1 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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 Loading @@ -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, } }
packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/MobileConnectionRepository.kt +7 −0 Original line number Diff line number Diff line Loading @@ -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 Loading
packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/MobileConnectionsRepository.kt +6 −0 Original line number Diff line number Diff line Loading @@ -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 }
packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/MobileRepositorySwitcher.kt +7 −0 Original line number Diff line number Diff line Loading @@ -187,4 +187,11 @@ constructor( } return realRepository.getRepoForSubId(subId) } override suspend fun isInEcmMode(): Boolean = if (isDemoMode.value) { demoMobileConnectionsRepository.isInEcmMode() } else { realRepository.isInEcmMode() } }