Fix VtsHalAdapterPreparer

* Enable adb root at the beginning of preparer setup.
* Ignore std:err output of lshal.
* Throw TargetSetupError instead of RuntimeException

Bug: 76152041
Test: make vts

Merged-In: I5df90bdda04037e8adfb6be0b80a4916bf53f9bd
Change-Id: I5df90bdda04037e8adfb6be0b80a4916bf53f9bd
(cherry picked from commit 0cbd05ce44ae9f8fa2457ecec1844422a3169a77)
diff --git a/harnesses/tradefed/src/com/android/tradefed/targetprep/VtsHalAdapterPreparer.java b/harnesses/tradefed/src/com/android/tradefed/targetprep/VtsHalAdapterPreparer.java
index 72cf50a..2aef118 100644
--- a/harnesses/tradefed/src/com/android/tradefed/targetprep/VtsHalAdapterPreparer.java
+++ b/harnesses/tradefed/src/com/android/tradefed/targetprep/VtsHalAdapterPreparer.java
@@ -61,7 +61,7 @@
     static final String SCRIPT_PATH = "/data/local/tmp/vts_adapter.sh";
     // Command to list the registered instance for the given hal@version.
     static final String LIST_HAL_CMD =
-            "lshal -ti --neat | grep -E '^hwbinder' | awk '{print $2}' | grep %s";
+            "lshal -ti --neat 2>/dev/null | grep -E '^hwbinder' | awk '{print $2}' | grep %s";
 
     @Option(name = "adapter-binary-name",
             description = "Adapter binary file name (typically under /data/nativetest*/)")
@@ -92,7 +92,9 @@
      */
     @Override
     public void setUp(ITestDevice device, IBuildInfo buildInfo)
-            throws TargetSetupError, BuildError, DeviceNotAvailableException, RuntimeException {
+            throws TargetSetupError, BuildError, DeviceNotAvailableException {
+        // adb root.
+        device.enableAdbRoot();
         String bitness =
                 (mAbi != null) ? ((mAbi.getBitness() == "32") ? "" : mAbi.getBitness()) : "";
         try {
@@ -109,11 +111,11 @@
         for (String line : out.split("\n")) {
             if (!line.isEmpty()) {
                 if (!line.contains(HAL_INTERFACE_SEP)) {
-                    throw new RuntimeException("HAL instance with wrong format.");
+                    throw new TargetSetupError("HAL instance with wrong format.");
                 }
                 String interfaceInstance = line.split(HAL_INTERFACE_SEP, 2)[1];
                 if (!interfaceInstance.contains(HAL_INSTANCE_SEP)) {
-                    throw new RuntimeException("HAL instance with wrong format.");
+                    throw new TargetSetupError("HAL instance with wrong format.");
                 }
                 String interfaceName = interfaceInstance.split(HAL_INSTANCE_SEP, 2)[0];
                 String instanceName = interfaceInstance.split(HAL_INSTANCE_SEP, 2)[1];