Android: Synchronize window creation in QtEmbeddedDelegate

Qt window loading is initiated either when the QtView is attached
to its Android window, or when the Android QPA plugin has been loaded
and is ready, depending on the order. Since the window attachment
happens in the Android UI thread, and the Android QPA plugin callback
happens in Qt thread, add synchronized block to make sure the execution
stays ordered.

Fixes: QTBUG-122626
Change-Id: Id476032f02aa8990432a02f62b6bf6237a17e7ac
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
(cherry picked from commit d899cdb3a4dc9eb1ad489f7541244110e7e80f61)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Tinja Paavoseppä 2024-02-22 15:08:06 +02:00 committed by Qt Cherry-pick Bot
parent a2d67a2671
commit 589529e728

View File

@ -28,6 +28,7 @@ class QtEmbeddedDelegate extends QtActivityDelegateBase implements QtNative.AppS
private QtView m_view;
private long m_rootWindowRef = 0L;
private QtNative.ApplicationStateDetails m_stateDetails;
private boolean m_windowLoaded = false;
private static native void createRootWindow(View rootView);
static native void deleteWindow(long windowReference);
@ -91,16 +92,18 @@ class QtEmbeddedDelegate extends QtActivityDelegateBase implements QtNative.AppS
@Override
public void onAppStateDetailsChanged(QtNative.ApplicationStateDetails details) {
m_stateDetails = details;
if (m_stateDetails.nativePluginIntegrationReady) {
QtNative.runAction(() -> {
DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
QtDisplayManager.setApplicationDisplayMetrics(m_activity,
metrics.widthPixels,
metrics.heightPixels);
if (m_view != null)
createRootWindow(m_view);
});
synchronized (this) {
m_stateDetails = details;
if (m_stateDetails.nativePluginIntegrationReady) {
QtNative.runAction(() -> {
DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
QtDisplayManager.setApplicationDisplayMetrics(m_activity,
metrics.widthPixels,
metrics.heightPixels);
});
createRootWindow();
}
}
}
@ -130,8 +133,9 @@ class QtEmbeddedDelegate extends QtActivityDelegateBase implements QtNative.AppS
public void queueLoadWindow()
{
if (m_stateDetails.nativePluginIntegrationReady) {
createRootWindow(m_view);
synchronized (this) {
if (m_stateDetails.nativePluginIntegrationReady)
createRootWindow();
}
}
@ -150,4 +154,11 @@ class QtEmbeddedDelegate extends QtActivityDelegateBase implements QtNative.AppS
deleteWindow(m_rootWindowRef);
m_rootWindowRef = 0L;
}
private void createRootWindow() {
if (m_view != null && !m_windowLoaded) {
createRootWindow(m_view);
m_windowLoaded = true;
}
}
}