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 | 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; |
Winson Chung | fbbb158 | 2018-11-13 16:09:01 -0800 | [diff] [blame] | 29 | |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 30 | import static com.android.server.wm.ActivityStackSupervisor.PRESERVE_WINDOWS; |
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 | |
| 36 | import android.app.ActivityOptions; |
Winson Chung | f993016 | 2018-02-12 14:51:46 -0800 | [diff] [blame] | 37 | import android.app.AppOpsManager; |
| 38 | import android.app.IAssistDataReceiver; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 39 | import android.content.ComponentName; |
Winson Chung | f993016 | 2018-02-12 14:51:46 -0800 | [diff] [blame] | 40 | import android.content.Context; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 41 | import android.content.Intent; |
Winson Chung | fbbb158 | 2018-11-13 16:09:01 -0800 | [diff] [blame] | 42 | import android.os.Bundle; |
| 43 | import android.os.IBinder; |
Winson Chung | ddf6297 | 2018-02-12 11:10:04 -0800 | [diff] [blame] | 44 | import android.os.RemoteException; |
Winson Chung | 584d652 | 2018-02-07 23:57:38 +0000 | [diff] [blame] | 45 | import android.os.Trace; |
Winson Chung | ddf6297 | 2018-02-12 11:10:04 -0800 | [diff] [blame] | 46 | import android.util.Slog; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 47 | import android.view.IRecentsAnimationRunner; |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 48 | |
Winson Chung | fbbb158 | 2018-11-13 16:09:01 -0800 | [diff] [blame] | 49 | import com.android.server.LocalServices; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 50 | import com.android.server.am.AssistDataRequester; |
Felipe Leme | 749b889 | 2018-12-03 16:30:30 -0800 | [diff] [blame] | 51 | import com.android.server.contentcapture.ContentCaptureManagerInternal; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 52 | import com.android.server.wm.RecentsAnimationController.RecentsAnimationCallbacks; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 53 | |
Winson Chung | fbbb158 | 2018-11-13 16:09:01 -0800 | [diff] [blame] | 54 | import java.util.List; |
| 55 | |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 56 | /** |
| 57 | * Manages the recents animation, including the reordering of the stacks for the transition and |
| 58 | * cleanup. See {@link com.android.server.wm.RecentsAnimationController}. |
| 59 | */ |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 60 | class RecentsAnimation implements RecentsAnimationCallbacks, |
| 61 | ActivityDisplay.OnStackOrderChangedListener { |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 62 | private static final String TAG = RecentsAnimation.class.getSimpleName(); |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 63 | private static final boolean DEBUG = DEBUG_RECENTS_ANIMATIONS; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 64 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 65 | private final ActivityTaskManagerService mService; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 66 | private final ActivityStackSupervisor mStackSupervisor; |
| 67 | private final ActivityStartController mActivityStartController; |
| 68 | private final WindowManagerService mWindowManager; |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 69 | private final ActivityDisplay mDefaultDisplay; |
Jorim Jaggi | bc2aabe | 2018-03-08 17:27:43 +0100 | [diff] [blame] | 70 | private final int mCallingPid; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 71 | |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 72 | private int mTargetActivityType; |
Winson Chung | f993016 | 2018-02-12 14:51:46 -0800 | [diff] [blame] | 73 | private AssistDataRequester mAssistDataRequester; |
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, |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 80 | int callingPid) { |
| 81 | mService = atm; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 82 | mStackSupervisor = stackSupervisor; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 83 | mDefaultDisplay = mService.mRootActivityContainer.getDefaultDisplay(); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 84 | mActivityStartController = activityStartController; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 85 | mWindowManager = wm; |
Jorim Jaggi | bc2aabe | 2018-03-08 17:27:43 +0100 | [diff] [blame] | 86 | mCallingPid = callingPid; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | void startRecentsActivity(Intent intent, IRecentsAnimationRunner recentsAnimationRunner, |
Winson Chung | f993016 | 2018-02-12 14:51:46 -0800 | [diff] [blame] | 90 | ComponentName recentsComponent, int recentsUid, |
Winson Chung | fbbb158 | 2018-11-13 16:09:01 -0800 | [diff] [blame] | 91 | @Deprecated IAssistDataReceiver assistDataReceiver) { |
Winson Chung | f993016 | 2018-02-12 14:51:46 -0800 | [diff] [blame] | 92 | if (DEBUG) Slog.d(TAG, "startRecentsActivity(): intent=" + intent |
| 93 | + " assistDataReceiver=" + assistDataReceiver); |
Winson Chung | 584d652 | 2018-02-07 23:57:38 +0000 | [diff] [blame] | 94 | Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "RecentsAnimation#startRecentsActivity"); |
Winson Chung | ddf6297 | 2018-02-12 11:10:04 -0800 | [diff] [blame] | 95 | |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 96 | // TODO(multi-display) currently only support recents animation in default display. |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 97 | final DisplayContent dc = |
| 98 | mService.mRootActivityContainer.getDefaultDisplay().mDisplayContent; |
Winson Chung | ddf6297 | 2018-02-12 11:10:04 -0800 | [diff] [blame] | 99 | if (!mWindowManager.canStartRecentsAnimation()) { |
| 100 | notifyAnimationCancelBeforeStart(recentsAnimationRunner); |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 101 | if (DEBUG) Slog.d(TAG, "Can't start recents animation, nextAppTransition=" |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 102 | + dc.mAppTransition.getAppTransition()); |
Winson Chung | ddf6297 | 2018-02-12 11:10:04 -0800 | [diff] [blame] | 103 | return; |
| 104 | } |
| 105 | |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 106 | // If the activity is associated with the recents stack, then try and get that first |
| 107 | mTargetActivityType = intent.getComponent() != null |
| 108 | && recentsComponent.equals(intent.getComponent()) |
| 109 | ? ACTIVITY_TYPE_RECENTS |
| 110 | : ACTIVITY_TYPE_HOME; |
Winson Chung | 9344203 | 2018-12-04 13:24:29 -0800 | [diff] [blame] | 111 | ActivityStack targetStack = mDefaultDisplay.getStack(WINDOWING_MODE_UNDEFINED, |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 112 | mTargetActivityType); |
Winson Chung | 00a0969 | 2018-04-19 16:14:09 -0700 | [diff] [blame] | 113 | ActivityRecord targetActivity = getTargetActivity(targetStack, intent.getComponent()); |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 114 | final boolean hasExistingActivity = targetActivity != null; |
| 115 | if (hasExistingActivity) { |
| 116 | final ActivityDisplay display = targetActivity.getDisplay(); |
| 117 | mRestoreTargetBehindStack = display.getStackAbove(targetStack); |
| 118 | if (mRestoreTargetBehindStack == null) { |
Winson Chung | ddf6297 | 2018-02-12 11:10:04 -0800 | [diff] [blame] | 119 | notifyAnimationCancelBeforeStart(recentsAnimationRunner); |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 120 | if (DEBUG) Slog.d(TAG, "No stack above target stack=" + targetStack); |
Winson Chung | ddf6297 | 2018-02-12 11:10:04 -0800 | [diff] [blame] | 121 | return; |
| 122 | } |
| 123 | } |
| 124 | |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 125 | // Send launch hint if we are actually launching the target. If it's already visible |
| 126 | // (shouldn't happen in general) we don't need to send it. |
| 127 | if (targetActivity == null || !targetActivity.visible) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 128 | mService.mRootActivityContainer.sendPowerHintForLaunchStartIfNeeded( |
| 129 | true /* forceSend */, targetActivity); |
Jorim Jaggi | ac96052 | 2018-03-22 23:20:36 +0100 | [diff] [blame] | 130 | } |
| 131 | |
Igor Murashkin | 212d06c | 2018-10-22 16:34:39 -0700 | [diff] [blame] | 132 | mStackSupervisor.getActivityMetricsLogger().notifyActivityLaunching(intent); |
Jorim Jaggi | 54cff64 | 2018-03-15 15:51:32 +0100 | [diff] [blame] | 133 | |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 134 | mService.mH.post(() -> mService.mAmInternal.setRunningRemoteAnimation(mCallingPid, true)); |
Jorim Jaggi | bc2aabe | 2018-03-08 17:27:43 +0100 | [diff] [blame] | 135 | |
Winson Chung | 1e6d4a9 | 2018-01-26 10:04:20 -0800 | [diff] [blame] | 136 | mWindowManager.deferSurfaceLayout(); |
| 137 | try { |
Winson Chung | f993016 | 2018-02-12 14:51:46 -0800 | [diff] [blame] | 138 | // Kick off the assist data request in the background before showing the target activity |
Winson Chung | 3be4f26 | 2018-12-19 12:22:14 -0800 | [diff] [blame] | 139 | requestAssistData(recentsComponent, recentsUid, assistDataReceiver); |
Winson Chung | f993016 | 2018-02-12 14:51:46 -0800 | [diff] [blame] | 140 | |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 141 | if (hasExistingActivity) { |
| 142 | // 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] | 143 | mDefaultDisplay.moveStackBehindBottomMostVisibleStack(targetStack); |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 144 | if (DEBUG) Slog.d(TAG, "Moved stack=" + targetStack + " behind stack=" |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 145 | + mDefaultDisplay.getStackAbove(targetStack)); |
Winson Chung | 00a0969 | 2018-04-19 16:14:09 -0700 | [diff] [blame] | 146 | |
| 147 | // If there are multiple tasks in the target stack (ie. the home stack, with 3p |
| 148 | // and default launchers coexisting), then move the task to the top as a part of |
| 149 | // moving the stack to the front |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 150 | if (targetStack.topTask() != targetActivity.getTaskRecord()) { |
| 151 | targetStack.addTask(targetActivity.getTaskRecord(), true /* toTop */, |
Winson Chung | 00a0969 | 2018-04-19 16:14:09 -0700 | [diff] [blame] | 152 | "startRecentsActivity"); |
| 153 | } |
Winson Chung | ddf6297 | 2018-02-12 11:10:04 -0800 | [diff] [blame] | 154 | } else { |
Winson Chung | 9344203 | 2018-12-04 13:24:29 -0800 | [diff] [blame] | 155 | // No recents activity, create the new recents activity bottom most |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 156 | ActivityOptions options = ActivityOptions.makeBasic(); |
| 157 | options.setLaunchActivityType(mTargetActivityType); |
| 158 | options.setAvoidMoveToFront(); |
Winson Chung | 1e6d4a9 | 2018-01-26 10:04:20 -0800 | [diff] [blame] | 159 | intent.addFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_NO_ANIMATION); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 160 | |
Winson Chung | 1e6d4a9 | 2018-01-26 10:04:20 -0800 | [diff] [blame] | 161 | mActivityStartController |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 162 | .obtainStarter(intent, "startRecentsActivity_noTargetActivity") |
Winson Chung | 1e6d4a9 | 2018-01-26 10:04:20 -0800 | [diff] [blame] | 163 | .setCallingUid(recentsUid) |
| 164 | .setCallingPackage(recentsComponent.getPackageName()) |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 165 | .setActivityOptions(SafeActivityOptions.fromBundle(options.toBundle())) |
Winson Chung | 3be4f26 | 2018-12-19 12:22:14 -0800 | [diff] [blame] | 166 | .setMayWait(mService.getCurrentUserId()) |
Winson Chung | 1e6d4a9 | 2018-01-26 10:04:20 -0800 | [diff] [blame] | 167 | .execute(); |
Winson Chung | 9344203 | 2018-12-04 13:24:29 -0800 | [diff] [blame] | 168 | |
| 169 | // Move the recents activity into place for the animation |
| 170 | targetActivity = mDefaultDisplay.getStack(WINDOWING_MODE_UNDEFINED, |
| 171 | mTargetActivityType).getTopActivity(); |
| 172 | targetStack = targetActivity.getActivityStack(); |
| 173 | mDefaultDisplay.moveStackBehindBottomMostVisibleStack(targetStack); |
| 174 | if (DEBUG) { |
| 175 | Slog.d(TAG, "Moved stack=" + targetStack + " behind stack=" |
| 176 | + mDefaultDisplay.getStackAbove(targetStack)); |
| 177 | } |
| 178 | |
Winson Chung | 1e6d4a9 | 2018-01-26 10:04:20 -0800 | [diff] [blame] | 179 | mWindowManager.prepareAppTransition(TRANSIT_NONE, false); |
Winson Chung | ba40d3a | 2018-05-16 09:40:16 -0700 | [diff] [blame] | 180 | mWindowManager.executeAppTransition(); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 181 | |
Winson Chung | ddf6297 | 2018-02-12 11:10:04 -0800 | [diff] [blame] | 182 | |
Winson Chung | 1e6d4a9 | 2018-01-26 10:04:20 -0800 | [diff] [blame] | 183 | // TODO: Maybe wait for app to draw in this particular case? |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 184 | |
| 185 | if (DEBUG) Slog.d(TAG, "Started intent=" + intent); |
Winson Chung | 1e6d4a9 | 2018-01-26 10:04:20 -0800 | [diff] [blame] | 186 | } |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 187 | |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 188 | // 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] | 189 | // duration of the gesture that is driven by the recents component |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 190 | targetActivity.mLaunchTaskBehind = true; |
Winson Chung | 1e6d4a9 | 2018-01-26 10:04:20 -0800 | [diff] [blame] | 191 | |
| 192 | // 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] | 193 | // started. Cancel any existing recents animation running synchronously (do not hold the |
| 194 | // WM lock) |
| 195 | mWindowManager.cancelRecentsAnimationSynchronously(REORDER_MOVE_TO_ORIGINAL_POSITION, |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 196 | "startRecentsActivity"); |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 197 | mWindowManager.initializeRecentsAnimation(mTargetActivityType, recentsAnimationRunner, |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 198 | this, mDefaultDisplay.mDisplayId, |
| 199 | mStackSupervisor.mRecentTasks.getRecentTaskIds()); |
Winson Chung | 1e6d4a9 | 2018-01-26 10:04:20 -0800 | [diff] [blame] | 200 | |
| 201 | // If we updated the launch-behind state, update the visibility of the activities after |
| 202 | // we fetch the visible tasks to be controlled by the animation |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 203 | mService.mRootActivityContainer.ensureActivitiesVisible(null, 0, PRESERVE_WINDOWS); |
Jorim Jaggi | 54cff64 | 2018-03-15 15:51:32 +0100 | [diff] [blame] | 204 | |
| 205 | mStackSupervisor.getActivityMetricsLogger().notifyActivityLaunched(START_TASK_TO_FRONT, |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 206 | targetActivity); |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 207 | |
| 208 | // Register for stack order changes |
| 209 | mDefaultDisplay.registerStackOrderChangedListener(this); |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 210 | } catch (Exception e) { |
| 211 | Slog.e(TAG, "Failed to start recents activity", e); |
| 212 | throw e; |
Winson Chung | 1e6d4a9 | 2018-01-26 10:04:20 -0800 | [diff] [blame] | 213 | } finally { |
| 214 | mWindowManager.continueSurfaceLayout(); |
Winson Chung | 584d652 | 2018-02-07 23:57:38 +0000 | [diff] [blame] | 215 | Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 216 | } |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 217 | } |
| 218 | |
Winson Chung | fbbb158 | 2018-11-13 16:09:01 -0800 | [diff] [blame] | 219 | /** |
| 220 | * Requests assist data for the top visible activities. |
| 221 | */ |
| 222 | private void requestAssistData(ComponentName recentsComponent, int recentsUid, |
Winson Chung | 3be4f26 | 2018-12-19 12:22:14 -0800 | [diff] [blame] | 223 | @Deprecated IAssistDataReceiver assistDataReceiver) { |
Winson Chung | fbbb158 | 2018-11-13 16:09:01 -0800 | [diff] [blame] | 224 | final AppOpsManager appOpsManager = (AppOpsManager) |
| 225 | mService.mContext.getSystemService(Context.APP_OPS_SERVICE); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 226 | final List<IBinder> topActivities = |
| 227 | mService.mRootActivityContainer.getTopVisibleActivities(); |
Winson Chung | fbbb158 | 2018-11-13 16:09:01 -0800 | [diff] [blame] | 228 | final AssistDataRequester.AssistDataRequesterCallbacks assistDataCallbacks; |
| 229 | if (assistDataReceiver != null) { |
| 230 | assistDataCallbacks = new AssistDataReceiverProxy(assistDataReceiver, |
| 231 | recentsComponent.getPackageName()) { |
| 232 | @Override |
| 233 | public void onAssistDataReceivedLocked(Bundle data, int activityIndex, |
| 234 | int activityCount) { |
| 235 | // Try to notify the intelligence service first |
Felipe Leme | 749b889 | 2018-12-03 16:30:30 -0800 | [diff] [blame] | 236 | final ContentCaptureManagerInternal imService = |
| 237 | LocalServices.getService(ContentCaptureManagerInternal.class); |
Winson Chung | fbbb158 | 2018-11-13 16:09:01 -0800 | [diff] [blame] | 238 | final IBinder activityToken = topActivities.get(activityIndex); |
Winson Chung | 3be4f26 | 2018-12-19 12:22:14 -0800 | [diff] [blame] | 239 | final ActivityRecord r = ActivityRecord.forTokenLocked(activityToken); |
| 240 | if (r != null && (imService == null |
| 241 | || !imService.sendActivityAssistData(r.mUserId, activityToken, data))) { |
Winson Chung | fbbb158 | 2018-11-13 16:09:01 -0800 | [diff] [blame] | 242 | // Otherwise, use the provided assist data receiver |
| 243 | super.onAssistDataReceivedLocked(data, activityIndex, activityCount); |
| 244 | } |
| 245 | } |
| 246 | }; |
| 247 | } else { |
Felipe Leme | 749b889 | 2018-12-03 16:30:30 -0800 | [diff] [blame] | 248 | final ContentCaptureManagerInternal imService = |
| 249 | LocalServices.getService(ContentCaptureManagerInternal.class); |
Winson Chung | fbbb158 | 2018-11-13 16:09:01 -0800 | [diff] [blame] | 250 | if (imService == null) { |
| 251 | // There is no intelligence service, so there is no point requesting assist data |
| 252 | return; |
| 253 | } |
| 254 | |
| 255 | assistDataCallbacks = new AssistDataRequester.AssistDataRequesterCallbacks() { |
| 256 | @Override |
| 257 | public boolean canHandleReceivedAssistDataLocked() { |
| 258 | return true; |
| 259 | } |
| 260 | |
| 261 | @Override |
| 262 | public void onAssistDataReceivedLocked(Bundle data, int activityIndex, |
| 263 | int activityCount) { |
| 264 | // Try to notify the intelligence service |
| 265 | final IBinder activityToken = topActivities.get(activityIndex); |
Winson Chung | 3be4f26 | 2018-12-19 12:22:14 -0800 | [diff] [blame] | 266 | final ActivityRecord r = ActivityRecord.forTokenLocked(activityToken); |
| 267 | if (r != null) { |
| 268 | imService.sendActivityAssistData(r.mUserId, activityToken, data); |
| 269 | } |
Winson Chung | fbbb158 | 2018-11-13 16:09:01 -0800 | [diff] [blame] | 270 | } |
| 271 | }; |
| 272 | } |
| 273 | mAssistDataRequester = new AssistDataRequester(mService.mContext, mWindowManager, |
| 274 | appOpsManager, assistDataCallbacks, this, OP_ASSIST_STRUCTURE, OP_NONE); |
Winson Chung | 48b2bbd | 2018-11-15 16:02:56 -0800 | [diff] [blame] | 275 | mAssistDataRequester.requestAutofillData(topActivities, |
Winson Chung | fbbb158 | 2018-11-13 16:09:01 -0800 | [diff] [blame] | 276 | recentsUid, recentsComponent.getPackageName()); |
| 277 | } |
| 278 | |
Winson Chung | 65c5f99 | 2018-04-20 14:58:57 -0700 | [diff] [blame] | 279 | private void finishAnimation(@RecentsAnimationController.ReorderMode int reorderMode) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 280 | synchronized (mService.mGlobalLock) { |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 281 | if (DEBUG) Slog.d(TAG, "onAnimationFinished(): controller=" |
Winson Chung | 65c5f99 | 2018-04-20 14:58:57 -0700 | [diff] [blame] | 282 | + mWindowManager.getRecentsAnimationController() |
| 283 | + " reorderMode=" + reorderMode); |
Winson Chung | f993016 | 2018-02-12 14:51:46 -0800 | [diff] [blame] | 284 | |
| 285 | // Cancel the associated assistant data request |
| 286 | if (mAssistDataRequester != null) { |
| 287 | mAssistDataRequester.cancel(); |
| 288 | mAssistDataRequester = null; |
| 289 | } |
| 290 | |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 291 | // Unregister for stack order changes |
| 292 | mDefaultDisplay.unregisterStackOrderChangedListener(this); |
| 293 | |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 294 | if (mWindowManager.getRecentsAnimationController() == null) return; |
| 295 | |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 296 | // Just to be sure end the launch hint in case the target activity was never launched. |
| 297 | // However, if we're keeping the activity and making it visible, we can leave it on. |
| 298 | if (reorderMode != REORDER_KEEP_IN_PLACE) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 299 | mService.mRootActivityContainer.sendPowerHintForLaunchEndIfNeeded(); |
Jorim Jaggi | ac96052 | 2018-03-22 23:20:36 +0100 | [diff] [blame] | 300 | } |
| 301 | |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 302 | mService.mH.post( |
| 303 | () -> mService.mAmInternal.setRunningRemoteAnimation(mCallingPid, false)); |
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(() -> { |
Winson Chung | 584d652 | 2018-02-07 23:57:38 +0000 | [diff] [blame] | 306 | Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, |
| 307 | "RecentsAnimation#onAnimationFinished_inSurfaceTransaction"); |
Winson Chung | 1e6d4a9 | 2018-01-26 10:04:20 -0800 | [diff] [blame] | 308 | mWindowManager.deferSurfaceLayout(); |
| 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); |
Winson Chung | 82389a9 | 2018-05-03 10:43:51 -0700 | [diff] [blame] | 314 | final ActivityRecord targetActivity = targetStack != null |
| 315 | ? targetStack.getTopActivity() |
| 316 | : null; |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 317 | if (DEBUG) Slog.d(TAG, "onAnimationFinished(): targetStack=" + targetStack |
| 318 | + " targetActivity=" + targetActivity |
| 319 | + " mRestoreTargetBehindStack=" + mRestoreTargetBehindStack); |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 320 | if (targetActivity == null) { |
Winson Chung | 1e6d4a9 | 2018-01-26 10:04:20 -0800 | [diff] [blame] | 321 | return; |
| 322 | } |
| 323 | |
| 324 | // Restore the launched-behind state |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 325 | targetActivity.mLaunchTaskBehind = false; |
Winson Chung | 1e6d4a9 | 2018-01-26 10:04:20 -0800 | [diff] [blame] | 326 | |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 327 | if (reorderMode == REORDER_MOVE_TO_TOP) { |
| 328 | // Bring the target stack to the front |
| 329 | mStackSupervisor.mNoAnimActivities.add(targetActivity); |
| 330 | targetStack.moveToFront("RecentsAnimation.onAnimationFinished()"); |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 331 | if (DEBUG) { |
| 332 | final ActivityStack topStack = getTopNonAlwaysOnTopStack(); |
| 333 | if (topStack != targetStack) { |
| 334 | Slog.w(TAG, "Expected target stack=" + targetStack |
| 335 | + " to be top most but found stack=" + topStack); |
| 336 | } |
| 337 | } |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 338 | } else if (reorderMode == REORDER_MOVE_TO_ORIGINAL_POSITION){ |
| 339 | // Restore the target stack to its previous position |
| 340 | final ActivityDisplay display = targetActivity.getDisplay(); |
| 341 | display.moveStackBehindStack(targetStack, mRestoreTargetBehindStack); |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 342 | if (DEBUG) { |
| 343 | final ActivityStack aboveTargetStack = |
| 344 | mDefaultDisplay.getStackAbove(targetStack); |
| 345 | if (mRestoreTargetBehindStack != null |
| 346 | && aboveTargetStack != mRestoreTargetBehindStack) { |
| 347 | Slog.w(TAG, "Expected target stack=" + targetStack |
| 348 | + " to restored behind stack=" + mRestoreTargetBehindStack |
| 349 | + " but it is behind stack=" + aboveTargetStack); |
| 350 | } |
| 351 | } |
Winson Chung | 6a38fca | 2018-03-28 17:57:09 -0700 | [diff] [blame] | 352 | } else { |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 353 | // Keep target stack in place, nothing changes, so ignore the transition |
| 354 | // logic below |
Winson Chung | 6a38fca | 2018-03-28 17:57:09 -0700 | [diff] [blame] | 355 | return; |
Winson Chung | 1e6d4a9 | 2018-01-26 10:04:20 -0800 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | mWindowManager.prepareAppTransition(TRANSIT_NONE, false); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 359 | mService.mRootActivityContainer.ensureActivitiesVisible(null, 0, false); |
| 360 | mService.mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Winson Chung | 1e6d4a9 | 2018-01-26 10:04:20 -0800 | [diff] [blame] | 361 | |
| 362 | // No reason to wait for the pausing activity in this case, as the hiding of |
| 363 | // surfaces needs to be done immediately. |
| 364 | mWindowManager.executeAppTransition(); |
Winson Chung | f557c3b | 2018-03-16 10:55:20 -0700 | [diff] [blame] | 365 | |
| 366 | // After reordering the stacks, reset the minimized state. At this point, either |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 367 | // the target activity is now top-most and we will stay minimized (if in |
| 368 | // split-screen), or we will have returned to the app, and the minimized state |
| 369 | // should be reset |
Winson Chung | f557c3b | 2018-03-16 10:55:20 -0700 | [diff] [blame] | 370 | mWindowManager.checkSplitScreenMinimizedChanged(true /* animate */); |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 371 | } catch (Exception e) { |
| 372 | Slog.e(TAG, "Failed to clean up recents activity", e); |
| 373 | throw e; |
Winson Chung | 1e6d4a9 | 2018-01-26 10:04:20 -0800 | [diff] [blame] | 374 | } finally { |
| 375 | mWindowManager.continueSurfaceLayout(); |
Winson Chung | 584d652 | 2018-02-07 23:57:38 +0000 | [diff] [blame] | 376 | Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 377 | } |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 378 | }); |
| 379 | } |
| 380 | } |
Winson Chung | ddf6297 | 2018-02-12 11:10:04 -0800 | [diff] [blame] | 381 | |
Winson Chung | 65c5f99 | 2018-04-20 14:58:57 -0700 | [diff] [blame] | 382 | @Override |
| 383 | public void onAnimationFinished(@RecentsAnimationController.ReorderMode int reorderMode, |
| 384 | boolean runSychronously) { |
| 385 | if (runSychronously) { |
| 386 | finishAnimation(reorderMode); |
| 387 | } else { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 388 | mService.mH.post(() -> finishAnimation(reorderMode)); |
Winson Chung | 65c5f99 | 2018-04-20 14:58:57 -0700 | [diff] [blame] | 389 | } |
| 390 | } |
| 391 | |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 392 | @Override |
Winson Chung | 65d66d3 | 2018-12-13 17:48:39 -0800 | [diff] [blame] | 393 | public void onStackOrderChanged(ActivityStack stack) { |
| 394 | if (DEBUG) Slog.d(TAG, "onStackOrderChanged(): stack=" + stack); |
| 395 | if (mDefaultDisplay.getIndexOf(stack) == -1 || !stack.shouldBeVisible(null)) { |
| 396 | // The stack is not visible, so ignore this change |
| 397 | return; |
| 398 | } |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 399 | final RecentsAnimationController controller = |
| 400 | mWindowManager.getRecentsAnimationController(); |
Winson Chung | 65d66d3 | 2018-12-13 17:48:39 -0800 | [diff] [blame] | 401 | |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 402 | // Cancel running recents animation and screenshot previous task when the next |
| 403 | // transition starts in below cases: |
| 404 | // 1) The next launching task is not in recents animation task. |
| 405 | // 2) The next task is home activity. (i.e. pressing home key to back home in recents). |
| 406 | if ((!controller.isAnimatingTask(stack.getTaskStack().getTopChild()) |
| 407 | || controller.isTargetApp(stack.getTopActivity().mAppWindowToken)) |
| 408 | && controller.shouldCancelWithDeferredScreenshot()) { |
| 409 | controller.cancelOnNextTransitionStart(); |
| 410 | } else { |
| 411 | // Just cancel directly to unleash from launcher when the next launching task is the |
| 412 | // current top task. |
| 413 | mWindowManager.cancelRecentsAnimationSynchronously(REORDER_KEEP_IN_PLACE, |
| 414 | "stackOrderChanged"); |
| 415 | } |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 416 | } |
| 417 | |
Winson Chung | ddf6297 | 2018-02-12 11:10:04 -0800 | [diff] [blame] | 418 | /** |
| 419 | * Called only when the animation should be canceled prior to starting. |
| 420 | */ |
| 421 | private void notifyAnimationCancelBeforeStart(IRecentsAnimationRunner recentsAnimationRunner) { |
| 422 | try { |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 423 | recentsAnimationRunner.onAnimationCanceled(false /* deferredWithScreenshot */); |
Winson Chung | ddf6297 | 2018-02-12 11:10:04 -0800 | [diff] [blame] | 424 | } catch (RemoteException e) { |
| 425 | Slog.e(TAG, "Failed to cancel recents animation before start", e); |
| 426 | } |
| 427 | } |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 428 | |
| 429 | /** |
| 430 | * @return The top stack that is not always-on-top. |
| 431 | */ |
| 432 | private ActivityStack getTopNonAlwaysOnTopStack() { |
| 433 | for (int i = mDefaultDisplay.getChildCount() - 1; i >= 0; i--) { |
| 434 | final ActivityStack s = mDefaultDisplay.getChildAt(i); |
| 435 | if (s.getWindowConfiguration().isAlwaysOnTop()) { |
| 436 | continue; |
| 437 | } |
| 438 | return s; |
| 439 | } |
| 440 | return null; |
| 441 | } |
Winson Chung | 00a0969 | 2018-04-19 16:14:09 -0700 | [diff] [blame] | 442 | |
| 443 | /** |
| 444 | * @return the top activity in the {@param targetStack} matching the {@param component}, or just |
| 445 | * the top activity of the top task if no task matches the component. |
| 446 | */ |
| 447 | private ActivityRecord getTargetActivity(ActivityStack targetStack, ComponentName component) { |
| 448 | if (targetStack == null) { |
| 449 | return null; |
| 450 | } |
| 451 | |
| 452 | for (int i = targetStack.getChildCount() - 1; i >= 0; i--) { |
Winson Chung | 65d66d3 | 2018-12-13 17:48:39 -0800 | [diff] [blame] | 453 | final TaskRecord task = targetStack.getChildAt(i); |
Winson Chung | 00a0969 | 2018-04-19 16:14:09 -0700 | [diff] [blame] | 454 | if (task.getBaseIntent().getComponent().equals(component)) { |
| 455 | return task.getTopActivity(); |
| 456 | } |
| 457 | } |
| 458 | return targetStack.getTopActivity(); |
| 459 | } |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 460 | } |