summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Caitlin Shkuratov <caitlinshk@google.com> 2023-04-07 14:08:59 +0000
committer Caitlin Shkuratov <caitlinshk@google.com> 2023-04-07 14:45:01 +0000
commit321dd53f3655e240d15df6f575c1607e77c7b4e6 (patch)
treebf0e265078e69d2051c0d31b6775f1292fc77763
parentc4fa3f8f521124bb36e1925a4473c9d69c69f028 (diff)
[Status bar] Expose a #isWifiConnected API on WifiRepository.
Bug: 275317488 Test: atest WifiRepositoryImplTest WifiInteractorImplTest WifiNetworkModelTest Change-Id: Ib0a75bcb3b5fc5d6935f58ae681bd436e7da2aa1
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/data/repository/WifiRepository.kt9
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/domain/interactor/WifiInteractor.kt3
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/shared/model/WifiNetworkModel.kt6
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/wifi/data/repository/prod/WifiRepositoryImplTest.kt144
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/wifi/shared/model/WifiNetworkModelTest.kt37
5 files changed, 197 insertions, 2 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 08c14e743bb6..f800cf496ca9 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
@@ -33,6 +33,15 @@ interface WifiRepository {
/** Observable for the current wifi network activity. */
val wifiActivity: StateFlow<DataActivityModel>
+
+ /**
+ * Returns true if the device is currently connected to a wifi network with a valid SSID and
+ * false otherwise.
+ */
+ fun isWifiConnectedWithValidSsid(): Boolean {
+ val currentNetwork = wifiNetwork.value
+ return currentNetwork is WifiNetworkModel.Active && currentNetwork.hasValidSsid()
+ }
}
/**
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/domain/interactor/WifiInteractor.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/domain/interactor/WifiInteractor.kt
index 96ab074c6e56..1a41abf031bf 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/domain/interactor/WifiInteractor.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/domain/interactor/WifiInteractor.kt
@@ -16,7 +16,6 @@
package com.android.systemui.statusbar.pipeline.wifi.domain.interactor
-import android.net.wifi.WifiManager
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.statusbar.pipeline.shared.data.model.ConnectivitySlot
import com.android.systemui.statusbar.pipeline.shared.data.model.DataActivityModel
@@ -76,7 +75,7 @@ constructor(
when {
info.isPasspointAccessPoint || info.isOnlineSignUpForPasspointAccessPoint ->
info.passpointProviderFriendlyName
- info.ssid != WifiManager.UNKNOWN_SSID -> info.ssid
+ info.hasValidSsid() -> info.ssid
else -> null
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/shared/model/WifiNetworkModel.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/shared/model/WifiNetworkModel.kt
index 0923d7848d8c..4b33c88cea30 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/shared/model/WifiNetworkModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/shared/model/WifiNetworkModel.kt
@@ -16,6 +16,7 @@
package com.android.systemui.statusbar.pipeline.wifi.shared.model
+import android.net.wifi.WifiManager.UNKNOWN_SSID
import android.telephony.SubscriptionManager
import androidx.annotation.VisibleForTesting
import com.android.systemui.log.table.Diffable
@@ -223,6 +224,11 @@ sealed class WifiNetworkModel : Diffable<WifiNetworkModel> {
}
}
+ /** Returns true if this network has a valid SSID and false otherwise. */
+ fun hasValidSsid(): Boolean {
+ return ssid != null && ssid != UNKNOWN_SSID
+ }
+
override fun logDiffs(prevVal: WifiNetworkModel, row: TableRowLogger) {
if (prevVal !is Active) {
logFull(row)
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/wifi/data/repository/prod/WifiRepositoryImplTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/wifi/data/repository/prod/WifiRepositoryImplTest.kt
index aeb52e0cd834..d30e0246c2dd 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/wifi/data/repository/prod/WifiRepositoryImplTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/wifi/data/repository/prod/WifiRepositoryImplTest.kt
@@ -29,6 +29,7 @@ import android.net.vcn.VcnTransportInfo
import android.net.wifi.WifiInfo
import android.net.wifi.WifiManager
import android.net.wifi.WifiManager.TrafficStateCallback
+import android.net.wifi.WifiManager.UNKNOWN_SSID
import android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
@@ -1089,6 +1090,149 @@ class WifiRepositoryImplTest : SysuiTestCase() {
}
@Test
+ fun isWifiConnectedWithValidSsid_inactiveNetwork_false() =
+ testScope.runTest {
+ val job = underTest.wifiNetwork.launchIn(this)
+
+ val wifiInfo =
+ mock<WifiInfo>().apply {
+ whenever(this.ssid).thenReturn(SSID)
+ // A non-primary network is inactive
+ whenever(this.isPrimary).thenReturn(false)
+ }
+
+ getNetworkCallback()
+ .onCapabilitiesChanged(NETWORK, createWifiNetworkCapabilities(wifiInfo))
+
+ assertThat(underTest.isWifiConnectedWithValidSsid()).isFalse()
+
+ job.cancel()
+ }
+
+ @Test
+ fun isWifiConnectedWithValidSsid_carrierMergedNetwork_false() =
+ testScope.runTest {
+ val job = underTest.wifiNetwork.launchIn(this)
+
+ val wifiInfo =
+ mock<WifiInfo>().apply {
+ whenever(this.isPrimary).thenReturn(true)
+ whenever(this.isCarrierMerged).thenReturn(true)
+ }
+
+ getNetworkCallback()
+ .onCapabilitiesChanged(NETWORK, createWifiNetworkCapabilities(wifiInfo))
+
+ assertThat(underTest.isWifiConnectedWithValidSsid()).isFalse()
+
+ job.cancel()
+ }
+
+ @Test
+ fun isWifiConnectedWithValidSsid_invalidNetwork_false() =
+ testScope.runTest {
+ val job = underTest.wifiNetwork.launchIn(this)
+
+ 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),
+ )
+
+ assertThat(underTest.isWifiConnectedWithValidSsid()).isFalse()
+
+ job.cancel()
+ }
+
+ @Test
+ fun isWifiConnectedWithValidSsid_activeNetwork_nullSsid_false() =
+ testScope.runTest {
+ val job = underTest.wifiNetwork.launchIn(this)
+
+ val wifiInfo =
+ mock<WifiInfo>().apply {
+ whenever(this.isPrimary).thenReturn(true)
+ whenever(this.ssid).thenReturn(null)
+ }
+
+ getNetworkCallback()
+ .onCapabilitiesChanged(NETWORK, createWifiNetworkCapabilities(wifiInfo))
+
+ assertThat(underTest.isWifiConnectedWithValidSsid()).isFalse()
+
+ job.cancel()
+ }
+
+ @Test
+ fun isWifiConnectedWithValidSsid_activeNetwork_unknownSsid_false() =
+ testScope.runTest {
+ val job = underTest.wifiNetwork.launchIn(this)
+
+ val wifiInfo =
+ mock<WifiInfo>().apply {
+ whenever(this.isPrimary).thenReturn(true)
+ whenever(this.ssid).thenReturn(UNKNOWN_SSID)
+ }
+
+ getNetworkCallback()
+ .onCapabilitiesChanged(NETWORK, createWifiNetworkCapabilities(wifiInfo))
+
+ assertThat(underTest.isWifiConnectedWithValidSsid()).isFalse()
+
+ job.cancel()
+ }
+
+ @Test
+ fun isWifiConnectedWithValidSsid_activeNetwork_validSsid_true() =
+ testScope.runTest {
+ val job = underTest.wifiNetwork.launchIn(this)
+
+ val wifiInfo =
+ mock<WifiInfo>().apply {
+ whenever(this.isPrimary).thenReturn(true)
+ whenever(this.ssid).thenReturn("FakeSsid")
+ }
+
+ getNetworkCallback()
+ .onCapabilitiesChanged(NETWORK, createWifiNetworkCapabilities(wifiInfo))
+
+ assertThat(underTest.isWifiConnectedWithValidSsid()).isTrue()
+
+ job.cancel()
+ }
+
+ @Test
+ fun isWifiConnectedWithValidSsid_activeToInactive_trueToFalse() =
+ testScope.runTest {
+ val job = underTest.wifiNetwork.launchIn(this)
+
+ // Start with active
+ val wifiInfo =
+ mock<WifiInfo>().apply {
+ whenever(this.isPrimary).thenReturn(true)
+ whenever(this.ssid).thenReturn("FakeSsid")
+ }
+ getNetworkCallback()
+ .onCapabilitiesChanged(NETWORK, createWifiNetworkCapabilities(wifiInfo))
+ assertThat(underTest.isWifiConnectedWithValidSsid()).isTrue()
+
+ // WHEN the network is lost
+ getNetworkCallback().onLost(NETWORK)
+
+ // THEN the isWifiConnected updates
+ assertThat(underTest.isWifiConnectedWithValidSsid()).isFalse()
+
+ job.cancel()
+ }
+
+ @Test
fun wifiActivity_callbackGivesNone_activityFlowHasNone() =
testScope.runTest {
var latest: DataActivityModel? = null
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/wifi/shared/model/WifiNetworkModelTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/wifi/shared/model/WifiNetworkModelTest.kt
index ab4e93ceee84..4e0c309512e8 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/wifi/shared/model/WifiNetworkModelTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/wifi/shared/model/WifiNetworkModelTest.kt
@@ -16,6 +16,7 @@
package com.android.systemui.statusbar.pipeline.wifi.shared.model
+import android.net.wifi.WifiManager.UNKNOWN_SSID
import android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
@@ -50,6 +51,42 @@ class WifiNetworkModelTest : SysuiTestCase() {
WifiNetworkModel.CarrierMerged(NETWORK_ID, INVALID_SUBSCRIPTION_ID, 1)
}
+ @Test
+ fun active_hasValidSsid_nullSsid_false() {
+ val network =
+ WifiNetworkModel.Active(
+ NETWORK_ID,
+ level = MAX_VALID_LEVEL,
+ ssid = null,
+ )
+
+ assertThat(network.hasValidSsid()).isFalse()
+ }
+
+ @Test
+ fun active_hasValidSsid_unknownSsid_false() {
+ val network =
+ WifiNetworkModel.Active(
+ NETWORK_ID,
+ level = MAX_VALID_LEVEL,
+ ssid = UNKNOWN_SSID,
+ )
+
+ assertThat(network.hasValidSsid()).isFalse()
+ }
+
+ @Test
+ fun active_hasValidSsid_validSsid_true() {
+ val network =
+ WifiNetworkModel.Active(
+ NETWORK_ID,
+ level = MAX_VALID_LEVEL,
+ ssid = "FakeSsid",
+ )
+
+ assertThat(network.hasValidSsid()).isTrue()
+ }
+
// Non-exhaustive logDiffs test -- just want to make sure the logging logic isn't totally broken
@Test