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