Skip to content

Commit

Permalink
Support only read properties from storage
Browse files Browse the repository at this point in the history
  • Loading branch information
topjohnwu committed May 19, 2023
1 parent dc61033 commit 8f8fa6c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion build.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ def build_binary(args):

header("* Building binaries: " + " ".join(args.target))

run_cargo_build(args)
# run_cargo_build(args)

dump_flag_header()

Expand Down
23 changes: 16 additions & 7 deletions native/src/core/resetprop/resetprop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ struct PropFlags {
void setSkipSvc() { flags |= 1; }
void setPersist() { flags |= (1 << 1); }
void setContext() { flags |= (1 << 2); }
void setPersistOnly() { flags |= (1 << 3); setPersist(); }
bool isSkipSvc() const { return flags & 1; }
bool isPersist() const { return flags & (1 << 1); }
bool isContext() const { return flags & (1 << 2); }
bool isPersistOnly() const { return flags & (1 << 3); }
private:
uint32_t flags = 0;
};
Expand All @@ -56,12 +58,13 @@ General flags:
-v print verbose output to stderr
Read mode flags:
-Z get property context instead of value
-p also read persistent props from storage
-P only read persistent props from storage
-Z get property context instead of value
Write mode flags:
-n set properties bypassing property_service
-p always write persistent props changes to storage
-p always write persistent prop changes to storage
)EOF", arg0);
exit(1);
Expand Down Expand Up @@ -178,10 +181,12 @@ static string get_prop(const char *name, PropFlags flags) {
}

string val;
if (auto pi = system_property_find(name)) {
prop_to_string cb(val);
read_prop_with_cb(pi, &cb);
LOGD("resetprop: get prop [%s]: [%s]\n", name, val.data());
if (!flags.isPersistOnly()) {
if (auto pi = system_property_find(name)) {
prop_to_string cb(val);
read_prop_with_cb(pi, &cb);
LOGD("resetprop: get prop [%s]: [%s]\n", name, val.data());
}
}

if (val.empty() && flags.isPersist() && str_starts(name, "persist."))
Expand All @@ -195,7 +200,8 @@ static string get_prop(const char *name, PropFlags flags) {
static void print_props(PropFlags flags) {
prop_list list;
prop_collector collector(list);
system_property_foreach(read_prop_with_cb, &collector);
if (!flags.isPersistOnly())
system_property_foreach(read_prop_with_cb, &collector);
if (flags.isPersist())
persist_get_props(&collector);
for (auto &[key, val] : list) {
Expand Down Expand Up @@ -291,6 +297,9 @@ int resetprop_main(int argc, char *argv[]) {
case 'p':
flags.setPersist();
continue;
case 'P':
flags.setPersistOnly();
continue;
case 'v':
set_log_level_state(LogLevel::Debug, true);
continue;
Expand Down
2 changes: 1 addition & 1 deletion native/src/core/resetprop/resetprop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ using prop_list = std::map<std::string, std::string>;
struct prop_collector : prop_cb {
explicit prop_collector(prop_list &list) : list(list) {}
void exec(const char *name, const char *value) override {
list.insert_or_assign(name, value);
list.insert({name, value});
}
private:
prop_list &list;
Expand Down

0 comments on commit 8f8fa6c

Please sign in to comment.