Loading services/tests/servicestests/src/com/android/server/am/ActivityRecordTests.java +6 −11 Original line number Diff line number Diff line Loading @@ -51,11 +51,6 @@ import org.junit.Test; @Presubmit @RunWith(AndroidJUnit4.class) public class ActivityRecordTests extends ActivityTestsBase { private final ComponentName testActivityComponent = ComponentName.unflattenFromString("com.foo/.BarActivity"); private final ComponentName secondaryActivityComponent = ComponentName.unflattenFromString("com.foo/.BarActivity2"); private ActivityManagerService mService; private TestActivityStack mStack; private TaskRecord mTask; Loading @@ -69,8 +64,8 @@ public class ActivityRecordTests extends ActivityTestsBase { mService = createActivityManagerService(); mStack = mService.mStackSupervisor.getDefaultDisplay().createStack( WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); mTask = createTask(mService.mStackSupervisor, testActivityComponent, mStack); mActivity = createActivity(mService, testActivityComponent, mTask); mTask = new TaskBuilder(mService.mStackSupervisor).setStack(mStack).build(); mActivity = new ActivityBuilder(mService).setTask(mTask).build(); } @Test Loading @@ -94,8 +89,8 @@ public class ActivityRecordTests extends ActivityTestsBase { @Test public void testNoCleanupMovingActivityInSameStack() throws Exception { final TaskRecord newTask = createTask(mService.mStackSupervisor, testActivityComponent, mStack); final TaskRecord newTask = new TaskBuilder(mService.mStackSupervisor).setStack(mStack) .build(); mActivity.reparent(newTask, 0, null /*reason*/); assertEquals(mStack.onActivityRemovedFromStackInvocationCount(), 0); } Loading Loading @@ -149,13 +144,13 @@ public class ActivityRecordTests extends ActivityTestsBase { mService.mSupportsMultiWindow = true; final TaskRecord task = taskPresent ? createTask(mService.mStackSupervisor, testActivityComponent, mStack) : null; ? new TaskBuilder(mService.mStackSupervisor).setStack(mStack).build() : null; if (task != null) { task.setResizeMode(taskResizeable ? RESIZE_MODE_RESIZEABLE : RESIZE_MODE_UNRESIZEABLE); } final ActivityRecord record = createActivity(mService, secondaryActivityComponent, task); final ActivityRecord record = new ActivityBuilder(mService).setTask(task).build(); record.info.resizeMode = activityResizeable ? RESIZE_MODE_RESIZEABLE : RESIZE_MODE_UNRESIZEABLE; Loading services/tests/servicestests/src/com/android/server/am/ActivityStackSupervisorTests.java +10 −16 Original line number Diff line number Diff line Loading @@ -51,9 +51,6 @@ import static com.android.server.am.ActivityStackSupervisor.MATCH_TASK_IN_STACKS @Presubmit @RunWith(AndroidJUnit4.class) public class ActivityStackSupervisorTests extends ActivityTestsBase { private final ComponentName testActivityComponent = ComponentName.unflattenFromString("com.foo/.BarActivity"); private ActivityManagerService mService; private ActivityStackSupervisor mSupervisor; private ActivityStack mFullscreenStack; Loading Loading @@ -87,15 +84,14 @@ public class ActivityStackSupervisorTests extends ActivityTestsBase { */ @Test public void testReplacingTaskInPinnedStack() throws Exception { final TaskRecord firstTask = createTask( mSupervisor, testActivityComponent, mFullscreenStack); final ActivityRecord firstActivity = createActivity(mService, testActivityComponent, firstTask); // Create a new task on the full screen stack final TaskRecord secondTask = createTask( mSupervisor, testActivityComponent, mFullscreenStack); final ActivityRecord secondActivity = createActivity(mService, testActivityComponent, secondTask); final ActivityRecord firstActivity = new ActivityBuilder(mService).setCreateTask(true) .setStack(mFullscreenStack).build(); final TaskRecord firstTask = firstActivity.getTask(); final ActivityRecord secondActivity = new ActivityBuilder(mService).setCreateTask(true) .setStack(mFullscreenStack).build(); final TaskRecord secondTask = secondActivity.getTask(); mSupervisor.setFocusStackUnchecked("testReplacingTaskInPinnedStack", mFullscreenStack); // Ensure full screen stack has both tasks. Loading Loading @@ -142,10 +138,8 @@ public class ActivityStackSupervisorTests extends ActivityTestsBase { */ @Test public void testStoppingActivityRemovedWhenResumed() throws Exception { final TaskRecord firstTask = createTask( mSupervisor, testActivityComponent, mFullscreenStack); final ActivityRecord firstActivity = createActivity(mService, testActivityComponent, firstTask); final ActivityRecord firstActivity = new ActivityBuilder(mService).setCreateTask(true) .setStack(mFullscreenStack).build(); mSupervisor.mStoppingActivities.add(firstActivity); firstActivity.completeResumeLocked(); Loading services/tests/servicestests/src/com/android/server/am/ActivityStackTests.java +18 −17 Original line number Diff line number Diff line Loading @@ -23,7 +23,9 @@ import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_SECONDARY; import static com.android.server.am.ActivityStack.REMOVE_TASK_MODE_DESTROYING; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; Loading Loading @@ -51,11 +53,6 @@ import org.junit.Test; @Presubmit @RunWith(AndroidJUnit4.class) public class ActivityStackTests extends ActivityTestsBase { private static final ComponentName testActivityComponent = ComponentName.unflattenFromString("com.foo/.BarActivity"); private static final ComponentName testOverlayComponent = ComponentName.unflattenFromString("com.foo/.OverlayActivity"); private ActivityManagerService mService; private ActivityStackSupervisor mSupervisor; private ActivityStack mStack; Loading @@ -70,7 +67,7 @@ public class ActivityStackTests extends ActivityTestsBase { mSupervisor = mService.mStackSupervisor; mStack = mService.mStackSupervisor.getDefaultDisplay().createStack( WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); mTask = createTask(mSupervisor, testActivityComponent, mStack); mTask = new TaskBuilder(mSupervisor).setStack(mStack).build(); } @Test Loading @@ -82,7 +79,7 @@ public class ActivityStackTests extends ActivityTestsBase { @Test public void testOccupiedTaskCleanupOnRemove() throws Exception { final ActivityRecord r = createActivity(mService, testActivityComponent, mTask); final ActivityRecord r = new ActivityBuilder(mService).setTask(mTask).build(); assertNotNull(mTask.getWindowContainerController()); mStack.removeTask(mTask, "testOccupiedTaskCleanupOnRemove", REMOVE_TASK_MODE_DESTROYING); assertNotNull(mTask.getWindowContainerController()); Loading @@ -90,7 +87,7 @@ public class ActivityStackTests extends ActivityTestsBase { @Test public void testNoPauseDuringResumeTopActivity() throws Exception { final ActivityRecord r = createActivity(mService, testActivityComponent, mTask); final ActivityRecord r = new ActivityBuilder(mService).setTask(mTask).build(); // Simulate the a resumed activity set during // {@link ActivityStack#resumeTopActivityUncheckedLocked}. Loading @@ -108,7 +105,7 @@ public class ActivityStackTests extends ActivityTestsBase { @Test public void testStopActivityWhenActivityDestroyed() throws Exception { final ActivityRecord r = createActivity(mService, testActivityComponent, mTask); final ActivityRecord r = new ActivityBuilder(mService).setTask(mTask).build(); r.info.flags |= ActivityInfo.FLAG_NO_HISTORY; mSupervisor.setFocusStackUnchecked("testStopActivityWithDestroy", mStack); mStack.stopActivityLocked(r); Loading @@ -118,18 +115,23 @@ public class ActivityStackTests extends ActivityTestsBase { @Test public void testFindTaskWithOverlay() throws Exception { final ActivityRecord r = createActivity(mService, testActivityComponent, mTask, 0); final ActivityRecord r = new ActivityBuilder(mService) .setCreateTask(true) .setStack(mStack) .setUid(0) .build(); final TaskRecord task = r.getTask(); // Overlay must be for a different user to prevent recognizing a matching top activity final ActivityRecord taskOverlay = createActivity(mService, testOverlayComponent, mTask, UserHandle.PER_USER_RANGE * 2); final ActivityRecord taskOverlay = new ActivityBuilder(mService).setTask(task) .setUid(UserHandle.PER_USER_RANGE * 2).build(); taskOverlay.mTaskOverlay = true; final ActivityStackSupervisor.FindTaskResult result = new ActivityStackSupervisor.FindTaskResult(); mStack.findTaskLocked(r, result); assertEquals(mTask.getTopActivity(false /* includeOverlays */), r); assertEquals(mTask.getTopActivity(true /* includeOverlays */), taskOverlay); assertEquals(task.getTopActivity(false /* includeOverlays */), r); assertEquals(task.getTopActivity(true /* includeOverlays */), taskOverlay); assertNotNull(result.r); } Loading Loading @@ -245,9 +247,8 @@ public class ActivityStackTests extends ActivityTestsBase { private <T extends ActivityStack> T createStackForShouldBeVisibleTest( ActivityDisplay display, int windowingMode, int activityType, boolean onTop) { final T stack = display.createStack(windowingMode, activityType, onTop); // Create a task and activity in the stack so that it has a top running activity. final TaskRecord task = createTask(mSupervisor, testActivityComponent, stack); final ActivityRecord r = createActivity(mService, testActivityComponent, task, 0); final ActivityRecord r = new ActivityBuilder(mService).setUid(0).setStack(stack) .setCreateTask(true).build(); return stack; } } services/tests/servicestests/src/com/android/server/am/ActivityStarterTests.java +8 −9 Original line number Diff line number Diff line Loading @@ -50,9 +50,6 @@ import static org.mockito.Mockito.times; @Presubmit @RunWith(AndroidJUnit4.class) public class ActivityStarterTests extends ActivityTestsBase { private static final ComponentName testActivityComponent = ComponentName.unflattenFromString("com.foo/.BarActivity"); private ActivityManagerService mService; private ActivityStarter mStarter; Loading @@ -66,9 +63,10 @@ public class ActivityStarterTests extends ActivityTestsBase { @Test public void testUpdateLaunchBounds() throws Exception { // When in a non-resizeable stack, the task bounds should be updated. final TaskRecord task = createTask(mService.mStackSupervisor, testActivityComponent, mService.mStackSupervisor.getDefaultDisplay().createStack( WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */)); final TaskRecord task = new TaskBuilder(mService.mStackSupervisor) .setStack(mService.mStackSupervisor.getDefaultDisplay().createStack( WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */)) .build(); final Rect bounds = new Rect(10, 10, 100, 100); mStarter.updateBounds(task, bounds); Loading @@ -76,9 +74,10 @@ public class ActivityStarterTests extends ActivityTestsBase { assertEquals(task.getStack().mBounds, null); // When in a resizeable stack, the stack bounds should be updated as well. final TaskRecord task2 = createTask(mService.mStackSupervisor, testActivityComponent, mService.mStackSupervisor.getDefaultDisplay().createStack( WINDOWING_MODE_PINNED, ACTIVITY_TYPE_STANDARD, true /* onTop */)); final TaskRecord task2 = new TaskBuilder(mService.mStackSupervisor) .setStack(mService.mStackSupervisor.getDefaultDisplay().createStack( WINDOWING_MODE_PINNED, ACTIVITY_TYPE_STANDARD, true /* onTop */)) .build(); assertTrue(task2.getStack() instanceof PinnedActivityStack); mStarter.updateBounds(task2, bounds); Loading services/tests/servicestests/src/com/android/server/am/ActivityTestsBase.java +145 −44 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package com.android.server.am; import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD; import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; import static android.view.Display.DEFAULT_DISPLAY; import static org.mockito.Mockito.mock; Loading Loading @@ -81,58 +83,157 @@ public class ActivityTestsBase { return service; } protected static ActivityRecord createActivity(ActivityManagerService service, ComponentName component, TaskRecord task) { return createActivity(service, component, task, 0 /* userId */); /** * Builder for creating new activities. */ protected static class ActivityBuilder { // An id appended to the end of the component name to make it unique private static int sCurrentActivityId = 0; // Default package name private static final String DEFAULT_PACKAGE = "com.foo"; // Default base activity name private static final String DEFAULT_BASE_ACTIVITY_NAME = ".BarActivity"; private final ActivityManagerService mService; private ComponentName mComponent; private TaskRecord mTaskRecord; private int mUid; private boolean mCreateTask; private ActivityStack mStack; ActivityBuilder(ActivityManagerService service) { mService = service; } ActivityBuilder setComponent(ComponentName component) { mComponent = component; return this; } ActivityBuilder setTask(TaskRecord task) { mTaskRecord = task; return this; } ActivityBuilder setStack(ActivityStack stack) { mStack = stack; return this; } ActivityBuilder setCreateTask(boolean createTask) { mCreateTask = createTask; return this; } ActivityBuilder setUid(int uid) { mUid = uid; return this; } ActivityRecord build() { if (mComponent == null) { final int id = sCurrentActivityId++; mComponent = ComponentName.createRelative(DEFAULT_PACKAGE, DEFAULT_BASE_ACTIVITY_NAME + id); } if (mCreateTask) { mTaskRecord = new TaskBuilder(mService.mStackSupervisor) .setComponent(mComponent) .setStack(mStack).build(); } protected static ActivityRecord createActivity(ActivityManagerService service, ComponentName component, TaskRecord task, int uid) { Intent intent = new Intent(); intent.setComponent(component); intent.setComponent(mComponent); final ActivityInfo aInfo = new ActivityInfo(); aInfo.applicationInfo = new ApplicationInfo(); aInfo.applicationInfo.packageName = component.getPackageName(); aInfo.applicationInfo.uid = uid; AttributeCache.init(service.mContext); final ActivityRecord activity = new ActivityRecord(service, null /* caller */, aInfo.applicationInfo.packageName = mComponent.getPackageName(); aInfo.applicationInfo.uid = mUid; AttributeCache.init(mService.mContext); final ActivityRecord activity = new ActivityRecord(mService, null /* caller */, 0 /* launchedFromPid */, 0, null, intent, null, aInfo /*aInfo*/, new Configuration(), null /* resultTo */, null /* resultWho */, 0 /* reqCode */, false /*componentSpecified*/, false /* rootVoiceInteraction */, service.mStackSupervisor, null /* options */, null /* sourceRecord */); mService.mStackSupervisor, null /* options */, null /* sourceRecord */); activity.mWindowContainerController = mock(AppWindowContainerController.class); if (task != null) { task.addActivityToTop(activity); if (mTaskRecord != null) { mTaskRecord.addActivityToTop(activity); } return activity; } } /** * Builder for creating new tasks. */ protected static class TaskBuilder { private final ActivityStackSupervisor mSupervisor; private ComponentName mComponent; private String mPackage; private int mFlags = 0; private int mTaskId = 0; protected static TaskRecord createTask(ActivityStackSupervisor supervisor, ComponentName component, ActivityStack stack) { return createTask(supervisor, component, 0 /* flags */, 0 /* taskId */, stack); private ActivityStack mStack; TaskBuilder(ActivityStackSupervisor supervisor) { mSupervisor = supervisor; } TaskBuilder setComponent(ComponentName component) { mComponent = component; return this; } TaskBuilder setPackage(String packageName) { mPackage = packageName; return this; } TaskBuilder setFlags(int flags) { mFlags = flags; return this; } TaskBuilder setTaskId(int taskId) { mTaskId = taskId; return this; } TaskBuilder setStack(ActivityStack stack) { mStack = stack; return this; } TaskRecord build() { if (mStack == null) { mStack = mSupervisor.getDefaultDisplay().createStack( WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); } protected static TaskRecord createTask(ActivityStackSupervisor supervisor, ComponentName component, int flags, int taskId, ActivityStack stack) { final ActivityInfo aInfo = new ActivityInfo(); aInfo.applicationInfo = new ApplicationInfo(); aInfo.applicationInfo.packageName = component.getPackageName(); aInfo.applicationInfo.packageName = mPackage; Intent intent = new Intent(); intent.setComponent(component); intent.setFlags(flags); intent.setComponent(mComponent); intent.setFlags(mFlags); final TaskRecord task = new TaskRecord(supervisor.mService, taskId, aInfo, final TaskRecord task = new TaskRecord(mSupervisor.mService, mTaskId, aInfo, intent /*intent*/, null /*_taskDescription*/); supervisor.setFocusStackUnchecked("test", stack); stack.addTask(task, true, "creating test task"); task.setStack(stack); mSupervisor.setFocusStackUnchecked("test", mStack); mStack.addTask(task, true, "creating test task"); task.setStack(mStack); task.setWindowContainerController(mock(TaskWindowContainerController.class)); return task; } } /** * An {@link ActivityManagerService} subclass which provides a test Loading Loading
services/tests/servicestests/src/com/android/server/am/ActivityRecordTests.java +6 −11 Original line number Diff line number Diff line Loading @@ -51,11 +51,6 @@ import org.junit.Test; @Presubmit @RunWith(AndroidJUnit4.class) public class ActivityRecordTests extends ActivityTestsBase { private final ComponentName testActivityComponent = ComponentName.unflattenFromString("com.foo/.BarActivity"); private final ComponentName secondaryActivityComponent = ComponentName.unflattenFromString("com.foo/.BarActivity2"); private ActivityManagerService mService; private TestActivityStack mStack; private TaskRecord mTask; Loading @@ -69,8 +64,8 @@ public class ActivityRecordTests extends ActivityTestsBase { mService = createActivityManagerService(); mStack = mService.mStackSupervisor.getDefaultDisplay().createStack( WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); mTask = createTask(mService.mStackSupervisor, testActivityComponent, mStack); mActivity = createActivity(mService, testActivityComponent, mTask); mTask = new TaskBuilder(mService.mStackSupervisor).setStack(mStack).build(); mActivity = new ActivityBuilder(mService).setTask(mTask).build(); } @Test Loading @@ -94,8 +89,8 @@ public class ActivityRecordTests extends ActivityTestsBase { @Test public void testNoCleanupMovingActivityInSameStack() throws Exception { final TaskRecord newTask = createTask(mService.mStackSupervisor, testActivityComponent, mStack); final TaskRecord newTask = new TaskBuilder(mService.mStackSupervisor).setStack(mStack) .build(); mActivity.reparent(newTask, 0, null /*reason*/); assertEquals(mStack.onActivityRemovedFromStackInvocationCount(), 0); } Loading Loading @@ -149,13 +144,13 @@ public class ActivityRecordTests extends ActivityTestsBase { mService.mSupportsMultiWindow = true; final TaskRecord task = taskPresent ? createTask(mService.mStackSupervisor, testActivityComponent, mStack) : null; ? new TaskBuilder(mService.mStackSupervisor).setStack(mStack).build() : null; if (task != null) { task.setResizeMode(taskResizeable ? RESIZE_MODE_RESIZEABLE : RESIZE_MODE_UNRESIZEABLE); } final ActivityRecord record = createActivity(mService, secondaryActivityComponent, task); final ActivityRecord record = new ActivityBuilder(mService).setTask(task).build(); record.info.resizeMode = activityResizeable ? RESIZE_MODE_RESIZEABLE : RESIZE_MODE_UNRESIZEABLE; Loading
services/tests/servicestests/src/com/android/server/am/ActivityStackSupervisorTests.java +10 −16 Original line number Diff line number Diff line Loading @@ -51,9 +51,6 @@ import static com.android.server.am.ActivityStackSupervisor.MATCH_TASK_IN_STACKS @Presubmit @RunWith(AndroidJUnit4.class) public class ActivityStackSupervisorTests extends ActivityTestsBase { private final ComponentName testActivityComponent = ComponentName.unflattenFromString("com.foo/.BarActivity"); private ActivityManagerService mService; private ActivityStackSupervisor mSupervisor; private ActivityStack mFullscreenStack; Loading Loading @@ -87,15 +84,14 @@ public class ActivityStackSupervisorTests extends ActivityTestsBase { */ @Test public void testReplacingTaskInPinnedStack() throws Exception { final TaskRecord firstTask = createTask( mSupervisor, testActivityComponent, mFullscreenStack); final ActivityRecord firstActivity = createActivity(mService, testActivityComponent, firstTask); // Create a new task on the full screen stack final TaskRecord secondTask = createTask( mSupervisor, testActivityComponent, mFullscreenStack); final ActivityRecord secondActivity = createActivity(mService, testActivityComponent, secondTask); final ActivityRecord firstActivity = new ActivityBuilder(mService).setCreateTask(true) .setStack(mFullscreenStack).build(); final TaskRecord firstTask = firstActivity.getTask(); final ActivityRecord secondActivity = new ActivityBuilder(mService).setCreateTask(true) .setStack(mFullscreenStack).build(); final TaskRecord secondTask = secondActivity.getTask(); mSupervisor.setFocusStackUnchecked("testReplacingTaskInPinnedStack", mFullscreenStack); // Ensure full screen stack has both tasks. Loading Loading @@ -142,10 +138,8 @@ public class ActivityStackSupervisorTests extends ActivityTestsBase { */ @Test public void testStoppingActivityRemovedWhenResumed() throws Exception { final TaskRecord firstTask = createTask( mSupervisor, testActivityComponent, mFullscreenStack); final ActivityRecord firstActivity = createActivity(mService, testActivityComponent, firstTask); final ActivityRecord firstActivity = new ActivityBuilder(mService).setCreateTask(true) .setStack(mFullscreenStack).build(); mSupervisor.mStoppingActivities.add(firstActivity); firstActivity.completeResumeLocked(); Loading
services/tests/servicestests/src/com/android/server/am/ActivityStackTests.java +18 −17 Original line number Diff line number Diff line Loading @@ -23,7 +23,9 @@ import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_SECONDARY; import static com.android.server.am.ActivityStack.REMOVE_TASK_MODE_DESTROYING; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; Loading Loading @@ -51,11 +53,6 @@ import org.junit.Test; @Presubmit @RunWith(AndroidJUnit4.class) public class ActivityStackTests extends ActivityTestsBase { private static final ComponentName testActivityComponent = ComponentName.unflattenFromString("com.foo/.BarActivity"); private static final ComponentName testOverlayComponent = ComponentName.unflattenFromString("com.foo/.OverlayActivity"); private ActivityManagerService mService; private ActivityStackSupervisor mSupervisor; private ActivityStack mStack; Loading @@ -70,7 +67,7 @@ public class ActivityStackTests extends ActivityTestsBase { mSupervisor = mService.mStackSupervisor; mStack = mService.mStackSupervisor.getDefaultDisplay().createStack( WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); mTask = createTask(mSupervisor, testActivityComponent, mStack); mTask = new TaskBuilder(mSupervisor).setStack(mStack).build(); } @Test Loading @@ -82,7 +79,7 @@ public class ActivityStackTests extends ActivityTestsBase { @Test public void testOccupiedTaskCleanupOnRemove() throws Exception { final ActivityRecord r = createActivity(mService, testActivityComponent, mTask); final ActivityRecord r = new ActivityBuilder(mService).setTask(mTask).build(); assertNotNull(mTask.getWindowContainerController()); mStack.removeTask(mTask, "testOccupiedTaskCleanupOnRemove", REMOVE_TASK_MODE_DESTROYING); assertNotNull(mTask.getWindowContainerController()); Loading @@ -90,7 +87,7 @@ public class ActivityStackTests extends ActivityTestsBase { @Test public void testNoPauseDuringResumeTopActivity() throws Exception { final ActivityRecord r = createActivity(mService, testActivityComponent, mTask); final ActivityRecord r = new ActivityBuilder(mService).setTask(mTask).build(); // Simulate the a resumed activity set during // {@link ActivityStack#resumeTopActivityUncheckedLocked}. Loading @@ -108,7 +105,7 @@ public class ActivityStackTests extends ActivityTestsBase { @Test public void testStopActivityWhenActivityDestroyed() throws Exception { final ActivityRecord r = createActivity(mService, testActivityComponent, mTask); final ActivityRecord r = new ActivityBuilder(mService).setTask(mTask).build(); r.info.flags |= ActivityInfo.FLAG_NO_HISTORY; mSupervisor.setFocusStackUnchecked("testStopActivityWithDestroy", mStack); mStack.stopActivityLocked(r); Loading @@ -118,18 +115,23 @@ public class ActivityStackTests extends ActivityTestsBase { @Test public void testFindTaskWithOverlay() throws Exception { final ActivityRecord r = createActivity(mService, testActivityComponent, mTask, 0); final ActivityRecord r = new ActivityBuilder(mService) .setCreateTask(true) .setStack(mStack) .setUid(0) .build(); final TaskRecord task = r.getTask(); // Overlay must be for a different user to prevent recognizing a matching top activity final ActivityRecord taskOverlay = createActivity(mService, testOverlayComponent, mTask, UserHandle.PER_USER_RANGE * 2); final ActivityRecord taskOverlay = new ActivityBuilder(mService).setTask(task) .setUid(UserHandle.PER_USER_RANGE * 2).build(); taskOverlay.mTaskOverlay = true; final ActivityStackSupervisor.FindTaskResult result = new ActivityStackSupervisor.FindTaskResult(); mStack.findTaskLocked(r, result); assertEquals(mTask.getTopActivity(false /* includeOverlays */), r); assertEquals(mTask.getTopActivity(true /* includeOverlays */), taskOverlay); assertEquals(task.getTopActivity(false /* includeOverlays */), r); assertEquals(task.getTopActivity(true /* includeOverlays */), taskOverlay); assertNotNull(result.r); } Loading Loading @@ -245,9 +247,8 @@ public class ActivityStackTests extends ActivityTestsBase { private <T extends ActivityStack> T createStackForShouldBeVisibleTest( ActivityDisplay display, int windowingMode, int activityType, boolean onTop) { final T stack = display.createStack(windowingMode, activityType, onTop); // Create a task and activity in the stack so that it has a top running activity. final TaskRecord task = createTask(mSupervisor, testActivityComponent, stack); final ActivityRecord r = createActivity(mService, testActivityComponent, task, 0); final ActivityRecord r = new ActivityBuilder(mService).setUid(0).setStack(stack) .setCreateTask(true).build(); return stack; } }
services/tests/servicestests/src/com/android/server/am/ActivityStarterTests.java +8 −9 Original line number Diff line number Diff line Loading @@ -50,9 +50,6 @@ import static org.mockito.Mockito.times; @Presubmit @RunWith(AndroidJUnit4.class) public class ActivityStarterTests extends ActivityTestsBase { private static final ComponentName testActivityComponent = ComponentName.unflattenFromString("com.foo/.BarActivity"); private ActivityManagerService mService; private ActivityStarter mStarter; Loading @@ -66,9 +63,10 @@ public class ActivityStarterTests extends ActivityTestsBase { @Test public void testUpdateLaunchBounds() throws Exception { // When in a non-resizeable stack, the task bounds should be updated. final TaskRecord task = createTask(mService.mStackSupervisor, testActivityComponent, mService.mStackSupervisor.getDefaultDisplay().createStack( WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */)); final TaskRecord task = new TaskBuilder(mService.mStackSupervisor) .setStack(mService.mStackSupervisor.getDefaultDisplay().createStack( WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */)) .build(); final Rect bounds = new Rect(10, 10, 100, 100); mStarter.updateBounds(task, bounds); Loading @@ -76,9 +74,10 @@ public class ActivityStarterTests extends ActivityTestsBase { assertEquals(task.getStack().mBounds, null); // When in a resizeable stack, the stack bounds should be updated as well. final TaskRecord task2 = createTask(mService.mStackSupervisor, testActivityComponent, mService.mStackSupervisor.getDefaultDisplay().createStack( WINDOWING_MODE_PINNED, ACTIVITY_TYPE_STANDARD, true /* onTop */)); final TaskRecord task2 = new TaskBuilder(mService.mStackSupervisor) .setStack(mService.mStackSupervisor.getDefaultDisplay().createStack( WINDOWING_MODE_PINNED, ACTIVITY_TYPE_STANDARD, true /* onTop */)) .build(); assertTrue(task2.getStack() instanceof PinnedActivityStack); mStarter.updateBounds(task2, bounds); Loading
services/tests/servicestests/src/com/android/server/am/ActivityTestsBase.java +145 −44 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package com.android.server.am; import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD; import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; import static android.view.Display.DEFAULT_DISPLAY; import static org.mockito.Mockito.mock; Loading Loading @@ -81,58 +83,157 @@ public class ActivityTestsBase { return service; } protected static ActivityRecord createActivity(ActivityManagerService service, ComponentName component, TaskRecord task) { return createActivity(service, component, task, 0 /* userId */); /** * Builder for creating new activities. */ protected static class ActivityBuilder { // An id appended to the end of the component name to make it unique private static int sCurrentActivityId = 0; // Default package name private static final String DEFAULT_PACKAGE = "com.foo"; // Default base activity name private static final String DEFAULT_BASE_ACTIVITY_NAME = ".BarActivity"; private final ActivityManagerService mService; private ComponentName mComponent; private TaskRecord mTaskRecord; private int mUid; private boolean mCreateTask; private ActivityStack mStack; ActivityBuilder(ActivityManagerService service) { mService = service; } ActivityBuilder setComponent(ComponentName component) { mComponent = component; return this; } ActivityBuilder setTask(TaskRecord task) { mTaskRecord = task; return this; } ActivityBuilder setStack(ActivityStack stack) { mStack = stack; return this; } ActivityBuilder setCreateTask(boolean createTask) { mCreateTask = createTask; return this; } ActivityBuilder setUid(int uid) { mUid = uid; return this; } ActivityRecord build() { if (mComponent == null) { final int id = sCurrentActivityId++; mComponent = ComponentName.createRelative(DEFAULT_PACKAGE, DEFAULT_BASE_ACTIVITY_NAME + id); } if (mCreateTask) { mTaskRecord = new TaskBuilder(mService.mStackSupervisor) .setComponent(mComponent) .setStack(mStack).build(); } protected static ActivityRecord createActivity(ActivityManagerService service, ComponentName component, TaskRecord task, int uid) { Intent intent = new Intent(); intent.setComponent(component); intent.setComponent(mComponent); final ActivityInfo aInfo = new ActivityInfo(); aInfo.applicationInfo = new ApplicationInfo(); aInfo.applicationInfo.packageName = component.getPackageName(); aInfo.applicationInfo.uid = uid; AttributeCache.init(service.mContext); final ActivityRecord activity = new ActivityRecord(service, null /* caller */, aInfo.applicationInfo.packageName = mComponent.getPackageName(); aInfo.applicationInfo.uid = mUid; AttributeCache.init(mService.mContext); final ActivityRecord activity = new ActivityRecord(mService, null /* caller */, 0 /* launchedFromPid */, 0, null, intent, null, aInfo /*aInfo*/, new Configuration(), null /* resultTo */, null /* resultWho */, 0 /* reqCode */, false /*componentSpecified*/, false /* rootVoiceInteraction */, service.mStackSupervisor, null /* options */, null /* sourceRecord */); mService.mStackSupervisor, null /* options */, null /* sourceRecord */); activity.mWindowContainerController = mock(AppWindowContainerController.class); if (task != null) { task.addActivityToTop(activity); if (mTaskRecord != null) { mTaskRecord.addActivityToTop(activity); } return activity; } } /** * Builder for creating new tasks. */ protected static class TaskBuilder { private final ActivityStackSupervisor mSupervisor; private ComponentName mComponent; private String mPackage; private int mFlags = 0; private int mTaskId = 0; protected static TaskRecord createTask(ActivityStackSupervisor supervisor, ComponentName component, ActivityStack stack) { return createTask(supervisor, component, 0 /* flags */, 0 /* taskId */, stack); private ActivityStack mStack; TaskBuilder(ActivityStackSupervisor supervisor) { mSupervisor = supervisor; } TaskBuilder setComponent(ComponentName component) { mComponent = component; return this; } TaskBuilder setPackage(String packageName) { mPackage = packageName; return this; } TaskBuilder setFlags(int flags) { mFlags = flags; return this; } TaskBuilder setTaskId(int taskId) { mTaskId = taskId; return this; } TaskBuilder setStack(ActivityStack stack) { mStack = stack; return this; } TaskRecord build() { if (mStack == null) { mStack = mSupervisor.getDefaultDisplay().createStack( WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); } protected static TaskRecord createTask(ActivityStackSupervisor supervisor, ComponentName component, int flags, int taskId, ActivityStack stack) { final ActivityInfo aInfo = new ActivityInfo(); aInfo.applicationInfo = new ApplicationInfo(); aInfo.applicationInfo.packageName = component.getPackageName(); aInfo.applicationInfo.packageName = mPackage; Intent intent = new Intent(); intent.setComponent(component); intent.setFlags(flags); intent.setComponent(mComponent); intent.setFlags(mFlags); final TaskRecord task = new TaskRecord(supervisor.mService, taskId, aInfo, final TaskRecord task = new TaskRecord(mSupervisor.mService, mTaskId, aInfo, intent /*intent*/, null /*_taskDescription*/); supervisor.setFocusStackUnchecked("test", stack); stack.addTask(task, true, "creating test task"); task.setStack(stack); mSupervisor.setFocusStackUnchecked("test", mStack); mStack.addTask(task, true, "creating test task"); task.setStack(mStack); task.setWindowContainerController(mock(TaskWindowContainerController.class)); return task; } } /** * An {@link ActivityManagerService} subclass which provides a test Loading