Merge "Check exceptions in BBQ and SC JNI code" into udc-dev
diff --git a/core/jni/android_graphics_BLASTBufferQueue.cpp b/core/jni/android_graphics_BLASTBufferQueue.cpp
index 55aa711..4474d4ca 100644
--- a/core/jni/android_graphics_BLASTBufferQueue.cpp
+++ b/core/jni/android_graphics_BLASTBufferQueue.cpp
@@ -52,7 +52,7 @@
return env;
}
- struct {
+struct {
jmethodID onTransactionHang;
} gTransactionHangCallback;
@@ -72,12 +72,14 @@
}
void onTransactionHang(const std::string& reason) {
- if (mTransactionHangObject) {
- JNIEnv* env = getenv(mVm);
- ScopedLocalRef<jstring> jReason(env, env->NewStringUTF(reason.c_str()));
- getenv(mVm)->CallVoidMethod(mTransactionHangObject,
- gTransactionHangCallback.onTransactionHang, jReason.get());
+ if (!mTransactionHangObject) {
+ return;
}
+ JNIEnv* env = getenv(mVm);
+ ScopedLocalRef<jstring> jReason(env, env->NewStringUTF(reason.c_str()));
+ getenv(mVm)->CallVoidMethod(mTransactionHangObject,
+ gTransactionHangCallback.onTransactionHang, jReason.get());
+ DieIfException(env, "Uncaught exception in TransactionHangCallback.");
}
private:
diff --git a/core/jni/android_view_SurfaceControl.cpp b/core/jni/android_view_SurfaceControl.cpp
index e42c6f1..8e96ac1 100644
--- a/core/jni/android_view_SurfaceControl.cpp
+++ b/core/jni/android_view_SurfaceControl.cpp
@@ -285,6 +285,7 @@
JNIEnv* env = getenv();
env->CallVoidMethod(mTransactionCommittedListenerObject,
gTransactionCommittedListenerClassInfo.onTransactionCommitted);
+ DieIfException(env, "Uncaught exception in TransactionCommittedListener.");
}
static void transactionCallbackThunk(void* context, nsecs_t /*latchTime*/,
@@ -325,6 +326,7 @@
binder::Status onWindowInfosReported() override {
JNIEnv* env = getenv();
env->CallVoidMethod(mListener, gRunnableClassInfo.run);
+ DieIfException(env, "Uncaught exception in WindowInfosReportedListener.");
return binder::Status::ok();
}
@@ -356,6 +358,7 @@
env->CallVoidMethod(mTrustedPresentationCallback,
gTrustedPresentationCallbackClassInfo.onTrustedPresentationChanged,
inTrustedPresentationState);
+ DieIfException(env, "Uncaught exception in TrustedPresentationCallback.");
}
void addCallbackRef(const sp<SurfaceComposerClient::PresentationCallbackRAII>& callbackRef) {
diff --git a/core/jni/core_jni_helpers.h b/core/jni/core_jni_helpers.h
index b85a425..210dc89 100644
--- a/core/jni/core_jni_helpers.h
+++ b/core/jni/core_jni_helpers.h
@@ -134,6 +134,15 @@
return env;
}
+static inline void DieIfException(JNIEnv* env, const char* message) {
+ if (env->ExceptionCheck()) {
+ jnihelp::ExpandableString summary;
+ jnihelp::ExpandableStringInitialize(&summary);
+ jnihelp::GetStackTraceOrSummary(env, nullptr, &summary);
+ LOG_ALWAYS_FATAL("%s\n%s", message, summary.data);
+ }
+}
+
} // namespace android
#endif // CORE_JNI_HELPERS