Search in sources :

Example 26 with ScanResult

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

Example 27 with ScanResult

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

Example 28 with ScanResult

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

Example 29 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 30 with ScanResult

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

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