Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 309a75db authored by Lorenzo Colitti's avatar Lorenzo Colitti
Browse files

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
parent c0b9efa4
Loading
Loading
Loading
Loading
+22 −3
Original line number Diff line number Diff line
@@ -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.
     * @return true if the DNS server was added, false if it was already present.
     * @hide
     */
    public void addDnsServer(InetAddress dnsServer) {
        if (dnsServer != null) mDnses.add(dnsServer);
    public boolean addDnsServer(InetAddress 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);
        }
    }

    /**