You've already forked android_translation_layer
mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-10-27 11:48:10 -07:00
NativeActivity: cooperate with nativebridge when it's in use
This commit is contained in:
@@ -264,14 +264,35 @@ jlong Java_android_app_NativeActivity_loadNativeCode(JNIEnv* env, jobject clazz,
|
|||||||
const char* pathStr = (*env)->GetStringUTFChars(env, path, NULL);
|
const char* pathStr = (*env)->GetStringUTFChars(env, path, NULL);
|
||||||
struct NativeCode* code = NULL;
|
struct NativeCode* code = NULL;
|
||||||
|
|
||||||
void* handle = bionic_dlopen(pathStr, RTLD_LAZY);
|
static void *libnb_handle = NULL;
|
||||||
|
bool (*NativeBridgeIsSupported)(const char*);
|
||||||
|
void* (*NativeBridgeLoadLibrary)(const char*, int);
|
||||||
|
void* (*NativeBridgeGetTrampoline)(void*, const char*, const char*, uint32_t);
|
||||||
|
if(!libnb_handle) {
|
||||||
|
libnb_handle = dlopen("libnativebridge.so", RTLD_LAZY);
|
||||||
|
NativeBridgeIsSupported = dlsym(libnb_handle, "NativeBridgeIsSupported");
|
||||||
|
NativeBridgeLoadLibrary = dlsym(libnb_handle, "NativeBridgeLoadLibrary");
|
||||||
|
NativeBridgeGetTrampoline = dlsym(libnb_handle, "NativeBridgeGetTrampoline");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool use_native_bridge = NativeBridgeIsSupported(pathStr);
|
||||||
|
|
||||||
|
void* handle;
|
||||||
|
if(use_native_bridge)
|
||||||
|
handle = NativeBridgeLoadLibrary(pathStr, RTLD_LAZY);
|
||||||
|
else
|
||||||
|
handle = bionic_dlopen(pathStr, RTLD_LAZY);
|
||||||
|
|
||||||
(*env)->ReleaseStringUTFChars(env, path, pathStr);
|
(*env)->ReleaseStringUTFChars(env, path, pathStr);
|
||||||
|
|
||||||
if (handle != NULL) {
|
if (handle != NULL) {
|
||||||
const char* funcStr = (*env)->GetStringUTFChars(env, funcName, NULL);
|
const char* funcStr = (*env)->GetStringUTFChars(env, funcName, NULL);
|
||||||
code = NativeCode_new(handle, (ANativeActivity_createFunc*)
|
ANativeActivity_createFunc* create_func;
|
||||||
bionic_dlsym(handle, funcStr));
|
if(use_native_bridge)
|
||||||
|
create_func = NativeBridgeGetTrampoline(handle, funcStr, NULL, 0);
|
||||||
|
else
|
||||||
|
create_func = bionic_dlsym(handle, funcStr);
|
||||||
|
code = NativeCode_new(handle, (ANativeActivity_createFunc*)create_func);
|
||||||
(*env)->ReleaseStringUTFChars(env, funcName, funcStr);
|
(*env)->ReleaseStringUTFChars(env, funcName, funcStr);
|
||||||
|
|
||||||
if (code->createActivityFunc == NULL) {
|
if (code->createActivityFunc == NULL) {
|
||||||
|
|||||||
@@ -9,6 +9,10 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
#undef android_app_NativeActivity_MODE_PRIVATE
|
#undef android_app_NativeActivity_MODE_PRIVATE
|
||||||
#define android_app_NativeActivity_MODE_PRIVATE 0L
|
#define android_app_NativeActivity_MODE_PRIVATE 0L
|
||||||
|
#undef android_app_NativeActivity_RESULT_CANCELED
|
||||||
|
#define android_app_NativeActivity_RESULT_CANCELED 0L
|
||||||
|
#undef android_app_NativeActivity_RESULT_OK
|
||||||
|
#define android_app_NativeActivity_RESULT_OK -1L
|
||||||
/*
|
/*
|
||||||
* Class: android_app_NativeActivity
|
* Class: android_app_NativeActivity
|
||||||
* Method: loadNativeCode
|
* Method: loadNativeCode
|
||||||
|
|||||||
Reference in New Issue
Block a user