summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--services/core/java/com/android/server/AnimationThread.java2
-rw-r--r--services/core/java/com/android/server/UiThread.java18
-rw-r--r--services/core/java/com/android/server/am/ActivityManagerService.java3
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/ActivityDisplayTests.java20
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java4
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/ActivityStackSupervisorTests.java40
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/ActivityStackTests.java2
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/ActivityStartControllerTests.java2
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/ActivityStarterTests.java4
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/ActivityTaskManagerServiceTests.java2
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/ActivityTestsBase.java16
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/AppChangeTransitionTests.java2
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/AppTransitionControllerTest.java98
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/AppTransitionTests.java9
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/AppWindowThumbnailTest.java5
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/AppWindowTokenAnimationTests.java2
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/AppWindowTokenTests.java42
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/AssistDataRequesterTest.java9
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java170
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/DisplayPolicyLayoutTests.java671
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/DisplayPolicyTests.java11
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/DragDropControllerTests.java28
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/RecentsAnimationControllerTest.java12
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/RootWindowContainerTests.java18
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/RunningTasksTest.java2
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/SystemServiceTestsBase.java59
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/SystemServicesTestRule.java80
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/TaskPositioningControllerTests.java54
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/TaskRecordTests.java3
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/TaskStackContainersTests.java4
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/TaskStackTests.java13
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/TaskTests.java4
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/UnknownAppVisibilityControllerTest.java8
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/WallpaperControllerTests.java44
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/WindowFrameTests.java4
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/WindowManagerGlobalLockRule.java47
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/WindowProcessControllerTests.java9
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/WindowTestsBase.java21
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/ZOrderingTests.java2
39 files changed, 763 insertions, 781 deletions
diff --git a/services/core/java/com/android/server/AnimationThread.java b/services/core/java/com/android/server/AnimationThread.java
index c607b1e058bc..fad743eafdaa 100644
--- a/services/core/java/com/android/server/AnimationThread.java
+++ b/services/core/java/com/android/server/AnimationThread.java
@@ -64,7 +64,7 @@ public final class AnimationThread extends ServiceThread {
*/
@VisibleForTesting
public static void dispose() {
- synchronized (DisplayThread.class) {
+ synchronized (AnimationThread.class) {
if (sInstance == null) {
return;
}
diff --git a/services/core/java/com/android/server/UiThread.java b/services/core/java/com/android/server/UiThread.java
index b2fa6846a6d0..34fc9abec51e 100644
--- a/services/core/java/com/android/server/UiThread.java
+++ b/services/core/java/com/android/server/UiThread.java
@@ -21,6 +21,8 @@ import android.os.Looper;
import android.os.Process;
import android.os.Trace;
+import com.android.internal.annotations.VisibleForTesting;
+
/**
* Shared singleton thread for showing UI. This is a foreground thread, and in
* additional should not have operations that can take more than a few ms scheduled
@@ -68,4 +70,20 @@ public final class UiThread extends ServiceThread {
return sHandler;
}
}
+
+ /**
+ * Disposes current ui thread if it's initialized. Should only be used in tests to set up a
+ * new environment.
+ */
+ @VisibleForTesting
+ public static void dispose() {
+ synchronized (UiThread.class) {
+ if (sInstance == null) {
+ return;
+ }
+
+ getHandler().runWithScissors(sInstance::quit, 0 /* timeout */);
+ sInstance = null;
+ }
+ }
}
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index b520900ec16f..71ff60720489 100644
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -2405,7 +2405,8 @@ public class ActivityManagerService extends IActivityManager.Stub
final ActiveUids activeUids = new ActiveUids(this, false /* postChangesToAtm */);
mProcessList.init(this, activeUids);
mLowMemDetector = null;
- mOomAdjuster = new OomAdjuster(this, mProcessList, activeUids, handlerThread);
+ mOomAdjuster = hasHandlerThread
+ ? new OomAdjuster(this, mProcessList, activeUids, handlerThread) : null;
mIntentFirewall = hasHandlerThread
? new IntentFirewall(new IntentFirewallInterface(), mHandler) : null;
diff --git a/services/tests/wmtests/src/com/android/server/wm/ActivityDisplayTests.java b/services/tests/wmtests/src/com/android/server/wm/ActivityDisplayTests.java
index 6c78f6f0443f..69cc9b256b83 100644
--- a/services/tests/wmtests/src/com/android/server/wm/ActivityDisplayTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/ActivityDisplayTests.java
@@ -24,11 +24,9 @@ import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
import static android.content.pm.ActivityInfo.FLAG_ALWAYS_FOCUSABLE;
import static android.content.pm.ActivityInfo.FLAG_SHOW_WHEN_LOCKED;
+import static com.android.dx.mockito.inline.extended.ExtendedMockito.clearInvocations;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.never;
-import static com.android.dx.mockito.inline.extended.ExtendedMockito.reset;
-import static com.android.dx.mockito.inline.extended.ExtendedMockito.spy;
-import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify;
import static com.android.server.wm.ActivityStackSupervisor.ON_TOP;
@@ -49,6 +47,7 @@ import android.platform.test.annotations.Presubmit;
import androidx.test.filters.SmallTest;
import org.junit.Test;
+import org.junit.runner.RunWith;
import java.util.ArrayList;
import java.util.concurrent.CompletableFuture;
@@ -62,6 +61,7 @@ import java.util.concurrent.TimeUnit;
*/
@SmallTest
@Presubmit
+@RunWith(WindowTestRunner.class)
public class ActivityDisplayTests extends ActivityTestsBase {
@Test
@@ -142,30 +142,24 @@ public class ActivityDisplayTests extends ActivityTestsBase {
// Create a display which supports system decoration and allows reparenting stacks to
// another display when the display is removed.
final ActivityDisplay display = createNewActivityDisplay();
- spyOn(display);
doReturn(false).when(display).shouldDestroyContentOnRemove();
doReturn(true).when(display).supportsSystemDecorations();
mRootActivityContainer.addChild(display, ActivityDisplay.POSITION_TOP);
// Put home stack on the display.
- final ActivityStack homeStack = display.createStack(
- WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, ON_TOP);
- final TaskRecord task = new TaskBuilder(mSupervisor).setStack(homeStack).build();
- new ActivityBuilder(mService).setTask(task).build();
- display.removeChild(homeStack);
- final ActivityStack spiedHomeStack = spy(homeStack);
- display.addChild(spiedHomeStack, ActivityDisplay.POSITION_TOP);
- reset(spiedHomeStack);
+ final ActivityStack homeStack = new StackBuilder(mRootActivityContainer)
+ .setDisplay(display).setActivityType(ACTIVITY_TYPE_HOME).build();
// Put a finishing standard activity which will be reparented.
final ActivityStack stack = createFullscreenStackWithSimpleActivityAt(display);
stack.topRunningActivityLocked().makeFinishingLocked();
+ clearInvocations(homeStack);
display.remove();
// The removed display should have no focused stack and its home stack should never resume.
assertNull(display.getFocusedStack());
- verify(spiedHomeStack, never()).resumeTopActivityUncheckedLocked(any(), any());
+ verify(homeStack, never()).resumeTopActivityUncheckedLocked(any(), any());
}
private ActivityStack createFullscreenStackWithSimpleActivityAt(ActivityDisplay display) {
diff --git a/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java b/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java
index 30c8eb36f34a..50203dfc043a 100644
--- a/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java
@@ -103,8 +103,6 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.invocation.InvocationOnMock;
-import java.util.concurrent.TimeUnit;
-
/**
* Tests for the {@link ActivityRecord} class.
*
@@ -646,7 +644,7 @@ public class ActivityRecordTests extends ActivityTestsBase {
// The override configuration should be reset and the activity's process will be killed.
assertFalse(mActivity.inSizeCompatMode());
verify(mActivity).restartProcessIfVisible();
- mLockRule.runWithScissors(mService.mH, () -> { }, TimeUnit.SECONDS.toMillis(3));
+ waitHandlerIdle(mService.mH);
verify(mService.mAmInternal).killProcess(
eq(mActivity.app.mName), eq(mActivity.app.mUid), anyString());
}
diff --git a/services/tests/wmtests/src/com/android/server/wm/ActivityStackSupervisorTests.java b/services/tests/wmtests/src/com/android/server/wm/ActivityStackSupervisorTests.java
index 9583b8acb14a..9e1df913b22c 100644
--- a/services/tests/wmtests/src/com/android/server/wm/ActivityStackSupervisorTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/ActivityStackSupervisorTests.java
@@ -44,6 +44,7 @@ import androidx.test.filters.MediumTest;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
/**
* Tests for the {@link ActivityStackSupervisor} class.
@@ -53,6 +54,7 @@ import org.junit.Test;
*/
@MediumTest
@Presubmit
+@RunWith(WindowTestRunner.class)
public class ActivityStackSupervisorTests extends ActivityTestsBase {
private ActivityStack mFullscreenStack;
@@ -79,32 +81,28 @@ public class ActivityStackSupervisorTests extends ActivityTestsBase {
/**
* Ensures that waiting results are notified of launches.
*/
- @SuppressWarnings("SynchronizeOnNonFinalField")
@Test
public void testReportWaitingActivityLaunchedIfNeeded() {
final ActivityRecord firstActivity = new ActivityBuilder(mService).setCreateTask(true)
.setStack(mFullscreenStack).build();
- // #notifyAll will be called on the ActivityManagerService. we must hold the object lock
- // when this happens.
- synchronized (mService.mGlobalLock) {
- final WaitResult taskToFrontWait = new WaitResult();
- mSupervisor.mWaitingActivityLaunched.add(taskToFrontWait);
- mSupervisor.reportWaitingActivityLaunchedIfNeeded(firstActivity, START_TASK_TO_FRONT);
-
- assertThat(mSupervisor.mWaitingActivityLaunched).isEmpty();
- assertEquals(taskToFrontWait.result, START_TASK_TO_FRONT);
- assertNull(taskToFrontWait.who);
-
- final WaitResult deliverToTopWait = new WaitResult();
- mSupervisor.mWaitingActivityLaunched.add(deliverToTopWait);
- mSupervisor.reportWaitingActivityLaunchedIfNeeded(firstActivity,
- START_DELIVERED_TO_TOP);
-
- assertThat(mSupervisor.mWaitingActivityLaunched).isEmpty();
- assertEquals(deliverToTopWait.result, START_DELIVERED_TO_TOP);
- assertEquals(deliverToTopWait.who, firstActivity.mActivityComponent);
- }
+ final WaitResult taskToFrontWait = new WaitResult();
+ mSupervisor.mWaitingActivityLaunched.add(taskToFrontWait);
+ // #notifyAll will be called on the ActivityTaskManagerService#mGlobalLock. The lock is hold
+ // implicitly by WindowManagerGlobalLockRule.
+ mSupervisor.reportWaitingActivityLaunchedIfNeeded(firstActivity, START_TASK_TO_FRONT);
+
+ assertThat(mSupervisor.mWaitingActivityLaunched).isEmpty();
+ assertEquals(taskToFrontWait.result, START_TASK_TO_FRONT);
+ assertNull(taskToFrontWait.who);
+
+ final WaitResult deliverToTopWait = new WaitResult();
+ mSupervisor.mWaitingActivityLaunched.add(deliverToTopWait);
+ mSupervisor.reportWaitingActivityLaunchedIfNeeded(firstActivity, START_DELIVERED_TO_TOP);
+
+ assertThat(mSupervisor.mWaitingActivityLaunched).isEmpty();
+ assertEquals(deliverToTopWait.result, START_DELIVERED_TO_TOP);
+ assertEquals(deliverToTopWait.who, firstActivity.mActivityComponent);
}
/**
diff --git a/services/tests/wmtests/src/com/android/server/wm/ActivityStackTests.java b/services/tests/wmtests/src/com/android/server/wm/ActivityStackTests.java
index 2a8b4c88c000..c2a05c243540 100644
--- a/services/tests/wmtests/src/com/android/server/wm/ActivityStackTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/ActivityStackTests.java
@@ -67,6 +67,7 @@ import androidx.test.filters.SmallTest;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
/**
* Tests for the {@link ActivityStack} class.
@@ -76,6 +77,7 @@ import org.junit.Test;
*/
@SmallTest
@Presubmit
+@RunWith(WindowTestRunner.class)
public class ActivityStackTests extends ActivityTestsBase {
private ActivityDisplay mDefaultDisplay;
private ActivityStack mStack;
diff --git a/services/tests/wmtests/src/com/android/server/wm/ActivityStartControllerTests.java b/services/tests/wmtests/src/com/android/server/wm/ActivityStartControllerTests.java
index a7bbe6e4cf02..5e4c96582d02 100644
--- a/services/tests/wmtests/src/com/android/server/wm/ActivityStartControllerTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/ActivityStartControllerTests.java
@@ -38,6 +38,7 @@ import com.android.server.wm.ActivityStarter.Factory;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
import java.util.Random;
@@ -49,6 +50,7 @@ import java.util.Random;
*/
@SmallTest
@Presubmit
+@RunWith(WindowTestRunner.class)
public class ActivityStartControllerTests extends ActivityTestsBase {
private ActivityStartController mController;
private Factory mFactory;
diff --git a/services/tests/wmtests/src/com/android/server/wm/ActivityStarterTests.java b/services/tests/wmtests/src/com/android/server/wm/ActivityStarterTests.java
index 1f672c0c95f3..78f3f7953d8d 100644
--- a/services/tests/wmtests/src/com/android/server/wm/ActivityStarterTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/ActivityStarterTests.java
@@ -753,7 +753,7 @@ public class ActivityStarterTests extends ActivityTestsBase {
false /* mockGetLaunchStack */);
// Create a secondary display at bottom.
- final TestActivityDisplay secondaryDisplay = spy(createNewActivityDisplay());
+ final TestActivityDisplay secondaryDisplay = createNewActivityDisplay();
mRootActivityContainer.addChild(secondaryDisplay, POSITION_BOTTOM);
final ActivityStack stack = secondaryDisplay.createStack(WINDOWING_MODE_FULLSCREEN,
ACTIVITY_TYPE_STANDARD, true /* onTop */);
@@ -791,7 +791,7 @@ public class ActivityStarterTests extends ActivityTestsBase {
false /* mockGetLaunchStack */);
// Create a secondary display with an activity.
- final TestActivityDisplay secondaryDisplay = spy(createNewActivityDisplay());
+ final TestActivityDisplay secondaryDisplay = createNewActivityDisplay();
mRootActivityContainer.addChild(secondaryDisplay, POSITION_TOP);
final ActivityRecord singleTaskActivity = createSingleTaskActivityOn(
secondaryDisplay.createStack(WINDOWING_MODE_FULLSCREEN,
diff --git a/services/tests/wmtests/src/com/android/server/wm/ActivityTaskManagerServiceTests.java b/services/tests/wmtests/src/com/android/server/wm/ActivityTaskManagerServiceTests.java
index 297aa7eab169..7b7e6e70cd80 100644
--- a/services/tests/wmtests/src/com/android/server/wm/ActivityTaskManagerServiceTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/ActivityTaskManagerServiceTests.java
@@ -26,6 +26,7 @@ import androidx.test.filters.MediumTest;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
/**
* Tests for the {@link ActivityTaskManagerService} class.
@@ -34,6 +35,7 @@ import org.junit.Test;
* atest WmTests:ActivityTaskManagerServiceTests
*/
@MediumTest
+@RunWith(WindowTestRunner.class)
public class ActivityTaskManagerServiceTests extends ActivityTestsBase {
@Before
diff --git a/services/tests/wmtests/src/com/android/server/wm/ActivityTestsBase.java b/services/tests/wmtests/src/com/android/server/wm/ActivityTestsBase.java
index d311dfc60675..f4d1cbfa5387 100644
--- a/services/tests/wmtests/src/com/android/server/wm/ActivityTestsBase.java
+++ b/services/tests/wmtests/src/com/android/server/wm/ActivityTestsBase.java
@@ -40,31 +40,17 @@ import android.content.pm.ApplicationInfo;
import android.content.res.Configuration;
import android.os.UserHandle;
import android.service.voice.IVoiceInteractionSession;
-import android.testing.DexmakerShareClassLoaderRule;
import android.view.DisplayInfo;
import com.android.server.AttributeCache;
import org.junit.Before;
import org.junit.BeforeClass;
-import org.junit.Rule;
/**
* A base class to handle common operations in activity related unit tests.
*/
-class ActivityTestsBase {
-
- @Rule
- public final DexmakerShareClassLoaderRule mDexmakerShareClassLoaderRule =
- new DexmakerShareClassLoaderRule();
-
- @Rule
- public final SystemServicesTestRule mSystemServicesTestRule = new SystemServicesTestRule();
-
- @WindowTestRunner.MethodWrapperRule
- public final WindowManagerGlobalLockRule mLockRule =
- new WindowManagerGlobalLockRule(mSystemServicesTestRule);
-
+class ActivityTestsBase extends SystemServiceTestsBase {
final Context mContext = getInstrumentation().getTargetContext();
ActivityTaskManagerService mService;
diff --git a/services/tests/wmtests/src/com/android/server/wm/AppChangeTransitionTests.java b/services/tests/wmtests/src/com/android/server/wm/AppChangeTransitionTests.java
index 629a95453054..61dbd67c3fe8 100644
--- a/services/tests/wmtests/src/com/android/server/wm/AppChangeTransitionTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/AppChangeTransitionTests.java
@@ -42,6 +42,7 @@ import androidx.test.filters.FlakyTest;
import androidx.test.filters.SmallTest;
import org.junit.Test;
+import org.junit.runner.RunWith;
/**
* Tests for change transitions
@@ -51,6 +52,7 @@ import org.junit.Test;
*/
@SmallTest
@Presubmit
+@RunWith(WindowTestRunner.class)
public class AppChangeTransitionTests extends WindowTestsBase {
private TaskStack mStack;
diff --git a/services/tests/wmtests/src/com/android/server/wm/AppTransitionControllerTest.java b/services/tests/wmtests/src/com/android/server/wm/AppTransitionControllerTest.java
index e71c8f47a69f..605d52045d50 100644
--- a/services/tests/wmtests/src/com/android/server/wm/AppTransitionControllerTest.java
+++ b/services/tests/wmtests/src/com/android/server/wm/AppTransitionControllerTest.java
@@ -36,6 +36,7 @@ import androidx.test.filters.SmallTest;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
/**
* Build/Install/Run:
@@ -43,6 +44,7 @@ import org.junit.Test;
*/
@SmallTest
@Presubmit
+@RunWith(WindowTestRunner.class)
public class AppTransitionControllerTest extends WindowTestsBase {
private AppTransitionController mAppTransitionController;
@@ -55,73 +57,63 @@ public class AppTransitionControllerTest extends WindowTestsBase {
@Test
@FlakyTest(bugId = 131005232)
public void testTranslucentOpen() {
- synchronized (mWm.mGlobalLock) {
- final AppWindowToken behind = createAppWindowToken(mDisplayContent,
- WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD);
- final AppWindowToken translucentOpening = createAppWindowToken(mDisplayContent,
- WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD);
- translucentOpening.setOccludesParent(false);
- translucentOpening.setHidden(true);
- mDisplayContent.mOpeningApps.add(behind);
- mDisplayContent.mOpeningApps.add(translucentOpening);
- assertEquals(WindowManager.TRANSIT_TRANSLUCENT_ACTIVITY_OPEN,
- mAppTransitionController.maybeUpdateTransitToTranslucentAnim(
- TRANSIT_TASK_OPEN));
- }
+ final AppWindowToken behind = createAppWindowToken(mDisplayContent,
+ WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD);
+ final AppWindowToken translucentOpening = createAppWindowToken(mDisplayContent,
+ WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD);
+ translucentOpening.setOccludesParent(false);
+ translucentOpening.setHidden(true);
+ mDisplayContent.mOpeningApps.add(behind);
+ mDisplayContent.mOpeningApps.add(translucentOpening);
+ assertEquals(WindowManager.TRANSIT_TRANSLUCENT_ACTIVITY_OPEN,
+ mAppTransitionController.maybeUpdateTransitToTranslucentAnim(TRANSIT_TASK_OPEN));
}
@Test
@FlakyTest(bugId = 131005232)
public void testTranslucentClose() {
- synchronized (mWm.mGlobalLock) {
- final AppWindowToken behind = createAppWindowToken(mDisplayContent,
- WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD);
- final AppWindowToken translucentClosing = createAppWindowToken(mDisplayContent,
- WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD);
- translucentClosing.setOccludesParent(false);
- mDisplayContent.mClosingApps.add(translucentClosing);
- assertEquals(WindowManager.TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE,
- mAppTransitionController.maybeUpdateTransitToTranslucentAnim(
- TRANSIT_TASK_CLOSE));
- }
+ final AppWindowToken behind = createAppWindowToken(mDisplayContent,
+ WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD);
+ final AppWindowToken translucentClosing = createAppWindowToken(mDisplayContent,
+ WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD);
+ translucentClosing.setOccludesParent(false);
+ mDisplayContent.mClosingApps.add(translucentClosing);
+ assertEquals(WindowManager.TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE,
+ mAppTransitionController.maybeUpdateTransitToTranslucentAnim(TRANSIT_TASK_CLOSE));
}
@Test
@FlakyTest(bugId = 131005232)
public void testChangeIsNotOverwritten() {
- synchronized (mWm.mGlobalLock) {
- final AppWindowToken behind = createAppWindowToken(mDisplayContent,
- WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD);
- final AppWindowToken translucentOpening = createAppWindowToken(mDisplayContent,
- WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD);
- translucentOpening.setOccludesParent(false);
- translucentOpening.setHidden(true);
- mDisplayContent.mOpeningApps.add(behind);
- mDisplayContent.mOpeningApps.add(translucentOpening);
- assertEquals(TRANSIT_TASK_CHANGE_WINDOWING_MODE,
- mAppTransitionController.maybeUpdateTransitToTranslucentAnim(
- TRANSIT_TASK_CHANGE_WINDOWING_MODE));
- }
+ final AppWindowToken behind = createAppWindowToken(mDisplayContent,
+ WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD);
+ final AppWindowToken translucentOpening = createAppWindowToken(mDisplayContent,
+ WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD);
+ translucentOpening.setOccludesParent(false);
+ translucentOpening.setHidden(true);
+ mDisplayContent.mOpeningApps.add(behind);
+ mDisplayContent.mOpeningApps.add(translucentOpening);
+ assertEquals(TRANSIT_TASK_CHANGE_WINDOWING_MODE,
+ mAppTransitionController.maybeUpdateTransitToTranslucentAnim(
+ TRANSIT_TASK_CHANGE_WINDOWING_MODE));
}
@Test
@FlakyTest(bugId = 131005232)
public void testTransitWithinTask() {
- synchronized (mWm.mGlobalLock) {
- final AppWindowToken opening = createAppWindowToken(mDisplayContent,
- WINDOWING_MODE_FREEFORM, ACTIVITY_TYPE_STANDARD);
- opening.setOccludesParent(false);
- final AppWindowToken closing = createAppWindowToken(mDisplayContent,
- WINDOWING_MODE_FREEFORM, ACTIVITY_TYPE_STANDARD);
- closing.setOccludesParent(false);
- Task task = opening.getTask();
- mDisplayContent.mOpeningApps.add(opening);
- mDisplayContent.mClosingApps.add(closing);
- assertFalse(mAppTransitionController.isTransitWithinTask(TRANSIT_ACTIVITY_OPEN, task));
- closing.getTask().removeChild(closing);
- task.addChild(closing, 0);
- assertTrue(mAppTransitionController.isTransitWithinTask(TRANSIT_ACTIVITY_OPEN, task));
- assertFalse(mAppTransitionController.isTransitWithinTask(TRANSIT_TASK_OPEN, task));
- }
+ final AppWindowToken opening = createAppWindowToken(mDisplayContent,
+ WINDOWING_MODE_FREEFORM, ACTIVITY_TYPE_STANDARD);
+ opening.setOccludesParent(false);
+ final AppWindowToken closing = createAppWindowToken(mDisplayContent,
+ WINDOWING_MODE_FREEFORM, ACTIVITY_TYPE_STANDARD);
+ closing.setOccludesParent(false);
+ final Task task = opening.getTask();
+ mDisplayContent.mOpeningApps.add(opening);
+ mDisplayContent.mClosingApps.add(closing);
+ assertFalse(mAppTransitionController.isTransitWithinTask(TRANSIT_ACTIVITY_OPEN, task));
+ closing.getTask().removeChild(closing);
+ task.addChild(closing, 0);
+ assertTrue(mAppTransitionController.isTransitWithinTask(TRANSIT_ACTIVITY_OPEN, task));
+ assertFalse(mAppTransitionController.isTransitWithinTask(TRANSIT_TASK_OPEN, task));
}
}
diff --git a/services/tests/wmtests/src/com/android/server/wm/AppTransitionTests.java b/services/tests/wmtests/src/com/android/server/wm/AppTransitionTests.java
index 45e68902e123..49e4c78551cb 100644
--- a/services/tests/wmtests/src/com/android/server/wm/AppTransitionTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/AppTransitionTests.java
@@ -31,7 +31,6 @@ import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentat
import static com.android.dx.mockito.inline.extended.ExtendedMockito.anyBoolean;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doNothing;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
-import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -55,6 +54,7 @@ import androidx.test.filters.SmallTest;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
/**
* Test class for {@link AppTransition}.
@@ -64,16 +64,13 @@ import org.junit.Test;
*/
@SmallTest
@Presubmit
+@RunWith(WindowTestRunner.class)
public class AppTransitionTests extends WindowTestsBase {
private DisplayContent mDc;
@Before
public void setUp() throws Exception {
- synchronized (mWm.mGlobalLock) {
- // Hold the lock to protect the stubbing from being accessed by other threads.
- spyOn(mWm.mRoot);
- doNothing().when(mWm.mRoot).performSurfacePlacement(anyBoolean());
- }
+ doNothing().when(mWm.mRoot).performSurfacePlacement(anyBoolean());
mDc = mWm.getDefaultDisplayContentLocked();
}
diff --git a/services/tests/wmtests/src/com/android/server/wm/AppWindowThumbnailTest.java b/services/tests/wmtests/src/com/android/server/wm/AppWindowThumbnailTest.java
index b8f8e21d64ac..aacdeb21c52b 100644
--- a/services/tests/wmtests/src/com/android/server/wm/AppWindowThumbnailTest.java
+++ b/services/tests/wmtests/src/com/android/server/wm/AppWindowThumbnailTest.java
@@ -17,8 +17,8 @@
package com.android.server.wm;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock;
-
import static com.android.dx.mockito.inline.extended.ExtendedMockito.when;
+
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@@ -26,12 +26,12 @@ import android.graphics.GraphicBuffer;
import android.graphics.PixelFormat;
import android.platform.test.annotations.Presubmit;
import android.view.Surface;
-import android.view.SurfaceControl;
import androidx.test.filters.FlakyTest;
import androidx.test.filters.SmallTest;
import org.junit.Test;
+import org.junit.runner.RunWith;
/**
* Test class for {@link TaskSnapshotSurface}.
@@ -42,6 +42,7 @@ import org.junit.Test;
*/
@SmallTest
@Presubmit
+@RunWith(WindowTestRunner.class)
public class AppWindowThumbnailTest extends WindowTestsBase {
private AppWindowThumbnail buildThumbnail() {
final GraphicBuffer buffer = GraphicBuffer.create(1, 1, PixelFormat.RGBA_8888,
diff --git a/services/tests/wmtests/src/com/android/server/wm/AppWindowTokenAnimationTests.java b/services/tests/wmtests/src/com/android/server/wm/AppWindowTokenAnimationTests.java
index 70d9b5fedbcb..8957486b2dfe 100644
--- a/services/tests/wmtests/src/com/android/server/wm/AppWindowTokenAnimationTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/AppWindowTokenAnimationTests.java
@@ -37,6 +37,7 @@ 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;
@@ -50,6 +51,7 @@ import org.mockito.MockitoAnnotations;
*/
@SmallTest
@Presubmit
+@RunWith(WindowTestRunner.class)
public class AppWindowTokenAnimationTests extends WindowTestsBase {
private TestAppWindowToken mToken;
diff --git a/services/tests/wmtests/src/com/android/server/wm/AppWindowTokenTests.java b/services/tests/wmtests/src/com/android/server/wm/AppWindowTokenTests.java
index 1f634b11d173..d528e415d75d 100644
--- a/services/tests/wmtests/src/com/android/server/wm/AppWindowTokenTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/AppWindowTokenTests.java
@@ -62,6 +62,7 @@ import androidx.test.filters.SmallTest;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
import org.mockito.Mockito;
/**
@@ -72,6 +73,7 @@ import org.mockito.Mockito;
*/
@SmallTest
@Presubmit
+@RunWith(WindowTestRunner.class)
public class AppWindowTokenTests extends WindowTestsBase {
TaskStack mStack;
@@ -324,40 +326,36 @@ public class AppWindowTokenTests extends WindowTestsBase {
@Test
public void testReportOrientationChangeOnVisibilityChange() {
- synchronized (mWm.mGlobalLock) {
- mToken.setOrientation(SCREEN_ORIENTATION_LANDSCAPE);
+ mToken.setOrientation(SCREEN_ORIENTATION_LANDSCAPE);
- mDisplayContent.getDisplayRotation().setFixedToUserRotation(
- DisplayRotation.FIXED_TO_USER_ROTATION_ENABLED);
+ mDisplayContent.getDisplayRotation().setFixedToUserRotation(
+ DisplayRotation.FIXED_TO_USER_ROTATION_ENABLED);
- doReturn(Configuration.ORIENTATION_LANDSCAPE).when(mToken.mActivityRecord)
- .getRequestedConfigurationOrientation();
+ doReturn(Configuration.ORIENTATION_LANDSCAPE).when(mToken.mActivityRecord)
+ .getRequestedConfigurationOrientation();
- mTask.mTaskRecord = Mockito.mock(TaskRecord.class, RETURNS_DEEP_STUBS);
- mToken.commitVisibility(null, false /* visible */, TRANSIT_UNSET,
- true /* performLayout */, false /* isVoiceInteraction */);
- }
+ mTask.mTaskRecord = Mockito.mock(TaskRecord.class, RETURNS_DEEP_STUBS);
+ mToken.commitVisibility(null /* lp */, false /* visible */, TRANSIT_UNSET,
+ true /* performLayout */, false /* isVoiceInteraction */);
verify(mTask.mTaskRecord).onConfigurationChanged(any(Configuration.class));
}
@Test
public void testReportOrientationChangeOnOpeningClosingAppChange() {
- synchronized (mWm.mGlobalLock) {
- mToken.setOrientation(SCREEN_ORIENTATION_LANDSCAPE);
+ mToken.setOrientation(SCREEN_ORIENTATION_LANDSCAPE);
- mDisplayContent.getDisplayRotation().setFixedToUserRotation(
- DisplayRotation.FIXED_TO_USER_ROTATION_ENABLED);
- mDisplayContent.getDisplayInfo().state = Display.STATE_ON;
- mDisplayContent.prepareAppTransition(WindowManager.TRANSIT_ACTIVITY_CLOSE,
- false /* alwaysKeepCurrent */, 0 /* flags */, true /* forceOverride */);
+ mDisplayContent.getDisplayRotation().setFixedToUserRotation(
+ DisplayRotation.FIXED_TO_USER_ROTATION_ENABLED);
+ mDisplayContent.getDisplayInfo().state = Display.STATE_ON;
+ mDisplayContent.prepareAppTransition(WindowManager.TRANSIT_ACTIVITY_CLOSE,
+ false /* alwaysKeepCurrent */, 0 /* flags */, true /* forceOverride */);
- doReturn(Configuration.ORIENTATION_LANDSCAPE).when(mToken.mActivityRecord)
- .getRequestedConfigurationOrientation();
+ doReturn(Configuration.ORIENTATION_LANDSCAPE).when(mToken.mActivityRecord)
+ .getRequestedConfigurationOrientation();
- mTask.mTaskRecord = Mockito.mock(TaskRecord.class, RETURNS_DEEP_STUBS);
- mToken.setVisibility(false, false);
- }
+ mTask.mTaskRecord = Mockito.mock(TaskRecord.class, RETURNS_DEEP_STUBS);
+ mToken.setVisibility(false /* visible */, false /* deferHidingClient */);
verify(mTask.mTaskRecord).onConfigurationChanged(any(Configuration.class));
}
diff --git a/services/tests/wmtests/src/com/android/server/wm/AssistDataRequesterTest.java b/services/tests/wmtests/src/com/android/server/wm/AssistDataRequesterTest.java
index bb574ceed4e0..2e85897b6fee 100644
--- a/services/tests/wmtests/src/com/android/server/wm/AssistDataRequesterTest.java
+++ b/services/tests/wmtests/src/com/android/server/wm/AssistDataRequesterTest.java
@@ -22,6 +22,8 @@ import static android.app.AppOpsManager.OP_ASSIST_SCREENSHOT;
import static android.app.AppOpsManager.OP_ASSIST_STRUCTURE;
import static android.graphics.Bitmap.Config.ARGB_8888;
+import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
+
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doAnswer;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock;
@@ -71,7 +73,7 @@ import java.util.concurrent.TimeUnit;
*/
@MediumTest
@Presubmit
-public class AssistDataRequesterTest extends ActivityTestsBase {
+public class AssistDataRequesterTest {
private static final String TAG = AssistDataRequesterTest.class.getSimpleName();
@@ -111,8 +113,9 @@ public class AssistDataRequesterTest extends ActivityTestsBase {
mHandler = new Handler(Looper.getMainLooper());
mCallbacksLock = new Object();
mCallbacks = new Callbacks();
- mDataRequester = new AssistDataRequester(mContext, mWm, mAppOpsManager, mCallbacks,
- mCallbacksLock, OP_ASSIST_STRUCTURE, OP_ASSIST_SCREENSHOT);
+ mDataRequester = new AssistDataRequester(getInstrumentation().getTargetContext(), mWm,
+ mAppOpsManager, mCallbacks, mCallbacksLock, OP_ASSIST_STRUCTURE,
+ OP_ASSIST_SCREENSHOT);
mDataRequester.mActivityTaskManager = mAtm;
// Gate the continuation of the assist data callbacks until we are ready within the tests
mGate = new CountDownLatch(1);
diff --git a/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java b/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java
index 44f3ee4130e0..ae4074275b97 100644
--- a/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java
@@ -47,7 +47,6 @@ import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.never;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.same;
-import static com.android.dx.mockito.inline.extended.ExtendedMockito.spy;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.times;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify;
@@ -72,7 +71,6 @@ import android.metrics.LogMaker;
import android.os.SystemClock;
import android.platform.test.annotations.Presubmit;
import android.util.DisplayMetrics;
-import android.util.MutableBoolean;
import android.view.DisplayCutout;
import android.view.Gravity;
import android.view.ISystemGestureExclusionListener;
@@ -88,6 +86,7 @@ import com.android.internal.logging.nano.MetricsProto;
import com.android.server.wm.utils.WmDisplayCutout;
import org.junit.Test;
+import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
@@ -105,6 +104,7 @@ import java.util.List;
*/
@SmallTest
@Presubmit
+@RunWith(WindowTestRunner.class)
public class DisplayContentTests extends WindowTestsBase {
@Test
@@ -435,78 +435,70 @@ public class DisplayContentTests extends WindowTestsBase {
@Test
public void testDisplayCutout_rot0() {
- synchronized (mWm.getWindowManagerLock()) {
- final DisplayContent dc = createNewDisplay();
- dc.mInitialDisplayWidth = 200;
- dc.mInitialDisplayHeight = 400;
- Rect r = new Rect(80, 0, 120, 10);
- final DisplayCutout cutout = new WmDisplayCutout(
- fromBoundingRect(r.left, r.top, r.right, r.bottom, BOUNDS_POSITION_TOP), null)
- .computeSafeInsets(200, 400).getDisplayCutout();
-
- dc.mInitialDisplayCutout = cutout;
- dc.getDisplayRotation().setRotation(Surface.ROTATION_0);
- dc.computeScreenConfiguration(new Configuration()); // recomputes dc.mDisplayInfo.
-
- assertEquals(cutout, dc.getDisplayInfo().displayCutout);
- }
+ final DisplayContent dc = createNewDisplay();
+ dc.mInitialDisplayWidth = 200;
+ dc.mInitialDisplayHeight = 400;
+ final Rect r = new Rect(80, 0, 120, 10);
+ final DisplayCutout cutout = new WmDisplayCutout(
+ fromBoundingRect(r.left, r.top, r.right, r.bottom, BOUNDS_POSITION_TOP), null)
+ .computeSafeInsets(200, 400).getDisplayCutout();
+
+ dc.mInitialDisplayCutout = cutout;
+ dc.getDisplayRotation().setRotation(Surface.ROTATION_0);
+ dc.computeScreenConfiguration(new Configuration()); // recomputes dc.mDisplayInfo.
+
+ assertEquals(cutout, dc.getDisplayInfo().displayCutout);
}
@Test
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();
- // Rotation may use real display info to compute bound, so here also uses the
- // same width and height.
- final int displayWidth = dc.mInitialDisplayWidth;
- final int displayHeight = dc.mInitialDisplayHeight;
- final int cutoutWidth = 40;
- final int cutoutHeight = 10;
- final int left = (displayWidth - cutoutWidth) / 2;
- final int top = 0;
- final int right = (displayWidth + cutoutWidth) / 2;
- final int bottom = cutoutHeight;
-
- 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)
- .computeSafeInsets(displayWidth, displayHeight).getDisplayCutout();
-
- dc.mInitialDisplayCutout = cutout;
- dc.getDisplayRotation().setRotation(Surface.ROTATION_90);
- dc.computeScreenConfiguration(new Configuration()); // recomputes dc.mDisplayInfo.
-
- // ----o---------- -------------
- // | | | | |
- // | ------o | o---
- // | | | |
- // | | -> | |
- // | | ---o
- // | | |
- // | | -------------
- final Rect r = new Rect(top, left, bottom, right);
- assertEquals(new WmDisplayCutout(
- fromBoundingRect(r.left, r.top, r.right, r.bottom, BOUNDS_POSITION_LEFT), null)
- .computeSafeInsets(displayHeight, displayWidth)
- .getDisplayCutout(), dc.getDisplayInfo().displayCutout);
- }
+ // Prevent mInitialDisplayCutout from being updated from real display (e.g. null
+ // if the device has no cutout).
+ final DisplayContent dc = createDisplayNoUpdateDisplayInfo();
+ // Rotation may use real display info to compute bound, so here also uses the
+ // same width and height.
+ final int displayWidth = dc.mInitialDisplayWidth;
+ final int displayHeight = dc.mInitialDisplayHeight;
+ final int cutoutWidth = 40;
+ final int cutoutHeight = 10;
+ final int left = (displayWidth - cutoutWidth) / 2;
+ final int top = 0;
+ final int right = (displayWidth + cutoutWidth) / 2;
+ final int bottom = cutoutHeight;
+
+ 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)
+ .computeSafeInsets(displayWidth, displayHeight).getDisplayCutout();
+
+ dc.mInitialDisplayCutout = cutout;
+ dc.getDisplayRotation().setRotation(Surface.ROTATION_90);
+ dc.computeScreenConfiguration(new Configuration()); // recomputes dc.mDisplayInfo.
+
+ // ----o---------- -------------
+ // | | | | |
+ // | ------o | o---
+ // | | | |
+ // | | -> | |
+ // | | ---o
+ // | | |
+ // | | -------------
+ final Rect r = new Rect(top, left, bottom, right);
+ assertEquals(new WmDisplayCutout(
+ fromBoundingRect(r.left, r.top, r.right, r.bottom, BOUNDS_POSITION_LEFT), null)
+ .computeSafeInsets(displayHeight, displayWidth).getDisplayCutout(),
+ dc.getDisplayInfo().displayCutout);
}
@Test
public void testLayoutSeq_assignedDuringLayout() {
- synchronized (mWm.getWindowManagerLock()) {
-
- final DisplayContent dc = createNewDisplay();
- final WindowState win = createWindow(null /* parent */, TYPE_BASE_APPLICATION, dc, "w");
+ final DisplayContent dc = createNewDisplay();
+ final WindowState win = createWindow(null /* parent */, TYPE_BASE_APPLICATION, dc, "w");
- dc.setLayoutNeeded();
- dc.performLayout(true /* initial */, false /* updateImeWindows */);
+ dc.setLayoutNeeded();
+ dc.performLayout(true /* initial */, false /* updateImeWindows */);
- assertThat(win.mLayoutSeq, is(dc.mLayoutSeq));
- }
+ assertThat(win.mLayoutSeq, is(dc.mLayoutSeq));
}
@Test
@@ -751,7 +743,7 @@ public class DisplayContentTests extends WindowTestsBase {
win.setHasSurface(true);
dc.updateSystemGestureExclusion();
- final MutableBoolean invoked = new MutableBoolean(false);
+ final boolean[] invoked = { false };
final ISystemGestureExclusionListener.Stub verifier =
new ISystemGestureExclusionListener.Stub() {
@Override
@@ -760,7 +752,7 @@ public class DisplayContentTests extends WindowTestsBase {
Region expected = Region.obtain();
expected.set(10, 20, 30, 40);
assertEquals(expected, actual);
- invoked.value = true;
+ invoked[0] = true;
}
};
try {
@@ -768,7 +760,7 @@ public class DisplayContentTests extends WindowTestsBase {
} finally {
dc.unregisterSystemGestureExclusionListener(verifier);
}
- assertTrue("SystemGestureExclusionListener was not invoked", invoked.value);
+ assertTrue("SystemGestureExclusionListener was not invoked", invoked[0]);
}
@Test
@@ -826,30 +818,28 @@ public class DisplayContentTests extends WindowTestsBase {
@Test
public void testCalculateSystemGestureExclusion_immersiveStickyLegacyWindow() throws Exception {
- synchronized (mWm.mGlobalLock) {
- mWm.mSystemGestureExcludedByPreQStickyImmersive = true;
+ mWm.mSystemGestureExcludedByPreQStickyImmersive = true;
- final DisplayContent dc = createNewDisplay();
- final WindowState win = createWindow(null, TYPE_BASE_APPLICATION, dc, "win");
- win.getAttrs().flags |= FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR;
- win.getAttrs().layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
- win.getAttrs().privateFlags |= PRIVATE_FLAG_NO_MOVE_ANIMATION;
- win.getAttrs().subtreeSystemUiVisibility = win.mSystemUiVisibility =
- SYSTEM_UI_FLAG_FULLSCREEN | SYSTEM_UI_FLAG_HIDE_NAVIGATION
- | SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
- win.mAppToken.mTargetSdk = P;
+ final DisplayContent dc = createNewDisplay();
+ final WindowState win = createWindow(null, TYPE_BASE_APPLICATION, dc, "win");
+ win.getAttrs().flags |= FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR;
+ win.getAttrs().layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
+ win.getAttrs().privateFlags |= PRIVATE_FLAG_NO_MOVE_ANIMATION;
+ win.getAttrs().subtreeSystemUiVisibility = win.mSystemUiVisibility =
+ SYSTEM_UI_FLAG_FULLSCREEN | SYSTEM_UI_FLAG_HIDE_NAVIGATION
+ | SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
+ win.mAppToken.mTargetSdk = P;
- dc.setLayoutNeeded();
- dc.performLayout(true /* initial */, false /* updateImeWindows */);
+ dc.setLayoutNeeded();
+ dc.performLayout(true /* initial */, false /* updateImeWindows */);
- win.setHasSurface(true);
+ win.setHasSurface(true);
- final Region expected = Region.obtain();
- expected.set(dc.getBounds());
- assertEquals(expected, calculateSystemGestureExclusion(dc));
+ final Region expected = Region.obtain();
+ expected.set(dc.getBounds());
+ assertEquals(expected, calculateSystemGestureExclusion(dc));
- win.setHasSurface(false);
- }
+ win.setHasSurface(false);
}
@Test
@@ -860,7 +850,7 @@ public class DisplayContentTests extends WindowTestsBase {
Configuration newConfig = new Configuration();
newConfig.orientation = Configuration.ORIENTATION_PORTRAIT;
- final DisplayContent displayContent = spy(createNewDisplay());
+ final DisplayContent displayContent = createNewDisplay();
Mockito.doReturn(mockLogger).when(displayContent).getMetricsLogger();
Mockito.doReturn(oldConfig).doReturn(newConfig).when(displayContent).getConfiguration();
@@ -886,9 +876,7 @@ public class DisplayContentTests extends WindowTestsBase {
}
private void updateFocusedWindow() {
- synchronized (mWm.mGlobalLock) {
- mWm.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false);
- }
+ mWm.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateInputWindows */);
}
/**
@@ -896,7 +884,7 @@ public class DisplayContentTests extends WindowTestsBase {
* the values set by test.
*/
private DisplayContent createDisplayNoUpdateDisplayInfo() {
- final DisplayContent displayContent = spy(createNewDisplay());
+ final DisplayContent displayContent = createNewDisplay();
doNothing().when(displayContent).updateDisplayInfo();
return displayContent;
}
diff --git a/services/tests/wmtests/src/com/android/server/wm/DisplayPolicyLayoutTests.java b/services/tests/wmtests/src/com/android/server/wm/DisplayPolicyLayoutTests.java
index de184b84857b..2a3731a2e483 100644
--- a/services/tests/wmtests/src/com/android/server/wm/DisplayPolicyLayoutTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/DisplayPolicyLayoutTests.java
@@ -63,9 +63,11 @@ import com.android.server.wm.utils.WmDisplayCutout;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
@SmallTest
@Presubmit
+@RunWith(WindowTestRunner.class)
public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase {
private DisplayFrames mFrames;
@@ -118,458 +120,415 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase {
@Test
public void layoutWindowLw_appDrawsBars() {
- synchronized (mWm.mGlobalLock) {
- mWindow.mAttrs.flags |= FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
- addWindow(mWindow);
-
- mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
- mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
-
- assertInsetByTopBottom(mWindow.getParentFrame(), 0, 0);
- assertInsetByTopBottom(mWindow.getStableFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
- assertInsetByTopBottom(mWindow.getContentFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
- assertInsetByTopBottom(mWindow.getDecorFrame(), 0, 0);
- assertInsetBy(mWindow.getDisplayFrameLw(), 0, 0, 0, 0);
- }
+ mWindow.mAttrs.flags |= FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
+ addWindow(mWindow);
+
+ mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
+ mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
+
+ assertInsetByTopBottom(mWindow.getParentFrame(), 0, 0);
+ assertInsetByTopBottom(mWindow.getStableFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
+ assertInsetByTopBottom(mWindow.getContentFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
+ assertInsetByTopBottom(mWindow.getDecorFrame(), 0, 0);
+ assertInsetBy(mWindow.getDisplayFrameLw(), 0, 0, 0, 0);
}
@Test
public void layoutWindowLw_appWontDrawBars() {
- synchronized (mWm.mGlobalLock) {
- mWindow.mAttrs.flags &= ~FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
- addWindow(mWindow);
-
- mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
- mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
-
- assertInsetByTopBottom(mWindow.getParentFrame(), 0, NAV_BAR_HEIGHT);
- assertInsetByTopBottom(mWindow.getStableFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
- assertInsetByTopBottom(mWindow.getContentFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
- assertInsetByTopBottom(mWindow.getDecorFrame(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
- assertInsetByTopBottom(mWindow.getDisplayFrameLw(), 0, NAV_BAR_HEIGHT);
- }
+ mWindow.mAttrs.flags &= ~FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
+ addWindow(mWindow);
+
+ mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
+ mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
+
+ assertInsetByTopBottom(mWindow.getParentFrame(), 0, NAV_BAR_HEIGHT);
+ assertInsetByTopBottom(mWindow.getStableFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
+ assertInsetByTopBottom(mWindow.getContentFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
+ assertInsetByTopBottom(mWindow.getDecorFrame(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
+ assertInsetByTopBottom(mWindow.getDisplayFrameLw(), 0, NAV_BAR_HEIGHT);
}
@Test
public void layoutWindowLw_appWontDrawBars_forceStatusAndNav() throws Exception {
- synchronized (mWm.mGlobalLock) {
- mWindow.mAttrs.flags &= ~FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
- mWindow.mAttrs.privateFlags |= PRIVATE_FLAG_FORCE_DRAW_BAR_BACKGROUNDS;
- addWindow(mWindow);
-
- mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
- mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
-
- assertInsetByTopBottom(mWindow.getParentFrame(), 0, 0);
- assertInsetByTopBottom(mWindow.getStableFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
- assertInsetByTopBottom(mWindow.getContentFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
- assertInsetByTopBottom(mWindow.getDecorFrame(), 0, 0);
- assertInsetByTopBottom(mWindow.getDisplayFrameLw(), 0, 0);
- }
+ mWindow.mAttrs.flags &= ~FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
+ mWindow.mAttrs.privateFlags |= PRIVATE_FLAG_FORCE_DRAW_BAR_BACKGROUNDS;
+ addWindow(mWindow);
+
+ mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
+ mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
+
+ assertInsetByTopBottom(mWindow.getParentFrame(), 0, 0);
+ assertInsetByTopBottom(mWindow.getStableFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
+ assertInsetByTopBottom(mWindow.getContentFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
+ assertInsetByTopBottom(mWindow.getDecorFrame(), 0, 0);
+ assertInsetByTopBottom(mWindow.getDisplayFrameLw(), 0, 0);
}
@Test
public void layoutWindowLw_keyguardDialog_hideNav() {
- synchronized (mWm.mGlobalLock) {
- mWindow.mAttrs.type = TYPE_KEYGUARD_DIALOG;
- mWindow.mAttrs.flags |= FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
- mWindow.mAttrs.systemUiVisibility = SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
- addWindow(mWindow);
-
- mDisplayPolicy.beginLayoutLw(mFrames, 0 /* uiMode */);
- mDisplayPolicy.layoutWindowLw(mWindow, null /* attached */, mFrames);
-
- assertInsetByTopBottom(mWindow.getParentFrame(), 0, 0);
- assertInsetByTopBottom(mWindow.getStableFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
- assertInsetByTopBottom(mWindow.getContentFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
- assertInsetByTopBottom(mWindow.getDecorFrame(), 0, 0);
- assertInsetByTopBottom(mWindow.getDisplayFrameLw(), 0, 0);
- }
+ mWindow.mAttrs.type = TYPE_KEYGUARD_DIALOG;
+ mWindow.mAttrs.flags |= FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
+ mWindow.mAttrs.systemUiVisibility = SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
+ addWindow(mWindow);
+
+ mDisplayPolicy.beginLayoutLw(mFrames, 0 /* uiMode */);
+ mDisplayPolicy.layoutWindowLw(mWindow, null /* attached */, mFrames);
+
+ assertInsetByTopBottom(mWindow.getParentFrame(), 0, 0);
+ assertInsetByTopBottom(mWindow.getStableFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
+ assertInsetByTopBottom(mWindow.getContentFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
+ assertInsetByTopBottom(mWindow.getDecorFrame(), 0, 0);
+ assertInsetByTopBottom(mWindow.getDisplayFrameLw(), 0, 0);
}
@Test
public void layoutWindowLw_withDisplayCutout() {
- synchronized (mWm.mGlobalLock) {
- addDisplayCutout();
+ addDisplayCutout();
- addWindow(mWindow);
+ addWindow(mWindow);
- mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
- mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
+ mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
+ mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
- assertInsetByTopBottom(mWindow.getParentFrame(), 0, 0);
- assertInsetByTopBottom(mWindow.getStableFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
- assertInsetByTopBottom(mWindow.getContentFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
- assertInsetByTopBottom(mWindow.getDecorFrame(), 0, 0);
- assertInsetByTopBottom(mWindow.getDisplayFrameLw(), 0, 0);
- }
+ assertInsetByTopBottom(mWindow.getParentFrame(), 0, 0);
+ assertInsetByTopBottom(mWindow.getStableFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
+ assertInsetByTopBottom(mWindow.getContentFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
+ assertInsetByTopBottom(mWindow.getDecorFrame(), 0, 0);
+ assertInsetByTopBottom(mWindow.getDisplayFrameLw(), 0, 0);
}
@Test
public void layoutWindowLw_withDisplayCutout_never() {
- synchronized (mWm.mGlobalLock) {
- addDisplayCutout();
+ addDisplayCutout();
- mWindow.mAttrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER;
- addWindow(mWindow);
+ mWindow.mAttrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER;
+ addWindow(mWindow);
- mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
- mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
+ mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
+ mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
- assertInsetByTopBottom(mWindow.getParentFrame(), STATUS_BAR_HEIGHT, 0);
- assertInsetByTopBottom(mWindow.getStableFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
- assertInsetByTopBottom(mWindow.getContentFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
- assertInsetByTopBottom(mWindow.getDecorFrame(), 0, 0);
- assertInsetByTopBottom(mWindow.getDisplayFrameLw(), STATUS_BAR_HEIGHT, 0);
- }
+ assertInsetByTopBottom(mWindow.getParentFrame(), STATUS_BAR_HEIGHT, 0);
+ assertInsetByTopBottom(mWindow.getStableFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
+ assertInsetByTopBottom(mWindow.getContentFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
+ assertInsetByTopBottom(mWindow.getDecorFrame(), 0, 0);
+ assertInsetByTopBottom(mWindow.getDisplayFrameLw(), STATUS_BAR_HEIGHT, 0);
}
@Test
public void layoutWindowLw_withDisplayCutout_layoutFullscreen() {
- synchronized (mWm.mGlobalLock) {
- addDisplayCutout();
+ addDisplayCutout();
- mWindow.mAttrs.subtreeSystemUiVisibility |= SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
- addWindow(mWindow);
+ mWindow.mAttrs.subtreeSystemUiVisibility |= SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
+ addWindow(mWindow);
- mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
- mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
+ mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
+ mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
- assertInsetByTopBottom(mWindow.getParentFrame(), 0, 0);
- assertInsetByTopBottom(mWindow.getStableFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
- assertInsetByTopBottom(mWindow.getContentFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
- assertInsetByTopBottom(mWindow.getDecorFrame(), 0, 0);
- assertInsetBy(mWindow.getDisplayFrameLw(), 0, 0, 0, 0);
- }
+ assertInsetByTopBottom(mWindow.getParentFrame(), 0, 0);
+ assertInsetByTopBottom(mWindow.getStableFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
+ assertInsetByTopBottom(mWindow.getContentFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
+ assertInsetByTopBottom(mWindow.getDecorFrame(), 0, 0);
+ assertInsetBy(mWindow.getDisplayFrameLw(), 0, 0, 0, 0);
}
@Test
public void layoutWindowLw_withDisplayCutout_fullscreen() {
- synchronized (mWm.mGlobalLock) {
- addDisplayCutout();
+ addDisplayCutout();
- mWindow.mAttrs.subtreeSystemUiVisibility |= SYSTEM_UI_FLAG_FULLSCREEN;
- addWindow(mWindow);
+ mWindow.mAttrs.subtreeSystemUiVisibility |= SYSTEM_UI_FLAG_FULLSCREEN;
+ addWindow(mWindow);
- mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
- mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
+ mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
+ mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
- assertInsetByTopBottom(mWindow.getParentFrame(), STATUS_BAR_HEIGHT, 0);
- assertInsetByTopBottom(mWindow.getStableFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
- assertInsetByTopBottom(mWindow.getContentFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
- assertInsetByTopBottom(mWindow.getDecorFrame(), 0, 0);
- assertInsetByTopBottom(mWindow.getDisplayFrameLw(), STATUS_BAR_HEIGHT, 0);
- }
+ assertInsetByTopBottom(mWindow.getParentFrame(), STATUS_BAR_HEIGHT, 0);
+ assertInsetByTopBottom(mWindow.getStableFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
+ assertInsetByTopBottom(mWindow.getContentFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
+ assertInsetByTopBottom(mWindow.getDecorFrame(), 0, 0);
+ assertInsetByTopBottom(mWindow.getDisplayFrameLw(), STATUS_BAR_HEIGHT, 0);
}
@Test
public void layoutWindowLw_withDisplayCutout_fullscreenInCutout() {
- synchronized (mWm.mGlobalLock) {
- addDisplayCutout();
-
- mWindow.mAttrs.subtreeSystemUiVisibility |= SYSTEM_UI_FLAG_FULLSCREEN;
- mWindow.mAttrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
- addWindow(mWindow);
-
- mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
- mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
-
- assertInsetByTopBottom(mWindow.getParentFrame(), 0, 0);
- assertInsetByTopBottom(mWindow.getStableFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
- assertInsetByTopBottom(mWindow.getContentFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
- assertInsetByTopBottom(mWindow.getDecorFrame(), 0, 0);
- assertInsetByTopBottom(mWindow.getDisplayFrameLw(), 0, 0);
- }
+ addDisplayCutout();
+
+ mWindow.mAttrs.subtreeSystemUiVisibility |= SYSTEM_UI_FLAG_FULLSCREEN;
+ mWindow.mAttrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
+ addWindow(mWindow);
+
+ mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
+ mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
+
+ assertInsetByTopBottom(mWindow.getParentFrame(), 0, 0);
+ assertInsetByTopBottom(mWindow.getStableFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
+ assertInsetByTopBottom(mWindow.getContentFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
+ assertInsetByTopBottom(mWindow.getDecorFrame(), 0, 0);
+ assertInsetByTopBottom(mWindow.getDisplayFrameLw(), 0, 0);
}
@Test
public void layoutWindowLw_withDisplayCutout_landscape() {
- synchronized (mWm.mGlobalLock) {
- addDisplayCutout();
- setRotation(ROTATION_90);
- addWindow(mWindow);
-
- mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
- mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
-
- assertInsetBy(mWindow.getParentFrame(), DISPLAY_CUTOUT_HEIGHT, 0, 0, 0);
- assertInsetBy(mWindow.getStableFrameLw(), 0, STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT, 0);
- assertInsetBy(mWindow.getContentFrameLw(),
- DISPLAY_CUTOUT_HEIGHT, STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT, 0);
- assertInsetBy(mWindow.getDecorFrame(), 0, 0, 0, 0);
- assertInsetBy(mWindow.getDisplayFrameLw(), DISPLAY_CUTOUT_HEIGHT, 0, 0, 0);
- }
+ addDisplayCutout();
+ setRotation(ROTATION_90);
+ addWindow(mWindow);
+
+ mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
+ mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
+
+ assertInsetBy(mWindow.getParentFrame(), DISPLAY_CUTOUT_HEIGHT, 0, 0, 0);
+ assertInsetBy(mWindow.getStableFrameLw(), 0, STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT, 0);
+ assertInsetBy(mWindow.getContentFrameLw(),
+ DISPLAY_CUTOUT_HEIGHT, STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT, 0);
+ assertInsetBy(mWindow.getDecorFrame(), 0, 0, 0, 0);
+ assertInsetBy(mWindow.getDisplayFrameLw(), DISPLAY_CUTOUT_HEIGHT, 0, 0, 0);
}
@Test
public void layoutWindowLw_withDisplayCutout_seascape() {
- synchronized (mWm.mGlobalLock) {
- addDisplayCutout();
- setRotation(ROTATION_270);
- addWindow(mWindow);
-
- mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
- mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
-
- assertInsetBy(mWindow.getParentFrame(), 0, 0, DISPLAY_CUTOUT_HEIGHT, 0);
- assertInsetBy(mWindow.getStableFrameLw(), NAV_BAR_HEIGHT, STATUS_BAR_HEIGHT, 0, 0);
- assertInsetBy(mWindow.getContentFrameLw(),
- NAV_BAR_HEIGHT, STATUS_BAR_HEIGHT, DISPLAY_CUTOUT_HEIGHT, 0);
- assertInsetBy(mWindow.getDecorFrame(), 0, 0, 0, 0);
- assertInsetBy(mWindow.getDisplayFrameLw(), 0, 0, DISPLAY_CUTOUT_HEIGHT, 0);
- }
+ addDisplayCutout();
+ setRotation(ROTATION_270);
+ addWindow(mWindow);
+
+ mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
+ mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
+
+ assertInsetBy(mWindow.getParentFrame(), 0, 0, DISPLAY_CUTOUT_HEIGHT, 0);
+ assertInsetBy(mWindow.getStableFrameLw(), NAV_BAR_HEIGHT, STATUS_BAR_HEIGHT, 0, 0);
+ assertInsetBy(mWindow.getContentFrameLw(),
+ NAV_BAR_HEIGHT, STATUS_BAR_HEIGHT, DISPLAY_CUTOUT_HEIGHT, 0);
+ assertInsetBy(mWindow.getDecorFrame(), 0, 0, 0, 0);
+ assertInsetBy(mWindow.getDisplayFrameLw(), 0, 0, DISPLAY_CUTOUT_HEIGHT, 0);
}
@Test
public void layoutWindowLw_withDisplayCutout_fullscreen_landscape() {
- synchronized (mWm.mGlobalLock) {
- addDisplayCutout();
- setRotation(ROTATION_90);
-
- mWindow.mAttrs.subtreeSystemUiVisibility |= SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
- addWindow(mWindow);
-
- mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
- mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
-
- assertInsetBy(mWindow.getParentFrame(), DISPLAY_CUTOUT_HEIGHT, 0, 0, 0);
- assertInsetBy(mWindow.getStableFrameLw(), 0, STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT, 0);
- assertInsetBy(mWindow.getContentFrameLw(),
- DISPLAY_CUTOUT_HEIGHT, STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT, 0);
- assertInsetBy(mWindow.getDecorFrame(), 0, 0, 0, 0);
- }
+ addDisplayCutout();
+ setRotation(ROTATION_90);
+
+ mWindow.mAttrs.subtreeSystemUiVisibility |= SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
+ addWindow(mWindow);
+
+ mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
+ mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
+
+ assertInsetBy(mWindow.getParentFrame(), DISPLAY_CUTOUT_HEIGHT, 0, 0, 0);
+ assertInsetBy(mWindow.getStableFrameLw(), 0, STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT, 0);
+ assertInsetBy(mWindow.getContentFrameLw(),
+ DISPLAY_CUTOUT_HEIGHT, STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT, 0);
+ assertInsetBy(mWindow.getDecorFrame(), 0, 0, 0, 0);
}
@Test
public void layoutWindowLw_withDisplayCutout_floatingInScreen() {
- synchronized (mWm.mGlobalLock) {
- addDisplayCutout();
+ addDisplayCutout();
- mWindow.mAttrs.flags = FLAG_LAYOUT_IN_SCREEN;
- mWindow.mAttrs.type = TYPE_APPLICATION_OVERLAY;
- mWindow.mAttrs.width = DISPLAY_WIDTH;
- mWindow.mAttrs.height = DISPLAY_HEIGHT;
- addWindow(mWindow);
+ mWindow.mAttrs.flags = FLAG_LAYOUT_IN_SCREEN;
+ mWindow.mAttrs.type = TYPE_APPLICATION_OVERLAY;
+ mWindow.mAttrs.width = DISPLAY_WIDTH;
+ mWindow.mAttrs.height = DISPLAY_HEIGHT;
+ addWindow(mWindow);
- mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
- mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
+ mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
+ mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
- assertInsetByTopBottom(mWindow.getParentFrame(), 0, NAV_BAR_HEIGHT);
- assertInsetByTopBottom(mWindow.getDisplayFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
- }
+ assertInsetByTopBottom(mWindow.getParentFrame(), 0, NAV_BAR_HEIGHT);
+ assertInsetByTopBottom(mWindow.getDisplayFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
}
@Test
public void layoutWindowLw_withDisplayCutout_fullscreenInCutout_landscape() {
- synchronized (mWm.mGlobalLock) {
- addDisplayCutout();
- setRotation(ROTATION_90);
-
- mWindow.mAttrs.subtreeSystemUiVisibility |= SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
- mWindow.mAttrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
- addWindow(mWindow);
-
- mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
- mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
-
- assertInsetBy(mWindow.getParentFrame(), 0, 0, 0, 0);
- assertInsetBy(mWindow.getStableFrameLw(), 0, STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT, 0);
- assertInsetBy(mWindow.getContentFrameLw(),
- DISPLAY_CUTOUT_HEIGHT, STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT, 0);
- assertInsetBy(mWindow.getDecorFrame(), 0, 0, 0, 0);
- }
+ addDisplayCutout();
+ setRotation(ROTATION_90);
+
+ mWindow.mAttrs.subtreeSystemUiVisibility |= SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
+ mWindow.mAttrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
+ addWindow(mWindow);
+
+ mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
+ mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
+
+ assertInsetBy(mWindow.getParentFrame(), 0, 0, 0, 0);
+ assertInsetBy(mWindow.getStableFrameLw(), 0, STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT, 0);
+ assertInsetBy(mWindow.getContentFrameLw(),
+ DISPLAY_CUTOUT_HEIGHT, STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT, 0);
+ assertInsetBy(mWindow.getDecorFrame(), 0, 0, 0, 0);
}
@Test
public void layoutWindowLw_withForwardInset_SoftInputAdjustResize() {
- synchronized (mWm.mGlobalLock) {
- mWindow.mAttrs.softInputMode = SOFT_INPUT_ADJUST_RESIZE;
- addWindow(mWindow);
-
- final int forwardedInsetBottom = 50;
- mDisplayPolicy.setForwardedInsets(Insets.of(0, 0, 0, forwardedInsetBottom));
- mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
- mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
-
- assertInsetBy(mWindow.getParentFrame(), 0, 0, 0, 0);
- assertInsetByTopBottom(mWindow.getStableFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
- assertInsetByTopBottom(mWindow.getContentFrameLw(),
- STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT + forwardedInsetBottom);
- assertInsetByTopBottom(mWindow.getVisibleFrameLw(),
- STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT + forwardedInsetBottom);
- assertInsetBy(mWindow.getDecorFrame(), 0, 0, 0, 0);
- assertInsetBy(mWindow.getDisplayFrameLw(), 0, 0, 0, 0);
- }
+ mWindow.mAttrs.softInputMode = SOFT_INPUT_ADJUST_RESIZE;
+ addWindow(mWindow);
+
+ final int forwardedInsetBottom = 50;
+ mDisplayPolicy.setForwardedInsets(Insets.of(0, 0, 0, forwardedInsetBottom));
+ mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
+ mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
+
+ assertInsetBy(mWindow.getParentFrame(), 0, 0, 0, 0);
+ assertInsetByTopBottom(mWindow.getStableFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
+ assertInsetByTopBottom(mWindow.getContentFrameLw(),
+ STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT + forwardedInsetBottom);
+ assertInsetByTopBottom(mWindow.getVisibleFrameLw(),
+ STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT + forwardedInsetBottom);
+ assertInsetBy(mWindow.getDecorFrame(), 0, 0, 0, 0);
+ assertInsetBy(mWindow.getDisplayFrameLw(), 0, 0, 0, 0);
}
@Test
public void layoutWindowLw_withForwardInset_SoftInputAdjustNothing() {
- synchronized (mWm.mGlobalLock) {
- mWindow.mAttrs.softInputMode = SOFT_INPUT_ADJUST_NOTHING;
- addWindow(mWindow);
-
- final int forwardedInsetBottom = 50;
- mDisplayPolicy.setForwardedInsets(Insets.of(0, 0, 0, forwardedInsetBottom));
- mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
- mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
-
- assertInsetBy(mWindow.getParentFrame(), 0, 0, 0, 0);
- assertInsetByTopBottom(mWindow.getStableFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
- assertInsetByTopBottom(mWindow.getContentFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
- assertInsetByTopBottom(mWindow.getVisibleFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
- assertInsetBy(mWindow.getDecorFrame(), 0, 0, 0, 0);
- assertInsetBy(mWindow.getDisplayFrameLw(), 0, 0, 0, 0);
- }
+ mWindow.mAttrs.softInputMode = SOFT_INPUT_ADJUST_NOTHING;
+ addWindow(mWindow);
+
+ final int forwardedInsetBottom = 50;
+ mDisplayPolicy.setForwardedInsets(Insets.of(0, 0, 0, forwardedInsetBottom));
+ mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
+ mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
+
+ assertInsetBy(mWindow.getParentFrame(), 0, 0, 0, 0);
+ assertInsetByTopBottom(mWindow.getStableFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
+ assertInsetByTopBottom(mWindow.getContentFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
+ assertInsetByTopBottom(mWindow.getVisibleFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
+ assertInsetBy(mWindow.getDecorFrame(), 0, 0, 0, 0);
+ assertInsetBy(mWindow.getDisplayFrameLw(), 0, 0, 0, 0);
}
@Test
public void layoutHint_appWindow() {
- synchronized (mWm.mGlobalLock) {
- // Initialize DisplayFrames
- mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
-
- final Rect outFrame = new Rect();
- final Rect outContentInsets = new Rect();
- final Rect outStableInsets = new Rect();
- final Rect outOutsets = new Rect();
- final DisplayCutout.ParcelableWrapper outDisplayCutout =
- new DisplayCutout.ParcelableWrapper();
-
- mDisplayPolicy.getLayoutHintLw(mWindow.mAttrs, null, mFrames,
- false /* floatingStack */, outFrame, outContentInsets, outStableInsets,
- outOutsets, outDisplayCutout);
-
- assertThat(outFrame, is(mFrames.mUnrestricted));
- assertThat(outContentInsets, is(new Rect(0, STATUS_BAR_HEIGHT, 0, NAV_BAR_HEIGHT)));
- assertThat(outStableInsets, is(new Rect(0, STATUS_BAR_HEIGHT, 0, NAV_BAR_HEIGHT)));
- assertThat(outOutsets, is(new Rect()));
- assertThat(outDisplayCutout, is(new DisplayCutout.ParcelableWrapper()));
- }
+ // Initialize DisplayFrames
+ mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
+
+ final Rect outFrame = new Rect();
+ final Rect outContentInsets = new Rect();
+ final Rect outStableInsets = new Rect();
+ final Rect outOutsets = new Rect();
+ final DisplayCutout.ParcelableWrapper outDisplayCutout =
+ new DisplayCutout.ParcelableWrapper();
+
+ mDisplayPolicy.getLayoutHintLw(mWindow.mAttrs, null, mFrames,
+ false /* floatingStack */, outFrame, outContentInsets, outStableInsets,
+ outOutsets, outDisplayCutout);
+
+ assertThat(outFrame, is(mFrames.mUnrestricted));
+ assertThat(outContentInsets, is(new Rect(0, STATUS_BAR_HEIGHT, 0, NAV_BAR_HEIGHT)));
+ assertThat(outStableInsets, is(new Rect(0, STATUS_BAR_HEIGHT, 0, NAV_BAR_HEIGHT)));
+ assertThat(outOutsets, is(new Rect()));
+ assertThat(outDisplayCutout, is(new DisplayCutout.ParcelableWrapper()));
}
@Test
public void layoutHint_appWindowInTask() {
- synchronized (mWm.mGlobalLock) {
- // Initialize DisplayFrames
- mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
-
- final Rect taskBounds = new Rect(100, 100, 200, 200);
-
- final Rect outFrame = new Rect();
- final Rect outContentInsets = new Rect();
- final Rect outStableInsets = new Rect();
- final Rect outOutsets = new Rect();
- final DisplayCutout.ParcelableWrapper outDisplayCutout =
- new DisplayCutout.ParcelableWrapper();
-
- mDisplayPolicy.getLayoutHintLw(mWindow.mAttrs, taskBounds, mFrames,
- false /* floatingStack */, outFrame, outContentInsets, outStableInsets,
- outOutsets, outDisplayCutout);
-
- assertThat(outFrame, is(taskBounds));
- assertThat(outContentInsets, is(new Rect()));
- assertThat(outStableInsets, is(new Rect()));
- assertThat(outOutsets, is(new Rect()));
- assertThat(outDisplayCutout, is(new DisplayCutout.ParcelableWrapper()));
- }
+ // Initialize DisplayFrames
+ mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
+
+ final Rect taskBounds = new Rect(100, 100, 200, 200);
+
+ final Rect outFrame = new Rect();
+ final Rect outContentInsets = new Rect();
+ final Rect outStableInsets = new Rect();
+ final Rect outOutsets = new Rect();
+ final DisplayCutout.ParcelableWrapper outDisplayCutout =
+ new DisplayCutout.ParcelableWrapper();
+
+ mDisplayPolicy.getLayoutHintLw(mWindow.mAttrs, taskBounds, mFrames,
+ false /* floatingStack */, outFrame, outContentInsets, outStableInsets,
+ outOutsets, outDisplayCutout);
+
+ assertThat(outFrame, is(taskBounds));
+ assertThat(outContentInsets, is(new Rect()));
+ assertThat(outStableInsets, is(new Rect()));
+ assertThat(outOutsets, is(new Rect()));
+ assertThat(outDisplayCutout, is(new DisplayCutout.ParcelableWrapper()));
}
@Test
public void layoutHint_appWindowInTask_outsideContentFrame() {
- synchronized (mWm.mGlobalLock) {
- // Initialize DisplayFrames
- mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
-
- // Task is in the nav bar area (usually does not happen, but this is similar enough to
- // the possible overlap with the IME)
- final Rect taskBounds = new Rect(100, mFrames.mContent.bottom + 1,
- 200, mFrames.mContent.bottom + 10);
-
- final Rect outFrame = new Rect();
- final Rect outContentInsets = new Rect();
- final Rect outStableInsets = new Rect();
- final Rect outOutsets = new Rect();
- final DisplayCutout.ParcelableWrapper outDisplayCutout =
- new DisplayCutout.ParcelableWrapper();
-
- mDisplayPolicy.getLayoutHintLw(mWindow.mAttrs, taskBounds, mFrames,
- true /* floatingStack */, outFrame, outContentInsets, outStableInsets,
- outOutsets, outDisplayCutout);
-
- assertThat(outFrame, is(taskBounds));
- assertThat(outContentInsets, is(new Rect()));
- assertThat(outStableInsets, is(new Rect()));
- assertThat(outOutsets, is(new Rect()));
- assertThat(outDisplayCutout, is(new DisplayCutout.ParcelableWrapper()));
- }
+ // Initialize DisplayFrames
+ mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
+
+ // Task is in the nav bar area (usually does not happen, but this is similar enough to
+ // the possible overlap with the IME)
+ final Rect taskBounds = new Rect(100, mFrames.mContent.bottom + 1,
+ 200, mFrames.mContent.bottom + 10);
+
+ final Rect outFrame = new Rect();
+ final Rect outContentInsets = new Rect();
+ final Rect outStableInsets = new Rect();
+ final Rect outOutsets = new Rect();
+ final DisplayCutout.ParcelableWrapper outDisplayCutout =
+ new DisplayCutout.ParcelableWrapper();
+
+ mDisplayPolicy.getLayoutHintLw(mWindow.mAttrs, taskBounds, mFrames,
+ true /* floatingStack */, outFrame, outContentInsets, outStableInsets,
+ outOutsets, outDisplayCutout);
+
+ assertThat(outFrame, is(taskBounds));
+ assertThat(outContentInsets, is(new Rect()));
+ assertThat(outStableInsets, is(new Rect()));
+ assertThat(outOutsets, is(new Rect()));
+ assertThat(outDisplayCutout, is(new DisplayCutout.ParcelableWrapper()));
}
@Test
public void forceShowSystemBars_clearsSystemUIFlags() {
- synchronized (mWm.mGlobalLock) {
- mDisplayPolicy.mLastSystemUiFlags |= SYSTEM_UI_FLAG_FULLSCREEN;
- mWindow.mAttrs.subtreeSystemUiVisibility |= SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
- mWindow.mAttrs.flags |= FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
- mWindow.mSystemUiVisibility = SYSTEM_UI_FLAG_FULLSCREEN;
- mDisplayPolicy.setForceShowSystemBars(true);
- addWindow(mWindow);
-
- mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
- mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
- // triggers updateSystemUiVisibilityLw which will reset the flags as needed
- int finishPostLayoutPolicyLw = mDisplayPolicy.focusChangedLw(mWindow, mWindow);
-
- assertEquals(WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT, finishPostLayoutPolicyLw);
- assertEquals(0, mDisplayPolicy.mLastSystemUiFlags);
- assertEquals(0, mWindow.mAttrs.systemUiVisibility);
- assertInsetByTopBottom(mWindow.getContentFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
- }
+ mDisplayPolicy.mLastSystemUiFlags |= SYSTEM_UI_FLAG_FULLSCREEN;
+ mWindow.mAttrs.subtreeSystemUiVisibility |= SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
+ mWindow.mAttrs.flags |= FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
+ mWindow.mSystemUiVisibility = SYSTEM_UI_FLAG_FULLSCREEN;
+ mDisplayPolicy.setForceShowSystemBars(true);
+ addWindow(mWindow);
+
+ mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
+ mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
+ // triggers updateSystemUiVisibilityLw which will reset the flags as needed
+ int finishPostLayoutPolicyLw = mDisplayPolicy.focusChangedLw(mWindow, mWindow);
+
+ assertEquals(WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT, finishPostLayoutPolicyLw);
+ assertEquals(0, mDisplayPolicy.mLastSystemUiFlags);
+ assertEquals(0, mWindow.mAttrs.systemUiVisibility);
+ assertInsetByTopBottom(mWindow.getContentFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
}
@Test
public void testScreenDecorWindows() {
- synchronized (mWm.mGlobalLock) {
- final WindowState decorWindow = createWindow(null, TYPE_APPLICATION_OVERLAY,
- "decorWindow");
- decorWindow.mAttrs.flags |= FLAG_NOT_FOCUSABLE;
- decorWindow.mAttrs.privateFlags |= PRIVATE_FLAG_IS_SCREEN_DECOR;
- addWindow(decorWindow);
- addWindow(mWindow);
-
- // Decor on top
- updateDecorWindow(decorWindow, MATCH_PARENT, DECOR_WINDOW_INSET, TOP);
- mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
- mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
- assertInsetByTopBottom(mWindow.getContentFrameLw(), DECOR_WINDOW_INSET, NAV_BAR_HEIGHT);
-
- // Decor on bottom
- updateDecorWindow(decorWindow, MATCH_PARENT, DECOR_WINDOW_INSET, BOTTOM);
- mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
- mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
- assertInsetByTopBottom(mWindow.getContentFrameLw(), STATUS_BAR_HEIGHT,
- DECOR_WINDOW_INSET);
-
- // Decor on the left
- updateDecorWindow(decorWindow, DECOR_WINDOW_INSET, MATCH_PARENT, LEFT);
- mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
- mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
- assertInsetBy(mWindow.getContentFrameLw(), DECOR_WINDOW_INSET, STATUS_BAR_HEIGHT, 0,
- NAV_BAR_HEIGHT);
-
- // Decor on the right
- updateDecorWindow(decorWindow, DECOR_WINDOW_INSET, MATCH_PARENT, RIGHT);
- mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
- mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
- assertInsetBy(mWindow.getContentFrameLw(), 0, STATUS_BAR_HEIGHT, DECOR_WINDOW_INSET,
- NAV_BAR_HEIGHT);
-
- // Decor not allowed as inset
- updateDecorWindow(decorWindow, DECOR_WINDOW_INSET, DECOR_WINDOW_INSET, TOP);
- mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
- mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
- assertInsetByTopBottom(mWindow.getContentFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
- }
+ final WindowState decorWindow = createWindow(null, TYPE_APPLICATION_OVERLAY, "decorWindow");
+ decorWindow.mAttrs.flags |= FLAG_NOT_FOCUSABLE;
+ decorWindow.mAttrs.privateFlags |= PRIVATE_FLAG_IS_SCREEN_DECOR;
+ addWindow(decorWindow);
+ addWindow(mWindow);
+
+ // Decor on top
+ updateDecorWindow(decorWindow, MATCH_PARENT, DECOR_WINDOW_INSET, TOP);
+ mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
+ mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
+ assertInsetByTopBottom(mWindow.getContentFrameLw(), DECOR_WINDOW_INSET, NAV_BAR_HEIGHT);
+
+ // Decor on bottom
+ updateDecorWindow(decorWindow, MATCH_PARENT, DECOR_WINDOW_INSET, BOTTOM);
+ mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
+ mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
+ assertInsetByTopBottom(mWindow.getContentFrameLw(), STATUS_BAR_HEIGHT,
+ DECOR_WINDOW_INSET);
+
+ // Decor on the left
+ updateDecorWindow(decorWindow, DECOR_WINDOW_INSET, MATCH_PARENT, LEFT);
+ mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
+ mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
+ assertInsetBy(mWindow.getContentFrameLw(), DECOR_WINDOW_INSET, STATUS_BAR_HEIGHT, 0,
+ NAV_BAR_HEIGHT);
+
+ // Decor on the right
+ updateDecorWindow(decorWindow, DECOR_WINDOW_INSET, MATCH_PARENT, RIGHT);
+ mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
+ mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
+ assertInsetBy(mWindow.getContentFrameLw(), 0, STATUS_BAR_HEIGHT, DECOR_WINDOW_INSET,
+ NAV_BAR_HEIGHT);
+
+ // Decor not allowed as inset
+ updateDecorWindow(decorWindow, DECOR_WINDOW_INSET, DECOR_WINDOW_INSET, TOP);
+ mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
+ mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
+ assertInsetByTopBottom(mWindow.getContentFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
}
private void updateDecorWindow(WindowState decorWindow, int width, int height, int gravity) {
diff --git a/services/tests/wmtests/src/com/android/server/wm/DisplayPolicyTests.java b/services/tests/wmtests/src/com/android/server/wm/DisplayPolicyTests.java
index 3ead97795954..e699b526e848 100644
--- a/services/tests/wmtests/src/com/android/server/wm/DisplayPolicyTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/DisplayPolicyTests.java
@@ -54,9 +54,11 @@ import androidx.test.filters.FlakyTest;
import androidx.test.filters.SmallTest;
import org.junit.Test;
+import org.junit.runner.RunWith;
@SmallTest
@Presubmit
+@RunWith(WindowTestRunner.class)
public class DisplayPolicyTests extends WindowTestsBase {
private WindowState createOpaqueFullscreen(boolean hasLightNavBar) {
@@ -225,13 +227,10 @@ public class DisplayPolicyTests extends WindowTestsBase {
final WindowState activity = createApplicationWindow();
final WindowState toast = createToastWindow();
- synchronized (mWm.mGlobalLock) {
- policy.adjustWindowParamsLw(
- toast, toast.mAttrs, 0 /* callingPid */, 0 /* callingUid */);
+ policy.adjustWindowParamsLw(toast, toast.mAttrs, 0 /* callingPid */, 0 /* callingUid */);
- assertTrue(policy.canToastShowWhenLocked(0 /* callingUid */));
- assertNotEquals(0, toast.getAttrs().flags & FLAG_SHOW_WHEN_LOCKED);
- }
+ assertTrue(policy.canToastShowWhenLocked(0 /* callingUid */));
+ assertNotEquals(0, toast.getAttrs().flags & FLAG_SHOW_WHEN_LOCKED);
}
private WindowState createToastWindow() {
diff --git a/services/tests/wmtests/src/com/android/server/wm/DragDropControllerTests.java b/services/tests/wmtests/src/com/android/server/wm/DragDropControllerTests.java
index bb80e5e4ddde..9d3c866d3ae7 100644
--- a/services/tests/wmtests/src/com/android/server/wm/DragDropControllerTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/DragDropControllerTests.java
@@ -23,7 +23,6 @@ import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.any;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock;
-import static com.android.dx.mockito.inline.extended.ExtendedMockito.spy;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.when;
import static org.junit.Assert.assertNotNull;
@@ -51,6 +50,7 @@ import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
+import org.junit.runner.RunWith;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@@ -59,10 +59,11 @@ import java.util.concurrent.TimeUnit;
* Tests for the {@link DragDropController} class.
*
* Build/Install/Run:
- * atest FrameworksServicesTests:DragDropControllerTests
+ * atest WmTests:DragDropControllerTests
*/
@SmallTest
@Presubmit
+@RunWith(WindowTestRunner.class)
public class DragDropControllerTests extends WindowTestsBase {
private static final int TIMEOUT_MS = 3000;
private TestDragDropController mTarget;
@@ -123,30 +124,25 @@ public class DragDropControllerTests extends WindowTestsBase {
@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(mWm.mInputManager.transferTouchFocus(any(), any())).thenReturn(true);
- synchronized (mWm.mGlobalLock) {
- mWm.mWindowMap.put(mWindow.mClient.asBinder(), mWindow);
- }
+ mWm.mWindowMap.put(mWindow.mClient.asBinder(), mWindow);
}
@After
public void tearDown() throws Exception {
final CountDownLatch latch;
- synchronized (mWm.mGlobalLock) {
- if (!mTarget.dragDropActiveLocked()) {
- return;
- }
- if (mToken != null) {
- mTarget.cancelDragAndDrop(mToken, false);
- }
- latch = new CountDownLatch(1);
- mTarget.setOnClosedCallbackLocked(latch::countDown);
+ if (!mTarget.dragDropActiveLocked()) {
+ return;
+ }
+ if (mToken != null) {
+ mTarget.cancelDragAndDrop(mToken, false);
}
- assertTrue(latch.await(TIMEOUT_MS, TimeUnit.MILLISECONDS));
+ latch = new CountDownLatch(1);
+ mTarget.setOnClosedCallbackLocked(latch::countDown);
+ assertTrue(awaitInWmLock(() -> latch.await(TIMEOUT_MS, TimeUnit.MILLISECONDS)));
}
@Test
diff --git a/services/tests/wmtests/src/com/android/server/wm/RecentsAnimationControllerTest.java b/services/tests/wmtests/src/com/android/server/wm/RecentsAnimationControllerTest.java
index f792b0db6cb5..5236b5d0e07f 100644
--- a/services/tests/wmtests/src/com/android/server/wm/RecentsAnimationControllerTest.java
+++ b/services/tests/wmtests/src/com/android/server/wm/RecentsAnimationControllerTest.java
@@ -66,15 +66,17 @@ 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;
/**
* Build/Install/Run:
- * atest FrameworksServicesTests:RecentsAnimationControllerTest
+ * atest WmTests:RecentsAnimationControllerTest
*/
@SmallTest
@Presubmit
+@RunWith(WindowTestRunner.class)
public class RecentsAnimationControllerTest extends WindowTestsBase {
@Mock SurfaceControl mMockLeash;
@@ -88,12 +90,8 @@ public class RecentsAnimationControllerTest extends WindowTestsBase {
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
- synchronized (mWm.mGlobalLock) {
- // Hold the lock to protect the stubbing from being accessed by other threads.
- spyOn(mWm.mRoot);
- doNothing().when(mWm.mRoot).performSurfacePlacement(anyBoolean());
- doReturn(mDisplayContent).when(mWm.mRoot).getDisplayContent(anyInt());
- }
+ doNothing().when(mWm.mRoot).performSurfacePlacement(anyBoolean());
+ doReturn(mDisplayContent).when(mWm.mRoot).getDisplayContent(anyInt());
when(mMockRunner.asBinder()).thenReturn(new Binder());
mController = spy(new RecentsAnimationController(mWm, mMockRunner, mAnimationCallbacks,
DEFAULT_DISPLAY));
diff --git a/services/tests/wmtests/src/com/android/server/wm/RootWindowContainerTests.java b/services/tests/wmtests/src/com/android/server/wm/RootWindowContainerTests.java
index db105ddc956d..afe18c332b9d 100644
--- a/services/tests/wmtests/src/com/android/server/wm/RootWindowContainerTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/RootWindowContainerTests.java
@@ -31,6 +31,7 @@ import android.platform.test.annotations.Presubmit;
import androidx.test.filters.SmallTest;
import org.junit.Test;
+import org.junit.runner.RunWith;
/**
* Tests for RootWindowContainer.
@@ -40,6 +41,7 @@ import org.junit.Test;
*/
@SmallTest
@Presubmit
+@RunWith(WindowTestRunner.class)
public class RootWindowContainerTests extends WindowTestsBase {
private static final int FAKE_CALLING_UID = 667;
@@ -91,18 +93,16 @@ public class RootWindowContainerTests extends WindowTestsBase {
@Test
public void testUpdateDefaultDisplayWindowingModeOnSettingsRetrieved() {
- synchronized (mWm.mGlobalLock) {
- assertEquals(WindowConfiguration.WINDOWING_MODE_FULLSCREEN,
- mWm.getDefaultDisplayContentLocked().getWindowingMode());
+ assertEquals(WindowConfiguration.WINDOWING_MODE_FULLSCREEN,
+ mWm.getDefaultDisplayContentLocked().getWindowingMode());
- mWm.mIsPc = true;
- mWm.mAtmService.mSupportsFreeformWindowManagement = true;
+ mWm.mIsPc = true;
+ mWm.mAtmService.mSupportsFreeformWindowManagement = true;
- mWm.mRoot.onSettingsRetrieved();
+ mWm.mRoot.onSettingsRetrieved();
- assertEquals(WindowConfiguration.WINDOWING_MODE_FREEFORM,
- mWm.getDefaultDisplayContentLocked().getWindowingMode());
- }
+ assertEquals(WindowConfiguration.WINDOWING_MODE_FREEFORM,
+ mWm.getDefaultDisplayContentLocked().getWindowingMode());
}
}
diff --git a/services/tests/wmtests/src/com/android/server/wm/RunningTasksTest.java b/services/tests/wmtests/src/com/android/server/wm/RunningTasksTest.java
index 3e316f674dbf..8326ad8bdefe 100644
--- a/services/tests/wmtests/src/com/android/server/wm/RunningTasksTest.java
+++ b/services/tests/wmtests/src/com/android/server/wm/RunningTasksTest.java
@@ -35,6 +35,7 @@ import androidx.test.filters.MediumTest;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
import java.util.ArrayList;
@@ -44,6 +45,7 @@ import java.util.ArrayList;
*/
@MediumTest
@Presubmit
+@RunWith(WindowTestRunner.class)
public class RunningTasksTest extends ActivityTestsBase {
private static final ArraySet<Integer> PROFILE_IDS = new ArraySet<>();
diff --git a/services/tests/wmtests/src/com/android/server/wm/SystemServiceTestsBase.java b/services/tests/wmtests/src/com/android/server/wm/SystemServiceTestsBase.java
new file mode 100644
index 000000000000..d1b6f6f3f4cf
--- /dev/null
+++ b/services/tests/wmtests/src/com/android/server/wm/SystemServiceTestsBase.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2019 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 android.os.Handler;
+import android.testing.DexmakerShareClassLoaderRule;
+
+import org.junit.Rule;
+
+import java.util.concurrent.Callable;
+
+/** The base class which provides the common rule for test classes under wm package. */
+class SystemServiceTestsBase {
+ @Rule
+ public final DexmakerShareClassLoaderRule mDexmakerShareClassLoaderRule =
+ new DexmakerShareClassLoaderRule();
+ @Rule
+ public final SystemServicesTestRule mSystemServicesTestRule = new SystemServicesTestRule();
+
+ @WindowTestRunner.MethodWrapperRule
+ public final WindowManagerGlobalLockRule mLockRule =
+ new WindowManagerGlobalLockRule(mSystemServicesTestRule);
+
+ /** Waits until the main handler for WM has processed all messages. */
+ void waitUntilHandlersIdle() {
+ mLockRule.waitForLocked(mSystemServicesTestRule::waitUntilWindowManagerHandlersIdle);
+ }
+
+ boolean waitHandlerIdle(Handler handler) {
+ return waitHandlerIdle(handler, 0 /* timeout */);
+ }
+
+ boolean waitHandlerIdle(Handler handler, long timeout) {
+ return runWithScissors(handler, () -> { }, timeout);
+ }
+
+ boolean runWithScissors(Handler handler, Runnable r, long timeout) {
+ return mLockRule.runWithScissors(handler, r, timeout);
+ }
+
+ /** It is used when we want to wait for a result inside {@link WindowManagerGlobalLock}. */
+ <T> T awaitInWmLock(Callable<T> callable) {
+ return mLockRule.waitForLocked(callable);
+ }
+}
diff --git a/services/tests/wmtests/src/com/android/server/wm/SystemServicesTestRule.java b/services/tests/wmtests/src/com/android/server/wm/SystemServicesTestRule.java
index 5a4d3991bedd..ef9821b92201 100644
--- a/services/tests/wmtests/src/com/android/server/wm/SystemServicesTestRule.java
+++ b/services/tests/wmtests/src/com/android/server/wm/SystemServicesTestRule.java
@@ -18,7 +18,6 @@ package com.android.server.wm;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME;
import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
-import static android.os.Process.THREAD_PRIORITY_DEFAULT;
import static android.testing.DexmakerShareClassLoaderRule.runWithDexmakerShareClassLoader;
import static android.view.Display.DEFAULT_DISPLAY;
@@ -36,7 +35,6 @@ import static com.android.dx.mockito.inline.extended.ExtendedMockito.mockitoSess
import static com.android.dx.mockito.inline.extended.ExtendedMockito.nullable;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.spy;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn;
-import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
import android.app.ActivityManagerInternal;
import android.app.AppOpsManager;
@@ -68,11 +66,12 @@ import com.android.server.AnimationThread;
import com.android.server.DisplayThread;
import com.android.server.LocalServices;
import com.android.server.LockGuard;
-import com.android.server.ServiceThread;
+import com.android.server.UiThread;
import com.android.server.Watchdog;
import com.android.server.am.ActivityManagerService;
import com.android.server.appop.AppOpsService;
import com.android.server.display.color.ColorDisplayService;
+import com.android.server.firewall.IntentFirewall;
import com.android.server.input.InputManagerService;
import com.android.server.pm.UserManagerService;
import com.android.server.policy.PermissionPolicyInternal;
@@ -105,13 +104,13 @@ public class SystemServicesTestRule implements TestRule {
private Context mContext;
private StaticMockitoSession mMockitoSession;
- ServiceThread mHandlerThread;
private ActivityManagerService mAmService;
private ActivityTaskManagerService mAtmService;
private WindowManagerService mWmService;
private TestWindowManagerPolicy mWMPolicy;
private WindowState.PowerManagerWrapper mPowerManagerWrapper;
private InputManagerService mImService;
+ private InputChannel mInputChannel;
/**
* Spied {@link SurfaceControl.Transaction} class than can be used to verify calls.
*/
@@ -147,10 +146,6 @@ public class SystemServicesTestRule implements TestRule {
}
private void setUpSystemCore() {
- mHandlerThread = new ServiceThread(
- "WmTestsThread", THREAD_PRIORITY_DEFAULT, true /* allowIo */);
- mHandlerThread.start();
-
doReturn(mock(Watchdog.class)).when(Watchdog::getInstance);
mContext = getInstrumentation().getTargetContext();
@@ -181,6 +176,11 @@ public class SystemServicesTestRule implements TestRule {
final AppOpsManager aom = mock(AppOpsManager.class);
doReturn(aom).when(mContext).getSystemService(eq(Context.APP_OPS_SERVICE));
+ // Prevent "WakeLock finalized while still held: SCREEN_FROZEN".
+ final PowerManager pm = mock(PowerManager.class);
+ doReturn(pm).when(mContext).getSystemService(eq(Context.POWER_SERVICE));
+ doReturn(mock(PowerManager.WakeLock.class)).when(pm).newWakeLock(anyInt(), anyString());
+
// DisplayManagerInternal
final DisplayManagerInternal dmi = mock(DisplayManagerInternal.class);
doReturn(dmi).when(() -> LocalServices.getService(eq(DisplayManagerInternal.class)));
@@ -214,11 +214,11 @@ public class SystemServicesTestRule implements TestRule {
// InputManagerService
mImService = mock(InputManagerService.class);
- // InputChannel is final and can't be mocked.
- final InputChannel[] input = InputChannel.openInputChannelPair(TAG_WM);
- if (input != null && input.length > 1) {
- doReturn(input[1]).when(mImService).monitorInput(anyString(), anyInt());
- }
+ // InputChannel cannot be mocked because it may pass to InputEventReceiver.
+ final InputChannel[] inputChannels = InputChannel.openInputChannelPair(TAG);
+ inputChannels[0].dispose();
+ mInputChannel = inputChannels[1];
+ doReturn(mInputChannel).when(mImService).monitorInput(anyString(), anyInt());
// StatusBarManagerInternal
final StatusBarManagerInternal sbmi = mock(StatusBarManagerInternal.class);
@@ -227,8 +227,7 @@ public class SystemServicesTestRule implements TestRule {
private void setUpActivityTaskManagerService() {
// ActivityManagerService
- mAmService = new ActivityManagerService(
- new AMTestInjector(mContext, mHandlerThread), mHandlerThread);
+ mAmService = new ActivityManagerService(new AMTestInjector(mContext), null /* thread */);
spyOn(mAmService);
doReturn(mock(IPackageManager.class)).when(mAmService).getPackageManager();
doNothing().when(mAmService).grantImplicitAccess(
@@ -246,6 +245,15 @@ public class SystemServicesTestRule implements TestRule {
doNothing().when(amInternal).startProcess(
any(), any(), anyBoolean(), anyBoolean(), any(), any());
doNothing().when(amInternal).updateOomLevelsForDisplay(anyInt());
+ doNothing().when(amInternal).broadcastGlobalConfigurationChanged(anyInt(), anyBoolean());
+ doNothing().when(amInternal).cleanUpServices(anyInt(), any(), any());
+ doReturn(UserHandle.USER_SYSTEM).when(amInternal).getCurrentUserId();
+ doReturn(TEST_USER_PROFILE_IDS).when(amInternal).getCurrentProfileIds();
+ doReturn(true).when(amInternal).isCurrentProfile(anyInt());
+ doReturn(true).when(amInternal).isUserRunning(anyInt(), anyInt());
+ doReturn(true).when(amInternal).hasStartedUserState(anyInt());
+ doReturn(false).when(amInternal).shouldConfirmCredentials(anyInt());
+ doReturn(false).when(amInternal).isActivityStartsLoggingEnabled();
LocalServices.addService(ActivityManagerInternal.class, amInternal);
mAtmService = new TestActivityTaskManagerService(mContext, mAmService);
@@ -289,7 +297,6 @@ public class SystemServicesTestRule implements TestRule {
}
private void tearDown() {
- waitUntilWindowManagerHandlersIdle();
// Unregister display listener from root to avoid issues with subsequent tests.
mContext.getSystemService(DisplayManager.class)
.unregisterDisplayListener(mAtmService.mRootActivityContainer);
@@ -297,37 +304,23 @@ public class SystemServicesTestRule implements TestRule {
// a static object, so we need to clean it up in tearDown(), even though we didn't set up
// in tests.
DeviceConfig.removeOnPropertiesChangedListener(mWmService.mPropertiesChangedListener);
- mWmService = null;
- mWMPolicy = null;
- mPowerManagerWrapper = null;
-
- tearDownLocalServices();
- tearDownSystemCore();
+ waitUntilWindowManagerHandlersIdle();
// Needs to explicitly dispose current static threads because there could be messages
// scheduled at a later time, and all mocks are invalid when it's executed.
DisplayThread.dispose();
AnimationThread.dispose();
+ UiThread.dispose();
+ mInputChannel.dispose();
+
+ tearDownLocalServices();
// Reset priority booster because animation thread has been changed.
WindowManagerService.sThreadPriorityBooster = new WindowManagerThreadPriorityBooster();
+ mMockitoSession.finishMocking();
Mockito.framework().clearInlineMocks();
}
- private void tearDownSystemCore() {
- if (mMockitoSession != null) {
- mMockitoSession.finishMocking();
- mMockitoSession = null;
- }
-
- if (mHandlerThread != null) {
- // Make sure there are no running messages and then quit the thread so the next test
- // won't be affected.
- mHandlerThread.getThreadHandler().runWithScissors(mHandlerThread::quit,
- 0 /* timeout */);
- }
- }
-
private static void tearDownLocalServices() {
LocalServices.removeServiceForTest(DisplayManagerInternal.class);
LocalServices.removeServiceForTest(PowerManagerInternal.class);
@@ -375,7 +368,6 @@ public class SystemServicesTestRule implements TestRule {
waitHandlerIdle(wm.mH);
waitHandlerIdle(wm.mAnimationHandler);
waitHandlerIdle(SurfaceAnimationThread.getHandler());
- waitHandlerIdle(mHandlerThread.getThreadHandler());
}
private void waitHandlerIdle(Handler handler) {
@@ -435,8 +427,12 @@ public class SystemServicesTestRule implements TestRule {
ams.mActivityTaskManager = this;
ams.mAtmInternal = mInternal;
onActivityManagerInternalAdded();
- initialize(
- ams.mIntentFirewall, ams.mPendingIntentController, mHandlerThread.getLooper());
+
+ final IntentFirewall intentFirewall = mock(IntentFirewall.class);
+ doReturn(true).when(intentFirewall).checkStartActivity(
+ any(), anyInt(), anyInt(), nullable(String.class), any());
+ initialize(intentFirewall, null /* intentController */,
+ DisplayThread.getHandler().getLooper());
spyOn(getLifecycleManager());
spyOn(getLockTaskController());
spyOn(getTaskChangeNotificationController());
@@ -493,11 +489,9 @@ public class SystemServicesTestRule implements TestRule {
// TODO: Can we just mock this?
private static class AMTestInjector extends ActivityManagerService.Injector {
- private ServiceThread mHandlerThread;
- AMTestInjector(Context context, ServiceThread handlerThread) {
+ AMTestInjector(Context context) {
super(context);
- mHandlerThread = handlerThread;
}
@Override
@@ -512,7 +506,7 @@ public class SystemServicesTestRule implements TestRule {
@Override
public Handler getUiHandler(ActivityManagerService service) {
- return mHandlerThread.getThreadHandler();
+ return UiThread.getHandler();
}
@Override
diff --git a/services/tests/wmtests/src/com/android/server/wm/TaskPositioningControllerTests.java b/services/tests/wmtests/src/com/android/server/wm/TaskPositioningControllerTests.java
index eb351b63a469..2ac5f7d94560 100644
--- a/services/tests/wmtests/src/com/android/server/wm/TaskPositioningControllerTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/TaskPositioningControllerTests.java
@@ -22,7 +22,6 @@ import static com.android.dx.mockito.inline.extended.ExtendedMockito.any;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.anyInt;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock;
-import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.when;
import static org.junit.Assert.assertFalse;
@@ -38,6 +37,7 @@ import androidx.test.filters.SmallTest;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
/**
* Tests for the {@link TaskPositioningController} class.
@@ -47,6 +47,7 @@ import org.junit.Test;
*/
@SmallTest
@Presubmit
+@RunWith(WindowTestRunner.class)
public class TaskPositioningControllerTests extends WindowTestsBase {
private static final int TIMEOUT_MS = 1000;
@@ -64,30 +65,23 @@ public class TaskPositioningControllerTests extends WindowTestsBase {
mWindow = createWindow(null, TYPE_BASE_APPLICATION, "window");
mWindow.mInputChannel = new InputChannel();
- synchronized (mWm.mGlobalLock) {
- mWm.mWindowMap.put(mWindow.mClient.asBinder(), mWindow);
- spyOn(mDisplayContent);
- doReturn(mock(InputMonitor.class)).when(mDisplayContent).getInputMonitor();
- }
+ mWm.mWindowMap.put(mWindow.mClient.asBinder(), mWindow);
+ doReturn(mock(InputMonitor.class)).when(mDisplayContent).getInputMonitor();
}
@Test
public void testStartAndFinishPositioning() {
- synchronized (mWm.mGlobalLock) {
- assertFalse(mTarget.isPositioningLocked());
- assertNull(mTarget.getDragWindowHandleLocked());
- }
+ assertFalse(mTarget.isPositioningLocked());
+ assertNull(mTarget.getDragWindowHandleLocked());
assertTrue(mTarget.startMovingTask(mWindow.mClient, 0, 0));
- synchronized (mWm.mGlobalLock) {
- assertTrue(mTarget.isPositioningLocked());
- assertNotNull(mTarget.getDragWindowHandleLocked());
- }
+ assertTrue(mTarget.isPositioningLocked());
+ assertNotNull(mTarget.getDragWindowHandleLocked());
mTarget.finishTaskPositioning();
// Wait until the looper processes finishTaskPositioning.
- assertTrue(mWm.mH.runWithScissors(() -> { }, TIMEOUT_MS));
+ assertTrue(waitHandlerIdle(mWm.mH, TIMEOUT_MS));
assertFalse(mTarget.isPositioningLocked());
assertNull(mTarget.getDragWindowHandleLocked());
@@ -96,21 +90,17 @@ public class TaskPositioningControllerTests extends WindowTestsBase {
@FlakyTest(bugId = 129507487)
@Test
public void testFinishPositioningWhenAppRequested() {
- synchronized (mWm.mGlobalLock) {
- assertFalse(mTarget.isPositioningLocked());
- assertNull(mTarget.getDragWindowHandleLocked());
- }
+ assertFalse(mTarget.isPositioningLocked());
+ assertNull(mTarget.getDragWindowHandleLocked());
assertTrue(mTarget.startMovingTask(mWindow.mClient, 0, 0));
- synchronized (mWm.mGlobalLock) {
- assertTrue(mTarget.isPositioningLocked());
- assertNotNull(mTarget.getDragWindowHandleLocked());
- }
+ assertTrue(mTarget.isPositioningLocked());
+ assertNotNull(mTarget.getDragWindowHandleLocked());
mTarget.finishTaskPositioning(mWindow.mClient);
// Wait until the looper processes finishTaskPositioning.
- assertTrue(mWm.mH.runWithScissors(() -> { }, TIMEOUT_MS));
+ assertTrue(waitHandlerIdle(mWm.mH, TIMEOUT_MS));
assertFalse(mTarget.isPositioningLocked());
assertNull(mTarget.getDragWindowHandleLocked());
@@ -118,10 +108,8 @@ public class TaskPositioningControllerTests extends WindowTestsBase {
@Test
public void testHandleTapOutsideTask() {
- synchronized (mWm.mGlobalLock) {
- assertFalse(mTarget.isPositioningLocked());
- assertNull(mTarget.getDragWindowHandleLocked());
- }
+ assertFalse(mTarget.isPositioningLocked());
+ assertNull(mTarget.getDragWindowHandleLocked());
final DisplayContent content = mock(DisplayContent.class);
when(content.findTaskForResizePoint(anyInt(), anyInt())).thenReturn(mWindow.getTask());
@@ -129,16 +117,14 @@ public class TaskPositioningControllerTests extends WindowTestsBase {
mTarget.handleTapOutsideTask(content, 0, 0);
// Wait until the looper processes finishTaskPositioning.
- assertTrue(mWm.mH.runWithScissors(() -> { }, TIMEOUT_MS));
+ assertTrue(waitHandlerIdle(mWm.mH, TIMEOUT_MS));
- synchronized (mWm.mGlobalLock) {
- assertTrue(mTarget.isPositioningLocked());
- assertNotNull(mTarget.getDragWindowHandleLocked());
- }
+ assertTrue(mTarget.isPositioningLocked());
+ assertNotNull(mTarget.getDragWindowHandleLocked());
mTarget.finishTaskPositioning();
// Wait until the looper processes finishTaskPositioning.
- assertTrue(mWm.mH.runWithScissors(() -> { }, TIMEOUT_MS));
+ assertTrue(waitHandlerIdle(mWm.mH, TIMEOUT_MS));
assertFalse(mTarget.isPositioningLocked());
assertNull(mTarget.getDragWindowHandleLocked());
diff --git a/services/tests/wmtests/src/com/android/server/wm/TaskRecordTests.java b/services/tests/wmtests/src/com/android/server/wm/TaskRecordTests.java
index c83401b2eb65..d3588a269bbc 100644
--- a/services/tests/wmtests/src/com/android/server/wm/TaskRecordTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/TaskRecordTests.java
@@ -51,7 +51,6 @@ import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
-import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import android.app.ActivityManager;
@@ -78,6 +77,7 @@ import com.android.server.wm.utils.WmDisplayCutout;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
@@ -98,6 +98,7 @@ import java.util.ArrayList;
*/
@MediumTest
@Presubmit
+@RunWith(WindowTestRunner.class)
public class TaskRecordTests extends ActivityTestsBase {
private static final String TASK_TAG = "task";
diff --git a/services/tests/wmtests/src/com/android/server/wm/TaskStackContainersTests.java b/services/tests/wmtests/src/com/android/server/wm/TaskStackContainersTests.java
index 74ccccca43bb..5a0f7ed89cd0 100644
--- a/services/tests/wmtests/src/com/android/server/wm/TaskStackContainersTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/TaskStackContainersTests.java
@@ -32,15 +32,17 @@ import androidx.test.filters.SmallTest;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
/**
* Tests for the {@link DisplayContent.TaskStackContainers} container in {@link DisplayContent}.
*
* Build/Install/Run:
- * atest FrameworksServicesTests:TaskStackContainersTests
+ * atest WmTests:TaskStackContainersTests
*/
@SmallTest
@Presubmit
+@RunWith(WindowTestRunner.class)
public class TaskStackContainersTests extends WindowTestsBase {
private TaskStack mPinnedStack;
diff --git a/services/tests/wmtests/src/com/android/server/wm/TaskStackTests.java b/services/tests/wmtests/src/com/android/server/wm/TaskStackTests.java
index 70ed62a4a11e..a2c76bed7840 100644
--- a/services/tests/wmtests/src/com/android/server/wm/TaskStackTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/TaskStackTests.java
@@ -34,15 +34,17 @@ import android.platform.test.annotations.Presubmit;
import androidx.test.filters.SmallTest;
import org.junit.Test;
+import org.junit.runner.RunWith;
/**
* Tests for the {@link TaskStack} class.
*
* Build/Install/Run:
- * atest FrameworksServicesTests:TaskStackTests
+ * atest WmTests:TaskStackTests
*/
@SmallTest
@Presubmit
+@RunWith(WindowTestRunner.class)
public class TaskStackTests extends WindowTestsBase {
@Test
@@ -176,13 +178,8 @@ public class TaskStackTests extends WindowTestsBase {
public void testStackOutset() {
final TaskStack stack = createTaskStackOnDisplay(mDisplayContent);
final int stackOutset = 10;
- // Clear the handler and hold the lock for mock, to prevent multi-thread issue.
- waitUntilHandlersIdle();
- synchronized (mWm.mGlobalLock) {
- spyOn(stack);
-
- doReturn(stackOutset).when(stack).getStackOutset();
- }
+ spyOn(stack);
+ doReturn(stackOutset).when(stack).getStackOutset();
final Rect stackBounds = new Rect(200, 200, 800, 1000);
// Update surface position and size by the given bounds.
diff --git a/services/tests/wmtests/src/com/android/server/wm/TaskTests.java b/services/tests/wmtests/src/com/android/server/wm/TaskTests.java
index 41842010d3a3..16fdf94cabbd 100644
--- a/services/tests/wmtests/src/com/android/server/wm/TaskTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/TaskTests.java
@@ -29,15 +29,17 @@ import android.platform.test.annotations.Presubmit;
import androidx.test.filters.SmallTest;
import org.junit.Test;
+import org.junit.runner.RunWith;
/**
* Test class for {@link Task}.
*
* Build/Install/Run:
- * atest FrameworksServicesTests:TaskTests
+ * atest WmTests:TaskTests
*/
@SmallTest
@Presubmit
+@RunWith(WindowTestRunner.class)
public class TaskTests extends WindowTestsBase {
@Test
diff --git a/services/tests/wmtests/src/com/android/server/wm/UnknownAppVisibilityControllerTest.java b/services/tests/wmtests/src/com/android/server/wm/UnknownAppVisibilityControllerTest.java
index a91daf0c7647..2e86178f4a10 100644
--- a/services/tests/wmtests/src/com/android/server/wm/UnknownAppVisibilityControllerTest.java
+++ b/services/tests/wmtests/src/com/android/server/wm/UnknownAppVisibilityControllerTest.java
@@ -24,15 +24,17 @@ import androidx.test.filters.SmallTest;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
/**
* Test class for {@link AppTransition}.
*
* Build/Install/Run:
- * atest FrameworksServicesTests:UnknownAppVisibilityControllerTest
+ * atest WmTests:UnknownAppVisibilityControllerTest
*/
@SmallTest
@Presubmit
+@RunWith(WindowTestRunner.class)
public class UnknownAppVisibilityControllerTest extends WindowTestsBase {
@Before
@@ -48,7 +50,7 @@ public class UnknownAppVisibilityControllerTest extends WindowTestsBase {
mDisplayContent.mUnknownAppVisibilityController.notifyRelayouted(token);
// Make sure our handler processed the message.
- mWm.mH.runWithScissors(() -> { }, 0);
+ waitHandlerIdle(mWm.mH);
assertTrue(mDisplayContent.mUnknownAppVisibilityController.allResolved());
}
@@ -64,7 +66,7 @@ public class UnknownAppVisibilityControllerTest extends WindowTestsBase {
mDisplayContent.mUnknownAppVisibilityController.notifyRelayouted(token2);
// Make sure our handler processed the message.
- mWm.mH.runWithScissors(() -> { }, 0);
+ waitHandlerIdle(mWm.mH);
assertTrue(mDisplayContent.mUnknownAppVisibilityController.allResolved());
}
diff --git a/services/tests/wmtests/src/com/android/server/wm/WallpaperControllerTests.java b/services/tests/wmtests/src/com/android/server/wm/WallpaperControllerTests.java
index 6249bde3cea6..14d8a9ddab67 100644
--- a/services/tests/wmtests/src/com/android/server/wm/WallpaperControllerTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/WallpaperControllerTests.java
@@ -30,6 +30,7 @@ import android.platform.test.annotations.Presubmit;
import androidx.test.filters.SmallTest;
import org.junit.Test;
+import org.junit.runner.RunWith;
/**
* Tests for the {@link WallpaperController} class.
@@ -39,37 +40,36 @@ import org.junit.Test;
*/
@SmallTest
@Presubmit
+@RunWith(WindowTestRunner.class)
public class WallpaperControllerTests extends WindowTestsBase {
@Test
public void testWallpaperScreenshot() {
WindowSurfaceController windowSurfaceController = mock(WindowSurfaceController.class);
- synchronized (mWm.mGlobalLock) {
- // No wallpaper
- final DisplayContent dc = createNewDisplay();
- assertFalse(dc.mWallpaperController.canScreenshotWallpaper());
+ // No wallpaper
+ final DisplayContent dc = createNewDisplay();
+ assertFalse(dc.mWallpaperController.canScreenshotWallpaper());
- // No wallpaper WSA Surface
- WindowToken wallpaperWindowToken = new WallpaperWindowToken(mWm, mock(IBinder.class),
- true, dc, true /* ownerCanManageAppTokens */);
- WindowState wallpaperWindow = createWindow(null /* parent */, TYPE_WALLPAPER,
- wallpaperWindowToken, "wallpaperWindow");
- assertFalse(dc.mWallpaperController.canScreenshotWallpaper());
+ // No wallpaper WSA Surface
+ WindowToken wallpaperWindowToken = new WallpaperWindowToken(mWm, mock(IBinder.class),
+ true, dc, true /* ownerCanManageAppTokens */);
+ WindowState wallpaperWindow = createWindow(null /* parent */, TYPE_WALLPAPER,
+ wallpaperWindowToken, "wallpaperWindow");
+ assertFalse(dc.mWallpaperController.canScreenshotWallpaper());
- // Wallpaper with not visible WSA surface.
- wallpaperWindow.mWinAnimator.mSurfaceController = windowSurfaceController;
- wallpaperWindow.mWinAnimator.mLastAlpha = 1;
- assertFalse(dc.mWallpaperController.canScreenshotWallpaper());
+ // Wallpaper with not visible WSA surface.
+ wallpaperWindow.mWinAnimator.mSurfaceController = windowSurfaceController;
+ wallpaperWindow.mWinAnimator.mLastAlpha = 1;
+ assertFalse(dc.mWallpaperController.canScreenshotWallpaper());
- when(windowSurfaceController.getShown()).thenReturn(true);
+ when(windowSurfaceController.getShown()).thenReturn(true);
- // Wallpaper with WSA alpha set to 0.
- wallpaperWindow.mWinAnimator.mLastAlpha = 0;
- assertFalse(dc.mWallpaperController.canScreenshotWallpaper());
+ // Wallpaper with WSA alpha set to 0.
+ wallpaperWindow.mWinAnimator.mLastAlpha = 0;
+ assertFalse(dc.mWallpaperController.canScreenshotWallpaper());
- // Wallpaper window with WSA Surface
- wallpaperWindow.mWinAnimator.mLastAlpha = 1;
- assertTrue(dc.mWallpaperController.canScreenshotWallpaper());
- }
+ // Wallpaper window with WSA Surface
+ wallpaperWindow.mWinAnimator.mLastAlpha = 1;
+ assertTrue(dc.mWallpaperController.canScreenshotWallpaper());
}
}
diff --git a/services/tests/wmtests/src/com/android/server/wm/WindowFrameTests.java b/services/tests/wmtests/src/com/android/server/wm/WindowFrameTests.java
index 60cefe858c54..3563febb46f8 100644
--- a/services/tests/wmtests/src/com/android/server/wm/WindowFrameTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/WindowFrameTests.java
@@ -43,16 +43,18 @@ import com.android.server.wm.utils.WmDisplayCutout;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
import org.mockito.Mockito;
/**
* Tests for the {@link WindowState#computeFrameLw} method and other window frame machinery.
*
* Build/Install/Run:
- * atest FrameworksServicesTests:WindowFrameTests
+ * atest WmTests:WindowFrameTests
*/
@SmallTest
@Presubmit
+@RunWith(WindowTestRunner.class)
public class WindowFrameTests extends WindowTestsBase {
private final IWindow mIWindow = new TestIWindow();
diff --git a/services/tests/wmtests/src/com/android/server/wm/WindowManagerGlobalLockRule.java b/services/tests/wmtests/src/com/android/server/wm/WindowManagerGlobalLockRule.java
index e0c314fd572e..c5f13e05843b 100644
--- a/services/tests/wmtests/src/com/android/server/wm/WindowManagerGlobalLockRule.java
+++ b/services/tests/wmtests/src/com/android/server/wm/WindowManagerGlobalLockRule.java
@@ -27,6 +27,9 @@ import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.Callable;
import java.util.concurrent.atomic.AtomicBoolean;
/**
@@ -59,34 +62,41 @@ class WindowManagerGlobalLockRule implements WindowTestRunner.MethodWrapper {
return base;
}
- void waitUntilHandlersIdle() {
- if (!mIsLocked) {
- mSystemServicesTestRule.waitUntilWindowManagerHandlersIdle();
- return;
- }
-
- waitForLocked(mSystemServicesTestRule::waitUntilWindowManagerHandlersIdle);
+ boolean runWithScissors(Handler handler, Runnable r, long timeout) {
+ return waitForLocked(() -> handler.runWithScissors(r, timeout));
}
- void runWithScissors(Handler handler, Runnable r, long timeout) {
- if (!mIsLocked) {
- handler.runWithScissors(r, timeout);
- return;
- }
-
- waitForLocked(() -> handler.runWithScissors(r, timeout));
+ void waitForLocked(Runnable r) {
+ waitForLocked(() -> {
+ r.run();
+ return null;
+ });
}
/**
* If the test holds the lock, we need to invoke {@link Object#wait} to release it so other
* threads won't be blocked when we are waiting.
*/
- private void waitForLocked(Runnable r) {
+ <T> T waitForLocked(Callable<T> callable) {
+ if (!mIsLocked) {
+ try {
+ return callable.call();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
final Object lock = mSystemServicesTestRule.getWindowManagerService().mGlobalLock;
final AtomicBoolean done = new AtomicBoolean(false);
+ final List<T> result = Arrays.asList((T) null);
+ final Exception[] exception = { null };
AsyncTask.SERIAL_EXECUTOR.execute(() -> {
- r.run();
+ try {
+ result.set(0, callable.call());
+ } catch (Exception e) {
+ exception[0] = e;
+ }
synchronized (lock) {
lock.notifyAll();
done.set(true);
@@ -101,6 +111,11 @@ class WindowManagerGlobalLockRule implements WindowTestRunner.MethodWrapper {
}
}
}
+ if (exception[0] != null) {
+ throw new RuntimeException(exception[0]);
+ }
+
+ return result.get(0);
}
/** Wraps methods annotated with {@link org.junit.Test}. */
diff --git a/services/tests/wmtests/src/com/android/server/wm/WindowProcessControllerTests.java b/services/tests/wmtests/src/com/android/server/wm/WindowProcessControllerTests.java
index 8c56ffaa6314..cc90ca1e2556 100644
--- a/services/tests/wmtests/src/com/android/server/wm/WindowProcessControllerTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/WindowProcessControllerTests.java
@@ -26,13 +26,13 @@ import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
import android.content.pm.ApplicationInfo;
import android.platform.test.annotations.Presubmit;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
import org.mockito.InOrder;
import org.mockito.Mockito;
@@ -43,6 +43,7 @@ import org.mockito.Mockito;
* atest WmTests:WindowProcessControllerTests
*/
@Presubmit
+@RunWith(WindowTestRunner.class)
public class WindowProcessControllerTests extends ActivityTestsBase {
WindowProcessController mWpc;
@@ -97,7 +98,7 @@ public class WindowProcessControllerTests extends ActivityTestsBase {
public void testSetRunningRecentsAnimation() {
mWpc.setRunningRecentsAnimation(true);
mWpc.setRunningRecentsAnimation(false);
- mService.mH.runWithScissors(() -> {}, 0);
+ waitHandlerIdle(mService.mH);
InOrder orderVerifier = Mockito.inOrder(mMockListener);
orderVerifier.verify(mMockListener).setRunningRemoteAnimation(eq(true));
@@ -108,7 +109,7 @@ public class WindowProcessControllerTests extends ActivityTestsBase {
public void testSetRunningRemoteAnimation() {
mWpc.setRunningRemoteAnimation(true);
mWpc.setRunningRemoteAnimation(false);
- mService.mH.runWithScissors(() -> {}, 0);
+ waitHandlerIdle(mService.mH);
InOrder orderVerifier = Mockito.inOrder(mMockListener);
orderVerifier.verify(mMockListener).setRunningRemoteAnimation(eq(true));
@@ -122,7 +123,7 @@ public class WindowProcessControllerTests extends ActivityTestsBase {
mWpc.setRunningRecentsAnimation(false);
mWpc.setRunningRemoteAnimation(false);
- mService.mH.runWithScissors(() -> {}, 0);
+ waitHandlerIdle(mService.mH);
InOrder orderVerifier = Mockito.inOrder(mMockListener);
orderVerifier.verify(mMockListener, times(3)).setRunningRemoteAnimation(eq(true));
diff --git a/services/tests/wmtests/src/com/android/server/wm/WindowTestsBase.java b/services/tests/wmtests/src/com/android/server/wm/WindowTestsBase.java
index 8930e5ac42f8..c574b0fd33b2 100644
--- a/services/tests/wmtests/src/com/android/server/wm/WindowTestsBase.java
+++ b/services/tests/wmtests/src/com/android/server/wm/WindowTestsBase.java
@@ -42,7 +42,6 @@ import static org.mockito.Mockito.mock;
import android.content.Context;
import android.content.res.Configuration;
-import android.testing.DexmakerShareClassLoaderRule;
import android.util.Log;
import android.view.Display;
import android.view.DisplayInfo;
@@ -55,7 +54,6 @@ 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;
@@ -65,7 +63,7 @@ import java.util.LinkedList;
*
* Make sure any requests to WM hold the WM lock if needed b/73966377
*/
-class WindowTestsBase {
+class WindowTestsBase extends SystemServiceTestsBase {
private static final String TAG = WindowTestsBase.class.getSimpleName();
WindowManagerService mWm;
@@ -92,16 +90,6 @@ class WindowTestsBase {
*/
Transaction mTransaction;
- @Rule
- public final DexmakerShareClassLoaderRule mDexmakerShareClassLoaderRule =
- new DexmakerShareClassLoaderRule();
- @Rule
- public final SystemServicesTestRule mSystemServicesTestRule = new SystemServicesTestRule();
-
- @WindowTestRunner.MethodWrapperRule
- public final WindowManagerGlobalLockRule mLockRule =
- new WindowManagerGlobalLockRule(mSystemServicesTestRule);
-
@BeforeClass
public static void setUpOnceBase() {
AttributeCache.init(getInstrumentation().getTargetContext());
@@ -205,13 +193,6 @@ class WindowTestsBase {
}
}
- /**
- * Waits until the main handler for WM has processed all messages.
- */
- void waitUntilHandlersIdle() {
- mLockRule.waitUntilHandlersIdle();
- }
-
private WindowToken createWindowToken(
DisplayContent dc, int windowingMode, int activityType, int type) {
synchronized (mWm.mGlobalLock) {
diff --git a/services/tests/wmtests/src/com/android/server/wm/ZOrderingTests.java b/services/tests/wmtests/src/com/android/server/wm/ZOrderingTests.java
index 2105ab003e0e..63b50b5a9b2b 100644
--- a/services/tests/wmtests/src/com/android/server/wm/ZOrderingTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/ZOrderingTests.java
@@ -47,6 +47,7 @@ import androidx.test.filters.SmallTest;
import org.junit.After;
import org.junit.Test;
+import org.junit.runner.RunWith;
import java.util.ArrayList;
import java.util.HashMap;
@@ -61,6 +62,7 @@ import java.util.function.Function;
*/
@SmallTest
@Presubmit
+@RunWith(WindowTestRunner.class)
public class ZOrderingTests extends WindowTestsBase {
private static class LayerRecordingTransaction extends SurfaceControl.Transaction {