summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2020-05-06 04:09:48 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2020-05-06 04:09:48 +0000
commit104a76ff70684221cdf05b6a1f0cedd91b468af8 (patch)
treeeaaeace9c4f97bd82a31303d90c8234b873c1a81 /libs
parent74eb8daa7af2c47fed5b6c90ee407fe652158943 (diff)
parentf0932e0e8d5c81dff2baabd1fe09de154f44689c (diff)
Merge "[WifiTrackerLib] Make scanner run on single thread" into rvc-dev am: f0932e0e8d
Change-Id: I8a59250712fc6d6d565f1154b6969eb4398ee97f
Diffstat (limited to 'libs')
-rw-r--r--libs/WifiTrackerLib/src/com/android/wifitrackerlib/BaseWifiTracker.java13
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;