From 398454ff68a31cbb4d4543b2e2ac24f66cf65db6 Mon Sep 17 00:00:00 2001 From: Mariia Sandrikova Date: Fri, 27 Nov 2020 11:26:02 +0000 Subject: [PATCH] Apply insets to max bounds instead of parent bounds in letterbox mode. Applying insets directly to parent bounds don't always work because parent bounds may not be equal to max bounds. For example, this happens when "Developer options > Display Cutout > Hide" option is selected or in One-handed mode. Fix: 174211584 Test: atest WMShellUnitTests Change-Id: I7415629aab39e5aac6c038f27494b87667ef84d9 --- .../shell/letterbox/LetterboxTaskListener.java | 16 +++++++--------- .../letterbox/LetterboxTaskListenerTest.java | 14 +++++++++++++- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/letterbox/LetterboxTaskListener.java b/libs/WindowManager/Shell/src/com/android/wm/shell/letterbox/LetterboxTaskListener.java index 061d3f86b6699..6e87f131ed95a 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/letterbox/LetterboxTaskListener.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/letterbox/LetterboxTaskListener.java @@ -107,6 +107,7 @@ public class LetterboxTaskListener implements ShellTaskOrganizer.TaskListener { transaction.setWindowCrop(leash, crop); } + // TODO(b/173440321): Correct presentation of letterboxed activities in One-handed mode. private void resolveTaskPositionAndCrop( ActivityManager.RunningTaskInfo taskInfo, Point positionInParent, @@ -125,15 +126,18 @@ public class LetterboxTaskListener implements ShellTaskOrganizer.TaskListener { final Rect activityBounds = taskInfo.letterboxActivityBounds; Insets insets = getInsets(); + Rect displayBoundsWithInsets = + new Rect(mWindowManager.getMaximumWindowMetrics().getBounds()); + displayBoundsWithInsets.inset(insets); Rect taskBoundsWithInsets = new Rect(taskBounds); - applyInsets(taskBoundsWithInsets, insets, taskInfo.parentBounds); + taskBoundsWithInsets.intersect(displayBoundsWithInsets); Rect activityBoundsWithInsets = new Rect(activityBounds); - applyInsets(activityBoundsWithInsets, insets, taskInfo.parentBounds); + activityBoundsWithInsets.intersect(displayBoundsWithInsets); Rect parentBoundsWithInsets = new Rect(parentBounds); - applyInsets(parentBoundsWithInsets, insets, parentBounds); + parentBoundsWithInsets.intersect(displayBoundsWithInsets); // Crop need to be in the task coordinates. crop.set(activityBoundsWithInsets); @@ -217,10 +221,4 @@ public class LetterboxTaskListener implements ShellTaskOrganizer.TaskListener { | WindowInsets.Type.displayCutout()); } - private void applyInsets(Rect innerBounds, Insets insets, Rect outerBounds) { - Rect outerBoundsWithInsets = new Rect(outerBounds); - outerBoundsWithInsets.inset(insets); - innerBounds.intersect(outerBoundsWithInsets); - } - } diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/letterbox/LetterboxTaskListenerTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/letterbox/LetterboxTaskListenerTest.java index 0f719afd08b39..fc0e20b553d37 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/letterbox/LetterboxTaskListenerTest.java +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/letterbox/LetterboxTaskListenerTest.java @@ -96,6 +96,7 @@ public final class LetterboxTaskListenerTest extends ShellTestCase { mLetterboxTaskListener.onTaskAppeared( createTaskInfo( /* taskId */ 1, + /* maxBounds= */ new Rect(0, 0, 200, 100), // equal to parent bounds /* parentBounds */ new Rect(0, 0, 200, 100), /* activityBounds */ new Rect(75, 0, 125, 75), /* taskBounds */ new Rect(50, 0, 125, 100)), @@ -109,6 +110,7 @@ public final class LetterboxTaskListenerTest extends ShellTestCase { mLetterboxTaskListener.onTaskInfoChanged( createTaskInfo( /* taskId */ 1, + /* maxBounds= */ new Rect(0, 0, 200, 100), // equal to parent bounds /* parentBounds */ new Rect(0, 0, 200, 100), // Activity is offset by 25 to the left /* activityBounds */ new Rect(50, 0, 100, 75), @@ -130,6 +132,7 @@ public final class LetterboxTaskListenerTest extends ShellTestCase { mLetterboxTaskListener.onTaskAppeared( createTaskInfo( /* taskId */ 1, + /* maxBounds= */ new Rect(0, 0, 200, 100), // equal to parent bounds /* parentBounds */ new Rect(0, 0, 200, 100), /* activityBounds */ new Rect(150, 0, 200, 75), /* taskBounds */ new Rect(125, 0, 200, 100)), @@ -150,6 +153,7 @@ public final class LetterboxTaskListenerTest extends ShellTestCase { mLetterboxTaskListener.onTaskAppeared( createTaskInfo( /* taskId */ 1, + /* maxBounds= */ new Rect(0, 0, 200, 100), // equal to parent bounds /* parentBounds */ new Rect(0, 0, 200, 100), /* activityBounds */ new Rect(150, 0, 200, 75), /* taskBounds */ new Rect(125, 0, 200, 100)), @@ -170,6 +174,7 @@ public final class LetterboxTaskListenerTest extends ShellTestCase { mLetterboxTaskListener.onTaskAppeared( createTaskInfo( /* taskId */ 1, + /* maxBounds= */ new Rect(0, 0, 200, 100), // equal to parent bounds /* parentBounds */ new Rect(0, 0, 200, 100), /* activityBounds */ new Rect(50, 0, 100, 75), /* taskBounds */ new Rect(25, 0, 100, 100)), @@ -190,6 +195,7 @@ public final class LetterboxTaskListenerTest extends ShellTestCase { mLetterboxTaskListener.onTaskAppeared( createTaskInfo( /* taskId */ 1, + /* maxBounds= */ new Rect(0, 0, 100, 150), // equal to parent bounds /* parentBounds */ new Rect(0, 0, 100, 150), /* activityBounds */ new Rect(0, 75, 50, 125), /* taskBounds */ new Rect(0, 50, 100, 125)), @@ -210,6 +216,7 @@ public final class LetterboxTaskListenerTest extends ShellTestCase { mLetterboxTaskListener.onTaskAppeared( createTaskInfo( /* taskId */ 1, + /* maxBounds= */ new Rect(0, 0, 100, 150), // equal to parent bounds /* parentBounds */ new Rect(0, 0, 100, 150), /* activityBounds */ new Rect(0, 75, 50, 125), /* taskBounds */ new Rect(0, 50, 100, 125)), @@ -230,6 +237,7 @@ public final class LetterboxTaskListenerTest extends ShellTestCase { mLetterboxTaskListener.onTaskAppeared( createTaskInfo( /* taskId */ 1, + /* maxBounds= */ new Rect(0, 0, 100, 150), // equal to parent bounds /* parentBounds */ new Rect(0, 0, 100, 150), /* activityBounds */ new Rect(0, 75, 50, 125), /* taskBounds */ new Rect(0, 50, 100, 125)), @@ -250,6 +258,7 @@ public final class LetterboxTaskListenerTest extends ShellTestCase { mLetterboxTaskListener.onTaskAppeared( createTaskInfo( /* taskId */ 1, + /* maxBounds= */ new Rect(0, 0, 200, 125), // equal to parent bounds /* parentBounds */ new Rect(0, 0, 200, 125), /* activityBounds */ new Rect(15, 0, 175, 120), /* taskBounds */ new Rect(0, 0, 100, 125)), // equal to parent bounds @@ -272,6 +281,7 @@ public final class LetterboxTaskListenerTest extends ShellTestCase { mLetterboxTaskListener.onTaskAppeared( createTaskInfo( /* taskId */ 1, + /* maxBounds= */ new Rect(0, 0, 100, 150), /* parentBounds */ new Rect(0, 75, 100, 225), /* activityBounds */ new Rect(25, 75, 75, 125), /* taskBounds */ new Rect(0, 75, 100, 125)), @@ -285,7 +295,7 @@ public final class LetterboxTaskListenerTest extends ShellTestCase { public void testOnTaskAppeared_calledSecondTimeWithSameTaskId_throwsException() { setWindowBoundsAndInsets(new Rect(), Insets.NONE); RunningTaskInfo taskInfo = - createTaskInfo(/* taskId */ 1, new Rect(), new Rect(), new Rect()); + createTaskInfo(/* taskId */ 1, new Rect(), new Rect(), new Rect(), new Rect()); mLetterboxTaskListener.onTaskAppeared(taskInfo, mLeash); mLetterboxTaskListener.onTaskAppeared(taskInfo, mLeash); } @@ -306,11 +316,13 @@ public final class LetterboxTaskListenerTest extends ShellTestCase { private static RunningTaskInfo createTaskInfo( int taskId, + final Rect maxBounds, final Rect parentBounds, final Rect activityBounds, final Rect taskBounds) { RunningTaskInfo taskInfo = new RunningTaskInfo(); taskInfo.taskId = taskId; + taskInfo.configuration.windowConfiguration.setMaxBounds(maxBounds); taskInfo.parentBounds = parentBounds; taskInfo.configuration.windowConfiguration.setBounds(taskBounds); taskInfo.letterboxActivityBounds = Rect.copyOrNull(activityBounds);