mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-01-03 11:17:38 +00:00
Slightly change wait usage and API
This commit is contained in:
parent
e94d65b4b2
commit
38527cd58f
@ -51,23 +51,27 @@ Usage: %s [flags] [arguments...]
|
|||||||
|
|
||||||
Read mode arguments:
|
Read mode arguments:
|
||||||
(no arguments) print all properties
|
(no arguments) print all properties
|
||||||
NAME [OLD_VALUE] get property of NAME, optionally with an OLD_VALUE for -w
|
NAME get property of NAME
|
||||||
|
|
||||||
Write mode arguments:
|
Write mode arguments:
|
||||||
NAME VALUE set property NAME as VALUE
|
NAME VALUE set property NAME as VALUE
|
||||||
-f,--file FILE load and set properties from FILE
|
-f,--file FILE load and set properties from FILE
|
||||||
-d,--delete NAME delete property
|
-d,--delete NAME delete property
|
||||||
|
|
||||||
|
Wait mode arguments (toggled with -w):
|
||||||
|
NAME wait until property NAME changes
|
||||||
|
NAME OLD_VALUE if value of property NAME is not OLD_VALUE, get value
|
||||||
|
or else wait until property NAME changes
|
||||||
|
|
||||||
General flags:
|
General flags:
|
||||||
-h,--help show this message
|
-h,--help show this message
|
||||||
-v print verbose output to stderr
|
-v print verbose output to stderr
|
||||||
|
-w switch to wait mode
|
||||||
|
|
||||||
Read mode flags:
|
Read mode flags:
|
||||||
-p also read persistent props from storage
|
-p also read persistent props from storage
|
||||||
-P only read persistent props from storage
|
-P only read persistent props from storage
|
||||||
-Z get property context instead of value
|
-Z get property context instead of value
|
||||||
-w wait for property change, and if OLD_VALUE is specified, wait for it to change to other value
|
|
||||||
return immediately if persistent
|
|
||||||
|
|
||||||
Write mode flags:
|
Write mode flags:
|
||||||
-n set properties bypassing property_service
|
-n set properties bypassing property_service
|
||||||
@ -187,7 +191,7 @@ static int set_prop(const char *name, const char *value, PropFlags flags) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<class StringType>
|
template<class StringType>
|
||||||
static StringType get_prop(const char *name, PropFlags flags, const char *wait_value = nullptr) {
|
static StringType get_prop(const char *name, PropFlags flags) {
|
||||||
if (!check_legal_property_name(name))
|
if (!check_legal_property_name(name))
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
@ -201,15 +205,10 @@ static StringType get_prop(const char *name, PropFlags flags, const char *wait_v
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!flags.isPersistOnly()) {
|
if (!flags.isPersistOnly()) {
|
||||||
auto pi = system_property_find(name);
|
if (auto pi = system_property_find(name)) {
|
||||||
if (!pi) return {};
|
|
||||||
read_prop_with_cb(pi, &cb);
|
|
||||||
if (flags.isWait() && (wait_value == nullptr || cb.val == wait_value)) {
|
|
||||||
uint32_t new_serial;
|
|
||||||
__system_property_wait(pi, cb.s, &new_serial, nullptr);
|
|
||||||
read_prop_with_cb(pi, &cb);
|
read_prop_with_cb(pi, &cb);
|
||||||
|
LOGD("resetprop: get prop [%s]: [%s]\n", name, cb.val.c_str());
|
||||||
}
|
}
|
||||||
LOGD("resetprop: get prop [%s]: [%s]\n", name, cb.val.c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cb.val.empty() && flags.isPersist() && str_starts(name, "persist."))
|
if (cb.val.empty() && flags.isPersist() && str_starts(name, "persist."))
|
||||||
@ -220,6 +219,30 @@ static StringType get_prop(const char *name, PropFlags flags, const char *wait_v
|
|||||||
return cb.val;
|
return cb.val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {};
|
||||||
|
}
|
||||||
|
|
||||||
|
prop_to_string<StringType> cb;
|
||||||
|
read_prop_with_cb(pi, &cb);
|
||||||
|
|
||||||
|
if (old_value == nullptr || cb.val == old_value) {
|
||||||
|
LOGD("resetprop: waiting for prop [%s]\n", name);
|
||||||
|
uint32_t new_serial;
|
||||||
|
__system_property_wait(pi, pi->serial, &new_serial, nullptr);
|
||||||
|
read_prop_with_cb(pi, &cb);
|
||||||
|
}
|
||||||
|
|
||||||
|
LOGD("resetprop: get prop [%s]: [%s]\n", name, cb.val.c_str());
|
||||||
|
return cb.val;
|
||||||
|
}
|
||||||
|
|
||||||
static void print_props(PropFlags flags) {
|
static void print_props(PropFlags flags) {
|
||||||
prop_list list;
|
prop_list list;
|
||||||
prop_collector collector(list);
|
prop_collector collector(list);
|
||||||
@ -357,6 +380,15 @@ int resetprop_main(int argc, char *argv[]) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (flags.isWait()) {
|
||||||
|
if (argc == 0) usage(argv0);
|
||||||
|
auto val = wait_prop<string>(argv[0], argv[1]);
|
||||||
|
if (val.empty())
|
||||||
|
return 1;
|
||||||
|
printf("%s\n", val.data());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
switch (argc) {
|
switch (argc) {
|
||||||
case 0:
|
case 0:
|
||||||
print_props(flags);
|
print_props(flags);
|
||||||
@ -369,15 +401,7 @@ int resetprop_main(int argc, char *argv[]) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
case 2:
|
case 2:
|
||||||
if (flags.isWait()) {
|
return set_prop(argv[0], argv[1], flags);
|
||||||
auto val = get_prop<string>(argv[0], flags, argv[1]);
|
|
||||||
if (val.empty())
|
|
||||||
return 1;
|
|
||||||
printf("%s\n", val.data());
|
|
||||||
return 0;
|
|
||||||
} else {
|
|
||||||
return set_prop(argv[0], argv[1], flags);
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
usage(argv0);
|
usage(argv0);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user