Fix multiuser support

This commit is contained in:
LoveSy 2020-12-05 18:42:21 +08:00 committed by solohsu
parent 3389af6edc
commit 1e3843376f
3 changed files with 17 additions and 19 deletions

View File

@ -133,9 +133,8 @@ namespace edxp {
return {};
}
// TODO ignore unrelated processes
bool ConfigManager::IsAppNeedHook(const std::string &package_name) const {
if (package_name == installer_pkg_name_) {
if (IsInstaller(package_name)) {
return true;
}
@ -229,7 +228,7 @@ namespace edxp {
scope.emplace(std::move(app_pkg_name));
}
scope.insert(module_pkg_name); // Always add module itself
if (module_pkg_name == installer_pkg_name_) scope.erase("android");
if (IsInstaller(module_pkg_name)) scope.erase("android");
LOGI("scope of %s is:\n%s", module_pkg_name.c_str(), ([&scope = scope]() {
std::ostringstream join;
std::copy(scope.begin(), scope.end(),
@ -297,8 +296,7 @@ namespace edxp {
fs::perms::others_exec);
path_chown(prefs_path, uid, 0);
}
if (pkg_name == installer_pkg_name_ || pkg_name == kPrimaryInstallerPkgName ||
pkg_name == "android") {
if (IsInstaller(pkg_name) || pkg_name == "android") {
auto conf_path = GetConfigPath();
if (!path_exists<true>(conf_path)) {
fs::create_directories(conf_path);
@ -320,13 +318,9 @@ namespace edxp {
}
if (pkg_name == kPrimaryInstallerPkgName) {
try {
auto installer_pkg_name_path = GetConfigPath("installer");
if (path_exists<true>(installer_pkg_name_path)) {
fs::remove(installer_pkg_name_path);
}
} catch (const fs::filesystem_error &e) {
LOGE("%s", e.what());
auto installer_pkg_name_path = GetConfigPath("installer");
if (path_exists<true>(installer_pkg_name_path)) {
fs::remove(installer_pkg_name_path);
}
}
}

View File

@ -42,6 +42,7 @@ namespace edxp {
instances_[user] = std::make_unique<ConfigManager>(user,
instance->second->IsInitialized());
}
current_user = user;
}
inline static auto ReleaseInstances() {
@ -97,6 +98,10 @@ namespace edxp {
static const auto &GetInjectDexPaths() { return inject_dex_paths_; };
bool IsInstaller(const std::string& pkg_name) const {
return pkg_name == installer_pkg_name_ || pkg_name == kPrimaryInstallerPkgName;
}
private:
inline static std::unordered_map<uid_t, std::unique_ptr<ConfigManager>> instances_{};
inline static uid_t current_user = 0u;

View File

@ -68,7 +68,7 @@ namespace edxp {
}
dexes.emplace_back(std::istreambuf_iterator<char>(is),
std::istreambuf_iterator<char>());
LOGD("Loaded %s with size %zu", path.c_str(), dexes.back().size());
LOGI("Loaded %s with size %zu", path.c_str(), dexes.back().size());
}
}
@ -97,7 +97,7 @@ namespace edxp {
env->SetObjectArrayElement(buffer_array, i, buffer);
}
jobject my_cl = JNI_NewObject(env, in_memory_classloader, initMid,
buffer_array, sys_classloader);
buffer_array, sys_classloader);
env->DeleteLocalRef(classloader);
env->DeleteLocalRef(sys_classloader);
env->DeleteLocalRef(in_memory_classloader);
@ -248,7 +248,7 @@ namespace edxp {
}
std::vector<unsigned char> dex{std::istreambuf_iterator<char>(is),
std::istreambuf_iterator<char>()};
LOGD("Loaded %s with size %zu", path.c_str(), dex.size());
LOGI("Loaded %s with size %zu", path.c_str(), dex.size());
jclass classloader = JNI_FindClass(env, "java/lang/ClassLoader");
jmethodID getsyscl_mid = JNI_GetStaticMethodID(
@ -336,7 +336,7 @@ namespace edxp {
std::vector<std::string> splits(path.begin(), path.end());
if (splits.size() < 5u) {
LOGE("can't parse %s", path.c_str());
return {false, uid, {}};
return {false, 0, name.get()};
}
const auto &uid_str = splits[3];
const auto &package_name = splits[4];
@ -383,8 +383,7 @@ namespace edxp {
package_name.c_str());
}
if (!skip && empty_list() &&
package_name != ConfigManager::GetInstance()->GetInstallerPackageName()) {
if (!skip && empty_list() && !ConfigManager::GetInstance()->IsInstaller(package_name)) {
skip = true;
LOGW("skip injecting xposed into %s because no module hooks it",
package_name.c_str());
@ -417,7 +416,7 @@ namespace edxp {
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);
PreLoadDex(ConfigManager::GetInjectDexPaths());
}
}