summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/model/NetworkNameModel.kt26
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/demo/DemoMobileConnectionsRepository.kt14
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/CarrierMergedConnectionRepository.kt77
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/FullMobileConnectionRepository.kt2
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionRepositoryImpl.kt18
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconInteractor.kt2
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/data/repository/demo/DemoModeWifiDataSource.kt7
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/data/repository/demo/DemoWifiRepository.kt7
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/data/repository/demo/model/FakeWifiEventModel.kt5
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/demo/DemoMobileConnectionParameterizedTest.kt3
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/demo/DemoMobileConnectionsRepositoryTest.kt5
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/CarrierMergedConnectionRepositoryTest.kt83
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/FullMobileConnectionRepositoryTest.kt32
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionRepositoryTest.kt44
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionsRepositoryTest.kt2
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/FakeMobileIconInteractor.kt2
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconInteractorTest.kt4
17 files changed, 244 insertions, 89 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/model/NetworkNameModel.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/model/NetworkNameModel.kt
index c50d82a66c76..78231e28803e 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/model/NetworkNameModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/model/NetworkNameModel.kt
@@ -48,15 +48,31 @@ sealed interface NetworkNameModel : Diffable<NetworkNameModel> {
* This name has been derived from telephony intents. see
* [android.telephony.TelephonyManager.ACTION_SERVICE_PROVIDERS_UPDATED]
*/
- data class Derived(override val name: String) : NetworkNameModel {
+ data class IntentDerived(override val name: String) : NetworkNameModel {
override fun logDiffs(prevVal: NetworkNameModel, row: TableRowLogger) {
- if (prevVal !is Derived || prevVal.name != name) {
- row.logChange(COL_NETWORK_NAME, "Derived($name)")
+ if (prevVal !is IntentDerived || prevVal.name != name) {
+ row.logChange(COL_NETWORK_NAME, "IntentDerived($name)")
}
}
override fun logFull(row: TableRowLogger) {
- row.logChange(COL_NETWORK_NAME, "Derived($name)")
+ row.logChange(COL_NETWORK_NAME, "IntentDerived($name)")
+ }
+ }
+
+ /**
+ * This name has been derived from the sim via
+ * [android.telephony.TelephonyManager.getSimOperatorName].
+ */
+ data class SimDerived(override val name: String) : NetworkNameModel {
+ override fun logDiffs(prevVal: NetworkNameModel, row: TableRowLogger) {
+ if (prevVal !is SimDerived || prevVal.name != name) {
+ row.logChange(COL_NETWORK_NAME, "SimDerived($name)")
+ }
+ }
+
+ override fun logFull(row: TableRowLogger) {
+ row.logChange(COL_NETWORK_NAME, "SimDerived($name)")
}
}
@@ -84,5 +100,5 @@ fun Intent.toNetworkNameModel(separator: String): NetworkNameModel? {
str.append(spn)
}
- return if (str.isNotEmpty()) NetworkNameModel.Derived(str.toString()) else null
+ return if (str.isNotEmpty()) NetworkNameModel.IntentDerived(str.toString()) else null
}
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 58cd36e59d52..d10d11d11c13 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
@@ -240,7 +240,7 @@ constructor(
// This is always true here, because we split out disabled states at the data-source level
connection.dataEnabled.value = true
- connection.networkName.value = NetworkNameModel.Derived(state.name)
+ connection.networkName.value = NetworkNameModel.IntentDerived(state.name)
connection.cdmaRoaming.value = state.roaming
connection.connectionInfo.value = state.toMobileConnectionModel()
@@ -258,10 +258,13 @@ constructor(
maybeCreateSubscription(subId)
carrierMergedSubId = subId
+ // TODO(b/261029387): until we have a command, use the most recent subId
+ defaultDataSubId.value = subId
+
val connection = getRepoForSubId(subId)
// This is always true here, because we split out disabled states at the data-source level
connection.dataEnabled.value = true
- connection.networkName.value = NetworkNameModel.Derived(CARRIER_MERGED_NAME)
+ connection.networkName.value = NetworkNameModel.IntentDerived(CARRIER_MERGED_NAME)
connection.numberOfLevels.value = event.numberOfLevels
connection.cdmaRoaming.value = false
connection.connectionInfo.value = event.toMobileConnectionModel()
@@ -336,7 +339,10 @@ constructor(
}
private fun FakeWifiEventModel.CarrierMerged.toMobileConnectionModel(): MobileConnectionModel {
- return createCarrierMergedConnectionModel(this.level)
+ return createCarrierMergedConnectionModel(
+ this.level,
+ activity.toMobileDataActivityModel(),
+ )
}
private fun SignalIcon.MobileIconGroup?.toResolvedNetworkType(): ResolvedNetworkType {
@@ -371,5 +377,5 @@ class DemoMobileConnectionRepository(
override val cdmaRoaming = MutableStateFlow(false)
- override val networkName = MutableStateFlow(NetworkNameModel.Derived("demo network"))
+ override val networkName = MutableStateFlow(NetworkNameModel.IntentDerived("demo network"))
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/CarrierMergedConnectionRepository.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/CarrierMergedConnectionRepository.kt
index f5041d89c1d1..938c7346f702 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/CarrierMergedConnectionRepository.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/CarrierMergedConnectionRepository.kt
@@ -16,6 +16,7 @@
package com.android.systemui.statusbar.pipeline.mobile.data.repository.prod
+import android.telephony.TelephonyManager
import android.util.Log
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
@@ -37,7 +38,6 @@ import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.combine
-import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
@@ -54,10 +54,18 @@ import kotlinx.coroutines.flow.stateIn
class CarrierMergedConnectionRepository(
override val subId: Int,
override val tableLogBuffer: TableLogBuffer,
- defaultNetworkName: NetworkNameModel,
+ private val telephonyManager: TelephonyManager,
@Application private val scope: CoroutineScope,
val wifiRepository: WifiRepository,
) : MobileConnectionRepository {
+ init {
+ if (telephonyManager.subscriptionId != subId) {
+ throw IllegalStateException(
+ "CarrierMergedRepo: TelephonyManager should be created with subId($subId). " +
+ "Found ${telephonyManager.subscriptionId} instead."
+ )
+ }
+ }
/**
* Outputs the carrier merged network to use, or null if we don't have a valid carrier merged
@@ -87,17 +95,28 @@ class CarrierMergedConnectionRepository(
}
override val connectionInfo: StateFlow<MobileConnectionModel> =
- network
- .map { it.toMobileConnectionModel() }
+ combine(network, wifiRepository.wifiActivity) { network, activity ->
+ if (network == null) {
+ MobileConnectionModel()
+ } else {
+ createCarrierMergedConnectionModel(network.level, activity)
+ }
+ }
.stateIn(scope, SharingStarted.WhileSubscribed(), MobileConnectionModel())
- // Carrier merged is never roaming.
- override val cdmaRoaming: StateFlow<Boolean> = MutableStateFlow(false).asStateFlow()
+ override val cdmaRoaming: StateFlow<Boolean> = MutableStateFlow(ROAMING).asStateFlow()
- // TODO(b/238425913): Fetch the carrier merged network name.
override val networkName: StateFlow<NetworkNameModel> =
- flowOf(defaultNetworkName)
- .stateIn(scope, SharingStarted.WhileSubscribed(), defaultNetworkName)
+ network
+ // The SIM operator name should be the same throughout the lifetime of a subId, **but**
+ // it may not be available when this repo is created because it takes time to load. To
+ // be safe, we re-fetch it each time the network has changed.
+ .map { NetworkNameModel.SimDerived(telephonyManager.simOperatorName) }
+ .stateIn(
+ scope,
+ SharingStarted.WhileSubscribed(),
+ NetworkNameModel.SimDerived(telephonyManager.simOperatorName),
+ )
override val numberOfLevels: StateFlow<Int> =
wifiRepository.wifiNetwork
@@ -112,37 +131,24 @@ class CarrierMergedConnectionRepository(
override val dataEnabled: StateFlow<Boolean> = wifiRepository.isWifiEnabled
- private fun WifiNetworkModel.CarrierMerged?.toMobileConnectionModel(): MobileConnectionModel {
- if (this == null) {
- return MobileConnectionModel()
- }
-
- return createCarrierMergedConnectionModel(level)
- }
-
companion object {
/**
* Creates an instance of [MobileConnectionModel] that represents a carrier merged network
- * with the given [level].
+ * with the given [level] and [activity].
*/
- fun createCarrierMergedConnectionModel(level: Int): MobileConnectionModel {
+ fun createCarrierMergedConnectionModel(
+ level: Int,
+ activity: DataActivityModel,
+ ): MobileConnectionModel {
return MobileConnectionModel(
primaryLevel = level,
cdmaLevel = level,
- // A [WifiNetworkModel.CarrierMerged] instance is always connected.
- // (A [WifiNetworkModel.Inactive] represents a disconnected network.)
- dataConnectionState = DataConnectionState.Connected,
- // TODO(b/238425913): This should come from [WifiRepository.wifiActivity].
- dataActivityDirection =
- DataActivityModel(
- hasActivityIn = false,
- hasActivityOut = false,
- ),
+ dataActivityDirection = activity,
+ // Here and below: These values are always the same for every carrier-merged
+ // connection.
resolvedNetworkType = ResolvedNetworkType.CarrierMergedNetworkType,
- // Carrier merged is never roaming
- isRoaming = false,
-
- // TODO(b/238425913): Verify that these fields never change for carrier merged.
+ dataConnectionState = DataConnectionState.Connected,
+ isRoaming = ROAMING,
isEmergencyOnly = false,
operatorAlphaShort = null,
isInService = true,
@@ -150,24 +156,27 @@ class CarrierMergedConnectionRepository(
carrierNetworkChangeActive = false,
)
}
+
+ // Carrier merged is never roaming
+ private const val ROAMING = false
}
@SysUISingleton
class Factory
@Inject
constructor(
+ private val telephonyManager: TelephonyManager,
@Application private val scope: CoroutineScope,
private val wifiRepository: WifiRepository,
) {
fun build(
subId: Int,
mobileLogger: TableLogBuffer,
- defaultNetworkName: NetworkNameModel,
): MobileConnectionRepository {
return CarrierMergedConnectionRepository(
subId,
mobileLogger,
- defaultNetworkName,
+ telephonyManager.createForSubscriptionId(subId),
scope,
wifiRepository,
)
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/FullMobileConnectionRepository.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/FullMobileConnectionRepository.kt
index f17791b65502..a39ea0abce5a 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/FullMobileConnectionRepository.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/FullMobileConnectionRepository.kt
@@ -86,7 +86,7 @@ class FullMobileConnectionRepository(
}
private val carrierMergedRepo: MobileConnectionRepository by lazy {
- carrierMergedRepoFactory.build(subId, tableLogBuffer, defaultNetworkName)
+ carrierMergedRepoFactory.build(subId, tableLogBuffer)
}
@VisibleForTesting
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionRepositoryImpl.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionRepositoryImpl.kt
index cfc4cc4ba947..dcce0ea58512 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionRepositoryImpl.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionRepositoryImpl.kt
@@ -61,6 +61,7 @@ import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
+import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.mapLatest
import kotlinx.coroutines.flow.mapNotNull
@@ -91,7 +92,7 @@ class MobileConnectionRepositoryImpl(
init {
if (telephonyManager.subscriptionId != subId) {
throw IllegalStateException(
- "TelephonyManager should be created with subId($subId). " +
+ "MobileRepo: TelephonyManager should be created with subId($subId). " +
"Found ${telephonyManager.subscriptionId} instead."
)
}
@@ -267,15 +268,14 @@ class MobileConnectionRepositoryImpl(
override val networkName: StateFlow<NetworkNameModel> =
broadcastDispatcher
- .broadcastFlow(IntentFilter(TelephonyManager.ACTION_SERVICE_PROVIDERS_UPDATED)) {
- intent,
- _ ->
- if (intent.getIntExtra(EXTRA_SUBSCRIPTION_ID, INVALID_SUBSCRIPTION_ID) != subId) {
- defaultNetworkName
- } else {
- intent.toNetworkNameModel(networkNameSeparator) ?: defaultNetworkName
- }
+ .broadcastFlow(
+ filter = IntentFilter(TelephonyManager.ACTION_SERVICE_PROVIDERS_UPDATED),
+ map = { intent, _ -> intent },
+ )
+ .filter { intent ->
+ intent.getIntExtra(EXTRA_SUBSCRIPTION_ID, INVALID_SUBSCRIPTION_ID) == subId
}
+ .map { intent -> intent.toNetworkNameModel(networkNameSeparator) ?: defaultNetworkName }
.stateIn(scope, SharingStarted.WhileSubscribed(), defaultNetworkName)
override val dataEnabled = run {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconInteractor.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconInteractor.kt
index 9b7614c2ad08..7b0f95271d63 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconInteractor.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconInteractor.kt
@@ -158,7 +158,7 @@ class MobileIconInteractorImpl(
if (
networkName is NetworkNameModel.Default && connection.operatorAlphaShort != null
) {
- NetworkNameModel.Derived(connection.operatorAlphaShort)
+ NetworkNameModel.IntentDerived(connection.operatorAlphaShort)
} else {
networkName
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/data/repository/demo/DemoModeWifiDataSource.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/data/repository/demo/DemoModeWifiDataSource.kt
index caac8fa2f2c3..7d2501ca0e79 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/data/repository/demo/DemoModeWifiDataSource.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/data/repository/demo/DemoModeWifiDataSource.kt
@@ -53,7 +53,7 @@ constructor(
private fun Bundle.activeWifiEvent(): FakeWifiEventModel.Wifi {
val level = getString("level")?.toInt()
- val activity = getString("activity")?.toActivity()
+ val activity = getString("activity").toActivity()
val ssid = getString("ssid")
val validated = getString("fully").toBoolean()
@@ -69,11 +69,12 @@ constructor(
val subId = getString("slot")?.toInt() ?: DEFAULT_CARRIER_MERGED_SUB_ID
val level = getString("level")?.toInt() ?: 0
val numberOfLevels = getString("numlevels")?.toInt() ?: DEFAULT_NUM_LEVELS
+ val activity = getString("activity").toActivity()
- return FakeWifiEventModel.CarrierMerged(subId, level, numberOfLevels)
+ return FakeWifiEventModel.CarrierMerged(subId, level, numberOfLevels, activity)
}
- private fun String.toActivity(): Int =
+ private fun String?.toActivity(): Int =
when (this) {
"inout" -> WifiManager.TrafficStateCallback.DATA_ACTIVITY_INOUT
"in" -> WifiManager.TrafficStateCallback.DATA_ACTIVITY_IN
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/data/repository/demo/DemoWifiRepository.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/data/repository/demo/DemoWifiRepository.kt
index e161b3e42d02..a19c3c3e86a6 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/data/repository/demo/DemoWifiRepository.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/data/repository/demo/DemoWifiRepository.kt
@@ -80,17 +80,14 @@ constructor(
private fun processEnabledWifiState(event: FakeWifiEventModel.Wifi) {
_isWifiEnabled.value = true
_isWifiDefault.value = true
- _wifiActivity.value =
- event.activity?.toWifiDataActivityModel()
- ?: DataActivityModel(hasActivityIn = false, hasActivityOut = false)
+ _wifiActivity.value = event.activity.toWifiDataActivityModel()
_wifiNetwork.value = event.toWifiNetworkModel()
}
private fun processCarrierMergedWifiState(event: FakeWifiEventModel.CarrierMerged) {
_isWifiEnabled.value = true
_isWifiDefault.value = true
- // TODO(b/238425913): Support activity in demo mode.
- _wifiActivity.value = DataActivityModel(hasActivityIn = false, hasActivityOut = false)
+ _wifiActivity.value = event.activity.toWifiDataActivityModel()
_wifiNetwork.value = event.toCarrierMergedModel()
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/data/repository/demo/model/FakeWifiEventModel.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/data/repository/demo/model/FakeWifiEventModel.kt
index 518f8ce66d2e..f5035cbc0215 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/data/repository/demo/model/FakeWifiEventModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/data/repository/demo/model/FakeWifiEventModel.kt
@@ -16,6 +16,8 @@
package com.android.systemui.statusbar.pipeline.wifi.data.repository.demo.model
+import android.telephony.Annotation
+
/**
* Model for demo wifi commands, ported from [NetworkControllerImpl]
*
@@ -24,7 +26,7 @@ package com.android.systemui.statusbar.pipeline.wifi.data.repository.demo.model
sealed interface FakeWifiEventModel {
data class Wifi(
val level: Int?,
- val activity: Int?,
+ @Annotation.DataActivityType val activity: Int,
val ssid: String?,
val validated: Boolean?,
) : FakeWifiEventModel
@@ -33,6 +35,7 @@ sealed interface FakeWifiEventModel {
val subscriptionId: Int,
val level: Int,
val numberOfLevels: Int,
+ @Annotation.DataActivityType val activity: Int,
) : FakeWifiEventModel
object WifiDisabled : FakeWifiEventModel
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/demo/DemoMobileConnectionParameterizedTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/demo/DemoMobileConnectionParameterizedTest.kt
index 6989b514a703..00ce412f2a65 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/demo/DemoMobileConnectionParameterizedTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/demo/DemoMobileConnectionParameterizedTest.kt
@@ -138,7 +138,8 @@ internal class DemoMobileConnectionParameterizedTest(private val testCase: TestC
assertThat(connectionInfo.carrierNetworkChangeActive)
.isEqualTo(model.carrierNetworkChange)
assertThat(connectionInfo.isRoaming).isEqualTo(model.roaming)
- assertThat(conn.networkName.value).isEqualTo(NetworkNameModel.Derived(model.name))
+ assertThat(conn.networkName.value)
+ .isEqualTo(NetworkNameModel.IntentDerived(model.name))
// TODO(b/261029387): check these once we start handling them
assertThat(connectionInfo.isEmergencyOnly).isFalse()
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/demo/DemoMobileConnectionsRepositoryTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/demo/DemoMobileConnectionsRepositoryTest.kt
index f12d113cfaa8..f60d92bde202 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/demo/DemoMobileConnectionsRepositoryTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/demo/DemoMobileConnectionsRepositoryTest.kt
@@ -539,7 +539,8 @@ class DemoMobileConnectionsRepositoryTest : SysuiTestCase() {
assertThat(connectionInfo.carrierNetworkChangeActive)
.isEqualTo(model.carrierNetworkChange)
assertThat(connectionInfo.isRoaming).isEqualTo(model.roaming)
- assertThat(conn.networkName.value).isEqualTo(NetworkNameModel.Derived(model.name))
+ assertThat(conn.networkName.value)
+ .isEqualTo(NetworkNameModel.IntentDerived(model.name))
// TODO(b/261029387) check these once we start handling them
assertThat(connectionInfo.isEmergencyOnly).isFalse()
@@ -594,9 +595,11 @@ fun validCarrierMergedEvent(
subId: Int = 1,
level: Int = 1,
numberOfLevels: Int = 4,
+ activity: Int = DATA_ACTIVITY_NONE,
): FakeWifiEventModel.CarrierMerged =
FakeWifiEventModel.CarrierMerged(
subscriptionId = subId,
level = level,
numberOfLevels = numberOfLevels,
+ activity = activity,
)
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/CarrierMergedConnectionRepositoryTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/CarrierMergedConnectionRepositoryTest.kt
index ea90150b432a..abb45619e1dd 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/CarrierMergedConnectionRepositoryTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/CarrierMergedConnectionRepositoryTest.kt
@@ -16,6 +16,7 @@
package com.android.systemui.statusbar.pipeline.mobile.data.repository.prod
+import android.telephony.TelephonyManager
import android.testing.AndroidTestingRunner
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
@@ -27,6 +28,7 @@ import com.android.systemui.statusbar.pipeline.mobile.data.model.ResolvedNetwork
import com.android.systemui.statusbar.pipeline.shared.data.model.DataActivityModel
import com.android.systemui.statusbar.pipeline.wifi.data.model.WifiNetworkModel
import com.android.systemui.statusbar.pipeline.wifi.data.repository.FakeWifiRepository
+import com.android.systemui.util.mockito.whenever
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.launchIn
@@ -49,6 +51,7 @@ class CarrierMergedConnectionRepositoryTest : SysuiTestCase() {
private lateinit var wifiRepository: FakeWifiRepository
@Mock private lateinit var logger: TableLogBuffer
+ @Mock private lateinit var telephonyManager: TelephonyManager
private val testDispatcher = UnconfinedTestDispatcher()
private val testScope = TestScope(testDispatcher)
@@ -56,13 +59,16 @@ class CarrierMergedConnectionRepositoryTest : SysuiTestCase() {
@Before
fun setUp() {
MockitoAnnotations.initMocks(this)
+ whenever(telephonyManager.subscriptionId).thenReturn(SUB_ID)
+ whenever(telephonyManager.simOperatorName).thenReturn("")
+
wifiRepository = FakeWifiRepository()
underTest =
CarrierMergedConnectionRepository(
SUB_ID,
logger,
- NetworkNameModel.Default("name"),
+ telephonyManager,
testScope.backgroundScope,
wifiRepository,
)
@@ -135,6 +141,44 @@ class CarrierMergedConnectionRepositoryTest : SysuiTestCase() {
}
@Test
+ fun connectionInfo_activity_comesFromWifiActivity() =
+ testScope.runTest {
+ var latest: MobileConnectionModel? = null
+ val job = underTest.connectionInfo.onEach { latest = it }.launchIn(this)
+
+ wifiRepository.setIsWifiEnabled(true)
+ wifiRepository.setIsWifiDefault(true)
+ wifiRepository.setWifiNetwork(
+ WifiNetworkModel.CarrierMerged(
+ networkId = NET_ID,
+ subscriptionId = SUB_ID,
+ level = 3,
+ )
+ )
+ wifiRepository.setWifiActivity(
+ DataActivityModel(
+ hasActivityIn = true,
+ hasActivityOut = false,
+ )
+ )
+
+ assertThat(latest!!.dataActivityDirection.hasActivityIn).isTrue()
+ assertThat(latest!!.dataActivityDirection.hasActivityOut).isFalse()
+
+ wifiRepository.setWifiActivity(
+ DataActivityModel(
+ hasActivityIn = false,
+ hasActivityOut = true,
+ )
+ )
+
+ assertThat(latest!!.dataActivityDirection.hasActivityIn).isFalse()
+ assertThat(latest!!.dataActivityDirection.hasActivityOut).isTrue()
+
+ job.cancel()
+ }
+
+ @Test
fun connectionInfo_carrierMergedWifi_wrongSubId_isDefault() =
testScope.runTest {
var latest: MobileConnectionModel? = null
@@ -244,6 +288,43 @@ class CarrierMergedConnectionRepositoryTest : SysuiTestCase() {
job.cancel()
}
+ @Test
+ fun networkName_usesSimOperatorNameAsInitial() =
+ testScope.runTest {
+ whenever(telephonyManager.simOperatorName).thenReturn("Test SIM name")
+
+ var latest: NetworkNameModel? = null
+ val job = underTest.networkName.onEach { latest = it }.launchIn(this)
+
+ assertThat(latest).isEqualTo(NetworkNameModel.SimDerived("Test SIM name"))
+
+ job.cancel()
+ }
+
+ @Test
+ fun networkName_updatesOnNetworkUpdate() =
+ testScope.runTest {
+ whenever(telephonyManager.simOperatorName).thenReturn("Test SIM name")
+
+ var latest: NetworkNameModel? = null
+ val job = underTest.networkName.onEach { latest = it }.launchIn(this)
+
+ assertThat(latest).isEqualTo(NetworkNameModel.SimDerived("Test SIM name"))
+
+ whenever(telephonyManager.simOperatorName).thenReturn("New SIM name")
+ wifiRepository.setWifiNetwork(
+ WifiNetworkModel.CarrierMerged(
+ networkId = NET_ID,
+ subscriptionId = SUB_ID,
+ level = 3,
+ )
+ )
+
+ assertThat(latest).isEqualTo(NetworkNameModel.SimDerived("New SIM name"))
+
+ job.cancel()
+ }
+
private companion object {
const val SUB_ID = 123
const val NET_ID = 456
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/FullMobileConnectionRepositoryTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/FullMobileConnectionRepositoryTest.kt
index da208a7f08c9..c02ca01cedc4 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/FullMobileConnectionRepositoryTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/FullMobileConnectionRepositoryTest.kt
@@ -88,8 +88,7 @@ class FullMobileConnectionRepositoryTest : SysuiTestCase() {
)
)
.thenReturn(mobileRepo)
- whenever(carrierMergedFactory.build(eq(SUB_ID), any(), eq(DEFAULT_NAME)))
- .thenReturn(carrierMergedRepo)
+ whenever(carrierMergedFactory.build(eq(SUB_ID), any())).thenReturn(carrierMergedRepo)
}
@Test
@@ -127,7 +126,7 @@ class FullMobileConnectionRepositoryTest : SysuiTestCase() {
assertThat(underTest.activeRepo.value).isEqualTo(mobileRepo)
assertThat(underTest.connectionInfo.value).isEqualTo(mobileConnectionInfo)
- verify(carrierMergedFactory, never()).build(SUB_ID, tableLogBuffer, DEFAULT_NAME)
+ verify(carrierMergedFactory, never()).build(SUB_ID, tableLogBuffer)
}
@Test
@@ -364,9 +363,10 @@ class FullMobileConnectionRepositoryTest : SysuiTestCase() {
fun connectionInfo_logging_notCarrierMerged_getsUpdates() =
testScope.runTest {
// SETUP: Use real repositories to verify the diffing still works. (See b/267501739.)
- val telephonyManager = mock<TelephonyManager>()
+ val telephonyManager =
+ mock<TelephonyManager>().apply { whenever(this.simOperatorName).thenReturn("") }
createRealMobileRepo(telephonyManager)
- createRealCarrierMergedRepo(FakeWifiRepository())
+ createRealCarrierMergedRepo(telephonyManager, FakeWifiRepository())
initializeRepo(startingIsCarrierMerged = false)
@@ -401,9 +401,11 @@ class FullMobileConnectionRepositoryTest : SysuiTestCase() {
fun connectionInfo_logging_carrierMerged_getsUpdates() =
testScope.runTest {
// SETUP: Use real repositories to verify the diffing still works. (See b/267501739.)
- createRealMobileRepo(mock())
+ val telephonyManager =
+ mock<TelephonyManager>().apply { whenever(this.simOperatorName).thenReturn("") }
+ createRealMobileRepo(telephonyManager)
val wifiRepository = FakeWifiRepository()
- createRealCarrierMergedRepo(wifiRepository)
+ createRealCarrierMergedRepo(telephonyManager, wifiRepository)
initializeRepo(startingIsCarrierMerged = true)
@@ -441,11 +443,12 @@ class FullMobileConnectionRepositoryTest : SysuiTestCase() {
fun connectionInfo_logging_updatesWhenCarrierMergedUpdates() =
testScope.runTest {
// SETUP: Use real repositories to verify the diffing still works. (See b/267501739.)
- val telephonyManager = mock<TelephonyManager>()
+ val telephonyManager =
+ mock<TelephonyManager>().apply { whenever(this.simOperatorName).thenReturn("") }
createRealMobileRepo(telephonyManager)
val wifiRepository = FakeWifiRepository()
- createRealCarrierMergedRepo(wifiRepository)
+ createRealCarrierMergedRepo(telephonyManager, wifiRepository)
initializeRepo(startingIsCarrierMerged = false)
@@ -516,11 +519,12 @@ class FullMobileConnectionRepositoryTest : SysuiTestCase() {
fun connectionInfo_logging_doesNotLogUpdatesForNotActiveRepo() =
testScope.runTest {
// SETUP: Use real repositories to verify the diffing still works. (See b/267501739.)
- val telephonyManager = mock<TelephonyManager>()
+ val telephonyManager =
+ mock<TelephonyManager>().apply { whenever(this.simOperatorName).thenReturn("") }
createRealMobileRepo(telephonyManager)
val wifiRepository = FakeWifiRepository()
- createRealCarrierMergedRepo(wifiRepository)
+ createRealCarrierMergedRepo(telephonyManager, wifiRepository)
// WHEN isCarrierMerged = false
initializeRepo(startingIsCarrierMerged = false)
@@ -617,6 +621,7 @@ class FullMobileConnectionRepositoryTest : SysuiTestCase() {
}
private fun createRealCarrierMergedRepo(
+ telephonyManager: TelephonyManager,
wifiRepository: FakeWifiRepository,
): CarrierMergedConnectionRepository {
wifiRepository.setIsWifiEnabled(true)
@@ -625,12 +630,11 @@ class FullMobileConnectionRepositoryTest : SysuiTestCase() {
CarrierMergedConnectionRepository(
SUB_ID,
tableLogBuffer,
- defaultNetworkName = NetworkNameModel.Default("default"),
+ telephonyManager,
testScope.backgroundScope,
wifiRepository,
)
- whenever(carrierMergedFactory.build(eq(SUB_ID), any(), eq(DEFAULT_NAME)))
- .thenReturn(realRepo)
+ whenever(carrierMergedFactory.build(eq(SUB_ID), any())).thenReturn(realRepo)
return realRepo
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionRepositoryTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionRepositoryTest.kt
index 1a5cc9abd9b6..a294088a41c0 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionRepositoryTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionRepositoryTest.kt
@@ -24,7 +24,6 @@ import android.telephony.ServiceState
import android.telephony.ServiceState.STATE_IN_SERVICE
import android.telephony.ServiceState.STATE_OUT_OF_SERVICE
import android.telephony.SignalStrength
-import android.telephony.SubscriptionInfo
import android.telephony.TelephonyCallback
import android.telephony.TelephonyCallback.DataActivityListener
import android.telephony.TelephonyCallback.ServiceStateListener
@@ -556,16 +555,51 @@ class MobileConnectionRepositoryTest : SysuiTestCase() {
}
@Test
- fun `network name - broadcast not for this sub id - returns default`() =
+ fun `network name - broadcast not for this sub id - keeps old value`() =
runBlocking(IMMEDIATE) {
var latest: NetworkNameModel? = null
val job = underTest.networkName.onEach { latest = it }.launchIn(this)
- val intent = spnIntent(subId = 101)
+ val intent = spnIntent()
+ fakeBroadcastDispatcher.registeredReceivers.forEach { receiver ->
+ receiver.onReceive(context, intent)
+ }
+ assertThat(latest).isEqualTo(intent.toNetworkNameModel(SEP))
+
+ // WHEN an intent with a different subId is sent
+ val wrongSubIntent = spnIntent(subId = 101)
fakeBroadcastDispatcher.registeredReceivers.forEach { receiver ->
+ receiver.onReceive(context, wrongSubIntent)
+ }
+
+ // THEN the previous intent's name is still used
+ assertThat(latest).isEqualTo(intent.toNetworkNameModel(SEP))
+
+ job.cancel()
+ }
+
+ @Test
+ fun `network name - broadcast has no data - updates to default`() =
+ runBlocking(IMMEDIATE) {
+ var latest: NetworkNameModel? = null
+ val job = underTest.networkName.onEach { latest = it }.launchIn(this)
+
+ val intent = spnIntent()
+ fakeBroadcastDispatcher.registeredReceivers.forEach { receiver ->
receiver.onReceive(context, intent)
}
+ assertThat(latest).isEqualTo(intent.toNetworkNameModel(SEP))
+
+ val intentWithoutInfo =
+ spnIntent(
+ showSpn = false,
+ showPlmn = false,
+ )
+
+ fakeBroadcastDispatcher.registeredReceivers.forEach { receiver ->
+ receiver.onReceive(context, intentWithoutInfo)
+ }
assertThat(latest).isEqualTo(DEFAULT_NAME)
@@ -573,7 +607,7 @@ class MobileConnectionRepositoryTest : SysuiTestCase() {
}
@Test
- fun `network name - operatorAlphaShort - tracked`() =
+ fun `operatorAlphaShort - tracked`() =
runBlocking(IMMEDIATE) {
var latest: String? = null
@@ -703,8 +737,6 @@ class MobileConnectionRepositoryTest : SysuiTestCase() {
companion object {
private val IMMEDIATE = Dispatchers.Main.immediate
private const val SUB_1_ID = 1
- private val SUB_1 =
- mock<SubscriptionInfo>().also { whenever(it.subscriptionId).thenReturn(SUB_1_ID) }
private val DEFAULT_NAME = NetworkNameModel.Default("default name")
private const val SEP = "-"
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 fef098139756..76e2bc08701e 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
@@ -94,6 +94,7 @@ class MobileConnectionsRepositoryTest : SysuiTestCase() {
@Before
fun setUp() {
MockitoAnnotations.initMocks(this)
+ whenever(telephonyManager.simOperatorName).thenReturn("")
// Set up so the individual connection repositories
whenever(telephonyManager.createForSubscriptionId(anyInt())).thenAnswer { invocation ->
@@ -141,6 +142,7 @@ class MobileConnectionsRepositoryTest : SysuiTestCase() {
)
carrierMergedFactory =
CarrierMergedConnectionRepository.Factory(
+ telephonyManager,
scope,
wifiRepository,
)
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/FakeMobileIconInteractor.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/FakeMobileIconInteractor.kt
index b9eda717dc1a..b645e667e183 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/FakeMobileIconInteractor.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/FakeMobileIconInteractor.kt
@@ -45,7 +45,7 @@ class FakeMobileIconInteractor(
private val _iconGroup = MutableStateFlow<SignalIcon.MobileIconGroup>(TelephonyIcons.THREE_G)
override val networkTypeIconGroup = _iconGroup
- override val networkName = MutableStateFlow(NetworkNameModel.Derived("demo mode"))
+ override val networkName = MutableStateFlow(NetworkNameModel.IntentDerived("demo mode"))
private val _isEmergencyOnly = MutableStateFlow(false)
override val isEmergencyOnly = _isEmergencyOnly
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconInteractorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconInteractorTest.kt
index f87f651a2480..fa072fc366eb 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconInteractorTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconInteractorTest.kt
@@ -531,7 +531,7 @@ class MobileIconInteractorTest : SysuiTestCase() {
)
yield()
- assertThat(latest).isEqualTo(NetworkNameModel.Derived(testOperatorName))
+ assertThat(latest).isEqualTo(NetworkNameModel.IntentDerived(testOperatorName))
// Default network name, operator name is null, uses the default
connectionRepository.setConnectionInfo(MobileConnectionModel(operatorAlphaShort = null))
@@ -575,6 +575,6 @@ class MobileIconInteractorTest : SysuiTestCase() {
private const val SUB_1_ID = 1
private val DEFAULT_NAME = NetworkNameModel.Default("test default name")
- private val DERIVED_NAME = NetworkNameModel.Derived("test derived name")
+ private val DERIVED_NAME = NetworkNameModel.IntentDerived("test derived name")
}
}