diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2020-05-06 03:52:33 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2020-05-06 03:52:33 +0000 |
commit | f0932e0e8d5c81dff2baabd1fe09de154f44689c (patch) | |
tree | 4e2b259bfde129565c6e5443573734ca95223aa1 | |
parent | 4d68b0507ef4bede9fd8af1a93f0637e78b5fe6c (diff) | |
parent | 53d7744eb5d911c34a42316b527fd87db3f7f965 (diff) |
Merge "[WifiTrackerLib] Make scanner run on single thread" into rvc-dev
-rw-r--r-- | libs/WifiTrackerLib/src/com/android/wifitrackerlib/BaseWifiTracker.java | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/BaseWifiTracker.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/BaseWifiTracker.java index 2f5b56eea..18611e242 100644 --- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/BaseWifiTracker.java +++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/BaseWifiTracker.java @@ -86,6 +86,7 @@ public class BaseWifiTracker implements LifecycleObserver { return BaseWifiTracker.sVerboseLogging; } + // Registered on the worker thread private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { @Override @WorkerThread @@ -224,9 +225,9 @@ public class BaseWifiTracker implements LifecycleObserver { mWifiNetworkScoreCache, NetworkScoreManager.SCORE_FILTER_SCAN_RESULTS); if (mWifiManager.getWifiState() == WifiManager.WIFI_STATE_ENABLED) { - mScanner.start(); + mWorkerHandler.post(mScanner::start); } else { - mScanner.stop(); + mWorkerHandler.post(mScanner::stop); } mWorkerHandler.post(this::handleOnStart); } @@ -237,7 +238,7 @@ public class BaseWifiTracker implements LifecycleObserver { @OnLifecycleEvent(Lifecycle.Event.ON_STOP) @MainThread public void onStop() { - mScanner.stop(); + mWorkerHandler.post(mScanner::stop); mContext.unregisterReceiver(mBroadcastReceiver); mConnectivityManager.unregisterNetworkCallback(mNetworkCallback); mNetworkScoreManager.unregisterNetworkScoreCache(NetworkKey.TYPE_WIFI, @@ -335,6 +336,7 @@ public class BaseWifiTracker implements LifecycleObserver { /** * Scanner to handle starting scans every SCAN_INTERVAL_MILLIS */ + @WorkerThread private class Scanner extends Handler { private static final int SCAN_RETRY_TIMES = 3; @@ -344,15 +346,13 @@ public class BaseWifiTracker implements LifecycleObserver { super(looper); } - @AnyThread private void start() { if (isVerboseLoggingEnabled()) { Log.v(mTag, "Scanner start"); } - post(this::postScan); + postScan(); } - @AnyThread private void stop() { if (isVerboseLoggingEnabled()) { Log.v(mTag, "Scanner stop"); @@ -361,7 +361,6 @@ public class BaseWifiTracker implements LifecycleObserver { removeCallbacksAndMessages(null); } - @WorkerThread private void postScan() { if (mWifiManager.startScan()) { mRetry = 0; |