blob: 29077f97ccdc6b0f6159160aa2a52fdb5e016f31 [file] [log] [blame]
Winson Chunge2d72172018-01-25 17:46:20 +00001/*
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
17package com.android.server.wm;
18
Jorim Jaggi54cff642018-03-15 15:51:32 +010019import static android.app.ActivityManagerInternal.APP_TRANSITION_RECENTS_ANIM;
Winson Chunge2d72172018-01-25 17:46:20 +000020import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME;
Jorim Jaggi54cff642018-03-15 15:51:32 +010021import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
Winson Chunge2d72172018-01-25 17:46:20 +000022import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY;
23import static android.view.RemoteAnimationTarget.MODE_CLOSING;
Winson Chunga89ffed2018-01-25 17:46:11 +000024import static android.view.WindowManager.INPUT_CONSUMER_RECENTS_ANIMATION;
Winson Chunge2d72172018-01-25 17:46:20 +000025import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
26import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
27import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Jorim Jaggi54cff642018-03-15 15:51:32 +010028import static com.android.server.wm.WindowManagerService.H.NOTIFY_APP_TRANSITION_STARTING;
Yi Jin6c6e9ca2018-03-20 16:53:35 -070029import static com.android.server.wm.RemoteAnimationAdapterWrapperProto.TARGET;
30import static com.android.server.wm.AnimationAdapterProto.REMOTE;
Winson Chunge2d72172018-01-25 17:46:20 +000031
Winson Chung6a38fca2018-03-28 17:57:09 -070032import android.annotation.IntDef;
Winson Chunge2d72172018-01-25 17:46:20 +000033import android.app.ActivityManager.TaskSnapshot;
34import android.app.WindowConfiguration;
Winson Chunge2d72172018-01-25 17:46:20 +000035import android.graphics.Point;
36import android.graphics.Rect;
37import android.os.Binder;
Adrian Roos842e7882018-03-26 17:34:06 +020038import android.os.IBinder.DeathRecipient;
Winson Chunge2d72172018-01-25 17:46:20 +000039import android.os.RemoteException;
40import android.os.SystemClock;
Winson Chung23aa7b12018-02-01 11:41:43 -080041import android.util.ArraySet;
Winson Chunge2d72172018-01-25 17:46:20 +000042import android.util.Log;
Jorim Jaggif75d1612018-02-27 15:05:21 +010043import android.util.Slog;import android.util.proto.ProtoOutputStream;
Vadim Tryshev593e9562018-03-08 17:15:45 -080044import android.util.SparseBooleanArray;
Jorim Jaggi54cff642018-03-15 15:51:32 +010045import android.util.SparseIntArray;
Winson Chunge2d72172018-01-25 17:46:20 +000046import android.view.IRecentsAnimationController;
47import android.view.IRecentsAnimationRunner;
48import android.view.RemoteAnimationTarget;
49import android.view.SurfaceControl;
50import android.view.SurfaceControl.Transaction;
Jorim Jaggif75d1612018-02-27 15:05:21 +010051
Winson Chung23aa7b12018-02-01 11:41:43 -080052import com.google.android.collect.Sets;
Jorim Jaggif75d1612018-02-27 15:05:21 +010053
54import com.android.server.wm.SurfaceAnimator.OnAnimationFinishedCallback;
Jorim Jaggi817ebdd2018-03-26 15:46:01 +020055import com.android.server.wm.utils.InsetUtils;
Jorim Jaggif75d1612018-02-27 15:05:21 +010056
Winson Chunge2d72172018-01-25 17:46:20 +000057import java.io.PrintWriter;
58import java.util.ArrayList;
Winson Chunge2d72172018-01-25 17:46:20 +000059/**
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 Roos842e7882018-03-26 17:34:06 +020066public class RecentsAnimationController implements DeathRecipient {
Winson Chunge2d72172018-01-25 17:46:20 +000067 private static final String TAG = TAG_WITH_CLASS_NAME ? "RecentsAnimationController" : TAG_WM;
68 private static final boolean DEBUG = false;
Adrian Roos842e7882018-03-26 17:34:06 +020069 private static final long FAILSAFE_DELAY = 1000;
Winson Chunge2d72172018-01-25 17:46:20 +000070
Winson Chung6a38fca2018-03-28 17:57:09 -070071 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 Chunge2d72172018-01-25 17:46:20 +000082 private final WindowManagerService mService;
83 private final IRecentsAnimationRunner mRunner;
84 private final RecentsAnimationCallbacks mCallbacks;
85 private final ArrayList<TaskAnimationAdapter> mPendingAnimations = new ArrayList<>();
Winson Chungddf62972018-02-12 11:10:04 -080086 private final int mDisplayId;
Winson Chung6a38fca2018-03-28 17:57:09 -070087 private final Runnable mFailsafeRunnable = () -> {
88 cancelAnimation(REORDER_MOVE_HOME_TO_ORIGINAL_POSITION);
89 };
Winson Chunge2d72172018-01-25 17:46:20 +000090
91 // The recents component app token that is shown behind the visibile tasks
92 private AppWindowToken mHomeAppToken;
Winson Chung584d6522018-02-07 23:57:38 +000093 private Rect mMinimizedHomeBounds = new Rect();
Winson Chunge2d72172018-01-25 17:46:20 +000094
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
101 private boolean mCanceled = false;
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 Chunga89ffed2018-01-25 17:46:11 +0000107 private Rect mTmpRect = new Rect();
108
Winson Chunge2d72172018-01-25 17:46:20 +0000109 public interface RecentsAnimationCallbacks {
Winson Chung6a38fca2018-03-28 17:57:09 -0700110 void onAnimationFinished(@ReorderMode int reorderMode);
Winson Chunge2d72172018-01-25 17:46:20 +0000111 }
112
113 private final IRecentsAnimationController mController =
114 new IRecentsAnimationController.Stub() {
115
116 @Override
117 public TaskSnapshot screenshotTask(int taskId) {
118 if (DEBUG) Log.d(TAG, "screenshotTask(" + taskId + "): mCanceled=" + mCanceled);
119 long token = Binder.clearCallingIdentity();
120 try {
121 synchronized (mService.getWindowManagerLock()) {
122 if (mCanceled) {
123 return null;
124 }
125 for (int i = mPendingAnimations.size() - 1; i >= 0; i--) {
126 final TaskAnimationAdapter adapter = mPendingAnimations.get(i);
127 final Task task = adapter.mTask;
128 if (task.mTaskId == taskId) {
Winson Chung23aa7b12018-02-01 11:41:43 -0800129 final TaskSnapshotController snapshotController =
130 mService.mTaskSnapshotController;
131 final ArraySet<Task> tasks = Sets.newArraySet(task);
132 snapshotController.snapshotTasks(tasks);
133 snapshotController.addSkipClosingAppSnapshotTasks(tasks);
134 return snapshotController.getSnapshot(taskId, 0 /* userId */,
135 false /* restoreFromDisk */, false /* reducedResolution */);
Winson Chunge2d72172018-01-25 17:46:20 +0000136 }
137 }
138 return null;
139 }
140 } finally {
141 Binder.restoreCallingIdentity(token);
142 }
143 }
144
145 @Override
146 public void finish(boolean moveHomeToTop) {
147 if (DEBUG) Log.d(TAG, "finish(" + moveHomeToTop + "): mCanceled=" + mCanceled);
148 long token = Binder.clearCallingIdentity();
149 try {
150 synchronized (mService.getWindowManagerLock()) {
151 if (mCanceled) {
152 return;
153 }
154 }
155
156 // Note, the callback will handle its own synchronization, do not lock on WM lock
157 // prior to calling the callback
Winson Chung6a38fca2018-03-28 17:57:09 -0700158 mCallbacks.onAnimationFinished(moveHomeToTop
159 ? REORDER_MOVE_HOME_TO_TOP
160 : REORDER_MOVE_HOME_TO_ORIGINAL_POSITION);
Winson Chunge2d72172018-01-25 17:46:20 +0000161 } finally {
162 Binder.restoreCallingIdentity(token);
163 }
164 }
165
166 @Override
Jorim Jaggi50bf59c2018-03-09 17:29:48 +0100167 public void setAnimationTargetsBehindSystemBars(boolean behindSystemBars)
168 throws RemoteException {
169 long token = Binder.clearCallingIdentity();
170 try {
171 synchronized (mService.getWindowManagerLock()) {
172 for (int i = mPendingAnimations.size() - 1; i >= 0; i--) {
173 mPendingAnimations.get(i).mTask.setCanAffectSystemUiFlags(behindSystemBars);
174 }
175 mService.mWindowPlacerLocked.requestTraversal();
176 }
177 } finally {
178 Binder.restoreCallingIdentity(token);
179 }
180 }
181
182 @Override
Winson Chunge2d72172018-01-25 17:46:20 +0000183 public void setInputConsumerEnabled(boolean enabled) {
184 if (DEBUG) Log.d(TAG, "setInputConsumerEnabled(" + enabled + "): mCanceled="
185 + mCanceled);
186 long token = Binder.clearCallingIdentity();
187 try {
188 synchronized (mService.getWindowManagerLock()) {
189 if (mCanceled) {
190 return;
191 }
192
193 mInputConsumerEnabled = enabled;
194 mService.mInputMonitor.updateInputWindowsLw(true /*force*/);
195 mService.scheduleAnimationLocked();
196 }
197 } finally {
198 Binder.restoreCallingIdentity(token);
199 }
200 }
201 };
202
203 /**
Winson Chunge2d72172018-01-25 17:46:20 +0000204 * @param remoteAnimationRunner The remote runner which should be notified when the animation is
205 * ready to start or has been canceled
206 * @param callbacks Callbacks to be made when the animation finishes
Winson Chunge2d72172018-01-25 17:46:20 +0000207 */
208 RecentsAnimationController(WindowManagerService service,
209 IRecentsAnimationRunner remoteAnimationRunner, RecentsAnimationCallbacks callbacks,
210 int displayId) {
211 mService = service;
212 mRunner = remoteAnimationRunner;
213 mCallbacks = callbacks;
Winson Chungddf62972018-02-12 11:10:04 -0800214 mDisplayId = displayId;
215 }
Winson Chunge2d72172018-01-25 17:46:20 +0000216
Winson Chungddf62972018-02-12 11:10:04 -0800217 /**
218 * Initializes the recents animation controller. This is a separate call from the constructor
219 * because it may call cancelAnimation() which needs to properly clean up the controller
220 * in the window manager.
221 */
Vadim Tryshev593e9562018-03-08 17:15:45 -0800222 public void initialize(SparseBooleanArray recentTaskIds) {
Winson Chunge2d72172018-01-25 17:46:20 +0000223 // Make leashes for each of the visible tasks and add it to the recents animation to be
224 // started
Winson Chungddf62972018-02-12 11:10:04 -0800225 final DisplayContent dc = mService.mRoot.getDisplayContent(mDisplayId);
226 final ArrayList<Task> visibleTasks = dc.getVisibleTasks();
Winson Chunge2d72172018-01-25 17:46:20 +0000227 final int taskCount = visibleTasks.size();
228 for (int i = 0; i < taskCount; i++) {
229 final Task task = visibleTasks.get(i);
230 final WindowConfiguration config = task.getWindowConfiguration();
231 if (config.tasksAreFloating()
232 || config.getWindowingMode() == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY
233 || config.getActivityType() == ACTIVITY_TYPE_HOME) {
234 continue;
235 }
Vadim Tryshev593e9562018-03-08 17:15:45 -0800236 addAnimation(task, !recentTaskIds.get(task.mTaskId));
Winson Chunge2d72172018-01-25 17:46:20 +0000237 }
238
Winson Chungddf62972018-02-12 11:10:04 -0800239 // Skip the animation if there is nothing to animate
240 if (mPendingAnimations.isEmpty()) {
Winson Chung6a38fca2018-03-28 17:57:09 -0700241 cancelAnimation(REORDER_MOVE_HOME_TO_ORIGINAL_POSITION);
Winson Chungddf62972018-02-12 11:10:04 -0800242 return;
243 }
244
Adrian Roos842e7882018-03-26 17:34:06 +0200245 try {
246 mRunner.asBinder().linkToDeath(this, 0);
247 } catch (RemoteException e) {
Winson Chung6a38fca2018-03-28 17:57:09 -0700248 cancelAnimation(REORDER_MOVE_HOME_TO_ORIGINAL_POSITION);
Adrian Roos842e7882018-03-26 17:34:06 +0200249 return;
250 }
251
Winson Chunge2d72172018-01-25 17:46:20 +0000252 // Adjust the wallpaper visibility for the showing home activity
253 final AppWindowToken recentsComponentAppToken =
254 dc.getHomeStack().getTopChild().getTopFullscreenAppToken();
255 if (recentsComponentAppToken != null) {
256 if (DEBUG) Log.d(TAG, "setHomeApp(" + recentsComponentAppToken.getName() + ")");
257 mHomeAppToken = recentsComponentAppToken;
Winson Chunge2d72172018-01-25 17:46:20 +0000258 if (recentsComponentAppToken.windowsCanBeWallpaperTarget()) {
259 dc.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
260 dc.setLayoutNeeded();
261 }
262 }
263
Winson Chung584d6522018-02-07 23:57:38 +0000264 // Save the minimized home height
265 dc.getDockedDividerController().getHomeStackBoundsInDockedMode(mMinimizedHomeBounds);
266
Winson Chunge2d72172018-01-25 17:46:20 +0000267 mService.mWindowPlacerLocked.performSurfacePlacement();
268 }
269
Vadim Tryshev593e9562018-03-08 17:15:45 -0800270 private void addAnimation(Task task, boolean isRecentTaskInvisible) {
Winson Chunge2d72172018-01-25 17:46:20 +0000271 if (DEBUG) Log.d(TAG, "addAnimation(" + task.getName() + ")");
272 final SurfaceAnimator anim = new SurfaceAnimator(task, null /* animationFinishedCallback */,
Chavi Weingartenb736e322018-02-23 00:27:54 +0000273 mService);
Vadim Tryshev593e9562018-03-08 17:15:45 -0800274 final TaskAnimationAdapter taskAdapter = new TaskAnimationAdapter(task,
275 isRecentTaskInvisible);
Winson Chunge2d72172018-01-25 17:46:20 +0000276 anim.startAnimation(task.getPendingTransaction(), taskAdapter, false /* hidden */);
277 task.commitPendingTransaction();
278 mPendingAnimations.add(taskAdapter);
279 }
280
281 void startAnimation() {
Winson Chungddf62972018-02-12 11:10:04 -0800282 if (DEBUG) Log.d(TAG, "startAnimation(): mPendingStart=" + mPendingStart
283 + " mCanceled=" + mCanceled);
284 if (!mPendingStart || mCanceled) {
285 // Skip starting if we've already started or canceled the animation
Winson Chunge2d72172018-01-25 17:46:20 +0000286 return;
287 }
288 try {
Winson Chung2dc37362018-03-12 17:57:06 -0700289 final ArrayList<RemoteAnimationTarget> appAnimations = new ArrayList<>();
Winson Chunge2d72172018-01-25 17:46:20 +0000290 for (int i = mPendingAnimations.size() - 1; i >= 0; i--) {
Winson Chung2dc37362018-03-12 17:57:06 -0700291 final RemoteAnimationTarget target =
292 mPendingAnimations.get(i).createRemoteAnimationApp();
293 if (target != null) {
294 appAnimations.add(target);
295 }
Winson Chunge2d72172018-01-25 17:46:20 +0000296 }
Winson Chung2dc37362018-03-12 17:57:06 -0700297 final RemoteAnimationTarget[] appTargets = appAnimations.toArray(
298 new RemoteAnimationTarget[appAnimations.size()]);
Winson Chunge2d72172018-01-25 17:46:20 +0000299 mPendingStart = false;
Winson Chung584d6522018-02-07 23:57:38 +0000300
301 final Rect minimizedHomeBounds =
302 mHomeAppToken != null && mHomeAppToken.inSplitScreenSecondaryWindowingMode()
303 ? mMinimizedHomeBounds : null;
304 final Rect contentInsets =
305 mHomeAppToken != null && mHomeAppToken.findMainWindow() != null
306 ? mHomeAppToken.findMainWindow().mContentInsets : null;
Winson Chung2dc37362018-03-12 17:57:06 -0700307 mRunner.onAnimationStart_New(mController, appTargets, contentInsets,
Winson Chung584d6522018-02-07 23:57:38 +0000308 minimizedHomeBounds);
Winson Chunge2d72172018-01-25 17:46:20 +0000309 } catch (RemoteException e) {
310 Slog.e(TAG, "Failed to start recents animation", e);
311 }
Jorim Jaggi54cff642018-03-15 15:51:32 +0100312 final SparseIntArray reasons = new SparseIntArray();
313 reasons.put(WINDOWING_MODE_FULLSCREEN, APP_TRANSITION_RECENTS_ANIM);
314 mService.mH.obtainMessage(NOTIFY_APP_TRANSITION_STARTING,
315 reasons).sendToTarget();
Winson Chunge2d72172018-01-25 17:46:20 +0000316 }
317
Winson Chung6a38fca2018-03-28 17:57:09 -0700318 void cancelAnimation(@ReorderMode int reorderMode) {
Winson Chunge2d72172018-01-25 17:46:20 +0000319 if (DEBUG) Log.d(TAG, "cancelAnimation()");
Winson Chung65fc89a2018-02-28 08:32:12 -0800320 synchronized (mService.getWindowManagerLock()) {
321 if (mCanceled) {
322 // We've already canceled the animation
323 return;
324 }
Adrian Roos842e7882018-03-26 17:34:06 +0200325 mService.mH.removeCallbacks(mFailsafeRunnable);
Winson Chung65fc89a2018-02-28 08:32:12 -0800326 mCanceled = true;
327 try {
328 mRunner.onAnimationCanceled();
329 } catch (RemoteException e) {
330 Slog.e(TAG, "Failed to cancel recents animation", e);
331 }
Winson Chunge2d72172018-01-25 17:46:20 +0000332 }
Winson Chunge2d72172018-01-25 17:46:20 +0000333 // Clean up and return to the previous app
Winson Chung65fc89a2018-02-28 08:32:12 -0800334 // Don't hold the WM lock here as it calls back to AM/RecentsAnimation
Winson Chung6a38fca2018-03-28 17:57:09 -0700335 mCallbacks.onAnimationFinished(reorderMode);
Winson Chunge2d72172018-01-25 17:46:20 +0000336 }
337
Winson Chung6a38fca2018-03-28 17:57:09 -0700338 void cleanupAnimation(@ReorderMode int reorderMode) {
Winson Chunge2d72172018-01-25 17:46:20 +0000339 if (DEBUG) Log.d(TAG, "cleanupAnimation(): mPendingAnimations="
340 + mPendingAnimations.size());
341 for (int i = mPendingAnimations.size() - 1; i >= 0; i--) {
342 final TaskAnimationAdapter adapter = mPendingAnimations.get(i);
Jorim Jaggi50bf59c2018-03-09 17:29:48 +0100343 adapter.mTask.setCanAffectSystemUiFlags(true);
Winson Chung6a38fca2018-03-28 17:57:09 -0700344 if (reorderMode == REORDER_MOVE_HOME_TO_TOP
345 || reorderMode == REORDER_KEEP_HOME_IN_PLACE) {
chaviw87ca63a2018-03-26 14:06:17 -0700346 adapter.mTask.dontAnimateDimExit();
347 }
Winson Chunge2d72172018-01-25 17:46:20 +0000348 adapter.mCapturedFinishCallback.onAnimationFinished(adapter);
349 }
350 mPendingAnimations.clear();
351
Adrian Roos842e7882018-03-26 17:34:06 +0200352 mRunner.asBinder().unlinkToDeath(this, 0);
353
Winson Chunge2d72172018-01-25 17:46:20 +0000354 mService.mInputMonitor.updateInputWindowsLw(true /*force*/);
Winson Chunga89ffed2018-01-25 17:46:11 +0000355 mService.destroyInputConsumer(INPUT_CONSUMER_RECENTS_ANIMATION);
Winson Chunge2d72172018-01-25 17:46:20 +0000356 }
357
Adrian Roos842e7882018-03-26 17:34:06 +0200358 void scheduleFailsafe() {
359 mService.mH.postDelayed(mFailsafeRunnable, FAILSAFE_DELAY);
360 }
361
362 @Override
363 public void binderDied() {
Winson Chung6a38fca2018-03-28 17:57:09 -0700364 cancelAnimation(REORDER_MOVE_HOME_TO_ORIGINAL_POSITION);
Adrian Roos842e7882018-03-26 17:34:06 +0200365 }
366
Winson Chunge2d72172018-01-25 17:46:20 +0000367 void checkAnimationReady(WallpaperController wallpaperController) {
368 if (mPendingStart) {
369 final boolean wallpaperReady = !isHomeAppOverWallpaper()
370 || (wallpaperController.getWallpaperTarget() != null
371 && wallpaperController.wallpaperTransitionReady());
372 if (wallpaperReady) {
373 mService.getRecentsAnimationController().startAnimation();
374 }
375 }
376 }
377
378 boolean isWallpaperVisible(WindowState w) {
379 return w != null && w.mAppToken != null && mHomeAppToken == w.mAppToken
380 && isHomeAppOverWallpaper();
381 }
382
Winson Chunga89ffed2018-01-25 17:46:11 +0000383 boolean hasInputConsumerForApp(AppWindowToken appToken) {
384 return mInputConsumerEnabled && isAnimatingApp(appToken);
385 }
386
387 boolean updateInputConsumerForApp(InputConsumerImpl recentsAnimationInputConsumer,
388 boolean hasFocus) {
389 // Update the input consumer touchable region to match the home app main window
390 final WindowState homeAppMainWindow = mHomeAppToken != null
391 ? mHomeAppToken.findMainWindow()
392 : null;
393 if (homeAppMainWindow != null) {
394 homeAppMainWindow.getBounds(mTmpRect);
395 recentsAnimationInputConsumer.mWindowHandle.hasFocus = hasFocus;
396 recentsAnimationInputConsumer.mWindowHandle.touchableRegion.set(mTmpRect);
397 return true;
398 }
399 return false;
400 }
401
402 private boolean isHomeAppOverWallpaper() {
Winson Chunge2d72172018-01-25 17:46:20 +0000403 if (mHomeAppToken == null) {
404 return false;
405 }
406 return mHomeAppToken.windowsCanBeWallpaperTarget();
407 }
408
Winson Chunga89ffed2018-01-25 17:46:11 +0000409 private boolean isAnimatingApp(AppWindowToken appToken) {
Winson Chunge2d72172018-01-25 17:46:20 +0000410 for (int i = mPendingAnimations.size() - 1; i >= 0; i--) {
411 final Task task = mPendingAnimations.get(i).mTask;
412 for (int j = task.getChildCount() - 1; j >= 0; j--) {
413 final AppWindowToken app = task.getChildAt(j);
414 if (app == appToken) {
415 return true;
416 }
417 }
418 }
419 return false;
420 }
421
Winson Chunge2d72172018-01-25 17:46:20 +0000422 private class TaskAnimationAdapter implements AnimationAdapter {
423
Vadim Tryshev593e9562018-03-08 17:15:45 -0800424 private final Task mTask;
Winson Chunge2d72172018-01-25 17:46:20 +0000425 private SurfaceControl mCapturedLeash;
426 private OnAnimationFinishedCallback mCapturedFinishCallback;
Vadim Tryshev593e9562018-03-08 17:15:45 -0800427 private final boolean mIsRecentTaskInvisible;
Jorim Jaggif75d1612018-02-27 15:05:21 +0100428 private RemoteAnimationTarget mTarget;
Winson Chunge2d72172018-01-25 17:46:20 +0000429
Vadim Tryshev593e9562018-03-08 17:15:45 -0800430 TaskAnimationAdapter(Task task, boolean isRecentTaskInvisible) {
Winson Chunge2d72172018-01-25 17:46:20 +0000431 mTask = task;
Vadim Tryshev593e9562018-03-08 17:15:45 -0800432 mIsRecentTaskInvisible = isRecentTaskInvisible;
Winson Chunge2d72172018-01-25 17:46:20 +0000433 }
434
435 RemoteAnimationTarget createRemoteAnimationApp() {
Winson Chung584d6522018-02-07 23:57:38 +0000436 final Point position = new Point();
437 final Rect bounds = new Rect();
438 final WindowContainer container = mTask.getParent();
439 container.getRelativePosition(position);
440 container.getBounds(bounds);
441 final WindowState mainWindow = mTask.getTopVisibleAppMainWindow();
Winson Chung2dc37362018-03-12 17:57:06 -0700442 if (mainWindow == null) {
443 return null;
444 }
Jorim Jaggi817ebdd2018-03-26 15:46:01 +0200445 final Rect insets = new Rect(mainWindow.mContentInsets);
446 InsetUtils.addInsets(insets, mainWindow.mAppToken.getLetterboxInsets());
Jorim Jaggif75d1612018-02-27 15:05:21 +0100447 mTarget = new RemoteAnimationTarget(mTask.mTaskId, MODE_CLOSING, mCapturedLeash,
Winson Chung584d6522018-02-07 23:57:38 +0000448 !mTask.fillsParent(), mainWindow.mWinAnimator.mLastClipRect,
Jorim Jaggi817ebdd2018-03-26 15:46:01 +0200449 insets, mTask.getPrefixOrderIndex(), position, bounds,
Vadim Tryshev593e9562018-03-08 17:15:45 -0800450 mTask.getWindowConfiguration(), mIsRecentTaskInvisible);
Jorim Jaggif75d1612018-02-27 15:05:21 +0100451 return mTarget;
Winson Chunge2d72172018-01-25 17:46:20 +0000452 }
453
454 @Override
455 public boolean getDetachWallpaper() {
456 return false;
457 }
458
459 @Override
Jorim Jaggi82c17862018-02-21 17:50:18 +0100460 public boolean getShowWallpaper() {
461 return false;
462 }
463
464 @Override
Winson Chunge2d72172018-01-25 17:46:20 +0000465 public int getBackgroundColor() {
466 return 0;
467 }
468
469 @Override
470 public void startAnimation(SurfaceControl animationLeash, Transaction t,
471 OnAnimationFinishedCallback finishCallback) {
472 mCapturedLeash = animationLeash;
473 mCapturedFinishCallback = finishCallback;
474 }
475
476 @Override
477 public void onAnimationCancelled(SurfaceControl animationLeash) {
Winson Chung6a38fca2018-03-28 17:57:09 -0700478 cancelAnimation(REORDER_MOVE_HOME_TO_ORIGINAL_POSITION);
Winson Chunge2d72172018-01-25 17:46:20 +0000479 }
480
481 @Override
482 public long getDurationHint() {
483 return 0;
484 }
485
486 @Override
487 public long getStatusBarTransitionsStartTime() {
488 return SystemClock.uptimeMillis();
489 }
Jorim Jaggif75d1612018-02-27 15:05:21 +0100490
491 @Override
492 public void dump(PrintWriter pw, String prefix) {
493 pw.print(prefix); pw.println("task=" + mTask);
494 if (mTarget != null) {
495 pw.print(prefix); pw.println("Target:");
496 mTarget.dump(pw, prefix + " ");
497 } else {
498 pw.print(prefix); pw.println("Target: null");
499 }
500 }
501
502 @Override
503 public void writeToProto(ProtoOutputStream proto) {
504 final long token = proto.start(REMOTE);
505 if (mTarget != null) {
506 mTarget.writeToProto(proto, TARGET);
507 }
508 proto.end(token);
509 }
Winson Chunge2d72172018-01-25 17:46:20 +0000510 }
511
512 public void dump(PrintWriter pw, String prefix) {
513 final String innerPrefix = prefix + " ";
514 pw.print(prefix); pw.println(RecentsAnimationController.class.getSimpleName() + ":");
515 pw.print(innerPrefix); pw.println("mPendingStart=" + mPendingStart);
516 pw.print(innerPrefix); pw.println("mHomeAppToken=" + mHomeAppToken);
517 }
518}