Use WaitForProperty() to wait for restorecon

We have android::base::WaitForProperty() that uses futexes to
efficiently wait for property value changes, so use that instead
polling.

Test: Boot bullhead
Change-Id: Id964eddbdbfd9b5ceac5ed83a8ed66b9e60008ca
diff --git a/Utils.cpp b/Utils.cpp
index 49b51d6..ab1b605 100644
--- a/Utils.cpp
+++ b/Utils.cpp
@@ -20,11 +20,11 @@
 
 #include <android-base/file.h>
 #include <android-base/logging.h>
+#include <android-base/properties.h>
 #include <android-base/stringprintf.h>
 #include <cutils/fs.h>
-#include <cutils/properties.h>
-#include <private/android_filesystem_config.h>
 #include <logwrap/logwrap.h>
+#include <private/android_filesystem_config.h>
 
 #include <mutex>
 #include <dirent.h>
@@ -639,19 +639,12 @@
 status_t RestoreconRecursive(const std::string& path) {
     LOG(VERBOSE) << "Starting restorecon of " << path;
 
-    // TODO: find a cleaner way of waiting for restorecon to finish
-    const char* cpath = path.c_str();
-    property_set("selinux.restorecon_recursive", "");
-    property_set("selinux.restorecon_recursive", cpath);
+    static constexpr const char* kRestoreconString = "selinux.restorecon_recursive";
 
-    char value[PROPERTY_VALUE_MAX];
-    while (true) {
-        property_get("selinux.restorecon_recursive", value, "");
-        if (strcmp(cpath, value) == 0) {
-            break;
-        }
-        usleep(100000); // 100ms
-    }
+    android::base::SetProperty(kRestoreconString, "");
+    android::base::SetProperty(kRestoreconString, path);
+
+    android::base::WaitForProperty(kRestoreconString, path);
 
     LOG(VERBOSE) << "Finished restorecon of " << path;
     return OK;
@@ -684,7 +677,7 @@
 }
 
 bool IsRunningInEmulator() {
-    return property_get_bool("ro.kernel.qemu", 0);
+    return android::base::GetBoolProperty("ro.kernel.qemu", false);
 }
 
 }  // namespace vold