Search in sources :

Example 81 with ScanResult

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

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 82 with ScanResult

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

the class WifiTrackerTest method testSavedOnlyNoLooper.

/**
     * This tests the case where Settings runs this on a non-looper thread for indexing.
     */
public void testSavedOnlyNoLooper() {
    mWifiTracker = new WifiTracker(mContext, mWifiListener, mLooper, true, false, true, mWifiManager, null);
    mWifiTracker.mScanner = mWifiTracker.new Scanner();
    List<WifiConfiguration> wifiConfigs = new ArrayList<WifiConfiguration>();
    List<ScanResult> scanResults = new ArrayList<ScanResult>();
    generateTestNetworks(wifiConfigs, scanResults, true);
    // Send all of the configs and scan results to the tracker.
    Mockito.when(mWifiManager.getConfiguredNetworks()).thenReturn(wifiConfigs);
    Mockito.when(mWifiManager.getScanResults()).thenReturn(scanResults);
    mWifiTracker.forceUpdate();
    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 83 with ScanResult

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

the class WifiTrackerTest method testNonEphemeralConnected.

public void testNonEphemeralConnected() {
    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>();
    generateTestNetworks(wifiConfigs, scanResults, false);
    // 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);
    // Do this twice to catch a bug that was happening in the caching, making things ephemeral.
    sendScanResultsAndProcess(true);
    List<AccessPoint> accessPoints = mWifiTracker.getAccessPoints();
    assertEquals("Expected number of results", NUM_NETWORKS - 1, accessPoints.size());
    assertFalse("Connection is not ephemeral", accessPoints.get(0).isEphemeral());
    assertTrue("Connected to wifi", accessPoints.get(0).isActive());
}
Also used : Scanner(com.android.settingslib.wifi.WifiTracker.Scanner) ScanResult(android.net.wifi.ScanResult) WifiConfiguration(android.net.wifi.WifiConfiguration) ArrayList(java.util.ArrayList)

Example 84 with ScanResult

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

the class AccessPoint method getVisibilityStatus.

/**
     * Returns the visibility status of the WifiConfiguration.
     *
     * @return autojoin debugging information
     * TODO: use a string formatter
     * ["rssi 5Ghz", "num results on 5GHz" / "rssi 5Ghz", "num results on 5GHz"]
     * For instance [-40,5/-30,2]
     */
private String getVisibilityStatus() {
    StringBuilder visibility = new StringBuilder();
    StringBuilder scans24GHz = null;
    StringBuilder scans5GHz = null;
    String bssid = null;
    long now = System.currentTimeMillis();
    if (mInfo != null) {
        bssid = mInfo.getBSSID();
        if (bssid != null) {
            visibility.append(" ").append(bssid);
        }
        visibility.append(" rssi=").append(mInfo.getRssi());
        visibility.append(" ");
        visibility.append(" score=").append(mInfo.score);
        visibility.append(String.format(" tx=%.1f,", mInfo.txSuccessRate));
        visibility.append(String.format("%.1f,", mInfo.txRetriesRate));
        visibility.append(String.format("%.1f ", mInfo.txBadRate));
        visibility.append(String.format("rx=%.1f", mInfo.rxSuccessRate));
    }
    int rssi5 = WifiConfiguration.INVALID_RSSI;
    int rssi24 = WifiConfiguration.INVALID_RSSI;
    int num5 = 0;
    int num24 = 0;
    int numBlackListed = 0;
    // Number scan results we included in the string
    int n24 = 0;
    // Number scan results we included in the string
    int n5 = 0;
    Map<String, ScanResult> list = mScanResultCache.snapshot();
    // TODO: sort list by RSSI or age
    for (ScanResult result : list.values()) {
        if (result.frequency >= LOWER_FREQ_5GHZ && result.frequency <= HIGHER_FREQ_5GHZ) {
            // Strictly speaking: [4915, 5825]
            // number of known BSSID on 5GHz band
            num5 = num5 + 1;
        } else if (result.frequency >= LOWER_FREQ_24GHZ && result.frequency <= HIGHER_FREQ_24GHZ) {
            // Strictly speaking: [2412, 2482]
            // number of known BSSID on 2.4Ghz band
            num24 = num24 + 1;
        }
        if (result.frequency >= LOWER_FREQ_5GHZ && result.frequency <= HIGHER_FREQ_5GHZ) {
            if (result.level > rssi5) {
                rssi5 = result.level;
            }
            if (n5 < 4) {
                if (scans5GHz == null)
                    scans5GHz = new StringBuilder();
                scans5GHz.append(" \n{").append(result.BSSID);
                if (bssid != null && result.BSSID.equals(bssid))
                    scans5GHz.append("*");
                scans5GHz.append("=").append(result.frequency);
                scans5GHz.append(",").append(result.level);
                scans5GHz.append("}");
                n5++;
            }
        } else if (result.frequency >= LOWER_FREQ_24GHZ && result.frequency <= HIGHER_FREQ_24GHZ) {
            if (result.level > rssi24) {
                rssi24 = result.level;
            }
            if (n24 < 4) {
                if (scans24GHz == null)
                    scans24GHz = new StringBuilder();
                scans24GHz.append(" \n{").append(result.BSSID);
                if (bssid != null && result.BSSID.equals(bssid))
                    scans24GHz.append("*");
                scans24GHz.append("=").append(result.frequency);
                scans24GHz.append(",").append(result.level);
                scans24GHz.append("}");
                n24++;
            }
        }
    }
    visibility.append(" [");
    if (num24 > 0) {
        visibility.append("(").append(num24).append(")");
        if (n24 <= 4) {
            if (scans24GHz != null) {
                visibility.append(scans24GHz.toString());
            }
        } else {
            visibility.append("max=").append(rssi24);
            if (scans24GHz != null) {
                visibility.append(",").append(scans24GHz.toString());
            }
        }
    }
    visibility.append(";");
    if (num5 > 0) {
        visibility.append("(").append(num5).append(")");
        if (n5 <= 4) {
            if (scans5GHz != null) {
                visibility.append(scans5GHz.toString());
            }
        } else {
            visibility.append("max=").append(rssi5);
            if (scans5GHz != null) {
                visibility.append(",").append(scans5GHz.toString());
            }
        }
    }
    if (numBlackListed > 0)
        visibility.append("!").append(numBlackListed);
    visibility.append("]");
    return visibility.toString();
}
Also used : ScanResult(android.net.wifi.ScanResult) SpannableString(android.text.SpannableString)

Example 85 with ScanResult

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

the class WifiTracker method updateAccessPoints.

private void updateAccessPoints() {
    // Swap the current access points into a cached list.
    List<AccessPoint> cachedAccessPoints = getAccessPoints();
    ArrayList<AccessPoint> accessPoints = new ArrayList<>();
    // Clear out the configs so we don't think something is saved when it isn't.
    for (AccessPoint accessPoint : cachedAccessPoints) {
        accessPoint.clearConfig();
    }
    /** Lookup table to more quickly update AccessPoints by only considering objects with the
         * correct SSID.  Maps SSID -> List of AccessPoints with the given SSID.  */
    Multimap<String, AccessPoint> apMap = new Multimap<String, AccessPoint>();
    WifiConfiguration connectionConfig = null;
    if (mLastInfo != null) {
        connectionConfig = getWifiConfigurationForNetworkId(mLastInfo.getNetworkId());
    }
    final Collection<ScanResult> results = fetchScanResults();
    final List<WifiConfiguration> configs = mWifiManager.getConfiguredNetworks();
    if (configs != null) {
        mSavedNetworksExist = configs.size() != 0;
        for (WifiConfiguration config : configs) {
            if (config.selfAdded && config.numAssociation == 0) {
                continue;
            }
            AccessPoint accessPoint = getCachedOrCreate(config, cachedAccessPoints);
            accessPoint.update(connectionConfig, mLastInfo, mLastNetworkInfo);
            if (mIncludeSaved) {
                // If saved network not present in scan result then set its Rssi to MAX_VALUE
                boolean apFound = false;
                for (ScanResult result : results) {
                    if (result.SSID.equals(accessPoint.getSsidStr())) {
                        apFound = true;
                        break;
                    }
                }
                if (!apFound) {
                    accessPoint.setRssi(Integer.MAX_VALUE);
                }
                accessPoints.add(accessPoint);
                apMap.put(accessPoint.getSsidStr(), accessPoint);
            } else {
                // If we aren't using saved networks, drop them into the cache so that
                // we have access to their saved info.
                cachedAccessPoints.add(accessPoint);
            }
        }
    }
    if (results != null) {
        for (ScanResult result : results) {
            // Ignore hidden and ad-hoc networks.
            if (result.SSID == null || result.SSID.length() == 0 || result.capabilities.contains("[IBSS]")) {
                continue;
            }
            boolean found = false;
            for (AccessPoint accessPoint : apMap.getAll(result.SSID)) {
                if (accessPoint.update(result)) {
                    found = true;
                    break;
                }
            }
            if (!found && mIncludeScans) {
                AccessPoint accessPoint = getCachedOrCreate(result, cachedAccessPoints);
                if (mLastInfo != null && mLastNetworkInfo != null) {
                    accessPoint.update(connectionConfig, mLastInfo, mLastNetworkInfo);
                }
                if (result.isPasspointNetwork()) {
                    // name).
                    try {
                        WifiConfiguration config = mWifiManager.getMatchingWifiConfig(result);
                        if (config != null) {
                            accessPoint.update(config);
                        }
                    } catch (UnsupportedOperationException e) {
                    // Passpoint not supported on the device.
                    }
                }
                accessPoints.add(accessPoint);
                apMap.put(accessPoint.getSsidStr(), accessPoint);
            }
        }
    }
    // Pre-sort accessPoints to speed preference insertion
    Collections.sort(accessPoints);
    // Log accesspoints that were deleted
    if (DBG)
        Log.d(TAG, "------ Dumping SSIDs that were not seen on this scan ------");
    for (AccessPoint prevAccessPoint : mAccessPoints) {
        if (prevAccessPoint.getSsid() == null)
            continue;
        String prevSsid = prevAccessPoint.getSsidStr();
        boolean found = false;
        for (AccessPoint newAccessPoint : accessPoints) {
            if (newAccessPoint.getSsid() != null && newAccessPoint.getSsid().equals(prevSsid)) {
                found = true;
                break;
            }
        }
        if (!found)
            if (DBG)
                Log.d(TAG, "Did not find " + prevSsid + " in this scan");
    }
    if (DBG)
        Log.d(TAG, "---- Done dumping SSIDs that were not seen on this scan ----");
    mAccessPoints = accessPoints;
    mMainHandler.sendEmptyMessage(MainHandler.MSG_ACCESS_POINT_CHANGED);
}
Also used : ScanResult(android.net.wifi.ScanResult) WifiConfiguration(android.net.wifi.WifiConfiguration) ArrayList(java.util.ArrayList)

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