Loading apishim/common/com/android/networkstack/apishim/ShimUtils.java +7 −0 Original line number Diff line number Diff line Loading @@ -42,4 +42,11 @@ public final class ShimUtils { + ("REL".equals(Build.VERSION.CODENAME) ? 0 : 1); return devApiLevel > apiLevel; } /** * Check whether the device supports in-development or final R networking APIs. */ public static boolean isAtLeastR() { return isReleaseOrDevelopmentApiAbove(Build.VERSION_CODES.Q); } } common/moduleutils/src/android/net/util/InterfaceParams.java +6 −4 Original line number Diff line number Diff line Loading @@ -16,8 +16,6 @@ package android.net.util; import static com.android.internal.util.Preconditions.checkArgument; import android.net.MacAddress; import android.text.TextUtils; Loading Loading @@ -66,8 +64,12 @@ public class InterfaceParams { } public InterfaceParams(String name, int index, MacAddress macAddr, int defaultMtu) { checkArgument((!TextUtils.isEmpty(name)), "impossible interface name"); checkArgument((index > 0), "invalid interface index"); if (TextUtils.isEmpty(name)) { throw new IllegalArgumentException("impossible interface name"); } if (index <= 0) throw new IllegalArgumentException("invalid interface index"); this.name = name; this.index = index; this.hasMacAddress = (macAddr != null); Loading src/android/net/ip/IpClient.java +15 −14 Original line number Diff line number Diff line Loading @@ -74,7 +74,6 @@ import com.android.internal.util.HexDump; import com.android.internal.util.IState; import com.android.internal.util.IndentingPrintWriter; import com.android.internal.util.MessageUtils; import com.android.internal.util.Preconditions; import com.android.internal.util.State; import com.android.internal.util.StateMachine; import com.android.internal.util.WakeupMessage; Loading Loading @@ -549,8 +548,8 @@ public class IpClient extends StateMachine { NetworkObserverRegistry observerRegistry, NetworkStackServiceManager nssManager, Dependencies deps) { super(IpClient.class.getSimpleName() + "." + ifName); Preconditions.checkNotNull(ifName); Preconditions.checkNotNull(callback); Objects.requireNonNull(ifName); Objects.requireNonNull(callback); mTag = getName(); Loading Loading @@ -1699,25 +1698,27 @@ public class IpClient extends StateMachine { class ClearingIpAddressesState extends State { @Override public void enter() { if (readyToProceed()) { deferMessage(obtainMessage(CMD_ADDRESSES_CLEARED)); } else { // Clear all IPv4 and IPv6 before proceeding to RunningState. // Clean up any leftover state from an abnormal exit from // tethering or during an IpClient restart. stopAllIP(); } // Ensure that interface parameters are fetched on the handler thread so they are // properly ordered with other events, such as restoring the interface MTU on teardown. mInterfaceParams = mDependencies.getInterfaceParams(mInterfaceName); if (mInterfaceParams == null) { logError("Failed to find InterfaceParams for " + mInterfaceName); doImmediateProvisioningFailure(IpManagerEvent.ERROR_INTERFACE_NOT_FOUND); transitionTo(mStoppedState); deferMessage(obtainMessage(CMD_STOP)); return; } mLinkObserver.setInterfaceParams(mInterfaceParams); if (readyToProceed()) { deferMessage(obtainMessage(CMD_ADDRESSES_CLEARED)); } else { // Clear all IPv4 and IPv6 before proceeding to RunningState. // Clean up any leftover state from an abnormal exit from // tethering or during an IpClient restart. stopAllIP(); } mCallback.setNeighborDiscoveryOffload(true); } Loading Loading @@ -1752,7 +1753,7 @@ public class IpClient extends StateMachine { } private boolean readyToProceed() { return (!mLinkProperties.hasIpv4Address() && !mLinkProperties.hasGlobalIpv6Address()); return !mLinkProperties.hasIpv4Address() && !mLinkProperties.hasGlobalIpv6Address(); } } Loading tests/integration/src/android/net/ip/IpClientIntegrationTest.java +2 −2 Original line number Diff line number Diff line Loading @@ -653,7 +653,7 @@ public class IpClientIntegrationTest { } private void assertNoHostname(String hostname) { if (ShimUtils.isReleaseOrDevelopmentApiAbove(Build.VERSION_CODES.Q)) { if (ShimUtils.isAtLeastR()) { assertNull(hostname); } else { // Until Q, if no hostname is set, the device falls back to the hostname set via Loading Loading @@ -1815,7 +1815,7 @@ public class IpClientIntegrationTest { // Ensure that the URL was set as expected in the callbacks. // Can't verify the URL up to Q as there is no such attribute in LinkProperties. if (!ShimUtils.isReleaseOrDevelopmentApiAbove(Build.VERSION_CODES.Q)) return; if (!ShimUtils.isAtLeastR()) return; verify(mCb).onLinkPropertiesChange(captor.capture()); assertTrue(captor.getAllValues().stream().anyMatch( lp -> Objects.equals(expectedUrl, lp.getCaptivePortalApiUrl()))); Loading tests/unit/src/android/net/netlink/InetDiagSocketTest.java +2 −3 Original line number Diff line number Diff line Loading @@ -37,7 +37,6 @@ import android.app.Instrumentation; import android.content.Context; import android.net.ConnectivityManager; import android.net.netlink.StructNlMsgHdr; import android.os.Build; import android.os.Process; import android.system.Os; Loading Loading @@ -196,7 +195,7 @@ public class InetDiagSocketTest { @Test public void testGetConnectionOwnerUid() throws Exception { // Skip the test for API <= Q, as b/141603906 this was only fixed in Q-QPR2 assumeTrue(ShimUtils.isReleaseOrDevelopmentApiAbove(Build.VERSION_CODES.Q)); assumeTrue(ShimUtils.isAtLeastR()); checkGetConnectionOwnerUid("::", null); checkGetConnectionOwnerUid("::", "::"); checkGetConnectionOwnerUid("0.0.0.0", null); Loading @@ -211,7 +210,7 @@ public class InetDiagSocketTest { @Test public void testB141603906() throws Exception { // Skip the test for API <= Q, as b/141603906 this was only fixed in Q-QPR2 assumeTrue(ShimUtils.isReleaseOrDevelopmentApiAbove(Build.VERSION_CODES.Q)); assumeTrue(ShimUtils.isAtLeastR()); final InetSocketAddress src = new InetSocketAddress(0); final InetSocketAddress dst = new InetSocketAddress(0); final int numThreads = 8; Loading Loading
apishim/common/com/android/networkstack/apishim/ShimUtils.java +7 −0 Original line number Diff line number Diff line Loading @@ -42,4 +42,11 @@ public final class ShimUtils { + ("REL".equals(Build.VERSION.CODENAME) ? 0 : 1); return devApiLevel > apiLevel; } /** * Check whether the device supports in-development or final R networking APIs. */ public static boolean isAtLeastR() { return isReleaseOrDevelopmentApiAbove(Build.VERSION_CODES.Q); } }
common/moduleutils/src/android/net/util/InterfaceParams.java +6 −4 Original line number Diff line number Diff line Loading @@ -16,8 +16,6 @@ package android.net.util; import static com.android.internal.util.Preconditions.checkArgument; import android.net.MacAddress; import android.text.TextUtils; Loading Loading @@ -66,8 +64,12 @@ public class InterfaceParams { } public InterfaceParams(String name, int index, MacAddress macAddr, int defaultMtu) { checkArgument((!TextUtils.isEmpty(name)), "impossible interface name"); checkArgument((index > 0), "invalid interface index"); if (TextUtils.isEmpty(name)) { throw new IllegalArgumentException("impossible interface name"); } if (index <= 0) throw new IllegalArgumentException("invalid interface index"); this.name = name; this.index = index; this.hasMacAddress = (macAddr != null); Loading
src/android/net/ip/IpClient.java +15 −14 Original line number Diff line number Diff line Loading @@ -74,7 +74,6 @@ import com.android.internal.util.HexDump; import com.android.internal.util.IState; import com.android.internal.util.IndentingPrintWriter; import com.android.internal.util.MessageUtils; import com.android.internal.util.Preconditions; import com.android.internal.util.State; import com.android.internal.util.StateMachine; import com.android.internal.util.WakeupMessage; Loading Loading @@ -549,8 +548,8 @@ public class IpClient extends StateMachine { NetworkObserverRegistry observerRegistry, NetworkStackServiceManager nssManager, Dependencies deps) { super(IpClient.class.getSimpleName() + "." + ifName); Preconditions.checkNotNull(ifName); Preconditions.checkNotNull(callback); Objects.requireNonNull(ifName); Objects.requireNonNull(callback); mTag = getName(); Loading Loading @@ -1699,25 +1698,27 @@ public class IpClient extends StateMachine { class ClearingIpAddressesState extends State { @Override public void enter() { if (readyToProceed()) { deferMessage(obtainMessage(CMD_ADDRESSES_CLEARED)); } else { // Clear all IPv4 and IPv6 before proceeding to RunningState. // Clean up any leftover state from an abnormal exit from // tethering or during an IpClient restart. stopAllIP(); } // Ensure that interface parameters are fetched on the handler thread so they are // properly ordered with other events, such as restoring the interface MTU on teardown. mInterfaceParams = mDependencies.getInterfaceParams(mInterfaceName); if (mInterfaceParams == null) { logError("Failed to find InterfaceParams for " + mInterfaceName); doImmediateProvisioningFailure(IpManagerEvent.ERROR_INTERFACE_NOT_FOUND); transitionTo(mStoppedState); deferMessage(obtainMessage(CMD_STOP)); return; } mLinkObserver.setInterfaceParams(mInterfaceParams); if (readyToProceed()) { deferMessage(obtainMessage(CMD_ADDRESSES_CLEARED)); } else { // Clear all IPv4 and IPv6 before proceeding to RunningState. // Clean up any leftover state from an abnormal exit from // tethering or during an IpClient restart. stopAllIP(); } mCallback.setNeighborDiscoveryOffload(true); } Loading Loading @@ -1752,7 +1753,7 @@ public class IpClient extends StateMachine { } private boolean readyToProceed() { return (!mLinkProperties.hasIpv4Address() && !mLinkProperties.hasGlobalIpv6Address()); return !mLinkProperties.hasIpv4Address() && !mLinkProperties.hasGlobalIpv6Address(); } } Loading
tests/integration/src/android/net/ip/IpClientIntegrationTest.java +2 −2 Original line number Diff line number Diff line Loading @@ -653,7 +653,7 @@ public class IpClientIntegrationTest { } private void assertNoHostname(String hostname) { if (ShimUtils.isReleaseOrDevelopmentApiAbove(Build.VERSION_CODES.Q)) { if (ShimUtils.isAtLeastR()) { assertNull(hostname); } else { // Until Q, if no hostname is set, the device falls back to the hostname set via Loading Loading @@ -1815,7 +1815,7 @@ public class IpClientIntegrationTest { // Ensure that the URL was set as expected in the callbacks. // Can't verify the URL up to Q as there is no such attribute in LinkProperties. if (!ShimUtils.isReleaseOrDevelopmentApiAbove(Build.VERSION_CODES.Q)) return; if (!ShimUtils.isAtLeastR()) return; verify(mCb).onLinkPropertiesChange(captor.capture()); assertTrue(captor.getAllValues().stream().anyMatch( lp -> Objects.equals(expectedUrl, lp.getCaptivePortalApiUrl()))); Loading
tests/unit/src/android/net/netlink/InetDiagSocketTest.java +2 −3 Original line number Diff line number Diff line Loading @@ -37,7 +37,6 @@ import android.app.Instrumentation; import android.content.Context; import android.net.ConnectivityManager; import android.net.netlink.StructNlMsgHdr; import android.os.Build; import android.os.Process; import android.system.Os; Loading Loading @@ -196,7 +195,7 @@ public class InetDiagSocketTest { @Test public void testGetConnectionOwnerUid() throws Exception { // Skip the test for API <= Q, as b/141603906 this was only fixed in Q-QPR2 assumeTrue(ShimUtils.isReleaseOrDevelopmentApiAbove(Build.VERSION_CODES.Q)); assumeTrue(ShimUtils.isAtLeastR()); checkGetConnectionOwnerUid("::", null); checkGetConnectionOwnerUid("::", "::"); checkGetConnectionOwnerUid("0.0.0.0", null); Loading @@ -211,7 +210,7 @@ public class InetDiagSocketTest { @Test public void testB141603906() throws Exception { // Skip the test for API <= Q, as b/141603906 this was only fixed in Q-QPR2 assumeTrue(ShimUtils.isReleaseOrDevelopmentApiAbove(Build.VERSION_CODES.Q)); assumeTrue(ShimUtils.isAtLeastR()); final InetSocketAddress src = new InetSocketAddress(0); final InetSocketAddress dst = new InetSocketAddress(0); final int numThreads = 8; Loading