odsign_e2e_tests: Use the current ART module.
Before this change, the test uses a test apex. However, it doesn't work
in CTS because the key used to sign the test apex in CTS doesn't match
the key that the device expects. After this change, the test uses the
current active ART module on device, which is always valid.
Bug: 215552478
Bug: 184143265
Test: Flash a prod system image and run odsign_e2e_tests build from
AOSP.
Change-Id: Ibbc9614cfab12feca223fa44ce7550690c51a79d
diff --git a/build/apex/Android.bp b/build/apex/Android.bp
index 015c84d..20368e0 100644
--- a/build/apex/Android.bp
+++ b/build/apex/Android.bp
@@ -332,15 +332,6 @@
},
}
-apex_test {
- name: "test_com.android.art",
- defaults: ["com.android.art-devel-defaults"],
- manifest: "test_apex_manifest.json",
- file_contexts: ":com.android.art.debug-file_contexts",
- certificate: ":com.android.art.certificate",
- installable: false,
-}
-
// "Broken" test APEX, only used for testing, including module
// `libart-broken` instead of `libart`.
apex_test {
diff --git a/test/odsign/Android.bp b/test/odsign/Android.bp
index f4a1d88..39b8021 100644
--- a/test/odsign/Android.bp
+++ b/test/odsign/Android.bp
@@ -26,7 +26,6 @@
"frameworks-base-hostutils",
],
data: [
- ":test_com.android.art",
":odsign_e2e_test_app",
],
test_config: "odsign-e2e-tests.xml",
diff --git a/test/odsign/test-src/com/android/tests/odsign/OdsignTestUtils.java b/test/odsign/test-src/com/android/tests/odsign/OdsignTestUtils.java
index bad206f..4d21c66 100644
--- a/test/odsign/test-src/com/android/tests/odsign/OdsignTestUtils.java
+++ b/test/odsign/test-src/com/android/tests/odsign/OdsignTestUtils.java
@@ -19,6 +19,7 @@
import static com.google.common.truth.Truth.assertWithMessage;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue;
@@ -29,6 +30,7 @@
import com.android.tradefed.invoker.TestInformation;
import com.android.tradefed.util.CommandResult;
+import java.io.File;
import java.time.Duration;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
@@ -37,6 +39,8 @@
import java.util.List;
import java.util.Optional;
import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -49,8 +53,6 @@
public static final List<String> APP_ARTIFACT_EXTENSIONS = List.of(".art", ".odex", ".vdex");
public static final List<String> BCP_ARTIFACT_EXTENSIONS = List.of(".art", ".oat", ".vdex");
- private static final String APEX_FILENAME = "test_com.android.art.apex";
-
private static final String ODREFRESH_COMPILATION_LOG =
"/data/misc/odrefresh/compilation-log.txt";
@@ -60,6 +62,7 @@
private static final String TAG = "OdsignTestUtils";
private static final String WAS_ADB_ROOT_KEY = TAG + ":WAS_ADB_ROOT";
private static final String ADB_ROOT_ENABLED_KEY = TAG + ":ADB_ROOT_ENABLED";
+ private static final String PACKAGE_NAME_KEY = TAG + ":PACKAGE_NAME";
private final InstallUtilsHost mInstallUtils;
private final TestInformation mTestInfo;
@@ -70,16 +73,36 @@
mTestInfo = testInfo;
}
+ /**
+ * Re-installs the current active ART module on device.
+ */
public void installTestApex() throws Exception {
assumeTrue("Updating APEX is not supported", mInstallUtils.isApexUpdateSupported());
- mInstallUtils.installApexes(APEX_FILENAME);
+
+ String packagesOutput =
+ mTestInfo.getDevice().executeShellCommand("pm list packages -f --apex-only");
+ Pattern p = Pattern.compile(
+ "^package:(.*)=com(\\.google)?\\.android\\.art$", Pattern.MULTILINE);
+ Matcher m = p.matcher(packagesOutput);
+ assertTrue("ART module not found. Packages are:\n" + packagesOutput, m.find());
+ String artApexPath = m.group(1);
+
+ File artApexFile = mTestInfo.getDevice().pullFile(artApexPath);
+ String installResult = mTestInfo.getDevice().installPackage(artApexFile, false);
+ assertNull("Failed to install APEX. Reason: " + installResult, installResult);
+
+ ApexInfo apex = mInstallUtils.getApexInfo(artApexFile);
+ mTestInfo.properties().put(PACKAGE_NAME_KEY, apex.name);
+
removeCompilationLogToAvoidBackoff();
}
public void uninstallTestApex() throws Exception {
- ApexInfo apex = mInstallUtils.getApexInfo(mInstallUtils.getTestFile(APEX_FILENAME));
- mTestInfo.getDevice().uninstallPackage(apex.name);
- removeCompilationLogToAvoidBackoff();
+ String packageName = mTestInfo.properties().get(PACKAGE_NAME_KEY);
+ if (packageName != null) {
+ mTestInfo.getDevice().uninstallPackage(packageName);
+ removeCompilationLogToAvoidBackoff();
+ }
}
public Set<String> getMappedArtifacts(String pid, String grepPattern) throws Exception {