From 4e576a04ada64265e64abc4132a9ea6f06a8ebb6 Mon Sep 17 00:00:00 2001 From: Amonoman <194841561+Amonoman@users.noreply.github.com> Date: Mon, 10 Aug 2026 20:26:50 +0200 Subject: [PATCH] Fix forced portrait orientation on Android app launch (#26873) * Fix forced portrait orientation on app launch MainActivity had no android:screenOrientation set and GameActivity used a fixed landscape value, so the app opened in portrait and the device rotation lock could pin it there. SDLActivity also called setRequestedOrientation() at runtime with a value computed from the window width and height at creation time, which fought the manifest setting and the system rotation lock. Set android:screenOrientation to sensorLandscape on MainActivity and GameActivity, and remove the runtime setRequestedOrientation() call in SDLActivity so the manifest setting is respected and the system rotation lock works as expected. * Remove unused orientation logic from SDLActivity --- .../app/src/main/AndroidManifest.xml | 3 +- .../main/java/org/libsdl/app/SDLActivity.java | 59 ------------------- 2 files changed, 2 insertions(+), 60 deletions(-) diff --git a/src/openrct2-android/app/src/main/AndroidManifest.xml b/src/openrct2-android/app/src/main/AndroidManifest.xml index 79aaaf4f53..91a5b7e13b 100755 --- a/src/openrct2-android/app/src/main/AndroidManifest.xml +++ b/src/openrct2-android/app/src/main/AndroidManifest.xml @@ -23,6 +23,7 @@ @@ -33,7 +34,7 @@ diff --git a/src/openrct2-android/app/src/main/java/org/libsdl/app/SDLActivity.java b/src/openrct2-android/app/src/main/java/org/libsdl/app/SDLActivity.java index a83477bc9f..210f1ebc19 100644 --- a/src/openrct2-android/app/src/main/java/org/libsdl/app/SDLActivity.java +++ b/src/openrct2-android/app/src/main/java/org/libsdl/app/SDLActivity.java @@ -968,65 +968,6 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh */ public void setOrientationBis(int w, int h, boolean resizable, String hint) { - int orientation_landscape = -1; - int orientation_portrait = -1; - - /* If set, hint "explicitly controls which UI orientations are allowed". */ - if (hint.contains("LandscapeRight") && hint.contains("LandscapeLeft")) { - orientation_landscape = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE; - } else if (hint.contains("LandscapeLeft")) { - orientation_landscape = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; - } else if (hint.contains("LandscapeRight")) { - orientation_landscape = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; - } - - /* exact match to 'Portrait' to distinguish with PortraitUpsideDown */ - boolean contains_Portrait = hint.contains("Portrait ") || hint.endsWith("Portrait"); - - if (contains_Portrait && hint.contains("PortraitUpsideDown")) { - orientation_portrait = ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT; - } else if (contains_Portrait) { - orientation_portrait = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; - } else if (hint.contains("PortraitUpsideDown")) { - orientation_portrait = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; - } - - boolean is_landscape_allowed = (orientation_landscape != -1); - boolean is_portrait_allowed = (orientation_portrait != -1); - int req; /* Requested orientation */ - - /* No valid hint, nothing is explicitly allowed */ - if (!is_portrait_allowed && !is_landscape_allowed) { - if (resizable) { - /* All orientations are allowed, respecting user orientation lock setting */ - req = ActivityInfo.SCREEN_ORIENTATION_FULL_USER; - } else { - /* Fixed window and nothing specified. Get orientation from w/h of created window */ - req = (w > h ? ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE : ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT); - } - } else { - /* At least one orientation is allowed */ - if (resizable) { - if (is_portrait_allowed && is_landscape_allowed) { - /* hint allows both landscape and portrait, promote to full user */ - req = ActivityInfo.SCREEN_ORIENTATION_FULL_USER; - } else { - /* Use the only one allowed "orientation" */ - req = (is_landscape_allowed ? orientation_landscape : orientation_portrait); - } - } else { - /* Fixed window and both orientations are allowed. Choose one. */ - if (is_portrait_allowed && is_landscape_allowed) { - req = (w > h ? orientation_landscape : orientation_portrait); - } else { - /* Use the only one allowed "orientation" */ - req = (is_landscape_allowed ? orientation_landscape : orientation_portrait); - } - } - } - - Log.v(TAG, "setOrientation() requestedOrientation=" + req + " width=" + w +" height="+ h +" resizable=" + resizable + " hint=" + hint); - mSingleton.setRequestedOrientation(req); } /**