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