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: |
Wale Ogunwale | bb28587 | 2018-03-01 13:05:30 -0800 | [diff] [blame] | 50 | * atest FrameworksServicesTests:com.android.server.am.ActivityStackTests |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 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 |
Bryce Lee | 8cab4a0 | 2018-01-05 09:00:49 -0800 | [diff] [blame] | 107 | public void testPrimarySplitScreenToFullscreenWhenMovedToBack() throws Exception { |
| 108 | // Create primary splitscreen stack. This will create secondary stacks and places the |
| 109 | // existing fullscreen stack on the bottom. |
| 110 | final ActivityStack primarySplitScreen = mService.mStackSupervisor.getDefaultDisplay() |
| 111 | .createStack(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY, ACTIVITY_TYPE_STANDARD, |
| 112 | true /* onTop */); |
| 113 | |
| 114 | // Assert windowing mode. |
| 115 | assertEquals(primarySplitScreen.getWindowingMode(), WINDOWING_MODE_SPLIT_SCREEN_PRIMARY); |
| 116 | |
| 117 | // Move primary to back. |
| 118 | primarySplitScreen.moveToBack("testPrimarySplitScreenToFullscreenWhenMovedToBack", |
| 119 | null /* task */); |
| 120 | |
| 121 | // Assert that stack is at the bottom. |
| 122 | assertEquals(mService.mStackSupervisor.getDefaultDisplay().getIndexOf(primarySplitScreen), |
| 123 | 0); |
| 124 | |
| 125 | // Ensure no longer in splitscreen. |
| 126 | assertEquals(primarySplitScreen.getWindowingMode(), WINDOWING_MODE_FULLSCREEN); |
| 127 | } |
| 128 | |
| 129 | @Test |
Bryce Lee | 3345c4e | 2017-04-25 07:40:41 -0700 | [diff] [blame] | 130 | public void testStopActivityWhenActivityDestroyed() throws Exception { |
Bryce Lee | 18d5159 | 2017-10-25 10:22:19 -0700 | [diff] [blame] | 131 | final ActivityRecord r = new ActivityBuilder(mService).setTask(mTask).build(); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 132 | r.info.flags |= ActivityInfo.FLAG_NO_HISTORY; |
| 133 | mSupervisor.setFocusStackUnchecked("testStopActivityWithDestroy", mStack); |
| 134 | mStack.stopActivityLocked(r); |
| 135 | // Mostly testing to make sure there is a crash in the call part, so if we get here we are |
| 136 | // good-to-go! |
Bryce Lee | 3345c4e | 2017-04-25 07:40:41 -0700 | [diff] [blame] | 137 | } |
Bryce Lee | 9f6affd | 2017-09-01 09:18:35 -0700 | [diff] [blame] | 138 | |
| 139 | @Test |
| 140 | public void testFindTaskWithOverlay() throws Exception { |
Bryce Lee | 18d5159 | 2017-10-25 10:22:19 -0700 | [diff] [blame] | 141 | final ActivityRecord r = new ActivityBuilder(mService) |
| 142 | .setCreateTask(true) |
| 143 | .setStack(mStack) |
| 144 | .setUid(0) |
| 145 | .build(); |
| 146 | final TaskRecord task = r.getTask(); |
Bryce Lee | 9f6affd | 2017-09-01 09:18:35 -0700 | [diff] [blame] | 147 | // 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] | 148 | final ActivityRecord taskOverlay = new ActivityBuilder(mService).setTask(task) |
| 149 | .setUid(UserHandle.PER_USER_RANGE * 2).build(); |
Bryce Lee | 9f6affd | 2017-09-01 09:18:35 -0700 | [diff] [blame] | 150 | taskOverlay.mTaskOverlay = true; |
| 151 | |
Bryce Lee | 9f6affd | 2017-09-01 09:18:35 -0700 | [diff] [blame] | 152 | final ActivityStackSupervisor.FindTaskResult result = |
| 153 | new ActivityStackSupervisor.FindTaskResult(); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 154 | mStack.findTaskLocked(r, result); |
Bryce Lee | 9f6affd | 2017-09-01 09:18:35 -0700 | [diff] [blame] | 155 | |
Bryce Lee | 18d5159 | 2017-10-25 10:22:19 -0700 | [diff] [blame] | 156 | assertEquals(task.getTopActivity(false /* includeOverlays */), r); |
| 157 | assertEquals(task.getTopActivity(true /* includeOverlays */), taskOverlay); |
Bryce Lee | 9f6affd | 2017-09-01 09:18:35 -0700 | [diff] [blame] | 158 | assertNotNull(result.r); |
| 159 | } |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 160 | |
| 161 | @Test |
| 162 | public void testShouldBeVisible_Fullscreen() throws Exception { |
| 163 | final ActivityDisplay display = mService.mStackSupervisor.getDefaultDisplay(); |
| 164 | final TestActivityStack homeStack = createStackForShouldBeVisibleTest(display, |
| 165 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); |
| 166 | final ActivityStack pinnedStack = createStackForShouldBeVisibleTest(display, |
| 167 | WINDOWING_MODE_PINNED, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 168 | |
| 169 | assertTrue(homeStack.shouldBeVisible(null /* starting */)); |
| 170 | assertTrue(pinnedStack.shouldBeVisible(null /* starting */)); |
| 171 | |
| 172 | final TestActivityStack fullscreenStack = createStackForShouldBeVisibleTest(display, |
| 173 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 174 | // Home stack shouldn't be visible behind an opaque fullscreen stack, but pinned stack |
| 175 | // should be visible since it is always on-top. |
| 176 | fullscreenStack.setIsTranslucent(false); |
| 177 | assertFalse(homeStack.shouldBeVisible(null /* starting */)); |
| 178 | assertTrue(pinnedStack.shouldBeVisible(null /* starting */)); |
| 179 | assertTrue(fullscreenStack.shouldBeVisible(null /* starting */)); |
| 180 | |
| 181 | // Home stack should be visible behind a translucent fullscreen stack. |
| 182 | fullscreenStack.setIsTranslucent(true); |
| 183 | assertTrue(homeStack.shouldBeVisible(null /* starting */)); |
| 184 | assertTrue(pinnedStack.shouldBeVisible(null /* starting */)); |
| 185 | } |
| 186 | |
| 187 | @Test |
| 188 | public void testShouldBeVisible_SplitScreen() throws Exception { |
| 189 | final ActivityDisplay display = mService.mStackSupervisor.getDefaultDisplay(); |
| 190 | final TestActivityStack homeStack = createStackForShouldBeVisibleTest(display, |
| 191 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 192 | // Home stack should always be fullscreen for this test. |
| 193 | homeStack.setSupportsSplitScreen(false); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 194 | final TestActivityStack splitScreenPrimary = createStackForShouldBeVisibleTest(display, |
| 195 | WINDOWING_MODE_SPLIT_SCREEN_PRIMARY, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 196 | final TestActivityStack splitScreenSecondary = createStackForShouldBeVisibleTest(display, |
| 197 | WINDOWING_MODE_SPLIT_SCREEN_SECONDARY, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 198 | |
| 199 | // Home stack shouldn't be visible if both halves of split-screen are opaque. |
| 200 | splitScreenPrimary.setIsTranslucent(false); |
| 201 | splitScreenSecondary.setIsTranslucent(false); |
| 202 | assertFalse(homeStack.shouldBeVisible(null /* starting */)); |
| 203 | assertTrue(splitScreenPrimary.shouldBeVisible(null /* starting */)); |
| 204 | assertTrue(splitScreenSecondary.shouldBeVisible(null /* starting */)); |
| 205 | |
| 206 | // Home stack should be visible if one of the halves of split-screen is translucent. |
| 207 | splitScreenPrimary.setIsTranslucent(true); |
| 208 | assertTrue(homeStack.shouldBeVisible(null /* starting */)); |
| 209 | assertTrue(splitScreenPrimary.shouldBeVisible(null /* starting */)); |
| 210 | assertTrue(splitScreenSecondary.shouldBeVisible(null /* starting */)); |
| 211 | |
| 212 | final TestActivityStack splitScreenSecondary2 = createStackForShouldBeVisibleTest(display, |
| 213 | WINDOWING_MODE_SPLIT_SCREEN_SECONDARY, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 214 | // First split-screen secondary shouldn't be visible behind another opaque split-split |
| 215 | // secondary. |
| 216 | splitScreenSecondary2.setIsTranslucent(false); |
| 217 | assertFalse(splitScreenSecondary.shouldBeVisible(null /* starting */)); |
| 218 | assertTrue(splitScreenSecondary2.shouldBeVisible(null /* starting */)); |
| 219 | |
| 220 | // First split-screen secondary should be visible behind another translucent split-split |
| 221 | // secondary. |
| 222 | splitScreenSecondary2.setIsTranslucent(true); |
| 223 | assertTrue(splitScreenSecondary.shouldBeVisible(null /* starting */)); |
| 224 | assertTrue(splitScreenSecondary2.shouldBeVisible(null /* starting */)); |
| 225 | |
| 226 | final TestActivityStack assistantStack = createStackForShouldBeVisibleTest(display, |
| 227 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_ASSISTANT, true /* onTop */); |
| 228 | |
| 229 | // Split-screen stacks shouldn't be visible behind an opaque fullscreen stack. |
| 230 | assistantStack.setIsTranslucent(false); |
| 231 | assertTrue(assistantStack.shouldBeVisible(null /* starting */)); |
| 232 | assertFalse(splitScreenPrimary.shouldBeVisible(null /* starting */)); |
| 233 | assertFalse(splitScreenSecondary.shouldBeVisible(null /* starting */)); |
| 234 | assertFalse(splitScreenSecondary2.shouldBeVisible(null /* starting */)); |
| 235 | |
| 236 | // Split-screen stacks should be visible behind a translucent fullscreen stack. |
| 237 | assistantStack.setIsTranslucent(true); |
| 238 | assertTrue(assistantStack.shouldBeVisible(null /* starting */)); |
| 239 | assertTrue(splitScreenPrimary.shouldBeVisible(null /* starting */)); |
| 240 | assertTrue(splitScreenSecondary.shouldBeVisible(null /* starting */)); |
| 241 | assertTrue(splitScreenSecondary2.shouldBeVisible(null /* starting */)); |
| 242 | } |
| 243 | |
| 244 | @Test |
| 245 | public void testShouldBeVisible_Finishing() throws Exception { |
| 246 | final ActivityDisplay display = mService.mStackSupervisor.getDefaultDisplay(); |
| 247 | final TestActivityStack homeStack = createStackForShouldBeVisibleTest(display, |
| 248 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); |
| 249 | final TestActivityStack translucentStack = createStackForShouldBeVisibleTest(display, |
| 250 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 251 | translucentStack.setIsTranslucent(true); |
| 252 | |
| 253 | assertTrue(homeStack.shouldBeVisible(null /* starting */)); |
| 254 | assertTrue(translucentStack.shouldBeVisible(null /* starting */)); |
| 255 | |
| 256 | final ActivityRecord topRunningHomeActivity = homeStack.topRunningActivityLocked(); |
| 257 | topRunningHomeActivity.finishing = true; |
| 258 | final ActivityRecord topRunningTranslucentActivity = |
| 259 | translucentStack.topRunningActivityLocked(); |
| 260 | topRunningTranslucentActivity.finishing = true; |
| 261 | |
| 262 | // Home shouldn't be visible since its activity is marked as finishing and it isn't the top |
| 263 | // of the stack list. |
| 264 | assertFalse(homeStack.shouldBeVisible(null /* starting */)); |
| 265 | // Home should be visible if we are starting an activity within it. |
| 266 | assertTrue(homeStack.shouldBeVisible(topRunningHomeActivity /* starting */)); |
| 267 | // The translucent stack should be visible since it is the top of the stack list even though |
| 268 | // it has its activity marked as finishing. |
| 269 | assertTrue(translucentStack.shouldBeVisible(null /* starting */)); |
| 270 | } |
| 271 | |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 272 | @Test |
| 273 | public void testMoveHomeStackBehindBottomMostVisibleStack_NoMoveHomeBehindFullscreen() { |
| 274 | final ActivityDisplay display = mService.mStackSupervisor.getDefaultDisplay(); |
| 275 | display.removeChild(mStack); |
| 276 | |
| 277 | final TestActivityStack homeStack = createStackForShouldBeVisibleTest(display, |
| 278 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); |
| 279 | final TestActivityStack fullscreenStack = createStackForShouldBeVisibleTest(display, |
| 280 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 281 | |
| 282 | homeStack.setIsTranslucent(false); |
| 283 | fullscreenStack.setIsTranslucent(false); |
| 284 | |
| 285 | // Ensure that we don't move the home stack if it is already behind the top fullscreen stack |
| 286 | int homeStackIndex = display.getIndexOf(homeStack); |
| 287 | assertTrue(display.getStackAboveHome() == fullscreenStack); |
| 288 | display.moveHomeStackBehindBottomMostVisibleStack(); |
| 289 | assertTrue(display.getIndexOf(homeStack) == homeStackIndex); |
| 290 | } |
| 291 | |
| 292 | @Test |
| 293 | public void testMoveHomeStackBehindBottomMostVisibleStack_NoMoveHomeBehindTranslucent() { |
| 294 | final ActivityDisplay display = mService.mStackSupervisor.getDefaultDisplay(); |
| 295 | display.removeChild(mStack); |
| 296 | |
| 297 | final TestActivityStack homeStack = createStackForShouldBeVisibleTest(display, |
| 298 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); |
| 299 | final TestActivityStack fullscreenStack = createStackForShouldBeVisibleTest(display, |
| 300 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 301 | |
| 302 | homeStack.setIsTranslucent(false); |
| 303 | fullscreenStack.setIsTranslucent(true); |
| 304 | |
| 305 | // Ensure that we don't move the home stack if it is already behind the top fullscreen stack |
| 306 | int homeStackIndex = display.getIndexOf(homeStack); |
| 307 | assertTrue(display.getStackAboveHome() == fullscreenStack); |
| 308 | display.moveHomeStackBehindBottomMostVisibleStack(); |
| 309 | assertTrue(display.getIndexOf(homeStack) == homeStackIndex); |
| 310 | } |
| 311 | |
| 312 | @Test |
| 313 | public void testMoveHomeStackBehindBottomMostVisibleStack_NoMoveHomeOnTop() { |
| 314 | final ActivityDisplay display = mService.mStackSupervisor.getDefaultDisplay(); |
| 315 | display.removeChild(mStack); |
| 316 | |
| 317 | final TestActivityStack fullscreenStack = createStackForShouldBeVisibleTest(display, |
| 318 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 319 | final TestActivityStack homeStack = createStackForShouldBeVisibleTest(display, |
| 320 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); |
| 321 | |
| 322 | homeStack.setIsTranslucent(false); |
| 323 | fullscreenStack.setIsTranslucent(false); |
| 324 | |
| 325 | // Ensure we don't move the home stack if it is already on top |
| 326 | int homeStackIndex = display.getIndexOf(homeStack); |
| 327 | assertTrue(display.getStackAboveHome() == null); |
| 328 | display.moveHomeStackBehindBottomMostVisibleStack(); |
| 329 | assertTrue(display.getIndexOf(homeStack) == homeStackIndex); |
| 330 | } |
| 331 | |
| 332 | @Test |
| 333 | public void testMoveHomeStackBehindBottomMostVisibleStack_MoveHomeBehindFullscreen() { |
| 334 | final ActivityDisplay display = mService.mStackSupervisor.getDefaultDisplay(); |
| 335 | display.removeChild(mStack); |
| 336 | |
| 337 | final TestActivityStack homeStack = createStackForShouldBeVisibleTest(display, |
| 338 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); |
| 339 | final TestActivityStack fullscreenStack1 = createStackForShouldBeVisibleTest(display, |
| 340 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 341 | final TestActivityStack fullscreenStack2 = createStackForShouldBeVisibleTest(display, |
| 342 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 343 | final TestActivityStack pinnedStack = createStackForShouldBeVisibleTest(display, |
| 344 | WINDOWING_MODE_PINNED, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 345 | |
| 346 | homeStack.setIsTranslucent(false); |
| 347 | fullscreenStack1.setIsTranslucent(false); |
| 348 | fullscreenStack2.setIsTranslucent(false); |
| 349 | |
| 350 | // Ensure that we move the home stack behind the bottom most fullscreen stack, ignoring the |
| 351 | // pinned stack |
| 352 | assertTrue(display.getStackAboveHome() == fullscreenStack1); |
| 353 | display.moveHomeStackBehindBottomMostVisibleStack(); |
| 354 | assertTrue(display.getStackAboveHome() == fullscreenStack2); |
| 355 | } |
| 356 | |
| 357 | @Test |
| 358 | public void testMoveHomeStackBehindBottomMostVisibleStack_MoveHomeBehindFullscreenAndTranslucent() { |
| 359 | final ActivityDisplay display = mService.mStackSupervisor.getDefaultDisplay(); |
| 360 | display.removeChild(mStack); |
| 361 | |
| 362 | final TestActivityStack homeStack = createStackForShouldBeVisibleTest(display, |
| 363 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); |
| 364 | final TestActivityStack fullscreenStack1 = createStackForShouldBeVisibleTest(display, |
| 365 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 366 | final TestActivityStack fullscreenStack2 = createStackForShouldBeVisibleTest(display, |
| 367 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 368 | |
| 369 | homeStack.setIsTranslucent(false); |
| 370 | fullscreenStack1.setIsTranslucent(false); |
| 371 | fullscreenStack2.setIsTranslucent(true); |
| 372 | |
| 373 | // Ensure that we move the home stack behind the bottom most non-translucent fullscreen |
| 374 | // stack |
| 375 | assertTrue(display.getStackAboveHome() == fullscreenStack1); |
| 376 | display.moveHomeStackBehindBottomMostVisibleStack(); |
| 377 | assertTrue(display.getStackAboveHome() == fullscreenStack1); |
| 378 | } |
| 379 | |
| 380 | @Test |
| 381 | public void testMoveHomeStackBehindStack_BehindHomeStack() { |
| 382 | final ActivityDisplay display = mService.mStackSupervisor.getDefaultDisplay(); |
| 383 | display.removeChild(mStack); |
| 384 | |
| 385 | final TestActivityStack fullscreenStack1 = createStackForShouldBeVisibleTest(display, |
| 386 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 387 | final TestActivityStack fullscreenStack2 = createStackForShouldBeVisibleTest(display, |
| 388 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 389 | final TestActivityStack homeStack = createStackForShouldBeVisibleTest(display, |
| 390 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); |
| 391 | |
| 392 | homeStack.setIsTranslucent(false); |
| 393 | fullscreenStack1.setIsTranslucent(false); |
| 394 | fullscreenStack2.setIsTranslucent(false); |
| 395 | |
| 396 | // Ensure we don't move the home stack behind itself |
| 397 | int homeStackIndex = display.getIndexOf(homeStack); |
| 398 | display.moveHomeStackBehindStack(homeStack); |
| 399 | assertTrue(display.getIndexOf(homeStack) == homeStackIndex); |
| 400 | } |
| 401 | |
| 402 | @Test |
| 403 | public void testMoveHomeStackBehindStack() { |
| 404 | final ActivityDisplay display = mService.mStackSupervisor.getDefaultDisplay(); |
| 405 | display.removeChild(mStack); |
| 406 | |
| 407 | final TestActivityStack fullscreenStack1 = createStackForShouldBeVisibleTest(display, |
| 408 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 409 | final TestActivityStack fullscreenStack2 = createStackForShouldBeVisibleTest(display, |
| 410 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
Winson Chung | 123e07a | 2018-02-27 11:47:16 -0800 | [diff] [blame] | 411 | final TestActivityStack fullscreenStack3 = createStackForShouldBeVisibleTest(display, |
| 412 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 413 | final TestActivityStack fullscreenStack4 = createStackForShouldBeVisibleTest(display, |
| 414 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 415 | final TestActivityStack homeStack = createStackForShouldBeVisibleTest(display, |
| 416 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); |
| 417 | |
| 418 | display.moveHomeStackBehindStack(fullscreenStack1); |
| 419 | assertTrue(display.getStackAboveHome() == fullscreenStack1); |
| 420 | display.moveHomeStackBehindStack(fullscreenStack2); |
| 421 | assertTrue(display.getStackAboveHome() == fullscreenStack2); |
Winson Chung | 123e07a | 2018-02-27 11:47:16 -0800 | [diff] [blame] | 422 | display.moveHomeStackBehindStack(fullscreenStack4); |
| 423 | assertTrue(display.getStackAboveHome() == fullscreenStack4); |
| 424 | display.moveHomeStackBehindStack(fullscreenStack2); |
| 425 | assertTrue(display.getStackAboveHome() == fullscreenStack2); |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 426 | } |
| 427 | |
Wale Ogunwale | bb28587 | 2018-03-01 13:05:30 -0800 | [diff] [blame] | 428 | @Test |
| 429 | public void testSplitScreenMoveToFront() throws Exception { |
| 430 | final ActivityDisplay display = mService.mStackSupervisor.getDefaultDisplay(); |
| 431 | final TestActivityStack splitScreenPrimary = createStackForShouldBeVisibleTest(display, |
| 432 | WINDOWING_MODE_SPLIT_SCREEN_PRIMARY, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 433 | final TestActivityStack splitScreenSecondary = createStackForShouldBeVisibleTest(display, |
| 434 | WINDOWING_MODE_SPLIT_SCREEN_SECONDARY, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 435 | final TestActivityStack assistantStack = createStackForShouldBeVisibleTest(display, |
| 436 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_ASSISTANT, true /* onTop */); |
| 437 | |
| 438 | splitScreenPrimary.setIsTranslucent(false); |
| 439 | splitScreenSecondary.setIsTranslucent(false); |
| 440 | assistantStack.setIsTranslucent(false); |
| 441 | |
| 442 | assertFalse(splitScreenPrimary.shouldBeVisible(null /* starting */)); |
| 443 | assertFalse(splitScreenSecondary.shouldBeVisible(null /* starting */)); |
| 444 | assertTrue(assistantStack.shouldBeVisible(null /* starting */)); |
| 445 | |
| 446 | splitScreenSecondary.moveToFront("testSplitScreenMoveToFront"); |
| 447 | |
| 448 | assertTrue(splitScreenPrimary.shouldBeVisible(null /* starting */)); |
| 449 | assertTrue(splitScreenSecondary.shouldBeVisible(null /* starting */)); |
| 450 | assertFalse(assistantStack.shouldBeVisible(null /* starting */)); |
| 451 | } |
| 452 | |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 453 | private <T extends ActivityStack> T createStackForShouldBeVisibleTest( |
| 454 | ActivityDisplay display, int windowingMode, int activityType, boolean onTop) { |
| 455 | final T stack = display.createStack(windowingMode, activityType, onTop); |
Bryce Lee | 18d5159 | 2017-10-25 10:22:19 -0700 | [diff] [blame] | 456 | final ActivityRecord r = new ActivityBuilder(mService).setUid(0).setStack(stack) |
| 457 | .setCreateTask(true).build(); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 458 | return stack; |
| 459 | } |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 460 | } |