Skip to content
This repository has been archived by the owner on Sep 2, 2021. It is now read-only.

Commit

Permalink
support apps installed in external storage (use adopted storage)
Browse files Browse the repository at this point in the history
  • Loading branch information
RikkaW committed Sep 1, 2019
1 parent 4e489e0 commit 3840b0b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion jni/main/hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
22 changes: 16 additions & 6 deletions jni/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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/<user_id>/<package>
if (sscanf(appDataDir, "/data/%*[^/]/%d/%s", &user, package_name) == 2)
break;

// /mnt/expand/<id>/user/<user_id>/<package>
if (sscanf(appDataDir, "/mnt/expand/%*[^/]/%*[^/]/%d/%s", &user, package_name) == 2)
break;

// /data/data/<package>
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 {
Expand Down

0 comments on commit 3840b0b

Please sign in to comment.