use of android.net.wifi.ScanResult in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class WifiStatusTest method handleScanResultsAvailable.
private void handleScanResultsAvailable() {
List<ScanResult> list = mWifiManager.getScanResults();
StringBuffer scanList = new StringBuffer();
if (list != null) {
for (int i = list.size() - 1; i >= 0; i--) {
final ScanResult scanResult = list.get(i);
if (scanResult == null) {
continue;
}
if (TextUtils.isEmpty(scanResult.SSID)) {
continue;
}
scanList.append(scanResult.SSID + " ");
}
}
mScanList.setText(scanList);
}
use of android.net.wifi.ScanResult in project teaTime by ancfdy.
the class AppWifiHelperMgr method lookupScanInfo.
/**
* 获取扫描WIFI列表的信息
* @return
*/
public String lookupScanInfo() {
StringBuilder scanBuilder = new StringBuilder();
if (scanResultList == null) {
return "";
}
for (int i = 0; i < scanResultList.size(); i++) {
ScanResult sResult = scanResultList.get(i);
scanBuilder.append("编号:" + (i + 1));
scanBuilder.append(" ");
//所有信息
scanBuilder.append(sResult.toString());
scanBuilder.append("\n");
}
scanBuilder.append("--------------华丽分割线--------------------");
for (int i = 0; i < wifiConfigList.size(); i++) {
scanBuilder.append(wifiConfigList.get(i).toString());
scanBuilder.append("\n");
}
return scanBuilder.toString();
}
use of android.net.wifi.ScanResult in project android_frameworks_base by crdroidandroid.
the class AccessPointTest method testOnLevelChanged.
public void testOnLevelChanged() {
ScanResult result = new ScanResult();
result.capabilities = "";
result.SSID = TEST_SSID;
// Give it a level.
result.level = WifiTrackerTest.levelToRssi(1);
mAccessPoint.update(result);
verifyOnLevelChangedCallback(1);
// Give it a better level.
result.level = WifiTrackerTest.levelToRssi(2);
mAccessPoint.update(result);
verifyOnLevelChangedCallback(1);
}
use of android.net.wifi.ScanResult in project android_frameworks_base by crdroidandroid.
the class WifiTracker method updateAccessPoints.
private void updateAccessPoints() {
// Swap the current access points into a cached list.
List<AccessPoint> cachedAccessPoints = getAccessPoints();
ArrayList<AccessPoint> accessPoints = new ArrayList<>();
// Clear out the configs so we don't think something is saved when it isn't.
for (AccessPoint accessPoint : cachedAccessPoints) {
accessPoint.clearConfig();
}
/** Lookup table to more quickly update AccessPoints by only considering objects with the
* correct SSID. Maps SSID -> List of AccessPoints with the given SSID. */
Multimap<String, AccessPoint> apMap = new Multimap<String, AccessPoint>();
WifiConfiguration connectionConfig = null;
if (mLastInfo != null) {
connectionConfig = getWifiConfigurationForNetworkId(mLastInfo.getNetworkId());
}
final Collection<ScanResult> results = fetchScanResults();
final List<WifiConfiguration> configs = mWifiManager.getConfiguredNetworks();
if (configs != null) {
mSavedNetworksExist = configs.size() != 0;
for (WifiConfiguration config : configs) {
if (config.selfAdded && config.numAssociation == 0) {
continue;
}
AccessPoint accessPoint = getCachedOrCreate(config, cachedAccessPoints);
accessPoint.update(connectionConfig, mLastInfo, mLastNetworkInfo);
if (mIncludeSaved) {
// If saved network not present in scan result then set its Rssi to MAX_VALUE
boolean apFound = false;
for (ScanResult result : results) {
if (result.SSID.equals(accessPoint.getSsidStr())) {
apFound = true;
break;
}
}
if (!apFound) {
accessPoint.setRssi(Integer.MAX_VALUE);
}
accessPoints.add(accessPoint);
apMap.put(accessPoint.getSsidStr(), accessPoint);
} else {
// If we aren't using saved networks, drop them into the cache so that
// we have access to their saved info.
cachedAccessPoints.add(accessPoint);
}
}
}
if (results != null) {
for (ScanResult result : results) {
// Ignore hidden and ad-hoc networks.
if (result.SSID == null || result.SSID.length() == 0 || result.capabilities.contains("[IBSS]")) {
continue;
}
boolean found = false;
for (AccessPoint accessPoint : apMap.getAll(result.SSID)) {
if (accessPoint.update(result)) {
found = true;
break;
}
}
if (!found && mIncludeScans) {
AccessPoint accessPoint = getCachedOrCreate(result, cachedAccessPoints);
if (mLastInfo != null && mLastNetworkInfo != null) {
accessPoint.update(connectionConfig, mLastInfo, mLastNetworkInfo);
}
if (result.isPasspointNetwork()) {
// name).
try {
WifiConfiguration config = mWifiManager.getMatchingWifiConfig(result);
if (config != null) {
accessPoint.update(config);
}
} catch (UnsupportedOperationException e) {
// Passpoint not supported on the device.
}
}
accessPoints.add(accessPoint);
apMap.put(accessPoint.getSsidStr(), accessPoint);
}
}
}
// Pre-sort accessPoints to speed preference insertion
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;
mMainHandler.sendEmptyMessage(MainHandler.MSG_ACCESS_POINT_CHANGED);
}
use of android.net.wifi.ScanResult in project android_frameworks_base by crdroidandroid.
the class WifiTracker method fetchScanResults.
private Collection<ScanResult> fetchScanResults() {
mScanId++;
final List<ScanResult> newResults = mWifiManager.getScanResults();
if (newResults == null) {
return null;
}
for (ScanResult newResult : newResults) {
if (newResult.SSID == null || newResult.SSID.isEmpty()) {
continue;
}
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();
}
Aggregations