From 0dc5880ab7dc350738ce3edc873e443c226718f4 Mon Sep 17 00:00:00 2001 From: chaviw Date: Tue, 24 Apr 2018 15:23:53 -0700 Subject: [PATCH] Synchronize RootWindowContainerTests There were a few failures that seem to be threading issues. Specifically, IndexOutOfBounds within a for loop that was iterating the size of the ArrayList and ArrayMap index failure. RootWindowContainerTests calls into methods in WM that assume the WM lock is already held. Ensure testSetDisplayOverrideConfigurationIfNeeded is synchronized. Test: RootWindowContainerTests#testSetDisplayOverrideConfigurationIfNeeded Change-Id: I5003fc4a59baae4990a1464dbbc85b0938312994 Fixes: 78349285 --- .../server/wm/RootWindowContainerTests.java | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/services/tests/servicestests/src/com/android/server/wm/RootWindowContainerTests.java b/services/tests/servicestests/src/com/android/server/wm/RootWindowContainerTests.java index 51b019a4d61ea..204e26cee532c 100644 --- a/services/tests/servicestests/src/com/android/server/wm/RootWindowContainerTests.java +++ b/services/tests/servicestests/src/com/android/server/wm/RootWindowContainerTests.java @@ -24,27 +24,29 @@ import static org.junit.Assert.assertTrue; public class RootWindowContainerTests extends WindowTestsBase { @Test public void testSetDisplayOverrideConfigurationIfNeeded() throws Exception { - // Add first stack we expect to be updated with configuration change. - final TaskStack stack = createTaskStackOnDisplay(mDisplayContent); - stack.getOverrideConfiguration().windowConfiguration.setBounds(new Rect(0, 0, 5, 5)); + synchronized (sWm.mWindowMap) { + // Add first stack we expect to be updated with configuration change. + final TaskStack stack = createTaskStackOnDisplay(mDisplayContent); + stack.getOverrideConfiguration().windowConfiguration.setBounds(new Rect(0, 0, 5, 5)); - // Add second task that will be set for deferred removal that should not be returned - // with the configuration change. - final TaskStack deferredDeletedStack = createTaskStackOnDisplay(mDisplayContent); - deferredDeletedStack.getOverrideConfiguration().windowConfiguration.setBounds( - new Rect(0, 0, 5, 5)); - deferredDeletedStack.mDeferRemoval = true; + // Add second task that will be set for deferred removal that should not be returned + // with the configuration change. + final TaskStack deferredDeletedStack = createTaskStackOnDisplay(mDisplayContent); + deferredDeletedStack.getOverrideConfiguration().windowConfiguration.setBounds( + new Rect(0, 0, 5, 5)); + deferredDeletedStack.mDeferRemoval = true; - final Configuration override = new Configuration( - mDisplayContent.getOverrideConfiguration()); - override.windowConfiguration.setBounds(new Rect(0, 0, 10, 10)); + final Configuration override = new Configuration( + mDisplayContent.getOverrideConfiguration()); + override.windowConfiguration.setBounds(new Rect(0, 0, 10, 10)); - // Set display override. - final int[] results = sWm.mRoot.setDisplayOverrideConfigurationIfNeeded(override, - mDisplayContent.getDisplayId()); + // Set display override. + final int[] results = sWm.mRoot.setDisplayOverrideConfigurationIfNeeded(override, + mDisplayContent.getDisplayId()); - // Ensure only first stack is returned. - assertTrue(results.length == 1); - assertTrue(results[0] == stack.mStackId); + // Ensure only first stack is returned. + assertTrue(results.length == 1); + assertTrue(results[0] == stack.mStackId); + } } }