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

Commit 0214ed9b authored by Andrii Kulian's avatar Andrii Kulian
Browse files

Don't report displays that are going to be removed

When display is removed from system, it is immediately removed from
AM, but removal can be deferred in WM if there is an active animation
on that display. If AM then requests display ids in focus order from
WM, it might get a display that was already deleted in AM.
This CL skips displays marked for deferred removal.

Bug: 38166277
Test: DisplayContentTests#testDontReportDeferredRemoval
Change-Id: I49544963f476fc58a609094781ed46541af8a238
parent e53243cb
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -1892,6 +1892,11 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
        return true;
    }

    /** @return 'true' if removal of this display content is deferred due to active animation. */
    boolean isRemovalDeferred() {
        return mDeferredRemoval;
    }

    boolean animateForIme(float interpolatedValue, float animationTarget,
            float dividerAnimationTarget) {
        boolean updated = false;
+6 −1
Original line number Diff line number Diff line
@@ -181,7 +181,12 @@ class RootWindowContainer extends WindowContainer<DisplayContent> {

        final int size = mChildren.size();
        for (int i = 0; i < size; ++i) {
            displaysInFocusOrder.put(i, mChildren.get(i).getDisplayId());
            final DisplayContent displayContent = mChildren.get(i);
            if (displayContent.isRemovalDeferred()) {
                // Don't report displays that are going to be removed soon.
                continue;
            }
            displaysInFocusOrder.put(i, displayContent.getDisplayId());
        }
    }

+20 −1
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import android.content.res.Configuration;
import android.platform.test.annotations.Presubmit;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import android.util.SparseIntArray;

import java.util.Arrays;
import java.util.LinkedList;
@@ -239,7 +240,7 @@ public class DisplayContentTests extends WindowTestsBase {
    @Test
    @Ignore
    public void testFocusedWindowMultipleDisplays() throws Exception {
        // Create a focusable window and check that focus is calcualted correctly
        // Create a focusable window and check that focus is calculated correctly
        final WindowState window1 =
                createWindow(null, TYPE_BASE_APPLICATION, mDisplayContent, "window1");
        assertEquals(window1, sWm.mRoot.computeFocusedWindow());
@@ -310,6 +311,24 @@ public class DisplayContentTests extends WindowTestsBase {
        assertEquals(afterStackCount - 1, mDisplayContent.getStaskPosById(PINNED_STACK_ID));
    }

    /**
     * Test that WM does not report displays to AM that are pending to be removed.
     */
    @Test
    public void testDontReportDeferredRemoval() {
        // Create a display and add an animating window to it.
        final DisplayContent dc = createNewDisplay();
        final WindowState window = createWindow(null /* parent */, TYPE_BASE_APPLICATION, dc, "w");
        window.mAnimatingExit = true;
        // Request display removal, it should be deferred.
        dc.removeIfPossible();
        // Request ordered display ids from WM.
        final SparseIntArray orderedDisplayIds = new SparseIntArray();
        sWm.getDisplaysInFocusOrder(orderedDisplayIds);
        // Make sure that display that is marked for removal is not reported.
        assertEquals(-1, orderedDisplayIds.indexOfValue(dc.getDisplayId()));
    }

    private static void verifySizes(DisplayContent displayContent, int expectedBaseWidth,
                             int expectedBaseHeight, int expectedBaseDensity) {
        assertEquals(displayContent.mBaseDisplayWidth, expectedBaseWidth);