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