Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7de4dd6e authored by dimitry's avatar dimitry Committed by android-build-merger
Browse files

Merge "NativeActivity: Improve error message reporting"

am: de3150db

Change-Id: Icdce5b900d87e136a398f6c68c4706b53dcdcec0
parents 0bdb9a6e de3150db
Loading
Loading
Loading
Loading
+16 −8
Original line number Diff line number Diff line
@@ -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