From ae9618cf4df75a9f02d6d66092c52c1c27bada39 Mon Sep 17 00:00:00 2001 From: zljj0818 Date: Tue, 9 Jun 2020 03:03:03 +0800 Subject: [PATCH] fix AttachCurrentThread override thread name issue (flutter/engine#18815) --- .../src/flutter/fml/platform/android/jni_util.cc | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/fml/platform/android/jni_util.cc b/engine/src/flutter/fml/platform/android/jni_util.cc index b84a351f1c..a3e3055f2d 100644 --- a/engine/src/flutter/fml/platform/android/jni_util.cc +++ b/engine/src/flutter/fml/platform/android/jni_util.cc @@ -4,6 +4,7 @@ #include "flutter/fml/platform/android/jni_util.h" +#include #include #include @@ -25,7 +26,18 @@ JNIEnv* AttachCurrentThread() { FML_DCHECK(g_jvm != nullptr) << "Trying to attach to current thread without calling InitJavaVM first."; JNIEnv* env = nullptr; - jint ret = g_jvm->AttachCurrentThread(&env, nullptr); + JavaVMAttachArgs args; + args.version = JNI_VERSION_1_4; + args.group = nullptr; + // 16 is the maximum size for thread names on Android. + char thread_name[16]; + int err = prctl(PR_GET_NAME, thread_name); + if (err < 0) { + args.name = nullptr; + } else { + args.name = thread_name; + } + jint ret = g_jvm->AttachCurrentThread(&env, &args); FML_DCHECK(JNI_OK == ret); return env; }