RikkaApps / Riru-ModuleTemplate

Module template of Riru.
MIT License
160 stars 127 forks source link

forkAndSpecializePost is not called in Pixel Experience (Custom ROM) #8

Closed aimardcr closed 3 years ago

aimardcr commented 3 years ago

So I have this device with PE Rom, forkAndSpecializePost is rarely called in this ROM. However forkAndSpecializePre is perfectly called (I have log the function and it executed fine). I have tested on other devices, my module works fine and forkAndSpecializePost is called perfectly. Is there work around for this?

Here is my code:


static void forkAndSpecializePre(
        JNIEnv *env, jclass clazz, jint *_uid, jint *gid, jintArray *gids, jint *runtimeFlags,
        jobjectArray *rlimits, jint *mountExternal, jstring *seInfo, jstring *niceName,
        jintArray *fdsToClose, jintArray *fdsToIgnore, jboolean *is_child_zygote,
        jstring *instructionSet, jstring *appDataDir, jboolean *isTopApp, jobjectArray *pkgDataInfoList,
        jobjectArray *whitelistedDataInfoList, jboolean *bindMountAppDataDirs, jboolean *bindMountAppStorageDirs) {

    enablePlugin = isPluginAvailable(env, *appDataDir);
}

static void forkAndSpecializePost(JNIEnv *env, jclass clazz, jint res) {
    if (res == 0) {
        // in app process
        if (enablePlugin) {
            int ret;
            pthread_t ntid;
            if ((ret = pthread_create(&ntid, NULL, loadPluginThread, NULL))) {
                LOGE("Error: %s\n", strerror(ret));
            }
        }
    } else {
        // in zygote process, res is child pid
        // don't print log here, see https://github.com/RikkaApps/Riru/blob/77adfd6a4a6a81bfd20569c910bc4854f2f84f5e/riru-core/jni/main/jni_native_method.cpp#L55-L66
    } 
}```
RikkaW commented 3 years ago

Probably because the ROM has "usap" enabled, so specializeAppProcess rather than forkAndSpecialize is used.