Search in sources :

Example 61 with ScanResult

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

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

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

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

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

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

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

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)

Example 65 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)

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