Merge changes from topic "cherrypicker-L99700030003921781:N71800030062077718" into 24D1-dev
* changes:
[Sat] Add device-based emergency calls only state to satellie icon
[Sb][Mobile] Listen for service states via broadcast for subId = -1
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/MobileInputLogger.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/MobileInputLogger.kt
index d4b2dbf..2e54972 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/MobileInputLogger.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/MobileInputLogger.kt
@@ -53,6 +53,27 @@
)
}
+ fun logTopLevelServiceStateBroadcastEmergencyOnly(subId: Int, serviceState: ServiceState) {
+ buffer.log(
+ TAG,
+ LogLevel.INFO,
+ {
+ int1 = subId
+ bool1 = serviceState.isEmergencyOnly
+ },
+ { "ACTION_SERVICE_STATE for subId=$int1. ServiceState.isEmergencyOnly=$bool1" }
+ )
+ }
+
+ fun logTopLevelServiceStateBroadcastMissingExtras(subId: Int) {
+ buffer.log(
+ TAG,
+ LogLevel.INFO,
+ { int1 = subId },
+ { "ACTION_SERVICE_STATE for subId=$int1. Intent is missing extras. Ignoring" }
+ )
+ }
+
fun logOnSignalStrengthsChanged(signalStrength: SignalStrength, subId: Int) {
buffer.log(
TAG,
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/model/ServiceStateModel.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/model/ServiceStateModel.kt
new file mode 100644
index 0000000..cce3eb0
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/model/ServiceStateModel.kt
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.statusbar.pipeline.mobile.data.model
+
+import android.telephony.ServiceState
+
+/**
+ * Simplified representation of a [ServiceState] for use in SystemUI. Add any fields that we need to
+ * extract from service state here for consumption downstream
+ */
+data class ServiceStateModel(val isEmergencyOnly: Boolean) {
+ companion object {
+ fun fromServiceState(serviceState: ServiceState): ServiceStateModel {
+ return ServiceStateModel(isEmergencyOnly = serviceState.isEmergencyOnly)
+ }
+ }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/MobileConnectionsRepository.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/MobileConnectionsRepository.kt
index 9471574..5ad8bf1 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/MobileConnectionsRepository.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/MobileConnectionsRepository.kt
@@ -21,6 +21,7 @@
import com.android.settingslib.SignalIcon.MobileIconGroup
import com.android.settingslib.mobile.MobileMappings
import com.android.settingslib.mobile.MobileMappings.Config
+import com.android.systemui.statusbar.pipeline.mobile.data.model.ServiceStateModel
import com.android.systemui.statusbar.pipeline.mobile.data.model.SubscriptionModel
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.StateFlow
@@ -92,6 +93,19 @@
val defaultMobileIconGroup: Flow<MobileIconGroup>
/**
+ * [deviceServiceState] is equivalent to the last [Intent.ACTION_SERVICE_STATE] broadcast with a
+ * subscriptionId of -1 (aka [SubscriptionManager.INVALID_SUBSCRIPTION_ID]).
+ *
+ * While each [MobileConnectionsRepository] listens for the service state of each subscription,
+ * there is potentially a service state associated with the device itself. This value can be
+ * used to calculate e.g., the emergency calling capability of the device (as opposed to the
+ * emergency calling capability of an individual mobile connection)
+ *
+ * Note: this is a [StateFlow] using an eager sharing strategy.
+ */
+ val deviceServiceState: StateFlow<ServiceStateModel?>
+
+ /**
* If any active SIM on the device is in
* [android.telephony.TelephonyManager.SIM_STATE_PIN_REQUIRED] or
* [android.telephony.TelephonyManager.SIM_STATE_PUK_REQUIRED] or
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/MobileRepositorySwitcher.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/MobileRepositorySwitcher.kt
index 8a8e33e..b068152 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/MobileRepositorySwitcher.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/MobileRepositorySwitcher.kt
@@ -25,6 +25,7 @@
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.demomode.DemoMode
import com.android.systemui.demomode.DemoModeController
+import com.android.systemui.statusbar.pipeline.mobile.data.model.ServiceStateModel
import com.android.systemui.statusbar.pipeline.mobile.data.model.SubscriptionModel
import com.android.systemui.statusbar.pipeline.mobile.data.repository.demo.DemoMobileConnectionsRepository
import com.android.systemui.statusbar.pipeline.mobile.data.repository.prod.MobileConnectionsRepositoryImpl
@@ -151,6 +152,15 @@
override val defaultMobileIconGroup: Flow<SignalIcon.MobileIconGroup> =
activeRepo.flatMapLatest { it.defaultMobileIconGroup }
+ override val deviceServiceState: StateFlow<ServiceStateModel?> =
+ activeRepo
+ .flatMapLatest { it.deviceServiceState }
+ .stateIn(
+ scope,
+ SharingStarted.WhileSubscribed(),
+ realRepository.deviceServiceState.value
+ )
+
override val isAnySimSecure: Flow<Boolean> = activeRepo.flatMapLatest { it.isAnySimSecure }
override fun getIsAnySimSecure(): Boolean = activeRepo.value.getIsAnySimSecure()
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/demo/DemoMobileConnectionsRepository.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/demo/DemoMobileConnectionsRepository.kt
index 2b3c632..a944e91 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/demo/DemoMobileConnectionsRepository.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/demo/DemoMobileConnectionsRepository.kt
@@ -27,6 +27,7 @@
import com.android.systemui.log.table.TableLogBufferFactory
import com.android.systemui.statusbar.pipeline.mobile.data.model.ResolvedNetworkType
import com.android.systemui.statusbar.pipeline.mobile.data.model.ResolvedNetworkType.DefaultNetworkType
+import com.android.systemui.statusbar.pipeline.mobile.data.model.ServiceStateModel
import com.android.systemui.statusbar.pipeline.mobile.data.model.SubscriptionModel
import com.android.systemui.statusbar.pipeline.mobile.data.repository.MobileConnectionRepository
import com.android.systemui.statusbar.pipeline.mobile.data.repository.MobileConnectionsRepository
@@ -136,6 +137,9 @@
override val defaultMobileIconGroup = flowOf(TelephonyIcons.THREE_G)
+ // TODO(b/339023069): demo command for device-based connectivity state
+ override val deviceServiceState: StateFlow<ServiceStateModel?> = MutableStateFlow(null)
+
override val isAnySimSecure: Flow<Boolean> = flowOf(getIsAnySimSecure())
override fun getIsAnySimSecure(): Boolean = false
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionsRepositoryImpl.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionsRepositoryImpl.kt
index 962b2229..1107165 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionsRepositoryImpl.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionsRepositoryImpl.kt
@@ -18,8 +18,10 @@
import android.annotation.SuppressLint
import android.content.Context
+import android.content.Intent
import android.content.IntentFilter
import android.telephony.CarrierConfigManager
+import android.telephony.ServiceState
import android.telephony.SubscriptionInfo
import android.telephony.SubscriptionManager
import android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID
@@ -44,6 +46,7 @@
import com.android.systemui.statusbar.pipeline.dagger.MobileSummaryLog
import com.android.systemui.statusbar.pipeline.mobile.data.MobileInputLogger
import com.android.systemui.statusbar.pipeline.mobile.data.model.NetworkNameModel
+import com.android.systemui.statusbar.pipeline.mobile.data.model.ServiceStateModel
import com.android.systemui.statusbar.pipeline.mobile.data.model.SubscriptionModel
import com.android.systemui.statusbar.pipeline.mobile.data.repository.MobileConnectionsRepository
import com.android.systemui.statusbar.pipeline.mobile.util.MobileMappingsProxy
@@ -63,6 +66,7 @@
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged
+import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.mapLatest
@@ -156,6 +160,35 @@
}
.flowOn(bgDispatcher)
+ /** Note that this flow is eager, so we don't miss any state */
+ override val deviceServiceState: StateFlow<ServiceStateModel?> =
+ broadcastDispatcher
+ .broadcastFlow(IntentFilter(Intent.ACTION_SERVICE_STATE)) { intent, _ ->
+ val subId =
+ intent.getIntExtra(
+ SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX,
+ INVALID_SUBSCRIPTION_ID
+ )
+
+ val extras = intent.extras
+ if (extras == null) {
+ logger.logTopLevelServiceStateBroadcastMissingExtras(subId)
+ return@broadcastFlow null
+ }
+
+ val serviceState = ServiceState.newFromBundle(extras)
+ logger.logTopLevelServiceStateBroadcastEmergencyOnly(subId, serviceState)
+ if (subId == INVALID_SUBSCRIPTION_ID) {
+ // Assume that -1 here is the device's service state. We don't care about
+ // other ones.
+ ServiceStateModel.fromServiceState(serviceState)
+ } else {
+ null
+ }
+ }
+ .filterNotNull()
+ .stateIn(scope, SharingStarted.Eagerly, null)
+
/**
* State flow that emits the set of mobile data subscriptions, each represented by its own
* [SubscriptionModel].
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconsInteractor.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconsInteractor.kt
index 91d7ca6..cc4d568 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconsInteractor.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconsInteractor.kt
@@ -111,6 +111,13 @@
val isForceHidden: Flow<Boolean>
/**
+ * True if the device-level service state (with -1 subscription id) reports emergency calls
+ * only. This value is only useful when there are no other subscriptions OR all existing
+ * subscriptions report that they are not in service.
+ */
+ val isDeviceInEmergencyCallsOnlyMode: Flow<Boolean>
+
+ /**
* Vends out a [MobileIconInteractor] tracking the [MobileConnectionRepository] for the given
* subId.
*/
@@ -377,6 +384,9 @@
.map { it.contains(ConnectivitySlot.MOBILE) }
.stateIn(scope, SharingStarted.WhileSubscribed(), false)
+ override val isDeviceInEmergencyCallsOnlyMode: Flow<Boolean> =
+ mobileConnectionsRepo.deviceServiceState.map { it?.isEmergencyOnly ?: false }
+
/** Vends out new [MobileIconInteractor] for a particular subId */
override fun getMobileConnectionInteractorForSubId(subId: Int): MobileIconInteractor =
reuseCache[subId]?.get() ?: createMobileConnectionInteractorForSubId(subId)
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/satellite/domain/interactor/DeviceBasedSatelliteInteractor.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/satellite/domain/interactor/DeviceBasedSatelliteInteractor.kt
index 51c053e..5b954b2 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/satellite/domain/interactor/DeviceBasedSatelliteInteractor.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/satellite/domain/interactor/DeviceBasedSatelliteInteractor.kt
@@ -19,6 +19,9 @@
import com.android.internal.telephony.flags.Flags
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
+import com.android.systemui.log.LogBuffer
+import com.android.systemui.log.core.LogLevel
+import com.android.systemui.statusbar.pipeline.dagger.OemSatelliteInputLog
import com.android.systemui.statusbar.pipeline.mobile.domain.interactor.MobileIconsInteractor
import com.android.systemui.statusbar.pipeline.satellite.data.DeviceBasedSatelliteRepository
import com.android.systemui.statusbar.pipeline.satellite.shared.model.SatelliteConnectionState
@@ -45,6 +48,7 @@
deviceProvisioningInteractor: DeviceProvisioningInteractor,
wifiInteractor: WifiInteractor,
@Application scope: CoroutineScope,
+ @OemSatelliteInputLog private val logBuffer: LogBuffer,
) {
/** Must be observed by any UI showing Satellite iconography */
val isSatelliteAllowed =
@@ -79,25 +83,52 @@
val isWifiActive: Flow<Boolean> =
wifiInteractor.wifiNetwork.map { it is WifiNetworkModel.Active }
+ private val allConnectionsOos =
+ iconsInteractor.icons.aggregateOver(
+ selector = { intr ->
+ combine(intr.isInService, intr.isEmergencyOnly, intr.isNonTerrestrial) {
+ isInService,
+ isEmergencyOnly,
+ isNtn ->
+ !isInService && !isEmergencyOnly && !isNtn
+ }
+ },
+ defaultValue = true, // no connections == everything is OOS
+ ) { isOosAndNotEmergencyAndNotSatellite ->
+ isOosAndNotEmergencyAndNotSatellite.all { it }
+ }
+
/** When all connections are considered OOS, satellite connectivity is potentially valid */
val areAllConnectionsOutOfService =
if (Flags.oemEnabledSatelliteFlag()) {
- iconsInteractor.icons.aggregateOver(
- selector = { intr ->
- combine(intr.isInService, intr.isEmergencyOnly, intr.isNonTerrestrial) {
- isInService,
- isEmergencyOnly,
- isNtn ->
- !isInService && !(isEmergencyOnly || isNtn)
- }
- }
- ) { isOosAndNotEmergencyOnlyOrSatellite ->
- isOosAndNotEmergencyOnlyOrSatellite.all { it }
+ combine(
+ allConnectionsOos,
+ iconsInteractor.isDeviceInEmergencyCallsOnlyMode,
+ ) { connectionsOos, deviceEmergencyOnly ->
+ logBuffer.log(
+ TAG,
+ LogLevel.INFO,
+ {
+ bool1 = connectionsOos
+ bool2 = deviceEmergencyOnly
+ },
+ {
+ "Updating OOS status. allConnectionsOOs=$bool1 " +
+ "deviceEmergencyOnly=$bool2"
+ },
+ )
+ // If no connections exist, or all are OOS, then we look to the device-based
+ // service state to detect if any calls are possible
+ connectionsOos && !deviceEmergencyOnly
}
} else {
flowOf(false)
}
.stateIn(scope, SharingStarted.WhileSubscribed(), true)
+
+ companion object {
+ const val TAG = "DeviceBasedSatelliteInteractor"
+ }
}
/**
@@ -106,12 +137,22 @@
*
* Provides a way to connect the reactivity of the top-level flow with the reactivity of an
* arbitrarily-defined relationship ([selector]) from R to the flow that R exposes.
+ *
+ * [defaultValue] allows for a default value to be used if there are no leaf nodes after applying
+ * [selector]. E.g., if there are no mobile connections, assume that there is no service.
*/
@OptIn(ExperimentalCoroutinesApi::class)
private inline fun <R, reified S, T> Flow<List<R>>.aggregateOver(
crossinline selector: (R) -> Flow<S>,
- crossinline transform: (Array<S>) -> T
+ defaultValue: T,
+ crossinline transform: (Array<S>) -> T,
): Flow<T> {
return map { list -> list.map { selector(it) } }
- .flatMapLatest { newFlows -> combine(newFlows) { newVals -> transform(newVals) } }
+ .flatMapLatest { newFlows ->
+ if (newFlows.isEmpty()) {
+ flowOf(defaultValue)
+ } else {
+ combine(newFlows) { newVals -> transform(newVals) }
+ }
+ }
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionsRepositoryTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionsRepositoryTest.kt
index 5152d6b..f59bc2b 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionsRepositoryTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionsRepositoryTest.kt
@@ -16,6 +16,7 @@
package com.android.systemui.statusbar.pipeline.mobile.data.repository.prod
+import android.annotation.SuppressLint
import android.content.Intent
import android.net.ConnectivityManager
import android.net.Network
@@ -26,8 +27,10 @@
import android.net.NetworkCapabilities.TRANSPORT_WIFI
import android.net.vcn.VcnTransportInfo
import android.net.wifi.WifiInfo
+import android.os.Bundle
import android.os.ParcelUuid
import android.telephony.CarrierConfigManager
+import android.telephony.ServiceState
import android.telephony.SubscriptionInfo
import android.telephony.SubscriptionManager
import android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID
@@ -50,6 +53,7 @@
import com.android.systemui.log.table.TableLogBufferFactory
import com.android.systemui.statusbar.pipeline.airplane.data.repository.FakeAirplaneModeRepository
import com.android.systemui.statusbar.pipeline.mobile.data.MobileInputLogger
+import com.android.systemui.statusbar.pipeline.mobile.data.model.ServiceStateModel
import com.android.systemui.statusbar.pipeline.mobile.data.model.SubscriptionModel
import com.android.systemui.statusbar.pipeline.mobile.data.repository.CarrierConfigRepository
import com.android.systemui.statusbar.pipeline.mobile.data.repository.MobileConnectionRepository
@@ -572,6 +576,51 @@
assertThat(mobileRepo.getIsCarrierMerged()).isFalse()
}
+ @SuppressLint("UnspecifiedRegisterReceiverFlag")
+ @Test
+ fun testDeviceServiceStateFromBroadcast_eagerlyWatchesBroadcast() =
+ testScope.runTest {
+ // Value starts out empty (null)
+ assertThat(underTest.deviceServiceState.value).isNull()
+
+ // WHEN an appropriate intent gets sent out
+ val intent = serviceStateIntent(subId = -1, emergencyOnly = false)
+ fakeBroadcastDispatcher.sendIntentToMatchingReceiversOnly(
+ context,
+ intent,
+ )
+ runCurrent()
+
+ // THEN the repo's state is updated
+ val expected = ServiceStateModel(isEmergencyOnly = false)
+ assertThat(underTest.deviceServiceState.value).isEqualTo(expected)
+ }
+
+ @Test
+ fun testDeviceServiceStateFromBroadcast_followsSubIdNegativeOne() =
+ testScope.runTest {
+ // device based state tracks -1
+ val intent = serviceStateIntent(subId = -1, emergencyOnly = false)
+ fakeBroadcastDispatcher.sendIntentToMatchingReceiversOnly(
+ context,
+ intent,
+ )
+ runCurrent()
+
+ val deviceBasedState = ServiceStateModel(isEmergencyOnly = false)
+ assertThat(underTest.deviceServiceState.value).isEqualTo(deviceBasedState)
+
+ // ... and ignores any other subId
+ val intent2 = serviceStateIntent(subId = 1, emergencyOnly = true)
+ fakeBroadcastDispatcher.sendIntentToMatchingReceiversOnly(
+ context,
+ intent2,
+ )
+ runCurrent()
+
+ assertThat(underTest.deviceServiceState.value).isEqualTo(deviceBasedState)
+ }
+
@Test
fun testConnectionCache_clearsInvalidSubscriptions() =
testScope.runTest {
@@ -1402,5 +1451,24 @@
whenever(it.transportInfo).thenReturn(WIFI_INFO_ACTIVE)
whenever(it.hasCapability(NET_CAPABILITY_VALIDATED)).thenReturn(true)
}
+
+ /**
+ * To properly mimic telephony manager, create a service state, and then turn it into an
+ * intent
+ */
+ private fun serviceStateIntent(
+ subId: Int,
+ emergencyOnly: Boolean = false,
+ ): Intent {
+ val serviceState = ServiceState().apply { isEmergencyOnly = emergencyOnly }
+
+ val bundle = Bundle()
+ serviceState.fillInNotifierBundle(bundle)
+
+ return Intent(Intent.ACTION_SERVICE_STATE).apply {
+ putExtras(bundle)
+ putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, subId)
+ }
+ }
}
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconsInteractorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconsInteractorTest.kt
index 0f9cbfa..58d9ee3 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconsInteractorTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconsInteractorTest.kt
@@ -28,6 +28,7 @@
import com.android.systemui.flags.FakeFeatureFlagsClassic
import com.android.systemui.flags.Flags
import com.android.systemui.log.table.TableLogBuffer
+import com.android.systemui.statusbar.pipeline.mobile.data.model.ServiceStateModel
import com.android.systemui.statusbar.pipeline.mobile.data.model.SubscriptionModel
import com.android.systemui.statusbar.pipeline.mobile.data.repository.FakeMobileConnectionRepository
import com.android.systemui.statusbar.pipeline.mobile.data.repository.FakeMobileConnectionsRepository
@@ -888,6 +889,22 @@
assertThat(interactor1).isSameInstanceAs(interactor2)
}
+ @Test
+ fun deviceBasedEmergencyMode_emergencyCallsOnly_followsDeviceServiceStateFromRepo() =
+ testScope.runTest {
+ val latest by collectLastValue(underTest.isDeviceInEmergencyCallsOnlyMode)
+
+ connectionsRepository.deviceServiceState.value =
+ ServiceStateModel(isEmergencyOnly = true)
+
+ assertThat(latest).isTrue()
+
+ connectionsRepository.deviceServiceState.value =
+ ServiceStateModel(isEmergencyOnly = false)
+
+ assertThat(latest).isFalse()
+ }
+
/**
* Convenience method for creating a pair of subscriptions to test the filteredSubscriptions
* flow.
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/satellite/domain/interactor/DeviceBasedSatelliteInteractorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/satellite/domain/interactor/DeviceBasedSatelliteInteractorTest.kt
index 405e3ed..d303976 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/satellite/domain/interactor/DeviceBasedSatelliteInteractorTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/satellite/domain/interactor/DeviceBasedSatelliteInteractorTest.kt
@@ -22,6 +22,7 @@
import com.android.internal.telephony.flags.Flags.FLAG_OEM_ENABLED_SATELLITE_FLAG
import com.android.systemui.SysuiTestCase
import com.android.systemui.coroutines.collectLastValue
+import com.android.systemui.log.core.FakeLogBuffer
import com.android.systemui.statusbar.pipeline.mobile.domain.interactor.FakeMobileIconsInteractor
import com.android.systemui.statusbar.pipeline.mobile.util.FakeMobileMappingsProxy
import com.android.systemui.statusbar.pipeline.satellite.data.prod.FakeDeviceBasedSatelliteRepository
@@ -71,6 +72,7 @@
deviceProvisioningInteractor,
wifiInteractor,
testScope.backgroundScope,
+ FakeLogBuffer.Factory.create(),
)
}
@@ -114,6 +116,7 @@
deviceProvisioningInteractor,
wifiInteractor,
testScope.backgroundScope,
+ FakeLogBuffer.Factory.create(),
)
val latest by collectLastValue(underTest.isSatelliteAllowed)
@@ -162,6 +165,7 @@
deviceProvisioningInteractor,
wifiInteractor,
testScope.backgroundScope,
+ FakeLogBuffer.Factory.create(),
)
val latest by collectLastValue(underTest.connectionState)
@@ -218,6 +222,7 @@
deviceProvisioningInteractor,
wifiInteractor,
testScope.backgroundScope,
+ FakeLogBuffer.Factory.create(),
)
val latest by collectLastValue(underTest.signalStrength)
@@ -238,25 +243,97 @@
@Test
@EnableFlags(FLAG_OEM_ENABLED_SATELLITE_FLAG)
- fun areAllConnectionsOutOfService_noConnections_yes() =
+ fun areAllConnectionsOutOfService_noConnections_noDeviceEmergencyCalls_yes() =
testScope.runTest {
val latest by collectLastValue(underTest.areAllConnectionsOutOfService)
// GIVEN, 0 connections
+ // GIVEN, device is not in emergency calls only mode
+ iconsInteractor.isDeviceInEmergencyCallsOnlyMode.value = false
+
// THEN the value is propagated to this interactor
assertThat(latest).isTrue()
}
@Test
@EnableFlags(FLAG_OEM_ENABLED_SATELLITE_FLAG)
- fun areAllConnectionsOutOfService_twoConnectionsOos_nonNtn_yes() =
+ fun areAllConnectionsOutOfService_noConnections_deviceEmergencyCalls_yes() =
+ testScope.runTest {
+ val latest by collectLastValue(underTest.areAllConnectionsOutOfService)
+
+ // GIVEN, 0 connections
+
+ // GIVEN, device is in emergency calls only mode
+ iconsInteractor.isDeviceInEmergencyCallsOnlyMode.value = true
+
+ // THEN the value is propagated to this interactor
+ assertThat(latest).isFalse()
+ }
+
+ @Test
+ @EnableFlags(FLAG_OEM_ENABLED_SATELLITE_FLAG)
+ fun areAllConnectionsOutOfService_oneConnectionInService_thenLost_noDeviceEmergencyCalls_yes() =
+ testScope.runTest {
+ val latest by collectLastValue(underTest.areAllConnectionsOutOfService)
+
+ // GIVEN, 1 connections
+ val i1 = iconsInteractor.getMobileConnectionInteractorForSubId(1)
+ // GIVEN, no device-based emergency calls
+ iconsInteractor.isDeviceInEmergencyCallsOnlyMode.value = false
+
+ // WHEN connection is in service
+ i1.isInService.value = true
+ i1.isEmergencyOnly.value = false
+ i1.isNonTerrestrial.value = false
+
+ // THEN we are considered NOT to be OOS
+ assertThat(latest).isFalse()
+
+ // WHEN the connection disappears
+ iconsInteractor.icons.value = listOf()
+
+ // THEN we are back to OOS
+ assertThat(latest).isTrue()
+ }
+
+ @Test
+ @EnableFlags(FLAG_OEM_ENABLED_SATELLITE_FLAG)
+ fun areAllConnectionsOutOfService_oneConnectionInService_thenLost_deviceEmergencyCalls_no() =
+ testScope.runTest {
+ val latest by collectLastValue(underTest.areAllConnectionsOutOfService)
+
+ // GIVEN, 1 connections
+ val i1 = iconsInteractor.getMobileConnectionInteractorForSubId(1)
+ // GIVEN, device-based emergency calls
+ iconsInteractor.isDeviceInEmergencyCallsOnlyMode.value = true
+
+ // WHEN one connection is in service
+ i1.isInService.value = true
+ i1.isEmergencyOnly.value = false
+ i1.isNonTerrestrial.value = false
+
+ // THEN we are considered NOT to be OOS
+ assertThat(latest).isFalse()
+
+ // WHEN the connection disappears
+ iconsInteractor.icons.value = listOf()
+
+ // THEN we are still NOT in OOS, due to device-based emergency calls
+ assertThat(latest).isFalse()
+ }
+
+ @Test
+ @EnableFlags(FLAG_OEM_ENABLED_SATELLITE_FLAG)
+ fun areAllConnectionsOutOfService_twoConnectionsOos_nonNtn_noDeviceEmergencyCalls_yes() =
testScope.runTest {
val latest by collectLastValue(underTest.areAllConnectionsOutOfService)
// GIVEN, 2 connections
val i1 = iconsInteractor.getMobileConnectionInteractorForSubId(1)
val i2 = iconsInteractor.getMobileConnectionInteractorForSubId(2)
+ // GIVEN, no device-based emergency calls
+ iconsInteractor.isDeviceInEmergencyCallsOnlyMode.value = false
// WHEN all of the connections are OOS and none are NTN
i1.isInService.value = false
@@ -272,13 +349,39 @@
@Test
@EnableFlags(FLAG_OEM_ENABLED_SATELLITE_FLAG)
- fun areAllConnectionsOutOfService_twoConnectionsOos_oneNtn_no() =
+ fun areAllConnectionsOutOfService_twoConnectionsOos_nonNtn_deviceEmergencyCalls_no() =
testScope.runTest {
val latest by collectLastValue(underTest.areAllConnectionsOutOfService)
// GIVEN, 2 connections
val i1 = iconsInteractor.getMobileConnectionInteractorForSubId(1)
val i2 = iconsInteractor.getMobileConnectionInteractorForSubId(2)
+ // GIVEN, device-based emergency calls
+ iconsInteractor.isDeviceInEmergencyCallsOnlyMode.value = true
+
+ // WHEN all of the connections are OOS and none are NTN
+ i1.isInService.value = false
+ i1.isEmergencyOnly.value = false
+ i1.isNonTerrestrial.value = false
+ i2.isInService.value = false
+ i2.isEmergencyOnly.value = false
+ i2.isNonTerrestrial.value = false
+
+ // THEN we are not considered OOS due to device based emergency calling
+ assertThat(latest).isFalse()
+ }
+
+ @Test
+ @EnableFlags(FLAG_OEM_ENABLED_SATELLITE_FLAG)
+ fun areAllConnectionsOutOfService_twoConnectionsOos_noDeviceEmergencyCalls_oneNtn_no() =
+ testScope.runTest {
+ val latest by collectLastValue(underTest.areAllConnectionsOutOfService)
+
+ // GIVEN, 2 connections
+ val i1 = iconsInteractor.getMobileConnectionInteractorForSubId(1)
+ val i2 = iconsInteractor.getMobileConnectionInteractorForSubId(2)
+ // GIVEN, no device-based emergency calls
+ iconsInteractor.isDeviceInEmergencyCallsOnlyMode.value = false
// WHEN all of the connections are OOS and one is NTN
i1.isInService.value = false
@@ -296,12 +399,14 @@
@Test
@EnableFlags(FLAG_OEM_ENABLED_SATELLITE_FLAG)
- fun areAllConnectionsOutOfService_oneConnectionOos_nonNtn_yes() =
+ fun areAllConnectionsOutOfService_oneConnectionOos_noDeviceEmergencyCalls_nonNtn_yes() =
testScope.runTest {
val latest by collectLastValue(underTest.areAllConnectionsOutOfService)
// GIVEN, 1 connection
val i1 = iconsInteractor.getMobileConnectionInteractorForSubId(1)
+ // GIVEN, no device-based emergency calls
+ iconsInteractor.isDeviceInEmergencyCallsOnlyMode.value = false
// WHEN all of the connections are OOS
i1.isInService.value = false
@@ -314,7 +419,27 @@
@Test
@EnableFlags(FLAG_OEM_ENABLED_SATELLITE_FLAG)
- fun areAllConnectionsOutOfService_oneConnectionOos_ntn_yes() =
+ fun areAllConnectionsOutOfService_oneConnectionOos_nonNtn_no() =
+ testScope.runTest {
+ val latest by collectLastValue(underTest.areAllConnectionsOutOfService)
+
+ // GIVEN, 1 connection
+ val i1 = iconsInteractor.getMobileConnectionInteractorForSubId(1)
+ // GIVEN, device-based emergency calls
+ iconsInteractor.isDeviceInEmergencyCallsOnlyMode.value = true
+
+ // WHEN all of the connections are OOS
+ i1.isInService.value = false
+ i1.isEmergencyOnly.value = false
+ i1.isNonTerrestrial.value = false
+
+ // THEN the value is propagated to this interactor
+ assertThat(latest).isFalse()
+ }
+
+ @Test
+ @EnableFlags(FLAG_OEM_ENABLED_SATELLITE_FLAG)
+ fun areAllConnectionsOutOfService_oneConnectionOos_ntn_no() =
testScope.runTest {
val latest by collectLastValue(underTest.areAllConnectionsOutOfService)
@@ -416,6 +541,7 @@
deviceProvisioningInteractor,
wifiInteractor,
testScope.backgroundScope,
+ FakeLogBuffer.Factory.create(),
)
val latest by collectLastValue(underTest.areAllConnectionsOutOfService)
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/satellite/ui/viewmodel/DeviceBasedSatelliteViewModelTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/satellite/ui/viewmodel/DeviceBasedSatelliteViewModelTest.kt
index ceaae9e..43b9568 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/satellite/ui/viewmodel/DeviceBasedSatelliteViewModelTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/satellite/ui/viewmodel/DeviceBasedSatelliteViewModelTest.kt
@@ -75,6 +75,7 @@
deviceProvisioningInteractor,
wifiInteractor,
testScope.backgroundScope,
+ FakeLogBuffer.Factory.create(),
)
underTest =
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/FakeMobileConnectionsRepository.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/FakeMobileConnectionsRepository.kt
index cce038f..8229575 100644
--- a/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/FakeMobileConnectionsRepository.kt
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/FakeMobileConnectionsRepository.kt
@@ -23,6 +23,7 @@
import com.android.settingslib.mobile.MobileMappings
import com.android.settingslib.mobile.TelephonyIcons
import com.android.systemui.log.table.TableLogBuffer
+import com.android.systemui.statusbar.pipeline.mobile.data.model.ServiceStateModel
import com.android.systemui.statusbar.pipeline.mobile.data.model.SubscriptionModel
import com.android.systemui.statusbar.pipeline.mobile.util.FakeMobileMappingsProxy
import com.android.systemui.statusbar.pipeline.mobile.util.MobileMappingsProxy
@@ -93,6 +94,8 @@
private val _defaultMobileIconGroup = MutableStateFlow(DEFAULT_ICON)
override val defaultMobileIconGroup = _defaultMobileIconGroup
+ override val deviceServiceState = MutableStateFlow<ServiceStateModel?>(null)
+
override val isAnySimSecure = MutableStateFlow(false)
override fun getIsAnySimSecure(): Boolean = isAnySimSecure.value
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/FakeMobileIconsInteractor.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/FakeMobileIconsInteractor.kt
index de6c87c2..3a4bf8e 100644
--- a/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/FakeMobileIconsInteractor.kt
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/FakeMobileIconsInteractor.kt
@@ -81,6 +81,8 @@
override val isForceHidden = MutableStateFlow(false)
+ override val isDeviceInEmergencyCallsOnlyMode = MutableStateFlow(false)
+
/** Always returns a new fake interactor */
override fun getMobileConnectionInteractorForSubId(subId: Int): FakeMobileIconInteractor {
return FakeMobileIconInteractor(tableLogBuffer).also {