From 2f87cc0610012c1f61ac9eb3c0b663a0f77d1ace Mon Sep 17 00:00:00 2001 From: Lorenzo Colitti Date: Fri, 20 Sep 2024 13:18:02 +0900 Subject: [PATCH 1/5] Stop depending on shims in CtsHostsideNetworkTests. These are no longer necessary, and now that udc-mainline-prod is gone, we are moving away from shims entirely. Bug: 365191921 Test: test-only change Change-Id: Ia441170c25a04d7b146b48e170d53e0916d49ecf --- tests/cts/hostside/app/Android.bp | 6 ------ .../android/cts/net/hostside/MyVpnService.java | 18 +++--------------- .../com/android/cts/net/hostside/VpnTest.java | 6 +++--- tests/cts/hostside/app2/Android.bp | 1 - 4 files changed, 6 insertions(+), 25 deletions(-) diff --git a/tests/cts/hostside/app/Android.bp b/tests/cts/hostside/app/Android.bp index 40cabc4f75..a6a1b7614b 100644 --- a/tests/cts/hostside/app/Android.bp +++ b/tests/cts/hostside/app/Android.bp @@ -54,9 +54,6 @@ android_test_helper_app { "framework-connectivity-test-defaults", "CtsHostsideNetworkTestsAppDefaults", ], - static_libs: [ - "NetworkStackApiStableShims", - ], } android_test_helper_app { @@ -67,7 +64,4 @@ android_test_helper_app { "CtsHostsideNetworkTestsAppDefaults", "ConnectivityNextEnableDefaults", ], - static_libs: [ - "NetworkStackApiCurrentShims", - ], } diff --git a/tests/cts/hostside/app/src/com/android/cts/net/hostside/MyVpnService.java b/tests/cts/hostside/app/src/com/android/cts/net/hostside/MyVpnService.java index fe522a0246..a39a8d015f 100644 --- a/tests/cts/hostside/app/src/com/android/cts/net/hostside/MyVpnService.java +++ b/tests/cts/hostside/app/src/com/android/cts/net/hostside/MyVpnService.java @@ -29,9 +29,6 @@ import android.util.Log; import android.util.Pair; import com.android.modules.utils.build.SdkLevel; -import com.android.networkstack.apishim.VpnServiceBuilderShimImpl; -import com.android.networkstack.apishim.common.UnsupportedApiLevelException; -import com.android.networkstack.apishim.common.VpnServiceBuilderShim; import com.android.testutils.PacketReflector; import java.io.IOException; @@ -102,8 +99,7 @@ public class MyVpnService extends VpnService { } private void start(String packageName, Intent intent) { - Builder builder = new Builder(); - VpnServiceBuilderShim vpnServiceBuilderShim = VpnServiceBuilderShimImpl.newInstance(); + VpnService.Builder builder = new VpnService.Builder(); final String addresses = parseIpAndMaskListArgument(packageName, intent, "addresses", builder::addAddress); @@ -112,11 +108,7 @@ public class MyVpnService extends VpnService { if (SdkLevel.isAtLeastT() && intent.getBooleanExtra(packageName + ".addRoutesByIpPrefix", false)) { addedRoutes = parseIpPrefixListArgument(packageName, intent, "routes", (prefix) -> { - try { - vpnServiceBuilderShim.addRoute(builder, prefix); - } catch (UnsupportedApiLevelException e) { - throw new RuntimeException(e); - } + builder.addRoute(prefix); }); } else { addedRoutes = parseIpAndMaskListArgument(packageName, intent, "routes", @@ -127,11 +119,7 @@ public class MyVpnService extends VpnService { if (SdkLevel.isAtLeastT()) { excludedRoutes = parseIpPrefixListArgument(packageName, intent, "excludedRoutes", (prefix) -> { - try { - vpnServiceBuilderShim.excludeRoute(builder, prefix); - } catch (UnsupportedApiLevelException e) { - throw new RuntimeException(e); - } + builder.excludeRoute(prefix); }); } diff --git a/tests/cts/hostside/app/src/com/android/cts/net/hostside/VpnTest.java b/tests/cts/hostside/app/src/com/android/cts/net/hostside/VpnTest.java index d7631ebb62..d05a8d075c 100755 --- a/tests/cts/hostside/app/src/com/android/cts/net/hostside/VpnTest.java +++ b/tests/cts/hostside/app/src/com/android/cts/net/hostside/VpnTest.java @@ -20,8 +20,11 @@ import static android.Manifest.permission.MANAGE_TEST_NETWORKS; import static android.Manifest.permission.NETWORK_SETTINGS; import static android.Manifest.permission.READ_DEVICE_CONFIG; import static android.Manifest.permission.WRITE_DEVICE_CONFIG; +import static android.content.Context.RECEIVER_EXPORTED; import static android.content.pm.PackageManager.FEATURE_TELEPHONY; import static android.content.pm.PackageManager.FEATURE_WIFI; +import static android.net.ConnectivityManager.BLOCKED_REASON_LOCKDOWN_VPN; +import static android.net.ConnectivityManager.BLOCKED_REASON_NONE; import static android.net.ConnectivityManager.FIREWALL_CHAIN_BACKGROUND; import static android.net.ConnectivityManager.TYPE_VPN; import static android.net.NetworkCapabilities.TRANSPORT_TEST; @@ -46,9 +49,6 @@ import static com.android.cts.net.hostside.VpnTest.TestSocketKeepaliveCallback.C import static com.android.cts.net.hostside.VpnTest.TestSocketKeepaliveCallback.CallbackType.ON_RESUMED; import static com.android.cts.net.hostside.VpnTest.TestSocketKeepaliveCallback.CallbackType.ON_STARTED; import static com.android.cts.net.hostside.VpnTest.TestSocketKeepaliveCallback.CallbackType.ON_STOPPED; -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.networkstack.apishim.ConstantsShim.RECEIVER_EXPORTED; import static com.android.testutils.Cleanup.testAndCleanup; import static com.android.testutils.RecorderCallback.CallbackEntry.BLOCKED_STATUS_INT; import static com.android.testutils.TestPermissionUtil.runAsShell; diff --git a/tests/cts/hostside/app2/Android.bp b/tests/cts/hostside/app2/Android.bp index cb55c7b8e9..24fe6f6d2a 100644 --- a/tests/cts/hostside/app2/Android.bp +++ b/tests/cts/hostside/app2/Android.bp @@ -26,7 +26,6 @@ android_test_helper_app { static_libs: [ "androidx.annotation_annotation", "CtsHostsideNetworkTestsAidl", - "NetworkStackApiStableShims", ], srcs: ["src/**/*.java"], // Tag this module as a cts test artifact From 64cd28ddd768178248a2afe72af11a555d978204 Mon Sep 17 00:00:00 2001 From: Lorenzo Colitti Date: Fri, 20 Sep 2024 13:40:10 +0900 Subject: [PATCH 2/5] Consolidate defaults for hostside network tests apps. For now, only share a couple of statements (min_sdk_version and platform_apis). More will be added later. Also, remove the test_suites stanzas everywhere. These are not relevant for test apps because the APKs will be pulled in by the data: stanzas anyway. Bug: 365191921 Test: atest CtsHostsideNetworkTests Change-Id: If510519b3bdd6ab27c1923bae523cddb694e0ecc --- tests/cts/hostside/Android.bp | 6 ++++++ tests/cts/hostside/app/Android.bp | 9 ++------- tests/cts/hostside/app2/Android.bp | 13 ++++--------- tests/cts/hostside/networkslicingtestapp/Android.bp | 11 +++-------- 4 files changed, 15 insertions(+), 24 deletions(-) diff --git a/tests/cts/hostside/Android.bp b/tests/cts/hostside/Android.bp index 14d5d5463a..0f87dc2bfe 100644 --- a/tests/cts/hostside/Android.bp +++ b/tests/cts/hostside/Android.bp @@ -23,6 +23,12 @@ package { default_applicable_licenses: ["Android-Apache-2.0"], } +java_defaults { + name: "CtsHostsideNetworkTestsAllAppDefaults", + platform_apis: true, + min_sdk_version: "30", +} + java_test_host { name: "CtsHostsideNetworkTests", defaults: ["cts_defaults"], diff --git a/tests/cts/hostside/app/Android.bp b/tests/cts/hostside/app/Android.bp index a6a1b7614b..c1b364c7aa 100644 --- a/tests/cts/hostside/app/Android.bp +++ b/tests/cts/hostside/app/Android.bp @@ -21,7 +21,6 @@ package { java_defaults { name: "CtsHostsideNetworkTestsAppDefaults", - platform_apis: true, static_libs: [ "CtsHostsideNetworkTestsAidl", "androidx.test.ext.junit", @@ -39,12 +38,6 @@ java_defaults { srcs: [ "src/**/*.java", ], - // Tag this module as a cts test artifact - test_suites: [ - "general-tests", - "sts", - ], - min_sdk_version: "30", } android_test_helper_app { @@ -53,6 +46,7 @@ android_test_helper_app { "cts_support_defaults", "framework-connectivity-test-defaults", "CtsHostsideNetworkTestsAppDefaults", + "CtsHostsideNetworkTestsAllAppDefaults", ], } @@ -62,6 +56,7 @@ android_test_helper_app { "cts_support_defaults", "framework-connectivity-test-defaults", "CtsHostsideNetworkTestsAppDefaults", + "CtsHostsideNetworkTestsAllAppDefaults", "ConnectivityNextEnableDefaults", ], } diff --git a/tests/cts/hostside/app2/Android.bp b/tests/cts/hostside/app2/Android.bp index 24fe6f6d2a..05abcdd022 100644 --- a/tests/cts/hostside/app2/Android.bp +++ b/tests/cts/hostside/app2/Android.bp @@ -21,19 +21,14 @@ package { android_test_helper_app { name: "CtsHostsideNetworkTestsApp2", - defaults: ["cts_support_defaults"], - platform_apis: true, + defaults: [ + "cts_support_defaults", + "CtsHostsideNetworkTestsAllAppDefaults", + ], static_libs: [ "androidx.annotation_annotation", "CtsHostsideNetworkTestsAidl", ], srcs: ["src/**/*.java"], - // Tag this module as a cts test artifact - test_suites: [ - "cts", - "general-tests", - "sts", - ], sdk_version: "test_current", - min_sdk_version: "30", } diff --git a/tests/cts/hostside/networkslicingtestapp/Android.bp b/tests/cts/hostside/networkslicingtestapp/Android.bp index 79ad2e2138..0eed51cc54 100644 --- a/tests/cts/hostside/networkslicingtestapp/Android.bp +++ b/tests/cts/hostside/networkslicingtestapp/Android.bp @@ -21,7 +21,6 @@ package { java_defaults { name: "CtsHostsideNetworkCapTestsAppDefaults", - platform_apis: true, static_libs: [ "androidx.test.ext.junit", "androidx.test.rules", @@ -29,13 +28,6 @@ java_defaults { "cts-net-utils", ], srcs: ["src/**/*.java"], - // Tag this module as a cts test artifact - test_suites: [ - "cts", - "general-tests", - "sts", - ], - min_sdk_version: "30", } android_test_helper_app { @@ -43,6 +35,7 @@ android_test_helper_app { defaults: [ "cts_support_defaults", "CtsHostsideNetworkCapTestsAppDefaults", + "CtsHostsideNetworkTestsAllAppDefaults", ], manifest: "AndroidManifestWithoutProperty.xml", sdk_version: "test_current", @@ -53,6 +46,7 @@ android_test_helper_app { defaults: [ "cts_support_defaults", "CtsHostsideNetworkCapTestsAppDefaults", + "CtsHostsideNetworkTestsAllAppDefaults", ], manifest: "AndroidManifestWithProperty.xml", sdk_version: "test_current", @@ -63,6 +57,7 @@ android_test_helper_app { defaults: [ "cts_support_defaults", "CtsHostsideNetworkCapTestsAppDefaults", + "CtsHostsideNetworkTestsAllAppDefaults", ], target_sdk_version: "33", manifest: "AndroidManifestWithoutProperty.xml", From 6a655a02d126e097a7023767f30c8b4dbe17128b Mon Sep 17 00:00:00 2001 From: Lorenzo Colitti Date: Fri, 20 Sep 2024 13:42:23 +0900 Subject: [PATCH 3/5] Set all hostside network tests apps' target SDK to 10000. This ensures they are subject to the most restrictive target SDK restrictions and that we never have to manually increment their target SDK version. Bug: 365191921 Test: atest CtsHostsideNetworkTests Change-Id: I66e4e53720b2860094b7a4d3194a81a063b116da --- tests/cts/hostside/Android.bp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/cts/hostside/Android.bp b/tests/cts/hostside/Android.bp index 0f87dc2bfe..3050d9a15e 100644 --- a/tests/cts/hostside/Android.bp +++ b/tests/cts/hostside/Android.bp @@ -27,6 +27,16 @@ java_defaults { name: "CtsHostsideNetworkTestsAllAppDefaults", platform_apis: true, min_sdk_version: "30", + // Set target SDK to 10000 so that all the test helper apps are always subject to the most + // recent (and possibly most restrictive) target SDK behaviour. Also, this matches the target + // SDK of the tests themselves, and of other tests such as CtsNetTestCases. + // Note that some of the test helper apps (e.g., CtsHostsideNetworkCapTestsAppSdk33) override + // this with older SDK versions. + // Also note that unlike android_test targets, "current" does not work: the target SDK is set to + // something like "VanillaIceCream" instead of 100000. This means that the tests will not run on + // released devices with errors such as "Requires development platform VanillaIceCream but this + // is a release platform". + target_sdk_version: "10000", } java_test_host { From 0820ccb0334581f581b735515153785677952f02 Mon Sep 17 00:00:00 2001 From: Lorenzo Colitti Date: Fri, 20 Sep 2024 14:45:49 +0900 Subject: [PATCH 4/5] Remove CtsHostsideNetworkTestAppNext. This is now identical to CtsHostsideNetworkTestsApp, and we're getting rid of -Next targets anyway, so there's no point in keeping it. Bug: 365191921 Test: atest CtsHostsideNetworkTests Change-Id: I57eb7c6d9bc37d222a9449bbc85265e7c6ec9ffc --- tests/cts/hostside/Android.bp | 8 +---- tests/cts/hostside/app/Android.bp | 30 +++++-------------- .../cts/net/HostsideNetworkTestCase.java | 7 +---- 3 files changed, 9 insertions(+), 36 deletions(-) diff --git a/tests/cts/hostside/Android.bp b/tests/cts/hostside/Android.bp index 3050d9a15e..97be91a837 100644 --- a/tests/cts/hostside/Android.bp +++ b/tests/cts/hostside/Android.bp @@ -12,12 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -next_app_data = [":CtsHostsideNetworkTestsAppNext"] - -// The above line is put in place to prevent any future automerger merge conflict between aosp, -// downstream branches. The CtsHostsideNetworkTestsAppNext target will not exist in -// some downstream branches, but it should exist in aosp and some downstream branches. - package { default_team: "trendy_team_fwk_core_networking", default_applicable_licenses: ["Android-Apache-2.0"], @@ -68,6 +62,6 @@ java_test_host { ":CtsHostsideNetworkCapTestsAppWithoutProperty", ":CtsHostsideNetworkCapTestsAppWithProperty", ":CtsHostsideNetworkCapTestsAppSdk33", - ] + next_app_data, + ], per_testcase_directory: true, } diff --git a/tests/cts/hostside/app/Android.bp b/tests/cts/hostside/app/Android.bp index c1b364c7aa..3868905120 100644 --- a/tests/cts/hostside/app/Android.bp +++ b/tests/cts/hostside/app/Android.bp @@ -19,8 +19,13 @@ package { default_applicable_licenses: ["Android-Apache-2.0"], } -java_defaults { - name: "CtsHostsideNetworkTestsAppDefaults", +android_test_helper_app { + name: "CtsHostsideNetworkTestsApp", + defaults: [ + "cts_support_defaults", + "framework-connectivity-test-defaults", + "CtsHostsideNetworkTestsAllAppDefaults", + ], static_libs: [ "CtsHostsideNetworkTestsAidl", "androidx.test.ext.junit", @@ -39,24 +44,3 @@ java_defaults { "src/**/*.java", ], } - -android_test_helper_app { - name: "CtsHostsideNetworkTestsApp", - defaults: [ - "cts_support_defaults", - "framework-connectivity-test-defaults", - "CtsHostsideNetworkTestsAppDefaults", - "CtsHostsideNetworkTestsAllAppDefaults", - ], -} - -android_test_helper_app { - name: "CtsHostsideNetworkTestsAppNext", - defaults: [ - "cts_support_defaults", - "framework-connectivity-test-defaults", - "CtsHostsideNetworkTestsAppDefaults", - "CtsHostsideNetworkTestsAllAppDefaults", - "ConnectivityNextEnableDefaults", - ], -} diff --git a/tests/cts/hostside/src/com/android/cts/net/HostsideNetworkTestCase.java b/tests/cts/hostside/src/com/android/cts/net/HostsideNetworkTestCase.java index 69d61b3354..e222ff6139 100644 --- a/tests/cts/hostside/src/com/android/cts/net/HostsideNetworkTestCase.java +++ b/tests/cts/hostside/src/com/android/cts/net/HostsideNetworkTestCase.java @@ -19,7 +19,6 @@ package com.android.cts.net; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import com.android.modules.utils.build.testing.DeviceSdkLevel; import com.android.tradefed.device.DeviceNotAvailableException; import com.android.tradefed.invoker.TestInformation; import com.android.tradefed.targetprep.BuildError; @@ -36,17 +35,13 @@ import org.junit.runner.RunWith; abstract class HostsideNetworkTestCase extends BaseHostJUnit4Test { protected static final String TEST_PKG = "com.android.cts.net.hostside"; protected static final String TEST_APK = "CtsHostsideNetworkTestsApp.apk"; - protected static final String TEST_APK_NEXT = "CtsHostsideNetworkTestsAppNext.apk"; protected static final String TEST_APP2_PKG = "com.android.cts.net.hostside.app2"; protected static final String TEST_APP2_APK = "CtsHostsideNetworkTestsApp2.apk"; @BeforeClassWithInfo public static void setUpOnceBase(TestInformation testInfo) throws Exception { - DeviceSdkLevel deviceSdkLevel = new DeviceSdkLevel(testInfo.getDevice()); - String testApk = deviceSdkLevel.isDeviceAtLeastV() ? TEST_APK_NEXT : TEST_APK; - uninstallPackage(testInfo, TEST_PKG, false); - installPackage(testInfo, testApk); + installPackage(testInfo, TEST_APK); } @AfterClassWithInfo From eca630007a5322df18d9beb8dc2f7ff2c1ccace6 Mon Sep 17 00:00:00 2001 From: Lorenzo Colitti Date: Fri, 20 Sep 2024 15:04:11 +0900 Subject: [PATCH 5/5] Skip testRouterSolicitations on T- devices. This does not lways pass on some devices before U. Now that the test is being added to MCTS, and needs to be backwards compatible, skip this test on T- devices. Test: atest CtsHostsideNetworkTests Change-Id: I2368f118d2539d70a97c937485f5179c47ba28d7 --- tests/cts/hostside/src/com/android/cts/net/ProcNetTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/cts/hostside/src/com/android/cts/net/ProcNetTest.java b/tests/cts/hostside/src/com/android/cts/net/ProcNetTest.java index fa68e3e60d..ae572e6235 100644 --- a/tests/cts/hostside/src/com/android/cts/net/ProcNetTest.java +++ b/tests/cts/hostside/src/com/android/cts/net/ProcNetTest.java @@ -166,6 +166,8 @@ public class ProcNetTest extends BaseHostJUnit4Test implements IBuildReceiver, I */ @Test public void testRouterSolicitations() throws Exception { + assumeTrue(new DeviceSdkLevel(mDevice).isDeviceAtLeastU()); + for (String interfaceDir : mSysctlDirs) { String path = IPV6_SYSCTL_DIR + "/" + interfaceDir + "/" + "router_solicitations"; int value = readIntFromPath(path); @@ -186,8 +188,7 @@ public class ProcNetTest extends BaseHostJUnit4Test implements IBuildReceiver, I */ @Test public void testCongestionControl() throws Exception { - final DeviceSdkLevel dsl = new DeviceSdkLevel(mDevice); - assumeTrue(dsl.isDeviceAtLeastV()); + assumeTrue(new DeviceSdkLevel(mDevice).isDeviceAtLeastV()); String path = "/proc/sys/net/ipv4/tcp_congestion_control"; String value = mDevice.executeAdbCommand("shell", "cat", path).trim();