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