2 * Copyright (C) 2017 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
17 package com.android.server.am;
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertNotNull;
21 import static org.junit.Assert.assertNull;
22 import static org.junit.Assert.assertTrue;
24 import android.app.ActivityManager;
25 import android.content.ComponentName;
26 import android.content.pm.ActivityInfo;
27 import android.platform.test.annotations.Presubmit;
28 import android.support.test.filters.SmallTest;
29 import android.support.test.runner.AndroidJUnit4;
31 import org.junit.runner.RunWith;
32 import org.junit.Test;
35 * Tests for the {@link ActivityStack} class.
38 * bit FrameworksServicesTests:com.android.server.am.ActivityStackTests
42 @RunWith(AndroidJUnit4.class)
43 public class ActivityStackTests extends ActivityTestsBase {
44 private static final int TEST_STACK_ID = 100;
45 private static final ComponentName testActivityComponent =
46 ComponentName.unflattenFromString("com.foo/.BarActivity");
49 public void testEmptyTaskCleanupOnRemove() throws Exception {
50 final ActivityManagerService service = createActivityManagerService();
51 final TaskRecord task = createTask(service, testActivityComponent, TEST_STACK_ID);
52 assertNotNull(task.getWindowContainerController());
53 service.mStackSupervisor.getStack(TEST_STACK_ID).removeTask(task,
54 "testEmptyTaskCleanupOnRemove", ActivityStack.REMOVE_TASK_MODE_DESTROYING);
55 assertNull(task.getWindowContainerController());
59 public void testOccupiedTaskCleanupOnRemove() throws Exception {
60 final ActivityManagerService service = createActivityManagerService();
61 final TaskRecord task = createTask(service, testActivityComponent, TEST_STACK_ID);
62 final ActivityRecord activityRecord = createActivity(service, testActivityComponent, task);
63 assertNotNull(task.getWindowContainerController());
64 service.mStackSupervisor.getStack(TEST_STACK_ID).removeTask(task,
65 "testOccupiedTaskCleanupOnRemove", ActivityStack.REMOVE_TASK_MODE_DESTROYING);
66 assertNotNull(task.getWindowContainerController());
70 public void testNoPauseDuringResumeTopActivity() throws Exception {
71 final ActivityManagerService service = createActivityManagerService();
72 final TaskRecord task = createTask(service, testActivityComponent, TEST_STACK_ID);
73 final ActivityRecord activityRecord = createActivity(service, testActivityComponent, task);
74 final ActivityStack testStack = service.mStackSupervisor.getStack(TEST_STACK_ID);
76 // Simulate the a resumed activity set during
77 // {@link ActivityStack#resumeTopActivityUncheckedLocked}.
78 service.mStackSupervisor.inResumeTopActivity = true;
79 testStack.mResumedActivity = activityRecord;
81 final boolean waiting = testStack.checkReadyForSleepLocked();
83 // Ensure we report not being ready for sleep.
86 // Make sure the resumed activity is untouched.
87 assertEquals(testStack.mResumedActivity, activityRecord);
91 public void testStopActivityWhenActivityDestroyed() throws Exception {
92 final ActivityManagerService service = createActivityManagerService();
93 final TaskRecord task = createTask(service, testActivityComponent, TEST_STACK_ID);
94 final ActivityRecord activityRecord = createActivity(service, testActivityComponent, task);
95 activityRecord.info.flags |= ActivityInfo.FLAG_NO_HISTORY;
96 final ActivityStack testStack = service.mStackSupervisor.getStack(TEST_STACK_ID);
97 service.mStackSupervisor.setFocusStackUnchecked("testStopActivityWithDestroy", testStack);
99 testStack.stopActivityLocked(activityRecord);
103 * This test verifies that {@link ActivityStack#STACK_VISIBLE_ACTIVITY_BEHIND} is returned from
104 * {@link ActivityStack#shouldBeVisible(ActivityRecord)} from a fullscreen workspace stack with
105 * a visible behind activity when top focused stack is the home stack.
108 public void testShouldBeVisibleWithVisibleBehindActivity() throws Exception {
109 final ActivityManagerService service = createActivityManagerService();
110 final TaskRecord task = createTask(service, testActivityComponent,
111 ActivityManager.StackId.FULLSCREEN_WORKSPACE_STACK_ID);
112 final ActivityStack fullscreenWorkspaceStackId = task.getStack();
113 final ActivityStack homeStack = service.mStackSupervisor.getStack(
114 ActivityManager.StackId.HOME_STACK_ID, true /*createStaticStackIfNeeded*/,
116 final ActivityRecord activityRecord = createActivity(service, testActivityComponent, task);
117 service.mStackSupervisor.setFocusStackUnchecked("testEmptyStackShouldBeVisible", homeStack);
118 service.mStackSupervisor.requestVisibleBehindLocked(activityRecord, true);
119 assertEquals(ActivityStack.STACK_VISIBLE_ACTIVITY_BEHIND,
120 fullscreenWorkspaceStackId.shouldBeVisible(null /*starting*/));