use of android.net.wifi.ScanResult in project android_frameworks_base by AOSPA.
the class WifiTrackerTest method testSavedOnly.
public void testSavedOnly() {
mWifiTracker = new WifiTracker(mContext, mWifiListener, mLooper, true, false, true, mWifiManager, mMainLooper);
mWifiTracker.mScanner = mWifiTracker.new Scanner();
List<WifiConfiguration> wifiConfigs = new ArrayList<WifiConfiguration>();
List<ScanResult> scanResults = new ArrayList<ScanResult>();
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);
List<AccessPoint> accessPoints = mWifiTracker.getAccessPoints();
// Only expect the first two to come back in the results.
assertEquals("Expected number of results", 2, accessPoints.size());
assertEquals(TEST_SSIDS[1], accessPoints.get(0).getSsid());
assertEquals(TEST_SSIDS[0], accessPoints.get(1).getSsid());
}
use of android.net.wifi.ScanResult in project android_frameworks_base by AOSPA.
the class WifiTrackerTest method testSavedOnlyNoLooper.
/**
* This tests the case where Settings runs this on a non-looper thread for indexing.
*/
public void testSavedOnlyNoLooper() {
mWifiTracker = new WifiTracker(mContext, mWifiListener, mLooper, true, false, true, mWifiManager, null);
mWifiTracker.mScanner = mWifiTracker.new Scanner();
List<WifiConfiguration> wifiConfigs = new ArrayList<WifiConfiguration>();
List<ScanResult> scanResults = new ArrayList<ScanResult>();
generateTestNetworks(wifiConfigs, scanResults, true);
// Send all of the configs and scan results to the tracker.
Mockito.when(mWifiManager.getConfiguredNetworks()).thenReturn(wifiConfigs);
Mockito.when(mWifiManager.getScanResults()).thenReturn(scanResults);
mWifiTracker.forceUpdate();
List<AccessPoint> accessPoints = mWifiTracker.getAccessPoints();
// Only expect the first two to come back in the results.
assertEquals("Expected number of results", 2, accessPoints.size());
assertEquals(TEST_SSIDS[1], accessPoints.get(0).getSsid());
assertEquals(TEST_SSIDS[0], accessPoints.get(1).getSsid());
}
use of android.net.wifi.ScanResult in project android_frameworks_base by AOSPA.
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 AOSPA.
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 by cSploit.
the class WifiScannerFragment method onListItemClick.
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
final ScanResult result = mAdapter.getItem(position);
if (result != null) {
final Keygen keygen = mWifiMatcher.getKeygen(result);
mPreviousConfig = NetworkManager.getWifiConfiguration(mWifiManager, result);
if (mPreviousConfig != null) {
mWifiManager.removeNetwork(mPreviousConfig.networkId);
}
if (keygen != null && (result.capabilities.contains("WEP") || result.capabilities.contains("WPA"))) {
mKeyList.clear();
new WifiCrackDialog(result.SSID, getResources().getString(R.string.enter_key_or_crack), getActivity(), new WifiCrackDialogListener() {
@Override
public void onManualConnect(String key) {
mCurrentNetworkId = performConnection(result, key);
if (mCurrentNetworkId != -1)
mConnectionReceiver.register(getActivity());
else
mConnectionReceiver.unregister();
}
@Override
public void onCrack() {
performCracking(keygen, result);
}
}).show();
} else {
if (result.capabilities.contains("WEP") || result.capabilities.contains("WPA")) {
new InputDialog(result.SSID, getString(R.string.enter_wifi_key), null, true, true, getActivity(), new InputDialogListener() {
@Override
public void onInputEntered(String input) {
mCurrentNetworkId = performConnection(result, input);
if (mCurrentNetworkId != -1)
mConnectionReceiver.register(getActivity());
else
mConnectionReceiver.unregister();
}
}).show();
} else
performConnection(result, null);
}
}
}
Aggregations