From fbcf72fa1b228a2885733dbba11e645893f01493 Mon Sep 17 00:00:00 2001 From: Pablo Gamito Date: Fri, 10 Feb 2023 15:57:51 +0000 Subject: [PATCH] Update condition for when to show letterbox Makes sure we show the letterbox even during the period a window is requesting to be redrawn because of a layout change (i.e. orientation change) or for any other reason, if the window's associated surface is still visible. This avoids seeing a letterbox flicker when this happens. Bug: 256052489 Bug: 266635069 Test: Launch the dialer for a phone call or Google wallet app on a large screen device and make sure the letterbox doesn't flicker on launch. Change-Id: I7911ddc45c1ff839cc22be09caa5cc7ddc022d45 --- .../com/android/server/wm/LetterboxUiController.java | 9 +++------ .../com/android/server/wm/LetterboxUiControllerTest.java | 1 + .../src/com/android/server/wm/SizeCompatTests.java | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/services/core/java/com/android/server/wm/LetterboxUiController.java b/services/core/java/com/android/server/wm/LetterboxUiController.java index d2e8ad1f66b9e..80cad3a69a75f 100644 --- a/services/core/java/com/android/server/wm/LetterboxUiController.java +++ b/services/core/java/com/android/server/wm/LetterboxUiController.java @@ -1001,7 +1001,7 @@ final class LetterboxUiController { @VisibleForTesting boolean shouldShowLetterboxUi(WindowState mainWindow) { - return isSurfaceReadyAndVisible(mainWindow) && mainWindow.areAppWindowBoundsLetterboxed() + return isSurfaceVisible(mainWindow) && mainWindow.areAppWindowBoundsLetterboxed() // Check for FLAG_SHOW_WALLPAPER explicitly instead of using // WindowContainer#showWallpaper because the later will return true when this // activity is using blurred wallpaper for letterbox background. @@ -1009,11 +1009,8 @@ final class LetterboxUiController { } @VisibleForTesting - boolean isSurfaceReadyAndVisible(WindowState mainWindow) { - boolean surfaceReady = mainWindow.isDrawn() // Regular case - // Waiting for relayoutWindow to call preserveSurface - || mainWindow.isDragResizeChanged(); - return surfaceReady && (mActivityRecord.isVisible() + boolean isSurfaceVisible(WindowState mainWindow) { + return mainWindow.isOnScreen() && (mActivityRecord.isVisible() || mActivityRecord.isVisibleRequested()); } 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 0d20f1772d0b8..656c07b1acee0 100644 --- a/services/tests/wmtests/src/com/android/server/wm/LetterboxUiControllerTest.java +++ b/services/tests/wmtests/src/com/android/server/wm/LetterboxUiControllerTest.java @@ -494,6 +494,7 @@ public class LetterboxUiControllerTest extends WindowTestsBase { doReturn(insets).when(mainWindow).getInsetsState(); doReturn(attrs).when(mainWindow).getAttrs(); doReturn(true).when(mainWindow).isDrawn(); + doReturn(true).when(mainWindow).isOnScreen(); doReturn(false).when(mainWindow).isLetterboxedForDisplayCutout(); doReturn(true).when(mainWindow).areAppWindowBoundsLetterboxed(); doReturn(true).when(mLetterboxConfiguration).isLetterboxActivityCornersRounded(); diff --git a/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java b/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java index c4269137199e7..7f42cdbdbe635 100644 --- a/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java @@ -502,7 +502,7 @@ public class SizeCompatTests extends WindowTestsBase { spyOn(mActivity.mLetterboxUiController); doReturn(true).when(mActivity.mLetterboxUiController) - .isSurfaceReadyAndVisible(any()); + .isSurfaceVisible(any()); assertTrue(mActivity.mLetterboxUiController.shouldShowLetterboxUi( mActivity.findMainWindow()));