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

Commit 32336c98 authored by Lorenzo Colitti's avatar Lorenzo Colitti
Browse files

Add a hasMacAddress member to InterfaceParams.

This is a convenience function for callers who would like to know
whether the interface has a MAC address. It is needed because the
constructed object will have a MAC address of 02:00:00:00:00:00
if the interface did not have a MAC address.

Test: added minimal unit test coverage
Change-Id: I422422d032afbbabcf8594def76702bb053f0a96
parent 21907e1c
Loading
Loading
Loading
Loading
+3 −1
Original line number Original line Diff line number Diff line
@@ -38,6 +38,7 @@ import java.net.SocketException;
public class InterfaceParams {
public class InterfaceParams {
    public final String name;
    public final String name;
    public final int index;
    public final int index;
    public final boolean hasMacAddress;
    public final MacAddress macAddr;
    public final MacAddress macAddr;
    public final int defaultMtu;
    public final int defaultMtu;


@@ -69,7 +70,8 @@ public class InterfaceParams {
        checkArgument((index > 0), "invalid interface index");
        checkArgument((index > 0), "invalid interface index");
        this.name = name;
        this.name = name;
        this.index = index;
        this.index = index;
        this.macAddr = (macAddr != null) ? macAddr : MacAddress.fromBytes(new byte[] {
        this.hasMacAddress = (macAddr != null);
        this.macAddr = hasMacAddress ? macAddr : MacAddress.fromBytes(new byte[] {
                0x02, 0x00, 0x00, 0x00, 0x00, 0x00 });
                0x02, 0x00, 0x00, 0x00, 0x00, 0x00 });
        this.defaultMtu = (defaultMtu > IPV6_MIN_MTU) ? defaultMtu : IPV6_MIN_MTU;
        this.defaultMtu = (defaultMtu > IPV6_MIN_MTU) ? defaultMtu : IPV6_MIN_MTU;
    }
    }
+19 −0
Original line number Original line Diff line number Diff line
@@ -52,6 +52,7 @@ import static junit.framework.Assert.fail;


import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertNull;
@@ -919,6 +920,24 @@ public class IpClientIntegrationTest {
        }
        }
    }
    }


    @Test
    public void testInterfaceParams() throws Exception {
        InterfaceParams params = InterfaceParams.getByName(mIfaceName);
        assertNotNull(params);
        assertEquals(mIfaceName, params.name);
        assertTrue(params.index > 0);
        assertNotNull(params.macAddr);
        assertTrue(params.hasMacAddress);

        // Sanity check.
        params = InterfaceParams.getByName("lo");
        assertNotNull(params);
        assertEquals("lo", params.name);
        assertTrue(params.index > 0);
        assertNotNull(params.macAddr);
        assertFalse(params.hasMacAddress);
    }

    @Test
    @Test
    public void testDhcpInit() throws Exception {
    public void testDhcpInit() throws Exception {
        startIpClientProvisioning(false /* isDhcpLeaseCacheEnabled */,
        startIpClientProvisioning(false /* isDhcpLeaseCacheEnabled */,
+2 −0
Original line number Original line Diff line number Diff line
@@ -17,6 +17,7 @@
package android.net.util;
package android.net.util;


import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertTrue;
@@ -49,6 +50,7 @@ public class InterfaceParamsTest {
        assertEquals("lo", ifParams.name);
        assertEquals("lo", ifParams.name);
        assertTrue(ifParams.index > 0);
        assertTrue(ifParams.index > 0);
        assertNotNull(ifParams.macAddr);
        assertNotNull(ifParams.macAddr);
        assertFalse(ifParams.hasMacAddress);
        assertTrue(ifParams.defaultMtu >= NetworkStackConstants.ETHER_MTU);
        assertTrue(ifParams.defaultMtu >= NetworkStackConstants.ETHER_MTU);
    }
    }
}
}