Android: account for edge-to-edge in tst_android

When running on Android 15 with target sdk set to 35 (Android 15),
the new edge-to-edge behavior is enforced, so the test needs to
account for that and take the full screen size instead of deducting
the insects.

Pick-to: 6.9.0 6.8
Task-number: QTBUG-132311
Change-Id: I178265b02878206ba95c8f83507963ce0bd0d732
Reviewed-by: Petri Virkkunen <petri.virkkunen@qt.io>
(cherry picked from commit 1f3c5f8f9025057f9a7f6b6143f33a529583ab19)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Assam Boudjelthia 2025-03-05 16:03:06 +02:00 committed by Qt Cherry-pick Bot
parent 07f088d340
commit a6e68f636e

View File

@ -25,6 +25,7 @@ Q_DECLARE_JNI_CLASS(Window, "android/view/Window")
Q_DECLARE_JNI_CLASS(WindowInsets, "android/view/WindowInsets")
Q_DECLARE_JNI_CLASS(WindowManager, "android/view/WindowManager")
Q_DECLARE_JNI_CLASS(WindowMetrics, "android/view/WindowMetrics")
Q_DECLARE_JNI_CLASS(ApplicationInfo, "android/content/pm/ApplicationInfo")
class tst_Android : public QObject
{
@ -249,27 +250,41 @@ void tst_Android::testFullScreenDimensions()
// available geometry == app size (system bars visible and removed from available geometry)
widget.showNormal();
QCoreApplication::processEvents();
QJniObject window = activity.callMethod<QtJniTypes::Window>("getWindow");
QVERIFY(window.isValid());
QJniObject decorView = window.callMethod<QtJniTypes::View>("getDecorView");
QVERIFY(decorView.isValid());
int expectedWidth;
int expectedHeight;
QJniObject insets = decorView.callMethod<QtJniTypes::WindowInsets>("getRootWindowInsets");
QVERIFY(insets.isValid());
const auto appContext = activity.callMethod<QtJniTypes::Context>("getApplicationContext");
const auto appInfo = appContext.callMethod<QtJniTypes::ApplicationInfo>("getApplicationInfo");
const int targetSdkVersion = appInfo.getField<jint>("targetSdkVersion");
const int sdkVersion = QNativeInterface::QAndroidApplication::sdkVersion();
int insetRight = insets.callMethod<jint>("getSystemWindowInsetRight");
int insetLeft = insets.callMethod<jint>("getSystemWindowInsetLeft");
int insetsWidth = insetRight + insetLeft;
if (sdkVersion >= __ANDROID_API_V__ && targetSdkVersion >= __ANDROID_API_V__) {
expectedWidth = appSize.width();
expectedHeight = appSize.height();
} else {
QJniObject window = activity.callMethod<QtJniTypes::Window>("getWindow");
QVERIFY(window.isValid());
int insetTop = insets.callMethod<jint>("getSystemWindowInsetTop");
int insetBottom = insets.callMethod<jint>("getSystemWindowInsetBottom");
int insetsHeight = insetTop + insetBottom;
QJniObject decorView = window.callMethod<QtJniTypes::View>("getDecorView");
QVERIFY(decorView.isValid());
auto insets = decorView.callMethod<QtJniTypes::WindowInsets>("getRootWindowInsets");
QVERIFY(insets.isValid());
int insetRight = insets.callMethod<jint>("getSystemWindowInsetRight");
int insetLeft = insets.callMethod<jint>("getSystemWindowInsetLeft");
int insetsWidth = insetRight + insetLeft;
int insetTop = insets.callMethod<jint>("getSystemWindowInsetTop");
int insetBottom = insets.callMethod<jint>("getSystemWindowInsetBottom");
int insetsHeight = insetTop + insetBottom;
expectedWidth = appSize.width() - insetsWidth;
expectedHeight = appSize.height() - insetsHeight;
}
int expectedWidth = appSize.width() - insetsWidth;
QTRY_COMPARE(screen->availableGeometry().width(), expectedWidth);
int expectedHeight = appSize.height() - insetsHeight;
QTRY_COMPARE(screen->availableGeometry().height(), expectedHeight);
QTRY_COMPARE(screen->geometry().width(), realSize.getField<jint>("x"));