Re-connect after adb root

Rooting the Microdroid sometimes makes the followings commands to fail
due to the connection being in an odd state. Work around this issue by
explicitly disconnecting and re-connecting to Microdroid right after the
rooting.

Bug: 246911025
Test: atest MicrodroidHostTestCases:com.android.microdroid.test.MicrodroidTestCase#testMicrodroidRamUsage
Change-Id: I7ec1aeb1197c90a34619cb83a69ed4cd4a6231a7
diff --git a/tests/hostside/helper/java/com/android/microdroid/test/host/MicrodroidHostTestCaseBase.java b/tests/hostside/helper/java/com/android/microdroid/test/host/MicrodroidHostTestCaseBase.java
index 7a9e2ea..875d89f 100644
--- a/tests/hostside/helper/java/com/android/microdroid/test/host/MicrodroidHostTestCaseBase.java
+++ b/tests/hostside/helper/java/com/android/microdroid/test/host/MicrodroidHostTestCaseBase.java
@@ -367,10 +367,11 @@
         runOnHostRetryingOnFailure(MICRODROID_COMMAND_TIMEOUT_MILLIS,
                 MICRODROID_ADB_CONNECT_MAX_ATTEMPTS, "adb", "-s", MICRODROID_SERIAL, "root");
         // adbd reboots after root. Some commands (including wait-for-device) following this fails
-        // with error: closed. Hence, we run adb shell true in microdroid with retries
-        // before returning.
-        runOnMicrodroidRetryingOnFailure(MICRODROID_COMMAND_TIMEOUT_MILLIS,
-                MICRODROID_ADB_CONNECT_MAX_ATTEMPTS, "true");
+        // with error: closed. Hence, we disconnect and re-connect to the device before returning.
+        runOnHostRetryingOnFailure(MICRODROID_COMMAND_TIMEOUT_MILLIS,
+                MICRODROID_ADB_CONNECT_MAX_ATTEMPTS, "adb", "disconnect", MICRODROID_SERIAL);
+        runOnHostRetryingOnFailure(MICRODROID_COMMAND_TIMEOUT_MILLIS,
+                MICRODROID_ADB_CONNECT_MAX_ATTEMPTS, "adb", "connect", MICRODROID_SERIAL);
     }
 
     // Establish an adb connection to microdroid by letting Android forward the connection to