Loading common/moduleutils/src/android/net/util/InterfaceParams.java +3 −1 Original line number Diff line number Diff line Loading @@ -38,6 +38,7 @@ import java.net.SocketException; public class InterfaceParams { public final String name; public final int index; public final boolean hasMacAddress; public final MacAddress macAddr; public final int defaultMtu; Loading Loading @@ -69,7 +70,8 @@ public class InterfaceParams { checkArgument((index > 0), "invalid interface index"); this.name = name; 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 }); this.defaultMtu = (defaultMtu > IPV6_MIN_MTU) ? defaultMtu : IPV6_MIN_MTU; } Loading tests/integration/src/android/net/ip/IpClientIntegrationTest.java +19 −0 Original line number Diff line number Diff line Loading @@ -52,6 +52,7 @@ import static junit.framework.Assert.fail; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; Loading Loading @@ -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 public void testDhcpInit() throws Exception { startIpClientProvisioning(false /* isDhcpLeaseCacheEnabled */, Loading tests/unit/src/android/net/util/InterfaceParamsTest.java +2 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package android.net.util; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; Loading Loading @@ -49,6 +50,7 @@ public class InterfaceParamsTest { assertEquals("lo", ifParams.name); assertTrue(ifParams.index > 0); assertNotNull(ifParams.macAddr); assertFalse(ifParams.hasMacAddress); assertTrue(ifParams.defaultMtu >= NetworkStackConstants.ETHER_MTU); } } Loading
common/moduleutils/src/android/net/util/InterfaceParams.java +3 −1 Original line number Diff line number Diff line Loading @@ -38,6 +38,7 @@ import java.net.SocketException; public class InterfaceParams { public final String name; public final int index; public final boolean hasMacAddress; public final MacAddress macAddr; public final int defaultMtu; Loading Loading @@ -69,7 +70,8 @@ public class InterfaceParams { checkArgument((index > 0), "invalid interface index"); this.name = name; 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 }); this.defaultMtu = (defaultMtu > IPV6_MIN_MTU) ? defaultMtu : IPV6_MIN_MTU; } Loading
tests/integration/src/android/net/ip/IpClientIntegrationTest.java +19 −0 Original line number Diff line number Diff line Loading @@ -52,6 +52,7 @@ import static junit.framework.Assert.fail; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; Loading Loading @@ -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 public void testDhcpInit() throws Exception { startIpClientProvisioning(false /* isDhcpLeaseCacheEnabled */, Loading
tests/unit/src/android/net/util/InterfaceParamsTest.java +2 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package android.net.util; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; Loading Loading @@ -49,6 +50,7 @@ public class InterfaceParamsTest { assertEquals("lo", ifParams.name); assertTrue(ifParams.index > 0); assertNotNull(ifParams.macAddr); assertFalse(ifParams.hasMacAddress); assertTrue(ifParams.defaultMtu >= NetworkStackConstants.ETHER_MTU); } }