Skip to content

Commit

Permalink
Support waiting on non-exist prop
Browse files Browse the repository at this point in the history
  • Loading branch information
yujincheng08 committed May 18, 2024
1 parent 2afcdc6 commit 941a363
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions native/src/core/resetprop/resetprop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,20 +226,23 @@ template<class StringType>
static StringType wait_prop(const char *name, const char *old_value) {
if (!check_legal_property_name(name))
return {};
auto pi = system_property_find(name);
if (!pi) {
LOGD("resetprop: prop [%s] does not exist\n", name);
return {};

const prop_info *pi;
auto serial = __system_property_area_serial();
while (!(pi = system_property_find(name))) {
LOGD("resetprop: waiting for prop [%s] to exist\n", name);
system_property_wait(nullptr, serial, &serial, nullptr);
}

prop_to_string<StringType> cb;
read_prop_with_cb(pi, &cb);

if (old_value == nullptr || cb.val == old_value) {
while (old_value == nullptr || cb.val == old_value) {
LOGD("resetprop: waiting for prop [%s]\n", name);
uint32_t new_serial;
system_property_wait(pi, cb.serial, &new_serial, nullptr);
read_prop_with_cb(pi, &cb);
if (old_value == nullptr) break;
}

LOGD("resetprop: get prop [%s]: [%s]\n", name, cb.val.c_str());
Expand Down

0 comments on commit 941a363

Please sign in to comment.