Add __system_property_wait and return the serial in __system_property_read_callback.
In order to implement android::base::WaitForProperty well, we need a way to
wait not for *any* property to change (__system_property_wait_any), but to
specifically wait for the property represented by a given `prop_info` to
change.
The android::base::WaitForProperty implementation, like attempts to cache
system properties in the past, also needs a way to keep serials and values
in sync, but the existing functions don't provide a cheap way to get a
consistent snapshot. Change the __system_property_read_callback callback's
type to include the serial corresponding to the given value.
Add a test, slightly clean up some of the existing tests (and name them to
include the names of the functions they're testing, in our usual style).
Bug: http://b/35201172
Test: ran tests
Change-Id: Ibc8ebe2e88eef1e333a1bd3dd7f68135f1ba7fb5
diff --git a/tests/system_properties_test2.cpp b/tests/system_properties_test2.cpp
index 0560960..e6e7ef2 100644
--- a/tests/system_properties_test2.cpp
+++ b/tests/system_properties_test2.cpp
@@ -90,20 +90,22 @@
ASSERT_TRUE(pi != nullptr);
std::string expected_name = property_name;
- __system_property_read_callback(pi, [](void* cookie, const char *name, const char *value) {
- const std::string* expected_name = static_cast<const std::string*>(cookie);
- ASSERT_EQ(*expected_name, name);
- ASSERT_STREQ("value1-1", value);
+ __system_property_read_callback(pi,
+ [](void* cookie, const char* name, const char* value, unsigned /*serial*/) {
+ const std::string* expected_name = static_cast<const std::string*>(cookie);
+ ASSERT_EQ(*expected_name, name);
+ ASSERT_STREQ("value1-1", value);
}, &expected_name);
pi = __system_property_find(long_property_name.c_str());
ASSERT_TRUE(pi != nullptr);
expected_name = long_property_name;
- __system_property_read_callback(pi, [](void* cookie, const char *name, const char *value) {
- const std::string* expected_name = static_cast<const std::string*>(cookie);
- ASSERT_EQ(*expected_name, name);
- ASSERT_STREQ("value2", value);
+ __system_property_read_callback(pi,
+ [](void* cookie, const char* name, const char* value, unsigned /*serial*/) {
+ const std::string* expected_name = static_cast<const std::string*>(cookie);
+ ASSERT_EQ(*expected_name, name);
+ ASSERT_STREQ("value2", value);
}, &expected_name);
// Check that read() for long names still works but returns truncated version of the name