Search in sources :

Example 21 with Scanner

use of com.android.settingslib.wifi.WifiTracker.Scanner 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 22 with Scanner

use of com.android.settingslib.wifi.WifiTracker.Scanner 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 23 with Scanner

use of com.android.settingslib.wifi.WifiTracker.Scanner 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 24 with Scanner

use of com.android.settingslib.wifi.WifiTracker.Scanner 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 25 with Scanner

use of com.android.settingslib.wifi.WifiTracker.Scanner in project android_frameworks_base by crdroidandroid.

the class WifiTrackerTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    mWifiManager = Mockito.mock(WifiManager.class);
    mWifiListener = Mockito.mock(WifiListener.class);
    mWorkerThread = new HandlerThread("TestHandlerThread");
    mWorkerThread.start();
    mLooper = mWorkerThread.getLooper();
    mMainThread = new HandlerThread("TestHandlerThread");
    mMainThread.start();
    mMainLooper = mMainThread.getLooper();
    mWifiTracker = new WifiTracker(mContext, mWifiListener, mLooper, true, true, true, mWifiManager, mMainLooper);
    mWifiTracker.mScanner = mWifiTracker.new Scanner();
    Mockito.when(mWifiManager.isWifiEnabled()).thenReturn(true);
}
Also used : WifiManager(android.net.wifi.WifiManager) WifiListener(com.android.settingslib.wifi.WifiTracker.WifiListener) Scanner(com.android.settingslib.wifi.WifiTracker.Scanner) HandlerThread(android.os.HandlerThread)

Aggregations

Scanner (com.android.settingslib.wifi.WifiTracker.Scanner)25 ScanResult (android.net.wifi.ScanResult)20 WifiConfiguration (android.net.wifi.WifiConfiguration)20 ArrayList (java.util.ArrayList)20 WifiManager (android.net.wifi.WifiManager)5 HandlerThread (android.os.HandlerThread)5 WifiListener (com.android.settingslib.wifi.WifiTracker.WifiListener)5