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 {}; return {};
} }
// TODO ignore unrelated processes
bool ConfigManager::IsAppNeedHook(const std::string &package_name) const { bool ConfigManager::IsAppNeedHook(const std::string &package_name) const {
if (package_name == installer_pkg_name_) { if (IsInstaller(package_name)) {
return true; return true;
} }
@ -229,7 +228,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
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]() { 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(),
@ -297,8 +296,7 @@ namespace edxp {
fs::perms::others_exec); fs::perms::others_exec);
path_chown(prefs_path, uid, 0); path_chown(prefs_path, uid, 0);
} }
if (pkg_name == installer_pkg_name_ || pkg_name == kPrimaryInstallerPkgName || if (IsInstaller(pkg_name) || pkg_name == "android") {
pkg_name == "android") {
auto conf_path = GetConfigPath(); auto conf_path = GetConfigPath();
if (!path_exists<true>(conf_path)) { if (!path_exists<true>(conf_path)) {
fs::create_directories(conf_path); fs::create_directories(conf_path);
@ -320,13 +318,9 @@ namespace edxp {
} }
if (pkg_name == kPrimaryInstallerPkgName) { if (pkg_name == kPrimaryInstallerPkgName) {
try { auto installer_pkg_name_path = GetConfigPath("installer");
auto installer_pkg_name_path = GetConfigPath("installer"); if (path_exists<true>(installer_pkg_name_path)) {
if (path_exists<true>(installer_pkg_name_path)) { fs::remove(installer_pkg_name_path);
fs::remove(installer_pkg_name_path);
}
} catch (const fs::filesystem_error &e) {
LOGE("%s", e.what());
} }
} }
} }

View File

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

View File

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