summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-03-30 16:41:01 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-03-30 16:41:01 +0000
commitcfdfb59819b7aa89d47e337bbfdbbe198c2dc83b (patch)
tree9dff2d3defb29f88272e92c7b94bcca8dd8aaaa0
parentdb05c9ce91766e98d4de18bc2db549ecb0086e62 (diff)
parent52413369330a223736191ea25de234b872afbf99 (diff)
downloadcts-android12-mainline-extservices-release.tar.gz
Merge cherrypicks of [17507263] into sparse-8197035-L50100000953802643.android-mainline-12.0.0_r87android12-mainline-extservices-release
Change-Id: I9c08220ea277dcb83110f005ceaac5d4269ebde5
-rw-r--r--hostsidetests/appcompat/strictjavapackages/src/android/compat/sjp/cts/StrictJavaPackagesTest.java72
1 files changed, 72 insertions, 0 deletions
diff --git a/hostsidetests/appcompat/strictjavapackages/src/android/compat/sjp/cts/StrictJavaPackagesTest.java b/hostsidetests/appcompat/strictjavapackages/src/android/compat/sjp/cts/StrictJavaPackagesTest.java
index 5ac8f32f498..1ac7c2c714c 100644
--- a/hostsidetests/appcompat/strictjavapackages/src/android/compat/sjp/cts/StrictJavaPackagesTest.java
+++ b/hostsidetests/appcompat/strictjavapackages/src/android/compat/sjp/cts/StrictJavaPackagesTest.java
@@ -512,6 +512,78 @@ public class StrictJavaPackagesTest extends BaseHostJUnit4Test {
}
/**
+ * Ensure that no apk-in-apex bundles classes that could be eclipsed by jars in
+ * BOOTCLASSPATH, SYSTEMSERVERCLASSPATH.
+ */
+ @Test
+ public void testApkInApex_nonClasspathClasses() throws Exception {
+ HashMultimap<String, Multimap<String, String>> perApkClasspathDuplicates =
+ HashMultimap.create();
+ Arrays.stream(collectApkInApexPaths())
+ .parallel()
+ .forEach(apk -> {
+ try {
+ final ImmutableSet<String> apkClasses =
+ Classpaths.getClassDefsFromJar(getDevice(), apk).stream()
+ .map(ClassDef::getType)
+ .collect(ImmutableSet.toImmutableSet());
+ // b/226559955: The directory paths containing APKs contain the build ID,
+ // so strip out the @BUILD_ID portion.
+ // e.g. /apex/com.android.bluetooth/app/Bluetooth@SC-DEV/Bluetooth.apk ->
+ // /apex/com.android.bluetooth/app/Bluetooth/Bluetooth.apk
+ apk = apk.replaceFirst("@[^/]*", "");
+ final ImmutableSet<String> burndownClasses =
+ FULL_APK_IN_APEX_BURNDOWN.getOrDefault(apk, ImmutableSet.of());
+ final Multimap<String, String> duplicates =
+ Multimaps.filterValues(sJarsToClasses, apkClasses::contains);
+ final Multimap<String, String> filteredDuplicates =
+ Multimaps.filterValues(duplicates,
+ className -> !burndownClasses.contains(className)
+ // TODO: b/225341497
+ && !className.equals("Landroidx/annotation/Keep;"));
+ if (!filteredDuplicates.isEmpty()) {
+ synchronized (perApkClasspathDuplicates) {
+ perApkClasspathDuplicates.put(apk, filteredDuplicates);
+ }
+ }
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ });
+ assertThat(perApkClasspathDuplicates).isEmpty();
+ }
+
+ private String[] collectApkInApexPaths() {
+ try {
+ final CompatibilityBuildHelper buildHelper = new CompatibilityBuildHelper(getBuild());
+ final String installError = getDevice().installPackage(
+ buildHelper.getTestFile(TEST_HELPER_APK), false);
+ assertWithMessage("Failed to install %s due to: %s", TEST_HELPER_APK, installError)
+ .that(installError).isNull();
+ runDeviceTests(new DeviceTestRunOptions(TEST_HELPER_PACKAGE)
+ .setDevice(getDevice())
+ .setTestClassName(TEST_HELPER_PACKAGE + ".ApexDeviceTest")
+ .setTestMethodName("testCollectApkInApexPaths"));
+ final String remoteFile = "/sdcard/apk-in-apex-paths.txt";
+ String content;
+ try {
+ content = getDevice().pullFileContents(remoteFile);
+ } finally {
+ getDevice().deleteFile(remoteFile);
+ }
+ return content.split("\n");
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ } finally {
+ try {
+ getDevice().uninstallPackage(TEST_HELPER_PACKAGE);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+ /**
* Gets the duplicate classes within a list of jar files.
*
* @param jars a list of jar files.