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:
parent
e3d32bce79
commit
8fa91217bc
@ -47,6 +47,7 @@
|
||||
#include "qwindow.h"
|
||||
#include "qrect.h"
|
||||
#include "QtGui/qaccessible.h"
|
||||
#include <QtCore/private/qjnihelpers_p.h>
|
||||
|
||||
#include "qdebug.h"
|
||||
|
||||
@ -207,7 +208,7 @@ if (!clazz) { \
|
||||
if (desc.isEmpty())
|
||||
desc = iface->text(QAccessible::Description);
|
||||
if (QAccessibleTextInterface *textIface = iface->textInterface()) {
|
||||
if (textIface->selectionCount() > 0) {
|
||||
if (m_setTextSelectionMethodID && textIface->selectionCount() > 0) {
|
||||
int startSelection;
|
||||
int endSelection;
|
||||
textIface->selection(0, &startSelection, &endSelection);
|
||||
@ -259,12 +260,15 @@ if (!clazz) { \
|
||||
|
||||
bool registerNatives(JNIEnv *env)
|
||||
{
|
||||
if (QtAndroidPrivate::androidSdkVersion() < 16)
|
||||
return true; // We need API level 16 or higher
|
||||
|
||||
jclass clazz;
|
||||
FIND_AND_CHECK_CLASS("org/qtproject/qt5/android/accessibility/QtNativeAccessibility");
|
||||
jclass appClass = static_cast<jclass>(env->NewGlobalRef(clazz));
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -277,9 +281,12 @@ if (!clazz) { \
|
||||
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_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");
|
||||
|
||||
if (QtAndroidPrivate::androidSdkVersion() >= 18) {
|
||||
GET_AND_CHECK_STATIC_METHOD(m_setTextSelectionMethodID, nodeInfoClass, "setTextSelection", "(II)V");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -423,6 +423,7 @@ namespace QtAndroid
|
||||
m_destroySurfaceMethodID,
|
||||
surfaceId);
|
||||
}
|
||||
|
||||
} // namespace QtAndroid
|
||||
|
||||
|
||||
@ -743,15 +744,6 @@ static int registerNatives(JNIEnv *env)
|
||||
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*/)
|
||||
{
|
||||
typedef union {
|
||||
@ -774,17 +766,12 @@ Q_DECL_EXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void */*reserved*/)
|
||||
|| !QtAndroidInput::registerNatives(env)
|
||||
|| !QtAndroidClipboard::registerNatives(env)
|
||||
|| !QtAndroidMenu::registerNatives(env)
|
||||
|| !QtAndroidAccessibility::registerNatives(env)
|
||||
|| !QtAndroidDialogHelpers::registerNatives(env)) {
|
||||
__android_log_print(ANDROID_LOG_FATAL, "Qt", "registerNatives failed");
|
||||
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;
|
||||
return JNI_VERSION_1_4;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user