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

Commit d92ae486 authored by Bryce Lee's avatar Bryce Lee
Browse files

Do not propagate parent bound changes from task as onResize.

When a stack is resized on the WindowManager side, it does not
itself signal a resize in any children. The children themselves will
receive updated override configurations for this. It is therefore not
necesssary to propagate calls from the task to the children when the
stack is resized.

This changelist separates out the callback for parent resizing into
onParentResize. The default implementation is to call onResize. The
default implementation of onResize now calls onParentResize on its
children. For Task, onParentResize is overridden to prevent
propagation.

Change-Id: If7990c88f12245774d085650b15da9abc96bf622
Fixes: 70558903
Test: atest FrameworksServicesTests:com.android.server.wm.WindowContainerTests#testOnParentResizePropagation
parent 4e3ead32
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -218,6 +218,14 @@ public abstract class ConfigurationContainer<E extends ConfigurationContainer> {
        return mReturnBounds;
    }

    /**
     * Returns {@code true} if the {@link WindowConfiguration} in the override
     * {@link Configuration} specifies bounds.
     */
    public boolean hasOverrideBounds() {
        return !getOverrideBounds().isEmpty();
    }

    /**
     * Sets the passed in {@link Rect} to the current bounds.
     * @see {@link #getOverrideBounds()}.
+13 −1
Original line number Diff line number Diff line
@@ -461,10 +461,22 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
    void onResize() {
        for (int i = mChildren.size() - 1; i >= 0; --i) {
            final WindowContainer wc = mChildren.get(i);
            wc.onResize();
            wc.onParentResize();
        }
    }

    void onParentResize() {
        // In the case this container has specified its own bounds, a parent resize will not
        // affect its bounds. Any relevant changes will be propagated through changes to the
        // Configuration override.
        if (hasOverrideBounds()) {
            return;
        }

        // Default implementation is to treat as resize on self.
        onResize();
    }

    void onMovedByResize() {
        for (int i = mChildren.size() - 1; i >= 0; --i) {
            final WindowContainer wc = mChildren.get(i);
+38 −1
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;

import android.content.res.Configuration;
import android.graphics.Rect;
import android.platform.test.annotations.Presubmit;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
@@ -41,11 +42,16 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

/**
 * Test class for {@link WindowContainer}.
 *
 * Build/Install/Run:
 *  bit FrameworksServicesTests:com.android.server.wm.WindowContainerTests
 *  atest FrameworksServicesTests:com.android.server.wm.WindowContainerTests
 */
@SmallTest
@Presubmit
@@ -644,6 +650,37 @@ public class WindowContainerTests extends WindowTestsBase {
        assertEquals(1, child2.getPrefixOrderIndex());
    }

    /**
     * Ensure children of a {@link WindowContainer} do not have
     * {@link WindowContainer#onParentResize()} called when {@link WindowContainer#onParentResize()}
     * is invoked with overridden bounds.
     */
    @Test
    public void testOnParentResizePropagation() throws Exception {
        final TestWindowContainerBuilder builder = new TestWindowContainerBuilder();
        final TestWindowContainer root = builder.build();

        final TestWindowContainer child = root.addChildWindow();
        child.setBounds(new Rect(1,1,2,2));

        final TestWindowContainer grandChild = mock(TestWindowContainer.class);

        child.addChildWindow(grandChild);
        root.onResize();

        // Make sure the child does not propagate resize through onParentResize when bounds are set.
        verify(grandChild, never()).onParentResize();

        child.removeChild(grandChild);

        child.setBounds(null);
        child.addChildWindow(grandChild);
        root.onResize();

        // Make sure the child propagates resize through onParentResize when no bounds set.
        verify(grandChild, times(1)).onParentResize();
    }

    /* Used so we can gain access to some protected members of the {@link WindowContainer} class */
    private class TestWindowContainer extends WindowContainer<TestWindowContainer> {
        private final int mLayer;