FileDocCategorySizeDatePackage
StaticIpConfiguration.javaAPI DocAndroid 5.1 API7419Thu Mar 12 22:22:10 GMT 2015android.net

StaticIpConfiguration

public class StaticIpConfiguration extends Object implements android.os.Parcelable
Class that describes static IP configuration. This class is different from LinkProperties because it represents configuration intent. The general contract is that if we can represent a configuration here, then we should be able to configure it on a network. The intent is that it closely match the UI we have for configuring networks. In contrast, LinkProperties represents current state. It is much more expressive. For example, it supports multiple IP addresses, multiple routes, stacked interfaces, and so on. Because LinkProperties is so expressive, using it to represent configuration intent as well as current state causes problems. For example, we could unknowingly save a configuration that we are not in fact capable of applying, or we could save a configuration that the UI cannot display, which has the potential for malicious code to hide hostile or unexpected configuration from the user: see, for example, http://b/12663469 and http://b/16893413 .
hide

Fields Summary
public android.net.LinkAddress
ipAddress
public InetAddress
gateway
public final ArrayList
dnsServers
public String
domains
public static Creator
CREATOR
Implement the Parcelable interface
Constructors Summary
public StaticIpConfiguration()

        dnsServers = new ArrayList<InetAddress>();
    
public StaticIpConfiguration(StaticIpConfiguration source)

        this();
        if (source != null) {
            // All of these except dnsServers are immutable, so no need to make copies.
            ipAddress = source.ipAddress;
            gateway = source.gateway;
            dnsServers.addAll(source.dnsServers);
            domains = source.domains;
        }
    
Methods Summary
public voidclear()

        ipAddress = null;
        gateway = null;
        dnsServers.clear();
        domains = null;
    
public intdescribeContents()
Implement the Parcelable interface


         
       
        return 0;
    
public booleanequals(java.lang.Object obj)

        if (this == obj) return true;

        if (!(obj instanceof StaticIpConfiguration)) return false;

        StaticIpConfiguration other = (StaticIpConfiguration) obj;

        return other != null &&
                Objects.equals(ipAddress, other.ipAddress) &&
                Objects.equals(gateway, other.gateway) &&
                dnsServers.equals(other.dnsServers) &&
                Objects.equals(domains, other.domains);
    
public java.util.ListgetRoutes(java.lang.String iface)
Returns the network routes specified by this object. Will typically include a directly-connected route for the IP address's local subnet and a default route. If the default gateway is not covered by the directly-connected route, it will also contain a host route to the gateway as well. This configuration is arguably invalid, but it used to work in K and earlier, and other OSes appear to accept it.

        List<RouteInfo> routes = new ArrayList<RouteInfo>(3);
        if (ipAddress != null) {
            RouteInfo connectedRoute = new RouteInfo(ipAddress, null, iface);
            routes.add(connectedRoute);
            if (gateway != null && !connectedRoute.matches(gateway)) {
                routes.add(RouteInfo.makeHostRoute(gateway, iface));
            }
        }
        if (gateway != null) {
            routes.add(new RouteInfo((IpPrefix) null, gateway, iface));
        }
        return routes;
    
public inthashCode()

        int result = 13;
        result = 47 * result + (ipAddress == null ? 0 : ipAddress.hashCode());
        result = 47 * result + (gateway == null ? 0 : gateway.hashCode());
        result = 47 * result + (domains == null ? 0 : domains.hashCode());
        result = 47 * result + dnsServers.hashCode();
        return result;
    
protected static voidreadFromParcel(android.net.StaticIpConfiguration s, android.os.Parcel in)

        s.ipAddress = in.readParcelable(null);
        s.gateway = NetworkUtils.unparcelInetAddress(in);
        s.dnsServers.clear();
        int size = in.readInt();
        for (int i = 0; i < size; i++) {
            s.dnsServers.add(NetworkUtils.unparcelInetAddress(in));
        }
    
public LinkPropertiestoLinkProperties(java.lang.String iface)
Returns a LinkProperties object expressing the data in this object. Note that the information contained in the LinkProperties will not be a complete picture of the link's configuration, because any configuration information that is obtained dynamically by the network (e.g., IPv6 configuration) will not be included.

        LinkProperties lp = new LinkProperties();
        lp.setInterfaceName(iface);
        if (ipAddress != null) {
            lp.addLinkAddress(ipAddress);
        }
        for (RouteInfo route : getRoutes(iface)) {
            lp.addRoute(route);
        }
        for (InetAddress dns : dnsServers) {
            lp.addDnsServer(dns);
        }
        lp.setDomains(domains);
        return lp;
    
public java.lang.StringtoString()

        StringBuffer str = new StringBuffer();

        str.append("IP address ");
        if (ipAddress != null ) str.append(ipAddress).append(" ");

        str.append("Gateway ");
        if (gateway != null) str.append(gateway.getHostAddress()).append(" ");

        str.append(" DNS servers: [");
        for (InetAddress dnsServer : dnsServers) {
            str.append(" ").append(dnsServer.getHostAddress());
        }

        str.append(" ] Domains");
        if (domains != null) str.append(domains);
        return str.toString();
    
public voidwriteToParcel(android.os.Parcel dest, int flags)
Implement the Parcelable interface

        dest.writeParcelable(ipAddress, flags);
        NetworkUtils.parcelInetAddress(dest, gateway, flags);
        dest.writeInt(dnsServers.size());
        for (InetAddress dnsServer : dnsServers) {
            NetworkUtils.parcelInetAddress(dest, dnsServer, flags);
        }