From aff384b616a1c280a407cfeff4dcb0d839f5c85d Mon Sep 17 00:00:00 2001 From: Graciela Wissen Putri Date: Fri, 24 Mar 2023 10:28:11 +0000 Subject: [PATCH] Add opt-out property for orientation loop override Fix: 274925661 Test: atest WmTests:LetterboxUiControllerTest Change-Id: Ia24d9de88243ad0fa1eec0e9632570fb58ff6c3f --- core/java/android/view/WindowManager.java | 36 +++++++++++++++++++ .../server/wm/LetterboxUiController.java | 16 ++++++++- .../server/wm/LetterboxUiControllerTest.java | 34 ++++++++++++++++++ 3 files changed, 85 insertions(+), 1 deletion(-) diff --git a/core/java/android/view/WindowManager.java b/core/java/android/view/WindowManager.java index a01c8328b37ce..033f7263bfc6e 100644 --- a/core/java/android/view/WindowManager.java +++ b/core/java/android/view/WindowManager.java @@ -852,6 +852,42 @@ public interface WindowManager extends ViewManager { String PROPERTY_COMPAT_IGNORE_REQUESTED_ORIENTATION = "android.window.PROPERTY_COMPAT_IGNORE_REQUESTED_ORIENTATION"; + /** + * Application level {@link android.content.pm.PackageManager.Property PackageManager.Property} + * for an app to inform the system that the app can be opted-out from the compatibility + * treatment that avoids {@link android.app.Activity#setRequestedOrientation} loops. The loop + * can be trigerred by ignoreRequestedOrientation display setting enabled on the device or + * by the landscape natural orientation of the device. + * + *

The system could ignore {@link android.app.Activity#setRequestedOrientation} + * call from an app if both of the following conditions are true: + *

+ * + *

Setting this property to {@code false} informs the system that the app must be + * opted-out from the compatibility treatment even if the device manufacturer has opted the app + * into the treatment. + * + *

Not setting this property at all, or setting this property to {@code true} has no effect. + * + *

Syntax: + *

+     * <application>
+     *   <property
+     *     android:name=
+     *       "android.window.PROPERTY_COMPAT_IGNORE_ORIENTATION_REQUEST_WHEN_LOOP_DETECTED"
+     *     android:value="false"/>
+     * </application>
+     * 
+ * + * @hide + */ + // TODO(b/274924641): Make this public API. + String PROPERTY_COMPAT_IGNORE_ORIENTATION_REQUEST_WHEN_LOOP_DETECTED = + "android.window.PROPERTY_COMPAT_IGNORE_ORIENTATION_REQUEST_WHEN_LOOP_DETECTED"; + /** * Application level {@link android.content.pm.PackageManager.Property PackageManager * .Property} for an app to inform the system that it needs to be opted-out from the diff --git a/services/core/java/com/android/server/wm/LetterboxUiController.java b/services/core/java/com/android/server/wm/LetterboxUiController.java index 4d0c7683d6218..0c1923e1d28b8 100644 --- a/services/core/java/com/android/server/wm/LetterboxUiController.java +++ b/services/core/java/com/android/server/wm/LetterboxUiController.java @@ -50,6 +50,7 @@ import static android.view.WindowManager.PROPERTY_CAMERA_COMPAT_ENABLE_REFRESH_V import static android.view.WindowManager.PROPERTY_COMPAT_ALLOW_DISPLAY_ORIENTATION_OVERRIDE; import static android.view.WindowManager.PROPERTY_COMPAT_ALLOW_ORIENTATION_OVERRIDE; import static android.view.WindowManager.PROPERTY_COMPAT_ENABLE_FAKE_FOCUS; +import static android.view.WindowManager.PROPERTY_COMPAT_IGNORE_ORIENTATION_REQUEST_WHEN_LOOP_DETECTED; import static android.view.WindowManager.PROPERTY_COMPAT_IGNORE_REQUESTED_ORIENTATION; import static com.android.internal.util.FrameworkStatsLog.APP_COMPAT_STATE_CHANGED__LETTERBOX_POSITION__BOTTOM; @@ -237,6 +238,9 @@ final class LetterboxUiController { @Nullable private final Boolean mBooleanPropertyIgnoreRequestedOrientation; + @Nullable + private final Boolean mBooleanPropertyIgnoreOrientationRequestWhenLoopDetected; + @Nullable private final Boolean mBooleanPropertyFakeFocus; @@ -254,6 +258,10 @@ final class LetterboxUiController { readComponentProperty(packageManager, mActivityRecord.packageName, mLetterboxConfiguration::isPolicyForIgnoringRequestedOrientationEnabled, PROPERTY_COMPAT_IGNORE_REQUESTED_ORIENTATION); + mBooleanPropertyIgnoreOrientationRequestWhenLoopDetected = + readComponentProperty(packageManager, mActivityRecord.packageName, + mLetterboxConfiguration::isPolicyForIgnoringRequestedOrientationEnabled, + PROPERTY_COMPAT_IGNORE_ORIENTATION_REQUEST_WHEN_LOOP_DETECTED); mBooleanPropertyFakeFocus = readComponentProperty(packageManager, mActivityRecord.packageName, mLetterboxConfiguration::isCompatFakeFocusEnabled, @@ -432,6 +440,8 @@ final class LetterboxUiController { * *

This treatment is enabled when the following conditions are met: *