diff options
author | Lauri Pohjanheimo <lauri.pohjanheimo@qt.io> | 2024-03-11 13:33:05 +0200 |
---|---|---|
committer | Lauri Pohjanheimo <lauri.pohjanheimo@qt.io> | 2024-04-12 02:20:51 +0300 |
commit | 6209079c7a34c4656e6e110ae5194feb19f6134a (patch) | |
tree | aa1c602abb2f44d23dbc0be850e5fe02e768d502 /tests/auto/corelib/platform/android/tst_android.cpp | |
parent | 19258608e9ea02043ce9b53d4a9c99700ce49c1b (diff) |
Android: fix 180 degree orientation issue
On android documentation orientation changes are sent via
onConfigurationChanged callback. Previous implementation
based orientation detection to onSizeChanged callback.
That callback is not called when orientation turns 180 degrees.
i.e. between landscape and inverted landscape.
This fix adds detection to on onConfigurationChanged to catch
those cases.
Fixes: QTBUG-118887
Fixes: QTBUG-118236
Pick-to: 6.7 6.5
Change-Id: Ie2f81798de97e460de839f7ebfde9a9efa25909f
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
Diffstat (limited to 'tests/auto/corelib/platform/android/tst_android.cpp')
-rw-r--r-- | tests/auto/corelib/platform/android/tst_android.cpp | 40 |
1 files changed, 35 insertions, 5 deletions
diff --git a/tests/auto/corelib/platform/android/tst_android.cpp b/tests/auto/corelib/platform/android/tst_android.cpp index e03308a883..07b939969c 100644 --- a/tests/auto/corelib/platform/android/tst_android.cpp +++ b/tests/auto/corelib/platform/android/tst_android.cpp @@ -312,11 +312,39 @@ void tst_Android::orientationChange_data() const QSize portraitSize = QGuiApplication::primaryScreen()->size(); const QSize landscapeSize = QSize(portraitSize.height(), portraitSize.width()); + // Rotations without 180 degree or inverted portrait, assuming that the device is in portrait + // position. These are ok for Android 6(API 23), 8 (API 27) and 14 (API 34) QTest::newRow("InvertedLandscape") << 8 << Qt::InvertedLandscapeOrientation << landscapeSize; - QTest::newRow("InvertedPortrait") << 9 << Qt::InvertedPortraitOrientation << portraitSize; - QTest::newRow("Landscape") << 0 << Qt::LandscapeOrientation << landscapeSize; - // Leave Portrait till the end QTest::newRow("Portrait") << 1 << Qt::PortraitOrientation << portraitSize; + QTest::newRow("Landscape") << 0 << Qt::LandscapeOrientation << landscapeSize; + QTest::newRow("Portrait2") << 1 << Qt::PortraitOrientation << portraitSize; + + // Rotations over inverted portrait doing only 90 degree turns. + QTest::newRow("InvertedLandscape2") << 8 << Qt::InvertedLandscapeOrientation << landscapeSize; + QTest::newRow("InvertedPortrait") << 9 << Qt::InvertedPortraitOrientation << portraitSize; + QTest::newRow("Landscape2") << 0 << Qt::LandscapeOrientation << landscapeSize; + QTest::newRow("InvertedPortrait2") << 9 << Qt::InvertedPortraitOrientation << portraitSize; + QTest::newRow("InvertedLandscape3") << 8 << Qt::InvertedLandscapeOrientation << landscapeSize; + + // Rotations with 180 degree turns. + // Android 6 (API23) Does not understand these transitions. + if (QNativeInterface::QAndroidApplication::sdkVersion() > __ANDROID_API_M__) { + QTest::newRow("Landscape3") << 0 << Qt::LandscapeOrientation << landscapeSize; + QTest::newRow("InvertedLandscape4") + << 8 << Qt::InvertedLandscapeOrientation << landscapeSize; + QTest::newRow("Portrait3") << 1 << Qt::PortraitOrientation << portraitSize; + } else { + qWarning() << "180 degree turn rotation test cases are not run on Android 6 (API 23) and " + "below."; + } + // Android 8 (API 27) does not understand portrait-'inverted portrait'-portrait transition. + if (QNativeInterface::QAndroidApplication::sdkVersion() > __ANDROID_API_O_MR1__) { + QTest::newRow("InvertedPortrait3") << 9 << Qt::InvertedPortraitOrientation << portraitSize; + QTest::newRow("Portrait4") << 1 << Qt::PortraitOrientation << portraitSize; + } else { + qWarning() << "Portrait-'Inverted portrait'-Portrait rotation test cases are not run on " + "Android 8 (API 27) and below."; + } } void tst_Android::orientationChange() @@ -329,11 +357,13 @@ void tst_Android::orientationChange() QWidget widget; widget.show(); + QScreen *screen = QGuiApplication::primaryScreen(); + QSignalSpy orientationSpy(screen, SIGNAL(orientationChanged(Qt::ScreenOrientation))); + auto context = QNativeInterface::QAndroidApplication::context(); context.callMethod<void>("setRequestedOrientation", nativeOrientation); - QScreen *screen = QGuiApplication::primaryScreen(); - QSignalSpy orientationSpy(screen, SIGNAL(orientationChanged(Qt::ScreenOrientation))); + orientationSpy.wait(); QTRY_COMPARE(screen->orientation(), expected); QCOMPARE(orientationSpy.size(), 1); QCOMPARE(screen->size(), screenSize); |