Search in sources :

Example 11 with ScanResult

use of android.net.wifi.ScanResult in project platform_frameworks_base by android.

the class WifiTracker method fetchScanResults.

private Collection<ScanResult> fetchScanResults() {
    mScanId++;
    final List<ScanResult> newResults = mWifiManager.getScanResults();
    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 12 with ScanResult

use of android.net.wifi.ScanResult in project platform_frameworks_base by android.

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

use of android.net.wifi.ScanResult in project platform_frameworks_base by android.

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

use of android.net.wifi.ScanResult in project platform_frameworks_base by android.

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

use of android.net.wifi.ScanResult in project platform_frameworks_base by android.

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