ConfigManager only initialize once

This commit is contained in:
LoveSy 2020-12-03 02:18:03 +08:00 committed by solohsu
parent 993ba29616
commit 72d320d819
4 changed files with 25 additions and 16 deletions

View File

@ -146,12 +146,12 @@ namespace edxp {
}
}
ConfigManager::ConfigManager(uid_t user) :
ConfigManager::ConfigManager(uid_t user, bool initialized) :
user_(user),
data_path_prefix_(fs::path(use_prot_storage_ ? "/data/user_de" : "/data/user") /
std::to_string(user_)),
base_config_path_(RetrieveBaseConfigPath()),
initialized_(InitConfigPath()),
initialized_(initialized || InitConfigPath()),
installer_pkg_name_(RetrieveInstallerPkgName()),
white_list_enable_(path_exists(GetConfigPath("usewhitelist"))),
deopt_boot_image_enabled_(path_exists(GetConfigPath("deoptbootimage"))),
@ -225,7 +225,7 @@ namespace edxp {
scope.emplace(std::move(app_pkg_name));
}
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::copy(scope.begin(), scope.end(),
std::ostream_iterator<std::string>(join, "\n "));

View File

@ -30,11 +30,14 @@ namespace edxp {
return instances_[current_user].get();
}
inline auto IsInitialized() const { return initialized_; }
inline static void SetCurrentUser(uid_t user) {
if (auto instance = instances_.find(user);
instance == instances_.end() || !instance->second ||
instance->second->NeedUpdateConfig()) {
instance == instances_.end() || !instance->second) {
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_);
}
inline auto IsInitialized() const { return initialized_; }
// Always true now
inline auto IsBlackWhiteListEnabled() const { return true; }
@ -116,7 +117,7 @@ namespace edxp {
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);
@ -131,6 +132,7 @@ namespace edxp {
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 &, bool&&);
std::filesystem::path RetrieveBaseConfigPath() const;

View File

@ -236,7 +236,7 @@ namespace edxp {
skip_ = true;
LOGW("skip injecting into android because no module hooks it");
}
if(!skip_) {
if (!skip_) {
PreLoadDex(ConfigManager::GetInjectDexPaths());
}
}
@ -297,12 +297,14 @@ namespace edxp {
}
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) {
const auto app_id = uid % PER_USER_RANGE;
bool skip = false;
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;
}
if (!skip && !info_res) {
@ -328,7 +330,7 @@ namespace edxp {
package_name.c_str());
}
if (!skip && app_modules_list_.empty() &&
if (!skip && empty_list() &&
package_name != ConfigManager::GetInstance()->GetInstallerPackageName()) {
skip = true;
LOGW("skip injecting xposed into %s because no module hooks it",
@ -354,9 +356,14 @@ namespace edxp {
app_data_dir_ = app_data_dir;
nice_name_ = nice_name;
ConfigManager::SetCurrentUser(user);
skip_ = ShouldSkipInject(package_name, user, uid, res, app_modules_list_, is_child_zygote);
if(!skip_) {
app_modules_list_ = ConfigManager::GetInstance()->GetAppModuleList(package_name);
skip_ = ShouldSkipInject(package_name, user, uid, res,
// Only obtains when needed
[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);
PreLoadDex(ConfigManager::GetInjectDexPaths());
}

View File

@ -114,7 +114,7 @@ namespace edxp {
static bool
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);
static std::tuple<bool, uid_t, std::string> GetAppInfoFromDir(JNIEnv *env, jstring dir, jstring nice_name);