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

Commit e39c217c authored by Caitlin Shkuratov's avatar Caitlin Shkuratov Committed by Android (Google) Code Review
Browse files

Merge "[SB][Wifi] Create a dedicated thread for WifiTrackerLib." into main

parents ccfdc8b3 30b9141a
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -87,7 +87,7 @@ public class AccessPointControllerImpl implements AccessPointController,
     */
    public void init() {
        if (mWifiPickerTracker == null) {
            mWifiPickerTracker = mWifiPickerTrackerFactory.create(this.getLifecycle(), this);
            mWifiPickerTracker = mWifiPickerTrackerFactory.create(this.getLifecycle(), this, TAG);
        }
    }

+8 −3
Original line number Diff line number Diff line
@@ -23,8 +23,8 @@ import android.os.Handler
import android.os.SimpleClock
import androidx.lifecycle.Lifecycle
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.util.concurrency.ThreadFactory
import com.android.systemui.util.time.SystemClock
import com.android.wifitrackerlib.WifiPickerTracker
import com.android.wifitrackerlib.WifiPickerTracker.WifiPickerTrackerCallback
@@ -46,7 +46,7 @@ constructor(
    private val connectivityManager: ConnectivityManager,
    private val systemClock: SystemClock,
    @Main private val mainHandler: Handler,
    @Background private val workerHandler: Handler,
    private val threadFactory: ThreadFactory,
) {
    private val clock: Clock =
        object : SimpleClock(ZoneOffset.UTC) {
@@ -60,11 +60,13 @@ constructor(
    /**
     * Creates a [WifiPickerTracker] instance.
     *
     * @param name a name to identify the worker thread used for [WifiPickerTracker] operations.
     * @return a new [WifiPickerTracker] or null if [WifiManager] is null.
     */
    fun create(
        lifecycle: Lifecycle,
        listener: WifiPickerTrackerCallback,
        name: String,
    ): WifiPickerTracker? {
        return if (wifiManager == null) {
            null
@@ -75,7 +77,10 @@ constructor(
                wifiManager,
                connectivityManager,
                mainHandler,
                workerHandler,
                // WifiPickerTracker can take tens of seconds to finish operations, so it can't use
                // the default background handler (it would block all other background operations).
                // Use a custom handler instead.
                threadFactory.buildHandlerOnNewThread("WifiPickerTracker-$name"),
                clock,
                MAX_SCAN_AGE_MILLIS,
                SCAN_INTERVAL_MILLIS,
+1 −1
Original line number Diff line number Diff line
@@ -165,7 +165,7 @@ constructor(
                    }

                wifiPickerTracker =
                    wifiPickerTrackerFactory.create(lifecycle, callback).apply {
                    wifiPickerTrackerFactory.create(lifecycle, callback, "WifiRepository").apply {
                        // By default, [WifiPickerTracker] will scan to see all available wifi
                        // networks in the area. Because SysUI only needs to display the
                        // **connected** network, we don't need scans to be running (and in fact,
+2 −2
Original line number Diff line number Diff line
@@ -72,7 +72,7 @@ class AccessPointControllerImplTest : SysuiTestCase() {
    @Before
    fun setUp() {
        MockitoAnnotations.initMocks(this)
        `when`(wifiPickerTrackerFactory.create(any(), any())).thenReturn(wifiPickerTracker)
        `when`(wifiPickerTrackerFactory.create(any(), any(), any())).thenReturn(wifiPickerTracker)

        `when`(wifiPickerTracker.connectedWifiEntry).thenReturn(wifiEntryConnected)
        `when`(wifiPickerTracker.wifiEntries).thenReturn(ArrayList<WifiEntry>().apply {
@@ -165,7 +165,7 @@ class AccessPointControllerImplTest : SysuiTestCase() {

    @Test
    fun testReturnEmptyListWhenNoWifiPickerTracker() {
        `when`(wifiPickerTrackerFactory.create(any(), any())).thenReturn(null)
        `when`(wifiPickerTrackerFactory.create(any(), any(), any())).thenReturn(null)
        val otherController = AccessPointControllerImpl(
                userManager,
                userTracker,
+1 −1
Original line number Diff line number Diff line
@@ -105,7 +105,7 @@ class WifiRepositoryViaTrackerLibTest : SysuiTestCase() {
    fun setUp() {
        featureFlags.set(Flags.INSTANT_TETHER, false)
        featureFlags.set(Flags.WIFI_SECONDARY_NETWORKS, false)
        whenever(wifiPickerTrackerFactory.create(any(), capture(callbackCaptor)))
        whenever(wifiPickerTrackerFactory.create(any(), capture(callbackCaptor), any()))
            .thenReturn(wifiPickerTracker)
    }