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