Embed test-purpose APEXes as data

On Pixel devices, adbd/statsd apexes have different names, which causes
`pm path` to fail.

Instead, embed test-purpose APEXes as data and use them for testing.
This can also provide isolation for the testing environment.

Bug: 221024307
Test: atest MicrodroidHostTestCases (on internal branches)
Change-Id: I4a71ea662e789d48bdbdf2008bbdd666778a72fe
diff --git a/tests/hostside/Android.bp b/tests/hostside/Android.bp
index 6083fe5..fa9da9d 100644
--- a/tests/hostside/Android.bp
+++ b/tests/hostside/Android.bp
@@ -23,6 +23,8 @@
         ":test.com.android.virt.pem",
         ":test2.com.android.virt.pem",
         ":test-payload-metadata",
+        ":com.android.adbd{.apex}",
+        ":com.android.os.statsd{.apex}",
     ],
     data_native_bins: [
         "sepolicy-analyze",
diff --git a/tests/hostside/java/android/virt/test/MicrodroidTestCase.java b/tests/hostside/java/android/virt/test/MicrodroidTestCase.java
index 579fc18..1218b68 100644
--- a/tests/hostside/java/android/virt/test/MicrodroidTestCase.java
+++ b/tests/hostside/java/android/virt/test/MicrodroidTestCase.java
@@ -224,6 +224,12 @@
         final String payloadMetadataPath = TEST_ROOT + "payload-metadata.img";
         getDevice().pushFile(findTestFile("test-payload-metadata.img"), payloadMetadataPath);
 
+        // push APEXes required for the VM.
+        final String statsdApexPath = TEST_ROOT + "com.android.os.statsd.apex";
+        final String adbdApexPath = TEST_ROOT + "com.android.adbd.apex";
+        getDevice().pushFile(findTestFile("com.android.os.statsd.apex"), statsdApexPath);
+        getDevice().pushFile(findTestFile("com.android.adbd.apex"), adbdApexPath);
+
         // Since Java APP can't start a VM with a custom image, here, we start a VM using `vm run`
         // command with a VM Raw config which is equiv. to what virtualizationservice creates with
         // a VM App config.
@@ -264,17 +270,8 @@
         // - apk and idsig
         Disk payloadDisk = new Disk();
         payloadDisk.addPartition("payload-metadata", payloadMetadataPath);
-        String[] apexes = {"com.android.os.statsd", "com.android.adbd"};
-        for (int i = 0; i < apexes.length; i++) {
-            String apexPath = getPathForPackage(apexes[i]);
-            String filename = apexes[i] + ".apex";
-            File localApexFile = new File(virtApexDir, filename);
-            String remoteApexFile = TEST_ROOT + filename;
-            // Since `adb shell vm` can't access apex_data_file, we `adb pull/push` apex files.
-            getDevice().pullFile(apexPath, localApexFile);
-            getDevice().pushFile(localApexFile, remoteApexFile);
-            payloadDisk.addPartition("microdroid-apex-" + i, remoteApexFile);
-        }
+        payloadDisk.addPartition("microdroid-apex-0", statsdApexPath);
+        payloadDisk.addPartition("microdroid-apex-1", adbdApexPath);
         payloadDisk.addPartition("microdroid-apk", apkPath);
         payloadDisk.addPartition("microdroid-apk-idsig", idSigPath);
         config.disks.add(payloadDisk);