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; |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 59 | |
| 60 | /** |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 61 | * Build/Install/Run: |
| 62 | * atest WmTests:RecentsAnimationTest |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 63 | */ |
| 64 | @MediumTest |
| 65 | @Presubmit |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 66 | public class RecentsAnimationTest extends ActivityTestsBase { |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 67 | |
Winson Chung | 2bc60c0 | 2019-05-16 17:36:05 -0700 | [diff] [blame] | 68 | private static final int TEST_USER_ID = 100; |
| 69 | |
Riddle Hsu | 43233b7 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 70 | private final ComponentName mRecentsComponent = |
| 71 | new ComponentName(mContext.getPackageName(), "RecentsActivity"); |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 72 | private RecentsAnimationController mRecentsAnimationController; |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 73 | |
| 74 | @Before |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 75 | public void setUp() throws Exception { |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 76 | mRecentsAnimationController = mock(RecentsAnimationController.class); |
| 77 | doReturn(mRecentsAnimationController).when( |
| 78 | mService.mWindowManager).getRecentsAnimationController(); |
Riddle Hsu | 43233b7 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 79 | doReturn(true).when(mService.mWindowManager).canStartRecentsAnimation(); |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 80 | |
| 81 | final RecentTasks recentTasks = mService.getRecentTasks(); |
| 82 | spyOn(recentTasks); |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 83 | doReturn(mRecentsComponent).when(recentTasks).getRecentsComponent(); |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | @Test |
Riddle Hsu | 0e59172 | 2019-05-03 22:22:36 +0800 | [diff] [blame] | 87 | public void testRecentsActivityVisiblility() { |
| 88 | ActivityDisplay display = mRootActivityContainer.getDefaultDisplay(); |
| 89 | ActivityStack recentsStack = display.createStack(WINDOWING_MODE_FULLSCREEN, |
| 90 | ACTIVITY_TYPE_RECENTS, true /* onTop */); |
| 91 | ActivityRecord recentActivity = new ActivityBuilder(mService) |
| 92 | .setComponent(mRecentsComponent) |
| 93 | .setCreateTask(true) |
| 94 | .setStack(recentsStack) |
| 95 | .build(); |
| 96 | ActivityRecord topActivity = new ActivityBuilder(mService).setCreateTask(true).build(); |
| 97 | topActivity.fullscreen = true; |
| 98 | topActivity.getActivityStack().moveToFront("testRecentsActivityVisiblility"); |
| 99 | |
| 100 | doCallRealMethod().when(mRootActivityContainer).ensureActivitiesVisible( |
| 101 | any() /* starting */, anyInt() /* configChanges */, |
| 102 | anyBoolean() /* preserveWindows */); |
| 103 | |
| 104 | RecentsAnimationCallbacks recentsAnimation = startRecentsActivity( |
| 105 | mRecentsComponent, true /* getRecentsAnimation */); |
| 106 | // The launch-behind state should make the recents activity visible. |
| 107 | assertTrue(recentActivity.visible); |
| 108 | |
| 109 | // Simulate the animation is cancelled without changing the stack order. |
| 110 | recentsAnimation.onAnimationFinished(REORDER_KEEP_IN_PLACE, true /* runSychronously */, |
| 111 | false /* sendUserLeaveHint */); |
| 112 | // The non-top recents activity should be invisible by the restored launch-behind state. |
| 113 | assertFalse(recentActivity.visible); |
| 114 | } |
| 115 | |
| 116 | @Test |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 117 | public void testPreloadRecentsActivity() { |
| 118 | // Ensure that the fake recent component can be resolved by the recents intent. |
| 119 | mockTaskRecordFactory(builder -> builder.setComponent(mRecentsComponent)); |
| 120 | ActivityInfo aInfo = new ActivityInfo(); |
| 121 | aInfo.applicationInfo = new ApplicationInfo(); |
| 122 | aInfo.applicationInfo.uid = 10001; |
| 123 | aInfo.applicationInfo.targetSdkVersion = mContext.getApplicationInfo().targetSdkVersion; |
| 124 | aInfo.packageName = aInfo.applicationInfo.packageName = mRecentsComponent.getPackageName(); |
| 125 | aInfo.processName = "recents"; |
| 126 | doReturn(aInfo).when(mSupervisor).resolveActivity(any() /* intent */, any() /* rInfo */, |
| 127 | anyInt() /* startFlags */, any() /* profilerInfo */); |
| 128 | |
| 129 | // Assume its process is alive because the caller should be the recents service. |
| 130 | WindowProcessController wpc = new WindowProcessController(mService, aInfo.applicationInfo, |
| 131 | aInfo.processName, aInfo.applicationInfo.uid, 0 /* userId */, |
| 132 | mock(Object.class) /* owner */, mock(WindowProcessListener.class)); |
| 133 | wpc.setThread(mock(IApplicationThread.class)); |
| 134 | doReturn(wpc).when(mService).getProcessController(eq(wpc.mName), eq(wpc.mUid)); |
| 135 | |
| 136 | Intent recentsIntent = new Intent().setComponent(mRecentsComponent); |
| 137 | // Null animation indicates to preload. |
| 138 | mService.startRecentsActivity(recentsIntent, null /* assistDataReceiver */, |
| 139 | null /* recentsAnimationRunner */); |
| 140 | |
| 141 | ActivityDisplay display = mRootActivityContainer.getDefaultDisplay(); |
| 142 | ActivityStack recentsStack = display.getStack(WINDOWING_MODE_FULLSCREEN, |
| 143 | ACTIVITY_TYPE_RECENTS); |
| 144 | assertThat(recentsStack).isNotNull(); |
| 145 | |
| 146 | ActivityRecord recentsActivity = recentsStack.getTopActivity(); |
| 147 | // The activity is started in background so it should be invisible and will be stopped. |
| 148 | assertThat(recentsActivity).isNotNull(); |
| 149 | assertThat(mSupervisor.mStoppingActivities).contains(recentsActivity); |
| 150 | assertFalse(recentsActivity.visible); |
| 151 | |
| 152 | // Assume it is stopped to test next use case. |
| 153 | recentsActivity.activityStoppedLocked(null /* newIcicle */, null /* newPersistentState */, |
| 154 | null /* description */); |
| 155 | mSupervisor.mStoppingActivities.remove(recentsActivity); |
| 156 | |
| 157 | spyOn(recentsActivity); |
| 158 | // Start when the recents activity exists. It should ensure the configuration. |
| 159 | mService.startRecentsActivity(recentsIntent, null /* assistDataReceiver */, |
| 160 | null /* recentsAnimationRunner */); |
| 161 | |
| 162 | verify(recentsActivity).ensureActivityConfiguration(anyInt() /* globalChanges */, |
| 163 | anyBoolean() /* preserveWindow */, eq(true) /* ignoreVisibility */); |
| 164 | assertThat(mSupervisor.mStoppingActivities).contains(recentsActivity); |
| 165 | } |
| 166 | |
| 167 | @Test |
Louis Chang | 7cf8460 | 2019-05-30 15:35:40 +0800 | [diff] [blame] | 168 | public void testRestartRecentsActivity() throws Exception { |
| 169 | // Have a recents activity that is not attached to its process (ActivityRecord.app = null). |
| 170 | ActivityDisplay display = mRootActivityContainer.getDefaultDisplay(); |
| 171 | ActivityStack recentsStack = display.createStack(WINDOWING_MODE_FULLSCREEN, |
| 172 | ACTIVITY_TYPE_RECENTS, true /* onTop */); |
| 173 | ActivityRecord recentActivity = new ActivityBuilder(mService).setComponent( |
| 174 | mRecentsComponent).setCreateTask(true).setStack(recentsStack).build(); |
| 175 | WindowProcessController app = recentActivity.app; |
| 176 | recentActivity.app = null; |
| 177 | |
| 178 | // Start an activity on top. |
| 179 | new ActivityBuilder(mService).setCreateTask(true).build().getActivityStack().moveToFront( |
| 180 | "testRestartRecentsActivity"); |
| 181 | |
| 182 | doCallRealMethod().when(mRootActivityContainer).ensureActivitiesVisible( |
| 183 | any() /* starting */, anyInt() /* configChanges */, |
| 184 | anyBoolean() /* preserveWindows */); |
| 185 | doReturn(app).when(mService).getProcessController(eq(recentActivity.processName), anyInt()); |
| 186 | ClientLifecycleManager lifecycleManager = mService.getLifecycleManager(); |
| 187 | doNothing().when(lifecycleManager).scheduleTransaction(any()); |
| 188 | AppWarnings appWarnings = mService.getAppWarningsLocked(); |
| 189 | spyOn(appWarnings); |
| 190 | doNothing().when(appWarnings).onStartActivity(any()); |
| 191 | |
| 192 | startRecentsActivity(); |
| 193 | |
| 194 | // Recents activity must be restarted, but not be resumed while running recents animation. |
| 195 | verify(mRootActivityContainer.mStackSupervisor).startSpecificActivityLocked( |
| 196 | eq(recentActivity), eq(false), anyBoolean()); |
| 197 | assertThat(recentActivity.getState()).isEqualTo(PAUSED); |
| 198 | } |
| 199 | |
| 200 | @Test |
Riddle Hsu | 43233b7 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 201 | public void testSetLaunchTaskBehindOfTargetActivity() { |
| 202 | ActivityDisplay display = mRootActivityContainer.getDefaultDisplay(); |
| 203 | display.mDisplayContent.mBoundsAnimationController = mock(BoundsAnimationController.class); |
| 204 | ActivityStack homeStack = display.getHomeStack(); |
| 205 | // Assume the home activity support recents. |
| 206 | ActivityRecord targetActivity = homeStack.getTopActivity(); |
| 207 | // Put another home activity in home stack. |
| 208 | ActivityRecord anotherHomeActivity = new ActivityBuilder(mService) |
| 209 | .setComponent(new ComponentName(mContext.getPackageName(), "Home2")) |
| 210 | .setCreateTask(true) |
| 211 | .setStack(homeStack) |
| 212 | .build(); |
| 213 | // Start an activity on top so the recents activity can be started. |
| 214 | new ActivityBuilder(mService) |
| 215 | .setCreateTask(true) |
| 216 | .build() |
| 217 | .getActivityStack() |
| 218 | .moveToFront("Activity start"); |
| 219 | |
| 220 | // Start the recents animation. |
| 221 | RecentsAnimationCallbacks recentsAnimation = startRecentsActivity( |
| 222 | targetActivity.getTaskRecord().getBaseIntent().getComponent(), |
| 223 | true /* getRecentsAnimation */); |
| 224 | // Ensure launch-behind is set for being visible. |
| 225 | assertTrue(targetActivity.mLaunchTaskBehind); |
| 226 | |
| 227 | anotherHomeActivity.moveFocusableActivityToTop("launchAnotherHome"); |
| 228 | // The current top activity is not the recents so the animation should be canceled. |
| 229 | verify(mService.mWindowManager, times(1)).cancelRecentsAnimationSynchronously( |
| 230 | eq(REORDER_KEEP_IN_PLACE), any() /* reason */); |
| 231 | |
| 232 | // The test uses mocked RecentsAnimationController so we have to invoke the callback |
| 233 | // manually to simulate the flow. |
| 234 | recentsAnimation.onAnimationFinished(REORDER_KEEP_IN_PLACE, true /* runSychronously */, |
| 235 | false /* sendUserLeaveHint */); |
| 236 | // We should restore the launch-behind of the original target activity. |
| 237 | assertFalse(targetActivity.mLaunchTaskBehind); |
| 238 | } |
| 239 | |
| 240 | @Test |
Winson Chung | 65d66d3 | 2018-12-13 17:48:39 -0800 | [diff] [blame] | 241 | public void testCancelAnimationOnVisibleStackOrderChange() { |
| 242 | ActivityDisplay display = mService.mRootActivityContainer.getDefaultDisplay(); |
Tracy Zhou | 9c675d4 | 2019-04-08 00:32:40 -0700 | [diff] [blame] | 243 | display.mDisplayContent.mBoundsAnimationController = mock(BoundsAnimationController.class); |
Winson Chung | 65d66d3 | 2018-12-13 17:48:39 -0800 | [diff] [blame] | 244 | ActivityStack fullscreenStack = display.createStack(WINDOWING_MODE_FULLSCREEN, |
| 245 | ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 246 | new ActivityBuilder(mService) |
| 247 | .setComponent(new ComponentName(mContext.getPackageName(), "App1")) |
| 248 | .setCreateTask(true) |
| 249 | .setStack(fullscreenStack) |
| 250 | .build(); |
| 251 | ActivityStack recentsStack = display.createStack(WINDOWING_MODE_FULLSCREEN, |
| 252 | ACTIVITY_TYPE_RECENTS, true /* onTop */); |
| 253 | new ActivityBuilder(mService) |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 254 | .setComponent(mRecentsComponent) |
| 255 | .setCreateTask(true) |
| 256 | .setStack(recentsStack) |
| 257 | .build(); |
Winson Chung | 65d66d3 | 2018-12-13 17:48:39 -0800 | [diff] [blame] | 258 | ActivityStack fullscreenStack2 = display.createStack(WINDOWING_MODE_FULLSCREEN, |
| 259 | ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 260 | new ActivityBuilder(mService) |
| 261 | .setComponent(new ComponentName(mContext.getPackageName(), "App2")) |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 262 | .setCreateTask(true) |
| 263 | .setStack(fullscreenStack2) |
| 264 | .build(); |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 265 | |
| 266 | // Start the recents animation |
Riddle Hsu | 43233b7 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 267 | startRecentsActivity(); |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 268 | |
| 269 | fullscreenStack.moveToFront("Activity start"); |
| 270 | |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 271 | // Ensure that the recents animation was canceled by cancelAnimationSynchronously(). |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 272 | verify(mService.mWindowManager, times(1)).cancelRecentsAnimationSynchronously( |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 273 | eq(REORDER_KEEP_IN_PLACE), any()); |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 274 | |
| 275 | // Assume recents animation already started, set a state that cancel recents animation |
| 276 | // with screenshot. |
| 277 | doReturn(true).when(mRecentsAnimationController).shouldCancelWithDeferredScreenshot(); |
| 278 | // Start another fullscreen activity. |
| 279 | fullscreenStack2.moveToFront("Activity start"); |
| 280 | |
| 281 | // Ensure that the recents animation was canceled by cancelOnNextTransitionStart(). |
| 282 | verify(mRecentsAnimationController, times(1)).cancelOnNextTransitionStart(); |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 283 | } |
Winson Chung | 65d66d3 | 2018-12-13 17:48:39 -0800 | [diff] [blame] | 284 | |
| 285 | @Test |
| 286 | public void testKeepAnimationOnHiddenStackOrderChange() { |
| 287 | ActivityDisplay display = mService.mRootActivityContainer.getDefaultDisplay(); |
| 288 | ActivityStack fullscreenStack = display.createStack(WINDOWING_MODE_FULLSCREEN, |
| 289 | ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 290 | new ActivityBuilder(mService) |
| 291 | .setComponent(new ComponentName(mContext.getPackageName(), "App1")) |
| 292 | .setCreateTask(true) |
| 293 | .setStack(fullscreenStack) |
| 294 | .build(); |
| 295 | ActivityStack recentsStack = display.createStack(WINDOWING_MODE_FULLSCREEN, |
| 296 | ACTIVITY_TYPE_RECENTS, true /* onTop */); |
| 297 | new ActivityBuilder(mService) |
| 298 | .setComponent(mRecentsComponent) |
| 299 | .setCreateTask(true) |
| 300 | .setStack(recentsStack) |
| 301 | .build(); |
| 302 | ActivityStack fullscreenStack2 = display.createStack(WINDOWING_MODE_FULLSCREEN, |
| 303 | ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 304 | new ActivityBuilder(mService) |
| 305 | .setComponent(new ComponentName(mContext.getPackageName(), "App2")) |
| 306 | .setCreateTask(true) |
| 307 | .setStack(fullscreenStack2) |
| 308 | .build(); |
Winson Chung | 65d66d3 | 2018-12-13 17:48:39 -0800 | [diff] [blame] | 309 | |
| 310 | // Start the recents animation |
Riddle Hsu | 43233b7 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 311 | startRecentsActivity(); |
Winson Chung | 65d66d3 | 2018-12-13 17:48:39 -0800 | [diff] [blame] | 312 | |
| 313 | fullscreenStack.remove(); |
| 314 | |
| 315 | // Ensure that the recents animation was NOT canceled |
| 316 | verify(mService.mWindowManager, times(0)).cancelRecentsAnimationSynchronously( |
| 317 | eq(REORDER_KEEP_IN_PLACE), any()); |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 318 | verify(mRecentsAnimationController, times(0)).cancelOnNextTransitionStart(); |
Winson Chung | 65d66d3 | 2018-12-13 17:48:39 -0800 | [diff] [blame] | 319 | } |
Riddle Hsu | 43233b7 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 320 | |
Winson Chung | 2bc60c0 | 2019-05-16 17:36:05 -0700 | [diff] [blame] | 321 | @Test |
| 322 | public void testMultipleUserHomeActivity_findUserHomeTask() { |
| 323 | ActivityDisplay display = mService.mRootActivityContainer.getDefaultDisplay(); |
| 324 | ActivityStack homeStack = display.getStack(WINDOWING_MODE_UNDEFINED, ACTIVITY_TYPE_HOME); |
| 325 | ActivityRecord otherUserHomeActivity = new ActivityBuilder(mService) |
| 326 | .setStack(homeStack) |
| 327 | .setCreateTask(true) |
| 328 | .setComponent(new ComponentName(mContext.getPackageName(), "Home2")) |
| 329 | .build(); |
| 330 | otherUserHomeActivity.getTaskRecord().userId = TEST_USER_ID; |
| 331 | |
| 332 | ActivityStack fullscreenStack = display.createStack(WINDOWING_MODE_FULLSCREEN, |
| 333 | ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 334 | new ActivityBuilder(mService) |
| 335 | .setComponent(new ComponentName(mContext.getPackageName(), "App1")) |
| 336 | .setCreateTask(true) |
| 337 | .setStack(fullscreenStack) |
| 338 | .build(); |
| 339 | |
| 340 | doReturn(TEST_USER_ID).when(mService).getCurrentUserId(); |
| 341 | doCallRealMethod().when(mRootActivityContainer).ensureActivitiesVisible( |
| 342 | any() /* starting */, anyInt() /* configChanges */, |
| 343 | anyBoolean() /* preserveWindows */); |
| 344 | |
| 345 | startRecentsActivity(otherUserHomeActivity.getTaskRecord().getBaseIntent().getComponent(), |
| 346 | true); |
| 347 | |
| 348 | // Ensure we find the task for the right user and it is made visible |
| 349 | assertTrue(otherUserHomeActivity.visible); |
| 350 | } |
| 351 | |
Riddle Hsu | 43233b7 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 352 | private void startRecentsActivity() { |
| 353 | startRecentsActivity(mRecentsComponent, false /* getRecentsAnimation */); |
| 354 | } |
| 355 | |
| 356 | /** |
| 357 | * @return non-null {@link RecentsAnimationCallbacks} if the given {@code getRecentsAnimation} |
| 358 | * is {@code true}. |
| 359 | */ |
| 360 | private RecentsAnimationCallbacks startRecentsActivity(ComponentName recentsComponent, |
| 361 | boolean getRecentsAnimation) { |
| 362 | RecentsAnimationCallbacks[] recentsAnimation = { null }; |
| 363 | if (getRecentsAnimation) { |
| 364 | doAnswer(invocation -> { |
| 365 | // The callback is actually RecentsAnimation. |
| 366 | recentsAnimation[0] = invocation.getArgument(2); |
| 367 | return null; |
| 368 | }).when(mService.mWindowManager).initializeRecentsAnimation( |
| 369 | anyInt() /* targetActivityType */, any() /* recentsAnimationRunner */, |
| 370 | any() /* callbacks */, anyInt() /* displayId */, any() /* recentTaskIds */); |
| 371 | } |
| 372 | |
| 373 | Intent recentsIntent = new Intent(); |
| 374 | recentsIntent.setComponent(recentsComponent); |
| 375 | mService.startRecentsActivity(recentsIntent, null /* assistDataReceiver */, |
| 376 | mock(IRecentsAnimationRunner.class)); |
| 377 | return recentsAnimation[0]; |
| 378 | } |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 379 | } |