Android: fix tst_android::testFullScreenDimensions()
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ø <tor.arne.vestbo@qt.io> (cherry picked from commit 50603fddc535179ee02379a8807fe5cb104e0aae)
This commit is contained in:
parent
8e2209f3b0
commit
a0897816f8
@ -19,10 +19,12 @@ using namespace Qt::StringLiterals;
|
|||||||
|
|
||||||
Q_DECLARE_JNI_CLASS(Display, "android/view/Display")
|
Q_DECLARE_JNI_CLASS(Display, "android/view/Display")
|
||||||
Q_DECLARE_JNI_CLASS(Point, "android/graphics/Point")
|
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(View, "android/view/View")
|
||||||
Q_DECLARE_JNI_CLASS(Window, "android/view/Window")
|
Q_DECLARE_JNI_CLASS(Window, "android/view/Window")
|
||||||
Q_DECLARE_JNI_CLASS(WindowInsets, "android/view/WindowInsets")
|
Q_DECLARE_JNI_CLASS(WindowInsets, "android/view/WindowInsets")
|
||||||
Q_DECLARE_JNI_CLASS(WindowManager, "android/view/WindowManager")
|
Q_DECLARE_JNI_CLASS(WindowManager, "android/view/WindowManager")
|
||||||
|
Q_DECLARE_JNI_CLASS(WindowMetrics, "android/view/WindowMetrics")
|
||||||
|
|
||||||
class tst_Android : public QObject
|
class tst_Android : public QObject
|
||||||
{
|
{
|
||||||
@ -222,9 +224,19 @@ void tst_Android::testFullScreenDimensions()
|
|||||||
QJniObject display = windowManager.callMethod<QtJniTypes::Display>("getDefaultDisplay");
|
QJniObject display = windowManager.callMethod<QtJniTypes::Display>("getDefaultDisplay");
|
||||||
QVERIFY(display.isValid());
|
QVERIFY(display.isValid());
|
||||||
|
|
||||||
QtJniTypes::Point appSize{};
|
QSize appSize;
|
||||||
QVERIFY(appSize.isValid());
|
if (QNativeInterface::QAndroidApplication::sdkVersion() >= __ANDROID_API_R__) {
|
||||||
display.callMethod<void>("getSize", appSize);
|
using namespace QtJniTypes;
|
||||||
|
auto windowMetrics = windowManager.callMethod<WindowMetrics>("getCurrentWindowMetrics");
|
||||||
|
auto bounds = windowMetrics.callMethod<Rect>("getBounds");
|
||||||
|
appSize.setWidth(bounds.callMethod<int>("width"));
|
||||||
|
appSize.setHeight(bounds.callMethod<int>("height"));
|
||||||
|
} else {
|
||||||
|
QtJniTypes::Point jappSize{};
|
||||||
|
display.callMethod<void>("getSize", jappSize);
|
||||||
|
appSize.setWidth(jappSize.getField<jint>("x"));
|
||||||
|
appSize.setHeight(jappSize.getField<jint>("y"));
|
||||||
|
}
|
||||||
|
|
||||||
QtJniTypes::Point realSize{};
|
QtJniTypes::Point realSize{};
|
||||||
QVERIFY(realSize.isValid());
|
QVERIFY(realSize.isValid());
|
||||||
@ -254,10 +266,10 @@ void tst_Android::testFullScreenDimensions()
|
|||||||
int insetBottom = insets.callMethod<jint>("getSystemWindowInsetBottom");
|
int insetBottom = insets.callMethod<jint>("getSystemWindowInsetBottom");
|
||||||
int insetsHeight = insetTop + insetBottom;
|
int insetsHeight = insetTop + insetBottom;
|
||||||
|
|
||||||
int expectedWidth = appSize.getField<jint>("x") - insetsWidth;
|
int expectedWidth = appSize.width() - insetsWidth;
|
||||||
QTRY_COMPARE(screen->availableGeometry().width(), expectedWidth);
|
QTRY_COMPARE(screen->availableGeometry().width(), expectedWidth);
|
||||||
|
|
||||||
int expectedHeight = appSize.getField<jint>("y") - insetsHeight;
|
int expectedHeight = appSize.height() - insetsHeight;
|
||||||
QTRY_COMPARE(screen->availableGeometry().height(), expectedHeight);
|
QTRY_COMPARE(screen->availableGeometry().height(), expectedHeight);
|
||||||
|
|
||||||
QTRY_COMPARE(screen->geometry().width(), realSize.getField<jint>("x"));
|
QTRY_COMPARE(screen->geometry().width(), realSize.getField<jint>("x"));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user