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() { |
Andrii Kulian | 4c0fd0d | 2020-03-29 13:32:14 -0700 | [diff] [blame] | 91 | TaskDisplayArea taskDisplayArea = mRootWindowContainer.getDefaultTaskDisplayArea(); |
Andrii Kulian | 86d676c | 2020-03-27 19:34:54 -0700 | [diff] [blame] | 92 | ActivityStack recentsStack = taskDisplayArea.createStack(WINDOWING_MODE_FULLSCREEN, |
Riddle Hsu | 0e59172 | 2019-05-03 22:22:36 +0800 | [diff] [blame] | 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(); |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 100 | topActivity.getRootTask().moveToFront("testRecentsActivityVisiblility"); |
Riddle Hsu | 0e59172 | 2019-05-03 22:22:36 +0800 | [diff] [blame] | 101 | |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 102 | doCallRealMethod().when(mRootWindowContainer).ensureActivitiesVisible( |
Riddle Hsu | 0e59172 | 2019-05-03 22:22:36 +0800 | [diff] [blame] | 103 | any() /* starting */, anyInt() /* configChanges */, |
Louis Chang | 3ff72a8 | 2019-12-17 12:12:59 +0800 | [diff] [blame] | 104 | anyBoolean() /* preserveWindows */, anyBoolean() /* notifyClients */); |
Riddle Hsu | 0e59172 | 2019-05-03 22:22:36 +0800 | [diff] [blame] | 105 | |
| 106 | RecentsAnimationCallbacks recentsAnimation = startRecentsActivity( |
| 107 | mRecentsComponent, true /* getRecentsAnimation */); |
| 108 | // The launch-behind state should make the recents activity visible. |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 109 | assertTrue(recentActivity.mVisibleRequested); |
Riddle Hsu | 0e59172 | 2019-05-03 22:22:36 +0800 | [diff] [blame] | 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. |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 114 | assertFalse(recentActivity.mVisibleRequested); |
Riddle Hsu | 0e59172 | 2019-05-03 22:22:36 +0800 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | @Test |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 118 | public void testPreloadRecentsActivity() { |
Andrii Kulian | 4c0fd0d | 2020-03-29 13:32:14 -0700 | [diff] [blame] | 119 | TaskDisplayArea defaultTaskDisplayArea = mRootWindowContainer.getDefaultTaskDisplayArea(); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 120 | final ActivityStack homeStack = |
Andrii Kulian | 86d676c | 2020-03-27 19:34:54 -0700 | [diff] [blame] | 121 | defaultTaskDisplayArea.getStack(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME); |
| 122 | defaultTaskDisplayArea.positionStackAtTop(homeStack, false /* includingParents */); |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 123 | ActivityRecord topRunningHomeActivity = homeStack.topRunningActivity(); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 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 | |
Andrii Kulian | 86d676c | 2020-03-27 19:34:54 -0700 | [diff] [blame] | 152 | ActivityStack recentsStack = defaultTaskDisplayArea.getStack(WINDOWING_MODE_FULLSCREEN, |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 153 | ACTIVITY_TYPE_RECENTS); |
| 154 | assertThat(recentsStack).isNotNull(); |
| 155 | |
Wale Ogunwale | 21e0648 | 2019-11-18 05:14:15 -0800 | [diff] [blame] | 156 | ActivityRecord recentsActivity = recentsStack.getTopNonFinishingActivity(); |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 157 | // The activity is started in background so it should be invisible and will be stopped. |
| 158 | assertThat(recentsActivity).isNotNull(); |
| 159 | assertThat(mSupervisor.mStoppingActivities).contains(recentsActivity); |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 160 | assertFalse(recentsActivity.mVisibleRequested); |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 161 | |
| 162 | // Assume it is stopped to test next use case. |
Wale Ogunwale | 196db71 | 2019-12-27 15:35:39 +0000 | [diff] [blame] | 163 | recentsActivity.activityStopped(null /* newIcicle */, null /* newPersistentState */, |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 164 | null /* description */); |
| 165 | mSupervisor.mStoppingActivities.remove(recentsActivity); |
| 166 | |
| 167 | spyOn(recentsActivity); |
| 168 | // Start when the recents activity exists. It should ensure the configuration. |
| 169 | mService.startRecentsActivity(recentsIntent, null /* assistDataReceiver */, |
| 170 | null /* recentsAnimationRunner */); |
| 171 | |
| 172 | verify(recentsActivity).ensureActivityConfiguration(anyInt() /* globalChanges */, |
| 173 | anyBoolean() /* preserveWindow */, eq(true) /* ignoreVisibility */); |
| 174 | assertThat(mSupervisor.mStoppingActivities).contains(recentsActivity); |
| 175 | } |
| 176 | |
| 177 | @Test |
Louis Chang | 7cf8460 | 2019-05-30 15:35:40 +0800 | [diff] [blame] | 178 | public void testRestartRecentsActivity() throws Exception { |
| 179 | // Have a recents activity that is not attached to its process (ActivityRecord.app = null). |
Andrii Kulian | 4c0fd0d | 2020-03-29 13:32:14 -0700 | [diff] [blame] | 180 | TaskDisplayArea defaultTaskDisplayArea = mRootWindowContainer.getDefaultTaskDisplayArea(); |
Andrii Kulian | 86d676c | 2020-03-27 19:34:54 -0700 | [diff] [blame] | 181 | ActivityStack recentsStack = defaultTaskDisplayArea.createStack(WINDOWING_MODE_FULLSCREEN, |
Louis Chang | 7cf8460 | 2019-05-30 15:35:40 +0800 | [diff] [blame] | 182 | ACTIVITY_TYPE_RECENTS, true /* onTop */); |
| 183 | ActivityRecord recentActivity = new ActivityBuilder(mService).setComponent( |
| 184 | mRecentsComponent).setCreateTask(true).setStack(recentsStack).build(); |
| 185 | WindowProcessController app = recentActivity.app; |
| 186 | recentActivity.app = null; |
| 187 | |
| 188 | // Start an activity on top. |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 189 | new ActivityBuilder(mService).setCreateTask(true).build().getRootTask().moveToFront( |
Louis Chang | 7cf8460 | 2019-05-30 15:35:40 +0800 | [diff] [blame] | 190 | "testRestartRecentsActivity"); |
| 191 | |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 192 | doCallRealMethod().when(mRootWindowContainer).ensureActivitiesVisible( |
Louis Chang | 7cf8460 | 2019-05-30 15:35:40 +0800 | [diff] [blame] | 193 | any() /* starting */, anyInt() /* configChanges */, |
Louis Chang | 3ff72a8 | 2019-12-17 12:12:59 +0800 | [diff] [blame] | 194 | anyBoolean() /* preserveWindows */, anyBoolean() /* notifyClients */); |
Louis Chang | 7cf8460 | 2019-05-30 15:35:40 +0800 | [diff] [blame] | 195 | doReturn(app).when(mService).getProcessController(eq(recentActivity.processName), anyInt()); |
| 196 | ClientLifecycleManager lifecycleManager = mService.getLifecycleManager(); |
| 197 | doNothing().when(lifecycleManager).scheduleTransaction(any()); |
Louis Chang | 7cf8460 | 2019-05-30 15:35:40 +0800 | [diff] [blame] | 198 | |
| 199 | startRecentsActivity(); |
| 200 | |
| 201 | // Recents activity must be restarted, but not be resumed while running recents animation. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 202 | verify(mRootWindowContainer.mStackSupervisor).startSpecificActivity( |
Louis Chang | 7cf8460 | 2019-05-30 15:35:40 +0800 | [diff] [blame] | 203 | eq(recentActivity), eq(false), anyBoolean()); |
| 204 | assertThat(recentActivity.getState()).isEqualTo(PAUSED); |
| 205 | } |
| 206 | |
| 207 | @Test |
Riddle Hsu | 43233b7 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 208 | public void testSetLaunchTaskBehindOfTargetActivity() { |
Andrii Kulian | 4c0fd0d | 2020-03-29 13:32:14 -0700 | [diff] [blame] | 209 | TaskDisplayArea taskDisplayArea = mRootWindowContainer.getDefaultTaskDisplayArea(); |
Andrii Kulian | 86d676c | 2020-03-27 19:34:54 -0700 | [diff] [blame] | 210 | ActivityStack homeStack = taskDisplayArea.getRootHomeTask(); |
Riddle Hsu | 43233b7 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 211 | // Assume the home activity support recents. |
Wale Ogunwale | 21e0648 | 2019-11-18 05:14:15 -0800 | [diff] [blame] | 212 | ActivityRecord targetActivity = homeStack.getTopNonFinishingActivity(); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 213 | if (targetActivity == null) { |
| 214 | targetActivity = new ActivityBuilder(mService) |
| 215 | .setCreateTask(true) |
| 216 | .setStack(homeStack) |
| 217 | .build(); |
| 218 | } |
| 219 | |
Riddle Hsu | 43233b7 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 220 | // Put another home activity in home stack. |
| 221 | ActivityRecord anotherHomeActivity = new ActivityBuilder(mService) |
| 222 | .setComponent(new ComponentName(mContext.getPackageName(), "Home2")) |
| 223 | .setCreateTask(true) |
| 224 | .setStack(homeStack) |
| 225 | .build(); |
| 226 | // Start an activity on top so the recents activity can be started. |
| 227 | new ActivityBuilder(mService) |
| 228 | .setCreateTask(true) |
| 229 | .build() |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 230 | .getRootTask() |
Riddle Hsu | 43233b7 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 231 | .moveToFront("Activity start"); |
| 232 | |
| 233 | // Start the recents animation. |
| 234 | RecentsAnimationCallbacks recentsAnimation = startRecentsActivity( |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 235 | targetActivity.getTask().getBaseIntent().getComponent(), |
Riddle Hsu | 43233b7 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 236 | true /* getRecentsAnimation */); |
| 237 | // Ensure launch-behind is set for being visible. |
| 238 | assertTrue(targetActivity.mLaunchTaskBehind); |
| 239 | |
| 240 | anotherHomeActivity.moveFocusableActivityToTop("launchAnotherHome"); |
Riddle Hsu | 43233b7 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 241 | |
| 242 | // The test uses mocked RecentsAnimationController so we have to invoke the callback |
| 243 | // manually to simulate the flow. |
Wale Ogunwale | a441b92 | 2019-06-27 19:21:44 -0700 | [diff] [blame] | 244 | recentsAnimation.onAnimationFinished(REORDER_KEEP_IN_PLACE, false /* sendUserLeaveHint */); |
Riddle Hsu | 43233b7 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 245 | // We should restore the launch-behind of the original target activity. |
| 246 | assertFalse(targetActivity.mLaunchTaskBehind); |
| 247 | } |
| 248 | |
| 249 | @Test |
Winson Chung | 65d66d3 | 2018-12-13 17:48:39 -0800 | [diff] [blame] | 250 | public void testCancelAnimationOnVisibleStackOrderChange() { |
Andrii Kulian | 4c0fd0d | 2020-03-29 13:32:14 -0700 | [diff] [blame] | 251 | TaskDisplayArea taskDisplayArea = mRootWindowContainer.getDefaultTaskDisplayArea(); |
Andrii Kulian | 86d676c | 2020-03-27 19:34:54 -0700 | [diff] [blame] | 252 | ActivityStack fullscreenStack = taskDisplayArea.createStack(WINDOWING_MODE_FULLSCREEN, |
Winson Chung | 65d66d3 | 2018-12-13 17:48:39 -0800 | [diff] [blame] | 253 | ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 254 | new ActivityBuilder(mService) |
| 255 | .setComponent(new ComponentName(mContext.getPackageName(), "App1")) |
| 256 | .setCreateTask(true) |
| 257 | .setStack(fullscreenStack) |
| 258 | .build(); |
Andrii Kulian | 86d676c | 2020-03-27 19:34:54 -0700 | [diff] [blame] | 259 | ActivityStack recentsStack = taskDisplayArea.createStack(WINDOWING_MODE_FULLSCREEN, |
Winson Chung | 65d66d3 | 2018-12-13 17:48:39 -0800 | [diff] [blame] | 260 | ACTIVITY_TYPE_RECENTS, true /* onTop */); |
| 261 | new ActivityBuilder(mService) |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 262 | .setComponent(mRecentsComponent) |
| 263 | .setCreateTask(true) |
| 264 | .setStack(recentsStack) |
| 265 | .build(); |
Andrii Kulian | 86d676c | 2020-03-27 19:34:54 -0700 | [diff] [blame] | 266 | ActivityStack fullscreenStack2 = taskDisplayArea.createStack(WINDOWING_MODE_FULLSCREEN, |
Winson Chung | 65d66d3 | 2018-12-13 17:48:39 -0800 | [diff] [blame] | 267 | ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 268 | new ActivityBuilder(mService) |
| 269 | .setComponent(new ComponentName(mContext.getPackageName(), "App2")) |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 270 | .setCreateTask(true) |
| 271 | .setStack(fullscreenStack2) |
| 272 | .build(); |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 273 | |
| 274 | // Start the recents animation |
Riddle Hsu | 43233b7 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 275 | startRecentsActivity(); |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 276 | |
| 277 | fullscreenStack.moveToFront("Activity start"); |
| 278 | |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 279 | // Assume recents animation already started, set a state that cancel recents animation |
| 280 | // with screenshot. |
Winson Chung | 7a545ae | 2019-07-16 14:52:13 -0700 | [diff] [blame] | 281 | doReturn(true).when(mRecentsAnimationController).shouldDeferCancelUntilNextTransition(); |
| 282 | doReturn(true).when(mRecentsAnimationController).shouldDeferCancelWithScreenshot(); |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 283 | // Start another fullscreen activity. |
| 284 | fullscreenStack2.moveToFront("Activity start"); |
| 285 | |
Winson Chung | 7a545ae | 2019-07-16 14:52:13 -0700 | [diff] [blame] | 286 | // Ensure that the recents animation was canceled by setCancelOnNextTransitionStart(). |
| 287 | verify(mRecentsAnimationController, times(1)).setCancelOnNextTransitionStart(); |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 288 | } |
Winson Chung | 65d66d3 | 2018-12-13 17:48:39 -0800 | [diff] [blame] | 289 | |
| 290 | @Test |
| 291 | public void testKeepAnimationOnHiddenStackOrderChange() { |
Andrii Kulian | 4c0fd0d | 2020-03-29 13:32:14 -0700 | [diff] [blame] | 292 | TaskDisplayArea taskDisplayArea = mRootWindowContainer.getDefaultTaskDisplayArea(); |
Andrii Kulian | 86d676c | 2020-03-27 19:34:54 -0700 | [diff] [blame] | 293 | ActivityStack fullscreenStack = taskDisplayArea.createStack(WINDOWING_MODE_FULLSCREEN, |
Winson Chung | 65d66d3 | 2018-12-13 17:48:39 -0800 | [diff] [blame] | 294 | ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 295 | new ActivityBuilder(mService) |
| 296 | .setComponent(new ComponentName(mContext.getPackageName(), "App1")) |
| 297 | .setCreateTask(true) |
| 298 | .setStack(fullscreenStack) |
| 299 | .build(); |
Andrii Kulian | 86d676c | 2020-03-27 19:34:54 -0700 | [diff] [blame] | 300 | ActivityStack recentsStack = taskDisplayArea.createStack(WINDOWING_MODE_FULLSCREEN, |
Winson Chung | 65d66d3 | 2018-12-13 17:48:39 -0800 | [diff] [blame] | 301 | ACTIVITY_TYPE_RECENTS, true /* onTop */); |
| 302 | new ActivityBuilder(mService) |
| 303 | .setComponent(mRecentsComponent) |
| 304 | .setCreateTask(true) |
| 305 | .setStack(recentsStack) |
| 306 | .build(); |
Andrii Kulian | 86d676c | 2020-03-27 19:34:54 -0700 | [diff] [blame] | 307 | ActivityStack fullscreenStack2 = taskDisplayArea.createStack(WINDOWING_MODE_FULLSCREEN, |
Winson Chung | 65d66d3 | 2018-12-13 17:48:39 -0800 | [diff] [blame] | 308 | ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 309 | new ActivityBuilder(mService) |
| 310 | .setComponent(new ComponentName(mContext.getPackageName(), "App2")) |
| 311 | .setCreateTask(true) |
| 312 | .setStack(fullscreenStack2) |
| 313 | .build(); |
Winson Chung | 65d66d3 | 2018-12-13 17:48:39 -0800 | [diff] [blame] | 314 | |
| 315 | // Start the recents animation |
Riddle Hsu | 43233b7 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 316 | startRecentsActivity(); |
Winson Chung | 65d66d3 | 2018-12-13 17:48:39 -0800 | [diff] [blame] | 317 | |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 318 | fullscreenStack.removeIfPossible(); |
Winson Chung | 65d66d3 | 2018-12-13 17:48:39 -0800 | [diff] [blame] | 319 | |
| 320 | // Ensure that the recents animation was NOT canceled |
Wale Ogunwale | a441b92 | 2019-06-27 19:21:44 -0700 | [diff] [blame] | 321 | verify(mService.mWindowManager, times(0)).cancelRecentsAnimation( |
Winson Chung | 65d66d3 | 2018-12-13 17:48:39 -0800 | [diff] [blame] | 322 | eq(REORDER_KEEP_IN_PLACE), any()); |
Winson Chung | 7a545ae | 2019-07-16 14:52:13 -0700 | [diff] [blame] | 323 | verify(mRecentsAnimationController, times(0)).setCancelOnNextTransitionStart(); |
Winson Chung | 65d66d3 | 2018-12-13 17:48:39 -0800 | [diff] [blame] | 324 | } |
Riddle Hsu | 43233b7 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 325 | |
Winson Chung | 2bc60c0 | 2019-05-16 17:36:05 -0700 | [diff] [blame] | 326 | @Test |
| 327 | public void testMultipleUserHomeActivity_findUserHomeTask() { |
Andrii Kulian | 4c0fd0d | 2020-03-29 13:32:14 -0700 | [diff] [blame] | 328 | TaskDisplayArea taskDisplayArea = mRootWindowContainer.getDefaultDisplay() |
| 329 | .getDefaultTaskDisplayArea(); |
Andrii Kulian | 86d676c | 2020-03-27 19:34:54 -0700 | [diff] [blame] | 330 | ActivityStack homeStack = taskDisplayArea.getStack(WINDOWING_MODE_UNDEFINED, |
| 331 | ACTIVITY_TYPE_HOME); |
Winson Chung | 2bc60c0 | 2019-05-16 17:36:05 -0700 | [diff] [blame] | 332 | ActivityRecord otherUserHomeActivity = new ActivityBuilder(mService) |
| 333 | .setStack(homeStack) |
| 334 | .setCreateTask(true) |
| 335 | .setComponent(new ComponentName(mContext.getPackageName(), "Home2")) |
| 336 | .build(); |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 337 | otherUserHomeActivity.getTask().mUserId = TEST_USER_ID; |
Winson Chung | 2bc60c0 | 2019-05-16 17:36:05 -0700 | [diff] [blame] | 338 | |
Andrii Kulian | 86d676c | 2020-03-27 19:34:54 -0700 | [diff] [blame] | 339 | ActivityStack fullscreenStack = taskDisplayArea.createStack(WINDOWING_MODE_FULLSCREEN, |
Winson Chung | 2bc60c0 | 2019-05-16 17:36:05 -0700 | [diff] [blame] | 340 | ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 341 | new ActivityBuilder(mService) |
| 342 | .setComponent(new ComponentName(mContext.getPackageName(), "App1")) |
| 343 | .setCreateTask(true) |
| 344 | .setStack(fullscreenStack) |
| 345 | .build(); |
| 346 | |
| 347 | doReturn(TEST_USER_ID).when(mService).getCurrentUserId(); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 348 | doCallRealMethod().when(mRootWindowContainer).ensureActivitiesVisible( |
Winson Chung | 2bc60c0 | 2019-05-16 17:36:05 -0700 | [diff] [blame] | 349 | any() /* starting */, anyInt() /* configChanges */, |
Louis Chang | 3ff72a8 | 2019-12-17 12:12:59 +0800 | [diff] [blame] | 350 | anyBoolean() /* preserveWindows */, anyBoolean() /* notifyClients */); |
Winson Chung | 2bc60c0 | 2019-05-16 17:36:05 -0700 | [diff] [blame] | 351 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 352 | startRecentsActivity(otherUserHomeActivity.getTask().getBaseIntent().getComponent(), |
Winson Chung | 2bc60c0 | 2019-05-16 17:36:05 -0700 | [diff] [blame] | 353 | true); |
| 354 | |
| 355 | // Ensure we find the task for the right user and it is made visible |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 356 | assertTrue(otherUserHomeActivity.mVisibleRequested); |
Winson Chung | 2bc60c0 | 2019-05-16 17:36:05 -0700 | [diff] [blame] | 357 | } |
| 358 | |
Riddle Hsu | 43233b7 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 359 | private void startRecentsActivity() { |
| 360 | startRecentsActivity(mRecentsComponent, false /* getRecentsAnimation */); |
| 361 | } |
| 362 | |
| 363 | /** |
| 364 | * @return non-null {@link RecentsAnimationCallbacks} if the given {@code getRecentsAnimation} |
| 365 | * is {@code true}. |
| 366 | */ |
| 367 | private RecentsAnimationCallbacks startRecentsActivity(ComponentName recentsComponent, |
| 368 | boolean getRecentsAnimation) { |
| 369 | RecentsAnimationCallbacks[] recentsAnimation = { null }; |
| 370 | if (getRecentsAnimation) { |
| 371 | doAnswer(invocation -> { |
| 372 | // The callback is actually RecentsAnimation. |
| 373 | recentsAnimation[0] = invocation.getArgument(2); |
| 374 | return null; |
| 375 | }).when(mService.mWindowManager).initializeRecentsAnimation( |
| 376 | anyInt() /* targetActivityType */, any() /* recentsAnimationRunner */, |
wilsonshih | 417b70c1 | 2019-10-16 16:12:02 +0800 | [diff] [blame] | 377 | any() /* callbacks */, anyInt() /* displayId */, any() /* recentTaskIds */, |
| 378 | any() /* targetActivity */); |
Riddle Hsu | 43233b7 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | Intent recentsIntent = new Intent(); |
| 382 | recentsIntent.setComponent(recentsComponent); |
| 383 | mService.startRecentsActivity(recentsIntent, null /* assistDataReceiver */, |
| 384 | mock(IRecentsAnimationRunner.class)); |
| 385 | return recentsAnimation[0]; |
| 386 | } |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 387 | } |