Search in sources :

Example 61 with WifiConfiguration

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

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

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

the class SettingsBackupAgent method getWifiSupplicant.

private byte[] getWifiSupplicant(String filename) {
    BufferedReader br = null;
    try {
        File file = new File(filename);
        if (!file.exists()) {
            return EMPTY_DATA;
        }
        WifiManager wifi = (WifiManager) getSystemService(WIFI_SERVICE);
        List<WifiConfiguration> configs = wifi.getConfiguredNetworks();
        WifiNetworkSettings fromFile = new WifiNetworkSettings();
        br = new BufferedReader(new FileReader(file));
        fromFile.readNetworks(br, configs, false);
        // Write the parsed networks into a packed byte array
        if (fromFile.mKnownNetworks.size() > 0) {
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            OutputStreamWriter out = new OutputStreamWriter(bos);
            fromFile.write(out);
            out.flush();
            return bos.toByteArray();
        } else {
            return EMPTY_DATA;
        }
    } catch (IOException ioe) {
        Log.w(TAG, "Couldn't backup " + filename);
        return EMPTY_DATA;
    } finally {
        IoUtils.closeQuietly(br);
    }
}
Also used : WifiManager(android.net.wifi.WifiManager) WifiConfiguration(android.net.wifi.WifiConfiguration) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) OutputStreamWriter(java.io.OutputStreamWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) File(java.io.File)

Example 63 with WifiConfiguration

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

the class WifiConfigurationHelper method createGenericConfig.

/**
     * Create a generic {@link WifiConfiguration} used by the other create methods.
     */
private static WifiConfiguration createGenericConfig(String ssid) {
    WifiConfiguration config = new WifiConfiguration();
    config.SSID = quotedString(ssid);
    config.setIpAssignment(IpAssignment.DHCP);
    config.setProxySettings(ProxySettings.NONE);
    return config;
}
Also used : WifiConfiguration(android.net.wifi.WifiConfiguration)

Example 64 with WifiConfiguration

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

the class WifiConfigurationHelper method getWifiConfiguration.

/**
     * Parse a {@link JSONObject} and return the wifi configuration.
     *
     * @throws IllegalArgumentException if any mandatory fields are missing.
     */
private static WifiConfiguration getWifiConfiguration(JSONObject jsonConfig) throws JSONException {
    String ssid = jsonConfig.getString("ssid");
    String password = null;
    WifiConfiguration config;
    int securityType = getSecurityType(jsonConfig.getString("security"));
    switch(securityType) {
        case NONE:
            config = createOpenConfig(ssid);
            break;
        case WEP:
            password = jsonConfig.getString("password");
            config = createWepConfig(ssid, password);
            break;
        case PSK:
            password = jsonConfig.getString("password");
            config = createPskConfig(ssid, password);
            break;
        case EAP:
            password = jsonConfig.getString("password");
            int eapMethod = getEapMethod(jsonConfig.getString("eap"));
            Integer phase2 = null;
            if (jsonConfig.has("phase2")) {
                phase2 = getPhase2(jsonConfig.getString("phase2"));
            }
            String identity = null;
            if (jsonConfig.has("identity")) {
                identity = jsonConfig.getString("identity");
            }
            String anonymousIdentity = null;
            if (jsonConfig.has("anonymous_identity")) {
                anonymousIdentity = jsonConfig.getString("anonymous_identity");
            }
            String caCert = null;
            if (jsonConfig.has("ca_cert")) {
                caCert = (jsonConfig.getString("ca_cert"));
            }
            String clientCert = null;
            if (jsonConfig.has("client_cert")) {
                clientCert = jsonConfig.getString("client_cert");
            }
            config = createEapConfig(ssid, password, eapMethod, phase2, identity, anonymousIdentity, caCert, clientCert);
            break;
        default:
            // Should never reach here as getSecurityType will already throw an exception
            throw new IllegalArgumentException();
    }
    if (jsonConfig.has("ip")) {
        StaticIpConfiguration staticIpConfig = new StaticIpConfiguration();
        InetAddress ipAddress = getInetAddress(jsonConfig.getString("ip"));
        int prefixLength = getPrefixLength(jsonConfig.getInt("prefix_length"));
        staticIpConfig.ipAddress = new LinkAddress(ipAddress, prefixLength);
        staticIpConfig.gateway = getInetAddress(jsonConfig.getString("gateway"));
        staticIpConfig.dnsServers.add(getInetAddress(jsonConfig.getString("dns1")));
        staticIpConfig.dnsServers.add(getInetAddress(jsonConfig.getString("dns2")));
        config.setIpAssignment(IpAssignment.STATIC);
        config.setStaticIpConfiguration(staticIpConfig);
    } else {
        config.setIpAssignment(IpAssignment.DHCP);
    }
    config.setProxySettings(ProxySettings.NONE);
    return config;
}
Also used : LinkAddress(android.net.LinkAddress) WifiConfiguration(android.net.wifi.WifiConfiguration) StaticIpConfiguration(android.net.StaticIpConfiguration) InetAddress(java.net.InetAddress)

Example 65 with WifiConfiguration

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

the class WifiConfigurationHelper method createWepConfig.

/**
     * Create a {@link WifiConfiguration} for a WEP secured network
     *
     * @param ssid The SSID of the wifi network
     * @param password Either a 10, 26, or 58 character hex string or the plain text password
     * @return The {@link WifiConfiguration}
     */
public static WifiConfiguration createWepConfig(String ssid, String password) {
    WifiConfiguration config = createGenericConfig(ssid);
    if (isHex(password, 10) || isHex(password, 26) || isHex(password, 58)) {
        config.wepKeys[0] = password;
    } else {
        config.wepKeys[0] = quotedString(password);
    }
    config.allowedKeyManagement.set(KeyMgmt.NONE);
    config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
    config.allowedAuthAlgorithms.set(AuthAlgorithm.SHARED);
    return config;
}
Also used : WifiConfiguration(android.net.wifi.WifiConfiguration)

Aggregations

WifiConfiguration (android.net.wifi.WifiConfiguration)569 WifiManager (android.net.wifi.WifiManager)88 LargeTest (android.test.suitebuilder.annotation.LargeTest)53 IOException (java.io.IOException)48 ArrayList (java.util.ArrayList)47 AccessPoint (com.android.settingslib.wifi.AccessPoint)46 Test (org.junit.Test)45 WifiEnterpriseConfig (android.net.wifi.WifiEnterpriseConfig)40 WifiInfo (android.net.wifi.WifiInfo)36 ScanResult (android.net.wifi.ScanResult)27 NetworkInfo (android.net.NetworkInfo)22 StaticIpConfiguration (android.net.StaticIpConfiguration)20 Credential (com.android.hotspot2.pps.Credential)20 Scanner (com.android.settingslib.wifi.WifiTracker.Scanner)20 Intent (android.content.Intent)19 Bundle (android.os.Bundle)19 ValidatedEditTextPreference (com.android.settings.widget.ValidatedEditTextPreference)16 Before (org.junit.Before)13 VisibleForTesting (android.support.annotation.VisibleForTesting)12 Preference (android.support.v7.preference.Preference)12