[LayoutlibLoader] Print exception when FindClassOrDie, etc fail
Bug: 318393625
Test: Manual test with an unloadable class
Change-Id: Ifc7dca37f858cc1f76fcbfe6fc8c1bfbe75ab10a
diff --git a/core/jni/LayoutlibLoader.cpp b/core/jni/LayoutlibLoader.cpp
index 01e9f43..06d5eb3 100644
--- a/core/jni/LayoutlibLoader.cpp
+++ b/core/jni/LayoutlibLoader.cpp
@@ -362,6 +362,22 @@
using namespace android;
+// Called right before aborting by LOG_ALWAYS_FATAL. Print the pending exception.
+void abort_handler(const char* abort_message) {
+ ALOGE("Abort to abort the process...");
+
+ JNIEnv* env = NULL;
+ if (javaVM->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) {
+ ALOGE("vm->GetEnv() failed");
+ return;
+ }
+ if (env->ExceptionOccurred() != NULL) {
+ ALOGE("Pending exception:");
+ env->ExceptionDescribe();
+ }
+ ALOGE("Aborting because: %s", abort_message);
+}
+
JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void*) {
javaVM = vm;
JNIEnv* env = nullptr;
@@ -369,6 +385,8 @@
return JNI_ERR;
}
+ __android_log_set_aborter(abort_handler);
+
init_android_graphics();
// Configuration is stored as java System properties.