blob: 44ca2cdcb14296b0917aa9e79318f06548258f53 [file] [log] [blame]
Winson Chung0f7ec962018-05-03 18:03:15 -07001/*
Wale Ogunwale59507092018-10-29 09:00:30 -07002 * Copyright (C) 2018 The Android Open Source Project
Winson Chung0f7ec962018-05-03 18:03:15 -07003 *
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 Ogunwale59507092018-10-29 09:00:30 -070014 * limitations under the License
Winson Chung0f7ec962018-05-03 18:03:15 -070015 */
16
Wale Ogunwale59507092018-10-29 09:00:30 -070017package com.android.server.wm;
Winson Chung0f7ec962018-05-03 18:03:15 -070018
Winson Chung2bc60c02019-05-16 17:36:05 -070019import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME;
Winson Chung0f7ec962018-05-03 18:03:15 -070020import static android.app.WindowConfiguration.ACTIVITY_TYPE_RECENTS;
21import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD;
22import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
Winson Chung2bc60c02019-05-16 17:36:05 -070023import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;
Brett Chabota26eda92018-07-23 13:08:30 -070024
Riddle Hsu43233b72019-04-24 23:55:11 +080025import static com.android.dx.mockito.inline.extended.ExtendedMockito.doAnswer;
Riddle Hsu0e591722019-05-03 22:22:36 +080026import static com.android.dx.mockito.inline.extended.ExtendedMockito.doCallRealMethod;
Louis Chang7cf84602019-05-30 15:35:40 +080027import static com.android.dx.mockito.inline.extended.ExtendedMockito.doNothing;
Tadashi G. Takaokaa7a66952018-11-16 15:04:21 +090028import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
29import static com.android.dx.mockito.inline.extended.ExtendedMockito.eq;
30import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock;
Wale Ogunwaleb73f3962018-11-20 07:58:22 -080031import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn;
Tadashi G. Takaokaa7a66952018-11-16 15:04:21 +090032import static com.android.dx.mockito.inline.extended.ExtendedMockito.times;
33import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify;
Louis Chang7cf84602019-05-30 15:35:40 +080034import static com.android.server.wm.ActivityStack.ActivityState.PAUSED;
Winson Chung0f7ec962018-05-03 18:03:15 -070035import static com.android.server.wm.RecentsAnimationController.REORDER_KEEP_IN_PLACE;
Brett Chabota26eda92018-07-23 13:08:30 -070036
Louis Chang7cf84602019-05-30 15:35:40 +080037import static com.google.common.truth.Truth.assertThat;
38
Riddle Hsu43233b72019-04-24 23:55:11 +080039import static org.junit.Assert.assertFalse;
40import static org.junit.Assert.assertTrue;
lumark54284462019-03-05 20:44:27 +080041import static org.mockito.ArgumentMatchers.any;
Riddle Hsu0e591722019-05-03 22:22:36 +080042import static org.mockito.ArgumentMatchers.anyBoolean;
Riddle Hsu43233b72019-04-24 23:55:11 +080043import static org.mockito.ArgumentMatchers.anyInt;
lumark54284462019-03-05 20:44:27 +080044
Riddle Hsu609a8e22019-06-27 16:46:29 -060045import android.app.IApplicationThread;
Winson Chung0f7ec962018-05-03 18:03:15 -070046import android.content.ComponentName;
Winson Chung0f7ec962018-05-03 18:03:15 -070047import android.content.Intent;
Riddle Hsu609a8e22019-06-27 16:46:29 -060048import android.content.pm.ActivityInfo;
49import android.content.pm.ApplicationInfo;
Winson Chung0f7ec962018-05-03 18:03:15 -070050import android.platform.test.annotations.Presubmit;
Winson Chung0f7ec962018-05-03 18:03:15 -070051import android.view.IRecentsAnimationRunner;
Brett Chabota26eda92018-07-23 13:08:30 -070052
Brett Chabota26eda92018-07-23 13:08:30 -070053import androidx.test.filters.MediumTest;
Brett Chabota26eda92018-07-23 13:08:30 -070054
Riddle Hsu43233b72019-04-24 23:55:11 +080055import com.android.server.wm.RecentsAnimationController.RecentsAnimationCallbacks;
56
Winson Chung0f7ec962018-05-03 18:03:15 -070057import org.junit.Before;
58import org.junit.Test;
Riddle Hsu2da2d032019-08-28 21:08:58 +080059import org.junit.runner.RunWith;
Winson Chung0f7ec962018-05-03 18:03:15 -070060
61/**
Tadashi G. Takaoka74ccec22018-10-23 11:07:13 +090062 * Build/Install/Run:
63 * atest WmTests:RecentsAnimationTest
Winson Chung0f7ec962018-05-03 18:03:15 -070064 */
65@MediumTest
66@Presubmit
Riddle Hsu2da2d032019-08-28 21:08:58 +080067@RunWith(WindowTestRunner.class)
Winson Chung0f7ec962018-05-03 18:03:15 -070068public class RecentsAnimationTest extends ActivityTestsBase {
Winson Chung0f7ec962018-05-03 18:03:15 -070069
Winson Chung2bc60c02019-05-16 17:36:05 -070070 private static final int TEST_USER_ID = 100;
71
Riddle Hsu43233b72019-04-24 23:55:11 +080072 private final ComponentName mRecentsComponent =
73 new ComponentName(mContext.getPackageName(), "RecentsActivity");
lumark54284462019-03-05 20:44:27 +080074 private RecentsAnimationController mRecentsAnimationController;
Winson Chung0f7ec962018-05-03 18:03:15 -070075
76 @Before
Winson Chung0f7ec962018-05-03 18:03:15 -070077 public void setUp() throws Exception {
lumark54284462019-03-05 20:44:27 +080078 mRecentsAnimationController = mock(RecentsAnimationController.class);
Wale Ogunwale8a1860a2019-06-05 08:57:19 -070079 mService.mWindowManager.setRecentsAnimationController(mRecentsAnimationController);
80 doNothing().when(mService.mWindowManager).initializeRecentsAnimation(
wilsonshih417b70c12019-10-16 16:12:02 +080081 anyInt(), any(), any(), anyInt(), any(), any());
Wale Ogunwaleb73f3962018-11-20 07:58:22 -080082
83 final RecentTasks recentTasks = mService.getRecentTasks();
84 spyOn(recentTasks);
Wale Ogunwaleb73f3962018-11-20 07:58:22 -080085 doReturn(mRecentsComponent).when(recentTasks).getRecentsComponent();
Winson Chung0f7ec962018-05-03 18:03:15 -070086 }
87
88 @Test
Riddle Hsu0e591722019-05-03 22:22:36 +080089 public void testRecentsActivityVisiblility() {
Andrii Kulian4c0fd0d2020-03-29 13:32:14 -070090 TaskDisplayArea taskDisplayArea = mRootWindowContainer.getDefaultTaskDisplayArea();
Andrii Kulian86d676c2020-03-27 19:34:54 -070091 ActivityStack recentsStack = taskDisplayArea.createStack(WINDOWING_MODE_FULLSCREEN,
Riddle Hsu0e591722019-05-03 22:22:36 +080092 ACTIVITY_TYPE_RECENTS, true /* onTop */);
93 ActivityRecord recentActivity = new ActivityBuilder(mService)
94 .setComponent(mRecentsComponent)
95 .setCreateTask(true)
96 .setStack(recentsStack)
97 .build();
98 ActivityRecord topActivity = new ActivityBuilder(mService).setCreateTask(true).build();
Wale Ogunwale1ebcd8e2020-01-21 11:27:03 -080099 topActivity.getRootTask().moveToFront("testRecentsActivityVisiblility");
Riddle Hsu0e591722019-05-03 22:22:36 +0800100
Louis Chang149d5c82019-12-30 09:47:39 +0800101 doCallRealMethod().when(mRootWindowContainer).ensureActivitiesVisible(
Riddle Hsu0e591722019-05-03 22:22:36 +0800102 any() /* starting */, anyInt() /* configChanges */,
Louis Chang3ff72a82019-12-17 12:12:59 +0800103 anyBoolean() /* preserveWindows */, anyBoolean() /* notifyClients */);
Riddle Hsu0e591722019-05-03 22:22:36 +0800104
105 RecentsAnimationCallbacks recentsAnimation = startRecentsActivity(
106 mRecentsComponent, true /* getRecentsAnimation */);
107 // The launch-behind state should make the recents activity visible.
Issei Suzuki1669ea42019-11-06 14:20:59 +0100108 assertTrue(recentActivity.mVisibleRequested);
Riddle Hsu0e591722019-05-03 22:22:36 +0800109
110 // Simulate the animation is cancelled without changing the stack order.
Wale Ogunwalea441b922019-06-27 19:21:44 -0700111 recentsAnimation.onAnimationFinished(REORDER_KEEP_IN_PLACE, false /* sendUserLeaveHint */);
Riddle Hsu0e591722019-05-03 22:22:36 +0800112 // The non-top recents activity should be invisible by the restored launch-behind state.
Issei Suzuki1669ea42019-11-06 14:20:59 +0100113 assertFalse(recentActivity.mVisibleRequested);
Riddle Hsu0e591722019-05-03 22:22:36 +0800114 }
115
116 @Test
Riddle Hsu609a8e22019-06-27 16:46:29 -0600117 public void testPreloadRecentsActivity() {
Andrii Kulian4c0fd0d2020-03-29 13:32:14 -0700118 TaskDisplayArea defaultTaskDisplayArea = mRootWindowContainer.getDefaultTaskDisplayArea();
Wale Ogunwale8a1860a2019-06-05 08:57:19 -0700119 final ActivityStack homeStack =
Andrii Kulian86d676c2020-03-27 19:34:54 -0700120 defaultTaskDisplayArea.getStack(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME);
121 defaultTaskDisplayArea.positionStackAtTop(homeStack, false /* includingParents */);
Wale Ogunwale85fb19a2019-12-05 10:41:05 +0900122 ActivityRecord topRunningHomeActivity = homeStack.topRunningActivity();
Wale Ogunwale8a1860a2019-06-05 08:57:19 -0700123 if (topRunningHomeActivity == null) {
124 topRunningHomeActivity = new ActivityBuilder(mService)
125 .setStack(homeStack)
126 .setCreateTask(true)
127 .build();
128 }
129
Riddle Hsu609a8e22019-06-27 16:46:29 -0600130 ActivityInfo aInfo = new ActivityInfo();
131 aInfo.applicationInfo = new ApplicationInfo();
132 aInfo.applicationInfo.uid = 10001;
133 aInfo.applicationInfo.targetSdkVersion = mContext.getApplicationInfo().targetSdkVersion;
134 aInfo.packageName = aInfo.applicationInfo.packageName = mRecentsComponent.getPackageName();
135 aInfo.processName = "recents";
136 doReturn(aInfo).when(mSupervisor).resolveActivity(any() /* intent */, any() /* rInfo */,
137 anyInt() /* startFlags */, any() /* profilerInfo */);
138
139 // Assume its process is alive because the caller should be the recents service.
140 WindowProcessController wpc = new WindowProcessController(mService, aInfo.applicationInfo,
141 aInfo.processName, aInfo.applicationInfo.uid, 0 /* userId */,
142 mock(Object.class) /* owner */, mock(WindowProcessListener.class));
143 wpc.setThread(mock(IApplicationThread.class));
144 doReturn(wpc).when(mService).getProcessController(eq(wpc.mName), eq(wpc.mUid));
145
146 Intent recentsIntent = new Intent().setComponent(mRecentsComponent);
147 // Null animation indicates to preload.
148 mService.startRecentsActivity(recentsIntent, null /* assistDataReceiver */,
149 null /* recentsAnimationRunner */);
150
Andrii Kulian86d676c2020-03-27 19:34:54 -0700151 ActivityStack recentsStack = defaultTaskDisplayArea.getStack(WINDOWING_MODE_FULLSCREEN,
Riddle Hsu609a8e22019-06-27 16:46:29 -0600152 ACTIVITY_TYPE_RECENTS);
153 assertThat(recentsStack).isNotNull();
154
Wale Ogunwale21e06482019-11-18 05:14:15 -0800155 ActivityRecord recentsActivity = recentsStack.getTopNonFinishingActivity();
Riddle Hsu609a8e22019-06-27 16:46:29 -0600156 // The activity is started in background so it should be invisible and will be stopped.
157 assertThat(recentsActivity).isNotNull();
158 assertThat(mSupervisor.mStoppingActivities).contains(recentsActivity);
Issei Suzuki1669ea42019-11-06 14:20:59 +0100159 assertFalse(recentsActivity.mVisibleRequested);
Riddle Hsu609a8e22019-06-27 16:46:29 -0600160
161 // Assume it is stopped to test next use case.
Wale Ogunwale196db712019-12-27 15:35:39 +0000162 recentsActivity.activityStopped(null /* newIcicle */, null /* newPersistentState */,
Riddle Hsu609a8e22019-06-27 16:46:29 -0600163 null /* description */);
164 mSupervisor.mStoppingActivities.remove(recentsActivity);
165
166 spyOn(recentsActivity);
167 // Start when the recents activity exists. It should ensure the configuration.
168 mService.startRecentsActivity(recentsIntent, null /* assistDataReceiver */,
169 null /* recentsAnimationRunner */);
170
171 verify(recentsActivity).ensureActivityConfiguration(anyInt() /* globalChanges */,
172 anyBoolean() /* preserveWindow */, eq(true) /* ignoreVisibility */);
173 assertThat(mSupervisor.mStoppingActivities).contains(recentsActivity);
174 }
175
176 @Test
Louis Chang7cf84602019-05-30 15:35:40 +0800177 public void testRestartRecentsActivity() throws Exception {
178 // Have a recents activity that is not attached to its process (ActivityRecord.app = null).
Andrii Kulian4c0fd0d2020-03-29 13:32:14 -0700179 TaskDisplayArea defaultTaskDisplayArea = mRootWindowContainer.getDefaultTaskDisplayArea();
Andrii Kulian86d676c2020-03-27 19:34:54 -0700180 ActivityStack recentsStack = defaultTaskDisplayArea.createStack(WINDOWING_MODE_FULLSCREEN,
Louis Chang7cf84602019-05-30 15:35:40 +0800181 ACTIVITY_TYPE_RECENTS, true /* onTop */);
182 ActivityRecord recentActivity = new ActivityBuilder(mService).setComponent(
183 mRecentsComponent).setCreateTask(true).setStack(recentsStack).build();
184 WindowProcessController app = recentActivity.app;
185 recentActivity.app = null;
186
187 // Start an activity on top.
Wale Ogunwale1ebcd8e2020-01-21 11:27:03 -0800188 new ActivityBuilder(mService).setCreateTask(true).build().getRootTask().moveToFront(
Louis Chang7cf84602019-05-30 15:35:40 +0800189 "testRestartRecentsActivity");
190
Louis Chang149d5c82019-12-30 09:47:39 +0800191 doCallRealMethod().when(mRootWindowContainer).ensureActivitiesVisible(
Louis Chang7cf84602019-05-30 15:35:40 +0800192 any() /* starting */, anyInt() /* configChanges */,
Louis Chang3ff72a82019-12-17 12:12:59 +0800193 anyBoolean() /* preserveWindows */, anyBoolean() /* notifyClients */);
Louis Chang7cf84602019-05-30 15:35:40 +0800194 doReturn(app).when(mService).getProcessController(eq(recentActivity.processName), anyInt());
195 ClientLifecycleManager lifecycleManager = mService.getLifecycleManager();
196 doNothing().when(lifecycleManager).scheduleTransaction(any());
Louis Chang7cf84602019-05-30 15:35:40 +0800197
198 startRecentsActivity();
199
200 // Recents activity must be restarted, but not be resumed while running recents animation.
Louis Chang149d5c82019-12-30 09:47:39 +0800201 verify(mRootWindowContainer.mStackSupervisor).startSpecificActivity(
Louis Chang7cf84602019-05-30 15:35:40 +0800202 eq(recentActivity), eq(false), anyBoolean());
203 assertThat(recentActivity.getState()).isEqualTo(PAUSED);
204 }
205
206 @Test
Riddle Hsu43233b72019-04-24 23:55:11 +0800207 public void testSetLaunchTaskBehindOfTargetActivity() {
Andrii Kulian4c0fd0d2020-03-29 13:32:14 -0700208 TaskDisplayArea taskDisplayArea = mRootWindowContainer.getDefaultTaskDisplayArea();
Andrii Kulian86d676c2020-03-27 19:34:54 -0700209 ActivityStack homeStack = taskDisplayArea.getRootHomeTask();
Riddle Hsu43233b72019-04-24 23:55:11 +0800210 // Assume the home activity support recents.
Wale Ogunwale21e06482019-11-18 05:14:15 -0800211 ActivityRecord targetActivity = homeStack.getTopNonFinishingActivity();
Wale Ogunwale8a1860a2019-06-05 08:57:19 -0700212 if (targetActivity == null) {
213 targetActivity = new ActivityBuilder(mService)
214 .setCreateTask(true)
215 .setStack(homeStack)
216 .build();
217 }
218
Riddle Hsu43233b72019-04-24 23:55:11 +0800219 // Put another home activity in home stack.
220 ActivityRecord anotherHomeActivity = new ActivityBuilder(mService)
221 .setComponent(new ComponentName(mContext.getPackageName(), "Home2"))
222 .setCreateTask(true)
223 .setStack(homeStack)
224 .build();
225 // Start an activity on top so the recents activity can be started.
226 new ActivityBuilder(mService)
227 .setCreateTask(true)
228 .build()
Wale Ogunwale1ebcd8e2020-01-21 11:27:03 -0800229 .getRootTask()
Riddle Hsu43233b72019-04-24 23:55:11 +0800230 .moveToFront("Activity start");
231
232 // Start the recents animation.
233 RecentsAnimationCallbacks recentsAnimation = startRecentsActivity(
Louis Changcdec0802019-11-11 11:45:07 +0800234 targetActivity.getTask().getBaseIntent().getComponent(),
Riddle Hsu43233b72019-04-24 23:55:11 +0800235 true /* getRecentsAnimation */);
236 // Ensure launch-behind is set for being visible.
237 assertTrue(targetActivity.mLaunchTaskBehind);
238
239 anotherHomeActivity.moveFocusableActivityToTop("launchAnotherHome");
Riddle Hsu43233b72019-04-24 23:55:11 +0800240
241 // The test uses mocked RecentsAnimationController so we have to invoke the callback
242 // manually to simulate the flow.
Wale Ogunwalea441b922019-06-27 19:21:44 -0700243 recentsAnimation.onAnimationFinished(REORDER_KEEP_IN_PLACE, false /* sendUserLeaveHint */);
Riddle Hsu43233b72019-04-24 23:55:11 +0800244 // We should restore the launch-behind of the original target activity.
245 assertFalse(targetActivity.mLaunchTaskBehind);
246 }
247
248 @Test
Winson Chung65d66d32018-12-13 17:48:39 -0800249 public void testCancelAnimationOnVisibleStackOrderChange() {
Andrii Kulian4c0fd0d2020-03-29 13:32:14 -0700250 TaskDisplayArea taskDisplayArea = mRootWindowContainer.getDefaultTaskDisplayArea();
Andrii Kulian86d676c2020-03-27 19:34:54 -0700251 ActivityStack fullscreenStack = taskDisplayArea.createStack(WINDOWING_MODE_FULLSCREEN,
Winson Chung65d66d32018-12-13 17:48:39 -0800252 ACTIVITY_TYPE_STANDARD, true /* onTop */);
253 new ActivityBuilder(mService)
254 .setComponent(new ComponentName(mContext.getPackageName(), "App1"))
255 .setCreateTask(true)
256 .setStack(fullscreenStack)
257 .build();
Andrii Kulian86d676c2020-03-27 19:34:54 -0700258 ActivityStack recentsStack = taskDisplayArea.createStack(WINDOWING_MODE_FULLSCREEN,
Winson Chung65d66d32018-12-13 17:48:39 -0800259 ACTIVITY_TYPE_RECENTS, true /* onTop */);
260 new ActivityBuilder(mService)
Winson Chung0f7ec962018-05-03 18:03:15 -0700261 .setComponent(mRecentsComponent)
262 .setCreateTask(true)
263 .setStack(recentsStack)
264 .build();
Andrii Kulian86d676c2020-03-27 19:34:54 -0700265 ActivityStack fullscreenStack2 = taskDisplayArea.createStack(WINDOWING_MODE_FULLSCREEN,
Winson Chung65d66d32018-12-13 17:48:39 -0800266 ACTIVITY_TYPE_STANDARD, true /* onTop */);
267 new ActivityBuilder(mService)
268 .setComponent(new ComponentName(mContext.getPackageName(), "App2"))
Winson Chung0f7ec962018-05-03 18:03:15 -0700269 .setCreateTask(true)
270 .setStack(fullscreenStack2)
271 .build();
Winson Chung0f7ec962018-05-03 18:03:15 -0700272
273 // Start the recents animation
Riddle Hsu43233b72019-04-24 23:55:11 +0800274 startRecentsActivity();
Winson Chung0f7ec962018-05-03 18:03:15 -0700275
276 fullscreenStack.moveToFront("Activity start");
277
lumark54284462019-03-05 20:44:27 +0800278 // Assume recents animation already started, set a state that cancel recents animation
279 // with screenshot.
Winson Chung7a545ae2019-07-16 14:52:13 -0700280 doReturn(true).when(mRecentsAnimationController).shouldDeferCancelUntilNextTransition();
281 doReturn(true).when(mRecentsAnimationController).shouldDeferCancelWithScreenshot();
lumark54284462019-03-05 20:44:27 +0800282 // Start another fullscreen activity.
283 fullscreenStack2.moveToFront("Activity start");
284
Winson Chung7a545ae2019-07-16 14:52:13 -0700285 // Ensure that the recents animation was canceled by setCancelOnNextTransitionStart().
286 verify(mRecentsAnimationController, times(1)).setCancelOnNextTransitionStart();
Winson Chung0f7ec962018-05-03 18:03:15 -0700287 }
Winson Chung65d66d32018-12-13 17:48:39 -0800288
289 @Test
290 public void testKeepAnimationOnHiddenStackOrderChange() {
Andrii Kulian4c0fd0d2020-03-29 13:32:14 -0700291 TaskDisplayArea taskDisplayArea = mRootWindowContainer.getDefaultTaskDisplayArea();
Andrii Kulian86d676c2020-03-27 19:34:54 -0700292 ActivityStack fullscreenStack = taskDisplayArea.createStack(WINDOWING_MODE_FULLSCREEN,
Winson Chung65d66d32018-12-13 17:48:39 -0800293 ACTIVITY_TYPE_STANDARD, true /* onTop */);
294 new ActivityBuilder(mService)
295 .setComponent(new ComponentName(mContext.getPackageName(), "App1"))
296 .setCreateTask(true)
297 .setStack(fullscreenStack)
298 .build();
Andrii Kulian86d676c2020-03-27 19:34:54 -0700299 ActivityStack recentsStack = taskDisplayArea.createStack(WINDOWING_MODE_FULLSCREEN,
Winson Chung65d66d32018-12-13 17:48:39 -0800300 ACTIVITY_TYPE_RECENTS, true /* onTop */);
301 new ActivityBuilder(mService)
302 .setComponent(mRecentsComponent)
303 .setCreateTask(true)
304 .setStack(recentsStack)
305 .build();
Andrii Kulian86d676c2020-03-27 19:34:54 -0700306 ActivityStack fullscreenStack2 = taskDisplayArea.createStack(WINDOWING_MODE_FULLSCREEN,
Winson Chung65d66d32018-12-13 17:48:39 -0800307 ACTIVITY_TYPE_STANDARD, true /* onTop */);
308 new ActivityBuilder(mService)
309 .setComponent(new ComponentName(mContext.getPackageName(), "App2"))
310 .setCreateTask(true)
311 .setStack(fullscreenStack2)
312 .build();
Winson Chung65d66d32018-12-13 17:48:39 -0800313
314 // Start the recents animation
Riddle Hsu43233b72019-04-24 23:55:11 +0800315 startRecentsActivity();
Winson Chung65d66d32018-12-13 17:48:39 -0800316
Wale Ogunwalebebd8cd2019-10-28 15:53:31 -0700317 fullscreenStack.removeIfPossible();
Winson Chung65d66d32018-12-13 17:48:39 -0800318
319 // Ensure that the recents animation was NOT canceled
Wale Ogunwalea441b922019-06-27 19:21:44 -0700320 verify(mService.mWindowManager, times(0)).cancelRecentsAnimation(
Winson Chung65d66d32018-12-13 17:48:39 -0800321 eq(REORDER_KEEP_IN_PLACE), any());
Winson Chung7a545ae2019-07-16 14:52:13 -0700322 verify(mRecentsAnimationController, times(0)).setCancelOnNextTransitionStart();
Winson Chung65d66d32018-12-13 17:48:39 -0800323 }
Riddle Hsu43233b72019-04-24 23:55:11 +0800324
Winson Chung2bc60c02019-05-16 17:36:05 -0700325 @Test
326 public void testMultipleUserHomeActivity_findUserHomeTask() {
Andrii Kulian4c0fd0d2020-03-29 13:32:14 -0700327 TaskDisplayArea taskDisplayArea = mRootWindowContainer.getDefaultDisplay()
328 .getDefaultTaskDisplayArea();
Andrii Kulian86d676c2020-03-27 19:34:54 -0700329 ActivityStack homeStack = taskDisplayArea.getStack(WINDOWING_MODE_UNDEFINED,
330 ACTIVITY_TYPE_HOME);
Winson Chung2bc60c02019-05-16 17:36:05 -0700331 ActivityRecord otherUserHomeActivity = new ActivityBuilder(mService)
332 .setStack(homeStack)
333 .setCreateTask(true)
334 .setComponent(new ComponentName(mContext.getPackageName(), "Home2"))
335 .build();
Louis Changcdec0802019-11-11 11:45:07 +0800336 otherUserHomeActivity.getTask().mUserId = TEST_USER_ID;
Winson Chung2bc60c02019-05-16 17:36:05 -0700337
Andrii Kulian86d676c2020-03-27 19:34:54 -0700338 ActivityStack fullscreenStack = taskDisplayArea.createStack(WINDOWING_MODE_FULLSCREEN,
Winson Chung2bc60c02019-05-16 17:36:05 -0700339 ACTIVITY_TYPE_STANDARD, true /* onTop */);
340 new ActivityBuilder(mService)
341 .setComponent(new ComponentName(mContext.getPackageName(), "App1"))
342 .setCreateTask(true)
343 .setStack(fullscreenStack)
344 .build();
345
346 doReturn(TEST_USER_ID).when(mService).getCurrentUserId();
Louis Chang149d5c82019-12-30 09:47:39 +0800347 doCallRealMethod().when(mRootWindowContainer).ensureActivitiesVisible(
Winson Chung2bc60c02019-05-16 17:36:05 -0700348 any() /* starting */, anyInt() /* configChanges */,
Louis Chang3ff72a82019-12-17 12:12:59 +0800349 anyBoolean() /* preserveWindows */, anyBoolean() /* notifyClients */);
Winson Chung2bc60c02019-05-16 17:36:05 -0700350
Louis Changcdec0802019-11-11 11:45:07 +0800351 startRecentsActivity(otherUserHomeActivity.getTask().getBaseIntent().getComponent(),
Winson Chung2bc60c02019-05-16 17:36:05 -0700352 true);
353
354 // Ensure we find the task for the right user and it is made visible
Issei Suzuki1669ea42019-11-06 14:20:59 +0100355 assertTrue(otherUserHomeActivity.mVisibleRequested);
Winson Chung2bc60c02019-05-16 17:36:05 -0700356 }
357
Riddle Hsu43233b72019-04-24 23:55:11 +0800358 private void startRecentsActivity() {
359 startRecentsActivity(mRecentsComponent, false /* getRecentsAnimation */);
360 }
361
362 /**
363 * @return non-null {@link RecentsAnimationCallbacks} if the given {@code getRecentsAnimation}
364 * is {@code true}.
365 */
366 private RecentsAnimationCallbacks startRecentsActivity(ComponentName recentsComponent,
367 boolean getRecentsAnimation) {
368 RecentsAnimationCallbacks[] recentsAnimation = { null };
369 if (getRecentsAnimation) {
370 doAnswer(invocation -> {
371 // The callback is actually RecentsAnimation.
372 recentsAnimation[0] = invocation.getArgument(2);
373 return null;
374 }).when(mService.mWindowManager).initializeRecentsAnimation(
375 anyInt() /* targetActivityType */, any() /* recentsAnimationRunner */,
wilsonshih417b70c12019-10-16 16:12:02 +0800376 any() /* callbacks */, anyInt() /* displayId */, any() /* recentTaskIds */,
377 any() /* targetActivity */);
Riddle Hsu43233b72019-04-24 23:55:11 +0800378 }
379
380 Intent recentsIntent = new Intent();
381 recentsIntent.setComponent(recentsComponent);
382 mService.startRecentsActivity(recentsIntent, null /* assistDataReceiver */,
383 mock(IRecentsAnimationRunner.class));
384 return recentsAnimation[0];
385 }
Winson Chung0f7ec962018-05-03 18:03:15 -0700386}