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

Commit c1342633 authored by Caitlin Shkuratov's avatar Caitlin Shkuratov
Browse files

[Status Bar][Wifi] Disable wifi scanning in TrackerLibRepo.

Bug: 292534484
Test: atest WifiRepositoryViaTrackerLibTest
Change-Id: Ifea61ce54fbc92b2b990b6cd86ab712aa5693f91
parent d6581965
Loading
Loading
Loading
Loading
+12 −10
Original line number Original line Diff line number Diff line
@@ -136,19 +136,21 @@ constructor(
                        }
                        }
                    }
                    }


                // TODO(b/292591403): [WifiPickerTrackerFactory] currently scans to see all
                wifiPickerTracker =
                // available wifi networks every 10s. Because SysUI only needs to display the
                    wifiPickerTrackerFactory.create(lifecycle, callback).apply {
                // **connected** network, we don't need scans to be running. We should disable these
                        // By default, [WifiPickerTracker] will scan to see all available wifi
                // scans (ideal) or at least run them very infrequently.
                        // networks in the area. Because SysUI only needs to display the
                wifiPickerTracker = wifiPickerTrackerFactory.create(lifecycle, callback)
                        // **connected** network, we don't need scans to be running (and in fact,
                        // running scans is costly and should be avoided whenever possible).
                        this?.disableScanning()
                    }
                // The lifecycle must be STARTED in order for the callback to receive events.
                // The lifecycle must be STARTED in order for the callback to receive events.
                mainExecutor.execute { lifecycle.currentState = Lifecycle.State.STARTED }
                mainExecutor.execute { lifecycle.currentState = Lifecycle.State.STARTED }
                awaitClose {
                awaitClose {
                    mainExecutor.execute { lifecycle.currentState = Lifecycle.State.CREATED }
                    mainExecutor.execute { lifecycle.currentState = Lifecycle.State.CREATED }
                }
                }
            }
            }
            // TODO(b/292534484): Update to Eagerly once scans are disabled. (Here and other flows)
            .stateIn(scope, SharingStarted.Eagerly, current)
            .stateIn(scope, SharingStarted.WhileSubscribed(), current)
    }
    }


    override val isWifiEnabled: StateFlow<Boolean> =
    override val isWifiEnabled: StateFlow<Boolean> =
@@ -161,7 +163,7 @@ constructor(
                columnName = COL_NAME_IS_ENABLED,
                columnName = COL_NAME_IS_ENABLED,
                initialValue = false,
                initialValue = false,
            )
            )
            .stateIn(scope, SharingStarted.WhileSubscribed(), false)
            .stateIn(scope, SharingStarted.Eagerly, false)


    override val wifiNetwork: StateFlow<WifiNetworkModel> =
    override val wifiNetwork: StateFlow<WifiNetworkModel> =
        wifiPickerTrackerInfo
        wifiPickerTrackerInfo
@@ -172,7 +174,7 @@ constructor(
                columnPrefix = "",
                columnPrefix = "",
                initialValue = WIFI_NETWORK_DEFAULT,
                initialValue = WIFI_NETWORK_DEFAULT,
            )
            )
            .stateIn(scope, SharingStarted.WhileSubscribed(), WIFI_NETWORK_DEFAULT)
            .stateIn(scope, SharingStarted.Eagerly, WIFI_NETWORK_DEFAULT)


    /** Converts WifiTrackerLib's [WifiEntry] into our internal model. */
    /** Converts WifiTrackerLib's [WifiEntry] into our internal model. */
    private fun WifiEntry.toWifiNetworkModel(): WifiNetworkModel {
    private fun WifiEntry.toWifiNetworkModel(): WifiNetworkModel {
@@ -236,7 +238,7 @@ constructor(
                columnName = COL_NAME_IS_DEFAULT,
                columnName = COL_NAME_IS_DEFAULT,
                initialValue = false,
                initialValue = false,
            )
            )
            .stateIn(scope, SharingStarted.WhileSubscribed(), false)
            .stateIn(scope, SharingStarted.Eagerly, false)


    override val wifiActivity: StateFlow<DataActivityModel> =
    override val wifiActivity: StateFlow<DataActivityModel> =
        WifiRepositoryHelper.createActivityFlow(
        WifiRepositoryHelper.createActivityFlow(
+9 −0
Original line number Original line Diff line number Diff line
@@ -102,6 +102,15 @@ class WifiRepositoryViaTrackerLibTest : SysuiTestCase() {
            .thenReturn(wifiPickerTracker)
            .thenReturn(wifiPickerTracker)
    }
    }


    @Test
    fun wifiPickerTrackerCreation_scansDisabled() =
        testScope.runTest {
            collectLastValue(underTest.wifiNetwork)
            testScope.runCurrent()

            verify(wifiPickerTracker).disableScanning()
        }

    @Test
    @Test
    fun isWifiEnabled_enabled_true() =
    fun isWifiEnabled_enabled_true() =
        testScope.runTest {
        testScope.runTest {