diff options
| author | 2020-04-27 18:35:14 +0900 | |
|---|---|---|
| committer | 2020-04-28 11:35:43 +0900 | |
| commit | a07fb93cb06d5c4bcc00df6339eaa4904dfd0714 (patch) | |
| tree | b53f222344826b3a3d4df6e2305fca62fd7d0614 | |
| parent | cf9ab7aa3a1d3e47f8e35fd1b34697a3e2575fd2 (diff) | |
Report caption insets change when layout
This patch let DecorCaptionView report back to it's owner about height
change, instead of let the DecorView query the height. The previous
query points enableCaption() and updateDecorCaptionStatus() cannot
ensure the caption layout is finished and attached to the phone window.
Such that it may return a zero caption insets when it shouldn't be, if
the app do window configuration change handling by restarting.
The layout will ensure the caption insets get set when everything is
ready.
There will be no caption height change when resizing or moving, make
sure the calculated insets always include the caption regardless of the
frame position.
Bug: 154792488
Test: Manuel test with message and settings app.
Test: go/wm-smoke
Test: atest InsetsControllerTest#testCaptionInsetsStateAssemble
Test: atest InsetsSourceTest#testCalculateInsets_caption_resizing
Change-Id: I1728628eccb32b912210a64fe3a1c9cbe9e3b302
4 files changed, 28 insertions, 5 deletions
diff --git a/core/java/android/view/InsetsSource.java b/core/java/android/view/InsetsSource.java index 033ccef3666d..d3f4b1bf9b81 100644 --- a/core/java/android/view/InsetsSource.java +++ b/core/java/android/view/InsetsSource.java @@ -116,15 +116,15 @@ public class InsetsSource implements Parcelable { if (!ignoreVisibility && !mVisible) { return Insets.NONE; } - if (!getIntersection(frame, relativeFrame, mTmpFrame)) { - return Insets.NONE; - } // During drag-move and drag-resizing, the caption insets position may not get updated // before the app frame get updated. To layout the app content correctly during drag events, // we always return the insets with the corresponding height covering the top. if (getType() == ITYPE_CAPTION_BAR) { return Insets.of(0, frame.height(), 0, 0); } + if (!getIntersection(frame, relativeFrame, mTmpFrame)) { + return Insets.NONE; + } // TODO: Currently, non-floating IME always intersects at bottom due to issues with cutout. // However, we should let the policy decide from the server. diff --git a/core/java/com/android/internal/policy/DecorView.java b/core/java/com/android/internal/policy/DecorView.java index f5d38ca37bb7..863659d7c4eb 100644 --- a/core/java/com/android/internal/policy/DecorView.java +++ b/core/java/com/android/internal/policy/DecorView.java @@ -2019,10 +2019,17 @@ public class DecorView extends FrameLayout implements RootViewSurfaceTaker, Wind if (getForeground() != null) { drawableChanged(); } - getWindowInsetsController().setCaptionInsetsHeight(getCaptionInsetsHeight()); } } + /** + * An interface to be called when the caption visibility or height changed, to report the + * corresponding insets change to the InsetsController. + */ + public void notifyCaptionHeightChanged() { + getWindowInsetsController().setCaptionInsetsHeight(getCaptionInsetsHeight()); + } + void setWindow(PhoneWindow phoneWindow) { mWindow = phoneWindow; Context context = getContext(); @@ -2093,7 +2100,6 @@ public class DecorView extends FrameLayout implements RootViewSurfaceTaker, Wind mDecorCaptionView.onConfigurationChanged(displayWindowDecor); enableCaption(displayWindowDecor); } - getWindowInsetsController().setCaptionInsetsHeight(getCaptionInsetsHeight()); } void onResourcesLoaded(LayoutInflater inflater, int layoutResource) { diff --git a/core/java/com/android/internal/widget/DecorCaptionView.java b/core/java/com/android/internal/widget/DecorCaptionView.java index 7a01024ffc36..21021457377a 100644 --- a/core/java/com/android/internal/widget/DecorCaptionView.java +++ b/core/java/com/android/internal/widget/DecorCaptionView.java @@ -30,6 +30,7 @@ import android.view.ViewOutlineProvider; import android.view.Window; import com.android.internal.R; +import com.android.internal.policy.DecorView; import com.android.internal.policy.PhoneWindow; import java.util.ArrayList; @@ -305,6 +306,8 @@ public class DecorCaptionView extends ViewGroup implements View.OnTouchListener, } } + ((DecorView) mOwner.getDecorView()).notifyCaptionHeightChanged(); + // This assumes that the caption bar is at the top. mOwner.notifyRestrictedCaptionAreaCallback(mMaximize.getLeft(), mMaximize.getTop(), mClose.getRight(), mClose.getBottom()); diff --git a/core/tests/coretests/src/android/view/InsetsSourceTest.java b/core/tests/coretests/src/android/view/InsetsSourceTest.java index b3f6fe9e88b9..c61f33e15b18 100644 --- a/core/tests/coretests/src/android/view/InsetsSourceTest.java +++ b/core/tests/coretests/src/android/view/InsetsSourceTest.java @@ -16,6 +16,7 @@ package android.view; +import static android.view.InsetsState.ITYPE_CAPTION_BAR; import static android.view.InsetsState.ITYPE_IME; import static android.view.InsetsState.ITYPE_NAVIGATION_BAR; @@ -46,11 +47,13 @@ public class InsetsSourceTest { private InsetsSource mSource = new InsetsSource(ITYPE_NAVIGATION_BAR); private InsetsSource mImeSource = new InsetsSource(ITYPE_IME); + private InsetsSource mCaptionSource = new InsetsSource(ITYPE_CAPTION_BAR); @Before public void setUp() { mSource.setVisible(true); mImeSource.setVisible(true); + mCaptionSource.setVisible(true); } @Test @@ -102,6 +105,17 @@ public class InsetsSourceTest { } @Test + public void testCalculateInsets_caption_resizing() { + mCaptionSource.setFrame(new Rect(0, 0, 100, 100)); + Insets insets = mCaptionSource.calculateInsets(new Rect(0, 0, 200, 200), false); + assertEquals(Insets.of(0, 100, 0, 0), insets); + insets = mCaptionSource.calculateInsets(new Rect(0, 0, 50, 200), false); + assertEquals(Insets.of(0, 100, 0, 0), insets); + insets = mCaptionSource.calculateInsets(new Rect(100, 100, 200, 500), false); + assertEquals(Insets.of(0, 100, 0, 0), insets); + } + + @Test public void testCalculateInsets_invisible() { mSource.setFrame(new Rect(0, 0, 500, 100)); mSource.setVisible(false); |