Search in sources :

Example 91 with ScanResult

use of android.net.wifi.ScanResult in project android_frameworks_base by crdroidandroid.

the class WifiTracker method fetchScanResults.

private Collection<ScanResult> fetchScanResults() {
    mScanId++;
    final List<ScanResult> newResults = mWifiManager.getScanResults();
    if (newResults == null) {
        return null;
    }
    for (ScanResult newResult : newResults) {
        if (newResult.SSID == null || newResult.SSID.isEmpty()) {
            continue;
        }
        mScanResultCache.put(newResult.BSSID, newResult);
        mSeenBssids.put(newResult.BSSID, mScanId);
    }
    if (mScanId > NUM_SCANS_TO_CONFIRM_AP_LOSS) {
        if (DBG)
            Log.d(TAG, "------ Dumping SSIDs that were expired on this scan ------");
        Integer threshold = mScanId - NUM_SCANS_TO_CONFIRM_AP_LOSS;
        for (Iterator<Map.Entry<String, Integer>> it = mSeenBssids.entrySet().iterator(); it.hasNext(); ) /* nothing */
        {
            Map.Entry<String, Integer> e = it.next();
            if (e.getValue() < threshold) {
                ScanResult result = mScanResultCache.get(e.getKey());
                if (DBG)
                    Log.d(TAG, "Removing " + e.getKey() + ":(" + result.SSID + ")");
                mScanResultCache.remove(e.getKey());
                it.remove();
            }
        }
        if (DBG)
            Log.d(TAG, "---- Done Dumping SSIDs that were expired on this scan ----");
    }
    return mScanResultCache.values();
}
Also used : ScanResult(android.net.wifi.ScanResult) HashMap(java.util.HashMap) Map(java.util.Map)

Example 92 with ScanResult

use of android.net.wifi.ScanResult in project PhoneProfilesPlus by henrichg.

the class WifiScanJob method fillScanResults.

static void fillScanResults(Context context) {
    List<WifiSSIDData> scanResults = new ArrayList<>();
    boolean save = false;
    if (wifi == null)
        wifi = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
    if (Permissions.checkLocation(context)) {
        List<ScanResult> _scanResults = wifi.getScanResults();
        PPApplication.logE("%%%% WifiScanJob.fillScanResults", "_scanResults=" + _scanResults);
        if (_scanResults != null) {
            // PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
            // boolean isScreenOn = pm.isScreenOn();
            // PPApplication.logE("%%%% WifiScanJob.fillScanResults", "isScreenOn="+isScreenOn);
            // if ((android.os.Build.VERSION.SDK_INT < 21) || (_scanResults.size() > 0) || isScreenOn) {
            save = true;
            scanResults.clear();
            for (ScanResult device : _scanResults) {
                boolean found = false;
                for (WifiSSIDData _device : scanResults) {
                    if (_device.bssid.equals(device.BSSID)) {
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    scanResults.add(new WifiSSIDData(device.SSID, device.BSSID, false));
                }
            }
        // }
        } else
            PPApplication.logE("%%%% WifiScanJob.fillScanResults", "_scanResults=null");
    } else
        save = true;
    if (save)
        saveScanResults(context, scanResults);
}
Also used : WifiManager(android.net.wifi.WifiManager) ScanResult(android.net.wifi.ScanResult) ArrayList(java.util.ArrayList)

Example 93 with ScanResult

use of android.net.wifi.ScanResult in project wiseasily by eFishery.

the class ScanWifi method onAPChanged.

@Override
public void onAPChanged(List<ScanResult> scanResults) {
    if (callback != null) {
        List<ScanResult> scanResultsFilter = new ArrayList<>();
        for (ScanResult scanResult : scanResults) {
            if (scanFilter == null || scanFilter.matchesStart(scanResult)) {
                scanResultsFilter.add(scanResult);
            }
        }
        callback.onAPChanged(scanResultsFilter);
    }
}
Also used : ScanResult(android.net.wifi.ScanResult) ArrayList(java.util.ArrayList)

Example 94 with ScanResult

use of android.net.wifi.ScanResult in project BaseProject by fly803.

the class AppNetworkMgr method getScanResultsByBSSID.

/**
 * 过滤扫描结果
 * @param context
 * @param bssid
 * @return
 */
public static ScanResult getScanResultsByBSSID(Context context, String bssid) {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    ScanResult scanResult = null;
    boolean f = wifiManager.startScan();
    if (!f) {
        getScanResultsByBSSID(context, bssid);
    }
    List<ScanResult> list = wifiManager.getScanResults();
    if (list != null) {
        for (int i = 0; i < list.size(); i++) {
            scanResult = list.get(i);
            if (scanResult.BSSID.equals(bssid)) {
                break;
            }
        }
    }
    return scanResult;
}
Also used : WifiManager(android.net.wifi.WifiManager) ScanResult(android.net.wifi.ScanResult)

Example 95 with ScanResult

use of android.net.wifi.ScanResult in project android_packages_apps_Settings by DirtyUnicorns.

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)119 ArrayList (java.util.ArrayList)42 WifiConfiguration (android.net.wifi.WifiConfiguration)29 Scanner (com.android.settingslib.wifi.WifiTracker.Scanner)20 WifiManager (android.net.wifi.WifiManager)14 Test (org.junit.Test)11 AccessPoint (com.android.settingslib.wifi.AccessPoint)9 WifiInfo (android.net.wifi.WifiInfo)8 HashMap (java.util.HashMap)7 LargeTest (android.test.suitebuilder.annotation.LargeTest)6 Map (java.util.Map)6 Bundle (android.os.Bundle)5 SpannableString (android.text.SpannableString)5 Button (android.widget.Button)4 AlertDialog (androidx.appcompat.app.AlertDialog)4 Parcel (android.os.Parcel)3 InOrder (org.mockito.InOrder)3 SuppressLint (android.annotation.SuppressLint)2 GsmCellLocation (android.telephony.gsm.GsmCellLocation)2 ImageView (android.widget.ImageView)2