use of android.net.wifi.ScanResult in project android_frameworks_base by ResurrectionRemix.
the class WifiTrackerTest method testAvailableOnly.
public void testAvailableOnly() {
mWifiTracker = new WifiTracker(mContext, mWifiListener, mLooper, false, true, true, mWifiManager, mMainLooper);
mWifiTracker.mScanner = mWifiTracker.new Scanner();
List<WifiConfiguration> wifiConfigs = new ArrayList<WifiConfiguration>();
List<ScanResult> scanResults = new ArrayList<ScanResult>();
String[] expectedSsids = generateTestNetworks(wifiConfigs, scanResults, true);
// Tell WifiTracker we are connected now.
sendConnected();
// Send all of the configs and scan results to the tracker.
Mockito.when(mWifiManager.getConfiguredNetworks()).thenReturn(wifiConfigs);
Mockito.when(mWifiManager.getScanResults()).thenReturn(scanResults);
sendScanResultsAndProcess(false);
// Expect the last one (sorted order) to be left off since its only saved.
List<AccessPoint> accessPoints = mWifiTracker.getAccessPoints();
assertEquals("Expected number of results", NUM_NETWORKS - 1, accessPoints.size());
for (int i = 0; i < NUM_NETWORKS - 1; i++) {
assertEquals("Verifying slot " + i, expectedSsids[i], accessPoints.get(i).getSsid());
}
}
use of android.net.wifi.ScanResult in project android_frameworks_base by ResurrectionRemix.
the class WifiTrackerTest method testNonEphemeralConnected.
public void testNonEphemeralConnected() {
mWifiTracker = new WifiTracker(mContext, mWifiListener, mLooper, false, true, true, mWifiManager, mMainLooper);
mWifiTracker.mScanner = mWifiTracker.new Scanner();
List<WifiConfiguration> wifiConfigs = new ArrayList<WifiConfiguration>();
List<ScanResult> scanResults = new ArrayList<ScanResult>();
generateTestNetworks(wifiConfigs, scanResults, false);
// Tell WifiTracker we are connected now.
sendConnected();
// Send all of the configs and scan results to the tracker.
Mockito.when(mWifiManager.getConfiguredNetworks()).thenReturn(wifiConfigs);
Mockito.when(mWifiManager.getScanResults()).thenReturn(scanResults);
// Do this twice to catch a bug that was happening in the caching, making things ephemeral.
sendScanResultsAndProcess(true);
List<AccessPoint> accessPoints = mWifiTracker.getAccessPoints();
assertEquals("Expected number of results", NUM_NETWORKS - 1, accessPoints.size());
assertFalse("Connection is not ephemeral", accessPoints.get(0).isEphemeral());
assertTrue("Connected to wifi", accessPoints.get(0).isActive());
}
use of android.net.wifi.ScanResult in project android_frameworks_base by ResurrectionRemix.
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 ResurrectionRemix.
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 DirtyUnicorns.
the class WifiTrackerTest method testAvailableOnly.
public void testAvailableOnly() {
mWifiTracker = new WifiTracker(mContext, mWifiListener, mLooper, false, true, true, mWifiManager, mMainLooper);
mWifiTracker.mScanner = mWifiTracker.new Scanner();
List<WifiConfiguration> wifiConfigs = new ArrayList<WifiConfiguration>();
List<ScanResult> scanResults = new ArrayList<ScanResult>();
String[] expectedSsids = generateTestNetworks(wifiConfigs, scanResults, true);
// Tell WifiTracker we are connected now.
sendConnected();
// Send all of the configs and scan results to the tracker.
Mockito.when(mWifiManager.getConfiguredNetworks()).thenReturn(wifiConfigs);
Mockito.when(mWifiManager.getScanResults()).thenReturn(scanResults);
sendScanResultsAndProcess(false);
// Expect the last one (sorted order) to be left off since its only saved.
List<AccessPoint> accessPoints = mWifiTracker.getAccessPoints();
assertEquals("Expected number of results", NUM_NETWORKS - 1, accessPoints.size());
for (int i = 0; i < NUM_NETWORKS - 1; i++) {
assertEquals("Verifying slot " + i, expectedSsids[i], accessPoints.get(i).getSsid());
}
}
Aggregations