diff --git a/services/tests/servicestests/src/com/android/server/wm/AnimatingAppWindowTokenRegistryTest.java b/services/tests/servicestests/src/com/android/server/wm/AnimatingAppWindowTokenRegistryTest.java index b5fe8b159c475..a9071612a7259 100644 --- a/services/tests/servicestests/src/com/android/server/wm/AnimatingAppWindowTokenRegistryTest.java +++ b/services/tests/servicestests/src/com/android/server/wm/AnimatingAppWindowTokenRegistryTest.java @@ -11,7 +11,7 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License + * limitations under the License. */ package com.android.server.wm; @@ -29,11 +29,9 @@ import android.platform.test.annotations.Presubmit; import androidx.test.filters.FlakyTest; import androidx.test.filters.SmallTest; -import androidx.test.runner.AndroidJUnit4; import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -41,12 +39,11 @@ import org.mockito.MockitoAnnotations; * Tests for the {@link TaskStack} class. * * Build/Install/Run: - * atest FrameworksServicesTests:com.android.server.wm.AnimatingAppWindowTokenRegistryTest + * atest FrameworksServicesTests:AnimatingAppWindowTokenRegistryTest */ @SmallTest @Presubmit @FlakyTest(detail = "Promote once confirmed non-flaky") -@RunWith(AndroidJUnit4.class) public class AnimatingAppWindowTokenRegistryTest extends WindowTestsBase { @Mock @@ -56,14 +53,14 @@ public class AnimatingAppWindowTokenRegistryTest extends WindowTestsBase { Runnable mMockEndDeferFinishCallback1; @Mock Runnable mMockEndDeferFinishCallback2; + @Before public void setUp() throws Exception { - super.setUp(); MockitoAnnotations.initMocks(this); } @Test - public void testDeferring() throws Exception { + public void testDeferring() { final AppWindowToken window1 = createAppWindowToken(mDisplayContent, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD); final AppWindowToken window2 = createAppWindow(window1.getTask(), ACTIVITY_TYPE_STANDARD, @@ -85,7 +82,7 @@ public class AnimatingAppWindowTokenRegistryTest extends WindowTestsBase { } @Test - public void testContainerRemoved() throws Exception { + public void testContainerRemoved() { final AppWindowToken window1 = createAppWindowToken(mDisplayContent, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD); final AppWindowToken window2 = createAppWindow(window1.getTask(), ACTIVITY_TYPE_STANDARD, diff --git a/services/tests/servicestests/src/com/android/server/wm/AppTransitionControllerTest.java b/services/tests/servicestests/src/com/android/server/wm/AppTransitionControllerTest.java index fc3ca93df8016..5e12a950c560b 100644 --- a/services/tests/servicestests/src/com/android/server/wm/AppTransitionControllerTest.java +++ b/services/tests/servicestests/src/com/android/server/wm/AppTransitionControllerTest.java @@ -11,7 +11,7 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License + * limitations under the License. */ package com.android.server.wm; @@ -27,28 +27,28 @@ import android.platform.test.annotations.Presubmit; import android.view.WindowManager; import androidx.test.filters.SmallTest; -import androidx.test.runner.AndroidJUnit4; import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; +/** + * Build/Install/Run: + * atest FrameworksServicesTests:AppTransitionControllerTest + */ @SmallTest @Presubmit -@RunWith(AndroidJUnit4.class) public class AppTransitionControllerTest extends WindowTestsBase { private AppTransitionController mAppTransitionController; @Before public void setUp() throws Exception { - super.setUp(); - mAppTransitionController = new AppTransitionController(sWm, mDisplayContent); + mAppTransitionController = new AppTransitionController(mWm, mDisplayContent); } @Test - public void testTranslucentOpen() throws Exception { - synchronized (sWm.mGlobalLock) { + public void testTranslucentOpen() { + synchronized (mWm.mGlobalLock) { final AppWindowToken behind = createAppWindowToken(mDisplayContent, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD); final AppWindowToken translucentOpening = createAppWindowToken(mDisplayContent, @@ -64,8 +64,8 @@ public class AppTransitionControllerTest extends WindowTestsBase { } @Test - public void testTranslucentClose() throws Exception { - synchronized (sWm.mGlobalLock) { + public void testTranslucentClose() { + synchronized (mWm.mGlobalLock) { final AppWindowToken behind = createAppWindowToken(mDisplayContent, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD); final AppWindowToken translucentClosing = createAppWindowToken(mDisplayContent, diff --git a/services/tests/servicestests/src/com/android/server/wm/AppTransitionTests.java b/services/tests/servicestests/src/com/android/server/wm/AppTransitionTests.java index ee6fbac3f19f2..f12619c6e337c 100644 --- a/services/tests/servicestests/src/com/android/server/wm/AppTransitionTests.java +++ b/services/tests/servicestests/src/com/android/server/wm/AppTransitionTests.java @@ -11,7 +11,7 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License + * limitations under the License. */ package com.android.server.wm; @@ -32,81 +32,75 @@ import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.spy; -import android.content.Context; import android.graphics.Rect; import android.platform.test.annotations.Presubmit; import android.view.Display; import android.view.IApplicationToken; -import androidx.test.InstrumentationRegistry; import androidx.test.filters.SmallTest; -import androidx.test.runner.AndroidJUnit4; import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; /** * Test class for {@link AppTransition}. * - * atest AppTransitionTests + * Build/Install/Run: + * atest FrameworksServicesTests:AppTransitionTests */ @SmallTest @Presubmit -@RunWith(AndroidJUnit4.class) public class AppTransitionTests extends WindowTestsBase { private DisplayContent mDc; @Before public void setUp() throws Exception { - super.setUp(); - final Context context = InstrumentationRegistry.getTargetContext(); - mDc = sWm.getDefaultDisplayContentLocked(); + mDc = mWm.getDefaultDisplayContentLocked(); // For unit test, we don't need to test performSurfacePlacement to prevent some // abnormal interaction with surfaceflinger native side. - sWm.mRoot = spy(sWm.mRoot); - doNothing().when(sWm.mRoot).performSurfacePlacement(anyBoolean()); + mWm.mRoot = spy(mWm.mRoot); + doNothing().when(mWm.mRoot).performSurfacePlacement(anyBoolean()); } @Test - public void testKeyguardOverride() throws Exception { - sWm.prepareAppTransition(TRANSIT_ACTIVITY_OPEN, false /* alwaysKeepCurrent */); - sWm.prepareAppTransition(TRANSIT_KEYGUARD_GOING_AWAY, false /* alwaysKeepCurrent */); + public void testKeyguardOverride() { + mWm.prepareAppTransition(TRANSIT_ACTIVITY_OPEN, false /* alwaysKeepCurrent */); + mWm.prepareAppTransition(TRANSIT_KEYGUARD_GOING_AWAY, false /* alwaysKeepCurrent */); assertEquals(TRANSIT_KEYGUARD_GOING_AWAY, mDc.mAppTransition.getAppTransition()); } @Test - public void testKeyguardKeep() throws Exception { - sWm.prepareAppTransition(TRANSIT_KEYGUARD_GOING_AWAY, false /* alwaysKeepCurrent */); - sWm.prepareAppTransition(TRANSIT_ACTIVITY_OPEN, false /* alwaysKeepCurrent */); + public void testKeyguardKeep() { + mWm.prepareAppTransition(TRANSIT_KEYGUARD_GOING_AWAY, false /* alwaysKeepCurrent */); + mWm.prepareAppTransition(TRANSIT_ACTIVITY_OPEN, false /* alwaysKeepCurrent */); assertEquals(TRANSIT_KEYGUARD_GOING_AWAY, mDc.mAppTransition.getAppTransition()); } @Test - public void testForceOverride() throws Exception { - sWm.prepareAppTransition(TRANSIT_KEYGUARD_UNOCCLUDE, false /* alwaysKeepCurrent */); + public void testForceOverride() { + mWm.prepareAppTransition(TRANSIT_KEYGUARD_UNOCCLUDE, false /* alwaysKeepCurrent */); mDc.getController().prepareAppTransition(TRANSIT_ACTIVITY_OPEN, false /* alwaysKeepCurrent */, 0 /* flags */, true /* forceOverride */); assertEquals(TRANSIT_ACTIVITY_OPEN, mDc.mAppTransition.getAppTransition()); } @Test - public void testCrashing() throws Exception { - sWm.prepareAppTransition(TRANSIT_ACTIVITY_OPEN, false /* alwaysKeepCurrent */); - sWm.prepareAppTransition(TRANSIT_CRASHING_ACTIVITY_CLOSE, false /* alwaysKeepCurrent */); + public void testCrashing() { + mWm.prepareAppTransition(TRANSIT_ACTIVITY_OPEN, false /* alwaysKeepCurrent */); + mWm.prepareAppTransition(TRANSIT_CRASHING_ACTIVITY_CLOSE, false /* alwaysKeepCurrent */); assertEquals(TRANSIT_CRASHING_ACTIVITY_CLOSE, mDc.mAppTransition.getAppTransition()); } @Test - public void testKeepKeyguard_withCrashing() throws Exception { - sWm.prepareAppTransition(TRANSIT_KEYGUARD_GOING_AWAY, false /* alwaysKeepCurrent */); - sWm.prepareAppTransition(TRANSIT_CRASHING_ACTIVITY_CLOSE, false /* alwaysKeepCurrent */); + public void testKeepKeyguard_withCrashing() { + mWm.prepareAppTransition(TRANSIT_KEYGUARD_GOING_AWAY, false /* alwaysKeepCurrent */); + mWm.prepareAppTransition(TRANSIT_CRASHING_ACTIVITY_CLOSE, false /* alwaysKeepCurrent */); assertEquals(TRANSIT_KEYGUARD_GOING_AWAY, mDc.mAppTransition.getAppTransition()); } @Test - public void testAppTransitionStateForMultiDisplay() throws Exception { + public void testAppTransitionStateForMultiDisplay() { // Create 2 displays & presume both display the state is ON for ready to display & animate. final DisplayContent dc1 = createNewDisplayWithController(Display.STATE_ON); final DisplayContent dc2 = createNewDisplayWithController(Display.STATE_ON); @@ -149,7 +143,7 @@ public class AppTransitionTests extends WindowTestsBase { } @Test - public void testCleanAppTransitionWhenTaskStackReparent() throws Exception { + public void testCleanAppTransitionWhenTaskStackReparent() { // Create 2 displays & presume both display the state is ON for ready to display & animate. final DisplayContent dc1 = createNewDisplayWithController(Display.STATE_ON); final DisplayContent dc2 = createNewDisplayWithController(Display.STATE_ON); diff --git a/services/tests/servicestests/src/com/android/server/wm/AppWindowContainerControllerTests.java b/services/tests/servicestests/src/com/android/server/wm/AppWindowContainerControllerTests.java index fcd8a39e4d079..415b5d93d90e1 100644 --- a/services/tests/servicestests/src/com/android/server/wm/AppWindowContainerControllerTests.java +++ b/services/tests/servicestests/src/com/android/server/wm/AppWindowContainerControllerTests.java @@ -21,6 +21,8 @@ import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; import static android.content.res.Configuration.EMPTY; import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; +import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -29,10 +31,8 @@ import static org.junit.Assert.fail; import android.platform.test.annotations.Presubmit; -import androidx.test.InstrumentationRegistry; import androidx.test.filters.FlakyTest; import androidx.test.filters.SmallTest; -import androidx.test.runner.AndroidJUnit4; import com.android.server.wm.WindowTestUtils.TestTaskWindowContainerController; @@ -41,16 +41,17 @@ import org.junit.Test; /** * Test class for {@link AppWindowContainerController}. * - * atest FrameworksServicesTests:com.android.server.wm.AppWindowContainerControllerTests + * atest FrameworksServicesTests:AppWindowContainerControllerTests */ +@FlakyTest(bugId = 74078662) @SmallTest @Presubmit -@FlakyTest(bugId = 74078662) -@org.junit.runner.RunWith(AndroidJUnit4.class) public class AppWindowContainerControllerTests extends WindowTestsBase { + private final String mPackageName = getInstrumentation().getTargetContext().getPackageName(); + @Test - public void testRemoveContainer() throws Exception { + public void testRemoveContainer() { final WindowTestUtils.TestAppWindowContainerController controller = createAppWindowController(); @@ -68,7 +69,7 @@ public class AppWindowContainerControllerTests extends WindowTestsBase { } @Test - public void testSetOrientation() throws Exception { + public void testSetOrientation() { final WindowTestUtils.TestAppWindowContainerController controller = createAppWindowController(); @@ -84,7 +85,7 @@ public class AppWindowContainerControllerTests extends WindowTestsBase { assertEquals(SCREEN_ORIENTATION_UNSPECIFIED, controller.getOrientation()); // Reset display frozen state - sWm.mDisplayFrozen = false; + mWm.mDisplayFrozen = false; } private void assertHasStartingWindow(AppWindowToken atoken) { @@ -103,10 +104,10 @@ public class AppWindowContainerControllerTests extends WindowTestsBase { } @Test - public void testCreateRemoveStartingWindow() throws Exception { + public void testCreateRemoveStartingWindow() { final WindowTestUtils.TestAppWindowContainerController controller = createAppWindowController(); - controller.addStartingWindow(InstrumentationRegistry.getContext().getPackageName(), + controller.addStartingWindow(mPackageName, android.R.style.Theme, null, "Test", 0, 0, 0, 0, null, true, true, false, true, false, false); waitUntilHandlersIdle(); @@ -118,34 +119,34 @@ public class AppWindowContainerControllerTests extends WindowTestsBase { } @Test - public void testAddRemoveRace() throws Exception { - + public void testAddRemoveRace() { // There was once a race condition between adding and removing starting windows for (int i = 0; i < 1000; i++) { final WindowTestUtils.TestAppWindowContainerController controller = createAppWindowController(); - controller.addStartingWindow(InstrumentationRegistry.getContext().getPackageName(), + controller.addStartingWindow(mPackageName, android.R.style.Theme, null, "Test", 0, 0, 0, 0, null, true, true, false, true, false, false); controller.removeStartingWindow(); waitUntilHandlersIdle(); assertNoStartingWindow(controller.getAppWindowToken(mDisplayContent)); - controller.getAppWindowToken(mDisplayContent).getParent().getParent().removeImmediately(); + controller.getAppWindowToken( + mDisplayContent).getParent().getParent().removeImmediately(); } } @Test - public void testTransferStartingWindow() throws Exception { + public void testTransferStartingWindow() { final WindowTestUtils.TestAppWindowContainerController controller1 = createAppWindowController(); final WindowTestUtils.TestAppWindowContainerController controller2 = createAppWindowController(); - controller1.addStartingWindow(InstrumentationRegistry.getContext().getPackageName(), + controller1.addStartingWindow(mPackageName, android.R.style.Theme, null, "Test", 0, 0, 0, 0, null, true, true, false, true, false, false); waitUntilHandlersIdle(); - controller2.addStartingWindow(InstrumentationRegistry.getContext().getPackageName(), + controller2.addStartingWindow(mPackageName, android.R.style.Theme, null, "Test", 0, 0, 0, 0, controller1.mToken.asBinder(), true, true, false, true, false, false); waitUntilHandlersIdle(); @@ -154,19 +155,19 @@ public class AppWindowContainerControllerTests extends WindowTestsBase { } @Test - public void testTransferStartingWindowWhileCreating() throws Exception { + public void testTransferStartingWindowWhileCreating() { final WindowTestUtils.TestAppWindowContainerController controller1 = createAppWindowController(); final WindowTestUtils.TestAppWindowContainerController controller2 = createAppWindowController(); - ((TestWindowManagerPolicy) sWm.mPolicy).setRunnableWhenAddingSplashScreen(() -> { + ((TestWindowManagerPolicy) mWm.mPolicy).setRunnableWhenAddingSplashScreen(() -> { // Surprise, ...! Transfer window in the middle of the creation flow. - controller2.addStartingWindow(InstrumentationRegistry.getContext().getPackageName(), + controller2.addStartingWindow(mPackageName, android.R.style.Theme, null, "Test", 0, 0, 0, 0, controller1.mToken.asBinder(), true, true, false, true, false, false); }); - controller1.addStartingWindow(InstrumentationRegistry.getContext().getPackageName(), + controller1.addStartingWindow(mPackageName, android.R.style.Theme, null, "Test", 0, 0, 0, 0, null, true, true, false, true, false, false); waitUntilHandlersIdle(); @@ -175,7 +176,7 @@ public class AppWindowContainerControllerTests extends WindowTestsBase { } @Test - public void testTryTransferStartingWindowFromHiddenAboveToken() throws Exception { + public void testTryTransferStartingWindowFromHiddenAboveToken() { // Add two tasks on top of each other. TestTaskWindowContainerController taskController = @@ -186,7 +187,7 @@ public class AppWindowContainerControllerTests extends WindowTestsBase { createAppWindowController(taskController); // Add a starting window. - controllerTop.addStartingWindow(InstrumentationRegistry.getContext().getPackageName(), + controllerTop.addStartingWindow(mPackageName, android.R.style.Theme, null, "Test", 0, 0, 0, 0, null, true, true, false, true, false, false); waitUntilHandlersIdle(); @@ -202,7 +203,7 @@ public class AppWindowContainerControllerTests extends WindowTestsBase { } @Test - public void testReparent() throws Exception { + public void testReparent() { final StackWindowController stackController = createStackControllerOnDisplay(mDisplayContent); final WindowTestUtils.TestTaskWindowContainerController taskController1 = diff --git a/services/tests/servicestests/src/com/android/server/wm/AppWindowTokenAnimationTests.java b/services/tests/servicestests/src/com/android/server/wm/AppWindowTokenAnimationTests.java index e3ab5cf4fc524..4522494349a3c 100644 --- a/services/tests/servicestests/src/com/android/server/wm/AppWindowTokenAnimationTests.java +++ b/services/tests/servicestests/src/com/android/server/wm/AppWindowTokenAnimationTests.java @@ -11,7 +11,7 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License + * limitations under the License. */ package com.android.server.wm; @@ -26,15 +26,14 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.verify; -import androidx.test.filters.SmallTest; -import androidx.test.runner.AndroidJUnit4; - import android.view.SurfaceControl; +import androidx.test.filters.SmallTest; + import com.android.server.wm.WindowTestUtils.TestAppWindowToken; +import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -43,10 +42,9 @@ import org.mockito.MockitoAnnotations; * Animation related tests for the {@link AppWindowToken} class. * * Build/Install/Run: - * atest FrameworksServicesTests:com.android.server.wm.AppWindowTokenAnimationTests + * atest FrameworksServicesTests:AppWindowTokenAnimationTests */ @SmallTest -@RunWith(AndroidJUnit4.class) public class AppWindowTokenAnimationTests extends WindowTestsBase { private TestAppWindowToken mToken; @@ -56,9 +54,8 @@ public class AppWindowTokenAnimationTests extends WindowTestsBase { @Mock private AnimationAdapter mSpec; - @Override + @Before public void setUp() throws Exception { - super.setUp(); MockitoAnnotations.initMocks(this); mToken = createTestAppWindowToken(mDisplayContent, WINDOWING_MODE_FULLSCREEN, @@ -67,7 +64,7 @@ public class AppWindowTokenAnimationTests extends WindowTestsBase { } @Test - public void clipAfterAnim_boundsLayerIsCreated() throws Exception { + public void clipAfterAnim_boundsLayerIsCreated() { mToken.mNeedsAnimationBoundsLayer = true; mToken.mSurfaceAnimator.startAnimation(mTransaction, mSpec, true /* hidden */); @@ -78,7 +75,7 @@ public class AppWindowTokenAnimationTests extends WindowTestsBase { } @Test - public void clipAfterAnim_boundsLayerIsDestroyed() throws Exception { + public void clipAfterAnim_boundsLayerIsDestroyed() { mToken.mNeedsAnimationBoundsLayer = true; mToken.mSurfaceAnimator.startAnimation(mTransaction, mSpec, true /* hidden */); final SurfaceControl leash = mToken.mSurfaceAnimator.mLeash; @@ -95,7 +92,7 @@ public class AppWindowTokenAnimationTests extends WindowTestsBase { } @Test - public void clipAfterAnimCancelled_boundsLayerIsDestroyed() throws Exception { + public void clipAfterAnimCancelled_boundsLayerIsDestroyed() { mToken.mNeedsAnimationBoundsLayer = true; mToken.mSurfaceAnimator.startAnimation(mTransaction, mSpec, true /* hidden */); final SurfaceControl leash = mToken.mSurfaceAnimator.mLeash; @@ -108,7 +105,7 @@ public class AppWindowTokenAnimationTests extends WindowTestsBase { } @Test - public void clipNoneAnim_boundsLayerIsNotCreated() throws Exception { + public void clipNoneAnim_boundsLayerIsNotCreated() { mToken.mNeedsAnimationBoundsLayer = false; mToken.mSurfaceAnimator.startAnimation(mTransaction, mSpec, true /* hidden */); diff --git a/services/tests/servicestests/src/com/android/server/wm/AppWindowTokenTests.java b/services/tests/servicestests/src/com/android/server/wm/AppWindowTokenTests.java index 7935ec1681423..a8e1ed46c1660 100644 --- a/services/tests/servicestests/src/com/android/server/wm/AppWindowTokenTests.java +++ b/services/tests/servicestests/src/com/android/server/wm/AppWindowTokenTests.java @@ -11,7 +11,7 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License + * limitations under the License. */ package com.android.server.wm; @@ -47,31 +47,27 @@ import android.view.WindowManager; import androidx.test.filters.FlakyTest; import androidx.test.filters.SmallTest; -import androidx.test.runner.AndroidJUnit4; +import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; /** * Tests for the {@link AppWindowToken} class. * * Build/Install/Run: - * atest FrameworksServicesTests:com.android.server.wm.AppWindowTokenTests + * atest FrameworksServicesTests:AppWindowTokenTests */ +@FlakyTest(bugId = 68267650) @SmallTest -// TODO: b/68267650 -// @Presubmit -@RunWith(AndroidJUnit4.class) +@Presubmit public class AppWindowTokenTests extends WindowTestsBase { TaskStack mStack; Task mTask; WindowTestUtils.TestAppWindowToken mToken; - @Override + @Before public void setUp() throws Exception { - super.setUp(); - mStack = createTaskStackOnDisplay(mDisplayContent); mTask = createTaskInStack(mStack, 0 /* userId */); mToken = WindowTestUtils.createTestAppWindowToken(mDisplayContent); @@ -81,7 +77,7 @@ public class AppWindowTokenTests extends WindowTestsBase { @Test @Presubmit - public void testAddWindow_Order() throws Exception { + public void testAddWindow_Order() { assertEquals(0, mToken.getWindowsCount()); final WindowState win1 = createWindow(null, TYPE_APPLICATION, mToken, "win1"); @@ -107,7 +103,7 @@ public class AppWindowTokenTests extends WindowTestsBase { @Test @Presubmit - public void testFindMainWindow() throws Exception { + public void testFindMainWindow() { assertNull(mToken.findMainWindow()); final WindowState window1 = createWindow(null, TYPE_BASE_APPLICATION, mToken, "window1"); @@ -123,7 +119,7 @@ public class AppWindowTokenTests extends WindowTestsBase { @Test @Presubmit - public void testGetTopFullscreenWindow() throws Exception { + public void testGetTopFullscreenWindow() { assertNull(mToken.getTopFullscreenWindow()); final WindowState window1 = createWindow(null, TYPE_BASE_APPLICATION, mToken, "window1"); @@ -138,10 +134,10 @@ public class AppWindowTokenTests extends WindowTestsBase { } @Test - public void testLandscapeSeascapeRotationByApp() throws Exception { + public void testLandscapeSeascapeRotationByApp() { // Some plumbing to get the service ready for rotation updates. - sWm.mDisplayReady = true; - sWm.mDisplayEnabled = true; + mWm.mDisplayReady = true; + mWm.mDisplayEnabled = true; final WindowManager.LayoutParams attrs = new WindowManager.LayoutParams( TYPE_BASE_APPLICATION); @@ -151,26 +147,26 @@ public class AppWindowTokenTests extends WindowTestsBase { // Set initial orientation and update. mToken.setOrientation(SCREEN_ORIENTATION_LANDSCAPE); - sWm.updateOrientationFromAppTokens(mDisplayContent.getOverrideConfiguration(), null, + mWm.updateOrientationFromAppTokens(mDisplayContent.getOverrideConfiguration(), null, mDisplayContent.getDisplayId()); assertEquals(SCREEN_ORIENTATION_LANDSCAPE, mDisplayContent.getLastOrientation()); appWindow.resizeReported = false; // Update the orientation to perform 180 degree rotation and check that resize was reported. mToken.setOrientation(SCREEN_ORIENTATION_REVERSE_LANDSCAPE); - sWm.updateOrientationFromAppTokens(mDisplayContent.getOverrideConfiguration(), null, + mWm.updateOrientationFromAppTokens(mDisplayContent.getOverrideConfiguration(), null, mDisplayContent.getDisplayId()); - sWm.mRoot.performSurfacePlacement(false /* recoveringMemory */); + mWm.mRoot.performSurfacePlacement(false /* recoveringMemory */); assertEquals(SCREEN_ORIENTATION_REVERSE_LANDSCAPE, mDisplayContent.getLastOrientation()); assertTrue(appWindow.resizeReported); appWindow.removeImmediately(); } @Test - public void testLandscapeSeascapeRotationByPolicy() throws Exception { + public void testLandscapeSeascapeRotationByPolicy() { // Some plumbing to get the service ready for rotation updates. - sWm.mDisplayReady = true; - sWm.mDisplayEnabled = true; + mWm.mDisplayReady = true; + mWm.mDisplayEnabled = true; final DisplayRotation spiedRotation = spy(mDisplayContent.getDisplayRotation()); mDisplayContent.setDisplayRotation(spiedRotation); @@ -194,15 +190,15 @@ public class AppWindowTokenTests extends WindowTestsBase { private void performRotation(DisplayRotation spiedRotation, int rotationToReport) { doReturn(rotationToReport).when(spiedRotation).rotationForOrientation(anyInt(), anyInt()); - sWm.updateRotation(false, false); + mWm.updateRotation(false, false); // Prevent the next rotation from being deferred by animation. - sWm.mAnimator.setScreenRotationAnimationLocked(mDisplayContent.getDisplayId(), null); - sWm.mRoot.performSurfacePlacement(false /* recoveringMemory */); + mWm.mAnimator.setScreenRotationAnimationLocked(mDisplayContent.getDisplayId(), null); + mWm.mRoot.performSurfacePlacement(false /* recoveringMemory */); } @Test @Presubmit - public void testGetOrientation() throws Exception { + public void testGetOrientation() { mToken.setOrientation(SCREEN_ORIENTATION_LANDSCAPE); mToken.setFillsParent(false); @@ -220,7 +216,7 @@ public class AppWindowTokenTests extends WindowTestsBase { @Test @Presubmit - public void testKeyguardFlagsDuringRelaunch() throws Exception { + public void testKeyguardFlagsDuringRelaunch() { final WindowManager.LayoutParams attrs = new WindowManager.LayoutParams( TYPE_BASE_APPLICATION); attrs.flags |= FLAG_SHOW_WHEN_LOCKED | FLAG_DISMISS_KEYGUARD; @@ -246,7 +242,7 @@ public class AppWindowTokenTests extends WindowTestsBase { @Test @FlakyTest(detail = "Promote once confirmed non-flaky") - public void testStuckExitingWindow() throws Exception { + public void testStuckExitingWindow() { final WindowState closingWindow = createWindow(null, FIRST_APPLICATION_WINDOW, "closingWindow"); closingWindow.mAnimatingExit = true; diff --git a/services/tests/servicestests/src/com/android/server/wm/BoundsAnimationControllerTests.java b/services/tests/servicestests/src/com/android/server/wm/BoundsAnimationControllerTests.java index d65055cf0e078..1c5391ed3a6c1 100644 --- a/services/tests/servicestests/src/com/android/server/wm/BoundsAnimationControllerTests.java +++ b/services/tests/servicestests/src/com/android/server/wm/BoundsAnimationControllerTests.java @@ -11,12 +11,12 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License + * limitations under the License. */ package com.android.server.wm; -import static android.view.Display.DEFAULT_DISPLAY; +import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; import static com.android.server.wm.BoundsAnimationController.NO_PIP_MODE_CHANGED_CALLBACKS; import static com.android.server.wm.BoundsAnimationController.SCHEDULE_PIP_MODE_CHANGED_ON_END; @@ -24,11 +24,11 @@ import static com.android.server.wm.BoundsAnimationController.SCHEDULE_PIP_MODE_ import static com.android.server.wm.BoundsAnimationController.SchedulePipModeChangedState; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import android.animation.ValueAnimator; import android.content.Context; @@ -37,16 +37,14 @@ import android.os.Handler; import android.os.Looper; import android.platform.test.annotations.Presubmit; -import androidx.test.InstrumentationRegistry; import androidx.test.annotation.UiThreadTest; import androidx.test.filters.SmallTest; -import androidx.test.runner.AndroidJUnit4; import com.android.server.wm.BoundsAnimationController.BoundsAnimator; import com.android.server.wm.WindowManagerInternal.AppTransitionListener; +import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; /** * Test class for {@link BoundsAnimationController} to ensure that it sends the right callbacks @@ -59,21 +57,20 @@ import org.junit.runner.RunWith; * appropriately. * * Build/Install/Run: - * bit FrameworksServicesTests:com.android.server.wm.BoundsAnimationControllerTests + * atest FrameworksServicesTests:BoundsAnimationControllerTests */ @SmallTest @Presubmit -@RunWith(AndroidJUnit4.class) public class BoundsAnimationControllerTests extends WindowTestsBase { /** * Mock value animator to simulate updates with. */ - private class MockValueAnimator extends ValueAnimator { + private static class MockValueAnimator extends ValueAnimator { private float mFraction; - public MockValueAnimator getWithValue(float fraction) { + MockValueAnimator getWithValue(float fraction) { mFraction = fraction; return this; } @@ -87,12 +84,12 @@ public class BoundsAnimationControllerTests extends WindowTestsBase { /** * Mock app transition to fire notifications to the bounds animator. */ - private class MockAppTransition extends AppTransition { + private static class MockAppTransition extends AppTransition { private AppTransitionListener mListener; - MockAppTransition(Context context) { - super(context, sWm, mDisplayContent); + MockAppTransition(Context context, WindowManagerService wm, DisplayContent displayContent) { + super(context, wm, displayContent); } @Override @@ -120,7 +117,7 @@ public class BoundsAnimationControllerTests extends WindowTestsBase { /** * A test animate bounds user to track callbacks from the bounds animation. */ - private class TestBoundsAnimationTarget implements BoundsAnimationTarget { + private static class TestBoundsAnimationTarget implements BoundsAnimationTarget { boolean mAwaitingAnimationStart; boolean mMovedToFullscreen; @@ -193,21 +190,23 @@ public class BoundsAnimationControllerTests extends WindowTestsBase { /** * Drives the animations, makes common assertions along the way. */ - private class BoundsAnimationDriver { + private static class BoundsAnimationDriver { + + private final BoundsAnimationController mController; + private final TestBoundsAnimationTarget mTarget; + private final MockValueAnimator mMockAnimator; - private BoundsAnimationController mController; - private TestBoundsAnimationTarget mTarget; private BoundsAnimator mAnimator; - private Rect mFrom; private Rect mTo; private Rect mLargerBounds; private Rect mExpectedFinalBounds; BoundsAnimationDriver(BoundsAnimationController controller, - TestBoundsAnimationTarget target) { + TestBoundsAnimationTarget target, MockValueAnimator mockValueAnimator) { mController = controller; mTarget = target; + mMockAnimator = mockValueAnimator; } BoundsAnimationDriver start(Rect from, Rect to) { @@ -222,7 +221,7 @@ public class BoundsAnimationControllerTests extends WindowTestsBase { // Started, not running assertTrue(mTarget.mAwaitingAnimationStart); - assertTrue(!mTarget.mAnimationStarted); + assertFalse(mTarget.mAnimationStarted); startImpl(from, to); @@ -236,7 +235,7 @@ public class BoundsAnimationControllerTests extends WindowTestsBase { } // Started and running - assertTrue(!mTarget.mAwaitingAnimationStart); + assertFalse(mTarget.mAwaitingAnimationStart); assertTrue(mTarget.mAnimationStarted); return this; @@ -268,7 +267,7 @@ public class BoundsAnimationControllerTests extends WindowTestsBase { assertTrue(mTarget.mForcePipModeChangedCallback); } else { // No animation start for replacing animation - assertTrue(!mTarget.mAnimationStarted); + assertFalse(mTarget.mAnimationStarted); } mTarget.mAnimationStarted = true; return this; @@ -297,7 +296,7 @@ public class BoundsAnimationControllerTests extends WindowTestsBase { // Animating to larger size if (mFrom.equals(mLargerBounds)) { - assertTrue(!mAnimator.animatingToLargerSize()); + assertFalse(mAnimator.animatingToLargerSize()); } else if (mTo.equals(mLargerBounds)) { assertTrue(mAnimator.animatingToLargerSize()); } @@ -339,10 +338,10 @@ public class BoundsAnimationControllerTests extends WindowTestsBase { mAnimator.onAnimationUpdate(mMockAnimator.getWithValue(0.5f)); // Not started, not running, cancel reset - assertTrue(!mTarget.mCancelRequested); + assertFalse(mTarget.mCancelRequested); // Stack/task bounds not updated - assertTrue(!mTarget.mBoundsUpdated); + assertFalse(mTarget.mBoundsUpdated); // Callback made assertTrue(mTarget.mAnimationEnded); @@ -372,14 +371,10 @@ public class BoundsAnimationControllerTests extends WindowTestsBase { return this; } - private Rect getLargerBounds(Rect r1, Rect r2) { + private static Rect getLargerBounds(Rect r1, Rect r2) { int r1Area = r1.width() * r1.height(); int r2Area = r2.width() * r2.height(); - if (r1Area <= r2Area) { - return r2; - } else { - return r1; - } + return (r1Area <= r2Area) ? r2 : r1; } } @@ -395,32 +390,29 @@ public class BoundsAnimationControllerTests extends WindowTestsBase { // Common private MockAppTransition mMockAppTransition; - private MockValueAnimator mMockAnimator; private TestBoundsAnimationTarget mTarget; private BoundsAnimationController mController; private BoundsAnimationDriver mDriver; // Temp - private Rect mTmpRect = new Rect(); + private static final Rect sTmpRect = new Rect(); - @Override + @Before public void setUp() throws Exception { - super.setUp(); - - final Context context = InstrumentationRegistry.getTargetContext(); + final Context context = getInstrumentation().getTargetContext(); final Handler handler = new Handler(Looper.getMainLooper()); - mMockAppTransition = new MockAppTransition(context); - mMockAnimator = new MockValueAnimator(); + mMockAppTransition = new MockAppTransition(context, mWm, mDisplayContent); mTarget = new TestBoundsAnimationTarget(); mController = new BoundsAnimationController(context, mMockAppTransition, handler, null); - mDriver = new BoundsAnimationDriver(mController, mTarget); + final MockValueAnimator mockValueAnimator = new MockValueAnimator(); + mDriver = new BoundsAnimationDriver(mController, mTarget, mockValueAnimator); } /** BASE TRANSITIONS **/ @UiThreadTest @Test - public void testFullscreenToFloatingTransition() throws Exception { + public void testFullscreenToFloatingTransition() { mDriver.start(BOUNDS_FULL, BOUNDS_FLOATING) .expectStarted(!SCHEDULE_PIP_MODE_CHANGED) .update(0f) @@ -432,7 +424,7 @@ public class BoundsAnimationControllerTests extends WindowTestsBase { @UiThreadTest @Test - public void testFloatingToFullscreenTransition() throws Exception { + public void testFloatingToFullscreenTransition() { mDriver.start(BOUNDS_FLOATING, BOUNDS_FULL) .expectStarted(SCHEDULE_PIP_MODE_CHANGED) .update(0f) @@ -444,7 +436,7 @@ public class BoundsAnimationControllerTests extends WindowTestsBase { @UiThreadTest @Test - public void testFloatingToSmallerFloatingTransition() throws Exception { + public void testFloatingToSmallerFloatingTransition() { mDriver.start(BOUNDS_FLOATING, BOUNDS_SMALLER_FLOATING) .expectStarted(!SCHEDULE_PIP_MODE_CHANGED) .update(0f) @@ -456,7 +448,7 @@ public class BoundsAnimationControllerTests extends WindowTestsBase { @UiThreadTest @Test - public void testFloatingToLargerFloatingTransition() throws Exception { + public void testFloatingToLargerFloatingTransition() { mDriver.start(BOUNDS_SMALLER_FLOATING, BOUNDS_FLOATING) .expectStarted(!SCHEDULE_PIP_MODE_CHANGED) .update(0f) @@ -470,7 +462,7 @@ public class BoundsAnimationControllerTests extends WindowTestsBase { @UiThreadTest @Test - public void testFullscreenToFloatingCancelFromTarget() throws Exception { + public void testFullscreenToFloatingCancelFromTarget() { mDriver.start(BOUNDS_FULL, BOUNDS_FLOATING) .expectStarted(!SCHEDULE_PIP_MODE_CHANGED) .update(0.25f) @@ -480,7 +472,7 @@ public class BoundsAnimationControllerTests extends WindowTestsBase { @UiThreadTest @Test - public void testFullscreenToFloatingCancelFromAnimationToSameBounds() throws Exception { + public void testFullscreenToFloatingCancelFromAnimationToSameBounds() { mDriver.start(BOUNDS_FULL, BOUNDS_FLOATING) .expectStarted(!SCHEDULE_PIP_MODE_CHANGED) .update(0.25f) @@ -491,7 +483,7 @@ public class BoundsAnimationControllerTests extends WindowTestsBase { @UiThreadTest @Test - public void testFullscreenToFloatingCancelFromAnimationToFloatingBounds() throws Exception { + public void testFullscreenToFloatingCancelFromAnimationToFloatingBounds() { mDriver.start(BOUNDS_FULL, BOUNDS_FLOATING) .expectStarted(!SCHEDULE_PIP_MODE_CHANGED) .update(0.25f) @@ -503,7 +495,7 @@ public class BoundsAnimationControllerTests extends WindowTestsBase { @UiThreadTest @Test - public void testFullscreenToFloatingCancelFromAnimationToFullscreenBounds() throws Exception { + public void testFullscreenToFloatingCancelFromAnimationToFullscreenBounds() { // When animating from fullscreen and the animation is interruped, we expect the animation // start callback to be made, with a forced pip mode change callback mDriver.start(BOUNDS_FULL, BOUNDS_FLOATING) @@ -518,7 +510,7 @@ public class BoundsAnimationControllerTests extends WindowTestsBase { @UiThreadTest @Test - public void testFloatingToFullscreenCancelFromTarget() throws Exception { + public void testFloatingToFullscreenCancelFromTarget() { mDriver.start(BOUNDS_FLOATING, BOUNDS_FULL) .expectStarted(SCHEDULE_PIP_MODE_CHANGED) .update(0.25f) @@ -528,7 +520,7 @@ public class BoundsAnimationControllerTests extends WindowTestsBase { @UiThreadTest @Test - public void testFloatingToFullscreenCancelFromAnimationToSameBounds() throws Exception { + public void testFloatingToFullscreenCancelFromAnimationToSameBounds() { mDriver.start(BOUNDS_FLOATING, BOUNDS_FULL) .expectStarted(SCHEDULE_PIP_MODE_CHANGED) .update(0.25f) @@ -539,7 +531,7 @@ public class BoundsAnimationControllerTests extends WindowTestsBase { @UiThreadTest @Test - public void testFloatingToFullscreenCancelFromAnimationToFloatingBounds() throws Exception { + public void testFloatingToFullscreenCancelFromAnimationToFloatingBounds() { mDriver.start(BOUNDS_FLOATING, BOUNDS_FULL) .expectStarted(SCHEDULE_PIP_MODE_CHANGED) .update(0.25f) @@ -553,7 +545,7 @@ public class BoundsAnimationControllerTests extends WindowTestsBase { @UiThreadTest @Test - public void testFloatingToSmallerFloatingCancelFromTarget() throws Exception { + public void testFloatingToSmallerFloatingCancelFromTarget() { mDriver.start(BOUNDS_FLOATING, BOUNDS_SMALLER_FLOATING) .expectStarted(!SCHEDULE_PIP_MODE_CHANGED) .update(0.25f) @@ -563,7 +555,7 @@ public class BoundsAnimationControllerTests extends WindowTestsBase { @UiThreadTest @Test - public void testFloatingToLargerFloatingCancelFromTarget() throws Exception { + public void testFloatingToLargerFloatingCancelFromTarget() { mDriver.start(BOUNDS_SMALLER_FLOATING, BOUNDS_FLOATING) .expectStarted(!SCHEDULE_PIP_MODE_CHANGED) .update(0.25f) @@ -575,7 +567,7 @@ public class BoundsAnimationControllerTests extends WindowTestsBase { @UiThreadTest @Test - public void testBoundsAreCopied() throws Exception { + public void testBoundsAreCopied() { Rect from = new Rect(0, 0, 100, 100); Rect to = new Rect(25, 25, 75, 75); mDriver.start(from, to) @@ -588,9 +580,9 @@ public class BoundsAnimationControllerTests extends WindowTestsBase { /** * @return whether the task and stack bounds would be the same if they were at the same offset. */ - private boolean assertEqualSizeAtOffset(Rect stackBounds, Rect taskBounds) { - mTmpRect.set(taskBounds); - mTmpRect.offsetTo(stackBounds.left, stackBounds.top); - return stackBounds.equals(mTmpRect); + private static boolean assertEqualSizeAtOffset(Rect stackBounds, Rect taskBounds) { + sTmpRect.set(taskBounds); + sTmpRect.offsetTo(stackBounds.left, stackBounds.top); + return stackBounds.equals(sTmpRect); } } diff --git a/services/tests/servicestests/src/com/android/server/wm/DimmerTests.java b/services/tests/servicestests/src/com/android/server/wm/DimmerTests.java index 21555e38a7e80..b6a7cfba7dc47 100644 --- a/services/tests/servicestests/src/com/android/server/wm/DimmerTests.java +++ b/services/tests/servicestests/src/com/android/server/wm/DimmerTests.java @@ -11,7 +11,7 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License + * limitations under the License. */ package com.android.server.wm; @@ -32,26 +32,22 @@ import android.platform.test.annotations.Presubmit; import android.view.SurfaceControl; import android.view.SurfaceSession; -import androidx.test.runner.AndroidJUnit4; - import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; /** * Build/Install/Run: - * atest FrameworksServicesTests:com.android.server.wm.DimmerTests; + * atest FrameworksServicesTests:DimmerTests; */ @Presubmit -@RunWith(AndroidJUnit4.class) public class DimmerTests extends WindowTestsBase { - private class TestWindowContainer extends WindowContainer { + private static class TestWindowContainer extends WindowContainer { final SurfaceControl mControl = mock(SurfaceControl.class); final SurfaceControl.Transaction mTransaction = mock(SurfaceControl.Transaction.class); - TestWindowContainer() { - super(sWm); + TestWindowContainer(WindowManagerService wm) { + super(wm); } @Override @@ -65,13 +61,13 @@ public class DimmerTests extends WindowTestsBase { } } - private class MockSurfaceBuildingContainer extends WindowContainer { + private static class MockSurfaceBuildingContainer extends WindowContainer { final SurfaceSession mSession = new SurfaceSession(); final SurfaceControl mHostControl = mock(SurfaceControl.class); final SurfaceControl.Transaction mHostTransaction = mock(SurfaceControl.Transaction.class); - MockSurfaceBuildingContainer() { - super(sWm); + MockSurfaceBuildingContainer(WindowManagerService wm) { + super(wm); } class MockSurfaceBuilder extends SurfaceControl.Builder { @@ -116,15 +112,14 @@ public class DimmerTests extends WindowTestsBase { @Before public void setUp() throws Exception { - super.setUp(); - mHost = new MockSurfaceBuildingContainer(); + mHost = new MockSurfaceBuildingContainer(mWm); mSurfaceAnimatorStarter = spy(new SurfaceAnimatorStarterImpl()); mTransaction = mock(SurfaceControl.Transaction.class); mDimmer = new Dimmer(mHost, mSurfaceAnimatorStarter); } @Test - public void testDimAboveNoChildCreatesSurface() throws Exception { + public void testDimAboveNoChildCreatesSurface() { final float alpha = 0.8f; mDimmer.dimAbove(mTransaction, alpha); @@ -137,7 +132,7 @@ public class DimmerTests extends WindowTestsBase { } @Test - public void testDimAboveNoChildRedundantlyUpdatesAlphaOnExistingSurface() throws Exception { + public void testDimAboveNoChildRedundantlyUpdatesAlphaOnExistingSurface() { float alpha = 0.8f; mDimmer.dimAbove(mTransaction, alpha); final SurfaceControl firstSurface = getDimLayer(); @@ -150,7 +145,7 @@ public class DimmerTests extends WindowTestsBase { } @Test - public void testUpdateDimsAppliesSize() throws Exception { + public void testUpdateDimsAppliesSize() { mDimmer.dimAbove(mTransaction, 0.8f); int width = 100; @@ -163,7 +158,7 @@ public class DimmerTests extends WindowTestsBase { } @Test - public void testDimAboveNoChildNotReset() throws Exception { + public void testDimAboveNoChildNotReset() { mDimmer.dimAbove(mTransaction, 0.8f); SurfaceControl dimLayer = getDimLayer(); mDimmer.resetDimStates(); @@ -174,8 +169,8 @@ public class DimmerTests extends WindowTestsBase { } @Test - public void testDimAboveWithChildCreatesSurfaceAboveChild() throws Exception { - TestWindowContainer child = new TestWindowContainer(); + public void testDimAboveWithChildCreatesSurfaceAboveChild() { + TestWindowContainer child = new TestWindowContainer(mWm); mHost.addChild(child, 0); final float alpha = 0.8f; @@ -189,8 +184,8 @@ public class DimmerTests extends WindowTestsBase { } @Test - public void testDimBelowWithChildSurfaceCreatesSurfaceBelowChild() throws Exception { - TestWindowContainer child = new TestWindowContainer(); + public void testDimBelowWithChildSurfaceCreatesSurfaceBelowChild() { + TestWindowContainer child = new TestWindowContainer(mWm); mHost.addChild(child, 0); final float alpha = 0.8f; @@ -204,8 +199,8 @@ public class DimmerTests extends WindowTestsBase { } @Test - public void testDimBelowWithChildSurfaceDestroyedWhenReset() throws Exception { - TestWindowContainer child = new TestWindowContainer(); + public void testDimBelowWithChildSurfaceDestroyedWhenReset() { + TestWindowContainer child = new TestWindowContainer(mWm); mHost.addChild(child, 0); final float alpha = 0.8f; @@ -220,8 +215,8 @@ public class DimmerTests extends WindowTestsBase { } @Test - public void testDimBelowWithChildSurfaceNotDestroyedWhenPersisted() throws Exception { - TestWindowContainer child = new TestWindowContainer(); + public void testDimBelowWithChildSurfaceNotDestroyedWhenPersisted() { + TestWindowContainer child = new TestWindowContainer(mWm); mHost.addChild(child, 0); final float alpha = 0.8f; @@ -236,9 +231,9 @@ public class DimmerTests extends WindowTestsBase { } @Test - public void testDimUpdateWhileDimming() throws Exception { + public void testDimUpdateWhileDimming() { Rect bounds = new Rect(); - TestWindowContainer child = new TestWindowContainer(); + TestWindowContainer child = new TestWindowContainer(mWm); mHost.addChild(child, 0); final float alpha = 0.8f; @@ -258,8 +253,8 @@ public class DimmerTests extends WindowTestsBase { } @Test - public void testRemoveDimImmediately() throws Exception { - TestWindowContainer child = new TestWindowContainer(); + public void testRemoveDimImmediately() { + TestWindowContainer child = new TestWindowContainer(mWm); mHost.addChild(child, 0); mDimmer.dimAbove(mTransaction, child, 1); diff --git a/services/tests/servicestests/src/com/android/server/wm/DisplayContentTests.java b/services/tests/servicestests/src/com/android/server/wm/DisplayContentTests.java index 8b75570a8b291..dd374e959a63f 100644 --- a/services/tests/servicestests/src/com/android/server/wm/DisplayContentTests.java +++ b/services/tests/servicestests/src/com/android/server/wm/DisplayContentTests.java @@ -11,7 +11,7 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License + * limitations under the License. */ package com.android.server.wm; @@ -53,7 +53,6 @@ import android.graphics.Rect; import android.os.SystemClock; import android.platform.test.annotations.Presubmit; import android.util.DisplayMetrics; -import android.util.SparseIntArray; import android.view.DisplayCutout; import android.view.Gravity; import android.view.MotionEvent; @@ -61,12 +60,10 @@ import android.view.Surface; import androidx.test.filters.FlakyTest; import androidx.test.filters.SmallTest; -import androidx.test.runner.AndroidJUnit4; import com.android.server.wm.utils.WmDisplayCutout; import org.junit.Test; -import org.junit.runner.RunWith; import java.util.ArrayList; import java.util.Arrays; @@ -78,16 +75,15 @@ import java.util.List; * Tests for the {@link DisplayContent} class. * * Build/Install/Run: - * atest com.android.server.wm.DisplayContentTests + * atest FrameworksServicesTests:DisplayContentTests */ @SmallTest @Presubmit -@RunWith(AndroidJUnit4.class) public class DisplayContentTests extends WindowTestsBase { @Test @FlakyTest(bugId = 77772044) - public void testForAllWindows() throws Exception { + public void testForAllWindows() { final WindowState exitingAppWindow = createWindow(null, TYPE_BASE_APPLICATION, mDisplayContent, "exiting app"); final AppWindowToken exitingAppToken = exitingAppWindow.mAppToken; @@ -108,11 +104,11 @@ public class DisplayContentTests extends WindowTestsBase { } @Test - public void testForAllWindows_WithAppImeTarget() throws Exception { + public void testForAllWindows_WithAppImeTarget() { final WindowState imeAppTarget = createWindow(null, TYPE_BASE_APPLICATION, mDisplayContent, "imeAppTarget"); - sWm.mInputMethodTarget = imeAppTarget; + mWm.mInputMethodTarget = imeAppTarget; assertForAllWindowsOrder(Arrays.asList( mWallpaperWindow, @@ -128,8 +124,8 @@ public class DisplayContentTests extends WindowTestsBase { } @Test - public void testForAllWindows_WithChildWindowImeTarget() throws Exception { - sWm.mInputMethodTarget = mChildAppWindowAbove; + public void testForAllWindows_WithChildWindowImeTarget() { + mWm.mInputMethodTarget = mChildAppWindowAbove; assertForAllWindowsOrder(Arrays.asList( mWallpaperWindow, @@ -144,8 +140,8 @@ public class DisplayContentTests extends WindowTestsBase { } @Test - public void testForAllWindows_WithStatusBarImeTarget() throws Exception { - sWm.mInputMethodTarget = mStatusBarWindow; + public void testForAllWindows_WithStatusBarImeTarget() { + mWm.mInputMethodTarget = mStatusBarWindow; assertForAllWindowsOrder(Arrays.asList( mWallpaperWindow, @@ -160,7 +156,7 @@ public class DisplayContentTests extends WindowTestsBase { } @Test - public void testForAllWindows_WithInBetweenWindowToken() throws Exception { + public void testForAllWindows_WithInBetweenWindowToken() { // This window is set-up to be z-ordered between some windows that go in the same token like // the nav bar and status bar. final WindowState voiceInteractionWindow = createWindow(null, TYPE_VOICE_INTERACTION, @@ -180,7 +176,7 @@ public class DisplayContentTests extends WindowTestsBase { } @Test - public void testComputeImeTarget() throws Exception { + public void testComputeImeTarget() { // Verify that an app window can be an ime target. final WindowState appWin = createWindow(null, TYPE_APPLICATION, mDisplayContent, "appWin"); appWin.setHasSurface(true); @@ -203,7 +199,7 @@ public class DisplayContentTests extends WindowTestsBase { * container references updates. */ @Test - public void testMoveStackBetweenDisplays() throws Exception { + public void testMoveStackBetweenDisplays() { // Create a second display. final DisplayContent dc = createNewDisplay(); @@ -233,7 +229,7 @@ public class DisplayContentTests extends WindowTestsBase { * This tests override configuration updates for display content. */ @Test - public void testDisplayOverrideConfigUpdate() throws Exception { + public void testDisplayOverrideConfigUpdate() { final int displayId = mDisplayContent.getDisplayId(); final Configuration currentOverrideConfig = mDisplayContent.getOverrideConfiguration(); @@ -242,7 +238,7 @@ public class DisplayContentTests extends WindowTestsBase { newOverrideConfig.densityDpi += 120; newOverrideConfig.fontScale += 0.3; - sWm.setNewDisplayOverrideConfiguration(newOverrideConfig, displayId); + mWm.setNewDisplayOverrideConfiguration(newOverrideConfig, displayId); // Check that override config is applied. assertEquals(newOverrideConfig, mDisplayContent.getOverrideConfiguration()); @@ -252,7 +248,7 @@ public class DisplayContentTests extends WindowTestsBase { * This tests global configuration updates when default display config is updated. */ @Test - public void testDefaultDisplayOverrideConfigUpdate() throws Exception { + public void testDefaultDisplayOverrideConfigUpdate() { final Configuration currentConfig = mDisplayContent.getConfiguration(); // Create new, slightly changed override configuration and apply it to the display. @@ -260,16 +256,16 @@ public class DisplayContentTests extends WindowTestsBase { newOverrideConfig.densityDpi += 120; newOverrideConfig.fontScale += 0.3; - sWm.setNewDisplayOverrideConfiguration(newOverrideConfig, DEFAULT_DISPLAY); + mWm.setNewDisplayOverrideConfiguration(newOverrideConfig, DEFAULT_DISPLAY); // Check that global configuration is updated, as we've updated default display's config. - Configuration globalConfig = sWm.mRoot.getConfiguration(); + Configuration globalConfig = mWm.mRoot.getConfiguration(); assertEquals(newOverrideConfig.densityDpi, globalConfig.densityDpi); assertEquals(newOverrideConfig.fontScale, globalConfig.fontScale, 0.1 /* delta */); // Return back to original values. - sWm.setNewDisplayOverrideConfiguration(currentConfig, DEFAULT_DISPLAY); - globalConfig = sWm.mRoot.getConfiguration(); + mWm.setNewDisplayOverrideConfiguration(currentConfig, DEFAULT_DISPLAY); + globalConfig = mWm.mRoot.getConfiguration(); assertEquals(currentConfig.densityDpi, globalConfig.densityDpi); assertEquals(currentConfig.fontScale, globalConfig.fontScale, 0.1 /* delta */); } @@ -278,8 +274,8 @@ public class DisplayContentTests extends WindowTestsBase { * Tests tapping on a stack in different display results in window gaining focus. */ @Test - public void testInputEventBringsCorrectDisplayInFocus() throws Exception { - DisplayContent dc0 = sWm.getDefaultDisplayContentLocked(); + public void testInputEventBringsCorrectDisplayInFocus() { + DisplayContent dc0 = mWm.getDefaultDisplayContentLocked(); // Create a second display final DisplayContent dc1 = createNewDisplay(); @@ -303,51 +299,51 @@ public class DisplayContentTests extends WindowTestsBase { // tap on primary display. tapOnDisplay(dc0); // Check focus is on primary display. - assertEquals(sWm.mRoot.getTopFocusedDisplayContent().mCurrentFocus, + assertEquals(mWm.mRoot.getTopFocusedDisplayContent().mCurrentFocus, dc0.findFocusedWindow()); // Tap on secondary display. tapOnDisplay(dc1); // Check focus is on secondary. - assertEquals(sWm.mRoot.getTopFocusedDisplayContent().mCurrentFocus, + assertEquals(mWm.mRoot.getTopFocusedDisplayContent().mCurrentFocus, dc1.findFocusedWindow()); } @Test - public void testFocusedWindowMultipleDisplays() throws Exception { + public void testFocusedWindowMultipleDisplays() { // Create a focusable window and check that focus is calculated correctly final WindowState window1 = createWindow(null, TYPE_BASE_APPLICATION, mDisplayContent, "window1"); updateFocusedWindow(); assertTrue(window1.isFocused()); - assertEquals(window1, sWm.mRoot.getTopFocusedDisplayContent().mCurrentFocus); + assertEquals(window1, mWm.mRoot.getTopFocusedDisplayContent().mCurrentFocus); // Check that a new display doesn't affect focus final DisplayContent dc = createNewDisplay(); updateFocusedWindow(); assertTrue(window1.isFocused()); - assertEquals(window1, sWm.mRoot.getTopFocusedDisplayContent().mCurrentFocus); + assertEquals(window1, mWm.mRoot.getTopFocusedDisplayContent().mCurrentFocus); // Add a window to the second display, and it should be focused final WindowState window2 = createWindow(null, TYPE_BASE_APPLICATION, dc, "window2"); updateFocusedWindow(); assertTrue(window1.isFocused()); assertTrue(window2.isFocused()); - assertEquals(window2, sWm.mRoot.getTopFocusedDisplayContent().mCurrentFocus); + assertEquals(window2, mWm.mRoot.getTopFocusedDisplayContent().mCurrentFocus); // Move the first window to the to including parents, and make sure focus is updated window1.getParent().positionChildAt(POSITION_TOP, window1, true); updateFocusedWindow(); assertTrue(window1.isFocused()); assertTrue(window2.isFocused()); - assertEquals(window1, sWm.mRoot.getTopFocusedDisplayContent().mCurrentFocus); + assertEquals(window1, mWm.mRoot.getTopFocusedDisplayContent().mCurrentFocus); } /** * This tests setting the maximum ui width on a display. */ @Test - public void testMaxUiWidth() throws Exception { + public void testMaxUiWidth() { // Prevent base display metrics for test from being updated to the value of real display. final DisplayContent displayContent = createDisplayNoUpdateDisplayInfo(); final int baseWidth = 1440; @@ -439,8 +435,8 @@ public class DisplayContentTests extends WindowTestsBase { } @Test - public void testDisplayCutout_rot0() throws Exception { - synchronized (sWm.getWindowManagerLock()) { + public void testDisplayCutout_rot0() { + synchronized (mWm.getWindowManagerLock()) { final DisplayContent dc = createNewDisplay(); dc.mInitialDisplayWidth = 200; dc.mInitialDisplayHeight = 400; @@ -458,8 +454,8 @@ public class DisplayContentTests extends WindowTestsBase { } @Test - public void testDisplayCutout_rot90() throws Exception { - synchronized (sWm.getWindowManagerLock()) { + public void testDisplayCutout_rot90() { + synchronized (mWm.getWindowManagerLock()) { // Prevent mInitialDisplayCutout from being updated from real display (e.g. null // if the device has no cutout). final DisplayContent dc = createDisplayNoUpdateDisplayInfo(); @@ -476,7 +472,8 @@ public class DisplayContentTests extends WindowTestsBase { final Rect r1 = new Rect(left, top, right, bottom); final DisplayCutout cutout = new WmDisplayCutout( - fromBoundingRect(r1.left, r1.top, r1.right, r1.bottom, BOUNDS_POSITION_TOP), null) + fromBoundingRect(r1.left, r1.top, r1.right, r1.bottom, BOUNDS_POSITION_TOP), + null) .computeSafeInsets(displayWidth, displayHeight).getDisplayCutout(); dc.mInitialDisplayCutout = cutout; @@ -500,8 +497,8 @@ public class DisplayContentTests extends WindowTestsBase { } @Test - public void testLayoutSeq_assignedDuringLayout() throws Exception { - synchronized (sWm.getWindowManagerLock()) { + public void testLayoutSeq_assignedDuringLayout() { + synchronized (mWm.getWindowManagerLock()) { final DisplayContent dc = createNewDisplay(); final WindowState win = createWindow(null /* parent */, TYPE_BASE_APPLICATION, dc, "w"); @@ -533,7 +530,7 @@ public class DisplayContentTests extends WindowTestsBase { assertEquals("Visible keyguard must influence device orientation", SCREEN_ORIENTATION_PORTRAIT, dc.getOrientation()); - sWm.setKeyguardGoingAway(true); + mWm.setKeyguardGoingAway(true); assertEquals("Keyguard that is going away must not influence device orientation", SCREEN_ORIENTATION_LANDSCAPE, dc.getOrientation()); } @@ -543,10 +540,10 @@ public class DisplayContentTests extends WindowTestsBase { final DisplayContent dc = createNewDisplay(); assertTrue(dc.mShouldOverrideDisplayConfiguration); - sWm.dontOverrideDisplayInfo(dc.getDisplayId()); + mWm.dontOverrideDisplayInfo(dc.getDisplayId()); assertFalse(dc.mShouldOverrideDisplayConfiguration); - verify(sWm.mDisplayManagerInternal, times(1)) + verify(mWm.mDisplayManagerInternal, times(1)) .setDisplayInfoOverrideFromWindowManager(dc.getDisplayId(), null); } @@ -572,7 +569,7 @@ public class DisplayContentTests extends WindowTestsBase { } private boolean isOptionsPanelAtRight(int displayId) { - return (sWm.getPreferredOptionsPanelGravity(displayId) & Gravity.RIGHT) == Gravity.RIGHT; + return (mWm.getPreferredOptionsPanelGravity(displayId) & Gravity.RIGHT) == Gravity.RIGHT; } private static void verifySizes(DisplayContent displayContent, int expectedBaseWidth, @@ -583,8 +580,8 @@ public class DisplayContentTests extends WindowTestsBase { } private void updateFocusedWindow() { - synchronized (sWm.mGlobalLock) { - sWm.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false); + synchronized (mWm.mGlobalLock) { + mWm.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false); } } diff --git a/services/tests/servicestests/src/com/android/server/wm/DisplaySettingsTests.java b/services/tests/servicestests/src/com/android/server/wm/DisplaySettingsTests.java index 3be125815d210..f0c49c8ab0b37 100644 --- a/services/tests/servicestests/src/com/android/server/wm/DisplaySettingsTests.java +++ b/services/tests/servicestests/src/com/android/server/wm/DisplaySettingsTests.java @@ -12,11 +12,12 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ package com.android.server.wm; +import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; @@ -31,15 +32,13 @@ import android.view.Display; import android.view.DisplayInfo; import android.view.Surface; -import androidx.test.InstrumentationRegistry; import androidx.test.filters.SmallTest; -import androidx.test.runner.AndroidJUnit4; import com.android.server.policy.WindowManagerPolicy; +import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; import java.io.File; @@ -47,14 +46,13 @@ import java.io.File; * Tests for the {@link DisplaySettings} class. * * Build/Install/Run: - * atest FrameworksServicesTests:com.android.server.wm.DisplaySettingsTests + * atest FrameworksServicesTests:DisplaySettingsTests */ @SmallTest @Presubmit -@RunWith(AndroidJUnit4.class) public class DisplaySettingsTests extends WindowTestsBase { - private File mTestFolder; + private static final File TEST_FOLDER = getInstrumentation().getTargetContext().getCacheDir(); private DisplaySettings mTarget; private DisplayContent mPrimaryDisplay; @@ -62,21 +60,23 @@ public class DisplaySettingsTests extends WindowTestsBase { @Before public void setUp() throws Exception { - super.setUp(); + deleteRecursively(TEST_FOLDER); - mTestFolder = InstrumentationRegistry.getContext().getCacheDir(); - deleteRecursively(mTestFolder); + mWm.setSupportsFreeformWindowManagement(false); + mWm.setIsPc(false); - sWm.setSupportsFreeformWindowManagement(false); - sWm.setIsPc(false); + mTarget = new DisplaySettings(mWm, TEST_FOLDER); - mTarget = new DisplaySettings(sWm, mTestFolder); - - mPrimaryDisplay = sWm.getDefaultDisplayContentLocked(); + mPrimaryDisplay = mWm.getDefaultDisplayContentLocked(); mSecondaryDisplay = mDisplayContent; assertNotEquals(Display.DEFAULT_DISPLAY, mSecondaryDisplay.getDisplayId()); } + @After + public void tearDown() { + deleteRecursively(TEST_FOLDER); + } + @Test public void testPrimaryDisplayDefaultToFullscreenWithoutFreeformSupport() { mTarget.applySettingsToDisplayLocked(mPrimaryDisplay); @@ -87,7 +87,7 @@ public class DisplaySettingsTests extends WindowTestsBase { @Test public void testPrimaryDisplayDefaultToFullscreenWithFreeformSupportNonPc() { - sWm.setSupportsFreeformWindowManagement(true); + mWm.setSupportsFreeformWindowManagement(true); mTarget.applySettingsToDisplayLocked(mPrimaryDisplay); @@ -97,8 +97,8 @@ public class DisplaySettingsTests extends WindowTestsBase { @Test public void testPrimaryDisplayDefaultToFreeformWithFreeformIsPc() { - sWm.setSupportsFreeformWindowManagement(true); - sWm.setIsPc(true); + mWm.setSupportsFreeformWindowManagement(true); + mWm.setIsPc(true); mTarget.applySettingsToDisplayLocked(mPrimaryDisplay); @@ -116,7 +116,7 @@ public class DisplaySettingsTests extends WindowTestsBase { @Test public void testSecondaryDisplayDefaultToFreeformWithFreeformSupportNonPc() { - sWm.setSupportsFreeformWindowManagement(true); + mWm.setSupportsFreeformWindowManagement(true); mTarget.applySettingsToDisplayLocked(mSecondaryDisplay); @@ -126,8 +126,8 @@ public class DisplaySettingsTests extends WindowTestsBase { @Test public void testSecondaryDisplayDefaultToFreeformWithFreeformSupportIsPc() { - sWm.setSupportsFreeformWindowManagement(true); - sWm.setIsPc(true); + mWm.setSupportsFreeformWindowManagement(true); + mWm.setIsPc(true); mTarget.applySettingsToDisplayLocked(mSecondaryDisplay); @@ -157,7 +157,7 @@ public class DisplaySettingsTests extends WindowTestsBase { doAnswer(invocation -> { ((DisplayInfo) invocation.getArguments()[1]).copyFrom(originalInfo); return null; - }).when(sWm.mDisplayManagerInternal).getNonOverrideDisplayInfo(anyInt(), any()); + }).when(mWm.mDisplayManagerInternal).getNonOverrideDisplayInfo(anyInt(), any()); mTarget.setForcedSize(mSecondaryDisplay, 1000 /* width */, 2000 /* height */); applySettingsToDisplayByNewInstance(mSecondaryDisplay); @@ -165,7 +165,7 @@ public class DisplaySettingsTests extends WindowTestsBase { assertEquals(1000 /* width */, mSecondaryDisplay.mBaseDisplayWidth); assertEquals(2000 /* height */, mSecondaryDisplay.mBaseDisplayHeight); - sWm.clearForcedDisplaySize(mSecondaryDisplay.getDisplayId()); + mWm.clearForcedDisplaySize(mSecondaryDisplay.getDisplayId()); assertEquals(mSecondaryDisplay.mInitialDisplayWidth, mSecondaryDisplay.mBaseDisplayWidth); assertEquals(mSecondaryDisplay.mInitialDisplayHeight, mSecondaryDisplay.mBaseDisplayHeight); } @@ -177,7 +177,7 @@ public class DisplaySettingsTests extends WindowTestsBase { assertEquals(600 /* density */, mSecondaryDisplay.mBaseDisplayDensity); - sWm.clearForcedDisplayDensityForUser(mSecondaryDisplay.getDisplayId(), 0 /* userId */); + mWm.clearForcedDisplayDensityForUser(mSecondaryDisplay.getDisplayId(), 0 /* userId */); assertEquals(mSecondaryDisplay.mInitialDisplayDensity, mSecondaryDisplay.mBaseDisplayDensity); } @@ -189,7 +189,7 @@ public class DisplaySettingsTests extends WindowTestsBase { assertTrue(mSecondaryDisplay.mDisplayScalingDisabled); - sWm.setForcedDisplayScalingMode(mSecondaryDisplay.getDisplayId(), + mWm.setForcedDisplayScalingMode(mSecondaryDisplay.getDisplayId(), DisplayContent.FORCE_SCALING_MODE_AUTO); assertFalse(mSecondaryDisplay.mDisplayScalingDisabled); } @@ -298,20 +298,20 @@ public class DisplaySettingsTests extends WindowTestsBase { * that also means the previous state must be written correctly. */ private void applySettingsToDisplayByNewInstance(DisplayContent display) { - new DisplaySettings(sWm, mTestFolder).applySettingsToDisplayLocked(display); + new DisplaySettings(mWm, TEST_FOLDER).applySettingsToDisplayLocked(display); } private static boolean deleteRecursively(File file) { + boolean fullyDeleted = true; if (file.isFile()) { return file.delete(); + } else if (file.isDirectory()) { + final File[] files = file.listFiles(); + for (File child : files) { + fullyDeleted &= deleteRecursively(child); + } + fullyDeleted &= file.delete(); } - - boolean fullyDeleted = true; - final File[] files = file.listFiles(); - for (File child : files) { - fullyDeleted &= deleteRecursively(child); - } - fullyDeleted &= file.delete(); return fullyDeleted; } } diff --git a/services/tests/servicestests/src/com/android/server/wm/DragDropControllerTests.java b/services/tests/servicestests/src/com/android/server/wm/DragDropControllerTests.java index 31b2fefed420b..55e766da09fc6 100644 --- a/services/tests/servicestests/src/com/android/server/wm/DragDropControllerTests.java +++ b/services/tests/servicestests/src/com/android/server/wm/DragDropControllerTests.java @@ -11,7 +11,7 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License + * limitations under the License. */ package com.android.server.wm; @@ -40,23 +40,24 @@ import android.view.SurfaceControl; import android.view.SurfaceSession; import android.view.View; -import com.android.internal.annotations.GuardedBy; +import androidx.test.filters.SmallTest; + import com.android.server.LocalServices; import org.junit.After; +import org.junit.AfterClass; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; -import androidx.test.filters.SmallTest; - /** * Tests for the {@link DragDropController} class. * * Build/Install/Run: - * atest FrameworksServicesTests:com.android.server.wm.DragDropControllerTests + * atest FrameworksServicesTests:DragDropControllerTests */ @SmallTest @Presubmit @@ -67,7 +68,6 @@ public class DragDropControllerTests extends WindowTestsBase { private IBinder mToken; static class TestDragDropController extends DragDropController { - @GuardedBy("sWm.mWindowMap") private Runnable mCloseCallback; TestDragDropController(WindowManagerService service, Looper looper) { @@ -107,31 +107,34 @@ public class DragDropControllerTests extends WindowTestsBase { return window; } - @Override - @Before - public void setUp() throws Exception { + @BeforeClass + public static void setUpOnce() { final UserManagerInternal userManager = mock(UserManagerInternal.class); LocalServices.addService(UserManagerInternal.class, userManager); + } - super.setUp(); + @AfterClass + public static void tearDownOnce() { + LocalServices.removeServiceForTest(UserManagerInternal.class); + } - mTarget = new TestDragDropController(sWm, sWm.mH.getLooper()); + @Before + public void setUp() throws Exception { + mTarget = new TestDragDropController(mWm, mWm.mH.getLooper()); mDisplayContent = spy(mDisplayContent); mWindow = createDropTargetWindow("Drag test window", 0); doReturn(mWindow).when(mDisplayContent).getTouchableWinAtPointLocked(0, 0); - when(sWm.mInputManager.transferTouchFocus(any(), any())).thenReturn(true); + when(mWm.mInputManager.transferTouchFocus(any(), any())).thenReturn(true); - synchronized (sWm.mGlobalLock) { - sWm.mWindowMap.put(mWindow.mClient.asBinder(), mWindow); + synchronized (mWm.mGlobalLock) { + mWm.mWindowMap.put(mWindow.mClient.asBinder(), mWindow); } } - @Override @After public void tearDown() throws Exception { - LocalServices.removeServiceForTest(UserManagerInternal.class); final CountDownLatch latch; - synchronized (sWm.mGlobalLock) { + synchronized (mWm.mGlobalLock) { if (!mTarget.dragDropActiveLocked()) { return; } @@ -142,8 +145,6 @@ public class DragDropControllerTests extends WindowTestsBase { mTarget.setOnClosedCallbackLocked(latch::countDown); } assertTrue(latch.await(TIMEOUT_MS, TimeUnit.MILLISECONDS)); - - super.tearDown(); } @Test @@ -174,7 +175,7 @@ public class DragDropControllerTests extends WindowTestsBase { .setFormat(PixelFormat.TRANSLUCENT) .build(); - assertTrue(sWm.mInputManager.transferTouchFocus(null, null)); + assertTrue(mWm.mInputManager.transferTouchFocus(null, null)); mToken = mTarget.performDrag( new SurfaceSession(), 0, 0, mWindow.mClient, flag, surface, 0, 0, 0, 0, 0, data); diff --git a/services/tests/servicestests/src/com/android/server/wm/PinnedStackControllerTest.java b/services/tests/servicestests/src/com/android/server/wm/PinnedStackControllerTest.java index 7222a999e23cb..1fae317f3af8e 100644 --- a/services/tests/servicestests/src/com/android/server/wm/PinnedStackControllerTest.java +++ b/services/tests/servicestests/src/com/android/server/wm/PinnedStackControllerTest.java @@ -1,3 +1,19 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.android.server.wm; import static android.view.Display.DEFAULT_DISPLAY; @@ -16,17 +32,18 @@ import android.platform.test.annotations.Presubmit; import android.view.IPinnedStackListener; import androidx.test.filters.SmallTest; -import androidx.test.runner.AndroidJUnit4; import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +/** + * Build/Install/Run: + * atest FrameworksServicesTests:PinnedStackControllerTest + */ @SmallTest @Presubmit -@RunWith(AndroidJUnit4.class) public class PinnedStackControllerTest extends WindowTestsBase { @Mock private IPinnedStackListener mIPinnedStackListener; @@ -34,15 +51,15 @@ public class PinnedStackControllerTest extends WindowTestsBase { @Before public void setUp() throws Exception { - super.setUp(); MockitoAnnotations.initMocks(this); + when(mIPinnedStackListener.asBinder()).thenReturn(mIPinnedStackListenerStub); } @Test public void setShelfHeight_shelfVisibilityChangedTriggered() throws RemoteException { - sWm.mSupportsPictureInPicture = true; - sWm.registerPinnedStackListener(DEFAULT_DISPLAY, mIPinnedStackListener); + mWm.mSupportsPictureInPicture = true; + mWm.registerPinnedStackListener(DEFAULT_DISPLAY, mIPinnedStackListener); verify(mIPinnedStackListener).onImeVisibilityChanged(false, 0); verify(mIPinnedStackListener).onShelfVisibilityChanged(false, 0); @@ -55,7 +72,7 @@ public class PinnedStackControllerTest extends WindowTestsBase { final int SHELF_HEIGHT = 300; - sWm.setShelfHeight(true, SHELF_HEIGHT); + mWm.setShelfHeight(true, SHELF_HEIGHT); verify(mIPinnedStackListener).onShelfVisibilityChanged(true, SHELF_HEIGHT); verify(mIPinnedStackListener).onMovementBoundsChanged(any(), any(), any(), eq(false), eq(true), anyInt()); diff --git a/services/tests/servicestests/src/com/android/server/wm/RecentsAnimationControllerTest.java b/services/tests/servicestests/src/com/android/server/wm/RecentsAnimationControllerTest.java index 088e22972cc9f..fe5fc068a36b7 100644 --- a/services/tests/servicestests/src/com/android/server/wm/RecentsAnimationControllerTest.java +++ b/services/tests/servicestests/src/com/android/server/wm/RecentsAnimationControllerTest.java @@ -11,7 +11,7 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License + * limitations under the License. */ package com.android.server.wm; @@ -24,9 +24,9 @@ import static android.view.Display.DEFAULT_DISPLAY; import static com.android.server.wm.RecentsAnimationController.REORDER_KEEP_IN_PLACE; import static com.android.server.wm.RecentsAnimationController.REORDER_MOVE_TO_ORIGINAL_POSITION; -import static org.junit.Assert.fail; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.verify; @@ -42,22 +42,20 @@ import android.view.SurfaceControl; import androidx.test.filters.FlakyTest; import androidx.test.filters.SmallTest; -import androidx.test.runner.AndroidJUnit4; import com.android.server.wm.SurfaceAnimator.OnAnimationFinishedCallback; import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.MockitoAnnotations; /** - * atest FrameworksServicesTests:com.android.server.wm.RecentsAnimationControllerTest + * Build/Install/Run: + * atest FrameworksServicesTests:RecentsAnimationControllerTest */ @SmallTest @Presubmit -@RunWith(AndroidJUnit4.class) public class RecentsAnimationControllerTest extends WindowTestsBase { @Mock SurfaceControl mMockLeash; @@ -69,10 +67,10 @@ public class RecentsAnimationControllerTest extends WindowTestsBase { @Before public void setUp() throws Exception { - super.setUp(); MockitoAnnotations.initMocks(this); + when(mMockRunner.asBinder()).thenReturn(new Binder()); - mController = new RecentsAnimationController(sWm, mMockRunner, mAnimationCallbacks, + mController = new RecentsAnimationController(mWm, mMockRunner, mAnimationCallbacks, DEFAULT_DISPLAY); } @@ -96,7 +94,7 @@ public class RecentsAnimationControllerTest extends WindowTestsBase { } @Test - public void testCancelAfterRemove_expectIgnored() throws Exception { + public void testCancelAfterRemove_expectIgnored() { final AppWindowToken appWindow = createAppWindowToken(mDisplayContent, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD); AnimationAdapter adapter = mController.addAnimation(appWindow.getTask(), @@ -114,10 +112,10 @@ public class RecentsAnimationControllerTest extends WindowTestsBase { } } - @Test @FlakyTest(bugId = 117117823) - public void testIncludedApps_expectTargetAndVisible() throws Exception { - sWm.setRecentsAnimationController(mController); + @Test + public void testIncludedApps_expectTargetAndVisible() { + mWm.setRecentsAnimationController(mController); final AppWindowToken homeAppWindow = createAppWindowToken(mDisplayContent, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME); final AppWindowToken appWindow = createAppWindowToken(mDisplayContent, diff --git a/services/tests/servicestests/src/com/android/server/wm/RemoteAnimationControllerTest.java b/services/tests/servicestests/src/com/android/server/wm/RemoteAnimationControllerTest.java index ae92984ebf65b..fa5379576e8b8 100644 --- a/services/tests/servicestests/src/com/android/server/wm/RemoteAnimationControllerTest.java +++ b/services/tests/servicestests/src/com/android/server/wm/RemoteAnimationControllerTest.java @@ -11,7 +11,7 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License + * limitations under the License. */ package com.android.server.wm; @@ -39,7 +39,6 @@ import android.view.SurfaceControl; import android.view.SurfaceControl.Transaction; import androidx.test.filters.SmallTest; -import androidx.test.runner.AndroidJUnit4; import com.android.server.testutils.OffsettableClock; import com.android.server.testutils.TestHandler; @@ -47,17 +46,16 @@ import com.android.server.wm.SurfaceAnimator.OnAnimationFinishedCallback; import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.MockitoAnnotations; /** - * atest FrameworksServicesTests:com.android.server.wm.RemoteAnimationControllerTest + * Build/Install/Run: + * atest FrameworksServicesTests:RemoteAnimationControllerTest */ @SmallTest @Presubmit -@RunWith(AndroidJUnit4.class) public class RemoteAnimationControllerTest extends WindowTestsBase { @Mock SurfaceControl mMockLeash; @@ -71,15 +69,13 @@ public class RemoteAnimationControllerTest extends WindowTestsBase { @Before public void setUp() throws Exception { - super.setUp(); MockitoAnnotations.initMocks(this); + when(mMockRunner.asBinder()).thenReturn(new Binder()); mAdapter = new RemoteAnimationAdapter(mMockRunner, 100, 50); mAdapter.setCallingPid(123); - sWm.mH.runWithScissors(() -> { - mHandler = new TestHandler(null, mClock); - }, 0); - mController = new RemoteAnimationController(sWm, mAdapter, mHandler); + mWm.mH.runWithScissors(() -> mHandler = new TestHandler(null, mClock), 0); + mController = new RemoteAnimationController(mWm, mAdapter, mHandler); } @Test @@ -91,7 +87,7 @@ public class RemoteAnimationControllerTest extends WindowTestsBase { new Point(50, 100), new Rect(50, 100, 150, 150)); adapter.startAnimation(mMockLeash, mMockTransaction, mFinishedCallback); mController.goodToGo(); - sWm.mAnimator.executeAfterPrepareSurfacesRunnables(); + mWm.mAnimator.executeAfterPrepareSurfacesRunnables(); final ArgumentCaptor appsCaptor = ArgumentCaptor.forClass(RemoteAnimationTarget[].class); final ArgumentCaptor finishedCaptor = @@ -146,7 +142,7 @@ public class RemoteAnimationControllerTest extends WindowTestsBase { @Test public void testTimeout_scaled() throws Exception { - sWm.setAnimationScale(2, 5.0f); + mWm.setAnimationScale(2, 5.0f); try{ final WindowState win = createWindow(null /* parent */, TYPE_BASE_APPLICATION, "testWin"); final AnimationAdapter adapter = mController.createAnimationAdapter(win.mAppToken, @@ -165,19 +161,19 @@ public class RemoteAnimationControllerTest extends WindowTestsBase { verify(mMockRunner).onAnimationCancelled(); verify(mFinishedCallback).onAnimationFinished(eq(adapter)); } finally { - sWm.setAnimationScale(2, 1.0f); + mWm.setAnimationScale(2, 1.0f); } } @Test - public void testZeroAnimations() throws Exception { + public void testZeroAnimations() { mController.goodToGo(); verifyNoMoreInteractionsExceptAsBinder(mMockRunner); } @Test - public void testNotReallyStarted() throws Exception { + public void testNotReallyStarted() { final WindowState win = createWindow(null /* parent */, TYPE_BASE_APPLICATION, "testWin"); mController.createAnimationAdapter(win.mAppToken, new Point(50, 100), new Rect(50, 100, 150, 150)); @@ -195,7 +191,7 @@ public class RemoteAnimationControllerTest extends WindowTestsBase { new Point(50, 100), new Rect(50, 100, 150, 150)); adapter.startAnimation(mMockLeash, mMockTransaction, mFinishedCallback); mController.goodToGo(); - sWm.mAnimator.executeAfterPrepareSurfacesRunnables(); + mWm.mAnimator.executeAfterPrepareSurfacesRunnables(); final ArgumentCaptor appsCaptor = ArgumentCaptor.forClass(RemoteAnimationTarget[].class); final ArgumentCaptor finishedCaptor = @@ -206,7 +202,7 @@ public class RemoteAnimationControllerTest extends WindowTestsBase { } @Test - public void testRemovedBeforeStarted() throws Exception { + public void testRemovedBeforeStarted() { final WindowState win = createWindow(null /* parent */, TYPE_BASE_APPLICATION, "testWin"); final AnimationAdapter adapter = mController.createAnimationAdapter(win.mAppToken, new Point(50, 100), new Rect(50, 100, 150, 150)); 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 001bed969d8fb..62a617d8f20a9 100644 --- a/services/tests/servicestests/src/com/android/server/wm/RootWindowContainerTests.java +++ b/services/tests/servicestests/src/com/android/server/wm/RootWindowContainerTests.java @@ -1,30 +1,43 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.android.server.wm; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertEquals; import android.content.res.Configuration; import android.graphics.Rect; import android.platform.test.annotations.Presubmit; import androidx.test.filters.SmallTest; -import androidx.test.runner.AndroidJUnit4; import org.junit.Test; -import org.junit.runner.RunWith; /** * Tests for the {@link RootWindowContainer} class. * * Build/Install/Run: - * atest FrameworksServicesTests:com.android.server.wm.RootWindowContainerTests + * atest FrameworksServicesTests:RootWindowContainerTests */ @SmallTest @Presubmit -@RunWith(AndroidJUnit4.class) public class RootWindowContainerTests extends WindowTestsBase { @Test - public void testSetDisplayOverrideConfigurationIfNeeded() throws Exception { - synchronized (sWm.mGlobalLock) { + public void testSetDisplayOverrideConfigurationIfNeeded() { + synchronized (mWm.mGlobalLock) { // 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)); @@ -41,12 +54,12 @@ public class RootWindowContainerTests extends WindowTestsBase { override.windowConfiguration.setBounds(new Rect(0, 0, 10, 10)); // Set display override. - final int[] results = sWm.mRoot.setDisplayOverrideConfigurationIfNeeded(override, + final int[] results = mWm.mRoot.setDisplayOverrideConfigurationIfNeeded(override, mDisplayContent.getDisplayId()); // Ensure only first stack is returned. - assertTrue(results.length == 1); - assertTrue(results[0] == stack.mStackId); + assertEquals(1, results.length); + assertEquals(stack.mStackId, results[0]); } } } diff --git a/services/tests/servicestests/src/com/android/server/wm/StackWindowControllerTests.java b/services/tests/servicestests/src/com/android/server/wm/StackWindowControllerTests.java index 9f2645cc98ae8..ce5b13cab1a70 100644 --- a/services/tests/servicestests/src/com/android/server/wm/StackWindowControllerTests.java +++ b/services/tests/servicestests/src/com/android/server/wm/StackWindowControllerTests.java @@ -11,7 +11,7 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License + * limitations under the License. */ package com.android.server.wm; @@ -25,10 +25,8 @@ import android.graphics.Rect; import android.platform.test.annotations.Presubmit; import androidx.test.filters.SmallTest; -import androidx.test.runner.AndroidJUnit4; import org.junit.Test; -import org.junit.runner.RunWith; /** * Test class for {@link StackWindowController}. @@ -38,10 +36,9 @@ import org.junit.runner.RunWith; */ @SmallTest @Presubmit -@RunWith(AndroidJUnit4.class) public class StackWindowControllerTests extends WindowTestsBase { @Test - public void testRemoveContainer() throws Exception { + public void testRemoveContainer() { final StackWindowController stackController = createStackControllerOnDisplay(mDisplayContent); final WindowTestUtils.TestTaskWindowContainerController taskController = @@ -61,7 +58,7 @@ public class StackWindowControllerTests extends WindowTestsBase { } @Test - public void testRemoveContainer_deferRemoval() throws Exception { + public void testRemoveContainer_deferRemoval() { final StackWindowController stackController = createStackControllerOnDisplay(mDisplayContent); final WindowTestUtils.TestTaskWindowContainerController taskController = @@ -87,7 +84,7 @@ public class StackWindowControllerTests extends WindowTestsBase { } @Test - public void testReparent() throws Exception { + public void testReparent() { // Create first stack on primary display. final StackWindowController stack1Controller = createStackControllerOnDisplay(mDisplayContent); diff --git a/services/tests/servicestests/src/com/android/server/wm/SurfaceAnimationRunnerTest.java b/services/tests/servicestests/src/com/android/server/wm/SurfaceAnimationRunnerTest.java index 4551c3611102c..584f2695891b1 100644 --- a/services/tests/servicestests/src/com/android/server/wm/SurfaceAnimationRunnerTest.java +++ b/services/tests/servicestests/src/com/android/server/wm/SurfaceAnimationRunnerTest.java @@ -11,7 +11,7 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License + * limitations under the License. */ package com.android.server.wm; @@ -27,6 +27,8 @@ import static org.mockito.Mockito.eq; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import static java.util.concurrent.TimeUnit.SECONDS; + import android.animation.AnimationHandler.AnimationFrameCallbackProvider; import android.animation.ValueAnimator; import android.graphics.Matrix; @@ -42,30 +44,27 @@ import android.view.animation.TranslateAnimation; import androidx.test.filters.FlakyTest; import androidx.test.filters.SmallTest; -import androidx.test.runner.AndroidJUnit4; import com.android.server.wm.LocalAnimationAdapter.AnimationSpec; import org.junit.Before; import org.junit.Rule; import org.junit.Test; -import org.junit.runner.RunWith; import org.mockito.Mock; +import org.mockito.MockitoAnnotations; import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; -import static java.util.concurrent.TimeUnit.SECONDS; - import java.util.concurrent.CountDownLatch; /** * Test class for {@link SurfaceAnimationRunner}. * - * atest FrameworksServicesTests:com.android.server.wm.SurfaceAnimationRunnerTest + * Build/Install/Run: + * atest FrameworksServicesTests:SurfaceAnimationRunnerTest */ @SmallTest @Presubmit -@RunWith(AndroidJUnit4.class) public class SurfaceAnimationRunnerTest extends WindowTestsBase { @Mock SurfaceControl mMockSurface; @@ -79,7 +78,8 @@ public class SurfaceAnimationRunnerTest extends WindowTestsBase { @Before public void setUp() throws Exception { - super.setUp(); + MockitoAnnotations.initMocks(this); + mFinishCallbackLatch = new CountDownLatch(1); mSurfaceAnimationRunner = new SurfaceAnimationRunner(null /* callbackProvider */, null, mMockTransaction, mMockPowerManager); @@ -112,7 +112,7 @@ public class SurfaceAnimationRunnerTest extends WindowTestsBase { } @Test - public void testCancel_notStarted() throws Exception { + public void testCancel_notStarted() { mSurfaceAnimationRunner = new SurfaceAnimationRunner(new NoOpFrameCallbackProvider(), null, mMockTransaction, mMockPowerManager); mSurfaceAnimationRunner diff --git a/services/tests/servicestests/src/com/android/server/wm/SurfaceAnimatorTest.java b/services/tests/servicestests/src/com/android/server/wm/SurfaceAnimatorTest.java index 7b5e8deeeb65e..6833dc5f04972 100644 --- a/services/tests/servicestests/src/com/android/server/wm/SurfaceAnimatorTest.java +++ b/services/tests/servicestests/src/com/android/server/wm/SurfaceAnimatorTest.java @@ -11,7 +11,7 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License + * limitations under the License. */ package com.android.server.wm; @@ -35,14 +35,13 @@ import android.view.SurfaceSession; import androidx.test.filters.FlakyTest; import androidx.test.filters.SmallTest; -import androidx.test.runner.AndroidJUnit4; import com.android.server.wm.SurfaceAnimator.Animatable; import com.android.server.wm.SurfaceAnimator.OnAnimationFinishedCallback; +import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -50,11 +49,11 @@ import org.mockito.MockitoAnnotations; /** * Test class for {@link SurfaceAnimatorTest}. * - * atest FrameworksServicesTests:com.android.server.wm.SurfaceAnimatorTest + * Build/Install/Run: + * atest FrameworksServicesTests:SurfaceAnimatorTest */ @SmallTest @Presubmit -@RunWith(AndroidJUnit4.class) public class SurfaceAnimatorTest extends WindowTestsBase { @Mock AnimationAdapter mSpec; @@ -68,15 +67,24 @@ public class SurfaceAnimatorTest extends WindowTestsBase { @Before public void setUp() throws Exception { - super.setUp(); MockitoAnnotations.initMocks(this); - mAnimatable = new MyAnimatable(); - mAnimatable2 = new MyAnimatable(); - mDeferFinishAnimatable = new DeferFinishAnimatable(); + + mAnimatable = new MyAnimatable(mWm, mSession, mTransaction); + mAnimatable2 = new MyAnimatable(mWm, mSession, mTransaction); + mDeferFinishAnimatable = new DeferFinishAnimatable(mWm, mSession, mTransaction); + } + + @After + public void tearDown() { + mAnimatable = null; + mAnimatable2 = null; + mDeferFinishAnimatable = null; + mSession.kill(); + mSession = null; } @Test - public void testRunAnimation() throws Exception { + public void testRunAnimation() { mAnimatable.mSurfaceAnimator.startAnimation(mTransaction, mSpec, true /* hidden */); final ArgumentCaptor callbackCaptor = ArgumentCaptor.forClass( OnAnimationFinishedCallback.class); @@ -92,7 +100,7 @@ public class SurfaceAnimatorTest extends WindowTestsBase { } @Test - public void testOverrideAnimation() throws Exception { + public void testOverrideAnimation() { mAnimatable.mSurfaceAnimator.startAnimation(mTransaction, mSpec, true /* hidden */); final SurfaceControl firstLeash = mAnimatable.mLeash; mAnimatable.mSurfaceAnimator.startAnimation(mTransaction, mSpec2, true /* hidden */); @@ -117,7 +125,7 @@ public class SurfaceAnimatorTest extends WindowTestsBase { } @Test - public void testCancelAnimation() throws Exception { + public void testCancelAnimation() { mAnimatable.mSurfaceAnimator.startAnimation(mTransaction, mSpec, true /* hidden */); assertAnimating(mAnimatable); mAnimatable.mSurfaceAnimator.cancelAnimation(); @@ -128,7 +136,7 @@ public class SurfaceAnimatorTest extends WindowTestsBase { } @Test - public void testDelayingAnimationStart() throws Exception { + public void testDelayingAnimationStart() { mAnimatable.mSurfaceAnimator.startDelayingAnimationStart(); mAnimatable.mSurfaceAnimator.startAnimation(mTransaction, mSpec, true /* hidden */); verifyZeroInteractions(mSpec); @@ -139,7 +147,7 @@ public class SurfaceAnimatorTest extends WindowTestsBase { } @Test - public void testDelayingAnimationStartAndCancelled() throws Exception { + public void testDelayingAnimationStartAndCancelled() { mAnimatable.mSurfaceAnimator.startDelayingAnimationStart(); mAnimatable.mSurfaceAnimator.startAnimation(mTransaction, mSpec, true /* hidden */); mAnimatable.mSurfaceAnimator.cancelAnimation(); @@ -150,7 +158,7 @@ public class SurfaceAnimatorTest extends WindowTestsBase { } @Test - public void testTransferAnimation() throws Exception { + public void testTransferAnimation() { mAnimatable.mSurfaceAnimator.startAnimation(mTransaction, mSpec, true /* hidden */); final ArgumentCaptor callbackCaptor = ArgumentCaptor.forClass( @@ -171,7 +179,7 @@ public class SurfaceAnimatorTest extends WindowTestsBase { @Test @FlakyTest(detail = "Promote once confirmed non-flaky") - public void testDeferFinish() throws Exception { + public void testDeferFinish() { // Start animation mDeferFinishAnimatable.mSurfaceAnimator.startAnimation(mTransaction, mSpec, @@ -186,7 +194,7 @@ public class SurfaceAnimatorTest extends WindowTestsBase { assertAnimating(mDeferFinishAnimatable); // Now end defer finishing. - mDeferFinishAnimatable.endDeferFinishCallback.run(); + mDeferFinishAnimatable.mEndDeferFinishCallback.run(); assertNotAnimating(mAnimatable2); assertTrue(mDeferFinishAnimatable.mFinishedCallbackCalled); verify(mTransaction).destroy(eq(mDeferFinishAnimatable.mLeash)); @@ -202,26 +210,30 @@ public class SurfaceAnimatorTest extends WindowTestsBase { assertNull(animatable.mSurfaceAnimator.getAnimation()); } - private class MyAnimatable implements Animatable { + private static class MyAnimatable implements Animatable { + private final SurfaceSession mSession; + private final Transaction mTransaction; final SurfaceControl mParent; final SurfaceControl mSurface; final SurfaceAnimator mSurfaceAnimator; SurfaceControl mLeash; boolean mFinishedCallbackCalled; - MyAnimatable() { - mParent = sWm.makeSurfaceBuilder(mSession) + MyAnimatable(WindowManagerService wm, SurfaceSession session, Transaction transaction) { + mSession = session; + mTransaction = transaction; + mParent = wm.makeSurfaceBuilder(mSession) .setName("test surface parent") .setSize(3000, 3000) .build(); - mSurface = sWm.makeSurfaceBuilder(mSession) + mSurface = wm.makeSurfaceBuilder(mSession) .setName("test surface") .setSize(1, 1) .build(); mFinishedCallbackCalled = false; mLeash = null; - mSurfaceAnimator = new SurfaceAnimator(this, mFinishedCallback, sWm); + mSurfaceAnimator = new SurfaceAnimator(this, mFinishedCallback, wm); } @Override @@ -281,13 +293,18 @@ public class SurfaceAnimatorTest extends WindowTestsBase { private final Runnable mFinishedCallback = () -> mFinishedCallbackCalled = true; } - private class DeferFinishAnimatable extends MyAnimatable { + private static class DeferFinishAnimatable extends MyAnimatable { - Runnable endDeferFinishCallback; + Runnable mEndDeferFinishCallback; + + DeferFinishAnimatable(WindowManagerService wm, SurfaceSession session, + Transaction transaction) { + super(wm, session, transaction); + } @Override public boolean shouldDeferAnimationFinish(Runnable endDeferFinishCallback) { - this.endDeferFinishCallback = endDeferFinishCallback; + mEndDeferFinishCallback = endDeferFinishCallback; return true; } } diff --git a/services/tests/servicestests/src/com/android/server/wm/TaskPositionerTests.java b/services/tests/servicestests/src/com/android/server/wm/TaskPositionerTests.java index 17b7fc1fd0f0e..785b955863dbb 100644 --- a/services/tests/servicestests/src/com/android/server/wm/TaskPositionerTests.java +++ b/services/tests/servicestests/src/com/android/server/wm/TaskPositionerTests.java @@ -11,7 +11,7 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License + * limitations under the License. */ package com.android.server.wm; @@ -35,24 +35,22 @@ import android.util.Log; import android.view.Display; import androidx.test.filters.SmallTest; -import androidx.test.runner.AndroidJUnit4; import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; import org.mockito.Mockito; /** * Tests for the {@link TaskPositioner} class. * - * runtest frameworks-services -c com.android.server.wm.TaskPositionerTests + * Build/Install/Run: + * atest FrameworksServicesTests:TaskPositionerTests */ @SmallTest -@RunWith(AndroidJUnit4.class) public class TaskPositionerTests extends WindowTestsBase { - private final boolean DEBUGGING = false; - private final String TAG = "TaskPositionerTest"; + private static final boolean DEBUGGING = false; + private static final String TAG = "TaskPositionerTest"; private final static int MOUSE_DELTA_X = 5; private final static int MOUSE_DELTA_Y = 5; @@ -65,8 +63,6 @@ public class TaskPositionerTests extends WindowTestsBase { @Before public void setUp() throws Exception { - super.setUp(); - TaskPositioner.setFactory(null); final Display display = mDisplayContent.getDisplay(); @@ -77,7 +73,7 @@ public class TaskPositionerTests extends WindowTestsBase { mMinVisibleWidth = dipToPixel(MINIMUM_VISIBLE_WIDTH_IN_DP, dm); mMinVisibleHeight = dipToPixel(MINIMUM_VISIBLE_HEIGHT_IN_DP, dm); - mPositioner = new TaskPositioner(sWm, Mockito.mock(IActivityTaskManager.class)); + mPositioner = new TaskPositioner(mWm, Mockito.mock(IActivityTaskManager.class)); mPositioner.register(mDisplayContent); mWindow = Mockito.spy(createWindow(null, TYPE_BASE_APPLICATION, "window")); @@ -94,7 +90,7 @@ public class TaskPositionerTests extends WindowTestsBase { } @Test - public void testOverrideFactory() throws Exception { + public void testOverrideFactory() { final boolean[] created = new boolean[1]; created[0] = false; TaskPositioner.setFactory(new TaskPositioner.Factory() { @@ -105,7 +101,7 @@ public class TaskPositionerTests extends WindowTestsBase { } }); - assertNull(TaskPositioner.create(sWm)); + assertNull(TaskPositioner.create(mWm)); assertTrue(created[0]); } @@ -114,7 +110,7 @@ public class TaskPositionerTests extends WindowTestsBase { * as does some basic tests (e.g. dragging in Y only will keep X stable). */ @Test - public void testBasicFreeWindowResizing() throws Exception { + public void testBasicFreeWindowResizing() { final Rect r = new Rect(100, 220, 700, 520); final int midY = (r.top + r.bottom) / 2; mDimBounds.set(r); @@ -175,7 +171,7 @@ public class TaskPositionerTests extends WindowTestsBase { * This tests that by dragging any edge, the fixed / opposite edge(s) remains anchored. */ @Test - public void testFreeWindowResizingTestAllEdges() throws Exception { + public void testFreeWindowResizingTestAllEdges() { final Rect r = new Rect(100, 220, 700, 520); final int midX = (r.left + r.right) / 2; final int midY = (r.top + r.bottom) / 2; @@ -260,7 +256,7 @@ public class TaskPositionerTests extends WindowTestsBase { * right things upon resizing when dragged from the top left corner. */ @Test - public void testLandscapePreservedWindowResizingDragTopLeft() throws Exception { + public void testLandscapePreservedWindowResizingDragTopLeft() { final Rect r = new Rect(100, 220, 700, 520); mDimBounds.set(r); @@ -298,7 +294,7 @@ public class TaskPositionerTests extends WindowTestsBase { * right things upon resizing when dragged from the left corner. */ @Test - public void testLandscapePreservedWindowResizingDragLeft() throws Exception { + public void testLandscapePreservedWindowResizingDragLeft() { final Rect r = new Rect(100, 220, 700, 520); final int midY = (r.top + r.bottom) / 2; mDimBounds.set(r); @@ -339,7 +335,7 @@ public class TaskPositionerTests extends WindowTestsBase { * right things upon resizing when dragged from the top corner. */ @Test - public void testLandscapePreservedWindowResizingDragTop() throws Exception { + public void testLandscapePreservedWindowResizingDragTop() { final Rect r = new Rect(100, 220, 700, 520); final int midX = (r.left + r.right) / 2; mDimBounds.set(r); @@ -376,7 +372,7 @@ public class TaskPositionerTests extends WindowTestsBase { * right things upon resizing when dragged from the top left corner. */ @Test - public void testPortraitPreservedWindowResizingDragTopLeft() throws Exception { + public void testPortraitPreservedWindowResizingDragTopLeft() { final Rect r = new Rect(330, 100, 630, 600); mDimBounds.set(r); @@ -409,7 +405,7 @@ public class TaskPositionerTests extends WindowTestsBase { * right things upon resizing when dragged from the left corner. */ @Test - public void testPortraitPreservedWindowResizingDragLeft() throws Exception { + public void testPortraitPreservedWindowResizingDragLeft() { final Rect r = new Rect(330, 100, 630, 600); final int midY = (r.top + r.bottom) / 2; mDimBounds.set(r); @@ -452,7 +448,7 @@ public class TaskPositionerTests extends WindowTestsBase { * right things upon resizing when dragged from the top corner. */ @Test - public void testPortraitPreservedWindowResizingDragTop() throws Exception { + public void testPortraitPreservedWindowResizingDragTop() { final Rect r = new Rect(330, 100, 630, 600); final int midX = (r.left + r.right) / 2; mDimBounds.set(r); @@ -485,7 +481,7 @@ public class TaskPositionerTests extends WindowTestsBase { mPositioner.getWindowDragBounds()); } - private void assertBoundsEquals(Rect expected, Rect actual) { + private static void assertBoundsEquals(Rect expected, Rect actual) { if (DEBUGGING) { if (!expected.equals(actual)) { Log.e(TAG, "rect(" + actual.toString() + ") != isRect(" + actual.toString() diff --git a/services/tests/servicestests/src/com/android/server/wm/TaskPositioningControllerTests.java b/services/tests/servicestests/src/com/android/server/wm/TaskPositioningControllerTests.java index d1480c5865cfa..00b462954bd9d 100644 --- a/services/tests/servicestests/src/com/android/server/wm/TaskPositioningControllerTests.java +++ b/services/tests/servicestests/src/com/android/server/wm/TaskPositioningControllerTests.java @@ -11,7 +11,7 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License + * limitations under the License. */ package com.android.server.wm; @@ -32,70 +32,66 @@ import android.view.InputChannel; import androidx.test.filters.FlakyTest; import androidx.test.filters.SmallTest; -import androidx.test.runner.AndroidJUnit4; import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; /** * Tests for the {@link TaskPositioningController} class. * - * atest com.android.server.wm.TaskPositioningControllerTests + * Build/Install/Run: + * atest FrameworksServicesTests:TaskPositioningControllerTests */ -@SmallTest @FlakyTest(bugId = 117924387) -@RunWith(AndroidJUnit4.class) +@SmallTest @Presubmit public class TaskPositioningControllerTests extends WindowTestsBase { private static final int TIMEOUT_MS = 1000; + private TaskPositioningController mTarget; private WindowState mWindow; @Before public void setUp() throws Exception { - super.setUp(); + assertNotNull(mWm.mTaskPositioningController); + mTarget = mWm.mTaskPositioningController; - assertNotNull(sWm.mTaskPositioningController); - mTarget = sWm.mTaskPositioningController; - - when(sWm.mInputManager.transferTouchFocus( + when(mWm.mInputManager.transferTouchFocus( any(InputChannel.class), any(InputChannel.class))).thenReturn(true); mWindow = createWindow(null, TYPE_BASE_APPLICATION, "window"); mWindow.mInputChannel = new InputChannel(); - synchronized (sWm.mGlobalLock) { - sWm.mWindowMap.put(mWindow.mClient.asBinder(), mWindow); + synchronized (mWm.mGlobalLock) { + mWm.mWindowMap.put(mWindow.mClient.asBinder(), mWindow); } } @Test - public void testStartAndFinishPositioning() throws Exception { - synchronized (sWm.mGlobalLock) { + public void testStartAndFinishPositioning() { + synchronized (mWm.mGlobalLock) { assertFalse(mTarget.isPositioningLocked()); assertNull(mTarget.getDragWindowHandleLocked()); } assertTrue(mTarget.startMovingTask(mWindow.mClient, 0, 0)); - synchronized (sWm.mGlobalLock) { + synchronized (mWm.mGlobalLock) { assertTrue(mTarget.isPositioningLocked()); assertNotNull(mTarget.getDragWindowHandleLocked()); } mTarget.finishTaskPositioning(); // Wait until the looper processes finishTaskPositioning. - assertTrue(sWm.mH.runWithScissors(() -> {}, TIMEOUT_MS)); + assertTrue(mWm.mH.runWithScissors(() -> { }, TIMEOUT_MS)); assertFalse(mTarget.isPositioningLocked()); assertNull(mTarget.getDragWindowHandleLocked()); } @Test - public void testHandleTapOutsideTask() throws Exception { - synchronized (sWm.mGlobalLock) { - + public void testHandleTapOutsideTask() { + synchronized (mWm.mGlobalLock) { assertFalse(mTarget.isPositioningLocked()); assertNull(mTarget.getDragWindowHandleLocked()); } @@ -106,16 +102,16 @@ public class TaskPositioningControllerTests extends WindowTestsBase { mTarget.handleTapOutsideTask(content, 0, 0); // Wait until the looper processes finishTaskPositioning. - assertTrue(sWm.mH.runWithScissors(() -> {}, TIMEOUT_MS)); + assertTrue(mWm.mH.runWithScissors(() -> { }, TIMEOUT_MS)); - synchronized (sWm.mGlobalLock) { + synchronized (mWm.mGlobalLock) { assertTrue(mTarget.isPositioningLocked()); assertNotNull(mTarget.getDragWindowHandleLocked()); } mTarget.finishTaskPositioning(); // Wait until the looper processes finishTaskPositioning. - assertTrue(sWm.mH.runWithScissors(() -> {}, TIMEOUT_MS)); + assertTrue(mWm.mH.runWithScissors(() -> { }, TIMEOUT_MS)); assertFalse(mTarget.isPositioningLocked()); assertNull(mTarget.getDragWindowHandleLocked()); diff --git a/services/tests/servicestests/src/com/android/server/wm/TaskSnapshotCacheTest.java b/services/tests/servicestests/src/com/android/server/wm/TaskSnapshotCacheTest.java index c9d800449ff9a..1c6afd545b1f4 100644 --- a/services/tests/servicestests/src/com/android/server/wm/TaskSnapshotCacheTest.java +++ b/services/tests/servicestests/src/com/android/server/wm/TaskSnapshotCacheTest.java @@ -11,7 +11,7 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License + * limitations under the License. */ package com.android.server.wm; @@ -24,32 +24,32 @@ import static junit.framework.Assert.assertNull; import android.platform.test.annotations.Presubmit; import androidx.test.filters.SmallTest; -import androidx.test.runner.AndroidJUnit4; import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; /** * Test class for {@link TaskSnapshotCache}. * - * runtest frameworks-services -c com.android.server.wm.TaskSnapshotCacheTest + * Build/Install/Run: + * atest FrameworksServicesTests:TaskSnapshotCacheTest */ @SmallTest @Presubmit -@RunWith(AndroidJUnit4.class) public class TaskSnapshotCacheTest extends TaskSnapshotPersisterTestBase { private TaskSnapshotCache mCache; + @Override @Before - public void setUp() throws Exception { + public void setUp() { super.setUp(); - mCache = new TaskSnapshotCache(sWm, mLoader); + + mCache = new TaskSnapshotCache(mWm, mLoader); } @Test - public void testAppRemoved() throws Exception { + public void testAppRemoved() { final WindowState window = createWindow(null, FIRST_APPLICATION_WINDOW, "window"); mCache.putSnapshot(window.getTask(), createSnapshot()); assertNotNull(mCache.getSnapshot(window.getTask().mTaskId, 0 /* userId */, @@ -60,7 +60,7 @@ public class TaskSnapshotCacheTest extends TaskSnapshotPersisterTestBase { } @Test - public void testAppDied() throws Exception { + public void testAppDied() { final WindowState window = createWindow(null, FIRST_APPLICATION_WINDOW, "window"); mCache.putSnapshot(window.getTask(), createSnapshot()); assertNotNull(mCache.getSnapshot(window.getTask().mTaskId, 0 /* userId */, @@ -71,7 +71,7 @@ public class TaskSnapshotCacheTest extends TaskSnapshotPersisterTestBase { } @Test - public void testTaskRemoved() throws Exception { + public void testTaskRemoved() { final WindowState window = createWindow(null, FIRST_APPLICATION_WINDOW, "window"); mCache.putSnapshot(window.getTask(), createSnapshot()); assertNotNull(mCache.getSnapshot(window.getTask().mTaskId, 0 /* userId */, @@ -82,32 +82,32 @@ public class TaskSnapshotCacheTest extends TaskSnapshotPersisterTestBase { } @Test - public void testReduced_notCached() throws Exception { + public void testReduced_notCached() { final WindowState window = createWindow(null, FIRST_APPLICATION_WINDOW, "window"); - mPersister.persistSnapshot(window.getTask().mTaskId, sWm.mCurrentUserId, createSnapshot()); + mPersister.persistSnapshot(window.getTask().mTaskId, mWm.mCurrentUserId, createSnapshot()); mPersister.waitForQueueEmpty(); - assertNull(mCache.getSnapshot(window.getTask().mTaskId, sWm.mCurrentUserId, + assertNull(mCache.getSnapshot(window.getTask().mTaskId, mWm.mCurrentUserId, false /* restoreFromDisk */, false /* reducedResolution */)); // Load it from disk - assertNotNull(mCache.getSnapshot(window.getTask().mTaskId, sWm.mCurrentUserId, + assertNotNull(mCache.getSnapshot(window.getTask().mTaskId, mWm.mCurrentUserId, true /* restoreFromDisk */, true /* reducedResolution */)); // Make sure it's not in the cache now. - assertNull(mCache.getSnapshot(window.getTask().mTaskId, sWm.mCurrentUserId, + assertNull(mCache.getSnapshot(window.getTask().mTaskId, mWm.mCurrentUserId, false /* restoreFromDisk */, false /* reducedResolution */)); } @Test - public void testRestoreFromDisk() throws Exception { + public void testRestoreFromDisk() { final WindowState window = createWindow(null, FIRST_APPLICATION_WINDOW, "window"); - mPersister.persistSnapshot(window.getTask().mTaskId, sWm.mCurrentUserId, createSnapshot()); + mPersister.persistSnapshot(window.getTask().mTaskId, mWm.mCurrentUserId, createSnapshot()); mPersister.waitForQueueEmpty(); - assertNull(mCache.getSnapshot(window.getTask().mTaskId, sWm.mCurrentUserId, + assertNull(mCache.getSnapshot(window.getTask().mTaskId, mWm.mCurrentUserId, false /* restoreFromDisk */, false /* reducedResolution */)); // Load it from disk - assertNotNull(mCache.getSnapshot(window.getTask().mTaskId, sWm.mCurrentUserId, + assertNotNull(mCache.getSnapshot(window.getTask().mTaskId, mWm.mCurrentUserId, true /* restoreFromDisk */, false /* reducedResolution */)); } } diff --git a/services/tests/servicestests/src/com/android/server/wm/TaskSnapshotControllerTest.java b/services/tests/servicestests/src/com/android/server/wm/TaskSnapshotControllerTest.java index efce063c8fca5..d2c07651d83cb 100644 --- a/services/tests/servicestests/src/com/android/server/wm/TaskSnapshotControllerTest.java +++ b/services/tests/servicestests/src/com/android/server/wm/TaskSnapshotControllerTest.java @@ -11,7 +11,7 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License + * limitations under the License. */ package com.android.server.wm; @@ -20,7 +20,8 @@ import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW; import static android.view.WindowManager.LayoutParams.FLAG_SECURE; import static android.view.WindowManager.TRANSIT_UNSET; -import static com.android.server.wm.TaskSnapshotController.*; +import static com.android.server.wm.TaskSnapshotController.SNAPSHOT_MODE_APP_THEME; +import static com.android.server.wm.TaskSnapshotController.SNAPSHOT_MODE_REAL; import static junit.framework.Assert.assertEquals; @@ -28,25 +29,23 @@ import android.platform.test.annotations.Presubmit; import android.util.ArraySet; import androidx.test.filters.SmallTest; -import androidx.test.runner.AndroidJUnit4; import com.google.android.collect.Sets; import org.junit.Test; -import org.junit.runner.RunWith; /** * Test class for {@link TaskSnapshotController}. * - * runtest frameworks-services -c com.android.server.wm.TaskSnapshotControllerTest + * Build/Install/Run: + * * atest FrameworksServicesTests:TaskSnapshotControllerTest */ @SmallTest @Presubmit -@RunWith(AndroidJUnit4.class) public class TaskSnapshotControllerTest extends WindowTestsBase { @Test - public void testGetClosingApps_closing() throws Exception { + public void testGetClosingApps_closing() { final WindowState closingWindow = createWindow(null, FIRST_APPLICATION_WINDOW, "closingWindow"); closingWindow.mAppToken.setVisibility(null, false /* visible */, TRANSIT_UNSET, @@ -54,13 +53,13 @@ public class TaskSnapshotControllerTest extends WindowTestsBase { final ArraySet closingApps = new ArraySet<>(); closingApps.add(closingWindow.mAppToken); final ArraySet closingTasks = new ArraySet<>(); - sWm.mTaskSnapshotController.getClosingTasks(closingApps, closingTasks); + mWm.mTaskSnapshotController.getClosingTasks(closingApps, closingTasks); assertEquals(1, closingTasks.size()); assertEquals(closingWindow.mAppToken.getTask(), closingTasks.valueAt(0)); } @Test - public void testGetClosingApps_notClosing() throws Exception { + public void testGetClosingApps_notClosing() { final WindowState closingWindow = createWindow(null, FIRST_APPLICATION_WINDOW, "closingWindow"); final WindowState openingWindow = createAppWindow(closingWindow.getTask(), @@ -72,12 +71,12 @@ public class TaskSnapshotControllerTest extends WindowTestsBase { final ArraySet closingApps = new ArraySet<>(); closingApps.add(closingWindow.mAppToken); final ArraySet closingTasks = new ArraySet<>(); - sWm.mTaskSnapshotController.getClosingTasks(closingApps, closingTasks); + mWm.mTaskSnapshotController.getClosingTasks(closingApps, closingTasks); assertEquals(0, closingTasks.size()); } @Test - public void testGetClosingApps_skipClosingAppsSnapshotTasks() throws Exception { + public void testGetClosingApps_skipClosingAppsSnapshotTasks() { final WindowState closingWindow = createWindow(null, FIRST_APPLICATION_WINDOW, "closingWindow"); closingWindow.mAppToken.setVisibility(null, false /* visible */, TRANSIT_UNSET, @@ -85,29 +84,29 @@ public class TaskSnapshotControllerTest extends WindowTestsBase { final ArraySet closingApps = new ArraySet<>(); closingApps.add(closingWindow.mAppToken); final ArraySet closingTasks = new ArraySet<>(); - sWm.mTaskSnapshotController.addSkipClosingAppSnapshotTasks( + mWm.mTaskSnapshotController.addSkipClosingAppSnapshotTasks( Sets.newArraySet(closingWindow.mAppToken.getTask())); - sWm.mTaskSnapshotController.getClosingTasks(closingApps, closingTasks); + mWm.mTaskSnapshotController.getClosingTasks(closingApps, closingTasks); assertEquals(0, closingTasks.size()); } @Test - public void testGetSnapshotMode() throws Exception { + public void testGetSnapshotMode() { final WindowState disabledWindow = createWindow(null, FIRST_APPLICATION_WINDOW, mDisplayContent, "disabledWindow"); disabledWindow.mAppToken.setDisablePreviewScreenshots(true); assertEquals(SNAPSHOT_MODE_APP_THEME, - sWm.mTaskSnapshotController.getSnapshotMode(disabledWindow.getTask())); + mWm.mTaskSnapshotController.getSnapshotMode(disabledWindow.getTask())); final WindowState normalWindow = createWindow(null, FIRST_APPLICATION_WINDOW, mDisplayContent, "normalWindow"); assertEquals(SNAPSHOT_MODE_REAL, - sWm.mTaskSnapshotController.getSnapshotMode(normalWindow.getTask())); + mWm.mTaskSnapshotController.getSnapshotMode(normalWindow.getTask())); final WindowState secureWindow = createWindow(null, FIRST_APPLICATION_WINDOW, mDisplayContent, "secureWindow"); secureWindow.mAttrs.flags |= FLAG_SECURE; assertEquals(SNAPSHOT_MODE_APP_THEME, - sWm.mTaskSnapshotController.getSnapshotMode(secureWindow.getTask())); + mWm.mTaskSnapshotController.getSnapshotMode(secureWindow.getTask())); } } diff --git a/services/tests/servicestests/src/com/android/server/wm/TaskSnapshotPersisterLoaderTest.java b/services/tests/servicestests/src/com/android/server/wm/TaskSnapshotPersisterLoaderTest.java index 600b2e52b0834..b0eafeeae0430 100644 --- a/services/tests/servicestests/src/com/android/server/wm/TaskSnapshotPersisterLoaderTest.java +++ b/services/tests/servicestests/src/com/android/server/wm/TaskSnapshotPersisterLoaderTest.java @@ -11,7 +11,7 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License + * limitations under the License. */ package com.android.server.wm; @@ -34,23 +34,22 @@ import android.util.ArraySet; import android.view.View; import androidx.test.filters.MediumTest; -import androidx.test.runner.AndroidJUnit4; import com.android.server.wm.TaskSnapshotPersister.RemoveObsoleteFilesQueueItem; import org.junit.Test; -import org.junit.runner.RunWith; import java.io.File; +import java.util.function.Predicate; /** * Test class for {@link TaskSnapshotPersister} and {@link TaskSnapshotLoader} * - * atest FrameworksServicesTests:TaskSnapshotPersisterLoaderTest + * Build/Install/Run: + * atest FrameworksServicesTests:TaskSnapshotPersisterLoaderTest */ @MediumTest @Presubmit -@RunWith(AndroidJUnit4.class) public class TaskSnapshotPersisterLoaderTest extends TaskSnapshotPersisterTestBase { private static final Rect TEST_INSETS = new Rect(10, 20, 30, 40); @@ -59,9 +58,9 @@ public class TaskSnapshotPersisterLoaderTest extends TaskSnapshotPersisterTestBa public void testPersistAndLoadSnapshot() { mPersister.persistSnapshot(1 , mTestUserId, createSnapshot()); mPersister.waitForQueueEmpty(); - final File[] files = new File[] { new File(sFilesDir.getPath() + "/snapshots/1.proto"), - new File(sFilesDir.getPath() + "/snapshots/1.jpg"), - new File(sFilesDir.getPath() + "/snapshots/1_reduced.jpg")}; + final File[] files = new File[] { new File(FILES_DIR.getPath() + "/snapshots/1.proto"), + new File(FILES_DIR.getPath() + "/snapshots/1.jpg"), + new File(FILES_DIR.getPath() + "/snapshots/1_reduced.jpg")}; assertTrueForFiles(files, File::exists, " must exist"); final TaskSnapshot snapshot = mLoader.loadTask(1, mTestUserId, false /* reduced */); assertNotNull(snapshot); @@ -70,9 +69,10 @@ public class TaskSnapshotPersisterLoaderTest extends TaskSnapshotPersisterTestBa assertEquals(Configuration.ORIENTATION_PORTRAIT, snapshot.getOrientation()); } - private void assertTrueForFiles(File[] files, Predicate predicate, String message) { + private static void assertTrueForFiles(File[] files, Predicate predicate, + String message) { for (File file : files) { - assertTrue(file.getName() + message, predicate.apply(file)); + assertTrue(file.getName() + message, predicate.test(file)); } } @@ -81,9 +81,9 @@ public class TaskSnapshotPersisterLoaderTest extends TaskSnapshotPersisterTestBa mPersister.persistSnapshot(1, mTestUserId, createSnapshot()); mPersister.onTaskRemovedFromRecents(1, mTestUserId); mPersister.waitForQueueEmpty(); - assertFalse(new File(sFilesDir.getPath() + "/snapshots/1.proto").exists()); - assertFalse(new File(sFilesDir.getPath() + "/snapshots/1.jpg").exists()); - assertFalse(new File(sFilesDir.getPath() + "/snapshots/1_reduced.jpg").exists()); + assertFalse(new File(FILES_DIR.getPath() + "/snapshots/1.proto").exists()); + assertFalse(new File(FILES_DIR.getPath() + "/snapshots/1.jpg").exists()); + assertFalse(new File(FILES_DIR.getPath() + "/snapshots/1_reduced.jpg").exists()); } /** @@ -120,12 +120,12 @@ public class TaskSnapshotPersisterLoaderTest extends TaskSnapshotPersisterTestBa // Make sure 1,2 were purged but removeObsoleteFiles wasn't. final File[] existsFiles = new File[] { - new File(sFilesDir.getPath() + "/snapshots/3.proto"), - new File(sFilesDir.getPath() + "/snapshots/4.proto")}; + new File(FILES_DIR.getPath() + "/snapshots/3.proto"), + new File(FILES_DIR.getPath() + "/snapshots/4.proto")}; final File[] nonExistsFiles = new File[] { - new File(sFilesDir.getPath() + "/snapshots/100.proto"), - new File(sFilesDir.getPath() + "/snapshots/1.proto"), - new File(sFilesDir.getPath() + "/snapshots/1.proto")}; + new File(FILES_DIR.getPath() + "/snapshots/100.proto"), + new File(FILES_DIR.getPath() + "/snapshots/1.proto"), + new File(FILES_DIR.getPath() + "/snapshots/1.proto")}; assertTrueForFiles(existsFiles, File::exists, " must exist"); assertTrueForFiles(nonExistsFiles, file -> !file.exists(), " must not exist"); } @@ -149,10 +149,10 @@ public class TaskSnapshotPersisterLoaderTest extends TaskSnapshotPersisterTestBa assertTrue(a.isReducedResolution()); mPersister.persistSnapshot(1 , mTestUserId, a); mPersister.waitForQueueEmpty(); - final File[] files = new File[] { new File(sFilesDir.getPath() + "/snapshots/1.proto"), - new File(sFilesDir.getPath() + "/snapshots/1_reduced.jpg")}; + final File[] files = new File[] { new File(FILES_DIR.getPath() + "/snapshots/1.proto"), + new File(FILES_DIR.getPath() + "/snapshots/1_reduced.jpg")}; final File[] nonExistsFiles = new File[] { - new File(sFilesDir.getPath() + "/snapshots/1.jpg"), + new File(FILES_DIR.getPath() + "/snapshots/1.jpg"), }; assertTrueForFiles(files, File::exists, " must exist"); assertTrueForFiles(nonExistsFiles, file -> !file.exists(), " must not exist"); @@ -195,8 +195,8 @@ public class TaskSnapshotPersisterLoaderTest extends TaskSnapshotPersisterTestBa TaskSnapshot b = new TaskSnapshotBuilder() .setWindowingMode(WINDOWING_MODE_PINNED) .build(); - assertTrue(a.getWindowingMode() == WINDOWING_MODE_FULLSCREEN); - assertTrue(b.getWindowingMode() == WINDOWING_MODE_PINNED); + assertEquals(WINDOWING_MODE_FULLSCREEN, a.getWindowingMode()); + assertEquals(WINDOWING_MODE_PINNED, b.getWindowingMode()); mPersister.persistSnapshot(1, mTestUserId, a); mPersister.persistSnapshot(2, mTestUserId, b); mPersister.waitForQueueEmpty(); @@ -204,8 +204,8 @@ public class TaskSnapshotPersisterLoaderTest extends TaskSnapshotPersisterTestBa final TaskSnapshot snapshotB = mLoader.loadTask(2, mTestUserId, false /* reduced */); assertNotNull(snapshotA); assertNotNull(snapshotB); - assertTrue(snapshotA.getWindowingMode() == WINDOWING_MODE_FULLSCREEN); - assertTrue(snapshotB.getWindowingMode() == WINDOWING_MODE_PINNED); + assertEquals(WINDOWING_MODE_FULLSCREEN, snapshotA.getWindowingMode()); + assertEquals(WINDOWING_MODE_PINNED, snapshotB.getWindowingMode()); } @Test @@ -239,8 +239,8 @@ public class TaskSnapshotPersisterLoaderTest extends TaskSnapshotPersisterTestBa TaskSnapshot b = new TaskSnapshotBuilder() .setSystemUiVisibility(lightBarFlags) .build(); - assertTrue(a.getSystemUiVisibility() == 0); - assertTrue(b.getSystemUiVisibility() == lightBarFlags); + assertEquals(0, a.getSystemUiVisibility()); + assertEquals(lightBarFlags, b.getSystemUiVisibility()); mPersister.persistSnapshot(1, mTestUserId, a); mPersister.persistSnapshot(2, mTestUserId, b); mPersister.waitForQueueEmpty(); @@ -248,8 +248,8 @@ public class TaskSnapshotPersisterLoaderTest extends TaskSnapshotPersisterTestBa final TaskSnapshot snapshotB = mLoader.loadTask(2, mTestUserId, false /* reduced */); assertNotNull(snapshotA); assertNotNull(snapshotB); - assertTrue(snapshotA.getSystemUiVisibility() == 0); - assertTrue(snapshotB.getSystemUiVisibility() == lightBarFlags); + assertEquals(0, snapshotA.getSystemUiVisibility()); + assertEquals(lightBarFlags, snapshotB.getSystemUiVisibility()); } @Test @@ -261,13 +261,13 @@ public class TaskSnapshotPersisterLoaderTest extends TaskSnapshotPersisterTestBa mPersister.removeObsoleteFiles(taskIds, new int[] { mTestUserId }); mPersister.waitForQueueEmpty(); final File[] existsFiles = new File[] { - new File(sFilesDir.getPath() + "/snapshots/1.proto"), - new File(sFilesDir.getPath() + "/snapshots/1.jpg"), - new File(sFilesDir.getPath() + "/snapshots/1_reduced.jpg") }; + new File(FILES_DIR.getPath() + "/snapshots/1.proto"), + new File(FILES_DIR.getPath() + "/snapshots/1.jpg"), + new File(FILES_DIR.getPath() + "/snapshots/1_reduced.jpg") }; final File[] nonExistsFiles = new File[] { - new File(sFilesDir.getPath() + "/snapshots/2.proto"), - new File(sFilesDir.getPath() + "/snapshots/2.jpg"), - new File(sFilesDir.getPath() + "/snapshots/2_reduced.jpg")}; + new File(FILES_DIR.getPath() + "/snapshots/2.proto"), + new File(FILES_DIR.getPath() + "/snapshots/2.jpg"), + new File(FILES_DIR.getPath() + "/snapshots/2_reduced.jpg")}; assertTrueForFiles(existsFiles, File::exists, " must exist"); assertTrueForFiles(nonExistsFiles, file -> !file.exists(), " must not exist"); } @@ -281,24 +281,12 @@ public class TaskSnapshotPersisterLoaderTest extends TaskSnapshotPersisterTestBa mPersister.persistSnapshot(2, mTestUserId, createSnapshot()); mPersister.waitForQueueEmpty(); final File[] existsFiles = new File[] { - new File(sFilesDir.getPath() + "/snapshots/1.proto"), - new File(sFilesDir.getPath() + "/snapshots/1.jpg"), - new File(sFilesDir.getPath() + "/snapshots/1_reduced.jpg"), - new File(sFilesDir.getPath() + "/snapshots/2.proto"), - new File(sFilesDir.getPath() + "/snapshots/2.jpg"), - new File(sFilesDir.getPath() + "/snapshots/2_reduced.jpg")}; + new File(FILES_DIR.getPath() + "/snapshots/1.proto"), + new File(FILES_DIR.getPath() + "/snapshots/1.jpg"), + new File(FILES_DIR.getPath() + "/snapshots/1_reduced.jpg"), + new File(FILES_DIR.getPath() + "/snapshots/2.proto"), + new File(FILES_DIR.getPath() + "/snapshots/2.jpg"), + new File(FILES_DIR.getPath() + "/snapshots/2_reduced.jpg")}; assertTrueForFiles(existsFiles, File::exists, " must exist"); } - - /** - * Private predicate definition. - * - * This is needed because com.android.internal.util.Predicate is deprecated - * and can only be used with classes fron android.test.runner. This cannot - * use java.util.function.Predicate because that is not present on all API - * versions that this test must run on. - */ - private interface Predicate { - boolean apply(T t); - } } diff --git a/services/tests/servicestests/src/com/android/server/wm/TaskSnapshotPersisterTestBase.java b/services/tests/servicestests/src/com/android/server/wm/TaskSnapshotPersisterTestBase.java index 33b137ef33e2a..0f9b82586e0e8 100644 --- a/services/tests/servicestests/src/com/android/server/wm/TaskSnapshotPersisterTestBase.java +++ b/services/tests/servicestests/src/com/android/server/wm/TaskSnapshotPersisterTestBase.java @@ -11,7 +11,7 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License + * limitations under the License. */ package com.android.server.wm; @@ -21,6 +21,8 @@ import static android.content.res.Configuration.ORIENTATION_PORTRAIT; import static android.graphics.GraphicBuffer.USAGE_HW_TEXTURE; import static android.graphics.GraphicBuffer.USAGE_SW_READ_RARELY; +import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; + import android.app.ActivityManager.TaskSnapshot; import android.graphics.Canvas; import android.graphics.Color; @@ -31,51 +33,37 @@ import android.os.UserManager; import org.junit.After; import org.junit.Before; -import org.junit.BeforeClass; import java.io.File; -import androidx.test.InstrumentationRegistry; - /** * Base class for tests that use a {@link TaskSnapshotPersister}. */ class TaskSnapshotPersisterTestBase extends WindowTestsBase { private static final Rect TEST_INSETS = new Rect(10, 20, 30, 40); + static final File FILES_DIR = getInstrumentation().getTargetContext().getFilesDir(); TaskSnapshotPersister mPersister; TaskSnapshotLoader mLoader; int mTestUserId; - static File sFilesDir; - @BeforeClass - public static void setUpUser() { - sFilesDir = InstrumentationRegistry.getContext().getFilesDir(); - } - - @Override @Before - public void setUp() throws Exception { - super.setUp(); - - final UserManager um = UserManager.get(InstrumentationRegistry.getContext()); + public void setUp() { + final UserManager um = UserManager.get(getInstrumentation().getTargetContext()); mTestUserId = um.getUserHandle(); - mPersister = new TaskSnapshotPersister(userId -> sFilesDir); + mPersister = new TaskSnapshotPersister(userId -> FILES_DIR); mLoader = new TaskSnapshotLoader(mPersister); mPersister.start(); } - @Override @After - public void tearDown() throws Exception { + public void tearDown() { cleanDirectory(); - - super.tearDown(); } private void cleanDirectory() { - final File[] files = new File(sFilesDir, "snapshots").listFiles(); + final File[] files = new File(FILES_DIR, "snapshots").listFiles(); if (files == null) { return; } @@ -99,7 +87,7 @@ class TaskSnapshotPersisterTestBase extends WindowTestsBase { /** * Builds a TaskSnapshot. */ - class TaskSnapshotBuilder { + static class TaskSnapshotBuilder { private float mScale = 1f; private boolean mIsRealSnapshot = true; @@ -107,32 +95,32 @@ class TaskSnapshotPersisterTestBase extends WindowTestsBase { private int mWindowingMode = WINDOWING_MODE_FULLSCREEN; private int mSystemUiVisibility = 0; - public TaskSnapshotBuilder setScale(float scale) { + TaskSnapshotBuilder setScale(float scale) { mScale = scale; return this; } - public TaskSnapshotBuilder setIsRealSnapshot(boolean isRealSnapshot) { + TaskSnapshotBuilder setIsRealSnapshot(boolean isRealSnapshot) { mIsRealSnapshot = isRealSnapshot; return this; } - public TaskSnapshotBuilder setIsTranslucent(boolean isTranslucent) { + TaskSnapshotBuilder setIsTranslucent(boolean isTranslucent) { mIsTranslucent = isTranslucent; return this; } - public TaskSnapshotBuilder setWindowingMode(int windowingMode) { + TaskSnapshotBuilder setWindowingMode(int windowingMode) { mWindowingMode = windowingMode; return this; } - public TaskSnapshotBuilder setSystemUiVisibility(int systemUiVisibility) { + TaskSnapshotBuilder setSystemUiVisibility(int systemUiVisibility) { mSystemUiVisibility = systemUiVisibility; return this; } - public TaskSnapshot build() { + TaskSnapshot build() { final GraphicBuffer buffer = GraphicBuffer.create(100, 100, PixelFormat.RGBA_8888, USAGE_HW_TEXTURE | USAGE_SW_READ_RARELY | USAGE_SW_READ_RARELY); Canvas c = buffer.lockCanvas(); @@ -142,6 +130,5 @@ class TaskSnapshotPersisterTestBase extends WindowTestsBase { mScale < 1f /* reducedResolution */, mScale, mIsRealSnapshot, mWindowingMode, mSystemUiVisibility, mIsTranslucent); } - } } diff --git a/services/tests/servicestests/src/com/android/server/wm/TaskSnapshotSurfaceTest.java b/services/tests/servicestests/src/com/android/server/wm/TaskSnapshotSurfaceTest.java index 91074b9db0815..7c16191efec4c 100644 --- a/services/tests/servicestests/src/com/android/server/wm/TaskSnapshotSurfaceTest.java +++ b/services/tests/servicestests/src/com/android/server/wm/TaskSnapshotSurfaceTest.java @@ -39,21 +39,19 @@ import android.platform.test.annotations.Presubmit; import android.view.Surface; import androidx.test.filters.SmallTest; -import androidx.test.runner.AndroidJUnit4; import com.android.server.wm.TaskSnapshotSurface.Window; import org.junit.Test; -import org.junit.runner.RunWith; /** * Test class for {@link TaskSnapshotSurface}. * - * runtest frameworks-services -c com.android.server.wm.TaskSnapshotSurfaceTest + * Build/Install/Run: + * atest FrameworksServicesTests:TaskSnapshotSurfaceTest */ @SmallTest @Presubmit -@RunWith(AndroidJUnit4.class) public class TaskSnapshotSurfaceTest extends WindowTestsBase { private TaskSnapshotSurface mSurface; @@ -65,7 +63,7 @@ public class TaskSnapshotSurfaceTest extends WindowTestsBase { final TaskSnapshot snapshot = new TaskSnapshot(buffer, ORIENTATION_PORTRAIT, contentInsets, false, 1.0f, true /* isRealSnapshot */, WINDOWING_MODE_FULLSCREEN, 0 /* systemUiVisibility */, false /* isTranslucent */); - mSurface = new TaskSnapshotSurface(sWm, new Window(), new Surface(), snapshot, "Test", + mSurface = new TaskSnapshotSurface(mWm, new Window(), new Surface(), snapshot, "Test", Color.WHITE, Color.RED, Color.BLUE, sysuiVis, windowFlags, 0, taskBounds, ORIENTATION_PORTRAIT); } @@ -76,7 +74,7 @@ public class TaskSnapshotSurfaceTest extends WindowTestsBase { } @Test - public void fillEmptyBackground_fillHorizontally() throws Exception { + public void fillEmptyBackground_fillHorizontally() { setupSurface(200, 100); final Canvas mockCanvas = mock(Canvas.class); when(mockCanvas.getWidth()).thenReturn(200); @@ -86,7 +84,7 @@ public class TaskSnapshotSurfaceTest extends WindowTestsBase { } @Test - public void fillEmptyBackground_fillVertically() throws Exception { + public void fillEmptyBackground_fillVertically() { setupSurface(100, 200); final Canvas mockCanvas = mock(Canvas.class); when(mockCanvas.getWidth()).thenReturn(100); @@ -96,7 +94,7 @@ public class TaskSnapshotSurfaceTest extends WindowTestsBase { } @Test - public void fillEmptyBackground_fillBoth() throws Exception { + public void fillEmptyBackground_fillBoth() { setupSurface(200, 200); final Canvas mockCanvas = mock(Canvas.class); when(mockCanvas.getWidth()).thenReturn(200); @@ -107,7 +105,7 @@ public class TaskSnapshotSurfaceTest extends WindowTestsBase { } @Test - public void fillEmptyBackground_dontFill_sameSize() throws Exception { + public void fillEmptyBackground_dontFill_sameSize() { setupSurface(100, 100); final Canvas mockCanvas = mock(Canvas.class); when(mockCanvas.getWidth()).thenReturn(100); @@ -117,7 +115,7 @@ public class TaskSnapshotSurfaceTest extends WindowTestsBase { } @Test - public void fillEmptyBackground_dontFill_bitmapLarger() throws Exception { + public void fillEmptyBackground_dontFill_bitmapLarger() { setupSurface(100, 100); final Canvas mockCanvas = mock(Canvas.class); when(mockCanvas.getWidth()).thenReturn(100); diff --git a/services/tests/servicestests/src/com/android/server/wm/TaskStackContainersTests.java b/services/tests/servicestests/src/com/android/server/wm/TaskStackContainersTests.java index 0e9a63ce728b4..f01e9f0662c92 100644 --- a/services/tests/servicestests/src/com/android/server/wm/TaskStackContainersTests.java +++ b/services/tests/servicestests/src/com/android/server/wm/TaskStackContainersTests.java @@ -11,7 +11,7 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License + * limitations under the License. */ package com.android.server.wm; @@ -27,17 +27,17 @@ import static org.junit.Assert.assertTrue; import android.platform.test.annotations.Presubmit; +import androidx.test.filters.SmallTest; + import org.junit.After; import org.junit.Before; import org.junit.Test; -import androidx.test.filters.SmallTest; - /** * Tests for the {@link DisplayContent.TaskStackContainers} container in {@link DisplayContent}. * * Build/Install/Run: - * atest FrameworksServicesTests:com.android.server.wm.TaskStackContainersTests + * atest FrameworksServicesTests:TaskStackContainersTests */ @SmallTest @Presubmit @@ -45,11 +45,8 @@ public class TaskStackContainersTests extends WindowTestsBase { private TaskStack mPinnedStack; - @Override @Before public void setUp() throws Exception { - super.setUp(); - mPinnedStack = createStackControllerOnStackOnDisplay( WINDOWING_MODE_PINNED, ACTIVITY_TYPE_STANDARD, mDisplayContent).mContainer; // Stack should contain visible app window to be considered visible. @@ -61,12 +58,9 @@ public class TaskStackContainersTests extends WindowTestsBase { assertTrue(mPinnedStack.isVisible()); } - @Override @After public void tearDown() throws Exception { mPinnedStack.removeImmediately(); - - super.tearDown(); } @Test @@ -121,14 +115,14 @@ public class TaskStackContainersTests extends WindowTestsBase { final Task task = createTaskInStack(stack, 0 /* userId */); // Add another display at top. - sWm.mRoot.positionChildAt(WindowContainer.POSITION_TOP, createNewDisplay(), + mWm.mRoot.positionChildAt(WindowContainer.POSITION_TOP, createNewDisplay(), false /* includingParents */); // Move the task of {@code mDisplayContent} to top. stack.positionChildAt(WindowContainer.POSITION_TOP, task, true /* includingParents */); - final int indexOfDisplayWithPinnedStack = sWm.mRoot.mChildren.indexOf(mDisplayContent); + final int indexOfDisplayWithPinnedStack = mWm.mRoot.mChildren.indexOf(mDisplayContent); assertEquals("The testing DisplayContent should be moved to top with task", - sWm.mRoot.getChildCount() - 1, indexOfDisplayWithPinnedStack); + mWm.mRoot.getChildCount() - 1, indexOfDisplayWithPinnedStack); } } diff --git a/services/tests/servicestests/src/com/android/server/wm/TaskStackTests.java b/services/tests/servicestests/src/com/android/server/wm/TaskStackTests.java index cb5c1cd67092d..7ac331829fb19 100644 --- a/services/tests/servicestests/src/com/android/server/wm/TaskStackTests.java +++ b/services/tests/servicestests/src/com/android/server/wm/TaskStackTests.java @@ -11,7 +11,7 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License + * limitations under the License. */ package com.android.server.wm; @@ -25,24 +25,21 @@ import static org.junit.Assert.assertNull; import android.platform.test.annotations.Presubmit; import androidx.test.filters.SmallTest; -import androidx.test.runner.AndroidJUnit4; import org.junit.Test; -import org.junit.runner.RunWith; /** * Tests for the {@link TaskStack} class. * * Build/Install/Run: - * bit FrameworksServicesTests:com.android.server.wm.TaskStackTests + * atest FrameworksServicesTests:TaskStackTests */ @SmallTest @Presubmit -@RunWith(AndroidJUnit4.class) public class TaskStackTests extends WindowTestsBase { @Test - public void testStackPositionChildAt() throws Exception { + public void testStackPositionChildAt() { final TaskStack stack = createTaskStackOnDisplay(mDisplayContent); final Task task1 = createTaskInStack(stack, 0 /* userId */); final Task task2 = createTaskInStack(stack, 1 /* userId */); @@ -59,7 +56,7 @@ public class TaskStackTests extends WindowTestsBase { } @Test - public void testClosingAppDifferentStackOrientation() throws Exception { + public void testClosingAppDifferentStackOrientation() { final TaskStack stack = createTaskStackOnDisplay(mDisplayContent); final Task task1 = createTaskInStack(stack, 0 /* userId */); WindowTestUtils.TestAppWindowToken appWindowToken1 = @@ -79,7 +76,7 @@ public class TaskStackTests extends WindowTestsBase { } @Test - public void testMoveTaskToBackDifferentStackOrientation() throws Exception { + public void testMoveTaskToBackDifferentStackOrientation() { final TaskStack stack = createTaskStackOnDisplay(mDisplayContent); final Task task1 = createTaskInStack(stack, 0 /* userId */); WindowTestUtils.TestAppWindowToken appWindowToken1 = @@ -99,7 +96,7 @@ public class TaskStackTests extends WindowTestsBase { } @Test - public void testStackRemoveImmediately() throws Exception { + public void testStackRemoveImmediately() { final TaskStack stack = createTaskStackOnDisplay(mDisplayContent); final Task task = createTaskInStack(stack, 0 /* userId */); assertEquals(stack, task.mStack); diff --git a/services/tests/servicestests/src/com/android/server/wm/TaskWindowContainerControllerTests.java b/services/tests/servicestests/src/com/android/server/wm/TaskWindowContainerControllerTests.java index edd76647f4a87..1af79e41fe376 100644 --- a/services/tests/servicestests/src/com/android/server/wm/TaskWindowContainerControllerTests.java +++ b/services/tests/servicestests/src/com/android/server/wm/TaskWindowContainerControllerTests.java @@ -11,7 +11,7 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License + * limitations under the License. */ package com.android.server.wm; @@ -24,24 +24,21 @@ import static org.junit.Assert.assertTrue; import android.platform.test.annotations.Presubmit; import androidx.test.filters.SmallTest; -import androidx.test.runner.AndroidJUnit4; import org.junit.Test; -import org.junit.runner.RunWith; /** * Test class for {@link TaskWindowContainerController}. * * Build/Install/Run: - * bit FrameworksServicesTests:com.android.server.wm.TaskWindowContainerControllerTests + * atest FrameworksServicesTests:TaskWindowContainerControllerTests */ @SmallTest @Presubmit -@RunWith(AndroidJUnit4.class) public class TaskWindowContainerControllerTests extends WindowTestsBase { @Test - public void testRemoveContainer() throws Exception { + public void testRemoveContainer() { final WindowTestUtils.TestTaskWindowContainerController taskController = new WindowTestUtils.TestTaskWindowContainerController(this); final WindowTestUtils.TestAppWindowContainerController appController = @@ -54,7 +51,7 @@ public class TaskWindowContainerControllerTests extends WindowTestsBase { } @Test - public void testRemoveContainer_deferRemoval() throws Exception { + public void testRemoveContainer_deferRemoval() { final WindowTestUtils.TestTaskWindowContainerController taskController = new WindowTestUtils.TestTaskWindowContainerController(this); final WindowTestUtils.TestAppWindowContainerController appController = @@ -79,7 +76,7 @@ public class TaskWindowContainerControllerTests extends WindowTestsBase { } @Test - public void testReparent() throws Exception { + public void testReparent() { final StackWindowController stackController1 = createStackControllerOnDisplay(mDisplayContent); final WindowTestUtils.TestTaskWindowContainerController taskController = @@ -116,7 +113,7 @@ public class TaskWindowContainerControllerTests extends WindowTestsBase { } @Test - public void testReparent_BetweenDisplays() throws Exception { + public void testReparent_BetweenDisplays() { // Create first stack on primary display. final StackWindowController stack1Controller = createStackControllerOnDisplay(mDisplayContent); diff --git a/services/tests/servicestests/src/com/android/server/wm/TestIWindow.java b/services/tests/servicestests/src/com/android/server/wm/TestIWindow.java index 353aa7deb534b..e8d0a066dade5 100644 --- a/services/tests/servicestests/src/com/android/server/wm/TestIWindow.java +++ b/services/tests/servicestests/src/com/android/server/wm/TestIWindow.java @@ -11,13 +11,11 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License + * limitations under the License. */ package com.android.server.wm; -import com.android.internal.os.IResultReceiver; - import android.graphics.Rect; import android.os.Bundle; import android.os.ParcelFileDescriptor; @@ -27,87 +25,71 @@ import android.view.DisplayCutout; import android.view.DragEvent; import android.view.IWindow; +import com.android.internal.os.IResultReceiver; + public class TestIWindow extends IWindow.Stub { @Override public void executeCommand(String command, String parameters, - ParcelFileDescriptor descriptor) - throws RemoteException { - + ParcelFileDescriptor descriptor) throws RemoteException { } @Override public void resized(Rect frame, Rect overscanInsets, Rect contentInsets, Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw, MergedConfiguration mergedConfig, Rect backDropFrame, boolean forceLayout, boolean alwaysConsumeNavBar, int displayId, - DisplayCutout.ParcelableWrapper displayCutout) - throws RemoteException { - + DisplayCutout.ParcelableWrapper displayCutout) throws RemoteException { } @Override public void moved(int newX, int newY) throws RemoteException { - } @Override public void dispatchAppVisibility(boolean visible) throws RemoteException { - } @Override public void dispatchGetNewSurface() throws RemoteException { - } @Override - public void windowFocusChanged(boolean hasFocus, boolean inTouchMode) - throws RemoteException { - + public void windowFocusChanged(boolean hasFocus, boolean inTouchMode) throws RemoteException { } @Override public void closeSystemDialogs(String reason) throws RemoteException { - } @Override - public void dispatchWallpaperOffsets(float x, float y, float xStep, float yStep, - boolean sync) + public void dispatchWallpaperOffsets(float x, float y, float xStep, float yStep, boolean sync) throws RemoteException { - } @Override public void dispatchWallpaperCommand(String action, int x, int y, int z, Bundle extras, boolean sync) throws RemoteException { - } @Override public void dispatchDragEvent(DragEvent event) throws RemoteException { - } @Override public void updatePointerIcon(float x, float y) throws RemoteException { - } @Override public void dispatchSystemUiVisibilityChanged(int seq, int globalVisibility, int localValue, int localChanges) throws RemoteException { - } @Override public void dispatchWindowShown() throws RemoteException { - } @Override public void requestAppKeyboardShortcuts(IResultReceiver receiver, int deviceId) throws RemoteException { - } @Override diff --git a/services/tests/servicestests/src/com/android/server/wm/TestWindowManagerPolicy.java b/services/tests/servicestests/src/com/android/server/wm/TestWindowManagerPolicy.java index 19abd9e8dac90..0165e7d4e84b1 100644 --- a/services/tests/servicestests/src/com/android/server/wm/TestWindowManagerPolicy.java +++ b/services/tests/servicestests/src/com/android/server/wm/TestWindowManagerPolicy.java @@ -11,7 +11,7 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License + * limitations under the License. */ package com.android.server.wm; @@ -46,8 +46,6 @@ import java.io.PrintWriter; import java.util.function.Supplier; class TestWindowManagerPolicy implements WindowManagerPolicy { - private static final String TAG = "TestWindowManagerPolicy"; - private final Supplier mWmSupplier; int rotationToReport = 0; @@ -55,21 +53,18 @@ class TestWindowManagerPolicy implements WindowManagerPolicy { private Runnable mRunnableWhenAddingSplashScreen; - public TestWindowManagerPolicy(Supplier wmSupplier) { - + TestWindowManagerPolicy(Supplier wmSupplier) { mWmSupplier = wmSupplier; } @Override public void registerShortcutKey(long shortcutCode, IShortcutService shortcutKeyReceiver) throws RemoteException { - } @Override public void init(Context context, IWindowManager windowManager, WindowManagerFuncs windowManagerFuncs) { - } public void setDefaultDisplay(DisplayContentInfo displayContentInfo) { @@ -93,7 +88,6 @@ class TestWindowManagerPolicy implements WindowManagerPolicy { @Override public void adjustConfigurationLw(Configuration config, int keyboardPresence, int navigationPresence) { - } @Override @@ -179,7 +173,6 @@ class TestWindowManagerPolicy implements WindowManagerPolicy { @Override public void removeWindowLw(WindowState win) { - } @Override @@ -189,7 +182,6 @@ class TestWindowManagerPolicy implements WindowManagerPolicy { @Override public void selectRotationAnimationLw(int[] anim) { - } @Override @@ -220,14 +212,12 @@ class TestWindowManagerPolicy implements WindowManagerPolicy { } @Override - public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, - int policyFlags) { + public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) { return 0; } @Override - public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, - int policyFlags) { + public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) { return null; } @@ -238,12 +228,11 @@ class TestWindowManagerPolicy implements WindowManagerPolicy { @Override public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) { - } @Override - public void applyPostLayoutPolicyLw(WindowState win, - WindowManager.LayoutParams attrs, WindowState attached, WindowState imeTarget) { + public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs, + WindowState attached, WindowState imeTarget) { } @Override @@ -257,49 +246,40 @@ class TestWindowManagerPolicy implements WindowManagerPolicy { } @Override - public int focusChangedLw(WindowState lastFocus, - WindowState newFocus) { + public int focusChangedLw(WindowState lastFocus, WindowState newFocus) { return 0; } @Override public void startedWakingUp() { - } @Override public void finishedWakingUp() { - } @Override public void startedGoingToSleep(int why) { - } @Override public void finishedGoingToSleep(int why) { - } @Override public void screenTurningOn(ScreenOnListener screenOnListener) { - } @Override public void screenTurnedOn() { - } @Override public void screenTurningOff(ScreenOffListener screenOffListener) { - } @Override public void screenTurnedOff() { - } @Override @@ -314,22 +294,18 @@ class TestWindowManagerPolicy implements WindowManagerPolicy { @Override public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) { - } @Override public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) { - } @Override public void enableKeyguard(boolean enabled) { - } @Override public void exitKeyguardSecurely(OnKeyguardExitResult callback) { - } @Override @@ -382,53 +358,44 @@ class TestWindowManagerPolicy implements WindowManagerPolicy { } public void setSafeMode(boolean safeMode) { - } @Override public void systemReady() { - } @Override public void systemBooted() { - } @Override public void showBootMessage(CharSequence msg, boolean always) { - } @Override public void hideBootMessages() { - } @Override public void userActivity() { - } @Override public void enableScreenAfterBoot() { - } @Override - public boolean performHapticFeedbackLw(WindowState win, int effectId, - boolean always, String reason) { + public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always, + String reason) { return false; } @Override public void keepScreenOnStartedLw() { - } @Override public void keepScreenOnStoppedLw() { - } @Override @@ -443,37 +410,30 @@ class TestWindowManagerPolicy implements WindowManagerPolicy { @Override public void lockNow(Bundle options) { - } @Override public void showRecentApps() { - } @Override public void showGlobalActions() { - } @Override public void setCurrentUserLw(int newUserId) { - } @Override public void setSwitchingUser(boolean switching) { - } @Override public void writeToProto(ProtoOutputStream proto, long fieldId) { - } @Override public void dump(String prefix, PrintWriter writer, String[] args) { - } @Override @@ -483,13 +443,11 @@ class TestWindowManagerPolicy implements WindowManagerPolicy { @Override public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) { - } @Override public void getStableInsetsLw(int displayRotation, int displayWidth, int displayHeight, DisplayCutout cutout, Rect outInsets) { - } @Override @@ -506,7 +464,6 @@ class TestWindowManagerPolicy implements WindowManagerPolicy { @Override public void getNonDecorInsetsLw(int displayRotation, int displayWidth, int displayHeight, DisplayCutout cutout, Rect outInsets) { - } @Override @@ -517,7 +474,6 @@ class TestWindowManagerPolicy implements WindowManagerPolicy { @Override public void onConfigurationChanged(DisplayContentInfo displayContentInfo) { - } @Override @@ -528,12 +484,10 @@ class TestWindowManagerPolicy implements WindowManagerPolicy { @Override public void setPipVisibilityLw(boolean visible) { - } @Override public void setRecentsVisibilityLw(boolean visible) { - } @Override diff --git a/services/tests/servicestests/src/com/android/server/wm/UnknownAppVisibilityControllerTest.java b/services/tests/servicestests/src/com/android/server/wm/UnknownAppVisibilityControllerTest.java index 54456fbd6f3bb..9e22c0a86d969 100644 --- a/services/tests/servicestests/src/com/android/server/wm/UnknownAppVisibilityControllerTest.java +++ b/services/tests/servicestests/src/com/android/server/wm/UnknownAppVisibilityControllerTest.java @@ -11,52 +11,50 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License + * limitations under the License. */ package com.android.server.wm; import static junit.framework.Assert.assertTrue; +import android.os.SystemClock; import android.platform.test.annotations.Presubmit; import androidx.test.filters.SmallTest; -import androidx.test.runner.AndroidJUnit4; import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; /** * Test class for {@link AppTransition}. * - * runtest frameworks-services -c com.android.server.wm.UnknownAppVisibilityControllerTest + * Build/Install/Run: + * atest FrameworksServicesTests:UnknownAppVisibilityControllerTest */ @SmallTest @Presubmit -@RunWith(AndroidJUnit4.class) public class UnknownAppVisibilityControllerTest extends WindowTestsBase { @Before public void setUp() throws Exception { - super.setUp(); mDisplayContent.mUnknownAppVisibilityController.clear(); } @Test - public void testFlow() throws Exception { + public void testFlow() { final AppWindowToken token = WindowTestUtils.createTestAppWindowToken(mDisplayContent); mDisplayContent.mUnknownAppVisibilityController.notifyLaunched(token); mDisplayContent.mUnknownAppVisibilityController.notifyAppResumedFinished(token); mDisplayContent.mUnknownAppVisibilityController.notifyRelayouted(token); // Make sure our handler processed the message. - Thread.sleep(100); + SystemClock.sleep(100); assertTrue(mDisplayContent.mUnknownAppVisibilityController.allResolved()); } @Test - public void testMultiple() throws Exception { + public void testMultiple() { final AppWindowToken token1 = WindowTestUtils.createTestAppWindowToken(mDisplayContent); final AppWindowToken token2 = WindowTestUtils.createTestAppWindowToken(mDisplayContent); mDisplayContent.mUnknownAppVisibilityController.notifyLaunched(token1); @@ -67,12 +65,12 @@ public class UnknownAppVisibilityControllerTest extends WindowTestsBase { mDisplayContent.mUnknownAppVisibilityController.notifyRelayouted(token2); // Make sure our handler processed the message. - Thread.sleep(100); + SystemClock.sleep(100); assertTrue(mDisplayContent.mUnknownAppVisibilityController.allResolved()); } @Test - public void testClear() throws Exception { + public void testClear() { final AppWindowToken token = WindowTestUtils.createTestAppWindowToken(mDisplayContent); mDisplayContent.mUnknownAppVisibilityController.notifyLaunched(token); mDisplayContent.mUnknownAppVisibilityController.clear();; @@ -80,7 +78,7 @@ public class UnknownAppVisibilityControllerTest extends WindowTestsBase { } @Test - public void testAppRemoved() throws Exception { + public void testAppRemoved() { final AppWindowToken token = WindowTestUtils.createTestAppWindowToken(mDisplayContent); mDisplayContent.mUnknownAppVisibilityController.notifyLaunched(token); mDisplayContent.mUnknownAppVisibilityController.appRemovedOrHidden(token); diff --git a/services/tests/servicestests/src/com/android/server/wm/WallpaperControllerTests.java b/services/tests/servicestests/src/com/android/server/wm/WallpaperControllerTests.java index e3280ca3c9f06..25e73e3740c51 100644 --- a/services/tests/servicestests/src/com/android/server/wm/WallpaperControllerTests.java +++ b/services/tests/servicestests/src/com/android/server/wm/WallpaperControllerTests.java @@ -1,3 +1,19 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.android.server.wm; import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; @@ -13,33 +29,30 @@ import android.os.IBinder; import android.platform.test.annotations.Presubmit; import androidx.test.filters.SmallTest; -import androidx.test.runner.AndroidJUnit4; import org.junit.Test; -import org.junit.runner.RunWith; /** * Tests for the {@link WallpaperController} class. * * Build/Install/Run: - * atest com.android.server.wm.WallpaperControllerTests + * atest FrameworksServicesTests:WallpaperControllerTests */ @SmallTest @Presubmit -@RunWith(AndroidJUnit4.class) public class WallpaperControllerTests extends WindowTestsBase { @Test public void testWallpaperScreenshot() { WindowSurfaceController windowSurfaceController = mock(WindowSurfaceController.class); - synchronized (sWm.mGlobalLock) { + synchronized (mWm.mGlobalLock) { // No wallpaper final DisplayContent dc = createNewDisplay(); - Bitmap wallpaperBitmap = sWm.mRoot.mWallpaperController.screenshotWallpaperLocked(); + Bitmap wallpaperBitmap = mWm.mRoot.mWallpaperController.screenshotWallpaperLocked(); assertNull(wallpaperBitmap); // No wallpaper WSA Surface - WindowToken wallpaperWindowToken = new WallpaperWindowToken(sWm, mock(IBinder.class), + WindowToken wallpaperWindowToken = new WallpaperWindowToken(mWm, mock(IBinder.class), true, dc, true /* ownerCanManageAppTokens */); WindowState wallpaperWindow = createWindow(null /* parent */, TYPE_WALLPAPER, wallpaperWindowToken, "wallpaperWindow"); diff --git a/services/tests/servicestests/src/com/android/server/wm/WindowConfigurationTests.java b/services/tests/servicestests/src/com/android/server/wm/WindowConfigurationTests.java index e7cc2859ff628..4369c96dd488b 100644 --- a/services/tests/servicestests/src/com/android/server/wm/WindowConfigurationTests.java +++ b/services/tests/servicestests/src/com/android/server/wm/WindowConfigurationTests.java @@ -36,26 +36,24 @@ import android.view.DisplayInfo; import androidx.test.filters.FlakyTest; import androidx.test.filters.SmallTest; -import androidx.test.runner.AndroidJUnit4; +import org.junit.Before; import org.junit.Test; /** * Test class to for {@link android.app.WindowConfiguration}. * * Build/Install/Run: - * bit FrameworksServicesTests:com.android.server.wm.WindowConfigurationTests + * atest FrameworksServicesTests:WindowConfigurationTests */ -@SmallTest @FlakyTest(bugId = 74078662) +@SmallTest @Presubmit -@org.junit.runner.RunWith(AndroidJUnit4.class) public class WindowConfigurationTests extends WindowTestsBase { private Rect mParentBounds; - @Override + @Before public void setUp() throws Exception { - super.setUp(); mParentBounds = new Rect(10 /*left*/, 30 /*top*/, 80 /*right*/, 60 /*bottom*/); } @@ -95,7 +93,7 @@ public class WindowConfigurationTests extends WindowTestsBase { /** Tests {@link android.app.WindowConfiguration#compareTo(WindowConfiguration)}. */ @Test - public void testConfigurationCompareTo() throws Exception { + public void testConfigurationCompareTo() { final Configuration blankConfig = new Configuration(); final WindowConfiguration blankWinConfig = new WindowConfiguration(); @@ -135,7 +133,7 @@ public class WindowConfigurationTests extends WindowTestsBase { } @Test - public void testSetActivityType() throws Exception { + public void testSetActivityType() { final WindowConfiguration config = new WindowConfiguration(); config.setActivityType(ACTIVITY_TYPE_HOME); assertEquals(ACTIVITY_TYPE_HOME, config.getActivityType()); @@ -147,12 +145,12 @@ public class WindowConfigurationTests extends WindowTestsBase { /** Ensures the configuration app bounds at the root level match the app dimensions. */ @Test - public void testAppBounds_RootConfigurationBounds() throws Exception { + public void testAppBounds_RootConfigurationBounds() { final DisplayInfo info = mDisplayContent.getDisplayInfo(); info.appWidth = 1024; info.appHeight = 768; - final Rect appBounds = sWm.computeNewConfiguration( + final Rect appBounds = mWm.computeNewConfiguration( mDisplayContent.getDisplayId()).windowConfiguration.getAppBounds(); // The bounds should always be positioned in the top left. assertEquals(appBounds.left, 0); @@ -165,7 +163,7 @@ public class WindowConfigurationTests extends WindowTestsBase { /** Ensures that bounds are clipped to their parent. */ @Test - public void testAppBounds_BoundsClipping() throws Exception { + public void testAppBounds_BoundsClipping() { final Rect shiftedBounds = new Rect(mParentBounds); shiftedBounds.offset(10, 10); final Rect expectedBounds = new Rect(mParentBounds); @@ -176,7 +174,7 @@ public class WindowConfigurationTests extends WindowTestsBase { /** Ensures that empty bounds are not propagated to the configuration. */ @Test - public void testAppBounds_EmptyBounds() throws Exception { + public void testAppBounds_EmptyBounds() { final Rect emptyBounds = new Rect(); testStackBoundsConfiguration(WINDOWING_MODE_FULLSCREEN, mParentBounds, emptyBounds, null /*ExpectedBounds*/); @@ -184,7 +182,7 @@ public class WindowConfigurationTests extends WindowTestsBase { /** Ensures that bounds on freeform stacks are not clipped. */ @Test - public void testAppBounds_FreeFormBounds() throws Exception { + public void testAppBounds_FreeFormBounds() { final Rect freeFormBounds = new Rect(mParentBounds); freeFormBounds.offset(10, 10); testStackBoundsConfiguration(WINDOWING_MODE_FREEFORM, mParentBounds, freeFormBounds, @@ -193,7 +191,7 @@ public class WindowConfigurationTests extends WindowTestsBase { /** Ensures that fully contained bounds are not clipped. */ @Test - public void testAppBounds_ContainedBounds() throws Exception { + public void testAppBounds_ContainedBounds() { final Rect insetBounds = new Rect(mParentBounds); insetBounds.inset(5, 5, 5, 5); testStackBoundsConfiguration( @@ -202,7 +200,7 @@ public class WindowConfigurationTests extends WindowTestsBase { /** Ensures that full screen free form bounds are clipped */ @Test - public void testAppBounds_FullScreenFreeFormBounds() throws Exception { + public void testAppBounds_FullScreenFreeFormBounds() { final Rect fullScreenBounds = new Rect(0, 0, mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight); testStackBoundsConfiguration(WINDOWING_MODE_FULLSCREEN, mParentBounds, fullScreenBounds, diff --git a/services/tests/servicestests/src/com/android/server/wm/WindowContainerControllerTests.java b/services/tests/servicestests/src/com/android/server/wm/WindowContainerControllerTests.java index 6b1feb87aa428..7592f1c1fca0a 100644 --- a/services/tests/servicestests/src/com/android/server/wm/WindowContainerControllerTests.java +++ b/services/tests/servicestests/src/com/android/server/wm/WindowContainerControllerTests.java @@ -11,7 +11,7 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License + * limitations under the License. */ package com.android.server.wm; @@ -28,7 +28,6 @@ import android.platform.test.annotations.Presubmit; import androidx.test.filters.FlakyTest; import androidx.test.filters.SmallTest; -import androidx.test.runner.AndroidJUnit4; import org.junit.Test; @@ -36,18 +35,17 @@ import org.junit.Test; * Test class for {@link WindowContainerController}. * * Build/Install/Run: - * bit FrameworksServicesTests:com.android.server.wm.WindowContainerControllerTests + * atest FrameworksServicesTests:WindowContainerControllerTests */ +@FlakyTest(bugId = 74078662) @SmallTest @Presubmit -@FlakyTest(bugId = 74078662) -@org.junit.runner.RunWith(AndroidJUnit4.class) public class WindowContainerControllerTests extends WindowTestsBase { @Test - public void testCreation() throws Exception { - final WindowContainerController controller = new WindowContainerController(null, sWm); - final WindowContainer container = new WindowContainer(sWm); + public void testCreation() { + final WindowContainerController controller = new WindowContainerController<>(null, mWm); + final WindowContainer container = new WindowContainer(mWm); container.setController(controller); assertEquals(controller, container.getController()); @@ -55,9 +53,9 @@ public class WindowContainerControllerTests extends WindowTestsBase { } @Test - public void testSetContainer() throws Exception { - final WindowContainerController controller = new WindowContainerController(null, sWm); - final WindowContainer container = new WindowContainer(sWm); + public void testSetContainer() { + final WindowContainerController controller = new WindowContainerController<>(null, mWm); + final WindowContainer container = new WindowContainer(mWm); controller.setContainer(container); assertEquals(controller.mContainer, container); @@ -65,7 +63,7 @@ public class WindowContainerControllerTests extends WindowTestsBase { // Assert we can't change the container to another one once set boolean gotException = false; try { - controller.setContainer(new WindowContainer(sWm)); + controller.setContainer(new WindowContainer(mWm)); } catch (IllegalArgumentException e) { gotException = true; } @@ -77,9 +75,9 @@ public class WindowContainerControllerTests extends WindowTestsBase { } @Test - public void testRemoveContainer() throws Exception { - final WindowContainerController controller = new WindowContainerController(null, sWm); - final WindowContainer container = new WindowContainer(sWm); + public void testRemoveContainer() { + final WindowContainerController controller = new WindowContainerController<>(null, mWm); + final WindowContainer container = new WindowContainer(mWm); controller.setContainer(container); assertEquals(controller.mContainer, container); @@ -89,9 +87,9 @@ public class WindowContainerControllerTests extends WindowTestsBase { } @Test - public void testOnOverrideConfigurationChanged() throws Exception { - final WindowContainerController controller = new WindowContainerController(null, sWm); - final WindowContainer container = new WindowContainer(sWm); + public void testOnOverrideConfigurationChanged() { + final WindowContainerController controller = new WindowContainerController<>(null, mWm); + final WindowContainer container = new WindowContainer(mWm); controller.setContainer(container); assertEquals(controller.mContainer, container); 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 dc763b9bb079f..e59afd6564200 100644 --- a/services/tests/servicestests/src/com/android/server/wm/WindowContainerTests.java +++ b/services/tests/servicestests/src/com/android/server/wm/WindowContainerTests.java @@ -11,7 +11,7 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License + * limitations under the License. */ package com.android.server.wm; @@ -46,10 +46,8 @@ import android.view.SurfaceSession; import androidx.test.filters.FlakyTest; import androidx.test.filters.SmallTest; -import androidx.test.runner.AndroidJUnit4; import org.junit.Test; -import org.junit.runner.RunWith; import java.util.Comparator; @@ -57,24 +55,23 @@ import java.util.Comparator; * Test class for {@link WindowContainer}. * * Build/Install/Run: - * atest FrameworksServicesTests:com.android.server.wm.WindowContainerTests + * atest FrameworksServicesTests:WindowContainerTests */ @SmallTest @Presubmit @FlakyTest(bugId = 74078662) -@RunWith(AndroidJUnit4.class) public class WindowContainerTests extends WindowTestsBase { @Test - public void testCreation() throws Exception { - final TestWindowContainer w = new TestWindowContainerBuilder().setLayer(0).build(); + public void testCreation() { + final TestWindowContainer w = new TestWindowContainerBuilder(mWm).setLayer(0).build(); assertNull("window must have no parent", w.getParentWindow()); assertEquals("window must have no children", 0, w.getChildrenCount()); } @Test - public void testAdd() throws Exception { - final TestWindowContainerBuilder builder = new TestWindowContainerBuilder(); + public void testAdd() { + final TestWindowContainerBuilder builder = new TestWindowContainerBuilder(mWm); final TestWindowContainer root = builder.setLayer(0).build(); final TestWindowContainer layer1 = root.addChildWindow(builder.setLayer(1)); @@ -113,23 +110,24 @@ public class WindowContainerTests extends WindowTestsBase { } @Test - public void testAddChildSetsSurfacePosition() throws Exception { - MockSurfaceBuildingContainer top = new MockSurfaceBuildingContainer(); + public void testAddChildSetsSurfacePosition() { + try (MockSurfaceBuildingContainer top = new MockSurfaceBuildingContainer(mWm)) { - final SurfaceControl.Transaction transaction = mock(SurfaceControl.Transaction.class); - sWm.mTransactionFactory = () -> transaction; + final SurfaceControl.Transaction transaction = mock(SurfaceControl.Transaction.class); + mWm.mTransactionFactory = () -> transaction; - WindowContainer child = new WindowContainer(sWm); - child.setBounds(1, 1, 10, 10); + WindowContainer child = new WindowContainer(mWm); + child.setBounds(1, 1, 10, 10); - verify(transaction, never()).setPosition(any(), anyFloat(), anyFloat()); - top.addChild(child, 0); - verify(transaction, times(1)).setPosition(any(), eq(1.f), eq(1.f)); + verify(transaction, never()).setPosition(any(), anyFloat(), anyFloat()); + top.addChild(child, 0); + verify(transaction, times(1)).setPosition(any(), eq(1.f), eq(1.f)); + } } @Test - public void testAdd_AlreadyHasParent() throws Exception { - final TestWindowContainerBuilder builder = new TestWindowContainerBuilder(); + public void testAdd_AlreadyHasParent() { + final TestWindowContainerBuilder builder = new TestWindowContainerBuilder(mWm); final TestWindowContainer root = builder.setLayer(0).build(); final TestWindowContainer child1 = root.addChildWindow(); @@ -153,8 +151,8 @@ public class WindowContainerTests extends WindowTestsBase { } @Test - public void testHasChild() throws Exception { - final TestWindowContainerBuilder builder = new TestWindowContainerBuilder(); + public void testHasChild() { + final TestWindowContainerBuilder builder = new TestWindowContainerBuilder(mWm); final TestWindowContainer root = builder.setLayer(0).build(); final TestWindowContainer child1 = root.addChildWindow(); @@ -183,8 +181,8 @@ public class WindowContainerTests extends WindowTestsBase { } @Test - public void testRemoveImmediately() throws Exception { - final TestWindowContainerBuilder builder = new TestWindowContainerBuilder(); + public void testRemoveImmediately() { + final TestWindowContainerBuilder builder = new TestWindowContainerBuilder(mWm); final TestWindowContainer root = builder.setLayer(0).build(); final TestWindowContainer child1 = root.addChildWindow(); @@ -218,9 +216,9 @@ public class WindowContainerTests extends WindowTestsBase { } @Test - public void testRemoveImmediately_WithController() throws Exception { - final WindowContainer container = new WindowContainer(sWm); - final WindowContainerController controller = new WindowContainerController(null, sWm); + public void testRemoveImmediately_WithController() { + final WindowContainer container = new WindowContainer(mWm); + final WindowContainerController controller = new WindowContainerController<>(null, mWm); container.setController(controller); assertEquals(controller, container.getController()); @@ -232,9 +230,9 @@ public class WindowContainerTests extends WindowTestsBase { } @Test - public void testSetController() throws Exception { - final WindowContainerController controller = new WindowContainerController(null, sWm); - final WindowContainer container = new WindowContainer(sWm); + public void testSetController() { + final WindowContainerController controller = new WindowContainerController<>(null, mWm); + final WindowContainer container = new WindowContainer(mWm); container.setController(controller); assertEquals(controller, container.getController()); @@ -243,7 +241,7 @@ public class WindowContainerTests extends WindowTestsBase { // Assert we can't change the controller to another one once set boolean gotException = false; try { - container.setController(new WindowContainerController(null, sWm)); + container.setController(new WindowContainerController<>(null, mWm)); } catch (IllegalArgumentException e) { gotException = true; } @@ -256,8 +254,8 @@ public class WindowContainerTests extends WindowTestsBase { } @Test - public void testAddChildByIndex() throws Exception { - final TestWindowContainerBuilder builder = new TestWindowContainerBuilder(); + public void testAddChildByIndex() { + final TestWindowContainerBuilder builder = new TestWindowContainerBuilder(mWm); final TestWindowContainer root = builder.setLayer(0).build(); final TestWindowContainer child = root.addChildWindow(); @@ -283,8 +281,8 @@ public class WindowContainerTests extends WindowTestsBase { } @Test - public void testPositionChildAt() throws Exception { - final TestWindowContainerBuilder builder = new TestWindowContainerBuilder(); + public void testPositionChildAt() { + final TestWindowContainerBuilder builder = new TestWindowContainerBuilder(mWm); final TestWindowContainer root = builder.setLayer(0).build(); final TestWindowContainer child1 = root.addChildWindow(); @@ -307,8 +305,8 @@ public class WindowContainerTests extends WindowTestsBase { } @Test - public void testPositionChildAtIncludeParents() throws Exception { - final TestWindowContainerBuilder builder = new TestWindowContainerBuilder(); + public void testPositionChildAtIncludeParents() { + final TestWindowContainerBuilder builder = new TestWindowContainerBuilder(mWm); final TestWindowContainer root = builder.setLayer(0).build(); final TestWindowContainer child1 = root.addChildWindow(); @@ -349,12 +347,11 @@ public class WindowContainerTests extends WindowTestsBase { } @Test - public void testPositionChildAtInvalid() throws Exception { - final TestWindowContainerBuilder builder = new TestWindowContainerBuilder(); + public void testPositionChildAtInvalid() { + final TestWindowContainerBuilder builder = new TestWindowContainerBuilder(mWm); final TestWindowContainer root = builder.setLayer(0).build(); final TestWindowContainer child1 = root.addChildWindow(); - final TestWindowContainer child2 = root.addChildWindow(); boolean gotException = false; try { @@ -376,8 +373,8 @@ public class WindowContainerTests extends WindowTestsBase { } @Test - public void testIsAnimating() throws Exception { - final TestWindowContainerBuilder builder = new TestWindowContainerBuilder(); + public void testIsAnimating() { + final TestWindowContainerBuilder builder = new TestWindowContainerBuilder(mWm); final TestWindowContainer root = builder.setLayer(0).build(); final TestWindowContainer child1 = root.addChildWindow(builder.setIsAnimating(true)); @@ -402,8 +399,8 @@ public class WindowContainerTests extends WindowTestsBase { } @Test - public void testIsVisible() throws Exception { - final TestWindowContainerBuilder builder = new TestWindowContainerBuilder(); + public void testIsVisible() { + final TestWindowContainerBuilder builder = new TestWindowContainerBuilder(mWm); final TestWindowContainer root = builder.setLayer(0).build(); final TestWindowContainer child1 = root.addChildWindow(builder.setIsVisible(true)); @@ -422,7 +419,7 @@ public class WindowContainerTests extends WindowTestsBase { @Test public void testOverrideConfigurationAncestorNotification() { - final TestWindowContainerBuilder builder = new TestWindowContainerBuilder(); + final TestWindowContainerBuilder builder = new TestWindowContainerBuilder(mWm); final TestWindowContainer grandparent = builder.setLayer(0).build(); final TestWindowContainer parent = grandparent.addChildWindow(); @@ -433,8 +430,8 @@ public class WindowContainerTests extends WindowTestsBase { } @Test - public void testRemoveChild() throws Exception { - final TestWindowContainerBuilder builder = new TestWindowContainerBuilder(); + public void testRemoveChild() { + final TestWindowContainerBuilder builder = new TestWindowContainerBuilder(mWm); final TestWindowContainer root = builder.setLayer(0).build(); final TestWindowContainer child1 = root.addChildWindow(); final TestWindowContainer child2 = root.addChildWindow(); @@ -460,7 +457,7 @@ public class WindowContainerTests extends WindowTestsBase { } @Test - public void testGetOrientation_childSpecified() throws Exception { + public void testGetOrientation_childSpecified() { testGetOrientation_childSpecifiedConfig(false, SCREEN_ORIENTATION_LANDSCAPE, SCREEN_ORIENTATION_LANDSCAPE); testGetOrientation_childSpecifiedConfig(false, SCREEN_ORIENTATION_UNSET, @@ -469,7 +466,7 @@ public class WindowContainerTests extends WindowTestsBase { private void testGetOrientation_childSpecifiedConfig(boolean childVisible, int childOrientation, int expectedOrientation) { - final TestWindowContainerBuilder builder = new TestWindowContainerBuilder(); + final TestWindowContainerBuilder builder = new TestWindowContainerBuilder(mWm); final TestWindowContainer root = builder.setLayer(0).build(); root.setFillsParent(true); @@ -486,16 +483,16 @@ public class WindowContainerTests extends WindowTestsBase { } @Test - public void testGetOrientation_Unset() throws Exception { - final TestWindowContainerBuilder builder = new TestWindowContainerBuilder(); + public void testGetOrientation_Unset() { + final TestWindowContainerBuilder builder = new TestWindowContainerBuilder(mWm); final TestWindowContainer root = builder.setLayer(0).setIsVisible(true).build(); // Unspecified well because we didn't specify anything... assertEquals(SCREEN_ORIENTATION_UNSPECIFIED, root.getOrientation()); } @Test - public void testGetOrientation_InvisibleParentUnsetVisibleChildren() throws Exception { - final TestWindowContainerBuilder builder = new TestWindowContainerBuilder(); + public void testGetOrientation_InvisibleParentUnsetVisibleChildren() { + final TestWindowContainerBuilder builder = new TestWindowContainerBuilder(mWm); final TestWindowContainer root = builder.setLayer(0).setIsVisible(true).build(); builder.setIsVisible(false).setLayer(-1); @@ -516,12 +513,11 @@ public class WindowContainerTests extends WindowTestsBase { visibleUnset.setOrientation(SCREEN_ORIENTATION_UNSET); assertEquals(SCREEN_ORIENTATION_UNSET, visibleUnset.getOrientation()); assertEquals(SCREEN_ORIENTATION_LANDSCAPE, root.getOrientation()); - } @Test - public void testGetOrientation_setBehind() throws Exception { - final TestWindowContainerBuilder builder = new TestWindowContainerBuilder(); + public void testGetOrientation_setBehind() { + final TestWindowContainerBuilder builder = new TestWindowContainerBuilder(mWm); final TestWindowContainer root = builder.setLayer(0).setIsVisible(true).build(); builder.setIsVisible(true).setLayer(-1); @@ -541,8 +537,8 @@ public class WindowContainerTests extends WindowTestsBase { } @Test - public void testGetOrientation_fillsParent() throws Exception { - final TestWindowContainerBuilder builder = new TestWindowContainerBuilder(); + public void testGetOrientation_fillsParent() { + final TestWindowContainerBuilder builder = new TestWindowContainerBuilder(mWm); final TestWindowContainer root = builder.setLayer(0).setIsVisible(true).build(); builder.setIsVisible(true).setLayer(-1); @@ -577,8 +573,8 @@ public class WindowContainerTests extends WindowTestsBase { } @Test - public void testCompareTo() throws Exception { - final TestWindowContainerBuilder builder = new TestWindowContainerBuilder(); + public void testCompareTo() { + final TestWindowContainerBuilder builder = new TestWindowContainerBuilder(mWm); final TestWindowContainer root = builder.setLayer(0).build(); final TestWindowContainer child1 = root.addChildWindow(); @@ -588,8 +584,6 @@ public class WindowContainerTests extends WindowTestsBase { final TestWindowContainer child2 = root.addChildWindow(); final TestWindowContainer child21 = child2.addChildWindow(); final TestWindowContainer child22 = child2.addChildWindow(); - final TestWindowContainer child23 = child2.addChildWindow(); - final TestWindowContainer child221 = child22.addChildWindow(); final TestWindowContainer child222 = child22.addChildWindow(); final TestWindowContainer child223 = child22.addChildWindow(); final TestWindowContainer child2221 = child222.addChildWindow(); @@ -620,8 +614,8 @@ public class WindowContainerTests extends WindowTestsBase { } @Test - public void testPrefixOrderIndex() throws Exception { - final TestWindowContainerBuilder builder = new TestWindowContainerBuilder(); + public void testPrefixOrderIndex() { + final TestWindowContainerBuilder builder = new TestWindowContainerBuilder(mWm); final TestWindowContainer root = builder.build(); final TestWindowContainer child1 = root.addChildWindow(); @@ -654,8 +648,8 @@ public class WindowContainerTests extends WindowTestsBase { } @Test - public void testPrefixOrder_addEntireSubtree() throws Exception { - final TestWindowContainerBuilder builder = new TestWindowContainerBuilder(); + public void testPrefixOrder_addEntireSubtree() { + final TestWindowContainerBuilder builder = new TestWindowContainerBuilder(mWm); final TestWindowContainer root = builder.build(); final TestWindowContainer subtree = builder.build(); final TestWindowContainer subtree2 = builder.build(); @@ -677,8 +671,8 @@ public class WindowContainerTests extends WindowTestsBase { } @Test - public void testPrefixOrder_remove() throws Exception { - final TestWindowContainerBuilder builder = new TestWindowContainerBuilder(); + public void testPrefixOrder_remove() { + final TestWindowContainerBuilder builder = new TestWindowContainerBuilder(mWm); final TestWindowContainer root = builder.build(); final TestWindowContainer child1 = root.addChildWindow(); @@ -705,8 +699,8 @@ public class WindowContainerTests extends WindowTestsBase { * is invoked with overridden bounds. */ @Test - public void testOnParentResizePropagation() throws Exception { - final TestWindowContainerBuilder builder = new TestWindowContainerBuilder(); + public void testOnParentResizePropagation() { + final TestWindowContainerBuilder builder = new TestWindowContainerBuilder(mWm); final TestWindowContainer root = builder.build(); final TestWindowContainer child = root.addChildWindow(); @@ -731,7 +725,7 @@ public class WindowContainerTests extends WindowTestsBase { } /* Used so we can gain access to some protected members of the {@link WindowContainer} class */ - private class TestWindowContainer extends WindowContainer { + private static class TestWindowContainer extends WindowContainer { private final int mLayer; private boolean mIsAnimating; private boolean mIsVisible; @@ -745,7 +739,7 @@ public class WindowContainerTests extends WindowTestsBase { * Compares 2 window layers and returns -1 if the first is lesser than the second in terms * of z-order and 1 otherwise. */ - private final Comparator mWindowSubLayerComparator = (w1, w2) -> { + private static final Comparator SUBLAYER_COMPARATOR = (w1, w2) -> { final int layer1 = w1.mLayer; final int layer2 = w2.mLayer; if (layer1 < layer2 || (layer1 == layer2 && layer2 < 0 )) { @@ -753,12 +747,14 @@ public class WindowContainerTests extends WindowTestsBase { // the negative one should go below others; the positive one should go above others. return -1; } + if (layer1 == layer2) return 0; return 1; }; - TestWindowContainer(int layer, boolean isAnimating, boolean isVisible, - Integer orientation) { - super(sWm); + TestWindowContainer(WindowManagerService wm, int layer, boolean isAnimating, + boolean isVisible, Integer orientation) { + super(wm); + mLayer = layer; mIsAnimating = isAnimating; mIsVisible = isVisible; @@ -775,18 +771,18 @@ public class WindowContainerTests extends WindowTestsBase { } TestWindowContainer addChildWindow(TestWindowContainer child) { - addChild(child, mWindowSubLayerComparator); + addChild(child, SUBLAYER_COMPARATOR); return child; } TestWindowContainer addChildWindow(TestWindowContainerBuilder childBuilder) { TestWindowContainer child = childBuilder.build(); - addChild(child, mWindowSubLayerComparator); + addChild(child, SUBLAYER_COMPARATOR); return child; } TestWindowContainer addChildWindow() { - return addChildWindow(new TestWindowContainerBuilder().setLayer(1)); + return addChildWindow(new TestWindowContainerBuilder(mService).setLayer(1)); } @Override @@ -830,14 +826,19 @@ public class WindowContainerTests extends WindowTestsBase { } } - private class TestWindowContainerBuilder { + private static class TestWindowContainerBuilder { + private final WindowManagerService mWm; private int mLayer; private boolean mIsAnimating; private boolean mIsVisible; private Integer mOrientation; - public TestWindowContainerBuilder() { - reset(); + TestWindowContainerBuilder(WindowManagerService wm) { + mWm = wm; + mLayer = 0; + mIsAnimating = false; + mIsVisible = false; + mOrientation = null; } TestWindowContainerBuilder setLayer(int layer) { @@ -860,27 +861,20 @@ public class WindowContainerTests extends WindowTestsBase { return this; } - TestWindowContainerBuilder reset() { - mLayer = 0; - mIsAnimating = false; - mIsVisible = false; - mOrientation = null; - return this; - } - TestWindowContainer build() { - return new TestWindowContainer(mLayer, mIsAnimating, mIsVisible, mOrientation); + return new TestWindowContainer(mWm, mLayer, mIsAnimating, mIsVisible, mOrientation); } } - private class MockSurfaceBuildingContainer extends WindowContainer { - final SurfaceSession mSession = new SurfaceSession(); + private static class MockSurfaceBuildingContainer extends WindowContainer + implements AutoCloseable { + private final SurfaceSession mSession = new SurfaceSession(); - MockSurfaceBuildingContainer() { - super(sWm); + MockSurfaceBuildingContainer(WindowManagerService wm) { + super(wm); } - class MockSurfaceBuilder extends SurfaceControl.Builder { + static class MockSurfaceBuilder extends SurfaceControl.Builder { MockSurfaceBuilder(SurfaceSession ss) { super(ss); } @@ -895,5 +889,10 @@ public class WindowContainerTests extends WindowTestsBase { SurfaceControl.Builder makeChildSurface(WindowContainer child) { return new MockSurfaceBuilder(mSession); } + + @Override + public void close() { + mSession.kill(); + } } } diff --git a/services/tests/servicestests/src/com/android/server/wm/WindowContainerTraversalTests.java b/services/tests/servicestests/src/com/android/server/wm/WindowContainerTraversalTests.java index ffc86226cd393..2b8b934287016 100644 --- a/services/tests/servicestests/src/com/android/server/wm/WindowContainerTraversalTests.java +++ b/services/tests/servicestests/src/com/android/server/wm/WindowContainerTraversalTests.java @@ -11,7 +11,7 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License + * limitations under the License. */ package com.android.server.wm; @@ -28,23 +28,23 @@ import static org.mockito.Mockito.verify; import android.platform.test.annotations.Presubmit; import androidx.test.filters.SmallTest; -import androidx.test.runner.AndroidJUnit4; import org.junit.Test; -import org.junit.runner.RunWith; import java.util.function.Consumer; /** * Tests for {@link WindowContainer#forAllWindows} and various implementations. + * + * Build/Install/Run: + * atest FrameworksServicesTests:WindowContainerTraversalTests */ @SmallTest @Presubmit -@RunWith(AndroidJUnit4.class) public class WindowContainerTraversalTests extends WindowTestsBase { @Test - public void testDockedDividerPosition() throws Exception { + public void testDockedDividerPosition() { final WindowState splitScreenWindow = createWindowOnStack(null, WINDOWING_MODE_SPLIT_SCREEN_PRIMARY, ACTIVITY_TYPE_STANDARD, TYPE_BASE_APPLICATION, mDisplayContent, "splitScreenWindow"); @@ -52,7 +52,7 @@ public class WindowContainerTraversalTests extends WindowTestsBase { WINDOWING_MODE_SPLIT_SCREEN_SECONDARY, ACTIVITY_TYPE_STANDARD, TYPE_BASE_APPLICATION, mDisplayContent, "splitScreenSecondaryWindow"); - sWm.mInputMethodTarget = splitScreenWindow; + mWm.mInputMethodTarget = splitScreenWindow; Consumer c = mock(Consumer.class); mDisplayContent.forAllWindows(c, false); diff --git a/services/tests/servicestests/src/com/android/server/wm/WindowFrameTests.java b/services/tests/servicestests/src/com/android/server/wm/WindowFrameTests.java index 7cd131420049b..b0c8d8bfee1bc 100644 --- a/services/tests/servicestests/src/com/android/server/wm/WindowFrameTests.java +++ b/services/tests/servicestests/src/com/android/server/wm/WindowFrameTests.java @@ -11,14 +11,14 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License + * limitations under the License. */ package com.android.server.wm; import static android.view.DisplayCutout.BOUNDS_POSITION_TOP; import static android.view.DisplayCutout.fromBoundingRect; -import static android.view.WindowManager.LayoutParams.FILL_PARENT; +import static android.view.WindowManager.LayoutParams.MATCH_PARENT; import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION; import static org.junit.Assert.assertEquals; @@ -33,33 +33,32 @@ import android.view.IWindow; import android.view.WindowManager; import androidx.test.filters.SmallTest; -import androidx.test.runner.AndroidJUnit4; import com.android.server.wm.utils.WmDisplayCutout; import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; /** * Tests for the {@link WindowState#computeFrameLw} method and other window frame machinery. * - * Build/Install/Run: bit FrameworksServicesTests:com.android.server.wm.WindowFrameTests + * Build/Install/Run: + * atest FrameworksServicesTests:WindowFrameTests */ @SmallTest @Presubmit -@RunWith(AndroidJUnit4.class) public class WindowFrameTests extends WindowTestsBase { private WindowToken mWindowToken; private final IWindow mIWindow = new TestIWindow(); private final Rect mEmptyRect = new Rect(); - class WindowStateWithTask extends WindowState { + static class WindowStateWithTask extends WindowState { final Task mTask; boolean mDockedResizingForTest = false; - WindowStateWithTask(WindowManager.LayoutParams attrs, Task t) { - super(sWm, null, mIWindow, mWindowToken, null, 0, 0, attrs, 0, 0, + WindowStateWithTask(WindowManagerService wm, IWindow iWindow, WindowToken windowToken, + WindowManager.LayoutParams attrs, Task t) { + super(wm, null, iWindow, windowToken, null, 0, 0, attrs, 0, 0, false /* ownerCanAddInternalSystemWindow */); mTask = t; } @@ -73,14 +72,15 @@ public class WindowFrameTests extends WindowTestsBase { boolean isDockedResizing() { return mDockedResizingForTest; } - }; + } - class TaskWithBounds extends Task { + private static class TaskWithBounds extends Task { final Rect mBounds; final Rect mInsetBounds = new Rect(); boolean mFullscreenForTest = true; - TaskWithBounds(Rect bounds) { - super(0, mStubStack, 0, sWm, 0, false, new TaskDescription(), null); + + TaskWithBounds(TaskStack stack, WindowManagerService wm, Rect bounds) { + super(0, stack, 0, wm, 0, false, new TaskDescription(), null); mBounds = bounds; setBounds(bounds); } @@ -113,14 +113,12 @@ public class WindowFrameTests extends WindowTestsBase { @Before public void setUp() throws Exception { - super.setUp(); - // Just any non zero value. - sWm.mSystemDecorLayer = 10000; + mWm.mSystemDecorLayer = 10000; mWindowToken = WindowTestUtils.createTestAppWindowToken( - sWm.getDefaultDisplayContentLocked()); - mStubStack = new TaskStack(sWm, 0, null); + mWm.getDefaultDisplayContentLocked()); + mStubStack = new TaskStack(mWm, 0, null); } // Do not use this function directly in the tests below. Instead, use more explicit function @@ -170,9 +168,10 @@ public class WindowFrameTests extends WindowTestsBase { } @Test - public void testLayoutInFullscreenTaskInsets() throws Exception { - Task task = new TaskWithBounds(null); // fullscreen task doesn't use bounds for computeFrame - WindowState w = createWindow(task, FILL_PARENT, FILL_PARENT); + public void testLayoutInFullscreenTaskInsets() { + // fullscreen task doesn't use bounds for computeFrame + final Task task = new TaskWithBounds(mStubStack, mWm, null); + WindowState w = createWindow(task, MATCH_PARENT, MATCH_PARENT); w.mAttrs.gravity = Gravity.LEFT | Gravity.TOP; final int bottomContentInset = 100; @@ -227,9 +226,10 @@ public class WindowFrameTests extends WindowTestsBase { } @Test - public void testLayoutInFullscreenTaskNoInsets() throws Exception { - Task task = new TaskWithBounds(null); // fullscreen task doesn't use bounds for computeFrame - WindowState w = createWindow(task, FILL_PARENT, FILL_PARENT); + public void testLayoutInFullscreenTaskNoInsets() { + // fullscreen task doesn't use bounds for computeFrame + final Task task = new TaskWithBounds(mStubStack, mWm, null); + WindowState w = createWindow(task, MATCH_PARENT, MATCH_PARENT); w.mAttrs.gravity = Gravity.LEFT | Gravity.TOP; // With no insets or system decor all the frames incoming from PhoneWindowManager @@ -307,7 +307,7 @@ public class WindowFrameTests extends WindowTestsBase { @Test public void testLayoutNonfullscreenTask() { - final DisplayInfo displayInfo = sWm.getDefaultDisplayContentLocked().getDisplayInfo(); + final DisplayInfo displayInfo = mWm.getDefaultDisplayContentLocked().getDisplayInfo(); final int logicalWidth = displayInfo.logicalWidth; final int logicalHeight = displayInfo.logicalHeight; @@ -316,9 +316,9 @@ public class WindowFrameTests extends WindowTestsBase { final int taskRight = logicalWidth / 4 * 3; final int taskBottom = logicalHeight / 4 * 3; final Rect taskBounds = new Rect(taskLeft, taskTop, taskRight, taskBottom); - TaskWithBounds task = new TaskWithBounds(taskBounds); + final TaskWithBounds task = new TaskWithBounds(mStubStack, mWm, taskBounds); task.mFullscreenForTest = false; - WindowState w = createWindow(task, FILL_PARENT, FILL_PARENT); + WindowState w = createWindow(task, MATCH_PARENT, MATCH_PARENT); w.mAttrs.gravity = Gravity.LEFT | Gravity.TOP; final Rect pf = new Rect(0, 0, logicalWidth, logicalHeight); @@ -367,7 +367,7 @@ public class WindowFrameTests extends WindowTestsBase { @Test public void testCalculatePolicyCrop() { final WindowStateWithTask w = createWindow( - new TaskWithBounds(null), FILL_PARENT, FILL_PARENT); + new TaskWithBounds(mStubStack, mWm, null), MATCH_PARENT, MATCH_PARENT); w.mAttrs.gravity = Gravity.LEFT | Gravity.TOP; final DisplayInfo displayInfo = w.getDisplayContent().getDisplayInfo(); @@ -423,7 +423,7 @@ public class WindowFrameTests extends WindowTestsBase { @Test public void testLayoutLetterboxedWindow() { // First verify task behavior in multi-window mode. - final DisplayInfo displayInfo = sWm.getDefaultDisplayContentLocked().getDisplayInfo(); + final DisplayInfo displayInfo = mWm.getDefaultDisplayContentLocked().getDisplayInfo(); final int logicalWidth = displayInfo.logicalWidth; final int logicalHeight = displayInfo.logicalHeight; @@ -432,10 +432,10 @@ public class WindowFrameTests extends WindowTestsBase { final int taskRight = logicalWidth / 4 * 3; final int taskBottom = logicalHeight / 4 * 3; final Rect taskBounds = new Rect(taskLeft, taskTop, taskRight, taskBottom); - TaskWithBounds task = new TaskWithBounds(taskBounds); + final TaskWithBounds task = new TaskWithBounds(mStubStack, mWm, taskBounds); task.mInsetBounds.set(taskLeft, taskTop, taskRight, taskBottom); task.mFullscreenForTest = false; - WindowState w = createWindow(task, FILL_PARENT, FILL_PARENT); + WindowState w = createWindow(task, MATCH_PARENT, MATCH_PARENT); w.mAttrs.gravity = Gravity.LEFT | Gravity.TOP; final Rect pf = new Rect(0, 0, logicalWidth, logicalHeight); @@ -467,8 +467,8 @@ public class WindowFrameTests extends WindowTestsBase { @Test public void testDisplayCutout() { // Regular fullscreen task and window - Task task = new TaskWithBounds(null); - WindowState w = createWindow(task, FILL_PARENT, FILL_PARENT); + final Task task = new TaskWithBounds(mStubStack, mWm, null); + WindowState w = createWindow(task, MATCH_PARENT, MATCH_PARENT); w.mAttrs.gravity = Gravity.LEFT | Gravity.TOP; final Rect pf = new Rect(0, 0, 1000, 2000); @@ -491,10 +491,11 @@ public class WindowFrameTests extends WindowTestsBase { @Test public void testDisplayCutout_tempInsetBounds() { // Regular fullscreen task and window - TaskWithBounds task = new TaskWithBounds(new Rect(0, -500, 1000, 1500)); + final TaskWithBounds task = new TaskWithBounds(mStubStack, mWm, + new Rect(0, -500, 1000, 1500)); task.mFullscreenForTest = false; task.mInsetBounds.set(0, 0, 1000, 2000); - WindowState w = createWindow(task, FILL_PARENT, FILL_PARENT); + WindowState w = createWindow(task, MATCH_PARENT, MATCH_PARENT); w.mAttrs.gravity = Gravity.LEFT | Gravity.TOP; final Rect pf = new Rect(0, -500, 1000, 1500); @@ -519,7 +520,6 @@ public class WindowFrameTests extends WindowTestsBase { attrs.width = width; attrs.height = height; - return new WindowStateWithTask(attrs, task); + return new WindowStateWithTask(mWm, mIWindow, mWindowToken, attrs, task); } - } diff --git a/services/tests/servicestests/src/com/android/server/wm/WindowManagerServiceRule.java b/services/tests/servicestests/src/com/android/server/wm/WindowManagerServiceRule.java index 012c4be75fe59..4e75ec9e83480 100644 --- a/services/tests/servicestests/src/com/android/server/wm/WindowManagerServiceRule.java +++ b/services/tests/servicestests/src/com/android/server/wm/WindowManagerServiceRule.java @@ -19,6 +19,8 @@ package com.android.server.wm; import static android.testing.DexmakerShareClassLoaderRule.runWithDexmakerShareClassLoader; import static android.view.Display.DEFAULT_DISPLAY; +import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; + import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; import static org.mockito.ArgumentMatchers.any; @@ -51,8 +53,6 @@ import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; -import androidx.test.InstrumentationRegistry; - /** * A test rule that sets up a fresh WindowManagerService instance before each test and makes sure * to properly tear it down after. @@ -89,7 +89,7 @@ public class WindowManagerServiceRule implements TestRule { } private void setUp() { - final Context context = InstrumentationRegistry.getTargetContext(); + final Context context = getInstrumentation().getTargetContext(); removeServices(); diff --git a/services/tests/servicestests/src/com/android/server/wm/WindowManagerServiceRuleTest.java b/services/tests/servicestests/src/com/android/server/wm/WindowManagerServiceRuleTest.java index 570a853a62ca6..343d35959df4f 100644 --- a/services/tests/servicestests/src/com/android/server/wm/WindowManagerServiceRuleTest.java +++ b/services/tests/servicestests/src/com/android/server/wm/WindowManagerServiceRuleTest.java @@ -22,13 +22,14 @@ import static org.junit.Assert.assertThat; import android.platform.test.annotations.Presubmit; import androidx.test.filters.SmallTest; -import androidx.test.runner.AndroidJUnit4; import org.junit.Rule; import org.junit.Test; -import org.junit.runner.RunWith; -@RunWith(AndroidJUnit4.class) +/** + * Build/InstallRun: + * atest FrameworksServicesTests:WindowManagerServiceRuleTest + */ @Presubmit @SmallTest public class WindowManagerServiceRuleTest { @@ -40,4 +41,4 @@ public class WindowManagerServiceRuleTest { public void testWindowManagerSetUp() { assertThat(mRule.getWindowManagerService(), notNullValue()); } -} \ No newline at end of file +} diff --git a/services/tests/servicestests/src/com/android/server/wm/WindowStateTests.java b/services/tests/servicestests/src/com/android/server/wm/WindowStateTests.java index 3637baf13c727..118ce8962259a 100644 --- a/services/tests/servicestests/src/com/android/server/wm/WindowStateTests.java +++ b/services/tests/servicestests/src/com/android/server/wm/WindowStateTests.java @@ -11,7 +11,7 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License + * limitations under the License. */ package com.android.server.wm; @@ -58,32 +58,28 @@ import android.view.DisplayCutout; import android.view.SurfaceControl; import android.view.WindowManager; +import androidx.test.filters.FlakyTest; +import androidx.test.filters.SmallTest; + import com.android.server.wm.utils.WmDisplayCutout; import org.junit.Test; -import org.junit.runner.RunWith; -import java.util.Arrays; import java.util.LinkedList; -import androidx.test.filters.FlakyTest; -import androidx.test.filters.SmallTest; -import androidx.test.runner.AndroidJUnit4; - /** * Tests for the {@link WindowState} class. * - * atest FrameworksServicesTests:com.android.server.wm.WindowStateTests + * Build/Install/Run: + * atest FrameworksServicesTests:WindowStateTests */ -@SmallTest @FlakyTest(bugId = 74078662) -// TODO(b/116597907): Re-enable this test in postsubmit after the bug is fixed. -// @Presubmit -@RunWith(AndroidJUnit4.class) +@SmallTest +@Presubmit public class WindowStateTests extends WindowTestsBase { @Test - public void testIsParentWindowHidden() throws Exception { + public void testIsParentWindowHidden() { final WindowState parentWindow = createWindow(null, TYPE_APPLICATION, "parentWindow"); final WindowState child1 = createWindow(parentWindow, FIRST_SUB_WINDOW, "child1"); final WindowState child2 = createWindow(parentWindow, FIRST_SUB_WINDOW, "child2"); @@ -98,11 +94,10 @@ public class WindowStateTests extends WindowTestsBase { assertFalse(parentWindow.isParentWindowHidden()); assertFalse(child1.isParentWindowHidden()); assertFalse(child2.isParentWindowHidden()); - } @Test - public void testIsChildWindow() throws Exception { + public void testIsChildWindow() { final WindowState parentWindow = createWindow(null, TYPE_APPLICATION, "parentWindow"); final WindowState child1 = createWindow(parentWindow, FIRST_SUB_WINDOW, "child1"); final WindowState child2 = createWindow(parentWindow, FIRST_SUB_WINDOW, "child2"); @@ -115,7 +110,7 @@ public class WindowStateTests extends WindowTestsBase { } @Test - public void testHasChild() throws Exception { + public void testHasChild() { final WindowState win1 = createWindow(null, TYPE_APPLICATION, "win1"); final WindowState win11 = createWindow(win1, FIRST_SUB_WINDOW, "win11"); final WindowState win12 = createWindow(win1, FIRST_SUB_WINDOW, "win12"); @@ -136,7 +131,7 @@ public class WindowStateTests extends WindowTestsBase { } @Test - public void testGetParentWindow() throws Exception { + public void testGetParentWindow() { final WindowState parentWindow = createWindow(null, TYPE_APPLICATION, "parentWindow"); final WindowState child1 = createWindow(parentWindow, FIRST_SUB_WINDOW, "child1"); final WindowState child2 = createWindow(parentWindow, FIRST_SUB_WINDOW, "child2"); @@ -157,7 +152,7 @@ public class WindowStateTests extends WindowTestsBase { } @Test - public void testGetTopParentWindow() throws Exception { + public void testGetTopParentWindow() { final WindowState root = createWindow(null, TYPE_APPLICATION, "root"); final WindowState child1 = createWindow(root, FIRST_SUB_WINDOW, "child1"); final WindowState child2 = createWindow(child1, FIRST_SUB_WINDOW, "child2"); @@ -183,7 +178,7 @@ public class WindowStateTests extends WindowTestsBase { } @Test - public void testCanBeImeTarget() throws Exception { + public void testCanBeImeTarget() { final WindowState appWindow = createWindow(null, TYPE_APPLICATION, "appWindow"); final WindowState imeWindow = createWindow(null, TYPE_INPUT_METHOD, "imeWindow"); @@ -219,7 +214,7 @@ public class WindowStateTests extends WindowTestsBase { } @Test - public void testGetWindow() throws Exception { + public void testGetWindow() { final WindowState root = createWindow(null, TYPE_APPLICATION, "root"); final WindowState mediaChild = createWindow(root, TYPE_APPLICATION_MEDIA, "mediaChild"); final WindowState mediaOverlayChild = createWindow(root, @@ -231,7 +226,7 @@ public class WindowStateTests extends WindowTestsBase { final WindowState aboveSubPanelChild = createWindow(root, TYPE_APPLICATION_ABOVE_SUB_PANEL, "aboveSubPanelChild"); - final LinkedList windows = new LinkedList(); + final LinkedList windows = new LinkedList<>(); root.getWindow(w -> { windows.addLast(w); @@ -249,7 +244,7 @@ public class WindowStateTests extends WindowTestsBase { } @Test - public void testPrepareWindowToDisplayDuringRelayout() throws Exception { + public void testPrepareWindowToDisplayDuringRelayout() { testPrepareWindowToDisplayDuringRelayout(false /*wasVisible*/); testPrepareWindowToDisplayDuringRelayout(true /*wasVisible*/); @@ -262,14 +257,14 @@ public class WindowStateTests extends WindowTestsBase { final WindowState second = createWindow(null, TYPE_APPLICATION, appWindowToken, "second"); second.mAttrs.flags |= WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON; - reset(mPowerManagerWrapper); + reset(sPowerManagerWrapper); first.prepareWindowToDisplayDuringRelayout(false /*wasVisible*/); - verify(mPowerManagerWrapper, never()).wakeUp(anyLong(), anyString()); + verify(sPowerManagerWrapper, never()).wakeUp(anyLong(), anyString()); assertTrue(appWindowToken.canTurnScreenOn()); - reset(mPowerManagerWrapper); + reset(sPowerManagerWrapper); second.prepareWindowToDisplayDuringRelayout(false /*wasVisible*/); - verify(mPowerManagerWrapper).wakeUp(anyLong(), anyString()); + verify(sPowerManagerWrapper).wakeUp(anyLong(), anyString()); assertFalse(appWindowToken.canTurnScreenOn()); // Call prepareWindowToDisplayDuringRelayout for two window that have FLAG_TURN_SCREEN_ON @@ -278,14 +273,14 @@ public class WindowStateTests extends WindowTestsBase { first.mAttrs.flags |= WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON; second.mAttrs.flags |= WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON; - reset(mPowerManagerWrapper); + reset(sPowerManagerWrapper); first.prepareWindowToDisplayDuringRelayout(false /*wasVisible*/); - verify(mPowerManagerWrapper).wakeUp(anyLong(), anyString()); + verify(sPowerManagerWrapper).wakeUp(anyLong(), anyString()); assertFalse(appWindowToken.canTurnScreenOn()); - reset(mPowerManagerWrapper); + reset(sPowerManagerWrapper); second.prepareWindowToDisplayDuringRelayout(false /*wasVisible*/); - verify(mPowerManagerWrapper, never()).wakeUp(anyLong(), anyString()); + verify(sPowerManagerWrapper, never()).wakeUp(anyLong(), anyString()); assertFalse(appWindowToken.canTurnScreenOn()); // Call prepareWindowToDisplayDuringRelayout for a windows that are not children of an @@ -299,17 +294,17 @@ public class WindowStateTests extends WindowTestsBase { firstWindow.mAttrs.flags |= WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON; secondWindow.mAttrs.flags |= WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON; - reset(mPowerManagerWrapper); + reset(sPowerManagerWrapper); firstWindow.prepareWindowToDisplayDuringRelayout(false /*wasVisible*/); - verify(mPowerManagerWrapper).wakeUp(anyLong(), anyString()); + verify(sPowerManagerWrapper).wakeUp(anyLong(), anyString()); - reset(mPowerManagerWrapper); + reset(sPowerManagerWrapper); secondWindow.prepareWindowToDisplayDuringRelayout(false /*wasVisible*/); - verify(mPowerManagerWrapper).wakeUp(anyLong(), anyString()); + verify(sPowerManagerWrapper).wakeUp(anyLong(), anyString()); } @Test - public void testCanAffectSystemUiFlags() throws Exception { + public void testCanAffectSystemUiFlags() { final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); app.mToken.setHidden(false); assertTrue(app.canAffectSystemUiFlags()); @@ -318,11 +313,10 @@ public class WindowStateTests extends WindowTestsBase { app.mToken.setHidden(false); app.mAttrs.alpha = 0.0f; assertFalse(app.canAffectSystemUiFlags()); - } @Test - public void testCanAffectSystemUiFlags_disallow() throws Exception { + public void testCanAffectSystemUiFlags_disallow() { final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); app.mToken.setHidden(false); assertTrue(app.canAffectSystemUiFlags()); @@ -331,7 +325,7 @@ public class WindowStateTests extends WindowTestsBase { } @Test - public void testIsSelfOrAncestorWindowAnimating() throws Exception { + public void testIsSelfOrAncestorWindowAnimating() { final WindowState root = createWindow(null, TYPE_APPLICATION, "root"); final WindowState child1 = createWindow(root, FIRST_SUB_WINDOW, "child1"); final WindowState child2 = createWindow(child1, FIRST_SUB_WINDOW, "child2"); @@ -344,7 +338,7 @@ public class WindowStateTests extends WindowTestsBase { } @Test - public void testLayoutSeqResetOnReparent() throws Exception { + public void testLayoutSeqResetOnReparent() { final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); app.mLayoutSeq = 1; mDisplayContent.mLayoutSeq = 1; @@ -355,7 +349,7 @@ public class WindowStateTests extends WindowTestsBase { } @Test - public void testDisplayIdUpdatedOnReparent() throws Exception { + public void testDisplayIdUpdatedOnReparent() { final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); // fake a different display app.mInputWindowHandle.displayId = mDisplayContent.getDisplayId() + 1; @@ -418,11 +412,11 @@ public class WindowStateTests extends WindowTestsBase { } private void testPrepareWindowToDisplayDuringRelayout(boolean wasVisible) { - reset(mPowerManagerWrapper); + reset(sPowerManagerWrapper); final WindowState root = createWindow(null, TYPE_APPLICATION, "root"); root.mAttrs.flags |= WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON; root.prepareWindowToDisplayDuringRelayout(wasVisible /*wasVisible*/); - verify(mPowerManagerWrapper).wakeUp(anyLong(), anyString()); + verify(sPowerManagerWrapper).wakeUp(anyLong(), anyString()); } } diff --git a/services/tests/servicestests/src/com/android/server/wm/WindowTestUtils.java b/services/tests/servicestests/src/com/android/server/wm/WindowTestUtils.java index e155be486a44b..9e12f020d06e0 100644 --- a/services/tests/servicestests/src/com/android/server/wm/WindowTestUtils.java +++ b/services/tests/servicestests/src/com/android/server/wm/WindowTestUtils.java @@ -11,11 +11,26 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License + * limitations under the License. */ package com.android.server.wm; +import static android.app.AppOpsManager.OP_NONE; +import static android.content.pm.ActivityInfo.RESIZE_MODE_UNRESIZEABLE; +import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; + +import static com.android.server.wm.WindowContainer.POSITION_TOP; + +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.anyBoolean; +import static org.mockito.Mockito.anyFloat; +import static org.mockito.Mockito.anyInt; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + import android.app.ActivityManager; import android.content.Context; import android.content.res.Configuration; @@ -26,24 +41,9 @@ import android.view.Display; import android.view.IApplicationToken; import android.view.IWindow; import android.view.Surface; -import android.view.SurfaceControl; import android.view.SurfaceControl.Transaction; import android.view.WindowManager; -import static android.app.AppOpsManager.OP_NONE; -import static android.content.pm.ActivityInfo.RESIZE_MODE_UNRESIZEABLE; -import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; - -import static com.android.server.wm.WindowContainer.POSITION_TOP; -import static org.mockito.Mockito.any; -import static org.mockito.Mockito.anyBoolean; -import static org.mockito.Mockito.anyFloat; -import static org.mockito.Mockito.anyInt; -import static org.mockito.Mockito.doAnswer; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - import org.mockito.invocation.InvocationOnMock; /** @@ -277,35 +277,33 @@ public class WindowTestUtils { */ public static class TestTaskWindowContainerController extends TaskWindowContainerController { + static final TaskWindowContainerListener NOP_LISTENER = new TaskWindowContainerListener() { + @Override + public void registerConfigurationChangeListener( + ConfigurationContainerListener listener) { + } + + @Override + public void unregisterConfigurationChangeListener( + ConfigurationContainerListener listener) { + } + + @Override + public void onSnapshotChanged(ActivityManager.TaskSnapshot snapshot) { + } + + @Override + public void requestResize(Rect bounds, int resizeMode) { + } + }; + TestTaskWindowContainerController(WindowTestsBase testsBase) { this(testsBase.createStackControllerOnDisplay(testsBase.mDisplayContent)); } TestTaskWindowContainerController(StackWindowController stackController) { - super(sNextTaskId++, new TaskWindowContainerListener() { - @Override - public void registerConfigurationChangeListener( - ConfigurationContainerListener listener) { - - } - - @Override - public void unregisterConfigurationChangeListener( - ConfigurationContainerListener listener) { - - } - - @Override - public void onSnapshotChanged(ActivityManager.TaskSnapshot snapshot) { - - } - - @Override - public void requestResize(Rect bounds, int resizeMode) { - - } - }, stackController, 0 /* userId */, null /* bounds */, RESIZE_MODE_UNRESIZEABLE, - false /* supportsPictureInPicture */, true /* toTop*/, + super(sNextTaskId++, NOP_LISTENER, stackController, 0 /* userId */, null /* bounds */, + RESIZE_MODE_UNRESIZEABLE, false /* supportsPictureInPicture */, true /* toTop*/, true /* showForAllUsers */, new ActivityManager.TaskDescription(), stackController.mService); } diff --git a/services/tests/servicestests/src/com/android/server/wm/WindowTestsBase.java b/services/tests/servicestests/src/com/android/server/wm/WindowTestsBase.java index 73bb1c9aa74b8..945cbb91b0294 100644 --- a/services/tests/servicestests/src/com/android/server/wm/WindowTestsBase.java +++ b/services/tests/servicestests/src/com/android/server/wm/WindowTestsBase.java @@ -11,7 +11,7 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License + * limitations under the License. */ package com.android.server.wm; @@ -35,6 +35,8 @@ import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR; import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR; import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; +import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; + import static org.mockito.Mockito.mock; import android.content.Context; @@ -52,13 +54,12 @@ import com.android.server.AttributeCache; import org.junit.After; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Rule; import java.util.HashSet; import java.util.LinkedList; -import androidx.test.InstrumentationRegistry; - /** * Common base class for window manager unit test classes. * @@ -66,7 +67,8 @@ import androidx.test.InstrumentationRegistry; */ class WindowTestsBase { private static final String TAG = WindowTestsBase.class.getSimpleName(); - WindowManagerService sWm = null; // TODO(roosa): rename to mWm in follow-up CL + + WindowManagerService mWm; private final IWindow mIWindow = new TestIWindow(); private Session mMockSession; // The default display is removed in {@link #setUp} and then we iterate over all displays to @@ -97,32 +99,36 @@ class WindowTestsBase { @Rule public final WindowManagerServiceRule mWmRule = new WindowManagerServiceRule(); - static WindowState.PowerManagerWrapper mPowerManagerWrapper; // TODO(roosa): make non-static. + static WindowState.PowerManagerWrapper sPowerManagerWrapper; // TODO(roosa): make non-static. + + @BeforeClass + public static void setUpOnceBase() { + AttributeCache.init(getInstrumentation().getTargetContext()); + sPowerManagerWrapper = mock(WindowState.PowerManagerWrapper.class); + } @Before - public void setUp() throws Exception { + public void setUpBase() { // If @Before throws an exception, the error isn't logged. This will make sure any failures // in the set up are clear. This can be removed when b/37850063 is fixed. try { mMockSession = mock(Session.class); - mPowerManagerWrapper = mock(WindowState.PowerManagerWrapper.class); - final Context context = InstrumentationRegistry.getTargetContext(); - AttributeCache.init(context); + final Context context = getInstrumentation().getTargetContext(); - sWm = mWmRule.getWindowManagerService(); + mWm = mWmRule.getWindowManagerService(); beforeCreateDisplay(); - mWallpaperController = new WallpaperController(sWm); + mWallpaperController = new WallpaperController(mWm); context.getDisplay().getDisplayInfo(mDisplayInfo); mDisplayContent = createNewDisplay(); - sWm.mDisplayEnabled = true; - sWm.mDisplayReady = true; + mWm.mDisplayEnabled = true; + mWm.mDisplayReady = true; // Set-up some common windows. - mCommonWindows = new HashSet(); - synchronized (sWm.mGlobalLock) { + mCommonWindows = new HashSet<>(); + synchronized (mWm.mGlobalLock) { mWallpaperWindow = createCommonWindow(null, TYPE_WALLPAPER, "wallpaperWindow"); mImeWindow = createCommonWindow(null, TYPE_INPUT_METHOD, "mImeWindow"); mDisplayContent.mInputMethodWindow = mImeWindow; @@ -154,7 +160,7 @@ class WindowTestsBase { } @After - public void tearDown() throws Exception { + public void tearDownBase() { // If @After throws an exception, the error isn't logged. This will make sure any failures // in the tear down are clear. This can be removed when b/37850063 is fixed. try { @@ -164,8 +170,8 @@ class WindowTestsBase { final LinkedList nonCommonWindows = new LinkedList<>(); - synchronized (sWm.mGlobalLock) { - sWm.mRoot.forAllWindows(w -> { + synchronized (mWm.mGlobalLock) { + mWm.mRoot.forAllWindows(w -> { if (!mCommonWindows.contains(w)) { nonCommonWindows.addLast(w); } @@ -175,18 +181,18 @@ class WindowTestsBase { nonCommonWindows.pollLast().removeImmediately(); } - for (int i = sWm.mRoot.mChildren.size() - 1; i >= 0; --i) { - final DisplayContent displayContent = sWm.mRoot.mChildren.get(i); + for (int i = mWm.mRoot.mChildren.size() - 1; i >= 0; --i) { + final DisplayContent displayContent = mWm.mRoot.mChildren.get(i); if (!displayContent.isDefaultDisplay) { displayContent.removeImmediately(); } } // Remove app transition & window freeze timeout callbacks to prevent unnecessary // actions after test. - sWm.getDefaultDisplayContentLocked().mAppTransition + mWm.getDefaultDisplayContentLocked().mAppTransition .removeAppTransitionTimeoutCallbacks(); - sWm.mH.removeMessages(WindowManagerService.H.WINDOW_FREEZE_TIMEOUT); - sWm.mInputMethodTarget = null; + mWm.mH.removeMessages(WindowManagerService.H.WINDOW_FREEZE_TIMEOUT); + mWm.mInputMethodTarget = null; } // Wait until everything is really cleaned up. @@ -198,7 +204,7 @@ class WindowTestsBase { } private WindowState createCommonWindow(WindowState parent, int type, String name) { - synchronized (sWm.mGlobalLock) { + synchronized (mWm.mGlobalLock) { final WindowState win = createWindow(parent, type, name); mCommonWindows.add(win); // Prevent common windows from been IMe targets @@ -216,7 +222,7 @@ class WindowTestsBase { private WindowToken createWindowToken( DisplayContent dc, int windowingMode, int activityType, int type) { - synchronized (sWm.mGlobalLock) { + synchronized (mWm.mGlobalLock) { if (type < FIRST_APPLICATION_WINDOW || type > LAST_APPLICATION_WINDOW) { return WindowTestUtils.createTestWindowToken(type, dc); } @@ -241,7 +247,7 @@ class WindowTestsBase { } WindowState createWindow(WindowState parent, int type, String name) { - synchronized (sWm.mGlobalLock) { + synchronized (mWm.mGlobalLock) { return (parent == null) ? createWindow(parent, type, mDisplayContent, name) : createWindow(parent, type, parent.mToken, name); @@ -250,14 +256,14 @@ class WindowTestsBase { WindowState createWindowOnStack(WindowState parent, int windowingMode, int activityType, int type, DisplayContent dc, String name) { - synchronized (sWm.mGlobalLock) { + synchronized (mWm.mGlobalLock) { final WindowToken token = createWindowToken(dc, windowingMode, activityType, type); return createWindow(parent, type, token, name); } } WindowState createAppWindow(Task task, int type, String name) { - synchronized (sWm.mGlobalLock) { + synchronized (mWm.mGlobalLock) { final AppWindowToken token = WindowTestUtils.createTestAppWindowToken(mDisplayContent); task.addChild(token, 0); return createWindow(null, type, token, name); @@ -265,7 +271,7 @@ class WindowTestsBase { } WindowState createWindow(WindowState parent, int type, DisplayContent dc, String name) { - synchronized (sWm.mGlobalLock) { + synchronized (mWm.mGlobalLock) { final WindowToken token = createWindowToken( dc, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, type); return createWindow(parent, type, token, name); @@ -274,7 +280,7 @@ class WindowTestsBase { WindowState createWindow(WindowState parent, int type, DisplayContent dc, String name, boolean ownerCanAddInternalSystemWindow) { - synchronized (sWm.mGlobalLock) { + synchronized (mWm.mGlobalLock) { final WindowToken token = createWindowToken( dc, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, type); return createWindow(parent, type, token, name, 0 /* ownerId */, @@ -283,7 +289,7 @@ class WindowTestsBase { } WindowState createWindow(WindowState parent, int type, WindowToken token, String name) { - synchronized (sWm.mGlobalLock) { + synchronized (mWm.mGlobalLock) { return createWindow(parent, type, token, name, 0 /* ownerId */, false /* ownerCanAddInternalSystemWindow */); } @@ -292,7 +298,7 @@ class WindowTestsBase { WindowState createWindow(WindowState parent, int type, WindowToken token, String name, int ownerId, boolean ownerCanAddInternalSystemWindow) { return createWindow(parent, type, token, name, ownerId, ownerCanAddInternalSystemWindow, - sWm, mMockSession, mIWindow); + mWm, mMockSession, mIWindow); } static WindowState createWindow(WindowState parent, int type, WindowToken token, @@ -305,7 +311,7 @@ class WindowTestsBase { final WindowState w = new WindowState(service, session, iWindow, token, parent, OP_NONE, 0, attrs, VISIBLE, ownerId, ownerCanAddInternalSystemWindow, - mPowerManagerWrapper); + sPowerManagerWrapper); // TODO: Probably better to make this call in the WindowState ctor to avoid errors with // adding it to the token... token.addWindow(w); @@ -315,13 +321,13 @@ class WindowTestsBase { /** Creates a {@link TaskStack} and adds it to the specified {@link DisplayContent}. */ TaskStack createTaskStackOnDisplay(DisplayContent dc) { - synchronized (sWm.mGlobalLock) { + synchronized (mWm.mGlobalLock) { return createStackControllerOnDisplay(dc).mContainer; } } StackWindowController createStackControllerOnDisplay(DisplayContent dc) { - synchronized (sWm.mGlobalLock) { + synchronized (mWm.mGlobalLock) { return createStackControllerOnStackOnDisplay( WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, dc); } @@ -329,13 +335,13 @@ class WindowTestsBase { StackWindowController createStackControllerOnStackOnDisplay( int windowingMode, int activityType, DisplayContent dc) { - synchronized (sWm.mGlobalLock) { + synchronized (mWm.mGlobalLock) { final Configuration overrideConfig = new Configuration(); overrideConfig.windowConfiguration.setWindowingMode(windowingMode); overrideConfig.windowConfiguration.setActivityType(activityType); final int stackId = ++sNextStackId; final StackWindowController controller = new StackWindowController(stackId, null, - dc.getDisplayId(), true /* onTop */, new Rect(), sWm); + dc.getDisplayId(), true /* onTop */, new Rect(), mWm); controller.onOverrideConfigurationChanged(overrideConfig); return controller; } @@ -343,7 +349,7 @@ class WindowTestsBase { /** Creates a {@link Task} and adds it to the specified {@link TaskStack}. */ Task createTaskInStack(TaskStack stack, int userId) { - return WindowTestUtils.createTaskInStack(sWm, stack, userId); + return WindowTestUtils.createTaskInStack(mWm, stack, userId); } /** Creates a {@link DisplayContent} and adds it to the system. */ @@ -351,8 +357,8 @@ class WindowTestsBase { final int displayId = sNextDisplayId++; final Display display = new Display(DisplayManagerGlobal.getInstance(), displayId, mDisplayInfo, DEFAULT_DISPLAY_ADJUSTMENTS); - synchronized (sWm.mGlobalLock) { - return new DisplayContent(display, sWm, mWallpaperController, + synchronized (mWm.mGlobalLock) { + return new DisplayContent(display, mWm, mWallpaperController, mock(DisplayWindowController.class)); } } @@ -375,20 +381,19 @@ class WindowTestsBase { final int displayId = sNextDisplayId++; final Display display = new Display(DisplayManagerGlobal.getInstance(), displayId, displayInfo, DEFAULT_DISPLAY_ADJUSTMENTS); - final DisplayWindowController dcw = new DisplayWindowController(display, sWm); - synchronized (sWm.mGlobalLock) { + final DisplayWindowController dcw = new DisplayWindowController(display, mWm); + synchronized (mWm.mGlobalLock) { // Display creation is driven by DisplayWindowController via ActivityStackSupervisor. // We skip those steps here. - return sWm.mRoot.createDisplayContent(display, dcw); + return mWm.mRoot.createDisplayContent(display, dcw); } } /** Creates a {@link com.android.server.wm.WindowTestUtils.TestWindowState} */ WindowTestUtils.TestWindowState createWindowState(WindowManager.LayoutParams attrs, WindowToken token) { - synchronized (sWm.mGlobalLock) { - return new WindowTestUtils.TestWindowState(sWm, mMockSession, mIWindow, attrs, token); + synchronized (mWm.mGlobalLock) { + return new WindowTestUtils.TestWindowState(mWm, mMockSession, mIWindow, attrs, token); } } - } diff --git a/services/tests/servicestests/src/com/android/server/wm/WindowTokenTests.java b/services/tests/servicestests/src/com/android/server/wm/WindowTokenTests.java index 3732486f4a07a..3048f1a3487b2 100644 --- a/services/tests/servicestests/src/com/android/server/wm/WindowTokenTests.java +++ b/services/tests/servicestests/src/com/android/server/wm/WindowTokenTests.java @@ -11,7 +11,7 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License + * limitations under the License. */ package com.android.server.wm; @@ -30,25 +30,22 @@ import android.platform.test.annotations.Presubmit; import androidx.test.filters.FlakyTest; import androidx.test.filters.SmallTest; -import androidx.test.runner.AndroidJUnit4; import org.junit.Test; -import org.junit.runner.RunWith; /** * Tests for the {@link WindowToken} class. * * Build/Install/Run: - * bit FrameworksServicesTests:com.android.server.wm.WindowTokenTests + * atest FrameworksServicesTests:WindowTokenTests */ -@SmallTest @FlakyTest(bugId = 74078662) +@SmallTest @Presubmit -@RunWith(AndroidJUnit4.class) public class WindowTokenTests extends WindowTestsBase { @Test - public void testAddWindow() throws Exception { + public void testAddWindow() { final WindowTestUtils.TestWindowToken token = WindowTestUtils.createTestWindowToken(0, mDisplayContent); @@ -78,7 +75,7 @@ public class WindowTokenTests extends WindowTestsBase { } @Test - public void testChildRemoval() throws Exception { + public void testChildRemoval() { final DisplayContent dc = mDisplayContent; final WindowTestUtils.TestWindowToken token = WindowTestUtils.createTestWindowToken(0, dc); @@ -102,7 +99,7 @@ public class WindowTokenTests extends WindowTestsBase { * Tokens should only be removed from the system when all their windows are gone. */ @Test - public void testTokenRemovalProcess() throws Exception { + public void testTokenRemovalProcess() { final WindowTestUtils.TestWindowToken token = WindowTestUtils.createTestWindowToken( TYPE_TOAST, mDisplayContent, true /* persistOnEmpty */); diff --git a/services/tests/servicestests/src/com/android/server/wm/ZOrderingTests.java b/services/tests/servicestests/src/com/android/server/wm/ZOrderingTests.java index 3a8c4ae73493a..32e4e0265193c 100644 --- a/services/tests/servicestests/src/com/android/server/wm/ZOrderingTests.java +++ b/services/tests/servicestests/src/com/android/server/wm/ZOrderingTests.java @@ -11,7 +11,7 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License + * limitations under the License. */ package com.android.server.wm; @@ -38,27 +38,30 @@ import android.platform.test.annotations.Presubmit; import android.view.SurfaceControl; import android.view.SurfaceSession; +import androidx.test.filters.FlakyTest; +import androidx.test.filters.SmallTest; + import org.junit.After; import org.junit.Test; import java.util.HashMap; import java.util.LinkedList; -import androidx.test.filters.FlakyTest; -import androidx.test.filters.SmallTest; - /** - * Tests for the {@link WindowLayersController} class. + * Tests for the {@link DisplayContent#assignChildLayers(SurfaceControl.Transaction)} method. * * Build/Install/Run: - * atest FrameworksServicesTests:com.android.server.wm.ZOrderingTests + * atest FrameworksServicesTests:ZOrderingTests */ -@SmallTest @FlakyTest(bugId = 74078662) +@SmallTest @Presubmit public class ZOrderingTests extends WindowTestsBase { - private class LayerRecordingTransaction extends SurfaceControl.Transaction { + private static class LayerRecordingTransaction extends SurfaceControl.Transaction { + // We have WM use our Hierarchy recording subclass of SurfaceControl.Builder + // such that we can keep track of the parents of Surfaces as they are constructed. + private final HashMap mParentFor = new HashMap<>(); HashMap mLayersForControl = new HashMap<>(); HashMap mRelativeLayersForControl = new HashMap<>(); @@ -85,17 +88,28 @@ public class ZOrderingTests extends WindowTestsBase { private SurfaceControl getRelativeLayer(SurfaceControl sc) { return mRelativeLayersForControl.get(sc); } + + void addParentFor(SurfaceControl child, SurfaceControl parent) { + mParentFor.put(child, parent); + } + + SurfaceControl getParentFor(SurfaceControl child) { + return mParentFor.get(child); + } + + @Override + public void close() { + + } } - // We have WM use our Hierarchy recording subclass of SurfaceControl.Builder - // such that we can keep track of the parents of Surfaces as they are constructed. - private HashMap mParentFor = new HashMap<>(); + private static class HierarchyRecorder extends SurfaceControl.Builder { + private LayerRecordingTransaction mTransaction; + private SurfaceControl mPendingParent; - private class HierarchyRecorder extends SurfaceControl.Builder { - SurfaceControl mPendingParent; - - HierarchyRecorder(SurfaceSession s) { + HierarchyRecorder(SurfaceSession s, LayerRecordingTransaction transaction) { super(s); + mTransaction = transaction; } @Override @@ -106,16 +120,26 @@ public class ZOrderingTests extends WindowTestsBase { @Override public SurfaceControl build() { - SurfaceControl sc = super.build(); - mParentFor.put(sc, mPendingParent); + final SurfaceControl sc = super.build(); + mTransaction.addParentFor(sc, mPendingParent); + mTransaction = null; mPendingParent = null; return sc; } } - private class HierarchyRecordingBuilderFactory implements SurfaceBuilderFactory { + private static class HierarchyRecordingBuilderFactory implements SurfaceBuilderFactory { + private LayerRecordingTransaction mTransaction; + + HierarchyRecordingBuilderFactory(LayerRecordingTransaction transaction) { + mTransaction = transaction; + } + + @Override public SurfaceControl.Builder make(SurfaceSession s) { - return new HierarchyRecorder(s); + final LayerRecordingTransaction transaction = mTransaction; + mTransaction = null; + return new HierarchyRecorder(s, transaction); } } @@ -127,18 +151,17 @@ public class ZOrderingTests extends WindowTestsBase { // which is after construction of the DisplayContent, meaning the HierarchyRecorder // would miss construction of the top-level layers. mTransaction = new LayerRecordingTransaction(); - sWm.mSurfaceBuilderFactory = new HierarchyRecordingBuilderFactory(); - sWm.mTransactionFactory = () -> mTransaction; + mWm.mSurfaceBuilderFactory = new HierarchyRecordingBuilderFactory(mTransaction); + mWm.mTransactionFactory = () -> mTransaction; } @After - public void after() { + public void tearDown() { mTransaction.close(); - mParentFor.keySet().forEach(SurfaceControl::destroy); - mParentFor.clear(); } - LinkedList getAncestors(LayerRecordingTransaction t, SurfaceControl sc) { + private static LinkedList getAncestors(LayerRecordingTransaction t, + SurfaceControl sc) { LinkedList p = new LinkedList<>(); SurfaceControl current = sc; do { @@ -148,23 +171,22 @@ public class ZOrderingTests extends WindowTestsBase { if (rs != null) { current = rs; } else { - current = mParentFor.get(current); + current = t.getParentFor(current); } } while (current != null); return p; } - void assertZOrderGreaterThan(LayerRecordingTransaction t, SurfaceControl left, + private static void assertZOrderGreaterThan(LayerRecordingTransaction t, SurfaceControl left, SurfaceControl right) { final LinkedList leftParentChain = getAncestors(t, left); final LinkedList rightParentChain = getAncestors(t, right); - SurfaceControl commonAncestor = null; SurfaceControl leftTop = leftParentChain.peekLast(); SurfaceControl rightTop = rightParentChain.peekLast(); while (leftTop != null && rightTop != null && leftTop == rightTop) { - commonAncestor = leftParentChain.removeLast(); + leftParentChain.removeLast(); rightParentChain.removeLast(); leftTop = leftParentChain.peekLast(); rightTop = rightParentChain.peekLast(); @@ -189,7 +211,7 @@ public class ZOrderingTests extends WindowTestsBase { @Test public void testAssignWindowLayers_ForImeWithNoTarget() { - sWm.mInputMethodTarget = null; + mWm.mInputMethodTarget = null; mDisplayContent.assignChildLayers(mTransaction); // The Ime has an higher base layer than app windows and lower base layer than system @@ -207,7 +229,7 @@ public class ZOrderingTests extends WindowTestsBase { @Test public void testAssignWindowLayers_ForImeWithAppTarget() { final WindowState imeAppTarget = createWindow("imeAppTarget"); - sWm.mInputMethodTarget = imeAppTarget; + mWm.mInputMethodTarget = imeAppTarget; mDisplayContent.assignChildLayers(mTransaction); @@ -233,7 +255,7 @@ public class ZOrderingTests extends WindowTestsBase { TYPE_APPLICATION_MEDIA_OVERLAY, imeAppTarget.mToken, "imeAppTargetChildBelowWindow"); - sWm.mInputMethodTarget = imeAppTarget; + mWm.mInputMethodTarget = imeAppTarget; mDisplayContent.assignChildLayers(mTransaction); // Ime should be above all app windows except for child windows that are z-ordered above it @@ -255,7 +277,7 @@ public class ZOrderingTests extends WindowTestsBase { final WindowState imeAppTarget = createWindow("imeAppTarget"); final WindowState appAboveImeTarget = createWindow("appAboveImeTarget"); - sWm.mInputMethodTarget = imeAppTarget; + mWm.mInputMethodTarget = imeAppTarget; mDisplayContent.assignChildLayers(mTransaction); // Ime should be above all app windows except for non-fullscreen app window above it and @@ -278,7 +300,7 @@ public class ZOrderingTests extends WindowTestsBase { mDisplayContent, "imeSystemOverlayTarget", true /* ownerCanAddInternalSystemWindow */); - sWm.mInputMethodTarget = imeSystemOverlayTarget; + mWm.mInputMethodTarget = imeSystemOverlayTarget; mDisplayContent.assignChildLayers(mTransaction); // The IME target base layer is higher than all window except for the nav bar window, so the @@ -301,7 +323,7 @@ public class ZOrderingTests extends WindowTestsBase { @Test public void testAssignWindowLayers_ForStatusBarImeTarget() { - sWm.mInputMethodTarget = mStatusBarWindow; + mWm.mInputMethodTarget = mStatusBarWindow; mDisplayContent.assignChildLayers(mTransaction); assertWindowHigher(mImeWindow, mChildAppWindowAbove); @@ -322,8 +344,8 @@ public class ZOrderingTests extends WindowTestsBase { final WindowState dockedStackWindow = createWindowOnStack(null, WINDOWING_MODE_SPLIT_SCREEN_PRIMARY, ACTIVITY_TYPE_STANDARD, TYPE_BASE_APPLICATION, mDisplayContent, "dockedStackWindow"); - final WindowState assistantStackWindow = createWindowOnStack(null, WINDOWING_MODE_FULLSCREEN, - ACTIVITY_TYPE_ASSISTANT, TYPE_BASE_APPLICATION, + final WindowState assistantStackWindow = createWindowOnStack(null, + WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_ASSISTANT, TYPE_BASE_APPLICATION, mDisplayContent, "assistantStackWindow"); final WindowState homeActivityWindow = createWindowOnStack(null, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, TYPE_BASE_APPLICATION, @@ -368,7 +390,8 @@ public class ZOrderingTests extends WindowTestsBase { final WindowState anyWindow = createWindow("anyWindow"); final WindowState child = createWindow(anyWindow, TYPE_APPLICATION_MEDIA, mDisplayContent, "TypeApplicationMediaChild"); - final WindowState mediaOverlayChild = createWindow(anyWindow, TYPE_APPLICATION_MEDIA_OVERLAY, + final WindowState mediaOverlayChild = createWindow(anyWindow, + TYPE_APPLICATION_MEDIA_OVERLAY, mDisplayContent, "TypeApplicationMediaOverlayChild"); mDisplayContent.assignChildLayers(mTransaction); @@ -388,8 +411,8 @@ public class ZOrderingTests extends WindowTestsBase { final WindowState splitScreenSecondaryWindow = createWindowOnStack(null, WINDOWING_MODE_SPLIT_SCREEN_SECONDARY, ACTIVITY_TYPE_STANDARD, TYPE_BASE_APPLICATION, mDisplayContent, "splitScreenSecondaryWindow"); - final WindowState assistantStackWindow = createWindowOnStack(null, WINDOWING_MODE_FULLSCREEN, - ACTIVITY_TYPE_ASSISTANT, TYPE_BASE_APPLICATION, + final WindowState assistantStackWindow = createWindowOnStack(null, + WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_ASSISTANT, TYPE_BASE_APPLICATION, mDisplayContent, "assistantStackWindow"); mDisplayContent.assignChildLayers(mTransaction); diff --git a/services/tests/servicestests/src/com/android/server/wm/WindowTracingTest.java b/services/tests/wmtests/src/com/android/server/wm/WindowTracingTest.java similarity index 82% rename from services/tests/servicestests/src/com/android/server/wm/WindowTracingTest.java rename to services/tests/wmtests/src/com/android/server/wm/WindowTracingTest.java index 01b7c4f650e7b..0445ea03da73a 100644 --- a/services/tests/servicestests/src/com/android/server/wm/WindowTracingTest.java +++ b/services/tests/wmtests/src/com/android/server/wm/WindowTracingTest.java @@ -16,6 +16,8 @@ package com.android.server.wm; +import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; + import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -29,21 +31,21 @@ import static org.mockito.Mockito.verifyZeroInteractions; import android.content.Context; import android.platform.test.annotations.Presubmit; +import android.testing.DexmakerShareClassLoaderRule; import android.util.proto.ProtoOutputStream; -import androidx.test.InstrumentationRegistry; import androidx.test.filters.FlakyTest; import androidx.test.filters.SmallTest; -import androidx.test.runner.AndroidJUnit4; import com.android.internal.util.Preconditions; -import com.android.server.wm.WindowManagerTraceProto; import org.junit.After; import org.junit.Before; import org.junit.Ignore; +import org.junit.Rule; import org.junit.Test; -import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; import java.io.File; import java.io.FileInputStream; @@ -55,41 +57,44 @@ import java.nio.charset.StandardCharsets; * Test class for {@link WindowTracing}. * * Build/Install/Run: - * bit FrameworksServicesTests:com.android.server.wm.WindowTracingTest + * atest FrameworksServicesTests:WindowTracingTest */ -@SmallTest @FlakyTest(bugId = 74078662) -// TODO(b/116597907): Re-enable this test in postsubmit after the bug is fixed. -// @Presubmit -@RunWith(AndroidJUnit4.class) -public class WindowTracingTest extends WindowTestsBase { +@SmallTest +@Presubmit +public class WindowTracingTest { - private static final byte[] MAGIC_HEADER = new byte[] { - 0x9, 0x57, 0x49, 0x4e, 0x54, 0x52, 0x41, 0x43, 0x45, + private static final byte[] MAGIC_HEADER = new byte[]{ + 0x9, 0x57, 0x49, 0x4e, 0x54, 0x52, 0x41, 0x43, 0x45, }; - private Context mTestContext; - private WindowTracing mWindowTracing; + @Rule + public final DexmakerShareClassLoaderRule mDexmakerShareClassLoaderRule = + new DexmakerShareClassLoaderRule(); + + @Mock private WindowManagerService mWmMock; + private WindowTracing mWindowTracing; private File mFile; - @Override @Before public void setUp() throws Exception { - super.setUp(); + MockitoAnnotations.initMocks(this); - mWmMock = mock(WindowManagerService.class); - - mTestContext = InstrumentationRegistry.getContext(); - - mFile = mTestContext.getFileStreamPath("tracing_test.dat"); + final Context testContext = getInstrumentation().getContext(); + mFile = testContext.getFileStreamPath("tracing_test.dat"); mFile.delete(); mWindowTracing = new WindowTracing(mFile); } + @After + public void tearDown() throws Exception { + mFile.delete(); + } + @Test - public void isEnabled_returnsFalseByDefault() throws Exception { + public void isEnabled_returnsFalseByDefault() { assertFalse(mWindowTracing.isEnabled()); } @@ -107,7 +112,7 @@ public class WindowTracingTest extends WindowTestsBase { } @Test - public void trace_discared_whenNotTracing() throws Exception { + public void trace_discared_whenNotTracing() { mWindowTracing.traceStateLocked("where", mWmMock); verifyZeroInteractions(mWmMock); } @@ -132,12 +137,12 @@ public class WindowTracingTest extends WindowTestsBase { } } - @Test @Ignore("Figure out why this test is crashing when setting up mWmMock.") + @Test public void tracing_endsUpInFile() throws Exception { mWindowTracing.startTrace(mock(PrintWriter.class)); - doAnswer((inv) -> { + doAnswer(inv -> { inv.getArgument(0).write( WindowManagerTraceProto.WHERE, "TEST_WM_PROTO"); return null; @@ -157,22 +162,14 @@ public class WindowTracingTest extends WindowTestsBase { } } - @Override - @After - public void tearDown() throws Exception { - super.tearDown(); - - mFile.delete(); - } - /** Return true if {@code needle} appears anywhere in {@code haystack[0..length]} */ - boolean containsBytes(byte[] haystack, int haystackLenght, byte[] needle) { - Preconditions.checkArgument(haystackLenght > 0); + private static boolean containsBytes(byte[] haystack, int haystackLength, byte[] needle) { + Preconditions.checkArgument(haystackLength > 0); Preconditions.checkArgument(needle.length > 0); - outer: for (int i = 0; i <= haystackLenght - needle.length; i++) { + outer: for (int i = 0; i <= haystackLength - needle.length; i++) { for (int j = 0; j < needle.length; j++) { - if (haystack[i+j] != needle[j]) { + if (haystack[i + j] != needle[j]) { continue outer; } }