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: Tinja Paavoseppä <tinja.paavoseppa@qt.io>
This commit is contained in:
Tinja Paavoseppä 2024-02-22 15:08:06 +02:00
parent 44ee8df9c7
commit 0533f7c075

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;
}
}
}