Search in sources :

Example 11 with StaticIpConfiguration

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

the class StaticIpConfigurationTest method testToLinkProperties.

@SmallTest
public void testToLinkProperties() {
    LinkProperties expected = new LinkProperties();
    expected.setInterfaceName(IFACE);
    StaticIpConfiguration s = new StaticIpConfiguration();
    assertEquals(expected, s.toLinkProperties(IFACE));
    final RouteInfo connectedRoute = new RouteInfo(new IpPrefix(ADDRSTR), null, IFACE);
    s.ipAddress = ADDR;
    expected.addLinkAddress(ADDR);
    expected.addRoute(connectedRoute);
    assertEquals(expected, s.toLinkProperties(IFACE));
    s.gateway = GATEWAY;
    RouteInfo defaultRoute = new RouteInfo(new IpPrefix("0.0.0.0/0"), GATEWAY, IFACE);
    expected.addRoute(defaultRoute);
    assertEquals(expected, s.toLinkProperties(IFACE));
    s.gateway = OFFLINKGATEWAY;
    expected.removeRoute(defaultRoute);
    defaultRoute = new RouteInfo(new IpPrefix("0.0.0.0/0"), OFFLINKGATEWAY, IFACE);
    expected.addRoute(defaultRoute);
    RouteInfo gatewayRoute = new RouteInfo(new IpPrefix("192.0.2.129/32"), null, IFACE);
    expected.addRoute(gatewayRoute);
    assertEquals(expected, s.toLinkProperties(IFACE));
    s.dnsServers.add(DNS1);
    expected.addDnsServer(DNS1);
    assertEquals(expected, s.toLinkProperties(IFACE));
    s.dnsServers.add(DNS2);
    s.dnsServers.add(DNS3);
    expected.addDnsServer(DNS2);
    expected.addDnsServer(DNS3);
    assertEquals(expected, s.toLinkProperties(IFACE));
    s.domains = "google.com";
    expected.setDomains("google.com");
    assertEquals(expected, s.toLinkProperties(IFACE));
    s.gateway = null;
    expected.removeRoute(defaultRoute);
    expected.removeRoute(gatewayRoute);
    assertEquals(expected, s.toLinkProperties(IFACE));
    // Without knowing the IP address, we don't have a directly-connected route, so we can't
    // tell if the gateway is off-link or not and we don't add a host route. This isn't a real
    // configuration, but we should at least not crash.
    s.gateway = OFFLINKGATEWAY;
    s.ipAddress = null;
    expected.removeLinkAddress(ADDR);
    expected.removeRoute(connectedRoute);
    expected.addRoute(defaultRoute);
    assertEquals(expected, s.toLinkProperties(IFACE));
}
Also used : IpPrefix(android.net.IpPrefix) StaticIpConfiguration(android.net.StaticIpConfiguration) RouteInfo(android.net.RouteInfo) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 12 with StaticIpConfiguration

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

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

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

the class StaticIpConfigurationTest method testConstructor.

@SmallTest
public void testConstructor() {
    StaticIpConfiguration s = new StaticIpConfiguration();
    checkEmpty(s);
}
Also used : StaticIpConfiguration(android.net.StaticIpConfiguration) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 14 with StaticIpConfiguration

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

the class StaticIpConfigurationTest method makeTestObject.

private StaticIpConfiguration makeTestObject() {
    StaticIpConfiguration s = new StaticIpConfiguration();
    s.ipAddress = ADDR;
    s.gateway = GATEWAY;
    s.dnsServers.add(DNS1);
    s.dnsServers.add(DNS2);
    s.dnsServers.add(DNS3);
    s.domains = "google.com";
    return s;
}
Also used : StaticIpConfiguration(android.net.StaticIpConfiguration)

Example 15 with StaticIpConfiguration

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

the class IpConfigStore method writeConfig.

private boolean writeConfig(DataOutputStream out, int configKey, IpConfiguration config) throws IOException {
    boolean written = false;
    try {
        switch(config.ipAssignment) {
            case STATIC:
                out.writeUTF(IP_ASSIGNMENT_KEY);
                out.writeUTF(config.ipAssignment.toString());
                StaticIpConfiguration staticIpConfiguration = config.staticIpConfiguration;
                if (staticIpConfiguration != null) {
                    if (staticIpConfiguration.ipAddress != null) {
                        LinkAddress ipAddress = staticIpConfiguration.ipAddress;
                        out.writeUTF(LINK_ADDRESS_KEY);
                        out.writeUTF(ipAddress.getAddress().getHostAddress());
                        out.writeInt(ipAddress.getPrefixLength());
                    }
                    if (staticIpConfiguration.gateway != null) {
                        out.writeUTF(GATEWAY_KEY);
                        // Default route.
                        out.writeInt(0);
                        // Have a gateway.
                        out.writeInt(1);
                        out.writeUTF(staticIpConfiguration.gateway.getHostAddress());
                    }
                    for (InetAddress inetAddr : staticIpConfiguration.dnsServers) {
                        out.writeUTF(DNS_KEY);
                        out.writeUTF(inetAddr.getHostAddress());
                    }
                }
                written = true;
                break;
            case DHCP:
                out.writeUTF(IP_ASSIGNMENT_KEY);
                out.writeUTF(config.ipAssignment.toString());
                written = true;
                break;
            case UNASSIGNED:
                /* Ignore */
                break;
            default:
                loge("Ignore invalid ip assignment while writing");
                break;
        }
        switch(config.proxySettings) {
            case STATIC:
                ProxyInfo proxyProperties = config.httpProxy;
                String exclusionList = proxyProperties.getExclusionListAsString();
                out.writeUTF(PROXY_SETTINGS_KEY);
                out.writeUTF(config.proxySettings.toString());
                out.writeUTF(PROXY_HOST_KEY);
                out.writeUTF(proxyProperties.getHost());
                out.writeUTF(PROXY_PORT_KEY);
                out.writeInt(proxyProperties.getPort());
                if (exclusionList != null) {
                    out.writeUTF(EXCLUSION_LIST_KEY);
                    out.writeUTF(exclusionList);
                }
                written = true;
                break;
            case PAC:
                ProxyInfo proxyPacProperties = config.httpProxy;
                out.writeUTF(PROXY_SETTINGS_KEY);
                out.writeUTF(config.proxySettings.toString());
                out.writeUTF(PROXY_PAC_FILE);
                out.writeUTF(proxyPacProperties.getPacFileUrl().toString());
                written = true;
                break;
            case NONE:
                out.writeUTF(PROXY_SETTINGS_KEY);
                out.writeUTF(config.proxySettings.toString());
                written = true;
                break;
            case UNASSIGNED:
                /* Ignore */
                break;
            default:
                loge("Ignore invalid proxy settings while writing");
                break;
        }
        if (written) {
            out.writeUTF(ID_KEY);
            out.writeInt(configKey);
        }
    } catch (NullPointerException e) {
        loge("Failure in writing " + config + e);
    }
    out.writeUTF(EOS);
    return written;
}
Also used : LinkAddress(android.net.LinkAddress) ProxyInfo(android.net.ProxyInfo) StaticIpConfiguration(android.net.StaticIpConfiguration) InetAddress(java.net.InetAddress)

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