mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-04-28 20:27:58 +03:00
NativeActivity: cooperate with nativebridge when it's in use
This commit is contained in:
parent
9f244edc05
commit
f61f200d7b
2 changed files with 28 additions and 3 deletions
|
@ -264,14 +264,35 @@ jlong Java_android_app_NativeActivity_loadNativeCode(JNIEnv* env, jobject clazz,
|
|||
const char* pathStr = (*env)->GetStringUTFChars(env, path, 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);
|
||||
|
||||
if (handle != NULL) {
|
||||
const char* funcStr = (*env)->GetStringUTFChars(env, funcName, NULL);
|
||||
code = NativeCode_new(handle, (ANativeActivity_createFunc*)
|
||||
bionic_dlsym(handle, funcStr));
|
||||
ANativeActivity_createFunc* create_func;
|
||||
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);
|
||||
|
||||
if (code->createActivityFunc == NULL) {
|
||||
|
|
|
@ -9,6 +9,10 @@ extern "C" {
|
|||
#endif
|
||||
#undef android_app_NativeActivity_MODE_PRIVATE
|
||||
#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
|
||||
* Method: loadNativeCode
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue