summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLorenzo Colitti <lorenzo@google.com>2020-04-28 00:31:10 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2020-04-28 00:31:10 +0000
commit7dd51c66504ce5ea2401489f13a1bbe789241751 (patch)
tree45cb88a4d3efe7e39e4de565da7c7d14e7685663
parent1725a2cd922f7af15538a856c9482f004b4535ff (diff)
parent26f7f6204173d1d56ec9981da7a00711341a0132 (diff)
Merge "Add a ShimUtils.isAtLeastR() and use it in tests." into rvc-dev
-rw-r--r--apishim/common/com/android/networkstack/apishim/ShimUtils.java7
-rw-r--r--tests/integration/src/android/net/ip/IpClientIntegrationTest.java4
-rw-r--r--tests/unit/src/android/net/netlink/InetDiagSocketTest.java5
-rw-r--r--tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java8
4 files changed, 15 insertions, 9 deletions
diff --git a/apishim/common/com/android/networkstack/apishim/ShimUtils.java b/apishim/common/com/android/networkstack/apishim/ShimUtils.java
index e9b5305..a9afe51 100644
--- a/apishim/common/com/android/networkstack/apishim/ShimUtils.java
+++ b/apishim/common/com/android/networkstack/apishim/ShimUtils.java
@@ -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);
+ }
}
diff --git a/tests/integration/src/android/net/ip/IpClientIntegrationTest.java b/tests/integration/src/android/net/ip/IpClientIntegrationTest.java
index 98393b8..4210619 100644
--- a/tests/integration/src/android/net/ip/IpClientIntegrationTest.java
+++ b/tests/integration/src/android/net/ip/IpClientIntegrationTest.java
@@ -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
@@ -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())));
diff --git a/tests/unit/src/android/net/netlink/InetDiagSocketTest.java b/tests/unit/src/android/net/netlink/InetDiagSocketTest.java
index 6b5ebdc..702de47 100644
--- a/tests/unit/src/android/net/netlink/InetDiagSocketTest.java
+++ b/tests/unit/src/android/net/netlink/InetDiagSocketTest.java
@@ -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;
@@ -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);
@@ -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;
diff --git a/tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java b/tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java
index cc5b40d..669a14e 100644
--- a/tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java
+++ b/tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java
@@ -815,7 +815,7 @@ public class NetworkMonitorTest {
private static CellIdentityGsm makeCellIdentityGsm(int lac, int cid, int arfcn, int bsic,
String mccStr, String mncStr, String alphal, String alphas)
throws ReflectiveOperationException {
- if (ShimUtils.isReleaseOrDevelopmentApiAbove(Build.VERSION_CODES.Q)) {
+ if (ShimUtils.isAtLeastR()) {
return new CellIdentityGsm(lac, cid, arfcn, bsic, mccStr, mncStr, alphal, alphas,
Collections.emptyList() /* additionalPlmns */);
} else {
@@ -830,7 +830,7 @@ public class NetworkMonitorTest {
private static CellIdentityLte makeCellIdentityLte(int ci, int pci, int tac, int earfcn,
int bandwidth, String mccStr, String mncStr, String alphal, String alphas)
throws ReflectiveOperationException {
- if (ShimUtils.isReleaseOrDevelopmentApiAbove(Build.VERSION_CODES.Q)) {
+ if (ShimUtils.isAtLeastR()) {
return new CellIdentityLte(ci, pci, tac, earfcn, new int[] {} /* bands */,
bandwidth, mccStr, mncStr, alphal, alphas,
Collections.emptyList() /* additionalPlmns */, null /* csgInfo */);
@@ -1739,13 +1739,13 @@ public class NetworkMonitorTest {
@Test
public void testDismissPortalInValidatedNetworkEnabledOsSupported() throws Exception {
- assumeTrue(ShimUtils.isReleaseOrDevelopmentApiAbove(Build.VERSION_CODES.Q));
+ assumeTrue(ShimUtils.isAtLeastR());
testDismissPortalInValidatedNetworkEnabled(TEST_LOGIN_URL);
}
@Test
public void testDismissPortalInValidatedNetworkEnabledOsNotSupported() throws Exception {
- assumeFalse(ShimUtils.isReleaseOrDevelopmentApiAbove(Build.VERSION_CODES.Q));
+ assumeFalse(ShimUtils.isAtLeastR());
testDismissPortalInValidatedNetworkEnabled(TEST_HTTP_URL);
}