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