Search in sources :

Example 41 with ScanResult

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

the class WifiTrackerTest method testSavedOnly.

public void testSavedOnly() {
    mWifiTracker = new WifiTracker(mContext, mWifiListener, mLooper, true, false, true, mWifiManager, mMainLooper);
    mWifiTracker.mScanner = mWifiTracker.new Scanner();
    List<WifiConfiguration> wifiConfigs = new ArrayList<WifiConfiguration>();
    List<ScanResult> scanResults = new ArrayList<ScanResult>();
    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);
    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 42 with ScanResult

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

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

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

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

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

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

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

the class WifiScannerFragment method onListItemClick.

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    final ScanResult result = mAdapter.getItem(position);
    if (result != null) {
        final Keygen keygen = mWifiMatcher.getKeygen(result);
        mPreviousConfig = NetworkManager.getWifiConfiguration(mWifiManager, result);
        if (mPreviousConfig != null) {
            mWifiManager.removeNetwork(mPreviousConfig.networkId);
        }
        if (keygen != null && (result.capabilities.contains("WEP") || result.capabilities.contains("WPA"))) {
            mKeyList.clear();
            new WifiCrackDialog(result.SSID, getResources().getString(R.string.enter_key_or_crack), getActivity(), new WifiCrackDialogListener() {

                @Override
                public void onManualConnect(String key) {
                    mCurrentNetworkId = performConnection(result, key);
                    if (mCurrentNetworkId != -1)
                        mConnectionReceiver.register(getActivity());
                    else
                        mConnectionReceiver.unregister();
                }

                @Override
                public void onCrack() {
                    performCracking(keygen, result);
                }
            }).show();
        } else {
            if (result.capabilities.contains("WEP") || result.capabilities.contains("WPA")) {
                new InputDialog(result.SSID, getString(R.string.enter_wifi_key), null, true, true, getActivity(), new InputDialogListener() {

                    @Override
                    public void onInputEntered(String input) {
                        mCurrentNetworkId = performConnection(result, input);
                        if (mCurrentNetworkId != -1)
                            mConnectionReceiver.register(getActivity());
                        else
                            mConnectionReceiver.unregister();
                    }
                }).show();
            } else
                performConnection(result, null);
        }
    }
}
Also used : InputDialogListener(org.csploit.android.gui.dialogs.InputDialog.InputDialogListener) ScanResult(android.net.wifi.ScanResult) Keygen(org.csploit.android.wifi.Keygen) InputDialog(org.csploit.android.gui.dialogs.InputDialog) WifiCrackDialog(org.csploit.android.gui.dialogs.WifiCrackDialog) WifiCrackDialogListener(org.csploit.android.gui.dialogs.WifiCrackDialog.WifiCrackDialogListener)

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