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