Winson Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [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 |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 14 | * limitations under the License. |
Winson Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | package com.android.server.wm; |
| 18 | |
Winson Chung | 732446a | 2018-09-19 13:15:17 -0700 | [diff] [blame] | 19 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME; |
Winson Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [diff] [blame] | 20 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD; |
| 21 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; |
| 22 | import static android.view.Display.DEFAULT_DISPLAY; |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 23 | import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
lumark | b5a78b3 | 2019-04-25 20:31:30 +0800 | [diff] [blame] | 24 | import static android.view.WindowManager.TRANSIT_ACTIVITY_CLOSE; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 25 | |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 26 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.atLeast; |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 27 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.doNothing; |
Winson Chung | 7a545ae | 2019-07-16 14:52:13 -0700 | [diff] [blame] | 28 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn; |
Winson Chung | d585219 | 2019-09-06 17:20:28 -0700 | [diff] [blame] | 29 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.reset; |
| 30 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.spy; |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 31 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn; |
Winson Chung | d585219 | 2019-09-06 17:20:28 -0700 | [diff] [blame] | 32 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.times; |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 33 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify; |
| 34 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.verifyNoMoreInteractions; |
| 35 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.when; |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 36 | import static com.android.server.wm.ActivityStackSupervisor.ON_TOP; |
Winson Chung | 7906b3e | 2018-05-10 10:32:39 -0700 | [diff] [blame] | 37 | import static com.android.server.wm.RecentsAnimationController.REORDER_KEEP_IN_PLACE; |
| 38 | import static com.android.server.wm.RecentsAnimationController.REORDER_MOVE_TO_ORIGINAL_POSITION; |
Winson Chung | d585219 | 2019-09-06 17:20:28 -0700 | [diff] [blame] | 39 | import static com.android.server.wm.RecentsAnimationController.REORDER_MOVE_TO_TOP; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 40 | |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 41 | import static org.junit.Assert.assertEquals; |
Winson Chung | 732446a | 2018-09-19 13:15:17 -0700 | [diff] [blame] | 42 | import static org.junit.Assert.assertFalse; |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 43 | import static org.junit.Assert.assertNotNull; |
Winson Chung | 7a545ae | 2019-07-16 14:52:13 -0700 | [diff] [blame] | 44 | import static org.junit.Assert.assertNull; |
Winson Chung | 732446a | 2018-09-19 13:15:17 -0700 | [diff] [blame] | 45 | import static org.junit.Assert.assertTrue; |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 46 | import static org.junit.Assert.fail; |
lumark | f6f3494 | 2019-04-29 16:56:50 +0800 | [diff] [blame] | 47 | import static org.mockito.ArgumentMatchers.any; |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 48 | import static org.mockito.ArgumentMatchers.anyBoolean; |
Winson Chung | 7a545ae | 2019-07-16 14:52:13 -0700 | [diff] [blame] | 49 | import static org.mockito.ArgumentMatchers.anyInt; |
Winson Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [diff] [blame] | 50 | import static org.mockito.ArgumentMatchers.eq; |
Winson Chung | d585219 | 2019-09-06 17:20:28 -0700 | [diff] [blame] | 51 | import static org.mockito.Mockito.mock; |
| 52 | import static org.mockito.Mockito.never; |
Winson Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [diff] [blame] | 53 | |
Tracy Zhou | 8089ffa | 2019-07-30 17:30:43 -0700 | [diff] [blame] | 54 | import android.app.ActivityManager.TaskSnapshot; |
Winson Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [diff] [blame] | 55 | import android.os.Binder; |
Winson Chung | d585219 | 2019-09-06 17:20:28 -0700 | [diff] [blame] | 56 | import android.os.IBinder; |
Winson Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [diff] [blame] | 57 | import android.os.IInterface; |
| 58 | import android.platform.test.annotations.Presubmit; |
Winson Chung | 732446a | 2018-09-19 13:15:17 -0700 | [diff] [blame] | 59 | import android.util.SparseBooleanArray; |
Winson Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [diff] [blame] | 60 | import android.view.IRecentsAnimationRunner; |
| 61 | import android.view.SurfaceControl; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 62 | |
| 63 | import androidx.test.filters.SmallTest; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 64 | |
Winson Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [diff] [blame] | 65 | import com.android.server.wm.SurfaceAnimator.OnAnimationFinishedCallback; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 66 | |
Winson Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [diff] [blame] | 67 | import org.junit.Before; |
| 68 | import org.junit.Test; |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 69 | import org.junit.runner.RunWith; |
Winson Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [diff] [blame] | 70 | import org.mockito.Mock; |
| 71 | import org.mockito.MockitoAnnotations; |
| 72 | |
| 73 | /** |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 74 | * Build/Install/Run: |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 75 | * atest WmTests:RecentsAnimationControllerTest |
Winson Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [diff] [blame] | 76 | */ |
| 77 | @SmallTest |
| 78 | @Presubmit |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 79 | @RunWith(WindowTestRunner.class) |
Winson Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [diff] [blame] | 80 | public 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 Zhou | 8089ffa | 2019-07-30 17:30:43 -0700 | [diff] [blame] | 87 | @Mock TaskSnapshot mMockTaskSnapshot; |
Winson Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [diff] [blame] | 88 | private RecentsAnimationController mController; |
| 89 | |
| 90 | @Before |
| 91 | public void setUp() throws Exception { |
Winson Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [diff] [blame] | 92 | MockitoAnnotations.initMocks(this); |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 93 | doNothing().when(mWm.mRoot).performSurfacePlacement(anyBoolean()); |
| 94 | doReturn(mDisplayContent).when(mWm.mRoot).getDisplayContent(anyInt()); |
Winson Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [diff] [blame] | 95 | when(mMockRunner.asBinder()).thenReturn(new Binder()); |
Winson Chung | d585219 | 2019-09-06 17:20:28 -0700 | [diff] [blame] | 96 | mController = spy(new RecentsAnimationController(mWm, mMockRunner, mAnimationCallbacks, |
| 97 | DEFAULT_DISPLAY)); |
Winson Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | @Test |
| 101 | public void testRemovedBeforeStarted_expectCanceled() throws Exception { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 102 | final ActivityRecord activity = createActivityRecord(mDisplayContent, |
Winson Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [diff] [blame] | 103 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 104 | AnimationAdapter adapter = mController.addAnimation(activity.getTask(), |
Winson Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [diff] [blame] | 105 | false /* isRecentTaskInvisible */); |
| 106 | adapter.startAnimation(mMockLeash, mMockTransaction, mFinishedCallback); |
| 107 | |
| 108 | // Remove the app window so that the animation target can not be created |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 109 | activity.removeImmediately(); |
Winson Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [diff] [blame] | 110 | 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 Zhou | 8089ffa | 2019-07-30 17:30:43 -0700 | [diff] [blame] | 115 | verify(mMockRunner).onAnimationCanceled(null /* taskSnapshot */); |
Winson Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [diff] [blame] | 116 | verifyNoMoreInteractionsExceptAsBinder(mMockRunner); |
| 117 | } |
| 118 | |
Winson Chung | 7906b3e | 2018-05-10 10:32:39 -0700 | [diff] [blame] | 119 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 120 | public void testCancelAfterRemove_expectIgnored() { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 121 | final ActivityRecord activity = createActivityRecord(mDisplayContent, |
Winson Chung | 7906b3e | 2018-05-10 10:32:39 -0700 | [diff] [blame] | 122 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 123 | AnimationAdapter adapter = mController.addAnimation(activity.getTask(), |
Winson Chung | 7906b3e | 2018-05-10 10:32:39 -0700 | [diff] [blame] | 124 | false /* isRecentTaskInvisible */); |
| 125 | adapter.startAnimation(mMockLeash, mMockTransaction, mFinishedCallback); |
| 126 | |
| 127 | // Remove the app window so that the animation target can not be created |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 128 | activity.removeImmediately(); |
Winson Chung | 7906b3e | 2018-05-10 10:32:39 -0700 | [diff] [blame] | 129 | 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. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 138 | @Test |
| 139 | public void testIncludedApps_expectTargetAndVisible() { |
| 140 | mWm.setRecentsAnimationController(mController); |
Riddle Hsu | d1549d2 | 2019-10-07 17:00:47 +0800 | [diff] [blame] | 141 | final ActivityStack homeStack = mDisplayContent.mActivityDisplay.getOrCreateStack( |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 142 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, ON_TOP); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 143 | final ActivityRecord homeActivity = |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 144 | new ActivityTestsBase.ActivityBuilder(mWm.mAtmService) |
Winson Chung | d585219 | 2019-09-06 17:20:28 -0700 | [diff] [blame] | 145 | .setStack(homeStack) |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 146 | .setCreateTask(true) |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 147 | .build(); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 148 | final ActivityRecord activity = createActivityRecord(mDisplayContent, |
Winson Chung | 732446a | 2018-09-19 13:15:17 -0700 | [diff] [blame] | 149 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 150 | final ActivityRecord hiddenActivity = createActivityRecord(mDisplayContent, |
Winson Chung | 732446a | 2018-09-19 13:15:17 -0700 | [diff] [blame] | 151 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD); |
Issei Suzuki | 7b9e257 | 2019-11-14 16:19:54 +0100 | [diff] [blame] | 152 | hiddenActivity.setHidden(true); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 153 | mDisplayContent.getConfiguration().windowConfiguration.setRotation( |
| 154 | mDisplayContent.getRotation()); |
wilsonshih | 417b70c1 | 2019-10-16 16:12:02 +0800 | [diff] [blame] | 155 | mController.initialize(ACTIVITY_TYPE_HOME, new SparseBooleanArray(), homeActivity); |
Winson Chung | 732446a | 2018-09-19 13:15:17 -0700 | [diff] [blame] | 156 | |
| 157 | // Ensure that we are animating the target activity as well |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 158 | assertTrue(mController.isAnimatingTask(homeActivity.getTask())); |
| 159 | assertTrue(mController.isAnimatingTask(activity.getTask())); |
| 160 | assertFalse(mController.isAnimatingTask(hiddenActivity.getTask())); |
Winson Chung | 732446a | 2018-09-19 13:15:17 -0700 | [diff] [blame] | 161 | } |
| 162 | |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 163 | @Test |
Winson Chung | d585219 | 2019-09-06 17:20:28 -0700 | [diff] [blame] | 164 | public void testWallpaperIncluded_expectTarget() throws Exception { |
| 165 | mWm.setRecentsAnimationController(mController); |
Riddle Hsu | d1549d2 | 2019-10-07 17:00:47 +0800 | [diff] [blame] | 166 | final ActivityStack homeStack = mDisplayContent.mActivityDisplay.getOrCreateStack( |
Winson Chung | d585219 | 2019-09-06 17:20:28 -0700 | [diff] [blame] | 167 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, ON_TOP); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 168 | final ActivityRecord homeAppWindow = |
Winson Chung | d585219 | 2019-09-06 17:20:28 -0700 | [diff] [blame] | 169 | new ActivityTestsBase.ActivityBuilder(mWm.mAtmService) |
| 170 | .setStack(homeStack) |
| 171 | .setCreateTask(true) |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 172 | .build(); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 173 | final ActivityRecord appWindow = createActivityRecord(mDisplayContent, |
Winson Chung | d585219 | 2019-09-06 17:20:28 -0700 | [diff] [blame] | 174 | 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()); |
wilsonshih | 417b70c1 | 2019-10-16 16:12:02 +0800 | [diff] [blame] | 184 | mController.initialize(ACTIVITY_TYPE_HOME, new SparseBooleanArray(), homeAppWindow); |
Winson Chung | d585219 | 2019-09-06 17:20:28 -0700 | [diff] [blame] | 185 | 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 Hsu | d1549d2 | 2019-10-07 17:00:47 +0800 | [diff] [blame] | 195 | final ActivityStack homeStack = mDisplayContent.mActivityDisplay.getOrCreateStack( |
Winson Chung | d585219 | 2019-09-06 17:20:28 -0700 | [diff] [blame] | 196 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, ON_TOP); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 197 | final ActivityRecord homeActivity = |
Winson Chung | d585219 | 2019-09-06 17:20:28 -0700 | [diff] [blame] | 198 | new ActivityTestsBase.ActivityBuilder(mWm.mAtmService) |
| 199 | .setStack(homeStack) |
| 200 | .setCreateTask(true) |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 201 | .build(); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 202 | final ActivityRecord activity = createActivityRecord(mDisplayContent, |
Winson Chung | d585219 | 2019-09-06 17:20:28 -0700 | [diff] [blame] | 203 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 204 | final WindowState win1 = createWindow(null, TYPE_BASE_APPLICATION, activity, "win1"); |
| 205 | activity.addWindow(win1); |
Winson Chung | d585219 | 2019-09-06 17:20:28 -0700 | [diff] [blame] | 206 | 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()); |
wilsonshih | 417b70c1 | 2019-10-16 16:12:02 +0800 | [diff] [blame] | 213 | mController.initialize(ACTIVITY_TYPE_HOME, new SparseBooleanArray(), homeActivity); |
Winson Chung | d585219 | 2019-09-06 17:20:28 -0700 | [diff] [blame] | 214 | mController.startAnimation(); |
| 215 | |
| 216 | // Cancel the animation and ensure the controller is still running |
| 217 | wallpaperWindowToken.cancelAnimation(); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 218 | assertTrue(mController.isAnimatingTask(activity.getTask())); |
Winson Chung | d585219 | 2019-09-06 17:20:28 -0700 | [diff] [blame] | 219 | 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 Hsu | d1549d2 | 2019-10-07 17:00:47 +0800 | [diff] [blame] | 226 | final ActivityStack homeStack = mDisplayContent.mActivityDisplay.getOrCreateStack( |
Winson Chung | d585219 | 2019-09-06 17:20:28 -0700 | [diff] [blame] | 227 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, ON_TOP); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 228 | final ActivityRecord homeActivity = |
Winson Chung | d585219 | 2019-09-06 17:20:28 -0700 | [diff] [blame] | 229 | new ActivityTestsBase.ActivityBuilder(mWm.mAtmService) |
| 230 | .setStack(homeStack) |
| 231 | .setCreateTask(true) |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 232 | .build(); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 233 | final WindowState hwin1 = createWindow(null, TYPE_BASE_APPLICATION, homeActivity, "hwin1"); |
| 234 | homeActivity.addWindow(hwin1); |
| 235 | final ActivityRecord activity = createActivityRecord(mDisplayContent, |
Winson Chung | d585219 | 2019-09-06 17:20:28 -0700 | [diff] [blame] | 236 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 237 | final WindowState win1 = createWindow(null, TYPE_BASE_APPLICATION, activity, "win1"); |
| 238 | activity.addWindow(win1); |
Winson Chung | d585219 | 2019-09-06 17:20:28 -0700 | [diff] [blame] | 239 | 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 |
wilsonshih | 417b70c1 | 2019-10-16 16:12:02 +0800 | [diff] [blame] | 245 | mController.initialize(ACTIVITY_TYPE_HOME, new SparseBooleanArray(), homeActivity); |
Winson Chung | d585219 | 2019-09-06 17:20:28 -0700 | [diff] [blame] | 246 | 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 Chung | 7a545ae | 2019-07-16 14:52:13 -0700 | [diff] [blame] | 257 | public void testDeferCancelAnimation() throws Exception { |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 258 | mWm.setRecentsAnimationController(mController); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 259 | final ActivityRecord activity = createActivityRecord(mDisplayContent, |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 260 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 261 | 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); |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 265 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 266 | mController.addAnimation(activity.getTask(), false /* isRecentTaskInvisible */); |
| 267 | assertTrue(mController.isAnimatingTask(activity.getTask())); |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 268 | |
Winson Chung | 7a545ae | 2019-07-16 14:52:13 -0700 | [diff] [blame] | 269 | mController.setDeferredCancel(true /* deferred */, false /* screenshot */); |
| 270 | mController.cancelAnimationWithScreenshot(false /* screenshot */); |
Tracy Zhou | 8089ffa | 2019-07-30 17:30:43 -0700 | [diff] [blame] | 271 | verify(mMockRunner).onAnimationCanceled(null /* taskSnapshot */); |
Winson Chung | 7a545ae | 2019-07-16 14:52:13 -0700 | [diff] [blame] | 272 | assertNull(mController.mRecentScreenshotAnimator); |
| 273 | |
| 274 | // Simulate the app transition finishing |
| 275 | mController.mAppTransitionListener.onAppTransitionStartingLocked(0, 0, 0, 0); |
Wale Ogunwale | a441b92 | 2019-06-27 19:21:44 -0700 | [diff] [blame] | 276 | verify(mAnimationCallbacks).onAnimationFinished(REORDER_KEEP_IN_PLACE, false); |
Winson Chung | 7a545ae | 2019-07-16 14:52:13 -0700 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | @Test |
| 280 | public void testDeferCancelAnimationWithScreenShot() throws Exception { |
| 281 | mWm.setRecentsAnimationController(mController); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 282 | final ActivityRecord activity = createActivityRecord(mDisplayContent, |
Winson Chung | 7a545ae | 2019-07-16 14:52:13 -0700 | [diff] [blame] | 283 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 284 | 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 Chung | 7a545ae | 2019-07-16 14:52:13 -0700 | [diff] [blame] | 288 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 289 | mController.addAnimation(activity.getTask(), false /* isRecentTaskInvisible */); |
| 290 | assertTrue(mController.isAnimatingTask(activity.getTask())); |
Winson Chung | 7a545ae | 2019-07-16 14:52:13 -0700 | [diff] [blame] | 291 | |
Tracy Zhou | 8089ffa | 2019-07-30 17:30:43 -0700 | [diff] [blame] | 292 | 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 Chung | 7a545ae | 2019-07-16 14:52:13 -0700 | [diff] [blame] | 297 | mController.setDeferredCancel(true /* deferred */, true /* screenshot */); |
| 298 | mController.cancelAnimationWithScreenshot(true /* screenshot */); |
Tracy Zhou | 8089ffa | 2019-07-30 17:30:43 -0700 | [diff] [blame] | 299 | verify(mMockRunner).onAnimationCanceled(mMockTaskSnapshot /* taskSnapshot */); |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 300 | assertNotNull(mController.mRecentScreenshotAnimator); |
| 301 | assertTrue(mController.mRecentScreenshotAnimator.isAnimating()); |
| 302 | |
| 303 | // Assume IRecentsAnimationController#cleanupScreenshot called to finish screenshot |
| 304 | // animation. |
lumark | f6f3494 | 2019-04-29 16:56:50 +0800 | [diff] [blame] | 305 | spyOn(mController.mRecentScreenshotAnimator.mAnimatable); |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 306 | mController.mRecentScreenshotAnimator.cancelAnimation(); |
lumark | f6f3494 | 2019-04-29 16:56:50 +0800 | [diff] [blame] | 307 | verify(mController.mRecentScreenshotAnimator.mAnimatable).onAnimationLeashLost(any()); |
Wale Ogunwale | a441b92 | 2019-06-27 19:21:44 -0700 | [diff] [blame] | 308 | verify(mAnimationCallbacks).onAnimationFinished(REORDER_KEEP_IN_PLACE, false); |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 309 | } |
| 310 | |
lumark | b5a78b3 | 2019-04-25 20:31:30 +0800 | [diff] [blame] | 311 | @Test |
| 312 | public void testShouldAnimateWhenNoCancelWithDeferredScreenshot() { |
| 313 | mWm.setRecentsAnimationController(mController); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 314 | final ActivityRecord activity = createActivityRecord(mDisplayContent, |
lumark | b5a78b3 | 2019-04-25 20:31:30 +0800 | [diff] [blame] | 315 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 316 | 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); |
lumark | b5a78b3 | 2019-04-25 20:31:30 +0800 | [diff] [blame] | 320 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 321 | mController.addAnimation(activity.getTask(), false /* isRecentTaskInvisible */); |
| 322 | assertTrue(mController.isAnimatingTask(activity.getTask())); |
lumark | b5a78b3 | 2019-04-25 20:31:30 +0800 | [diff] [blame] | 323 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 324 | // Assume activity transition should animate when no |
lumark | b5a78b3 | 2019-04-25 20:31:30 +0800 | [diff] [blame] | 325 | // IRecentsAnimationController#setCancelWithDeferredScreenshot called. |
Winson Chung | 7a545ae | 2019-07-16 14:52:13 -0700 | [diff] [blame] | 326 | assertFalse(mController.shouldDeferCancelWithScreenshot()); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 327 | assertTrue(activity.shouldAnimate(TRANSIT_ACTIVITY_CLOSE)); |
lumark | b5a78b3 | 2019-04-25 20:31:30 +0800 | [diff] [blame] | 328 | } |
| 329 | |
Winson Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [diff] [blame] | 330 | private static void verifyNoMoreInteractionsExceptAsBinder(IInterface binder) { |
| 331 | verify(binder, atLeast(0)).asBinder(); |
| 332 | verifyNoMoreInteractions(binder); |
| 333 | } |
| 334 | } |