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; |
Kazuki Takise | f85197b | 2018-06-18 18:18:36 +0900 | [diff] [blame] | 22 | import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM; |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 23 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 24 | import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; |
| 25 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; |
| 26 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_SECONDARY; |
Bryce Lee | 18d5159 | 2017-10-25 10:22:19 -0700 | [diff] [blame] | 27 | |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 28 | import static com.android.server.am.ActivityStack.ActivityState.PAUSING; |
| 29 | import static com.android.server.am.ActivityStack.ActivityState.RESUMED; |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 30 | import static com.android.server.am.ActivityStack.REMOVE_TASK_MODE_DESTROYING; |
Bryce Lee | 18d5159 | 2017-10-25 10:22:19 -0700 | [diff] [blame] | 31 | |
Bryce Lee | 5daa312 | 2017-04-19 10:40:42 -0700 | [diff] [blame] | 32 | import static org.junit.Assert.assertEquals; |
David Stevens | 18abd0e | 2017-08-17 14:55:47 -0700 | [diff] [blame] | 33 | import static org.junit.Assert.assertFalse; |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 34 | import static org.junit.Assert.assertNotNull; |
| 35 | import static org.junit.Assert.assertNull; |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 36 | import static org.junit.Assert.assertTrue; |
Bryce Lee | 271617a | 2018-03-15 10:39:12 -0700 | [diff] [blame] | 37 | import static org.mockito.Mockito.anyInt; |
| 38 | import static org.mockito.Mockito.doReturn; |
Bryce Lee | b0f993f | 2018-03-02 15:38:01 -0800 | [diff] [blame] | 39 | import static org.mockito.Mockito.mock; |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 40 | |
Bryce Lee | 3345c4e | 2017-04-25 07:40:41 -0700 | [diff] [blame] | 41 | import android.content.pm.ActivityInfo; |
Bryce Lee | 9f6affd | 2017-09-01 09:18:35 -0700 | [diff] [blame] | 42 | import android.os.UserHandle; |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 43 | import android.platform.test.annotations.Presubmit; |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 44 | |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 45 | import androidx.test.filters.SmallTest; |
| 46 | import androidx.test.runner.AndroidJUnit4; |
| 47 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 48 | import org.junit.Before; |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 49 | import org.junit.Test; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 50 | import org.junit.runner.RunWith; |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 51 | |
| 52 | /** |
| 53 | * Tests for the {@link ActivityStack} class. |
| 54 | * |
| 55 | * Build/Install/Run: |
Wale Ogunwale | bb28587 | 2018-03-01 13:05:30 -0800 | [diff] [blame] | 56 | * atest FrameworksServicesTests:com.android.server.am.ActivityStackTests |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 57 | */ |
| 58 | @SmallTest |
| 59 | @Presubmit |
| 60 | @RunWith(AndroidJUnit4.class) |
| 61 | public class ActivityStackTests extends ActivityTestsBase { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 62 | private ActivityTaskManagerService mService; |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 63 | private ActivityStackSupervisor mSupervisor; |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 64 | private ActivityDisplay mDefaultDisplay; |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 65 | private ActivityStack mStack; |
| 66 | private TaskRecord mTask; |
| 67 | |
| 68 | @Before |
| 69 | @Override |
| 70 | public void setUp() throws Exception { |
| 71 | super.setUp(); |
| 72 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 73 | mService = createActivityTaskManagerService(); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 74 | mSupervisor = mService.mStackSupervisor; |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 75 | mDefaultDisplay = mService.mStackSupervisor.getDefaultDisplay(); |
| 76 | mStack = mDefaultDisplay.createStack(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, |
| 77 | true /* onTop */); |
Bryce Lee | 18d5159 | 2017-10-25 10:22:19 -0700 | [diff] [blame] | 78 | mTask = new TaskBuilder(mSupervisor).setStack(mStack).build(); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 79 | } |
| 80 | |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 81 | @Test |
| 82 | public void testEmptyTaskCleanupOnRemove() throws Exception { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 83 | assertNotNull(mTask.getWindowContainerController()); |
| 84 | mStack.removeTask(mTask, "testEmptyTaskCleanupOnRemove", REMOVE_TASK_MODE_DESTROYING); |
| 85 | assertNull(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 | |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 88 | @Test |
| 89 | public void testOccupiedTaskCleanupOnRemove() throws Exception { |
Bryce Lee | 18d5159 | 2017-10-25 10:22:19 -0700 | [diff] [blame] | 90 | final ActivityRecord r = new ActivityBuilder(mService).setTask(mTask).build(); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 91 | assertNotNull(mTask.getWindowContainerController()); |
| 92 | mStack.removeTask(mTask, "testOccupiedTaskCleanupOnRemove", REMOVE_TASK_MODE_DESTROYING); |
| 93 | assertNotNull(mTask.getWindowContainerController()); |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 94 | } |
Bryce Lee | 5daa312 | 2017-04-19 10:40:42 -0700 | [diff] [blame] | 95 | |
| 96 | @Test |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 97 | public void testResumedActivity() throws Exception { |
| 98 | final ActivityRecord r = new ActivityBuilder(mService).setTask(mTask).build(); |
| 99 | assertEquals(mStack.getResumedActivity(), null); |
| 100 | r.setState(RESUMED, "testResumedActivity"); |
| 101 | assertEquals(mStack.getResumedActivity(), r); |
| 102 | r.setState(PAUSING, "testResumedActivity"); |
| 103 | assertEquals(mStack.getResumedActivity(), null); |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 104 | } |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 105 | |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 106 | @Test |
| 107 | public void testResumedActivityFromTaskReparenting() { |
| 108 | final ActivityRecord r = new ActivityBuilder(mService).setTask(mTask).build(); |
| 109 | // Ensure moving task between two stacks updates resumed activity |
| 110 | r.setState(RESUMED, "testResumedActivityFromTaskReparenting"); |
| 111 | assertEquals(mStack.getResumedActivity(), r); |
| 112 | |
| 113 | final ActivityStack destStack = mService.mStackSupervisor.getDefaultDisplay().createStack( |
| 114 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 115 | |
| 116 | mTask.reparent(destStack, true /* toTop */, TaskRecord.REPARENT_KEEP_STACK_AT_FRONT, |
| 117 | false /* animate */, true /* deferResume*/, |
| 118 | "testResumedActivityFromTaskReparenting"); |
| 119 | |
| 120 | assertEquals(mStack.getResumedActivity(), null); |
| 121 | assertEquals(destStack.getResumedActivity(), r); |
| 122 | } |
| 123 | |
| 124 | @Test |
| 125 | public void testResumedActivityFromActivityReparenting() { |
| 126 | final ActivityRecord r = new ActivityBuilder(mService).setTask(mTask).build(); |
| 127 | // Ensure moving task between two stacks updates resumed activity |
| 128 | r.setState(RESUMED, "testResumedActivityFromActivityReparenting"); |
| 129 | assertEquals(mStack.getResumedActivity(), r); |
| 130 | |
| 131 | final ActivityStack destStack = mService.mStackSupervisor.getDefaultDisplay().createStack( |
| 132 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 133 | final TaskRecord destTask = new TaskBuilder(mSupervisor).setStack(destStack).build(); |
| 134 | |
| 135 | mTask.removeActivity(r); |
| 136 | destTask.addActivityToTop(r); |
| 137 | |
| 138 | assertEquals(mStack.getResumedActivity(), null); |
| 139 | assertEquals(destStack.getResumedActivity(), r); |
Bryce Lee | 5daa312 | 2017-04-19 10:40:42 -0700 | [diff] [blame] | 140 | } |
Bryce Lee | 3345c4e | 2017-04-25 07:40:41 -0700 | [diff] [blame] | 141 | |
| 142 | @Test |
Bryce Lee | 8cab4a0 | 2018-01-05 09:00:49 -0800 | [diff] [blame] | 143 | public void testPrimarySplitScreenToFullscreenWhenMovedToBack() throws Exception { |
| 144 | // Create primary splitscreen stack. This will create secondary stacks and places the |
| 145 | // existing fullscreen stack on the bottom. |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 146 | final ActivityStack primarySplitScreen = mDefaultDisplay.createStack( |
| 147 | WINDOWING_MODE_SPLIT_SCREEN_PRIMARY, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
Bryce Lee | 8cab4a0 | 2018-01-05 09:00:49 -0800 | [diff] [blame] | 148 | |
| 149 | // Assert windowing mode. |
| 150 | assertEquals(primarySplitScreen.getWindowingMode(), WINDOWING_MODE_SPLIT_SCREEN_PRIMARY); |
| 151 | |
| 152 | // Move primary to back. |
| 153 | primarySplitScreen.moveToBack("testPrimarySplitScreenToFullscreenWhenMovedToBack", |
| 154 | null /* task */); |
| 155 | |
| 156 | // Assert that stack is at the bottom. |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 157 | assertEquals(mDefaultDisplay.getIndexOf(primarySplitScreen), 0); |
Bryce Lee | 8cab4a0 | 2018-01-05 09:00:49 -0800 | [diff] [blame] | 158 | |
| 159 | // Ensure no longer in splitscreen. |
| 160 | assertEquals(primarySplitScreen.getWindowingMode(), WINDOWING_MODE_FULLSCREEN); |
| 161 | } |
| 162 | |
| 163 | @Test |
Bryce Lee | 3345c4e | 2017-04-25 07:40:41 -0700 | [diff] [blame] | 164 | public void testStopActivityWhenActivityDestroyed() throws Exception { |
Bryce Lee | 18d5159 | 2017-10-25 10:22:19 -0700 | [diff] [blame] | 165 | final ActivityRecord r = new ActivityBuilder(mService).setTask(mTask).build(); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 166 | r.info.flags |= ActivityInfo.FLAG_NO_HISTORY; |
Andrii Kulian | 6a6c4f1 | 2018-07-16 21:23:33 -0700 | [diff] [blame] | 167 | mStack.moveToFront("testStopActivityWithDestroy"); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 168 | mStack.stopActivityLocked(r); |
| 169 | // Mostly testing to make sure there is a crash in the call part, so if we get here we are |
| 170 | // good-to-go! |
Bryce Lee | 3345c4e | 2017-04-25 07:40:41 -0700 | [diff] [blame] | 171 | } |
Bryce Lee | 9f6affd | 2017-09-01 09:18:35 -0700 | [diff] [blame] | 172 | |
| 173 | @Test |
| 174 | public void testFindTaskWithOverlay() throws Exception { |
Bryce Lee | 18d5159 | 2017-10-25 10:22:19 -0700 | [diff] [blame] | 175 | final ActivityRecord r = new ActivityBuilder(mService) |
| 176 | .setCreateTask(true) |
| 177 | .setStack(mStack) |
| 178 | .setUid(0) |
| 179 | .build(); |
| 180 | final TaskRecord task = r.getTask(); |
Bryce Lee | 9f6affd | 2017-09-01 09:18:35 -0700 | [diff] [blame] | 181 | // 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] | 182 | final ActivityRecord taskOverlay = new ActivityBuilder(mService).setTask(task) |
| 183 | .setUid(UserHandle.PER_USER_RANGE * 2).build(); |
Bryce Lee | 9f6affd | 2017-09-01 09:18:35 -0700 | [diff] [blame] | 184 | taskOverlay.mTaskOverlay = true; |
| 185 | |
Bryce Lee | 9f6affd | 2017-09-01 09:18:35 -0700 | [diff] [blame] | 186 | final ActivityStackSupervisor.FindTaskResult result = |
| 187 | new ActivityStackSupervisor.FindTaskResult(); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 188 | mStack.findTaskLocked(r, result); |
Bryce Lee | 9f6affd | 2017-09-01 09:18:35 -0700 | [diff] [blame] | 189 | |
Bryce Lee | 18d5159 | 2017-10-25 10:22:19 -0700 | [diff] [blame] | 190 | assertEquals(task.getTopActivity(false /* includeOverlays */), r); |
| 191 | assertEquals(task.getTopActivity(true /* includeOverlays */), taskOverlay); |
Louis Chang | c85b1a3 | 2018-08-14 16:40:53 +0800 | [diff] [blame^] | 192 | assertNotNull(result.mRecord); |
Bryce Lee | 9f6affd | 2017-09-01 09:18:35 -0700 | [diff] [blame] | 193 | } |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 194 | |
| 195 | @Test |
| 196 | public void testShouldBeVisible_Fullscreen() throws Exception { |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 197 | final TestActivityStack homeStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 198 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 199 | final ActivityStack pinnedStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 200 | WINDOWING_MODE_PINNED, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 201 | |
| 202 | assertTrue(homeStack.shouldBeVisible(null /* starting */)); |
| 203 | assertTrue(pinnedStack.shouldBeVisible(null /* starting */)); |
| 204 | |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 205 | final TestActivityStack fullscreenStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 206 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 207 | // Home stack shouldn't be visible behind an opaque fullscreen stack, but pinned stack |
| 208 | // should be visible since it is always on-top. |
| 209 | fullscreenStack.setIsTranslucent(false); |
| 210 | assertFalse(homeStack.shouldBeVisible(null /* starting */)); |
| 211 | assertTrue(pinnedStack.shouldBeVisible(null /* starting */)); |
| 212 | assertTrue(fullscreenStack.shouldBeVisible(null /* starting */)); |
| 213 | |
| 214 | // Home stack should be visible behind a translucent fullscreen stack. |
| 215 | fullscreenStack.setIsTranslucent(true); |
| 216 | assertTrue(homeStack.shouldBeVisible(null /* starting */)); |
| 217 | assertTrue(pinnedStack.shouldBeVisible(null /* starting */)); |
| 218 | } |
| 219 | |
| 220 | @Test |
| 221 | public void testShouldBeVisible_SplitScreen() throws Exception { |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 222 | final TestActivityStack homeStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 223 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 224 | // Home stack should always be fullscreen for this test. |
| 225 | homeStack.setSupportsSplitScreen(false); |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 226 | final TestActivityStack splitScreenPrimary = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 227 | WINDOWING_MODE_SPLIT_SCREEN_PRIMARY, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 228 | final TestActivityStack splitScreenSecondary = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 229 | WINDOWING_MODE_SPLIT_SCREEN_SECONDARY, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 230 | |
| 231 | // Home stack shouldn't be visible if both halves of split-screen are opaque. |
| 232 | splitScreenPrimary.setIsTranslucent(false); |
| 233 | splitScreenSecondary.setIsTranslucent(false); |
| 234 | assertFalse(homeStack.shouldBeVisible(null /* starting */)); |
| 235 | assertTrue(splitScreenPrimary.shouldBeVisible(null /* starting */)); |
| 236 | assertTrue(splitScreenSecondary.shouldBeVisible(null /* starting */)); |
| 237 | |
| 238 | // Home stack should be visible if one of the halves of split-screen is translucent. |
| 239 | splitScreenPrimary.setIsTranslucent(true); |
| 240 | assertTrue(homeStack.shouldBeVisible(null /* starting */)); |
| 241 | assertTrue(splitScreenPrimary.shouldBeVisible(null /* starting */)); |
| 242 | assertTrue(splitScreenSecondary.shouldBeVisible(null /* starting */)); |
| 243 | |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 244 | final TestActivityStack splitScreenSecondary2 = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 245 | WINDOWING_MODE_SPLIT_SCREEN_SECONDARY, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 246 | // First split-screen secondary shouldn't be visible behind another opaque split-split |
| 247 | // secondary. |
| 248 | splitScreenSecondary2.setIsTranslucent(false); |
| 249 | assertFalse(splitScreenSecondary.shouldBeVisible(null /* starting */)); |
| 250 | assertTrue(splitScreenSecondary2.shouldBeVisible(null /* starting */)); |
| 251 | |
Wale Ogunwale | 8e923af | 2018-03-23 08:48:11 -0700 | [diff] [blame] | 252 | // First split-screen secondary should be visible behind another translucent split-screen |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 253 | // secondary. |
| 254 | splitScreenSecondary2.setIsTranslucent(true); |
| 255 | assertTrue(splitScreenSecondary.shouldBeVisible(null /* starting */)); |
| 256 | assertTrue(splitScreenSecondary2.shouldBeVisible(null /* starting */)); |
| 257 | |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 258 | final TestActivityStack assistantStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 259 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_ASSISTANT, true /* onTop */); |
| 260 | |
| 261 | // Split-screen stacks shouldn't be visible behind an opaque fullscreen stack. |
| 262 | assistantStack.setIsTranslucent(false); |
| 263 | assertTrue(assistantStack.shouldBeVisible(null /* starting */)); |
| 264 | assertFalse(splitScreenPrimary.shouldBeVisible(null /* starting */)); |
| 265 | assertFalse(splitScreenSecondary.shouldBeVisible(null /* starting */)); |
| 266 | assertFalse(splitScreenSecondary2.shouldBeVisible(null /* starting */)); |
| 267 | |
| 268 | // Split-screen stacks should be visible behind a translucent fullscreen stack. |
| 269 | assistantStack.setIsTranslucent(true); |
| 270 | assertTrue(assistantStack.shouldBeVisible(null /* starting */)); |
| 271 | assertTrue(splitScreenPrimary.shouldBeVisible(null /* starting */)); |
| 272 | assertTrue(splitScreenSecondary.shouldBeVisible(null /* starting */)); |
| 273 | assertTrue(splitScreenSecondary2.shouldBeVisible(null /* starting */)); |
Wale Ogunwale | 8e923af | 2018-03-23 08:48:11 -0700 | [diff] [blame] | 274 | |
| 275 | // Assistant stack shouldn't be visible behind translucent split-screen stack |
| 276 | assistantStack.setIsTranslucent(false); |
| 277 | splitScreenPrimary.setIsTranslucent(true); |
| 278 | splitScreenSecondary2.setIsTranslucent(true); |
| 279 | splitScreenSecondary2.moveToFront("testShouldBeVisible_SplitScreen"); |
| 280 | splitScreenPrimary.moveToFront("testShouldBeVisible_SplitScreen"); |
| 281 | assertFalse(assistantStack.shouldBeVisible(null /* starting */)); |
| 282 | assertTrue(splitScreenPrimary.shouldBeVisible(null /* starting */)); |
| 283 | assertTrue(splitScreenSecondary2.shouldBeVisible(null /* starting */)); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | @Test |
| 287 | public void testShouldBeVisible_Finishing() throws Exception { |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 288 | final TestActivityStack homeStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 289 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 290 | final TestActivityStack translucentStack = createStackForShouldBeVisibleTest( |
| 291 | mDefaultDisplay, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, |
| 292 | true /* onTop */); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 293 | translucentStack.setIsTranslucent(true); |
| 294 | |
| 295 | assertTrue(homeStack.shouldBeVisible(null /* starting */)); |
| 296 | assertTrue(translucentStack.shouldBeVisible(null /* starting */)); |
| 297 | |
| 298 | final ActivityRecord topRunningHomeActivity = homeStack.topRunningActivityLocked(); |
| 299 | topRunningHomeActivity.finishing = true; |
| 300 | final ActivityRecord topRunningTranslucentActivity = |
| 301 | translucentStack.topRunningActivityLocked(); |
| 302 | topRunningTranslucentActivity.finishing = true; |
| 303 | |
| 304 | // Home shouldn't be visible since its activity is marked as finishing and it isn't the top |
| 305 | // of the stack list. |
| 306 | assertFalse(homeStack.shouldBeVisible(null /* starting */)); |
| 307 | // Home should be visible if we are starting an activity within it. |
| 308 | assertTrue(homeStack.shouldBeVisible(topRunningHomeActivity /* starting */)); |
| 309 | // The translucent stack should be visible since it is the top of the stack list even though |
| 310 | // it has its activity marked as finishing. |
| 311 | assertTrue(translucentStack.shouldBeVisible(null /* starting */)); |
| 312 | } |
| 313 | |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 314 | @Test |
| 315 | public void testMoveHomeStackBehindBottomMostVisibleStack_NoMoveHomeBehindFullscreen() { |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 316 | mDefaultDisplay.removeChild(mStack); |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 317 | |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 318 | final TestActivityStack homeStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 319 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 320 | final TestActivityStack fullscreenStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 321 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 322 | |
| 323 | homeStack.setIsTranslucent(false); |
| 324 | fullscreenStack.setIsTranslucent(false); |
| 325 | |
| 326 | // Ensure that we don't move the home stack if it is already behind the top fullscreen stack |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 327 | int homeStackIndex = mDefaultDisplay.getIndexOf(homeStack); |
| 328 | assertTrue(mDefaultDisplay.getStackAbove(homeStack) == fullscreenStack); |
| 329 | mDefaultDisplay.moveStackBehindBottomMostVisibleStack(homeStack); |
| 330 | assertTrue(mDefaultDisplay.getIndexOf(homeStack) == homeStackIndex); |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | @Test |
| 334 | public void testMoveHomeStackBehindBottomMostVisibleStack_NoMoveHomeBehindTranslucent() { |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 335 | mDefaultDisplay.removeChild(mStack); |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 336 | |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 337 | final TestActivityStack homeStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 338 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 339 | final TestActivityStack fullscreenStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 340 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 341 | |
| 342 | homeStack.setIsTranslucent(false); |
| 343 | fullscreenStack.setIsTranslucent(true); |
| 344 | |
| 345 | // Ensure that we don't move the home stack if it is already behind the top fullscreen stack |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 346 | int homeStackIndex = mDefaultDisplay.getIndexOf(homeStack); |
| 347 | assertTrue(mDefaultDisplay.getStackAbove(homeStack) == fullscreenStack); |
| 348 | mDefaultDisplay.moveStackBehindBottomMostVisibleStack(homeStack); |
| 349 | assertTrue(mDefaultDisplay.getIndexOf(homeStack) == homeStackIndex); |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | @Test |
| 353 | public void testMoveHomeStackBehindBottomMostVisibleStack_NoMoveHomeOnTop() { |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 354 | mDefaultDisplay.removeChild(mStack); |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 355 | |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 356 | final TestActivityStack fullscreenStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 357 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 358 | final TestActivityStack homeStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 359 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); |
| 360 | |
| 361 | homeStack.setIsTranslucent(false); |
| 362 | fullscreenStack.setIsTranslucent(false); |
| 363 | |
| 364 | // Ensure we don't move the home stack if it is already on top |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 365 | int homeStackIndex = mDefaultDisplay.getIndexOf(homeStack); |
| 366 | assertTrue(mDefaultDisplay.getStackAbove(homeStack) == null); |
| 367 | mDefaultDisplay.moveStackBehindBottomMostVisibleStack(homeStack); |
| 368 | assertTrue(mDefaultDisplay.getIndexOf(homeStack) == homeStackIndex); |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | @Test |
| 372 | public void testMoveHomeStackBehindBottomMostVisibleStack_MoveHomeBehindFullscreen() { |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 373 | mDefaultDisplay.removeChild(mStack); |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 374 | |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 375 | final TestActivityStack homeStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 376 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 377 | final TestActivityStack fullscreenStack1 = createStackForShouldBeVisibleTest( |
| 378 | mDefaultDisplay, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, |
| 379 | true /* onTop */); |
| 380 | final TestActivityStack fullscreenStack2 = createStackForShouldBeVisibleTest( |
| 381 | mDefaultDisplay, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, |
| 382 | true /* onTop */); |
| 383 | final TestActivityStack pinnedStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 384 | WINDOWING_MODE_PINNED, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 385 | |
| 386 | homeStack.setIsTranslucent(false); |
| 387 | fullscreenStack1.setIsTranslucent(false); |
| 388 | fullscreenStack2.setIsTranslucent(false); |
| 389 | |
| 390 | // Ensure that we move the home stack behind the bottom most fullscreen stack, ignoring the |
| 391 | // pinned stack |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 392 | assertTrue(mDefaultDisplay.getStackAbove(homeStack) == fullscreenStack1); |
| 393 | mDefaultDisplay.moveStackBehindBottomMostVisibleStack(homeStack); |
| 394 | assertTrue(mDefaultDisplay.getStackAbove(homeStack) == fullscreenStack2); |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | @Test |
| 398 | public void testMoveHomeStackBehindBottomMostVisibleStack_MoveHomeBehindFullscreenAndTranslucent() { |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 399 | mDefaultDisplay.removeChild(mStack); |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 400 | |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 401 | final TestActivityStack homeStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 402 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 403 | final TestActivityStack fullscreenStack1 = createStackForShouldBeVisibleTest( |
| 404 | mDefaultDisplay, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, |
| 405 | true /* onTop */); |
| 406 | final TestActivityStack fullscreenStack2 = createStackForShouldBeVisibleTest( |
| 407 | mDefaultDisplay, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, |
| 408 | true /* onTop */); |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 409 | |
| 410 | homeStack.setIsTranslucent(false); |
| 411 | fullscreenStack1.setIsTranslucent(false); |
| 412 | fullscreenStack2.setIsTranslucent(true); |
| 413 | |
| 414 | // Ensure that we move the home stack behind the bottom most non-translucent fullscreen |
| 415 | // stack |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 416 | assertTrue(mDefaultDisplay.getStackAbove(homeStack) == fullscreenStack1); |
| 417 | mDefaultDisplay.moveStackBehindBottomMostVisibleStack(homeStack); |
| 418 | assertTrue(mDefaultDisplay.getStackAbove(homeStack) == fullscreenStack1); |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | @Test |
| 422 | public void testMoveHomeStackBehindStack_BehindHomeStack() { |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 423 | mDefaultDisplay.removeChild(mStack); |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 424 | |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 425 | final TestActivityStack fullscreenStack1 = createStackForShouldBeVisibleTest( |
| 426 | mDefaultDisplay, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, |
| 427 | true /* onTop */); |
| 428 | final TestActivityStack fullscreenStack2 = createStackForShouldBeVisibleTest( |
| 429 | mDefaultDisplay, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, |
| 430 | true /* onTop */); |
| 431 | final TestActivityStack homeStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 432 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); |
| 433 | |
| 434 | homeStack.setIsTranslucent(false); |
| 435 | fullscreenStack1.setIsTranslucent(false); |
| 436 | fullscreenStack2.setIsTranslucent(false); |
| 437 | |
| 438 | // Ensure we don't move the home stack behind itself |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 439 | int homeStackIndex = mDefaultDisplay.getIndexOf(homeStack); |
| 440 | mDefaultDisplay.moveStackBehindStack(homeStack, homeStack); |
| 441 | assertTrue(mDefaultDisplay.getIndexOf(homeStack) == homeStackIndex); |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | @Test |
| 445 | public void testMoveHomeStackBehindStack() { |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 446 | mDefaultDisplay.removeChild(mStack); |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 447 | |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 448 | final TestActivityStack fullscreenStack1 = createStackForShouldBeVisibleTest( |
| 449 | mDefaultDisplay, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, |
| 450 | true /* onTop */); |
| 451 | final TestActivityStack fullscreenStack2 = createStackForShouldBeVisibleTest( |
| 452 | mDefaultDisplay, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, |
| 453 | true /* onTop */); |
| 454 | final TestActivityStack fullscreenStack3 = createStackForShouldBeVisibleTest( |
| 455 | mDefaultDisplay, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, |
| 456 | true /* onTop */); |
| 457 | final TestActivityStack fullscreenStack4 = createStackForShouldBeVisibleTest( |
| 458 | mDefaultDisplay, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, |
| 459 | true /* onTop */); |
| 460 | final TestActivityStack homeStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 461 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); |
| 462 | |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 463 | mDefaultDisplay.moveStackBehindStack(homeStack, fullscreenStack1); |
| 464 | assertTrue(mDefaultDisplay.getStackAbove(homeStack) == fullscreenStack1); |
| 465 | mDefaultDisplay.moveStackBehindStack(homeStack, fullscreenStack2); |
| 466 | assertTrue(mDefaultDisplay.getStackAbove(homeStack) == fullscreenStack2); |
| 467 | mDefaultDisplay.moveStackBehindStack(homeStack, fullscreenStack4); |
| 468 | assertTrue(mDefaultDisplay.getStackAbove(homeStack) == fullscreenStack4); |
| 469 | mDefaultDisplay.moveStackBehindStack(homeStack, fullscreenStack2); |
| 470 | assertTrue(mDefaultDisplay.getStackAbove(homeStack) == fullscreenStack2); |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 471 | } |
| 472 | |
Wale Ogunwale | bb28587 | 2018-03-01 13:05:30 -0800 | [diff] [blame] | 473 | @Test |
Kazuki Takise | f85197b | 2018-06-18 18:18:36 +0900 | [diff] [blame] | 474 | public void testSetAlwaysOnTop() { |
| 475 | final TestActivityStack homeStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
| 476 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); |
| 477 | final ActivityStack pinnedStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
| 478 | WINDOWING_MODE_PINNED, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 479 | assertTrue(mDefaultDisplay.getStackAbove(homeStack) == pinnedStack); |
| 480 | |
| 481 | final TestActivityStack alwaysOnTopStack = createStackForShouldBeVisibleTest( |
| 482 | mDefaultDisplay, WINDOWING_MODE_FREEFORM, ACTIVITY_TYPE_STANDARD, |
| 483 | true /* onTop */); |
| 484 | alwaysOnTopStack.setAlwaysOnTop(true); |
| 485 | assertTrue(alwaysOnTopStack.isAlwaysOnTop()); |
| 486 | // Ensure (non-pinned) always on top stack is put below pinned stack. |
| 487 | assertTrue(mDefaultDisplay.getStackAbove(alwaysOnTopStack) == pinnedStack); |
| 488 | |
| 489 | final TestActivityStack nonAlwaysOnTopStack = createStackForShouldBeVisibleTest( |
| 490 | mDefaultDisplay, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, |
| 491 | true /* onTop */); |
| 492 | // Ensure non always on top stack is put below always on top stacks. |
| 493 | assertTrue(mDefaultDisplay.getStackAbove(nonAlwaysOnTopStack) == alwaysOnTopStack); |
| 494 | |
| 495 | final TestActivityStack alwaysOnTopStack2 = createStackForShouldBeVisibleTest( |
| 496 | mDefaultDisplay, WINDOWING_MODE_FREEFORM, ACTIVITY_TYPE_STANDARD, |
| 497 | true /* onTop */); |
| 498 | alwaysOnTopStack2.setAlwaysOnTop(true); |
| 499 | assertTrue(alwaysOnTopStack2.isAlwaysOnTop()); |
| 500 | // Ensure newly created always on top stack is placed above other all always on top stacks. |
| 501 | assertTrue(mDefaultDisplay.getStackAbove(alwaysOnTopStack2) == pinnedStack); |
| 502 | |
| 503 | alwaysOnTopStack2.setAlwaysOnTop(false); |
| 504 | // Ensure, when always on top is turned off for a stack, the stack is put just below all |
| 505 | // other always on top stacks. |
| 506 | assertTrue(mDefaultDisplay.getStackAbove(alwaysOnTopStack2) == alwaysOnTopStack); |
Kazuki Takise | 048e266 | 2018-06-27 17:05:11 +0900 | [diff] [blame] | 507 | alwaysOnTopStack2.setAlwaysOnTop(true); |
| 508 | |
| 509 | // Ensure always on top state changes properly when windowing mode changes. |
| 510 | alwaysOnTopStack2.setWindowingMode(WINDOWING_MODE_FULLSCREEN); |
| 511 | assertFalse(alwaysOnTopStack2.isAlwaysOnTop()); |
| 512 | assertTrue(mDefaultDisplay.getStackAbove(alwaysOnTopStack2) == alwaysOnTopStack); |
| 513 | alwaysOnTopStack2.setWindowingMode(WINDOWING_MODE_FREEFORM); |
| 514 | assertTrue(alwaysOnTopStack2.isAlwaysOnTop()); |
| 515 | assertTrue(mDefaultDisplay.getStackAbove(alwaysOnTopStack2) == pinnedStack); |
Kazuki Takise | f85197b | 2018-06-18 18:18:36 +0900 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | @Test |
Wale Ogunwale | bb28587 | 2018-03-01 13:05:30 -0800 | [diff] [blame] | 519 | public void testSplitScreenMoveToFront() throws Exception { |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 520 | final TestActivityStack splitScreenPrimary = createStackForShouldBeVisibleTest( |
| 521 | mDefaultDisplay, WINDOWING_MODE_SPLIT_SCREEN_PRIMARY, ACTIVITY_TYPE_STANDARD, |
| 522 | true /* onTop */); |
| 523 | final TestActivityStack splitScreenSecondary = createStackForShouldBeVisibleTest( |
| 524 | mDefaultDisplay, WINDOWING_MODE_SPLIT_SCREEN_SECONDARY, ACTIVITY_TYPE_STANDARD, |
| 525 | true /* onTop */); |
| 526 | final TestActivityStack assistantStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Wale Ogunwale | bb28587 | 2018-03-01 13:05:30 -0800 | [diff] [blame] | 527 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_ASSISTANT, true /* onTop */); |
| 528 | |
| 529 | splitScreenPrimary.setIsTranslucent(false); |
| 530 | splitScreenSecondary.setIsTranslucent(false); |
| 531 | assistantStack.setIsTranslucent(false); |
| 532 | |
| 533 | assertFalse(splitScreenPrimary.shouldBeVisible(null /* starting */)); |
| 534 | assertFalse(splitScreenSecondary.shouldBeVisible(null /* starting */)); |
| 535 | assertTrue(assistantStack.shouldBeVisible(null /* starting */)); |
| 536 | |
| 537 | splitScreenSecondary.moveToFront("testSplitScreenMoveToFront"); |
| 538 | |
| 539 | assertTrue(splitScreenPrimary.shouldBeVisible(null /* starting */)); |
| 540 | assertTrue(splitScreenSecondary.shouldBeVisible(null /* starting */)); |
| 541 | assertFalse(assistantStack.shouldBeVisible(null /* starting */)); |
| 542 | } |
| 543 | |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 544 | private <T extends ActivityStack> T createStackForShouldBeVisibleTest( |
| 545 | ActivityDisplay display, int windowingMode, int activityType, boolean onTop) { |
Andrii Kulian | 6a6c4f1 | 2018-07-16 21:23:33 -0700 | [diff] [blame] | 546 | final T stack; |
| 547 | if (activityType == ACTIVITY_TYPE_HOME) { |
| 548 | // Home stack and activity are created in ActivityTestsBase#setupActivityManagerService |
| 549 | stack = mDefaultDisplay.getStack(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME); |
| 550 | if (onTop) { |
Riddle Hsu | 57831b5 | 2018-07-27 00:31:48 +0800 | [diff] [blame] | 551 | mDefaultDisplay.positionChildAtTop(stack, false /* includingParents */); |
Andrii Kulian | 6a6c4f1 | 2018-07-16 21:23:33 -0700 | [diff] [blame] | 552 | } else { |
| 553 | mDefaultDisplay.positionChildAtBottom(stack); |
| 554 | } |
| 555 | } else { |
| 556 | stack = display.createStack(windowingMode, activityType, onTop); |
| 557 | final ActivityRecord r = new ActivityBuilder(mService).setUid(0).setStack(stack) |
| 558 | .setCreateTask(true).build(); |
| 559 | } |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 560 | return stack; |
| 561 | } |
Bryce Lee | b0f993f | 2018-03-02 15:38:01 -0800 | [diff] [blame] | 562 | |
| 563 | @Test |
Bryce Lee | fbd263b4 | 2018-03-07 10:33:55 -0800 | [diff] [blame] | 564 | public void testFinishDisabledPackageActivities() throws Exception { |
| 565 | final ActivityRecord firstActivity = new ActivityBuilder(mService).setTask(mTask).build(); |
| 566 | final ActivityRecord secondActivity = new ActivityBuilder(mService).setTask(mTask).build(); |
| 567 | |
| 568 | // Making the second activity a task overlay without an app means it will be removed from |
| 569 | // the task's activities as well once first activity is removed. |
| 570 | secondActivity.mTaskOverlay = true; |
| 571 | secondActivity.app = null; |
| 572 | |
| 573 | assertEquals(mTask.mActivities.size(), 2); |
| 574 | |
| 575 | mStack.finishDisabledPackageActivitiesLocked(firstActivity.packageName, null, |
| 576 | true /* doit */, true /* evenPersistent */, UserHandle.USER_ALL); |
| 577 | |
| 578 | assertTrue(mTask.mActivities.isEmpty()); |
| 579 | assertTrue(mStack.getAllTasks().isEmpty()); |
| 580 | } |
| 581 | |
| 582 | @Test |
| 583 | public void testHandleAppDied() throws Exception { |
| 584 | final ActivityRecord firstActivity = new ActivityBuilder(mService).setTask(mTask).build(); |
| 585 | final ActivityRecord secondActivity = new ActivityBuilder(mService).setTask(mTask).build(); |
| 586 | |
| 587 | // Making the first activity a task overlay means it will be removed from the task's |
| 588 | // activities as well once second activity is removed as handleAppDied processes the |
| 589 | // activity list in reverse. |
| 590 | firstActivity.mTaskOverlay = true; |
| 591 | firstActivity.app = null; |
| 592 | |
| 593 | // second activity will be immediately removed as it has no state. |
| 594 | secondActivity.haveState = false; |
| 595 | |
| 596 | assertEquals(mTask.mActivities.size(), 2); |
| 597 | |
| 598 | mStack.handleAppDiedLocked(secondActivity.app); |
| 599 | |
| 600 | assertTrue(mTask.mActivities.isEmpty()); |
| 601 | assertTrue(mStack.getAllTasks().isEmpty()); |
| 602 | } |
Bryce Lee | 271617a | 2018-03-15 10:39:12 -0700 | [diff] [blame] | 603 | |
| 604 | @Test |
| 605 | public void testShouldSleepActivities() throws Exception { |
| 606 | // When focused activity and keyguard is going away, we should not sleep regardless |
| 607 | // of the display state |
| 608 | verifyShouldSleepActivities(true /* focusedStack */, true /*keyguardGoingAway*/, |
| 609 | true /* displaySleeping */, false /* expected*/); |
| 610 | |
| 611 | // When not the focused stack, defer to display sleeping state. |
| 612 | verifyShouldSleepActivities(false /* focusedStack */, true /*keyguardGoingAway*/, |
| 613 | true /* displaySleeping */, true /* expected*/); |
| 614 | |
| 615 | // If keyguard is going away, defer to the display sleeping state. |
| 616 | verifyShouldSleepActivities(true /* focusedStack */, false /*keyguardGoingAway*/, |
| 617 | true /* displaySleeping */, true /* expected*/); |
| 618 | verifyShouldSleepActivities(true /* focusedStack */, false /*keyguardGoingAway*/, |
| 619 | false /* displaySleeping */, false /* expected*/); |
| 620 | } |
| 621 | |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 622 | @Test |
| 623 | public void testStackOrderChangedOnRemoveStack() throws Exception { |
| 624 | StackOrderChangedListener listener = new StackOrderChangedListener(); |
| 625 | mDefaultDisplay.registerStackOrderChangedListener(listener); |
| 626 | try { |
| 627 | mDefaultDisplay.removeChild(mStack); |
| 628 | } finally { |
| 629 | mDefaultDisplay.unregisterStackOrderChangedListener(listener); |
| 630 | } |
| 631 | assertTrue(listener.changed); |
| 632 | } |
| 633 | |
| 634 | @Test |
| 635 | public void testStackOrderChangedOnAddPositionStack() throws Exception { |
| 636 | mDefaultDisplay.removeChild(mStack); |
| 637 | |
| 638 | StackOrderChangedListener listener = new StackOrderChangedListener(); |
| 639 | mDefaultDisplay.registerStackOrderChangedListener(listener); |
| 640 | try { |
| 641 | mDefaultDisplay.addChild(mStack, 0); |
| 642 | } finally { |
| 643 | mDefaultDisplay.unregisterStackOrderChangedListener(listener); |
| 644 | } |
| 645 | assertTrue(listener.changed); |
| 646 | } |
| 647 | |
| 648 | @Test |
| 649 | public void testStackOrderChangedOnPositionStack() throws Exception { |
| 650 | StackOrderChangedListener listener = new StackOrderChangedListener(); |
| 651 | try { |
| 652 | final TestActivityStack fullscreenStack1 = createStackForShouldBeVisibleTest( |
| 653 | mDefaultDisplay, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, |
| 654 | true /* onTop */); |
| 655 | mDefaultDisplay.registerStackOrderChangedListener(listener); |
| 656 | mDefaultDisplay.positionChildAtBottom(fullscreenStack1); |
| 657 | } finally { |
| 658 | mDefaultDisplay.unregisterStackOrderChangedListener(listener); |
| 659 | } |
| 660 | assertTrue(listener.changed); |
| 661 | } |
| 662 | |
Bryce Lee | 271617a | 2018-03-15 10:39:12 -0700 | [diff] [blame] | 663 | private void verifyShouldSleepActivities(boolean focusedStack, |
| 664 | boolean keyguardGoingAway, boolean displaySleeping, boolean expected) { |
Bryce Lee | 271617a | 2018-03-15 10:39:12 -0700 | [diff] [blame] | 665 | final ActivityDisplay display = mock(ActivityDisplay.class); |
| 666 | final KeyguardController keyguardController = mSupervisor.getKeyguardController(); |
| 667 | |
| 668 | doReturn(display).when(mSupervisor).getActivityDisplay(anyInt()); |
| 669 | doReturn(keyguardGoingAway).when(keyguardController).isKeyguardGoingAway(); |
| 670 | doReturn(displaySleeping).when(display).isSleeping(); |
Andrii Kulian | 6a6c4f1 | 2018-07-16 21:23:33 -0700 | [diff] [blame] | 671 | doReturn(focusedStack ? mStack : null).when(mSupervisor).getTopDisplayFocusedStack(); |
Bryce Lee | 271617a | 2018-03-15 10:39:12 -0700 | [diff] [blame] | 672 | |
| 673 | assertEquals(expected, mStack.shouldSleepActivities()); |
| 674 | } |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 675 | |
| 676 | private class StackOrderChangedListener implements ActivityDisplay.OnStackOrderChangedListener { |
| 677 | boolean changed = false; |
| 678 | |
| 679 | @Override |
| 680 | public void onStackOrderChanged() { |
| 681 | changed = true; |
| 682 | } |
| 683 | } |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 684 | } |