NativeActivity: Improve error message reporting
The error message is not necessary a dlerror(). For the devices with native bridge it is reported by NB implementation. Bug: http://b/67412560 Test: manual Change-Id: I05377c3490199c40419831b5aae27cb30d4a321b
This commit is contained in:
@@ -40,6 +40,7 @@
|
||||
#include "android_view_InputChannel.h"
|
||||
#include "android_view_KeyEvent.h"
|
||||
|
||||
#include "android-base/stringprintf.h"
|
||||
#include "nativebridge/native_bridge.h"
|
||||
#include "nativeloader/native_loader.h"
|
||||
|
||||
@@ -265,6 +266,8 @@ static int mainWorkCallback(int fd, int events, void* data) {
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
static thread_local std::string g_error_msg;
|
||||
|
||||
static jlong
|
||||
loadNativeCode_native(JNIEnv* env, jobject clazz, jstring path, jstring funcName,
|
||||
jobject messageQueue, jstring internalDataDir, jstring obbDir,
|
||||
@@ -277,7 +280,6 @@ loadNativeCode_native(JNIEnv* env, jobject clazz, jstring path, jstring funcName
|
||||
ScopedUtfChars pathStr(env, path);
|
||||
std::unique_ptr<NativeCode> code;
|
||||
bool needs_native_bridge = false;
|
||||
std::string error_msg;
|
||||
|
||||
void* handle = OpenNativeLibrary(env,
|
||||
sdkVersion,
|
||||
@@ -285,12 +287,12 @@ loadNativeCode_native(JNIEnv* env, jobject clazz, jstring path, jstring funcName
|
||||
classLoader,
|
||||
libraryPath,
|
||||
&needs_native_bridge,
|
||||
&error_msg);
|
||||
&g_error_msg);
|
||||
|
||||
if (handle == nullptr) {
|
||||
ALOGW("NativeActivity LoadNativeLibrary(\"%s\") failed: %s",
|
||||
pathStr.c_str(),
|
||||
error_msg.c_str());
|
||||
g_error_msg.c_str());
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -306,19 +308,22 @@ loadNativeCode_native(JNIEnv* env, jobject clazz, jstring path, jstring funcName
|
||||
env->ReleaseStringUTFChars(funcName, funcStr);
|
||||
|
||||
if (code->createActivityFunc == NULL) {
|
||||
ALOGW("ANativeActivity_onCreate not found");
|
||||
g_error_msg = needs_native_bridge ? NativeBridgeGetError() : dlerror();
|
||||
ALOGW("ANativeActivity_onCreate not found: %s", g_error_msg.c_str());
|
||||
return 0;
|
||||
}
|
||||
|
||||
code->messageQueue = android_os_MessageQueue_getMessageQueue(env, messageQueue);
|
||||
if (code->messageQueue == NULL) {
|
||||
ALOGW("Unable to retrieve native MessageQueue");
|
||||
g_error_msg = "Unable to retrieve native MessageQueue";
|
||||
ALOGW("%s", g_error_msg.c_str());
|
||||
return 0;
|
||||
}
|
||||
|
||||
int msgpipe[2];
|
||||
if (pipe(msgpipe)) {
|
||||
ALOGW("could not create pipe: %s", strerror(errno));
|
||||
g_error_msg = android::base::StringPrintf("could not create pipe: %s", strerror(errno));
|
||||
ALOGW("%s", g_error_msg.c_str());
|
||||
return 0;
|
||||
}
|
||||
code->mainWorkRead = msgpipe[0];
|
||||
@@ -334,7 +339,8 @@ loadNativeCode_native(JNIEnv* env, jobject clazz, jstring path, jstring funcName
|
||||
|
||||
code->ANativeActivity::callbacks = &code->callbacks;
|
||||
if (env->GetJavaVM(&code->vm) < 0) {
|
||||
ALOGW("NativeActivity GetJavaVM failed");
|
||||
g_error_msg = "NativeActivity GetJavaVM failed";
|
||||
ALOGW("%s", g_error_msg.c_str());
|
||||
return 0;
|
||||
}
|
||||
code->env = env;
|
||||
@@ -381,7 +387,9 @@ loadNativeCode_native(JNIEnv* env, jobject clazz, jstring path, jstring funcName
|
||||
}
|
||||
|
||||
static jstring getDlError_native(JNIEnv* env, jobject clazz) {
|
||||
return env->NewStringUTF(dlerror());
|
||||
jstring result = env->NewStringUTF(g_error_msg.c_str());
|
||||
g_error_msg.clear();
|
||||
return result;
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
Reference in New Issue
Block a user