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 | e10cea5 | 2018-10-16 23:33:23 +0800 | [diff] [blame^] | 41 | import static org.mockito.ArgumentMatchers.anyBoolean; |
| 42 | import static org.mockito.ArgumentMatchers.anyInt; |
| 43 | import static org.mockito.ArgumentMatchers.anyString; |
| 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 |
| 256 | public void testShouldBeVisible_Fullscreen() throws Exception { |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 257 | final TestActivityStack homeStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 258 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 259 | final ActivityStack pinnedStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 260 | WINDOWING_MODE_PINNED, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 261 | |
| 262 | assertTrue(homeStack.shouldBeVisible(null /* starting */)); |
| 263 | assertTrue(pinnedStack.shouldBeVisible(null /* starting */)); |
| 264 | |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 265 | final TestActivityStack fullscreenStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 266 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 267 | // Home stack shouldn't be visible behind an opaque fullscreen stack, but pinned stack |
| 268 | // should be visible since it is always on-top. |
| 269 | fullscreenStack.setIsTranslucent(false); |
| 270 | assertFalse(homeStack.shouldBeVisible(null /* starting */)); |
| 271 | assertTrue(pinnedStack.shouldBeVisible(null /* starting */)); |
| 272 | assertTrue(fullscreenStack.shouldBeVisible(null /* starting */)); |
| 273 | |
| 274 | // Home stack should be visible behind a translucent fullscreen stack. |
| 275 | fullscreenStack.setIsTranslucent(true); |
| 276 | assertTrue(homeStack.shouldBeVisible(null /* starting */)); |
| 277 | assertTrue(pinnedStack.shouldBeVisible(null /* starting */)); |
| 278 | } |
| 279 | |
| 280 | @Test |
| 281 | public void testShouldBeVisible_SplitScreen() throws Exception { |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 282 | final TestActivityStack homeStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 283 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 284 | // Home stack should always be fullscreen for this test. |
| 285 | homeStack.setSupportsSplitScreen(false); |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 286 | final TestActivityStack splitScreenPrimary = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 287 | WINDOWING_MODE_SPLIT_SCREEN_PRIMARY, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 288 | final TestActivityStack splitScreenSecondary = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 289 | WINDOWING_MODE_SPLIT_SCREEN_SECONDARY, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 290 | |
| 291 | // Home stack shouldn't be visible if both halves of split-screen are opaque. |
| 292 | splitScreenPrimary.setIsTranslucent(false); |
| 293 | splitScreenSecondary.setIsTranslucent(false); |
| 294 | assertFalse(homeStack.shouldBeVisible(null /* starting */)); |
| 295 | assertTrue(splitScreenPrimary.shouldBeVisible(null /* starting */)); |
| 296 | assertTrue(splitScreenSecondary.shouldBeVisible(null /* starting */)); |
| 297 | |
| 298 | // Home stack should be visible if one of the halves of split-screen is translucent. |
| 299 | splitScreenPrimary.setIsTranslucent(true); |
| 300 | assertTrue(homeStack.shouldBeVisible(null /* starting */)); |
| 301 | assertTrue(splitScreenPrimary.shouldBeVisible(null /* starting */)); |
| 302 | assertTrue(splitScreenSecondary.shouldBeVisible(null /* starting */)); |
| 303 | |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 304 | final TestActivityStack splitScreenSecondary2 = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 305 | WINDOWING_MODE_SPLIT_SCREEN_SECONDARY, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 306 | // First split-screen secondary shouldn't be visible behind another opaque split-split |
| 307 | // secondary. |
| 308 | splitScreenSecondary2.setIsTranslucent(false); |
| 309 | assertFalse(splitScreenSecondary.shouldBeVisible(null /* starting */)); |
| 310 | assertTrue(splitScreenSecondary2.shouldBeVisible(null /* starting */)); |
| 311 | |
Wale Ogunwale | 8e923af | 2018-03-23 08:48:11 -0700 | [diff] [blame] | 312 | // First split-screen secondary should be visible behind another translucent split-screen |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 313 | // secondary. |
| 314 | splitScreenSecondary2.setIsTranslucent(true); |
| 315 | assertTrue(splitScreenSecondary.shouldBeVisible(null /* starting */)); |
| 316 | assertTrue(splitScreenSecondary2.shouldBeVisible(null /* starting */)); |
| 317 | |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 318 | final TestActivityStack assistantStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 319 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_ASSISTANT, true /* onTop */); |
| 320 | |
| 321 | // Split-screen stacks shouldn't be visible behind an opaque fullscreen stack. |
| 322 | assistantStack.setIsTranslucent(false); |
| 323 | assertTrue(assistantStack.shouldBeVisible(null /* starting */)); |
| 324 | assertFalse(splitScreenPrimary.shouldBeVisible(null /* starting */)); |
| 325 | assertFalse(splitScreenSecondary.shouldBeVisible(null /* starting */)); |
| 326 | assertFalse(splitScreenSecondary2.shouldBeVisible(null /* starting */)); |
| 327 | |
| 328 | // Split-screen stacks should be visible behind a translucent fullscreen stack. |
| 329 | assistantStack.setIsTranslucent(true); |
| 330 | assertTrue(assistantStack.shouldBeVisible(null /* starting */)); |
| 331 | assertTrue(splitScreenPrimary.shouldBeVisible(null /* starting */)); |
| 332 | assertTrue(splitScreenSecondary.shouldBeVisible(null /* starting */)); |
| 333 | assertTrue(splitScreenSecondary2.shouldBeVisible(null /* starting */)); |
Wale Ogunwale | 8e923af | 2018-03-23 08:48:11 -0700 | [diff] [blame] | 334 | |
| 335 | // Assistant stack shouldn't be visible behind translucent split-screen stack |
| 336 | assistantStack.setIsTranslucent(false); |
| 337 | splitScreenPrimary.setIsTranslucent(true); |
| 338 | splitScreenSecondary2.setIsTranslucent(true); |
| 339 | splitScreenSecondary2.moveToFront("testShouldBeVisible_SplitScreen"); |
| 340 | splitScreenPrimary.moveToFront("testShouldBeVisible_SplitScreen"); |
| 341 | assertFalse(assistantStack.shouldBeVisible(null /* starting */)); |
| 342 | assertTrue(splitScreenPrimary.shouldBeVisible(null /* starting */)); |
| 343 | assertTrue(splitScreenSecondary2.shouldBeVisible(null /* starting */)); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | @Test |
| 347 | public void testShouldBeVisible_Finishing() throws Exception { |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 348 | final TestActivityStack homeStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 349 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 350 | final TestActivityStack translucentStack = createStackForShouldBeVisibleTest( |
| 351 | mDefaultDisplay, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, |
| 352 | true /* onTop */); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 353 | translucentStack.setIsTranslucent(true); |
| 354 | |
| 355 | assertTrue(homeStack.shouldBeVisible(null /* starting */)); |
| 356 | assertTrue(translucentStack.shouldBeVisible(null /* starting */)); |
| 357 | |
| 358 | final ActivityRecord topRunningHomeActivity = homeStack.topRunningActivityLocked(); |
| 359 | topRunningHomeActivity.finishing = true; |
| 360 | final ActivityRecord topRunningTranslucentActivity = |
| 361 | translucentStack.topRunningActivityLocked(); |
| 362 | topRunningTranslucentActivity.finishing = true; |
| 363 | |
| 364 | // Home shouldn't be visible since its activity is marked as finishing and it isn't the top |
| 365 | // of the stack list. |
| 366 | assertFalse(homeStack.shouldBeVisible(null /* starting */)); |
| 367 | // Home should be visible if we are starting an activity within it. |
| 368 | assertTrue(homeStack.shouldBeVisible(topRunningHomeActivity /* starting */)); |
| 369 | // The translucent stack should be visible since it is the top of the stack list even though |
| 370 | // it has its activity marked as finishing. |
| 371 | assertTrue(translucentStack.shouldBeVisible(null /* starting */)); |
| 372 | } |
| 373 | |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 374 | @Test |
| 375 | public void testMoveHomeStackBehindBottomMostVisibleStack_NoMoveHomeBehindFullscreen() { |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 376 | mDefaultDisplay.removeChild(mStack); |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 377 | |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 378 | final TestActivityStack homeStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 379 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 380 | final TestActivityStack fullscreenStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 381 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 382 | |
| 383 | homeStack.setIsTranslucent(false); |
| 384 | fullscreenStack.setIsTranslucent(false); |
| 385 | |
| 386 | // 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] | 387 | int homeStackIndex = mDefaultDisplay.getIndexOf(homeStack); |
| 388 | assertTrue(mDefaultDisplay.getStackAbove(homeStack) == fullscreenStack); |
| 389 | mDefaultDisplay.moveStackBehindBottomMostVisibleStack(homeStack); |
| 390 | assertTrue(mDefaultDisplay.getIndexOf(homeStack) == homeStackIndex); |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | @Test |
| 394 | public void testMoveHomeStackBehindBottomMostVisibleStack_NoMoveHomeBehindTranslucent() { |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 395 | mDefaultDisplay.removeChild(mStack); |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 396 | |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 397 | final TestActivityStack homeStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 398 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 399 | final TestActivityStack fullscreenStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 400 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 401 | |
| 402 | homeStack.setIsTranslucent(false); |
| 403 | fullscreenStack.setIsTranslucent(true); |
| 404 | |
| 405 | // 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] | 406 | int homeStackIndex = mDefaultDisplay.getIndexOf(homeStack); |
| 407 | assertTrue(mDefaultDisplay.getStackAbove(homeStack) == fullscreenStack); |
| 408 | mDefaultDisplay.moveStackBehindBottomMostVisibleStack(homeStack); |
| 409 | assertTrue(mDefaultDisplay.getIndexOf(homeStack) == homeStackIndex); |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | @Test |
| 413 | public void testMoveHomeStackBehindBottomMostVisibleStack_NoMoveHomeOnTop() { |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 414 | mDefaultDisplay.removeChild(mStack); |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 415 | |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 416 | final TestActivityStack fullscreenStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 417 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 418 | final TestActivityStack homeStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 419 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); |
| 420 | |
| 421 | homeStack.setIsTranslucent(false); |
| 422 | fullscreenStack.setIsTranslucent(false); |
| 423 | |
| 424 | // 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] | 425 | int homeStackIndex = mDefaultDisplay.getIndexOf(homeStack); |
| 426 | assertTrue(mDefaultDisplay.getStackAbove(homeStack) == null); |
| 427 | mDefaultDisplay.moveStackBehindBottomMostVisibleStack(homeStack); |
| 428 | assertTrue(mDefaultDisplay.getIndexOf(homeStack) == homeStackIndex); |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | @Test |
| 432 | public void testMoveHomeStackBehindBottomMostVisibleStack_MoveHomeBehindFullscreen() { |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 433 | mDefaultDisplay.removeChild(mStack); |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 434 | |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 435 | final TestActivityStack homeStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 436 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 437 | final TestActivityStack fullscreenStack1 = createStackForShouldBeVisibleTest( |
| 438 | mDefaultDisplay, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, |
| 439 | true /* onTop */); |
| 440 | final TestActivityStack fullscreenStack2 = createStackForShouldBeVisibleTest( |
| 441 | mDefaultDisplay, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, |
| 442 | true /* onTop */); |
| 443 | final TestActivityStack pinnedStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 444 | WINDOWING_MODE_PINNED, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 445 | |
| 446 | homeStack.setIsTranslucent(false); |
| 447 | fullscreenStack1.setIsTranslucent(false); |
| 448 | fullscreenStack2.setIsTranslucent(false); |
| 449 | |
| 450 | // Ensure that we move the home stack behind the bottom most fullscreen stack, ignoring the |
| 451 | // pinned stack |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 452 | assertTrue(mDefaultDisplay.getStackAbove(homeStack) == fullscreenStack1); |
| 453 | mDefaultDisplay.moveStackBehindBottomMostVisibleStack(homeStack); |
| 454 | assertTrue(mDefaultDisplay.getStackAbove(homeStack) == fullscreenStack2); |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | @Test |
| 458 | public void testMoveHomeStackBehindBottomMostVisibleStack_MoveHomeBehindFullscreenAndTranslucent() { |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 459 | mDefaultDisplay.removeChild(mStack); |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 460 | |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 461 | final TestActivityStack homeStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 462 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 463 | final TestActivityStack fullscreenStack1 = createStackForShouldBeVisibleTest( |
| 464 | mDefaultDisplay, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, |
| 465 | true /* onTop */); |
| 466 | final TestActivityStack fullscreenStack2 = createStackForShouldBeVisibleTest( |
| 467 | mDefaultDisplay, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, |
| 468 | true /* onTop */); |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 469 | |
| 470 | homeStack.setIsTranslucent(false); |
| 471 | fullscreenStack1.setIsTranslucent(false); |
| 472 | fullscreenStack2.setIsTranslucent(true); |
| 473 | |
| 474 | // Ensure that we move the home stack behind the bottom most non-translucent fullscreen |
| 475 | // stack |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 476 | assertTrue(mDefaultDisplay.getStackAbove(homeStack) == fullscreenStack1); |
| 477 | mDefaultDisplay.moveStackBehindBottomMostVisibleStack(homeStack); |
| 478 | assertTrue(mDefaultDisplay.getStackAbove(homeStack) == fullscreenStack1); |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | @Test |
| 482 | public void testMoveHomeStackBehindStack_BehindHomeStack() { |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 483 | mDefaultDisplay.removeChild(mStack); |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 484 | |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 485 | final TestActivityStack fullscreenStack1 = createStackForShouldBeVisibleTest( |
| 486 | mDefaultDisplay, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, |
| 487 | true /* onTop */); |
| 488 | final TestActivityStack fullscreenStack2 = createStackForShouldBeVisibleTest( |
| 489 | mDefaultDisplay, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, |
| 490 | true /* onTop */); |
| 491 | final TestActivityStack homeStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 492 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); |
| 493 | |
| 494 | homeStack.setIsTranslucent(false); |
| 495 | fullscreenStack1.setIsTranslucent(false); |
| 496 | fullscreenStack2.setIsTranslucent(false); |
| 497 | |
| 498 | // Ensure we don't move the home stack behind itself |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 499 | int homeStackIndex = mDefaultDisplay.getIndexOf(homeStack); |
| 500 | mDefaultDisplay.moveStackBehindStack(homeStack, homeStack); |
| 501 | assertTrue(mDefaultDisplay.getIndexOf(homeStack) == homeStackIndex); |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | @Test |
| 505 | public void testMoveHomeStackBehindStack() { |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 506 | mDefaultDisplay.removeChild(mStack); |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 507 | |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 508 | final TestActivityStack fullscreenStack1 = createStackForShouldBeVisibleTest( |
| 509 | mDefaultDisplay, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, |
| 510 | true /* onTop */); |
| 511 | final TestActivityStack fullscreenStack2 = createStackForShouldBeVisibleTest( |
| 512 | mDefaultDisplay, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, |
| 513 | true /* onTop */); |
| 514 | final TestActivityStack fullscreenStack3 = createStackForShouldBeVisibleTest( |
| 515 | mDefaultDisplay, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, |
| 516 | true /* onTop */); |
| 517 | final TestActivityStack fullscreenStack4 = createStackForShouldBeVisibleTest( |
| 518 | mDefaultDisplay, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, |
| 519 | true /* onTop */); |
| 520 | final TestActivityStack homeStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 521 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); |
| 522 | |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 523 | mDefaultDisplay.moveStackBehindStack(homeStack, fullscreenStack1); |
| 524 | assertTrue(mDefaultDisplay.getStackAbove(homeStack) == fullscreenStack1); |
| 525 | mDefaultDisplay.moveStackBehindStack(homeStack, fullscreenStack2); |
| 526 | assertTrue(mDefaultDisplay.getStackAbove(homeStack) == fullscreenStack2); |
| 527 | mDefaultDisplay.moveStackBehindStack(homeStack, fullscreenStack4); |
| 528 | assertTrue(mDefaultDisplay.getStackAbove(homeStack) == fullscreenStack4); |
| 529 | mDefaultDisplay.moveStackBehindStack(homeStack, fullscreenStack2); |
| 530 | assertTrue(mDefaultDisplay.getStackAbove(homeStack) == fullscreenStack2); |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 531 | } |
| 532 | |
Wale Ogunwale | bb28587 | 2018-03-01 13:05:30 -0800 | [diff] [blame] | 533 | @Test |
Kazuki Takise | f85197b | 2018-06-18 18:18:36 +0900 | [diff] [blame] | 534 | public void testSetAlwaysOnTop() { |
| 535 | final TestActivityStack homeStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
| 536 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); |
| 537 | final ActivityStack pinnedStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
| 538 | WINDOWING_MODE_PINNED, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 539 | assertTrue(mDefaultDisplay.getStackAbove(homeStack) == pinnedStack); |
| 540 | |
| 541 | final TestActivityStack alwaysOnTopStack = createStackForShouldBeVisibleTest( |
| 542 | mDefaultDisplay, WINDOWING_MODE_FREEFORM, ACTIVITY_TYPE_STANDARD, |
| 543 | true /* onTop */); |
| 544 | alwaysOnTopStack.setAlwaysOnTop(true); |
| 545 | assertTrue(alwaysOnTopStack.isAlwaysOnTop()); |
| 546 | // Ensure (non-pinned) always on top stack is put below pinned stack. |
| 547 | assertTrue(mDefaultDisplay.getStackAbove(alwaysOnTopStack) == pinnedStack); |
| 548 | |
| 549 | final TestActivityStack nonAlwaysOnTopStack = createStackForShouldBeVisibleTest( |
| 550 | mDefaultDisplay, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, |
| 551 | true /* onTop */); |
| 552 | // Ensure non always on top stack is put below always on top stacks. |
| 553 | assertTrue(mDefaultDisplay.getStackAbove(nonAlwaysOnTopStack) == alwaysOnTopStack); |
| 554 | |
| 555 | final TestActivityStack alwaysOnTopStack2 = createStackForShouldBeVisibleTest( |
| 556 | mDefaultDisplay, WINDOWING_MODE_FREEFORM, ACTIVITY_TYPE_STANDARD, |
| 557 | true /* onTop */); |
| 558 | alwaysOnTopStack2.setAlwaysOnTop(true); |
| 559 | assertTrue(alwaysOnTopStack2.isAlwaysOnTop()); |
| 560 | // Ensure newly created always on top stack is placed above other all always on top stacks. |
| 561 | assertTrue(mDefaultDisplay.getStackAbove(alwaysOnTopStack2) == pinnedStack); |
| 562 | |
| 563 | alwaysOnTopStack2.setAlwaysOnTop(false); |
| 564 | // Ensure, when always on top is turned off for a stack, the stack is put just below all |
| 565 | // other always on top stacks. |
| 566 | assertTrue(mDefaultDisplay.getStackAbove(alwaysOnTopStack2) == alwaysOnTopStack); |
Kazuki Takise | 048e266 | 2018-06-27 17:05:11 +0900 | [diff] [blame] | 567 | alwaysOnTopStack2.setAlwaysOnTop(true); |
| 568 | |
| 569 | // Ensure always on top state changes properly when windowing mode changes. |
| 570 | alwaysOnTopStack2.setWindowingMode(WINDOWING_MODE_FULLSCREEN); |
| 571 | assertFalse(alwaysOnTopStack2.isAlwaysOnTop()); |
| 572 | assertTrue(mDefaultDisplay.getStackAbove(alwaysOnTopStack2) == alwaysOnTopStack); |
| 573 | alwaysOnTopStack2.setWindowingMode(WINDOWING_MODE_FREEFORM); |
| 574 | assertTrue(alwaysOnTopStack2.isAlwaysOnTop()); |
| 575 | assertTrue(mDefaultDisplay.getStackAbove(alwaysOnTopStack2) == pinnedStack); |
Kazuki Takise | f85197b | 2018-06-18 18:18:36 +0900 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | @Test |
Wale Ogunwale | bb28587 | 2018-03-01 13:05:30 -0800 | [diff] [blame] | 579 | public void testSplitScreenMoveToFront() throws Exception { |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 580 | final TestActivityStack splitScreenPrimary = createStackForShouldBeVisibleTest( |
| 581 | mDefaultDisplay, WINDOWING_MODE_SPLIT_SCREEN_PRIMARY, ACTIVITY_TYPE_STANDARD, |
| 582 | true /* onTop */); |
| 583 | final TestActivityStack splitScreenSecondary = createStackForShouldBeVisibleTest( |
| 584 | mDefaultDisplay, WINDOWING_MODE_SPLIT_SCREEN_SECONDARY, ACTIVITY_TYPE_STANDARD, |
| 585 | true /* onTop */); |
| 586 | final TestActivityStack assistantStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Wale Ogunwale | bb28587 | 2018-03-01 13:05:30 -0800 | [diff] [blame] | 587 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_ASSISTANT, true /* onTop */); |
| 588 | |
| 589 | splitScreenPrimary.setIsTranslucent(false); |
| 590 | splitScreenSecondary.setIsTranslucent(false); |
| 591 | assistantStack.setIsTranslucent(false); |
| 592 | |
| 593 | assertFalse(splitScreenPrimary.shouldBeVisible(null /* starting */)); |
| 594 | assertFalse(splitScreenSecondary.shouldBeVisible(null /* starting */)); |
| 595 | assertTrue(assistantStack.shouldBeVisible(null /* starting */)); |
| 596 | |
| 597 | splitScreenSecondary.moveToFront("testSplitScreenMoveToFront"); |
| 598 | |
| 599 | assertTrue(splitScreenPrimary.shouldBeVisible(null /* starting */)); |
| 600 | assertTrue(splitScreenSecondary.shouldBeVisible(null /* starting */)); |
| 601 | assertFalse(assistantStack.shouldBeVisible(null /* starting */)); |
| 602 | } |
| 603 | |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 604 | private <T extends ActivityStack> T createStackForShouldBeVisibleTest( |
| 605 | ActivityDisplay display, int windowingMode, int activityType, boolean onTop) { |
Andrii Kulian | 6a6c4f1 | 2018-07-16 21:23:33 -0700 | [diff] [blame] | 606 | final T stack; |
| 607 | if (activityType == ACTIVITY_TYPE_HOME) { |
| 608 | // Home stack and activity are created in ActivityTestsBase#setupActivityManagerService |
| 609 | stack = mDefaultDisplay.getStack(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME); |
| 610 | if (onTop) { |
Riddle Hsu | 57831b5 | 2018-07-27 00:31:48 +0800 | [diff] [blame] | 611 | mDefaultDisplay.positionChildAtTop(stack, false /* includingParents */); |
Andrii Kulian | 6a6c4f1 | 2018-07-16 21:23:33 -0700 | [diff] [blame] | 612 | } else { |
| 613 | mDefaultDisplay.positionChildAtBottom(stack); |
| 614 | } |
| 615 | } else { |
| 616 | stack = display.createStack(windowingMode, activityType, onTop); |
| 617 | final ActivityRecord r = new ActivityBuilder(mService).setUid(0).setStack(stack) |
| 618 | .setCreateTask(true).build(); |
| 619 | } |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 620 | return stack; |
| 621 | } |
Bryce Lee | b0f993f | 2018-03-02 15:38:01 -0800 | [diff] [blame] | 622 | |
| 623 | @Test |
Bryce Lee | fbd263b4 | 2018-03-07 10:33:55 -0800 | [diff] [blame] | 624 | public void testFinishDisabledPackageActivities() throws Exception { |
| 625 | final ActivityRecord firstActivity = new ActivityBuilder(mService).setTask(mTask).build(); |
| 626 | final ActivityRecord secondActivity = new ActivityBuilder(mService).setTask(mTask).build(); |
| 627 | |
| 628 | // Making the second activity a task overlay without an app means it will be removed from |
| 629 | // the task's activities as well once first activity is removed. |
| 630 | secondActivity.mTaskOverlay = true; |
| 631 | secondActivity.app = null; |
| 632 | |
| 633 | assertEquals(mTask.mActivities.size(), 2); |
| 634 | |
| 635 | mStack.finishDisabledPackageActivitiesLocked(firstActivity.packageName, null, |
| 636 | true /* doit */, true /* evenPersistent */, UserHandle.USER_ALL); |
| 637 | |
| 638 | assertTrue(mTask.mActivities.isEmpty()); |
| 639 | assertTrue(mStack.getAllTasks().isEmpty()); |
| 640 | } |
| 641 | |
| 642 | @Test |
| 643 | public void testHandleAppDied() throws Exception { |
| 644 | final ActivityRecord firstActivity = new ActivityBuilder(mService).setTask(mTask).build(); |
| 645 | final ActivityRecord secondActivity = new ActivityBuilder(mService).setTask(mTask).build(); |
| 646 | |
| 647 | // Making the first activity a task overlay means it will be removed from the task's |
| 648 | // activities as well once second activity is removed as handleAppDied processes the |
| 649 | // activity list in reverse. |
| 650 | firstActivity.mTaskOverlay = true; |
| 651 | firstActivity.app = null; |
| 652 | |
| 653 | // second activity will be immediately removed as it has no state. |
| 654 | secondActivity.haveState = false; |
| 655 | |
| 656 | assertEquals(mTask.mActivities.size(), 2); |
| 657 | |
| 658 | mStack.handleAppDiedLocked(secondActivity.app); |
| 659 | |
| 660 | assertTrue(mTask.mActivities.isEmpty()); |
| 661 | assertTrue(mStack.getAllTasks().isEmpty()); |
| 662 | } |
Bryce Lee | 271617a | 2018-03-15 10:39:12 -0700 | [diff] [blame] | 663 | |
| 664 | @Test |
Riddle Hsu | e10cea5 | 2018-10-16 23:33:23 +0800 | [diff] [blame^] | 665 | public void testFinishCurrentActivity() { |
| 666 | // Create 2 activities on a new display. |
| 667 | final ActivityDisplay display = addNewActivityDisplayAt(ActivityDisplay.POSITION_TOP); |
| 668 | final ActivityStack stack1 = createStackForShouldBeVisibleTest(display, |
| 669 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 670 | final ActivityStack stack2 = createStackForShouldBeVisibleTest(display, |
| 671 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 672 | |
| 673 | // There is still an activity1 in stack1 so the activity2 should be added to finishing list |
| 674 | // that will be destroyed until idle. |
| 675 | final ActivityRecord activity2 = finishCurrentActivity(stack2); |
| 676 | assertEquals(FINISHING, activity2.getState()); |
| 677 | assertTrue(mSupervisor.mFinishingActivities.contains(activity2)); |
| 678 | |
| 679 | // The display becomes empty. Since there is no next activity to be idle, the activity |
| 680 | // should be destroyed immediately with updating configuration to restore original state. |
| 681 | final ActivityRecord activity1 = finishCurrentActivity(stack1); |
| 682 | assertEquals(DESTROYING, activity1.getState()); |
| 683 | verify(mSupervisor).ensureVisibilityAndConfig(eq(null) /* starting */, |
| 684 | eq(display.mDisplayId), anyBoolean(), anyBoolean()); |
| 685 | } |
| 686 | |
| 687 | private ActivityRecord finishCurrentActivity(ActivityStack stack) { |
| 688 | final ActivityRecord activity = stack.topRunningActivityLocked(); |
| 689 | assertNotNull(activity); |
| 690 | activity.setState(PAUSED, "finishCurrentActivity"); |
| 691 | activity.makeFinishingLocked(); |
| 692 | stack.finishCurrentActivityLocked(activity, ActivityStack.FINISH_AFTER_VISIBLE, |
| 693 | false /* oomAdj */, "finishCurrentActivity"); |
| 694 | return activity; |
| 695 | } |
| 696 | |
| 697 | @Test |
Bryce Lee | 271617a | 2018-03-15 10:39:12 -0700 | [diff] [blame] | 698 | public void testShouldSleepActivities() throws Exception { |
| 699 | // When focused activity and keyguard is going away, we should not sleep regardless |
| 700 | // of the display state |
| 701 | verifyShouldSleepActivities(true /* focusedStack */, true /*keyguardGoingAway*/, |
| 702 | true /* displaySleeping */, false /* expected*/); |
| 703 | |
| 704 | // When not the focused stack, defer to display sleeping state. |
| 705 | verifyShouldSleepActivities(false /* focusedStack */, true /*keyguardGoingAway*/, |
| 706 | true /* displaySleeping */, true /* expected*/); |
| 707 | |
| 708 | // If keyguard is going away, defer to the display sleeping state. |
| 709 | verifyShouldSleepActivities(true /* focusedStack */, false /*keyguardGoingAway*/, |
| 710 | true /* displaySleeping */, true /* expected*/); |
| 711 | verifyShouldSleepActivities(true /* focusedStack */, false /*keyguardGoingAway*/, |
| 712 | false /* displaySleeping */, false /* expected*/); |
| 713 | } |
| 714 | |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 715 | @Test |
| 716 | public void testStackOrderChangedOnRemoveStack() throws Exception { |
| 717 | StackOrderChangedListener listener = new StackOrderChangedListener(); |
| 718 | mDefaultDisplay.registerStackOrderChangedListener(listener); |
| 719 | try { |
| 720 | mDefaultDisplay.removeChild(mStack); |
| 721 | } finally { |
| 722 | mDefaultDisplay.unregisterStackOrderChangedListener(listener); |
| 723 | } |
| 724 | assertTrue(listener.changed); |
| 725 | } |
| 726 | |
| 727 | @Test |
| 728 | public void testStackOrderChangedOnAddPositionStack() throws Exception { |
| 729 | mDefaultDisplay.removeChild(mStack); |
| 730 | |
| 731 | StackOrderChangedListener listener = new StackOrderChangedListener(); |
| 732 | mDefaultDisplay.registerStackOrderChangedListener(listener); |
| 733 | try { |
| 734 | mDefaultDisplay.addChild(mStack, 0); |
| 735 | } finally { |
| 736 | mDefaultDisplay.unregisterStackOrderChangedListener(listener); |
| 737 | } |
| 738 | assertTrue(listener.changed); |
| 739 | } |
| 740 | |
| 741 | @Test |
| 742 | public void testStackOrderChangedOnPositionStack() throws Exception { |
| 743 | StackOrderChangedListener listener = new StackOrderChangedListener(); |
| 744 | try { |
| 745 | final TestActivityStack fullscreenStack1 = createStackForShouldBeVisibleTest( |
| 746 | mDefaultDisplay, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, |
| 747 | true /* onTop */); |
| 748 | mDefaultDisplay.registerStackOrderChangedListener(listener); |
| 749 | mDefaultDisplay.positionChildAtBottom(fullscreenStack1); |
| 750 | } finally { |
| 751 | mDefaultDisplay.unregisterStackOrderChangedListener(listener); |
| 752 | } |
| 753 | assertTrue(listener.changed); |
| 754 | } |
| 755 | |
Bryce Lee | 271617a | 2018-03-15 10:39:12 -0700 | [diff] [blame] | 756 | private void verifyShouldSleepActivities(boolean focusedStack, |
| 757 | boolean keyguardGoingAway, boolean displaySleeping, boolean expected) { |
Bryce Lee | 271617a | 2018-03-15 10:39:12 -0700 | [diff] [blame] | 758 | final ActivityDisplay display = mock(ActivityDisplay.class); |
| 759 | final KeyguardController keyguardController = mSupervisor.getKeyguardController(); |
| 760 | |
| 761 | doReturn(display).when(mSupervisor).getActivityDisplay(anyInt()); |
| 762 | doReturn(keyguardGoingAway).when(keyguardController).isKeyguardGoingAway(); |
| 763 | doReturn(displaySleeping).when(display).isSleeping(); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 764 | doReturn(focusedStack).when(mStack).isFocusedStackOnDisplay(); |
Bryce Lee | 271617a | 2018-03-15 10:39:12 -0700 | [diff] [blame] | 765 | |
| 766 | assertEquals(expected, mStack.shouldSleepActivities()); |
| 767 | } |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 768 | |
| 769 | private class StackOrderChangedListener implements ActivityDisplay.OnStackOrderChangedListener { |
| 770 | boolean changed = false; |
| 771 | |
| 772 | @Override |
| 773 | public void onStackOrderChanged() { |
| 774 | changed = true; |
| 775 | } |
| 776 | } |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 777 | } |