Fix flake

Microdroid tests have been flaky. One of the reasons is due to a race
condition. The adb connection to microdroid is established, but
microdroid hasn't finished the boot procedure. The test code runs and
checks the various assertions on the microdroid which is still booting.

Fix the flake by waiting until the boot procedure is finished. This is
done by monitoring the system property `init.svc.logd-reinit` which gets
a value when the `logd-reinit` service is started. The service is
started at the very end of the boot procedure.

Bug: 196015443
Test: monitor TH
Change-Id: I631f47046d6ea103019cf7c6f389d10f1d13fe99
diff --git a/tests/hostside/java/android/virt/test/MicrodroidTestCase.java b/tests/hostside/java/android/virt/test/MicrodroidTestCase.java
index aa7c9ab..a7b855a 100644
--- a/tests/hostside/java/android/virt/test/MicrodroidTestCase.java
+++ b/tests/hostside/java/android/virt/test/MicrodroidTestCase.java
@@ -44,6 +44,11 @@
                         /* debug */ false);
         adbConnectToMicrodroid(getDevice(), cid);
 
+        // Wait until logd-init starts. The service is one of the last services that are started in
+        // the microdroid boot procedure. Therefore, waiting for the service means that we wait for
+        // the boot to complete. TODO: we need a better marker eventually.
+        tryRunOnMicrodroid("watch -e \"getprop init.svc.logd-reinit | grep '^$'\"");
+
         // Test writing to /data partition
         runOnMicrodroid("echo MicrodroidTest > /data/local/tmp/test.txt");
         assertThat(runOnMicrodroid("cat /data/local/tmp/test.txt"), is("MicrodroidTest"));