FileDocCategorySizeDatePackage
DhcpResults.javaAPI DocAndroid 5.1 API6538Thu Mar 12 22:22:10 GMT 2015android.net

DhcpResults

public class DhcpResults extends StaticIpConfiguration
A simple object for retrieving the results of a DHCP request. Optimized (attempted) for that jni interface TODO - remove when DhcpInfo is deprecated. Move the remaining api to LinkProperties.
hide

Fields Summary
private static final String
TAG
public InetAddress
serverAddress
public String
vendorInfo
Vendor specific information (from RFC 2132).
public int
leaseDuration
public static final Creator
CREATOR
Implement the Parcelable interface
Constructors Summary
public DhcpResults()


      
        super();
    
public DhcpResults(StaticIpConfiguration source)

        super(source);
    
public DhcpResults(DhcpResults source)
copy constructor

        super(source);

        if (source != null) {
            // All these are immutable, so no need to make copies.
            serverAddress = source.serverAddress;
            vendorInfo = source.vendorInfo;
            leaseDuration = source.leaseDuration;
        }
    
Methods Summary
public booleanaddDns(java.lang.String addrString)

        if (TextUtils.isEmpty(addrString) == false) {
            try {
                dnsServers.add(NetworkUtils.numericToInetAddress(addrString));
            } catch (IllegalArgumentException e) {
                Log.e(TAG, "addDns failed with addrString " + addrString);
                return true;
            }
        }
        return false;
    
public voidclear()

        super.clear();
        vendorInfo = null;
        leaseDuration = 0;
    
public booleanequals(java.lang.Object obj)

        if (this == obj) return true;

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

        DhcpResults target = (DhcpResults)obj;

        return super.equals((StaticIpConfiguration) obj) &&
                Objects.equals(serverAddress, target.serverAddress) &&
                Objects.equals(vendorInfo, target.vendorInfo) &&
                leaseDuration == target.leaseDuration;
    
public booleanhasMeteredHint()
Test if this DHCP lease includes vendor hint that network link is metered, and sensitive to heavy data transfers.

        if (vendorInfo != null) {
            return vendorInfo.contains("ANDROID_METERED");
        } else {
            return false;
        }
    
private static voidreadFromParcel(android.net.DhcpResults dhcpResults, android.os.Parcel in)

        StaticIpConfiguration.readFromParcel(dhcpResults, in);
        dhcpResults.leaseDuration = in.readInt();
        dhcpResults.serverAddress = NetworkUtils.unparcelInetAddress(in);
        dhcpResults.vendorInfo = in.readString();
    
public voidsetDomains(java.lang.String newDomains)

        domains = newDomains;
    
public booleansetGateway(java.lang.String addrString)

        try {
            gateway = NetworkUtils.numericToInetAddress(addrString);
        } catch (IllegalArgumentException e) {
            Log.e(TAG, "setGateway failed with addrString " + addrString);
            return true;
        }
        return false;
    
public booleansetIpAddress(java.lang.String addrString, int prefixLength)

        try {
            Inet4Address addr = (Inet4Address) NetworkUtils.numericToInetAddress(addrString);
            ipAddress = new LinkAddress(addr, prefixLength);
        } catch (IllegalArgumentException|ClassCastException e) {
            Log.e(TAG, "setIpAddress failed with addrString " + addrString + "/" + prefixLength);
            return true;
        }
        return false;
    
public voidsetLeaseDuration(int duration)

        leaseDuration = duration;
    
public booleansetServerAddress(java.lang.String addrString)

        try {
            serverAddress = NetworkUtils.numericToInetAddress(addrString);
        } catch (IllegalArgumentException e) {
            Log.e(TAG, "setServerAddress failed with addrString " + addrString);
            return true;
        }
        return false;
    
public voidsetVendorInfo(java.lang.String info)

        vendorInfo = info;
    
public java.lang.StringtoString()

        StringBuffer str = new StringBuffer(super.toString());

        str.append(" DHCP server ").append(serverAddress);
        str.append(" Vendor info ").append(vendorInfo);
        str.append(" lease ").append(leaseDuration).append(" seconds");

        return str.toString();
    
public voidupdateFromDhcpRequest(android.net.DhcpResults orig)
Updates the DHCP fields that need to be retained from original DHCP request if the current renewal shows them being empty.

        if (orig == null) return;
        if (gateway == null) gateway = orig.gateway;
        if (dnsServers.size() == 0) {
            dnsServers.addAll(orig.dnsServers);
        }
    
public voidwriteToParcel(android.os.Parcel dest, int flags)
Implement the Parcelable interface


         
          
        super.writeToParcel(dest, flags);
        dest.writeInt(leaseDuration);
        NetworkUtils.parcelInetAddress(dest, serverAddress, flags);
        dest.writeString(vendorInfo);