Merge "Made AccessPoint's scan result list thread safe" into qt-dev
am: 8e13ea659e
Change-Id: I88d3d604a5679972b9e6652ebd185fe3c11544b9
This commit is contained in:
@@ -55,6 +55,7 @@ import android.util.ArraySet;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
|
|
||||||
|
import androidx.annotation.GuardedBy;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import com.android.internal.annotations.VisibleForTesting;
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
@@ -108,6 +109,14 @@ public class AccessPoint implements Comparable<AccessPoint> {
|
|||||||
/** The key which identifies this AccessPoint grouping. */
|
/** The key which identifies this AccessPoint grouping. */
|
||||||
private String mKey;
|
private String mKey;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Synchronization lock for managing concurrency between main and worker threads.
|
||||||
|
*
|
||||||
|
* <p>This lock should be held for all modifications to {@link #mScanResults} and
|
||||||
|
* {@link #mExtraScanResults}.
|
||||||
|
*/
|
||||||
|
private final Object mLock = new Object();
|
||||||
|
|
||||||
@IntDef({Speed.NONE, Speed.SLOW, Speed.MODERATE, Speed.FAST, Speed.VERY_FAST})
|
@IntDef({Speed.NONE, Speed.SLOW, Speed.MODERATE, Speed.FAST, Speed.VERY_FAST})
|
||||||
@Retention(RetentionPolicy.SOURCE)
|
@Retention(RetentionPolicy.SOURCE)
|
||||||
public @interface Speed {
|
public @interface Speed {
|
||||||
@@ -134,12 +143,14 @@ public class AccessPoint implements Comparable<AccessPoint> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** The underlying set of scan results comprising this AccessPoint. */
|
/** The underlying set of scan results comprising this AccessPoint. */
|
||||||
|
@GuardedBy("mLock")
|
||||||
private final ArraySet<ScanResult> mScanResults = new ArraySet<>();
|
private final ArraySet<ScanResult> mScanResults = new ArraySet<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extra set of unused scan results corresponding to this AccessPoint for verbose logging
|
* Extra set of unused scan results corresponding to this AccessPoint for verbose logging
|
||||||
* purposes, such as a set of Passpoint roaming scan results when home scans are available.
|
* purposes, such as a set of Passpoint roaming scan results when home scans are available.
|
||||||
*/
|
*/
|
||||||
|
@GuardedBy("mLock")
|
||||||
private final ArraySet<ScanResult> mExtraScanResults = new ArraySet<>();
|
private final ArraySet<ScanResult> mExtraScanResults = new ArraySet<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -489,9 +500,11 @@ public class AccessPoint implements Comparable<AccessPoint> {
|
|||||||
|
|
||||||
if (isVerboseLoggingEnabled()) {
|
if (isVerboseLoggingEnabled()) {
|
||||||
builder.append(",rssi=").append(mRssi);
|
builder.append(",rssi=").append(mRssi);
|
||||||
|
synchronized (mLock) {
|
||||||
builder.append(",scan cache size=").append(mScanResults.size()
|
builder.append(",scan cache size=").append(mScanResults.size()
|
||||||
+ mExtraScanResults.size());
|
+ mExtraScanResults.size());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return builder.append(')').toString();
|
return builder.append(')').toString();
|
||||||
}
|
}
|
||||||
@@ -532,6 +545,7 @@ public class AccessPoint implements Comparable<AccessPoint> {
|
|||||||
*/
|
*/
|
||||||
private boolean updateScores(WifiNetworkScoreCache scoreCache, long maxScoreCacheAgeMillis) {
|
private boolean updateScores(WifiNetworkScoreCache scoreCache, long maxScoreCacheAgeMillis) {
|
||||||
long nowMillis = SystemClock.elapsedRealtime();
|
long nowMillis = SystemClock.elapsedRealtime();
|
||||||
|
synchronized (mLock) {
|
||||||
for (ScanResult result : mScanResults) {
|
for (ScanResult result : mScanResults) {
|
||||||
ScoredNetwork score = scoreCache.getScoredNetwork(result);
|
ScoredNetwork score = scoreCache.getScoredNetwork(result);
|
||||||
if (score == null) {
|
if (score == null) {
|
||||||
@@ -546,6 +560,7 @@ public class AccessPoint implements Comparable<AccessPoint> {
|
|||||||
timedScore.update(score, nowMillis);
|
timedScore.update(score, nowMillis);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Remove old cached networks
|
// Remove old cached networks
|
||||||
long evictionCutoff = nowMillis - maxScoreCacheAgeMillis;
|
long evictionCutoff = nowMillis - maxScoreCacheAgeMillis;
|
||||||
@@ -619,6 +634,7 @@ public class AccessPoint implements Comparable<AccessPoint> {
|
|||||||
mIsScoredNetworkMetered |= score.meteredHint;
|
mIsScoredNetworkMetered |= score.meteredHint;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
synchronized (mLock) {
|
||||||
for (ScanResult result : mScanResults) {
|
for (ScanResult result : mScanResults) {
|
||||||
ScoredNetwork score = scoreCache.getScoredNetwork(result);
|
ScoredNetwork score = scoreCache.getScoredNetwork(result);
|
||||||
if (score == null) {
|
if (score == null) {
|
||||||
@@ -627,6 +643,7 @@ public class AccessPoint implements Comparable<AccessPoint> {
|
|||||||
mIsScoredNetworkMetered |= score.meteredHint;
|
mIsScoredNetworkMetered |= score.meteredHint;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return oldMetering == mIsScoredNetworkMetered;
|
return oldMetering == mIsScoredNetworkMetered;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -741,8 +758,10 @@ public class AccessPoint implements Comparable<AccessPoint> {
|
|||||||
*/
|
*/
|
||||||
public Set<ScanResult> getScanResults() {
|
public Set<ScanResult> getScanResults() {
|
||||||
Set<ScanResult> allScans = new ArraySet<>();
|
Set<ScanResult> allScans = new ArraySet<>();
|
||||||
|
synchronized (mLock) {
|
||||||
allScans.addAll(mScanResults);
|
allScans.addAll(mScanResults);
|
||||||
allScans.addAll(mExtraScanResults);
|
allScans.addAll(mExtraScanResults);
|
||||||
|
}
|
||||||
return allScans;
|
return allScans;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -766,12 +785,14 @@ public class AccessPoint implements Comparable<AccessPoint> {
|
|||||||
|
|
||||||
ScanResult bestResult = null;
|
ScanResult bestResult = null;
|
||||||
int bestRssi = UNREACHABLE_RSSI;
|
int bestRssi = UNREACHABLE_RSSI;
|
||||||
|
synchronized (mLock) {
|
||||||
for (ScanResult result : mScanResults) {
|
for (ScanResult result : mScanResults) {
|
||||||
if (result.level > bestRssi) {
|
if (result.level > bestRssi) {
|
||||||
bestRssi = result.level;
|
bestRssi = result.level;
|
||||||
bestResult = result;
|
bestResult = result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Set the rssi to the average of the current rssi and the previous rssi.
|
// Set the rssi to the average of the current rssi and the previous rssi.
|
||||||
if (bestRssi != UNREACHABLE_RSSI && mRssi != UNREACHABLE_RSSI) {
|
if (bestRssi != UNREACHABLE_RSSI && mRssi != UNREACHABLE_RSSI) {
|
||||||
@@ -1210,9 +1231,11 @@ public class AccessPoint implements Comparable<AccessPoint> {
|
|||||||
savedState.putInt(KEY_EAPTYPE, mEapType);
|
savedState.putInt(KEY_EAPTYPE, mEapType);
|
||||||
if (mConfig != null) savedState.putParcelable(KEY_CONFIG, mConfig);
|
if (mConfig != null) savedState.putParcelable(KEY_CONFIG, mConfig);
|
||||||
savedState.putParcelable(KEY_WIFIINFO, mInfo);
|
savedState.putParcelable(KEY_WIFIINFO, mInfo);
|
||||||
|
synchronized (mLock) {
|
||||||
savedState.putParcelableArray(KEY_SCANRESULTS,
|
savedState.putParcelableArray(KEY_SCANRESULTS,
|
||||||
mScanResults.toArray(new Parcelable[mScanResults.size()
|
mScanResults.toArray(new Parcelable[mScanResults.size()
|
||||||
+ mExtraScanResults.size()]));
|
+ mExtraScanResults.size()]));
|
||||||
|
}
|
||||||
savedState.putParcelableArrayList(KEY_SCOREDNETWORKCACHE,
|
savedState.putParcelableArrayList(KEY_SCOREDNETWORKCACHE,
|
||||||
new ArrayList<>(mScoredNetworkCache.values()));
|
new ArrayList<>(mScoredNetworkCache.values()));
|
||||||
if (mNetworkInfo != null) {
|
if (mNetworkInfo != null) {
|
||||||
@@ -1291,8 +1314,10 @@ public class AccessPoint implements Comparable<AccessPoint> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int oldLevel = getLevel();
|
int oldLevel = getLevel();
|
||||||
|
synchronized (mLock) {
|
||||||
mScanResults.clear();
|
mScanResults.clear();
|
||||||
mScanResults.addAll(scanResults);
|
mScanResults.addAll(scanResults);
|
||||||
|
}
|
||||||
updateBestRssiInfo();
|
updateBestRssiInfo();
|
||||||
int newLevel = getLevel();
|
int newLevel = getLevel();
|
||||||
|
|
||||||
@@ -1323,18 +1348,20 @@ public class AccessPoint implements Comparable<AccessPoint> {
|
|||||||
void setScanResultsPasspoint(
|
void setScanResultsPasspoint(
|
||||||
@Nullable Collection<ScanResult> homeScans,
|
@Nullable Collection<ScanResult> homeScans,
|
||||||
@Nullable Collection<ScanResult> roamingScans) {
|
@Nullable Collection<ScanResult> roamingScans) {
|
||||||
|
synchronized (mLock) {
|
||||||
mExtraScanResults.clear();
|
mExtraScanResults.clear();
|
||||||
if (!CollectionUtils.isEmpty(homeScans)) {
|
if (!CollectionUtils.isEmpty(homeScans)) {
|
||||||
|
mIsRoaming = false;
|
||||||
if (!CollectionUtils.isEmpty(roamingScans)) {
|
if (!CollectionUtils.isEmpty(roamingScans)) {
|
||||||
mExtraScanResults.addAll(roamingScans);
|
mExtraScanResults.addAll(roamingScans);
|
||||||
}
|
}
|
||||||
mIsRoaming = false;
|
|
||||||
setScanResults(homeScans);
|
setScanResults(homeScans);
|
||||||
} else if (!CollectionUtils.isEmpty(roamingScans)) {
|
} else if (!CollectionUtils.isEmpty(roamingScans)) {
|
||||||
mIsRoaming = true;
|
mIsRoaming = true;
|
||||||
setScanResults(roamingScans);
|
setScanResults(roamingScans);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempt to update the AccessPoint with the current connection info.
|
* Attempt to update the AccessPoint with the current connection info.
|
||||||
|
|||||||
Reference in New Issue
Block a user