Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 98eb78a6 authored by Caitlin Shkuratov's avatar Caitlin Shkuratov
Browse files

[Status Bar] WifiTrackerLib: Use WifiEntry.title for SSID.

More information in the bug description about why we should be able to
use `title` for SSID.

Bug: 292534484
Test: flag on, switch wifi networks a few times, `adb shell dumpsys
activity service com.android.systemui/.SystemUIService
WifiTrackerLibTableLog` -> verify table has the wifi network names
listed for `ssid`
Test: atest WifiRepositoryViaTrackerLibTest

Change-Id: I10921ebf76e3e60cb6d626353886d56b791890e4
parent 1adda683
Loading
Loading
Loading
Loading
+6 −3
Original line number Original line Diff line number Diff line
@@ -185,9 +185,12 @@ constructor(
                networkId = NETWORK_ID,
                networkId = NETWORK_ID,
                isValidated = this.hasInternetAccess(),
                isValidated = this.hasInternetAccess(),
                level = this.level,
                level = this.level,
                ssid = this.ssid,
                ssid = this.title,
                // TODO(b/292534484): Fetch the real values from [WifiEntry] (#getTitle might be
                // With WifiTrackerLib, [WifiEntry.title] will appropriately fetch the  SSID for
                // appropriate).
                // 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,
                isPasspointAccessPoint = false,
                isOnlineSignUpForPasspointAccessPoint = false,
                isOnlineSignUpForPasspointAccessPoint = false,
                passpointProviderFriendlyName = null,
                passpointProviderFriendlyName = null,
+38 −17
Original line number Original line Diff line number Diff line
@@ -240,7 +240,7 @@ class WifiRepositoryViaTrackerLibTest : SysuiTestCase() {
                mock<WifiEntry>().apply {
                mock<WifiEntry>().apply {
                    whenever(this.isPrimaryNetwork).thenReturn(true)
                    whenever(this.isPrimaryNetwork).thenReturn(true)
                    whenever(this.level).thenReturn(3)
                    whenever(this.level).thenReturn(3)
                    whenever(this.ssid).thenReturn(SSID)
                    whenever(this.title).thenReturn(TITLE)
                }
                }
            whenever(wifiPickerTracker.connectedWifiEntry).thenReturn(wifiEntry)
            whenever(wifiPickerTracker.connectedWifiEntry).thenReturn(wifiEntry)
            getCallback().onWifiEntriesChanged()
            getCallback().onWifiEntriesChanged()
@@ -248,7 +248,28 @@ class WifiRepositoryViaTrackerLibTest : SysuiTestCase() {
            assertThat(latest is WifiNetworkModel.Active).isTrue()
            assertThat(latest is WifiNetworkModel.Active).isTrue()
            val latestActive = latest as WifiNetworkModel.Active
            val latestActive = latest as WifiNetworkModel.Active
            assertThat(latestActive.level).isEqualTo(3)
            assertThat(latestActive.level).isEqualTo(3)
            assertThat(latestActive.ssid).isEqualTo(SSID)
            assertThat(latestActive.ssid).isEqualTo(TITLE)
        }

    @Test
    fun accessPointInfo_alwaysFalse() =
        testScope.runTest {
            val latest by collectLastValue(underTest.wifiNetwork)

            val wifiEntry =
                mock<WifiEntry>().apply {
                    whenever(this.isPrimaryNetwork).thenReturn(true)
                    whenever(this.level).thenReturn(3)
                    whenever(this.title).thenReturn(TITLE)
                }
            whenever(wifiPickerTracker.connectedWifiEntry).thenReturn(wifiEntry)
            getCallback().onWifiEntriesChanged()

            assertThat(latest is WifiNetworkModel.Active).isTrue()
            val latestActive = latest as WifiNetworkModel.Active
            assertThat(latestActive.isPasspointAccessPoint).isFalse()
            assertThat(latestActive.isOnlineSignUpForPasspointAccessPoint).isFalse()
            assertThat(latestActive.passpointProviderFriendlyName).isNull()
        }
        }


    @Test
    @Test
@@ -384,7 +405,7 @@ class WifiRepositoryViaTrackerLibTest : SysuiTestCase() {
                mock<WifiEntry>().apply {
                mock<WifiEntry>().apply {
                    whenever(this.isPrimaryNetwork).thenReturn(true)
                    whenever(this.isPrimaryNetwork).thenReturn(true)
                    whenever(this.level).thenReturn(3)
                    whenever(this.level).thenReturn(3)
                    whenever(this.ssid).thenReturn("AB")
                    whenever(this.title).thenReturn("AB")
                }
                }
            whenever(wifiPickerTracker.connectedWifiEntry).thenReturn(wifiEntry)
            whenever(wifiPickerTracker.connectedWifiEntry).thenReturn(wifiEntry)
            getCallback().onWifiEntriesChanged()
            getCallback().onWifiEntriesChanged()
@@ -399,7 +420,7 @@ class WifiRepositoryViaTrackerLibTest : SysuiTestCase() {
                mock<WifiEntry>().apply {
                mock<WifiEntry>().apply {
                    whenever(this.isPrimaryNetwork).thenReturn(true)
                    whenever(this.isPrimaryNetwork).thenReturn(true)
                    whenever(this.level).thenReturn(4)
                    whenever(this.level).thenReturn(4)
                    whenever(this.ssid).thenReturn("CD")
                    whenever(this.title).thenReturn("CD")
                }
                }
            whenever(wifiPickerTracker.connectedWifiEntry).thenReturn(newWifiEntry)
            whenever(wifiPickerTracker.connectedWifiEntry).thenReturn(newWifiEntry)
            getCallback().onWifiEntriesChanged()
            getCallback().onWifiEntriesChanged()
@@ -432,12 +453,12 @@ class WifiRepositoryViaTrackerLibTest : SysuiTestCase() {
            val wifiEntry =
            val wifiEntry =
                mock<WifiEntry>().apply {
                mock<WifiEntry>().apply {
                    whenever(this.isPrimaryNetwork).thenReturn(true)
                    whenever(this.isPrimaryNetwork).thenReturn(true)
                    whenever(this.ssid).thenReturn(SSID)
                    whenever(this.title).thenReturn(TITLE)
                }
                }
            whenever(wifiPickerTracker.connectedWifiEntry).thenReturn(wifiEntry)
            whenever(wifiPickerTracker.connectedWifiEntry).thenReturn(wifiEntry)
            getCallback().onWifiEntriesChanged()
            getCallback().onWifiEntriesChanged()


            assertThat((latest as WifiNetworkModel.Active).ssid).isEqualTo(SSID)
            assertThat((latest as WifiNetworkModel.Active).ssid).isEqualTo(TITLE)


            // WHEN we lose our current network
            // WHEN we lose our current network
            whenever(wifiPickerTracker.connectedWifiEntry).thenReturn(null)
            whenever(wifiPickerTracker.connectedWifiEntry).thenReturn(null)
@@ -482,7 +503,7 @@ class WifiRepositoryViaTrackerLibTest : SysuiTestCase() {
                mock<WifiEntry>().apply {
                mock<WifiEntry>().apply {
                    whenever(this.isPrimaryNetwork).thenReturn(true)
                    whenever(this.isPrimaryNetwork).thenReturn(true)
                    whenever(this.level).thenReturn(1)
                    whenever(this.level).thenReturn(1)
                    whenever(this.ssid).thenReturn(SSID)
                    whenever(this.title).thenReturn(TITLE)
                }
                }
            whenever(wifiPickerTracker.connectedWifiEntry).thenReturn(wifiEntry)
            whenever(wifiPickerTracker.connectedWifiEntry).thenReturn(wifiEntry)
            getCallback().onWifiEntriesChanged()
            getCallback().onWifiEntriesChanged()
@@ -490,7 +511,7 @@ class WifiRepositoryViaTrackerLibTest : SysuiTestCase() {
            assertThat(latest1 is WifiNetworkModel.Active).isTrue()
            assertThat(latest1 is WifiNetworkModel.Active).isTrue()
            val latest1Active = latest1 as WifiNetworkModel.Active
            val latest1Active = latest1 as WifiNetworkModel.Active
            assertThat(latest1Active.level).isEqualTo(1)
            assertThat(latest1Active.level).isEqualTo(1)
            assertThat(latest1Active.ssid).isEqualTo(SSID)
            assertThat(latest1Active.ssid).isEqualTo(TITLE)


            // WHEN we add a second subscriber after having already emitted a value
            // WHEN we add a second subscriber after having already emitted a value
            val latest2 by collectLastValue(underTest.wifiNetwork)
            val latest2 by collectLastValue(underTest.wifiNetwork)
@@ -499,7 +520,7 @@ class WifiRepositoryViaTrackerLibTest : SysuiTestCase() {
            assertThat(latest2 is WifiNetworkModel.Active).isTrue()
            assertThat(latest2 is WifiNetworkModel.Active).isTrue()
            val latest2Active = latest2 as WifiNetworkModel.Active
            val latest2Active = latest2 as WifiNetworkModel.Active
            assertThat(latest2Active.level).isEqualTo(1)
            assertThat(latest2Active.level).isEqualTo(1)
            assertThat(latest2Active.ssid).isEqualTo(SSID)
            assertThat(latest2Active.ssid).isEqualTo(TITLE)
        }
        }


    @Test
    @Test
@@ -569,14 +590,14 @@ class WifiRepositoryViaTrackerLibTest : SysuiTestCase() {
    */
    */


    @Test
    @Test
    fun isWifiConnectedWithValidSsid_activeNetwork_nullSsid_false() =
    fun isWifiConnectedWithValidSsid_activeNetwork_nullTitle_false() =
        testScope.runTest {
        testScope.runTest {
            collectLastValue(underTest.wifiNetwork)
            collectLastValue(underTest.wifiNetwork)


            val wifiEntry =
            val wifiEntry =
                mock<WifiEntry>().apply {
                mock<WifiEntry>().apply {
                    whenever(this.isPrimaryNetwork).thenReturn(true)
                    whenever(this.isPrimaryNetwork).thenReturn(true)
                    whenever(this.ssid).thenReturn(null)
                    whenever(this.title).thenReturn(null)
                }
                }
            whenever(wifiPickerTracker.connectedWifiEntry).thenReturn(wifiEntry)
            whenever(wifiPickerTracker.connectedWifiEntry).thenReturn(wifiEntry)
            getCallback().onWifiEntriesChanged()
            getCallback().onWifiEntriesChanged()
@@ -586,14 +607,14 @@ class WifiRepositoryViaTrackerLibTest : SysuiTestCase() {
        }
        }


    @Test
    @Test
    fun isWifiConnectedWithValidSsid_activeNetwork_unknownSsid_false() =
    fun isWifiConnectedWithValidSsid_activeNetwork_unknownTitle_false() =
        testScope.runTest {
        testScope.runTest {
            collectLastValue(underTest.wifiNetwork)
            collectLastValue(underTest.wifiNetwork)


            val wifiEntry =
            val wifiEntry =
                mock<WifiEntry>().apply {
                mock<WifiEntry>().apply {
                    whenever(this.isPrimaryNetwork).thenReturn(true)
                    whenever(this.isPrimaryNetwork).thenReturn(true)
                    whenever(this.ssid).thenReturn(UNKNOWN_SSID)
                    whenever(this.title).thenReturn(UNKNOWN_SSID)
                }
                }
            whenever(wifiPickerTracker.connectedWifiEntry).thenReturn(wifiEntry)
            whenever(wifiPickerTracker.connectedWifiEntry).thenReturn(wifiEntry)
            getCallback().onWifiEntriesChanged()
            getCallback().onWifiEntriesChanged()
@@ -603,14 +624,14 @@ class WifiRepositoryViaTrackerLibTest : SysuiTestCase() {
        }
        }


    @Test
    @Test
    fun isWifiConnectedWithValidSsid_activeNetwork_validSsid_true() =
    fun isWifiConnectedWithValidSsid_activeNetwork_validTitle_true() =
        testScope.runTest {
        testScope.runTest {
            collectLastValue(underTest.wifiNetwork)
            collectLastValue(underTest.wifiNetwork)


            val wifiEntry =
            val wifiEntry =
                mock<WifiEntry>().apply {
                mock<WifiEntry>().apply {
                    whenever(this.isPrimaryNetwork).thenReturn(true)
                    whenever(this.isPrimaryNetwork).thenReturn(true)
                    whenever(this.ssid).thenReturn("fakeSsid")
                    whenever(this.title).thenReturn("fakeSsid")
                }
                }
            whenever(wifiPickerTracker.connectedWifiEntry).thenReturn(wifiEntry)
            whenever(wifiPickerTracker.connectedWifiEntry).thenReturn(wifiEntry)
            getCallback().onWifiEntriesChanged()
            getCallback().onWifiEntriesChanged()
@@ -628,7 +649,7 @@ class WifiRepositoryViaTrackerLibTest : SysuiTestCase() {
            val wifiEntry =
            val wifiEntry =
                mock<WifiEntry>().apply {
                mock<WifiEntry>().apply {
                    whenever(this.isPrimaryNetwork).thenReturn(true)
                    whenever(this.isPrimaryNetwork).thenReturn(true)
                    whenever(this.ssid).thenReturn("fakeSsid")
                    whenever(this.title).thenReturn("fakeSsid")
                }
                }
            whenever(wifiPickerTracker.connectedWifiEntry).thenReturn(wifiEntry)
            whenever(wifiPickerTracker.connectedWifiEntry).thenReturn(wifiEntry)
            getCallback().onWifiEntriesChanged()
            getCallback().onWifiEntriesChanged()
@@ -717,6 +738,6 @@ class WifiRepositoryViaTrackerLibTest : SysuiTestCase() {
    }
    }


    private companion object {
    private companion object {
        const val SSID = "AB"
        const val TITLE = "AB"
    }
    }
}
}