use of android.net.wifi.ScanResult in project android_frameworks_base by DirtyUnicorns.
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 DirtyUnicorns.
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 ParanoidAndroid.
the class WifiStressTest method testWifiScanning.
/**
* Stress Wifi Scanning
* TODO: test the scanning quality for each frequency band
*/
@LargeTest
public void testWifiScanning() {
int scanTimeSum = 0;
int i;
// count times of given ssid appear in scan results.
int ssidAppearInScanResultsCount = 0;
for (i = 0; i < mScanIterations; i++) {
log("testWifiScanning: iteration: " + i);
int averageScanTime = 0;
if (i > 0) {
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));
long startTime = System.currentTimeMillis();
mAct.scanResultAvailable = false;
assertTrue("start scan failed", mAct.mWifiManager.startScan());
while (true) {
if ((System.currentTimeMillis() - startTime) > ConnectivityManagerTestActivity.WIFI_SCAN_TIMEOUT) {
fail("Wifi scanning takes more than " + ConnectivityManagerTestActivity.WIFI_SCAN_TIMEOUT + " ms");
}
synchronized (mAct) {
try {
mAct.wait(ConnectivityManagerTestActivity.WAIT_FOR_SCAN_RESULT);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (mAct.scanResultAvailable) {
long scanTime = (System.currentTimeMillis() - startTime);
scanTimeSum += scanTime;
break;
}
}
}
if ((mAct.mWifiManager.getScanResults() == null) || (mAct.mWifiManager.getScanResults().size() <= 0)) {
fail("Scan results are empty ");
}
List<ScanResult> netList = mAct.mWifiManager.getScanResults();
if (netList != null) {
log("size of scan result list: " + netList.size());
for (int s = 0; s < netList.size(); s++) {
ScanResult sr = netList.get(s);
log(String.format("scan result for %s is: %s", sr.SSID, sr.toString()));
log(String.format("signal level for %s is %d ", sr.SSID, sr.level));
if (sr.SSID.equals(mSsid)) {
ssidAppearInScanResultsCount += 1;
log("Number of times " + mSsid + " appear in the scan list: " + ssidAppearInScanResultsCount);
break;
}
}
}
}
if (i == mScanIterations) {
writeOutput(String.format("iteration %d out of %d", i, mScanIterations));
writeOutput(String.format("average scanning time is %d", scanTimeSum / mScanIterations));
writeOutput(String.format("ssid appear %d out of %d scan iterations", ssidAppearInScanResultsCount, mScanIterations));
}
}
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 routerkeygenAndroid by routerkeygen.
the class WifiListAdapter method getView.
public View getView(int position, View convertView, ViewGroup parent) {
final ScanResult wifi = getItem(position);
if (convertView == null) {
convertView = inflater.inflate(R.layout.item_list_wifi, parent, false);
convertView.setTag(new ViewHolder((TextView) convertView.findViewById(R.id.wifiName), (TextView) convertView.findViewById(R.id.wifiMAC), (ImageView) convertView.findViewById(R.id.strenght)));
}
final ViewHolder holder = (ViewHolder) convertView.getTag();
holder.ssid.setText(wifi.SSID);
holder.ssid.setTypeface(typeface);
holder.ssid.setSelected(true);
holder.ssid.setEllipsize(TruncateAt.MARQUEE);
holder.mac.setText(wifi.BSSID.toUpperCase(Locale.getDefault()));
holder.mac.setTypeface(typeface);
holder.mac.setSelected(true);
holder.mac.setEllipsize(TruncateAt.MARQUEE);
final int strenght = WifiManager.calculateSignalLevel(wifi.level, 4);
if (isLocked(wifi)) {
holder.networkStrenght.setImageDrawable(wifiSignalLocked[strenght]);
} else {
holder.networkStrenght.setImageDrawable(wifiSignal[strenght]);
}
return convertView;
}
Aggregations