Wait for data without sysprop listeners.
add_sysprop_change_callback requires piping report_sysprop_change over
binder (and hwbinder). This was (and still is) a temporary solution
until the persist.hal.binderizatoin flag can be passed through kernel
argument.
Currently working with partners to replace these flags with kernel
arguments.
Test: lights/nfc work on with ag/1835881.
Test: perfboot: (three runs) 19902ms avg with the above CL, 19479ms with
Change-Id: I240cf100dc070be43ca49dd9856fb7603231ffd2
diff --git a/transport/LegacySupport.cpp b/transport/LegacySupport.cpp
index 3f91eb0..d2e8688 100644
--- a/transport/LegacySupport.cpp
+++ b/transport/LegacySupport.cpp
@@ -17,9 +17,9 @@
#include <hidl/LegacySupport.h>
-#include <condition_variable>
+#include <chrono>
#include <cutils/properties.h>
-#include <mutex>
+#include <thread>
#include <utils/misc.h>
#include <utils/Log.h>
@@ -27,56 +27,14 @@
namespace hardware {
static const char* kDataProperty = "vold.post_fs_data_done";
-static std::mutex gDataMutex;
-static std::condition_variable gDataCondition;
-static bool gDataDone = false;
-static bool gDataStarted = false;
-
-static void voldDecryptCallback() {
- std::lock_guard<std::mutex> lock(gDataMutex);
-
- if (gDataDone) {
- return; // TODO: add remove_sysprop_change_callback
- }
-
- // more expensive to query property_get_bool than to check the lock
- if (!property_get_bool(kDataProperty, false)) {
- return; // other sysprop set, and this hasn't been set yet
- }
-
- // file system is mounted!
-
- gDataDone = true;
- gDataCondition.notify_all();
-}
void waitForData() {
- {
- std::unique_lock<std::mutex> lock(gDataMutex);
+ using namespace std::literals::chrono_literals;
- // unlikely, but we should make sure two threads in the same process
- // don't call this method at the same time
- if (gDataStarted) {
- // just wait to be notified
- gDataCondition.wait(lock, [] () {
- return gDataDone;
- });
- return;
- }
+ // TODO(b/34274385) remove this
+ while (!property_get_bool(kDataProperty, false)) {
+ std::this_thread::sleep_for(300ms);
}
-
- add_sysprop_change_callback(voldDecryptCallback, 0 /* priority */);
-
- // if it already got setup before we registered the decrypt callback,
- // we must still wake up.
- voldDecryptCallback();
-
- std::unique_lock<std::mutex> lock(gDataMutex);
- gDataCondition.wait(lock, [] () {
- return gDataDone;
- });
-
- gDataStarted = true;
}
namespace details {