Modify DNS server update methods.

1. Make addDnsServer not add duplicate servers and return a
   boolean value incating whether it changed anything. This is
   consistent with what we do for LinkAddresses and routes.
2. Add a setDnsServers method that sets all the DNS servers to
   the specified collection. This is consistent with what we do
   for LinkAddress.

Bug: 9180552
Change-Id: I5baed09253261b66ea42ae2ea82398118e3ab0ac
This commit is contained in:
Lorenzo Colitti
2014-06-24 00:34:39 +09:00
parent fc854695c1
commit 131eb31373

View File

@@ -264,13 +264,32 @@ public final class LinkProperties implements Parcelable {
} }
/** /**
* Adds the given {@link InetAddress} to the list of DNS servers. * Adds the given {@link InetAddress} to the list of DNS servers, if not present.
* *
* @param dnsServer The {@link InetAddress} to add to the list of DNS servers. * @param dnsServer The {@link InetAddress} to add to the list of DNS servers.
* @return true if the DNS server was added, false if it was already present.
* @hide * @hide
*/ */
public void addDnsServer(InetAddress dnsServer) { public boolean addDnsServer(InetAddress dnsServer) {
if (dnsServer != null) mDnses.add(dnsServer); if (dnsServer != null && !mDnses.contains(dnsServer)) {
mDnses.add(dnsServer);
return true;
}
return false;
}
/**
* Replaces the DNS servers in this {@code LinkProperties} with
* the given {@link Collection} of {@link InetAddress} objects.
*
* @param addresses The {@link Collection} of DNS servers to set in this object.
* @hide
*/
public void setDnsServers(Collection<InetAddress> dnsServers) {
mDnses.clear();
for (InetAddress dnsServer: dnsServers) {
addDnsServer(dnsServer);
}
} }
/** /**