From 3840b0b9cbcdf877d1e68389632f9d22f96e8592 Mon Sep 17 00:00:00 2001 From: RikkaW Date: Sun, 1 Sep 2019 16:22:05 +0800 Subject: [PATCH] support apps installed in external storage (use adopted storage) --- jni/main/hook.cpp | 2 +- jni/main/main.cpp | 22 ++++++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/jni/main/hook.cpp b/jni/main/hook.cpp index d455828..0921812 100644 --- a/jni/main/hook.cpp +++ b/jni/main/hook.cpp @@ -69,7 +69,7 @@ NEW_FUNC_DEF(std::string, _ZN7android4base11GetPropertyERKNSt3__112basic_stringI } void install_hook(const char *package_name, int user) { - LOGI("install hook for %s (%d)", package_name, user); + LOGI("install hook for %d:%s", user, package_name); XHOOK_REGISTER(__system_property_get); diff --git a/jni/main/main.cpp b/jni/main/main.cpp index 1507abb..056e893 100644 --- a/jni/main/main.cpp +++ b/jni/main/main.cpp @@ -27,12 +27,22 @@ static bool is_app_need_hook(JNIEnv *env, jstring jAppDataDir, jstring jPackageN } else if (jAppDataDir) { const char *appDataDir = env->GetStringUTFChars(jAppDataDir, nullptr); int user = 0; - if (sscanf(appDataDir, "/data/%*[^/]/%d/%s", &user, package_name) != 2) { - if (sscanf(appDataDir, "/data/%*[^/]/%s", package_name) != 1) { - package_name[0] = '\0'; - LOGW("can't parse %s", appDataDir); - return false; - } + while (true) { + // /data/user// + if (sscanf(appDataDir, "/data/%*[^/]/%d/%s", &user, package_name) == 2) + break; + + // /mnt/expand//user// + if (sscanf(appDataDir, "/mnt/expand/%*[^/]/%*[^/]/%d/%s", &user, package_name) == 2) + break; + + // /data/data/ + if (sscanf(appDataDir, "/data/%*[^/]/%s", package_name) == 1) + break; + + package_name[0] = '\0'; + LOGW("can't parse %s", appDataDir); + return false; } env->ReleaseStringUTFChars(jAppDataDir, appDataDir); } else {