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