Skip to content

Commit 91773c3

Browse files
committed
Support only read properties from storage
1 parent dc61033 commit 91773c3

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

native/src/core/resetprop/resetprop.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ struct PropFlags {
2929
void setSkipSvc() { flags |= 1; }
3030
void setPersist() { flags |= (1 << 1); }
3131
void setContext() { flags |= (1 << 2); }
32+
void setPersistOnly() { flags |= (1 << 3); setPersist(); }
3233
bool isSkipSvc() const { return flags & 1; }
3334
bool isPersist() const { return flags & (1 << 1); }
3435
bool isContext() const { return flags & (1 << 2); }
36+
bool isPersistOnly() const { return flags & (1 << 3); }
3537
private:
3638
uint32_t flags = 0;
3739
};
@@ -56,12 +58,13 @@ General flags:
5658
-v print verbose output to stderr
5759
5860
Read mode flags:
59-
-Z get property context instead of value
6061
-p also read persistent props from storage
62+
-P only read persistent props from storage
63+
-Z get property context instead of value
6164
6265
Write mode flags:
6366
-n set properties bypassing property_service
64-
-p always write persistent props changes to storage
67+
-p always write persistent prop changes to storage
6568
6669
)EOF", arg0);
6770
exit(1);
@@ -178,10 +181,12 @@ static string get_prop(const char *name, PropFlags flags) {
178181
}
179182

180183
string val;
181-
if (auto pi = system_property_find(name)) {
182-
prop_to_string cb(val);
183-
read_prop_with_cb(pi, &cb);
184-
LOGD("resetprop: get prop [%s]: [%s]\n", name, val.data());
184+
if (!flags.isPersistOnly()) {
185+
if (auto pi = system_property_find(name)) {
186+
prop_to_string cb(val);
187+
read_prop_with_cb(pi, &cb);
188+
LOGD("resetprop: get prop [%s]: [%s]\n", name, val.data());
189+
}
185190
}
186191

187192
if (val.empty() && flags.isPersist() && str_starts(name, "persist."))
@@ -195,7 +200,8 @@ static string get_prop(const char *name, PropFlags flags) {
195200
static void print_props(PropFlags flags) {
196201
prop_list list;
197202
prop_collector collector(list);
198-
system_property_foreach(read_prop_with_cb, &collector);
203+
if (!flags.isPersistOnly())
204+
system_property_foreach(read_prop_with_cb, &collector);
199205
if (flags.isPersist())
200206
persist_get_props(&collector);
201207
for (auto &[key, val] : list) {
@@ -291,6 +297,9 @@ int resetprop_main(int argc, char *argv[]) {
291297
case 'p':
292298
flags.setPersist();
293299
continue;
300+
case 'P':
301+
flags.setPersistOnly();
302+
continue;
294303
case 'v':
295304
set_log_level_state(LogLevel::Debug, true);
296305
continue;

native/src/core/resetprop/resetprop.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ using prop_list = std::map<std::string, std::string>;
1515
struct prop_collector : prop_cb {
1616
explicit prop_collector(prop_list &list) : list(list) {}
1717
void exec(const char *name, const char *value) override {
18-
list.insert_or_assign(name, value);
18+
list.insert({name, value});
1919
}
2020
private:
2121
prop_list &list;

0 commit comments

Comments
 (0)