Merge "NativeActivity: Improve error message reporting"

This commit is contained in:
Treehugger Robot
2017-10-05 09:44:21 +00:00
committed by Gerrit Code Review

View File

@@ -40,6 +40,7 @@
#include "android_view_InputChannel.h" #include "android_view_InputChannel.h"
#include "android_view_KeyEvent.h" #include "android_view_KeyEvent.h"
#include "android-base/stringprintf.h"
#include "nativebridge/native_bridge.h" #include "nativebridge/native_bridge.h"
#include "nativeloader/native_loader.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 static jlong
loadNativeCode_native(JNIEnv* env, jobject clazz, jstring path, jstring funcName, loadNativeCode_native(JNIEnv* env, jobject clazz, jstring path, jstring funcName,
jobject messageQueue, jstring internalDataDir, jstring obbDir, jobject messageQueue, jstring internalDataDir, jstring obbDir,
@@ -277,7 +280,6 @@ loadNativeCode_native(JNIEnv* env, jobject clazz, jstring path, jstring funcName
ScopedUtfChars pathStr(env, path); ScopedUtfChars pathStr(env, path);
std::unique_ptr<NativeCode> code; std::unique_ptr<NativeCode> code;
bool needs_native_bridge = false; bool needs_native_bridge = false;
std::string error_msg;
void* handle = OpenNativeLibrary(env, void* handle = OpenNativeLibrary(env,
sdkVersion, sdkVersion,
@@ -285,12 +287,12 @@ loadNativeCode_native(JNIEnv* env, jobject clazz, jstring path, jstring funcName
classLoader, classLoader,
libraryPath, libraryPath,
&needs_native_bridge, &needs_native_bridge,
&error_msg); &g_error_msg);
if (handle == nullptr) { if (handle == nullptr) {
ALOGW("NativeActivity LoadNativeLibrary(\"%s\") failed: %s", ALOGW("NativeActivity LoadNativeLibrary(\"%s\") failed: %s",
pathStr.c_str(), pathStr.c_str(),
error_msg.c_str()); g_error_msg.c_str());
return 0; return 0;
} }
@@ -306,19 +308,22 @@ loadNativeCode_native(JNIEnv* env, jobject clazz, jstring path, jstring funcName
env->ReleaseStringUTFChars(funcName, funcStr); env->ReleaseStringUTFChars(funcName, funcStr);
if (code->createActivityFunc == NULL) { 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; return 0;
} }
code->messageQueue = android_os_MessageQueue_getMessageQueue(env, messageQueue); code->messageQueue = android_os_MessageQueue_getMessageQueue(env, messageQueue);
if (code->messageQueue == NULL) { 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; return 0;
} }
int msgpipe[2]; int msgpipe[2];
if (pipe(msgpipe)) { 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; return 0;
} }
code->mainWorkRead = msgpipe[0]; code->mainWorkRead = msgpipe[0];
@@ -334,7 +339,8 @@ loadNativeCode_native(JNIEnv* env, jobject clazz, jstring path, jstring funcName
code->ANativeActivity::callbacks = &code->callbacks; code->ANativeActivity::callbacks = &code->callbacks;
if (env->GetJavaVM(&code->vm) < 0) { 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; return 0;
} }
code->env = env; 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) { 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 static void