From d0d9fbe3cbf3d8f45cdeceb3aa53c1c587ddfb5e Mon Sep 17 00:00:00 2001 From: Caitlin Shkuratov Date: Tue, 7 Feb 2023 18:25:53 +0000 Subject: [PATCH] [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 --- .../demo/DemoMobileConnectionsRepository.kt | 8 +++- .../prod/CarrierMergedConnectionRepository.kt | 31 +++++++-------- .../repository/demo/DemoModeWifiDataSource.kt | 3 +- .../repository/demo/DemoWifiRepository.kt | 3 +- .../demo/model/FakeWifiEventModel.kt | 1 + .../DemoMobileConnectionsRepositoryTest.kt | 2 + .../CarrierMergedConnectionRepositoryTest.kt | 38 +++++++++++++++++++ 7 files changed, 64 insertions(+), 22 deletions(-) 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 58cd36e59d525..a778c99a1cffb 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 @@ -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 { 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 f5041d89c1d18..e1a134ec1d7c4 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 @@ -87,8 +87,13 @@ class CarrierMergedConnectionRepository( } override val connectionInfo: StateFlow = - 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 = 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, 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 145c6db6ccbbf..7d2501ca0e79b 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 @@ -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 = 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 08c09d6c8e2a6..a19c3c3e86a6e 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 @@ -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() } 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 4f5074259e27b..f5035cbc02154 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 @@ -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 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 f12d113cfaa8f..d19aa43fb1553 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 @@ -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, ) 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 ea90150b432a5..b60b1b40c5082 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 @@ -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 {