diff options
author | Steven Moreland <smoreland@google.com> | 2020-11-18 18:23:51 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2020-11-18 18:23:51 +0000 |
commit | 0226e893325393b6f6067fc3aeb83597f424eca3 (patch) | |
tree | c94d33df0d00560640195ddc35cf6eeefb7ffd14 | |
parent | ab1b8a7a20a3909eeb507f6a50a9e2261c1377a4 (diff) | |
parent | 8f4319d5a7e471f68ffdc921343da33f9ed803da (diff) |
Merge "HwBinder: log exceptions from Java"
-rw-r--r-- | core/jni/android_os_HwBinder.cpp | 12 | ||||
-rw-r--r-- | core/jni/android_util_Binder.cpp | 25 | ||||
-rw-r--r-- | core/jni/android_util_Binder.h | 2 |
3 files changed, 19 insertions, 20 deletions
diff --git a/core/jni/android_os_HwBinder.cpp b/core/jni/android_os_HwBinder.cpp index 48f33a6a3d77..781895eeeaba 100644 --- a/core/jni/android_os_HwBinder.cpp +++ b/core/jni/android_os_HwBinder.cpp @@ -20,6 +20,8 @@ #include "android_os_HwBinder.h" +#include "android_util_Binder.h" // for binder_report_exception + #include "android_os_HwParcel.h" #include "android_os_HwRemoteBinder.h" @@ -183,15 +185,7 @@ status_t JHwBinder::onTransact( env->ExceptionDescribe(); env->ExceptionClear(); - // It is illegal to call IsInstanceOf if there is a pending exception. - // Attempting to do so results in a JniAbort which crashes the entire process. - if (env->IsInstanceOf(excep, gErrorClass)) { - /* It's an error */ - LOG(ERROR) << "Forcefully exiting"; - _exit(1); - } else { - LOG(ERROR) << "Uncaught exception!"; - } + binder_report_exception(env, excep, "Uncaught error or exception in hwbinder!"); env->DeleteLocalRef(excep); } diff --git a/core/jni/android_util_Binder.cpp b/core/jni/android_util_Binder.cpp index 9643b64c68f8..581dc0848a28 100644 --- a/core/jni/android_util_Binder.cpp +++ b/core/jni/android_util_Binder.cpp @@ -302,8 +302,9 @@ static void report_java_lang_error(JNIEnv* env, jthrowable error, const char* ms report_java_lang_error_fatal_error(env, error, msg); } -static void report_exception(JNIEnv* env, jthrowable excep, const char* msg) -{ +namespace android { + +void binder_report_exception(JNIEnv* env, jthrowable excep, const char* msg) { env->ExceptionClear(); ScopedLocalRef<jstring> tagstr(env, env->NewStringUTF(LOG_TAG)); @@ -331,6 +332,8 @@ static void report_exception(JNIEnv* env, jthrowable excep, const char* msg) } } +} // namespace android + class JavaBBinderHolder; class JavaBBinder : public BBinder @@ -405,9 +408,9 @@ protected: if (env->ExceptionCheck()) { ScopedLocalRef<jthrowable> excep(env, env->ExceptionOccurred()); - report_exception(env, excep.get(), - "*** Uncaught remote exception! " - "(Exceptions are not yet supported across processes.)"); + binder_report_exception(env, excep.get(), + "*** Uncaught remote exception! " + "(Exceptions are not yet supported across processes.)"); res = JNI_FALSE; } @@ -421,8 +424,8 @@ protected: if (env->ExceptionCheck()) { ScopedLocalRef<jthrowable> excep(env, env->ExceptionOccurred()); - report_exception(env, excep.get(), - "*** Uncaught exception in onBinderStrictModePolicyChange"); + binder_report_exception(env, excep.get(), + "*** Uncaught exception in onBinderStrictModePolicyChange"); } // Need to always call through the native implementation of @@ -567,8 +570,8 @@ public: jBinderProxy.get()); if (env->ExceptionCheck()) { jthrowable excep = env->ExceptionOccurred(); - report_exception(env, excep, - "*** Uncaught exception returned from death notification!"); + binder_report_exception(env, excep, + "*** Uncaught exception returned from death notification!"); } // Serialize with our containing DeathRecipientList so that we can't @@ -1163,8 +1166,8 @@ static void android_os_BinderInternal_proxyLimitcallback(int uid) if (env->ExceptionCheck()) { ScopedLocalRef<jthrowable> excep(env, env->ExceptionOccurred()); - report_exception(env, excep.get(), - "*** Uncaught exception in binderProxyLimitCallbackFromNative"); + binder_report_exception(env, excep.get(), + "*** Uncaught exception in binderProxyLimitCallbackFromNative"); } } diff --git a/core/jni/android_util_Binder.h b/core/jni/android_util_Binder.h index c109d6c265c3..9098d46ee29c 100644 --- a/core/jni/android_util_Binder.h +++ b/core/jni/android_util_Binder.h @@ -35,6 +35,8 @@ extern void set_dalvik_blockguard_policy(JNIEnv* env, jint strict_policy); extern void signalExceptionForError(JNIEnv* env, jobject obj, status_t err, bool canThrowRemoteException = false, int parcelSize = 0); +// does not take ownership of the exception, aborts if this is an error +void binder_report_exception(JNIEnv* env, jthrowable excep, const char* msg); } #endif |