mirror of
https://github.com/rhunk/SnapEnhance.git
synced 2025-05-29 21:10:20 +02:00
fix(native): error handling
This commit is contained in:
parent
5347c50c15
commit
c35382f001
@ -11,19 +11,19 @@
|
|||||||
#include "hooks/sqlite_mutex.h"
|
#include "hooks/sqlite_mutex.h"
|
||||||
#include "hooks/duplex_hook.h"
|
#include "hooks/duplex_hook.h"
|
||||||
|
|
||||||
void JNICALL init(JNIEnv *env, jobject clazz) {
|
bool JNICALL init(JNIEnv *env, jobject clazz) {
|
||||||
LOGD("Initializing native");
|
LOGD("Initializing native");
|
||||||
using namespace common;
|
using namespace common;
|
||||||
|
|
||||||
native_lib_object = env->NewGlobalRef(clazz);
|
native_lib_object = env->NewGlobalRef(clazz);
|
||||||
client_module = util::get_module(("split_config." + std::string(ARM64 ? "arm64_v8a" : "armeabi-v7a") + ".apk").c_str());
|
client_module = util::get_module("libclient.so");
|
||||||
|
|
||||||
if (client_module.base == 0) {
|
if (client_module.base == 0) {
|
||||||
LOGD("split_config not found, trying libclient.so");
|
LOGD("libclient.so not found, trying split_config");
|
||||||
client_module = util::get_module("libclient.so");
|
client_module = util::get_module(("split_config." + std::string(ARM64 ? "arm64_v8a" : "armeabi-v7a") + ".apk").c_str());
|
||||||
if (client_module.base == 0) {
|
if (client_module.base == 0) {
|
||||||
LOGE("can't find libclient.so");
|
LOGE("can't find split_config!");
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,9 +38,10 @@ void JNICALL init(JNIEnv *env, jobject clazz) {
|
|||||||
util::remap_sections(BUILD_PACKAGE);
|
util::remap_sections(BUILD_PACKAGE);
|
||||||
|
|
||||||
LOGD("Native initialized");
|
LOGD("Native initialized");
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void JNICALL load_config(JNIEnv *env, jobject _, jobject config_object) {
|
void JNICALL load_config(JNIEnv *env, jobject, jobject config_object) {
|
||||||
auto native_config_clazz = env->GetObjectClass(config_object);
|
auto native_config_clazz = env->GetObjectClass(config_object);
|
||||||
#define GET_CONFIG_BOOL(name) env->GetBooleanField(config_object, env->GetFieldID(native_config_clazz, name, "Z"))
|
#define GET_CONFIG_BOOL(name) env->GetBooleanField(config_object, env->GetFieldID(native_config_clazz, name, "Z"))
|
||||||
auto native_config = common::native_config;
|
auto native_config = common::native_config;
|
||||||
@ -50,7 +51,7 @@ void JNICALL load_config(JNIEnv *env, jobject _, jobject config_object) {
|
|||||||
native_config->hook_asset_open = GET_CONFIG_BOOL("hookAssetOpen");
|
native_config->hook_asset_open = GET_CONFIG_BOOL("hookAssetOpen");
|
||||||
}
|
}
|
||||||
|
|
||||||
void JNICALL lock_database(JNIEnv *env, jobject _, jstring database_name, jobject runnable) {
|
void JNICALL lock_database(JNIEnv *env, jobject, jstring database_name, jobject runnable) {
|
||||||
auto database_name_str = env->GetStringUTFChars(database_name, nullptr);
|
auto database_name_str = env->GetStringUTFChars(database_name, nullptr);
|
||||||
auto mutex = SqliteMutexHook::mutex_map[database_name_str];
|
auto mutex = SqliteMutexHook::mutex_map[database_name_str];
|
||||||
env->ReleaseStringUTFChars(database_name, database_name_str);
|
env->ReleaseStringUTFChars(database_name, database_name_str);
|
||||||
@ -76,7 +77,7 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *_) {
|
|||||||
vm->GetEnv((void **)&env, JNI_VERSION_1_6);
|
vm->GetEnv((void **)&env, JNI_VERSION_1_6);
|
||||||
|
|
||||||
auto methods = std::vector<JNINativeMethod>();
|
auto methods = std::vector<JNINativeMethod>();
|
||||||
methods.push_back({"init", "()V", (void *)init});
|
methods.push_back({"init", "()Z", (void *)init});
|
||||||
methods.push_back({"loadConfig", "(L" BUILD_NAMESPACE "/NativeConfig;)V", (void *)load_config});
|
methods.push_back({"loadConfig", "(L" BUILD_NAMESPACE "/NativeConfig;)V", (void *)load_config});
|
||||||
methods.push_back({"lockDatabase", "(Ljava/lang/String;Ljava/lang/Runnable;)V", (void *)lock_database});
|
methods.push_back({"lockDatabase", "(Ljava/lang/String;Ljava/lang/Runnable;)V", (void *)lock_database});
|
||||||
|
|
||||||
|
@ -17,10 +17,12 @@ class NativeLib {
|
|||||||
System.loadLibrary(BuildConfig.NATIVE_NAME)
|
System.loadLibrary(BuildConfig.NATIVE_NAME)
|
||||||
initialized = true
|
initialized = true
|
||||||
callback(this)
|
callback(this)
|
||||||
init()
|
if (!init()) {
|
||||||
|
throw IllegalStateException("NativeLib init failed. Check logcat for more info")
|
||||||
|
}
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
initialized = false
|
initialized = false
|
||||||
Log.e("SnapEnhance", "NativeLib init failed")
|
Log.e("SnapEnhance", "NativeLib init failed", it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,7 +59,7 @@ class NativeLib {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private external fun init()
|
private external fun init(): Boolean
|
||||||
private external fun loadConfig(config: NativeConfig)
|
private external fun loadConfig(config: NativeConfig)
|
||||||
private external fun lockDatabase(name: String, callback: Runnable)
|
private external fun lockDatabase(name: String, callback: Runnable)
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user