Add better version checks for accessibility
We would spam the debug output on devices with api < 16 with some warnings that the super class a11y delegate could not be found and others. Instead check the runtime version before trying to load the JNI code and only load the delegate if api is new enough. Change-Id: I52286cb99924b034b9b58c53566f15030939b0c9 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
This commit is contained in:
parent
54ed14d5c6
commit
2c11a492fb
@ -117,6 +117,7 @@ public class QtSurface extends SurfaceView implements SurfaceHolder.Callback
|
||||
|
||||
// Initialize Accessibility
|
||||
// The accessibility code depends on android API level 16, so dynamically resolve it
|
||||
if (android.os.Build.VERSION.SDK_INT >= 16) {
|
||||
try {
|
||||
final String a11yDelegateClassName = "org.qtproject.qt5.android.accessibility.QtAccessibilityDelegate";
|
||||
Class<?> qtDelegateClass = Class.forName(a11yDelegateClassName);
|
||||
@ -134,6 +135,7 @@ public class QtSurface extends SurfaceView implements SurfaceHolder.Callback
|
||||
Log.w("Qt A11y", "Unknown exception: " + e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean dispatchHoverEvent(MotionEvent event) {
|
||||
// Always attempt to dispatch hover events to accessibility first.
|
||||
|
@ -834,6 +834,15 @@ 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 {
|
||||
@ -856,11 +865,17 @@ Q_DECL_EXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void */*reserved*/)
|
||||
|| !QtAndroidInput::registerNatives(env)
|
||||
|| !QtAndroidClipboard::registerNatives(env)
|
||||
|| !QtAndroidMenu::registerNatives(env)
|
||||
|| !QtAndroidAccessibility::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…
Reference in New Issue
Block a user