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