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