Minor code changes across all sources

This commit is contained in:
topjohnwu
2019-06-30 19:09:31 -07:00
parent db8dd9f186
commit ff3710de66
20 changed files with 50 additions and 82 deletions

View File

@@ -9,7 +9,7 @@
#include <vector>
#include <algorithm>
#include <magisk.h>
#include <logging.h>
#include <resetprop.h>
#include <utils.h>
#include <flags.h>
@@ -17,7 +17,7 @@
#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
#include "private/_system_properties.h"
#include "private/system_properties.h"
#include "_resetprop.h"
#include "private/resetprop.h"
using namespace std;
@@ -80,15 +80,14 @@ illegal:
static void read_props(const prop_info *pi, void *read_cb) {
__system_property_read_callback(
pi, [](auto cb, auto name, auto value, auto) -> void
{
pi, [](auto cb, auto name, auto value, auto) {
((read_cb_t *) cb)->exec(name, value);
}, read_cb);
}
void collect_props(const char *name, const char *value, void *v_plist) {
auto &prop_list = *static_cast<vector<prop_t> *>(v_plist);
prop_list.emplace_back(name, value);
auto prop_list = static_cast<vector<prop_t> *>(v_plist);
prop_list->emplace_back(name, value);
}
static void collect_unique_props(const char *name, const char *value, void *v_plist) {
@@ -121,15 +120,18 @@ static void print_props(bool persist) {
* Implementations of functions in resetprop.h (APIs)
* **************************************************/
#define ENSURE_INIT(ret) if (init_resetprop()) return ret
int prop_exist(const char *name) {
if (init_resetprop()) return 0;
ENSURE_INIT(0);
return __system_property_find(name) != nullptr;
}
// Get prop by name, return string
string getprop(const char *name, bool persist) {
if (!check_legal_property_name(name) || init_resetprop())
if (!check_legal_property_name(name))
return string();
ENSURE_INIT(string());
const prop_info *pi = __system_property_find(name);
if (pi == nullptr) {
if (persist && strncmp(name, "persist.", 8) == 0) {
@@ -151,7 +153,7 @@ string getprop(const char *name, bool persist) {
}
void getprop(void (*callback)(const char *, const char *, void *), void *cookie, bool persist) {
if (init_resetprop()) return;
ENSURE_INIT();
read_cb_t read_cb(callback, cookie);
__system_property_foreach(read_props, &read_cb);
if (persist) {
@@ -163,8 +165,7 @@ void getprop(void (*callback)(const char *, const char *, void *), void *cookie,
int setprop(const char *name, const char *value, bool trigger) {
if (!check_legal_property_name(name))
return 1;
if (init_resetprop())
return -1;
ENSURE_INIT(-1);
int ret;
@@ -197,7 +198,7 @@ int setprop(const char *name, const char *value, bool trigger) {
int deleteprop(const char *name, bool persist) {
if (!check_legal_property_name(name))
return 1;
if (init_resetprop()) return -1;
ENSURE_INIT(-1);
char path[PATH_MAX];
path[0] = '\0';
LOGD("resetprop: deleteprop [%s]\n", name);
@@ -207,7 +208,7 @@ int deleteprop(const char *name, bool persist) {
}
void load_prop_file(const char *filename, bool trigger) {
if (init_resetprop()) return;
ENSURE_INIT();
LOGD("resetprop: Parse prop file [%s]\n", filename);
parse_prop_file(filename, [=](auto key, auto val) -> bool {
setprop(key.data(), val.data(), trigger);