Merge "Add public API methods for private DNS."
This commit is contained in:
@@ -50,6 +50,8 @@ public final class LinkProperties implements Parcelable {
|
|||||||
private String mIfaceName;
|
private String mIfaceName;
|
||||||
private ArrayList<LinkAddress> mLinkAddresses = new ArrayList<LinkAddress>();
|
private ArrayList<LinkAddress> mLinkAddresses = new ArrayList<LinkAddress>();
|
||||||
private ArrayList<InetAddress> mDnses = new ArrayList<InetAddress>();
|
private ArrayList<InetAddress> mDnses = new ArrayList<InetAddress>();
|
||||||
|
private boolean mUsePrivateDns;
|
||||||
|
private String mPrivateDnsServerName;
|
||||||
private String mDomains;
|
private String mDomains;
|
||||||
private ArrayList<RouteInfo> mRoutes = new ArrayList<RouteInfo>();
|
private ArrayList<RouteInfo> mRoutes = new ArrayList<RouteInfo>();
|
||||||
private ProxyInfo mHttpProxy;
|
private ProxyInfo mHttpProxy;
|
||||||
@@ -165,6 +167,8 @@ public final class LinkProperties implements Parcelable {
|
|||||||
mIfaceName = source.getInterfaceName();
|
mIfaceName = source.getInterfaceName();
|
||||||
for (LinkAddress l : source.getLinkAddresses()) mLinkAddresses.add(l);
|
for (LinkAddress l : source.getLinkAddresses()) mLinkAddresses.add(l);
|
||||||
for (InetAddress i : source.getDnsServers()) mDnses.add(i);
|
for (InetAddress i : source.getDnsServers()) mDnses.add(i);
|
||||||
|
mUsePrivateDns = source.mUsePrivateDns;
|
||||||
|
mPrivateDnsServerName = source.mPrivateDnsServerName;
|
||||||
mDomains = source.getDomains();
|
mDomains = source.getDomains();
|
||||||
for (RouteInfo r : source.getRoutes()) mRoutes.add(r);
|
for (RouteInfo r : source.getRoutes()) mRoutes.add(r);
|
||||||
mHttpProxy = (source.getHttpProxy() == null) ?
|
mHttpProxy = (source.getHttpProxy() == null) ?
|
||||||
@@ -390,6 +394,59 @@ public final class LinkProperties implements Parcelable {
|
|||||||
return Collections.unmodifiableList(mDnses);
|
return Collections.unmodifiableList(mDnses);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set whether private DNS is currently in use on this network.
|
||||||
|
*
|
||||||
|
* @param usePrivateDns The private DNS state.
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public void setUsePrivateDns(boolean usePrivateDns) {
|
||||||
|
mUsePrivateDns = usePrivateDns;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 {@link #getPrivateDnsServerName} is not
|
||||||
|
* {@code null}, DNS queries must be sent to the specified DNS server.
|
||||||
|
*
|
||||||
|
* @return {@code true} if private DNS is in use, {@code false} otherwise.
|
||||||
|
*/
|
||||||
|
public boolean isPrivateDnsActive() {
|
||||||
|
return mUsePrivateDns;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the name of the private DNS server to which private DNS queries
|
||||||
|
* should be sent when in strict mode. This value should be {@code null}
|
||||||
|
* when private DNS is off or in opportunistic mode.
|
||||||
|
*
|
||||||
|
* @param privateDnsServerName The private DNS server name.
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public void setPrivateDnsServerName(@Nullable String privateDnsServerName) {
|
||||||
|
mPrivateDnsServerName = privateDnsServerName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the private DNS server name that is in use. If not {@code 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
|
||||||
|
* {@code null} and {@link #isPrivateDnsActive} is {@code true}, private
|
||||||
|
* DNS is in opportunistic mode, and applications should ensure that DNS
|
||||||
|
* queries are encrypted and sent to a DNS server returned by
|
||||||
|
* {@link #getDnsServers}. System DNS will handle each of these cases
|
||||||
|
* correctly, but applications implementing their own DNS lookups must make
|
||||||
|
* sure to follow these requirements.
|
||||||
|
*
|
||||||
|
* @return The private DNS server name.
|
||||||
|
*/
|
||||||
|
public @Nullable String getPrivateDnsServerName() {
|
||||||
|
return mPrivateDnsServerName;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the DNS domain search path used on this link.
|
* Sets the DNS domain search path used on this link.
|
||||||
*
|
*
|
||||||
@@ -622,6 +679,8 @@ public final class LinkProperties implements Parcelable {
|
|||||||
mIfaceName = null;
|
mIfaceName = null;
|
||||||
mLinkAddresses.clear();
|
mLinkAddresses.clear();
|
||||||
mDnses.clear();
|
mDnses.clear();
|
||||||
|
mUsePrivateDns = false;
|
||||||
|
mPrivateDnsServerName = null;
|
||||||
mDomains = null;
|
mDomains = null;
|
||||||
mRoutes.clear();
|
mRoutes.clear();
|
||||||
mHttpProxy = null;
|
mHttpProxy = null;
|
||||||
@@ -649,6 +708,13 @@ public final class LinkProperties implements Parcelable {
|
|||||||
for (InetAddress addr : mDnses) dns += addr.getHostAddress() + ",";
|
for (InetAddress addr : mDnses) dns += addr.getHostAddress() + ",";
|
||||||
dns += "] ";
|
dns += "] ";
|
||||||
|
|
||||||
|
String usePrivateDns = "UsePrivateDns: " + mUsePrivateDns + " ";
|
||||||
|
|
||||||
|
String privateDnsServerName = "";
|
||||||
|
if (privateDnsServerName != null) {
|
||||||
|
privateDnsServerName = "PrivateDnsServerName: " + mPrivateDnsServerName + " ";
|
||||||
|
}
|
||||||
|
|
||||||
String domainName = "Domains: " + mDomains;
|
String domainName = "Domains: " + mDomains;
|
||||||
|
|
||||||
String mtu = " MTU: " + mMtu;
|
String mtu = " MTU: " + mMtu;
|
||||||
@@ -671,8 +737,9 @@ public final class LinkProperties implements Parcelable {
|
|||||||
}
|
}
|
||||||
stacked += "] ";
|
stacked += "] ";
|
||||||
}
|
}
|
||||||
return "{" + ifaceName + linkAddresses + routes + dns + domainName + mtu
|
return "{" + ifaceName + linkAddresses + routes + dns + usePrivateDns
|
||||||
+ tcpBuffSizes + proxy + stacked + "}";
|
+ privateDnsServerName + domainName + mtu + tcpBuffSizes + proxy
|
||||||
|
+ stacked + "}";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -895,6 +962,20 @@ public final class LinkProperties implements Parcelable {
|
|||||||
mDnses.containsAll(targetDnses) : false;
|
mDnses.containsAll(targetDnses) : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compares this {@code LinkProperties} private DNS settings against the
|
||||||
|
* target.
|
||||||
|
*
|
||||||
|
* @param target LinkProperties to compare.
|
||||||
|
* @return {@code true} if both are identical, {@code false} otherwise.
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public boolean isIdenticalPrivateDns(LinkProperties target) {
|
||||||
|
return (isPrivateDnsActive() == target.isPrivateDnsActive()
|
||||||
|
&& TextUtils.equals(getPrivateDnsServerName(),
|
||||||
|
target.getPrivateDnsServerName()));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compares this {@code LinkProperties} Routes against the target
|
* Compares this {@code LinkProperties} Routes against the target
|
||||||
*
|
*
|
||||||
@@ -989,14 +1070,15 @@ public final class LinkProperties implements Parcelable {
|
|||||||
* stacked interfaces are not so much a property of the link as a
|
* stacked interfaces are not so much a property of the link as a
|
||||||
* description of connections between links.
|
* description of connections between links.
|
||||||
*/
|
*/
|
||||||
return isIdenticalInterfaceName(target) &&
|
return isIdenticalInterfaceName(target)
|
||||||
isIdenticalAddresses(target) &&
|
&& isIdenticalAddresses(target)
|
||||||
isIdenticalDnses(target) &&
|
&& isIdenticalDnses(target)
|
||||||
isIdenticalRoutes(target) &&
|
&& isIdenticalPrivateDns(target)
|
||||||
isIdenticalHttpProxy(target) &&
|
&& isIdenticalRoutes(target)
|
||||||
isIdenticalStackedLinks(target) &&
|
&& isIdenticalHttpProxy(target)
|
||||||
isIdenticalMtu(target) &&
|
&& isIdenticalStackedLinks(target)
|
||||||
isIdenticalTcpBufferSizes(target);
|
&& isIdenticalMtu(target)
|
||||||
|
&& isIdenticalTcpBufferSizes(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1091,7 +1173,9 @@ public final class LinkProperties implements Parcelable {
|
|||||||
+ ((null == mHttpProxy) ? 0 : mHttpProxy.hashCode())
|
+ ((null == mHttpProxy) ? 0 : mHttpProxy.hashCode())
|
||||||
+ mStackedLinks.hashCode() * 47)
|
+ mStackedLinks.hashCode() * 47)
|
||||||
+ mMtu * 51
|
+ mMtu * 51
|
||||||
+ ((null == mTcpBufferSizes) ? 0 : mTcpBufferSizes.hashCode());
|
+ ((null == mTcpBufferSizes) ? 0 : mTcpBufferSizes.hashCode())
|
||||||
|
+ (mUsePrivateDns ? 57 : 0)
|
||||||
|
+ ((null == mPrivateDnsServerName) ? 0 : mPrivateDnsServerName.hashCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1108,6 +1192,8 @@ public final class LinkProperties implements Parcelable {
|
|||||||
for(InetAddress d : mDnses) {
|
for(InetAddress d : mDnses) {
|
||||||
dest.writeByteArray(d.getAddress());
|
dest.writeByteArray(d.getAddress());
|
||||||
}
|
}
|
||||||
|
dest.writeBoolean(mUsePrivateDns);
|
||||||
|
dest.writeString(mPrivateDnsServerName);
|
||||||
dest.writeString(mDomains);
|
dest.writeString(mDomains);
|
||||||
dest.writeInt(mMtu);
|
dest.writeInt(mMtu);
|
||||||
dest.writeString(mTcpBufferSizes);
|
dest.writeString(mTcpBufferSizes);
|
||||||
@@ -1148,6 +1234,8 @@ public final class LinkProperties implements Parcelable {
|
|||||||
netProp.addDnsServer(InetAddress.getByAddress(in.createByteArray()));
|
netProp.addDnsServer(InetAddress.getByAddress(in.createByteArray()));
|
||||||
} catch (UnknownHostException e) { }
|
} catch (UnknownHostException e) { }
|
||||||
}
|
}
|
||||||
|
netProp.setUsePrivateDns(in.readBoolean());
|
||||||
|
netProp.setPrivateDnsServerName(in.readString());
|
||||||
netProp.setDomains(in.readString());
|
netProp.setDomains(in.readString());
|
||||||
netProp.setMtu(in.readInt());
|
netProp.setMtu(in.readInt());
|
||||||
netProp.setTcpBufferSizes(in.readString());
|
netProp.setTcpBufferSizes(in.readString());
|
||||||
|
|||||||
@@ -79,6 +79,9 @@ public class LinkPropertiesTest {
|
|||||||
assertTrue(source.isIdenticalDnses(target));
|
assertTrue(source.isIdenticalDnses(target));
|
||||||
assertTrue(target.isIdenticalDnses(source));
|
assertTrue(target.isIdenticalDnses(source));
|
||||||
|
|
||||||
|
assertTrue(source.isIdenticalPrivateDns(target));
|
||||||
|
assertTrue(target.isIdenticalPrivateDns(source));
|
||||||
|
|
||||||
assertTrue(source.isIdenticalRoutes(target));
|
assertTrue(source.isIdenticalRoutes(target));
|
||||||
assertTrue(target.isIdenticalRoutes(source));
|
assertTrue(target.isIdenticalRoutes(source));
|
||||||
|
|
||||||
@@ -91,6 +94,9 @@ public class LinkPropertiesTest {
|
|||||||
assertTrue(source.isIdenticalMtu(target));
|
assertTrue(source.isIdenticalMtu(target));
|
||||||
assertTrue(target.isIdenticalMtu(source));
|
assertTrue(target.isIdenticalMtu(source));
|
||||||
|
|
||||||
|
assertTrue(source.isIdenticalTcpBufferSizes(target));
|
||||||
|
assertTrue(target.isIdenticalTcpBufferSizes(source));
|
||||||
|
|
||||||
// Check result of equals().
|
// Check result of equals().
|
||||||
assertTrue(source.equals(target));
|
assertTrue(source.equals(target));
|
||||||
assertTrue(target.equals(source));
|
assertTrue(target.equals(source));
|
||||||
|
|||||||
Reference in New Issue
Block a user