Refactor: pull up getPathForPackage()

This also fixes a runtime dependency problem by changing the module type
from java_test_helper_library to plain java_library_host. Previously, I
had a problem that after adding a method to the base class calling it
resulted in NoMethodFoundException at runtime (when running atest).

Bug: n/a
Test: atest MicrodroidHostTestCases
Change-Id: I8430bc6f2adf43a62bc7b91fd0a3fb26d5c65807
diff --git a/tests/hostside/helper/Android.bp b/tests/hostside/helper/Android.bp
index aa748ab..4ca0bf0 100644
--- a/tests/hostside/helper/Android.bp
+++ b/tests/hostside/helper/Android.bp
@@ -2,12 +2,9 @@
     default_applicable_licenses: ["Android-Apache-2.0"],
 }
 
-java_test_helper_library {
+java_library_host {
     name: "VirtualizationTestHelper",
-    host_supported: true,
-    device_supported: false,
     srcs: ["java/**/*.java"],
-    test_suites: ["general-tests"],
     libs: [
         "tradefed",
         "compatibility-tradefed",
diff --git a/tests/hostside/helper/java/android/virt/test/VirtualizationTestCaseBase.java b/tests/hostside/helper/java/android/virt/test/VirtualizationTestCaseBase.java
index e45e524..0f6204c 100644
--- a/tests/hostside/helper/java/android/virt/test/VirtualizationTestCaseBase.java
+++ b/tests/hostside/helper/java/android/virt/test/VirtualizationTestCaseBase.java
@@ -194,6 +194,22 @@
         }
     }
 
+    public String getPathForPackage(String packageName)
+            throws DeviceNotAvailableException {
+        return getPathForPackage(getDevice(), packageName);
+    }
+
+    // Get the path to the installed apk. Note that
+    // getDevice().getAppPackageInfo(...).getCodePath() doesn't work due to the incorrect
+    // parsing of the "=" character. (b/190975227). So we use the `pm path` command directly.
+    private static String getPathForPackage(ITestDevice device, String packageName)
+            throws DeviceNotAvailableException {
+        CommandRunner android = new CommandRunner(device);
+        String pathLine = android.run("pm", "path", packageName);
+        assertTrue("package not found", pathLine.startsWith("package:"));
+        return pathLine.substring("package:".length());
+    }
+
     public static String startMicrodroid(
             ITestDevice androidDevice,
             IBuildInfo buildInfo,
@@ -247,13 +263,8 @@
             androidDevice.installPackage(apkFile, /* reinstall */ true);
         }
 
-        // Get the path to the installed apk. Note that
-        // getDevice().getAppPackageInfo(...).getCodePath() doesn't work due to the incorrect
-        // parsing of the "=" character. (b/190975227). So we use the `pm path` command directly.
         if (apkPath == null) {
-            apkPath = android.run("pm", "path", packageName);
-            assertTrue(apkPath.startsWith("package:"));
-            apkPath = apkPath.substring("package:".length());
+            apkPath = getPathForPackage(androidDevice, packageName);
         }
 
         android.run("mkdir", "-p", TEST_ROOT);
diff --git a/tests/hostside/java/android/virt/test/MicrodroidTestCase.java b/tests/hostside/java/android/virt/test/MicrodroidTestCase.java
index d0bc91a..e65459a 100644
--- a/tests/hostside/java/android/virt/test/MicrodroidTestCase.java
+++ b/tests/hostside/java/android/virt/test/MicrodroidTestCase.java
@@ -143,14 +143,6 @@
         boolean writable;
     }
 
-    private String getPathForPackage(String packageName)
-            throws DeviceNotAvailableException {
-        CommandRunner android = new CommandRunner(getDevice());
-        String pathLine = android.run("pm", "path", packageName);
-        assertTrue("package not found", pathLine.startsWith("package:"));
-        return pathLine.substring("package:".length());
-    }
-
     private void resignVirtApex(File virtApexDir, File signingKey) {
         File signVirtApex = findTestFile("sign_virt_apex");