diff options
4 files changed, 64 insertions, 71 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/data/repository/WifiRepository.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/data/repository/WifiRepository.kt index b11b4727c3c3..b29d46174bd1 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/data/repository/WifiRepository.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/data/repository/WifiRepository.kt @@ -49,6 +49,9 @@ interface WifiRepository { const val COL_NAME_IS_ENABLED = "isEnabled" /** Column name to use for [isWifiDefault] for table logging. */ const val COL_NAME_IS_DEFAULT = "isDefault" + + const val CARRIER_MERGED_INVALID_SUB_ID_REASON = + "Wifi network was carrier merged but had invalid sub ID" } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/data/repository/prod/WifiRepositoryImpl.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/data/repository/prod/WifiRepositoryImpl.kt index 946c571998ac..afd15765d163 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/data/repository/prod/WifiRepositoryImpl.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/data/repository/prod/WifiRepositoryImpl.kt @@ -42,6 +42,7 @@ import com.android.systemui.statusbar.pipeline.shared.data.model.DataActivityMod import com.android.systemui.statusbar.pipeline.shared.data.repository.ConnectivityRepository import com.android.systemui.statusbar.pipeline.shared.data.repository.ConnectivityRepositoryImpl.Companion.getMainOrUnderlyingWifiInfo import com.android.systemui.statusbar.pipeline.wifi.data.repository.WifiRepository +import com.android.systemui.statusbar.pipeline.wifi.data.repository.WifiRepository.Companion.CARRIER_MERGED_INVALID_SUB_ID_REASON import com.android.systemui.statusbar.pipeline.wifi.data.repository.WifiRepository.Companion.COL_NAME_IS_DEFAULT import com.android.systemui.statusbar.pipeline.wifi.data.repository.WifiRepository.Companion.COL_NAME_IS_ENABLED import com.android.systemui.statusbar.pipeline.wifi.data.repository.WifiRepositoryDagger @@ -277,9 +278,6 @@ constructor( .addTransportType(TRANSPORT_WIFI) .addTransportType(TRANSPORT_CELLULAR) .build() - - private const val CARRIER_MERGED_INVALID_SUB_ID_REASON = - "Wifi network was carrier merged but had invalid sub ID" } @SysUISingleton diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/data/repository/prod/WifiRepositoryViaTrackerLib.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/data/repository/prod/WifiRepositoryViaTrackerLib.kt index 43f8bc6ef3f8..7cf9a7d5a481 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/data/repository/prod/WifiRepositoryViaTrackerLib.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/data/repository/prod/WifiRepositoryViaTrackerLib.kt @@ -17,6 +17,7 @@ package com.android.systemui.statusbar.pipeline.wifi.data.repository.prod import android.net.wifi.WifiManager +import android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID import androidx.lifecycle.Lifecycle import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.LifecycleRegistry @@ -33,6 +34,7 @@ import com.android.systemui.statusbar.connectivity.WifiPickerTrackerFactory import com.android.systemui.statusbar.pipeline.dagger.WifiTrackerLibInputLog import com.android.systemui.statusbar.pipeline.dagger.WifiTrackerLibTableLog import com.android.systemui.statusbar.pipeline.shared.data.model.DataActivityModel +import com.android.systemui.statusbar.pipeline.wifi.data.repository.WifiRepository.Companion.CARRIER_MERGED_INVALID_SUB_ID_REASON import com.android.systemui.statusbar.pipeline.wifi.data.repository.WifiRepository.Companion.COL_NAME_IS_DEFAULT import com.android.systemui.statusbar.pipeline.wifi.data.repository.WifiRepository.Companion.COL_NAME_IS_ENABLED import com.android.systemui.statusbar.pipeline.wifi.data.repository.WifiRepositoryViaTrackerLibDagger @@ -178,41 +180,52 @@ constructor( return WIFI_NETWORK_DEFAULT } return if (this is MergedCarrierEntry) { + this.convertCarrierMergedToModel() + } else { + this.convertNormalToModel() + } + } + + private fun MergedCarrierEntry.convertCarrierMergedToModel(): WifiNetworkModel { + return if (this.subscriptionId == INVALID_SUBSCRIPTION_ID) { + WifiNetworkModel.Invalid(CARRIER_MERGED_INVALID_SUB_ID_REASON) + } else { WifiNetworkModel.CarrierMerged( networkId = NETWORK_ID, - // TODO(b/292534484): Fetch the real subscription ID from [MergedCarrierEntry]. - subscriptionId = TEMP_SUB_ID, + subscriptionId = this.subscriptionId, level = this.level, // WifiManager APIs to calculate the signal level start from 0, so // maxSignalLevel + 1 represents the total level buckets count. numberOfLevels = wifiManager.maxSignalLevel + 1, ) - } else { - val hotspotDeviceType = - if (isInstantTetherEnabled && this is HotspotNetworkEntry) { - this.deviceType.toHotspotDeviceType() - } else { - WifiNetworkModel.HotspotDeviceType.NONE - } - - WifiNetworkModel.Active( - networkId = NETWORK_ID, - isValidated = this.hasInternetAccess(), - level = this.level, - ssid = this.title, - hotspotDeviceType = hotspotDeviceType, - // With WifiTrackerLib, [WifiEntry.title] will appropriately fetch the SSID for - // typical wifi networks *and* passpoint/OSU APs. So, the AP-specific values can - // always be false/null in this repository. - // TODO(b/292534484): Remove these fields from the wifi network model once this - // repository is fully enabled. - isPasspointAccessPoint = false, - isOnlineSignUpForPasspointAccessPoint = false, - passpointProviderFriendlyName = null, - ) } } + private fun WifiEntry.convertNormalToModel(): WifiNetworkModel { + val hotspotDeviceType = + if (isInstantTetherEnabled && this is HotspotNetworkEntry) { + this.deviceType.toHotspotDeviceType() + } else { + WifiNetworkModel.HotspotDeviceType.NONE + } + + return WifiNetworkModel.Active( + networkId = NETWORK_ID, + isValidated = this.hasInternetAccess(), + level = this.level, + ssid = this.title, + hotspotDeviceType = hotspotDeviceType, + // With WifiTrackerLib, [WifiEntry.title] will appropriately fetch the SSID for + // typical wifi networks *and* passpoint/OSU APs. So, the AP-specific values can + // always be false/null in this repository. + // TODO(b/292534484): Remove these fields from the wifi network model once this + // repository is fully enabled. + isPasspointAccessPoint = false, + isOnlineSignUpForPasspointAccessPoint = false, + passpointProviderFriendlyName = null, + ) + } + override val isWifiDefault: StateFlow<Boolean> = wifiPickerTrackerInfo .map { it.isDefault } @@ -310,13 +323,5 @@ constructor( * to [WifiRepositoryViaTrackerLib]. */ private const val NETWORK_ID = -1 - - /** - * A temporary subscription ID until WifiTrackerLib exposes a method to fetch the - * subscription ID. - * - * Use -2 because [SubscriptionManager.INVALID_SUBSCRIPTION_ID] is -1. - */ - private const val TEMP_SUB_ID = -2 } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/wifi/data/repository/prod/WifiRepositoryViaTrackerLibTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/wifi/data/repository/prod/WifiRepositoryViaTrackerLibTest.kt index 7a78ae368fa9..6d2954b0e856 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/wifi/data/repository/prod/WifiRepositoryViaTrackerLibTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/wifi/data/repository/prod/WifiRepositoryViaTrackerLibTest.kt @@ -19,6 +19,7 @@ package com.android.systemui.statusbar.pipeline.wifi.data.repository.prod import android.net.wifi.WifiManager import android.net.wifi.WifiManager.UNKNOWN_SSID import android.net.wifi.sharedconnectivity.app.NetworkProviderInfo +import android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID import android.testing.TestableLooper import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase @@ -431,6 +432,7 @@ class WifiRepositoryViaTrackerLibTest : SysuiTestCase() { mock<MergedCarrierEntry>().apply { whenever(this.isPrimaryNetwork).thenReturn(true) whenever(this.level).thenReturn(3) + whenever(this.subscriptionId).thenReturn(567) } whenever(wifiPickerTracker.connectedWifiEntry).thenReturn(wifiEntry) getCallback().onWifiEntriesChanged() @@ -438,7 +440,7 @@ class WifiRepositoryViaTrackerLibTest : SysuiTestCase() { assertThat(latest is WifiNetworkModel.CarrierMerged).isTrue() val latestMerged = latest as WifiNetworkModel.CarrierMerged assertThat(latestMerged.level).isEqualTo(3) - // numberOfLevels = maxSignalLevel + 1 + assertThat(latestMerged.subscriptionId).isEqualTo(567) } @Test @@ -461,30 +463,23 @@ class WifiRepositoryViaTrackerLibTest : SysuiTestCase() { assertThat(latestMerged.numberOfLevels).isEqualTo(6) } - /* TODO(b/292534484): Re-enable this test once WifiTrackerLib gives us the subscription ID. @Test fun wifiNetwork_carrierMergedButInvalidSubId_flowHasInvalid() = testScope.runTest { val latest by collectLastValue(underTest.wifiNetwork) - val wifiInfo = - mock<WifiInfo>().apply { - whenever(this.isPrimary).thenReturn(true) - whenever(this.isCarrierMerged).thenReturn(true) + val wifiEntry = + mock<MergedCarrierEntry>().apply { + whenever(this.isPrimaryNetwork).thenReturn(true) whenever(this.subscriptionId).thenReturn(INVALID_SUBSCRIPTION_ID) } + whenever(wifiPickerTracker.connectedWifiEntry).thenReturn(wifiEntry) - getNetworkCallback() - .onCapabilitiesChanged( - NETWORK, - createWifiNetworkCapabilities(wifiInfo), - ) + getCallback().onWifiEntriesChanged() assertThat(latest).isInstanceOf(WifiNetworkModel.Invalid::class.java) } - */ - @Test fun wifiNetwork_notValidated_networkNotValidated() = testScope.runTest { @@ -714,30 +709,22 @@ class WifiRepositoryViaTrackerLibTest : SysuiTestCase() { assertThat(underTest.isWifiConnectedWithValidSsid()).isFalse() } - /* TODO(b/292534484): Re-enable this test once WifiTrackerLib gives us the subscription ID. - @Test - fun isWifiConnectedWithValidSsid_invalidNetwork_false() = - testScope.runTest { - collectLastValue(underTest.wifiNetwork) - - val wifiInfo = - mock<WifiInfo>().apply { - whenever(this.isPrimary).thenReturn(true) - whenever(this.isCarrierMerged).thenReturn(true) - whenever(this.subscriptionId).thenReturn(INVALID_SUBSCRIPTION_ID) - } - - getNetworkCallback() - .onCapabilitiesChanged( - NETWORK, - createWifiNetworkCapabilities(wifiInfo), - ) - testScope.runCurrent() + @Test + fun isWifiConnectedWithValidSsid_invalidNetwork_false() = + testScope.runTest { + collectLastValue(underTest.wifiNetwork) - assertThat(underTest.isWifiConnectedWithValidSsid()).isFalse() - } + val wifiEntry = + mock<MergedCarrierEntry>().apply { + whenever(this.isPrimaryNetwork).thenReturn(true) + whenever(this.subscriptionId).thenReturn(INVALID_SUBSCRIPTION_ID) + } + whenever(wifiPickerTracker.connectedWifiEntry).thenReturn(wifiEntry) + getCallback().onWifiEntriesChanged() + testScope.runCurrent() - */ + assertThat(underTest.isWifiConnectedWithValidSsid()).isFalse() + } @Test fun isWifiConnectedWithValidSsid_activeNetwork_nullTitle_false() = |