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