From aa9db67edcf6729f5c837ca77e42d0bcdc82baf4 Mon Sep 17 00:00:00 2001 From: Lorenzo Colitti Date: Thu, 15 Apr 2021 10:22:57 +0900 Subject: [PATCH 1/3] Import ConnectivityManager.BLOCKED_REASON_* from ConstantsShim. This is needed for the tests to compile in mainline-prod. Bug: 165835257 Test: atest CtsNetTestCases:android.net.ConnectivityManagerTest Change-Id: I32924824e9968996f379e31f1b28eb6a8f29bc5d --- .../cts/net/src/android/net/cts/ConnectivityManagerTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java b/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java index d67eb236f1..18617e85d6 100644 --- a/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java +++ b/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java @@ -28,8 +28,6 @@ import static android.content.pm.PackageManager.FEATURE_WIFI; import static android.content.pm.PackageManager.FEATURE_WIFI_DIRECT; import static android.content.pm.PackageManager.GET_PERMISSIONS; import static android.content.pm.PackageManager.PERMISSION_GRANTED; -import static android.net.ConnectivityManager.BLOCKED_REASON_LOCKDOWN_VPN; -import static android.net.ConnectivityManager.BLOCKED_REASON_NONE; import static android.net.ConnectivityManager.TYPE_BLUETOOTH; import static android.net.ConnectivityManager.TYPE_ETHERNET; import static android.net.ConnectivityManager.TYPE_MOBILE_CBS; @@ -64,6 +62,8 @@ import static android.system.OsConstants.AF_UNSPEC; import static com.android.compatibility.common.util.SystemUtil.runShellCommand; import static com.android.compatibility.common.util.SystemUtil.runWithShellPermissionIdentity; +import static com.android.networkstack.apishim.ConstantsShim.BLOCKED_REASON_LOCKDOWN_VPN; +import static com.android.networkstack.apishim.ConstantsShim.BLOCKED_REASON_NONE; import static com.android.testutils.MiscAsserts.assertThrows; import static com.android.testutils.TestPermissionUtil.runAsShell; From 7ba366de0bd21c14f93cde9adf9cf26ad6300e53 Mon Sep 17 00:00:00 2001 From: Lorenzo Colitti Date: Thu, 15 Apr 2021 13:13:00 +0900 Subject: [PATCH 2/3] Use the non-API static UserHandle.getUid method in tests. The code was updated in AOSP to use the new non-static UserHandle#getUid(int), which is only available in S or above. This fails to build in mainline-prod. Instead of defining a shim for this, simply use an older method that takes a userId. Bug: 165835257 Test: atest CtsNetTestCases:android.net.cts.ConnectivityManagerTest Test: CtsNetTestCasesLatestSdk:android.net.cts.ConnectivityManagerTest Change-Id: Id529f8b201cc871aa3155aef0f44574d88040c2d --- tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java b/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java index 18617e85d6..90bdb5eb2a 100644 --- a/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java +++ b/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java @@ -1823,7 +1823,7 @@ public class ConnectivityManagerTest { final DetailedBlockedStatusCallback otherUidCallback = new DetailedBlockedStatusCallback(); final int myUid = Process.myUid(); - final int otherUid = UserHandle.of(5).getUid(Process.FIRST_APPLICATION_UID); + final int otherUid = UserHandle.getUid(5, Process.FIRST_APPLICATION_UID); final Handler handler = new Handler(Looper.getMainLooper()); mCm.registerDefaultNetworkCallback(myUidCallback, handler); mCmShim.registerDefaultNetworkCallbackAsUid(otherUid, otherUidCallback, handler); From ddeb269ca0ff7b6d01e35e5f3f2e2be9a8dde62b Mon Sep 17 00:00:00 2001 From: Lorenzo Colitti Date: Thu, 15 Apr 2021 13:24:22 +0900 Subject: [PATCH 3/3] Fix CtsNetTestCasesLatestSdk in AOSP. This test suite is broken in AOSP due to a number of tests that depend on S APIs. We attempted to prevent those tests running on R builds with: @IgnoreUpTo(Build.VERSION_CODES.R) but this is not sufficient for them to pass when the test is compiled against the R SDK (e.g., in CtsNetTestCasesLatestSdk). This is because when compiling against the R SDK, the test uses the API 30 shims, which throw UnsupportedApiLevelException even though the method actually exists on device. Fix this using: assumeTrue(shouldTestSApis()); This is not great, but at least it unbreaks the tests for now. Test: atest CtsNetTestCases:android.net.cts.ConnectivityManagerTest Test: atest CtsNetTestCasesLatestSdk:android.net.cts.ConnectivityManagerTest Change-Id: Ifee0aea5afef6bd4bc762a4b1f25fc05e562d49a --- .../android/net/cts/ConnectivityManagerTest.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java b/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java index 90bdb5eb2a..e8751d86d5 100644 --- a/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java +++ b/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java @@ -137,7 +137,6 @@ import com.android.networkstack.apishim.ConstantsShim; import com.android.networkstack.apishim.common.ConnectivityManagerShim; import com.android.testutils.CompatUtil; import com.android.testutils.DevSdkIgnoreRule; -import com.android.testutils.DevSdkIgnoreRule.IgnoreUpTo; import com.android.testutils.DevSdkIgnoreRuleKt; import com.android.testutils.RecorderCallback.CallbackEntry; import com.android.testutils.SkipPresubmit; @@ -1719,8 +1718,11 @@ public class ConnectivityManagerTest { * {@link android.Manifest.permission.NETWORK_SETTINGS}. */ @Test - @IgnoreUpTo(Build.VERSION_CODES.R) public void testRequestBackgroundNetwork() { + // Cannot use @IgnoreUpTo(Build.VERSION_CODES.R) because this test also requires API 31 + // shims, and @IgnoreUpTo does not check that. + assumeTrue(shouldTestSApis()); + // Create a tun interface. Use the returned interface name as the specifier to create // a test network request. final TestNetworkManager tnm = runWithShellPermissionIdentity(() -> @@ -1861,8 +1863,10 @@ public class ConnectivityManagerTest { } @Test - @IgnoreUpTo(Build.VERSION_CODES.R) public void testBlockedStatusCallback() { + // Cannot use @IgnoreUpTo(Build.VERSION_CODES.R) because this test also requires API 31 + // shims, and @IgnoreUpTo does not check that. + assumeTrue(shouldTestSApis()); runWithShellPermissionIdentity(() -> doTestBlockedStatusCallback(), NETWORK_SETTINGS); } @@ -1893,8 +1897,10 @@ public class ConnectivityManagerTest { } @Test - @IgnoreUpTo(Build.VERSION_CODES.R) public void testLegacyLockdownEnabled() { + // Cannot use @IgnoreUpTo(Build.VERSION_CODES.R) because this test also requires API 31 + // shims, and @IgnoreUpTo does not check that. + assumeTrue(shouldTestSApis()); runWithShellPermissionIdentity(() -> doTestLegacyLockdownEnabled(), NETWORK_SETTINGS); }