diff options
5 files changed, 123 insertions, 0 deletions
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index 8d5129465b0e..68fd7c71bcfd 100644 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -4469,4 +4469,10 @@ TODO: b/170470621 - remove once we can have multiple Internal displays in DMS as well as a notification from DisplayStateManager. --> <string-array name="config_internalFoldedPhysicalDisplayIds" translatable="false" /> + + <!-- Aspect ratio of task level letterboxing. Values <= 1.0 will be ignored. + Note: Activity min/max aspect ratio restrictions will still be respected by the + activity-level letterboxing (size-compat mode). Therefore this override can control the + maximum screen area that can be occupied by the app in the letterbox mode. --> + <item name="config_taskLetterboxAspectRatio" format="float" type="dimen">0.0</item> </resources> diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index 697f7e0e898a..8daa6539ff64 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -4084,4 +4084,6 @@ <java-symbol type="dimen" name="controls_thumbnail_image_max_height" /> <java-symbol type="dimen" name="controls_thumbnail_image_max_width" /> + + <java-symbol type="dimen" name="config_taskLetterboxAspectRatio" /> </resources> diff --git a/services/core/java/com/android/server/wm/Task.java b/services/core/java/com/android/server/wm/Task.java index ef1a3be70f9d..5bc5b47d5cfc 100644 --- a/services/core/java/com/android/server/wm/Task.java +++ b/services/core/java/com/android/server/wm/Task.java @@ -149,6 +149,7 @@ import static com.android.server.wm.WindowContainerChildProto.TASK; import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STACK; import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TASK_MOVEMENT; import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; +import static com.android.server.wm.WindowManagerService.MIN_TASK_LETTERBOX_ASPECT_RATIO; import static com.android.server.wm.WindowManagerService.dipToPixel; import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_BEFORE_ANIM; @@ -2960,6 +2961,14 @@ class Task extends WindowContainer<WindowContainer> { } } + // Override from config_letterboxAspectRatio or via ADB with set-letterbox-aspect-ratio. + final float letterboxAspectRatioOverride = mWmService.getTaskLetterboxAspectRatio(); + // Activity min/max aspect ratio restrictions will be respected by the activity-level + // letterboxing (size-compat mode). Therefore this override can control the maximum screen + // area that can be occupied by the app in the letterbox mode. + aspect = letterboxAspectRatioOverride > MIN_TASK_LETTERBOX_ASPECT_RATIO + ? letterboxAspectRatioOverride : aspect; + if (forcedOrientation == ORIENTATION_LANDSCAPE) { final int height = (int) Math.rint(parentWidth / aspect); final int top = parentBounds.centerY() - height / 2; diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java index 81fe4748a932..f5d1ccd6a58f 100644 --- a/services/core/java/com/android/server/wm/WindowManagerService.java +++ b/services/core/java/com/android/server/wm/WindowManagerService.java @@ -454,6 +454,14 @@ public class WindowManagerService extends IWindowManager.Stub /** System UI can create more window context... */ private static final int SYSTEM_UI_MULTIPLIER = 2; + /** + * Override of task letterbox aspect ratio that is set via ADB with + * set-task-letterbox-aspect-ratio or via {@link + * com.android.internal.R.dimen.config_taskLetterboxAspectRatio} will be ignored + * if it is <= this value. + */ + static final float MIN_TASK_LETTERBOX_ASPECT_RATIO = 1.0f; + final WindowManagerConstants mConstants; final WindowTracing mWindowTracing; @@ -962,6 +970,10 @@ public class WindowManagerService extends IWindowManager.Stub private boolean mAnimationsDisabled = false; boolean mPointerLocationEnabled = false; + // Aspect ratio of task level letterboxing, values <= MIN_TASK_LETTERBOX_ASPECT_RATIO will be + // ignored. + private float mTaskLetterboxAspectRatio; + final InputManagerService mInputManager; final DisplayManagerInternal mDisplayManagerInternal; final DisplayManager mDisplayManager; @@ -1190,6 +1202,8 @@ public class WindowManagerService extends IWindowManager.Stub com.android.internal.R.bool.config_perDisplayFocusEnabled); mAssistantOnTopOfDream = context.getResources().getBoolean( com.android.internal.R.bool.config_assistantOnTopOfDream); + mTaskLetterboxAspectRatio = context.getResources().getFloat( + com.android.internal.R.dimen.config_taskLetterboxAspectRatio); mInputManager = inputManager; // Must be before createDisplayContentLocked. mDisplayManagerInternal = LocalServices.getService(DisplayManagerInternal.class); @@ -3755,6 +3769,53 @@ public class WindowManagerService extends IWindowManager.Stub } } + /** + * Overrides the aspect ratio of task level letterboxing. If given value is <= {@link + * #MIN_TASK_LETTERBOX_ASPECT_RATIO}, both it and a value of {@link + * com.android.internal.R.dimen.config_taskLetterboxAspectRatio} will be ignored and + * the framework implementation will be used to determine the aspect ratio. + */ + void setTaskLetterboxAspectRatio(float aspectRatio) { + final long origId = Binder.clearCallingIdentity(); + try { + synchronized (mGlobalLock) { + mTaskLetterboxAspectRatio = aspectRatio; + } + } finally { + Binder.restoreCallingIdentity(origId); + } + } + + /** + * Resets the aspect ratio of task level letterboxing to {@link + * com.android.internal.R.dimen.config_taskLetterboxAspectRatio}. + */ + void resetTaskLetterboxAspectRatio() { + final long origId = Binder.clearCallingIdentity(); + try { + synchronized (mGlobalLock) { + mTaskLetterboxAspectRatio = mContext.getResources().getFloat( + com.android.internal.R.dimen.config_taskLetterboxAspectRatio); + } + } finally { + Binder.restoreCallingIdentity(origId); + } + } + + /** + * Gets the aspect ratio of task level letterboxing. + */ + float getTaskLetterboxAspectRatio() { + final long origId = Binder.clearCallingIdentity(); + try { + synchronized (mGlobalLock) { + return mTaskLetterboxAspectRatio; + } + } finally { + Binder.restoreCallingIdentity(origId); + } + } + @Override public void setIgnoreOrientationRequest(int displayId, boolean ignoreOrientationRequest) { mAtmInternal.enforceCallerIsRecentsOrHasPermission( diff --git a/services/core/java/com/android/server/wm/WindowManagerShellCommand.java b/services/core/java/com/android/server/wm/WindowManagerShellCommand.java index fe312e6b4c46..a3a9c1ce9219 100644 --- a/services/core/java/com/android/server/wm/WindowManagerShellCommand.java +++ b/services/core/java/com/android/server/wm/WindowManagerShellCommand.java @@ -111,6 +111,10 @@ public class WindowManagerShellCommand extends ShellCommand { return runGetIgnoreOrientationRequest(pw); case "dump-visible-window-views": return runDumpVisibleWindowViews(pw); + case "set-task-letterbox-aspect-ratio": + return runSetTaskLetterboxAspectRatio(pw); + case "get-task-letterbox-aspect-ratio": + return runGetTaskLetterboxAspectRatio(pw); case "reset": return runReset(pw); default: @@ -509,6 +513,38 @@ public class WindowManagerShellCommand extends ShellCommand { return 0; } + private int runSetTaskLetterboxAspectRatio(PrintWriter pw) throws RemoteException { + final float aspectRatio; + try { + String arg = getNextArgRequired(); + if ("reset".equals(arg)) { + mInternal.resetTaskLetterboxAspectRatio(); + return 0; + } + aspectRatio = Float.parseFloat(arg); + } catch (NumberFormatException e) { + getErrPrintWriter().println("Error: bad aspect ratio format " + e); + return -1; + } catch (IllegalArgumentException e) { + getErrPrintWriter().println( + "Error: 'reset' or aspect ratio should be provided as an argument " + e); + return -1; + } + + mInternal.setTaskLetterboxAspectRatio(aspectRatio); + return 0; + } + + private int runGetTaskLetterboxAspectRatio(PrintWriter pw) throws RemoteException { + final float aspectRatio = mInternal.getTaskLetterboxAspectRatio(); + if (aspectRatio <= WindowManagerService.MIN_TASK_LETTERBOX_ASPECT_RATIO) { + pw.println("Letterbox aspect ratio is not set"); + } else { + pw.println("Letterbox aspect ratio is " + aspectRatio); + } + return 0; + } + private int runReset(PrintWriter pw) throws RemoteException { int displayId = getDisplayId(getNextArg()); @@ -533,6 +569,9 @@ public class WindowManagerShellCommand extends ShellCommand { // set-ignore-orientation-request mInterface.setIgnoreOrientationRequest(displayId, false /* ignoreOrientationRequest */); + // set-task-letterbox-aspect-ratio + mInternal.resetTaskLetterboxAspectRatio(); + pw.println("Reset all settings for displayId=" + displayId); return 0; } @@ -563,6 +602,12 @@ public class WindowManagerShellCommand extends ShellCommand { pw.println(" set-ignore-orientation-request [-d DISPLAY_ID] [true|1|false|0]"); pw.println(" get-ignore-orientation-request [-d DISPLAY_ID] "); pw.println(" If app requested orientation should be ignored."); + pw.println(" set-task-letterbox-aspect-ratio [reset|aspectRatio]"); + pw.println(" get-task-letterbox-aspect-ratio"); + pw.println(" Aspect ratio of task level letterboxing. If aspectRatio <= " + + WindowManagerService.MIN_TASK_LETTERBOX_ASPECT_RATIO); + pw.println(" both it and R.dimen.config_taskLetterboxAspectRatio will be ignored"); + pw.println(" and framework implementation will be used to determine aspect ratio."); pw.println(" reset [-d DISPLAY_ID]"); pw.println(" Reset all override settings."); if (!IS_USER) { |