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

Commit 32f68e6b authored by Remi NGUYEN VAN's avatar Remi NGUYEN VAN Committed by android-build-merger
Browse files

Merge "Add varargs methods to build DhcpServingParams" am: 80f3ddca am: c461d4dd

am: 2488bcfa

Change-Id: Ice92a68a65cf488ed6e24a71fd8272240a6ea033
parents 04f6a613 2488bcfa
Loading
Loading
Loading
Loading
+50 −0
Original line number Diff line number Diff line
@@ -28,6 +28,8 @@ import android.net.IpPrefix;
import android.net.LinkAddress;
import android.net.NetworkUtils;

import com.google.android.collect.Sets;

import java.net.Inet4Address;
import java.util.Collections;
import java.util.HashSet;
@@ -154,6 +156,25 @@ public class DhcpServingParams {
            return this;
        }

        /**
         * Set the default routers to be advertised to DHCP clients.
         *
         * <p>Each router must be inside the served prefix. This may be an empty list of routers,
         * but it must always be set explicitly before building the {@link DhcpServingParams}.
         */
        public Builder setDefaultRouters(@NonNull Inet4Address... defaultRouters) {
            return setDefaultRouters(Sets.newArraySet(defaultRouters));
        }

        /**
         * Convenience method to build the parameters with no default router.
         *
         * <p>Equivalent to calling {@link #setDefaultRouters(Inet4Address...)} with no address.
         */
        public Builder withNoDefaultRouter() {
            return setDefaultRouters();
        }

        /**
         * Set the DNS servers to be advertised to DHCP clients.
         *
@@ -165,6 +186,25 @@ public class DhcpServingParams {
            return this;
        }

        /**
         * Set the DNS servers to be advertised to DHCP clients.
         *
         * <p>This may be an empty list of servers, but it must always be set explicitly before
         * building the {@link DhcpServingParams}.
         */
        public Builder setDnsServers(@NonNull Inet4Address... dnsServers) {
            return setDnsServers(Sets.newArraySet(dnsServers));
        }

        /**
         * Convenience method to build the parameters with no DNS server.
         *
         * <p>Equivalent to calling {@link #setDnsServers(Inet4Address...)} with no address.
         */
        public Builder withNoDnsServer() {
            return setDnsServers();
        }

        /**
         * Set excluded addresses that the DHCP server is not allowed to assign to clients.
         *
@@ -176,6 +216,16 @@ public class DhcpServingParams {
            return this;
        }

        /**
         * Set excluded addresses that the DHCP server is not allowed to assign to clients.
         *
         * <p>This parameter is optional. DNS servers and default routers are always excluded
         * and do not need to be set here.
         */
        public Builder setExcludedAddrs(@NonNull Inet4Address... excludedAddrs) {
            return setExcludedAddrs(Sets.newArraySet(excludedAddrs));
        }

        /**
         * Set the lease time for leases assigned by the DHCP server.
         *
+2 −3
Original line number Diff line number Diff line
@@ -37,7 +37,6 @@ import org.junit.runner.RunWith;

import java.net.Inet4Address;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

@@ -150,14 +149,14 @@ public class DhcpServingParamsTest {

    @Test(expected = InvalidParameterException.class)
    public void testBuild_PrefixTooSmall() throws InvalidParameterException {
        mBuilder.setDefaultRouters(Collections.singleton(parseAddr("192.168.0.254")))
        mBuilder.setDefaultRouters(parseAddr("192.168.0.254"))
                .setServerAddr(new LinkAddress(TEST_SERVER_ADDR, 31))
                .build();
    }

    @Test(expected = InvalidParameterException.class)
    public void testBuild_RouterNotInPrefix() throws InvalidParameterException {
        mBuilder.setDefaultRouters(Collections.singleton(parseAddr("192.168.254.254"))).build();
        mBuilder.setDefaultRouters(parseAddr("192.168.254.254")).build();
    }

    private static <T> void assertContains(@NonNull Set<T> set, @NonNull Set<T> subset) {