From 1e5fe4bebf680efcc2df0edff45a9f19400d9a4e Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Fri, 27 Nov 2020 00:01:21 +0800 Subject: [PATCH] Make the visibility of rotated insets up-to-date Otherwise the client app may not perform insets animation because of a stale state that is no different from the previous one. Bug: 170416293 Test: DisplayContentTests#testApplyTopFixedRotationTransform Change-Id: I6f89ba08d4996da0cf30fb18bab331678dc74622 --- .../com/android/server/wm/DisplayContent.java | 22 +++++++++++++++++++ .../server/wm/InsetsStateController.java | 5 +---- .../server/wm/DisplayContentTests.java | 11 ++++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java index 4133ea2b2a7b9..178d87e6e6f73 100644 --- a/services/core/java/com/android/server/wm/DisplayContent.java +++ b/services/core/java/com/android/server/wm/DisplayContent.java @@ -1674,6 +1674,28 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp } } + void notifyInsetsChanged(Consumer dispatchInsetsChanged) { + if (mFixedRotationLaunchingApp != null) { + // The insets state of fixed rotation app is a rotated copy. Make sure the visibilities + // of insets sources are consistent with the latest state. + final InsetsState rotatedState = + mFixedRotationLaunchingApp.getFixedRotationTransformInsetsState(); + if (rotatedState != null) { + final InsetsState state = mInsetsStateController.getRawInsetsState(); + for (int i = 0; i < InsetsState.SIZE; i++) { + final InsetsSource source = state.peekSource(i); + if (source != null) { + rotatedState.setSourceVisible(i, source.isVisible()); + } + } + } + } + forAllWindows(dispatchInsetsChanged, true /* traverseTopToBottom */); + if (mRemoteInsetsControlTarget != null) { + mRemoteInsetsControlTarget.notifyInsetsChanged(); + } + } + /** * Update rotation of the display. * diff --git a/services/core/java/com/android/server/wm/InsetsStateController.java b/services/core/java/com/android/server/wm/InsetsStateController.java index 9d70fd771f313..752d6b4fc9082 100644 --- a/services/core/java/com/android/server/wm/InsetsStateController.java +++ b/services/core/java/com/android/server/wm/InsetsStateController.java @@ -496,10 +496,7 @@ class InsetsStateController { } void notifyInsetsChanged() { - mDisplayContent.forAllWindows(mDispatchInsetsChanged, true /* traverseTopToBottom */); - if (mDisplayContent.mRemoteInsetsControlTarget != null) { - mDisplayContent.mRemoteInsetsControlTarget.notifyInsetsChanged(); - } + mDisplayContent.notifyInsetsChanged(mDispatchInsetsChanged); } void dump(String prefix, PrintWriter pw) { diff --git a/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java b/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java index d9217188582fb..64065e96b0f2b 100644 --- a/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java @@ -1202,6 +1202,17 @@ public class DisplayContentTests extends WindowTestsBase { assertTrue(mNavBarWindow.getParent().isAnimating(WindowContainer.AnimationFlags.PARENTS, ANIMATION_TYPE_FIXED_TRANSFORM)); + // If the visibility of insets state is changed, the rotated state should be updated too. + final InsetsState rotatedState = app.getFixedRotationTransformInsetsState(); + final InsetsState state = mDisplayContent.getInsetsStateController().getRawInsetsState(); + assertEquals(state.getSource(ITYPE_STATUS_BAR).isVisible(), + rotatedState.getSource(ITYPE_STATUS_BAR).isVisible()); + state.getSource(ITYPE_STATUS_BAR).setVisible( + !rotatedState.getSource(ITYPE_STATUS_BAR).isVisible()); + mDisplayContent.getInsetsStateController().notifyInsetsChanged(); + assertEquals(state.getSource(ITYPE_STATUS_BAR).isVisible(), + rotatedState.getSource(ITYPE_STATUS_BAR).isVisible()); + final Rect outFrame = new Rect(); final Rect outInsets = new Rect(); final Rect outStableInsets = new Rect();