feat(native): pre init

This commit is contained in:
rhunk
2024-07-28 19:39:57 +02:00
parent d3f9d03dcf
commit 8c4e32d614
2 changed files with 11 additions and 5 deletions

View File

@@ -24,7 +24,10 @@ use std::ffi::c_void;
use std::thread::JoinHandle;
fn pre_init() {
debug!("Pre init");
linker_hook::init();
custom_font_hook::init();
fstat_hook::init();
}
fn init(mut env: JNIEnv, _class: JObject, signature_cache: JString) -> jstring {
@@ -66,9 +69,7 @@ fn init(mut env: JNIEnv, _class: JObject, signature_cache: JString) -> jstring {
duplex_hook::init(),
unary_call_hook::init(),
composer_hook::init(),
fstat_hook::init(),
sqlite_hook::init(),
custom_font_hook::init()
sqlite_hook::init()
);
threads.into_iter().for_each(|t| t.join().unwrap());
@@ -108,6 +109,11 @@ pub extern "system" fn JNI_OnLoad(_vm: JavaVM, _: *mut c_void) -> jint {
env.register_native_methods(
native_lib_class,
&[
NativeMethod {
name: "preInit".into(),
sig: "()V".into(),
fn_ptr: pre_init as *mut c_void,
},
NativeMethod {
name: "init".into(),
sig: "(Ljava/lang/String;)Ljava/lang/String;".into(),
@@ -141,7 +147,5 @@ pub extern "system" fn JNI_OnLoad(_vm: JavaVM, _: *mut c_void) -> jint {
]
).expect("Failed to register native methods");
pre_init();
JNI_VERSION_1_6
}

View File

@@ -20,6 +20,7 @@ class NativeLib {
System.loadLibrary(BuildConfig.NATIVE_NAME)
initialized = true
callback(this)
preInit()
return@runCatching {
signatureCache = init(signatureCache) ?: throw IllegalStateException("NativeLib init failed. Check logcat for more info")
}
@@ -65,6 +66,7 @@ class NativeLib {
System.load(generatedPath)
}
private external fun preInit()
private external fun init(signatureCache: String?): String?
private external fun loadConfig(config: NativeConfig)
private external fun lockDatabase(name: String, callback: Runnable)