Don't mock out TaskRecord & ActivityStack during test (56/n)
Use TaskBuilder and StackBuilder to create objects needed for tests so we are not mocking out TaskRecord and ActivityStack when we create Task and TaskStack for tests. Bug: 80414790 Test: Existing tests pass Change-Id: I537d765576859ecfdd0152e95e4d9261d74fd624
This commit is contained in:
@@ -60,11 +60,9 @@ public class AppChangeTransitionTests extends WindowTestsBase {
|
||||
private ActivityRecord mActivity;
|
||||
|
||||
public void setUpOnDisplay(DisplayContent dc) {
|
||||
mStack = createTaskStackOnDisplay(WINDOWING_MODE_UNDEFINED, ACTIVITY_TYPE_STANDARD, dc);
|
||||
mTask = createTaskInStack(mStack, 0 /* userId */);
|
||||
mActivity = WindowTestUtils.createTestActivityRecord(dc);
|
||||
|
||||
mTask.addChild(mActivity, 0);
|
||||
mActivity = createTestActivityRecord(dc, WINDOWING_MODE_UNDEFINED, ACTIVITY_TYPE_STANDARD);
|
||||
mTask = mActivity.getTask();
|
||||
mStack = mTask.mStack;
|
||||
|
||||
// Set a remote animator with snapshot disabled. Snapshots don't work in wmtests.
|
||||
RemoteAnimationDefinition definition = new RemoteAnimationDefinition();
|
||||
@@ -167,7 +165,7 @@ public class AppChangeTransitionTests extends WindowTestsBase {
|
||||
// setup currently defaults to no snapshot.
|
||||
setUpOnDisplay(mDisplayContent);
|
||||
|
||||
mTask.setWindowingMode(WINDOWING_MODE_FREEFORM);
|
||||
mTask.mTaskRecord.setWindowingMode(WINDOWING_MODE_FREEFORM);
|
||||
assertEquals(1, mDisplayContent.mChangingApps.size());
|
||||
assertTrue(mActivity.isInChangeTransition());
|
||||
|
||||
|
||||
@@ -21,12 +21,15 @@ import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
|
||||
|
||||
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
|
||||
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;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
|
||||
import android.graphics.Rect;
|
||||
import android.platform.test.annotations.Presubmit;
|
||||
@@ -119,7 +122,7 @@ public class TaskStackTests extends WindowTestsBase {
|
||||
@Test
|
||||
public void testRemoveContainer() {
|
||||
final TaskStack stack = createTaskStackOnDisplay(mDisplayContent);
|
||||
final WindowTestUtils.TestTask task = WindowTestUtils.createTestTask(stack);
|
||||
final Task task = createTaskInStack(stack, 0 /* userId */);
|
||||
|
||||
assertNotNull(stack);
|
||||
assertNotNull(task);
|
||||
@@ -135,10 +138,10 @@ public class TaskStackTests extends WindowTestsBase {
|
||||
@Test
|
||||
public void testRemoveContainer_deferRemoval() {
|
||||
final TaskStack stack = createTaskStackOnDisplay(mDisplayContent);
|
||||
final WindowTestUtils.TestTask task = WindowTestUtils.createTestTask(stack);
|
||||
final Task task = createTaskInStack(stack, 0 /* userId */);
|
||||
|
||||
// Stack removal is deferred if one of its child is animating.
|
||||
task.setLocalIsAnimating(true);
|
||||
doReturn(true).when(task).isSelfAnimating();
|
||||
|
||||
stack.removeIfPossible();
|
||||
// For the case of deferred removal the task controller will still be connected to the its
|
||||
@@ -157,8 +160,7 @@ public class TaskStackTests extends WindowTestsBase {
|
||||
public void testReparent() {
|
||||
// Create first stack on primary display.
|
||||
final TaskStack stack1 = createTaskStackOnDisplay(mDisplayContent);
|
||||
final WindowTestUtils.TestTask task1 = WindowTestUtils.createTestTask(stack1);
|
||||
task1.mOnDisplayChangedCalled = false;
|
||||
final Task task1 = createTaskInStack(stack1, 0 /* userId */);
|
||||
|
||||
// Create second display and put second stack on it.
|
||||
final DisplayContent dc = createNewDisplay();
|
||||
@@ -170,7 +172,7 @@ public class TaskStackTests extends WindowTestsBase {
|
||||
final int stack1PositionInParent = stack1.getParent().mChildren.indexOf(stack1);
|
||||
final int stack2PositionInParent = stack1.getParent().mChildren.indexOf(stack2);
|
||||
assertEquals(stack1PositionInParent, stack2PositionInParent + 1);
|
||||
assertTrue(task1.mOnDisplayChangedCalled);
|
||||
verify(task1, times(1)).onDisplayChanged(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -16,11 +16,16 @@
|
||||
|
||||
package com.android.server.wm;
|
||||
|
||||
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
|
||||
import static com.android.dx.mockito.inline.extended.ExtendedMockito.times;
|
||||
import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
|
||||
import android.graphics.Point;
|
||||
import android.graphics.Rect;
|
||||
@@ -45,7 +50,7 @@ public class TaskTests extends WindowTestsBase {
|
||||
@Test
|
||||
public void testRemoveContainer() {
|
||||
final TaskStack stackController1 = createTaskStackOnDisplay(mDisplayContent);
|
||||
final WindowTestUtils.TestTask task = WindowTestUtils.createTestTask(stackController1);
|
||||
final Task task = createTaskInStack(stackController1, 0 /* userId */);
|
||||
final ActivityRecord activity =
|
||||
WindowTestUtils.createActivityRecordInTask(mDisplayContent, task);
|
||||
|
||||
@@ -59,11 +64,11 @@ public class TaskTests extends WindowTestsBase {
|
||||
@Test
|
||||
public void testRemoveContainer_deferRemoval() {
|
||||
final TaskStack stackController1 = createTaskStackOnDisplay(mDisplayContent);
|
||||
final WindowTestUtils.TestTask task = WindowTestUtils.createTestTask(stackController1);
|
||||
final Task task = createTaskInStack(stackController1, 0 /* userId */);
|
||||
final ActivityRecord activity =
|
||||
WindowTestUtils.createActivityRecordInTask(mDisplayContent, task);
|
||||
|
||||
task.mShouldDeferRemoval = true;
|
||||
doReturn(true).when(task).shouldDeferRemoval();
|
||||
|
||||
task.removeIfPossible();
|
||||
// For the case of deferred removal the task will still be connected to the its app token
|
||||
@@ -81,9 +86,9 @@ public class TaskTests extends WindowTestsBase {
|
||||
@Test
|
||||
public void testReparent() {
|
||||
final TaskStack stackController1 = createTaskStackOnDisplay(mDisplayContent);
|
||||
final WindowTestUtils.TestTask task = WindowTestUtils.createTestTask(stackController1);
|
||||
final Task task = createTaskInStack(stackController1, 0 /* userId */);
|
||||
final TaskStack stackController2 = createTaskStackOnDisplay(mDisplayContent);
|
||||
final WindowTestUtils.TestTask task2 = WindowTestUtils.createTestTask(stackController2);
|
||||
final Task task2 = createTaskInStack(stackController2, 0 /* userId */);
|
||||
|
||||
boolean gotException = false;
|
||||
try {
|
||||
@@ -104,34 +109,33 @@ public class TaskTests extends WindowTestsBase {
|
||||
|
||||
task.reparent(stackController2, 0, false/* moveParents */);
|
||||
assertEquals(stackController2, task.getParent());
|
||||
assertEquals(0, task.positionInParent());
|
||||
assertEquals(1, task2.positionInParent());
|
||||
assertEquals(0, task.getParent().mChildren.indexOf(task));
|
||||
assertEquals(1, task2.getParent().mChildren.indexOf(task2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReparent_BetweenDisplays() {
|
||||
// Create first stack on primary display.
|
||||
final TaskStack stack1 = createTaskStackOnDisplay(mDisplayContent);
|
||||
final WindowTestUtils.TestTask task = WindowTestUtils.createTestTask(stack1);
|
||||
task.mOnDisplayChangedCalled = false;
|
||||
final Task task = createTaskInStack(stack1, 0 /* userId */);
|
||||
assertEquals(mDisplayContent, stack1.getDisplayContent());
|
||||
|
||||
// Create second display and put second stack on it.
|
||||
final DisplayContent dc = createNewDisplay();
|
||||
final TaskStack stack2 = createTaskStackOnDisplay(dc);
|
||||
final WindowTestUtils.TestTask task2 = WindowTestUtils.createTestTask(stack2);
|
||||
final Task task2 = createTaskInStack(stack2, 0 /* userId */);
|
||||
// Reparent and check state
|
||||
task.reparent(stack2, 0, false /* moveParents */);
|
||||
assertEquals(stack2, task.getParent());
|
||||
assertEquals(0, task.positionInParent());
|
||||
assertEquals(1, task2.positionInParent());
|
||||
assertTrue(task.mOnDisplayChangedCalled);
|
||||
assertEquals(0, task.getParent().mChildren.indexOf(task));
|
||||
assertEquals(1, task2.getParent().mChildren.indexOf(task2));
|
||||
verify(task, times(1)).onDisplayChanged(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBounds() {
|
||||
final TaskStack stack1 = createTaskStackOnDisplay(mDisplayContent);
|
||||
final WindowTestUtils.TestTask task = WindowTestUtils.createTestTask(stack1);
|
||||
final Task task = createTaskInStack(stack1, 0 /* userId */);
|
||||
|
||||
// Check that setting bounds also updates surface position
|
||||
Rect bounds = new Rect(10, 10, 100, 200);
|
||||
|
||||
@@ -16,24 +16,24 @@
|
||||
|
||||
package com.android.server.wm;
|
||||
|
||||
import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD;
|
||||
import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
|
||||
import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
|
||||
import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_SECONDARY;
|
||||
import static android.view.DisplayCutout.BOUNDS_POSITION_TOP;
|
||||
import static android.view.DisplayCutout.fromBoundingRect;
|
||||
import static android.view.WindowManager.LayoutParams.MATCH_PARENT;
|
||||
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
|
||||
|
||||
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 org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Rect;
|
||||
import android.platform.test.annotations.Presubmit;
|
||||
import android.view.DisplayInfo;
|
||||
import android.view.Gravity;
|
||||
import android.view.IWindow;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import androidx.test.filters.FlakyTest;
|
||||
@@ -57,29 +57,11 @@ import org.mockito.Mockito;
|
||||
@RunWith(WindowTestRunner.class)
|
||||
public class WindowFrameTests extends WindowTestsBase {
|
||||
|
||||
private final IWindow mIWindow = new TestIWindow();
|
||||
private final Rect mEmptyRect = new Rect();
|
||||
private DisplayContent mTestDisplayContent;
|
||||
|
||||
static class FrameTestWindowState extends WindowState {
|
||||
boolean mDockedResizingForTest = false;
|
||||
FrameTestWindowState(WindowManagerService wm, IWindow iWindow, WindowToken windowToken,
|
||||
WindowManager.LayoutParams attrs) {
|
||||
super(wm, mock(Session.class), iWindow, windowToken, null, 0, 0, attrs, 0, 0,
|
||||
false /* ownerCanAddInternalSystemWindow */);
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean isDockedResizing() {
|
||||
return mDockedResizingForTest;
|
||||
}
|
||||
}
|
||||
|
||||
TaskStack mStubStack;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
mStubStack = mock(TaskStack.class);
|
||||
DisplayInfo testDisplayInfo = new DisplayInfo(mDisplayInfo);
|
||||
testDisplayInfo.displayCutout = null;
|
||||
mTestDisplayContent = createNewDisplay(testDisplayInfo);
|
||||
@@ -129,8 +111,7 @@ public class WindowFrameTests extends WindowTestsBase {
|
||||
expectedRect.bottom);
|
||||
}
|
||||
|
||||
private void assertPolicyCrop(
|
||||
FrameTestWindowState w, int left, int top, int right, int bottom) {
|
||||
private void assertPolicyCrop(WindowState w, int left, int top, int right, int bottom) {
|
||||
Rect policyCrop = new Rect();
|
||||
w.calculatePolicyCrop(policyCrop);
|
||||
assertRect(policyCrop, left, top, right, bottom);
|
||||
@@ -139,7 +120,7 @@ public class WindowFrameTests extends WindowTestsBase {
|
||||
@Test
|
||||
public void testLayoutInFullscreenTaskInsets() {
|
||||
// fullscreen task doesn't use bounds for computeFrame
|
||||
WindowState w = createWindow(MATCH_PARENT, MATCH_PARENT);
|
||||
WindowState w = createWindow();
|
||||
w.mAttrs.gravity = Gravity.LEFT | Gravity.TOP;
|
||||
|
||||
final int bottomContentInset = 100;
|
||||
@@ -196,7 +177,7 @@ public class WindowFrameTests extends WindowTestsBase {
|
||||
@Test
|
||||
public void testLayoutInFullscreenTaskNoInsets() {
|
||||
// fullscreen task doesn't use bounds for computeFrame
|
||||
WindowState w = createWindow(MATCH_PARENT, MATCH_PARENT);
|
||||
WindowState w = createWindow();
|
||||
w.mAttrs.gravity = Gravity.LEFT | Gravity.TOP;
|
||||
|
||||
// With no insets or system decor all the frames incoming from PhoneWindowManager
|
||||
@@ -278,16 +259,16 @@ public class WindowFrameTests extends WindowTestsBase {
|
||||
final int logicalWidth = displayInfo.logicalWidth;
|
||||
final int logicalHeight = displayInfo.logicalHeight;
|
||||
|
||||
final int taskLeft = logicalWidth / 4;
|
||||
final int taskTop = logicalHeight / 4;
|
||||
final int taskRight = logicalWidth / 4 * 3;
|
||||
final int taskBottom = logicalHeight / 4 * 3;
|
||||
final Rect taskBounds = new Rect(taskLeft, taskTop, taskRight, taskBottom);
|
||||
WindowState w = createWindow(MATCH_PARENT, MATCH_PARENT);
|
||||
final Rect taskBounds = new Rect(
|
||||
logicalWidth / 4, logicalHeight / 4, logicalWidth / 4 * 3, logicalHeight / 4 * 3);
|
||||
WindowState w = createWindow();
|
||||
final Task task = w.getTask();
|
||||
// Use split-screen because it is non-fullscreen, but also not floating
|
||||
task.setWindowingMode(WINDOWING_MODE_SPLIT_SCREEN_SECONDARY);
|
||||
task.setBounds(taskBounds);
|
||||
task.mTaskRecord.setWindowingMode(WINDOWING_MODE_SPLIT_SCREEN_SECONDARY);
|
||||
task.mTaskRecord.setBounds(taskBounds);
|
||||
// The bounds we are requesting might be different from what the system resolved based on
|
||||
// other factors.
|
||||
final Rect resolvedTaskBounds = task.getBounds();
|
||||
w.mAttrs.gravity = Gravity.LEFT | Gravity.TOP;
|
||||
|
||||
final Rect pf = new Rect(0, 0, logicalWidth, logicalHeight);
|
||||
@@ -296,8 +277,8 @@ public class WindowFrameTests extends WindowTestsBase {
|
||||
w.computeFrameLw();
|
||||
// For non fullscreen tasks the containing frame is based off the
|
||||
// task bounds not the parent frame.
|
||||
assertFrame(w, taskLeft, taskTop, taskRight, taskBottom);
|
||||
assertContentFrame(w, taskBounds);
|
||||
assertEquals(resolvedTaskBounds, w.getFrameLw());
|
||||
assertContentFrame(w, resolvedTaskBounds);
|
||||
assertContentInset(w, 0, 0, 0, 0);
|
||||
|
||||
pf.set(0, 0, logicalWidth, logicalHeight);
|
||||
@@ -307,36 +288,38 @@ public class WindowFrameTests extends WindowTestsBase {
|
||||
final Rect cf = new Rect(0, 0, cfRight, cfBottom);
|
||||
windowFrames.setFrames(pf, pf, pf, cf, cf, pf, cf, mEmptyRect);
|
||||
w.computeFrameLw();
|
||||
assertFrame(w, taskLeft, taskTop, taskRight, taskBottom);
|
||||
int contentInsetRight = taskRight - cfRight;
|
||||
int contentInsetBottom = taskBottom - cfBottom;
|
||||
assertEquals(resolvedTaskBounds, w.getFrameLw());
|
||||
int contentInsetRight = resolvedTaskBounds.right - cfRight;
|
||||
int contentInsetBottom = resolvedTaskBounds.bottom - cfBottom;
|
||||
assertContentInset(w, 0, 0, contentInsetRight, contentInsetBottom);
|
||||
assertContentFrame(w, new Rect(taskLeft, taskTop, taskRight - contentInsetRight,
|
||||
taskBottom - contentInsetBottom));
|
||||
assertContentFrame(w, new Rect(resolvedTaskBounds.left, resolvedTaskBounds.top,
|
||||
resolvedTaskBounds.right - contentInsetRight,
|
||||
resolvedTaskBounds.bottom - contentInsetBottom));
|
||||
|
||||
pf.set(0, 0, logicalWidth, logicalHeight);
|
||||
// If we set displayed bounds, the insets will be computed with the main task bounds
|
||||
// but the frame will be positioned according to the displayed bounds.
|
||||
final int insetLeft = logicalWidth / 5;
|
||||
final int insetTop = logicalHeight / 5;
|
||||
final int insetRight = insetLeft + (taskRight - taskLeft);
|
||||
final int insetBottom = insetTop + (taskBottom - taskTop);
|
||||
task.setOverrideDisplayedBounds(taskBounds);
|
||||
task.setBounds(insetLeft, insetTop, insetRight, insetBottom);
|
||||
final int insetRight = insetLeft + (resolvedTaskBounds.right - resolvedTaskBounds.left);
|
||||
final int insetBottom = insetTop + (resolvedTaskBounds.bottom - resolvedTaskBounds.top);
|
||||
task.mTaskRecord.setDisplayedBounds(resolvedTaskBounds);
|
||||
task.mTaskRecord.setBounds(insetLeft, insetTop, insetRight, insetBottom);
|
||||
windowFrames.setFrames(pf, pf, pf, cf, cf, pf, cf, mEmptyRect);
|
||||
w.computeFrameLw();
|
||||
assertFrame(w, taskLeft, taskTop, taskRight, taskBottom);
|
||||
assertEquals(resolvedTaskBounds, w.getFrameLw());
|
||||
contentInsetRight = insetRight - cfRight;
|
||||
contentInsetBottom = insetBottom - cfBottom;
|
||||
assertContentInset(w, 0, 0, contentInsetRight, contentInsetBottom);
|
||||
assertContentFrame(w, new Rect(taskLeft, taskTop, taskRight - contentInsetRight,
|
||||
taskBottom - contentInsetBottom));
|
||||
assertContentFrame(w, new Rect(resolvedTaskBounds.left, resolvedTaskBounds.top,
|
||||
resolvedTaskBounds.right - contentInsetRight,
|
||||
resolvedTaskBounds.bottom - contentInsetBottom));
|
||||
}
|
||||
|
||||
@Test
|
||||
@FlakyTest(bugId = 130388666)
|
||||
public void testCalculatePolicyCrop() {
|
||||
final FrameTestWindowState w = createWindow(MATCH_PARENT, MATCH_PARENT);
|
||||
final WindowState w = createWindow();
|
||||
w.mAttrs.gravity = Gravity.LEFT | Gravity.TOP;
|
||||
|
||||
final DisplayInfo displayInfo = w.getDisplayContent().getDisplayInfo();
|
||||
@@ -381,7 +364,7 @@ public class WindowFrameTests extends WindowTestsBase {
|
||||
// to the computed window frame.
|
||||
assertPolicyCrop(w, 0, 0, logicalWidth / 2, logicalHeight / 2);
|
||||
|
||||
w.mDockedResizingForTest = true;
|
||||
doReturn(true).when(w).isDockedResizing();
|
||||
// But if we are docked resizing it won't be, however we will still be
|
||||
// shrunk to the decor frame and the display.
|
||||
assertPolicyCrop(w, 0, 0,
|
||||
@@ -402,7 +385,7 @@ public class WindowFrameTests extends WindowTestsBase {
|
||||
final int taskRight = logicalWidth / 4 * 3;
|
||||
final int taskBottom = logicalHeight / 4 * 3;
|
||||
final Rect taskBounds = new Rect(taskLeft, taskTop, taskRight, taskBottom);
|
||||
WindowState w = createWindow(MATCH_PARENT, MATCH_PARENT);
|
||||
WindowState w = createWindow();
|
||||
final Task task = w.getTask();
|
||||
// Use split-screen because it is non-fullscreen, but also not floating
|
||||
task.setWindowingMode(WINDOWING_MODE_SPLIT_SCREEN_SECONDARY);
|
||||
@@ -440,7 +423,7 @@ public class WindowFrameTests extends WindowTestsBase {
|
||||
@FlakyTest(bugId = 130388666)
|
||||
public void testDisplayCutout() {
|
||||
// Regular fullscreen task and window
|
||||
WindowState w = createWindow(MATCH_PARENT, MATCH_PARENT);
|
||||
WindowState w = createWindow();
|
||||
w.mAttrs.gravity = Gravity.LEFT | Gravity.TOP;
|
||||
|
||||
final Rect pf = new Rect(0, 0, 1000, 2000);
|
||||
@@ -464,7 +447,7 @@ public class WindowFrameTests extends WindowTestsBase {
|
||||
@FlakyTest(bugId = 130388666)
|
||||
public void testDisplayCutout_tempDisplayedBounds() {
|
||||
// Regular fullscreen task and window
|
||||
WindowState w = createWindow(MATCH_PARENT, MATCH_PARENT);
|
||||
WindowState w = createWindow();
|
||||
final Task task = w.getTask();
|
||||
task.setBounds(new Rect(0, 0, 1000, 2000));
|
||||
task.setOverrideDisplayedBounds(new Rect(0, -500, 1000, 1500));
|
||||
@@ -489,11 +472,12 @@ public class WindowFrameTests extends WindowTestsBase {
|
||||
|
||||
@Test
|
||||
public void testFreeformContentInsets() {
|
||||
removeGlobalMinSizeRestriction();
|
||||
// fullscreen task doesn't use bounds for computeFrame
|
||||
WindowState w = createWindow(MATCH_PARENT, MATCH_PARENT);
|
||||
WindowState w = createWindow();
|
||||
final Task task = w.getTask();
|
||||
w.mAttrs.gravity = Gravity.LEFT | Gravity.TOP;
|
||||
task.setWindowingMode(WINDOWING_MODE_FREEFORM);
|
||||
task.mTaskRecord.setWindowingMode(WINDOWING_MODE_FREEFORM);
|
||||
|
||||
DisplayContent dc = mTestDisplayContent;
|
||||
dc.mInputMethodTarget = w;
|
||||
@@ -515,7 +499,7 @@ public class WindowFrameTests extends WindowTestsBase {
|
||||
// First check that it only gets moved up enough to show window.
|
||||
final Rect winRect = new Rect(200, 200, 300, 500);
|
||||
|
||||
task.setBounds(winRect);
|
||||
task.mTaskRecord.setBounds(winRect);
|
||||
w.getWindowFrames().setFrames(pf, df, of, cf, vf, dcf, sf, mEmptyRect);
|
||||
w.computeFrameLw();
|
||||
|
||||
@@ -527,7 +511,7 @@ public class WindowFrameTests extends WindowTestsBase {
|
||||
|
||||
// Now check that it won't get moved beyond the top and then has appropriate insets
|
||||
winRect.bottom = 600;
|
||||
task.setBounds(winRect);
|
||||
task.mTaskRecord.setBounds(winRect);
|
||||
w.setBounds(winRect);
|
||||
w.getWindowFrames().setFrames(pf, df, of, cf, vf, dcf, sf, mEmptyRect);
|
||||
w.computeFrameLw();
|
||||
@@ -544,16 +528,9 @@ public class WindowFrameTests extends WindowTestsBase {
|
||||
assertEquals(winRect, w.getFrameLw());
|
||||
}
|
||||
|
||||
private FrameTestWindowState createWindow(int width, int height) {
|
||||
final WindowManager.LayoutParams attrs = new WindowManager.LayoutParams(TYPE_APPLICATION);
|
||||
attrs.width = width;
|
||||
attrs.height = height;
|
||||
|
||||
ActivityRecord activity = createActivityRecord(mTestDisplayContent,
|
||||
WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD);
|
||||
|
||||
FrameTestWindowState ws = new FrameTestWindowState(mWm, mIWindow, activity, attrs);
|
||||
activity.addWindow(ws);
|
||||
private WindowState createWindow() {
|
||||
final WindowState ws = createWindow(null, TYPE_APPLICATION, mTestDisplayContent, "WindowFrameTests");
|
||||
spyOn(ws);
|
||||
return ws;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,16 +33,16 @@ import com.android.server.wm.ActivityTestsBase.ActivityBuilder;
|
||||
* A collection of static functions that provide access to WindowManager related test functionality.
|
||||
*/
|
||||
class WindowTestUtils {
|
||||
private static int sNextTaskId = 0;
|
||||
|
||||
/** Creates a {@link Task} and adds it to the specified {@link TaskStack}. */
|
||||
static Task createTaskInStack(WindowManagerService service, TaskStack stack,
|
||||
int userId) {
|
||||
static Task createTaskInStack(WindowManagerService service, TaskStack stack, int userId) {
|
||||
synchronized (service.mGlobalLock) {
|
||||
final Task newTask = new Task(sNextTaskId++, stack, userId, service, 0, false,
|
||||
new ActivityManager.TaskDescription(), null);
|
||||
stack.addTask(newTask, POSITION_TOP);
|
||||
return newTask;
|
||||
final TaskRecord task = new ActivityTestsBase.TaskBuilder(
|
||||
stack.mActivityStack.mStackSupervisor)
|
||||
.setUserId(userId)
|
||||
.setStack(stack.mActivityStack)
|
||||
.build();
|
||||
return task.mTask;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,17 +53,33 @@ class WindowTestUtils {
|
||||
return activity;
|
||||
}
|
||||
|
||||
static ActivityRecord createTestActivityRecord(ActivityStack stack) {
|
||||
synchronized (stack.mService.mGlobalLock) {
|
||||
final ActivityRecord activity = new ActivityTestsBase.ActivityBuilder(
|
||||
stack.mService)
|
||||
.setStack(stack)
|
||||
.setCreateTask(true)
|
||||
.build();
|
||||
postCreateActivitySetup(activity, stack.mTaskStack.getDisplayContent());
|
||||
return activity;
|
||||
}
|
||||
}
|
||||
|
||||
static ActivityRecord createTestActivityRecord(DisplayContent dc) {
|
||||
synchronized (dc.mWmService.mGlobalLock) {
|
||||
final ActivityRecord activity = new ActivityBuilder(dc.mWmService.mAtmService).build();
|
||||
activity.onDisplayChanged(dc);
|
||||
activity.setOccludesParent(true);
|
||||
activity.setHidden(false);
|
||||
activity.hiddenRequested = false;
|
||||
postCreateActivitySetup(activity, dc);
|
||||
return activity;
|
||||
}
|
||||
}
|
||||
|
||||
private static void postCreateActivitySetup(ActivityRecord activity, DisplayContent dc) {
|
||||
activity.onDisplayChanged(dc);
|
||||
activity.setOccludesParent(true);
|
||||
activity.setHidden(false);
|
||||
activity.hiddenRequested = false;
|
||||
}
|
||||
|
||||
static TestWindowToken createTestWindowToken(int type, DisplayContent dc) {
|
||||
return createTestWindowToken(type, dc, false /* persistOnEmpty */);
|
||||
}
|
||||
@@ -92,49 +108,6 @@ class WindowTestUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/* Used so we can gain access to some protected members of the {@link Task} class */
|
||||
static class TestTask extends Task {
|
||||
boolean mShouldDeferRemoval = false;
|
||||
boolean mOnDisplayChangedCalled = false;
|
||||
private boolean mIsAnimating = false;
|
||||
|
||||
TestTask(int taskId, TaskStack stack, int userId, WindowManagerService service,
|
||||
int resizeMode, boolean supportsPictureInPicture,
|
||||
TaskRecord taskRecord) {
|
||||
super(taskId, stack, userId, service, resizeMode, supportsPictureInPicture,
|
||||
new ActivityManager.TaskDescription(), taskRecord);
|
||||
stack.addTask(this, POSITION_TOP);
|
||||
}
|
||||
|
||||
boolean shouldDeferRemoval() {
|
||||
return mShouldDeferRemoval;
|
||||
}
|
||||
|
||||
int positionInParent() {
|
||||
return getParent().mChildren.indexOf(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
void onDisplayChanged(DisplayContent dc) {
|
||||
super.onDisplayChanged(dc);
|
||||
mOnDisplayChangedCalled = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean isSelfAnimating() {
|
||||
return mIsAnimating;
|
||||
}
|
||||
|
||||
void setLocalIsAnimating(boolean isAnimating) {
|
||||
mIsAnimating = isAnimating;
|
||||
}
|
||||
}
|
||||
|
||||
static TestTask createTestTask(TaskStack stack) {
|
||||
return new TestTask(sNextTaskId++, stack, 0, stack.mWmService, RESIZE_MODE_UNRESIZEABLE,
|
||||
false, mock(TaskRecord.class));
|
||||
}
|
||||
|
||||
/** Used to track resize reports. */
|
||||
static class TestWindowState extends WindowState {
|
||||
boolean mResizeReported;
|
||||
|
||||
@@ -211,11 +211,7 @@ class WindowTestsBase extends SystemServiceTestsBase {
|
||||
ActivityRecord createTestActivityRecord(DisplayContent dc, int
|
||||
windowingMode, int activityType) {
|
||||
final TaskStack stack = createTaskStackOnDisplay(windowingMode, activityType, dc);
|
||||
final Task task = createTaskInStack(stack, 0 /* userId */);
|
||||
final ActivityRecord activity =
|
||||
WindowTestUtils.createTestActivityRecord(dc);
|
||||
task.addChild(activity, 0);
|
||||
return activity;
|
||||
return WindowTestUtils.createTestActivityRecord(stack.mActivityStack);
|
||||
}
|
||||
|
||||
WindowState createWindow(WindowState parent, int type, String name) {
|
||||
@@ -327,14 +323,14 @@ class WindowTestsBase extends SystemServiceTestsBase {
|
||||
|
||||
TaskStack createTaskStackOnDisplay(int windowingMode, int activityType, DisplayContent dc) {
|
||||
synchronized (mWm.mGlobalLock) {
|
||||
final Configuration overrideConfig = new Configuration();
|
||||
overrideConfig.windowConfiguration.setWindowingMode(windowingMode);
|
||||
overrideConfig.windowConfiguration.setActivityType(activityType);
|
||||
final int stackId = ++sNextStackId;
|
||||
final TaskStack stack = new TaskStack(mWm, stackId, mock(ActivityStack.class));
|
||||
dc.setStackOnDisplay(stackId, true, stack);
|
||||
stack.onRequestedOverrideConfigurationChanged(overrideConfig);
|
||||
return stack;
|
||||
final ActivityStack stack = new ActivityTestsBase.StackBuilder(
|
||||
dc.mWmService.mAtmService.mRootActivityContainer)
|
||||
.setDisplay(dc.mActivityDisplay)
|
||||
.setWindowingMode(windowingMode)
|
||||
.setActivityType(activityType)
|
||||
.setCreateActivity(false)
|
||||
.build();
|
||||
return stack.mTaskStack;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -386,4 +382,9 @@ class WindowTestsBase extends SystemServiceTestsBase {
|
||||
displayInfo.ownerUid = SYSTEM_UID;
|
||||
return createNewDisplay(displayInfo);
|
||||
}
|
||||
|
||||
/** Sets the default minimum task size to 1 so that tests can use small task sizes */
|
||||
public void removeGlobalMinSizeRestriction() {
|
||||
mWm.mAtmService.mRootActivityContainer.mDefaultMinSizeOfResizeableTaskDp = 1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user