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

Commit

Permalink
log should not be printed in zygote process
Browse files Browse the repository at this point in the history
  • Loading branch information
RikkaW committed Sep 9, 2019
1 parent 3840b0b commit c5e3066
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def moduleId = "location_report_enabler"
def moduleName = "Location Report Enabler"
def moduleAuthor = "Rikka"
def moduleDescription = "Enable Google location report by hook system_property_get (and android::base::GetProperty for API 28+)."
def versionName = "v9.2"
def versionCode = 11
def versionName = "v9.3"
def versionCode = 12
def riruApi = 4

def moduleIdMagisk = "riru_location_report_enabler"
Expand Down
37 changes: 21 additions & 16 deletions jni/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ static bool is_app_need_hook(JNIEnv *env, jstring jAppDataDir, jstring jPackageN
break;

package_name[0] = '\0';
LOGW("can't parse %s", appDataDir);
return false;
}
env->ReleaseStringUTFChars(jAppDataDir, appDataDir);
Expand Down Expand Up @@ -73,6 +72,20 @@ static void load_config() {
close(fd);
}

static void appProcessPre(JNIEnv *env, jint _uid, jstring appDataDir, jstring packageName) {
uid = _uid;
enable_hook = is_app_need_hook(env, appDataDir, packageName);

if (enable_hook)
load_config();
}

static void appProcessPost() {
if (enable_hook) {
install_hook(package_name, uid / 100000);
}
}

extern "C" {
__attribute__((visibility("default"))) void nativeForkAndSpecializePre(
JNIEnv *env, jclass clazz, jint *_uid, jint *gid, jintArray *gids, jint *runtime_flags,
Expand All @@ -81,17 +94,14 @@ __attribute__((visibility("default"))) void nativeForkAndSpecializePre(
jstring *instructionSet, jstring *appDataDir, jstring *packageName,
jobjectArray *packagesForUID, jstring *sandboxId) {

uid = *_uid;
enable_hook = is_app_need_hook(env, *appDataDir, *packageName);

if (enable_hook)
load_config();
appProcessPre(env, *_uid, *appDataDir, *packageName);
}

__attribute__((visibility("default"))) int nativeForkAndSpecializePost(
JNIEnv *env, jclass clazz, jint res) {
if (res == 0 && enable_hook) install_hook(package_name, uid / 100000);
return !enable_hook;
if (res != 0) return 0;
appProcessPost();
return 0;
}

__attribute__((visibility("default"))) void specializeAppProcessPre(
Expand All @@ -100,17 +110,12 @@ __attribute__((visibility("default"))) void specializeAppProcessPre(
jboolean *startChildZygote, jstring *instructionSet, jstring *appDataDir,
jstring *packageName, jobjectArray *packagesForUID, jstring *sandboxId) {

uid = *_uid;
enable_hook = is_app_need_hook(env, *appDataDir, *packageName);

if (enable_hook)
load_config();
appProcessPre(env, *_uid, *appDataDir, *packageName);
}

__attribute__((visibility("default"))) int specializeAppProcessPost(
JNIEnv *env, jclass clazz) {

if (enable_hook) install_hook(package_name, uid / 100000);
return !enable_hook;
appProcessPost();
return 0;
}
}

0 comments on commit c5e3066

Please sign in to comment.