Make sure we run gracefully below API level 18

Task-number: QTBUG-39508
Change-Id: I023ba7c50de5c95a5514658797125e22016a6543
Reviewed-by: Yoann Lopes <yoann.lopes@digia.com>
Reviewed-by: Christian Stromme <christian.stromme@digia.com>
This commit is contained in:
Jan Arve Saether 2014-06-06 14:59:53 +02:00 committed by The Qt Project
parent e3d32bce79
commit 8fa91217bc
2 changed files with 12 additions and 18 deletions

View File

@ -47,6 +47,7 @@
#include "qwindow.h" #include "qwindow.h"
#include "qrect.h" #include "qrect.h"
#include "QtGui/qaccessible.h" #include "QtGui/qaccessible.h"
#include <QtCore/private/qjnihelpers_p.h>
#include "qdebug.h" #include "qdebug.h"
@ -207,7 +208,7 @@ if (!clazz) { \
if (desc.isEmpty()) if (desc.isEmpty())
desc = iface->text(QAccessible::Description); desc = iface->text(QAccessible::Description);
if (QAccessibleTextInterface *textIface = iface->textInterface()) { if (QAccessibleTextInterface *textIface = iface->textInterface()) {
if (textIface->selectionCount() > 0) { if (m_setTextSelectionMethodID && textIface->selectionCount() > 0) {
int startSelection; int startSelection;
int endSelection; int endSelection;
textIface->selection(0, &startSelection, &endSelection); textIface->selection(0, &startSelection, &endSelection);
@ -259,12 +260,15 @@ if (!clazz) { \
bool registerNatives(JNIEnv *env) bool registerNatives(JNIEnv *env)
{ {
if (QtAndroidPrivate::androidSdkVersion() < 16)
return true; // We need API level 16 or higher
jclass clazz; jclass clazz;
FIND_AND_CHECK_CLASS("org/qtproject/qt5/android/accessibility/QtNativeAccessibility"); FIND_AND_CHECK_CLASS("org/qtproject/qt5/android/accessibility/QtNativeAccessibility");
jclass appClass = static_cast<jclass>(env->NewGlobalRef(clazz)); jclass appClass = static_cast<jclass>(env->NewGlobalRef(clazz));
if (env->RegisterNatives(appClass, methods, sizeof(methods) / sizeof(methods[0])) < 0) { if (env->RegisterNatives(appClass, methods, sizeof(methods) / sizeof(methods[0])) < 0) {
__android_log_print(ANDROID_LOG_FATAL,"Qt", "RegisterNatives failed"); __android_log_print(ANDROID_LOG_FATAL,"Qt A11y", "RegisterNatives failed");
return false; return false;
} }
@ -277,9 +281,12 @@ if (!clazz) { \
GET_AND_CHECK_STATIC_METHOD(m_setEnabledMethodID, nodeInfoClass, "setEnabled", "(Z)V"); GET_AND_CHECK_STATIC_METHOD(m_setEnabledMethodID, nodeInfoClass, "setEnabled", "(Z)V");
GET_AND_CHECK_STATIC_METHOD(m_setFocusableMethodID, nodeInfoClass, "setFocusable", "(Z)V"); GET_AND_CHECK_STATIC_METHOD(m_setFocusableMethodID, nodeInfoClass, "setFocusable", "(Z)V");
GET_AND_CHECK_STATIC_METHOD(m_setFocusedMethodID, nodeInfoClass, "setFocused", "(Z)V"); GET_AND_CHECK_STATIC_METHOD(m_setFocusedMethodID, nodeInfoClass, "setFocused", "(Z)V");
GET_AND_CHECK_STATIC_METHOD(m_setTextSelectionMethodID, nodeInfoClass, "setTextSelection", "(II)V");
GET_AND_CHECK_STATIC_METHOD(m_setVisibleToUserMethodID, nodeInfoClass, "setVisibleToUser", "(Z)V"); GET_AND_CHECK_STATIC_METHOD(m_setVisibleToUserMethodID, nodeInfoClass, "setVisibleToUser", "(Z)V");
if (QtAndroidPrivate::androidSdkVersion() >= 18) {
GET_AND_CHECK_STATIC_METHOD(m_setTextSelectionMethodID, nodeInfoClass, "setTextSelection", "(II)V");
}
return true; return true;
} }
} }

View File

@ -423,6 +423,7 @@ namespace QtAndroid
m_destroySurfaceMethodID, m_destroySurfaceMethodID,
surfaceId); surfaceId);
} }
} // namespace QtAndroid } // namespace QtAndroid
@ -743,15 +744,6 @@ static int registerNatives(JNIEnv *env)
return JNI_TRUE; return JNI_TRUE;
} }
jint androidApiLevel(JNIEnv *env)
{
jclass clazz;
FIND_AND_CHECK_CLASS("android/os/Build$VERSION");
jfieldID fieldId;
GET_AND_CHECK_STATIC_FIELD(fieldId, clazz, "SDK_INT", "I");
return env->GetStaticIntField(clazz, fieldId);
}
Q_DECL_EXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void */*reserved*/) Q_DECL_EXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void */*reserved*/)
{ {
typedef union { typedef union {
@ -774,17 +766,12 @@ Q_DECL_EXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void */*reserved*/)
|| !QtAndroidInput::registerNatives(env) || !QtAndroidInput::registerNatives(env)
|| !QtAndroidClipboard::registerNatives(env) || !QtAndroidClipboard::registerNatives(env)
|| !QtAndroidMenu::registerNatives(env) || !QtAndroidMenu::registerNatives(env)
|| !QtAndroidAccessibility::registerNatives(env)
|| !QtAndroidDialogHelpers::registerNatives(env)) { || !QtAndroidDialogHelpers::registerNatives(env)) {
__android_log_print(ANDROID_LOG_FATAL, "Qt", "registerNatives failed"); __android_log_print(ANDROID_LOG_FATAL, "Qt", "registerNatives failed");
return -1; return -1;
} }
jint apiLevel = androidApiLevel(env);
if (apiLevel >= 16 && !QtAndroidAccessibility::registerNatives(env)) {
__android_log_print(ANDROID_LOG_FATAL, "Qt A11y", "registerNatives failed");
return -1;
}
m_javaVM = vm; m_javaVM = vm;
return JNI_VERSION_1_4; return JNI_VERSION_1_4;
} }