blob: 4ee1f47d02e06976b03033711d2b85636f870336 [file] [log] [blame]
Bryce Lee840c5662017-04-13 10:02:51 -07001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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
15 */
16
17package com.android.server.am;
18
Wale Ogunwale04a05ac2017-09-17 21:35:02 -070019import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD;
20import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
21import static com.android.server.am.ActivityStack.REMOVE_TASK_MODE_DESTROYING;
Bryce Lee5daa3122017-04-19 10:40:42 -070022import static org.junit.Assert.assertEquals;
David Stevens18abd0e2017-08-17 14:55:47 -070023import static org.junit.Assert.assertFalse;
Bryce Lee840c5662017-04-13 10:02:51 -070024import static org.junit.Assert.assertNotNull;
25import static org.junit.Assert.assertNull;
26
27import android.content.ComponentName;
Bryce Lee3345c4e2017-04-25 07:40:41 -070028import android.content.pm.ActivityInfo;
Bryce Lee9f6affd2017-09-01 09:18:35 -070029import android.os.UserHandle;
Bryce Lee840c5662017-04-13 10:02:51 -070030import android.platform.test.annotations.Presubmit;
31import android.support.test.filters.SmallTest;
32import android.support.test.runner.AndroidJUnit4;
33
34import org.junit.runner.RunWith;
Wale Ogunwale04a05ac2017-09-17 21:35:02 -070035import org.junit.Before;
Bryce Lee840c5662017-04-13 10:02:51 -070036import org.junit.Test;
37
38/**
39 * Tests for the {@link ActivityStack} class.
40 *
41 * Build/Install/Run:
42 * bit FrameworksServicesTests:com.android.server.am.ActivityStackTests
43 */
44@SmallTest
45@Presubmit
46@RunWith(AndroidJUnit4.class)
47public class ActivityStackTests extends ActivityTestsBase {
Bryce Lee04ab3462017-04-10 15:06:33 -070048 private static final int TEST_STACK_ID = 100;
49 private static final ComponentName testActivityComponent =
Bryce Lee840c5662017-04-13 10:02:51 -070050 ComponentName.unflattenFromString("com.foo/.BarActivity");
Bryce Lee9f6affd2017-09-01 09:18:35 -070051 private static final ComponentName testOverlayComponent =
52 ComponentName.unflattenFromString("com.foo/.OverlayActivity");
Bryce Lee840c5662017-04-13 10:02:51 -070053
Wale Ogunwale04a05ac2017-09-17 21:35:02 -070054 private ActivityManagerService mService;
55 private ActivityStackSupervisor mSupervisor;
56 private ActivityStack mStack;
57 private TaskRecord mTask;
58
59 @Before
60 @Override
61 public void setUp() throws Exception {
62 super.setUp();
63
64 mService = createActivityManagerService();
65 mSupervisor = mService.mStackSupervisor;
66 mStack = mService.mStackSupervisor.getDefaultDisplay().createStack(
67 WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */);
68 mTask = createTask(mSupervisor, testActivityComponent, mStack);
69 }
70
Bryce Lee840c5662017-04-13 10:02:51 -070071 @Test
72 public void testEmptyTaskCleanupOnRemove() throws Exception {
Wale Ogunwale04a05ac2017-09-17 21:35:02 -070073 assertNotNull(mTask.getWindowContainerController());
74 mStack.removeTask(mTask, "testEmptyTaskCleanupOnRemove", REMOVE_TASK_MODE_DESTROYING);
75 assertNull(mTask.getWindowContainerController());
Bryce Lee840c5662017-04-13 10:02:51 -070076 }
Bryce Lee5daa3122017-04-19 10:40:42 -070077
Bryce Lee840c5662017-04-13 10:02:51 -070078 @Test
79 public void testOccupiedTaskCleanupOnRemove() throws Exception {
Wale Ogunwale04a05ac2017-09-17 21:35:02 -070080 final ActivityRecord r = createActivity(mService, testActivityComponent, mTask);
81 assertNotNull(mTask.getWindowContainerController());
82 mStack.removeTask(mTask, "testOccupiedTaskCleanupOnRemove", REMOVE_TASK_MODE_DESTROYING);
83 assertNotNull(mTask.getWindowContainerController());
Bryce Lee840c5662017-04-13 10:02:51 -070084 }
Bryce Lee5daa3122017-04-19 10:40:42 -070085
86 @Test
87 public void testNoPauseDuringResumeTopActivity() throws Exception {
Wale Ogunwale04a05ac2017-09-17 21:35:02 -070088 final ActivityRecord r = createActivity(mService, testActivityComponent, mTask);
Bryce Lee5daa3122017-04-19 10:40:42 -070089
90 // Simulate the a resumed activity set during
91 // {@link ActivityStack#resumeTopActivityUncheckedLocked}.
Wale Ogunwale04a05ac2017-09-17 21:35:02 -070092 mSupervisor.inResumeTopActivity = true;
93 mStack.mResumedActivity = r;
Bryce Lee5daa3122017-04-19 10:40:42 -070094
Wale Ogunwale04a05ac2017-09-17 21:35:02 -070095 final boolean waiting = mStack.goToSleepIfPossible(false);
Bryce Lee5daa3122017-04-19 10:40:42 -070096
97 // Ensure we report not being ready for sleep.
David Stevens18abd0e2017-08-17 14:55:47 -070098 assertFalse(waiting);
Bryce Lee5daa3122017-04-19 10:40:42 -070099
100 // Make sure the resumed activity is untouched.
Wale Ogunwale04a05ac2017-09-17 21:35:02 -0700101 assertEquals(mStack.mResumedActivity, r);
Bryce Lee5daa3122017-04-19 10:40:42 -0700102 }
Bryce Lee3345c4e2017-04-25 07:40:41 -0700103
104 @Test
105 public void testStopActivityWhenActivityDestroyed() throws Exception {
Wale Ogunwale04a05ac2017-09-17 21:35:02 -0700106 final ActivityRecord r = createActivity(mService, testActivityComponent, mTask);
107 r.info.flags |= ActivityInfo.FLAG_NO_HISTORY;
108 mSupervisor.setFocusStackUnchecked("testStopActivityWithDestroy", mStack);
109 mStack.stopActivityLocked(r);
110 // Mostly testing to make sure there is a crash in the call part, so if we get here we are
111 // good-to-go!
Bryce Lee3345c4e2017-04-25 07:40:41 -0700112 }
Bryce Lee9f6affd2017-09-01 09:18:35 -0700113
114 @Test
115 public void testFindTaskWithOverlay() throws Exception {
Wale Ogunwale04a05ac2017-09-17 21:35:02 -0700116 final ActivityRecord r = createActivity(mService, testActivityComponent, mTask, 0);
Bryce Lee9f6affd2017-09-01 09:18:35 -0700117 // Overlay must be for a different user to prevent recognizing a matching top activity
Wale Ogunwale04a05ac2017-09-17 21:35:02 -0700118 final ActivityRecord taskOverlay = createActivity(mService, testOverlayComponent, mTask,
Bryce Lee9f6affd2017-09-01 09:18:35 -0700119 UserHandle.PER_USER_RANGE * 2);
120 taskOverlay.mTaskOverlay = true;
121
Bryce Lee9f6affd2017-09-01 09:18:35 -0700122 final ActivityStackSupervisor.FindTaskResult result =
123 new ActivityStackSupervisor.FindTaskResult();
Wale Ogunwale04a05ac2017-09-17 21:35:02 -0700124 mStack.findTaskLocked(r, result);
Bryce Lee9f6affd2017-09-01 09:18:35 -0700125
Wale Ogunwale04a05ac2017-09-17 21:35:02 -0700126 assertEquals(mTask.getTopActivity(false /* includeOverlays */), r);
127 assertEquals(mTask.getTopActivity(true /* includeOverlays */), taskOverlay);
Bryce Lee9f6affd2017-09-01 09:18:35 -0700128 assertNotNull(result.r);
129 }
Bryce Lee840c5662017-04-13 10:02:51 -0700130}