From a0897816f827c1b9ae8f7a6423564d441655d51c Mon Sep 17 00:00:00 2001 From: Assam Boudjelthia Date: Sat, 30 Nov 2024 22:59:07 +0200 Subject: [PATCH] Android: fix tst_android::testFullScreenDimensions() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The test was reporting wrong app size values and then expecting a wrong height after subtracting the system bar heights. This was happening because an older API was still being used, using newer APIs fixes that. Fixes: QTBUG-131338 Pick-to: 6.5 Change-Id: I7306ce62d9c683f84069cc19086a6cd28abf5441 Reviewed-by: Tor Arne Vestbø (cherry picked from commit 50603fddc535179ee02379a8807fe5cb104e0aae) --- .../corelib/platform/android/tst_android.cpp | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/tests/auto/corelib/platform/android/tst_android.cpp b/tests/auto/corelib/platform/android/tst_android.cpp index d6e7ebbc5fa..d6964ce8d08 100644 --- a/tests/auto/corelib/platform/android/tst_android.cpp +++ b/tests/auto/corelib/platform/android/tst_android.cpp @@ -19,10 +19,12 @@ using namespace Qt::StringLiterals; Q_DECLARE_JNI_CLASS(Display, "android/view/Display") Q_DECLARE_JNI_CLASS(Point, "android/graphics/Point") +Q_DECLARE_JNI_CLASS(Rect, "android/graphics/Rect") Q_DECLARE_JNI_CLASS(View, "android/view/View") 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") class tst_Android : public QObject { @@ -222,9 +224,19 @@ void tst_Android::testFullScreenDimensions() QJniObject display = windowManager.callMethod("getDefaultDisplay"); QVERIFY(display.isValid()); - QtJniTypes::Point appSize{}; - QVERIFY(appSize.isValid()); - display.callMethod("getSize", appSize); + QSize appSize; + if (QNativeInterface::QAndroidApplication::sdkVersion() >= __ANDROID_API_R__) { + using namespace QtJniTypes; + auto windowMetrics = windowManager.callMethod("getCurrentWindowMetrics"); + auto bounds = windowMetrics.callMethod("getBounds"); + appSize.setWidth(bounds.callMethod("width")); + appSize.setHeight(bounds.callMethod("height")); + } else { + QtJniTypes::Point jappSize{}; + display.callMethod("getSize", jappSize); + appSize.setWidth(jappSize.getField("x")); + appSize.setHeight(jappSize.getField("y")); + } QtJniTypes::Point realSize{}; QVERIFY(realSize.isValid()); @@ -254,10 +266,10 @@ void tst_Android::testFullScreenDimensions() int insetBottom = insets.callMethod("getSystemWindowInsetBottom"); int insetsHeight = insetTop + insetBottom; - int expectedWidth = appSize.getField("x") - insetsWidth; + int expectedWidth = appSize.width() - insetsWidth; QTRY_COMPARE(screen->availableGeometry().width(), expectedWidth); - int expectedHeight = appSize.getField("y") - insetsHeight; + int expectedHeight = appSize.height() - insetsHeight; QTRY_COMPARE(screen->availableGeometry().height(), expectedHeight); QTRY_COMPARE(screen->geometry().width(), realSize.getField("x"));