Skip to content

Commit

Permalink
Do not log exceptions from JNI lookups of APIs that are known to be u…
Browse files Browse the repository at this point in the history
…navailable on older devices (flutter#44357)

These exceptions are benign but were being logged every time an app is launched on a device with an Android API level below 26.
  • Loading branch information
jason-simmons authored Aug 7, 2023
1 parent 39ce1c0 commit 1acbfce
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
6 changes: 4 additions & 2 deletions fml/platform/android/jni_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,13 @@ bool HasException(JNIEnv* env) {
return env->ExceptionCheck() != JNI_FALSE;
}

bool ClearException(JNIEnv* env) {
bool ClearException(JNIEnv* env, bool silent) {
if (!HasException(env)) {
return false;
}
env->ExceptionDescribe();
if (!silent) {
env->ExceptionDescribe();
}
env->ExceptionClear();
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion fml/platform/android/jni_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ ScopedJavaLocalRef<jobjectArray> VectorToBufferArray(

bool HasException(JNIEnv* env);

bool ClearException(JNIEnv* env);
bool ClearException(JNIEnv* env, bool silent = false);

bool CheckException(JNIEnv* env);
std::string GetJavaExceptionInfo(JNIEnv* env, jthrowable java_throwable);
Expand Down
6 changes: 3 additions & 3 deletions shell/platform/android/platform_view_android_jni_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1194,7 +1194,7 @@ bool PlatformViewAndroid::Register(JNIEnv* env) {

if (g_image_get_hardware_buffer_method == nullptr) {
// Continue on as this method may not exist at API <= 29.
fml::jni::ClearException(env);
fml::jni::ClearException(env, true);
}

g_image_close_method = env->GetMethodID(g_image_class->obj(), "close", "()V");
Expand All @@ -1214,11 +1214,11 @@ bool PlatformViewAndroid::Register(JNIEnv* env) {
env->GetMethodID(g_hardware_buffer_class->obj(), "close", "()V");
if (g_hardware_buffer_close_method == nullptr) {
// Continue on as this class may not exist at API <= 26.
fml::jni::ClearException(env);
fml::jni::ClearException(env, true);
}
} else {
// Continue on as this class may not exist at API <= 26.
fml::jni::ClearException(env);
fml::jni::ClearException(env, true);
}

g_compute_platform_resolved_locale_method = env->GetMethodID(
Expand Down

0 comments on commit 1acbfce

Please sign in to comment.