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