diff options
3 files changed, 59 insertions, 2 deletions
diff --git a/services/core/java/com/android/server/wm/ConfigurationContainer.java b/services/core/java/com/android/server/wm/ConfigurationContainer.java index d340923b754e..2c2389b12577 100644 --- a/services/core/java/com/android/server/wm/ConfigurationContainer.java +++ b/services/core/java/com/android/server/wm/ConfigurationContainer.java @@ -219,6 +219,14 @@ public abstract class ConfigurationContainer<E extends ConfigurationContainer> { } /** + * 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()}. */ diff --git a/services/core/java/com/android/server/wm/WindowContainer.java b/services/core/java/com/android/server/wm/WindowContainer.java index 42c6ec25a7a8..74cc1308537b 100644 --- a/services/core/java/com/android/server/wm/WindowContainer.java +++ b/services/core/java/com/android/server/wm/WindowContainer.java @@ -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); diff --git a/services/tests/servicestests/src/com/android/server/wm/WindowContainerTests.java b/services/tests/servicestests/src/com/android/server/wm/WindowContainerTests.java index 196b4a99d02d..1bd9a933885b 100644 --- a/services/tests/servicestests/src/com/android/server/wm/WindowContainerTests.java +++ b/services/tests/servicestests/src/com/android/server/wm/WindowContainerTests.java @@ -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; |