Android: Fix android accessibility not being set active

Android platform event of activating accessibility might be received,
before the platform plugin is initialized, thus disregarding the activation
step.

This change saves the activation event state and defers setting it in
platform integration.

Fixes: QTBUG-77320
Pick-to: 5.15 5.12
Change-Id: I06aab76159d1de0e72c0c535dbe80c2858f8e79b
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
Vikke Matikainen 2020-02-24 11:58:03 +02:00 committed by Volker Hilsheimer
parent b9b03165a5
commit b1433a6988
3 changed files with 17 additions and 1 deletions

View File

@ -72,20 +72,28 @@ namespace QtAndroidAccessibility
static jmethodID m_setTextSelectionMethodID = 0;
static jmethodID m_setVisibleToUserMethodID = 0;
static bool m_accessibilityActivated = false;
void initialize()
{
QJNIObjectPrivate::callStaticMethod<void>(QtAndroid::applicationClass(),
"initializeAccessibility");
}
bool isActive()
{
return m_accessibilityActivated;
}
static void setActive(JNIEnv */*env*/, jobject /*thiz*/, jboolean active)
{
QMutexLocker lock(QtAndroid::platformInterfaceMutex());
QAndroidPlatformIntegration *platformIntegration = QtAndroid::androidPlatformIntegration();
m_accessibilityActivated = active;
if (platformIntegration)
platformIntegration->accessibility()->setActive(active);
else
__android_log_print(ANDROID_LOG_WARN, m_qtTag, "Could not activate platform accessibility.");
__android_log_print(ANDROID_LOG_WARN, m_qtTag, "Could not (yet) activate platform accessibility.");
}
QAccessibleInterface *interfaceFromId(jint objectId)

View File

@ -47,6 +47,7 @@ QT_BEGIN_NAMESPACE
namespace QtAndroidAccessibility
{
void initialize();
bool isActive();
bool registerNatives(JNIEnv *env);
}

View File

@ -55,6 +55,7 @@
#include <qpa/qplatformoffscreensurface.h>
#include "androidjnimain.h"
#include "androidjniaccessibility.h"
#include "qabstracteventdispatcher.h"
#include "qandroideventdispatcher.h"
#include "qandroidplatformbackingstore.h"
@ -151,6 +152,12 @@ void QAndroidPlatformNativeInterface::customEvent(QEvent *event)
QMutexLocker lock(QtAndroid::platformInterfaceMutex());
QAndroidPlatformIntegration *api = static_cast<QAndroidPlatformIntegration *>(QGuiApplicationPrivate::platformIntegration());
QtAndroid::setAndroidPlatformIntegration(api);
#ifndef QT_NO_ACCESSIBILITY
// Android accessibility activation event might have been already received
api->accessibility()->setActive(QtAndroidAccessibility::isActive());
#endif // QT_NO_ACCESSIBILITY
api->flushPendingUpdates();
}