blob: ca8f5351c73a1cc8095e420ff5bc02519156a8bc [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());
Riddle Hsu43233b72019-04-24 23:55:11 +080082 doReturn(true).when(mService.mWindowManager).canStartRecentsAnimation();
Wale Ogunwaleb73f3962018-11-20 07:58:22 -080083
84 final RecentTasks recentTasks = mService.getRecentTasks();
85 spyOn(recentTasks);
Wale Ogunwaleb73f3962018-11-20 07:58:22 -080086 doReturn(mRecentsComponent).when(recentTasks).getRecentsComponent();
Winson Chung0f7ec962018-05-03 18:03:15 -070087 }
88
89 @Test
Riddle Hsu0e591722019-05-03 22:22:36 +080090 public void testRecentsActivityVisiblility() {
91 ActivityDisplay display = mRootActivityContainer.getDefaultDisplay();
92 ActivityStack recentsStack = display.createStack(WINDOWING_MODE_FULLSCREEN,
93 ACTIVITY_TYPE_RECENTS, true /* onTop */);
94 ActivityRecord recentActivity = new ActivityBuilder(mService)
95 .setComponent(mRecentsComponent)
96 .setCreateTask(true)
97 .setStack(recentsStack)
98 .build();
99 ActivityRecord topActivity = new ActivityBuilder(mService).setCreateTask(true).build();
Riddle Hsu0e591722019-05-03 22:22:36 +0800100 topActivity.getActivityStack().moveToFront("testRecentsActivityVisiblility");
101
102 doCallRealMethod().when(mRootActivityContainer).ensureActivitiesVisible(
103 any() /* starting */, anyInt() /* configChanges */,
104 anyBoolean() /* preserveWindows */);
105
106 RecentsAnimationCallbacks recentsAnimation = startRecentsActivity(
107 mRecentsComponent, true /* getRecentsAnimation */);
108 // The launch-behind state should make the recents activity visible.
109 assertTrue(recentActivity.visible);
110
111 // Simulate the animation is cancelled without changing the stack order.
Wale Ogunwalea441b922019-06-27 19:21:44 -0700112 recentsAnimation.onAnimationFinished(REORDER_KEEP_IN_PLACE, false /* sendUserLeaveHint */);
Riddle Hsu0e591722019-05-03 22:22:36 +0800113 // The non-top recents activity should be invisible by the restored launch-behind state.
114 assertFalse(recentActivity.visible);
115 }
116
117 @Test
Riddle Hsu609a8e22019-06-27 16:46:29 -0600118 public void testPreloadRecentsActivity() {
Wale Ogunwale8a1860a2019-06-05 08:57:19 -0700119 final ActivityDisplay defaultDisplay = mRootActivityContainer.getDefaultDisplay();
120 final ActivityStack homeStack =
121 defaultDisplay.getStack(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME);
122 defaultDisplay.positionChildAtTop(homeStack, false /* includingParents */);
123 ActivityRecord topRunningHomeActivity = homeStack.topRunningActivityLocked();
124 if (topRunningHomeActivity == null) {
125 topRunningHomeActivity = new ActivityBuilder(mService)
126 .setStack(homeStack)
127 .setCreateTask(true)
128 .build();
129 }
130
Riddle Hsu609a8e22019-06-27 16:46:29 -0600131 ActivityInfo aInfo = new ActivityInfo();
132 aInfo.applicationInfo = new ApplicationInfo();
133 aInfo.applicationInfo.uid = 10001;
134 aInfo.applicationInfo.targetSdkVersion = mContext.getApplicationInfo().targetSdkVersion;
135 aInfo.packageName = aInfo.applicationInfo.packageName = mRecentsComponent.getPackageName();
136 aInfo.processName = "recents";
137 doReturn(aInfo).when(mSupervisor).resolveActivity(any() /* intent */, any() /* rInfo */,
138 anyInt() /* startFlags */, any() /* profilerInfo */);
139
140 // Assume its process is alive because the caller should be the recents service.
141 WindowProcessController wpc = new WindowProcessController(mService, aInfo.applicationInfo,
142 aInfo.processName, aInfo.applicationInfo.uid, 0 /* userId */,
143 mock(Object.class) /* owner */, mock(WindowProcessListener.class));
144 wpc.setThread(mock(IApplicationThread.class));
145 doReturn(wpc).when(mService).getProcessController(eq(wpc.mName), eq(wpc.mUid));
146
147 Intent recentsIntent = new Intent().setComponent(mRecentsComponent);
148 // Null animation indicates to preload.
149 mService.startRecentsActivity(recentsIntent, null /* assistDataReceiver */,
150 null /* recentsAnimationRunner */);
151
152 ActivityDisplay display = mRootActivityContainer.getDefaultDisplay();
153 ActivityStack recentsStack = display.getStack(WINDOWING_MODE_FULLSCREEN,
154 ACTIVITY_TYPE_RECENTS);
155 assertThat(recentsStack).isNotNull();
156
157 ActivityRecord recentsActivity = recentsStack.getTopActivity();
158 // The activity is started in background so it should be invisible and will be stopped.
159 assertThat(recentsActivity).isNotNull();
160 assertThat(mSupervisor.mStoppingActivities).contains(recentsActivity);
161 assertFalse(recentsActivity.visible);
162
163 // Assume it is stopped to test next use case.
164 recentsActivity.activityStoppedLocked(null /* newIcicle */, null /* newPersistentState */,
165 null /* description */);
166 mSupervisor.mStoppingActivities.remove(recentsActivity);
167
168 spyOn(recentsActivity);
169 // Start when the recents activity exists. It should ensure the configuration.
170 mService.startRecentsActivity(recentsIntent, null /* assistDataReceiver */,
171 null /* recentsAnimationRunner */);
172
173 verify(recentsActivity).ensureActivityConfiguration(anyInt() /* globalChanges */,
174 anyBoolean() /* preserveWindow */, eq(true) /* ignoreVisibility */);
175 assertThat(mSupervisor.mStoppingActivities).contains(recentsActivity);
176 }
177
178 @Test
Louis Chang7cf84602019-05-30 15:35:40 +0800179 public void testRestartRecentsActivity() throws Exception {
180 // Have a recents activity that is not attached to its process (ActivityRecord.app = null).
181 ActivityDisplay display = mRootActivityContainer.getDefaultDisplay();
182 ActivityStack recentsStack = display.createStack(WINDOWING_MODE_FULLSCREEN,
183 ACTIVITY_TYPE_RECENTS, true /* onTop */);
184 ActivityRecord recentActivity = new ActivityBuilder(mService).setComponent(
185 mRecentsComponent).setCreateTask(true).setStack(recentsStack).build();
186 WindowProcessController app = recentActivity.app;
187 recentActivity.app = null;
188
189 // Start an activity on top.
190 new ActivityBuilder(mService).setCreateTask(true).build().getActivityStack().moveToFront(
191 "testRestartRecentsActivity");
192
193 doCallRealMethod().when(mRootActivityContainer).ensureActivitiesVisible(
194 any() /* starting */, anyInt() /* configChanges */,
195 anyBoolean() /* preserveWindows */);
196 doReturn(app).when(mService).getProcessController(eq(recentActivity.processName), anyInt());
197 ClientLifecycleManager lifecycleManager = mService.getLifecycleManager();
198 doNothing().when(lifecycleManager).scheduleTransaction(any());
Louis Chang7cf84602019-05-30 15:35:40 +0800199
200 startRecentsActivity();
201
202 // Recents activity must be restarted, but not be resumed while running recents animation.
203 verify(mRootActivityContainer.mStackSupervisor).startSpecificActivityLocked(
204 eq(recentActivity), eq(false), anyBoolean());
205 assertThat(recentActivity.getState()).isEqualTo(PAUSED);
206 }
207
208 @Test
Riddle Hsu43233b72019-04-24 23:55:11 +0800209 public void testSetLaunchTaskBehindOfTargetActivity() {
210 ActivityDisplay display = mRootActivityContainer.getDefaultDisplay();
211 display.mDisplayContent.mBoundsAnimationController = mock(BoundsAnimationController.class);
212 ActivityStack homeStack = display.getHomeStack();
213 // Assume the home activity support recents.
214 ActivityRecord targetActivity = homeStack.getTopActivity();
Wale Ogunwale8a1860a2019-06-05 08:57:19 -0700215 if (targetActivity == null) {
216 targetActivity = new ActivityBuilder(mService)
217 .setCreateTask(true)
218 .setStack(homeStack)
219 .build();
220 }
221
Riddle Hsu43233b72019-04-24 23:55:11 +0800222 // Put another home activity in home stack.
223 ActivityRecord anotherHomeActivity = new ActivityBuilder(mService)
224 .setComponent(new ComponentName(mContext.getPackageName(), "Home2"))
225 .setCreateTask(true)
226 .setStack(homeStack)
227 .build();
228 // Start an activity on top so the recents activity can be started.
229 new ActivityBuilder(mService)
230 .setCreateTask(true)
231 .build()
232 .getActivityStack()
233 .moveToFront("Activity start");
234
235 // Start the recents animation.
236 RecentsAnimationCallbacks recentsAnimation = startRecentsActivity(
237 targetActivity.getTaskRecord().getBaseIntent().getComponent(),
238 true /* getRecentsAnimation */);
239 // Ensure launch-behind is set for being visible.
240 assertTrue(targetActivity.mLaunchTaskBehind);
241
242 anotherHomeActivity.moveFocusableActivityToTop("launchAnotherHome");
243 // The current top activity is not the recents so the animation should be canceled.
Wale Ogunwalea441b922019-06-27 19:21:44 -0700244 verify(mService.mWindowManager, times(1)).cancelRecentsAnimation(
Riddle Hsu43233b72019-04-24 23:55:11 +0800245 eq(REORDER_KEEP_IN_PLACE), any() /* reason */);
246
247 // The test uses mocked RecentsAnimationController so we have to invoke the callback
248 // manually to simulate the flow.
Wale Ogunwalea441b922019-06-27 19:21:44 -0700249 recentsAnimation.onAnimationFinished(REORDER_KEEP_IN_PLACE, false /* sendUserLeaveHint */);
Riddle Hsu43233b72019-04-24 23:55:11 +0800250 // We should restore the launch-behind of the original target activity.
251 assertFalse(targetActivity.mLaunchTaskBehind);
252 }
253
254 @Test
Winson Chung65d66d32018-12-13 17:48:39 -0800255 public void testCancelAnimationOnVisibleStackOrderChange() {
256 ActivityDisplay display = mService.mRootActivityContainer.getDefaultDisplay();
Tracy Zhou9c675d42019-04-08 00:32:40 -0700257 display.mDisplayContent.mBoundsAnimationController = mock(BoundsAnimationController.class);
Winson Chung65d66d32018-12-13 17:48:39 -0800258 ActivityStack fullscreenStack = display.createStack(WINDOWING_MODE_FULLSCREEN,
259 ACTIVITY_TYPE_STANDARD, true /* onTop */);
260 new ActivityBuilder(mService)
261 .setComponent(new ComponentName(mContext.getPackageName(), "App1"))
262 .setCreateTask(true)
263 .setStack(fullscreenStack)
264 .build();
265 ActivityStack recentsStack = display.createStack(WINDOWING_MODE_FULLSCREEN,
266 ACTIVITY_TYPE_RECENTS, true /* onTop */);
267 new ActivityBuilder(mService)
Winson Chung0f7ec962018-05-03 18:03:15 -0700268 .setComponent(mRecentsComponent)
269 .setCreateTask(true)
270 .setStack(recentsStack)
271 .build();
Winson Chung65d66d32018-12-13 17:48:39 -0800272 ActivityStack fullscreenStack2 = display.createStack(WINDOWING_MODE_FULLSCREEN,
273 ACTIVITY_TYPE_STANDARD, true /* onTop */);
274 new ActivityBuilder(mService)
275 .setComponent(new ComponentName(mContext.getPackageName(), "App2"))
Winson Chung0f7ec962018-05-03 18:03:15 -0700276 .setCreateTask(true)
277 .setStack(fullscreenStack2)
278 .build();
Winson Chung0f7ec962018-05-03 18:03:15 -0700279
280 // Start the recents animation
Riddle Hsu43233b72019-04-24 23:55:11 +0800281 startRecentsActivity();
Winson Chung0f7ec962018-05-03 18:03:15 -0700282
283 fullscreenStack.moveToFront("Activity start");
284
lumark54284462019-03-05 20:44:27 +0800285 // Ensure that the recents animation was canceled by cancelAnimationSynchronously().
Wale Ogunwalea441b922019-06-27 19:21:44 -0700286 verify(mService.mWindowManager, times(1)).cancelRecentsAnimation(
Winson Chung0f7ec962018-05-03 18:03:15 -0700287 eq(REORDER_KEEP_IN_PLACE), any());
lumark54284462019-03-05 20:44:27 +0800288
289 // Assume recents animation already started, set a state that cancel recents animation
290 // with screenshot.
Winson Chung7a545ae2019-07-16 14:52:13 -0700291 doReturn(true).when(mRecentsAnimationController).shouldDeferCancelUntilNextTransition();
292 doReturn(true).when(mRecentsAnimationController).shouldDeferCancelWithScreenshot();
lumark54284462019-03-05 20:44:27 +0800293 // Start another fullscreen activity.
294 fullscreenStack2.moveToFront("Activity start");
295
Winson Chung7a545ae2019-07-16 14:52:13 -0700296 // Ensure that the recents animation was canceled by setCancelOnNextTransitionStart().
297 verify(mRecentsAnimationController, times(1)).setCancelOnNextTransitionStart();
Winson Chung0f7ec962018-05-03 18:03:15 -0700298 }
Winson Chung65d66d32018-12-13 17:48:39 -0800299
300 @Test
301 public void testKeepAnimationOnHiddenStackOrderChange() {
302 ActivityDisplay display = mService.mRootActivityContainer.getDefaultDisplay();
303 ActivityStack fullscreenStack = display.createStack(WINDOWING_MODE_FULLSCREEN,
304 ACTIVITY_TYPE_STANDARD, true /* onTop */);
305 new ActivityBuilder(mService)
306 .setComponent(new ComponentName(mContext.getPackageName(), "App1"))
307 .setCreateTask(true)
308 .setStack(fullscreenStack)
309 .build();
310 ActivityStack recentsStack = display.createStack(WINDOWING_MODE_FULLSCREEN,
311 ACTIVITY_TYPE_RECENTS, true /* onTop */);
312 new ActivityBuilder(mService)
313 .setComponent(mRecentsComponent)
314 .setCreateTask(true)
315 .setStack(recentsStack)
316 .build();
317 ActivityStack fullscreenStack2 = display.createStack(WINDOWING_MODE_FULLSCREEN,
318 ACTIVITY_TYPE_STANDARD, true /* onTop */);
319 new ActivityBuilder(mService)
320 .setComponent(new ComponentName(mContext.getPackageName(), "App2"))
321 .setCreateTask(true)
322 .setStack(fullscreenStack2)
323 .build();
Winson Chung65d66d32018-12-13 17:48:39 -0800324
325 // Start the recents animation
Riddle Hsu43233b72019-04-24 23:55:11 +0800326 startRecentsActivity();
Winson Chung65d66d32018-12-13 17:48:39 -0800327
328 fullscreenStack.remove();
329
330 // Ensure that the recents animation was NOT canceled
Wale Ogunwalea441b922019-06-27 19:21:44 -0700331 verify(mService.mWindowManager, times(0)).cancelRecentsAnimation(
Winson Chung65d66d32018-12-13 17:48:39 -0800332 eq(REORDER_KEEP_IN_PLACE), any());
Winson Chung7a545ae2019-07-16 14:52:13 -0700333 verify(mRecentsAnimationController, times(0)).setCancelOnNextTransitionStart();
Winson Chung65d66d32018-12-13 17:48:39 -0800334 }
Riddle Hsu43233b72019-04-24 23:55:11 +0800335
Winson Chung2bc60c02019-05-16 17:36:05 -0700336 @Test
337 public void testMultipleUserHomeActivity_findUserHomeTask() {
338 ActivityDisplay display = mService.mRootActivityContainer.getDefaultDisplay();
339 ActivityStack homeStack = display.getStack(WINDOWING_MODE_UNDEFINED, ACTIVITY_TYPE_HOME);
340 ActivityRecord otherUserHomeActivity = new ActivityBuilder(mService)
341 .setStack(homeStack)
342 .setCreateTask(true)
343 .setComponent(new ComponentName(mContext.getPackageName(), "Home2"))
344 .build();
Wale Ogunwale4e79a1c2019-10-05 20:52:40 -0700345 otherUserHomeActivity.getTaskRecord().mUserId = TEST_USER_ID;
Winson Chung2bc60c02019-05-16 17:36:05 -0700346
347 ActivityStack fullscreenStack = display.createStack(WINDOWING_MODE_FULLSCREEN,
348 ACTIVITY_TYPE_STANDARD, true /* onTop */);
349 new ActivityBuilder(mService)
350 .setComponent(new ComponentName(mContext.getPackageName(), "App1"))
351 .setCreateTask(true)
352 .setStack(fullscreenStack)
353 .build();
354
355 doReturn(TEST_USER_ID).when(mService).getCurrentUserId();
356 doCallRealMethod().when(mRootActivityContainer).ensureActivitiesVisible(
357 any() /* starting */, anyInt() /* configChanges */,
358 anyBoolean() /* preserveWindows */);
359
360 startRecentsActivity(otherUserHomeActivity.getTaskRecord().getBaseIntent().getComponent(),
361 true);
362
363 // Ensure we find the task for the right user and it is made visible
364 assertTrue(otherUserHomeActivity.visible);
365 }
366
Riddle Hsu43233b72019-04-24 23:55:11 +0800367 private void startRecentsActivity() {
368 startRecentsActivity(mRecentsComponent, false /* getRecentsAnimation */);
369 }
370
371 /**
372 * @return non-null {@link RecentsAnimationCallbacks} if the given {@code getRecentsAnimation}
373 * is {@code true}.
374 */
375 private RecentsAnimationCallbacks startRecentsActivity(ComponentName recentsComponent,
376 boolean getRecentsAnimation) {
377 RecentsAnimationCallbacks[] recentsAnimation = { null };
378 if (getRecentsAnimation) {
379 doAnswer(invocation -> {
380 // The callback is actually RecentsAnimation.
381 recentsAnimation[0] = invocation.getArgument(2);
382 return null;
383 }).when(mService.mWindowManager).initializeRecentsAnimation(
384 anyInt() /* targetActivityType */, any() /* recentsAnimationRunner */,
wilsonshih417b70c12019-10-16 16:12:02 +0800385 any() /* callbacks */, anyInt() /* displayId */, any() /* recentTaskIds */,
386 any() /* targetActivity */);
Riddle Hsu43233b72019-04-24 23:55:11 +0800387 }
388
389 Intent recentsIntent = new Intent();
390 recentsIntent.setComponent(recentsComponent);
391 mService.startRecentsActivity(recentsIntent, null /* assistDataReceiver */,
392 mock(IRecentsAnimationRunner.class));
393 return recentsAnimation[0];
394 }
Winson Chung0f7ec962018-05-03 18:03:15 -0700395}