LinkProperties


public final class LinkProperties
extends Object implements Parcelable

java.lang.Object
   ↳ android.net.LinkProperties


Describes the properties of a network link. A link represents a connection to a network. It may have multiple addresses and multiple gateways, multiple dns servers but only one http proxy and one network interface. Note that this is just a holder of data. Modifying it does not affect live networks.

Summary

Inherited constants

Fields

public static final Creator<LinkProperties> CREATOR

Implement the Parcelable interface.

Public constructors

LinkProperties()

Constructs a new LinkProperties with default values.

Public methods

boolean addRoute(RouteInfo route)

Adds a RouteInfo to this LinkProperties.

void clear()

Clears this object to its initial state.

int describeContents()

Implement the Parcelable interface

boolean equals(Object obj)

Compares this LinkProperties instance against the target LinkProperties in obj.

Inet4Address getDhcpServerAddress()

Get DHCP server address

List<InetAddress> getDnsServers()

Returns all the InetAddress for DNS servers on this link.

String getDomains()

Get the DNS domains search path set for this link.

ProxyInfo getHttpProxy()

Gets the recommended ProxyInfo (or null) set on this link.

String getInterfaceName()

Gets the interface name for this link.

List<LinkAddress> getLinkAddresses()

Returns all the LinkAddress on this link.

int getMtu()

Gets any non-default MTU size set for this link.

IpPrefix getNat64Prefix()

Returns the NAT64 prefix in use on this link, if any.

String getPrivateDnsServerName()

Returns the private DNS server name that is in use.

List<RouteInfo> getRoutes()

Returns all the RouteInfo set on this link.

int hashCode()

Generate hashcode based on significant fields Equal objects must produce the same hash code, while unequal objects may have the same hash codes.

boolean isPrivateDnsActive()

Returns whether private DNS is currently in use on this network.

boolean isWakeOnLanSupported()

Returns whether the network interface supports WakeOnLAN

void setDhcpServerAddress(Inet4Address serverAddress)

Set DHCP server address.

void setDnsServers(Collection<InetAddress> dnsServers)

Replaces the DNS servers in this LinkProperties with the given Collection of InetAddress objects.

void setDomains(String domains)

Sets the DNS domain search path used on this link.

void setHttpProxy(ProxyInfo proxy)

Sets the recommended ProxyInfo to use on this link, or null for none.

void setInterfaceName(String iface)

Sets the interface name for this link.

void setLinkAddresses(Collection<LinkAddress> addresses)

Replaces the LinkAddress in this LinkProperties with the given Collection of LinkAddress.

void setMtu(int mtu)

Sets the Maximum Transmission Unit size to use on this link.

void setNat64Prefix(IpPrefix prefix)

Sets the NAT64 prefix in use on this link.

String toString()

Returns a string representation of the object.

void writeToParcel(Parcel dest, int flags)

Implement the Parcelable interface.

Inherited methods

Fields

CREATOR

Added in API level 21
public static final Creator<LinkProperties> CREATOR

Implement the Parcelable interface.

Public constructors

LinkProperties

Added in API level 29
public LinkProperties ()

Constructs a new LinkProperties with default values.

Public methods

addRoute

Added in API level 29
public boolean addRoute (RouteInfo route)

Adds a RouteInfo to this LinkProperties. If there is a RouteInfo with the same destination, gateway and interface with different properties (e.g., different MTU), it will be updated. If the RouteInfo had an interface name set and that differs from the interface set for this LinkProperties an IllegalArgumentException will be thrown. The proper course is to add either un-named or properly named RouteInfo.

Parameters
route RouteInfo: A RouteInfo to add to this object. This value cannot be null.

Returns
boolean true was added or updated, false otherwise.

clear

Added in API level 29
public void clear ()

Clears this object to its initial state.

describeContents

Added in API level 21
public int describeContents ()

Implement the Parcelable interface

Returns
int a bitmask indicating the set of special object types marshaled by this Parcelable object instance. Value is either 0 or CONTENTS_FILE_DESCRIPTOR

equals

Added in API level 21
public boolean equals (Object obj)

Compares this LinkProperties instance against the target LinkProperties in obj. Two LinkPropertieses are equal if all their fields are equal in values. For collection fields, such as mDnses, containsAll() is used to check if two collections contains the same elements, independent of order. There are two thoughts regarding containsAll() 1. Duplicated elements. eg, (A, B, B) and (A, A, B) are equal. 2. Worst case performance is O(n^2).

Parameters
obj Object: the object to be tested for equality. This value may be null.

Returns
boolean true if both objects are equal, false otherwise.

getDhcpServerAddress

Added in API level 30
public Inet4Address getDhcpServerAddress ()

Get DHCP server address

Returns
Inet4Address The current DHCP server address. This value may be null.

getDnsServers

Added in API level 21
public List<InetAddress> getDnsServers ()

Returns all the InetAddress for DNS servers on this link.

Returns
List<InetAddress> An unmodifiable List of InetAddress for DNS servers on this link. This value cannot be null.

getDomains

Added in API level 21
public String getDomains ()

Get the DNS domains search path set for this link. May be null if not set.

Returns
String A String containing the comma separated domains to search when resolving host names on this link or null.

getHttpProxy

Added in API level 21
public ProxyInfo getHttpProxy ()

Gets the recommended ProxyInfo (or null) set on this link.

Returns
ProxyInfo The ProxyInfo set on this link or null.

getInterfaceName

Added in API level 21
public String getInterfaceName ()

Gets the interface name for this link. May be null if not set.

Returns
String The interface name set for this link or null.

getLinkAddresses

Added in API level 21
public List<LinkAddress> getLinkAddresses ()

Returns all the LinkAddress on this link. Typically a link will have one IPv4 address and one or more IPv6 addresses.

Returns
List<LinkAddress> An unmodifiable List of LinkAddress for this link. This value cannot be null.

getMtu

Added in API level 29
public int getMtu ()

Gets any non-default MTU size set for this link. Note that if the default is being used this will return 0.

Returns
int The mtu value set for this link.

getNat64Prefix

Added in API level 30
public IpPrefix getNat64Prefix ()

Returns the NAT64 prefix in use on this link, if any.

Returns
IpPrefix the NAT64 prefix or null.

getPrivateDnsServerName

Added in API level 28
public String getPrivateDnsServerName ()

Returns the private DNS server name that is in use. If not null, private DNS is in strict mode. In this mode, applications should ensure that all DNS queries are encrypted and sent to this hostname and that queries are only sent if the hostname's certificate is valid. If null and isPrivateDnsActive() is true, private DNS is in opportunistic mode, and applications should ensure that DNS queries are encrypted and sent to a DNS server returned by getDnsServers(). System DNS will handle each of these cases correctly, but applications implementing their own DNS lookups must make sure to follow these requirements.

Returns
String The private DNS server name.

getRoutes

Added in API level 21
public List<RouteInfo> getRoutes ()

Returns all the RouteInfo set on this link. Only unicast routes are returned for apps targeting Android S or below.

Returns
List<RouteInfo> An unmodifiable List of RouteInfo for this link. This value cannot be null.

hashCode

Added in API level 21
public int hashCode ()

Generate hashcode based on significant fields Equal objects must produce the same hash code, while unequal objects may have the same hash codes.

Returns
int a hash code value for this object.

isPrivateDnsActive

Added in API level 28
public boolean isPrivateDnsActive ()

Returns whether private DNS is currently in use on this network. When private DNS is in use, applications must not send unencrypted DNS queries as doing so could reveal private user information. Furthermore, if private DNS is in use and getPrivateDnsServerName() is not null, DNS queries must be sent to the specified DNS server.

Returns
boolean true if private DNS is in use, false otherwise.

isWakeOnLanSupported

Added in API level 30
public boolean isWakeOnLanSupported ()

Returns whether the network interface supports WakeOnLAN

Returns
boolean true if interface supports WakeOnLAN, false otherwise.

setDhcpServerAddress

Added in API level 30
public void setDhcpServerAddress (Inet4Address serverAddress)

Set DHCP server address.

Parameters
serverAddress Inet4Address: the server address to set. This value may be null.

setDnsServers

Added in API level 29
public void setDnsServers (Collection<InetAddress> dnsServers)

Replaces the DNS servers in this LinkProperties with the given Collection of InetAddress objects.

Parameters
dnsServers Collection: The Collection of DNS servers to set in this object. This value cannot be null.

setDomains

Added in API level 29
public void setDomains (String domains)

Sets the DNS domain search path used on this link.

Parameters
domains String: A String listing in priority order the comma separated domains to search when resolving host names on this link. This value may be null.

setHttpProxy

Added in API level 29
public void setHttpProxy (ProxyInfo proxy)

Sets the recommended ProxyInfo to use on this link, or null for none. Note that Http Proxies are only a hint - the system recommends their use, but it does not enforce it and applications may ignore them.

Parameters
proxy ProxyInfo: A ProxyInfo defining the HTTP Proxy to use on this link. This value may be null.

setInterfaceName

Added in API level 29
public void setInterfaceName (String iface)

Sets the interface name for this link. All RouteInfo already set for this will have their interface changed to match this new value.

Parameters
iface String: The name of the network interface used for this link. This value may be null.

setLinkAddresses

Added in API level 29
public void setLinkAddresses (Collection<LinkAddress> addresses)

Replaces the LinkAddress in this LinkProperties with the given Collection of LinkAddress.

Parameters
addresses Collection: The Collection of LinkAddress to set in this object. This value cannot be null.

setMtu

Added in API level 29
public void setMtu (int mtu)

Sets the Maximum Transmission Unit size to use on this link. This should not be used unless the system default (1500) is incorrect. Values less than 68 or greater than 10000 will be ignored.

Parameters
mtu int: The MTU to use for this link.

setNat64Prefix

Added in API level 30
public void setNat64Prefix (IpPrefix prefix)

Sets the NAT64 prefix in use on this link. Currently, only 96-bit prefixes (i.e., where the 32-bit IPv4 address is at the end of the 128-bit IPv6 address) are supported or null for no prefix.

Parameters
prefix IpPrefix: the NAT64 prefix. This value may be null.

toString

Added in API level 21
public String toString ()

Returns a string representation of the object.

Returns
String a string representation of the object.

writeToParcel

Added in API level 21
public void writeToParcel (Parcel dest, 
                int flags)

Implement the Parcelable interface.

Parameters
dest Parcel: The Parcel in which the object should be written. This value cannot be null.

flags int: Additional flags about how the object should be written. May be 0 or Parcelable.PARCELABLE_WRITE_RETURN_VALUE. Value is either 0 or a combination of Parcelable.PARCELABLE_WRITE_RETURN_VALUE, and android.os.Parcelable.PARCELABLE_ELIDE_DUPLICATES