replace sleep wait into property wait

- Wait for the creation of ro.boottime.persistent_properties
  for the availability of persist props.
- Then read persist.hal.binderization.

bug: 35178781
Test: reboot
Change-Id: Ica53672d1b8bbfcdef8b818ff5b8ad672c9aafaa
diff --git a/transport/LegacySupport.cpp b/transport/LegacySupport.cpp
index 17371d4..0032fc3 100644
--- a/transport/LegacySupport.cpp
+++ b/transport/LegacySupport.cpp
@@ -15,36 +15,39 @@
  */
 #define LOG_TAG "libhidltransport"
 
+#include <inttypes.h>
+
 #include <hidl/LegacySupport.h>
 
 #include <chrono>
-#include <cutils/properties.h>
 #include <thread>
 #include <utils/misc.h>
 #include <utils/Log.h>
+#include <utils/SystemClock.h>
+
+#include <android-base/properties.h>
 
 namespace android {
 namespace hardware {
 
-static const char* kDataProperty = "vold.post_fs_data_done";
-
-void waitForData() {
-    using namespace std::literals::chrono_literals;
-
-    // TODO(b/34274385) remove this
-    while (!property_get_bool(kDataProperty, false)) {
-        std::this_thread::sleep_for(300ms);
-    }
-
-    // TODO(b/35178781) wait a bit longer
-    std::this_thread::sleep_for(300ms);
-}
-
 namespace details {
 
+using android::base::GetBoolProperty;
+using android::base::GetUintProperty;
+using android::base::WaitForPropertyCreation;
+
+static const char* kPersistPropReadyProperty = "ro.boottime.persistent_properties";
+static const char* kBinderizationProperty = "persist.hal.binderization";
+
 bool blockingHalBinderizationEnabled() {
-    waitForData();
-    return property_get_bool("persist.hal.binderization", false);
+    uint64_t t = GetUintProperty<uint64_t>(kPersistPropReadyProperty, 0, UINT64_MAX);
+    if (t == 0) { // not set yet
+        int64_t startTime = elapsedRealtime();
+        WaitForPropertyCreation(kPersistPropReadyProperty, std::chrono::milliseconds::max());
+        ALOGI("Waiting for %s took %" PRId64 " ms", kPersistPropReadyProperty,
+              elapsedRealtime() - startTime);
+    }
+    return GetBoolProperty(kBinderizationProperty, false);
 }
 
 void blockIfBinderizationDisabled(const std::string& interface,