CachedProperty: add method to wait for change.
Test: mma && adb sync && adb shell /data/nativetest64/libbase_test/libbase_test64
Change-Id: Ie2d4c6cc5cf54b61e8fc191fbb3d91bc6d3588d9
diff --git a/properties.cpp b/properties.cpp
index 7e30c82..7e851e6 100644
--- a/properties.cpp
+++ b/properties.cpp
@@ -280,6 +280,25 @@
}
}
+const char* CachedProperty::WaitForChange(std::chrono::milliseconds relative_timeout) {
+ if (!prop_info_) {
+ auto start_time = std::chrono::steady_clock::now();
+ prop_info_ = WaitForPropertyCreation(property_name_, relative_timeout, start_time);
+ if (!prop_info_) {
+ return nullptr;
+ }
+ } else {
+ timespec ts;
+ DurationToTimeSpec(ts, relative_timeout);
+
+ uint32_t old_serial = cached_property_serial_.value_or(0);
+ uint32_t new_serial;
+ if (!__system_property_wait(prop_info_, old_serial, &new_serial, &ts)) return nullptr;
+ }
+
+ return Get(nullptr);
+}
+
#endif
} // namespace base