diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2020-05-06 04:22:52 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2020-05-06 04:22:52 +0000 |
commit | 7d2ab812671a10f754c6cf6f7feb86aa15cc6477 (patch) | |
tree | 91983e827825792b0c6ef4fca45dcef0159f894e | |
parent | e22825db8cb79bfa757a498629b1768815c57b0b (diff) | |
parent | 104a76ff70684221cdf05b6a1f0cedd91b468af8 (diff) |
Merge "[WifiTrackerLib] Make scanner run on single thread" into rvc-dev am: f0932e0e8d am: 104a76ff70
Change-Id: Id251ab9a0acc63eaa1dbe0e7aa04533c913a5da9
-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; |