summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Pablo Gamito <pablogamito@google.com> 2023-04-05 13:18:11 +0000
committer Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> 2023-04-05 13:18:11 +0000
commit33a3e4135a1fc9ced1c0240ad7bc6288b73bb723 (patch)
treed5c4fa9c8f80d61fc6fb9b1492f7168e1bf782de
parent4237cb28938a5216777a92d8e3a1898c87636eff (diff)
parent9a283c1e16cfb3538fa5546c2c14f799ede4e98d (diff)
Merge "Prevent flicker on orientation change while starting" into tm-qpr-dev am: ceebff7531 am: 9a283c1e16
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/22335688 Change-Id: Ifeafba301f255940d9b6548e0c8473c2912768f8 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--services/core/java/com/android/server/wm/ActivityRecord.java4
-rw-r--r--services/core/java/com/android/server/wm/LetterboxUiController.java32
-rw-r--r--services/core/java/com/android/server/wm/WindowState.java13
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/LetterboxUiControllerTest.java4
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java2
5 files changed, 44 insertions, 11 deletions
diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java
index 5f56923e2f53..8346e7c83190 100644
--- a/services/core/java/com/android/server/wm/ActivityRecord.java
+++ b/services/core/java/com/android/server/wm/ActivityRecord.java
@@ -4068,7 +4068,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
}
void finishRelaunching() {
- mLetterboxUiController.setRelauchingAfterRequestedOrientationChanged(false);
+ mLetterboxUiController.setRelaunchingAfterRequestedOrientationChanged(false);
mTaskSupervisor.getActivityMetricsLogger().notifyActivityRelaunched(this);
if (mPendingRelaunchCount > 0) {
@@ -9500,7 +9500,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
mRelaunchReason = RELAUNCH_REASON_NONE;
}
if (isRequestedOrientationChanged) {
- mLetterboxUiController.setRelauchingAfterRequestedOrientationChanged(true);
+ mLetterboxUiController.setRelaunchingAfterRequestedOrientationChanged(true);
}
if (mState == PAUSING) {
// A little annoying: we are waiting for this activity to finish pausing. Let's not
diff --git a/services/core/java/com/android/server/wm/LetterboxUiController.java b/services/core/java/com/android/server/wm/LetterboxUiController.java
index b0c384dcd7ac..18d92f316618 100644
--- a/services/core/java/com/android/server/wm/LetterboxUiController.java
+++ b/services/core/java/com/android/server/wm/LetterboxUiController.java
@@ -237,7 +237,9 @@ final class LetterboxUiController {
@Nullable
private final Boolean mBooleanPropertyFakeFocus;
- private boolean mIsRelauchingAfterRequestedOrientationChanged;
+ private boolean mIsRelaunchingAfterRequestedOrientationChanged;
+
+ private boolean mLastShouldShowLetterboxUi;
private boolean mDoubleTapEvent;
@@ -387,7 +389,7 @@ final class LetterboxUiController {
::isPolicyForIgnoringRequestedOrientationEnabled,
mIsOverrideEnableCompatIgnoreRequestedOrientationEnabled,
mBooleanPropertyIgnoreRequestedOrientation)) {
- if (mIsRelauchingAfterRequestedOrientationChanged) {
+ if (mIsRelaunchingAfterRequestedOrientationChanged) {
Slog.w(TAG, "Ignoring orientation update to "
+ screenOrientationToString(requestedOrientation)
+ " due to relaunching after setRequestedOrientation for "
@@ -476,8 +478,8 @@ final class LetterboxUiController {
* Sets whether an activity is relaunching after the app has called {@link
* android.app.Activity#setRequestedOrientation}.
*/
- void setRelauchingAfterRequestedOrientationChanged(boolean isRelaunching) {
- mIsRelauchingAfterRequestedOrientationChanged = isRelaunching;
+ void setRelaunchingAfterRequestedOrientationChanged(boolean isRelaunching) {
+ mIsRelaunchingAfterRequestedOrientationChanged = isRelaunching;
}
/**
@@ -1154,12 +1156,28 @@ final class LetterboxUiController {
@VisibleForTesting
boolean shouldShowLetterboxUi(WindowState mainWindow) {
- return (mActivityRecord.isInLetterboxAnimation() || isSurfaceVisible(mainWindow))
+ if (mIsRelaunchingAfterRequestedOrientationChanged || !isSurfaceReadyToShow(mainWindow)) {
+ return mLastShouldShowLetterboxUi;
+ }
+
+ final boolean shouldShowLetterboxUi =
+ (mActivityRecord.isInLetterboxAnimation() || 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.
&& (mainWindow.getAttrs().flags & FLAG_SHOW_WALLPAPER) == 0;
+
+ mLastShouldShowLetterboxUi = shouldShowLetterboxUi;
+
+ return shouldShowLetterboxUi;
+ }
+
+ @VisibleForTesting
+ boolean isSurfaceReadyToShow(WindowState mainWindow) {
+ return mainWindow.isDrawn() // Regular case
+ // Waiting for relayoutWindow to call preserveSurface
+ || mainWindow.isDragResizeChanged();
}
@VisibleForTesting
@@ -1297,6 +1315,10 @@ final class LetterboxUiController {
return null;
}
+ boolean getIsRelaunchingAfterRequestedOrientationChanged() {
+ return mIsRelaunchingAfterRequestedOrientationChanged;
+ }
+
private void adjustBoundsForTaskbar(final WindowState mainWindow, final Rect bounds) {
// Rounded corners should be displayed above the taskbar. When taskbar is hidden,
// an insets frame is equal to a navigation bar which shouldn't affect position of
diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java
index 23934e00408a..736f489cf99d 100644
--- a/services/core/java/com/android/server/wm/WindowState.java
+++ b/services/core/java/com/android/server/wm/WindowState.java
@@ -5230,8 +5230,17 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
if (surfaceInsetsChanged) {
mLastSurfaceInsets.set(mAttrs.surfaceInsets);
}
- if (surfaceSizeChanged && mWinAnimator.getShown() && !canPlayMoveAnimation()
- && okToDisplay() && mSyncState == SYNC_STATE_NONE) {
+ final boolean surfaceResizedWithoutMoveAnimation = surfaceSizeChanged
+ && mWinAnimator.getShown() && !canPlayMoveAnimation() && okToDisplay()
+ && mSyncState == SYNC_STATE_NONE;
+ final ActivityRecord activityRecord = getActivityRecord();
+ // If this window belongs to an activity that is relaunching due to an orientation
+ // change then delay the position update until it has redrawn to avoid any flickers.
+ final boolean isLetterboxedAndRelaunching = activityRecord != null
+ && activityRecord.areBoundsLetterboxed()
+ && activityRecord.mLetterboxUiController
+ .getIsRelaunchingAfterRequestedOrientationChanged();
+ if (surfaceResizedWithoutMoveAnimation || isLetterboxedAndRelaunching) {
applyWithNextDraw(mSetSurfacePositionConsumer);
} else {
mSetSurfacePositionConsumer.accept(t);
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 12e4825e5f85..2ecde8b8a082 100644
--- a/services/tests/wmtests/src/com/android/server/wm/LetterboxUiControllerTest.java
+++ b/services/tests/wmtests/src/com/android/server/wm/LetterboxUiControllerTest.java
@@ -146,7 +146,7 @@ public class LetterboxUiControllerTest extends WindowTestsBase {
mActivity = setUpActivityWithComponent();
mController = new LetterboxUiController(mWm, mActivity);
prepareActivityThatShouldIgnoreRequestedOrientationDuringRelaunch();
- mController.setRelauchingAfterRequestedOrientationChanged(false);
+ mController.setRelaunchingAfterRequestedOrientationChanged(false);
spyOn(mDisplayContent.mDisplayRotationCompatPolicy);
doReturn(true).when(mDisplayContent.mDisplayRotationCompatPolicy)
@@ -870,7 +870,7 @@ public class LetterboxUiControllerTest extends WindowTestsBase {
private void prepareActivityThatShouldIgnoreRequestedOrientationDuringRelaunch() {
doReturn(true).when(mLetterboxConfiguration)
.isPolicyForIgnoringRequestedOrientationEnabled();
- mController.setRelauchingAfterRequestedOrientationChanged(true);
+ mController.setRelaunchingAfterRequestedOrientationChanged(true);
}
private ActivityRecord setUpActivityWithComponent() {
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 a646d01378aa..e96d1abf9ced 100644
--- a/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java
@@ -813,6 +813,8 @@ public class SizeCompatTests extends WindowTestsBase {
spyOn(mActivity.mLetterboxUiController);
doReturn(true).when(mActivity.mLetterboxUiController)
+ .isSurfaceReadyToShow(any());
+ doReturn(true).when(mActivity.mLetterboxUiController)
.isSurfaceVisible(any());
assertTrue(mActivity.mLetterboxUiController.shouldShowLetterboxUi(