Search in sources :

Example 21 with StaticIpConfiguration

use of android.net.StaticIpConfiguration in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class WifiConfigController method showIpConfigFields.

private void showIpConfigFields() {
    WifiConfiguration config = null;
    mView.findViewById(R.id.ip_fields).setVisibility(View.VISIBLE);
    if (mAccessPoint != null && mAccessPoint.isSaved()) {
        config = mAccessPoint.getConfig();
    }
    if (mIpSettingsSpinner.getSelectedItemPosition() == STATIC_IP) {
        mView.findViewById(R.id.staticip).setVisibility(View.VISIBLE);
        if (mIpAddressView == null) {
            mIpAddressView = (TextView) mView.findViewById(R.id.ipaddress);
            mIpAddressView.addTextChangedListener(this);
            mGatewayView = (TextView) mView.findViewById(R.id.gateway);
            mGatewayView.addTextChangedListener(this);
            mNetworkPrefixLengthView = (TextView) mView.findViewById(R.id.network_prefix_length);
            mNetworkPrefixLengthView.addTextChangedListener(this);
            mDns1View = (TextView) mView.findViewById(R.id.dns1);
            mDns1View.addTextChangedListener(this);
            mDns2View = (TextView) mView.findViewById(R.id.dns2);
            mDns2View.addTextChangedListener(this);
        }
        if (config != null) {
            StaticIpConfiguration staticConfig = config.getStaticIpConfiguration();
            if (staticConfig != null) {
                if (staticConfig.ipAddress != null) {
                    mIpAddressView.setText(staticConfig.ipAddress.getAddress().getHostAddress());
                    mNetworkPrefixLengthView.setText(Integer.toString(staticConfig.ipAddress.getNetworkPrefixLength()));
                }
                if (staticConfig.gateway != null) {
                    mGatewayView.setText(staticConfig.gateway.getHostAddress());
                }
                Iterator<InetAddress> dnsIterator = staticConfig.dnsServers.iterator();
                if (dnsIterator.hasNext()) {
                    mDns1View.setText(dnsIterator.next().getHostAddress());
                }
                if (dnsIterator.hasNext()) {
                    mDns2View.setText(dnsIterator.next().getHostAddress());
                }
            }
        }
    } else {
        mView.findViewById(R.id.staticip).setVisibility(View.GONE);
    }
}
Also used : WifiConfiguration(android.net.wifi.WifiConfiguration) StaticIpConfiguration(android.net.StaticIpConfiguration) InetAddress(java.net.InetAddress)

Example 22 with StaticIpConfiguration

use of android.net.StaticIpConfiguration in project android_frameworks_base by crdroidandroid.

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 23 with StaticIpConfiguration

use of android.net.StaticIpConfiguration in project android_frameworks_base by crdroidandroid.

the class StaticIpConfigurationTest method testCopyAndClear.

@SmallTest
public void testCopyAndClear() {
    StaticIpConfiguration empty = new StaticIpConfiguration((StaticIpConfiguration) null);
    checkEmpty(empty);
    StaticIpConfiguration s1 = makeTestObject();
    StaticIpConfiguration s2 = new StaticIpConfiguration(s1);
    assertEquals(s1, s2);
    s2.clear();
    assertEquals(empty, s2);
}
Also used : StaticIpConfiguration(android.net.StaticIpConfiguration) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 24 with StaticIpConfiguration

use of android.net.StaticIpConfiguration in project android_frameworks_base by crdroidandroid.

the class StaticIpConfigurationTest method testParceling.

@SmallTest
public void testParceling() {
    StaticIpConfiguration s = makeTestObject();
    StaticIpConfiguration s2 = passThroughParcel(s);
    assertEquals(s, s2);
}
Also used : StaticIpConfiguration(android.net.StaticIpConfiguration) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 25 with StaticIpConfiguration

use of android.net.StaticIpConfiguration in project android_frameworks_base by crdroidandroid.

the class StaticIpConfigurationTest method passThroughParcel.

private StaticIpConfiguration passThroughParcel(StaticIpConfiguration s) {
    Parcel p = Parcel.obtain();
    StaticIpConfiguration s2 = null;
    try {
        s.writeToParcel(p, 0);
        p.setDataPosition(0);
        s2 = StaticIpConfiguration.CREATOR.createFromParcel(p);
    } finally {
        p.recycle();
    }
    assertNotNull(s2);
    return s2;
}
Also used : Parcel(android.os.Parcel) StaticIpConfiguration(android.net.StaticIpConfiguration)

Aggregations

StaticIpConfiguration (android.net.StaticIpConfiguration)52 SmallTest (android.test.suitebuilder.annotation.SmallTest)25 LinkAddress (android.net.LinkAddress)20 InetAddress (java.net.InetAddress)16 ProxyInfo (android.net.ProxyInfo)11 RouteInfo (android.net.RouteInfo)10 WifiConfiguration (android.net.wifi.WifiConfiguration)6 IpConfiguration (android.net.IpConfiguration)5 IpAssignment (android.net.IpConfiguration.IpAssignment)5 ProxySettings (android.net.IpConfiguration.ProxySettings)5 IpPrefix (android.net.IpPrefix)5 Parcel (android.os.Parcel)5 SparseArray (android.util.SparseArray)5 DataInputStream (java.io.DataInputStream)5 EOFException (java.io.EOFException)5 IOException (java.io.IOException)5 Inet4Address (java.net.Inet4Address)5 HashSet (java.util.HashSet)5 BufferedInputStream (java.io.BufferedInputStream)4 FileInputStream (java.io.FileInputStream)4