Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a287263b authored by Tiger Huang's avatar Tiger Huang Committed by Nicolò Mazzucato
Browse files

Update above insets state if a window is moved to another display

If a window is moved to another display, the insets state of the display
should be updated so that the window can receive and provide the correct
insets.

If an insets providing window is moved to another display, the above
insets state of the original display should be updated as well.

Bug: 428632678
Flag: EXEMPT bug fix
Test: atest InsetsStateControllerTest
Change-Id: I80a49a44ad1f895b16efce5a22d2147970ed73f5
parent fa2f6606
Loading
Loading
Loading
Loading
+23 −4
Original line number Diff line number Diff line
@@ -1455,11 +1455,30 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP

    @Override
    void onDisplayChanged(DisplayContent dc) {
        if (dc != null && mDisplayContent != null && dc != mDisplayContent
                && mDisplayContent.getImeInputTarget() == this) {
        if (mDisplayContent != null && dc != mDisplayContent) {
            if (mInsetsSourceProviders != null && mInsetsSourceProviders.size() > 0) {
                boolean notifyInsetsChange = false;
                for (int i = mInsetsSourceProviders.size() - 1; i >= 0; i--) {
                    if (mInsetsSourceProviders.valueAt(i).isServerVisible()) {
                        notifyInsetsChange = true;
                        break;
                    }
                }
                mDisplayContent.getInsetsStateController().updateAboveInsetsState(
                        notifyInsetsChange);
            }
            if (dc != null) {
                dc.getInsetsStateController().updateAboveInsetsState(
                        // This window doesn't have a frame yet. Don't let this window cause the
                        // insets change.
                        false /* notifyInsetsChange */);

                if (mDisplayContent.getImeInputTarget() == this) {
                    dc.updateImeInputAndControlTarget(getImeInputTarget());
                    mDisplayContent.setImeInputTarget(null /* target */);
                }
            }
        }
        super.onDisplayChanged(dc);
        // Window was not laid out for this display yet, so make sure mLayoutSeq does not match.
        if (dc != null && mInputWindowHandle.getDisplayId() != dc.getDisplayId()) {
+48 −0
Original line number Diff line number Diff line
@@ -548,6 +548,54 @@ public class InsetsStateControllerTest extends WindowTestsBase {
        verify(navBar, atLeastOnce()).notifyInsetsChanged();
    }

    /**
     * Verifies that moving the insets receiving window (app) to another display will stop the
     * window from receiving insets from the original display.
     */
    @UseTestDisplay
    @Test
    public void testUpdateAboveInsetsState_onDisplayChanged_app() {
        final WindowState app = createTestWindow("app");
        final WindowState statusBar = createTestWindow("statusBar");

        getController().getOrCreateSourceProvider(ID_STATUS_BAR, statusBars())
                .setWindow(statusBar, null, null);

        assertNull(app.mAboveInsetsState.peekSource(ID_STATUS_BAR));

        getController().updateAboveInsetsState(true /* notifyInsetsChange */);

        assertNotNull(app.mAboveInsetsState.peekSource(ID_STATUS_BAR));

        app.getTask().reparent(mDefaultDisplay.getDefaultTaskDisplayArea(), true /* onTop */);

        assertNull(app.mAboveInsetsState.peekSource(ID_STATUS_BAR));
    }

    /**
     * Verifies that moving the insets providing window (statusBar) to another display will stop the
     * window on the original display from receiving the insets.
     */
    @UseTestDisplay
    @Test
    public void testUpdateAboveInsetsState_onDisplayChanged_statusBar() {
        final WindowState app = createTestWindow("app");
        final WindowState statusBar = createTestWindow("statusBar");

        getController().getOrCreateSourceProvider(ID_STATUS_BAR, statusBars())
                .setWindow(statusBar, null, null);

        assertNull(app.mAboveInsetsState.peekSource(ID_STATUS_BAR));

        getController().updateAboveInsetsState(true /* notifyInsetsChange */);

        assertNotNull(app.mAboveInsetsState.peekSource(ID_STATUS_BAR));

        statusBar.getTask().reparent(mDefaultDisplay.getDefaultTaskDisplayArea(), true /* onTop */);

        assertNull(app.mAboveInsetsState.peekSource(ID_STATUS_BAR));
    }

    @Test
    public void testUpdateAboveInsetsState_imeTargetOnScreenBehavior() {
        final WindowToken imeToken = createTestWindowToken(TYPE_INPUT_METHOD, mDisplayContent);