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