ConfigManager only initialize once
This commit is contained in:
parent
993ba29616
commit
72d320d819
|
|
@ -146,12 +146,12 @@ namespace edxp {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfigManager::ConfigManager(uid_t user) :
|
ConfigManager::ConfigManager(uid_t user, bool initialized) :
|
||||||
user_(user),
|
user_(user),
|
||||||
data_path_prefix_(fs::path(use_prot_storage_ ? "/data/user_de" : "/data/user") /
|
data_path_prefix_(fs::path(use_prot_storage_ ? "/data/user_de" : "/data/user") /
|
||||||
std::to_string(user_)),
|
std::to_string(user_)),
|
||||||
base_config_path_(RetrieveBaseConfigPath()),
|
base_config_path_(RetrieveBaseConfigPath()),
|
||||||
initialized_(InitConfigPath()),
|
initialized_(initialized || InitConfigPath()),
|
||||||
installer_pkg_name_(RetrieveInstallerPkgName()),
|
installer_pkg_name_(RetrieveInstallerPkgName()),
|
||||||
white_list_enable_(path_exists(GetConfigPath("usewhitelist"))),
|
white_list_enable_(path_exists(GetConfigPath("usewhitelist"))),
|
||||||
deopt_boot_image_enabled_(path_exists(GetConfigPath("deoptbootimage"))),
|
deopt_boot_image_enabled_(path_exists(GetConfigPath("deoptbootimage"))),
|
||||||
|
|
@ -225,7 +225,7 @@ namespace edxp {
|
||||||
scope.emplace(std::move(app_pkg_name));
|
scope.emplace(std::move(app_pkg_name));
|
||||||
}
|
}
|
||||||
scope.insert(module_pkg_name); // Always add module itself
|
scope.insert(module_pkg_name); // Always add module itself
|
||||||
LOGD("scope of %s is:\n%s", module_pkg_name.c_str(), ([&scope = scope]() {
|
LOGI("scope of %s is:\n%s", module_pkg_name.c_str(), ([&scope = scope]() {
|
||||||
std::ostringstream join;
|
std::ostringstream join;
|
||||||
std::copy(scope.begin(), scope.end(),
|
std::copy(scope.begin(), scope.end(),
|
||||||
std::ostream_iterator<std::string>(join, "\n "));
|
std::ostream_iterator<std::string>(join, "\n "));
|
||||||
|
|
|
||||||
|
|
@ -30,11 +30,14 @@ namespace edxp {
|
||||||
return instances_[current_user].get();
|
return instances_[current_user].get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline auto IsInitialized() const { return initialized_; }
|
||||||
|
|
||||||
inline static void SetCurrentUser(uid_t user) {
|
inline static void SetCurrentUser(uid_t user) {
|
||||||
if (auto instance = instances_.find(user);
|
if (auto instance = instances_.find(user);
|
||||||
instance == instances_.end() || !instance->second ||
|
instance == instances_.end() || !instance->second) {
|
||||||
instance->second->NeedUpdateConfig()) {
|
|
||||||
instances_[user] = std::make_unique<ConfigManager>(user);
|
instances_[user] = std::make_unique<ConfigManager>(user);
|
||||||
|
} else if(instance->second->NeedUpdateConfig()) {
|
||||||
|
instances_[user] = std::make_unique<ConfigManager>(user, instance->second->IsInitialized());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -42,8 +45,6 @@ namespace edxp {
|
||||||
return std::move(instances_);
|
return std::move(instances_);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline auto IsInitialized() const { return initialized_; }
|
|
||||||
|
|
||||||
// Always true now
|
// Always true now
|
||||||
inline auto IsBlackWhiteListEnabled() const { return true; }
|
inline auto IsBlackWhiteListEnabled() const { return true; }
|
||||||
|
|
||||||
|
|
@ -116,7 +117,7 @@ namespace edxp {
|
||||||
|
|
||||||
const std::filesystem::file_time_type last_write_time_;
|
const std::filesystem::file_time_type last_write_time_;
|
||||||
|
|
||||||
ConfigManager(uid_t uid);
|
ConfigManager(uid_t uid, bool initialized=false);
|
||||||
|
|
||||||
static std::unordered_set<std::string> GetAppList(const std::filesystem::path &dir);
|
static std::unordered_set<std::string> GetAppList(const std::filesystem::path &dir);
|
||||||
|
|
||||||
|
|
@ -131,6 +132,7 @@ namespace edxp {
|
||||||
bool InitConfigPath() const;
|
bool InitConfigPath() const;
|
||||||
|
|
||||||
friend std::unique_ptr<ConfigManager> std::make_unique<ConfigManager>(uid_t &);
|
friend std::unique_ptr<ConfigManager> std::make_unique<ConfigManager>(uid_t &);
|
||||||
|
friend std::unique_ptr<ConfigManager> std::make_unique<ConfigManager>(uid_t &, bool&&);
|
||||||
|
|
||||||
std::filesystem::path RetrieveBaseConfigPath() const;
|
std::filesystem::path RetrieveBaseConfigPath() const;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -236,7 +236,7 @@ namespace edxp {
|
||||||
skip_ = true;
|
skip_ = true;
|
||||||
LOGW("skip injecting into android because no module hooks it");
|
LOGW("skip injecting into android because no module hooks it");
|
||||||
}
|
}
|
||||||
if(!skip_) {
|
if (!skip_) {
|
||||||
PreLoadDex(ConfigManager::GetInjectDexPaths());
|
PreLoadDex(ConfigManager::GetInjectDexPaths());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -297,12 +297,14 @@ namespace edxp {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Context::ShouldSkipInject(const std::string &package_name, uid_t user, uid_t uid,
|
bool Context::ShouldSkipInject(const std::string &package_name, uid_t user, uid_t uid,
|
||||||
bool info_res, const std::vector<std::string> &app_modules_list_,
|
bool info_res,
|
||||||
|
const std::function<bool()> &empty_list,
|
||||||
bool is_child_zygote) {
|
bool is_child_zygote) {
|
||||||
const auto app_id = uid % PER_USER_RANGE;
|
const auto app_id = uid % PER_USER_RANGE;
|
||||||
bool skip = false;
|
bool skip = false;
|
||||||
if (!ConfigManager::GetInstance()->IsInitialized()) {
|
if (!ConfigManager::GetInstance()->IsInitialized()) {
|
||||||
LOGE("skip injecting into %s because configurations are not loaded properly", package_name.c_str());
|
LOGE("skip injecting into %s because configurations are not loaded properly",
|
||||||
|
package_name.c_str());
|
||||||
skip = true;
|
skip = true;
|
||||||
}
|
}
|
||||||
if (!skip && !info_res) {
|
if (!skip && !info_res) {
|
||||||
|
|
@ -328,7 +330,7 @@ namespace edxp {
|
||||||
package_name.c_str());
|
package_name.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!skip && app_modules_list_.empty() &&
|
if (!skip && empty_list() &&
|
||||||
package_name != ConfigManager::GetInstance()->GetInstallerPackageName()) {
|
package_name != ConfigManager::GetInstance()->GetInstallerPackageName()) {
|
||||||
skip = true;
|
skip = true;
|
||||||
LOGW("skip injecting xposed into %s because no module hooks it",
|
LOGW("skip injecting xposed into %s because no module hooks it",
|
||||||
|
|
@ -354,9 +356,14 @@ namespace edxp {
|
||||||
app_data_dir_ = app_data_dir;
|
app_data_dir_ = app_data_dir;
|
||||||
nice_name_ = nice_name;
|
nice_name_ = nice_name;
|
||||||
ConfigManager::SetCurrentUser(user);
|
ConfigManager::SetCurrentUser(user);
|
||||||
skip_ = ShouldSkipInject(package_name, user, uid, res, app_modules_list_, is_child_zygote);
|
skip_ = ShouldSkipInject(package_name, user, uid, res,
|
||||||
if(!skip_) {
|
// Only obtains when needed
|
||||||
app_modules_list_ = ConfigManager::GetInstance()->GetAppModuleList(package_name);
|
[this, &package_name = package_name]() {
|
||||||
|
app_modules_list_ = ConfigManager::GetInstance()->GetAppModuleList(
|
||||||
|
package_name);
|
||||||
|
return app_modules_list_.empty();
|
||||||
|
}, is_child_zygote);
|
||||||
|
if (!skip_) {
|
||||||
ConfigManager::GetInstance()->EnsurePermission(package_name, uid % PER_USER_RANGE);
|
ConfigManager::GetInstance()->EnsurePermission(package_name, uid % PER_USER_RANGE);
|
||||||
PreLoadDex(ConfigManager::GetInjectDexPaths());
|
PreLoadDex(ConfigManager::GetInjectDexPaths());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -114,7 +114,7 @@ namespace edxp {
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
ShouldSkipInject(const std::string &package_name, uid_t user, uid_t uid, bool res,
|
ShouldSkipInject(const std::string &package_name, uid_t user, uid_t uid, bool res,
|
||||||
const std::vector<std::string> &app_module_list,
|
const std::function<bool()>& empty_list,
|
||||||
bool is_child_zygote);
|
bool is_child_zygote);
|
||||||
|
|
||||||
static std::tuple<bool, uid_t, std::string> GetAppInfoFromDir(JNIEnv *env, jstring dir, jstring nice_name);
|
static std::tuple<bool, uid_t, std::string> GetAppInfoFromDir(JNIEnv *env, jstring dir, jstring nice_name);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue