Android: Stop ART from complaining about missing thread names.

The new Android jvm (ART) complains loudly if we attach without
supplying a thread name.

Task-number: QTBUG-35441

Change-Id: I962d613be0db50f3ca9a4c786b36003f31c9db14
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
bb10
Christian Strømme 2014-02-28 17:09:27 +01:00 committed by The Qt Project
parent b94493e6c8
commit 5f6cbfb070
1 changed files with 10 additions and 1 deletions

View File

@ -44,6 +44,7 @@
#include <QtCore/qthreadstorage.h>
#include <QtCore/qhash.h>
#include <QtCore/qstring.h>
#include <QtCore/QThread>
QT_BEGIN_NAMESPACE
@ -52,6 +53,11 @@ static inline QString keyBase()
return QStringLiteral("%1%2%3");
}
static inline QByteArray threadBaseName()
{
return QByteArrayLiteral("QtThread-");
}
static QString qt_convertJString(jstring string)
{
QJNIEnvironmentPrivate env;
@ -179,7 +185,10 @@ QJNIEnvironmentPrivate::QJNIEnvironmentPrivate()
{
JavaVM *vm = QtAndroidPrivate::javaVM();
if (vm->GetEnv((void**)&jniEnv, JNI_VERSION_1_6) == JNI_EDETACHED) {
if (vm->AttachCurrentThread(&jniEnv, 0) != JNI_OK)
const qulonglong id = reinterpret_cast<qulonglong>(QThread::currentThreadId());
const QByteArray threadName = threadBaseName() + QByteArray::number(id);
JavaVMAttachArgs args = { JNI_VERSION_1_6, threadName, Q_NULLPTR };
if (vm->AttachCurrentThread(&jniEnv, &args) != JNI_OK)
return;
}