[SB Refactor] Supprt activity in/out for carrier merged connections.
Bug: 238425913 Bug: 264684296 Test: manual: `adb shell am broadcast -a com.android.systemui.demo -e command network -e wifi carriermerged -e level 2 -e activity out` -> shows carrier merged connection with activity arrows Test: atest CarrierMergedConnectionRepositoryTest Change-Id: If3e00d82c0278bba68da08f972da002729f1a5a3
This commit is contained in:
@@ -258,6 +258,9 @@ 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
|
||||
@@ -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 {
|
||||
|
||||
@@ -87,8 +87,13 @@ 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.
|
||||
@@ -112,32 +117,22 @@ 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,
|
||||
resolvedNetworkType = ResolvedNetworkType.CarrierMergedNetworkType,
|
||||
// Carrier merged is never roaming
|
||||
isRoaming = false,
|
||||
|
||||
@@ -69,8 +69,9 @@ 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 =
|
||||
|
||||
@@ -87,8 +87,7 @@ constructor(
|
||||
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()
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ sealed interface FakeWifiEventModel {
|
||||
val subscriptionId: Int,
|
||||
val level: Int,
|
||||
val numberOfLevels: Int,
|
||||
@Annotation.DataActivityType val activity: Int,
|
||||
) : FakeWifiEventModel
|
||||
|
||||
object WifiDisabled : FakeWifiEventModel
|
||||
|
||||
@@ -594,9 +594,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,
|
||||
)
|
||||
|
||||
@@ -134,6 +134,44 @@ class CarrierMergedConnectionRepositoryTest : SysuiTestCase() {
|
||||
job.cancel()
|
||||
}
|
||||
|
||||
@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 {
|
||||
|
||||
Reference in New Issue
Block a user