Search in sources :

Example 56 with ScanResult

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());
    }
}
Also used : Scanner(com.android.settingslib.wifi.WifiTracker.Scanner) ScanResult(android.net.wifi.ScanResult) WifiConfiguration(android.net.wifi.WifiConfiguration) ArrayList(java.util.ArrayList)

Example 57 with ScanResult

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);
}
Also used : ScanResult(android.net.wifi.ScanResult) WifiInfo(android.net.wifi.WifiInfo)

Example 58 with ScanResult

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));
    }
}
Also used : ScanResult(android.net.wifi.ScanResult) Bundle(android.os.Bundle) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 59 with ScanResult

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();
}
Also used : ScanResult(android.net.wifi.ScanResult)

Example 60 with ScanResult

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);
}
Also used : ScanResult(android.net.wifi.ScanResult) AccessPoint(com.android.settingslib.wifi.AccessPoint)

Aggregations

ScanResult (android.net.wifi.ScanResult)75 WifiConfiguration (android.net.wifi.WifiConfiguration)27 ArrayList (java.util.ArrayList)27 Scanner (com.android.settingslib.wifi.WifiTracker.Scanner)20 WifiManager (android.net.wifi.WifiManager)7 WifiInfo (android.net.wifi.WifiInfo)6 LargeTest (android.test.suitebuilder.annotation.LargeTest)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6 Bundle (android.os.Bundle)5 SpannableString (android.text.SpannableString)5 DhcpInfo (android.net.DhcpInfo)1 NetworkInfo (android.net.NetworkInfo)1 Parcelable (android.os.Parcelable)1 NeighboringCellInfo (android.telephony.NeighboringCellInfo)1 TelephonyManager (android.telephony.TelephonyManager)1 GsmCellLocation (android.telephony.gsm.GsmCellLocation)1 ImageView (android.widget.ImageView)1 RelativeLayout (android.widget.RelativeLayout)1 TextView (android.widget.TextView)1