Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [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 |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 17 | package com.android.server.wm; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 18 | |
Jorim Jaggi | 54cff64 | 2018-03-15 15:51:32 +0100 | [diff] [blame] | 19 | import static android.app.ActivityManager.START_TASK_TO_FRONT; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 20 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME; |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 21 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_RECENTS; |
| 22 | import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 23 | import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; |
| 24 | import static android.content.Intent.FLAG_ACTIVITY_NO_ANIMATION; |
Winson Chung | 584d652 | 2018-02-07 23:57:38 +0000 | [diff] [blame] | 25 | import static android.os.Trace.TRACE_TAG_ACTIVITY_MANAGER; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 26 | import static android.view.WindowManager.TRANSIT_NONE; |
Winson Chung | fbbb158 | 2018-11-13 16:09:01 -0800 | [diff] [blame] | 27 | |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 28 | import static com.android.server.wm.ActivityStackSupervisor.PRESERVE_WINDOWS; |
Tracy Zhou | 9c675d4 | 2019-04-08 00:32:40 -0700 | [diff] [blame] | 29 | import static com.android.server.wm.BoundsAnimationController.BOUNDS; |
| 30 | import static com.android.server.wm.BoundsAnimationController.FADE_IN; |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 31 | import static com.android.server.wm.RecentsAnimationController.REORDER_KEEP_IN_PLACE; |
| 32 | import static com.android.server.wm.RecentsAnimationController.REORDER_MOVE_TO_ORIGINAL_POSITION; |
| 33 | import static com.android.server.wm.RecentsAnimationController.REORDER_MOVE_TO_TOP; |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 34 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_RECENTS_ANIMATIONS; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 35 | |
Jorim Jaggi | 589c5ba | 2019-07-30 16:50:13 +0200 | [diff] [blame^] | 36 | import android.annotation.Nullable; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 37 | import android.app.ActivityOptions; |
| 38 | import android.content.ComponentName; |
| 39 | import android.content.Intent; |
Winson Chung | ddf6297 | 2018-02-12 11:10:04 -0800 | [diff] [blame] | 40 | import android.os.RemoteException; |
Winson Chung | 584d652 | 2018-02-07 23:57:38 +0000 | [diff] [blame] | 41 | import android.os.Trace; |
Winson Chung | ddf6297 | 2018-02-12 11:10:04 -0800 | [diff] [blame] | 42 | import android.util.Slog; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 43 | import android.view.IRecentsAnimationRunner; |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 44 | |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 45 | import com.android.server.wm.RecentsAnimationController.RecentsAnimationCallbacks; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 46 | |
| 47 | /** |
| 48 | * Manages the recents animation, including the reordering of the stacks for the transition and |
| 49 | * cleanup. See {@link com.android.server.wm.RecentsAnimationController}. |
| 50 | */ |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 51 | class RecentsAnimation implements RecentsAnimationCallbacks, |
| 52 | ActivityDisplay.OnStackOrderChangedListener { |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 53 | private static final String TAG = RecentsAnimation.class.getSimpleName(); |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 54 | private static final boolean DEBUG = DEBUG_RECENTS_ANIMATIONS; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 55 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 56 | private final ActivityTaskManagerService mService; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 57 | private final ActivityStackSupervisor mStackSupervisor; |
| 58 | private final ActivityStartController mActivityStartController; |
| 59 | private final WindowManagerService mWindowManager; |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 60 | private final ActivityDisplay mDefaultDisplay; |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 61 | private final Intent mTargetIntent; |
| 62 | private final ComponentName mRecentsComponent; |
| 63 | private final int mRecentsUid; |
Jorim Jaggi | 589c5ba | 2019-07-30 16:50:13 +0200 | [diff] [blame^] | 64 | private final @Nullable WindowProcessController mCaller; |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 65 | private final int mUserId; |
| 66 | private final int mTargetActivityType; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 67 | |
Riddle Hsu | 43233b7 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 68 | /** |
| 69 | * The activity which has been launched behind. We need to remember the activity because the |
| 70 | * target stack may have other activities, then we are able to restore the launch-behind state |
| 71 | * for the exact activity. |
| 72 | */ |
| 73 | private ActivityRecord mLaunchedTargetActivity; |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 74 | |
| 75 | // The stack to restore the target stack behind when the animation is finished |
| 76 | private ActivityStack mRestoreTargetBehindStack; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 77 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 78 | RecentsAnimation(ActivityTaskManagerService atm, ActivityStackSupervisor stackSupervisor, |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 79 | ActivityStartController activityStartController, WindowManagerService wm, |
Jorim Jaggi | 589c5ba | 2019-07-30 16:50:13 +0200 | [diff] [blame^] | 80 | Intent targetIntent, ComponentName recentsComponent, int recentsUid, |
| 81 | @Nullable WindowProcessController caller) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 82 | mService = atm; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 83 | mStackSupervisor = stackSupervisor; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 84 | mDefaultDisplay = mService.mRootActivityContainer.getDefaultDisplay(); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 85 | mActivityStartController = activityStartController; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 86 | mWindowManager = wm; |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 87 | mTargetIntent = targetIntent; |
| 88 | mRecentsComponent = recentsComponent; |
| 89 | mRecentsUid = recentsUid; |
Jorim Jaggi | 589c5ba | 2019-07-30 16:50:13 +0200 | [diff] [blame^] | 90 | mCaller = caller; |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 91 | mUserId = atm.getCurrentUserId(); |
| 92 | mTargetActivityType = targetIntent.getComponent() != null |
| 93 | && recentsComponent.equals(targetIntent.getComponent()) |
| 94 | ? ACTIVITY_TYPE_RECENTS |
| 95 | : ACTIVITY_TYPE_HOME; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 96 | } |
| 97 | |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 98 | /** |
| 99 | * Starts the recents activity in background without animation if the record doesn't exist or |
| 100 | * the client isn't launched. If the recents activity is already alive, ensure its configuration |
| 101 | * is updated to the current one. |
| 102 | */ |
| 103 | void preloadRecentsActivity() { |
| 104 | if (DEBUG) Slog.d(TAG, "Preload recents with " + mTargetIntent); |
| 105 | ActivityStack targetStack = mDefaultDisplay.getStack(WINDOWING_MODE_UNDEFINED, |
| 106 | mTargetActivityType); |
| 107 | ActivityRecord targetActivity = getTargetActivity(targetStack); |
| 108 | if (targetActivity != null) { |
| 109 | if (targetActivity.visible || targetActivity.isTopRunningActivity()) { |
| 110 | // The activity is ready. |
| 111 | return; |
| 112 | } |
| 113 | if (targetActivity.attachedToProcess()) { |
| 114 | // The activity may be relaunched if it cannot handle the current configuration |
| 115 | // changes. The activity will be paused state if it is relaunched, otherwise it |
| 116 | // keeps the original stopped state. |
| 117 | targetActivity.ensureActivityConfiguration(0 /* globalChanges */, |
| 118 | false /* preserveWindow */, true /* ignoreVisibility */); |
| 119 | if (DEBUG) Slog.d(TAG, "Updated config=" + targetActivity.getConfiguration()); |
| 120 | } |
| 121 | } else { |
| 122 | // Create the activity record. Because the activity is invisible, this doesn't really |
| 123 | // start the client. |
| 124 | startRecentsActivityInBackground("preloadRecents"); |
| 125 | targetStack = mDefaultDisplay.getStack(WINDOWING_MODE_UNDEFINED, mTargetActivityType); |
| 126 | targetActivity = getTargetActivity(targetStack); |
| 127 | if (targetActivity == null) { |
| 128 | Slog.w(TAG, "Cannot start " + mTargetIntent); |
| 129 | return; |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | if (!targetActivity.attachedToProcess()) { |
| 134 | if (DEBUG) Slog.d(TAG, "Real start recents"); |
| 135 | mStackSupervisor.startSpecificActivityLocked(targetActivity, false /* andResume */, |
| 136 | false /* checkConfig */); |
| 137 | // Make sure the activity won't be involved in transition. |
| 138 | if (targetActivity.mAppWindowToken != null) { |
| 139 | targetActivity.mAppWindowToken.getDisplayContent().mUnknownAppVisibilityController |
| 140 | .appRemovedOrHidden(targetActivity.mAppWindowToken); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | // Invisible activity should be stopped. If the recents activity is alive and its doesn't |
| 145 | // need to relaunch by current configuration, then it may be already in stopped state. |
| 146 | if (!targetActivity.isState(ActivityStack.ActivityState.STOPPING, |
| 147 | ActivityStack.ActivityState.STOPPED)) { |
| 148 | // Add to stopping instead of stop immediately. So the client has the chance to perform |
| 149 | // traversal in non-stopped state (ViewRootImpl.mStopped) that would initialize more |
| 150 | // things (e.g. the measure can be done earlier). The actual stop will be performed when |
| 151 | // it reports idle. |
| 152 | targetStack.addToStopping(targetActivity, true /* scheduleIdle */, |
| 153 | true /* idleDelayed */, "preloadRecents"); |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | void startRecentsActivity(IRecentsAnimationRunner recentsAnimationRunner) { |
| 158 | if (DEBUG) Slog.d(TAG, "startRecentsActivity(): intent=" + mTargetIntent); |
Winson Chung | 584d652 | 2018-02-07 23:57:38 +0000 | [diff] [blame] | 159 | Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "RecentsAnimation#startRecentsActivity"); |
Winson Chung | ddf6297 | 2018-02-12 11:10:04 -0800 | [diff] [blame] | 160 | |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 161 | // TODO(multi-display) currently only support recents animation in default display. |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 162 | final DisplayContent dc = |
| 163 | mService.mRootActivityContainer.getDefaultDisplay().mDisplayContent; |
Winson Chung | ddf6297 | 2018-02-12 11:10:04 -0800 | [diff] [blame] | 164 | if (!mWindowManager.canStartRecentsAnimation()) { |
| 165 | notifyAnimationCancelBeforeStart(recentsAnimationRunner); |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 166 | if (DEBUG) Slog.d(TAG, "Can't start recents animation, nextAppTransition=" |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 167 | + dc.mAppTransition.getAppTransition()); |
Winson Chung | ddf6297 | 2018-02-12 11:10:04 -0800 | [diff] [blame] | 168 | return; |
| 169 | } |
| 170 | |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 171 | // If the activity is associated with the recents stack, then try and get that first |
Winson Chung | 9344203 | 2018-12-04 13:24:29 -0800 | [diff] [blame] | 172 | ActivityStack targetStack = mDefaultDisplay.getStack(WINDOWING_MODE_UNDEFINED, |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 173 | mTargetActivityType); |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 174 | ActivityRecord targetActivity = getTargetActivity(targetStack); |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 175 | final boolean hasExistingActivity = targetActivity != null; |
| 176 | if (hasExistingActivity) { |
| 177 | final ActivityDisplay display = targetActivity.getDisplay(); |
| 178 | mRestoreTargetBehindStack = display.getStackAbove(targetStack); |
| 179 | if (mRestoreTargetBehindStack == null) { |
Winson Chung | ddf6297 | 2018-02-12 11:10:04 -0800 | [diff] [blame] | 180 | notifyAnimationCancelBeforeStart(recentsAnimationRunner); |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 181 | if (DEBUG) Slog.d(TAG, "No stack above target stack=" + targetStack); |
Winson Chung | ddf6297 | 2018-02-12 11:10:04 -0800 | [diff] [blame] | 182 | return; |
| 183 | } |
| 184 | } |
| 185 | |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 186 | // Send launch hint if we are actually launching the target. If it's already visible |
| 187 | // (shouldn't happen in general) we don't need to send it. |
| 188 | if (targetActivity == null || !targetActivity.visible) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 189 | mService.mRootActivityContainer.sendPowerHintForLaunchStartIfNeeded( |
| 190 | true /* forceSend */, targetActivity); |
Jorim Jaggi | ac96052 | 2018-03-22 23:20:36 +0100 | [diff] [blame] | 191 | } |
| 192 | |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 193 | mStackSupervisor.getActivityMetricsLogger().notifyActivityLaunching(mTargetIntent); |
Jorim Jaggi | 54cff64 | 2018-03-15 15:51:32 +0100 | [diff] [blame] | 194 | |
Jorim Jaggi | 589c5ba | 2019-07-30 16:50:13 +0200 | [diff] [blame^] | 195 | if (mCaller != null) { |
| 196 | mCaller.setRunningRecentsAnimation(true); |
| 197 | } |
Jorim Jaggi | bc2aabe | 2018-03-08 17:27:43 +0100 | [diff] [blame] | 198 | |
Winson Chung | 1e6d4a9 | 2018-01-26 10:04:20 -0800 | [diff] [blame] | 199 | mWindowManager.deferSurfaceLayout(); |
| 200 | try { |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 201 | if (hasExistingActivity) { |
| 202 | // Move the recents activity into place for the animation if it is not top most |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 203 | mDefaultDisplay.moveStackBehindBottomMostVisibleStack(targetStack); |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 204 | if (DEBUG) Slog.d(TAG, "Moved stack=" + targetStack + " behind stack=" |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 205 | + mDefaultDisplay.getStackAbove(targetStack)); |
Winson Chung | 00a0969 | 2018-04-19 16:14:09 -0700 | [diff] [blame] | 206 | |
| 207 | // If there are multiple tasks in the target stack (ie. the home stack, with 3p |
| 208 | // and default launchers coexisting), then move the task to the top as a part of |
| 209 | // moving the stack to the front |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 210 | if (targetStack.topTask() != targetActivity.getTaskRecord()) { |
| 211 | targetStack.addTask(targetActivity.getTaskRecord(), true /* toTop */, |
Winson Chung | 00a0969 | 2018-04-19 16:14:09 -0700 | [diff] [blame] | 212 | "startRecentsActivity"); |
| 213 | } |
Winson Chung | ddf6297 | 2018-02-12 11:10:04 -0800 | [diff] [blame] | 214 | } else { |
Winson Chung | 9344203 | 2018-12-04 13:24:29 -0800 | [diff] [blame] | 215 | // No recents activity, create the new recents activity bottom most |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 216 | startRecentsActivityInBackground("startRecentsActivity_noTargetActivity"); |
Winson Chung | 9344203 | 2018-12-04 13:24:29 -0800 | [diff] [blame] | 217 | |
| 218 | // Move the recents activity into place for the animation |
Winson Chung | 2bc60c0 | 2019-05-16 17:36:05 -0700 | [diff] [blame] | 219 | targetStack = mDefaultDisplay.getStack(WINDOWING_MODE_UNDEFINED, |
| 220 | mTargetActivityType); |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 221 | targetActivity = getTargetActivity(targetStack); |
Winson Chung | 9344203 | 2018-12-04 13:24:29 -0800 | [diff] [blame] | 222 | mDefaultDisplay.moveStackBehindBottomMostVisibleStack(targetStack); |
| 223 | if (DEBUG) { |
| 224 | Slog.d(TAG, "Moved stack=" + targetStack + " behind stack=" |
| 225 | + mDefaultDisplay.getStackAbove(targetStack)); |
| 226 | } |
| 227 | |
Winson Chung | 1e6d4a9 | 2018-01-26 10:04:20 -0800 | [diff] [blame] | 228 | mWindowManager.prepareAppTransition(TRANSIT_NONE, false); |
Winson Chung | ba40d3a | 2018-05-16 09:40:16 -0700 | [diff] [blame] | 229 | mWindowManager.executeAppTransition(); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 230 | |
Winson Chung | 1e6d4a9 | 2018-01-26 10:04:20 -0800 | [diff] [blame] | 231 | // TODO: Maybe wait for app to draw in this particular case? |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 232 | |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 233 | if (DEBUG) Slog.d(TAG, "Started intent=" + mTargetIntent); |
Winson Chung | 1e6d4a9 | 2018-01-26 10:04:20 -0800 | [diff] [blame] | 234 | } |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 235 | |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 236 | // Mark the target activity as launch-behind to bump its visibility for the |
Winson Chung | 1e6d4a9 | 2018-01-26 10:04:20 -0800 | [diff] [blame] | 237 | // duration of the gesture that is driven by the recents component |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 238 | targetActivity.mLaunchTaskBehind = true; |
Riddle Hsu | 43233b7 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 239 | mLaunchedTargetActivity = targetActivity; |
Winson Chung | 1e6d4a9 | 2018-01-26 10:04:20 -0800 | [diff] [blame] | 240 | |
| 241 | // Fetch all the surface controls and pass them to the client to get the animation |
Winson Chung | 65c5f99 | 2018-04-20 14:58:57 -0700 | [diff] [blame] | 242 | // started. Cancel any existing recents animation running synchronously (do not hold the |
| 243 | // WM lock) |
| 244 | mWindowManager.cancelRecentsAnimationSynchronously(REORDER_MOVE_TO_ORIGINAL_POSITION, |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 245 | "startRecentsActivity"); |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 246 | mWindowManager.initializeRecentsAnimation(mTargetActivityType, recentsAnimationRunner, |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 247 | this, mDefaultDisplay.mDisplayId, |
| 248 | mStackSupervisor.mRecentTasks.getRecentTaskIds()); |
Winson Chung | 1e6d4a9 | 2018-01-26 10:04:20 -0800 | [diff] [blame] | 249 | |
| 250 | // If we updated the launch-behind state, update the visibility of the activities after |
| 251 | // we fetch the visible tasks to be controlled by the animation |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 252 | mService.mRootActivityContainer.ensureActivitiesVisible(null, 0, PRESERVE_WINDOWS); |
Jorim Jaggi | 54cff64 | 2018-03-15 15:51:32 +0100 | [diff] [blame] | 253 | |
| 254 | mStackSupervisor.getActivityMetricsLogger().notifyActivityLaunched(START_TASK_TO_FRONT, |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 255 | targetActivity); |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 256 | |
| 257 | // Register for stack order changes |
| 258 | mDefaultDisplay.registerStackOrderChangedListener(this); |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 259 | } catch (Exception e) { |
| 260 | Slog.e(TAG, "Failed to start recents activity", e); |
| 261 | throw e; |
Winson Chung | 1e6d4a9 | 2018-01-26 10:04:20 -0800 | [diff] [blame] | 262 | } finally { |
| 263 | mWindowManager.continueSurfaceLayout(); |
Winson Chung | 584d652 | 2018-02-07 23:57:38 +0000 | [diff] [blame] | 264 | Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 265 | } |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 266 | } |
| 267 | |
Tracy Zhou | 9c675d4 | 2019-04-08 00:32:40 -0700 | [diff] [blame] | 268 | private void finishAnimation(@RecentsAnimationController.ReorderMode int reorderMode, |
| 269 | boolean sendUserLeaveHint) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 270 | synchronized (mService.mGlobalLock) { |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 271 | if (DEBUG) Slog.d(TAG, "onAnimationFinished(): controller=" |
Winson Chung | 65c5f99 | 2018-04-20 14:58:57 -0700 | [diff] [blame] | 272 | + mWindowManager.getRecentsAnimationController() |
| 273 | + " reorderMode=" + reorderMode); |
Winson Chung | f993016 | 2018-02-12 14:51:46 -0800 | [diff] [blame] | 274 | |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 275 | // Unregister for stack order changes |
| 276 | mDefaultDisplay.unregisterStackOrderChangedListener(this); |
| 277 | |
Riddle Hsu | 0e59172 | 2019-05-03 22:22:36 +0800 | [diff] [blame] | 278 | final RecentsAnimationController controller = |
| 279 | mWindowManager.getRecentsAnimationController(); |
| 280 | if (controller == null) return; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 281 | |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 282 | // Just to be sure end the launch hint in case the target activity was never launched. |
| 283 | // However, if we're keeping the activity and making it visible, we can leave it on. |
| 284 | if (reorderMode != REORDER_KEEP_IN_PLACE) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 285 | mService.mRootActivityContainer.sendPowerHintForLaunchEndIfNeeded(); |
Jorim Jaggi | ac96052 | 2018-03-22 23:20:36 +0100 | [diff] [blame] | 286 | } |
| 287 | |
Winson Chung | 751579d | 2019-05-28 14:09:09 -0700 | [diff] [blame] | 288 | // Once the target is shown, prevent spurious background app switches |
| 289 | if (reorderMode == REORDER_MOVE_TO_TOP) { |
| 290 | mService.stopAppSwitches(); |
| 291 | } |
| 292 | |
Jorim Jaggi | 589c5ba | 2019-07-30 16:50:13 +0200 | [diff] [blame^] | 293 | if (mCaller != null) { |
| 294 | mCaller.setRunningRecentsAnimation(false); |
| 295 | } |
Jorim Jaggi | bc2aabe | 2018-03-08 17:27:43 +0100 | [diff] [blame] | 296 | |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 297 | mWindowManager.inSurfaceTransaction(() -> { |
Winson Chung | 584d652 | 2018-02-07 23:57:38 +0000 | [diff] [blame] | 298 | Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, |
| 299 | "RecentsAnimation#onAnimationFinished_inSurfaceTransaction"); |
Winson Chung | 1e6d4a9 | 2018-01-26 10:04:20 -0800 | [diff] [blame] | 300 | mWindowManager.deferSurfaceLayout(); |
| 301 | try { |
Winson Chung | 6a38fca | 2018-03-28 17:57:09 -0700 | [diff] [blame] | 302 | mWindowManager.cleanupRecentsAnimation(reorderMode); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 303 | |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 304 | final ActivityStack targetStack = mDefaultDisplay.getStack( |
| 305 | WINDOWING_MODE_UNDEFINED, mTargetActivityType); |
Riddle Hsu | 43233b7 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 306 | // Prefer to use the original target activity instead of top activity because |
| 307 | // we may have moved another task to top (starting 3p launcher). |
Winson Chung | 82389a9 | 2018-05-03 10:43:51 -0700 | [diff] [blame] | 308 | final ActivityRecord targetActivity = targetStack != null |
Riddle Hsu | 43233b7 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 309 | ? targetStack.isInStackLocked(mLaunchedTargetActivity) |
Winson Chung | 82389a9 | 2018-05-03 10:43:51 -0700 | [diff] [blame] | 310 | : null; |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 311 | if (DEBUG) Slog.d(TAG, "onAnimationFinished(): targetStack=" + targetStack |
| 312 | + " targetActivity=" + targetActivity |
| 313 | + " mRestoreTargetBehindStack=" + mRestoreTargetBehindStack); |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 314 | if (targetActivity == null) { |
Winson Chung | 1e6d4a9 | 2018-01-26 10:04:20 -0800 | [diff] [blame] | 315 | return; |
| 316 | } |
| 317 | |
| 318 | // Restore the launched-behind state |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 319 | targetActivity.mLaunchTaskBehind = false; |
Winson Chung | 1e6d4a9 | 2018-01-26 10:04:20 -0800 | [diff] [blame] | 320 | |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 321 | if (reorderMode == REORDER_MOVE_TO_TOP) { |
| 322 | // Bring the target stack to the front |
| 323 | mStackSupervisor.mNoAnimActivities.add(targetActivity); |
Tracy Zhou | 9c675d4 | 2019-04-08 00:32:40 -0700 | [diff] [blame] | 324 | |
| 325 | if (sendUserLeaveHint) { |
| 326 | // Setting this allows the previous app to PiP. |
| 327 | mStackSupervisor.mUserLeaving = true; |
| 328 | targetStack.moveTaskToFrontLocked(targetActivity.getTaskRecord(), |
| 329 | true /* noAnimation */, null /* activityOptions */, |
| 330 | targetActivity.appTimeTracker, |
| 331 | "RecentsAnimation.onAnimationFinished()"); |
| 332 | } else { |
| 333 | targetStack.moveToFront("RecentsAnimation.onAnimationFinished()"); |
| 334 | } |
| 335 | |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 336 | if (DEBUG) { |
| 337 | final ActivityStack topStack = getTopNonAlwaysOnTopStack(); |
| 338 | if (topStack != targetStack) { |
| 339 | Slog.w(TAG, "Expected target stack=" + targetStack |
| 340 | + " to be top most but found stack=" + topStack); |
| 341 | } |
| 342 | } |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 343 | } else if (reorderMode == REORDER_MOVE_TO_ORIGINAL_POSITION){ |
| 344 | // Restore the target stack to its previous position |
| 345 | final ActivityDisplay display = targetActivity.getDisplay(); |
| 346 | display.moveStackBehindStack(targetStack, mRestoreTargetBehindStack); |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 347 | if (DEBUG) { |
| 348 | final ActivityStack aboveTargetStack = |
| 349 | mDefaultDisplay.getStackAbove(targetStack); |
| 350 | if (mRestoreTargetBehindStack != null |
| 351 | && aboveTargetStack != mRestoreTargetBehindStack) { |
| 352 | Slog.w(TAG, "Expected target stack=" + targetStack |
| 353 | + " to restored behind stack=" + mRestoreTargetBehindStack |
| 354 | + " but it is behind stack=" + aboveTargetStack); |
| 355 | } |
| 356 | } |
Winson Chung | 6a38fca | 2018-03-28 17:57:09 -0700 | [diff] [blame] | 357 | } else { |
Riddle Hsu | 0e59172 | 2019-05-03 22:22:36 +0800 | [diff] [blame] | 358 | // If there is no recents screenshot animation, we can update the visibility |
| 359 | // of target stack immediately because it is visually invisible and the |
| 360 | // launch-behind state is restored. That also prevents the next transition |
| 361 | // type being disturbed if the visibility is updated after setting the next |
| 362 | // transition (the target activity will be one of closing apps). |
Winson Chung | 7a545ae | 2019-07-16 14:52:13 -0700 | [diff] [blame] | 363 | if (!controller.shouldDeferCancelWithScreenshot() |
Riddle Hsu | 0e59172 | 2019-05-03 22:22:36 +0800 | [diff] [blame] | 364 | && !targetStack.isFocusedStackOnDisplay()) { |
| 365 | targetStack.ensureActivitiesVisibleLocked(null /* starting */, |
| 366 | 0 /* starting */, false /* preserveWindows */); |
| 367 | } |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 368 | // Keep target stack in place, nothing changes, so ignore the transition |
| 369 | // logic below |
Winson Chung | 6a38fca | 2018-03-28 17:57:09 -0700 | [diff] [blame] | 370 | return; |
Winson Chung | 1e6d4a9 | 2018-01-26 10:04:20 -0800 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | mWindowManager.prepareAppTransition(TRANSIT_NONE, false); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 374 | mService.mRootActivityContainer.ensureActivitiesVisible(null, 0, false); |
| 375 | mService.mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Winson Chung | 1e6d4a9 | 2018-01-26 10:04:20 -0800 | [diff] [blame] | 376 | |
| 377 | // No reason to wait for the pausing activity in this case, as the hiding of |
| 378 | // surfaces needs to be done immediately. |
| 379 | mWindowManager.executeAppTransition(); |
Winson Chung | f557c3b | 2018-03-16 10:55:20 -0700 | [diff] [blame] | 380 | |
| 381 | // After reordering the stacks, reset the minimized state. At this point, either |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 382 | // the target activity is now top-most and we will stay minimized (if in |
| 383 | // split-screen), or we will have returned to the app, and the minimized state |
| 384 | // should be reset |
Winson Chung | f557c3b | 2018-03-16 10:55:20 -0700 | [diff] [blame] | 385 | mWindowManager.checkSplitScreenMinimizedChanged(true /* animate */); |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 386 | } catch (Exception e) { |
| 387 | Slog.e(TAG, "Failed to clean up recents activity", e); |
| 388 | throw e; |
Winson Chung | 1e6d4a9 | 2018-01-26 10:04:20 -0800 | [diff] [blame] | 389 | } finally { |
| 390 | mWindowManager.continueSurfaceLayout(); |
Winson Chung | 584d652 | 2018-02-07 23:57:38 +0000 | [diff] [blame] | 391 | Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 392 | } |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 393 | }); |
| 394 | } |
| 395 | } |
Winson Chung | ddf6297 | 2018-02-12 11:10:04 -0800 | [diff] [blame] | 396 | |
Winson Chung | 65c5f99 | 2018-04-20 14:58:57 -0700 | [diff] [blame] | 397 | @Override |
| 398 | public void onAnimationFinished(@RecentsAnimationController.ReorderMode int reorderMode, |
Tracy Zhou | 9c675d4 | 2019-04-08 00:32:40 -0700 | [diff] [blame] | 399 | boolean runSychronously, boolean sendUserLeaveHint) { |
Winson Chung | 65c5f99 | 2018-04-20 14:58:57 -0700 | [diff] [blame] | 400 | if (runSychronously) { |
Tracy Zhou | 9c675d4 | 2019-04-08 00:32:40 -0700 | [diff] [blame] | 401 | finishAnimation(reorderMode, sendUserLeaveHint); |
Winson Chung | 65c5f99 | 2018-04-20 14:58:57 -0700 | [diff] [blame] | 402 | } else { |
Tracy Zhou | 9c675d4 | 2019-04-08 00:32:40 -0700 | [diff] [blame] | 403 | mService.mH.post(() -> finishAnimation(reorderMode, sendUserLeaveHint)); |
Winson Chung | 65c5f99 | 2018-04-20 14:58:57 -0700 | [diff] [blame] | 404 | } |
| 405 | } |
| 406 | |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 407 | @Override |
Winson Chung | 65d66d3 | 2018-12-13 17:48:39 -0800 | [diff] [blame] | 408 | public void onStackOrderChanged(ActivityStack stack) { |
| 409 | if (DEBUG) Slog.d(TAG, "onStackOrderChanged(): stack=" + stack); |
| 410 | if (mDefaultDisplay.getIndexOf(stack) == -1 || !stack.shouldBeVisible(null)) { |
| 411 | // The stack is not visible, so ignore this change |
| 412 | return; |
| 413 | } |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 414 | final RecentsAnimationController controller = |
| 415 | mWindowManager.getRecentsAnimationController(); |
lumark | f6f3494 | 2019-04-29 16:56:50 +0800 | [diff] [blame] | 416 | if (controller == null) { |
| 417 | return; |
| 418 | } |
| 419 | |
Tracy Zhou | 9c675d4 | 2019-04-08 00:32:40 -0700 | [diff] [blame] | 420 | final DisplayContent dc = |
| 421 | mService.mRootActivityContainer.getDefaultDisplay().mDisplayContent; |
| 422 | dc.mBoundsAnimationController.setAnimationType( |
Winson Chung | 7a545ae | 2019-07-16 14:52:13 -0700 | [diff] [blame] | 423 | controller.shouldDeferCancelUntilNextTransition() ? FADE_IN : BOUNDS); |
Winson Chung | 65d66d3 | 2018-12-13 17:48:39 -0800 | [diff] [blame] | 424 | |
Winson Chung | 7a545ae | 2019-07-16 14:52:13 -0700 | [diff] [blame] | 425 | // We defer canceling the recents animation until the next app transition in the following |
| 426 | // cases: |
| 427 | // 1) The next launching task is not being animated by the recents animation |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 428 | // 2) The next task is home activity. (i.e. pressing home key to back home in recents). |
| 429 | if ((!controller.isAnimatingTask(stack.getTaskStack().getTopChild()) |
| 430 | || controller.isTargetApp(stack.getTopActivity().mAppWindowToken)) |
Winson Chung | 7a545ae | 2019-07-16 14:52:13 -0700 | [diff] [blame] | 431 | && controller.shouldDeferCancelUntilNextTransition()) { |
| 432 | // Always prepare an app transition since we rely on the transition callbacks to cleanup |
| 433 | mWindowManager.prepareAppTransition(TRANSIT_NONE, false); |
| 434 | controller.setCancelOnNextTransitionStart(); |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 435 | } else { |
| 436 | // Just cancel directly to unleash from launcher when the next launching task is the |
| 437 | // current top task. |
| 438 | mWindowManager.cancelRecentsAnimationSynchronously(REORDER_KEEP_IN_PLACE, |
| 439 | "stackOrderChanged"); |
| 440 | } |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 441 | } |
| 442 | |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 443 | private void startRecentsActivityInBackground(String reason) { |
| 444 | final ActivityOptions options = ActivityOptions.makeBasic(); |
| 445 | options.setLaunchActivityType(mTargetActivityType); |
| 446 | options.setAvoidMoveToFront(); |
| 447 | mTargetIntent.addFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_NO_ANIMATION); |
| 448 | |
| 449 | mActivityStartController |
| 450 | .obtainStarter(mTargetIntent, reason) |
| 451 | .setCallingUid(mRecentsUid) |
| 452 | .setCallingPackage(mRecentsComponent.getPackageName()) |
| 453 | .setActivityOptions(new SafeActivityOptions(options)) |
| 454 | .setMayWait(mUserId) |
| 455 | .execute(); |
| 456 | } |
| 457 | |
Winson Chung | ddf6297 | 2018-02-12 11:10:04 -0800 | [diff] [blame] | 458 | /** |
| 459 | * Called only when the animation should be canceled prior to starting. |
| 460 | */ |
Jorim Jaggi | 589c5ba | 2019-07-30 16:50:13 +0200 | [diff] [blame^] | 461 | static void notifyAnimationCancelBeforeStart(IRecentsAnimationRunner recentsAnimationRunner) { |
Winson Chung | ddf6297 | 2018-02-12 11:10:04 -0800 | [diff] [blame] | 462 | try { |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 463 | recentsAnimationRunner.onAnimationCanceled(false /* deferredWithScreenshot */); |
Winson Chung | ddf6297 | 2018-02-12 11:10:04 -0800 | [diff] [blame] | 464 | } catch (RemoteException e) { |
| 465 | Slog.e(TAG, "Failed to cancel recents animation before start", e); |
| 466 | } |
| 467 | } |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 468 | |
| 469 | /** |
| 470 | * @return The top stack that is not always-on-top. |
| 471 | */ |
| 472 | private ActivityStack getTopNonAlwaysOnTopStack() { |
| 473 | for (int i = mDefaultDisplay.getChildCount() - 1; i >= 0; i--) { |
| 474 | final ActivityStack s = mDefaultDisplay.getChildAt(i); |
| 475 | if (s.getWindowConfiguration().isAlwaysOnTop()) { |
| 476 | continue; |
| 477 | } |
| 478 | return s; |
| 479 | } |
| 480 | return null; |
| 481 | } |
Winson Chung | 00a0969 | 2018-04-19 16:14:09 -0700 | [diff] [blame] | 482 | |
| 483 | /** |
| 484 | * @return the top activity in the {@param targetStack} matching the {@param component}, or just |
| 485 | * the top activity of the top task if no task matches the component. |
| 486 | */ |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 487 | private ActivityRecord getTargetActivity(ActivityStack targetStack) { |
Winson Chung | 00a0969 | 2018-04-19 16:14:09 -0700 | [diff] [blame] | 488 | if (targetStack == null) { |
| 489 | return null; |
| 490 | } |
| 491 | |
| 492 | for (int i = targetStack.getChildCount() - 1; i >= 0; i--) { |
Winson Chung | 65d66d3 | 2018-12-13 17:48:39 -0800 | [diff] [blame] | 493 | final TaskRecord task = targetStack.getChildAt(i); |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 494 | if (task.userId == mUserId |
| 495 | && task.getBaseIntent().getComponent().equals(mTargetIntent.getComponent())) { |
Winson Chung | 00a0969 | 2018-04-19 16:14:09 -0700 | [diff] [blame] | 496 | return task.getTopActivity(); |
| 497 | } |
| 498 | } |
Winson Chung | 2bc60c0 | 2019-05-16 17:36:05 -0700 | [diff] [blame] | 499 | return null; |
Winson Chung | 00a0969 | 2018-04-19 16:14:09 -0700 | [diff] [blame] | 500 | } |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 501 | } |