Merge "Use WaitForProperty() to wait for restorecon" am: 963a205a1b am: 80ce34d6cb
am: dfd0492354

Change-Id: Id3b68e5b946fc1bf886f59e59fee3960a2899041
diff --git a/Utils.cpp b/Utils.cpp
index 15b3c0b..529cfb2 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;
@@ -670,7 +663,7 @@
 }
 
 bool IsRunningInEmulator() {
-    return property_get_bool("ro.kernel.qemu", 0);
+    return android::base::GetBoolProperty("ro.kernel.qemu", false);
 }
 
 }  // namespace vold