mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-10-15 18:20:21 +00:00
Minor code changes across all sources
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
#include <pb_encode.h>
|
||||
#include <utils.h>
|
||||
|
||||
#include "_resetprop.h"
|
||||
#include "private/resetprop.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
@@ -1,14 +1,9 @@
|
||||
/* resetprop.h - Internal struct definitions
|
||||
*/
|
||||
|
||||
|
||||
#ifndef MAGISK_PROPS_H
|
||||
#define MAGISK_PROPS_H
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <logging.h>
|
||||
|
||||
#include "private/system_properties.h"
|
||||
#include "system_properties.h"
|
||||
|
||||
struct prop_t {
|
||||
char *name;
|
||||
@@ -28,7 +23,7 @@ struct prop_t {
|
||||
bool operator<(const prop_t &prop) const {
|
||||
return strcmp(name, prop.name) < 0;
|
||||
}
|
||||
prop_t& operator= (prop_t &&prop) {
|
||||
prop_t& operator=(prop_t &&prop) {
|
||||
if (this != &prop) {
|
||||
free(name);
|
||||
name = prop.name;
|
||||
@@ -60,5 +55,3 @@ std::string persist_getprop(const char *name);
|
||||
void persist_getprop(read_cb_t *read_cb);
|
||||
bool persist_deleteprop(const char *name);
|
||||
void collect_props(const char *name, const char *value, void *v_plist);
|
||||
|
||||
#endif //MAGISK_PROPS_H
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user