Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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.wm; |
| 18 | |
Jorim Jaggi | 54cff64 | 2018-03-15 15:51:32 +0100 | [diff] [blame] | 19 | import static android.app.ActivityManagerInternal.APP_TRANSITION_RECENTS_ANIM; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 20 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME; |
Jorim Jaggi | 54cff64 | 2018-03-15 15:51:32 +0100 | [diff] [blame] | 21 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 22 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; |
| 23 | import static android.view.RemoteAnimationTarget.MODE_CLOSING; |
Winson Chung | a89ffed | 2018-01-25 17:46:11 +0000 | [diff] [blame] | 24 | import static android.view.WindowManager.INPUT_CONSUMER_RECENTS_ANIMATION; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 25 | import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; |
| 26 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME; |
| 27 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
Jorim Jaggi | 54cff64 | 2018-03-15 15:51:32 +0100 | [diff] [blame] | 28 | import static com.android.server.wm.WindowManagerService.H.NOTIFY_APP_TRANSITION_STARTING; |
Yi Jin | 6c6e9ca | 2018-03-20 16:53:35 -0700 | [diff] [blame] | 29 | import static com.android.server.wm.RemoteAnimationAdapterWrapperProto.TARGET; |
| 30 | import static com.android.server.wm.AnimationAdapterProto.REMOTE; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 31 | |
Winson Chung | 6a38fca | 2018-03-28 17:57:09 -0700 | [diff] [blame^] | 32 | import android.annotation.IntDef; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 33 | import android.app.ActivityManager.TaskSnapshot; |
| 34 | import android.app.WindowConfiguration; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 35 | import android.graphics.Point; |
| 36 | import android.graphics.Rect; |
| 37 | import android.os.Binder; |
Adrian Roos | 842e788 | 2018-03-26 17:34:06 +0200 | [diff] [blame] | 38 | import android.os.IBinder.DeathRecipient; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 39 | import android.os.RemoteException; |
| 40 | import android.os.SystemClock; |
Winson Chung | 23aa7b1 | 2018-02-01 11:41:43 -0800 | [diff] [blame] | 41 | import android.util.ArraySet; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 42 | import android.util.Log; |
Jorim Jaggi | f75d161 | 2018-02-27 15:05:21 +0100 | [diff] [blame] | 43 | import android.util.Slog;import android.util.proto.ProtoOutputStream; |
Vadim Tryshev | 593e956 | 2018-03-08 17:15:45 -0800 | [diff] [blame] | 44 | import android.util.SparseBooleanArray; |
Jorim Jaggi | 54cff64 | 2018-03-15 15:51:32 +0100 | [diff] [blame] | 45 | import android.util.SparseIntArray; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 46 | import android.view.IRecentsAnimationController; |
| 47 | import android.view.IRecentsAnimationRunner; |
| 48 | import android.view.RemoteAnimationTarget; |
| 49 | import android.view.SurfaceControl; |
| 50 | import android.view.SurfaceControl.Transaction; |
Jorim Jaggi | f75d161 | 2018-02-27 15:05:21 +0100 | [diff] [blame] | 51 | |
Winson Chung | 23aa7b1 | 2018-02-01 11:41:43 -0800 | [diff] [blame] | 52 | import com.google.android.collect.Sets; |
Jorim Jaggi | f75d161 | 2018-02-27 15:05:21 +0100 | [diff] [blame] | 53 | |
| 54 | import com.android.server.wm.SurfaceAnimator.OnAnimationFinishedCallback; |
Jorim Jaggi | 817ebdd | 2018-03-26 15:46:01 +0200 | [diff] [blame] | 55 | import com.android.server.wm.utils.InsetUtils; |
Jorim Jaggi | f75d161 | 2018-02-27 15:05:21 +0100 | [diff] [blame] | 56 | |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 57 | import java.io.PrintWriter; |
| 58 | import java.util.ArrayList; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 59 | /** |
| 60 | * Controls a single instance of the remote driven recents animation. In particular, this allows |
| 61 | * the calling SystemUI to animate the visible task windows as a part of the transition. The remote |
| 62 | * runner is provided an animation controller which allows it to take screenshots and to notify |
| 63 | * window manager when the animation is completed. In addition, window manager may also notify the |
| 64 | * app if it requires the animation to be canceled at any time (ie. due to timeout, etc.) |
| 65 | */ |
Adrian Roos | 842e788 | 2018-03-26 17:34:06 +0200 | [diff] [blame] | 66 | public class RecentsAnimationController implements DeathRecipient { |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 67 | private static final String TAG = TAG_WITH_CLASS_NAME ? "RecentsAnimationController" : TAG_WM; |
| 68 | private static final boolean DEBUG = false; |
Adrian Roos | 842e788 | 2018-03-26 17:34:06 +0200 | [diff] [blame] | 69 | private static final long FAILSAFE_DELAY = 1000; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 70 | |
Winson Chung | 6a38fca | 2018-03-28 17:57:09 -0700 | [diff] [blame^] | 71 | public static final int REORDER_KEEP_HOME_IN_PLACE = 0; |
| 72 | public static final int REORDER_MOVE_HOME_TO_TOP = 1; |
| 73 | public static final int REORDER_MOVE_HOME_TO_ORIGINAL_POSITION = 2; |
| 74 | |
| 75 | @IntDef(prefix = { "REORDER_MODE_" }, value = { |
| 76 | REORDER_KEEP_HOME_IN_PLACE, |
| 77 | REORDER_MOVE_HOME_TO_TOP, |
| 78 | REORDER_MOVE_HOME_TO_ORIGINAL_POSITION |
| 79 | }) |
| 80 | public @interface ReorderMode {} |
| 81 | |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 82 | private final WindowManagerService mService; |
| 83 | private final IRecentsAnimationRunner mRunner; |
| 84 | private final RecentsAnimationCallbacks mCallbacks; |
| 85 | private final ArrayList<TaskAnimationAdapter> mPendingAnimations = new ArrayList<>(); |
Winson Chung | ddf6297 | 2018-02-12 11:10:04 -0800 | [diff] [blame] | 86 | private final int mDisplayId; |
Winson Chung | 6a38fca | 2018-03-28 17:57:09 -0700 | [diff] [blame^] | 87 | private final Runnable mFailsafeRunnable = () -> { |
| 88 | cancelAnimation(REORDER_MOVE_HOME_TO_ORIGINAL_POSITION); |
| 89 | }; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 90 | |
| 91 | // The recents component app token that is shown behind the visibile tasks |
| 92 | private AppWindowToken mHomeAppToken; |
Winson Chung | 584d652 | 2018-02-07 23:57:38 +0000 | [diff] [blame] | 93 | private Rect mMinimizedHomeBounds = new Rect(); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 94 | |
| 95 | // We start the RecentsAnimationController in a pending-start state since we need to wait for |
| 96 | // the wallpaper/activity to draw before we can give control to the handler to start animating |
| 97 | // the visible task surfaces |
| 98 | private boolean mPendingStart = true; |
| 99 | |
| 100 | // Set when the animation has been canceled |
| 101 | private boolean mCanceled = false; |
| 102 | |
| 103 | // Whether or not the input consumer is enabled. The input consumer must be both registered and |
| 104 | // enabled for it to start intercepting touch events. |
| 105 | private boolean mInputConsumerEnabled; |
| 106 | |
Winson Chung | a89ffed | 2018-01-25 17:46:11 +0000 | [diff] [blame] | 107 | private Rect mTmpRect = new Rect(); |
| 108 | |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 109 | public interface RecentsAnimationCallbacks { |
Winson Chung | 6a38fca | 2018-03-28 17:57:09 -0700 | [diff] [blame^] | 110 | void onAnimationFinished(@ReorderMode int reorderMode); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | private final IRecentsAnimationController mController = |
| 114 | new IRecentsAnimationController.Stub() { |
| 115 | |
| 116 | @Override |
| 117 | public TaskSnapshot screenshotTask(int taskId) { |
| 118 | if (DEBUG) Log.d(TAG, "screenshotTask(" + taskId + "): mCanceled=" + mCanceled); |
| 119 | long token = Binder.clearCallingIdentity(); |
| 120 | try { |
| 121 | synchronized (mService.getWindowManagerLock()) { |
| 122 | if (mCanceled) { |
| 123 | return null; |
| 124 | } |
| 125 | for (int i = mPendingAnimations.size() - 1; i >= 0; i--) { |
| 126 | final TaskAnimationAdapter adapter = mPendingAnimations.get(i); |
| 127 | final Task task = adapter.mTask; |
| 128 | if (task.mTaskId == taskId) { |
Winson Chung | 23aa7b1 | 2018-02-01 11:41:43 -0800 | [diff] [blame] | 129 | final TaskSnapshotController snapshotController = |
| 130 | mService.mTaskSnapshotController; |
| 131 | final ArraySet<Task> tasks = Sets.newArraySet(task); |
| 132 | snapshotController.snapshotTasks(tasks); |
| 133 | snapshotController.addSkipClosingAppSnapshotTasks(tasks); |
| 134 | return snapshotController.getSnapshot(taskId, 0 /* userId */, |
| 135 | false /* restoreFromDisk */, false /* reducedResolution */); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 136 | } |
| 137 | } |
| 138 | return null; |
| 139 | } |
| 140 | } finally { |
| 141 | Binder.restoreCallingIdentity(token); |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | @Override |
| 146 | public void finish(boolean moveHomeToTop) { |
| 147 | if (DEBUG) Log.d(TAG, "finish(" + moveHomeToTop + "): mCanceled=" + mCanceled); |
| 148 | long token = Binder.clearCallingIdentity(); |
| 149 | try { |
| 150 | synchronized (mService.getWindowManagerLock()) { |
| 151 | if (mCanceled) { |
| 152 | return; |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | // Note, the callback will handle its own synchronization, do not lock on WM lock |
| 157 | // prior to calling the callback |
Winson Chung | 6a38fca | 2018-03-28 17:57:09 -0700 | [diff] [blame^] | 158 | mCallbacks.onAnimationFinished(moveHomeToTop |
| 159 | ? REORDER_MOVE_HOME_TO_TOP |
| 160 | : REORDER_MOVE_HOME_TO_ORIGINAL_POSITION); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 161 | } finally { |
| 162 | Binder.restoreCallingIdentity(token); |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | @Override |
Jorim Jaggi | 50bf59c | 2018-03-09 17:29:48 +0100 | [diff] [blame] | 167 | public void setAnimationTargetsBehindSystemBars(boolean behindSystemBars) |
| 168 | throws RemoteException { |
| 169 | long token = Binder.clearCallingIdentity(); |
| 170 | try { |
| 171 | synchronized (mService.getWindowManagerLock()) { |
| 172 | for (int i = mPendingAnimations.size() - 1; i >= 0; i--) { |
| 173 | mPendingAnimations.get(i).mTask.setCanAffectSystemUiFlags(behindSystemBars); |
| 174 | } |
| 175 | mService.mWindowPlacerLocked.requestTraversal(); |
| 176 | } |
| 177 | } finally { |
| 178 | Binder.restoreCallingIdentity(token); |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | @Override |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 183 | public void setInputConsumerEnabled(boolean enabled) { |
| 184 | if (DEBUG) Log.d(TAG, "setInputConsumerEnabled(" + enabled + "): mCanceled=" |
| 185 | + mCanceled); |
| 186 | long token = Binder.clearCallingIdentity(); |
| 187 | try { |
| 188 | synchronized (mService.getWindowManagerLock()) { |
| 189 | if (mCanceled) { |
| 190 | return; |
| 191 | } |
| 192 | |
| 193 | mInputConsumerEnabled = enabled; |
| 194 | mService.mInputMonitor.updateInputWindowsLw(true /*force*/); |
| 195 | mService.scheduleAnimationLocked(); |
| 196 | } |
| 197 | } finally { |
| 198 | Binder.restoreCallingIdentity(token); |
| 199 | } |
| 200 | } |
| 201 | }; |
| 202 | |
| 203 | /** |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 204 | * @param remoteAnimationRunner The remote runner which should be notified when the animation is |
| 205 | * ready to start or has been canceled |
| 206 | * @param callbacks Callbacks to be made when the animation finishes |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 207 | */ |
| 208 | RecentsAnimationController(WindowManagerService service, |
| 209 | IRecentsAnimationRunner remoteAnimationRunner, RecentsAnimationCallbacks callbacks, |
| 210 | int displayId) { |
| 211 | mService = service; |
| 212 | mRunner = remoteAnimationRunner; |
| 213 | mCallbacks = callbacks; |
Winson Chung | ddf6297 | 2018-02-12 11:10:04 -0800 | [diff] [blame] | 214 | mDisplayId = displayId; |
| 215 | } |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 216 | |
Winson Chung | ddf6297 | 2018-02-12 11:10:04 -0800 | [diff] [blame] | 217 | /** |
| 218 | * Initializes the recents animation controller. This is a separate call from the constructor |
| 219 | * because it may call cancelAnimation() which needs to properly clean up the controller |
| 220 | * in the window manager. |
| 221 | */ |
Vadim Tryshev | 593e956 | 2018-03-08 17:15:45 -0800 | [diff] [blame] | 222 | public void initialize(SparseBooleanArray recentTaskIds) { |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 223 | // Make leashes for each of the visible tasks and add it to the recents animation to be |
| 224 | // started |
Winson Chung | ddf6297 | 2018-02-12 11:10:04 -0800 | [diff] [blame] | 225 | final DisplayContent dc = mService.mRoot.getDisplayContent(mDisplayId); |
| 226 | final ArrayList<Task> visibleTasks = dc.getVisibleTasks(); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 227 | final int taskCount = visibleTasks.size(); |
| 228 | for (int i = 0; i < taskCount; i++) { |
| 229 | final Task task = visibleTasks.get(i); |
| 230 | final WindowConfiguration config = task.getWindowConfiguration(); |
| 231 | if (config.tasksAreFloating() |
| 232 | || config.getWindowingMode() == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY |
| 233 | || config.getActivityType() == ACTIVITY_TYPE_HOME) { |
| 234 | continue; |
| 235 | } |
Vadim Tryshev | 593e956 | 2018-03-08 17:15:45 -0800 | [diff] [blame] | 236 | addAnimation(task, !recentTaskIds.get(task.mTaskId)); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 237 | } |
| 238 | |
Winson Chung | ddf6297 | 2018-02-12 11:10:04 -0800 | [diff] [blame] | 239 | // Skip the animation if there is nothing to animate |
| 240 | if (mPendingAnimations.isEmpty()) { |
Winson Chung | 6a38fca | 2018-03-28 17:57:09 -0700 | [diff] [blame^] | 241 | cancelAnimation(REORDER_MOVE_HOME_TO_ORIGINAL_POSITION); |
Winson Chung | ddf6297 | 2018-02-12 11:10:04 -0800 | [diff] [blame] | 242 | return; |
| 243 | } |
| 244 | |
Adrian Roos | 842e788 | 2018-03-26 17:34:06 +0200 | [diff] [blame] | 245 | try { |
| 246 | mRunner.asBinder().linkToDeath(this, 0); |
| 247 | } catch (RemoteException e) { |
Winson Chung | 6a38fca | 2018-03-28 17:57:09 -0700 | [diff] [blame^] | 248 | cancelAnimation(REORDER_MOVE_HOME_TO_ORIGINAL_POSITION); |
Adrian Roos | 842e788 | 2018-03-26 17:34:06 +0200 | [diff] [blame] | 249 | return; |
| 250 | } |
| 251 | |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 252 | // Adjust the wallpaper visibility for the showing home activity |
| 253 | final AppWindowToken recentsComponentAppToken = |
| 254 | dc.getHomeStack().getTopChild().getTopFullscreenAppToken(); |
| 255 | if (recentsComponentAppToken != null) { |
| 256 | if (DEBUG) Log.d(TAG, "setHomeApp(" + recentsComponentAppToken.getName() + ")"); |
| 257 | mHomeAppToken = recentsComponentAppToken; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 258 | if (recentsComponentAppToken.windowsCanBeWallpaperTarget()) { |
| 259 | dc.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER; |
| 260 | dc.setLayoutNeeded(); |
| 261 | } |
| 262 | } |
| 263 | |
Winson Chung | 584d652 | 2018-02-07 23:57:38 +0000 | [diff] [blame] | 264 | // Save the minimized home height |
| 265 | dc.getDockedDividerController().getHomeStackBoundsInDockedMode(mMinimizedHomeBounds); |
| 266 | |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 267 | mService.mWindowPlacerLocked.performSurfacePlacement(); |
| 268 | } |
| 269 | |
Vadim Tryshev | 593e956 | 2018-03-08 17:15:45 -0800 | [diff] [blame] | 270 | private void addAnimation(Task task, boolean isRecentTaskInvisible) { |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 271 | if (DEBUG) Log.d(TAG, "addAnimation(" + task.getName() + ")"); |
| 272 | final SurfaceAnimator anim = new SurfaceAnimator(task, null /* animationFinishedCallback */, |
Chavi Weingarten | b736e32 | 2018-02-23 00:27:54 +0000 | [diff] [blame] | 273 | mService); |
Vadim Tryshev | 593e956 | 2018-03-08 17:15:45 -0800 | [diff] [blame] | 274 | final TaskAnimationAdapter taskAdapter = new TaskAnimationAdapter(task, |
| 275 | isRecentTaskInvisible); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 276 | anim.startAnimation(task.getPendingTransaction(), taskAdapter, false /* hidden */); |
| 277 | task.commitPendingTransaction(); |
| 278 | mPendingAnimations.add(taskAdapter); |
| 279 | } |
| 280 | |
| 281 | void startAnimation() { |
Winson Chung | ddf6297 | 2018-02-12 11:10:04 -0800 | [diff] [blame] | 282 | if (DEBUG) Log.d(TAG, "startAnimation(): mPendingStart=" + mPendingStart |
| 283 | + " mCanceled=" + mCanceled); |
| 284 | if (!mPendingStart || mCanceled) { |
| 285 | // Skip starting if we've already started or canceled the animation |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 286 | return; |
| 287 | } |
| 288 | try { |
Winson Chung | 2dc3736 | 2018-03-12 17:57:06 -0700 | [diff] [blame] | 289 | final ArrayList<RemoteAnimationTarget> appAnimations = new ArrayList<>(); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 290 | for (int i = mPendingAnimations.size() - 1; i >= 0; i--) { |
Winson Chung | 2dc3736 | 2018-03-12 17:57:06 -0700 | [diff] [blame] | 291 | final RemoteAnimationTarget target = |
| 292 | mPendingAnimations.get(i).createRemoteAnimationApp(); |
| 293 | if (target != null) { |
| 294 | appAnimations.add(target); |
| 295 | } |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 296 | } |
Winson Chung | 2dc3736 | 2018-03-12 17:57:06 -0700 | [diff] [blame] | 297 | final RemoteAnimationTarget[] appTargets = appAnimations.toArray( |
| 298 | new RemoteAnimationTarget[appAnimations.size()]); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 299 | mPendingStart = false; |
Winson Chung | 584d652 | 2018-02-07 23:57:38 +0000 | [diff] [blame] | 300 | |
| 301 | final Rect minimizedHomeBounds = |
| 302 | mHomeAppToken != null && mHomeAppToken.inSplitScreenSecondaryWindowingMode() |
| 303 | ? mMinimizedHomeBounds : null; |
| 304 | final Rect contentInsets = |
| 305 | mHomeAppToken != null && mHomeAppToken.findMainWindow() != null |
| 306 | ? mHomeAppToken.findMainWindow().mContentInsets : null; |
Winson Chung | 2dc3736 | 2018-03-12 17:57:06 -0700 | [diff] [blame] | 307 | mRunner.onAnimationStart_New(mController, appTargets, contentInsets, |
Winson Chung | 584d652 | 2018-02-07 23:57:38 +0000 | [diff] [blame] | 308 | minimizedHomeBounds); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 309 | } catch (RemoteException e) { |
| 310 | Slog.e(TAG, "Failed to start recents animation", e); |
| 311 | } |
Jorim Jaggi | 54cff64 | 2018-03-15 15:51:32 +0100 | [diff] [blame] | 312 | final SparseIntArray reasons = new SparseIntArray(); |
| 313 | reasons.put(WINDOWING_MODE_FULLSCREEN, APP_TRANSITION_RECENTS_ANIM); |
| 314 | mService.mH.obtainMessage(NOTIFY_APP_TRANSITION_STARTING, |
| 315 | reasons).sendToTarget(); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 316 | } |
| 317 | |
Winson Chung | 6a38fca | 2018-03-28 17:57:09 -0700 | [diff] [blame^] | 318 | void cancelAnimation(@ReorderMode int reorderMode) { |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 319 | if (DEBUG) Log.d(TAG, "cancelAnimation()"); |
Winson Chung | 65fc89a | 2018-02-28 08:32:12 -0800 | [diff] [blame] | 320 | synchronized (mService.getWindowManagerLock()) { |
| 321 | if (mCanceled) { |
| 322 | // We've already canceled the animation |
| 323 | return; |
| 324 | } |
Adrian Roos | 842e788 | 2018-03-26 17:34:06 +0200 | [diff] [blame] | 325 | mService.mH.removeCallbacks(mFailsafeRunnable); |
Winson Chung | 65fc89a | 2018-02-28 08:32:12 -0800 | [diff] [blame] | 326 | mCanceled = true; |
| 327 | try { |
| 328 | mRunner.onAnimationCanceled(); |
| 329 | } catch (RemoteException e) { |
| 330 | Slog.e(TAG, "Failed to cancel recents animation", e); |
| 331 | } |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 332 | } |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 333 | // Clean up and return to the previous app |
Winson Chung | 65fc89a | 2018-02-28 08:32:12 -0800 | [diff] [blame] | 334 | // Don't hold the WM lock here as it calls back to AM/RecentsAnimation |
Winson Chung | 6a38fca | 2018-03-28 17:57:09 -0700 | [diff] [blame^] | 335 | mCallbacks.onAnimationFinished(reorderMode); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 336 | } |
| 337 | |
Winson Chung | 6a38fca | 2018-03-28 17:57:09 -0700 | [diff] [blame^] | 338 | void cleanupAnimation(@ReorderMode int reorderMode) { |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 339 | if (DEBUG) Log.d(TAG, "cleanupAnimation(): mPendingAnimations=" |
| 340 | + mPendingAnimations.size()); |
| 341 | for (int i = mPendingAnimations.size() - 1; i >= 0; i--) { |
| 342 | final TaskAnimationAdapter adapter = mPendingAnimations.get(i); |
Jorim Jaggi | 50bf59c | 2018-03-09 17:29:48 +0100 | [diff] [blame] | 343 | adapter.mTask.setCanAffectSystemUiFlags(true); |
Winson Chung | 6a38fca | 2018-03-28 17:57:09 -0700 | [diff] [blame^] | 344 | if (reorderMode == REORDER_MOVE_HOME_TO_TOP |
| 345 | || reorderMode == REORDER_KEEP_HOME_IN_PLACE) { |
chaviw | 87ca63a | 2018-03-26 14:06:17 -0700 | [diff] [blame] | 346 | adapter.mTask.dontAnimateDimExit(); |
| 347 | } |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 348 | adapter.mCapturedFinishCallback.onAnimationFinished(adapter); |
| 349 | } |
| 350 | mPendingAnimations.clear(); |
| 351 | |
Adrian Roos | 842e788 | 2018-03-26 17:34:06 +0200 | [diff] [blame] | 352 | mRunner.asBinder().unlinkToDeath(this, 0); |
| 353 | |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 354 | mService.mInputMonitor.updateInputWindowsLw(true /*force*/); |
Winson Chung | a89ffed | 2018-01-25 17:46:11 +0000 | [diff] [blame] | 355 | mService.destroyInputConsumer(INPUT_CONSUMER_RECENTS_ANIMATION); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 356 | } |
| 357 | |
Adrian Roos | 842e788 | 2018-03-26 17:34:06 +0200 | [diff] [blame] | 358 | void scheduleFailsafe() { |
| 359 | mService.mH.postDelayed(mFailsafeRunnable, FAILSAFE_DELAY); |
| 360 | } |
| 361 | |
| 362 | @Override |
| 363 | public void binderDied() { |
Winson Chung | 6a38fca | 2018-03-28 17:57:09 -0700 | [diff] [blame^] | 364 | cancelAnimation(REORDER_MOVE_HOME_TO_ORIGINAL_POSITION); |
Adrian Roos | 842e788 | 2018-03-26 17:34:06 +0200 | [diff] [blame] | 365 | } |
| 366 | |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 367 | void checkAnimationReady(WallpaperController wallpaperController) { |
| 368 | if (mPendingStart) { |
| 369 | final boolean wallpaperReady = !isHomeAppOverWallpaper() |
| 370 | || (wallpaperController.getWallpaperTarget() != null |
| 371 | && wallpaperController.wallpaperTransitionReady()); |
| 372 | if (wallpaperReady) { |
| 373 | mService.getRecentsAnimationController().startAnimation(); |
| 374 | } |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | boolean isWallpaperVisible(WindowState w) { |
| 379 | return w != null && w.mAppToken != null && mHomeAppToken == w.mAppToken |
| 380 | && isHomeAppOverWallpaper(); |
| 381 | } |
| 382 | |
Winson Chung | a89ffed | 2018-01-25 17:46:11 +0000 | [diff] [blame] | 383 | boolean hasInputConsumerForApp(AppWindowToken appToken) { |
| 384 | return mInputConsumerEnabled && isAnimatingApp(appToken); |
| 385 | } |
| 386 | |
| 387 | boolean updateInputConsumerForApp(InputConsumerImpl recentsAnimationInputConsumer, |
| 388 | boolean hasFocus) { |
| 389 | // Update the input consumer touchable region to match the home app main window |
| 390 | final WindowState homeAppMainWindow = mHomeAppToken != null |
| 391 | ? mHomeAppToken.findMainWindow() |
| 392 | : null; |
| 393 | if (homeAppMainWindow != null) { |
| 394 | homeAppMainWindow.getBounds(mTmpRect); |
| 395 | recentsAnimationInputConsumer.mWindowHandle.hasFocus = hasFocus; |
| 396 | recentsAnimationInputConsumer.mWindowHandle.touchableRegion.set(mTmpRect); |
| 397 | return true; |
| 398 | } |
| 399 | return false; |
| 400 | } |
| 401 | |
| 402 | private boolean isHomeAppOverWallpaper() { |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 403 | if (mHomeAppToken == null) { |
| 404 | return false; |
| 405 | } |
| 406 | return mHomeAppToken.windowsCanBeWallpaperTarget(); |
| 407 | } |
| 408 | |
Winson Chung | a89ffed | 2018-01-25 17:46:11 +0000 | [diff] [blame] | 409 | private boolean isAnimatingApp(AppWindowToken appToken) { |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 410 | for (int i = mPendingAnimations.size() - 1; i >= 0; i--) { |
| 411 | final Task task = mPendingAnimations.get(i).mTask; |
| 412 | for (int j = task.getChildCount() - 1; j >= 0; j--) { |
| 413 | final AppWindowToken app = task.getChildAt(j); |
| 414 | if (app == appToken) { |
| 415 | return true; |
| 416 | } |
| 417 | } |
| 418 | } |
| 419 | return false; |
| 420 | } |
| 421 | |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 422 | private class TaskAnimationAdapter implements AnimationAdapter { |
| 423 | |
Vadim Tryshev | 593e956 | 2018-03-08 17:15:45 -0800 | [diff] [blame] | 424 | private final Task mTask; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 425 | private SurfaceControl mCapturedLeash; |
| 426 | private OnAnimationFinishedCallback mCapturedFinishCallback; |
Vadim Tryshev | 593e956 | 2018-03-08 17:15:45 -0800 | [diff] [blame] | 427 | private final boolean mIsRecentTaskInvisible; |
Jorim Jaggi | f75d161 | 2018-02-27 15:05:21 +0100 | [diff] [blame] | 428 | private RemoteAnimationTarget mTarget; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 429 | |
Vadim Tryshev | 593e956 | 2018-03-08 17:15:45 -0800 | [diff] [blame] | 430 | TaskAnimationAdapter(Task task, boolean isRecentTaskInvisible) { |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 431 | mTask = task; |
Vadim Tryshev | 593e956 | 2018-03-08 17:15:45 -0800 | [diff] [blame] | 432 | mIsRecentTaskInvisible = isRecentTaskInvisible; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | RemoteAnimationTarget createRemoteAnimationApp() { |
Winson Chung | 584d652 | 2018-02-07 23:57:38 +0000 | [diff] [blame] | 436 | final Point position = new Point(); |
| 437 | final Rect bounds = new Rect(); |
| 438 | final WindowContainer container = mTask.getParent(); |
| 439 | container.getRelativePosition(position); |
| 440 | container.getBounds(bounds); |
| 441 | final WindowState mainWindow = mTask.getTopVisibleAppMainWindow(); |
Winson Chung | 2dc3736 | 2018-03-12 17:57:06 -0700 | [diff] [blame] | 442 | if (mainWindow == null) { |
| 443 | return null; |
| 444 | } |
Jorim Jaggi | 817ebdd | 2018-03-26 15:46:01 +0200 | [diff] [blame] | 445 | final Rect insets = new Rect(mainWindow.mContentInsets); |
| 446 | InsetUtils.addInsets(insets, mainWindow.mAppToken.getLetterboxInsets()); |
Jorim Jaggi | f75d161 | 2018-02-27 15:05:21 +0100 | [diff] [blame] | 447 | mTarget = new RemoteAnimationTarget(mTask.mTaskId, MODE_CLOSING, mCapturedLeash, |
Winson Chung | 584d652 | 2018-02-07 23:57:38 +0000 | [diff] [blame] | 448 | !mTask.fillsParent(), mainWindow.mWinAnimator.mLastClipRect, |
Jorim Jaggi | 817ebdd | 2018-03-26 15:46:01 +0200 | [diff] [blame] | 449 | insets, mTask.getPrefixOrderIndex(), position, bounds, |
Vadim Tryshev | 593e956 | 2018-03-08 17:15:45 -0800 | [diff] [blame] | 450 | mTask.getWindowConfiguration(), mIsRecentTaskInvisible); |
Jorim Jaggi | f75d161 | 2018-02-27 15:05:21 +0100 | [diff] [blame] | 451 | return mTarget; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | @Override |
| 455 | public boolean getDetachWallpaper() { |
| 456 | return false; |
| 457 | } |
| 458 | |
| 459 | @Override |
Jorim Jaggi | 82c1786 | 2018-02-21 17:50:18 +0100 | [diff] [blame] | 460 | public boolean getShowWallpaper() { |
| 461 | return false; |
| 462 | } |
| 463 | |
| 464 | @Override |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 465 | public int getBackgroundColor() { |
| 466 | return 0; |
| 467 | } |
| 468 | |
| 469 | @Override |
| 470 | public void startAnimation(SurfaceControl animationLeash, Transaction t, |
| 471 | OnAnimationFinishedCallback finishCallback) { |
| 472 | mCapturedLeash = animationLeash; |
| 473 | mCapturedFinishCallback = finishCallback; |
| 474 | } |
| 475 | |
| 476 | @Override |
| 477 | public void onAnimationCancelled(SurfaceControl animationLeash) { |
Winson Chung | 6a38fca | 2018-03-28 17:57:09 -0700 | [diff] [blame^] | 478 | cancelAnimation(REORDER_MOVE_HOME_TO_ORIGINAL_POSITION); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | @Override |
| 482 | public long getDurationHint() { |
| 483 | return 0; |
| 484 | } |
| 485 | |
| 486 | @Override |
| 487 | public long getStatusBarTransitionsStartTime() { |
| 488 | return SystemClock.uptimeMillis(); |
| 489 | } |
Jorim Jaggi | f75d161 | 2018-02-27 15:05:21 +0100 | [diff] [blame] | 490 | |
| 491 | @Override |
| 492 | public void dump(PrintWriter pw, String prefix) { |
| 493 | pw.print(prefix); pw.println("task=" + mTask); |
| 494 | if (mTarget != null) { |
| 495 | pw.print(prefix); pw.println("Target:"); |
| 496 | mTarget.dump(pw, prefix + " "); |
| 497 | } else { |
| 498 | pw.print(prefix); pw.println("Target: null"); |
| 499 | } |
| 500 | } |
| 501 | |
| 502 | @Override |
| 503 | public void writeToProto(ProtoOutputStream proto) { |
| 504 | final long token = proto.start(REMOTE); |
| 505 | if (mTarget != null) { |
| 506 | mTarget.writeToProto(proto, TARGET); |
| 507 | } |
| 508 | proto.end(token); |
| 509 | } |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | public void dump(PrintWriter pw, String prefix) { |
| 513 | final String innerPrefix = prefix + " "; |
| 514 | pw.print(prefix); pw.println(RecentsAnimationController.class.getSimpleName() + ":"); |
| 515 | pw.print(innerPrefix); pw.println("mPendingStart=" + mPendingStart); |
| 516 | pw.print(innerPrefix); pw.println("mHomeAppToken=" + mHomeAppToken); |
| 517 | } |
| 518 | } |