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.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 20 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 21 | import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 22 | import static android.view.RemoteAnimationTarget.MODE_CLOSING; |
Winson Chung | 732446a | 2018-09-19 13:15:17 -0700 | [diff] [blame] | 23 | import static android.view.RemoteAnimationTarget.MODE_OPENING; |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 24 | import static android.view.WindowManager.DOCKED_INVALID; |
Winson Chung | a89ffed | 2018-01-25 17:46:11 +0000 | [diff] [blame] | 25 | import static android.view.WindowManager.INPUT_CONSUMER_RECENTS_ANIMATION; |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 26 | |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 27 | import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 28 | import static com.android.server.wm.ActivityTaskManagerInternal.APP_TRANSITION_RECENTS_ANIM; |
Yi Jin | 6c6e9ca | 2018-03-20 16:53:35 -0700 | [diff] [blame] | 29 | import static com.android.server.wm.AnimationAdapterProto.REMOTE; |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 30 | import static com.android.server.wm.RemoteAnimationAdapterWrapperProto.TARGET; |
| 31 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_RECENTS_ANIMATIONS; |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 32 | import static com.android.server.wm.WindowManagerInternal.AppTransitionListener; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 33 | |
Winson Chung | 6a38fca | 2018-03-28 17:57:09 -0700 | [diff] [blame] | 34 | import android.annotation.IntDef; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 35 | import android.app.ActivityManager.TaskSnapshot; |
| 36 | import android.app.WindowConfiguration; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 37 | import android.graphics.Point; |
| 38 | import android.graphics.Rect; |
| 39 | import android.os.Binder; |
Adrian Roos | 842e788 | 2018-03-26 17:34:06 +0200 | [diff] [blame] | 40 | import android.os.IBinder.DeathRecipient; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 41 | import android.os.RemoteException; |
| 42 | import android.os.SystemClock; |
Winson Chung | 23aa7b1 | 2018-02-01 11:41:43 -0800 | [diff] [blame] | 43 | import android.util.ArraySet; |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 44 | import android.util.Slog; |
Vadim Tryshev | 593e956 | 2018-03-08 17:15:45 -0800 | [diff] [blame] | 45 | import android.util.SparseBooleanArray; |
Jorim Jaggi | 54cff64 | 2018-03-15 15:51:32 +0100 | [diff] [blame] | 46 | import android.util.SparseIntArray; |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 47 | import android.util.proto.ProtoOutputStream; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 48 | import android.view.IRecentsAnimationController; |
| 49 | import android.view.IRecentsAnimationRunner; |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 50 | import android.view.InputWindowHandle; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 51 | import android.view.RemoteAnimationTarget; |
| 52 | import android.view.SurfaceControl; |
| 53 | import android.view.SurfaceControl.Transaction; |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 54 | |
Winson Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [diff] [blame] | 55 | import com.android.internal.annotations.VisibleForTesting; |
Winson Chung | a840c32 | 2018-04-20 15:58:18 -0700 | [diff] [blame] | 56 | import com.android.server.LocalServices; |
Yohei Yukawa | c3de83e | 2018-08-28 16:09:34 -0700 | [diff] [blame] | 57 | import com.android.server.inputmethod.InputMethodManagerInternal; |
Jorim Jaggi | f75d161 | 2018-02-27 15:05:21 +0100 | [diff] [blame] | 58 | import com.android.server.wm.SurfaceAnimator.OnAnimationFinishedCallback; |
Jorim Jaggi | 817ebdd | 2018-03-26 15:46:01 +0200 | [diff] [blame] | 59 | import com.android.server.wm.utils.InsetUtils; |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 60 | |
Vadim Tryshev | 257f86b | 2018-08-23 16:45:02 -0700 | [diff] [blame] | 61 | import com.google.android.collect.Sets; |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 62 | |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 63 | import java.io.PrintWriter; |
| 64 | import java.util.ArrayList; |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 65 | |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 66 | /** |
| 67 | * Controls a single instance of the remote driven recents animation. In particular, this allows |
| 68 | * the calling SystemUI to animate the visible task windows as a part of the transition. The remote |
| 69 | * runner is provided an animation controller which allows it to take screenshots and to notify |
| 70 | * window manager when the animation is completed. In addition, window manager may also notify the |
| 71 | * app if it requires the animation to be canceled at any time (ie. due to timeout, etc.) |
| 72 | */ |
Adrian Roos | 842e788 | 2018-03-26 17:34:06 +0200 | [diff] [blame] | 73 | public class RecentsAnimationController implements DeathRecipient { |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 74 | private static final String TAG = RecentsAnimationController.class.getSimpleName(); |
Adrian Roos | 842e788 | 2018-03-26 17:34:06 +0200 | [diff] [blame] | 75 | private static final long FAILSAFE_DELAY = 1000; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 76 | |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 77 | public static final int REORDER_KEEP_IN_PLACE = 0; |
| 78 | public static final int REORDER_MOVE_TO_TOP = 1; |
| 79 | public static final int REORDER_MOVE_TO_ORIGINAL_POSITION = 2; |
Winson Chung | 6a38fca | 2018-03-28 17:57:09 -0700 | [diff] [blame] | 80 | |
| 81 | @IntDef(prefix = { "REORDER_MODE_" }, value = { |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 82 | REORDER_KEEP_IN_PLACE, |
| 83 | REORDER_MOVE_TO_TOP, |
| 84 | REORDER_MOVE_TO_ORIGINAL_POSITION |
Winson Chung | 6a38fca | 2018-03-28 17:57:09 -0700 | [diff] [blame] | 85 | }) |
| 86 | public @interface ReorderMode {} |
| 87 | |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 88 | private final WindowManagerService mService; |
Winson Chung | 5c91e8f | 2018-05-07 10:06:55 -0700 | [diff] [blame] | 89 | private IRecentsAnimationRunner mRunner; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 90 | private final RecentsAnimationCallbacks mCallbacks; |
| 91 | private final ArrayList<TaskAnimationAdapter> mPendingAnimations = new ArrayList<>(); |
Winson Chung | ddf6297 | 2018-02-12 11:10:04 -0800 | [diff] [blame] | 92 | private final int mDisplayId; |
Winson Chung | 65c5f99 | 2018-04-20 14:58:57 -0700 | [diff] [blame] | 93 | private final Runnable mFailsafeRunnable = () -> |
| 94 | cancelAnimation(REORDER_MOVE_TO_ORIGINAL_POSITION, "failSafeRunnable"); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 95 | |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 96 | final Object mLock = new Object(); |
| 97 | |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 98 | // The recents component app token that is shown behind the visibile tasks |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 99 | private AppWindowToken mTargetAppToken; |
Winson Chung | 732446a | 2018-09-19 13:15:17 -0700 | [diff] [blame] | 100 | private int mTargetActivityType; |
Winson Chung | 584d652 | 2018-02-07 23:57:38 +0000 | [diff] [blame] | 101 | private Rect mMinimizedHomeBounds = new Rect(); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 102 | |
| 103 | // We start the RecentsAnimationController in a pending-start state since we need to wait for |
| 104 | // the wallpaper/activity to draw before we can give control to the handler to start animating |
| 105 | // the visible task surfaces |
| 106 | private boolean mPendingStart = true; |
| 107 | |
| 108 | // Set when the animation has been canceled |
Winson Chung | f557c3b | 2018-03-16 10:55:20 -0700 | [diff] [blame] | 109 | private boolean mCanceled; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 110 | |
| 111 | // Whether or not the input consumer is enabled. The input consumer must be both registered and |
| 112 | // enabled for it to start intercepting touch events. |
| 113 | private boolean mInputConsumerEnabled; |
| 114 | |
Winson Chung | f557c3b | 2018-03-16 10:55:20 -0700 | [diff] [blame] | 115 | // Whether or not the recents animation should cause the primary split-screen stack to be |
| 116 | // minimized |
| 117 | private boolean mSplitScreenMinimized; |
| 118 | |
Adrian Roos | 653c6c1 | 2018-04-09 14:12:46 -0700 | [diff] [blame] | 119 | private final Rect mTmpRect = new Rect(); |
| 120 | |
| 121 | private boolean mLinkedToDeathOfRunner; |
Winson Chung | a89ffed | 2018-01-25 17:46:11 +0000 | [diff] [blame] | 122 | |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 123 | private boolean mCancelWithDeferredScreenshot; |
| 124 | |
| 125 | private boolean mCancelOnNextTransitionStart; |
| 126 | |
| 127 | /** |
| 128 | * Animates the screenshot of task that used to be controlled by RecentsAnimation. |
| 129 | * @see {@link #cancelOnNextTransitionStart} |
| 130 | */ |
| 131 | SurfaceAnimator mRecentScreenshotAnimator; |
| 132 | |
| 133 | final AppTransitionListener mAppTransitionListener = new AppTransitionListener() { |
| 134 | @Override |
| 135 | public int onAppTransitionStartingLocked(int transit, long duration, |
| 136 | long statusBarAnimationStartTime, long statusBarAnimationDuration) { |
| 137 | onTransitionStart(); |
| 138 | mService.mRoot.getDisplayContent(mDisplayId).mAppTransition |
| 139 | .unregisterListener(this); |
| 140 | return 0; |
| 141 | } |
| 142 | }; |
| 143 | |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 144 | public interface RecentsAnimationCallbacks { |
Winson Chung | 65c5f99 | 2018-04-20 14:58:57 -0700 | [diff] [blame] | 145 | void onAnimationFinished(@ReorderMode int reorderMode, boolean runSychronously); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | private final IRecentsAnimationController mController = |
| 149 | new IRecentsAnimationController.Stub() { |
| 150 | |
| 151 | @Override |
| 152 | public TaskSnapshot screenshotTask(int taskId) { |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 153 | if (DEBUG_RECENTS_ANIMATIONS) Slog.d(TAG, "screenshotTask(" + taskId + "):" |
| 154 | + " mCanceled=" + mCanceled); |
Winson Chung | f557c3b | 2018-03-16 10:55:20 -0700 | [diff] [blame] | 155 | final long token = Binder.clearCallingIdentity(); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 156 | try { |
| 157 | synchronized (mService.getWindowManagerLock()) { |
| 158 | if (mCanceled) { |
| 159 | return null; |
| 160 | } |
| 161 | for (int i = mPendingAnimations.size() - 1; i >= 0; i--) { |
| 162 | final TaskAnimationAdapter adapter = mPendingAnimations.get(i); |
| 163 | final Task task = adapter.mTask; |
| 164 | if (task.mTaskId == taskId) { |
Winson Chung | 23aa7b1 | 2018-02-01 11:41:43 -0800 | [diff] [blame] | 165 | final TaskSnapshotController snapshotController = |
| 166 | mService.mTaskSnapshotController; |
| 167 | final ArraySet<Task> tasks = Sets.newArraySet(task); |
| 168 | snapshotController.snapshotTasks(tasks); |
| 169 | snapshotController.addSkipClosingAppSnapshotTasks(tasks); |
| 170 | return snapshotController.getSnapshot(taskId, 0 /* userId */, |
| 171 | false /* restoreFromDisk */, false /* reducedResolution */); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 172 | } |
| 173 | } |
| 174 | return null; |
| 175 | } |
| 176 | } finally { |
| 177 | Binder.restoreCallingIdentity(token); |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | @Override |
| 182 | public void finish(boolean moveHomeToTop) { |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 183 | if (DEBUG_RECENTS_ANIMATIONS) Slog.d(TAG, "finish(" + moveHomeToTop + "):" |
| 184 | + " mCanceled=" + mCanceled); |
Winson Chung | f557c3b | 2018-03-16 10:55:20 -0700 | [diff] [blame] | 185 | final long token = Binder.clearCallingIdentity(); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 186 | try { |
| 187 | synchronized (mService.getWindowManagerLock()) { |
| 188 | if (mCanceled) { |
| 189 | return; |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | // Note, the callback will handle its own synchronization, do not lock on WM lock |
| 194 | // prior to calling the callback |
Winson Chung | 6a38fca | 2018-03-28 17:57:09 -0700 | [diff] [blame] | 195 | mCallbacks.onAnimationFinished(moveHomeToTop |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 196 | ? REORDER_MOVE_TO_TOP |
Winson Chung | 65c5f99 | 2018-04-20 14:58:57 -0700 | [diff] [blame] | 197 | : REORDER_MOVE_TO_ORIGINAL_POSITION, |
| 198 | true /* runSynchronously */); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 199 | } finally { |
| 200 | Binder.restoreCallingIdentity(token); |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | @Override |
Jorim Jaggi | 50bf59c | 2018-03-09 17:29:48 +0100 | [diff] [blame] | 205 | public void setAnimationTargetsBehindSystemBars(boolean behindSystemBars) |
| 206 | throws RemoteException { |
Winson Chung | f557c3b | 2018-03-16 10:55:20 -0700 | [diff] [blame] | 207 | final long token = Binder.clearCallingIdentity(); |
Jorim Jaggi | 50bf59c | 2018-03-09 17:29:48 +0100 | [diff] [blame] | 208 | try { |
| 209 | synchronized (mService.getWindowManagerLock()) { |
| 210 | for (int i = mPendingAnimations.size() - 1; i >= 0; i--) { |
| 211 | mPendingAnimations.get(i).mTask.setCanAffectSystemUiFlags(behindSystemBars); |
| 212 | } |
| 213 | mService.mWindowPlacerLocked.requestTraversal(); |
| 214 | } |
| 215 | } finally { |
| 216 | Binder.restoreCallingIdentity(token); |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | @Override |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 221 | public void setInputConsumerEnabled(boolean enabled) { |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 222 | if (DEBUG_RECENTS_ANIMATIONS) Slog.d(TAG, "setInputConsumerEnabled(" + enabled + "):" |
| 223 | + " mCanceled=" + mCanceled); |
Winson Chung | f557c3b | 2018-03-16 10:55:20 -0700 | [diff] [blame] | 224 | final long token = Binder.clearCallingIdentity(); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 225 | try { |
| 226 | synchronized (mService.getWindowManagerLock()) { |
| 227 | if (mCanceled) { |
| 228 | return; |
| 229 | } |
| 230 | |
| 231 | mInputConsumerEnabled = enabled; |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 232 | final InputMonitor inputMonitor = |
| 233 | mService.mRoot.getDisplayContent(mDisplayId).getInputMonitor(); |
| 234 | inputMonitor.updateInputWindowsLw(true /*force*/); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 235 | mService.scheduleAnimationLocked(); |
| 236 | } |
| 237 | } finally { |
| 238 | Binder.restoreCallingIdentity(token); |
| 239 | } |
| 240 | } |
Winson Chung | f557c3b | 2018-03-16 10:55:20 -0700 | [diff] [blame] | 241 | |
| 242 | @Override |
| 243 | public void setSplitScreenMinimized(boolean minimized) { |
| 244 | final long token = Binder.clearCallingIdentity(); |
| 245 | try { |
| 246 | synchronized (mService.getWindowManagerLock()) { |
| 247 | if (mCanceled) { |
| 248 | return; |
| 249 | } |
| 250 | |
| 251 | mSplitScreenMinimized = minimized; |
| 252 | mService.checkSplitScreenMinimizedChanged(true /* animate */); |
| 253 | } |
| 254 | } finally { |
| 255 | Binder.restoreCallingIdentity(token); |
| 256 | } |
| 257 | } |
Winson Chung | a840c32 | 2018-04-20 15:58:18 -0700 | [diff] [blame] | 258 | |
| 259 | @Override |
| 260 | public void hideCurrentInputMethod() { |
| 261 | final long token = Binder.clearCallingIdentity(); |
| 262 | try { |
| 263 | final InputMethodManagerInternal inputMethodManagerInternal = |
| 264 | LocalServices.getService(InputMethodManagerInternal.class); |
| 265 | if (inputMethodManagerInternal != null) { |
| 266 | inputMethodManagerInternal.hideCurrentInputMethod(); |
| 267 | } |
| 268 | } finally { |
| 269 | Binder.restoreCallingIdentity(token); |
| 270 | } |
| 271 | } |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 272 | |
| 273 | @Override |
| 274 | public void setCancelWithDeferredScreenshot(boolean screenshot) { |
| 275 | synchronized (mLock) { |
| 276 | setCancelWithDeferredScreenshotLocked(screenshot); |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | @Override |
| 281 | public void cleanupScreenshot() { |
| 282 | synchronized (mLock) { |
| 283 | if (mRecentScreenshotAnimator != null) { |
| 284 | mRecentScreenshotAnimator.cancelAnimation(); |
| 285 | mRecentScreenshotAnimator = null; |
| 286 | } |
| 287 | } |
| 288 | } |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 289 | }; |
| 290 | |
| 291 | /** |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 292 | * @param remoteAnimationRunner The remote runner which should be notified when the animation is |
| 293 | * ready to start or has been canceled |
| 294 | * @param callbacks Callbacks to be made when the animation finishes |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 295 | */ |
| 296 | RecentsAnimationController(WindowManagerService service, |
| 297 | IRecentsAnimationRunner remoteAnimationRunner, RecentsAnimationCallbacks callbacks, |
| 298 | int displayId) { |
| 299 | mService = service; |
| 300 | mRunner = remoteAnimationRunner; |
| 301 | mCallbacks = callbacks; |
Winson Chung | ddf6297 | 2018-02-12 11:10:04 -0800 | [diff] [blame] | 302 | mDisplayId = displayId; |
| 303 | } |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 304 | |
Winson Chung | 732446a | 2018-09-19 13:15:17 -0700 | [diff] [blame] | 305 | public void initialize(int targetActivityType, SparseBooleanArray recentTaskIds) { |
| 306 | initialize(mService.mRoot.getDisplayContent(mDisplayId), targetActivityType, recentTaskIds); |
| 307 | } |
| 308 | |
Winson Chung | ddf6297 | 2018-02-12 11:10:04 -0800 | [diff] [blame] | 309 | /** |
| 310 | * Initializes the recents animation controller. This is a separate call from the constructor |
| 311 | * because it may call cancelAnimation() which needs to properly clean up the controller |
| 312 | * in the window manager. |
| 313 | */ |
Winson Chung | 732446a | 2018-09-19 13:15:17 -0700 | [diff] [blame] | 314 | @VisibleForTesting |
| 315 | void initialize(DisplayContent dc, int targetActivityType, SparseBooleanArray recentTaskIds) { |
| 316 | mTargetActivityType = targetActivityType; |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 317 | dc.mAppTransition.registerListenerLocked(mAppTransitionListener); |
Winson Chung | 732446a | 2018-09-19 13:15:17 -0700 | [diff] [blame] | 318 | |
| 319 | // Make leashes for each of the visible/target tasks and add it to the recents animation to |
| 320 | // be started |
Winson Chung | ddf6297 | 2018-02-12 11:10:04 -0800 | [diff] [blame] | 321 | final ArrayList<Task> visibleTasks = dc.getVisibleTasks(); |
Winson Chung | 732446a | 2018-09-19 13:15:17 -0700 | [diff] [blame] | 322 | final TaskStack targetStack = dc.getStack(WINDOWING_MODE_UNDEFINED, targetActivityType); |
| 323 | if (targetStack != null) { |
| 324 | for (int i = targetStack.getChildCount() - 1; i >= 0; i--) { |
| 325 | final Task t = targetStack.getChildAt(i); |
| 326 | if (!visibleTasks.contains(t)) { |
| 327 | visibleTasks.add(t); |
| 328 | } |
| 329 | } |
| 330 | } |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 331 | final int taskCount = visibleTasks.size(); |
| 332 | for (int i = 0; i < taskCount; i++) { |
| 333 | final Task task = visibleTasks.get(i); |
| 334 | final WindowConfiguration config = task.getWindowConfiguration(); |
| 335 | if (config.tasksAreFloating() |
Winson Chung | 732446a | 2018-09-19 13:15:17 -0700 | [diff] [blame] | 336 | || config.getWindowingMode() == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 337 | continue; |
| 338 | } |
Vadim Tryshev | 593e956 | 2018-03-08 17:15:45 -0800 | [diff] [blame] | 339 | addAnimation(task, !recentTaskIds.get(task.mTaskId)); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 340 | } |
| 341 | |
Winson Chung | ddf6297 | 2018-02-12 11:10:04 -0800 | [diff] [blame] | 342 | // Skip the animation if there is nothing to animate |
| 343 | if (mPendingAnimations.isEmpty()) { |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 344 | cancelAnimation(REORDER_MOVE_TO_ORIGINAL_POSITION, "initialize-noVisibleTasks"); |
Winson Chung | ddf6297 | 2018-02-12 11:10:04 -0800 | [diff] [blame] | 345 | return; |
| 346 | } |
| 347 | |
Adrian Roos | 842e788 | 2018-03-26 17:34:06 +0200 | [diff] [blame] | 348 | try { |
Adrian Roos | 653c6c1 | 2018-04-09 14:12:46 -0700 | [diff] [blame] | 349 | linkToDeathOfRunner(); |
Adrian Roos | 842e788 | 2018-03-26 17:34:06 +0200 | [diff] [blame] | 350 | } catch (RemoteException e) { |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 351 | cancelAnimation(REORDER_MOVE_TO_ORIGINAL_POSITION, "initialize-failedToLinkToDeath"); |
Adrian Roos | 842e788 | 2018-03-26 17:34:06 +0200 | [diff] [blame] | 352 | return; |
| 353 | } |
| 354 | |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 355 | // Adjust the wallpaper visibility for the showing target activity |
| 356 | final AppWindowToken recentsComponentAppToken = dc.getStack(WINDOWING_MODE_UNDEFINED, |
| 357 | targetActivityType).getTopChild().getTopFullscreenAppToken(); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 358 | if (recentsComponentAppToken != null) { |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 359 | if (DEBUG_RECENTS_ANIMATIONS) Slog.d(TAG, "setHomeApp(" |
| 360 | + recentsComponentAppToken.getName() + ")"); |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 361 | mTargetAppToken = recentsComponentAppToken; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 362 | if (recentsComponentAppToken.windowsCanBeWallpaperTarget()) { |
| 363 | dc.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER; |
| 364 | dc.setLayoutNeeded(); |
| 365 | } |
| 366 | } |
| 367 | |
Winson Chung | 584d652 | 2018-02-07 23:57:38 +0000 | [diff] [blame] | 368 | // Save the minimized home height |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 369 | final TaskStack dockedStack = dc.getSplitScreenPrimaryStackIgnoringVisibility(); |
| 370 | dc.getDockedDividerController().getHomeStackBoundsInDockedMode( |
| 371 | dc.getConfiguration(), |
| 372 | dockedStack == null ? DOCKED_INVALID : dockedStack.getDockSide(), |
| 373 | mMinimizedHomeBounds); |
Winson Chung | 584d652 | 2018-02-07 23:57:38 +0000 | [diff] [blame] | 374 | |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 375 | mService.mWindowPlacerLocked.performSurfacePlacement(); |
| 376 | } |
| 377 | |
Winson Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [diff] [blame] | 378 | @VisibleForTesting |
| 379 | AnimationAdapter addAnimation(Task task, boolean isRecentTaskInvisible) { |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 380 | if (DEBUG_RECENTS_ANIMATIONS) Slog.d(TAG, "addAnimation(" + task.getName() + ")"); |
Vadim Tryshev | 593e956 | 2018-03-08 17:15:45 -0800 | [diff] [blame] | 381 | final TaskAnimationAdapter taskAdapter = new TaskAnimationAdapter(task, |
| 382 | isRecentTaskInvisible); |
Winson Chung | 5720d8e | 2018-08-03 15:50:00 -0700 | [diff] [blame] | 383 | task.startAnimation(task.getPendingTransaction(), taskAdapter, false /* hidden */); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 384 | task.commitPendingTransaction(); |
| 385 | mPendingAnimations.add(taskAdapter); |
Winson Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [diff] [blame] | 386 | return taskAdapter; |
| 387 | } |
| 388 | |
| 389 | @VisibleForTesting |
| 390 | void removeAnimation(TaskAnimationAdapter taskAdapter) { |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 391 | if (DEBUG_RECENTS_ANIMATIONS) Slog.d(TAG, "removeAnimation(" |
| 392 | + taskAdapter.mTask.mTaskId + ")"); |
Winson Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [diff] [blame] | 393 | taskAdapter.mTask.setCanAffectSystemUiFlags(true); |
| 394 | taskAdapter.mCapturedFinishCallback.onAnimationFinished(taskAdapter); |
| 395 | mPendingAnimations.remove(taskAdapter); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | void startAnimation() { |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 399 | if (DEBUG_RECENTS_ANIMATIONS) Slog.d(TAG, "startAnimation(): mPendingStart=" + mPendingStart |
Winson Chung | ddf6297 | 2018-02-12 11:10:04 -0800 | [diff] [blame] | 400 | + " mCanceled=" + mCanceled); |
| 401 | if (!mPendingStart || mCanceled) { |
| 402 | // Skip starting if we've already started or canceled the animation |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 403 | return; |
| 404 | } |
| 405 | try { |
Winson Chung | 2dc3736 | 2018-03-12 17:57:06 -0700 | [diff] [blame] | 406 | final ArrayList<RemoteAnimationTarget> appAnimations = new ArrayList<>(); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 407 | for (int i = mPendingAnimations.size() - 1; i >= 0; i--) { |
Winson Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [diff] [blame] | 408 | final TaskAnimationAdapter taskAdapter = mPendingAnimations.get(i); |
| 409 | final RemoteAnimationTarget target = taskAdapter.createRemoteAnimationApp(); |
Winson Chung | 2dc3736 | 2018-03-12 17:57:06 -0700 | [diff] [blame] | 410 | if (target != null) { |
| 411 | appAnimations.add(target); |
Winson Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [diff] [blame] | 412 | } else { |
| 413 | removeAnimation(taskAdapter); |
Winson Chung | 2dc3736 | 2018-03-12 17:57:06 -0700 | [diff] [blame] | 414 | } |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 415 | } |
Winson Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [diff] [blame] | 416 | |
| 417 | // Skip the animation if there is nothing to animate |
| 418 | if (appAnimations.isEmpty()) { |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 419 | cancelAnimation(REORDER_MOVE_TO_ORIGINAL_POSITION, "startAnimation-noAppWindows"); |
Winson Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [diff] [blame] | 420 | return; |
| 421 | } |
| 422 | |
Winson Chung | 2dc3736 | 2018-03-12 17:57:06 -0700 | [diff] [blame] | 423 | final RemoteAnimationTarget[] appTargets = appAnimations.toArray( |
| 424 | new RemoteAnimationTarget[appAnimations.size()]); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 425 | mPendingStart = false; |
Winson Chung | 584d652 | 2018-02-07 23:57:38 +0000 | [diff] [blame] | 426 | |
Winson Chung | 9e8b0cb | 2018-08-03 16:23:52 -0700 | [diff] [blame] | 427 | // Perform layout if it was scheduled before to make sure that we get correct content |
| 428 | // insets for the target app window after a rotation |
| 429 | final DisplayContent displayContent = mService.mRoot.getDisplayContent(mDisplayId); |
| 430 | displayContent.performLayout(false /* initial */, false /* updateInputWindows */); |
| 431 | |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 432 | final Rect minimizedHomeBounds = mTargetAppToken != null |
| 433 | && mTargetAppToken.inSplitScreenSecondaryWindowingMode() |
| 434 | ? mMinimizedHomeBounds |
| 435 | : null; |
Vadim Tryshev | 257f86b | 2018-08-23 16:45:02 -0700 | [diff] [blame] | 436 | final Rect contentInsets; |
| 437 | if (mTargetAppToken != null && mTargetAppToken.findMainWindow() != null) { |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 438 | contentInsets = mTargetAppToken.findMainWindow().getContentInsets(); |
Vadim Tryshev | 257f86b | 2018-08-23 16:45:02 -0700 | [diff] [blame] | 439 | } else { |
| 440 | // If the window for the activity had not yet been created, use the display insets. |
| 441 | mService.getStableInsets(mDisplayId, mTmpRect); |
| 442 | contentInsets = mTmpRect; |
| 443 | } |
Winson Chung | 9e8b0cb | 2018-08-03 16:23:52 -0700 | [diff] [blame] | 444 | mRunner.onAnimationStart(mController, appTargets, contentInsets, minimizedHomeBounds); |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 445 | if (DEBUG_RECENTS_ANIMATIONS) { |
| 446 | Slog.d(TAG, "startAnimation(): Notify animation start:"); |
| 447 | for (int i = 0; i < mPendingAnimations.size(); i++) { |
| 448 | final Task task = mPendingAnimations.get(i).mTask; |
| 449 | Slog.d(TAG, "\t" + task.mTaskId); |
| 450 | } |
| 451 | } |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 452 | } catch (RemoteException e) { |
| 453 | Slog.e(TAG, "Failed to start recents animation", e); |
| 454 | } |
Jorim Jaggi | 54cff64 | 2018-03-15 15:51:32 +0100 | [diff] [blame] | 455 | final SparseIntArray reasons = new SparseIntArray(); |
| 456 | reasons.put(WINDOWING_MODE_FULLSCREEN, APP_TRANSITION_RECENTS_ANIM); |
Yunfan Chen | cafc706 | 2019-01-22 17:21:32 +0900 | [diff] [blame] | 457 | mService.mAtmInternal.notifyAppTransitionStarting(reasons, SystemClock.uptimeMillis()); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 458 | } |
| 459 | |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 460 | void cancelAnimation(@ReorderMode int reorderMode, String reason) { |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 461 | cancelAnimation(reorderMode, false /* runSynchronously */, false /*screenshot */, reason); |
Winson Chung | 65c5f99 | 2018-04-20 14:58:57 -0700 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | void cancelAnimationSynchronously(@ReorderMode int reorderMode, String reason) { |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 465 | cancelAnimation(reorderMode, true /* runSynchronously */, false /* screenshot */, reason); |
| 466 | } |
| 467 | |
| 468 | void cancelAnimationWithScreenShot() { |
| 469 | cancelAnimation(REORDER_KEEP_IN_PLACE, true /* sync */, true /* screenshot */, |
| 470 | "stackOrderChanged"); |
Winson Chung | 65c5f99 | 2018-04-20 14:58:57 -0700 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | private void cancelAnimation(@ReorderMode int reorderMode, boolean runSynchronously, |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 474 | boolean screenshot, String reason) { |
Winson Chung | 65c5f99 | 2018-04-20 14:58:57 -0700 | [diff] [blame] | 475 | if (DEBUG_RECENTS_ANIMATIONS) Slog.d(TAG, "cancelAnimation(): reason=" + reason |
| 476 | + " runSynchronously=" + runSynchronously); |
Winson Chung | 65fc89a | 2018-02-28 08:32:12 -0800 | [diff] [blame] | 477 | synchronized (mService.getWindowManagerLock()) { |
| 478 | if (mCanceled) { |
| 479 | // We've already canceled the animation |
| 480 | return; |
| 481 | } |
Adrian Roos | 842e788 | 2018-03-26 17:34:06 +0200 | [diff] [blame] | 482 | mService.mH.removeCallbacks(mFailsafeRunnable); |
Winson Chung | 65fc89a | 2018-02-28 08:32:12 -0800 | [diff] [blame] | 483 | mCanceled = true; |
| 484 | try { |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 485 | if (screenshot) { |
| 486 | // Screen shot previous task when next task starts transition. |
| 487 | final Task task = mPendingAnimations.get(0).mTask; |
| 488 | screenshotRecentTask(task, reorderMode, runSynchronously); |
| 489 | mRunner.onAnimationCanceled(true /* deferredWithScreenshot */); |
| 490 | return; |
| 491 | } |
| 492 | mRunner.onAnimationCanceled(false /* deferredWithScreenshot */); |
Winson Chung | 65fc89a | 2018-02-28 08:32:12 -0800 | [diff] [blame] | 493 | } catch (RemoteException e) { |
| 494 | Slog.e(TAG, "Failed to cancel recents animation", e); |
| 495 | } |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 496 | // Clean up and return to the previous app |
| 497 | mCallbacks.onAnimationFinished(reorderMode, runSynchronously); |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | /** |
| 502 | * Cancel recents animation when the next app transition starts. |
| 503 | * <p> |
| 504 | * When we cancel the recents animation due to a stack order change, we can't just cancel it |
| 505 | * immediately as it would lead to a flicker in Launcher if we just remove the task from the |
| 506 | * leash. Instead we screenshot the previous task and replace the child of the leash with the |
| 507 | * screenshot, so that Launcher can still control the leash lifecycle & make the next app |
| 508 | * transition animate smoothly without flickering. |
| 509 | */ |
| 510 | void cancelOnNextTransitionStart() { |
| 511 | mCancelOnNextTransitionStart = true; |
| 512 | } |
| 513 | |
| 514 | void setCancelWithDeferredScreenshotLocked(boolean screenshot) { |
| 515 | mCancelWithDeferredScreenshot = screenshot; |
| 516 | } |
| 517 | |
| 518 | boolean shouldCancelWithDeferredScreenshot() { |
| 519 | return mCancelWithDeferredScreenshot; |
| 520 | } |
| 521 | |
| 522 | void onTransitionStart() { |
| 523 | if (mCanceled) { |
| 524 | return; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 525 | } |
Winson Chung | f557c3b | 2018-03-16 10:55:20 -0700 | [diff] [blame] | 526 | |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 527 | if (mCancelOnNextTransitionStart) { |
| 528 | mCancelOnNextTransitionStart = false; |
| 529 | cancelAnimationWithScreenShot(); |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | void screenshotRecentTask(Task task, @ReorderMode int reorderMode, boolean runSynchronously) { |
| 534 | final TaskScreenshotAnimatable animatable = TaskScreenshotAnimatable.create(task); |
| 535 | if (animatable != null) { |
| 536 | mRecentScreenshotAnimator = new SurfaceAnimator( |
| 537 | animatable, |
| 538 | () -> { |
| 539 | if (DEBUG_RECENTS_ANIMATIONS) { |
| 540 | Slog.d(TAG, "mRecentScreenshotAnimator finish"); |
| 541 | } |
| 542 | mCallbacks.onAnimationFinished(reorderMode, runSynchronously); |
| 543 | }, mService); |
| 544 | mRecentScreenshotAnimator.transferAnimation(task.mSurfaceAnimator); |
| 545 | } |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 546 | } |
| 547 | |
Winson Chung | 6a38fca | 2018-03-28 17:57:09 -0700 | [diff] [blame] | 548 | void cleanupAnimation(@ReorderMode int reorderMode) { |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 549 | if (DEBUG_RECENTS_ANIMATIONS) Slog.d(TAG, |
| 550 | "cleanupAnimation(): Notify animation finished mPendingAnimations=" |
| 551 | + mPendingAnimations.size() + " reorderMode=" + reorderMode); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 552 | for (int i = mPendingAnimations.size() - 1; i >= 0; i--) { |
Winson Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [diff] [blame] | 553 | final TaskAnimationAdapter taskAdapter = mPendingAnimations.get(i); |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 554 | if (reorderMode == REORDER_MOVE_TO_TOP || reorderMode == REORDER_KEEP_IN_PLACE) { |
Winson Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [diff] [blame] | 555 | taskAdapter.mTask.dontAnimateDimExit(); |
chaviw | 87ca63a | 2018-03-26 14:06:17 -0700 | [diff] [blame] | 556 | } |
Winson Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [diff] [blame] | 557 | removeAnimation(taskAdapter); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 558 | } |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 559 | |
Winson Chung | 7906b3e | 2018-05-10 10:32:39 -0700 | [diff] [blame] | 560 | // Clear any pending failsafe runnables |
| 561 | mService.mH.removeCallbacks(mFailsafeRunnable); |
| 562 | |
Winson Chung | 5c91e8f | 2018-05-07 10:06:55 -0700 | [diff] [blame] | 563 | // Clear references to the runner |
Adrian Roos | 653c6c1 | 2018-04-09 14:12:46 -0700 | [diff] [blame] | 564 | unlinkToDeathOfRunner(); |
Winson Chung | 5c91e8f | 2018-05-07 10:06:55 -0700 | [diff] [blame] | 565 | mRunner = null; |
Winson Chung | 7906b3e | 2018-05-10 10:32:39 -0700 | [diff] [blame] | 566 | mCanceled = true; |
Winson Chung | 5c91e8f | 2018-05-07 10:06:55 -0700 | [diff] [blame] | 567 | |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 568 | // Make sure previous animator has cleaned-up. |
| 569 | if (mRecentScreenshotAnimator != null) { |
| 570 | mRecentScreenshotAnimator.cancelAnimation(); |
| 571 | mRecentScreenshotAnimator = null; |
| 572 | } |
| 573 | |
Winson Chung | db111ee | 2018-10-03 14:25:34 -0700 | [diff] [blame] | 574 | // Update the input windows after the animation is complete |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 575 | final InputMonitor inputMonitor = |
| 576 | mService.mRoot.getDisplayContent(mDisplayId).getInputMonitor(); |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 577 | inputMonitor.updateInputWindowsLw(true /*force*/); |
Winson Chung | 0bb66cc | 2018-04-10 11:58:15 -0700 | [diff] [blame] | 578 | |
| 579 | // We have deferred all notifications to the target app as a part of the recents animation, |
| 580 | // so if we are actually transitioning there, notify again here |
| 581 | if (mTargetAppToken != null) { |
| 582 | if (reorderMode == REORDER_MOVE_TO_TOP || reorderMode == REORDER_KEEP_IN_PLACE) { |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 583 | mService.mRoot.getDisplayContent(mDisplayId) |
| 584 | .mAppTransition.notifyAppTransitionFinishedLocked(mTargetAppToken.token); |
Winson Chung | 0bb66cc | 2018-04-10 11:58:15 -0700 | [diff] [blame] | 585 | } |
| 586 | } |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 587 | } |
| 588 | |
Adrian Roos | 842e788 | 2018-03-26 17:34:06 +0200 | [diff] [blame] | 589 | void scheduleFailsafe() { |
| 590 | mService.mH.postDelayed(mFailsafeRunnable, FAILSAFE_DELAY); |
| 591 | } |
| 592 | |
Adrian Roos | 653c6c1 | 2018-04-09 14:12:46 -0700 | [diff] [blame] | 593 | private void linkToDeathOfRunner() throws RemoteException { |
| 594 | if (!mLinkedToDeathOfRunner) { |
| 595 | mRunner.asBinder().linkToDeath(this, 0); |
| 596 | mLinkedToDeathOfRunner = true; |
| 597 | } |
| 598 | } |
| 599 | |
| 600 | private void unlinkToDeathOfRunner() { |
| 601 | if (mLinkedToDeathOfRunner) { |
| 602 | mRunner.asBinder().unlinkToDeath(this, 0); |
| 603 | mLinkedToDeathOfRunner = false; |
| 604 | } |
| 605 | } |
| 606 | |
Adrian Roos | 842e788 | 2018-03-26 17:34:06 +0200 | [diff] [blame] | 607 | @Override |
| 608 | public void binderDied() { |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 609 | cancelAnimation(REORDER_MOVE_TO_ORIGINAL_POSITION, "binderDied"); |
Winson Chung | db111ee | 2018-10-03 14:25:34 -0700 | [diff] [blame] | 610 | |
Arthur Hung | 1b636fa | 2018-12-04 15:53:49 +0800 | [diff] [blame] | 611 | synchronized (mService.getWindowManagerLock()) { |
| 612 | // Clear associated input consumers on runner death |
| 613 | final InputMonitor inputMonitor = |
| 614 | mService.mRoot.getDisplayContent(mDisplayId).getInputMonitor(); |
| 615 | inputMonitor.destroyInputConsumer(INPUT_CONSUMER_RECENTS_ANIMATION); |
| 616 | } |
Adrian Roos | 842e788 | 2018-03-26 17:34:06 +0200 | [diff] [blame] | 617 | } |
| 618 | |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 619 | void checkAnimationReady(WallpaperController wallpaperController) { |
| 620 | if (mPendingStart) { |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 621 | final boolean wallpaperReady = !isTargetOverWallpaper() |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 622 | || (wallpaperController.getWallpaperTarget() != null |
| 623 | && wallpaperController.wallpaperTransitionReady()); |
| 624 | if (wallpaperReady) { |
| 625 | mService.getRecentsAnimationController().startAnimation(); |
| 626 | } |
| 627 | } |
| 628 | } |
| 629 | |
Winson Chung | f557c3b | 2018-03-16 10:55:20 -0700 | [diff] [blame] | 630 | boolean isSplitScreenMinimized() { |
| 631 | return mSplitScreenMinimized; |
| 632 | } |
| 633 | |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 634 | boolean isWallpaperVisible(WindowState w) { |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 635 | return w != null && w.mAppToken != null && mTargetAppToken == w.mAppToken |
| 636 | && isTargetOverWallpaper(); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 637 | } |
| 638 | |
Winson Chung | db111ee | 2018-10-03 14:25:34 -0700 | [diff] [blame] | 639 | /** |
| 640 | * @return Whether to use the input consumer to override app input to route home/recents. |
| 641 | */ |
| 642 | boolean shouldApplyInputConsumer(AppWindowToken appToken) { |
| 643 | // Only apply the input consumer if it is enabled, it is not the target (home/recents) |
| 644 | // being revealed with the transition, and we are actively animating the app as a part of |
| 645 | // the animation |
| 646 | return mInputConsumerEnabled && mTargetAppToken != appToken && isAnimatingApp(appToken); |
Winson Chung | a89ffed | 2018-01-25 17:46:11 +0000 | [diff] [blame] | 647 | } |
| 648 | |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 649 | boolean updateInputConsumerForApp(InputWindowHandle inputWindowHandle, |
Winson Chung | a89ffed | 2018-01-25 17:46:11 +0000 | [diff] [blame] | 650 | boolean hasFocus) { |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 651 | // Update the input consumer touchable region to match the target app main window |
| 652 | final WindowState targetAppMainWindow = mTargetAppToken != null |
| 653 | ? mTargetAppToken.findMainWindow() |
Winson Chung | a89ffed | 2018-01-25 17:46:11 +0000 | [diff] [blame] | 654 | : null; |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 655 | if (targetAppMainWindow != null) { |
| 656 | targetAppMainWindow.getBounds(mTmpRect); |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 657 | inputWindowHandle.hasFocus = hasFocus; |
| 658 | inputWindowHandle.touchableRegion.set(mTmpRect); |
Winson Chung | a89ffed | 2018-01-25 17:46:11 +0000 | [diff] [blame] | 659 | return true; |
| 660 | } |
| 661 | return false; |
| 662 | } |
| 663 | |
Winson Chung | 0bb66cc | 2018-04-10 11:58:15 -0700 | [diff] [blame] | 664 | boolean isTargetApp(AppWindowToken token) { |
| 665 | return mTargetAppToken != null && token == mTargetAppToken; |
| 666 | } |
| 667 | |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 668 | private boolean isTargetOverWallpaper() { |
| 669 | if (mTargetAppToken == null) { |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 670 | return false; |
| 671 | } |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 672 | return mTargetAppToken.windowsCanBeWallpaperTarget(); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 673 | } |
| 674 | |
Winson Chung | d41f71d | 2018-03-16 15:26:07 -0700 | [diff] [blame] | 675 | boolean isAnimatingTask(Task task) { |
| 676 | for (int i = mPendingAnimations.size() - 1; i >= 0; i--) { |
| 677 | if (task == mPendingAnimations.get(i).mTask) { |
| 678 | return true; |
| 679 | } |
| 680 | } |
| 681 | return false; |
| 682 | } |
| 683 | |
Winson Chung | a89ffed | 2018-01-25 17:46:11 +0000 | [diff] [blame] | 684 | private boolean isAnimatingApp(AppWindowToken appToken) { |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 685 | for (int i = mPendingAnimations.size() - 1; i >= 0; i--) { |
| 686 | final Task task = mPendingAnimations.get(i).mTask; |
| 687 | for (int j = task.getChildCount() - 1; j >= 0; j--) { |
| 688 | final AppWindowToken app = task.getChildAt(j); |
| 689 | if (app == appToken) { |
| 690 | return true; |
| 691 | } |
| 692 | } |
| 693 | } |
| 694 | return false; |
| 695 | } |
| 696 | |
Winson Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [diff] [blame] | 697 | @VisibleForTesting |
| 698 | class TaskAnimationAdapter implements AnimationAdapter { |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 699 | |
Vadim Tryshev | 593e956 | 2018-03-08 17:15:45 -0800 | [diff] [blame] | 700 | private final Task mTask; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 701 | private SurfaceControl mCapturedLeash; |
| 702 | private OnAnimationFinishedCallback mCapturedFinishCallback; |
Vadim Tryshev | 593e956 | 2018-03-08 17:15:45 -0800 | [diff] [blame] | 703 | private final boolean mIsRecentTaskInvisible; |
Jorim Jaggi | f75d161 | 2018-02-27 15:05:21 +0100 | [diff] [blame] | 704 | private RemoteAnimationTarget mTarget; |
Winson Chung | d41f71d | 2018-03-16 15:26:07 -0700 | [diff] [blame] | 705 | private final Point mPosition = new Point(); |
| 706 | private final Rect mBounds = new Rect(); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 707 | |
Vadim Tryshev | 593e956 | 2018-03-08 17:15:45 -0800 | [diff] [blame] | 708 | TaskAnimationAdapter(Task task, boolean isRecentTaskInvisible) { |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 709 | mTask = task; |
Vadim Tryshev | 593e956 | 2018-03-08 17:15:45 -0800 | [diff] [blame] | 710 | mIsRecentTaskInvisible = isRecentTaskInvisible; |
Winson Chung | d41f71d | 2018-03-16 15:26:07 -0700 | [diff] [blame] | 711 | final WindowContainer container = mTask.getParent(); |
Evan Rosky | ed6767f | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 712 | container.getRelativeDisplayedPosition(mPosition); |
| 713 | mBounds.set(container.getDisplayedBounds()); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | RemoteAnimationTarget createRemoteAnimationApp() { |
Winson Chung | 173020c | 2018-05-04 15:36:47 -0700 | [diff] [blame] | 717 | final AppWindowToken topApp = mTask.getTopVisibleAppToken(); |
| 718 | final WindowState mainWindow = topApp != null |
| 719 | ? topApp.findMainWindow() |
| 720 | : null; |
Winson Chung | 2dc3736 | 2018-03-12 17:57:06 -0700 | [diff] [blame] | 721 | if (mainWindow == null) { |
| 722 | return null; |
| 723 | } |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 724 | final Rect insets = new Rect(); |
| 725 | mainWindow.getContentInsets(insets); |
Jorim Jaggi | 817ebdd | 2018-03-26 15:46:01 +0200 | [diff] [blame] | 726 | InsetUtils.addInsets(insets, mainWindow.mAppToken.getLetterboxInsets()); |
Winson Chung | 732446a | 2018-09-19 13:15:17 -0700 | [diff] [blame] | 727 | final int mode = topApp.getActivityType() == mTargetActivityType |
| 728 | ? MODE_OPENING |
| 729 | : MODE_CLOSING; |
| 730 | mTarget = new RemoteAnimationTarget(mTask.mTaskId, mode, mCapturedLeash, |
Winson Chung | 173020c | 2018-05-04 15:36:47 -0700 | [diff] [blame] | 731 | !topApp.fillsParent(), mainWindow.mWinAnimator.mLastClipRect, |
Winson Chung | d41f71d | 2018-03-16 15:26:07 -0700 | [diff] [blame] | 732 | insets, mTask.getPrefixOrderIndex(), mPosition, mBounds, |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 733 | mTask.getWindowConfiguration(), mIsRecentTaskInvisible, null, null); |
Jorim Jaggi | f75d161 | 2018-02-27 15:05:21 +0100 | [diff] [blame] | 734 | return mTarget; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | @Override |
Jorim Jaggi | 82c1786 | 2018-02-21 17:50:18 +0100 | [diff] [blame] | 738 | public boolean getShowWallpaper() { |
| 739 | return false; |
| 740 | } |
| 741 | |
| 742 | @Override |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 743 | public int getBackgroundColor() { |
| 744 | return 0; |
| 745 | } |
| 746 | |
| 747 | @Override |
| 748 | public void startAnimation(SurfaceControl animationLeash, Transaction t, |
| 749 | OnAnimationFinishedCallback finishCallback) { |
Winson Chung | 65a0586 | 2018-04-12 17:14:50 -0700 | [diff] [blame] | 750 | // Restore z-layering, position and stack crop until client has a chance to modify it. |
| 751 | t.setLayer(animationLeash, mTask.getPrefixOrderIndex()); |
Winson Chung | d41f71d | 2018-03-16 15:26:07 -0700 | [diff] [blame] | 752 | t.setPosition(animationLeash, mPosition.x, mPosition.y); |
Winson Chung | 65a0586 | 2018-04-12 17:14:50 -0700 | [diff] [blame] | 753 | mTmpRect.set(mBounds); |
| 754 | mTmpRect.offsetTo(0, 0); |
| 755 | t.setWindowCrop(animationLeash, mTmpRect); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 756 | mCapturedLeash = animationLeash; |
| 757 | mCapturedFinishCallback = finishCallback; |
| 758 | } |
| 759 | |
| 760 | @Override |
| 761 | public void onAnimationCancelled(SurfaceControl animationLeash) { |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 762 | cancelAnimation(REORDER_MOVE_TO_ORIGINAL_POSITION, "taskAnimationAdapterCanceled"); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 763 | } |
| 764 | |
| 765 | @Override |
| 766 | public long getDurationHint() { |
| 767 | return 0; |
| 768 | } |
| 769 | |
| 770 | @Override |
| 771 | public long getStatusBarTransitionsStartTime() { |
| 772 | return SystemClock.uptimeMillis(); |
| 773 | } |
Jorim Jaggi | f75d161 | 2018-02-27 15:05:21 +0100 | [diff] [blame] | 774 | |
| 775 | @Override |
| 776 | public void dump(PrintWriter pw, String prefix) { |
| 777 | pw.print(prefix); pw.println("task=" + mTask); |
| 778 | if (mTarget != null) { |
| 779 | pw.print(prefix); pw.println("Target:"); |
| 780 | mTarget.dump(pw, prefix + " "); |
| 781 | } else { |
| 782 | pw.print(prefix); pw.println("Target: null"); |
| 783 | } |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 784 | pw.println("mIsRecentTaskInvisible=" + mIsRecentTaskInvisible); |
| 785 | pw.println("mPosition=" + mPosition); |
| 786 | pw.println("mBounds=" + mBounds); |
| 787 | pw.println("mIsRecentTaskInvisible=" + mIsRecentTaskInvisible); |
Jorim Jaggi | f75d161 | 2018-02-27 15:05:21 +0100 | [diff] [blame] | 788 | } |
| 789 | |
| 790 | @Override |
| 791 | public void writeToProto(ProtoOutputStream proto) { |
| 792 | final long token = proto.start(REMOTE); |
| 793 | if (mTarget != null) { |
| 794 | mTarget.writeToProto(proto, TARGET); |
| 795 | } |
| 796 | proto.end(token); |
| 797 | } |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 798 | } |
| 799 | |
| 800 | public void dump(PrintWriter pw, String prefix) { |
| 801 | final String innerPrefix = prefix + " "; |
| 802 | pw.print(prefix); pw.println(RecentsAnimationController.class.getSimpleName() + ":"); |
| 803 | pw.print(innerPrefix); pw.println("mPendingStart=" + mPendingStart); |
Winson Chung | db111ee | 2018-10-03 14:25:34 -0700 | [diff] [blame] | 804 | pw.print(innerPrefix); pw.println("mPendingAnimations=" + mPendingAnimations.size()); |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 805 | pw.print(innerPrefix); pw.println("mCanceled=" + mCanceled); |
| 806 | pw.print(innerPrefix); pw.println("mInputConsumerEnabled=" + mInputConsumerEnabled); |
| 807 | pw.print(innerPrefix); pw.println("mSplitScreenMinimized=" + mSplitScreenMinimized); |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 808 | pw.print(innerPrefix); pw.println("mTargetAppToken=" + mTargetAppToken); |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 809 | pw.print(innerPrefix); pw.println("isTargetOverWallpaper=" + isTargetOverWallpaper()); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 810 | } |
| 811 | } |