blob: 1abd3662165ef92724168e73465fd4f289e3749f [file] [log] [blame]
Winson Chungda876c92018-04-05 18:31:06 -07001/*
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
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070014 * limitations under the License.
Winson Chungda876c92018-04-05 18:31:06 -070015 */
16
17package com.android.server.wm;
18
Winson Chung732446a2018-09-19 13:15:17 -070019import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME;
Winson Chungda876c92018-04-05 18:31:06 -070020import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD;
21import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
22import static android.view.Display.DEFAULT_DISPLAY;
lumark54284462019-03-05 20:44:27 +080023import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
lumarkb5a78b32019-04-25 20:31:30 +080024import static android.view.WindowManager.TRANSIT_ACTIVITY_CLOSE;
Brett Chabota26eda92018-07-23 13:08:30 -070025
Tadashi G. Takaokabf0d57b2018-11-19 16:09:58 +090026import static com.android.dx.mockito.inline.extended.ExtendedMockito.atLeast;
lumark54284462019-03-05 20:44:27 +080027import static com.android.dx.mockito.inline.extended.ExtendedMockito.doNothing;
Winson Chung7a545ae2019-07-16 14:52:13 -070028import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
Winson Chungd5852192019-09-06 17:20:28 -070029import static com.android.dx.mockito.inline.extended.ExtendedMockito.reset;
30import static com.android.dx.mockito.inline.extended.ExtendedMockito.spy;
lumark54284462019-03-05 20:44:27 +080031import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn;
Winson Chungd5852192019-09-06 17:20:28 -070032import static com.android.dx.mockito.inline.extended.ExtendedMockito.times;
Tadashi G. Takaokabf0d57b2018-11-19 16:09:58 +090033import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify;
34import static com.android.dx.mockito.inline.extended.ExtendedMockito.verifyNoMoreInteractions;
35import static com.android.dx.mockito.inline.extended.ExtendedMockito.when;
Wale Ogunwale8a1860a2019-06-05 08:57:19 -070036import static com.android.server.wm.ActivityStackSupervisor.ON_TOP;
Winson Chung7906b3e2018-05-10 10:32:39 -070037import static com.android.server.wm.RecentsAnimationController.REORDER_KEEP_IN_PLACE;
38import static com.android.server.wm.RecentsAnimationController.REORDER_MOVE_TO_ORIGINAL_POSITION;
Winson Chungd5852192019-09-06 17:20:28 -070039import static com.android.server.wm.RecentsAnimationController.REORDER_MOVE_TO_TOP;
Brett Chabota26eda92018-07-23 13:08:30 -070040
lumark54284462019-03-05 20:44:27 +080041import static org.junit.Assert.assertEquals;
Winson Chung732446a2018-09-19 13:15:17 -070042import static org.junit.Assert.assertFalse;
lumark54284462019-03-05 20:44:27 +080043import static org.junit.Assert.assertNotNull;
Winson Chung7a545ae2019-07-16 14:52:13 -070044import static org.junit.Assert.assertNull;
Winson Chung732446a2018-09-19 13:15:17 -070045import static org.junit.Assert.assertTrue;
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070046import static org.junit.Assert.fail;
lumarkf6f34942019-04-29 16:56:50 +080047import static org.mockito.ArgumentMatchers.any;
lumark54284462019-03-05 20:44:27 +080048import static org.mockito.ArgumentMatchers.anyBoolean;
Winson Chung7a545ae2019-07-16 14:52:13 -070049import static org.mockito.ArgumentMatchers.anyInt;
Winson Chungda876c92018-04-05 18:31:06 -070050import static org.mockito.ArgumentMatchers.eq;
Winson Chungd5852192019-09-06 17:20:28 -070051import static org.mockito.Mockito.mock;
52import static org.mockito.Mockito.never;
Winson Chungda876c92018-04-05 18:31:06 -070053
Tracy Zhou8089ffa2019-07-30 17:30:43 -070054import android.app.ActivityManager.TaskSnapshot;
Winson Chungda876c92018-04-05 18:31:06 -070055import android.os.Binder;
Winson Chungd5852192019-09-06 17:20:28 -070056import android.os.IBinder;
Winson Chungda876c92018-04-05 18:31:06 -070057import android.os.IInterface;
58import android.platform.test.annotations.Presubmit;
Winson Chung732446a2018-09-19 13:15:17 -070059import android.util.SparseBooleanArray;
Winson Chungda876c92018-04-05 18:31:06 -070060import android.view.IRecentsAnimationRunner;
61import android.view.SurfaceControl;
Brett Chabota26eda92018-07-23 13:08:30 -070062
63import androidx.test.filters.SmallTest;
Brett Chabota26eda92018-07-23 13:08:30 -070064
Winson Chungda876c92018-04-05 18:31:06 -070065import com.android.server.wm.SurfaceAnimator.OnAnimationFinishedCallback;
Brett Chabota26eda92018-07-23 13:08:30 -070066
Winson Chungda876c92018-04-05 18:31:06 -070067import org.junit.Before;
68import org.junit.Test;
Riddle Hsu73f53572019-09-23 23:13:01 +080069import org.junit.runner.RunWith;
Winson Chungda876c92018-04-05 18:31:06 -070070import org.mockito.Mock;
71import org.mockito.MockitoAnnotations;
72
73/**
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070074 * Build/Install/Run:
Riddle Hsu73f53572019-09-23 23:13:01 +080075 * atest WmTests:RecentsAnimationControllerTest
Winson Chungda876c92018-04-05 18:31:06 -070076 */
77@SmallTest
78@Presubmit
Riddle Hsu73f53572019-09-23 23:13:01 +080079@RunWith(WindowTestRunner.class)
Winson Chungda876c92018-04-05 18:31:06 -070080public class RecentsAnimationControllerTest extends WindowTestsBase {
81
82 @Mock SurfaceControl mMockLeash;
83 @Mock SurfaceControl.Transaction mMockTransaction;
84 @Mock OnAnimationFinishedCallback mFinishedCallback;
85 @Mock IRecentsAnimationRunner mMockRunner;
86 @Mock RecentsAnimationController.RecentsAnimationCallbacks mAnimationCallbacks;
Tracy Zhou8089ffa2019-07-30 17:30:43 -070087 @Mock TaskSnapshot mMockTaskSnapshot;
Winson Chungda876c92018-04-05 18:31:06 -070088 private RecentsAnimationController mController;
89
90 @Before
91 public void setUp() throws Exception {
Winson Chungda876c92018-04-05 18:31:06 -070092 MockitoAnnotations.initMocks(this);
Riddle Hsu73f53572019-09-23 23:13:01 +080093 doNothing().when(mWm.mRoot).performSurfacePlacement(anyBoolean());
94 doReturn(mDisplayContent).when(mWm.mRoot).getDisplayContent(anyInt());
Winson Chungda876c92018-04-05 18:31:06 -070095 when(mMockRunner.asBinder()).thenReturn(new Binder());
Winson Chungd5852192019-09-06 17:20:28 -070096 mController = spy(new RecentsAnimationController(mWm, mMockRunner, mAnimationCallbacks,
97 DEFAULT_DISPLAY));
Winson Chungda876c92018-04-05 18:31:06 -070098 }
99
100 @Test
101 public void testRemovedBeforeStarted_expectCanceled() throws Exception {
Garfield Tane8d84ab2019-10-11 09:49:40 -0700102 final ActivityRecord activity = createActivityRecord(mDisplayContent,
Winson Chungda876c92018-04-05 18:31:06 -0700103 WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD);
Garfield Tane8d84ab2019-10-11 09:49:40 -0700104 AnimationAdapter adapter = mController.addAnimation(activity.getTask(),
Winson Chungda876c92018-04-05 18:31:06 -0700105 false /* isRecentTaskInvisible */);
106 adapter.startAnimation(mMockLeash, mMockTransaction, mFinishedCallback);
107
108 // Remove the app window so that the animation target can not be created
Garfield Tane8d84ab2019-10-11 09:49:40 -0700109 activity.removeImmediately();
Winson Chungda876c92018-04-05 18:31:06 -0700110 mController.startAnimation();
111
112 // Verify that the finish callback to reparent the leash is called
113 verify(mFinishedCallback).onAnimationFinished(eq(adapter));
114 // Verify the animation canceled callback to the app was made
Tracy Zhou8089ffa2019-07-30 17:30:43 -0700115 verify(mMockRunner).onAnimationCanceled(null /* taskSnapshot */);
Winson Chungda876c92018-04-05 18:31:06 -0700116 verifyNoMoreInteractionsExceptAsBinder(mMockRunner);
117 }
118
Winson Chung7906b3e2018-05-10 10:32:39 -0700119 @Test
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700120 public void testCancelAfterRemove_expectIgnored() {
Garfield Tane8d84ab2019-10-11 09:49:40 -0700121 final ActivityRecord activity = createActivityRecord(mDisplayContent,
Winson Chung7906b3e2018-05-10 10:32:39 -0700122 WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD);
Garfield Tane8d84ab2019-10-11 09:49:40 -0700123 AnimationAdapter adapter = mController.addAnimation(activity.getTask(),
Winson Chung7906b3e2018-05-10 10:32:39 -0700124 false /* isRecentTaskInvisible */);
125 adapter.startAnimation(mMockLeash, mMockTransaction, mFinishedCallback);
126
127 // Remove the app window so that the animation target can not be created
Garfield Tane8d84ab2019-10-11 09:49:40 -0700128 activity.removeImmediately();
Winson Chung7906b3e2018-05-10 10:32:39 -0700129 mController.startAnimation();
130 mController.cleanupAnimation(REORDER_KEEP_IN_PLACE);
131 try {
132 mController.cancelAnimation(REORDER_MOVE_TO_ORIGINAL_POSITION, "test");
133 } catch (Exception e) {
134 fail("Unexpected failure when canceling animation after finishing it");
135 }
136 }
137
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700138 @Test
139 public void testIncludedApps_expectTargetAndVisible() {
140 mWm.setRecentsAnimationController(mController);
Riddle Hsud1549d22019-10-07 17:00:47 +0800141 final ActivityStack homeStack = mDisplayContent.mActivityDisplay.getOrCreateStack(
Wale Ogunwale8a1860a2019-06-05 08:57:19 -0700142 WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, ON_TOP);
Garfield Tane8d84ab2019-10-11 09:49:40 -0700143 final ActivityRecord homeActivity =
Wale Ogunwale8a1860a2019-06-05 08:57:19 -0700144 new ActivityTestsBase.ActivityBuilder(mWm.mAtmService)
Winson Chungd5852192019-09-06 17:20:28 -0700145 .setStack(homeStack)
Wale Ogunwale8a1860a2019-06-05 08:57:19 -0700146 .setCreateTask(true)
Wale Ogunwaleda8b8272018-11-29 19:37:37 -0800147 .build();
Garfield Tane8d84ab2019-10-11 09:49:40 -0700148 final ActivityRecord activity = createActivityRecord(mDisplayContent,
Winson Chung732446a2018-09-19 13:15:17 -0700149 WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD);
Garfield Tane8d84ab2019-10-11 09:49:40 -0700150 final ActivityRecord hiddenActivity = createActivityRecord(mDisplayContent,
Winson Chung732446a2018-09-19 13:15:17 -0700151 WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD);
Issei Suzukif2f6c912019-11-08 11:24:18 +0100152 hiddenActivity.setVisible(false);
Tiger Huang7c610aa2018-10-27 00:01:01 +0800153 mDisplayContent.getConfiguration().windowConfiguration.setRotation(
154 mDisplayContent.getRotation());
wilsonshih417b70c12019-10-16 16:12:02 +0800155 mController.initialize(ACTIVITY_TYPE_HOME, new SparseBooleanArray(), homeActivity);
Winson Chung732446a2018-09-19 13:15:17 -0700156
157 // Ensure that we are animating the target activity as well
Garfield Tane8d84ab2019-10-11 09:49:40 -0700158 assertTrue(mController.isAnimatingTask(homeActivity.getTask()));
159 assertTrue(mController.isAnimatingTask(activity.getTask()));
160 assertFalse(mController.isAnimatingTask(hiddenActivity.getTask()));
Winson Chung732446a2018-09-19 13:15:17 -0700161 }
162
lumark54284462019-03-05 20:44:27 +0800163 @Test
Winson Chungd5852192019-09-06 17:20:28 -0700164 public void testWallpaperIncluded_expectTarget() throws Exception {
165 mWm.setRecentsAnimationController(mController);
Riddle Hsud1549d22019-10-07 17:00:47 +0800166 final ActivityStack homeStack = mDisplayContent.mActivityDisplay.getOrCreateStack(
Winson Chungd5852192019-09-06 17:20:28 -0700167 WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, ON_TOP);
Garfield Tane8d84ab2019-10-11 09:49:40 -0700168 final ActivityRecord homeAppWindow =
Winson Chungd5852192019-09-06 17:20:28 -0700169 new ActivityTestsBase.ActivityBuilder(mWm.mAtmService)
170 .setStack(homeStack)
171 .setCreateTask(true)
Wale Ogunwaleda8b8272018-11-29 19:37:37 -0800172 .build();
Garfield Tane8d84ab2019-10-11 09:49:40 -0700173 final ActivityRecord appWindow = createActivityRecord(mDisplayContent,
Winson Chungd5852192019-09-06 17:20:28 -0700174 WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD);
175 final WindowState win1 = createWindow(null, TYPE_BASE_APPLICATION, appWindow, "win1");
176 appWindow.addWindow(win1);
177 final WallpaperWindowToken wallpaperWindowToken = new WallpaperWindowToken(mWm,
178 mock(IBinder.class), true, mDisplayContent, true /* ownerCanManageAppTokens */);
179 spyOn(mDisplayContent.mWallpaperController);
180 doReturn(true).when(mDisplayContent.mWallpaperController).isWallpaperVisible();
181
182 mDisplayContent.getConfiguration().windowConfiguration.setRotation(
183 mDisplayContent.getRotation());
wilsonshih417b70c12019-10-16 16:12:02 +0800184 mController.initialize(ACTIVITY_TYPE_HOME, new SparseBooleanArray(), homeAppWindow);
Winson Chungd5852192019-09-06 17:20:28 -0700185 mController.startAnimation();
186
187 // Ensure that we are animating the app and wallpaper target
188 assertTrue(mController.isAnimatingTask(appWindow.getTask()));
189 assertTrue(mController.isAnimatingWallpaper(wallpaperWindowToken));
190 }
191
192 @Test
193 public void testWallpaperAnimatorCanceled_expectAnimationKeepsRunning() throws Exception {
194 mWm.setRecentsAnimationController(mController);
Riddle Hsud1549d22019-10-07 17:00:47 +0800195 final ActivityStack homeStack = mDisplayContent.mActivityDisplay.getOrCreateStack(
Winson Chungd5852192019-09-06 17:20:28 -0700196 WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, ON_TOP);
Garfield Tane8d84ab2019-10-11 09:49:40 -0700197 final ActivityRecord homeActivity =
Winson Chungd5852192019-09-06 17:20:28 -0700198 new ActivityTestsBase.ActivityBuilder(mWm.mAtmService)
199 .setStack(homeStack)
200 .setCreateTask(true)
Wale Ogunwaleda8b8272018-11-29 19:37:37 -0800201 .build();
Garfield Tane8d84ab2019-10-11 09:49:40 -0700202 final ActivityRecord activity = createActivityRecord(mDisplayContent,
Winson Chungd5852192019-09-06 17:20:28 -0700203 WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD);
Garfield Tane8d84ab2019-10-11 09:49:40 -0700204 final WindowState win1 = createWindow(null, TYPE_BASE_APPLICATION, activity, "win1");
205 activity.addWindow(win1);
Winson Chungd5852192019-09-06 17:20:28 -0700206 final WallpaperWindowToken wallpaperWindowToken = new WallpaperWindowToken(mWm,
207 mock(IBinder.class), true, mDisplayContent, true /* ownerCanManageAppTokens */);
208 spyOn(mDisplayContent.mWallpaperController);
209 doReturn(true).when(mDisplayContent.mWallpaperController).isWallpaperVisible();
210
211 mDisplayContent.getConfiguration().windowConfiguration.setRotation(
212 mDisplayContent.getRotation());
wilsonshih417b70c12019-10-16 16:12:02 +0800213 mController.initialize(ACTIVITY_TYPE_HOME, new SparseBooleanArray(), homeActivity);
Winson Chungd5852192019-09-06 17:20:28 -0700214 mController.startAnimation();
215
216 // Cancel the animation and ensure the controller is still running
217 wallpaperWindowToken.cancelAnimation();
Garfield Tane8d84ab2019-10-11 09:49:40 -0700218 assertTrue(mController.isAnimatingTask(activity.getTask()));
Winson Chungd5852192019-09-06 17:20:28 -0700219 assertFalse(mController.isAnimatingWallpaper(wallpaperWindowToken));
220 verify(mMockRunner, never()).onAnimationCanceled(null /* taskSnapshot */);
221 }
222
223 @Test
224 public void testFinish_expectTargetAndWallpaperAdaptersRemoved() {
225 mWm.setRecentsAnimationController(mController);
Riddle Hsud1549d22019-10-07 17:00:47 +0800226 final ActivityStack homeStack = mDisplayContent.mActivityDisplay.getOrCreateStack(
Winson Chungd5852192019-09-06 17:20:28 -0700227 WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, ON_TOP);
Garfield Tane8d84ab2019-10-11 09:49:40 -0700228 final ActivityRecord homeActivity =
Winson Chungd5852192019-09-06 17:20:28 -0700229 new ActivityTestsBase.ActivityBuilder(mWm.mAtmService)
230 .setStack(homeStack)
231 .setCreateTask(true)
Wale Ogunwaleda8b8272018-11-29 19:37:37 -0800232 .build();
Garfield Tane8d84ab2019-10-11 09:49:40 -0700233 final WindowState hwin1 = createWindow(null, TYPE_BASE_APPLICATION, homeActivity, "hwin1");
234 homeActivity.addWindow(hwin1);
235 final ActivityRecord activity = createActivityRecord(mDisplayContent,
Winson Chungd5852192019-09-06 17:20:28 -0700236 WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD);
Garfield Tane8d84ab2019-10-11 09:49:40 -0700237 final WindowState win1 = createWindow(null, TYPE_BASE_APPLICATION, activity, "win1");
238 activity.addWindow(win1);
Winson Chungd5852192019-09-06 17:20:28 -0700239 final WallpaperWindowToken wallpaperWindowToken = new WallpaperWindowToken(mWm,
240 mock(IBinder.class), true, mDisplayContent, true /* ownerCanManageAppTokens */);
241 spyOn(mDisplayContent.mWallpaperController);
242 doReturn(true).when(mDisplayContent.mWallpaperController).isWallpaperVisible();
243
244 // Start and finish the animation
wilsonshih417b70c12019-10-16 16:12:02 +0800245 mController.initialize(ACTIVITY_TYPE_HOME, new SparseBooleanArray(), homeActivity);
Winson Chungd5852192019-09-06 17:20:28 -0700246 mController.startAnimation();
247 // Reset at this point since we may remove adapters that couldn't be created
248 reset(mController);
249 mController.cleanupAnimation(REORDER_MOVE_TO_TOP);
250
251 // Ensure that we remove the task (home & app) and wallpaper adapters
252 verify(mController, times(2)).removeAnimation(any());
253 verify(mController, times(1)).removeWallpaperAnimation(any());
254 }
255
256 @Test
Winson Chung7a545ae2019-07-16 14:52:13 -0700257 public void testDeferCancelAnimation() throws Exception {
lumark54284462019-03-05 20:44:27 +0800258 mWm.setRecentsAnimationController(mController);
Garfield Tane8d84ab2019-10-11 09:49:40 -0700259 final ActivityRecord activity = createActivityRecord(mDisplayContent,
lumark54284462019-03-05 20:44:27 +0800260 WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD);
Garfield Tane8d84ab2019-10-11 09:49:40 -0700261 final WindowState win1 = createWindow(null, TYPE_BASE_APPLICATION, activity, "win1");
262 activity.addWindow(win1);
263 assertEquals(activity.getTask().getTopVisibleActivity(), activity);
264 assertEquals(activity.findMainWindow(), win1);
lumark54284462019-03-05 20:44:27 +0800265
Garfield Tane8d84ab2019-10-11 09:49:40 -0700266 mController.addAnimation(activity.getTask(), false /* isRecentTaskInvisible */);
267 assertTrue(mController.isAnimatingTask(activity.getTask()));
lumark54284462019-03-05 20:44:27 +0800268
Winson Chung7a545ae2019-07-16 14:52:13 -0700269 mController.setDeferredCancel(true /* deferred */, false /* screenshot */);
270 mController.cancelAnimationWithScreenshot(false /* screenshot */);
Tracy Zhou8089ffa2019-07-30 17:30:43 -0700271 verify(mMockRunner).onAnimationCanceled(null /* taskSnapshot */);
Winson Chung7a545ae2019-07-16 14:52:13 -0700272 assertNull(mController.mRecentScreenshotAnimator);
273
274 // Simulate the app transition finishing
275 mController.mAppTransitionListener.onAppTransitionStartingLocked(0, 0, 0, 0);
Wale Ogunwalea441b922019-06-27 19:21:44 -0700276 verify(mAnimationCallbacks).onAnimationFinished(REORDER_KEEP_IN_PLACE, false);
Winson Chung7a545ae2019-07-16 14:52:13 -0700277 }
278
279 @Test
280 public void testDeferCancelAnimationWithScreenShot() throws Exception {
281 mWm.setRecentsAnimationController(mController);
Garfield Tane8d84ab2019-10-11 09:49:40 -0700282 final ActivityRecord activity = createActivityRecord(mDisplayContent,
Winson Chung7a545ae2019-07-16 14:52:13 -0700283 WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD);
Garfield Tane8d84ab2019-10-11 09:49:40 -0700284 final WindowState win1 = createWindow(null, TYPE_BASE_APPLICATION, activity, "win1");
285 activity.addWindow(win1);
286 assertEquals(activity.getTask().getTopVisibleActivity(), activity);
287 assertEquals(activity.findMainWindow(), win1);
Winson Chung7a545ae2019-07-16 14:52:13 -0700288
Garfield Tane8d84ab2019-10-11 09:49:40 -0700289 mController.addAnimation(activity.getTask(), false /* isRecentTaskInvisible */);
290 assertTrue(mController.isAnimatingTask(activity.getTask()));
Winson Chung7a545ae2019-07-16 14:52:13 -0700291
Tracy Zhou8089ffa2019-07-30 17:30:43 -0700292 spyOn(mWm.mTaskSnapshotController);
293 doNothing().when(mWm.mTaskSnapshotController).notifyAppVisibilityChanged(any(),
294 anyBoolean());
295 doReturn(mMockTaskSnapshot).when(mWm.mTaskSnapshotController).getSnapshot(anyInt(),
296 anyInt(), eq(false) /* restoreFromDisk */, eq(false) /* reducedResolution */);
Winson Chung7a545ae2019-07-16 14:52:13 -0700297 mController.setDeferredCancel(true /* deferred */, true /* screenshot */);
298 mController.cancelAnimationWithScreenshot(true /* screenshot */);
Tracy Zhou8089ffa2019-07-30 17:30:43 -0700299 verify(mMockRunner).onAnimationCanceled(mMockTaskSnapshot /* taskSnapshot */);
lumark54284462019-03-05 20:44:27 +0800300 assertNotNull(mController.mRecentScreenshotAnimator);
301 assertTrue(mController.mRecentScreenshotAnimator.isAnimating());
302
303 // Assume IRecentsAnimationController#cleanupScreenshot called to finish screenshot
304 // animation.
lumarkf6f34942019-04-29 16:56:50 +0800305 spyOn(mController.mRecentScreenshotAnimator.mAnimatable);
lumark54284462019-03-05 20:44:27 +0800306 mController.mRecentScreenshotAnimator.cancelAnimation();
lumarkf6f34942019-04-29 16:56:50 +0800307 verify(mController.mRecentScreenshotAnimator.mAnimatable).onAnimationLeashLost(any());
Wale Ogunwalea441b922019-06-27 19:21:44 -0700308 verify(mAnimationCallbacks).onAnimationFinished(REORDER_KEEP_IN_PLACE, false);
lumark54284462019-03-05 20:44:27 +0800309 }
310
lumarkb5a78b32019-04-25 20:31:30 +0800311 @Test
312 public void testShouldAnimateWhenNoCancelWithDeferredScreenshot() {
313 mWm.setRecentsAnimationController(mController);
Garfield Tane8d84ab2019-10-11 09:49:40 -0700314 final ActivityRecord activity = createActivityRecord(mDisplayContent,
lumarkb5a78b32019-04-25 20:31:30 +0800315 WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD);
Garfield Tane8d84ab2019-10-11 09:49:40 -0700316 final WindowState win1 = createWindow(null, TYPE_BASE_APPLICATION, activity, "win1");
317 activity.addWindow(win1);
318 assertEquals(activity.getTask().getTopVisibleActivity(), activity);
319 assertEquals(activity.findMainWindow(), win1);
lumarkb5a78b32019-04-25 20:31:30 +0800320
Garfield Tane8d84ab2019-10-11 09:49:40 -0700321 mController.addAnimation(activity.getTask(), false /* isRecentTaskInvisible */);
322 assertTrue(mController.isAnimatingTask(activity.getTask()));
lumarkb5a78b32019-04-25 20:31:30 +0800323
Garfield Tane8d84ab2019-10-11 09:49:40 -0700324 // Assume activity transition should animate when no
lumarkb5a78b32019-04-25 20:31:30 +0800325 // IRecentsAnimationController#setCancelWithDeferredScreenshot called.
Winson Chung7a545ae2019-07-16 14:52:13 -0700326 assertFalse(mController.shouldDeferCancelWithScreenshot());
Garfield Tane8d84ab2019-10-11 09:49:40 -0700327 assertTrue(activity.shouldAnimate(TRANSIT_ACTIVITY_CLOSE));
lumarkb5a78b32019-04-25 20:31:30 +0800328 }
329
Winson Chungda876c92018-04-05 18:31:06 -0700330 private static void verifyNoMoreInteractionsExceptAsBinder(IInterface binder) {
331 verify(binder, atLeast(0)).asBinder();
332 verifyNoMoreInteractions(binder);
333 }
334}