Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 1 | /* |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 2 | * Copyright (C) 2018 The Android Open Source Project |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 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 |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 14 | * limitations under the License |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 17 | package com.android.server.wm; |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 18 | |
Winson Chung | 2bc60c0 | 2019-05-16 17:36:05 -0700 | [diff] [blame] | 19 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME; |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 20 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_RECENTS; |
| 21 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD; |
| 22 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; |
Winson Chung | 2bc60c0 | 2019-05-16 17:36:05 -0700 | [diff] [blame] | 23 | import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 24 | |
Riddle Hsu | 43233b7 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 25 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.doAnswer; |
Riddle Hsu | 0e59172 | 2019-05-03 22:22:36 +0800 | [diff] [blame] | 26 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.doCallRealMethod; |
Louis Chang | 7cf8460 | 2019-05-30 15:35:40 +0800 | [diff] [blame] | 27 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.doNothing; |
Tadashi G. Takaoka | a7a6695 | 2018-11-16 15:04:21 +0900 | [diff] [blame] | 28 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn; |
| 29 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.eq; |
| 30 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock; |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 31 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn; |
Tadashi G. Takaoka | a7a6695 | 2018-11-16 15:04:21 +0900 | [diff] [blame] | 32 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.times; |
| 33 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify; |
Louis Chang | 7cf8460 | 2019-05-30 15:35:40 +0800 | [diff] [blame] | 34 | import static com.android.server.wm.ActivityStack.ActivityState.PAUSED; |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 35 | import static com.android.server.wm.RecentsAnimationController.REORDER_KEEP_IN_PLACE; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 36 | |
Louis Chang | 7cf8460 | 2019-05-30 15:35:40 +0800 | [diff] [blame] | 37 | import static com.google.common.truth.Truth.assertThat; |
| 38 | |
Riddle Hsu | 43233b7 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 39 | import static org.junit.Assert.assertFalse; |
| 40 | import static org.junit.Assert.assertTrue; |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 41 | import static org.mockito.ArgumentMatchers.any; |
Riddle Hsu | 0e59172 | 2019-05-03 22:22:36 +0800 | [diff] [blame] | 42 | import static org.mockito.ArgumentMatchers.anyBoolean; |
Riddle Hsu | 43233b7 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 43 | import static org.mockito.ArgumentMatchers.anyInt; |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 44 | |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 45 | import android.app.IApplicationThread; |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 46 | import android.content.ComponentName; |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 47 | import android.content.Intent; |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 48 | import android.content.pm.ActivityInfo; |
| 49 | import android.content.pm.ApplicationInfo; |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 50 | import android.platform.test.annotations.Presubmit; |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 51 | import android.view.IRecentsAnimationRunner; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 52 | |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 53 | import androidx.test.filters.MediumTest; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 54 | |
Riddle Hsu | 43233b7 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 55 | import com.android.server.wm.RecentsAnimationController.RecentsAnimationCallbacks; |
| 56 | |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 57 | import org.junit.Before; |
| 58 | import org.junit.Test; |
Riddle Hsu | 2da2d03 | 2019-08-28 21:08:58 +0800 | [diff] [blame] | 59 | import org.junit.runner.RunWith; |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 60 | |
| 61 | /** |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 62 | * Build/Install/Run: |
| 63 | * atest WmTests:RecentsAnimationTest |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 64 | */ |
| 65 | @MediumTest |
| 66 | @Presubmit |
Riddle Hsu | 2da2d03 | 2019-08-28 21:08:58 +0800 | [diff] [blame] | 67 | @RunWith(WindowTestRunner.class) |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 68 | public class RecentsAnimationTest extends ActivityTestsBase { |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 69 | |
Winson Chung | 2bc60c0 | 2019-05-16 17:36:05 -0700 | [diff] [blame] | 70 | private static final int TEST_USER_ID = 100; |
| 71 | |
Riddle Hsu | 43233b7 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 72 | private final ComponentName mRecentsComponent = |
| 73 | new ComponentName(mContext.getPackageName(), "RecentsActivity"); |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 74 | private RecentsAnimationController mRecentsAnimationController; |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 75 | |
| 76 | @Before |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 77 | public void setUp() throws Exception { |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 78 | mRecentsAnimationController = mock(RecentsAnimationController.class); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 79 | mService.mWindowManager.setRecentsAnimationController(mRecentsAnimationController); |
| 80 | doNothing().when(mService.mWindowManager).initializeRecentsAnimation( |
wilsonshih | 417b70c1 | 2019-10-16 16:12:02 +0800 | [diff] [blame] | 81 | anyInt(), any(), any(), anyInt(), any(), any()); |
Riddle Hsu | 43233b7 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 82 | doReturn(true).when(mService.mWindowManager).canStartRecentsAnimation(); |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 83 | |
| 84 | final RecentTasks recentTasks = mService.getRecentTasks(); |
| 85 | spyOn(recentTasks); |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 86 | doReturn(mRecentsComponent).when(recentTasks).getRecentsComponent(); |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | @Test |
Riddle Hsu | 0e59172 | 2019-05-03 22:22:36 +0800 | [diff] [blame] | 90 | 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 Hsu | 0e59172 | 2019-05-03 22:22:36 +0800 | [diff] [blame] | 100 | 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 Ogunwale | a441b92 | 2019-06-27 19:21:44 -0700 | [diff] [blame] | 112 | recentsAnimation.onAnimationFinished(REORDER_KEEP_IN_PLACE, false /* sendUserLeaveHint */); |
Riddle Hsu | 0e59172 | 2019-05-03 22:22:36 +0800 | [diff] [blame] | 113 | // The non-top recents activity should be invisible by the restored launch-behind state. |
| 114 | assertFalse(recentActivity.visible); |
| 115 | } |
| 116 | |
| 117 | @Test |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 118 | public void testPreloadRecentsActivity() { |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 119 | 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 Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 131 | 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 Chang | 7cf8460 | 2019-05-30 15:35:40 +0800 | [diff] [blame] | 179 | 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 Chang | 7cf8460 | 2019-05-30 15:35:40 +0800 | [diff] [blame] | 199 | |
| 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 Hsu | 43233b7 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 209 | 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 Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 215 | if (targetActivity == null) { |
| 216 | targetActivity = new ActivityBuilder(mService) |
| 217 | .setCreateTask(true) |
| 218 | .setStack(homeStack) |
| 219 | .build(); |
| 220 | } |
| 221 | |
Riddle Hsu | 43233b7 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 222 | // 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 Ogunwale | a441b92 | 2019-06-27 19:21:44 -0700 | [diff] [blame] | 244 | verify(mService.mWindowManager, times(1)).cancelRecentsAnimation( |
Riddle Hsu | 43233b7 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 245 | 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 Ogunwale | a441b92 | 2019-06-27 19:21:44 -0700 | [diff] [blame] | 249 | recentsAnimation.onAnimationFinished(REORDER_KEEP_IN_PLACE, false /* sendUserLeaveHint */); |
Riddle Hsu | 43233b7 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 250 | // We should restore the launch-behind of the original target activity. |
| 251 | assertFalse(targetActivity.mLaunchTaskBehind); |
| 252 | } |
| 253 | |
| 254 | @Test |
Winson Chung | 65d66d3 | 2018-12-13 17:48:39 -0800 | [diff] [blame] | 255 | public void testCancelAnimationOnVisibleStackOrderChange() { |
| 256 | ActivityDisplay display = mService.mRootActivityContainer.getDefaultDisplay(); |
Tracy Zhou | 9c675d4 | 2019-04-08 00:32:40 -0700 | [diff] [blame] | 257 | display.mDisplayContent.mBoundsAnimationController = mock(BoundsAnimationController.class); |
Winson Chung | 65d66d3 | 2018-12-13 17:48:39 -0800 | [diff] [blame] | 258 | 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 Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 268 | .setComponent(mRecentsComponent) |
| 269 | .setCreateTask(true) |
| 270 | .setStack(recentsStack) |
| 271 | .build(); |
Winson Chung | 65d66d3 | 2018-12-13 17:48:39 -0800 | [diff] [blame] | 272 | 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 Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 276 | .setCreateTask(true) |
| 277 | .setStack(fullscreenStack2) |
| 278 | .build(); |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 279 | |
| 280 | // Start the recents animation |
Riddle Hsu | 43233b7 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 281 | startRecentsActivity(); |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 282 | |
| 283 | fullscreenStack.moveToFront("Activity start"); |
| 284 | |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 285 | // Ensure that the recents animation was canceled by cancelAnimationSynchronously(). |
Wale Ogunwale | a441b92 | 2019-06-27 19:21:44 -0700 | [diff] [blame] | 286 | verify(mService.mWindowManager, times(1)).cancelRecentsAnimation( |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 287 | eq(REORDER_KEEP_IN_PLACE), any()); |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 288 | |
| 289 | // Assume recents animation already started, set a state that cancel recents animation |
| 290 | // with screenshot. |
Winson Chung | 7a545ae | 2019-07-16 14:52:13 -0700 | [diff] [blame] | 291 | doReturn(true).when(mRecentsAnimationController).shouldDeferCancelUntilNextTransition(); |
| 292 | doReturn(true).when(mRecentsAnimationController).shouldDeferCancelWithScreenshot(); |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 293 | // Start another fullscreen activity. |
| 294 | fullscreenStack2.moveToFront("Activity start"); |
| 295 | |
Winson Chung | 7a545ae | 2019-07-16 14:52:13 -0700 | [diff] [blame] | 296 | // Ensure that the recents animation was canceled by setCancelOnNextTransitionStart(). |
| 297 | verify(mRecentsAnimationController, times(1)).setCancelOnNextTransitionStart(); |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 298 | } |
Winson Chung | 65d66d3 | 2018-12-13 17:48:39 -0800 | [diff] [blame] | 299 | |
| 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 Chung | 65d66d3 | 2018-12-13 17:48:39 -0800 | [diff] [blame] | 324 | |
| 325 | // Start the recents animation |
Riddle Hsu | 43233b7 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 326 | startRecentsActivity(); |
Winson Chung | 65d66d3 | 2018-12-13 17:48:39 -0800 | [diff] [blame] | 327 | |
| 328 | fullscreenStack.remove(); |
| 329 | |
| 330 | // Ensure that the recents animation was NOT canceled |
Wale Ogunwale | a441b92 | 2019-06-27 19:21:44 -0700 | [diff] [blame] | 331 | verify(mService.mWindowManager, times(0)).cancelRecentsAnimation( |
Winson Chung | 65d66d3 | 2018-12-13 17:48:39 -0800 | [diff] [blame] | 332 | eq(REORDER_KEEP_IN_PLACE), any()); |
Winson Chung | 7a545ae | 2019-07-16 14:52:13 -0700 | [diff] [blame] | 333 | verify(mRecentsAnimationController, times(0)).setCancelOnNextTransitionStart(); |
Winson Chung | 65d66d3 | 2018-12-13 17:48:39 -0800 | [diff] [blame] | 334 | } |
Riddle Hsu | 43233b7 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 335 | |
Winson Chung | 2bc60c0 | 2019-05-16 17:36:05 -0700 | [diff] [blame] | 336 | @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 Ogunwale | 4e79a1c | 2019-10-05 20:52:40 -0700 | [diff] [blame] | 345 | otherUserHomeActivity.getTaskRecord().mUserId = TEST_USER_ID; |
Winson Chung | 2bc60c0 | 2019-05-16 17:36:05 -0700 | [diff] [blame] | 346 | |
| 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 Hsu | 43233b7 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 367 | 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 */, |
wilsonshih | 417b70c1 | 2019-10-16 16:12:02 +0800 | [diff] [blame] | 385 | any() /* callbacks */, anyInt() /* displayId */, any() /* recentTaskIds */, |
| 386 | any() /* targetActivity */); |
Riddle Hsu | 43233b7 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 387 | } |
| 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 Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 395 | } |