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; |
Louis Chang | 7b03ad9 | 2019-08-21 12:32:33 +0800 | [diff] [blame] | 28 | import static android.content.pm.ActivityInfo.FLAG_RESUME_WHILE_PAUSING; |
Bryce Lee | 18d5159 | 2017-10-25 10:22:19 -0700 | [diff] [blame] | 29 | |
Louis Chang | cfe4621 | 2019-07-30 10:34:18 +0800 | [diff] [blame] | 30 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.doNothing; |
Tadashi G. Takaoka | a7a6695 | 2018-11-16 15:04:21 +0900 | [diff] [blame] | 31 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn; |
| 32 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock; |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 33 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn; |
Tadashi G. Takaoka | a7a6695 | 2018-11-16 15:04:21 +0900 | [diff] [blame] | 34 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 35 | import static com.android.server.wm.ActivityStack.ActivityState.DESTROYING; |
wilsonshih | 8824a8a | 2019-03-12 17:21:35 +0800 | [diff] [blame] | 36 | import static com.android.server.wm.ActivityStack.ActivityState.FINISHING; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 37 | import static com.android.server.wm.ActivityStack.ActivityState.PAUSING; |
| 38 | import static com.android.server.wm.ActivityStack.ActivityState.RESUMED; |
Riddle Hsu | aaef731 | 2019-01-24 19:00:58 +0800 | [diff] [blame] | 39 | import static com.android.server.wm.ActivityStack.ActivityState.STOPPED; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 40 | import static com.android.server.wm.ActivityStack.ActivityState.STOPPING; |
| 41 | import static com.android.server.wm.ActivityStack.REMOVE_TASK_MODE_DESTROYING; |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 42 | import static com.android.server.wm.ActivityStack.STACK_VISIBILITY_INVISIBLE; |
| 43 | import static com.android.server.wm.ActivityStack.STACK_VISIBILITY_VISIBLE; |
| 44 | import static com.android.server.wm.ActivityStack.STACK_VISIBILITY_VISIBLE_BEHIND_TRANSLUCENT; |
Garfield Tan | f6cc5c9 | 2019-01-15 13:54:12 -0800 | [diff] [blame] | 45 | import static com.android.server.wm.ActivityTaskManagerService.RELAUNCH_REASON_FREE_RESIZE; |
| 46 | import static com.android.server.wm.ActivityTaskManagerService.RELAUNCH_REASON_WINDOWING_MODE_RESIZE; |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 47 | import static com.android.server.wm.TaskRecord.REPARENT_MOVE_STACK_TO_FRONT; |
Bryce Lee | 18d5159 | 2017-10-25 10:22:19 -0700 | [diff] [blame] | 48 | |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 49 | import static com.google.common.truth.Truth.assertThat; |
| 50 | |
Bryce Lee | 5daa312 | 2017-04-19 10:40:42 -0700 | [diff] [blame] | 51 | import static org.junit.Assert.assertEquals; |
David Stevens | 18abd0e | 2017-08-17 14:55:47 -0700 | [diff] [blame] | 52 | import static org.junit.Assert.assertFalse; |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 53 | import static org.junit.Assert.assertNotNull; |
| 54 | import static org.junit.Assert.assertNull; |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 55 | import static org.junit.Assert.assertTrue; |
Riddle Hsu | 138ef93 | 2018-10-26 17:12:06 +0800 | [diff] [blame] | 56 | import static org.mockito.ArgumentMatchers.any; |
Riddle Hsu | e10cea5 | 2018-10-16 23:33:23 +0800 | [diff] [blame] | 57 | import static org.mockito.ArgumentMatchers.anyBoolean; |
| 58 | import static org.mockito.ArgumentMatchers.anyInt; |
Riddle Hsu | e10cea5 | 2018-10-16 23:33:23 +0800 | [diff] [blame] | 59 | import static org.mockito.ArgumentMatchers.eq; |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 60 | |
Riddle Hsu | aaef731 | 2019-01-24 19:00:58 +0800 | [diff] [blame] | 61 | import android.content.ComponentName; |
Bryce Lee | 3345c4e | 2017-04-25 07:40:41 -0700 | [diff] [blame] | 62 | import android.content.pm.ActivityInfo; |
Bryce Lee | 9f6affd | 2017-09-01 09:18:35 -0700 | [diff] [blame] | 63 | import android.os.UserHandle; |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 64 | import android.platform.test.annotations.Presubmit; |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 65 | |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 66 | import androidx.test.filters.SmallTest; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 67 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 68 | import org.junit.Before; |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 69 | import org.junit.Test; |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame^] | 70 | import org.junit.runner.RunWith; |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 71 | |
| 72 | /** |
| 73 | * Tests for the {@link ActivityStack} class. |
| 74 | * |
| 75 | * Build/Install/Run: |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 76 | * atest WmTests:ActivityStackTests |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 77 | */ |
| 78 | @SmallTest |
| 79 | @Presubmit |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame^] | 80 | @RunWith(WindowTestRunner.class) |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 81 | public class ActivityStackTests extends ActivityTestsBase { |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 82 | private ActivityDisplay mDefaultDisplay; |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 83 | private ActivityStack mStack; |
| 84 | private TaskRecord mTask; |
| 85 | |
| 86 | @Before |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 87 | public void setUp() throws Exception { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 88 | mDefaultDisplay = mRootActivityContainer.getDefaultDisplay(); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 89 | mStack = mDefaultDisplay.createStack(WINDOWING_MODE_UNDEFINED, ACTIVITY_TYPE_STANDARD, |
| 90 | true /* onTop */); |
| 91 | spyOn(mStack); |
Bryce Lee | 18d5159 | 2017-10-25 10:22:19 -0700 | [diff] [blame] | 92 | mTask = new TaskBuilder(mSupervisor).setStack(mStack).build(); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 93 | } |
| 94 | |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 95 | @Test |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 96 | public void testEmptyTaskCleanupOnRemove() { |
Yunfan Chen | 0e7aff9 | 2018-12-05 16:35:32 -0800 | [diff] [blame] | 97 | assertNotNull(mTask.getTask()); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 98 | mStack.removeTask(mTask, "testEmptyTaskCleanupOnRemove", REMOVE_TASK_MODE_DESTROYING); |
Yunfan Chen | 0e7aff9 | 2018-12-05 16:35:32 -0800 | [diff] [blame] | 99 | assertNull(mTask.getTask()); |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 100 | } |
Bryce Lee | 5daa312 | 2017-04-19 10:40:42 -0700 | [diff] [blame] | 101 | |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 102 | @Test |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 103 | public void testOccupiedTaskCleanupOnRemove() { |
Bryce Lee | 18d5159 | 2017-10-25 10:22:19 -0700 | [diff] [blame] | 104 | final ActivityRecord r = new ActivityBuilder(mService).setTask(mTask).build(); |
Yunfan Chen | 0e7aff9 | 2018-12-05 16:35:32 -0800 | [diff] [blame] | 105 | assertNotNull(mTask.getTask()); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 106 | mStack.removeTask(mTask, "testOccupiedTaskCleanupOnRemove", REMOVE_TASK_MODE_DESTROYING); |
Yunfan Chen | 0e7aff9 | 2018-12-05 16:35:32 -0800 | [diff] [blame] | 107 | assertNotNull(mTask.getTask()); |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 108 | } |
Bryce Lee | 5daa312 | 2017-04-19 10:40:42 -0700 | [diff] [blame] | 109 | |
| 110 | @Test |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 111 | public void testResumedActivity() { |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 112 | final ActivityRecord r = new ActivityBuilder(mService).setTask(mTask).build(); |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 113 | assertNull(mStack.getResumedActivity()); |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 114 | r.setState(RESUMED, "testResumedActivity"); |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 115 | assertEquals(r, mStack.getResumedActivity()); |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 116 | r.setState(PAUSING, "testResumedActivity"); |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 117 | assertNull(mStack.getResumedActivity()); |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 118 | } |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 119 | |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 120 | @Test |
| 121 | public void testResumedActivityFromTaskReparenting() { |
| 122 | final ActivityRecord r = new ActivityBuilder(mService).setTask(mTask).build(); |
| 123 | // Ensure moving task between two stacks updates resumed activity |
| 124 | r.setState(RESUMED, "testResumedActivityFromTaskReparenting"); |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 125 | assertEquals(r, mStack.getResumedActivity()); |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 126 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 127 | final ActivityStack destStack = mRootActivityContainer.getDefaultDisplay().createStack( |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 128 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 129 | |
| 130 | mTask.reparent(destStack, true /* toTop */, TaskRecord.REPARENT_KEEP_STACK_AT_FRONT, |
| 131 | false /* animate */, true /* deferResume*/, |
| 132 | "testResumedActivityFromTaskReparenting"); |
| 133 | |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 134 | assertNull(mStack.getResumedActivity()); |
| 135 | assertEquals(r, destStack.getResumedActivity()); |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | @Test |
| 139 | public void testResumedActivityFromActivityReparenting() { |
| 140 | final ActivityRecord r = new ActivityBuilder(mService).setTask(mTask).build(); |
| 141 | // Ensure moving task between two stacks updates resumed activity |
| 142 | r.setState(RESUMED, "testResumedActivityFromActivityReparenting"); |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 143 | assertEquals(r, mStack.getResumedActivity()); |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 144 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 145 | final ActivityStack destStack = mRootActivityContainer.getDefaultDisplay().createStack( |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 146 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 147 | mTask.reparent(destStack, true /*toTop*/, REPARENT_MOVE_STACK_TO_FRONT, false, false, |
| 148 | "testResumedActivityFromActivityReparenting"); |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 149 | |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 150 | assertNull(mStack.getResumedActivity()); |
| 151 | assertEquals(r, destStack.getResumedActivity()); |
Bryce Lee | 5daa312 | 2017-04-19 10:40:42 -0700 | [diff] [blame] | 152 | } |
Bryce Lee | 3345c4e | 2017-04-25 07:40:41 -0700 | [diff] [blame] | 153 | |
| 154 | @Test |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 155 | public void testPrimarySplitScreenRestoresWhenMovedToBack() { |
Bryce Lee | 8cab4a0 | 2018-01-05 09:00:49 -0800 | [diff] [blame] | 156 | // Create primary splitscreen stack. This will create secondary stacks and places the |
| 157 | // existing fullscreen stack on the bottom. |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 158 | final ActivityStack primarySplitScreen = mDefaultDisplay.createStack( |
| 159 | WINDOWING_MODE_SPLIT_SCREEN_PRIMARY, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
Bryce Lee | 8cab4a0 | 2018-01-05 09:00:49 -0800 | [diff] [blame] | 160 | |
| 161 | // Assert windowing mode. |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 162 | assertEquals(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY, primarySplitScreen.getWindowingMode()); |
Bryce Lee | 8cab4a0 | 2018-01-05 09:00:49 -0800 | [diff] [blame] | 163 | |
| 164 | // Move primary to back. |
| 165 | primarySplitScreen.moveToBack("testPrimarySplitScreenToFullscreenWhenMovedToBack", |
| 166 | null /* task */); |
| 167 | |
| 168 | // Assert that stack is at the bottom. |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 169 | assertEquals(0, mDefaultDisplay.getIndexOf(primarySplitScreen)); |
Bryce Lee | 8cab4a0 | 2018-01-05 09:00:49 -0800 | [diff] [blame] | 170 | |
| 171 | // Ensure no longer in splitscreen. |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 172 | assertEquals(WINDOWING_MODE_FULLSCREEN, primarySplitScreen.getWindowingMode()); |
Evan Rosky | 1047574 | 2018-09-05 19:02:48 -0700 | [diff] [blame] | 173 | |
| 174 | // Ensure that the override mode is restored to undefined |
Evan Rosky | dfe3da7 | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 175 | assertEquals(WINDOWING_MODE_UNDEFINED, |
| 176 | primarySplitScreen.getRequestedOverrideWindowingMode()); |
Evan Rosky | 1047574 | 2018-09-05 19:02:48 -0700 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | @Test |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 180 | public void testPrimarySplitScreenRestoresPreviousWhenMovedToBack() { |
Evan Rosky | 1047574 | 2018-09-05 19:02:48 -0700 | [diff] [blame] | 181 | // This time, start with a fullscreen activitystack |
| 182 | final ActivityStack primarySplitScreen = mDefaultDisplay.createStack( |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 183 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
Evan Rosky | 1047574 | 2018-09-05 19:02:48 -0700 | [diff] [blame] | 184 | |
| 185 | primarySplitScreen.setWindowingMode(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY); |
| 186 | |
| 187 | // Assert windowing mode. |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 188 | assertEquals(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY, primarySplitScreen.getWindowingMode()); |
Evan Rosky | 1047574 | 2018-09-05 19:02:48 -0700 | [diff] [blame] | 189 | |
| 190 | // Move primary to back. |
| 191 | primarySplitScreen.moveToBack("testPrimarySplitScreenToFullscreenWhenMovedToBack", |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 192 | null /* task */); |
Evan Rosky | 1047574 | 2018-09-05 19:02:48 -0700 | [diff] [blame] | 193 | |
| 194 | // Assert that stack is at the bottom. |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 195 | assertEquals(0, mDefaultDisplay.getIndexOf(primarySplitScreen)); |
Evan Rosky | 1047574 | 2018-09-05 19:02:48 -0700 | [diff] [blame] | 196 | |
| 197 | // Ensure that the override mode is restored to what it was (fullscreen) |
Evan Rosky | dfe3da7 | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 198 | assertEquals(WINDOWING_MODE_FULLSCREEN, |
| 199 | primarySplitScreen.getRequestedOverrideWindowingMode()); |
Evan Rosky | 1047574 | 2018-09-05 19:02:48 -0700 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | @Test |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 203 | public void testStackInheritsDisplayWindowingMode() { |
Evan Rosky | 1047574 | 2018-09-05 19:02:48 -0700 | [diff] [blame] | 204 | final ActivityStack primarySplitScreen = mDefaultDisplay.createStack( |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 205 | WINDOWING_MODE_UNDEFINED, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
Evan Rosky | 1047574 | 2018-09-05 19:02:48 -0700 | [diff] [blame] | 206 | |
| 207 | assertEquals(WINDOWING_MODE_FULLSCREEN, primarySplitScreen.getWindowingMode()); |
Evan Rosky | dfe3da7 | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 208 | assertEquals(WINDOWING_MODE_UNDEFINED, |
| 209 | primarySplitScreen.getRequestedOverrideWindowingMode()); |
Evan Rosky | 1047574 | 2018-09-05 19:02:48 -0700 | [diff] [blame] | 210 | |
| 211 | mDefaultDisplay.setWindowingMode(WINDOWING_MODE_FREEFORM); |
| 212 | assertEquals(WINDOWING_MODE_FREEFORM, primarySplitScreen.getWindowingMode()); |
Evan Rosky | dfe3da7 | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 213 | assertEquals(WINDOWING_MODE_UNDEFINED, |
| 214 | primarySplitScreen.getRequestedOverrideWindowingMode()); |
Evan Rosky | 1047574 | 2018-09-05 19:02:48 -0700 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | @Test |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 218 | public void testStackOverridesDisplayWindowingMode() { |
Evan Rosky | 1047574 | 2018-09-05 19:02:48 -0700 | [diff] [blame] | 219 | final ActivityStack primarySplitScreen = mDefaultDisplay.createStack( |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 220 | WINDOWING_MODE_UNDEFINED, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
Evan Rosky | 1047574 | 2018-09-05 19:02:48 -0700 | [diff] [blame] | 221 | |
| 222 | assertEquals(WINDOWING_MODE_FULLSCREEN, primarySplitScreen.getWindowingMode()); |
Evan Rosky | dfe3da7 | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 223 | assertEquals(WINDOWING_MODE_UNDEFINED, |
| 224 | primarySplitScreen.getRequestedOverrideWindowingMode()); |
Evan Rosky | 1047574 | 2018-09-05 19:02:48 -0700 | [diff] [blame] | 225 | |
| 226 | primarySplitScreen.setWindowingMode(WINDOWING_MODE_FULLSCREEN); |
| 227 | // 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] | 228 | assertEquals(WINDOWING_MODE_FULLSCREEN, |
| 229 | primarySplitScreen.getRequestedOverrideWindowingMode()); |
Evan Rosky | 1047574 | 2018-09-05 19:02:48 -0700 | [diff] [blame] | 230 | |
| 231 | mDefaultDisplay.setWindowingMode(WINDOWING_MODE_FREEFORM); |
| 232 | assertEquals(WINDOWING_MODE_FULLSCREEN, primarySplitScreen.getWindowingMode()); |
Bryce Lee | 8cab4a0 | 2018-01-05 09:00:49 -0800 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | @Test |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 236 | public void testStopActivityWhenActivityDestroyed() { |
Bryce Lee | 18d5159 | 2017-10-25 10:22:19 -0700 | [diff] [blame] | 237 | final ActivityRecord r = new ActivityBuilder(mService).setTask(mTask).build(); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 238 | r.info.flags |= ActivityInfo.FLAG_NO_HISTORY; |
Andrii Kulian | 6a6c4f1 | 2018-07-16 21:23:33 -0700 | [diff] [blame] | 239 | mStack.moveToFront("testStopActivityWithDestroy"); |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 240 | r.stopIfPossible(); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 241 | // Mostly testing to make sure there is a crash in the call part, so if we get here we are |
| 242 | // good-to-go! |
Bryce Lee | 3345c4e | 2017-04-25 07:40:41 -0700 | [diff] [blame] | 243 | } |
Bryce Lee | 9f6affd | 2017-09-01 09:18:35 -0700 | [diff] [blame] | 244 | |
| 245 | @Test |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 246 | public void testFindTaskWithOverlay() { |
Bryce Lee | 18d5159 | 2017-10-25 10:22:19 -0700 | [diff] [blame] | 247 | final ActivityRecord r = new ActivityBuilder(mService) |
| 248 | .setCreateTask(true) |
| 249 | .setStack(mStack) |
| 250 | .setUid(0) |
| 251 | .build(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 252 | final TaskRecord task = r.getTaskRecord(); |
Bryce Lee | 9f6affd | 2017-09-01 09:18:35 -0700 | [diff] [blame] | 253 | // 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] | 254 | final ActivityRecord taskOverlay = new ActivityBuilder(mService).setTask(task) |
| 255 | .setUid(UserHandle.PER_USER_RANGE * 2).build(); |
Bryce Lee | 9f6affd | 2017-09-01 09:18:35 -0700 | [diff] [blame] | 256 | taskOverlay.mTaskOverlay = true; |
| 257 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 258 | final RootActivityContainer.FindTaskResult result = |
| 259 | new RootActivityContainer.FindTaskResult(); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 260 | mStack.findTaskLocked(r, result); |
Bryce Lee | 9f6affd | 2017-09-01 09:18:35 -0700 | [diff] [blame] | 261 | |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 262 | assertEquals(r, task.getTopActivity(false /* includeOverlays */)); |
| 263 | assertEquals(taskOverlay, task.getTopActivity(true /* includeOverlays */)); |
Louis Chang | c85b1a3 | 2018-08-14 16:40:53 +0800 | [diff] [blame] | 264 | assertNotNull(result.mRecord); |
Bryce Lee | 9f6affd | 2017-09-01 09:18:35 -0700 | [diff] [blame] | 265 | } |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 266 | |
| 267 | @Test |
Louis Chang | b05c8d8 | 2019-06-25 11:56:55 +0800 | [diff] [blame] | 268 | public void testFindTaskAlias() { |
| 269 | final String targetActivity = "target.activity"; |
| 270 | final String aliasActivity = "alias.activity"; |
| 271 | final ComponentName target = new ComponentName(DEFAULT_COMPONENT_PACKAGE_NAME, |
| 272 | targetActivity); |
| 273 | final ComponentName alias = new ComponentName(DEFAULT_COMPONENT_PACKAGE_NAME, |
| 274 | aliasActivity); |
| 275 | final TaskRecord task = new TaskBuilder(mService.mStackSupervisor).setStack(mStack).build(); |
| 276 | task.origActivity = alias; |
| 277 | task.realActivity = target; |
| 278 | new ActivityBuilder(mService).setComponent(target).setTask(task).setTargetActivity( |
| 279 | targetActivity).build(); |
| 280 | |
| 281 | // Using target activity to find task. |
| 282 | final ActivityRecord r1 = new ActivityBuilder(mService).setComponent( |
| 283 | target).setTargetActivity(targetActivity).build(); |
| 284 | RootActivityContainer.FindTaskResult result = new RootActivityContainer.FindTaskResult(); |
| 285 | mStack.findTaskLocked(r1, result); |
| 286 | assertThat(result.mRecord).isNotNull(); |
| 287 | |
| 288 | // Using alias activity to find task. |
| 289 | final ActivityRecord r2 = new ActivityBuilder(mService).setComponent( |
| 290 | alias).setTargetActivity(targetActivity).build(); |
| 291 | result = new RootActivityContainer.FindTaskResult(); |
| 292 | mStack.findTaskLocked(r2, result); |
| 293 | assertThat(result.mRecord).isNotNull(); |
| 294 | } |
| 295 | |
| 296 | @Test |
Riddle Hsu | 138ef93 | 2018-10-26 17:12:06 +0800 | [diff] [blame] | 297 | public void testMoveStackToBackIncludingParent() { |
| 298 | final ActivityDisplay display = addNewActivityDisplayAt(ActivityDisplay.POSITION_TOP); |
| 299 | final ActivityStack stack1 = createStackForShouldBeVisibleTest(display, |
| 300 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 301 | final ActivityStack stack2 = createStackForShouldBeVisibleTest(display, |
| 302 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 303 | |
| 304 | // Do not move display to back because there is still another stack. |
| 305 | stack2.moveToBack("testMoveStackToBackIncludingParent", stack2.topTask()); |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 306 | verify(stack2.getTaskStack()).positionChildAtBottom(any(), |
Riddle Hsu | 138ef93 | 2018-10-26 17:12:06 +0800 | [diff] [blame] | 307 | eq(false) /* includingParents */); |
| 308 | |
| 309 | // Also move display to back because there is only one stack left. |
| 310 | display.removeChild(stack1); |
| 311 | stack2.moveToBack("testMoveStackToBackIncludingParent", stack2.topTask()); |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 312 | verify(stack2.getTaskStack()).positionChildAtBottom(any(), |
Riddle Hsu | 138ef93 | 2018-10-26 17:12:06 +0800 | [diff] [blame] | 313 | eq(true) /* includingParents */); |
| 314 | } |
| 315 | |
| 316 | @Test |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 317 | public void testShouldBeVisible_Fullscreen() { |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 318 | final ActivityStack homeStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 319 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 320 | final ActivityStack pinnedStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 321 | WINDOWING_MODE_PINNED, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 322 | // Add an activity to the pinned stack so it isn't considered empty for visibility check. |
| 323 | final ActivityRecord pinnedActivity = new ActivityBuilder(mService) |
| 324 | .setCreateTask(true) |
| 325 | .setStack(pinnedStack) |
| 326 | .build(); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 327 | |
| 328 | assertTrue(homeStack.shouldBeVisible(null /* starting */)); |
| 329 | assertTrue(pinnedStack.shouldBeVisible(null /* starting */)); |
| 330 | |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 331 | final ActivityStack fullscreenStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 332 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 333 | // Home stack shouldn't be visible behind an opaque fullscreen stack, but pinned stack |
| 334 | // should be visible since it is always on-top. |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 335 | doReturn(false).when(fullscreenStack).isStackTranslucent(any()); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 336 | assertFalse(homeStack.shouldBeVisible(null /* starting */)); |
| 337 | assertTrue(pinnedStack.shouldBeVisible(null /* starting */)); |
| 338 | assertTrue(fullscreenStack.shouldBeVisible(null /* starting */)); |
| 339 | |
| 340 | // Home stack should be visible behind a translucent fullscreen stack. |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 341 | doReturn(true).when(fullscreenStack).isStackTranslucent(any()); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 342 | assertTrue(homeStack.shouldBeVisible(null /* starting */)); |
| 343 | assertTrue(pinnedStack.shouldBeVisible(null /* starting */)); |
| 344 | } |
| 345 | |
| 346 | @Test |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 347 | public void testShouldBeVisible_SplitScreen() { |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 348 | final ActivityStack homeStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 349 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 350 | // Home stack should always be fullscreen for this test. |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 351 | doReturn(false).when(homeStack).supportsSplitScreenWindowingMode(); |
| 352 | final ActivityStack splitScreenPrimary = |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 353 | createStackForShouldBeVisibleTest(mDefaultDisplay, |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 354 | WINDOWING_MODE_SPLIT_SCREEN_PRIMARY, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 355 | final ActivityStack splitScreenSecondary = |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 356 | createStackForShouldBeVisibleTest(mDefaultDisplay, |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 357 | WINDOWING_MODE_SPLIT_SCREEN_SECONDARY, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 358 | |
| 359 | // Home stack shouldn't be visible if both halves of split-screen are opaque. |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 360 | doReturn(false).when(splitScreenPrimary).isStackTranslucent(any()); |
| 361 | doReturn(false).when(splitScreenSecondary).isStackTranslucent(any()); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 362 | assertFalse(homeStack.shouldBeVisible(null /* starting */)); |
| 363 | assertTrue(splitScreenPrimary.shouldBeVisible(null /* starting */)); |
| 364 | assertTrue(splitScreenSecondary.shouldBeVisible(null /* starting */)); |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 365 | assertEquals(STACK_VISIBILITY_INVISIBLE, homeStack.getVisibility(null /* starting */)); |
| 366 | assertEquals(STACK_VISIBILITY_VISIBLE, |
| 367 | splitScreenPrimary.getVisibility(null /* starting */)); |
| 368 | assertEquals(STACK_VISIBILITY_VISIBLE, |
| 369 | splitScreenSecondary.getVisibility(null /* starting */)); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 370 | |
| 371 | // Home stack should be visible if one of the halves of split-screen is translucent. |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 372 | doReturn(true).when(splitScreenPrimary).isStackTranslucent(any()); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 373 | assertTrue(homeStack.shouldBeVisible(null /* starting */)); |
| 374 | assertTrue(splitScreenPrimary.shouldBeVisible(null /* starting */)); |
| 375 | assertTrue(splitScreenSecondary.shouldBeVisible(null /* starting */)); |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 376 | assertEquals(STACK_VISIBILITY_VISIBLE_BEHIND_TRANSLUCENT, |
| 377 | homeStack.getVisibility(null /* starting */)); |
| 378 | assertEquals(STACK_VISIBILITY_VISIBLE, |
| 379 | splitScreenPrimary.getVisibility(null /* starting */)); |
| 380 | assertEquals(STACK_VISIBILITY_VISIBLE, |
| 381 | splitScreenSecondary.getVisibility(null /* starting */)); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 382 | |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 383 | final ActivityStack splitScreenSecondary2 = |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 384 | createStackForShouldBeVisibleTest(mDefaultDisplay, |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 385 | WINDOWING_MODE_SPLIT_SCREEN_SECONDARY, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 386 | // First split-screen secondary shouldn't be visible behind another opaque split-split |
| 387 | // secondary. |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 388 | doReturn(false).when(splitScreenSecondary2).isStackTranslucent(any()); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 389 | assertFalse(splitScreenSecondary.shouldBeVisible(null /* starting */)); |
| 390 | assertTrue(splitScreenSecondary2.shouldBeVisible(null /* starting */)); |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 391 | assertEquals(STACK_VISIBILITY_INVISIBLE, |
| 392 | splitScreenSecondary.getVisibility(null /* starting */)); |
| 393 | assertEquals(STACK_VISIBILITY_VISIBLE, |
| 394 | splitScreenSecondary2.getVisibility(null /* starting */)); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 395 | |
Wale Ogunwale | 8e923af | 2018-03-23 08:48:11 -0700 | [diff] [blame] | 396 | // First split-screen secondary should be visible behind another translucent split-screen |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 397 | // secondary. |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 398 | doReturn(true).when(splitScreenSecondary2).isStackTranslucent(any()); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 399 | assertTrue(splitScreenSecondary.shouldBeVisible(null /* starting */)); |
| 400 | assertTrue(splitScreenSecondary2.shouldBeVisible(null /* starting */)); |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 401 | assertEquals(STACK_VISIBILITY_VISIBLE_BEHIND_TRANSLUCENT, |
| 402 | splitScreenSecondary.getVisibility(null /* starting */)); |
| 403 | assertEquals(STACK_VISIBILITY_VISIBLE, |
| 404 | splitScreenSecondary2.getVisibility(null /* starting */)); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 405 | |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 406 | final ActivityStack assistantStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 407 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_ASSISTANT, true /* onTop */); |
| 408 | |
| 409 | // Split-screen stacks shouldn't be visible behind an opaque fullscreen stack. |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 410 | doReturn(false).when(assistantStack).isStackTranslucent(any()); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 411 | assertTrue(assistantStack.shouldBeVisible(null /* starting */)); |
| 412 | assertFalse(splitScreenPrimary.shouldBeVisible(null /* starting */)); |
| 413 | assertFalse(splitScreenSecondary.shouldBeVisible(null /* starting */)); |
| 414 | assertFalse(splitScreenSecondary2.shouldBeVisible(null /* starting */)); |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 415 | assertEquals(STACK_VISIBILITY_VISIBLE, |
| 416 | assistantStack.getVisibility(null /* starting */)); |
| 417 | assertEquals(STACK_VISIBILITY_INVISIBLE, |
| 418 | splitScreenPrimary.getVisibility(null /* starting */)); |
| 419 | assertEquals(STACK_VISIBILITY_INVISIBLE, |
| 420 | splitScreenSecondary.getVisibility(null /* starting */)); |
| 421 | assertEquals(STACK_VISIBILITY_INVISIBLE, |
| 422 | splitScreenSecondary2.getVisibility(null /* starting */)); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 423 | |
| 424 | // Split-screen stacks should be visible behind a translucent fullscreen stack. |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 425 | doReturn(true).when(assistantStack).isStackTranslucent(any()); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 426 | assertTrue(assistantStack.shouldBeVisible(null /* starting */)); |
| 427 | assertTrue(splitScreenPrimary.shouldBeVisible(null /* starting */)); |
| 428 | assertTrue(splitScreenSecondary.shouldBeVisible(null /* starting */)); |
| 429 | assertTrue(splitScreenSecondary2.shouldBeVisible(null /* starting */)); |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 430 | assertEquals(STACK_VISIBILITY_VISIBLE, |
| 431 | assistantStack.getVisibility(null /* starting */)); |
| 432 | assertEquals(STACK_VISIBILITY_VISIBLE_BEHIND_TRANSLUCENT, |
| 433 | splitScreenPrimary.getVisibility(null /* starting */)); |
| 434 | assertEquals(STACK_VISIBILITY_VISIBLE_BEHIND_TRANSLUCENT, |
| 435 | splitScreenSecondary.getVisibility(null /* starting */)); |
| 436 | assertEquals(STACK_VISIBILITY_VISIBLE_BEHIND_TRANSLUCENT, |
| 437 | splitScreenSecondary2.getVisibility(null /* starting */)); |
Wale Ogunwale | 8e923af | 2018-03-23 08:48:11 -0700 | [diff] [blame] | 438 | |
| 439 | // Assistant stack shouldn't be visible behind translucent split-screen stack |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 440 | doReturn(false).when(assistantStack).isStackTranslucent(any()); |
| 441 | doReturn(true).when(splitScreenPrimary).isStackTranslucent(any()); |
| 442 | doReturn(true).when(splitScreenSecondary2).isStackTranslucent(any()); |
Wale Ogunwale | 8e923af | 2018-03-23 08:48:11 -0700 | [diff] [blame] | 443 | splitScreenSecondary2.moveToFront("testShouldBeVisible_SplitScreen"); |
| 444 | splitScreenPrimary.moveToFront("testShouldBeVisible_SplitScreen"); |
| 445 | assertFalse(assistantStack.shouldBeVisible(null /* starting */)); |
| 446 | assertTrue(splitScreenPrimary.shouldBeVisible(null /* starting */)); |
| 447 | assertTrue(splitScreenSecondary2.shouldBeVisible(null /* starting */)); |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 448 | assertEquals(STACK_VISIBILITY_INVISIBLE, |
| 449 | assistantStack.getVisibility(null /* starting */)); |
| 450 | assertEquals(STACK_VISIBILITY_VISIBLE, |
| 451 | splitScreenPrimary.getVisibility(null /* starting */)); |
| 452 | assertEquals(STACK_VISIBILITY_INVISIBLE, |
| 453 | splitScreenSecondary.getVisibility(null /* starting */)); |
| 454 | assertEquals(STACK_VISIBILITY_VISIBLE, |
| 455 | splitScreenSecondary2.getVisibility(null /* starting */)); |
| 456 | } |
| 457 | |
| 458 | @Test |
| 459 | public void testGetVisibility_FullscreenBehindTranslucent() { |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 460 | final ActivityStack bottomStack = |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 461 | createStandardStackForVisibilityTest(WINDOWING_MODE_FULLSCREEN, |
| 462 | false /* translucent */); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 463 | final ActivityStack translucentStack = |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 464 | createStandardStackForVisibilityTest(WINDOWING_MODE_FULLSCREEN, |
| 465 | true /* translucent */); |
| 466 | |
| 467 | assertEquals(STACK_VISIBILITY_VISIBLE_BEHIND_TRANSLUCENT, |
| 468 | bottomStack.getVisibility(null /* starting */)); |
| 469 | assertEquals(STACK_VISIBILITY_VISIBLE, |
| 470 | translucentStack.getVisibility(null /* starting */)); |
| 471 | } |
| 472 | |
| 473 | @Test |
| 474 | public void testGetVisibility_FullscreenBehindTranslucentAndOpaque() { |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 475 | final ActivityStack bottomStack = |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 476 | createStandardStackForVisibilityTest(WINDOWING_MODE_FULLSCREEN, |
| 477 | false /* translucent */); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 478 | final ActivityStack translucentStack = |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 479 | createStandardStackForVisibilityTest(WINDOWING_MODE_FULLSCREEN, |
| 480 | true /* translucent */); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 481 | final ActivityStack opaqueStack = |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 482 | createStandardStackForVisibilityTest(WINDOWING_MODE_FULLSCREEN, |
| 483 | false /* translucent */); |
| 484 | |
| 485 | assertEquals(STACK_VISIBILITY_INVISIBLE, bottomStack.getVisibility(null /* starting */)); |
| 486 | assertEquals(STACK_VISIBILITY_INVISIBLE, |
| 487 | translucentStack.getVisibility(null /* starting */)); |
| 488 | assertEquals(STACK_VISIBILITY_VISIBLE, opaqueStack.getVisibility(null /* starting */)); |
| 489 | } |
| 490 | |
| 491 | @Test |
| 492 | public void testGetVisibility_FullscreenBehindOpaqueAndTranslucent() { |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 493 | final ActivityStack bottomStack = |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 494 | createStandardStackForVisibilityTest(WINDOWING_MODE_FULLSCREEN, |
| 495 | false /* translucent */); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 496 | final ActivityStack opaqueStack = |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 497 | createStandardStackForVisibilityTest(WINDOWING_MODE_FULLSCREEN, |
| 498 | false /* translucent */); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 499 | final ActivityStack translucentStack = |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 500 | createStandardStackForVisibilityTest(WINDOWING_MODE_FULLSCREEN, |
| 501 | true /* translucent */); |
| 502 | |
| 503 | assertEquals(STACK_VISIBILITY_INVISIBLE, bottomStack.getVisibility(null /* starting */)); |
| 504 | assertEquals(STACK_VISIBILITY_VISIBLE_BEHIND_TRANSLUCENT, |
| 505 | opaqueStack.getVisibility(null /* starting */)); |
| 506 | assertEquals(STACK_VISIBILITY_VISIBLE, |
| 507 | translucentStack.getVisibility(null /* starting */)); |
| 508 | } |
| 509 | |
| 510 | @Test |
| 511 | public void testGetVisibility_FullscreenTranslucentBehindTranslucent() { |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 512 | final ActivityStack bottomTranslucentStack = |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 513 | createStandardStackForVisibilityTest(WINDOWING_MODE_FULLSCREEN, |
| 514 | true /* translucent */); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 515 | final ActivityStack translucentStack = |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 516 | createStandardStackForVisibilityTest(WINDOWING_MODE_FULLSCREEN, |
| 517 | true /* translucent */); |
| 518 | |
| 519 | assertEquals(STACK_VISIBILITY_VISIBLE_BEHIND_TRANSLUCENT, |
| 520 | bottomTranslucentStack.getVisibility(null /* starting */)); |
| 521 | assertEquals(STACK_VISIBILITY_VISIBLE, |
| 522 | translucentStack.getVisibility(null /* starting */)); |
| 523 | } |
| 524 | |
| 525 | @Test |
| 526 | public void testGetVisibility_FullscreenTranslucentBehindOpaque() { |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 527 | final ActivityStack bottomTranslucentStack = |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 528 | createStandardStackForVisibilityTest(WINDOWING_MODE_FULLSCREEN, |
| 529 | true /* translucent */); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 530 | final ActivityStack opaqueStack = |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 531 | createStandardStackForVisibilityTest(WINDOWING_MODE_FULLSCREEN, |
| 532 | false /* translucent */); |
| 533 | |
| 534 | assertEquals(STACK_VISIBILITY_INVISIBLE, |
| 535 | bottomTranslucentStack.getVisibility(null /* starting */)); |
| 536 | assertEquals(STACK_VISIBILITY_VISIBLE, opaqueStack.getVisibility(null /* starting */)); |
| 537 | } |
| 538 | |
| 539 | @Test |
| 540 | public void testGetVisibility_FullscreenBehindTranslucentAndPip() { |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 541 | final ActivityStack bottomStack = |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 542 | createStandardStackForVisibilityTest(WINDOWING_MODE_FULLSCREEN, |
| 543 | false /* translucent */); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 544 | final ActivityStack translucentStack = |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 545 | createStandardStackForVisibilityTest(WINDOWING_MODE_FULLSCREEN, |
| 546 | true /* translucent */); |
| 547 | final ActivityStack pinnedStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
| 548 | WINDOWING_MODE_PINNED, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 549 | |
| 550 | assertEquals(STACK_VISIBILITY_VISIBLE_BEHIND_TRANSLUCENT, |
| 551 | bottomStack.getVisibility(null /* starting */)); |
| 552 | assertEquals(STACK_VISIBILITY_VISIBLE, |
| 553 | translucentStack.getVisibility(null /* starting */)); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 554 | // Add an activity to the pinned stack so it isn't considered empty for visibility check. |
| 555 | final ActivityRecord pinnedActivity = new ActivityBuilder(mService) |
| 556 | .setCreateTask(true) |
| 557 | .setStack(pinnedStack) |
| 558 | .build(); |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 559 | assertEquals(STACK_VISIBILITY_VISIBLE, pinnedStack.getVisibility(null /* starting */)); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | @Test |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 563 | public void testShouldBeVisible_Finishing() { |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 564 | final ActivityStack homeStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 565 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 566 | ActivityRecord topRunningHomeActivity = homeStack.topRunningActivityLocked(); |
| 567 | if (topRunningHomeActivity == null) { |
| 568 | topRunningHomeActivity = new ActivityBuilder(mService) |
| 569 | .setStack(homeStack) |
| 570 | .setCreateTask(true) |
| 571 | .build(); |
| 572 | } |
| 573 | |
| 574 | final ActivityStack translucentStack = createStackForShouldBeVisibleTest( |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 575 | mDefaultDisplay, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, |
| 576 | true /* onTop */); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 577 | doReturn(true).when(translucentStack).isStackTranslucent(any()); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 578 | |
| 579 | assertTrue(homeStack.shouldBeVisible(null /* starting */)); |
| 580 | assertTrue(translucentStack.shouldBeVisible(null /* starting */)); |
| 581 | |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 582 | topRunningHomeActivity.finishing = true; |
| 583 | final ActivityRecord topRunningTranslucentActivity = |
| 584 | translucentStack.topRunningActivityLocked(); |
| 585 | topRunningTranslucentActivity.finishing = true; |
| 586 | |
Louis Chang | f2835df | 2018-10-17 15:14:45 +0800 | [diff] [blame] | 587 | // Home stack should be visible even there are no running activities. |
| 588 | assertTrue(homeStack.shouldBeVisible(null /* starting */)); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 589 | // Home should be visible if we are starting an activity within it. |
| 590 | assertTrue(homeStack.shouldBeVisible(topRunningHomeActivity /* starting */)); |
Louis Chang | f2835df | 2018-10-17 15:14:45 +0800 | [diff] [blame] | 591 | // The translucent stack shouldn't be visible since its activity marked as finishing. |
| 592 | assertFalse(translucentStack.shouldBeVisible(null /* starting */)); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 593 | } |
| 594 | |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 595 | @Test |
| 596 | public void testMoveHomeStackBehindBottomMostVisibleStack_NoMoveHomeBehindFullscreen() { |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 597 | mDefaultDisplay.removeChild(mStack); |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 598 | |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 599 | final ActivityStack homeStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 600 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 601 | final ActivityStack fullscreenStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 602 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 603 | |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 604 | doReturn(false).when(homeStack).isStackTranslucent(any()); |
| 605 | doReturn(false).when(fullscreenStack).isStackTranslucent(any()); |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 606 | |
| 607 | // 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] | 608 | int homeStackIndex = mDefaultDisplay.getIndexOf(homeStack); |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 609 | assertEquals(fullscreenStack, mDefaultDisplay.getStackAbove(homeStack)); |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 610 | mDefaultDisplay.moveStackBehindBottomMostVisibleStack(homeStack); |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 611 | assertEquals(homeStackIndex, mDefaultDisplay.getIndexOf(homeStack)); |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | @Test |
| 615 | public void testMoveHomeStackBehindBottomMostVisibleStack_NoMoveHomeBehindTranslucent() { |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 616 | mDefaultDisplay.removeChild(mStack); |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 617 | |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 618 | final ActivityStack homeStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 619 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 620 | final ActivityStack fullscreenStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 621 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 622 | |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 623 | doReturn(false).when(homeStack).isStackTranslucent(any()); |
| 624 | doReturn(true).when(fullscreenStack).isStackTranslucent(any()); |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 625 | |
| 626 | // 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] | 627 | int homeStackIndex = mDefaultDisplay.getIndexOf(homeStack); |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 628 | assertEquals(fullscreenStack, mDefaultDisplay.getStackAbove(homeStack)); |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 629 | mDefaultDisplay.moveStackBehindBottomMostVisibleStack(homeStack); |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 630 | assertEquals(homeStackIndex, mDefaultDisplay.getIndexOf(homeStack)); |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | @Test |
| 634 | public void testMoveHomeStackBehindBottomMostVisibleStack_NoMoveHomeOnTop() { |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 635 | mDefaultDisplay.removeChild(mStack); |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 636 | |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 637 | final ActivityStack fullscreenStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 638 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 639 | final ActivityStack homeStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 640 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); |
| 641 | |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 642 | doReturn(false).when(homeStack).isStackTranslucent(any()); |
| 643 | doReturn(false).when(fullscreenStack).isStackTranslucent(any()); |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 644 | |
| 645 | // 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] | 646 | int homeStackIndex = mDefaultDisplay.getIndexOf(homeStack); |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 647 | assertNull(mDefaultDisplay.getStackAbove(homeStack)); |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 648 | mDefaultDisplay.moveStackBehindBottomMostVisibleStack(homeStack); |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 649 | assertEquals(homeStackIndex, mDefaultDisplay.getIndexOf(homeStack)); |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | @Test |
| 653 | public void testMoveHomeStackBehindBottomMostVisibleStack_MoveHomeBehindFullscreen() { |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 654 | mDefaultDisplay.removeChild(mStack); |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 655 | |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 656 | final ActivityStack homeStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 657 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 658 | final ActivityStack fullscreenStack1 = createStackForShouldBeVisibleTest( |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 659 | mDefaultDisplay, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, |
| 660 | true /* onTop */); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 661 | final ActivityStack fullscreenStack2 = createStackForShouldBeVisibleTest( |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 662 | mDefaultDisplay, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, |
| 663 | true /* onTop */); |
Wale Ogunwale | 2411619 | 2018-11-07 07:46:56 -0800 | [diff] [blame] | 664 | final ActivityStack pinnedStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 665 | WINDOWING_MODE_PINNED, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 666 | |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 667 | doReturn(false).when(homeStack).isStackTranslucent(any()); |
| 668 | doReturn(false).when(fullscreenStack1).isStackTranslucent(any()); |
| 669 | doReturn(false).when(fullscreenStack2).isStackTranslucent(any()); |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 670 | |
| 671 | // Ensure that we move the home stack behind the bottom most fullscreen stack, ignoring the |
| 672 | // pinned stack |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 673 | assertEquals(fullscreenStack1, mDefaultDisplay.getStackAbove(homeStack)); |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 674 | mDefaultDisplay.moveStackBehindBottomMostVisibleStack(homeStack); |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 675 | assertEquals(fullscreenStack2, mDefaultDisplay.getStackAbove(homeStack)); |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 676 | } |
| 677 | |
| 678 | @Test |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 679 | public void |
| 680 | testMoveHomeStackBehindBottomMostVisibleStack_MoveHomeBehindFullscreenAndTranslucent() { |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 681 | mDefaultDisplay.removeChild(mStack); |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 682 | |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 683 | final ActivityStack homeStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 684 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 685 | final ActivityStack fullscreenStack1 = createStackForShouldBeVisibleTest( |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 686 | mDefaultDisplay, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, |
| 687 | true /* onTop */); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 688 | final ActivityStack fullscreenStack2 = createStackForShouldBeVisibleTest( |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 689 | mDefaultDisplay, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, |
| 690 | true /* onTop */); |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 691 | |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 692 | doReturn(false).when(homeStack).isStackTranslucent(any()); |
| 693 | doReturn(false).when(fullscreenStack1).isStackTranslucent(any()); |
| 694 | doReturn(true).when(fullscreenStack2).isStackTranslucent(any()); |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 695 | |
| 696 | // Ensure that we move the home stack behind the bottom most non-translucent fullscreen |
| 697 | // stack |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 698 | assertEquals(fullscreenStack1, mDefaultDisplay.getStackAbove(homeStack)); |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 699 | mDefaultDisplay.moveStackBehindBottomMostVisibleStack(homeStack); |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 700 | assertEquals(fullscreenStack1, mDefaultDisplay.getStackAbove(homeStack)); |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | @Test |
| 704 | public void testMoveHomeStackBehindStack_BehindHomeStack() { |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 705 | mDefaultDisplay.removeChild(mStack); |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 706 | |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 707 | final ActivityStack fullscreenStack1 = createStackForShouldBeVisibleTest( |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 708 | mDefaultDisplay, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, |
| 709 | true /* onTop */); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 710 | final ActivityStack fullscreenStack2 = createStackForShouldBeVisibleTest( |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 711 | mDefaultDisplay, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, |
| 712 | true /* onTop */); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 713 | final ActivityStack homeStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 714 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); |
| 715 | |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 716 | doReturn(false).when(homeStack).isStackTranslucent(any()); |
| 717 | doReturn(false).when(fullscreenStack1).isStackTranslucent(any()); |
| 718 | doReturn(false).when(fullscreenStack2).isStackTranslucent(any()); |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 719 | |
| 720 | // Ensure we don't move the home stack behind itself |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 721 | int homeStackIndex = mDefaultDisplay.getIndexOf(homeStack); |
| 722 | mDefaultDisplay.moveStackBehindStack(homeStack, homeStack); |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 723 | assertEquals(homeStackIndex, mDefaultDisplay.getIndexOf(homeStack)); |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 724 | } |
| 725 | |
| 726 | @Test |
| 727 | public void testMoveHomeStackBehindStack() { |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 728 | mDefaultDisplay.removeChild(mStack); |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 729 | |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 730 | final ActivityStack fullscreenStack1 = createStackForShouldBeVisibleTest( |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 731 | mDefaultDisplay, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, |
| 732 | true /* onTop */); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 733 | final ActivityStack fullscreenStack2 = createStackForShouldBeVisibleTest( |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 734 | mDefaultDisplay, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, |
| 735 | true /* onTop */); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 736 | final ActivityStack fullscreenStack3 = createStackForShouldBeVisibleTest( |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 737 | mDefaultDisplay, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, |
| 738 | true /* onTop */); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 739 | final ActivityStack fullscreenStack4 = createStackForShouldBeVisibleTest( |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 740 | mDefaultDisplay, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, |
| 741 | true /* onTop */); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 742 | final ActivityStack homeStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 743 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); |
| 744 | |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 745 | mDefaultDisplay.moveStackBehindStack(homeStack, fullscreenStack1); |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 746 | assertEquals(fullscreenStack1, mDefaultDisplay.getStackAbove(homeStack)); |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 747 | mDefaultDisplay.moveStackBehindStack(homeStack, fullscreenStack2); |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 748 | assertEquals(fullscreenStack2, mDefaultDisplay.getStackAbove(homeStack)); |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 749 | mDefaultDisplay.moveStackBehindStack(homeStack, fullscreenStack4); |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 750 | assertEquals(fullscreenStack4, mDefaultDisplay.getStackAbove(homeStack)); |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 751 | mDefaultDisplay.moveStackBehindStack(homeStack, fullscreenStack2); |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 752 | assertEquals(fullscreenStack2, mDefaultDisplay.getStackAbove(homeStack)); |
Winson Chung | d922b6b | 2018-02-16 16:41:50 -0800 | [diff] [blame] | 753 | } |
| 754 | |
Wale Ogunwale | bb28587 | 2018-03-01 13:05:30 -0800 | [diff] [blame] | 755 | @Test |
Kazuki Takise | f85197b | 2018-06-18 18:18:36 +0900 | [diff] [blame] | 756 | public void testSetAlwaysOnTop() { |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 757 | final ActivityStack homeStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Kazuki Takise | f85197b | 2018-06-18 18:18:36 +0900 | [diff] [blame] | 758 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); |
| 759 | final ActivityStack pinnedStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
| 760 | WINDOWING_MODE_PINNED, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 761 | assertEquals(pinnedStack, mDefaultDisplay.getStackAbove(homeStack)); |
Kazuki Takise | f85197b | 2018-06-18 18:18:36 +0900 | [diff] [blame] | 762 | |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 763 | final ActivityStack alwaysOnTopStack = createStackForShouldBeVisibleTest( |
Kazuki Takise | f85197b | 2018-06-18 18:18:36 +0900 | [diff] [blame] | 764 | mDefaultDisplay, WINDOWING_MODE_FREEFORM, ACTIVITY_TYPE_STANDARD, |
| 765 | true /* onTop */); |
| 766 | alwaysOnTopStack.setAlwaysOnTop(true); |
| 767 | assertTrue(alwaysOnTopStack.isAlwaysOnTop()); |
| 768 | // 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] | 769 | assertEquals(pinnedStack, mDefaultDisplay.getStackAbove(alwaysOnTopStack)); |
Kazuki Takise | f85197b | 2018-06-18 18:18:36 +0900 | [diff] [blame] | 770 | |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 771 | final ActivityStack nonAlwaysOnTopStack = createStackForShouldBeVisibleTest( |
Kazuki Takise | f85197b | 2018-06-18 18:18:36 +0900 | [diff] [blame] | 772 | mDefaultDisplay, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, |
| 773 | true /* onTop */); |
| 774 | // 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] | 775 | assertEquals(alwaysOnTopStack, mDefaultDisplay.getStackAbove(nonAlwaysOnTopStack)); |
Kazuki Takise | f85197b | 2018-06-18 18:18:36 +0900 | [diff] [blame] | 776 | |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 777 | final ActivityStack alwaysOnTopStack2 = createStackForShouldBeVisibleTest( |
Kazuki Takise | f85197b | 2018-06-18 18:18:36 +0900 | [diff] [blame] | 778 | mDefaultDisplay, WINDOWING_MODE_FREEFORM, ACTIVITY_TYPE_STANDARD, |
| 779 | true /* onTop */); |
| 780 | alwaysOnTopStack2.setAlwaysOnTop(true); |
| 781 | assertTrue(alwaysOnTopStack2.isAlwaysOnTop()); |
| 782 | // 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] | 783 | assertEquals(pinnedStack, mDefaultDisplay.getStackAbove(alwaysOnTopStack2)); |
Kazuki Takise | f85197b | 2018-06-18 18:18:36 +0900 | [diff] [blame] | 784 | |
| 785 | alwaysOnTopStack2.setAlwaysOnTop(false); |
| 786 | // Ensure, when always on top is turned off for a stack, the stack is put just below all |
| 787 | // other always on top stacks. |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 788 | assertEquals(alwaysOnTopStack, mDefaultDisplay.getStackAbove(alwaysOnTopStack2)); |
Kazuki Takise | 048e266 | 2018-06-27 17:05:11 +0900 | [diff] [blame] | 789 | alwaysOnTopStack2.setAlwaysOnTop(true); |
| 790 | |
| 791 | // Ensure always on top state changes properly when windowing mode changes. |
| 792 | alwaysOnTopStack2.setWindowingMode(WINDOWING_MODE_FULLSCREEN); |
| 793 | assertFalse(alwaysOnTopStack2.isAlwaysOnTop()); |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 794 | assertEquals(alwaysOnTopStack, mDefaultDisplay.getStackAbove(alwaysOnTopStack2)); |
Kazuki Takise | 048e266 | 2018-06-27 17:05:11 +0900 | [diff] [blame] | 795 | alwaysOnTopStack2.setWindowingMode(WINDOWING_MODE_FREEFORM); |
| 796 | assertTrue(alwaysOnTopStack2.isAlwaysOnTop()); |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 797 | assertEquals(pinnedStack, mDefaultDisplay.getStackAbove(alwaysOnTopStack2)); |
Kazuki Takise | f85197b | 2018-06-18 18:18:36 +0900 | [diff] [blame] | 798 | } |
| 799 | |
| 800 | @Test |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 801 | public void testSplitScreenMoveToFront() { |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 802 | final ActivityStack splitScreenPrimary = createStackForShouldBeVisibleTest( |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 803 | mDefaultDisplay, WINDOWING_MODE_SPLIT_SCREEN_PRIMARY, ACTIVITY_TYPE_STANDARD, |
| 804 | true /* onTop */); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 805 | final ActivityStack splitScreenSecondary = createStackForShouldBeVisibleTest( |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 806 | mDefaultDisplay, WINDOWING_MODE_SPLIT_SCREEN_SECONDARY, ACTIVITY_TYPE_STANDARD, |
| 807 | true /* onTop */); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 808 | final ActivityStack assistantStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Wale Ogunwale | bb28587 | 2018-03-01 13:05:30 -0800 | [diff] [blame] | 809 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_ASSISTANT, true /* onTop */); |
| 810 | |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 811 | doReturn(false).when(splitScreenPrimary).isStackTranslucent(any()); |
| 812 | doReturn(false).when(splitScreenSecondary).isStackTranslucent(any()); |
| 813 | doReturn(false).when(assistantStack).isStackTranslucent(any()); |
Wale Ogunwale | bb28587 | 2018-03-01 13:05:30 -0800 | [diff] [blame] | 814 | |
| 815 | assertFalse(splitScreenPrimary.shouldBeVisible(null /* starting */)); |
| 816 | assertFalse(splitScreenSecondary.shouldBeVisible(null /* starting */)); |
| 817 | assertTrue(assistantStack.shouldBeVisible(null /* starting */)); |
| 818 | |
| 819 | splitScreenSecondary.moveToFront("testSplitScreenMoveToFront"); |
| 820 | |
| 821 | assertTrue(splitScreenPrimary.shouldBeVisible(null /* starting */)); |
| 822 | assertTrue(splitScreenSecondary.shouldBeVisible(null /* starting */)); |
| 823 | assertFalse(assistantStack.shouldBeVisible(null /* starting */)); |
| 824 | } |
| 825 | |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 826 | private ActivityStack createStandardStackForVisibilityTest(int windowingMode, |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 827 | boolean translucent) { |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 828 | final ActivityStack stack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 829 | windowingMode, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 830 | doReturn(translucent).when(stack).isStackTranslucent(any()); |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 831 | return stack; |
| 832 | } |
| 833 | |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 834 | @SuppressWarnings("TypeParameterUnusedInFormals") |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 835 | private <T extends ActivityStack> T createStackForShouldBeVisibleTest( |
| 836 | ActivityDisplay display, int windowingMode, int activityType, boolean onTop) { |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 837 | final ActivityStack stack; |
Andrii Kulian | 6a6c4f1 | 2018-07-16 21:23:33 -0700 | [diff] [blame] | 838 | if (activityType == ACTIVITY_TYPE_HOME) { |
| 839 | // Home stack and activity are created in ActivityTestsBase#setupActivityManagerService |
| 840 | stack = mDefaultDisplay.getStack(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME); |
| 841 | if (onTop) { |
Riddle Hsu | 57831b5 | 2018-07-27 00:31:48 +0800 | [diff] [blame] | 842 | mDefaultDisplay.positionChildAtTop(stack, false /* includingParents */); |
Andrii Kulian | 6a6c4f1 | 2018-07-16 21:23:33 -0700 | [diff] [blame] | 843 | } else { |
| 844 | mDefaultDisplay.positionChildAtBottom(stack); |
| 845 | } |
| 846 | } else { |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 847 | stack = new StackBuilder(mRootActivityContainer) |
| 848 | .setDisplay(display) |
| 849 | .setWindowingMode(windowingMode) |
| 850 | .setActivityType(activityType) |
| 851 | .setOnTop(onTop) |
| 852 | .setCreateActivity(true) |
| 853 | .build(); |
Andrii Kulian | 6a6c4f1 | 2018-07-16 21:23:33 -0700 | [diff] [blame] | 854 | } |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 855 | return (T) stack; |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 856 | } |
Bryce Lee | b0f993f | 2018-03-02 15:38:01 -0800 | [diff] [blame] | 857 | |
| 858 | @Test |
Riddle Hsu | aaef731 | 2019-01-24 19:00:58 +0800 | [diff] [blame] | 859 | public void testFinishDisabledPackageActivities_FinishAliveActivities() { |
Bryce Lee | fbd263b4 | 2018-03-07 10:33:55 -0800 | [diff] [blame] | 860 | final ActivityRecord firstActivity = new ActivityBuilder(mService).setTask(mTask).build(); |
| 861 | final ActivityRecord secondActivity = new ActivityBuilder(mService).setTask(mTask).build(); |
Riddle Hsu | aaef731 | 2019-01-24 19:00:58 +0800 | [diff] [blame] | 862 | firstActivity.setState(STOPPED, "testFinishDisabledPackageActivities"); |
| 863 | secondActivity.setState(RESUMED, "testFinishDisabledPackageActivities"); |
| 864 | mStack.mResumedActivity = secondActivity; |
Bryce Lee | fbd263b4 | 2018-03-07 10:33:55 -0800 | [diff] [blame] | 865 | |
Riddle Hsu | aaef731 | 2019-01-24 19:00:58 +0800 | [diff] [blame] | 866 | // Note the activities have non-null ActivityRecord.app, so it won't remove directly. |
| 867 | mStack.finishDisabledPackageActivitiesLocked(firstActivity.packageName, |
| 868 | null /* filterByClasses */, true /* doit */, true /* evenPersistent */, |
| 869 | UserHandle.USER_ALL); |
| 870 | |
| 871 | // If the activity is disabled with {@link android.content.pm.PackageManager#DONT_KILL_APP} |
| 872 | // the activity should still follow the normal flow to finish and destroy. |
| 873 | assertThat(firstActivity.getState()).isEqualTo(DESTROYING); |
| 874 | assertThat(secondActivity.getState()).isEqualTo(PAUSING); |
| 875 | assertTrue(secondActivity.finishing); |
| 876 | } |
| 877 | |
| 878 | @Test |
| 879 | public void testFinishDisabledPackageActivities_RemoveNonAliveActivities() { |
| 880 | final ActivityRecord activity = new ActivityBuilder(mService).setTask(mTask).build(); |
| 881 | |
| 882 | // The overlay activity is not in the disabled package but it is in the same task. |
| 883 | final ActivityRecord overlayActivity = new ActivityBuilder(mService).setTask(mTask) |
| 884 | .setComponent(new ComponentName("package.overlay", ".OverlayActivity")).build(); |
| 885 | // If the task only remains overlay activity, the task should also be removed. |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 886 | // See {@link ActivityStack#removeFromHistory}. |
Riddle Hsu | aaef731 | 2019-01-24 19:00:58 +0800 | [diff] [blame] | 887 | overlayActivity.mTaskOverlay = true; |
| 888 | |
| 889 | // The activity without an app means it will be removed immediately. |
| 890 | // See {@link ActivityStack#destroyActivityLocked}. |
| 891 | activity.app = null; |
| 892 | overlayActivity.app = null; |
Bryce Lee | fbd263b4 | 2018-03-07 10:33:55 -0800 | [diff] [blame] | 893 | |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 894 | assertEquals(2, mTask.mActivities.size()); |
Bryce Lee | fbd263b4 | 2018-03-07 10:33:55 -0800 | [diff] [blame] | 895 | |
Riddle Hsu | aaef731 | 2019-01-24 19:00:58 +0800 | [diff] [blame] | 896 | mStack.finishDisabledPackageActivitiesLocked(activity.packageName, |
| 897 | null /* filterByClasses */, true /* doit */, true /* evenPersistent */, |
| 898 | UserHandle.USER_ALL); |
Bryce Lee | fbd263b4 | 2018-03-07 10:33:55 -0800 | [diff] [blame] | 899 | |
Riddle Hsu | aaef731 | 2019-01-24 19:00:58 +0800 | [diff] [blame] | 900 | // Although the overlay activity is in another package, the non-overlay activities are |
| 901 | // removed from the task. Since the overlay activity should be removed as well, the task |
| 902 | // should be empty. |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 903 | assertThat(mTask.mActivities).isEmpty(); |
| 904 | assertThat(mStack.getAllTasks()).isEmpty(); |
Bryce Lee | fbd263b4 | 2018-03-07 10:33:55 -0800 | [diff] [blame] | 905 | } |
| 906 | |
| 907 | @Test |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 908 | public void testHandleAppDied() { |
Bryce Lee | fbd263b4 | 2018-03-07 10:33:55 -0800 | [diff] [blame] | 909 | final ActivityRecord firstActivity = new ActivityBuilder(mService).setTask(mTask).build(); |
| 910 | final ActivityRecord secondActivity = new ActivityBuilder(mService).setTask(mTask).build(); |
| 911 | |
| 912 | // Making the first activity a task overlay means it will be removed from the task's |
| 913 | // activities as well once second activity is removed as handleAppDied processes the |
| 914 | // activity list in reverse. |
| 915 | firstActivity.mTaskOverlay = true; |
| 916 | firstActivity.app = null; |
| 917 | |
| 918 | // second activity will be immediately removed as it has no state. |
Andrii Kulian | 06b8dcb | 2019-07-10 21:09:38 -0700 | [diff] [blame] | 919 | secondActivity.setSavedState(null /* savedState */); |
Bryce Lee | fbd263b4 | 2018-03-07 10:33:55 -0800 | [diff] [blame] | 920 | |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 921 | assertEquals(2, mTask.mActivities.size()); |
Bryce Lee | fbd263b4 | 2018-03-07 10:33:55 -0800 | [diff] [blame] | 922 | |
| 923 | mStack.handleAppDiedLocked(secondActivity.app); |
| 924 | |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 925 | assertThat(mTask.mActivities).isEmpty(); |
| 926 | assertThat(mStack.getAllTasks()).isEmpty(); |
Bryce Lee | fbd263b4 | 2018-03-07 10:33:55 -0800 | [diff] [blame] | 927 | } |
Bryce Lee | 271617a | 2018-03-15 10:39:12 -0700 | [diff] [blame] | 928 | |
| 929 | @Test |
Garfield Tan | f6cc5c9 | 2019-01-15 13:54:12 -0800 | [diff] [blame] | 930 | public void testHandleAppDied_RelaunchesAfterCrashDuringWindowingModeResize() { |
| 931 | final ActivityRecord activity = new ActivityBuilder(mService).setTask(mTask).build(); |
| 932 | |
| 933 | activity.mRelaunchReason = RELAUNCH_REASON_WINDOWING_MODE_RESIZE; |
| 934 | activity.launchCount = 1; |
Andrii Kulian | 06b8dcb | 2019-07-10 21:09:38 -0700 | [diff] [blame] | 935 | activity.setSavedState(null /* savedState */); |
Garfield Tan | f6cc5c9 | 2019-01-15 13:54:12 -0800 | [diff] [blame] | 936 | |
| 937 | mStack.handleAppDiedLocked(activity.app); |
| 938 | |
| 939 | assertEquals(1, mTask.mActivities.size()); |
| 940 | assertEquals(1, mStack.getAllTasks().size()); |
| 941 | } |
| 942 | |
| 943 | @Test |
| 944 | public void testHandleAppDied_NotRelaunchAfterThreeCrashesDuringWindowingModeResize() { |
| 945 | final ActivityRecord activity = new ActivityBuilder(mService).setTask(mTask).build(); |
| 946 | |
| 947 | activity.mRelaunchReason = RELAUNCH_REASON_WINDOWING_MODE_RESIZE; |
| 948 | activity.launchCount = 3; |
Andrii Kulian | 06b8dcb | 2019-07-10 21:09:38 -0700 | [diff] [blame] | 949 | activity.setSavedState(null /* savedState */); |
Garfield Tan | f6cc5c9 | 2019-01-15 13:54:12 -0800 | [diff] [blame] | 950 | |
| 951 | mStack.handleAppDiedLocked(activity.app); |
| 952 | |
| 953 | assertThat(mTask.mActivities).isEmpty(); |
| 954 | assertThat(mStack.getAllTasks()).isEmpty(); |
| 955 | } |
| 956 | |
| 957 | @Test |
| 958 | public void testHandleAppDied_RelaunchesAfterCrashDuringFreeResize() { |
| 959 | final ActivityRecord activity = new ActivityBuilder(mService).setTask(mTask).build(); |
| 960 | |
| 961 | activity.mRelaunchReason = RELAUNCH_REASON_FREE_RESIZE; |
| 962 | activity.launchCount = 1; |
Andrii Kulian | 06b8dcb | 2019-07-10 21:09:38 -0700 | [diff] [blame] | 963 | activity.setSavedState(null /* savedState */); |
Garfield Tan | f6cc5c9 | 2019-01-15 13:54:12 -0800 | [diff] [blame] | 964 | |
| 965 | mStack.handleAppDiedLocked(activity.app); |
| 966 | |
| 967 | assertEquals(1, mTask.mActivities.size()); |
| 968 | assertEquals(1, mStack.getAllTasks().size()); |
| 969 | } |
| 970 | |
| 971 | @Test |
| 972 | public void testHandleAppDied_NotRelaunchAfterThreeCrashesDuringFreeResize() { |
| 973 | final ActivityRecord activity = new ActivityBuilder(mService).setTask(mTask).build(); |
| 974 | |
| 975 | activity.mRelaunchReason = RELAUNCH_REASON_FREE_RESIZE; |
| 976 | activity.launchCount = 3; |
Andrii Kulian | 06b8dcb | 2019-07-10 21:09:38 -0700 | [diff] [blame] | 977 | activity.setSavedState(null /* savedState */); |
Garfield Tan | f6cc5c9 | 2019-01-15 13:54:12 -0800 | [diff] [blame] | 978 | |
| 979 | mStack.handleAppDiedLocked(activity.app); |
| 980 | |
| 981 | assertThat(mTask.mActivities).isEmpty(); |
| 982 | assertThat(mStack.getAllTasks()).isEmpty(); |
| 983 | } |
| 984 | |
| 985 | @Test |
Louis Chang | 7b03ad9 | 2019-08-21 12:32:33 +0800 | [diff] [blame] | 986 | public void testCompletePauseOnResumeWhilePausingActivity() { |
| 987 | final ActivityRecord bottomActivity = new ActivityBuilder(mService).setTask(mTask).build(); |
| 988 | doReturn(true).when(bottomActivity).attachedToProcess(); |
| 989 | mStack.mPausingActivity = null; |
| 990 | mStack.mResumedActivity = bottomActivity; |
| 991 | final ActivityRecord topActivity = new ActivityBuilder(mService).setTask(mTask).build(); |
| 992 | topActivity.info.flags |= FLAG_RESUME_WHILE_PAUSING; |
| 993 | |
| 994 | mStack.startPausingLocked(false /* userLeaving */, false /* uiSleeping */, topActivity); |
| 995 | verify(mStack).completePauseLocked(anyBoolean(), eq(topActivity)); |
| 996 | } |
| 997 | |
| 998 | @Test |
Riddle Hsu | 2b9a6d7 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 999 | public void testAdjustFocusedStackToHomeWhenNoActivity() { |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 1000 | final ActivityStack homeStask = mDefaultDisplay.getHomeStack(); |
| 1001 | TaskRecord homeTask = homeStask.topTask(); |
| 1002 | if (homeTask == null) { |
| 1003 | // Create home task if there isn't one. |
| 1004 | homeTask = new TaskBuilder(mSupervisor).setStack(homeStask).build(); |
| 1005 | } |
| 1006 | |
Riddle Hsu | 2b9a6d7 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 1007 | final ActivityRecord topActivity = new ActivityBuilder(mService).setTask(mTask).build(); |
| 1008 | mStack.moveToFront("testAdjustFocusedStack"); |
| 1009 | |
Riddle Hsu | 2b9a6d7 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 1010 | // Simulate that home activity has not been started or is force-stopped. |
| 1011 | homeStask.removeTask(homeTask, "testAdjustFocusedStack", REMOVE_TASK_MODE_DESTROYING); |
| 1012 | |
| 1013 | // Finish the only activity. |
Andrii Kulian | 7dd39bb | 2019-07-22 13:11:10 -0700 | [diff] [blame] | 1014 | topActivity.finishIfPossible("testAdjustFocusedStack", false /* oomAdj */); |
Riddle Hsu | 2b9a6d7 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 1015 | // Although home stack is empty, it should still be the focused stack. |
| 1016 | assertEquals(homeStask, mDefaultDisplay.getFocusedStack()); |
| 1017 | } |
| 1018 | |
| 1019 | @Test |
wilsonshih | 8824a8a | 2019-03-12 17:21:35 +0800 | [diff] [blame] | 1020 | public void testWontFinishHomeStackImmediately() { |
| 1021 | final ActivityStack homeStack = createStackForShouldBeVisibleTest(mDefaultDisplay, |
| 1022 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); |
| 1023 | |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 1024 | ActivityRecord activity = homeStack.topRunningActivityLocked(); |
| 1025 | if (activity == null) { |
| 1026 | activity = new ActivityBuilder(mService) |
| 1027 | .setStack(homeStack) |
| 1028 | .setCreateTask(true) |
| 1029 | .build(); |
| 1030 | } |
| 1031 | |
wilsonshih | 8824a8a | 2019-03-12 17:21:35 +0800 | [diff] [blame] | 1032 | // Home stack should not be destroyed immediately. |
Andrii Kulian | 7dd39bb | 2019-07-22 13:11:10 -0700 | [diff] [blame] | 1033 | final ActivityRecord activity1 = finishTopActivity(homeStack); |
wilsonshih | 8824a8a | 2019-03-12 17:21:35 +0800 | [diff] [blame] | 1034 | assertEquals(FINISHING, activity1.getState()); |
| 1035 | } |
| 1036 | |
| 1037 | @Test |
Riddle Hsu | e10cea5 | 2018-10-16 23:33:23 +0800 | [diff] [blame] | 1038 | public void testFinishCurrentActivity() { |
| 1039 | // Create 2 activities on a new display. |
| 1040 | final ActivityDisplay display = addNewActivityDisplayAt(ActivityDisplay.POSITION_TOP); |
| 1041 | final ActivityStack stack1 = createStackForShouldBeVisibleTest(display, |
| 1042 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 1043 | final ActivityStack stack2 = createStackForShouldBeVisibleTest(display, |
| 1044 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 1045 | |
| 1046 | // There is still an activity1 in stack1 so the activity2 should be added to finishing list |
| 1047 | // that will be destroyed until idle. |
Louis Chang | f2835df | 2018-10-17 15:14:45 +0800 | [diff] [blame] | 1048 | stack2.getTopActivity().visible = true; |
Andrii Kulian | 7dd39bb | 2019-07-22 13:11:10 -0700 | [diff] [blame] | 1049 | final ActivityRecord activity2 = finishTopActivity(stack2); |
Louis Chang | f2835df | 2018-10-17 15:14:45 +0800 | [diff] [blame] | 1050 | assertEquals(STOPPING, activity2.getState()); |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 1051 | assertThat(mSupervisor.mStoppingActivities).contains(activity2); |
Riddle Hsu | e10cea5 | 2018-10-16 23:33:23 +0800 | [diff] [blame] | 1052 | |
| 1053 | // The display becomes empty. Since there is no next activity to be idle, the activity |
| 1054 | // should be destroyed immediately with updating configuration to restore original state. |
Andrii Kulian | 7dd39bb | 2019-07-22 13:11:10 -0700 | [diff] [blame] | 1055 | final ActivityRecord activity1 = finishTopActivity(stack1); |
Riddle Hsu | e10cea5 | 2018-10-16 23:33:23 +0800 | [diff] [blame] | 1056 | assertEquals(DESTROYING, activity1.getState()); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1057 | verify(mRootActivityContainer).ensureVisibilityAndConfig(eq(null) /* starting */, |
Riddle Hsu | e10cea5 | 2018-10-16 23:33:23 +0800 | [diff] [blame] | 1058 | eq(display.mDisplayId), anyBoolean(), anyBoolean()); |
| 1059 | } |
| 1060 | |
Andrii Kulian | 7dd39bb | 2019-07-22 13:11:10 -0700 | [diff] [blame] | 1061 | private ActivityRecord finishTopActivity(ActivityStack stack) { |
Riddle Hsu | e10cea5 | 2018-10-16 23:33:23 +0800 | [diff] [blame] | 1062 | final ActivityRecord activity = stack.topRunningActivityLocked(); |
| 1063 | assertNotNull(activity); |
Andrii Kulian | 7dd39bb | 2019-07-22 13:11:10 -0700 | [diff] [blame] | 1064 | activity.setState(STOPPED, "finishTopActivity"); |
Riddle Hsu | e10cea5 | 2018-10-16 23:33:23 +0800 | [diff] [blame] | 1065 | activity.makeFinishingLocked(); |
Andrii Kulian | 7dd39bb | 2019-07-22 13:11:10 -0700 | [diff] [blame] | 1066 | activity.completeFinishing("finishTopActivity"); |
Riddle Hsu | e10cea5 | 2018-10-16 23:33:23 +0800 | [diff] [blame] | 1067 | return activity; |
| 1068 | } |
| 1069 | |
| 1070 | @Test |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 1071 | public void testShouldSleepActivities() { |
Bryce Lee | 271617a | 2018-03-15 10:39:12 -0700 | [diff] [blame] | 1072 | // When focused activity and keyguard is going away, we should not sleep regardless |
| 1073 | // of the display state |
| 1074 | verifyShouldSleepActivities(true /* focusedStack */, true /*keyguardGoingAway*/, |
| 1075 | true /* displaySleeping */, false /* expected*/); |
| 1076 | |
| 1077 | // When not the focused stack, defer to display sleeping state. |
| 1078 | verifyShouldSleepActivities(false /* focusedStack */, true /*keyguardGoingAway*/, |
| 1079 | true /* displaySleeping */, true /* expected*/); |
| 1080 | |
| 1081 | // If keyguard is going away, defer to the display sleeping state. |
| 1082 | verifyShouldSleepActivities(true /* focusedStack */, false /*keyguardGoingAway*/, |
| 1083 | true /* displaySleeping */, true /* expected*/); |
| 1084 | verifyShouldSleepActivities(true /* focusedStack */, false /*keyguardGoingAway*/, |
| 1085 | false /* displaySleeping */, false /* expected*/); |
| 1086 | } |
| 1087 | |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 1088 | @Test |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 1089 | public void testStackOrderChangedOnRemoveStack() { |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 1090 | StackOrderChangedListener listener = new StackOrderChangedListener(); |
| 1091 | mDefaultDisplay.registerStackOrderChangedListener(listener); |
| 1092 | try { |
| 1093 | mDefaultDisplay.removeChild(mStack); |
| 1094 | } finally { |
| 1095 | mDefaultDisplay.unregisterStackOrderChangedListener(listener); |
| 1096 | } |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 1097 | assertTrue(listener.mChanged); |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 1098 | } |
| 1099 | |
| 1100 | @Test |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 1101 | public void testStackOrderChangedOnAddPositionStack() { |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 1102 | mDefaultDisplay.removeChild(mStack); |
| 1103 | |
| 1104 | StackOrderChangedListener listener = new StackOrderChangedListener(); |
| 1105 | mDefaultDisplay.registerStackOrderChangedListener(listener); |
| 1106 | try { |
| 1107 | mDefaultDisplay.addChild(mStack, 0); |
| 1108 | } finally { |
| 1109 | mDefaultDisplay.unregisterStackOrderChangedListener(listener); |
| 1110 | } |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 1111 | assertTrue(listener.mChanged); |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 1112 | } |
| 1113 | |
| 1114 | @Test |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 1115 | public void testStackOrderChangedOnPositionStack() { |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 1116 | StackOrderChangedListener listener = new StackOrderChangedListener(); |
| 1117 | try { |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 1118 | final ActivityStack fullscreenStack1 = createStackForShouldBeVisibleTest( |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 1119 | mDefaultDisplay, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, |
| 1120 | true /* onTop */); |
| 1121 | mDefaultDisplay.registerStackOrderChangedListener(listener); |
| 1122 | mDefaultDisplay.positionChildAtBottom(fullscreenStack1); |
| 1123 | } finally { |
| 1124 | mDefaultDisplay.unregisterStackOrderChangedListener(listener); |
| 1125 | } |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 1126 | assertTrue(listener.mChanged); |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 1127 | } |
| 1128 | |
Louis Chang | f7f7f9c | 2019-06-18 16:47:51 +0800 | [diff] [blame] | 1129 | @Test |
| 1130 | public void testResetTaskWithFinishingActivities() { |
| 1131 | final ActivityRecord taskTop = |
| 1132 | new ActivityBuilder(mService).setStack(mStack).setCreateTask(true).build(); |
| 1133 | // Make all activities in the task are finishing to simulate TaskRecord#getTopActivity |
| 1134 | // returns null. |
| 1135 | taskTop.finishing = true; |
| 1136 | |
| 1137 | final ActivityRecord newR = new ActivityBuilder(mService).build(); |
| 1138 | final ActivityRecord result = mStack.resetTaskIfNeededLocked(taskTop, newR); |
| 1139 | assertThat(result).isEqualTo(taskTop); |
| 1140 | } |
| 1141 | |
Louis Chang | cfe4621 | 2019-07-30 10:34:18 +0800 | [diff] [blame] | 1142 | @Test |
| 1143 | public void testNonTopVisibleActivityNotResume() { |
| 1144 | final ActivityRecord nonTopVisibleActivity = |
| 1145 | new ActivityBuilder(mService).setTask(mTask).build(); |
| 1146 | new ActivityBuilder(mService).setTask(mTask).build(); |
| 1147 | doReturn(false).when(nonTopVisibleActivity).attachedToProcess(); |
| 1148 | doReturn(true).when(nonTopVisibleActivity).shouldBeVisibleIgnoringKeyguard(anyBoolean()); |
| 1149 | doNothing().when(mSupervisor).startSpecificActivityLocked(any(), anyBoolean(), |
| 1150 | anyBoolean()); |
| 1151 | |
| 1152 | mStack.ensureActivitiesVisibleLocked(null /* starting */, 0 /* configChanges */, |
| 1153 | false /* preserveWindows */); |
| 1154 | verify(mSupervisor).startSpecificActivityLocked(any(), eq(false) /* andResume */, |
| 1155 | anyBoolean()); |
| 1156 | } |
| 1157 | |
Bryce Lee | 271617a | 2018-03-15 10:39:12 -0700 | [diff] [blame] | 1158 | private void verifyShouldSleepActivities(boolean focusedStack, |
| 1159 | boolean keyguardGoingAway, boolean displaySleeping, boolean expected) { |
Bryce Lee | 271617a | 2018-03-15 10:39:12 -0700 | [diff] [blame] | 1160 | final ActivityDisplay display = mock(ActivityDisplay.class); |
| 1161 | final KeyguardController keyguardController = mSupervisor.getKeyguardController(); |
| 1162 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1163 | doReturn(display).when(mRootActivityContainer).getActivityDisplay(anyInt()); |
Bryce Lee | 271617a | 2018-03-15 10:39:12 -0700 | [diff] [blame] | 1164 | doReturn(keyguardGoingAway).when(keyguardController).isKeyguardGoingAway(); |
| 1165 | doReturn(displaySleeping).when(display).isSleeping(); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 1166 | doReturn(focusedStack).when(mStack).isFocusedStackOnDisplay(); |
Bryce Lee | 271617a | 2018-03-15 10:39:12 -0700 | [diff] [blame] | 1167 | |
| 1168 | assertEquals(expected, mStack.shouldSleepActivities()); |
| 1169 | } |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 1170 | |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 1171 | private static class StackOrderChangedListener |
| 1172 | implements ActivityDisplay.OnStackOrderChangedListener { |
| 1173 | public boolean mChanged = false; |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 1174 | |
| 1175 | @Override |
Winson Chung | 65d66d3 | 2018-12-13 17:48:39 -0800 | [diff] [blame] | 1176 | public void onStackOrderChanged(ActivityStack stack) { |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 1177 | mChanged = true; |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 1178 | } |
| 1179 | } |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 1180 | } |