Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 The Android Open Source Project |
| 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 |
| 14 | * limitations under the License |
| 15 | */ |
| 16 | |
| 17 | package com.android.server.wm; |
| 18 | |
Andrii Kulian | 3ff5a0b | 2019-05-16 13:18:04 -0700 | [diff] [blame] | 19 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 20 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_RECENTS; |
| 21 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD; |
| 22 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; |
| 23 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN_OR_SPLIT_SCREEN_SECONDARY; |
| 24 | import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; |
| 25 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; |
| 26 | import static android.content.pm.ActivityInfo.FLAG_ALWAYS_FOCUSABLE; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 27 | import static android.view.Display.DEFAULT_DISPLAY; |
lumark | f65e02d | 2019-09-14 19:25:21 +0800 | [diff] [blame] | 28 | import static android.view.Display.TYPE_VIRTUAL; |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 29 | |
Louis Chang | 3ff72a8 | 2019-12-17 12:12:59 +0800 | [diff] [blame] | 30 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.doNothing; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 31 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn; |
| 32 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock; |
| 33 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.never; |
| 34 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.reset; |
| 35 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.spy; |
Keun young Park | 340546a | 2019-05-06 16:27:44 -0700 | [diff] [blame] | 36 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 37 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.times; |
| 38 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify; |
Andrii Kulian | 3ff5a0b | 2019-05-16 13:18:04 -0700 | [diff] [blame] | 39 | import static com.android.server.wm.ActivityStackSupervisor.ON_TOP; |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 40 | import static com.android.server.wm.RootWindowContainer.MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE; |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 41 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 42 | import static org.junit.Assert.assertEquals; |
| 43 | import static org.junit.Assert.assertFalse; |
| 44 | import static org.junit.Assert.assertNotNull; |
| 45 | import static org.junit.Assert.assertNull; |
| 46 | import static org.junit.Assert.assertTrue; |
| 47 | import static org.mockito.ArgumentMatchers.any; |
| 48 | import static org.mockito.ArgumentMatchers.anyBoolean; |
| 49 | import static org.mockito.ArgumentMatchers.anyInt; |
| 50 | import static org.mockito.ArgumentMatchers.contains; |
| 51 | import static org.mockito.ArgumentMatchers.eq; |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 52 | import static org.mockito.ArgumentMatchers.refEq; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 53 | |
| 54 | import android.app.ActivityOptions; |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 55 | import android.content.ComponentName; |
| 56 | import android.content.Intent; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 57 | import android.content.pm.ActivityInfo; |
| 58 | import android.content.pm.ApplicationInfo; |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 59 | import android.content.pm.ResolveInfo; |
Keun young Park | 340546a | 2019-05-06 16:27:44 -0700 | [diff] [blame] | 60 | import android.content.res.Resources; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 61 | import android.graphics.Rect; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 62 | import android.platform.test.annotations.Presubmit; |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 63 | import android.util.Pair; |
| 64 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 65 | import androidx.test.filters.MediumTest; |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 66 | |
| 67 | import com.android.internal.app.ResolverActivity; |
Jorim Jaggi | a5cf680 | 2019-04-26 19:43:11 +0200 | [diff] [blame] | 68 | import com.android.server.wm.ActivityStack.ActivityState; |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 69 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 70 | import org.junit.Before; |
| 71 | import org.junit.Test; |
Riddle Hsu | 2da2d03 | 2019-08-28 21:08:58 +0800 | [diff] [blame] | 72 | import org.junit.runner.RunWith; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 73 | |
| 74 | import java.util.ArrayList; |
Garfield Tan | 26835f0 | 2019-02-07 14:38:38 -0800 | [diff] [blame] | 75 | import java.util.Arrays; |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 76 | import java.util.List; |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 77 | import java.util.function.Consumer; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 78 | |
| 79 | /** |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 80 | * Tests for the {@link RootWindowContainer} class. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 81 | * |
| 82 | * Build/Install/Run: |
Riddle Hsu | ff9e828 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 83 | * atest WmTests:RootActivityContainerTests |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 84 | */ |
| 85 | @MediumTest |
| 86 | @Presubmit |
Riddle Hsu | 2da2d03 | 2019-08-28 21:08:58 +0800 | [diff] [blame] | 87 | @RunWith(WindowTestRunner.class) |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 88 | public class RootActivityContainerTests extends ActivityTestsBase { |
| 89 | private ActivityStack mFullscreenStack; |
| 90 | |
| 91 | @Before |
| 92 | public void setUp() throws Exception { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 93 | mFullscreenStack = mRootWindowContainer.getDefaultDisplay().createStack( |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 94 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
Louis Chang | 3ff72a8 | 2019-12-17 12:12:59 +0800 | [diff] [blame] | 95 | doNothing().when(mService).updateSleepIfNeededLocked(); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | /** |
| 99 | * This test ensures that we do not try to restore a task based off an invalid task id. We |
| 100 | * should expect {@code null} to be returned in this case. |
| 101 | */ |
| 102 | @Test |
| 103 | public void testRestoringInvalidTask() { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 104 | mRootWindowContainer.getDefaultDisplay().removeAllTasks(); |
| 105 | Task task = mRootWindowContainer.anyTaskForId(0 /*taskId*/, |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 106 | MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE, null, false /* onTop */); |
| 107 | assertNull(task); |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * This test ensures that an existing task in the pinned stack is moved to the fullscreen |
| 112 | * activity stack when a new task is added. |
| 113 | */ |
| 114 | @Test |
| 115 | public void testReplacingTaskInPinnedStack() { |
| 116 | final ActivityRecord firstActivity = new ActivityBuilder(mService).setCreateTask(true) |
| 117 | .setStack(mFullscreenStack).build(); |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 118 | final Task task = firstActivity.getTask(); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 119 | |
Ben Lin | 6db8fb2 | 2019-10-18 16:03:44 -0700 | [diff] [blame] | 120 | final ActivityRecord secondActivity = new ActivityBuilder(mService).setTask(task) |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 121 | .setStack(mFullscreenStack).build(); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 122 | |
| 123 | mFullscreenStack.moveToFront("testReplacingTaskInPinnedStack"); |
| 124 | |
| 125 | // Ensure full screen stack has both tasks. |
Ben Lin | 6db8fb2 | 2019-10-18 16:03:44 -0700 | [diff] [blame] | 126 | ensureStackPlacement(mFullscreenStack, firstActivity, secondActivity); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 127 | |
| 128 | // Move first activity to pinned stack. |
| 129 | final Rect sourceBounds = new Rect(); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 130 | mRootWindowContainer.moveActivityToPinnedStack(firstActivity, sourceBounds, |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 131 | 0f /*aspectRatio*/, "initialMove"); |
| 132 | |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 133 | final DisplayContent display = mFullscreenStack.getDisplay(); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 134 | ActivityStack pinnedStack = display.getPinnedStack(); |
| 135 | // Ensure a task has moved over. |
Ben Lin | 6db8fb2 | 2019-10-18 16:03:44 -0700 | [diff] [blame] | 136 | ensureStackPlacement(pinnedStack, firstActivity); |
| 137 | ensureStackPlacement(mFullscreenStack, secondActivity); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 138 | |
| 139 | // Move second activity to pinned stack. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 140 | mRootWindowContainer.moveActivityToPinnedStack(secondActivity, sourceBounds, |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 141 | 0f /*aspectRatio*/, "secondMove"); |
| 142 | |
| 143 | // Need to get stacks again as a new instance might have been created. |
| 144 | pinnedStack = display.getPinnedStack(); |
| 145 | mFullscreenStack = display.getStack(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD); |
| 146 | // Ensure stacks have swapped tasks. |
Ben Lin | 6db8fb2 | 2019-10-18 16:03:44 -0700 | [diff] [blame] | 147 | ensureStackPlacement(pinnedStack, secondActivity); |
| 148 | ensureStackPlacement(mFullscreenStack, firstActivity); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 149 | } |
| 150 | |
Ben Lin | 6db8fb2 | 2019-10-18 16:03:44 -0700 | [diff] [blame] | 151 | private static void ensureStackPlacement(ActivityStack stack, ActivityRecord... activities) { |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 152 | final Task task = stack.getBottomMostTask(); |
Ben Lin | 6db8fb2 | 2019-10-18 16:03:44 -0700 | [diff] [blame] | 153 | final ArrayList<ActivityRecord> stackActivities = new ArrayList<>(); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 154 | |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 155 | task.forAllActivities((Consumer<ActivityRecord>) stackActivities::add, false); |
Ben Lin | 6db8fb2 | 2019-10-18 16:03:44 -0700 | [diff] [blame] | 156 | |
| 157 | assertEquals("Expecting " + Arrays.deepToString(activities) + " got " + stackActivities, |
| 158 | stackActivities.size(), activities != null ? activities.length : 0); |
| 159 | |
| 160 | if (activities == null) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 161 | return; |
| 162 | } |
| 163 | |
Ben Lin | 6db8fb2 | 2019-10-18 16:03:44 -0700 | [diff] [blame] | 164 | for (ActivityRecord activity : activities) { |
| 165 | assertTrue(stackActivities.contains(activity)); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 166 | } |
| 167 | } |
| 168 | |
| 169 | @Test |
| 170 | public void testApplySleepTokens() { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 171 | final DisplayContent display = mRootWindowContainer.getDefaultDisplay(); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 172 | final KeyguardController keyguard = mSupervisor.getKeyguardController(); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 173 | final ActivityStack stack = new StackBuilder(mRootWindowContainer) |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 174 | .setCreateActivity(false) |
| 175 | .setDisplay(display) |
| 176 | .setOnTop(false) |
| 177 | .build(); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 178 | |
| 179 | // Make sure we wake and resume in the case the display is turning on and the keyguard is |
| 180 | // not showing. |
| 181 | verifySleepTokenBehavior(display, keyguard, stack, true /*displaySleeping*/, |
| 182 | false /* displayShouldSleep */, true /* isFocusedStack */, |
| 183 | false /* keyguardShowing */, true /* expectWakeFromSleep */, |
| 184 | true /* expectResumeTopActivity */); |
| 185 | |
| 186 | // Make sure we wake and don't resume when the display is turning on and the keyguard is |
| 187 | // showing. |
| 188 | verifySleepTokenBehavior(display, keyguard, stack, true /*displaySleeping*/, |
| 189 | false /* displayShouldSleep */, true /* isFocusedStack */, |
| 190 | true /* keyguardShowing */, true /* expectWakeFromSleep */, |
| 191 | false /* expectResumeTopActivity */); |
| 192 | |
| 193 | // Make sure we wake and don't resume when the display is turning on and the keyguard is |
| 194 | // not showing as unfocused. |
| 195 | verifySleepTokenBehavior(display, keyguard, stack, true /*displaySleeping*/, |
| 196 | false /* displayShouldSleep */, false /* isFocusedStack */, |
| 197 | false /* keyguardShowing */, true /* expectWakeFromSleep */, |
| 198 | false /* expectResumeTopActivity */); |
| 199 | |
| 200 | // Should not do anything if the display state hasn't changed. |
| 201 | verifySleepTokenBehavior(display, keyguard, stack, false /*displaySleeping*/, |
| 202 | false /* displayShouldSleep */, true /* isFocusedStack */, |
| 203 | false /* keyguardShowing */, false /* expectWakeFromSleep */, |
| 204 | false /* expectResumeTopActivity */); |
| 205 | } |
| 206 | |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 207 | private void verifySleepTokenBehavior(DisplayContent display, KeyguardController keyguard, |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 208 | ActivityStack stack, boolean displaySleeping, boolean displayShouldSleep, |
| 209 | boolean isFocusedStack, boolean keyguardShowing, boolean expectWakeFromSleep, |
| 210 | boolean expectResumeTopActivity) { |
| 211 | reset(stack); |
| 212 | |
| 213 | doReturn(displayShouldSleep).when(display).shouldSleep(); |
| 214 | doReturn(displaySleeping).when(display).isSleeping(); |
| 215 | doReturn(keyguardShowing).when(keyguard).isKeyguardOrAodShowing(anyInt()); |
| 216 | |
| 217 | doReturn(isFocusedStack).when(stack).isFocusedStackOnDisplay(); |
| 218 | doReturn(isFocusedStack ? stack : null).when(display).getFocusedStack(); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 219 | mRootWindowContainer.applySleepTokens(true); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 220 | verify(stack, times(expectWakeFromSleep ? 1 : 0)).awakeFromSleepingLocked(); |
| 221 | verify(stack, times(expectResumeTopActivity ? 1 : 0)).resumeTopActivityUncheckedLocked( |
| 222 | null /* target */, null /* targetOptions */); |
| 223 | } |
| 224 | |
| 225 | /** |
| 226 | * Verifies that removal of activity with task and stack is done correctly. |
| 227 | */ |
| 228 | @Test |
| 229 | public void testRemovingStackOnAppCrash() { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 230 | final DisplayContent defaultDisplay = mRootWindowContainer.getDefaultDisplay(); |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 231 | final int originalStackCount = defaultDisplay.getStackCount(); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 232 | final ActivityStack stack = mRootWindowContainer.getDefaultDisplay().createStack( |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 233 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, false /* onTop */); |
| 234 | final ActivityRecord firstActivity = new ActivityBuilder(mService).setCreateTask(true) |
| 235 | .setStack(stack).build(); |
| 236 | |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 237 | assertEquals(originalStackCount + 1, defaultDisplay.getStackCount()); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 238 | |
| 239 | // Let's pretend that the app has crashed. |
| 240 | firstActivity.app.setThread(null); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 241 | mRootWindowContainer.finishTopCrashedActivities(firstActivity.app, "test"); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 242 | |
| 243 | // Verify that the stack was removed. |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 244 | assertEquals(originalStackCount, defaultDisplay.getStackCount()); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | @Test |
| 248 | public void testFocusability() { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 249 | final ActivityStack stack = mRootWindowContainer.getDefaultDisplay().createStack( |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 250 | WINDOWING_MODE_SPLIT_SCREEN_PRIMARY, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 251 | final ActivityRecord activity = new ActivityBuilder(mService).setCreateTask(true) |
| 252 | .setStack(stack).build(); |
| 253 | |
| 254 | // Under split screen primary we should be focusable when not minimized |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 255 | mRootWindowContainer.setDockedStackMinimized(false); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 256 | assertTrue(stack.isFocusable()); |
| 257 | assertTrue(activity.isFocusable()); |
| 258 | |
| 259 | // Under split screen primary we should not be focusable when minimized |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 260 | mRootWindowContainer.setDockedStackMinimized(true); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 261 | assertFalse(stack.isFocusable()); |
| 262 | assertFalse(activity.isFocusable()); |
| 263 | |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 264 | final ActivityStack pinnedStack = mRootWindowContainer.getDefaultDisplay().createStack( |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 265 | WINDOWING_MODE_PINNED, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 266 | final ActivityRecord pinnedActivity = new ActivityBuilder(mService).setCreateTask(true) |
| 267 | .setStack(pinnedStack).build(); |
| 268 | |
| 269 | // We should not be focusable when in pinned mode |
| 270 | assertFalse(pinnedStack.isFocusable()); |
| 271 | assertFalse(pinnedActivity.isFocusable()); |
| 272 | |
| 273 | // Add flag forcing focusability. |
| 274 | pinnedActivity.info.flags |= FLAG_ALWAYS_FOCUSABLE; |
| 275 | |
| 276 | // We should not be focusable when in pinned mode |
| 277 | assertTrue(pinnedStack.isFocusable()); |
| 278 | assertTrue(pinnedActivity.isFocusable()); |
| 279 | |
| 280 | // Without the overridding activity, stack should not be focusable. |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 281 | pinnedStack.removeChild(pinnedActivity.getTask(), "testFocusability"); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 282 | assertFalse(pinnedStack.isFocusable()); |
| 283 | } |
| 284 | |
| 285 | /** |
| 286 | * Verify that split-screen primary stack will be chosen if activity is launched that targets |
| 287 | * split-screen secondary, but a matching existing instance is found on top of split-screen |
| 288 | * primary stack. |
| 289 | */ |
| 290 | @Test |
| 291 | public void testSplitScreenPrimaryChosenWhenTopActivityLaunchedToSecondary() { |
| 292 | // Create primary split-screen stack with a task and an activity. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 293 | final ActivityStack primaryStack = mRootWindowContainer.getDefaultDisplay() |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 294 | .createStack(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY, ACTIVITY_TYPE_STANDARD, |
| 295 | true /* onTop */); |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 296 | final Task task = new TaskBuilder(mSupervisor).setStack(primaryStack).build(); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 297 | final ActivityRecord r = new ActivityBuilder(mService).setTask(task).build(); |
| 298 | |
| 299 | // Find a launch stack for the top activity in split-screen primary, while requesting |
| 300 | // split-screen secondary. |
| 301 | final ActivityOptions options = ActivityOptions.makeBasic(); |
| 302 | options.setLaunchWindowingMode(WINDOWING_MODE_FULLSCREEN_OR_SPLIT_SCREEN_SECONDARY); |
| 303 | final ActivityStack result = |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 304 | mRootWindowContainer.getLaunchStack(r, options, task, true /* onTop */); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 305 | |
| 306 | // Assert that the primary stack is returned. |
| 307 | assertEquals(primaryStack, result); |
| 308 | } |
| 309 | |
| 310 | /** |
| 311 | * Verify split-screen primary stack & task can resized by |
| 312 | * {@link android.app.IActivityTaskManager#resizeDockedStack} as expect. |
| 313 | */ |
| 314 | @Test |
| 315 | public void testResizeDockedStackForSplitScreenPrimary() { |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 316 | final Rect taskSize = new Rect(0, 0, 1000, 1000); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 317 | final Rect stackSize = new Rect(0, 0, 300, 300); |
| 318 | |
| 319 | // Create primary split-screen stack with a task. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 320 | final ActivityStack primaryStack = new StackBuilder(mRootWindowContainer) |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 321 | .setActivityType(ACTIVITY_TYPE_STANDARD) |
| 322 | .setWindowingMode(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) |
| 323 | .setOnTop(true) |
| 324 | .build(); |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 325 | final Task task = primaryStack.getTopMostTask(); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 326 | |
| 327 | // Resize dock stack. |
| 328 | mService.resizeDockedStack(stackSize, taskSize, null, null, null); |
| 329 | |
| 330 | // Verify dock stack & its task bounds if is equal as resized result. |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 331 | assertEquals(stackSize, primaryStack.getBounds()); |
| 332 | assertEquals(taskSize, task.getBounds()); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | /** |
| 336 | * Verify that home stack would be moved to front when the top activity is Recents. |
| 337 | */ |
| 338 | @Test |
| 339 | public void testFindTaskToMoveToFrontWhenRecentsOnTop() { |
| 340 | // Create stack/task on default display. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 341 | final DisplayContent display = mRootWindowContainer.getDefaultDisplay(); |
| 342 | final ActivityStack targetStack = new StackBuilder(mRootWindowContainer) |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 343 | .setOnTop(false) |
| 344 | .build(); |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 345 | final Task targetTask = targetStack.getBottomMostTask(); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 346 | |
| 347 | // Create Recents on top of the display. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 348 | final ActivityStack stack = new StackBuilder(mRootWindowContainer).setActivityType( |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 349 | ACTIVITY_TYPE_RECENTS).build(); |
| 350 | |
| 351 | final String reason = "findTaskToMoveToFront"; |
| 352 | mSupervisor.findTaskToMoveToFront(targetTask, 0, ActivityOptions.makeBasic(), reason, |
| 353 | false); |
| 354 | |
| 355 | verify(display).moveHomeStackToFront(contains(reason)); |
| 356 | } |
| 357 | |
| 358 | /** |
| 359 | * Verify that home stack won't be moved to front if the top activity on other display is |
| 360 | * Recents. |
| 361 | */ |
| 362 | @Test |
| 363 | public void testFindTaskToMoveToFrontWhenRecentsOnOtherDisplay() { |
| 364 | // Create stack/task on default display. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 365 | final DisplayContent display = mRootWindowContainer.getDefaultDisplay(); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 366 | final ActivityStack targetStack = display.createStack(WINDOWING_MODE_FULLSCREEN, |
| 367 | ACTIVITY_TYPE_STANDARD, false /* onTop */); |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 368 | final Task targetTask = new TaskBuilder(mSupervisor).setStack(targetStack).build(); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 369 | |
| 370 | // Create Recents on secondary display. |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 371 | final TestDisplayContent secondDisplay = addNewDisplayContentAt( |
| 372 | DisplayContent.POSITION_TOP); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 373 | final ActivityStack stack = secondDisplay.createStack(WINDOWING_MODE_FULLSCREEN, |
| 374 | ACTIVITY_TYPE_RECENTS, true /* onTop */); |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 375 | final Task task = new TaskBuilder(mSupervisor).setStack(stack).build(); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 376 | new ActivityBuilder(mService).setTask(task).build(); |
| 377 | |
| 378 | final String reason = "findTaskToMoveToFront"; |
| 379 | mSupervisor.findTaskToMoveToFront(targetTask, 0, ActivityOptions.makeBasic(), reason, |
| 380 | false); |
| 381 | |
| 382 | verify(display, never()).moveHomeStackToFront(contains(reason)); |
| 383 | } |
| 384 | |
| 385 | /** |
| 386 | * Verify if a stack is not at the topmost position, it should be able to resume its activity if |
| 387 | * the stack is the top focused. |
| 388 | */ |
| 389 | @Test |
| 390 | public void testResumeActivityWhenNonTopmostStackIsTopFocused() { |
| 391 | // Create a stack at bottom. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 392 | final DisplayContent display = mRootWindowContainer.getDefaultDisplay(); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 393 | final ActivityStack targetStack = spy(display.createStack(WINDOWING_MODE_FULLSCREEN, |
| 394 | ACTIVITY_TYPE_STANDARD, false /* onTop */)); |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 395 | final Task task = new TaskBuilder(mSupervisor).setStack(targetStack).build(); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 396 | final ActivityRecord activity = new ActivityBuilder(mService).setTask(task).build(); |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 397 | display.positionStackAtBottom(targetStack); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 398 | |
| 399 | // Assume the stack is not at the topmost position (e.g. behind always-on-top stacks) but it |
| 400 | // is the current top focused stack. |
| 401 | assertFalse(targetStack.isTopStackOnDisplay()); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 402 | doReturn(targetStack).when(mRootWindowContainer).getTopDisplayFocusedStack(); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 403 | |
| 404 | // Use the stack as target to resume. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 405 | mRootWindowContainer.resumeFocusedStacksTopActivities( |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 406 | targetStack, activity, null /* targetOptions */); |
| 407 | |
| 408 | // Verify the target stack should resume its activity. |
| 409 | verify(targetStack, times(1)).resumeTopActivityUncheckedLocked( |
| 410 | eq(activity), eq(null /* targetOptions */)); |
| 411 | } |
| 412 | |
| 413 | /** |
Andrii Kulian | 3ff5a0b | 2019-05-16 13:18:04 -0700 | [diff] [blame] | 414 | * Verify that home activity will be started on a display even if another display has a |
| 415 | * focusable activity. |
| 416 | */ |
| 417 | @Test |
| 418 | public void testResumeFocusedStacksStartsHomeActivity_NoActivities() { |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 419 | mFullscreenStack.removeIfPossible(); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 420 | mService.mRootWindowContainer.getDisplayContent(DEFAULT_DISPLAY).getHomeStack() |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 421 | .removeIfPossible(); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 422 | mService.mRootWindowContainer.getDisplayContent(DEFAULT_DISPLAY) |
Andrii Kulian | 3ff5a0b | 2019-05-16 13:18:04 -0700 | [diff] [blame] | 423 | .createStack(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, ON_TOP); |
| 424 | |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 425 | doReturn(true).when(mRootWindowContainer).resumeHomeActivity(any(), any(), anyInt()); |
Andrii Kulian | 3ff5a0b | 2019-05-16 13:18:04 -0700 | [diff] [blame] | 426 | |
| 427 | mService.setBooted(true); |
| 428 | |
| 429 | // Trigger resume on all displays |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 430 | mRootWindowContainer.resumeFocusedStacksTopActivities(); |
Andrii Kulian | 3ff5a0b | 2019-05-16 13:18:04 -0700 | [diff] [blame] | 431 | |
| 432 | // Verify that home activity was started on the default display |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 433 | verify(mRootWindowContainer).resumeHomeActivity(any(), any(), eq(DEFAULT_DISPLAY)); |
Andrii Kulian | 3ff5a0b | 2019-05-16 13:18:04 -0700 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | /** |
| 437 | * Verify that home activity will be started on a display even if another display has a |
| 438 | * focusable activity. |
| 439 | */ |
| 440 | @Test |
| 441 | public void testResumeFocusedStacksStartsHomeActivity_ActivityOnSecondaryScreen() { |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 442 | mFullscreenStack.removeIfPossible(); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 443 | mService.mRootWindowContainer.getDisplayContent(DEFAULT_DISPLAY).getHomeStack() |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 444 | .removeIfPossible(); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 445 | mService.mRootWindowContainer.getDisplayContent(DEFAULT_DISPLAY) |
Andrii Kulian | 3ff5a0b | 2019-05-16 13:18:04 -0700 | [diff] [blame] | 446 | .createStack(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, ON_TOP); |
| 447 | |
| 448 | // Create an activity on secondary display. |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 449 | final TestDisplayContent secondDisplay = addNewDisplayContentAt( |
| 450 | DisplayContent.POSITION_TOP); |
Andrii Kulian | 3ff5a0b | 2019-05-16 13:18:04 -0700 | [diff] [blame] | 451 | final ActivityStack stack = secondDisplay.createStack(WINDOWING_MODE_FULLSCREEN, |
| 452 | ACTIVITY_TYPE_STANDARD, true /* onTop */); |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 453 | final Task task = new TaskBuilder(mSupervisor).setStack(stack).build(); |
Andrii Kulian | 3ff5a0b | 2019-05-16 13:18:04 -0700 | [diff] [blame] | 454 | new ActivityBuilder(mService).setTask(task).build(); |
| 455 | |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 456 | doReturn(true).when(mRootWindowContainer).resumeHomeActivity(any(), any(), anyInt()); |
Andrii Kulian | 3ff5a0b | 2019-05-16 13:18:04 -0700 | [diff] [blame] | 457 | |
| 458 | mService.setBooted(true); |
| 459 | |
| 460 | // Trigger resume on all displays |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 461 | mRootWindowContainer.resumeFocusedStacksTopActivities(); |
Andrii Kulian | 3ff5a0b | 2019-05-16 13:18:04 -0700 | [diff] [blame] | 462 | |
| 463 | // Verify that home activity was started on the default display |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 464 | verify(mRootWindowContainer).resumeHomeActivity(any(), any(), eq(DEFAULT_DISPLAY)); |
Andrii Kulian | 3ff5a0b | 2019-05-16 13:18:04 -0700 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | /** |
Jorim Jaggi | a5cf680 | 2019-04-26 19:43:11 +0200 | [diff] [blame] | 468 | * Verify that a lingering transition is being executed in case the activity to be resumed is |
| 469 | * already resumed |
| 470 | */ |
| 471 | @Test |
| 472 | public void testResumeActivityLingeringTransition() { |
| 473 | // Create a stack at top. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 474 | final DisplayContent display = mRootWindowContainer.getDefaultDisplay(); |
Jorim Jaggi | a5cf680 | 2019-04-26 19:43:11 +0200 | [diff] [blame] | 475 | final ActivityStack targetStack = spy(display.createStack(WINDOWING_MODE_FULLSCREEN, |
| 476 | ACTIVITY_TYPE_STANDARD, false /* onTop */)); |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 477 | final Task task = new TaskBuilder(mSupervisor).setStack(targetStack).build(); |
Jorim Jaggi | a5cf680 | 2019-04-26 19:43:11 +0200 | [diff] [blame] | 478 | final ActivityRecord activity = new ActivityBuilder(mService).setTask(task).build(); |
| 479 | activity.setState(ActivityState.RESUMED, "test"); |
| 480 | |
| 481 | // Assume the stack is at the topmost position |
| 482 | assertTrue(targetStack.isTopStackOnDisplay()); |
| 483 | |
| 484 | // Use the stack as target to resume. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 485 | mRootWindowContainer.resumeFocusedStacksTopActivities(); |
Jorim Jaggi | a5cf680 | 2019-04-26 19:43:11 +0200 | [diff] [blame] | 486 | |
| 487 | // Verify the lingering app transition is being executed because it's already resumed |
| 488 | verify(targetStack, times(1)).executeAppTransition(any()); |
| 489 | } |
| 490 | |
| 491 | @Test |
| 492 | public void testResumeActivityLingeringTransition_notExecuted() { |
| 493 | // Create a stack at bottom. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 494 | final DisplayContent display = mRootWindowContainer.getDefaultDisplay(); |
Jorim Jaggi | a5cf680 | 2019-04-26 19:43:11 +0200 | [diff] [blame] | 495 | final ActivityStack targetStack = spy(display.createStack(WINDOWING_MODE_FULLSCREEN, |
| 496 | ACTIVITY_TYPE_STANDARD, false /* onTop */)); |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 497 | final Task task = new TaskBuilder(mSupervisor).setStack(targetStack).build(); |
Jorim Jaggi | a5cf680 | 2019-04-26 19:43:11 +0200 | [diff] [blame] | 498 | final ActivityRecord activity = new ActivityBuilder(mService).setTask(task).build(); |
| 499 | activity.setState(ActivityState.RESUMED, "test"); |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 500 | display.positionStackAtBottom(targetStack); |
Jorim Jaggi | a5cf680 | 2019-04-26 19:43:11 +0200 | [diff] [blame] | 501 | |
| 502 | // Assume the stack is at the topmost position |
| 503 | assertFalse(targetStack.isTopStackOnDisplay()); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 504 | doReturn(targetStack).when(mRootWindowContainer).getTopDisplayFocusedStack(); |
Jorim Jaggi | a5cf680 | 2019-04-26 19:43:11 +0200 | [diff] [blame] | 505 | |
| 506 | // Use the stack as target to resume. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 507 | mRootWindowContainer.resumeFocusedStacksTopActivities(); |
Jorim Jaggi | a5cf680 | 2019-04-26 19:43:11 +0200 | [diff] [blame] | 508 | |
| 509 | // Verify the lingering app transition is being executed because it's already resumed |
| 510 | verify(targetStack, never()).executeAppTransition(any()); |
| 511 | } |
| 512 | |
| 513 | /** |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 514 | * Tests that home activities can be started on the displays that supports system decorations. |
| 515 | */ |
Chilun | 2afb94e | 2018-12-25 20:42:45 +0800 | [diff] [blame] | 516 | @Test |
| 517 | public void testStartHomeOnAllDisplays() { |
Riddle Hsu | ff9e828 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 518 | mockResolveHomeActivity(); |
Chilun | 5995498 | 2019-05-23 14:50:48 +0800 | [diff] [blame] | 519 | mockResolveSecondaryHomeActivity(); |
Riddle Hsu | ff9e828 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 520 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 521 | // Create secondary displays. |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 522 | final TestDisplayContent secondDisplay = |
| 523 | new TestDisplayContent.Builder(mService, 1000, 1500) |
Evan Rosky | 4a51dbc0 | 2019-09-11 17:28:07 -0700 | [diff] [blame] | 524 | .setSystemDecorations(true).build(); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 525 | |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 526 | doReturn(true).when(mRootWindowContainer) |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 527 | .ensureVisibilityAndConfig(any(), anyInt(), anyBoolean(), anyBoolean()); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 528 | doReturn(true).when(mRootWindowContainer).canStartHomeOnDisplay( |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 529 | any(), anyInt(), anyBoolean()); |
| 530 | |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 531 | mRootWindowContainer.startHomeOnAllDisplays(0, "testStartHome"); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 532 | |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 533 | assertTrue(mRootWindowContainer.getDefaultDisplay().getTopStack().isActivityTypeHome()); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 534 | assertNotNull(secondDisplay.getTopStack()); |
| 535 | assertTrue(secondDisplay.getTopStack().isActivityTypeHome()); |
| 536 | } |
| 537 | |
| 538 | /** |
| 539 | * Tests that home activities won't be started before booting when display added. |
| 540 | */ |
| 541 | @Test |
| 542 | public void testNotStartHomeBeforeBoot() { |
| 543 | final int displayId = 1; |
| 544 | final boolean isBooting = mService.mAmInternal.isBooting(); |
| 545 | final boolean isBooted = mService.mAmInternal.isBooted(); |
| 546 | try { |
| 547 | mService.mAmInternal.setBooting(false); |
| 548 | mService.mAmInternal.setBooted(false); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 549 | mRootWindowContainer.onDisplayAdded(displayId); |
| 550 | verify(mRootWindowContainer, never()).startHomeOnDisplay(anyInt(), any(), anyInt()); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 551 | } finally { |
| 552 | mService.mAmInternal.setBooting(isBooting); |
| 553 | mService.mAmInternal.setBooted(isBooted); |
| 554 | } |
| 555 | } |
| 556 | |
| 557 | /** |
| 558 | * Tests whether home can be started if being instrumented. |
| 559 | */ |
| 560 | @Test |
| 561 | public void testCanStartHomeWhenInstrumented() { |
| 562 | final ActivityInfo info = new ActivityInfo(); |
| 563 | info.applicationInfo = new ApplicationInfo(); |
| 564 | final WindowProcessController app = mock(WindowProcessController.class); |
| 565 | doReturn(app).when(mService).getProcessController(any(), anyInt()); |
| 566 | |
| 567 | // Can not start home if we don't want to start home while home is being instrumented. |
| 568 | doReturn(true).when(app).isInstrumenting(); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 569 | assertFalse(mRootWindowContainer.canStartHomeOnDisplay(info, DEFAULT_DISPLAY, |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 570 | false /* allowInstrumenting*/)); |
| 571 | |
| 572 | // Can start home for other cases. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 573 | assertTrue(mRootWindowContainer.canStartHomeOnDisplay(info, DEFAULT_DISPLAY, |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 574 | true /* allowInstrumenting*/)); |
| 575 | |
| 576 | doReturn(false).when(app).isInstrumenting(); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 577 | assertTrue(mRootWindowContainer.canStartHomeOnDisplay(info, DEFAULT_DISPLAY, |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 578 | false /* allowInstrumenting*/)); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 579 | assertTrue(mRootWindowContainer.canStartHomeOnDisplay(info, DEFAULT_DISPLAY, |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 580 | true /* allowInstrumenting*/)); |
| 581 | } |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 582 | |
| 583 | /** |
Chilun | 85ebc0d | 2019-04-15 16:00:53 +0800 | [diff] [blame] | 584 | * Tests that secondary home activity should not be resolved if device is still locked. |
| 585 | */ |
| 586 | @Test |
| 587 | public void testStartSecondaryHomeOnDisplayWithUserKeyLocked() { |
| 588 | // Create secondary displays. |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 589 | final TestDisplayContent secondDisplay = |
| 590 | new TestDisplayContent.Builder(mService, 1000, 1500) |
Evan Rosky | 4a51dbc0 | 2019-09-11 17:28:07 -0700 | [diff] [blame] | 591 | .setSystemDecorations(true).build(); |
Chilun | 85ebc0d | 2019-04-15 16:00:53 +0800 | [diff] [blame] | 592 | |
Chilun | 85ebc0d | 2019-04-15 16:00:53 +0800 | [diff] [blame] | 593 | // Use invalid user id to let StorageManager.isUserKeyUnlocked() return false. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 594 | final int currentUser = mRootWindowContainer.mCurrentUser; |
| 595 | mRootWindowContainer.mCurrentUser = -1; |
Chilun | 85ebc0d | 2019-04-15 16:00:53 +0800 | [diff] [blame] | 596 | |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 597 | mRootWindowContainer.startHomeOnDisplay(0 /* userId */, "testStartSecondaryHome", |
Chilun | 85ebc0d | 2019-04-15 16:00:53 +0800 | [diff] [blame] | 598 | secondDisplay.mDisplayId, true /* allowInstrumenting */, true /* fromHomeKey */); |
| 599 | |
| 600 | try { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 601 | verify(mRootWindowContainer, never()).resolveSecondaryHomeActivity(anyInt(), |
Chilun | 85ebc0d | 2019-04-15 16:00:53 +0800 | [diff] [blame] | 602 | anyInt()); |
| 603 | } finally { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 604 | mRootWindowContainer.mCurrentUser = currentUser; |
Chilun | 85ebc0d | 2019-04-15 16:00:53 +0800 | [diff] [blame] | 605 | } |
| 606 | } |
| 607 | |
| 608 | /** |
| 609 | * Tests that secondary home activity should not be resolved if display does not support system |
| 610 | * decorations. |
| 611 | */ |
| 612 | @Test |
| 613 | public void testStartSecondaryHomeOnDisplayWithoutSysDecorations() { |
| 614 | // Create secondary displays. |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 615 | final TestDisplayContent secondDisplay = |
| 616 | new TestDisplayContent.Builder(mService, 1000, 1500) |
Evan Rosky | 4a51dbc0 | 2019-09-11 17:28:07 -0700 | [diff] [blame] | 617 | .setSystemDecorations(false).build(); |
Chilun | 85ebc0d | 2019-04-15 16:00:53 +0800 | [diff] [blame] | 618 | |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 619 | mRootWindowContainer.startHomeOnDisplay(0 /* userId */, "testStartSecondaryHome", |
Chilun | 85ebc0d | 2019-04-15 16:00:53 +0800 | [diff] [blame] | 620 | secondDisplay.mDisplayId, true /* allowInstrumenting */, true /* fromHomeKey */); |
| 621 | |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 622 | verify(mRootWindowContainer, never()).resolveSecondaryHomeActivity(anyInt(), anyInt()); |
Chilun | 85ebc0d | 2019-04-15 16:00:53 +0800 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | /** |
Riddle Hsu | ff9e828 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 626 | * Tests that when starting {@link #ResolverActivity} for home, it should use the standard |
| 627 | * activity type (in a new stack) so the order of back stack won't be broken. |
| 628 | */ |
| 629 | @Test |
| 630 | public void testStartResolverActivityForHome() { |
| 631 | final ActivityInfo info = new ActivityInfo(); |
| 632 | info.applicationInfo = new ApplicationInfo(); |
| 633 | info.applicationInfo.packageName = "android"; |
| 634 | info.name = ResolverActivity.class.getName(); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 635 | doReturn(info).when(mRootWindowContainer).resolveHomeActivity(anyInt(), any()); |
Riddle Hsu | ff9e828 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 636 | |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 637 | mRootWindowContainer.startHomeOnDisplay(0 /* userId */, "test", DEFAULT_DISPLAY); |
| 638 | final ActivityRecord resolverActivity = mRootWindowContainer.topRunningActivity(); |
Riddle Hsu | ff9e828 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 639 | |
| 640 | assertEquals(info, resolverActivity.info); |
| 641 | assertEquals(ACTIVITY_TYPE_STANDARD, resolverActivity.getActivityStack().getActivityType()); |
| 642 | } |
| 643 | |
| 644 | /** |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 645 | * Tests that secondary home should be selected if default home not set. |
| 646 | */ |
| 647 | @Test |
| 648 | public void testResolveSecondaryHomeActivityWhenDefaultHomeNotSet() { |
| 649 | final Intent defaultHomeIntent = mService.getHomeIntent(); |
| 650 | final ActivityInfo aInfoDefault = new ActivityInfo(); |
| 651 | aInfoDefault.name = ResolverActivity.class.getName(); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 652 | doReturn(aInfoDefault).when(mRootWindowContainer).resolveHomeActivity(anyInt(), |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 653 | refEq(defaultHomeIntent)); |
| 654 | |
| 655 | final String secondaryHomeComponent = mService.mContext.getResources().getString( |
| 656 | com.android.internal.R.string.config_secondaryHomeComponent); |
| 657 | final ComponentName comp = ComponentName.unflattenFromString(secondaryHomeComponent); |
| 658 | final Intent secondaryHomeIntent = mService.getSecondaryHomeIntent(null); |
| 659 | final ActivityInfo aInfoSecondary = new ActivityInfo(); |
| 660 | aInfoSecondary.name = comp.getClassName(); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 661 | doReturn(aInfoSecondary).when(mRootWindowContainer).resolveHomeActivity(anyInt(), |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 662 | refEq(secondaryHomeIntent)); |
| 663 | |
| 664 | // Should fallback to secondary home if default home not set. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 665 | final Pair<ActivityInfo, Intent> resolvedInfo = mRootWindowContainer |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 666 | .resolveSecondaryHomeActivity(0 /* userId */, 1 /* displayId */); |
| 667 | |
| 668 | assertEquals(comp.getClassName(), resolvedInfo.first.name); |
| 669 | } |
| 670 | |
| 671 | /** |
Keun young Park | 340546a | 2019-05-06 16:27:44 -0700 | [diff] [blame] | 672 | * Tests that the default secondary home activity is always picked when it is in forced by |
| 673 | * config_useSystemProvidedLauncherForSecondary. |
| 674 | */ |
| 675 | @Test |
| 676 | public void testResolveSecondaryHomeActivityForced() throws Exception { |
| 677 | Resources resources = mContext.getResources(); |
| 678 | spyOn(resources); |
| 679 | try { |
| 680 | // setUp: set secondary launcher and force it. |
| 681 | final String defaultSecondaryHome = |
| 682 | "com.android.test/com.android.test.TestDefaultSecondaryHome"; |
| 683 | final ComponentName secondaryComp = ComponentName.unflattenFromString( |
| 684 | defaultSecondaryHome); |
| 685 | doReturn(defaultSecondaryHome).when(resources).getString( |
| 686 | com.android.internal.R.string.config_secondaryHomeComponent); |
| 687 | doReturn(true).when(resources).getBoolean( |
| 688 | com.android.internal.R.bool.config_useSystemProvidedLauncherForSecondary); |
| 689 | final Intent secondaryHomeIntent = mService.getSecondaryHomeIntent(null); |
| 690 | assertEquals(secondaryComp, secondaryHomeIntent.getComponent()); |
| 691 | final ActivityInfo aInfoSecondary = new ActivityInfo(); |
| 692 | aInfoSecondary.name = secondaryComp.getClassName(); |
| 693 | aInfoSecondary.applicationInfo = new ApplicationInfo(); |
| 694 | aInfoSecondary.applicationInfo.packageName = secondaryComp.getPackageName(); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 695 | doReturn(aInfoSecondary).when(mRootWindowContainer).resolveHomeActivity(anyInt(), |
Keun young Park | 340546a | 2019-05-06 16:27:44 -0700 | [diff] [blame] | 696 | refEq(secondaryHomeIntent)); |
| 697 | final Intent homeIntent = mService.getHomeIntent(); |
| 698 | final ActivityInfo aInfoDefault = new ActivityInfo(); |
| 699 | aInfoDefault.name = "fakeHomeActivity"; |
| 700 | aInfoDefault.applicationInfo = new ApplicationInfo(); |
| 701 | aInfoDefault.applicationInfo.packageName = "fakeHomePackage"; |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 702 | doReturn(aInfoDefault).when(mRootWindowContainer).resolveHomeActivity(anyInt(), |
Keun young Park | 340546a | 2019-05-06 16:27:44 -0700 | [diff] [blame] | 703 | refEq(homeIntent)); |
| 704 | // Let resolveActivities call to validate both main launcher and second launcher so that |
| 705 | // resolveActivities call does not work as enabler for secondary. |
| 706 | final List<ResolveInfo> resolutions1 = new ArrayList<>(); |
| 707 | final ResolveInfo resolveInfo1 = new ResolveInfo(); |
| 708 | resolveInfo1.activityInfo = new ActivityInfo(); |
| 709 | resolveInfo1.activityInfo.name = aInfoDefault.name; |
| 710 | resolveInfo1.activityInfo.applicationInfo = aInfoDefault.applicationInfo; |
| 711 | resolutions1.add(resolveInfo1); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 712 | doReturn(resolutions1).when(mRootWindowContainer).resolveActivities(anyInt(), |
Keun young Park | 340546a | 2019-05-06 16:27:44 -0700 | [diff] [blame] | 713 | refEq(homeIntent)); |
| 714 | final List<ResolveInfo> resolutions2 = new ArrayList<>(); |
| 715 | final ResolveInfo resolveInfo2 = new ResolveInfo(); |
| 716 | resolveInfo2.activityInfo = new ActivityInfo(); |
| 717 | resolveInfo2.activityInfo.name = aInfoSecondary.name; |
| 718 | resolveInfo2.activityInfo.applicationInfo = aInfoSecondary.applicationInfo; |
| 719 | resolutions2.add(resolveInfo2); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 720 | doReturn(resolutions2).when(mRootWindowContainer).resolveActivities(anyInt(), |
Keun young Park | 340546a | 2019-05-06 16:27:44 -0700 | [diff] [blame] | 721 | refEq(secondaryHomeIntent)); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 722 | doReturn(true).when(mRootWindowContainer).canStartHomeOnDisplay( |
Keun young Park | 340546a | 2019-05-06 16:27:44 -0700 | [diff] [blame] | 723 | any(), anyInt(), anyBoolean()); |
| 724 | |
| 725 | // Run the test |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 726 | final Pair<ActivityInfo, Intent> resolvedInfo = mRootWindowContainer |
Keun young Park | 340546a | 2019-05-06 16:27:44 -0700 | [diff] [blame] | 727 | .resolveSecondaryHomeActivity(0 /* userId */, 1 /* displayId */); |
| 728 | assertEquals(secondaryComp.getClassName(), resolvedInfo.first.name); |
| 729 | assertEquals(secondaryComp.getPackageName(), |
| 730 | resolvedInfo.first.applicationInfo.packageName); |
| 731 | assertEquals(aInfoSecondary.name, resolvedInfo.first.name); |
| 732 | } finally { |
| 733 | // tearDown |
| 734 | reset(resources); |
| 735 | } |
| 736 | } |
| 737 | |
| 738 | /** |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 739 | * Tests that secondary home should be selected if default home not support secondary displays |
| 740 | * or there is no matched activity in the same package as selected default home. |
| 741 | */ |
| 742 | @Test |
| 743 | public void testResolveSecondaryHomeActivityWhenDefaultHomeNotSupportMultiDisplay() { |
Riddle Hsu | ff9e828 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 744 | mockResolveHomeActivity(); |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 745 | |
| 746 | final List<ResolveInfo> resolutions = new ArrayList<>(); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 747 | doReturn(resolutions).when(mRootWindowContainer).resolveActivities(anyInt(), any()); |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 748 | |
| 749 | final String secondaryHomeComponent = mService.mContext.getResources().getString( |
| 750 | com.android.internal.R.string.config_secondaryHomeComponent); |
| 751 | final ComponentName comp = ComponentName.unflattenFromString(secondaryHomeComponent); |
| 752 | final Intent secondaryHomeIntent = mService.getSecondaryHomeIntent(null); |
| 753 | final ActivityInfo aInfoSecondary = new ActivityInfo(); |
| 754 | aInfoSecondary.name = comp.getClassName(); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 755 | doReturn(aInfoSecondary).when(mRootWindowContainer).resolveHomeActivity(anyInt(), |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 756 | refEq(secondaryHomeIntent)); |
| 757 | |
| 758 | // Should fallback to secondary home if selected default home not support secondary displays |
| 759 | // or there is no matched activity in the same package as selected default home. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 760 | final Pair<ActivityInfo, Intent> resolvedInfo = mRootWindowContainer |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 761 | .resolveSecondaryHomeActivity(0 /* userId */, 1 /* displayId */); |
| 762 | |
| 763 | assertEquals(comp.getClassName(), resolvedInfo.first.name); |
| 764 | } |
| 765 | |
| 766 | /** |
| 767 | * Tests that default home activity should be selected if it already support secondary displays. |
| 768 | */ |
| 769 | @Test |
| 770 | public void testResolveSecondaryHomeActivityWhenDefaultHomeSupportMultiDisplay() { |
Riddle Hsu | ff9e828 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 771 | final ActivityInfo aInfoDefault = mockResolveHomeActivity(); |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 772 | |
| 773 | final List<ResolveInfo> resolutions = new ArrayList<>(); |
| 774 | final ResolveInfo infoFake1 = new ResolveInfo(); |
| 775 | infoFake1.activityInfo = new ActivityInfo(); |
| 776 | infoFake1.activityInfo.name = "fakeActivity1"; |
| 777 | infoFake1.activityInfo.applicationInfo = new ApplicationInfo(); |
| 778 | infoFake1.activityInfo.applicationInfo.packageName = "fakePackage1"; |
| 779 | final ResolveInfo infoFake2 = new ResolveInfo(); |
| 780 | infoFake2.activityInfo = aInfoDefault; |
| 781 | resolutions.add(infoFake1); |
| 782 | resolutions.add(infoFake2); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 783 | doReturn(resolutions).when(mRootWindowContainer).resolveActivities(anyInt(), any()); |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 784 | |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 785 | doReturn(true).when(mRootWindowContainer).canStartHomeOnDisplay( |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 786 | any(), anyInt(), anyBoolean()); |
| 787 | |
| 788 | // Use default home activity if it support secondary displays. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 789 | final Pair<ActivityInfo, Intent> resolvedInfo = mRootWindowContainer |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 790 | .resolveSecondaryHomeActivity(0 /* userId */, 1 /* displayId */); |
| 791 | |
| 792 | assertEquals(aInfoDefault.applicationInfo.packageName, |
| 793 | resolvedInfo.first.applicationInfo.packageName); |
| 794 | assertEquals(aInfoDefault.name, resolvedInfo.first.name); |
| 795 | } |
| 796 | |
| 797 | /** |
| 798 | * Tests that the first one that matches should be selected if there are multiple activities. |
| 799 | */ |
| 800 | @Test |
| 801 | public void testResolveSecondaryHomeActivityWhenOtherActivitySupportMultiDisplay() { |
Riddle Hsu | ff9e828 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 802 | mockResolveHomeActivity(); |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 803 | |
| 804 | final List<ResolveInfo> resolutions = new ArrayList<>(); |
| 805 | final ResolveInfo infoFake1 = new ResolveInfo(); |
| 806 | infoFake1.activityInfo = new ActivityInfo(); |
| 807 | infoFake1.activityInfo.name = "fakeActivity1"; |
| 808 | infoFake1.activityInfo.applicationInfo = new ApplicationInfo(); |
| 809 | infoFake1.activityInfo.applicationInfo.packageName = "fakePackage1"; |
| 810 | final ResolveInfo infoFake2 = new ResolveInfo(); |
| 811 | infoFake2.activityInfo = new ActivityInfo(); |
| 812 | infoFake2.activityInfo.name = "fakeActivity2"; |
| 813 | infoFake2.activityInfo.applicationInfo = new ApplicationInfo(); |
| 814 | infoFake2.activityInfo.applicationInfo.packageName = "fakePackage2"; |
| 815 | resolutions.add(infoFake1); |
| 816 | resolutions.add(infoFake2); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 817 | doReturn(resolutions).when(mRootWindowContainer).resolveActivities(anyInt(), any()); |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 818 | |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 819 | doReturn(true).when(mRootWindowContainer).canStartHomeOnDisplay( |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 820 | any(), anyInt(), anyBoolean()); |
| 821 | |
| 822 | // Use the first one of matched activities in the same package as selected default home. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 823 | final Pair<ActivityInfo, Intent> resolvedInfo = mRootWindowContainer |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 824 | .resolveSecondaryHomeActivity(0 /* userId */, 1 /* displayId */); |
| 825 | |
| 826 | assertEquals(infoFake1.activityInfo.applicationInfo.packageName, |
| 827 | resolvedInfo.first.applicationInfo.packageName); |
| 828 | assertEquals(infoFake1.activityInfo.name, resolvedInfo.first.name); |
| 829 | } |
Riddle Hsu | ff9e828 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 830 | |
| 831 | /** |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 832 | * Test that {@link RootWindowContainer#getLaunchStack} with the real caller id will get the |
lumark | f65e02d | 2019-09-14 19:25:21 +0800 | [diff] [blame] | 833 | * expected stack when requesting the activity launch on the secondary display. |
| 834 | */ |
| 835 | @Test |
| 836 | public void testGetLaunchStackWithRealCallerId() { |
| 837 | // Create a non-system owned virtual display. |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 838 | final TestDisplayContent secondaryDisplay = |
| 839 | new TestDisplayContent.Builder(mService, 1000, 1500) |
Evan Rosky | 4a51dbc0 | 2019-09-11 17:28:07 -0700 | [diff] [blame] | 840 | .setType(TYPE_VIRTUAL).setOwnerUid(100).build(); |
lumark | f65e02d | 2019-09-14 19:25:21 +0800 | [diff] [blame] | 841 | |
| 842 | // Create an activity with specify the original launch pid / uid. |
| 843 | final ActivityRecord r = new ActivityBuilder(mService).setLaunchedFromPid(200) |
| 844 | .setLaunchedFromUid(200).build(); |
| 845 | |
| 846 | // Simulate ActivityStarter to find a launch stack for requesting the activity to launch |
| 847 | // on the secondary display with realCallerId. |
| 848 | final ActivityOptions options = ActivityOptions.makeBasic(); |
| 849 | options.setLaunchDisplayId(secondaryDisplay.mDisplayId); |
| 850 | options.setLaunchWindowingMode(WINDOWING_MODE_FULLSCREEN); |
| 851 | doReturn(true).when(mSupervisor).canPlaceEntityOnDisplay(secondaryDisplay.mDisplayId, |
| 852 | 300 /* test realCallerPid */, 300 /* test realCallerUid */, r.info); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 853 | final ActivityStack result = mRootWindowContainer.getLaunchStack(r, options, |
lumark | f65e02d | 2019-09-14 19:25:21 +0800 | [diff] [blame] | 854 | null /* task */, true /* onTop */, null, 300 /* test realCallerPid */, |
| 855 | 300 /* test realCallerUid */); |
| 856 | |
| 857 | // Assert that the stack is returned as expected. |
| 858 | assertNotNull(result); |
| 859 | assertEquals("The display ID of the stack should same as secondary display ", |
| 860 | secondaryDisplay.mDisplayId, result.mDisplayId); |
| 861 | } |
| 862 | |
| 863 | /** |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 864 | * Mock {@link RootWindowContainer#resolveHomeActivity} for returning consistent activity |
Riddle Hsu | ff9e828 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 865 | * info for test cases (the original implementation will resolve from the real package manager). |
| 866 | */ |
| 867 | private ActivityInfo mockResolveHomeActivity() { |
| 868 | final Intent homeIntent = mService.getHomeIntent(); |
| 869 | final ActivityInfo aInfoDefault = new ActivityInfo(); |
| 870 | aInfoDefault.name = "fakeHomeActivity"; |
| 871 | aInfoDefault.applicationInfo = new ApplicationInfo(); |
| 872 | aInfoDefault.applicationInfo.packageName = "fakeHomePackage"; |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 873 | doReturn(aInfoDefault).when(mRootWindowContainer).resolveHomeActivity(anyInt(), |
Riddle Hsu | ff9e828 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 874 | refEq(homeIntent)); |
| 875 | return aInfoDefault; |
| 876 | } |
Chilun | 5995498 | 2019-05-23 14:50:48 +0800 | [diff] [blame] | 877 | |
| 878 | /** |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 879 | * Mock {@link RootWindowContainer#resolveSecondaryHomeActivity} for returning consistent |
Chilun | 5995498 | 2019-05-23 14:50:48 +0800 | [diff] [blame] | 880 | * activity info for test cases (the original implementation will resolve from the real package |
| 881 | * manager). |
| 882 | */ |
| 883 | private void mockResolveSecondaryHomeActivity() { |
| 884 | final Intent secondaryHomeIntent = mService |
| 885 | .getSecondaryHomeIntent(null /* preferredPackage */); |
| 886 | final ActivityInfo aInfoSecondary = new ActivityInfo(); |
| 887 | aInfoSecondary.name = "fakeSecondaryHomeActivity"; |
| 888 | aInfoSecondary.applicationInfo = new ApplicationInfo(); |
| 889 | aInfoSecondary.applicationInfo.packageName = "fakeSecondaryHomePackage"; |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame^] | 890 | doReturn(Pair.create(aInfoSecondary, secondaryHomeIntent)).when(mRootWindowContainer) |
Chilun | 5995498 | 2019-05-23 14:50:48 +0800 | [diff] [blame] | 891 | .resolveSecondaryHomeActivity(anyInt(), anyInt()); |
| 892 | } |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 893 | } |