godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.34k stars 21.06k forks source link

Android screen orientation `sensor_portrait` doesn't work #55212

Open madmiraal opened 2 years ago

madmiraal commented 2 years ago

Godot version

3.4.stable

System information

Android

Issue description

Screen orientation sensor_portrait should keep the game in portrait mode, but automatically rotate the screen depending on whether or not the Android device is upside-down. However, currently, when the device is upside-down, the screen does not rotate.

Note: Both sensor_landscape and sensor modes work as expected. In sensor_landscape mode, the game will stay in landscape mode and automatically rotate depending on whether the device is rotated to the left or right. In sensor mode the game screen will rotate depending on the orientation of the device. If the device is upside-down, it will rotate as it should do in sensor_portrait mode.

Steps to reproduce

Minimal reproduction project

ScreenOrientation.zip

Calinou commented 2 years ago

Is there an OS-level switch that would prevent upside-down orientation? I noticed that I can't make any app go upside-down on my OnePlus 6 running Android 11. I tested this with the camera app, the gallery app, Google Play, F-Droid, Bromite, and more. The apps can go to landscape mode based on sensor orientation, but they will never go upside down even if I flip the device and keep it this way for 10 seconds.

madmiraal commented 2 years ago

Is there an OS-level switch that would prevent upside-down orientation?

No, because it works fine when setting screen orientation mode to sensor, which allows all four orientations. The MRP allows you to change the screen orientation mode in game, which allows you to confirm this.

madmiraal commented 2 years ago

I've tested this on a standard Android app with the same results.

Godot's sensor_portrait mode maps to Android's userPortrait mode (i.e. allows the user to control whether or not rotations happen), and Godot's sensor mode maps to Android's fullUser mode: https://github.com/godotengine/godot/blob/c0403b2ebe2d76903cef5d2ca7650e6b6d7ac8b2/platform/android/java/lib/src/org/godotengine/godot/GodotIO.java#L264-L288 From the Android docs: Mode Description
"sensorPortrait" Portrait orientation, but can be either normal or reverse portrait based on the device sensor. The sensor is used even if the user has locked sensor-based rotation. Added in API level 9.
"userPortrait" Portrait orientation, but can be either normal or reverse portrait based on the device sensor and the user's preference. Added in API level 18.
"sensor" The orientation is determined by the device orientation sensor. The orientation of the display depends on how the user is holding the device; it changes when the user rotates the device. Some devices, though, will not rotate to all four possible orientations, by default. To allow all four orientations, use "fullSensor" The sensor is used even if the user locked sensor-based rotation.
"fullSensor" The orientation is determined by the device orientation sensor for any of the 4 orientations. This is similar to "sensor" except this allows any of the 4 possible screen orientations, regardless of what the device will normally do (for example, some devices won't normally use reverse portrait or reverse landscape, but this enables those). Added in API level 9.

So, there are some devices that "will not rotate to all four possible orientations". Although this is overridden in fullSensor mode, it is not (as one would expect) overridden in sensorPortrait or userPortrait mode. This makes both sensorPortrait and userPortrait mode the same as portrait mode on some devices.

This has issue has previously been reported upstream (more than once): https://issuetracker.google.com/issues?q=sensorportrait, but the issues keep being closed without being fixed. So, I've created a new issue: https://issuetracker.google.com/issues/207403736

Leif-W commented 1 year ago

VLC has been doing the right thing for years. I've set the OS setting to locked portrait mode. VLC opens in portrait mode but plays videos in landscape mode. I've set VLC to last locked orientation. This makes the video flip landscape or reverse landscape only, based upon the sensor. Godot only loads in one of the landscape modes, despite OS being locked to portrait mode. This is half right, but Godot ignores the sensor and refuses to rotate 180° to reverse the landscape orientation. My preferred phone orientation makes this landscape orientation upside down. I can unlock the OS portrait mode to get Godot to rotate, but then every other app (VLC, browser, Termux, etc.) loads in the undesired landscape mode. Regardless of the contended upstream bug, the fact that VLC has behaved correctly clearly indicates that Godot is doing something incorrectly.

boruok commented 1 year ago

any workaround?