From 9af423f3c348775f73ad713090ee8a2351c1b20d Mon Sep 17 00:00:00 2001 From: Massimo Carli Date: Mon, 17 Apr 2023 18:01:21 +0000 Subject: [PATCH] Fix Transparent bounds from client layout If the client uses a layout with LayoutParams.WRAP_CONTENT it might happen that the requeste size for the translucent activity is smaller than the one provided by core through Configuration. In that case we need to adjust the bounds we use for cropping when applying rounded corners. Fix: 278525445 Test: Run atest WmTests:LetterboxUiControllerTest Change-Id: Ife63ab94c7fb7dd27d3d6c773806d9c49cd8eae8 --- .../server/wm/LetterboxUiController.java | 10 ++++++++ .../server/wm/LetterboxUiControllerTest.java | 23 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/services/core/java/com/android/server/wm/LetterboxUiController.java b/services/core/java/com/android/server/wm/LetterboxUiController.java index 0288e4bbb26ec..657d90abcb0bb 100644 --- a/services/core/java/com/android/server/wm/LetterboxUiController.java +++ b/services/core/java/com/android/server/wm/LetterboxUiController.java @@ -1280,6 +1280,16 @@ final class LetterboxUiController { final Rect cropBounds = new Rect(mActivityRecord.getBounds()); + // In case of translucent activities we check if the requested size is different from + // the size provided using inherited bounds. In that case we decide to not apply rounded + // corners because we assume the specific layout would. This is the case when the layout + // of the translucent activity uses only a part of all the bounds because of the use of + // LayoutParams.WRAP_CONTENT. + if (hasInheritedLetterboxBehavior() && (cropBounds.width() != mainWindow.mRequestedWidth + || cropBounds.height() != mainWindow.mRequestedHeight)) { + return null; + } + // It is important to call {@link #adjustBoundsIfNeeded} before {@link cropBounds.offsetTo} // because taskbar bounds used in {@link #adjustBoundsIfNeeded} // are in screen coordinates diff --git a/services/tests/wmtests/src/com/android/server/wm/LetterboxUiControllerTest.java b/services/tests/wmtests/src/com/android/server/wm/LetterboxUiControllerTest.java index 03c93e9760593..0cad695cd75c2 100644 --- a/services/tests/wmtests/src/com/android/server/wm/LetterboxUiControllerTest.java +++ b/services/tests/wmtests/src/com/android/server/wm/LetterboxUiControllerTest.java @@ -452,6 +452,29 @@ public class LetterboxUiControllerTest extends WindowTestsBase { assertTrue(mController.shouldForceRotateForCameraCompat()); } + @Test + public void testGetCropBoundsIfNeeded_handleCropForTransparentActivityBasedOnOpaqueBounds() { + final InsetsSource taskbar = new InsetsSource(/*id=*/ 0, + WindowInsets.Type.navigationBars()); + taskbar.setInsetsRoundedCornerFrame(true); + final WindowState mainWindow = mockForGetCropBoundsAndRoundedCorners(taskbar); + final Rect opaqueBounds = new Rect(0, 0, 500, 300); + doReturn(opaqueBounds).when(mActivity).getBounds(); + // Activity is translucent + spyOn(mActivity.mLetterboxUiController); + doReturn(true).when(mActivity.mLetterboxUiController).hasInheritedLetterboxBehavior(); + + // Makes requested sizes different + mainWindow.mRequestedWidth = opaqueBounds.width() - 1; + mainWindow.mRequestedHeight = opaqueBounds.height() - 1; + assertNull(mActivity.mLetterboxUiController.getCropBoundsIfNeeded(mainWindow)); + + // Makes requested sizes equals + mainWindow.mRequestedWidth = opaqueBounds.width(); + mainWindow.mRequestedHeight = opaqueBounds.height(); + assertNotNull(mActivity.mLetterboxUiController.getCropBoundsIfNeeded(mainWindow)); + } + @Test public void testGetCropBoundsIfNeeded_noCrop() { final InsetsSource taskbar = new InsetsSource(/*id=*/ 0,