Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.server.am; |
| 18 | |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame^] | 19 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_ASSISTANT; |
| 20 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME; |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 21 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD; |
| 22 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame^] | 23 | import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; |
| 24 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; |
| 25 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_SECONDARY; |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 26 | import static com.android.server.am.ActivityStack.REMOVE_TASK_MODE_DESTROYING; |
Bryce Lee | 5daa312 | 2017-04-19 10:40:42 -0700 | [diff] [blame] | 27 | import static org.junit.Assert.assertEquals; |
David Stevens | 18abd0e | 2017-08-17 14:55:47 -0700 | [diff] [blame] | 28 | import static org.junit.Assert.assertFalse; |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 29 | import static org.junit.Assert.assertNotNull; |
| 30 | import static org.junit.Assert.assertNull; |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame^] | 31 | import static org.junit.Assert.assertTrue; |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 32 | |
| 33 | import android.content.ComponentName; |
Bryce Lee | 3345c4e | 2017-04-25 07:40:41 -0700 | [diff] [blame] | 34 | import android.content.pm.ActivityInfo; |
Bryce Lee | 9f6affd | 2017-09-01 09:18:35 -0700 | [diff] [blame] | 35 | import android.os.UserHandle; |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 36 | import android.platform.test.annotations.Presubmit; |
| 37 | import android.support.test.filters.SmallTest; |
| 38 | import android.support.test.runner.AndroidJUnit4; |
| 39 | |
| 40 | import org.junit.runner.RunWith; |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 41 | import org.junit.Before; |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 42 | import org.junit.Test; |
| 43 | |
| 44 | /** |
| 45 | * Tests for the {@link ActivityStack} class. |
| 46 | * |
| 47 | * Build/Install/Run: |
| 48 | * bit FrameworksServicesTests:com.android.server.am.ActivityStackTests |
| 49 | */ |
| 50 | @SmallTest |
| 51 | @Presubmit |
| 52 | @RunWith(AndroidJUnit4.class) |
| 53 | public class ActivityStackTests extends ActivityTestsBase { |
Bryce Lee | 04ab346 | 2017-04-10 15:06:33 -0700 | [diff] [blame] | 54 | private static final ComponentName testActivityComponent = |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 55 | ComponentName.unflattenFromString("com.foo/.BarActivity"); |
Bryce Lee | 9f6affd | 2017-09-01 09:18:35 -0700 | [diff] [blame] | 56 | private static final ComponentName testOverlayComponent = |
| 57 | ComponentName.unflattenFromString("com.foo/.OverlayActivity"); |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 58 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 59 | private ActivityManagerService mService; |
| 60 | private ActivityStackSupervisor mSupervisor; |
| 61 | private ActivityStack mStack; |
| 62 | private TaskRecord mTask; |
| 63 | |
| 64 | @Before |
| 65 | @Override |
| 66 | public void setUp() throws Exception { |
| 67 | super.setUp(); |
| 68 | |
| 69 | mService = createActivityManagerService(); |
| 70 | mSupervisor = mService.mStackSupervisor; |
| 71 | mStack = mService.mStackSupervisor.getDefaultDisplay().createStack( |
| 72 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 73 | mTask = createTask(mSupervisor, testActivityComponent, mStack); |
| 74 | } |
| 75 | |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 76 | @Test |
| 77 | public void testEmptyTaskCleanupOnRemove() throws Exception { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 78 | assertNotNull(mTask.getWindowContainerController()); |
| 79 | mStack.removeTask(mTask, "testEmptyTaskCleanupOnRemove", REMOVE_TASK_MODE_DESTROYING); |
| 80 | assertNull(mTask.getWindowContainerController()); |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 81 | } |
Bryce Lee | 5daa312 | 2017-04-19 10:40:42 -0700 | [diff] [blame] | 82 | |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 83 | @Test |
| 84 | public void testOccupiedTaskCleanupOnRemove() throws Exception { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 85 | final ActivityRecord r = createActivity(mService, testActivityComponent, mTask); |
| 86 | assertNotNull(mTask.getWindowContainerController()); |
| 87 | mStack.removeTask(mTask, "testOccupiedTaskCleanupOnRemove", REMOVE_TASK_MODE_DESTROYING); |
| 88 | assertNotNull(mTask.getWindowContainerController()); |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 89 | } |
Bryce Lee | 5daa312 | 2017-04-19 10:40:42 -0700 | [diff] [blame] | 90 | |
| 91 | @Test |
| 92 | public void testNoPauseDuringResumeTopActivity() throws Exception { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 93 | final ActivityRecord r = createActivity(mService, testActivityComponent, mTask); |
Bryce Lee | 5daa312 | 2017-04-19 10:40:42 -0700 | [diff] [blame] | 94 | |
| 95 | // Simulate the a resumed activity set during |
| 96 | // {@link ActivityStack#resumeTopActivityUncheckedLocked}. |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 97 | mSupervisor.inResumeTopActivity = true; |
| 98 | mStack.mResumedActivity = r; |
Bryce Lee | 5daa312 | 2017-04-19 10:40:42 -0700 | [diff] [blame] | 99 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 100 | final boolean waiting = mStack.goToSleepIfPossible(false); |
Bryce Lee | 5daa312 | 2017-04-19 10:40:42 -0700 | [diff] [blame] | 101 | |
| 102 | // Ensure we report not being ready for sleep. |
David Stevens | 18abd0e | 2017-08-17 14:55:47 -0700 | [diff] [blame] | 103 | assertFalse(waiting); |
Bryce Lee | 5daa312 | 2017-04-19 10:40:42 -0700 | [diff] [blame] | 104 | |
| 105 | // Make sure the resumed activity is untouched. |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 106 | assertEquals(mStack.mResumedActivity, r); |
Bryce Lee | 5daa312 | 2017-04-19 10:40:42 -0700 | [diff] [blame] | 107 | } |
Bryce Lee | 3345c4e | 2017-04-25 07:40:41 -0700 | [diff] [blame] | 108 | |
| 109 | @Test |
| 110 | public void testStopActivityWhenActivityDestroyed() throws Exception { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 111 | final ActivityRecord r = createActivity(mService, testActivityComponent, mTask); |
| 112 | r.info.flags |= ActivityInfo.FLAG_NO_HISTORY; |
| 113 | mSupervisor.setFocusStackUnchecked("testStopActivityWithDestroy", mStack); |
| 114 | mStack.stopActivityLocked(r); |
| 115 | // Mostly testing to make sure there is a crash in the call part, so if we get here we are |
| 116 | // good-to-go! |
Bryce Lee | 3345c4e | 2017-04-25 07:40:41 -0700 | [diff] [blame] | 117 | } |
Bryce Lee | 9f6affd | 2017-09-01 09:18:35 -0700 | [diff] [blame] | 118 | |
| 119 | @Test |
| 120 | public void testFindTaskWithOverlay() throws Exception { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 121 | final ActivityRecord r = createActivity(mService, testActivityComponent, mTask, 0); |
Bryce Lee | 9f6affd | 2017-09-01 09:18:35 -0700 | [diff] [blame] | 122 | // Overlay must be for a different user to prevent recognizing a matching top activity |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 123 | final ActivityRecord taskOverlay = createActivity(mService, testOverlayComponent, mTask, |
Bryce Lee | 9f6affd | 2017-09-01 09:18:35 -0700 | [diff] [blame] | 124 | UserHandle.PER_USER_RANGE * 2); |
| 125 | taskOverlay.mTaskOverlay = true; |
| 126 | |
Bryce Lee | 9f6affd | 2017-09-01 09:18:35 -0700 | [diff] [blame] | 127 | final ActivityStackSupervisor.FindTaskResult result = |
| 128 | new ActivityStackSupervisor.FindTaskResult(); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 129 | mStack.findTaskLocked(r, result); |
Bryce Lee | 9f6affd | 2017-09-01 09:18:35 -0700 | [diff] [blame] | 130 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 131 | assertEquals(mTask.getTopActivity(false /* includeOverlays */), r); |
| 132 | assertEquals(mTask.getTopActivity(true /* includeOverlays */), taskOverlay); |
Bryce Lee | 9f6affd | 2017-09-01 09:18:35 -0700 | [diff] [blame] | 133 | assertNotNull(result.r); |
| 134 | } |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame^] | 135 | |
| 136 | @Test |
| 137 | public void testShouldBeVisible_Fullscreen() throws Exception { |
| 138 | final ActivityDisplay display = mService.mStackSupervisor.getDefaultDisplay(); |
| 139 | final TestActivityStack homeStack = createStackForShouldBeVisibleTest(display, |
| 140 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); |
| 141 | final ActivityStack pinnedStack = createStackForShouldBeVisibleTest(display, |
| 142 | WINDOWING_MODE_PINNED, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 143 | |
| 144 | assertTrue(homeStack.shouldBeVisible(null /* starting */)); |
| 145 | assertTrue(pinnedStack.shouldBeVisible(null /* starting */)); |
| 146 | |
| 147 | final TestActivityStack fullscreenStack = createStackForShouldBeVisibleTest(display, |
| 148 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 149 | // Home stack shouldn't be visible behind an opaque fullscreen stack, but pinned stack |
| 150 | // should be visible since it is always on-top. |
| 151 | fullscreenStack.setIsTranslucent(false); |
| 152 | assertFalse(homeStack.shouldBeVisible(null /* starting */)); |
| 153 | assertTrue(pinnedStack.shouldBeVisible(null /* starting */)); |
| 154 | assertTrue(fullscreenStack.shouldBeVisible(null /* starting */)); |
| 155 | |
| 156 | // Home stack should be visible behind a translucent fullscreen stack. |
| 157 | fullscreenStack.setIsTranslucent(true); |
| 158 | assertTrue(homeStack.shouldBeVisible(null /* starting */)); |
| 159 | assertTrue(pinnedStack.shouldBeVisible(null /* starting */)); |
| 160 | } |
| 161 | |
| 162 | @Test |
| 163 | public void testShouldBeVisible_SplitScreen() throws Exception { |
| 164 | final ActivityDisplay display = mService.mStackSupervisor.getDefaultDisplay(); |
| 165 | final TestActivityStack homeStack = createStackForShouldBeVisibleTest(display, |
| 166 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); |
| 167 | final TestActivityStack splitScreenPrimary = createStackForShouldBeVisibleTest(display, |
| 168 | WINDOWING_MODE_SPLIT_SCREEN_PRIMARY, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 169 | final TestActivityStack splitScreenSecondary = createStackForShouldBeVisibleTest(display, |
| 170 | WINDOWING_MODE_SPLIT_SCREEN_SECONDARY, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 171 | |
| 172 | // Home stack shouldn't be visible if both halves of split-screen are opaque. |
| 173 | splitScreenPrimary.setIsTranslucent(false); |
| 174 | splitScreenSecondary.setIsTranslucent(false); |
| 175 | assertFalse(homeStack.shouldBeVisible(null /* starting */)); |
| 176 | assertTrue(splitScreenPrimary.shouldBeVisible(null /* starting */)); |
| 177 | assertTrue(splitScreenSecondary.shouldBeVisible(null /* starting */)); |
| 178 | |
| 179 | // Home stack should be visible if one of the halves of split-screen is translucent. |
| 180 | splitScreenPrimary.setIsTranslucent(true); |
| 181 | assertTrue(homeStack.shouldBeVisible(null /* starting */)); |
| 182 | assertTrue(splitScreenPrimary.shouldBeVisible(null /* starting */)); |
| 183 | assertTrue(splitScreenSecondary.shouldBeVisible(null /* starting */)); |
| 184 | |
| 185 | final TestActivityStack splitScreenSecondary2 = createStackForShouldBeVisibleTest(display, |
| 186 | WINDOWING_MODE_SPLIT_SCREEN_SECONDARY, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 187 | // First split-screen secondary shouldn't be visible behind another opaque split-split |
| 188 | // secondary. |
| 189 | splitScreenSecondary2.setIsTranslucent(false); |
| 190 | assertFalse(splitScreenSecondary.shouldBeVisible(null /* starting */)); |
| 191 | assertTrue(splitScreenSecondary2.shouldBeVisible(null /* starting */)); |
| 192 | |
| 193 | // First split-screen secondary should be visible behind another translucent split-split |
| 194 | // secondary. |
| 195 | splitScreenSecondary2.setIsTranslucent(true); |
| 196 | assertTrue(splitScreenSecondary.shouldBeVisible(null /* starting */)); |
| 197 | assertTrue(splitScreenSecondary2.shouldBeVisible(null /* starting */)); |
| 198 | |
| 199 | final TestActivityStack assistantStack = createStackForShouldBeVisibleTest(display, |
| 200 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_ASSISTANT, true /* onTop */); |
| 201 | |
| 202 | // Split-screen stacks shouldn't be visible behind an opaque fullscreen stack. |
| 203 | assistantStack.setIsTranslucent(false); |
| 204 | assertTrue(assistantStack.shouldBeVisible(null /* starting */)); |
| 205 | assertFalse(splitScreenPrimary.shouldBeVisible(null /* starting */)); |
| 206 | assertFalse(splitScreenSecondary.shouldBeVisible(null /* starting */)); |
| 207 | assertFalse(splitScreenSecondary2.shouldBeVisible(null /* starting */)); |
| 208 | |
| 209 | // Split-screen stacks should be visible behind a translucent fullscreen stack. |
| 210 | assistantStack.setIsTranslucent(true); |
| 211 | assertTrue(assistantStack.shouldBeVisible(null /* starting */)); |
| 212 | assertTrue(splitScreenPrimary.shouldBeVisible(null /* starting */)); |
| 213 | assertTrue(splitScreenSecondary.shouldBeVisible(null /* starting */)); |
| 214 | assertTrue(splitScreenSecondary2.shouldBeVisible(null /* starting */)); |
| 215 | } |
| 216 | |
| 217 | @Test |
| 218 | public void testShouldBeVisible_Finishing() throws Exception { |
| 219 | final ActivityDisplay display = mService.mStackSupervisor.getDefaultDisplay(); |
| 220 | final TestActivityStack homeStack = createStackForShouldBeVisibleTest(display, |
| 221 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); |
| 222 | final TestActivityStack translucentStack = createStackForShouldBeVisibleTest(display, |
| 223 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 224 | translucentStack.setIsTranslucent(true); |
| 225 | |
| 226 | assertTrue(homeStack.shouldBeVisible(null /* starting */)); |
| 227 | assertTrue(translucentStack.shouldBeVisible(null /* starting */)); |
| 228 | |
| 229 | final ActivityRecord topRunningHomeActivity = homeStack.topRunningActivityLocked(); |
| 230 | topRunningHomeActivity.finishing = true; |
| 231 | final ActivityRecord topRunningTranslucentActivity = |
| 232 | translucentStack.topRunningActivityLocked(); |
| 233 | topRunningTranslucentActivity.finishing = true; |
| 234 | |
| 235 | // Home shouldn't be visible since its activity is marked as finishing and it isn't the top |
| 236 | // of the stack list. |
| 237 | assertFalse(homeStack.shouldBeVisible(null /* starting */)); |
| 238 | // Home should be visible if we are starting an activity within it. |
| 239 | assertTrue(homeStack.shouldBeVisible(topRunningHomeActivity /* starting */)); |
| 240 | // The translucent stack should be visible since it is the top of the stack list even though |
| 241 | // it has its activity marked as finishing. |
| 242 | assertTrue(translucentStack.shouldBeVisible(null /* starting */)); |
| 243 | } |
| 244 | |
| 245 | private <T extends ActivityStack> T createStackForShouldBeVisibleTest( |
| 246 | ActivityDisplay display, int windowingMode, int activityType, boolean onTop) { |
| 247 | final T stack = display.createStack(windowingMode, activityType, onTop); |
| 248 | // Create a task and activity in the stack so that it has a top running activity. |
| 249 | final TaskRecord task = createTask(mSupervisor, testActivityComponent, stack); |
| 250 | final ActivityRecord r = createActivity(mService, testActivityComponent, task, 0); |
| 251 | return stack; |
| 252 | } |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 253 | } |