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