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

Commit b3fc7674 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes from topic "caitlinshk-wifi-networkid" into main

* changes:
  [SB][Wifi] Remove unused networkId from WifiNetworkModel classes.
  [SB][Wifi] Remove passpoint-related values from wifi pipeline.
  [SB][Wifi] Save WifiEntry.level to local variable to avoid crashes.
parents 7f460f89 ae8b2ea9
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -185,7 +185,6 @@ class InternetTileDataInteractorTest : SysuiTestCase() {

            val networkModel =
                WifiNetworkModel.Active(
                    networkId = 1,
                    level = 4,
                    ssid = "test ssid",
                )
@@ -221,7 +220,6 @@ class InternetTileDataInteractorTest : SysuiTestCase() {

            val networkModel =
                WifiNetworkModel.Active(
                    networkId = 1,
                    level = 4,
                    ssid = "test ssid",
                    hotspotDeviceType = WifiNetworkModel.HotspotDeviceType.NONE,
@@ -546,7 +544,6 @@ class InternetTileDataInteractorTest : SysuiTestCase() {
    private fun setWifiNetworkWithHotspot(hotspot: WifiNetworkModel.HotspotDeviceType) {
        val networkModel =
            WifiNetworkModel.Active(
                networkId = 1,
                level = 4,
                ssid = "test ssid",
                hotspotDeviceType = hotspot,
+1 −49
Original line number Diff line number Diff line
@@ -93,7 +93,7 @@ class WifiInteractorImplTest : SysuiTestCase() {
    fun ssid_carrierMergedNetwork_outputsNull() =
        testScope.runTest {
            wifiRepository.setWifiNetwork(
                WifiNetworkModel.CarrierMerged(networkId = 1, subscriptionId = 2, level = 1)
                WifiNetworkModel.CarrierMerged(subscriptionId = 2, level = 1)
            )

            var latest: String? = "default"
@@ -105,54 +105,11 @@ class WifiInteractorImplTest : SysuiTestCase() {
            job.cancel()
        }

    @Test
    fun ssid_isPasspointAccessPoint_outputsPasspointName() =
        testScope.runTest {
            wifiRepository.setWifiNetwork(
                WifiNetworkModel.Active(
                    networkId = 1,
                    level = 1,
                    isPasspointAccessPoint = true,
                    passpointProviderFriendlyName = "friendly",
                )
            )

            var latest: String? = null
            val job = underTest.ssid.onEach { latest = it }.launchIn(this)
            runCurrent()

            assertThat(latest).isEqualTo("friendly")

            job.cancel()
        }

    @Test
    fun ssid_isOnlineSignUpForPasspoint_outputsPasspointName() =
        testScope.runTest {
            wifiRepository.setWifiNetwork(
                WifiNetworkModel.Active(
                    networkId = 1,
                    level = 1,
                    isOnlineSignUpForPasspointAccessPoint = true,
                    passpointProviderFriendlyName = "friendly",
                )
            )

            var latest: String? = null
            val job = underTest.ssid.onEach { latest = it }.launchIn(this)
            runCurrent()

            assertThat(latest).isEqualTo("friendly")

            job.cancel()
        }

    @Test
    fun ssid_unknownSsid_outputsNull() =
        testScope.runTest {
            wifiRepository.setWifiNetwork(
                WifiNetworkModel.Active(
                    networkId = 1,
                    level = 1,
                    ssid = WifiManager.UNKNOWN_SSID,
                )
@@ -172,7 +129,6 @@ class WifiInteractorImplTest : SysuiTestCase() {
        testScope.runTest {
            wifiRepository.setWifiNetwork(
                WifiNetworkModel.Active(
                    networkId = 1,
                    level = 1,
                    ssid = "MyAwesomeWifiNetwork",
                )
@@ -234,11 +190,9 @@ class WifiInteractorImplTest : SysuiTestCase() {
        testScope.runTest {
            val wifiNetwork =
                WifiNetworkModel.Active(
                    networkId = 45,
                    isValidated = true,
                    level = 3,
                    ssid = "AB",
                    passpointProviderFriendlyName = "friendly"
                )
            wifiRepository.setWifiNetwork(wifiNetwork)

@@ -346,7 +300,6 @@ class WifiInteractorImplTest : SysuiTestCase() {
            wifiRepository.setWifiNetwork(
                WifiNetworkModel.Active(
                    ssid = "ssid 2",
                    networkId = 1,
                    level = 2,
                )
            )
@@ -367,7 +320,6 @@ class WifiInteractorImplTest : SysuiTestCase() {
            wifiRepository.setWifiNetwork(
                WifiNetworkModel.Active(
                    ssid = "ssid 2",
                    networkId = 1,
                    level = 2,
                )
            )
+4 −13
Original line number Diff line number Diff line
@@ -115,9 +115,7 @@ class WifiViewModelTest : SysuiTestCase() {
            val latestKeyguard by collectLastValue(keyguard.wifiIcon)
            val latestQs by collectLastValue(qs.wifiIcon)

            wifiRepository.setWifiNetwork(
                WifiNetworkModel.Active(NETWORK_ID, isValidated = true, level = 1)
            )
            wifiRepository.setWifiNetwork(WifiNetworkModel.Active(isValidated = true, level = 1))

            assertThat(latestHome).isInstanceOf(WifiIcon.Visible::class.java)
            assertThat(latestHome).isEqualTo(latestKeyguard)
@@ -132,7 +130,6 @@ class WifiViewModelTest : SysuiTestCase() {
            // Even WHEN the network has a valid hotspot type
            wifiRepository.setWifiNetwork(
                WifiNetworkModel.Active(
                    NETWORK_ID,
                    isValidated = true,
                    level = 1,
                    hotspotDeviceType = WifiNetworkModel.HotspotDeviceType.LAPTOP,
@@ -194,9 +191,7 @@ class WifiViewModelTest : SysuiTestCase() {
            whenever(connectivityConstants.shouldShowActivityConfig).thenReturn(true)
            createAndSetViewModel()

            wifiRepository.setWifiNetwork(
                WifiNetworkModel.Active(NETWORK_ID, ssid = null, level = 1)
            )
            wifiRepository.setWifiNetwork(WifiNetworkModel.Active(ssid = null, level = 1))

            val activityIn by collectLastValue(underTest.isActivityInViewVisible)
            val activityOut by collectLastValue(underTest.isActivityOutViewVisible)
@@ -219,9 +214,7 @@ class WifiViewModelTest : SysuiTestCase() {
            whenever(connectivityConstants.shouldShowActivityConfig).thenReturn(true)
            createAndSetViewModel()

            wifiRepository.setWifiNetwork(
                WifiNetworkModel.Active(NETWORK_ID, ssid = null, level = 1)
            )
            wifiRepository.setWifiNetwork(WifiNetworkModel.Active(ssid = null, level = 1))

            val activityIn by collectLastValue(underTest.isActivityInViewVisible)
            val activityOut by collectLastValue(underTest.isActivityOutViewVisible)
@@ -470,8 +463,6 @@ class WifiViewModelTest : SysuiTestCase() {
    }

    companion object {
        private const val NETWORK_ID = 2
        private val ACTIVE_VALID_WIFI_NETWORK =
            WifiNetworkModel.Active(NETWORK_ID, ssid = "AB", level = 1)
        private val ACTIVE_VALID_WIFI_NETWORK = WifiNetworkModel.Active(ssid = "AB", level = 1)
    }
}
+0 −9
Original line number Diff line number Diff line
@@ -101,29 +101,20 @@ constructor(

    private fun FakeWifiEventModel.Wifi.toWifiNetworkModel(): WifiNetworkModel =
        WifiNetworkModel.Active(
            networkId = DEMO_NET_ID,
            isValidated = validated ?: true,
            level = level ?: 0,
            ssid = ssid ?: DEMO_NET_SSID,
            hotspotDeviceType = hotspotDeviceType,

            // These fields below aren't supported in demo mode, since they aren't needed to satisfy
            // the interface.
            isPasspointAccessPoint = false,
            isOnlineSignUpForPasspointAccessPoint = false,
            passpointProviderFriendlyName = null,
        )

    private fun FakeWifiEventModel.CarrierMerged.toCarrierMergedModel(): WifiNetworkModel =
        WifiNetworkModel.CarrierMerged(
            networkId = DEMO_NET_ID,
            subscriptionId = subscriptionId,
            level = level,
            numberOfLevels = numberOfLevels,
        )

    companion object {
        private const val DEMO_NET_ID = 1234
        private const val DEMO_NET_SSID = "Demo SSID"
    }
}
+12 −26
Original line number Diff line number Diff line
@@ -250,7 +250,6 @@ constructor(
            WifiNetworkModel.Invalid(CARRIER_MERGED_INVALID_SUB_ID_REASON)
        } else {
            WifiNetworkModel.CarrierMerged(
                networkId = NETWORK_ID,
                subscriptionId = this.subscriptionId,
                level = this.level,
                // WifiManager APIs to calculate the signal level start from 0, so
@@ -261,7 +260,17 @@ constructor(
    }

    private fun WifiEntry.convertNormalToModel(): WifiNetworkModel {
        if (this.level == WIFI_LEVEL_UNREACHABLE || this.level !in WIFI_LEVEL_MIN..WIFI_LEVEL_MAX) {
        // WifiEntry instance values aren't guaranteed to be stable between method calls because
        // WifiPickerTracker is continuously updating the same object. Save the level in a local
        // variable so that checking the level validity here guarantees that the level will still be
        // valid when we create the `WifiNetworkModel.Active` instance later. Otherwise, the level
        // could be valid here but become invalid later, and `WifiNetworkModel.Active` will throw
        // an exception. See b/362384551.
        val currentLevel = this.level
        if (
            currentLevel == WIFI_LEVEL_UNREACHABLE ||
                currentLevel !in WIFI_LEVEL_MIN..WIFI_LEVEL_MAX
        ) {
            // If our level means the network is unreachable or the level is otherwise invalid, we
            // don't have an active network.
            return WifiNetworkModel.Inactive
@@ -275,19 +284,10 @@ constructor(
            }

        return WifiNetworkModel.Active(
            networkId = NETWORK_ID,
            isValidated = this.hasInternetAccess(),
            level = this.level,
            level = currentLevel,
            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,
        )
    }

@@ -428,19 +428,5 @@ constructor(
        val ACTIVITY_DEFAULT = DataActivityModel(hasActivityIn = false, hasActivityOut = false)

        private const val TAG = "WifiTrackerLibInputLog"

        /**
         * [WifiNetworkModel.Active.networkId] is only used at the repository layer. It's used by
         * [WifiRepositoryImpl], which tracks the ID in order to correctly apply the framework
         * callbacks within the repository.
         *
         * Since this class does not need to manually apply framework callbacks and since the
         * network ID is not used beyond the repository, it's safe to use an invalid ID in this
         * repository.
         *
         * The [WifiNetworkModel.Active.networkId] field should be deleted once we've fully migrated
         * to [WifiRepositoryImpl].
         */
        private const val NETWORK_ID = -1
    }
}
Loading