Skip to content

Commit

Permalink
Always delete existing ro props at setprop
Browse files Browse the repository at this point in the history
  • Loading branch information
topjohnwu committed Mar 29, 2021
1 parent 2bef967 commit 7da3607
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions native/jni/resetprop/resetprop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,16 @@ struct resetprop : public sysprop {

int ret;
auto pi = const_cast<prop_info *>(__system_property_find(name));

// Always delete existing read-only properties, because they could be
// long properties and cannot directly go through __system_property_update
if (pi != nullptr && str_starts(name, "ro.")) {
delprop(name, false);
pi = nullptr;
}

if (pi != nullptr) {
if (prop_svc) {
if (strncmp(name, "ro.", 3) == 0)
delprop(name, false);
ret = system_property_set(name, value);
} else {
ret = __system_property_update(pi, value, strlen(value));
Expand Down Expand Up @@ -216,13 +222,18 @@ struct resetprop : public sysprop {
callback(key.data(), val.data(), cookie);
}

// Not an error when something is deleted
int delprop(const char *name, bool persist) override {
if (!check_legal_property_name(name))
return 1;
LOGD("resetprop: delete prop [%s]\n", name);
if (persist && strncmp(name, "persist.", 8) == 0)
persist = persist_deleteprop(name);
return __system_property_delete(name) && !(persist && strncmp(name, "persist.", 8) == 0);

int ret = __system_property_delete(name);
if (persist && str_starts(name, "persist.")) {
if (persist_deleteprop(name))
ret = 0;
}
return ret;
}
};

Expand Down

0 comments on commit 7da3607

Please sign in to comment.