use of android.net.wifi.ScanResult in project android_frameworks_base by AOSPA.
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 AOSPA.
the class AccessPointTest method testOnAccessPointChangedCallback.
public void testOnAccessPointChangedCallback() {
WifiInfo wifiInfo = Mockito.mock(WifiInfo.class);
Mockito.when(wifiInfo.getNetworkId()).thenReturn(NETWORK_ID);
mAccessPoint.update(wifiInfo, null);
verifyOnAccessPointsCallback(1);
mAccessPoint.update(null, null);
verifyOnAccessPointsCallback(2);
ScanResult result = new ScanResult();
result.capabilities = "";
result.SSID = TEST_SSID;
mAccessPoint.update(result);
verifyOnAccessPointsCallback(3);
}
use of android.net.wifi.ScanResult in project android_frameworks_base by AOSPA.
the class WifiStressTest method testWifiScanning.
/**
* Stress Wifi Scanning
* TODO: test the scanning quality for each frequency band
*/
@LargeTest
public void testWifiScanning() {
long scanTimeSum = 0, i, averageScanTime = -1;
// count times of given ssid appear in scan results.
int ssidAppearInScanResultsCount = 0;
for (i = 1; i <= mScanIterations; i++) {
logv("testWifiScanning: iteration: " + i);
averageScanTime = scanTimeSum / i;
writeOutput(String.format("iteration %d out of %d", i, mScanIterations));
writeOutput(String.format("average scanning time is %d", averageScanTime));
writeOutput(String.format("ssid appear %d out of %d scan iterations", ssidAppearInScanResultsCount, i));
List<ScanResult> scanResultLocal = null;
// wait for a scan result
long start = 0;
synchronized (mWifiScanResultLock) {
start = SystemClock.uptimeMillis();
assertTrue("start scan failed", mWifiManager.startScan());
try {
mWifiScanResultLock.wait(WAIT_FOR_SCAN_RESULT);
} catch (InterruptedException e) {
// ignore
}
scanTimeSum += SystemClock.uptimeMillis() - start;
// save the scan result while in lock
scanResultLocal = mLastScanResult;
}
if (scanResultLocal == null || scanResultLocal.isEmpty()) {
fail("Scan results are empty ");
}
logv("size of scan result list: " + scanResultLocal.size());
for (ScanResult sr : scanResultLocal) {
logv(String.format("scan result: " + sr.toString()));
if (mSsid.equals(sr.SSID)) {
ssidAppearInScanResultsCount += 1;
break;
}
}
}
Bundle result = new Bundle();
result.putLong("actual-iterations", i - 1);
result.putLong("avg-scan-time", averageScanTime);
result.putInt("ap-discovered", ssidAppearInScanResultsCount);
getInstrumentation().sendStatus(Activity.RESULT_FIRST_USER, result);
if (i == mScanIterations + 1) {
writeOutput(String.format("iteration %d out of %d", i - 1, mScanIterations));
writeOutput(String.format("average scanning time is %d", scanTimeSum / (i - 1)));
writeOutput(String.format("ssid appear %d out of %d scan iterations", ssidAppearInScanResultsCount, i - 1));
}
}
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 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);
}
Aggregations