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