Android: Remove AttachedJNIEnv class.
The JNI environment should be managed by QJNIEnvironmentPrivate directly or through QJNIObjectPrivate. There is also a clear difference between calls coming from or going into Java code. Calls coming from Java already comes with the 'right' environment and in most cases no extra considerations or set-up is needed. Change-Id: I92d935ddfb70332041869185d5a92438930ff9b9 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>
This commit is contained in:
parent
078380df1e
commit
0df7ab1cab
@ -80,7 +80,6 @@ static jmethodID m_createBitmapMethodID = Q_NULLPTR;
|
|||||||
static jobject m_ARGB_8888_BitmapConfigValue = Q_NULLPTR;
|
static jobject m_ARGB_8888_BitmapConfigValue = Q_NULLPTR;
|
||||||
static jobject m_RGB_565_BitmapConfigValue = Q_NULLPTR;
|
static jobject m_RGB_565_BitmapConfigValue = Q_NULLPTR;
|
||||||
|
|
||||||
jmethodID m_setFullScreenMethodID = Q_NULLPTR;
|
|
||||||
static bool m_statusBarShowing = true;
|
static bool m_statusBarShowing = true;
|
||||||
|
|
||||||
static jclass m_bitmapDrawableClass = Q_NULLPTR;
|
static jclass m_bitmapDrawableClass = Q_NULLPTR;
|
||||||
@ -182,13 +181,7 @@ namespace QtAndroid
|
|||||||
if (m_statusBarShowing)
|
if (m_statusBarShowing)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QtAndroid::AttachedJNIEnv env;
|
QJNIObjectPrivate::callStaticMethod<void>(m_applicationClass, "setFullScreen", "(Z)V", false);
|
||||||
if (!env.jniEnv) {
|
|
||||||
qWarning("Failed to get JNI Environment.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
env.jniEnv->CallStaticVoidMethod(m_applicationClass, m_setFullScreenMethodID, false);
|
|
||||||
m_statusBarShowing = true;
|
m_statusBarShowing = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,13 +190,7 @@ namespace QtAndroid
|
|||||||
if (!m_statusBarShowing)
|
if (!m_statusBarShowing)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QtAndroid::AttachedJNIEnv env;
|
QJNIObjectPrivate::callStaticMethod<void>(m_applicationClass, "setFullScreen", "(Z)V", true);
|
||||||
if (!env.jniEnv) {
|
|
||||||
qWarning("Failed to get JNI Environment.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
env.jniEnv->CallStaticVoidMethod(m_applicationClass, m_setFullScreenMethodID, true);
|
|
||||||
m_statusBarShowing = false;
|
m_statusBarShowing = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -453,16 +440,9 @@ static void *startMainMethod(void */*data*/)
|
|||||||
if (res < 0)
|
if (res < 0)
|
||||||
qWarning() << "dlclose failed:" << dlerror();
|
qWarning() << "dlclose failed:" << dlerror();
|
||||||
}
|
}
|
||||||
m_mainLibraryHnd = Q_NULLPTR;
|
|
||||||
m_main = Q_NULLPTR;
|
|
||||||
QtAndroid::AttachedJNIEnv env;
|
|
||||||
if (!env.jniEnv)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if (m_applicationClass) {
|
if (m_applicationClass)
|
||||||
jmethodID quitApp = env.jniEnv->GetStaticMethodID(m_applicationClass, "quitApp", "()V");
|
QJNIObjectPrivate::callStaticMethod<void>(m_applicationClass, "quitApp", "()V");
|
||||||
env.jniEnv->CallStaticVoidMethod(m_applicationClass, quitApp);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -723,7 +703,6 @@ static int registerNatives(JNIEnv *env)
|
|||||||
jclass clazz;
|
jclass clazz;
|
||||||
FIND_AND_CHECK_CLASS("org/qtproject/qt5/android/QtNative");
|
FIND_AND_CHECK_CLASS("org/qtproject/qt5/android/QtNative");
|
||||||
m_applicationClass = static_cast<jclass>(env->NewGlobalRef(clazz));
|
m_applicationClass = static_cast<jclass>(env->NewGlobalRef(clazz));
|
||||||
GET_AND_CHECK_STATIC_METHOD(m_setFullScreenMethodID, m_applicationClass, "setFullScreen", "(Z)V");
|
|
||||||
|
|
||||||
if (env->RegisterNatives(m_applicationClass, methods, sizeof(methods) / sizeof(methods[0])) < 0) {
|
if (env->RegisterNatives(m_applicationClass, methods, sizeof(methods) / sizeof(methods[0])) < 0) {
|
||||||
__android_log_print(ANDROID_LOG_FATAL,"Qt", "RegisterNatives failed");
|
__android_log_print(ANDROID_LOG_FATAL,"Qt", "RegisterNatives failed");
|
||||||
|
@ -85,29 +85,6 @@ namespace QtAndroid
|
|||||||
jobject createBitmap(int width, int height, QImage::Format format, JNIEnv *env);
|
jobject createBitmap(int width, int height, QImage::Format format, JNIEnv *env);
|
||||||
jobject createBitmapDrawable(jobject bitmap, JNIEnv *env = 0);
|
jobject createBitmapDrawable(jobject bitmap, JNIEnv *env = 0);
|
||||||
|
|
||||||
struct AttachedJNIEnv
|
|
||||||
{
|
|
||||||
AttachedJNIEnv()
|
|
||||||
{
|
|
||||||
attached = false;
|
|
||||||
if (QtAndroid::javaVM()->GetEnv((void**)&jniEnv, JNI_VERSION_1_6) < 0) {
|
|
||||||
if (QtAndroid::javaVM()->AttachCurrentThread(&jniEnv, NULL) < 0) {
|
|
||||||
__android_log_print(ANDROID_LOG_ERROR, "Qt", "AttachCurrentThread failed");
|
|
||||||
jniEnv = Q_NULLPTR;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
attached = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
~AttachedJNIEnv()
|
|
||||||
{
|
|
||||||
if (attached)
|
|
||||||
QtAndroid::javaVM()->DetachCurrentThread();
|
|
||||||
}
|
|
||||||
bool attached;
|
|
||||||
JNIEnv *jniEnv;
|
|
||||||
};
|
|
||||||
const char *classErrorMsgFmt();
|
const char *classErrorMsgFmt();
|
||||||
const char *methodErrorMsgFmt();
|
const char *methodErrorMsgFmt();
|
||||||
const char *qtTagText();
|
const char *qtTagText();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user