diff --git a/tests/cts/hostside/Android.bp b/tests/cts/hostside/Android.bp index 14d5d5463a..97be91a837 100644 --- a/tests/cts/hostside/Android.bp +++ b/tests/cts/hostside/Android.bp @@ -12,17 +12,27 @@ // 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"], } +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 { name: "CtsHostsideNetworkTests", defaults: ["cts_defaults"], @@ -52,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 2ca9adb753..7fff1c2613 100644 --- a/tests/cts/hostside/app/Android.bp +++ b/tests/cts/hostside/app/Android.bp @@ -19,9 +19,13 @@ package { default_applicable_licenses: ["Android-Apache-2.0"], } -java_defaults { - name: "CtsHostsideNetworkTestsAppDefaults", - platform_apis: true, +android_test_helper_app { + name: "CtsHostsideNetworkTestsApp", + defaults: [ + "cts_support_defaults", + "framework-connectivity-test-defaults", + "CtsHostsideNetworkTestsAllAppDefaults", + ], static_libs: [ "CtsHostsideNetworkTestsAidl", "androidx.test.ext.junit", @@ -39,35 +43,4 @@ 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 { - name: "CtsHostsideNetworkTestsApp", - defaults: [ - "cts_support_defaults", - "framework-connectivity-test-defaults", - "CtsHostsideNetworkTestsAppDefaults", - ], - static_libs: [ - "NetworkStackApiStableShims", - ], -} - -android_test_helper_app { - name: "CtsHostsideNetworkTestsAppNext", - defaults: [ - "cts_support_defaults", - "framework-connectivity-test-defaults", - "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..05abcdd022 100644 --- a/tests/cts/hostside/app2/Android.bp +++ b/tests/cts/hostside/app2/Android.bp @@ -21,20 +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", - "NetworkStackApiStableShims", ], 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", 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 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();