am edb83227: Merge "Fix access point list jumping around in WifiSettings" into mnc-dev
* commit 'edb832271bc036975d9ff8cd1513b6a1e097f3cd': Fix access point list jumping around in WifiSettings
This commit is contained in:
@@ -46,6 +46,7 @@ import android.util.LruCache;
|
|||||||
|
|
||||||
import com.android.settingslib.R;
|
import com.android.settingslib.R;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
@@ -79,10 +80,15 @@ public class AccessPoint implements Comparable<AccessPoint> {
|
|||||||
* For now this data is used only with Verbose Logging so as to show the band and number
|
* For now this data is used only with Verbose Logging so as to show the band and number
|
||||||
* of BSSIDs on which that network is seen.
|
* of BSSIDs on which that network is seen.
|
||||||
*/
|
*/
|
||||||
public LruCache<String, ScanResult> mScanResultCache;
|
public LruCache<String, ScanResult> mScanResultCache = new LruCache<String, ScanResult>(32);
|
||||||
|
|
||||||
private static final String KEY_NETWORKINFO = "key_networkinfo";
|
private static final String KEY_NETWORKINFO = "key_networkinfo";
|
||||||
private static final String KEY_WIFIINFO = "key_wifiinfo";
|
private static final String KEY_WIFIINFO = "key_wifiinfo";
|
||||||
private static final String KEY_SCANRESULT = "key_scanresult";
|
private static final String KEY_SCANRESULT = "key_scanresult";
|
||||||
|
private static final String KEY_SSID = "key_ssid";
|
||||||
|
private static final String KEY_SECURITY = "key_security";
|
||||||
|
private static final String KEY_PSKTYPE = "key_psktype";
|
||||||
|
private static final String KEY_SCANRESULTCACHE = "key_scanresultcache";
|
||||||
private static final String KEY_CONFIG = "key_config";
|
private static final String KEY_CONFIG = "key_config";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -108,7 +114,6 @@ public class AccessPoint implements Comparable<AccessPoint> {
|
|||||||
private int pskType = PSK_UNKNOWN;
|
private int pskType = PSK_UNKNOWN;
|
||||||
|
|
||||||
private WifiConfiguration mConfig;
|
private WifiConfiguration mConfig;
|
||||||
private ScanResult mScanResult;
|
|
||||||
|
|
||||||
private int mRssi = Integer.MAX_VALUE;
|
private int mRssi = Integer.MAX_VALUE;
|
||||||
private long mSeen = 0;
|
private long mSeen = 0;
|
||||||
@@ -125,20 +130,35 @@ public class AccessPoint implements Comparable<AccessPoint> {
|
|||||||
if (mConfig != null) {
|
if (mConfig != null) {
|
||||||
loadConfig(mConfig);
|
loadConfig(mConfig);
|
||||||
}
|
}
|
||||||
mScanResult = (ScanResult) savedState.getParcelable(KEY_SCANRESULT);
|
if (savedState.containsKey(KEY_SSID)) {
|
||||||
if (mScanResult != null) {
|
ssid = savedState.getString(KEY_SSID);
|
||||||
loadResult(mScanResult);
|
}
|
||||||
|
if (savedState.containsKey(KEY_SECURITY)) {
|
||||||
|
security = savedState.getInt(KEY_SECURITY);
|
||||||
|
}
|
||||||
|
if (savedState.containsKey(KEY_PSKTYPE)) {
|
||||||
|
pskType = savedState.getInt(KEY_PSKTYPE);
|
||||||
}
|
}
|
||||||
mInfo = (WifiInfo) savedState.getParcelable(KEY_WIFIINFO);
|
mInfo = (WifiInfo) savedState.getParcelable(KEY_WIFIINFO);
|
||||||
if (savedState.containsKey(KEY_NETWORKINFO)) {
|
if (savedState.containsKey(KEY_NETWORKINFO)) {
|
||||||
mNetworkInfo = savedState.getParcelable(KEY_NETWORKINFO);
|
mNetworkInfo = savedState.getParcelable(KEY_NETWORKINFO);
|
||||||
}
|
}
|
||||||
|
if (savedState.containsKey(KEY_SCANRESULTCACHE)) {
|
||||||
|
ArrayList<ScanResult> scanResultArrayList =
|
||||||
|
savedState.getParcelableArrayList(KEY_SCANRESULTCACHE);
|
||||||
|
mScanResultCache.evictAll();
|
||||||
|
for (ScanResult result : scanResultArrayList) {
|
||||||
|
mScanResultCache.put(result.BSSID, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
update(mInfo, mNetworkInfo);
|
update(mInfo, mNetworkInfo);
|
||||||
|
mRssi = getRssi();
|
||||||
|
mSeen = getSeen();
|
||||||
}
|
}
|
||||||
|
|
||||||
AccessPoint(Context context, ScanResult result) {
|
AccessPoint(Context context, ScanResult result) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
loadResult(result);
|
initWithScanResult(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
AccessPoint(Context context, WifiConfiguration config) {
|
AccessPoint(Context context, WifiConfiguration config) {
|
||||||
@@ -240,6 +260,28 @@ public class AccessPoint implements Comparable<AccessPoint> {
|
|||||||
return WifiManager.calculateSignalLevel(mRssi, 4);
|
return WifiManager.calculateSignalLevel(mRssi, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getRssi() {
|
||||||
|
int rssi = Integer.MIN_VALUE;
|
||||||
|
for (ScanResult result : mScanResultCache.snapshot().values()) {
|
||||||
|
if (result.level > rssi) {
|
||||||
|
rssi = result.level;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return rssi;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getSeen() {
|
||||||
|
long seen = 0;
|
||||||
|
for (ScanResult result : mScanResultCache.snapshot().values()) {
|
||||||
|
if (result.timestamp > seen) {
|
||||||
|
seen = result.timestamp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return seen;
|
||||||
|
}
|
||||||
|
|
||||||
public NetworkInfo getNetworkInfo() {
|
public NetworkInfo getNetworkInfo() {
|
||||||
return mNetworkInfo;
|
return mNetworkInfo;
|
||||||
}
|
}
|
||||||
@@ -455,120 +497,109 @@ public class AccessPoint implements Comparable<AccessPoint> {
|
|||||||
visibility.append(String.format("rx=%.1f", mInfo.rxSuccessRate));
|
visibility.append(String.format("rx=%.1f", mInfo.rxSuccessRate));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mScanResultCache != null) {
|
int rssi5 = WifiConfiguration.INVALID_RSSI;
|
||||||
int rssi5 = WifiConfiguration.INVALID_RSSI;
|
int rssi24 = WifiConfiguration.INVALID_RSSI;
|
||||||
int rssi24 = WifiConfiguration.INVALID_RSSI;
|
int num5 = 0;
|
||||||
int num5 = 0;
|
int num24 = 0;
|
||||||
int num24 = 0;
|
int numBlackListed = 0;
|
||||||
int numBlackListed = 0;
|
int n24 = 0; // Number scan results we included in the string
|
||||||
int n24 = 0; // Number scan results we included in the string
|
int n5 = 0; // Number scan results we included in the string
|
||||||
int n5 = 0; // Number scan results we included in the string
|
Map<String, ScanResult> list = mScanResultCache.snapshot();
|
||||||
Map<String, ScanResult> list = mScanResultCache.snapshot();
|
// TODO: sort list by RSSI or age
|
||||||
// TODO: sort list by RSSI or age
|
for (ScanResult result : list.values()) {
|
||||||
for (ScanResult result : list.values()) {
|
if (result.seen == 0)
|
||||||
if (result.seen == 0)
|
continue;
|
||||||
continue;
|
|
||||||
|
|
||||||
if (result.autoJoinStatus != ScanResult.ENABLED) numBlackListed++;
|
if (result.autoJoinStatus != ScanResult.ENABLED) numBlackListed++;
|
||||||
|
|
||||||
if (result.frequency >= LOWER_FREQ_5GHZ
|
if (result.frequency >= LOWER_FREQ_5GHZ
|
||||||
&& result.frequency <= HIGHER_FREQ_5GHZ) {
|
&& result.frequency <= HIGHER_FREQ_5GHZ) {
|
||||||
// Strictly speaking: [4915, 5825]
|
// Strictly speaking: [4915, 5825]
|
||||||
// number of known BSSID on 5GHz band
|
// number of known BSSID on 5GHz band
|
||||||
num5 = num5 + 1;
|
num5 = num5 + 1;
|
||||||
} else if (result.frequency >= LOWER_FREQ_24GHZ
|
} else if (result.frequency >= LOWER_FREQ_24GHZ
|
||||||
&& result.frequency <= HIGHER_FREQ_24GHZ) {
|
&& result.frequency <= HIGHER_FREQ_24GHZ) {
|
||||||
// Strictly speaking: [2412, 2482]
|
// Strictly speaking: [2412, 2482]
|
||||||
// number of known BSSID on 2.4Ghz band
|
// number of known BSSID on 2.4Ghz band
|
||||||
num24 = num24 + 1;
|
num24 = num24 + 1;
|
||||||
}
|
|
||||||
|
|
||||||
// Ignore results seen, older than 20 seconds
|
|
||||||
if (now - result.seen > VISIBILITY_OUTDATED_AGE_IN_MILLI) continue;
|
|
||||||
|
|
||||||
if (result.frequency >= LOWER_FREQ_5GHZ
|
|
||||||
&& result.frequency <= HIGHER_FREQ_5GHZ) {
|
|
||||||
if (result.level > rssi5) {
|
|
||||||
rssi5 = result.level;
|
|
||||||
}
|
|
||||||
if (n5 < 4) {
|
|
||||||
if (scans5GHz == null) scans5GHz = new StringBuilder();
|
|
||||||
scans5GHz.append(" \n{").append(result.BSSID);
|
|
||||||
if (bssid != null && result.BSSID.equals(bssid)) scans5GHz.append("*");
|
|
||||||
scans5GHz.append("=").append(result.frequency);
|
|
||||||
scans5GHz.append(",").append(result.level);
|
|
||||||
if (result.autoJoinStatus != 0) {
|
|
||||||
scans5GHz.append(",st=").append(result.autoJoinStatus);
|
|
||||||
}
|
|
||||||
if (result.numIpConfigFailures != 0) {
|
|
||||||
scans5GHz.append(",ipf=").append(result.numIpConfigFailures);
|
|
||||||
}
|
|
||||||
scans5GHz.append("}");
|
|
||||||
n5++;
|
|
||||||
}
|
|
||||||
} else if (result.frequency >= LOWER_FREQ_24GHZ
|
|
||||||
&& result.frequency <= HIGHER_FREQ_24GHZ) {
|
|
||||||
if (result.level > rssi24) {
|
|
||||||
rssi24 = result.level;
|
|
||||||
}
|
|
||||||
if (n24 < 4) {
|
|
||||||
if (scans24GHz == null) scans24GHz = new StringBuilder();
|
|
||||||
scans24GHz.append(" \n{").append(result.BSSID);
|
|
||||||
if (bssid != null && result.BSSID.equals(bssid)) scans24GHz.append("*");
|
|
||||||
scans24GHz.append("=").append(result.frequency);
|
|
||||||
scans24GHz.append(",").append(result.level);
|
|
||||||
if (result.autoJoinStatus != 0) {
|
|
||||||
scans24GHz.append(",st=").append(result.autoJoinStatus);
|
|
||||||
}
|
|
||||||
if (result.numIpConfigFailures != 0) {
|
|
||||||
scans24GHz.append(",ipf=").append(result.numIpConfigFailures);
|
|
||||||
}
|
|
||||||
scans24GHz.append("}");
|
|
||||||
n24++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
visibility.append(" [");
|
|
||||||
if (num24 > 0) {
|
// Ignore results seen, older than 20 seconds
|
||||||
visibility.append("(").append(num24).append(")");
|
if (now - result.seen > VISIBILITY_OUTDATED_AGE_IN_MILLI) continue;
|
||||||
if (n24 <= 4) {
|
|
||||||
if (scans24GHz != null) {
|
if (result.frequency >= LOWER_FREQ_5GHZ
|
||||||
visibility.append(scans24GHz.toString());
|
&& result.frequency <= HIGHER_FREQ_5GHZ) {
|
||||||
}
|
if (result.level > rssi5) {
|
||||||
} else {
|
rssi5 = result.level;
|
||||||
visibility.append("max=").append(rssi24);
|
|
||||||
if (scans24GHz != null) {
|
|
||||||
visibility.append(",").append(scans24GHz.toString());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
if (n5 < 4) {
|
||||||
visibility.append(";");
|
if (scans5GHz == null) scans5GHz = new StringBuilder();
|
||||||
if (num5 > 0) {
|
scans5GHz.append(" \n{").append(result.BSSID);
|
||||||
visibility.append("(").append(num5).append(")");
|
if (bssid != null && result.BSSID.equals(bssid)) scans5GHz.append("*");
|
||||||
if (n5 <= 4) {
|
scans5GHz.append("=").append(result.frequency);
|
||||||
if (scans5GHz != null) {
|
scans5GHz.append(",").append(result.level);
|
||||||
visibility.append(scans5GHz.toString());
|
if (result.autoJoinStatus != 0) {
|
||||||
|
scans5GHz.append(",st=").append(result.autoJoinStatus);
|
||||||
}
|
}
|
||||||
} else {
|
if (result.numIpConfigFailures != 0) {
|
||||||
visibility.append("max=").append(rssi5);
|
scans5GHz.append(",ipf=").append(result.numIpConfigFailures);
|
||||||
if (scans5GHz != null) {
|
|
||||||
visibility.append(",").append(scans5GHz.toString());
|
|
||||||
}
|
}
|
||||||
|
scans5GHz.append("}");
|
||||||
|
n5++;
|
||||||
}
|
}
|
||||||
}
|
} else if (result.frequency >= LOWER_FREQ_24GHZ
|
||||||
if (numBlackListed > 0)
|
&& result.frequency <= HIGHER_FREQ_24GHZ) {
|
||||||
visibility.append("!").append(numBlackListed);
|
if (result.level > rssi24) {
|
||||||
visibility.append("]");
|
rssi24 = result.level;
|
||||||
} else {
|
}
|
||||||
if (mRssi != Integer.MAX_VALUE) {
|
if (n24 < 4) {
|
||||||
visibility.append(" rssi=");
|
if (scans24GHz == null) scans24GHz = new StringBuilder();
|
||||||
visibility.append(mRssi);
|
scans24GHz.append(" \n{").append(result.BSSID);
|
||||||
if (mScanResult != null) {
|
if (bssid != null && result.BSSID.equals(bssid)) scans24GHz.append("*");
|
||||||
visibility.append(", f=");
|
scans24GHz.append("=").append(result.frequency);
|
||||||
visibility.append(mScanResult.frequency);
|
scans24GHz.append(",").append(result.level);
|
||||||
|
if (result.autoJoinStatus != 0) {
|
||||||
|
scans24GHz.append(",st=").append(result.autoJoinStatus);
|
||||||
|
}
|
||||||
|
if (result.numIpConfigFailures != 0) {
|
||||||
|
scans24GHz.append(",ipf=").append(result.numIpConfigFailures);
|
||||||
|
}
|
||||||
|
scans24GHz.append("}");
|
||||||
|
n24++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
visibility.append(" [");
|
||||||
|
if (num24 > 0) {
|
||||||
|
visibility.append("(").append(num24).append(")");
|
||||||
|
if (n24 <= 4) {
|
||||||
|
if (scans24GHz != null) {
|
||||||
|
visibility.append(scans24GHz.toString());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
visibility.append("max=").append(rssi24);
|
||||||
|
if (scans24GHz != null) {
|
||||||
|
visibility.append(",").append(scans24GHz.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
visibility.append(";");
|
||||||
|
if (num5 > 0) {
|
||||||
|
visibility.append("(").append(num5).append(")");
|
||||||
|
if (n5 <= 4) {
|
||||||
|
if (scans5GHz != null) {
|
||||||
|
visibility.append(scans5GHz.toString());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
visibility.append("max=").append(rssi5);
|
||||||
|
if (scans5GHz != null) {
|
||||||
|
visibility.append(",").append(scans5GHz.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (numBlackListed > 0)
|
||||||
|
visibility.append("!").append(numBlackListed);
|
||||||
|
visibility.append("]");
|
||||||
|
|
||||||
return visibility.toString();
|
return visibility.toString();
|
||||||
}
|
}
|
||||||
@@ -635,28 +666,29 @@ public class AccessPoint implements Comparable<AccessPoint> {
|
|||||||
ssid = config.providerFriendlyName;
|
ssid = config.providerFriendlyName;
|
||||||
else
|
else
|
||||||
ssid = (config.SSID == null ? "" : removeDoubleQuotes(config.SSID));
|
ssid = (config.SSID == null ? "" : removeDoubleQuotes(config.SSID));
|
||||||
|
|
||||||
security = getSecurity(config);
|
security = getSecurity(config);
|
||||||
networkId = config.networkId;
|
networkId = config.networkId;
|
||||||
mConfig = config;
|
mConfig = config;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadResult(ScanResult result) {
|
private void initWithScanResult(ScanResult result) {
|
||||||
ssid = result.SSID;
|
ssid = result.SSID;
|
||||||
security = getSecurity(result);
|
security = getSecurity(result);
|
||||||
if (security == SECURITY_PSK)
|
if (security == SECURITY_PSK)
|
||||||
pskType = getPskType(result);
|
pskType = getPskType(result);
|
||||||
mRssi = result.level;
|
mRssi = result.level;
|
||||||
mScanResult = result;
|
mSeen = result.timestamp;
|
||||||
if (result.seen > mSeen) {
|
|
||||||
mSeen = result.seen;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveWifiState(Bundle savedState) {
|
public void saveWifiState(Bundle savedState) {
|
||||||
savedState.putParcelable(KEY_CONFIG, mConfig);
|
if (ssid != null) savedState.putString(KEY_SSID, getSsidStr());
|
||||||
savedState.putParcelable(KEY_SCANRESULT, mScanResult);
|
savedState.putInt(KEY_SECURITY, security);
|
||||||
|
savedState.putInt(KEY_PSKTYPE, pskType);
|
||||||
|
if (mConfig != null) savedState.putParcelable(KEY_CONFIG, mConfig);
|
||||||
savedState.putParcelable(KEY_WIFIINFO, mInfo);
|
savedState.putParcelable(KEY_WIFIINFO, mInfo);
|
||||||
|
savedState.putParcelableArrayList(KEY_SCANRESULTCACHE,
|
||||||
|
new ArrayList<ScanResult>(mScanResultCache.snapshot().values()));
|
||||||
if (mNetworkInfo != null) {
|
if (mNetworkInfo != null) {
|
||||||
savedState.putParcelable(KEY_NETWORKINFO, mNetworkInfo);
|
savedState.putParcelable(KEY_NETWORKINFO, mNetworkInfo);
|
||||||
}
|
}
|
||||||
@@ -667,32 +699,31 @@ public class AccessPoint implements Comparable<AccessPoint> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
boolean update(ScanResult result) {
|
boolean update(ScanResult result) {
|
||||||
if (result.seen > mSeen) {
|
|
||||||
mSeen = result.seen;
|
|
||||||
}
|
|
||||||
if (WifiTracker.sVerboseLogging > 0) {
|
|
||||||
if (mScanResultCache == null) {
|
|
||||||
mScanResultCache = new LruCache<String, ScanResult>(32);
|
|
||||||
}
|
|
||||||
mScanResultCache.put(result.BSSID, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ssid.equals(result.SSID) && security == getSecurity(result)) {
|
if (ssid.equals(result.SSID) && security == getSecurity(result)) {
|
||||||
if (WifiManager.compareSignalLevel(result.level, mRssi) > 0) {
|
/* Update the LRU timestamp, if BSSID exists */
|
||||||
int oldLevel = getLevel();
|
mScanResultCache.get(result.BSSID);
|
||||||
mRssi = result.level;
|
|
||||||
if (getLevel() != oldLevel && mAccessPointListener != null) {
|
/* Add or update the scan result for the BSSID */
|
||||||
mAccessPointListener.onLevelChanged(this);
|
mScanResultCache.put(result.BSSID, result);
|
||||||
}
|
|
||||||
|
int oldLevel = getLevel();
|
||||||
|
int oldRssi = getRssi();
|
||||||
|
mSeen = getSeen();
|
||||||
|
mRssi = (getRssi() + oldRssi)/2;
|
||||||
|
int newLevel = getLevel();
|
||||||
|
|
||||||
|
if (newLevel > 0 && newLevel != oldLevel && mAccessPointListener != null) {
|
||||||
|
mAccessPointListener.onLevelChanged(this);
|
||||||
}
|
}
|
||||||
// This flag only comes from scans, is not easily saved in config
|
// This flag only comes from scans, is not easily saved in config
|
||||||
if (security == SECURITY_PSK) {
|
if (security == SECURITY_PSK) {
|
||||||
pskType = getPskType(result);
|
pskType = getPskType(result);
|
||||||
}
|
}
|
||||||
mScanResult = result;
|
|
||||||
if (mAccessPointListener != null) {
|
if (mAccessPointListener != null) {
|
||||||
mAccessPointListener.onAccessPointChanged(this);
|
mAccessPointListener.onAccessPointChanged(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import android.net.wifi.WifiManager;
|
|||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
|
import android.util.Log;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.android.internal.annotations.VisibleForTesting;
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
@@ -35,9 +36,12 @@ import com.android.settingslib.R;
|
|||||||
|
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -45,6 +49,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|||||||
*/
|
*/
|
||||||
public class WifiTracker {
|
public class WifiTracker {
|
||||||
private static final String TAG = "WifiTracker";
|
private static final String TAG = "WifiTracker";
|
||||||
|
private static final boolean DBG = false;
|
||||||
|
|
||||||
/** verbose logging flag. this flag is set thru developer debugging options
|
/** verbose logging flag. this flag is set thru developer debugging options
|
||||||
* and used so as to assist with in-the-field WiFi connectivity debugging */
|
* and used so as to assist with in-the-field WiFi connectivity debugging */
|
||||||
@@ -70,6 +75,10 @@ public class WifiTracker {
|
|||||||
private boolean mSavedNetworksExist;
|
private boolean mSavedNetworksExist;
|
||||||
private boolean mRegistered;
|
private boolean mRegistered;
|
||||||
private ArrayList<AccessPoint> mAccessPoints = new ArrayList<>();
|
private ArrayList<AccessPoint> mAccessPoints = new ArrayList<>();
|
||||||
|
private HashMap<String, Integer> mSeenBssids = new HashMap<>();
|
||||||
|
private HashMap<String, ScanResult> mScanResultCache = new HashMap<>();
|
||||||
|
private Integer mScanId = 0;
|
||||||
|
private static final int NUM_SCANS_TO_CONFIRM_AP_LOSS = 3;
|
||||||
|
|
||||||
private NetworkInfo mLastNetworkInfo;
|
private NetworkInfo mLastNetworkInfo;
|
||||||
private WifiInfo mLastInfo;
|
private WifiInfo mLastInfo;
|
||||||
@@ -166,6 +175,11 @@ public class WifiTracker {
|
|||||||
if (mScanner == null) {
|
if (mScanner == null) {
|
||||||
mScanner = new Scanner();
|
mScanner = new Scanner();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mScanResultCache.clear();
|
||||||
|
mSeenBssids.clear();
|
||||||
|
mScanId = 0;
|
||||||
|
|
||||||
if (mWifiManager.isWifiEnabled()) {
|
if (mWifiManager.isWifiEnabled()) {
|
||||||
mScanner.resume();
|
mScanner.resume();
|
||||||
}
|
}
|
||||||
@@ -237,6 +251,33 @@ public class WifiTracker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Collection<ScanResult> fetchScanResults() {
|
||||||
|
mScanId++;
|
||||||
|
final List<ScanResult> newResults = mWifiManager.getScanResults();
|
||||||
|
for (ScanResult newResult : newResults) {
|
||||||
|
mScanResultCache.put(newResult.BSSID, newResult);
|
||||||
|
mSeenBssids.put(newResult.BSSID, mScanId);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mScanId > NUM_SCANS_TO_CONFIRM_AP_LOSS) {
|
||||||
|
if (DBG) Log.d(TAG, "------ Dumping SSIDs that were expired on this scan ------");
|
||||||
|
Integer threshold = mScanId - NUM_SCANS_TO_CONFIRM_AP_LOSS;
|
||||||
|
for (Iterator<Map.Entry<String, Integer>> it = mSeenBssids.entrySet().iterator();
|
||||||
|
it.hasNext(); /* nothing */) {
|
||||||
|
Map.Entry<String, Integer> e = it.next();
|
||||||
|
if (e.getValue() < threshold) {
|
||||||
|
ScanResult result = mScanResultCache.get(e.getKey());
|
||||||
|
if (DBG) Log.d(TAG, "Removing " + e.getKey() + ":(" + result.SSID + ")");
|
||||||
|
mScanResultCache.remove(e.getKey());
|
||||||
|
it.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (DBG) Log.d(TAG, "---- Done Dumping SSIDs that were expired on this scan ----");
|
||||||
|
}
|
||||||
|
|
||||||
|
return mScanResultCache.values();
|
||||||
|
}
|
||||||
|
|
||||||
private void updateAccessPoints() {
|
private void updateAccessPoints() {
|
||||||
// Swap the current access points into a cached list.
|
// Swap the current access points into a cached list.
|
||||||
List<AccessPoint> cachedAccessPoints = getAccessPoints();
|
List<AccessPoint> cachedAccessPoints = getAccessPoints();
|
||||||
@@ -283,7 +324,7 @@ public class WifiTracker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<ScanResult> results = mWifiManager.getScanResults();
|
final Collection<ScanResult> results = fetchScanResults();
|
||||||
if (results != null) {
|
if (results != null) {
|
||||||
for (ScanResult result : results) {
|
for (ScanResult result : results) {
|
||||||
// Ignore hidden and ad-hoc networks.
|
// Ignore hidden and ad-hoc networks.
|
||||||
@@ -328,6 +369,24 @@ public class WifiTracker {
|
|||||||
|
|
||||||
// Pre-sort accessPoints to speed preference insertion
|
// Pre-sort accessPoints to speed preference insertion
|
||||||
Collections.sort(accessPoints);
|
Collections.sort(accessPoints);
|
||||||
|
|
||||||
|
// Log accesspoints that were deleted
|
||||||
|
if (DBG) Log.d(TAG, "------ Dumping SSIDs that were not seen on this scan ------");
|
||||||
|
for (AccessPoint prevAccessPoint : mAccessPoints) {
|
||||||
|
if (prevAccessPoint.getSsid() == null) continue;
|
||||||
|
String prevSsid = prevAccessPoint.getSsidStr();
|
||||||
|
boolean found = false;
|
||||||
|
for (AccessPoint newAccessPoint : accessPoints) {
|
||||||
|
if (newAccessPoint.getSsid() != null && newAccessPoint.getSsid().equals(prevSsid)) {
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!found)
|
||||||
|
if (DBG) Log.d(TAG, "Did not find " + prevSsid + " in this scan");
|
||||||
|
}
|
||||||
|
if (DBG) Log.d(TAG, "---- Done dumping SSIDs that were not seen on this scan ----");
|
||||||
|
|
||||||
mAccessPoints = accessPoints;
|
mAccessPoints = accessPoints;
|
||||||
mMainHandler.sendEmptyMessage(MainHandler.MSG_ACCESS_POINT_CHANGED);
|
mMainHandler.sendEmptyMessage(MainHandler.MSG_ACCESS_POINT_CHANGED);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user