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 | |
| 17 | package com.android.server.am; |
| 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 | f993016 | 2018-02-12 14:51:46 -0800 | [diff] [blame^] | 20 | import static android.app.AppOpsManager.OP_ASSIST_STRUCTURE; |
| 21 | import static android.app.AppOpsManager.OP_NONE; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 22 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME; |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 23 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_RECENTS; |
| 24 | import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 25 | import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; |
| 26 | import static android.content.Intent.FLAG_ACTIVITY_NO_ANIMATION; |
Winson Chung | 584d652 | 2018-02-07 23:57:38 +0000 | [diff] [blame] | 27 | import static android.os.Trace.TRACE_TAG_ACTIVITY_MANAGER; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 28 | import static android.view.WindowManager.TRANSIT_NONE; |
| 29 | import static com.android.server.am.ActivityStackSupervisor.PRESERVE_WINDOWS; |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 30 | import static com.android.server.wm.RecentsAnimationController.REORDER_KEEP_IN_PLACE; |
| 31 | import static com.android.server.wm.RecentsAnimationController.REORDER_MOVE_TO_ORIGINAL_POSITION; |
| 32 | import static com.android.server.wm.RecentsAnimationController.REORDER_MOVE_TO_TOP; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 33 | |
| 34 | import android.app.ActivityOptions; |
Winson Chung | f993016 | 2018-02-12 14:51:46 -0800 | [diff] [blame^] | 35 | import android.app.AppOpsManager; |
| 36 | import android.app.IAssistDataReceiver; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 37 | import android.content.ComponentName; |
Winson Chung | f993016 | 2018-02-12 14:51:46 -0800 | [diff] [blame^] | 38 | import android.content.Context; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 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; |
Winson Chung | 6a38fca | 2018-03-28 17:57:09 -0700 | [diff] [blame] | 44 | import com.android.server.wm.RecentsAnimationController; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 45 | import com.android.server.wm.RecentsAnimationController.RecentsAnimationCallbacks; |
| 46 | import com.android.server.wm.WindowManagerService; |
| 47 | |
| 48 | /** |
| 49 | * Manages the recents animation, including the reordering of the stacks for the transition and |
| 50 | * cleanup. See {@link com.android.server.wm.RecentsAnimationController}. |
| 51 | */ |
| 52 | class RecentsAnimation implements RecentsAnimationCallbacks { |
| 53 | private static final String TAG = RecentsAnimation.class.getSimpleName(); |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 54 | // TODO (b/73188263): Reset debugging flags |
| 55 | private static final boolean DEBUG = true; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 56 | |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 57 | private final ActivityManagerService mService; |
| 58 | private final ActivityStackSupervisor mStackSupervisor; |
| 59 | private final ActivityStartController mActivityStartController; |
| 60 | private final WindowManagerService mWindowManager; |
| 61 | private final UserController mUserController; |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 62 | private final ActivityDisplay mDefaultDisplay; |
Jorim Jaggi | bc2aabe | 2018-03-08 17:27:43 +0100 | [diff] [blame] | 63 | private final int mCallingPid; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 64 | |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 65 | private int mTargetActivityType; |
Winson Chung | f993016 | 2018-02-12 14:51:46 -0800 | [diff] [blame^] | 66 | private AssistDataRequester mAssistDataRequester; |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 67 | |
| 68 | // The stack to restore the target stack behind when the animation is finished |
| 69 | private ActivityStack mRestoreTargetBehindStack; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 70 | |
| 71 | RecentsAnimation(ActivityManagerService am, ActivityStackSupervisor stackSupervisor, |
| 72 | ActivityStartController activityStartController, WindowManagerService wm, |
Jorim Jaggi | bc2aabe | 2018-03-08 17:27:43 +0100 | [diff] [blame] | 73 | UserController userController, int callingPid) { |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 74 | mService = am; |
| 75 | mStackSupervisor = stackSupervisor; |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 76 | mDefaultDisplay = stackSupervisor.getDefaultDisplay(); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 77 | mActivityStartController = activityStartController; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 78 | mWindowManager = wm; |
| 79 | mUserController = userController; |
Jorim Jaggi | bc2aabe | 2018-03-08 17:27:43 +0100 | [diff] [blame] | 80 | mCallingPid = callingPid; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | void startRecentsActivity(Intent intent, IRecentsAnimationRunner recentsAnimationRunner, |
Winson Chung | f993016 | 2018-02-12 14:51:46 -0800 | [diff] [blame^] | 84 | ComponentName recentsComponent, int recentsUid, |
| 85 | IAssistDataReceiver assistDataReceiver) { |
| 86 | if (DEBUG) Slog.d(TAG, "startRecentsActivity(): intent=" + intent |
| 87 | + " assistDataReceiver=" + assistDataReceiver); |
Winson Chung | 584d652 | 2018-02-07 23:57:38 +0000 | [diff] [blame] | 88 | Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "RecentsAnimation#startRecentsActivity"); |
Winson Chung | ddf6297 | 2018-02-12 11:10:04 -0800 | [diff] [blame] | 89 | |
| 90 | if (!mWindowManager.canStartRecentsAnimation()) { |
| 91 | notifyAnimationCancelBeforeStart(recentsAnimationRunner); |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 92 | if (DEBUG) Slog.d(TAG, "Can't start recents animation, nextAppTransition=" |
| 93 | + mWindowManager.getPendingAppTransition()); |
Winson Chung | ddf6297 | 2018-02-12 11:10:04 -0800 | [diff] [blame] | 94 | return; |
| 95 | } |
| 96 | |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 97 | // If the activity is associated with the recents stack, then try and get that first |
| 98 | mTargetActivityType = intent.getComponent() != null |
| 99 | && recentsComponent.equals(intent.getComponent()) |
| 100 | ? ACTIVITY_TYPE_RECENTS |
| 101 | : ACTIVITY_TYPE_HOME; |
| 102 | final ActivityStack targetStack = mDefaultDisplay.getStack(WINDOWING_MODE_UNDEFINED, |
| 103 | mTargetActivityType); |
| 104 | ActivityRecord targetActivity = targetStack != null |
| 105 | ? targetStack.getTopActivity() |
| 106 | : null; |
| 107 | final boolean hasExistingActivity = targetActivity != null; |
| 108 | if (hasExistingActivity) { |
| 109 | final ActivityDisplay display = targetActivity.getDisplay(); |
| 110 | mRestoreTargetBehindStack = display.getStackAbove(targetStack); |
| 111 | if (mRestoreTargetBehindStack == null) { |
Winson Chung | ddf6297 | 2018-02-12 11:10:04 -0800 | [diff] [blame] | 112 | notifyAnimationCancelBeforeStart(recentsAnimationRunner); |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 113 | if (DEBUG) Slog.d(TAG, "No stack above target stack=" + targetStack); |
Winson Chung | ddf6297 | 2018-02-12 11:10:04 -0800 | [diff] [blame] | 114 | return; |
| 115 | } |
| 116 | } |
| 117 | |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 118 | // Send launch hint if we are actually launching the target. If it's already visible |
| 119 | // (shouldn't happen in general) we don't need to send it. |
| 120 | if (targetActivity == null || !targetActivity.visible) { |
Jorim Jaggi | ac96052 | 2018-03-22 23:20:36 +0100 | [diff] [blame] | 121 | mStackSupervisor.sendPowerHintForLaunchStartIfNeeded(true /* forceSend */, |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 122 | targetActivity); |
Jorim Jaggi | ac96052 | 2018-03-22 23:20:36 +0100 | [diff] [blame] | 123 | } |
| 124 | |
Jorim Jaggi | 54cff64 | 2018-03-15 15:51:32 +0100 | [diff] [blame] | 125 | mStackSupervisor.getActivityMetricsLogger().notifyActivityLaunching(); |
| 126 | |
Jorim Jaggi | bc2aabe | 2018-03-08 17:27:43 +0100 | [diff] [blame] | 127 | mService.setRunningRemoteAnimation(mCallingPid, true); |
| 128 | |
Winson Chung | 1e6d4a9 | 2018-01-26 10:04:20 -0800 | [diff] [blame] | 129 | mWindowManager.deferSurfaceLayout(); |
| 130 | try { |
Winson Chung | f993016 | 2018-02-12 14:51:46 -0800 | [diff] [blame^] | 131 | // Kick off the assist data request in the background before showing the target activity |
| 132 | if (assistDataReceiver != null) { |
| 133 | final AppOpsManager appOpsManager = (AppOpsManager) |
| 134 | mService.mContext.getSystemService(Context.APP_OPS_SERVICE); |
| 135 | final AssistDataReceiverProxy proxy = new AssistDataReceiverProxy( |
| 136 | assistDataReceiver, recentsComponent.getPackageName()); |
| 137 | mAssistDataRequester = new AssistDataRequester(mService.mContext, mService, |
| 138 | mWindowManager, appOpsManager, proxy, this, OP_ASSIST_STRUCTURE, OP_NONE); |
| 139 | mAssistDataRequester.requestAssistData(mStackSupervisor.getTopVisibleActivities(), |
| 140 | true /* fetchData */, false /* fetchScreenshots */, |
| 141 | true /* allowFetchData */, false /* allowFetchScreenshots */, |
| 142 | recentsUid, recentsComponent.getPackageName()); |
| 143 | } |
| 144 | |
Winson Chung | ddf6297 | 2018-02-12 11:10:04 -0800 | [diff] [blame] | 145 | final ActivityDisplay display; |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 146 | if (hasExistingActivity) { |
| 147 | // Move the recents activity into place for the animation if it is not top most |
| 148 | display = targetActivity.getDisplay(); |
| 149 | display.moveStackBehindBottomMostVisibleStack(targetStack); |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 150 | if (DEBUG) Slog.d(TAG, "Moved stack=" + targetStack + " behind stack=" |
| 151 | + display.getStackAbove(targetStack)); |
Winson Chung | ddf6297 | 2018-02-12 11:10:04 -0800 | [diff] [blame] | 152 | } else { |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 153 | // No recents activity |
| 154 | ActivityOptions options = ActivityOptions.makeBasic(); |
| 155 | options.setLaunchActivityType(mTargetActivityType); |
| 156 | options.setAvoidMoveToFront(); |
Winson Chung | 1e6d4a9 | 2018-01-26 10:04:20 -0800 | [diff] [blame] | 157 | intent.addFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_NO_ANIMATION); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 158 | |
Winson Chung | 1e6d4a9 | 2018-01-26 10:04:20 -0800 | [diff] [blame] | 159 | mActivityStartController |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 160 | .obtainStarter(intent, "startRecentsActivity_noTargetActivity") |
Winson Chung | 1e6d4a9 | 2018-01-26 10:04:20 -0800 | [diff] [blame] | 161 | .setCallingUid(recentsUid) |
| 162 | .setCallingPackage(recentsComponent.getPackageName()) |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 163 | .setActivityOptions(SafeActivityOptions.fromBundle(options.toBundle())) |
Winson Chung | 1e6d4a9 | 2018-01-26 10:04:20 -0800 | [diff] [blame] | 164 | .setMayWait(mUserController.getCurrentUserId()) |
| 165 | .execute(); |
| 166 | mWindowManager.prepareAppTransition(TRANSIT_NONE, false); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 167 | |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 168 | targetActivity = mDefaultDisplay.getStack(WINDOWING_MODE_UNDEFINED, |
| 169 | mTargetActivityType).getTopActivity(); |
| 170 | display = targetActivity.getDisplay(); |
Winson Chung | ddf6297 | 2018-02-12 11:10:04 -0800 | [diff] [blame] | 171 | |
Winson Chung | 1e6d4a9 | 2018-01-26 10:04:20 -0800 | [diff] [blame] | 172 | // TODO: Maybe wait for app to draw in this particular case? |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 173 | |
| 174 | if (DEBUG) Slog.d(TAG, "Started intent=" + intent); |
Winson Chung | 1e6d4a9 | 2018-01-26 10:04:20 -0800 | [diff] [blame] | 175 | } |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 176 | |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 177 | // 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] | 178 | // duration of the gesture that is driven by the recents component |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 179 | targetActivity.mLaunchTaskBehind = true; |
Winson Chung | 1e6d4a9 | 2018-01-26 10:04:20 -0800 | [diff] [blame] | 180 | |
| 181 | // Fetch all the surface controls and pass them to the client to get the animation |
| 182 | // started |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 183 | mWindowManager.cancelRecentsAnimation(REORDER_MOVE_TO_ORIGINAL_POSITION, |
| 184 | "startRecentsActivity"); |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 185 | mWindowManager.initializeRecentsAnimation(mTargetActivityType, recentsAnimationRunner, |
| 186 | this, display.mDisplayId, mStackSupervisor.mRecentTasks.getRecentTaskIds()); |
Winson Chung | 1e6d4a9 | 2018-01-26 10:04:20 -0800 | [diff] [blame] | 187 | |
| 188 | // If we updated the launch-behind state, update the visibility of the activities after |
| 189 | // we fetch the visible tasks to be controlled by the animation |
| 190 | mStackSupervisor.ensureActivitiesVisibleLocked(null, 0, PRESERVE_WINDOWS); |
Jorim Jaggi | 54cff64 | 2018-03-15 15:51:32 +0100 | [diff] [blame] | 191 | |
| 192 | mStackSupervisor.getActivityMetricsLogger().notifyActivityLaunched(START_TASK_TO_FRONT, |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 193 | targetActivity); |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 194 | } catch (Exception e) { |
| 195 | Slog.e(TAG, "Failed to start recents activity", e); |
| 196 | throw e; |
Winson Chung | 1e6d4a9 | 2018-01-26 10:04:20 -0800 | [diff] [blame] | 197 | } finally { |
| 198 | mWindowManager.continueSurfaceLayout(); |
Winson Chung | 584d652 | 2018-02-07 23:57:38 +0000 | [diff] [blame] | 199 | Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 200 | } |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | @Override |
Winson Chung | 6a38fca | 2018-03-28 17:57:09 -0700 | [diff] [blame] | 204 | public void onAnimationFinished(@RecentsAnimationController.ReorderMode int reorderMode) { |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 205 | synchronized (mService) { |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 206 | if (DEBUG) Slog.d(TAG, "onAnimationFinished(): controller=" |
| 207 | + mWindowManager.getRecentsAnimationController() |
| 208 | + " reorderMode=" + reorderMode); |
Winson Chung | f993016 | 2018-02-12 14:51:46 -0800 | [diff] [blame^] | 209 | |
| 210 | // Cancel the associated assistant data request |
| 211 | if (mAssistDataRequester != null) { |
| 212 | mAssistDataRequester.cancel(); |
| 213 | mAssistDataRequester = null; |
| 214 | } |
| 215 | |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 216 | if (mWindowManager.getRecentsAnimationController() == null) return; |
| 217 | |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 218 | // Just to be sure end the launch hint in case the target activity was never launched. |
| 219 | // However, if we're keeping the activity and making it visible, we can leave it on. |
| 220 | if (reorderMode != REORDER_KEEP_IN_PLACE) { |
Jorim Jaggi | ac96052 | 2018-03-22 23:20:36 +0100 | [diff] [blame] | 221 | mStackSupervisor.sendPowerHintForLaunchEndIfNeeded(); |
| 222 | } |
| 223 | |
Jorim Jaggi | bc2aabe | 2018-03-08 17:27:43 +0100 | [diff] [blame] | 224 | mService.setRunningRemoteAnimation(mCallingPid, false); |
| 225 | |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 226 | mWindowManager.inSurfaceTransaction(() -> { |
Winson Chung | 584d652 | 2018-02-07 23:57:38 +0000 | [diff] [blame] | 227 | Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, |
| 228 | "RecentsAnimation#onAnimationFinished_inSurfaceTransaction"); |
Winson Chung | 1e6d4a9 | 2018-01-26 10:04:20 -0800 | [diff] [blame] | 229 | mWindowManager.deferSurfaceLayout(); |
| 230 | try { |
Winson Chung | 6a38fca | 2018-03-28 17:57:09 -0700 | [diff] [blame] | 231 | mWindowManager.cleanupRecentsAnimation(reorderMode); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 232 | |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 233 | final ActivityStack targetStack = mDefaultDisplay.getStack( |
| 234 | WINDOWING_MODE_UNDEFINED, mTargetActivityType); |
| 235 | final ActivityRecord targetActivity = targetStack.getTopActivity(); |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 236 | if (DEBUG) Slog.d(TAG, "onAnimationFinished(): targetStack=" + targetStack |
| 237 | + " targetActivity=" + targetActivity |
| 238 | + " mRestoreTargetBehindStack=" + mRestoreTargetBehindStack); |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 239 | if (targetActivity == null) { |
Winson Chung | 1e6d4a9 | 2018-01-26 10:04:20 -0800 | [diff] [blame] | 240 | return; |
| 241 | } |
| 242 | |
| 243 | // Restore the launched-behind state |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 244 | targetActivity.mLaunchTaskBehind = false; |
Winson Chung | 1e6d4a9 | 2018-01-26 10:04:20 -0800 | [diff] [blame] | 245 | |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 246 | if (reorderMode == REORDER_MOVE_TO_TOP) { |
| 247 | // Bring the target stack to the front |
| 248 | mStackSupervisor.mNoAnimActivities.add(targetActivity); |
| 249 | targetStack.moveToFront("RecentsAnimation.onAnimationFinished()"); |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 250 | if (DEBUG) { |
| 251 | final ActivityStack topStack = getTopNonAlwaysOnTopStack(); |
| 252 | if (topStack != targetStack) { |
| 253 | Slog.w(TAG, "Expected target stack=" + targetStack |
| 254 | + " to be top most but found stack=" + topStack); |
| 255 | } |
| 256 | } |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 257 | } else if (reorderMode == REORDER_MOVE_TO_ORIGINAL_POSITION){ |
| 258 | // Restore the target stack to its previous position |
| 259 | final ActivityDisplay display = targetActivity.getDisplay(); |
| 260 | display.moveStackBehindStack(targetStack, mRestoreTargetBehindStack); |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 261 | if (DEBUG) { |
| 262 | final ActivityStack aboveTargetStack = |
| 263 | mDefaultDisplay.getStackAbove(targetStack); |
| 264 | if (mRestoreTargetBehindStack != null |
| 265 | && aboveTargetStack != mRestoreTargetBehindStack) { |
| 266 | Slog.w(TAG, "Expected target stack=" + targetStack |
| 267 | + " to restored behind stack=" + mRestoreTargetBehindStack |
| 268 | + " but it is behind stack=" + aboveTargetStack); |
| 269 | } |
| 270 | } |
Winson Chung | 6a38fca | 2018-03-28 17:57:09 -0700 | [diff] [blame] | 271 | } else { |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 272 | // Keep target stack in place, nothing changes, so ignore the transition |
| 273 | // logic below |
Winson Chung | 6a38fca | 2018-03-28 17:57:09 -0700 | [diff] [blame] | 274 | return; |
Winson Chung | 1e6d4a9 | 2018-01-26 10:04:20 -0800 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | mWindowManager.prepareAppTransition(TRANSIT_NONE, false); |
| 278 | mStackSupervisor.ensureActivitiesVisibleLocked(null, 0, false); |
| 279 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
| 280 | |
| 281 | // No reason to wait for the pausing activity in this case, as the hiding of |
| 282 | // surfaces needs to be done immediately. |
| 283 | mWindowManager.executeAppTransition(); |
Winson Chung | f557c3b | 2018-03-16 10:55:20 -0700 | [diff] [blame] | 284 | |
| 285 | // After reordering the stacks, reset the minimized state. At this point, either |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 286 | // the target activity is now top-most and we will stay minimized (if in |
| 287 | // split-screen), or we will have returned to the app, and the minimized state |
| 288 | // should be reset |
Winson Chung | f557c3b | 2018-03-16 10:55:20 -0700 | [diff] [blame] | 289 | mWindowManager.checkSplitScreenMinimizedChanged(true /* animate */); |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 290 | } catch (Exception e) { |
| 291 | Slog.e(TAG, "Failed to clean up recents activity", e); |
| 292 | throw e; |
Winson Chung | 1e6d4a9 | 2018-01-26 10:04:20 -0800 | [diff] [blame] | 293 | } finally { |
| 294 | mWindowManager.continueSurfaceLayout(); |
Winson Chung | 584d652 | 2018-02-07 23:57:38 +0000 | [diff] [blame] | 295 | Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 296 | } |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 297 | }); |
| 298 | } |
| 299 | } |
Winson Chung | ddf6297 | 2018-02-12 11:10:04 -0800 | [diff] [blame] | 300 | |
| 301 | /** |
| 302 | * Called only when the animation should be canceled prior to starting. |
| 303 | */ |
| 304 | private void notifyAnimationCancelBeforeStart(IRecentsAnimationRunner recentsAnimationRunner) { |
| 305 | try { |
| 306 | recentsAnimationRunner.onAnimationCanceled(); |
| 307 | } catch (RemoteException e) { |
| 308 | Slog.e(TAG, "Failed to cancel recents animation before start", e); |
| 309 | } |
| 310 | } |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 311 | |
| 312 | /** |
| 313 | * @return The top stack that is not always-on-top. |
| 314 | */ |
| 315 | private ActivityStack getTopNonAlwaysOnTopStack() { |
| 316 | for (int i = mDefaultDisplay.getChildCount() - 1; i >= 0; i--) { |
| 317 | final ActivityStack s = mDefaultDisplay.getChildAt(i); |
| 318 | if (s.getWindowConfiguration().isAlwaysOnTop()) { |
| 319 | continue; |
| 320 | } |
| 321 | return s; |
| 322 | } |
| 323 | return null; |
| 324 | } |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 325 | } |