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

Commit 4719d033 authored by Cosmo Hsieh's avatar Cosmo Hsieh Committed by Android (Google) Code Review
Browse files

Merge "Fix WifiTracker keeps sacnning even if onStop() is called." into qt-dev

parents 1d40ffca 9c227d9e
Loading
Loading
Loading
Loading
+34 −16
Original line number Original line Diff line number Diff line
@@ -123,7 +123,8 @@ public class WifiTracker implements LifecycleObserver, OnStart, OnStop, OnDestro
    /**
    /**
     * Synchronization lock for managing concurrency between main and worker threads.
     * Synchronization lock for managing concurrency between main and worker threads.
     *
     *
     * <p>This lock should be held for all modifications to {@link #mInternalAccessPoints}.
     * <p>This lock should be held for all modifications to {@link #mInternalAccessPoints} and
     * {@link #mScanner}.
     */
     */
    private final Object mLock = new Object();
    private final Object mLock = new Object();


@@ -168,6 +169,7 @@ public class WifiTracker implements LifecycleObserver, OnStart, OnStop, OnDestro
    private static final String WIFI_SECURITY_OWE = "OWE";
    private static final String WIFI_SECURITY_OWE = "OWE";
    private static final String WIFI_SECURITY_SUITE_B_192 = "SUITE_B_192";
    private static final String WIFI_SECURITY_SUITE_B_192 = "SUITE_B_192";


    @GuardedBy("mLock")
    @VisibleForTesting
    @VisibleForTesting
    Scanner mScanner;
    Scanner mScanner;


@@ -276,10 +278,12 @@ public class WifiTracker implements LifecycleObserver, OnStart, OnStop, OnDestro
     * <p>Sets {@link #mStaleScanResults} to true.
     * <p>Sets {@link #mStaleScanResults} to true.
     */
     */
    private void pauseScanning() {
    private void pauseScanning() {
        synchronized (mLock) {
            if (mScanner != null) {
            if (mScanner != null) {
                mScanner.pause();
                mScanner.pause();
                mScanner = null;
                mScanner = null;
            }
            }
        }
        mStaleScanResults = true;
        mStaleScanResults = true;
    }
    }


@@ -289,6 +293,7 @@ public class WifiTracker implements LifecycleObserver, OnStart, OnStop, OnDestro
     * <p>The score cache should be registered before this method is invoked.
     * <p>The score cache should be registered before this method is invoked.
     */
     */
    public void resumeScanning() {
    public void resumeScanning() {
        synchronized (mLock) {
            if (mScanner == null) {
            if (mScanner == null) {
                mScanner = new Scanner();
                mScanner = new Scanner();
            }
            }
@@ -297,6 +302,7 @@ public class WifiTracker implements LifecycleObserver, OnStart, OnStop, OnDestro
                mScanner.resume();
                mScanner.resume();
            }
            }
        }
        }
    }


    /**
    /**
     * Start tracking wifi networks and scores.
     * Start tracking wifi networks and scores.
@@ -743,7 +749,6 @@ public class WifiTracker implements LifecycleObserver, OnStart, OnStop, OnDestro
    }
    }


    private void updateNetworkInfo(NetworkInfo networkInfo) {
    private void updateNetworkInfo(NetworkInfo networkInfo) {

        /* Sticky broadcasts can call this when wifi is disabled */
        /* Sticky broadcasts can call this when wifi is disabled */
        if (!isWifiEnabled()) {
        if (!isWifiEnabled()) {
            clearAccessPointsAndConditionallyUpdate();
            clearAccessPointsAndConditionallyUpdate();
@@ -880,19 +885,26 @@ public class WifiTracker implements LifecycleObserver, OnStart, OnStop, OnDestro
     * true.
     * true.
     */
     */
    private void updateWifiState(int state) {
    private void updateWifiState(int state) {
        if (isVerboseLoggingEnabled()) {
            Log.d(TAG, "updateWifiState: " + state);
        }
        if (state == WifiManager.WIFI_STATE_ENABLED) {
        if (state == WifiManager.WIFI_STATE_ENABLED) {
            synchronized (mLock) {
                if (mScanner != null) {
                if (mScanner != null) {
                    // We only need to resume if mScanner isn't null because
                    // We only need to resume if mScanner isn't null because
                    // that means we want to be scanning.
                    // that means we want to be scanning.
                    mScanner.resume();
                    mScanner.resume();
                }
                }
            }
        } else {
        } else {
            clearAccessPointsAndConditionallyUpdate();
            clearAccessPointsAndConditionallyUpdate();
            mLastInfo = null;
            mLastInfo = null;
            mLastNetworkInfo = null;
            mLastNetworkInfo = null;
            synchronized (mLock) {
                if (mScanner != null) {
                if (mScanner != null) {
                    mScanner.pause();
                    mScanner.pause();
                }
                }
            }
            mStaleScanResults = true;
            mStaleScanResults = true;
        }
        }
        mListener.onWifiStateChanged(state);
        mListener.onWifiStateChanged(state);
@@ -919,12 +931,18 @@ public class WifiTracker implements LifecycleObserver, OnStart, OnStop, OnDestro
        private int mRetry = 0;
        private int mRetry = 0;


        void resume() {
        void resume() {
            if (isVerboseLoggingEnabled()) {
                Log.d(TAG, "Scanner resume");
            }
            if (!hasMessages(MSG_SCAN)) {
            if (!hasMessages(MSG_SCAN)) {
                sendEmptyMessage(MSG_SCAN);
                sendEmptyMessage(MSG_SCAN);
            }
            }
        }
        }


        void pause() {
        void pause() {
            if (isVerboseLoggingEnabled()) {
                Log.d(TAG, "Scanner pause");
            }
            mRetry = 0;
            mRetry = 0;
            removeMessages(MSG_SCAN);
            removeMessages(MSG_SCAN);
        }
        }