blob: c7617546780d512776a716b11ea33c9e74552256 [file] [log] [blame]
Craig Mautner164d4bb2012-11-26 13:51:23 -08001/*
2 * Copyright (C) 2011 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 Jaggif84e2f62018-01-16 14:17:59 +010019import static android.view.WindowManager.LayoutParams;
20import static android.view.WindowManager.TRANSIT_ACTIVITY_CLOSE;
21import static android.view.WindowManager.TRANSIT_ACTIVITY_OPEN;
22import static android.view.WindowManager.TRANSIT_ACTIVITY_RELAUNCH;
Adrian Roos93577212018-04-10 14:12:10 -070023import static android.view.WindowManager.TRANSIT_CRASHING_ACTIVITY_CLOSE;
Jorim Jaggif84e2f62018-01-16 14:17:59 +010024import static android.view.WindowManager.TRANSIT_DOCK_TASK_FROM_RECENTS;
25import static android.view.WindowManager.TRANSIT_FLAG_KEYGUARD_GOING_AWAY_NO_ANIMATION;
26import static android.view.WindowManager.TRANSIT_FLAG_KEYGUARD_GOING_AWAY_TO_SHADE;
27import static android.view.WindowManager.TRANSIT_KEYGUARD_GOING_AWAY;
28import static android.view.WindowManager.TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER;
29import static android.view.WindowManager.TRANSIT_KEYGUARD_OCCLUDE;
30import static android.view.WindowManager.TRANSIT_KEYGUARD_UNOCCLUDE;
31import static android.view.WindowManager.TRANSIT_NONE;
32import static android.view.WindowManager.TRANSIT_TASK_CLOSE;
Jorim Jaggicecf4242018-02-21 18:46:53 +010033import static android.view.WindowManager.TRANSIT_TASK_IN_PLACE;
Jorim Jaggif84e2f62018-01-16 14:17:59 +010034import static android.view.WindowManager.TRANSIT_TASK_OPEN;
35import static android.view.WindowManager.TRANSIT_TASK_OPEN_BEHIND;
36import static android.view.WindowManager.TRANSIT_TASK_TO_BACK;
37import static android.view.WindowManager.TRANSIT_TASK_TO_FRONT;
Jorim Jaggi98a9d202018-03-26 16:17:07 +020038import static android.view.WindowManager.TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE;
39import static android.view.WindowManager.TRANSIT_TRANSLUCENT_ACTIVITY_OPEN;
Jorim Jaggif84e2f62018-01-16 14:17:59 +010040import static android.view.WindowManager.TRANSIT_UNSET;
41import static android.view.WindowManager.TRANSIT_WALLPAPER_CLOSE;
42import static android.view.WindowManager.TRANSIT_WALLPAPER_INTRA_CLOSE;
43import static android.view.WindowManager.TRANSIT_WALLPAPER_INTRA_OPEN;
44import static android.view.WindowManager.TRANSIT_WALLPAPER_OPEN;
Tony Mak83546a82018-01-22 13:56:20 +000045
Filip Gruszczynski82861362015-10-16 14:21:09 -070046import static com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation;
47import static com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
48import static com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation;
49import static com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
50import static com.android.internal.R.styleable.WindowAnimation_launchTaskBehindSourceAnimation;
51import static com.android.internal.R.styleable.WindowAnimation_launchTaskBehindTargetAnimation;
52import static com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation;
53import static com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
54import static com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation;
55import static com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
56import static com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation;
57import static com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
58import static com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation;
59import static com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
60import static com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation;
61import static com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
62import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation;
63import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
64import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation;
65import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
66import static com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation;
67import static com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Filip Gruszczynski198dcbf2016-01-18 10:02:00 -080068import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
69import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080070import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
71import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Adrian Roose99bc052017-11-20 17:55:31 +010072import static com.android.server.wm.WindowManagerInternal.AppTransitionListener;
Tony Mak089c35e2017-12-18 20:34:14 +000073import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_AFTER_ANIM;
Matthew Ngbf1d9852017-03-14 12:23:09 -070074import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_BEFORE_ANIM;
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +010075import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_NONE;
Yi Jin6c6e9ca2018-03-20 16:53:35 -070076import static com.android.server.wm.AppTransitionProto.APP_TRANSITION_STATE;
77import static com.android.server.wm.AppTransitionProto.LAST_USED_APP_TRANSITION;
Filip Gruszczynski82861362015-10-16 14:21:09 -070078
Tony Mak64b8d562017-12-28 17:44:02 +000079import android.annotation.DrawableRes;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -070080import android.annotation.Nullable;
Matthew Ng43db6d22017-06-27 15:29:39 -070081import android.app.ActivityManager;
Tony Mak089c35e2017-12-18 20:34:14 +000082import android.content.ComponentName;
Craig Mautner164d4bb2012-11-26 13:51:23 -080083import android.content.Context;
Winson21700932016-03-24 17:26:23 -070084import android.content.res.Configuration;
Todd Kennedy64c57a82018-04-19 15:17:24 -070085import android.content.res.ResourceId;
John Reck519ad482018-02-12 17:08:48 -080086import android.graphics.Bitmap;
87import android.graphics.Canvas;
Tony Mak64b8d562017-12-28 17:44:02 +000088import android.graphics.Color;
Winson Chungaa7fa012017-05-24 15:50:06 -070089import android.graphics.GraphicBuffer;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +010090import android.graphics.Path;
John Reck519ad482018-02-12 17:08:48 -080091import android.graphics.Picture;
Winson Chung399f6202014-03-19 10:47:20 -070092import android.graphics.Rect;
Tony Mak64b8d562017-12-28 17:44:02 +000093import android.graphics.drawable.Drawable;
Jorim Jaggied410b62017-05-05 15:16:14 +020094import android.os.Binder;
Craig Mautner164d4bb2012-11-26 13:51:23 -080095import android.os.Debug;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010096import android.os.IBinder;
Craig Mautner164d4bb2012-11-26 13:51:23 -080097import android.os.IRemoteCallback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010098import android.os.RemoteException;
Jorim Jaggif5f9e122017-10-24 18:21:09 +020099import android.os.SystemClock;
Manu Cornetd7376802017-01-13 13:44:07 -0800100import android.os.SystemProperties;
Tony Mak089c35e2017-12-18 20:34:14 +0000101import android.os.UserHandle;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800102import android.util.ArraySet;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800103import android.util.Slog;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700104import android.util.SparseArray;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700105import android.util.proto.ProtoOutputStream;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700106import android.view.AppTransitionAnimationSpec;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100107import android.view.IAppTransitionAnimationSpecsFuture;
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100108import android.view.RemoteAnimationAdapter;
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100109import android.view.WindowManager.TransitionFlags;
110import android.view.WindowManager.TransitionType;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800111import android.view.animation.AlphaAnimation;
112import android.view.animation.Animation;
113import android.view.animation.AnimationSet;
114import android.view.animation.AnimationUtils;
Winson Chung399f6202014-03-19 10:47:20 -0700115import android.view.animation.ClipRectAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800116import android.view.animation.Interpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700117import android.view.animation.PathInterpolator;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800118import android.view.animation.ScaleAnimation;
Winson Chung399f6202014-03-19 10:47:20 -0700119import android.view.animation.TranslateAnimation;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700120
Jorim Jaggi98a9d202018-03-26 16:17:07 +0200121import com.android.internal.R;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800122import com.android.internal.util.DumpUtils.Dump;
123import com.android.server.AttributeCache;
124import com.android.server.wm.WindowManagerService.H;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800125import com.android.server.wm.animation.ClipRectLRAnimation;
126import com.android.server.wm.animation.ClipRectTBAnimation;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100127import com.android.server.wm.animation.CurvedTranslateAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800128
129import java.io.PrintWriter;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100130import java.util.ArrayList;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100131import java.util.concurrent.ExecutorService;
132import java.util.concurrent.Executors;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800133
Craig Mautner164d4bb2012-11-26 13:51:23 -0800134// State management of app transitions. When we are preparing for a
135// transition, mNextAppTransition will be the kind of transition to
136// perform or TRANSIT_NONE if we are not waiting. If we are waiting,
137// mOpeningApps and mClosingApps are the lists of tokens that will be
138// made visible or hidden at the next transition.
139public class AppTransition implements Dump {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800140 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppTransition" : TAG_WM;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700141 private static final int CLIP_REVEAL_TRANSLATION_Y_DP = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800142
Winson Chunga4ccb862014-08-22 15:26:27 -0700143 /** Fraction of animation at which the recents thumbnail stays completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700144 private static final float RECENTS_THUMBNAIL_FADEIN_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800145 /** Fraction of animation at which the recents thumbnail becomes completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700146 private static final float RECENTS_THUMBNAIL_FADEOUT_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800147
Filip Gruszczynski84fa3352016-01-25 16:28:49 -0800148 static final int DEFAULT_APP_TRANSITION_DURATION = 336;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800149
150 /** Interpolator to be used for animations that respond directly to a touch */
151 static final Interpolator TOUCH_RESPONSE_INTERPOLATOR =
152 new PathInterpolator(0.3f, 0f, 0.1f, 1f);
153
Jorim Jaggic69bd222016-03-15 14:38:37 +0100154 private static final Interpolator THUMBNAIL_DOCK_INTERPOLATOR =
155 new PathInterpolator(0.85f, 0f, 1f, 1f);
156
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800157 /**
158 * Maximum duration for the clip reveal animation. This is used when there is a lot of movement
159 * involved, to make it more understandable.
160 */
161 private static final int MAX_CLIP_REVEAL_TRANSITION_DURATION = 420;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700162 private static final int THUMBNAIL_APP_TRANSITION_DURATION = 336;
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700163 private static final long APP_TRANSITION_TIMEOUT_MS = 5000;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800164
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800165 private final Context mContext;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800166 private final WindowManagerService mService;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800167
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100168 private @TransitionType int mNextAppTransition = TRANSIT_UNSET;
169 private @TransitionFlags int mNextAppTransitionFlags = 0;
Chong Zhang60091a92016-07-27 17:52:45 -0700170 private int mLastUsedAppTransition = TRANSIT_UNSET;
171 private String mLastOpeningApp;
172 private String mLastClosingApp;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800173
174 private static final int NEXT_TRANSIT_TYPE_NONE = 0;
175 private static final int NEXT_TRANSIT_TYPE_CUSTOM = 1;
176 private static final int NEXT_TRANSIT_TYPE_SCALE_UP = 2;
177 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP = 3;
178 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN = 4;
Winson Chunga4ccb862014-08-22 15:26:27 -0700179 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP = 5;
180 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN = 6;
Winson Chung044d5292014-11-06 11:05:19 -0800181 private static final int NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE = 7;
Chet Haase10e23ab2015-02-11 15:08:38 -0800182 private static final int NEXT_TRANSIT_TYPE_CLIP_REVEAL = 8;
Tony Mak089c35e2017-12-18 20:34:14 +0000183
184 /**
185 * Refers to the transition to activity started by using {@link
186 * android.content.pm.crossprofile.CrossProfileApps#startMainActivity(ComponentName, UserHandle)
187 * }.
188 */
189 private static final int NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS = 9;
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100190 private static final int NEXT_TRANSIT_TYPE_REMOTE = 10;
191
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800192 private int mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
193
Winson Chung399f6202014-03-19 10:47:20 -0700194 // These are the possible states for the enter/exit activities during a thumbnail transition
195 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_UP = 0;
196 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_UP = 1;
197 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN = 2;
198 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN = 3;
199
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800200 private String mNextAppTransitionPackage;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800201 // Used for thumbnail transitions. True if we're scaling up, false if scaling down
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800202 private boolean mNextAppTransitionScaleUp;
203 private IRemoteCallback mNextAppTransitionCallback;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +0100204 private IRemoteCallback mNextAppTransitionFutureCallback;
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -0700205 private IRemoteCallback mAnimationFinishedCallback;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800206 private int mNextAppTransitionEnter;
207 private int mNextAppTransitionExit;
Winson Chung044d5292014-11-06 11:05:19 -0800208 private int mNextAppTransitionInPlace;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700209
210 // Keyed by task id.
211 private final SparseArray<AppTransitionAnimationSpec> mNextAppTransitionAnimationsSpecs
212 = new SparseArray<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100213 private IAppTransitionAnimationSpecsFuture mNextAppTransitionAnimationsSpecsFuture;
214 private boolean mNextAppTransitionAnimationsSpecsPending;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700215 private AppTransitionAnimationSpec mDefaultNextAppTransitionAnimationSpec;
216
Winson Chunga4ccb862014-08-22 15:26:27 -0700217 private Rect mNextAppTransitionInsets = new Rect();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800218
Winson Chung2820c452014-04-15 15:34:44 -0700219 private Rect mTmpFromClipRect = new Rect();
220 private Rect mTmpToClipRect = new Rect();
221
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700222 private final Rect mTmpRect = new Rect();
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700223
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800224 private final static int APP_STATE_IDLE = 0;
225 private final static int APP_STATE_READY = 1;
226 private final static int APP_STATE_RUNNING = 2;
227 private final static int APP_STATE_TIMEOUT = 3;
228 private int mAppTransitionState = APP_STATE_IDLE;
229
230 private final int mConfigShortAnimTime;
Craig Mautner321bdf52012-12-18 09:53:24 -0800231 private final Interpolator mDecelerateInterpolator;
Winson Chunga4ccb862014-08-22 15:26:27 -0700232 private final Interpolator mThumbnailFadeInInterpolator;
233 private final Interpolator mThumbnailFadeOutInterpolator;
Chet Haase10e23ab2015-02-11 15:08:38 -0800234 private final Interpolator mLinearOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700235 private final Interpolator mFastOutLinearInInterpolator;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100236 private final Interpolator mFastOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700237 private final Interpolator mClipHorizontalInterpolator = new PathInterpolator(0, 0, 0.4f, 1f);
238
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700239 private final int mClipRevealTranslationY;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800240
Amith Yamasani4befbec2013-07-10 16:18:01 -0700241 private int mCurrentUserId = 0;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800242 private long mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Amith Yamasani4befbec2013-07-10 16:18:01 -0700243
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100244 private final ArrayList<AppTransitionListener> mListeners = new ArrayList<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100245 private final ExecutorService mDefaultExecutor = Executors.newSingleThreadExecutor();
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100246
Jorim Jaggif97ed922016-02-18 18:57:07 -0800247 private int mLastClipRevealMaxTranslation;
248 private boolean mLastHadClipReveal;
249
Manu Cornetd7376802017-01-13 13:44:07 -0800250 private final boolean mGridLayoutRecentsEnabled;
Matthew Ng43db6d22017-06-27 15:29:39 -0700251 private final boolean mLowRamRecentsEnabled;
Manu Cornetd7376802017-01-13 13:44:07 -0800252
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100253 private RemoteAnimationController mRemoteAnimationController;
254
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800255 AppTransition(Context context, WindowManagerService service) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800256 mContext = context;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800257 mService = service;
Chet Haase10e23ab2015-02-11 15:08:38 -0800258 mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
259 com.android.internal.R.interpolator.linear_out_slow_in);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700260 mFastOutLinearInInterpolator = AnimationUtils.loadInterpolator(context,
261 com.android.internal.R.interpolator.fast_out_linear_in);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100262 mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
263 com.android.internal.R.interpolator.fast_out_slow_in);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800264 mConfigShortAnimTime = context.getResources().getInteger(
265 com.android.internal.R.integer.config_shortAnimTime);
Craig Mautner321bdf52012-12-18 09:53:24 -0800266 mDecelerateInterpolator = AnimationUtils.loadInterpolator(context,
267 com.android.internal.R.interpolator.decelerate_cubic);
Winson Chunga4ccb862014-08-22 15:26:27 -0700268 mThumbnailFadeInInterpolator = new Interpolator() {
269 @Override
270 public float getInterpolation(float input) {
271 // Linear response for first fraction, then complete after that.
272 if (input < RECENTS_THUMBNAIL_FADEIN_FRACTION) {
273 return 0f;
274 }
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700275 float t = (input - RECENTS_THUMBNAIL_FADEIN_FRACTION) /
Winson Chunga4ccb862014-08-22 15:26:27 -0700276 (1f - RECENTS_THUMBNAIL_FADEIN_FRACTION);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700277 return mFastOutLinearInInterpolator.getInterpolation(t);
Winson Chunga4ccb862014-08-22 15:26:27 -0700278 }
279 };
280 mThumbnailFadeOutInterpolator = new Interpolator() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800281 @Override
282 public float getInterpolation(float input) {
283 // Linear response for first fraction, then complete after that.
284 if (input < RECENTS_THUMBNAIL_FADEOUT_FRACTION) {
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700285 float t = input / RECENTS_THUMBNAIL_FADEOUT_FRACTION;
286 return mLinearOutSlowInInterpolator.getInterpolation(t);
Craig Mautner321bdf52012-12-18 09:53:24 -0800287 }
Winson Chunga4ccb862014-08-22 15:26:27 -0700288 return 1f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800289 }
290 };
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700291 mClipRevealTranslationY = (int) (CLIP_REVEAL_TRANSLATION_Y_DP
292 * mContext.getResources().getDisplayMetrics().density);
Manu Cornetd7376802017-01-13 13:44:07 -0800293 mGridLayoutRecentsEnabled = SystemProperties.getBoolean("ro.recents.grid", false);
Matthew Ng43db6d22017-06-27 15:29:39 -0700294 mLowRamRecentsEnabled = ActivityManager.isLowRamDeviceStatic();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800295 }
296
297 boolean isTransitionSet() {
298 return mNextAppTransition != TRANSIT_UNSET;
299 }
300
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100301 boolean isTransitionEqual(@TransitionType int transit) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800302 return mNextAppTransition == transit;
303 }
304
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100305 @TransitionType int getAppTransition() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800306 return mNextAppTransition;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800307 }
308
Jorim Jaggife762342016-10-13 14:33:27 +0200309 private void setAppTransition(int transit, int flags) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800310 mNextAppTransition = transit;
Jorim Jaggife762342016-10-13 14:33:27 +0200311 mNextAppTransitionFlags |= flags;
Chong Zhang60091a92016-07-27 17:52:45 -0700312 setLastAppTransition(TRANSIT_UNSET, null, null);
Jorim Jaggi245281c2017-06-07 14:33:04 -0700313 updateBooster();
Chong Zhang60091a92016-07-27 17:52:45 -0700314 }
315
316 void setLastAppTransition(int transit, AppWindowToken openingApp, AppWindowToken closingApp) {
317 mLastUsedAppTransition = transit;
318 mLastOpeningApp = "" + openingApp;
319 mLastClosingApp = "" + closingApp;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800320 }
321
322 boolean isReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800323 return mAppTransitionState == APP_STATE_READY
324 || mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800325 }
326
Craig Mautnerae446592012-12-06 19:05:05 -0800327 void setReady() {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700328 setAppTransitionState(APP_STATE_READY);
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100329 fetchAppTransitionSpecsFromFuture();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800330 }
331
332 boolean isRunning() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800333 return mAppTransitionState == APP_STATE_RUNNING;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800334 }
335
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800336 void setIdle() {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700337 setAppTransitionState(APP_STATE_IDLE);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800338 }
339
340 boolean isTimeout() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800341 return mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800342 }
343
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800344 void setTimeout() {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700345 setAppTransitionState(APP_STATE_TIMEOUT);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800346 }
347
Winson Chungaa7fa012017-05-24 15:50:06 -0700348 GraphicBuffer getAppTransitionThumbnailHeader(int taskId) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700349 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800350 if (spec == null) {
351 spec = mDefaultNextAppTransitionAnimationSpec;
352 }
Winson Chungaa7fa012017-05-24 15:50:06 -0700353 return spec != null ? spec.buffer : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800354 }
355
Winson Chunga4ccb862014-08-22 15:26:27 -0700356 /** Returns whether the next thumbnail transition is aspect scaled up. */
357 boolean isNextThumbnailTransitionAspectScaled() {
358 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
359 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
360 }
361
362 /** Returns whether the next thumbnail transition is scaling up. */
363 boolean isNextThumbnailTransitionScaleUp() {
364 return mNextAppTransitionScaleUp;
365 }
366
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -0800367 boolean isNextAppTransitionThumbnailUp() {
368 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
369 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP;
370 }
371
372 boolean isNextAppTransitionThumbnailDown() {
373 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN ||
374 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
375 }
376
Tony Mak64b8d562017-12-28 17:44:02 +0000377
378 boolean isNextAppTransitionOpenCrossProfileApps() {
379 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS;
380 }
381
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100382 /**
383 * @return true if and only if we are currently fetching app transition specs from the future
384 * passed into {@link #overridePendingAppTransitionMultiThumbFuture}
385 */
386 boolean isFetchingAppTransitionsSpecs() {
387 return mNextAppTransitionAnimationsSpecsPending;
388 }
389
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700390 private boolean prepare() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800391 if (!isRunning()) {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700392 setAppTransitionState(APP_STATE_IDLE);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100393 notifyAppTransitionPendingLocked();
Jorim Jaggif97ed922016-02-18 18:57:07 -0800394 mLastHadClipReveal = false;
395 mLastClipRevealMaxTranslation = 0;
396 mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700397 return true;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800398 }
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700399 return false;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800400 }
401
Jorim Jaggife762342016-10-13 14:33:27 +0200402 /**
403 * @return bit-map of WindowManagerPolicy#FINISH_LAYOUT_REDO_* to indicate whether another
404 * layout pass needs to be done
405 */
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200406 int goodToGo(int transit, AppWindowToken topOpeningApp,
407 AppWindowToken topClosingApp, ArraySet<AppWindowToken> openingApps,
Jorim Jaggife762342016-10-13 14:33:27 +0200408 ArraySet<AppWindowToken> closingApps) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800409 mNextAppTransition = TRANSIT_UNSET;
Jorim Jaggife762342016-10-13 14:33:27 +0200410 mNextAppTransitionFlags = 0;
Jorim Jaggi245281c2017-06-07 14:33:04 -0700411 setAppTransitionState(APP_STATE_RUNNING);
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200412 final AnimationAdapter topOpeningAnim = topOpeningApp != null
413 ? topOpeningApp.getAnimation()
414 : null;
Jorim Jaggife762342016-10-13 14:33:27 +0200415 int redoLayout = notifyAppTransitionStartingLocked(transit,
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200416 topOpeningApp != null ? topOpeningApp.token : null,
417 topClosingApp != null ? topClosingApp.token : null,
418 topOpeningAnim != null ? topOpeningAnim.getDurationHint() : 0,
419 topOpeningAnim != null
420 ? topOpeningAnim.getStatusBarTransitionsStartTime()
421 : SystemClock.uptimeMillis(),
422 AnimationAdapter.STATUS_BAR_TRANSITION_DURATION);
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800423 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Jorim Jaggife762342016-10-13 14:33:27 +0200424 .notifyAppTransitionStarting(openingApps, transit);
Jorim Jaggi363ab982016-04-26 19:51:20 -0700425
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100426 if (mRemoteAnimationController != null) {
427 mRemoteAnimationController.goodToGo();
428 }
Jorim Jaggife762342016-10-13 14:33:27 +0200429 return redoLayout;
Jorim Jaggi363ab982016-04-26 19:51:20 -0700430 }
431
Craig Mautner164d4bb2012-11-26 13:51:23 -0800432 void clear() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800433 mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800434 mNextAppTransitionPackage = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700435 mNextAppTransitionAnimationsSpecs.clear();
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100436 mRemoteAnimationController = null;
Jorim Jaggi65193992015-11-23 16:49:59 -0800437 mNextAppTransitionAnimationsSpecsFuture = null;
438 mDefaultNextAppTransitionAnimationSpec = null;
439 mAnimationFinishedCallback = null;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800440 }
441
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800442 void freeze() {
Jorim Jaggife762342016-10-13 14:33:27 +0200443 final int transit = mNextAppTransition;
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100444 setAppTransition(TRANSIT_UNSET, 0 /* flags */);
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800445 clear();
446 setReady();
Jorim Jaggife762342016-10-13 14:33:27 +0200447 notifyAppTransitionCancelledLocked(transit);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100448 }
449
Jorim Jaggi245281c2017-06-07 14:33:04 -0700450 private void setAppTransitionState(int state) {
451 mAppTransitionState = state;
452 updateBooster();
453 }
454
455 /**
456 * Updates whether we currently boost wm locked sections and the animation thread. We want to
457 * boost the priorities to a more important value whenever an app transition is going to happen
458 * soon or an app transition is running.
459 */
Jorim Jaggic8cc2292018-03-15 20:16:15 +0100460 void updateBooster() {
461 WindowManagerService.sThreadPriorityBooster.setAppTransitionRunning(needsBoosting());
462 }
463
464 private boolean needsBoosting() {
465 final boolean recentsAnimRunning = mService.getRecentsAnimationController() != null;
466 return mNextAppTransition != TRANSIT_UNSET
467 || mAppTransitionState == APP_STATE_READY
468 || mAppTransitionState == APP_STATE_RUNNING
469 || recentsAnimRunning;
Jorim Jaggi245281c2017-06-07 14:33:04 -0700470 }
471
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100472 void registerListenerLocked(AppTransitionListener listener) {
473 mListeners.add(listener);
474 }
475
Wale Ogunwalea48eadb2015-05-14 17:43:12 -0700476 public void notifyAppTransitionFinishedLocked(IBinder token) {
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100477 for (int i = 0; i < mListeners.size(); i++) {
478 mListeners.get(i).onAppTransitionFinishedLocked(token);
479 }
480 }
481
482 private void notifyAppTransitionPendingLocked() {
483 for (int i = 0; i < mListeners.size(); i++) {
484 mListeners.get(i).onAppTransitionPendingLocked();
485 }
486 }
487
Jorim Jaggife762342016-10-13 14:33:27 +0200488 private void notifyAppTransitionCancelledLocked(int transit) {
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100489 for (int i = 0; i < mListeners.size(); i++) {
Jorim Jaggife762342016-10-13 14:33:27 +0200490 mListeners.get(i).onAppTransitionCancelledLocked(transit);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100491 }
492 }
493
Jorim Jaggife762342016-10-13 14:33:27 +0200494 private int notifyAppTransitionStartingLocked(int transit, IBinder openToken,
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200495 IBinder closeToken, long duration, long statusBarAnimationStartTime,
496 long statusBarAnimationDuration) {
Jorim Jaggife762342016-10-13 14:33:27 +0200497 int redoLayout = 0;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100498 for (int i = 0; i < mListeners.size(); i++) {
Jorim Jaggife762342016-10-13 14:33:27 +0200499 redoLayout |= mListeners.get(i).onAppTransitionStartingLocked(transit, openToken,
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200500 closeToken, duration, statusBarAnimationStartTime, statusBarAnimationDuration);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100501 }
Jorim Jaggife762342016-10-13 14:33:27 +0200502 return redoLayout;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800503 }
504
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100505 private AttributeCache.Entry getCachedAnimations(LayoutParams lp) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800506 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg="
507 + (lp != null ? lp.packageName : null)
508 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
509 if (lp != null && lp.windowAnimations != 0) {
510 // If this is a system resource, don't try to load it from the
511 // application resources. It is nice to avoid loading application
512 // resources if we can.
513 String packageName = lp.packageName != null ? lp.packageName : "android";
514 int resId = lp.windowAnimations;
515 if ((resId&0xFF000000) == 0x01000000) {
516 packageName = "android";
517 }
518 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
519 + packageName);
520 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700521 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800522 }
523 return null;
524 }
525
526 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
527 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package="
528 + packageName + " resId=0x" + Integer.toHexString(resId));
529 if (packageName != null) {
530 if ((resId&0xFF000000) == 0x01000000) {
531 packageName = "android";
532 }
533 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
534 + packageName);
535 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700536 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800537 }
538 return null;
539 }
540
Jorim Jaggi0a1523d2018-04-19 17:48:38 +0200541 Animation loadAnimationAttr(LayoutParams lp, int animAttr, int transit) {
Todd Kennedy64c57a82018-04-19 15:17:24 -0700542 int resId = ResourceId.ID_NULL;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800543 Context context = mContext;
Jorim Jaggi5f95b002018-04-19 13:27:52 +0000544 if (animAttr >= 0) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800545 AttributeCache.Entry ent = getCachedAnimations(lp);
546 if (ent != null) {
547 context = ent.context;
Todd Kennedy64c57a82018-04-19 15:17:24 -0700548 resId = ent.array.getResourceId(animAttr, 0);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800549 }
550 }
Todd Kennedy64c57a82018-04-19 15:17:24 -0700551 resId = updateToTranslucentAnimIfNeeded(resId, transit);
552 if (ResourceId.isValid(resId)) {
553 return AnimationUtils.loadAnimation(context, resId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800554 }
555 return null;
556 }
557
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100558 Animation loadAnimationRes(LayoutParams lp, int resId) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700559 Context context = mContext;
Todd Kennedy64c57a82018-04-19 15:17:24 -0700560 if (ResourceId.isValid(resId)) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700561 AttributeCache.Entry ent = getCachedAnimations(lp);
562 if (ent != null) {
563 context = ent.context;
564 }
565 return AnimationUtils.loadAnimation(context, resId);
566 }
567 return null;
568 }
569
570 private Animation loadAnimationRes(String packageName, int resId) {
Todd Kennedy64c57a82018-04-19 15:17:24 -0700571 if (ResourceId.isValid(resId)) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800572 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
573 if (ent != null) {
Todd Kennedy64c57a82018-04-19 15:17:24 -0700574 return AnimationUtils.loadAnimation(ent.context, resId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800575 }
576 }
Craig Mautner164d4bb2012-11-26 13:51:23 -0800577 return null;
578 }
579
Jorim Jaggi0a1523d2018-04-19 17:48:38 +0200580 private int updateToTranslucentAnimIfNeeded(int anim, int transit) {
581 if (transit == TRANSIT_TRANSLUCENT_ACTIVITY_OPEN && anim == R.anim.activity_open_enter) {
582 return R.anim.activity_translucent_open_enter;
583 }
584 if (transit == TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE && anim == R.anim.activity_close_exit) {
585 return R.anim.activity_translucent_close_exit;
586 }
587 return anim;
588 }
589
Craig Mautner164d4bb2012-11-26 13:51:23 -0800590 /**
591 * Compute the pivot point for an animation that is scaling from a small
592 * rect on screen to a larger rect. The pivot point varies depending on
593 * the distance between the inner and outer edges on both sides. This
594 * function computes the pivot point for one dimension.
595 * @param startPos Offset from left/top edge of outer rectangle to
596 * left/top edge of inner rectangle.
597 * @param finalScale The scaling factor between the size of the outer
598 * and inner rectangles.
599 */
600 private static float computePivot(int startPos, float finalScale) {
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800601
602 /*
603 Theorem of intercepting lines:
604
605 + + +-----------------------------------------------+
606 | | | |
607 | | | |
608 | | | |
609 | | | |
610 x | y | | |
611 | | | |
612 | | | |
613 | | | |
614 | | | |
615 | + | +--------------------+ |
616 | | | | |
617 | | | | |
618 | | | | |
619 | | | | |
620 | | | | |
621 | | | | |
622 | | | | |
623 | | | | |
624 | | | | |
625 | | | | |
626 | | | | |
627 | | | | |
628 | | | | |
629 | | | | |
630 | | | | |
631 | | | | |
632 | | | | |
633 | | +--------------------+ |
634 | | |
635 | | |
636 | | |
637 | | |
638 | | |
639 | | |
640 | | |
641 | +-----------------------------------------------+
642 |
643 |
644 |
645 |
646 |
647 |
648 |
649 |
650 |
651 + ++
652 p ++
653
654 scale = (x - y) / x
655 <=> x = -y / (scale - 1)
656 */
Craig Mautner164d4bb2012-11-26 13:51:23 -0800657 final float denom = finalScale-1;
658 if (Math.abs(denom) < .0001f) {
659 return startPos;
660 }
661 return -startPos / denom;
662 }
663
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700664 private Animation createScaleUpAnimationLocked(int transit, boolean enter,
665 Rect containingFrame) {
666 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700667 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700668 final int appWidth = containingFrame.width();
669 final int appHeight = containingFrame.height();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800670 if (enter) {
671 // Entering app zooms out from the center of the initial rect.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700672 float scaleW = mTmpRect.width() / (float) appWidth;
673 float scaleH = mTmpRect.height() / (float) appHeight;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800674 Animation scale = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700675 computePivot(mTmpRect.left, scaleW),
Winson4c3fecd2016-07-13 12:29:48 -0700676 computePivot(mTmpRect.top, scaleH));
Craig Mautner321bdf52012-12-18 09:53:24 -0800677 scale.setInterpolator(mDecelerateInterpolator);
678
Craig Mautner164d4bb2012-11-26 13:51:23 -0800679 Animation alpha = new AlphaAnimation(0, 1);
Winson Chunga4ccb862014-08-22 15:26:27 -0700680 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
Craig Mautner321bdf52012-12-18 09:53:24 -0800681
682 AnimationSet set = new AnimationSet(false);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800683 set.addAnimation(scale);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800684 set.addAnimation(alpha);
685 set.setDetachWallpaper(true);
686 a = set;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800687 } else if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
688 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800689 // If we are on top of the wallpaper, we need an animation that
690 // correctly handles the wallpaper staying static behind all of
691 // the animated elements. To do this, will just have the existing
692 // element fade out.
693 a = new AlphaAnimation(1, 0);
694 a.setDetachWallpaper(true);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800695 } else {
Craig Mautner321bdf52012-12-18 09:53:24 -0800696 // For normal animations, the exiting element just holds in place.
697 a = new AlphaAnimation(1, 1);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800698 }
Craig Mautner321bdf52012-12-18 09:53:24 -0800699
700 // Pick the desired duration. If this is an inter-activity transition,
701 // it is the standard duration for that. Otherwise we use the longer
702 // task transition duration.
703 final long duration;
704 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800705 case TRANSIT_ACTIVITY_OPEN:
706 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800707 duration = mConfigShortAnimTime;
708 break;
709 default:
710 duration = DEFAULT_APP_TRANSITION_DURATION;
711 break;
712 }
713 a.setDuration(duration);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800714 a.setFillAfter(true);
Craig Mautner321bdf52012-12-18 09:53:24 -0800715 a.setInterpolator(mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800716 a.initialize(appWidth, appHeight, appWidth, appHeight);
717 return a;
718 }
719
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700720 private void getDefaultNextAppTransitionStartRect(Rect rect) {
721 if (mDefaultNextAppTransitionAnimationSpec == null ||
722 mDefaultNextAppTransitionAnimationSpec.rect == null) {
Jorim Jaggi2550f3f2017-03-14 20:15:59 +0100723 Slog.e(TAG, "Starting rect for app requested, but none available", new Throwable());
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700724 rect.setEmpty();
725 } else {
726 rect.set(mDefaultNextAppTransitionAnimationSpec.rect);
727 }
728 }
729
730 void getNextAppTransitionStartRect(int taskId, Rect rect) {
731 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800732 if (spec == null) {
733 spec = mDefaultNextAppTransitionAnimationSpec;
734 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700735 if (spec == null || spec.rect == null) {
Jorim Jaggi2550f3f2017-03-14 20:15:59 +0100736 Slog.e(TAG, "Starting rect for task: " + taskId + " requested, but not available",
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700737 new Throwable());
738 rect.setEmpty();
739 } else {
740 rect.set(spec.rect);
741 }
742 }
743
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800744 private void putDefaultNextAppTransitionCoordinates(int left, int top, int width, int height,
Winson Chungaa7fa012017-05-24 15:50:06 -0700745 GraphicBuffer buffer) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700746 mDefaultNextAppTransitionAnimationSpec = new AppTransitionAnimationSpec(-1 /* taskId */,
Winson Chungaa7fa012017-05-24 15:50:06 -0700747 buffer, new Rect(left, top, left + width, top + height));
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700748 }
749
Jorim Jaggif97ed922016-02-18 18:57:07 -0800750 /**
751 * @return the duration of the last clip reveal animation
752 */
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800753 long getLastClipRevealTransitionDuration() {
754 return mLastClipRevealTransitionDuration;
755 }
756
757 /**
Jorim Jaggif97ed922016-02-18 18:57:07 -0800758 * @return the maximum distance the app surface is traveling of the last clip reveal animation
759 */
760 int getLastClipRevealMaxTranslation() {
761 return mLastClipRevealMaxTranslation;
762 }
763
764 /**
765 * @return true if in the last app transition had a clip reveal animation, false otherwise
766 */
767 boolean hadClipRevealAnimation() {
768 return mLastHadClipReveal;
769 }
770
771 /**
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800772 * Calculates the duration for the clip reveal animation. If the clip is "cut off", meaning that
773 * the start rect is outside of the target rect, and there is a lot of movement going on.
774 *
775 * @param cutOff whether the start rect was not fully contained by the end rect
776 * @param translationX the total translation the surface moves in x direction
777 * @param translationY the total translation the surfaces moves in y direction
778 * @param displayFrame our display frame
779 *
780 * @return the duration of the clip reveal animation, in milliseconds
781 */
782 private long calculateClipRevealTransitionDuration(boolean cutOff, float translationX,
783 float translationY, Rect displayFrame) {
784 if (!cutOff) {
785 return DEFAULT_APP_TRANSITION_DURATION;
786 }
787 final float fraction = Math.max(Math.abs(translationX) / displayFrame.width(),
788 Math.abs(translationY) / displayFrame.height());
789 return (long) (DEFAULT_APP_TRANSITION_DURATION + fraction *
790 (MAX_CLIP_REVEAL_TRANSITION_DURATION - DEFAULT_APP_TRANSITION_DURATION));
791 }
792
793 private Animation createClipRevealAnimationLocked(int transit, boolean enter, Rect appFrame,
794 Rect displayFrame) {
Chet Haase10e23ab2015-02-11 15:08:38 -0800795 final Animation anim;
796 if (enter) {
Craig Mautner80b1f642015-04-22 10:59:09 -0700797 final int appWidth = appFrame.width();
798 final int appHeight = appFrame.height();
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800799
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700800 // mTmpRect will contain an area around the launcher icon that was pressed. We will
Filip Gruszczynski82861362015-10-16 14:21:09 -0700801 // clip reveal from that area in the final area of the app.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700802 getDefaultNextAppTransitionStartRect(mTmpRect);
Craig Mautner80b1f642015-04-22 10:59:09 -0700803
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700804 float t = 0f;
805 if (appHeight > 0) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800806 t = (float) mTmpRect.top / displayFrame.height();
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700807 }
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800808 int translationY = mClipRevealTranslationY + (int)(displayFrame.height() / 7f * t);
809 int translationX = 0;
810 int translationYCorrection = translationY;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700811 int centerX = mTmpRect.centerX();
812 int centerY = mTmpRect.centerY();
813 int halfWidth = mTmpRect.width() / 2;
814 int halfHeight = mTmpRect.height() / 2;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800815 int clipStartX = centerX - halfWidth - appFrame.left;
816 int clipStartY = centerY - halfHeight - appFrame.top;
817 boolean cutOff = false;
818
819 // If the starting rectangle is fully or partially outside of the target rectangle, we
820 // need to start the clipping at the edge and then achieve the rest with translation
821 // and extending the clip rect from that edge.
822 if (appFrame.top > centerY - halfHeight) {
823 translationY = (centerY - halfHeight) - appFrame.top;
824 translationYCorrection = 0;
825 clipStartY = 0;
826 cutOff = true;
827 }
828 if (appFrame.left > centerX - halfWidth) {
829 translationX = (centerX - halfWidth) - appFrame.left;
830 clipStartX = 0;
831 cutOff = true;
832 }
833 if (appFrame.right < centerX + halfWidth) {
834 translationX = (centerX + halfWidth) - appFrame.right;
835 clipStartX = appWidth - mTmpRect.width();
836 cutOff = true;
837 }
838 final long duration = calculateClipRevealTransitionDuration(cutOff, translationX,
839 translationY, displayFrame);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700840
841 // Clip third of the from size of launch icon, expand to full width/height
Chet Haase10e23ab2015-02-11 15:08:38 -0800842 Animation clipAnimLR = new ClipRectLRAnimation(
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800843 clipStartX, clipStartX + mTmpRect.width(), 0, appWidth);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700844 clipAnimLR.setInterpolator(mClipHorizontalInterpolator);
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800845 clipAnimLR.setDuration((long) (duration / 2.5f));
Filip Gruszczynski82861362015-10-16 14:21:09 -0700846
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800847 TranslateAnimation translate = new TranslateAnimation(translationX, 0, translationY, 0);
848 translate.setInterpolator(cutOff ? TOUCH_RESPONSE_INTERPOLATOR
849 : mLinearOutSlowInInterpolator);
850 translate.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800851
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800852 Animation clipAnimTB = new ClipRectTBAnimation(
853 clipStartY, clipStartY + mTmpRect.height(),
854 0, appHeight,
855 translationYCorrection, 0,
856 mLinearOutSlowInInterpolator);
857 clipAnimTB.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
858 clipAnimTB.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800859
860 // Quick fade-in from icon to app window
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800861 final long alphaDuration = duration / 4;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700862 AlphaAnimation alpha = new AlphaAnimation(0.5f, 1);
Chet Haase10e23ab2015-02-11 15:08:38 -0800863 alpha.setDuration(alphaDuration);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700864 alpha.setInterpolator(mLinearOutSlowInInterpolator);
Chet Haase10e23ab2015-02-11 15:08:38 -0800865
866 AnimationSet set = new AnimationSet(false);
867 set.addAnimation(clipAnimLR);
868 set.addAnimation(clipAnimTB);
Filip Gruszczynski82861362015-10-16 14:21:09 -0700869 set.addAnimation(translate);
Chet Haase10e23ab2015-02-11 15:08:38 -0800870 set.addAnimation(alpha);
Filip Gruszczynski9e2cf5b2015-07-31 12:20:40 -0700871 set.setZAdjustment(Animation.ZORDER_TOP);
Chet Haase10e23ab2015-02-11 15:08:38 -0800872 set.initialize(appWidth, appHeight, appWidth, appHeight);
873 anim = set;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800874 mLastHadClipReveal = true;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800875 mLastClipRevealTransitionDuration = duration;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800876
877 // If the start rect was full inside the target rect (cutOff == false), we don't need
878 // to store the translation, because it's only used if cutOff == true.
879 mLastClipRevealMaxTranslation = cutOff
880 ? Math.max(Math.abs(translationY), Math.abs(translationX)) : 0;
Chet Haase10e23ab2015-02-11 15:08:38 -0800881 } else {
882 final long duration;
883 switch (transit) {
884 case TRANSIT_ACTIVITY_OPEN:
885 case TRANSIT_ACTIVITY_CLOSE:
886 duration = mConfigShortAnimTime;
887 break;
888 default:
889 duration = DEFAULT_APP_TRANSITION_DURATION;
890 break;
891 }
892 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
893 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
894 // If we are on top of the wallpaper, we need an animation that
895 // correctly handles the wallpaper staying static behind all of
896 // the animated elements. To do this, will just have the existing
897 // element fade out.
898 anim = new AlphaAnimation(1, 0);
899 anim.setDetachWallpaper(true);
900 } else {
901 // For normal animations, the exiting element just holds in place.
902 anim = new AlphaAnimation(1, 1);
903 }
904 anim.setInterpolator(mDecelerateInterpolator);
905 anim.setDuration(duration);
906 anim.setFillAfter(true);
907 }
908 return anim;
909 }
910
Winson Chung399f6202014-03-19 10:47:20 -0700911 /**
912 * Prepares the specified animation with a standard duration, interpolator, etc.
913 */
Winson Chung5393dff2014-05-08 14:25:43 -0700914 Animation prepareThumbnailAnimationWithDuration(Animation a, int appWidth, int appHeight,
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100915 long duration, Interpolator interpolator) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700916 if (duration > 0) {
917 a.setDuration(duration);
918 }
Winson Chung5393dff2014-05-08 14:25:43 -0700919 a.setFillAfter(true);
Jorim Jaggic69bd222016-03-15 14:38:37 +0100920 if (interpolator != null) {
921 a.setInterpolator(interpolator);
922 }
Winson Chung5393dff2014-05-08 14:25:43 -0700923 a.initialize(appWidth, appHeight, appWidth, appHeight);
924 return a;
925 }
926
927 /**
928 * Prepares the specified animation with a standard duration, interpolator, etc.
929 */
Winson Chung399f6202014-03-19 10:47:20 -0700930 Animation prepareThumbnailAnimation(Animation a, int appWidth, int appHeight, int transit) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800931 // Pick the desired duration. If this is an inter-activity transition,
932 // it is the standard duration for that. Otherwise we use the longer
933 // task transition duration.
Winson Chung5393dff2014-05-08 14:25:43 -0700934 final int duration;
Craig Mautner321bdf52012-12-18 09:53:24 -0800935 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800936 case TRANSIT_ACTIVITY_OPEN:
937 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800938 duration = mConfigShortAnimTime;
939 break;
940 default:
941 duration = DEFAULT_APP_TRANSITION_DURATION;
942 break;
943 }
Winson Chung5393dff2014-05-08 14:25:43 -0700944 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, duration,
945 mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800946 }
947
Winson Chung399f6202014-03-19 10:47:20 -0700948 /**
949 * Return the current thumbnail transition state.
950 */
951 int getThumbnailTransitionState(boolean enter) {
952 if (enter) {
953 if (mNextAppTransitionScaleUp) {
954 return THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
955 } else {
956 return THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN;
957 }
958 } else {
959 if (mNextAppTransitionScaleUp) {
960 return THUMBNAIL_TRANSITION_EXIT_SCALE_UP;
961 } else {
962 return THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN;
963 }
964 }
965 }
966
967 /**
Tony Mak64b8d562017-12-28 17:44:02 +0000968 * Creates an overlay with a background color and a thumbnail for the cross profile apps
969 * animation.
970 */
971 GraphicBuffer createCrossProfileAppsThumbnail(
972 @DrawableRes int thumbnailDrawableRes, Rect frame) {
973 final int width = frame.width();
974 final int height = frame.height();
975
John Reck519ad482018-02-12 17:08:48 -0800976 final Picture picture = new Picture();
977 final Canvas canvas = picture.beginRecording(width, height);
Tony Mak64b8d562017-12-28 17:44:02 +0000978 canvas.drawColor(Color.argb(0.6f, 0, 0, 0));
979 final int thumbnailSize = mService.mContext.getResources().getDimensionPixelSize(
980 com.android.internal.R.dimen.cross_profile_apps_thumbnail_size);
981 final Drawable drawable = mService.mContext.getDrawable(thumbnailDrawableRes);
982 drawable.setBounds(
983 (width - thumbnailSize) / 2,
984 (height - thumbnailSize) / 2,
985 (width + thumbnailSize) / 2,
986 (height + thumbnailSize) / 2);
987 drawable.draw(canvas);
John Reck519ad482018-02-12 17:08:48 -0800988 picture.endRecording();
Tony Mak64b8d562017-12-28 17:44:02 +0000989
John Reck519ad482018-02-12 17:08:48 -0800990 return Bitmap.createBitmap(picture).createGraphicBufferHandle();
Tony Mak64b8d562017-12-28 17:44:02 +0000991 }
992
993 Animation createCrossProfileAppsThumbnailAnimationLocked(Rect appRect) {
994 final Animation animation = loadAnimationRes(
995 "android", com.android.internal.R.anim.cross_profile_apps_thumbnail_enter);
996 return prepareThumbnailAnimationWithDuration(animation, appRect.width(),
997 appRect.height(), 0, null);
998 }
999
1000 /**
Winson Chung399f6202014-03-19 10:47:20 -07001001 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001002 * when a thumbnail is specified with the pending animation override.
Winson Chung399f6202014-03-19 10:47:20 -07001003 */
Jorim Jaggide63d442016-03-14 14:56:56 +01001004 Animation createThumbnailAspectScaleAnimationLocked(Rect appRect, @Nullable Rect contentInsets,
Winson Chungaa7fa012017-05-24 15:50:06 -07001005 GraphicBuffer thumbnailHeader, final int taskId, int uiMode, int orientation) {
Winson Chung399f6202014-03-19 10:47:20 -07001006 Animation a;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001007 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chung399f6202014-03-19 10:47:20 -07001008 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001009 final int thumbHeightI = thumbnailHeader.getHeight();
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -07001010 final int appWidth = appRect.width();
Winson Chung399f6202014-03-19 10:47:20 -07001011
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -07001012 float scaleW = appWidth / thumbWidth;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001013 getNextAppTransitionStartRect(taskId, mTmpRect);
Jorim Jaggi09072002016-03-25 16:48:42 -07001014 final float fromX;
Manu Cornet57b61492017-01-24 18:19:05 +09001015 float fromY;
Jorim Jaggi09072002016-03-25 16:48:42 -07001016 final float toX;
Manu Cornet57b61492017-01-24 18:19:05 +09001017 float toY;
Jorim Jaggi09072002016-03-25 16:48:42 -07001018 final float pivotX;
1019 final float pivotY;
Manu Cornetd7376802017-01-13 13:44:07 -08001020 if (shouldScaleDownThumbnailTransition(uiMode, orientation)) {
Jorim Jaggi09072002016-03-25 16:48:42 -07001021 fromX = mTmpRect.left;
1022 fromY = mTmpRect.top;
1023
1024 // For the curved translate animation to work, the pivot points needs to be at the
1025 // same absolute position as the one from the real surface.
1026 toX = mTmpRect.width() / 2 * (scaleW - 1f) + appRect.left;
1027 toY = appRect.height() / 2 * (1 - 1 / scaleW) + appRect.top;
1028 pivotX = mTmpRect.width() / 2;
1029 pivotY = appRect.height() / 2 / scaleW;
Manu Cornet57b61492017-01-24 18:19:05 +09001030 if (mGridLayoutRecentsEnabled) {
1031 // In the grid layout, the header is displayed above the thumbnail instead of
1032 // overlapping it.
1033 fromY -= thumbHeightI;
1034 toY -= thumbHeightI * scaleW;
1035 }
Jorim Jaggi09072002016-03-25 16:48:42 -07001036 } else {
1037 pivotX = 0;
1038 pivotY = 0;
1039 fromX = mTmpRect.left;
1040 fromY = mTmpRect.top;
1041 toX = appRect.left;
1042 toY = appRect.top;
1043 }
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001044 final long duration = getAspectScaleDuration();
1045 final Interpolator interpolator = getAspectScaleInterpolator();
Winson Chung399f6202014-03-19 10:47:20 -07001046 if (mNextAppTransitionScaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001047 // Animation up from the thumbnail to the full screen
Jorim Jaggi8448f332016-03-14 17:50:37 +01001048 Animation scale = new ScaleAnimation(1f, scaleW, 1f, scaleW, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001049 scale.setInterpolator(interpolator);
1050 scale.setDuration(duration);
Jorim Jaggic6c89a82016-01-28 17:48:21 -08001051 Animation alpha = new AlphaAnimation(1f, 0f);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001052 alpha.setInterpolator(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
1053 ? THUMBNAIL_DOCK_INTERPOLATOR : mThumbnailFadeOutInterpolator);
1054 alpha.setDuration(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
1055 ? duration / 2
1056 : duration);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001057 Animation translate = createCurvedMotion(fromX, toX, fromY, toY);
1058 translate.setInterpolator(interpolator);
1059 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -07001060
Jorim Jaggide63d442016-03-14 14:56:56 +01001061 mTmpFromClipRect.set(0, 0, thumbWidthI, thumbHeightI);
1062 mTmpToClipRect.set(appRect);
1063
1064 // Containing frame is in screen space, but we need the clip rect in the
1065 // app space.
1066 mTmpToClipRect.offsetTo(0, 0);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001067 mTmpToClipRect.right = (int) (mTmpToClipRect.right / scaleW);
1068 mTmpToClipRect.bottom = (int) (mTmpToClipRect.bottom / scaleW);
Jorim Jaggide63d442016-03-14 14:56:56 +01001069
1070 if (contentInsets != null) {
Jorim Jaggi8448f332016-03-14 17:50:37 +01001071 mTmpToClipRect.inset((int) (-contentInsets.left * scaleW),
1072 (int) (-contentInsets.top * scaleW),
1073 (int) (-contentInsets.right * scaleW),
1074 (int) (-contentInsets.bottom * scaleW));
Jorim Jaggide63d442016-03-14 14:56:56 +01001075 }
1076
1077 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001078 clipAnim.setInterpolator(interpolator);
1079 clipAnim.setDuration(duration);
Jorim Jaggide63d442016-03-14 14:56:56 +01001080
Winson Chung399f6202014-03-19 10:47:20 -07001081 // This AnimationSet uses the Interpolators assigned above.
1082 AnimationSet set = new AnimationSet(false);
1083 set.addAnimation(scale);
Manu Cornet57b61492017-01-24 18:19:05 +09001084 if (!mGridLayoutRecentsEnabled) {
1085 // In the grid layout, the header should be shown for the whole animation.
1086 set.addAnimation(alpha);
1087 }
Winson Chunga4ccb862014-08-22 15:26:27 -07001088 set.addAnimation(translate);
Jorim Jaggide63d442016-03-14 14:56:56 +01001089 set.addAnimation(clipAnim);
Winson Chung399f6202014-03-19 10:47:20 -07001090 a = set;
1091 } else {
Winson Chunga4ccb862014-08-22 15:26:27 -07001092 // Animation down from the full screen to the thumbnail
Jorim Jaggi8448f332016-03-14 17:50:37 +01001093 Animation scale = new ScaleAnimation(scaleW, 1f, scaleW, 1f, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001094 scale.setInterpolator(interpolator);
1095 scale.setDuration(duration);
Winson Chunga4ccb862014-08-22 15:26:27 -07001096 Animation alpha = new AlphaAnimation(0f, 1f);
1097 alpha.setInterpolator(mThumbnailFadeInInterpolator);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001098 alpha.setDuration(duration);
1099 Animation translate = createCurvedMotion(toX, fromX, toY, fromY);
1100 translate.setInterpolator(interpolator);
1101 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -07001102
Winson Chunga4ccb862014-08-22 15:26:27 -07001103 // This AnimationSet uses the Interpolators assigned above.
1104 AnimationSet set = new AnimationSet(false);
1105 set.addAnimation(scale);
Manu Cornet57b61492017-01-24 18:19:05 +09001106 if (!mGridLayoutRecentsEnabled) {
1107 // In the grid layout, the header should be shown for the whole animation.
1108 set.addAnimation(alpha);
1109 }
Winson Chunga4ccb862014-08-22 15:26:27 -07001110 set.addAnimation(translate);
1111 a = set;
1112
1113 }
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -07001114 return prepareThumbnailAnimationWithDuration(a, appWidth, appRect.height(), 0,
Jorim Jaggic69bd222016-03-15 14:38:37 +01001115 null);
Winson Chung399f6202014-03-19 10:47:20 -07001116 }
1117
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001118 private Animation createCurvedMotion(float fromX, float toX, float fromY, float toY) {
1119
1120 // Almost no x-change - use linear animation
Jorim Jaggic69bd222016-03-15 14:38:37 +01001121 if (Math.abs(toX - fromX) < 1f || mNextAppTransition != TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001122 return new TranslateAnimation(fromX, toX, fromY, toY);
1123 } else {
1124 final Path path = createCurvedPath(fromX, toX, fromY, toY);
1125 return new CurvedTranslateAnimation(path);
1126 }
1127 }
1128
1129 private Path createCurvedPath(float fromX, float toX, float fromY, float toY) {
1130 final Path path = new Path();
1131 path.moveTo(fromX, fromY);
Jorim Jaggi1f458fb2016-03-25 17:36:37 -07001132
1133 if (fromY > toY) {
1134 // If the object needs to go up, move it in horizontal direction first, then vertical.
1135 path.cubicTo(fromX, fromY, toX, 0.9f * fromY + 0.1f * toY, toX, toY);
1136 } else {
1137 // If the object needs to go down, move it in vertical direction first, then horizontal.
1138 path.cubicTo(fromX, fromY, fromX, 0.1f * fromY + 0.9f * toY, toX, toY);
1139 }
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001140 return path;
1141 }
1142
1143 private long getAspectScaleDuration() {
1144 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggic69bd222016-03-15 14:38:37 +01001145 return (long) (THUMBNAIL_APP_TRANSITION_DURATION * 1.35f);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001146 } else {
1147 return THUMBNAIL_APP_TRANSITION_DURATION;
1148 }
1149 }
1150
1151 private Interpolator getAspectScaleInterpolator() {
1152 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
1153 return mFastOutSlowInInterpolator;
1154 } else {
1155 return TOUCH_RESPONSE_INTERPOLATOR;
1156 }
1157 }
1158
Winson Chung399f6202014-03-19 10:47:20 -07001159 /**
1160 * This alternate animation is created when we are doing a thumbnail transition, for the
1161 * activity that is leaving, and the activity that is entering.
1162 */
Winson Chunga4ccb862014-08-22 15:26:27 -07001163 Animation createAspectScaledThumbnailEnterExitAnimationLocked(int thumbTransitState,
Winsonb2024762016-04-05 17:32:30 -07001164 int uiMode, int orientation, int transit, Rect containingFrame, Rect contentInsets,
Matthew Ng43db6d22017-06-27 15:29:39 -07001165 @Nullable Rect surfaceInsets, @Nullable Rect stableInsets, boolean freeform,
1166 int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -07001167 Animation a;
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001168 final int appWidth = containingFrame.width();
1169 final int appHeight = containingFrame.height();
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001170 getDefaultNextAppTransitionStartRect(mTmpRect);
1171 final int thumbWidthI = mTmpRect.width();
Winson Chung399f6202014-03-19 10:47:20 -07001172 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001173 final int thumbHeightI = mTmpRect.height();
Winson Chung399f6202014-03-19 10:47:20 -07001174 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
Winsoncbb625b2016-07-06 15:24:15 -07001175 final int thumbStartX = mTmpRect.left - containingFrame.left - contentInsets.left;
Winson21700932016-03-24 17:26:23 -07001176 final int thumbStartY = mTmpRect.top - containingFrame.top;
Winson Chung399f6202014-03-19 10:47:20 -07001177
1178 switch (thumbTransitState) {
Jorim Jaggi8448f332016-03-14 17:50:37 +01001179 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP:
1180 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1181 final boolean scaleUp = thumbTransitState == THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
1182 if (freeform && scaleUp) {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001183 a = createAspectScaledThumbnailEnterFreeformAnimationLocked(
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001184 containingFrame, surfaceInsets, taskId);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001185 } else if (freeform) {
1186 a = createAspectScaledThumbnailExitFreeformAnimationLocked(
1187 containingFrame, surfaceInsets, taskId);
Winson Chung2820c452014-04-15 15:34:44 -07001188 } else {
Winson21700932016-03-24 17:26:23 -07001189 AnimationSet set = new AnimationSet(true);
1190
1191 // In portrait, we scale to fit the width
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001192 mTmpFromClipRect.set(containingFrame);
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001193 mTmpToClipRect.set(containingFrame);
Jorim Jaggic6c89a82016-01-28 17:48:21 -08001194
1195 // Containing frame is in screen space, but we need the clip rect in the
1196 // app space.
1197 mTmpFromClipRect.offsetTo(0, 0);
1198 mTmpToClipRect.offsetTo(0, 0);
1199
1200 // Exclude insets region from the source clip.
1201 mTmpFromClipRect.inset(contentInsets);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001202 mNextAppTransitionInsets.set(contentInsets);
1203
Manu Cornetd7376802017-01-13 13:44:07 -08001204 if (shouldScaleDownThumbnailTransition(uiMode, orientation)) {
Jorim Jaggic69bd222016-03-15 14:38:37 +01001205 // We scale the width and clip to the top/left square
1206 float scale = thumbWidth /
1207 (appWidth - contentInsets.left - contentInsets.right);
Manu Cornetb68b7652017-01-23 19:37:53 +09001208 if (!mGridLayoutRecentsEnabled) {
1209 int unscaledThumbHeight = (int) (thumbHeight / scale);
1210 mTmpFromClipRect.bottom = mTmpFromClipRect.top + unscaledThumbHeight;
1211 }
Jorim Jaggic69bd222016-03-15 14:38:37 +01001212
1213 mNextAppTransitionInsets.set(contentInsets);
1214
Jorim Jaggi8448f332016-03-14 17:50:37 +01001215 Animation scaleAnim = new ScaleAnimation(
1216 scaleUp ? scale : 1, scaleUp ? 1 : scale,
1217 scaleUp ? scale : 1, scaleUp ? 1 : scale,
Jorim Jaggic69bd222016-03-15 14:38:37 +01001218 containingFrame.width() / 2f,
1219 containingFrame.height() / 2f + contentInsets.top);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001220 final float targetX = (mTmpRect.left - containingFrame.left);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001221 final float x = containingFrame.width() / 2f
1222 - containingFrame.width() / 2f * scale;
Jorim Jaggi8448f332016-03-14 17:50:37 +01001223 final float targetY = (mTmpRect.top - containingFrame.top);
Matthew Ng43db6d22017-06-27 15:29:39 -07001224 float y = containingFrame.height() / 2f
Jorim Jaggic69bd222016-03-15 14:38:37 +01001225 - containingFrame.height() / 2f * scale;
Matthew Ng43db6d22017-06-27 15:29:39 -07001226
1227 // During transition may require clipping offset from any top stable insets
1228 // such as the statusbar height when statusbar is hidden
1229 if (mLowRamRecentsEnabled && contentInsets.top == 0 && scaleUp) {
1230 mTmpFromClipRect.top += stableInsets.top;
1231 y += stableInsets.top;
1232 }
Jorim Jaggi8448f332016-03-14 17:50:37 +01001233 final float startX = targetX - x;
1234 final float startY = targetY - y;
1235 Animation clipAnim = scaleUp
1236 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1237 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1238 Animation translateAnim = scaleUp
Jorim Jaggic69bd222016-03-15 14:38:37 +01001239 ? createCurvedMotion(startX, 0, startY - contentInsets.top, 0)
1240 : createCurvedMotion(0, startX, 0, startY - contentInsets.top);
1241
Winson21700932016-03-24 17:26:23 -07001242 set.addAnimation(clipAnim);
1243 set.addAnimation(scaleAnim);
1244 set.addAnimation(translateAnim);
1245
1246 } else {
1247 // In landscape, we don't scale at all and only crop
1248 mTmpFromClipRect.bottom = mTmpFromClipRect.top + thumbHeightI;
1249 mTmpFromClipRect.right = mTmpFromClipRect.left + thumbWidthI;
1250
Jorim Jaggi8448f332016-03-14 17:50:37 +01001251 Animation clipAnim = scaleUp
1252 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1253 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1254 Animation translateAnim = scaleUp
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001255 ? createCurvedMotion(thumbStartX, 0,
1256 thumbStartY - contentInsets.top, 0)
1257 : createCurvedMotion(0, thumbStartX, 0,
1258 thumbStartY - contentInsets.top);
Winson21700932016-03-24 17:26:23 -07001259
1260 set.addAnimation(clipAnim);
1261 set.addAnimation(translateAnim);
1262 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001263 a = set;
Winson21700932016-03-24 17:26:23 -07001264 a.setZAdjustment(Animation.ZORDER_TOP);
Winson Chung2820c452014-04-15 15:34:44 -07001265 }
Winson Chung399f6202014-03-19 10:47:20 -07001266 break;
1267 }
1268 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001269 // Previous app window during the scale up
Winson Chung399f6202014-03-19 10:47:20 -07001270 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001271 // Fade out the source activity if we are animating to a wallpaper
Winson Chung399f6202014-03-19 10:47:20 -07001272 // activity.
1273 a = new AlphaAnimation(1, 0);
1274 } else {
Winson Chung399f6202014-03-19 10:47:20 -07001275 a = new AlphaAnimation(1, 1);
1276 }
1277 break;
1278 }
1279 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001280 // Target app window during the scale down
1281 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1282 // Fade in the destination activity if we are animating from a wallpaper
1283 // activity.
1284 a = new AlphaAnimation(0, 1);
1285 } else {
1286 a = new AlphaAnimation(1, 1);
1287 }
Winson Chung399f6202014-03-19 10:47:20 -07001288 break;
1289 }
Winson Chung399f6202014-03-19 10:47:20 -07001290 default:
1291 throw new RuntimeException("Invalid thumbnail transition state");
1292 }
1293
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001294 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight,
1295 getAspectScaleDuration(), getAspectScaleInterpolator());
Winson Chung399f6202014-03-19 10:47:20 -07001296 }
1297
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001298 private Animation createAspectScaledThumbnailEnterFreeformAnimationLocked(Rect frame,
1299 @Nullable Rect surfaceInsets, int taskId) {
1300 getNextAppTransitionStartRect(taskId, mTmpRect);
1301 return createAspectScaledThumbnailFreeformAnimationLocked(mTmpRect, frame, surfaceInsets,
1302 true);
1303 }
1304
1305 private Animation createAspectScaledThumbnailExitFreeformAnimationLocked(Rect frame,
1306 @Nullable Rect surfaceInsets, int taskId) {
1307 getNextAppTransitionStartRect(taskId, mTmpRect);
1308 return createAspectScaledThumbnailFreeformAnimationLocked(frame, mTmpRect, surfaceInsets,
1309 false);
1310 }
1311
1312 private AnimationSet createAspectScaledThumbnailFreeformAnimationLocked(Rect sourceFrame,
1313 Rect destFrame, @Nullable Rect surfaceInsets, boolean enter) {
1314 final float sourceWidth = sourceFrame.width();
1315 final float sourceHeight = sourceFrame.height();
1316 final float destWidth = destFrame.width();
1317 final float destHeight = destFrame.height();
1318 final float scaleH = enter ? sourceWidth / destWidth : destWidth / sourceWidth;
1319 final float scaleV = enter ? sourceHeight / destHeight : destHeight / sourceHeight;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001320 AnimationSet set = new AnimationSet(true);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001321 final int surfaceInsetsH = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001322 ? 0 : surfaceInsets.left + surfaceInsets.right;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001323 final int surfaceInsetsV = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001324 ? 0 : surfaceInsets.top + surfaceInsets.bottom;
1325 // We want the scaling to happen from the center of the surface. In order to achieve that,
1326 // we need to account for surface insets that will be used to enlarge the surface.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001327 final float scaleHCenter = ((enter ? destWidth : sourceWidth) + surfaceInsetsH) / 2;
1328 final float scaleVCenter = ((enter ? destHeight : sourceHeight) + surfaceInsetsV) / 2;
1329 final ScaleAnimation scale = enter ?
1330 new ScaleAnimation(scaleH, 1, scaleV, 1, scaleHCenter, scaleVCenter)
1331 : new ScaleAnimation(1, scaleH, 1, scaleV, scaleHCenter, scaleVCenter);
1332 final int sourceHCenter = sourceFrame.left + sourceFrame.width() / 2;
1333 final int sourceVCenter = sourceFrame.top + sourceFrame.height() / 2;
1334 final int destHCenter = destFrame.left + destFrame.width() / 2;
1335 final int destVCenter = destFrame.top + destFrame.height() / 2;
1336 final int fromX = enter ? sourceHCenter - destHCenter : destHCenter - sourceHCenter;
1337 final int fromY = enter ? sourceVCenter - destVCenter : destVCenter - sourceVCenter;
1338 final TranslateAnimation translation = enter ? new TranslateAnimation(fromX, 0, fromY, 0)
1339 : new TranslateAnimation(0, fromX, 0, fromY);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001340 set.addAnimation(scale);
1341 set.addAnimation(translation);
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001342
1343 final IRemoteCallback callback = mAnimationFinishedCallback;
1344 if (callback != null) {
1345 set.setAnimationListener(new Animation.AnimationListener() {
1346 @Override
1347 public void onAnimationStart(Animation animation) { }
1348
1349 @Override
1350 public void onAnimationEnd(Animation animation) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001351 mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK, callback).sendToTarget();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001352 }
1353
1354 @Override
1355 public void onAnimationRepeat(Animation animation) { }
1356 });
1357 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001358 return set;
1359 }
1360
Winson Chung399f6202014-03-19 10:47:20 -07001361 /**
Winson Chunga4ccb862014-08-22 15:26:27 -07001362 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001363 * when a thumbnail is specified with the pending animation override.
Winson Chunga4ccb862014-08-22 15:26:27 -07001364 */
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001365 Animation createThumbnailScaleAnimationLocked(int appWidth, int appHeight, int transit,
Winson Chungaa7fa012017-05-24 15:50:06 -07001366 GraphicBuffer thumbnailHeader) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001367 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001368 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001369 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chunga4ccb862014-08-22 15:26:27 -07001370 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001371 final int thumbHeightI = thumbnailHeader.getHeight();
Winson Chunga4ccb862014-08-22 15:26:27 -07001372 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1373
1374 if (mNextAppTransitionScaleUp) {
1375 // Animation for the thumbnail zooming from its initial size to the full screen
1376 float scaleW = appWidth / thumbWidth;
1377 float scaleH = appHeight / thumbHeight;
1378 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001379 computePivot(mTmpRect.left, 1 / scaleW),
1380 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001381 scale.setInterpolator(mDecelerateInterpolator);
1382
1383 Animation alpha = new AlphaAnimation(1, 0);
1384 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
1385
1386 // This AnimationSet uses the Interpolators assigned above.
1387 AnimationSet set = new AnimationSet(false);
1388 set.addAnimation(scale);
1389 set.addAnimation(alpha);
1390 a = set;
1391 } else {
1392 // Animation for the thumbnail zooming down from the full screen to its final size
1393 float scaleW = appWidth / thumbWidth;
1394 float scaleH = appHeight / thumbHeight;
1395 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001396 computePivot(mTmpRect.left, 1 / scaleW),
1397 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001398 }
1399
1400 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1401 }
1402
1403 /**
Winson Chung399f6202014-03-19 10:47:20 -07001404 * This animation is created when we are doing a thumbnail transition, for the activity that is
1405 * leaving, and the activity that is entering.
1406 */
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001407 Animation createThumbnailEnterExitAnimationLocked(int thumbTransitState, Rect containingFrame,
1408 int transit, int taskId) {
1409 final int appWidth = containingFrame.width();
1410 final int appHeight = containingFrame.height();
Winson Chungaa7fa012017-05-24 15:50:06 -07001411 final GraphicBuffer thumbnailHeader = getAppTransitionThumbnailHeader(taskId);
Winson Chung399f6202014-03-19 10:47:20 -07001412 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001413 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001414 final int thumbWidthI = thumbnailHeader != null ? thumbnailHeader.getWidth() : appWidth;
Winson Chung399f6202014-03-19 10:47:20 -07001415 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001416 final int thumbHeightI = thumbnailHeader != null ? thumbnailHeader.getHeight() : appHeight;
Winson Chung399f6202014-03-19 10:47:20 -07001417 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1418
1419 switch (thumbTransitState) {
1420 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
1421 // Entering app scales up with the thumbnail
1422 float scaleW = thumbWidth / appWidth;
1423 float scaleH = thumbHeight / appHeight;
1424 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001425 computePivot(mTmpRect.left, scaleW),
1426 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001427 break;
1428 }
1429 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
1430 // Exiting app while the thumbnail is scaling up should fade or stay in place
1431 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1432 // Fade out while bringing up selected activity. This keeps the
1433 // current activity from showing through a launching wallpaper
1434 // activity.
1435 a = new AlphaAnimation(1, 0);
1436 } else {
1437 // noop animation
1438 a = new AlphaAnimation(1, 1);
1439 }
1440 break;
1441 }
1442 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
1443 // Entering the other app, it should just be visible while we scale the thumbnail
1444 // down above it
1445 a = new AlphaAnimation(1, 1);
1446 break;
1447 }
1448 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1449 // Exiting the current app, the app should scale down with the thumbnail
1450 float scaleW = thumbWidth / appWidth;
1451 float scaleH = thumbHeight / appHeight;
1452 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001453 computePivot(mTmpRect.left, scaleW),
1454 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001455
1456 Animation alpha = new AlphaAnimation(1, 0);
1457
1458 AnimationSet set = new AnimationSet(true);
1459 set.addAnimation(scale);
1460 set.addAnimation(alpha);
1461 set.setZAdjustment(Animation.ZORDER_TOP);
1462 a = set;
1463 break;
1464 }
1465 default:
1466 throw new RuntimeException("Invalid thumbnail transition state");
1467 }
1468
1469 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1470 }
1471
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001472 private Animation createRelaunchAnimation(Rect containingFrame, Rect contentInsets) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001473 getDefaultNextAppTransitionStartRect(mTmpFromClipRect);
1474 final int left = mTmpFromClipRect.left;
1475 final int top = mTmpFromClipRect.top;
1476 mTmpFromClipRect.offset(-left, -top);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001477 // TODO: Isn't that strange that we ignore exact position of the containingFrame?
1478 mTmpToClipRect.set(0, 0, containingFrame.width(), containingFrame.height());
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001479 AnimationSet set = new AnimationSet(true);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001480 float fromWidth = mTmpFromClipRect.width();
1481 float toWidth = mTmpToClipRect.width();
1482 float fromHeight = mTmpFromClipRect.height();
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001483 // While the window might span the whole display, the actual content will be cropped to the
1484 // system decoration frame, for example when the window is docked. We need to take into
1485 // account the visible height when constructing the animation.
1486 float toHeight = mTmpToClipRect.height() - contentInsets.top - contentInsets.bottom;
1487 int translateAdjustment = 0;
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001488 if (fromWidth <= toWidth && fromHeight <= toHeight) {
1489 // The final window is larger in both dimensions than current window (e.g. we are
1490 // maximizing), so we can simply unclip the new window and there will be no disappearing
1491 // frame.
1492 set.addAnimation(new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect));
1493 } else {
1494 // The disappearing window has one larger dimension. We need to apply scaling, so the
1495 // first frame of the entry animation matches the old window.
1496 set.addAnimation(new ScaleAnimation(fromWidth / toWidth, 1, fromHeight / toHeight, 1));
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001497 // We might not be going exactly full screen, but instead be aligned under the status
1498 // bar using cropping. We still need to account for the cropped part, which will also
1499 // be scaled.
1500 translateAdjustment = (int) (contentInsets.top * fromHeight / toHeight);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001501 }
1502
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001503 // We animate the translation from the old position of the removed window, to the new
1504 // position of the added window. The latter might not be full screen, for example docked for
1505 // docked windows.
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001506 TranslateAnimation translate = new TranslateAnimation(left - containingFrame.left,
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001507 0, top - containingFrame.top - translateAdjustment, 0);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001508 set.addAnimation(translate);
1509 set.setDuration(DEFAULT_APP_TRANSITION_DURATION);
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07001510 set.setZAdjustment(Animation.ZORDER_TOP);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001511 return set;
1512 }
1513
Jorim Jaggic554b772015-06-04 16:07:57 -07001514 /**
1515 * @return true if and only if the first frame of the transition can be skipped, i.e. the first
1516 * frame of the transition doesn't change the visuals on screen, so we can start
1517 * directly with the second one
1518 */
1519 boolean canSkipFirstFrame() {
1520 return mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM
1521 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE
Jorim Jaggife762342016-10-13 14:33:27 +02001522 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CLIP_REVEAL
1523 && mNextAppTransition != TRANSIT_KEYGUARD_GOING_AWAY;
Jorim Jaggic554b772015-06-04 16:07:57 -07001524 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001525
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001526 RemoteAnimationController getRemoteAnimationController() {
1527 return mRemoteAnimationController;
1528 }
1529
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001530 /**
1531 *
1532 * @param frame These are the bounds of the window when it finishes the animation. This is where
1533 * the animation must usually finish in entrance animation, as the next frame will
1534 * display the window at these coordinates. In case of exit animation, this is
1535 * where the animation must start, as the frame before the animation is displaying
1536 * the window at these bounds.
1537 * @param insets Knowing where the window will be positioned is not enough. Some parts of the
1538 * window might be obscured, usually by the system windows (status bar and
1539 * navigation bar) and we use content insets to convey that information. This
1540 * usually affects the animation aspects vertically, as the system decoration is
1541 * at the top and the bottom. For example when we animate from full screen to
1542 * recents, we want to exclude the covered parts, because they won't match the
1543 * thumbnail after the last frame is executed.
1544 * @param surfaceInsets In rare situation the surface is larger than the content and we need to
1545 * know about this to make the animation frames match. We currently use
1546 * this for freeform windows, which have larger surfaces to display
1547 * shadows. When we animate them from recents, we want to match the content
1548 * to the recents thumbnail and hence need to account for the surface being
1549 * bigger.
1550 */
Jorim Jaggif84e2f62018-01-16 14:17:59 +01001551 Animation loadAnimation(LayoutParams lp, int transit, boolean enter, int uiMode,
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001552 int orientation, Rect frame, Rect displayFrame, Rect insets,
Matthew Ng43db6d22017-06-27 15:29:39 -07001553 @Nullable Rect surfaceInsets, @Nullable Rect stableInsets, boolean isVoiceInteraction,
1554 boolean freeform, int taskId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001555 Animation a;
Jorim Jaggife762342016-10-13 14:33:27 +02001556 if (isKeyguardGoingAwayTransit(transit) && enter) {
1557 a = loadKeyguardExitAnimation(transit);
1558 } else if (transit == TRANSIT_KEYGUARD_OCCLUDE) {
1559 a = null;
1560 } else if (transit == TRANSIT_KEYGUARD_UNOCCLUDE && !enter) {
1561 a = loadAnimationRes(lp, com.android.internal.R.anim.wallpaper_open_exit);
Adrian Roos93577212018-04-10 14:12:10 -07001562 } else if (transit == TRANSIT_CRASHING_ACTIVITY_CLOSE) {
1563 a = null;
Jorim Jaggife762342016-10-13 14:33:27 +02001564 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_OPEN
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001565 || transit == TRANSIT_TASK_OPEN
1566 || transit == TRANSIT_TASK_TO_FRONT)) {
1567 a = loadAnimationRes(lp, enter
1568 ? com.android.internal.R.anim.voice_activity_open_enter
1569 : com.android.internal.R.anim.voice_activity_open_exit);
1570 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1571 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001572 + " anim=" + a + " transit=" + appTransitionToString(transit)
1573 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001574 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_CLOSE
1575 || transit == TRANSIT_TASK_CLOSE
1576 || transit == TRANSIT_TASK_TO_BACK)) {
1577 a = loadAnimationRes(lp, enter
1578 ? com.android.internal.R.anim.voice_activity_close_enter
1579 : com.android.internal.R.anim.voice_activity_close_exit);
1580 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1581 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001582 + " anim=" + a + " transit=" + appTransitionToString(transit)
1583 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001584 } else if (transit == TRANSIT_ACTIVITY_RELAUNCH) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001585 a = createRelaunchAnimation(frame, insets);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001586 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1587 "applyAnimation:"
1588 + " anim=" + a + " nextAppTransition=" + mNextAppTransition
1589 + " transit=" + appTransitionToString(transit)
1590 + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001591 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM) {
1592 a = loadAnimationRes(mNextAppTransitionPackage, enter ?
Craig Mautner164d4bb2012-11-26 13:51:23 -08001593 mNextAppTransitionEnter : mNextAppTransitionExit);
1594 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1595 "applyAnimation:"
1596 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001597 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001598 + " Callers=" + Debug.getCallers(3));
Winson Chung044d5292014-11-06 11:05:19 -08001599 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE) {
1600 a = loadAnimationRes(mNextAppTransitionPackage, mNextAppTransitionInPlace);
1601 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1602 "applyAnimation:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001603 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM_IN_PLACE"
1604 + " transit=" + appTransitionToString(transit)
1605 + " Callers=" + Debug.getCallers(3));
Chet Haase10e23ab2015-02-11 15:08:38 -08001606 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001607 a = createClipRevealAnimationLocked(transit, enter, frame, displayFrame);
Chet Haase10e23ab2015-02-11 15:08:38 -08001608 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1609 "applyAnimation:"
1610 + " anim=" + a + " nextAppTransition=ANIM_CLIP_REVEAL"
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001611 + " transit=" + appTransitionToString(transit)
Chet Haase10e23ab2015-02-11 15:08:38 -08001612 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001613 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_SCALE_UP) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001614 a = createScaleUpAnimationLocked(transit, enter, frame);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001615 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1616 "applyAnimation:"
1617 + " anim=" + a + " nextAppTransition=ANIM_SCALE_UP"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001618 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001619 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001620 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
1621 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001622 mNextAppTransitionScaleUp =
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001623 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP);
Winson Chunga4ccb862014-08-22 15:26:27 -07001624 a = createThumbnailEnterExitAnimationLocked(getThumbnailTransitionState(enter),
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001625 frame, transit, taskId);
Winson Chunga4ccb862014-08-22 15:26:27 -07001626 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1627 String animName = mNextAppTransitionScaleUp ?
1628 "ANIM_THUMBNAIL_SCALE_UP" : "ANIM_THUMBNAIL_SCALE_DOWN";
1629 Slog.v(TAG, "applyAnimation:"
1630 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001631 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Winson Chunga4ccb862014-08-22 15:26:27 -07001632 + " Callers=" + Debug.getCallers(3));
1633 }
1634 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
1635 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN) {
1636 mNextAppTransitionScaleUp =
1637 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP);
1638 a = createAspectScaledThumbnailEnterExitAnimationLocked(
Winsonb2024762016-04-05 17:32:30 -07001639 getThumbnailTransitionState(enter), uiMode, orientation, transit, frame,
Matthew Ng43db6d22017-06-27 15:29:39 -07001640 insets, surfaceInsets, stableInsets, freeform, taskId);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001641 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1642 String animName = mNextAppTransitionScaleUp ?
Winson Chunga4ccb862014-08-22 15:26:27 -07001643 "ANIM_THUMBNAIL_ASPECT_SCALE_UP" : "ANIM_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner164d4bb2012-11-26 13:51:23 -08001644 Slog.v(TAG, "applyAnimation:"
1645 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001646 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001647 + " Callers=" + Debug.getCallers(3));
1648 }
Tony Mak83546a82018-01-22 13:56:20 +00001649 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS && enter) {
Jorim Jaggi98a9d202018-03-26 16:17:07 +02001650 a = loadAnimationRes("android",
1651 com.android.internal.R.anim.task_open_enter_cross_profile_apps);
Tony Mak089c35e2017-12-18 20:34:14 +00001652 Slog.v(TAG,
1653 "applyAnimation NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS:"
1654 + " anim=" + a + " transit=" + appTransitionToString(transit)
Jorim Jaggi98a9d202018-03-26 16:17:07 +02001655 + " isEntrance=true" + " Callers=" + Debug.getCallers(3));
Craig Mautner164d4bb2012-11-26 13:51:23 -08001656 } else {
1657 int animAttr = 0;
1658 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001659 case TRANSIT_ACTIVITY_OPEN:
Jorim Jaggi0a1523d2018-04-19 17:48:38 +02001660 case TRANSIT_TRANSLUCENT_ACTIVITY_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001661 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001662 ? WindowAnimation_activityOpenEnterAnimation
1663 : WindowAnimation_activityOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001664 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001665 case TRANSIT_ACTIVITY_CLOSE:
Jorim Jaggi0a1523d2018-04-19 17:48:38 +02001666 case TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001667 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001668 ? WindowAnimation_activityCloseEnterAnimation
1669 : WindowAnimation_activityCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001670 break;
Jorim Jaggi192086e2016-03-11 17:17:03 +01001671 case TRANSIT_DOCK_TASK_FROM_RECENTS:
Craig Mautner4b71aa12012-12-27 17:20:01 -08001672 case TRANSIT_TASK_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001673 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001674 ? WindowAnimation_taskOpenEnterAnimation
1675 : WindowAnimation_taskOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001676 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001677 case TRANSIT_TASK_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001678 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001679 ? WindowAnimation_taskCloseEnterAnimation
1680 : WindowAnimation_taskCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001681 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001682 case TRANSIT_TASK_TO_FRONT:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001683 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001684 ? WindowAnimation_taskToFrontEnterAnimation
1685 : WindowAnimation_taskToFrontExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001686 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001687 case TRANSIT_TASK_TO_BACK:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001688 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001689 ? WindowAnimation_taskToBackEnterAnimation
1690 : WindowAnimation_taskToBackExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001691 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001692 case TRANSIT_WALLPAPER_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001693 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001694 ? WindowAnimation_wallpaperOpenEnterAnimation
1695 : WindowAnimation_wallpaperOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001696 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001697 case TRANSIT_WALLPAPER_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001698 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001699 ? WindowAnimation_wallpaperCloseEnterAnimation
1700 : WindowAnimation_wallpaperCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001701 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001702 case TRANSIT_WALLPAPER_INTRA_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001703 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001704 ? WindowAnimation_wallpaperIntraOpenEnterAnimation
1705 : WindowAnimation_wallpaperIntraOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001706 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001707 case TRANSIT_WALLPAPER_INTRA_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001708 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001709 ? WindowAnimation_wallpaperIntraCloseEnterAnimation
1710 : WindowAnimation_wallpaperIntraCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001711 break;
Craig Mautnerbb742462014-07-07 15:28:55 -07001712 case TRANSIT_TASK_OPEN_BEHIND:
1713 animAttr = enter
1714 ? WindowAnimation_launchTaskBehindSourceAnimation
Craig Mautner3b2cd1d2014-08-25 14:25:54 -07001715 : WindowAnimation_launchTaskBehindTargetAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001716 }
Jorim Jaggi0a1523d2018-04-19 17:48:38 +02001717 a = animAttr != 0 ? loadAnimationAttr(lp, animAttr, transit) : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001718 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1719 "applyAnimation:"
1720 + " anim=" + a
1721 + " animAttr=0x" + Integer.toHexString(animAttr)
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001722 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001723 + " Callers=" + Debug.getCallers(3));
1724 }
1725 return a;
1726 }
1727
Jorim Jaggife762342016-10-13 14:33:27 +02001728 private Animation loadKeyguardExitAnimation(int transit) {
1729 if ((mNextAppTransitionFlags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_NO_ANIMATION) != 0) {
1730 return null;
1731 }
1732 final boolean toShade =
1733 (mNextAppTransitionFlags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_TO_SHADE) != 0;
1734 return mService.mPolicy.createHiddenByKeyguardExit(
1735 transit == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER, toShade);
1736 }
1737
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001738 int getAppStackClipMode() {
Matthew Ngbf1d9852017-03-14 12:23:09 -07001739 // When dismiss keyguard animation occurs, clip before the animation to prevent docked
1740 // app from showing beyond the divider
1741 if (mNextAppTransition == TRANSIT_KEYGUARD_GOING_AWAY
1742 || mNextAppTransition == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER) {
1743 return STACK_CLIP_BEFORE_ANIM;
1744 }
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001745 return mNextAppTransition == TRANSIT_ACTIVITY_RELAUNCH
Jorim Jaggic69bd222016-03-15 14:38:37 +01001746 || mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
Jorim Jaggi1f458fb2016-03-25 17:36:37 -07001747 || mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001748 ? STACK_CLIP_NONE
1749 : STACK_CLIP_AFTER_ANIM;
1750 }
1751
Jorim Jaggife762342016-10-13 14:33:27 +02001752 public int getTransitFlags() {
1753 return mNextAppTransitionFlags;
1754 }
1755
Craig Mautner164d4bb2012-11-26 13:51:23 -08001756 void postAnimationCallback() {
1757 if (mNextAppTransitionCallback != null) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001758 mService.mH.sendMessage(mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK,
1759 mNextAppTransitionCallback));
Craig Mautner164d4bb2012-11-26 13:51:23 -08001760 mNextAppTransitionCallback = null;
1761 }
1762 }
1763
1764 void overridePendingAppTransition(String packageName, int enterAnim, int exitAnim,
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001765 IRemoteCallback startedCallback) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001766 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001767 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001768 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001769 mNextAppTransitionPackage = packageName;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001770 mNextAppTransitionEnter = enterAnim;
1771 mNextAppTransitionExit = exitAnim;
1772 postAnimationCallback();
1773 mNextAppTransitionCallback = startedCallback;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001774 }
1775 }
1776
1777 void overridePendingAppTransitionScaleUp(int startX, int startY, int startWidth,
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001778 int startHeight) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001779 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001780 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001781 mNextAppTransitionType = NEXT_TRANSIT_TYPE_SCALE_UP;
Winson4c3fecd2016-07-13 12:29:48 -07001782 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001783 postAnimationCallback();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001784 }
1785 }
1786
Chet Haase10e23ab2015-02-11 15:08:38 -08001787 void overridePendingAppTransitionClipReveal(int startX, int startY,
1788 int startWidth, int startHeight) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001789 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001790 clear();
Chet Haase10e23ab2015-02-11 15:08:38 -08001791 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CLIP_REVEAL;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001792 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Chet Haase10e23ab2015-02-11 15:08:38 -08001793 postAnimationCallback();
Chet Haase10e23ab2015-02-11 15:08:38 -08001794 }
1795 }
1796
Winson Chungaa7fa012017-05-24 15:50:06 -07001797 void overridePendingAppTransitionThumb(GraphicBuffer srcThumb, int startX, int startY,
Craig Mautner164d4bb2012-11-26 13:51:23 -08001798 IRemoteCallback startedCallback, boolean scaleUp) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001799 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001800 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001801 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP
1802 : NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001803 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001804 putDefaultNextAppTransitionCoordinates(startX, startY, 0, 0, srcThumb);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001805 postAnimationCallback();
1806 mNextAppTransitionCallback = startedCallback;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001807 }
1808 }
1809
Winson Chungaa7fa012017-05-24 15:50:06 -07001810 void overridePendingAppTransitionAspectScaledThumb(GraphicBuffer srcThumb, int startX, int startY,
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001811 int targetWidth, int targetHeight, IRemoteCallback startedCallback, boolean scaleUp) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001812 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001813 clear();
Winson Chunga4ccb862014-08-22 15:26:27 -07001814 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1815 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Winson Chunga4ccb862014-08-22 15:26:27 -07001816 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001817 putDefaultNextAppTransitionCoordinates(startX, startY, targetWidth, targetHeight,
1818 srcThumb);
Winson Chunga4ccb862014-08-22 15:26:27 -07001819 postAnimationCallback();
1820 mNextAppTransitionCallback = startedCallback;
Winson Chunga4ccb862014-08-22 15:26:27 -07001821 }
1822 }
1823
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001824 void overridePendingAppTransitionMultiThumb(AppTransitionAnimationSpec[] specs,
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001825 IRemoteCallback onAnimationStartedCallback, IRemoteCallback onAnimationFinishedCallback,
1826 boolean scaleUp) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001827 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001828 clear();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001829 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1830 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001831 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi43102412015-11-11 16:28:37 +01001832 if (specs != null) {
1833 for (int i = 0; i < specs.length; i++) {
1834 AppTransitionAnimationSpec spec = specs[i];
1835 if (spec != null) {
1836 mNextAppTransitionAnimationsSpecs.put(spec.taskId, spec);
1837 if (i == 0) {
1838 // In full screen mode, the transition code depends on the default spec
1839 // to be set.
1840 Rect rect = spec.rect;
1841 putDefaultNextAppTransitionCoordinates(rect.left, rect.top,
Winson Chungaa7fa012017-05-24 15:50:06 -07001842 rect.width(), rect.height(), spec.buffer);
Jorim Jaggi43102412015-11-11 16:28:37 +01001843 }
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001844 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001845 }
1846 }
1847 postAnimationCallback();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001848 mNextAppTransitionCallback = onAnimationStartedCallback;
1849 mAnimationFinishedCallback = onAnimationFinishedCallback;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001850 }
1851 }
1852
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001853 void overridePendingAppTransitionMultiThumbFuture(
1854 IAppTransitionAnimationSpecsFuture specsFuture, IRemoteCallback callback,
1855 boolean scaleUp) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001856 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001857 clear();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001858 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1859 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001860 mNextAppTransitionAnimationsSpecsFuture = specsFuture;
1861 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001862 mNextAppTransitionFutureCallback = callback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001863 }
1864 }
1865
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001866 void overridePendingAppTransitionRemote(RemoteAnimationAdapter remoteAnimationAdapter) {
Winson Chung044d5292014-11-06 11:05:19 -08001867 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001868 clear();
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001869 mNextAppTransitionType = NEXT_TRANSIT_TYPE_REMOTE;
1870 mRemoteAnimationController = new RemoteAnimationController(mService,
1871 remoteAnimationAdapter, mService.mH);
1872 }
1873 }
1874
1875 void overrideInPlaceAppTransition(String packageName, int anim) {
1876 if (canOverridePendingAppTransition()) {
1877 clear();
Winson Chung044d5292014-11-06 11:05:19 -08001878 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE;
1879 mNextAppTransitionPackage = packageName;
1880 mNextAppTransitionInPlace = anim;
Winson Chung044d5292014-11-06 11:05:19 -08001881 }
1882 }
1883
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001884 /**
Tony Mak089c35e2017-12-18 20:34:14 +00001885 * @see {@link #NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS}
1886 */
1887 void overridePendingAppTransitionStartCrossProfileApps() {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001888 if (canOverridePendingAppTransition()) {
Tony Mak089c35e2017-12-18 20:34:14 +00001889 clear();
1890 mNextAppTransitionType = NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS;
1891 postAnimationCallback();
1892 }
1893 }
1894
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001895 private boolean canOverridePendingAppTransition() {
1896 // Remote animations always take precedence
1897 return isTransitionSet() && mNextAppTransitionType != NEXT_TRANSIT_TYPE_REMOTE;
1898 }
1899
Tony Mak089c35e2017-12-18 20:34:14 +00001900 /**
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001901 * If a future is set for the app transition specs, fetch it in another thread.
1902 */
1903 private void fetchAppTransitionSpecsFromFuture() {
1904 if (mNextAppTransitionAnimationsSpecsFuture != null) {
1905 mNextAppTransitionAnimationsSpecsPending = true;
1906 final IAppTransitionAnimationSpecsFuture future
1907 = mNextAppTransitionAnimationsSpecsFuture;
1908 mNextAppTransitionAnimationsSpecsFuture = null;
Jorim Jaggied410b62017-05-05 15:16:14 +02001909 mDefaultExecutor.execute(() -> {
1910 AppTransitionAnimationSpec[] specs = null;
1911 try {
1912 Binder.allowBlocking(future.asBinder());
1913 specs = future.get();
1914 } catch (RemoteException e) {
1915 Slog.w(TAG, "Failed to fetch app transition specs: " + e);
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001916 }
Jorim Jaggied410b62017-05-05 15:16:14 +02001917 synchronized (mService.mWindowMap) {
1918 mNextAppTransitionAnimationsSpecsPending = false;
1919 overridePendingAppTransitionMultiThumb(specs,
1920 mNextAppTransitionFutureCallback, null /* finishedCallback */,
1921 mNextAppTransitionScaleUp);
1922 mNextAppTransitionFutureCallback = null;
Jorim Jaggied410b62017-05-05 15:16:14 +02001923 }
1924 mService.requestTraversal();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001925 });
1926 }
1927 }
1928
Craig Mautner164d4bb2012-11-26 13:51:23 -08001929 @Override
1930 public String toString() {
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001931 return "mNextAppTransition=" + appTransitionToString(mNextAppTransition);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001932 }
1933
Craig Mautner4b71aa12012-12-27 17:20:01 -08001934 /**
1935 * Returns the human readable name of a window transition.
1936 *
1937 * @param transition The window transition.
1938 * @return The transition symbolic name.
1939 */
1940 public static String appTransitionToString(int transition) {
1941 switch (transition) {
1942 case TRANSIT_UNSET: {
1943 return "TRANSIT_UNSET";
1944 }
1945 case TRANSIT_NONE: {
1946 return "TRANSIT_NONE";
1947 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001948 case TRANSIT_ACTIVITY_OPEN: {
1949 return "TRANSIT_ACTIVITY_OPEN";
1950 }
1951 case TRANSIT_ACTIVITY_CLOSE: {
1952 return "TRANSIT_ACTIVITY_CLOSE";
1953 }
1954 case TRANSIT_TASK_OPEN: {
1955 return "TRANSIT_TASK_OPEN";
1956 }
1957 case TRANSIT_TASK_CLOSE: {
1958 return "TRANSIT_TASK_CLOSE";
1959 }
1960 case TRANSIT_TASK_TO_FRONT: {
1961 return "TRANSIT_TASK_TO_FRONT";
1962 }
1963 case TRANSIT_TASK_TO_BACK: {
1964 return "TRANSIT_TASK_TO_BACK";
1965 }
1966 case TRANSIT_WALLPAPER_CLOSE: {
1967 return "TRANSIT_WALLPAPER_CLOSE";
1968 }
1969 case TRANSIT_WALLPAPER_OPEN: {
1970 return "TRANSIT_WALLPAPER_OPEN";
1971 }
1972 case TRANSIT_WALLPAPER_INTRA_OPEN: {
1973 return "TRANSIT_WALLPAPER_INTRA_OPEN";
1974 }
1975 case TRANSIT_WALLPAPER_INTRA_CLOSE: {
1976 return "TRANSIT_WALLPAPER_INTRA_CLOSE";
1977 }
Craig Mautnerbb742462014-07-07 15:28:55 -07001978 case TRANSIT_TASK_OPEN_BEHIND: {
1979 return "TRANSIT_TASK_OPEN_BEHIND";
1980 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001981 case TRANSIT_ACTIVITY_RELAUNCH: {
1982 return "TRANSIT_ACTIVITY_RELAUNCH";
1983 }
Jorim Jaggi192086e2016-03-11 17:17:03 +01001984 case TRANSIT_DOCK_TASK_FROM_RECENTS: {
1985 return "TRANSIT_DOCK_TASK_FROM_RECENTS";
1986 }
Jorim Jaggife762342016-10-13 14:33:27 +02001987 case TRANSIT_KEYGUARD_GOING_AWAY: {
1988 return "TRANSIT_KEYGUARD_GOING_AWAY";
1989 }
1990 case TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER: {
1991 return "TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER";
1992 }
1993 case TRANSIT_KEYGUARD_OCCLUDE: {
1994 return "TRANSIT_KEYGUARD_OCCLUDE";
1995 }
1996 case TRANSIT_KEYGUARD_UNOCCLUDE: {
1997 return "TRANSIT_KEYGUARD_UNOCCLUDE";
1998 }
Jorim Jaggi98a9d202018-03-26 16:17:07 +02001999 case TRANSIT_TRANSLUCENT_ACTIVITY_OPEN: {
2000 return "TRANSIT_TRANSLUCENT_ACTIVITY_OPEN";
2001 }
2002 case TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE: {
2003 return "TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE";
2004 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002005 default: {
2006 return "<UNKNOWN>";
2007 }
2008 }
2009 }
2010
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002011 private String appStateToString() {
2012 switch (mAppTransitionState) {
2013 case APP_STATE_IDLE:
2014 return "APP_STATE_IDLE";
2015 case APP_STATE_READY:
2016 return "APP_STATE_READY";
2017 case APP_STATE_RUNNING:
2018 return "APP_STATE_RUNNING";
2019 case APP_STATE_TIMEOUT:
2020 return "APP_STATE_TIMEOUT";
2021 default:
2022 return "unknown state=" + mAppTransitionState;
2023 }
2024 }
2025
2026 private String transitTypeToString() {
2027 switch (mNextAppTransitionType) {
2028 case NEXT_TRANSIT_TYPE_NONE:
2029 return "NEXT_TRANSIT_TYPE_NONE";
2030 case NEXT_TRANSIT_TYPE_CUSTOM:
2031 return "NEXT_TRANSIT_TYPE_CUSTOM";
Winson Chung044d5292014-11-06 11:05:19 -08002032 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
2033 return "NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002034 case NEXT_TRANSIT_TYPE_SCALE_UP:
2035 return "NEXT_TRANSIT_TYPE_SCALE_UP";
2036 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
2037 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP";
2038 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
2039 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN";
Winson Chunga4ccb862014-08-22 15:26:27 -07002040 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
2041 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP";
2042 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN:
2043 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN";
Tony Mak64b8d562017-12-28 17:44:02 +00002044 case NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS:
2045 return "NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002046 default:
2047 return "unknown type=" + mNextAppTransitionType;
2048 }
2049 }
2050
Steven Timotiusaf03df62017-07-18 16:56:43 -07002051 void writeToProto(ProtoOutputStream proto, long fieldId) {
2052 final long token = proto.start(fieldId);
2053 proto.write(APP_TRANSITION_STATE, mAppTransitionState);
2054 proto.write(LAST_USED_APP_TRANSITION, mLastUsedAppTransition);
2055 proto.end(token);
2056 }
2057
Craig Mautner164d4bb2012-11-26 13:51:23 -08002058 @Override
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002059 public void dump(PrintWriter pw, String prefix) {
2060 pw.print(prefix); pw.println(this);
2061 pw.print(prefix); pw.print("mAppTransitionState="); pw.println(appStateToString());
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002062 if (mNextAppTransitionType != NEXT_TRANSIT_TYPE_NONE) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002063 pw.print(prefix); pw.print("mNextAppTransitionType=");
2064 pw.println(transitTypeToString());
Craig Mautner164d4bb2012-11-26 13:51:23 -08002065 }
2066 switch (mNextAppTransitionType) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002067 case NEXT_TRANSIT_TYPE_CUSTOM:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002068 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Craig Mautner164d4bb2012-11-26 13:51:23 -08002069 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002070 pw.print(prefix); pw.print("mNextAppTransitionEnter=0x");
Craig Mautner164d4bb2012-11-26 13:51:23 -08002071 pw.print(Integer.toHexString(mNextAppTransitionEnter));
2072 pw.print(" mNextAppTransitionExit=0x");
2073 pw.println(Integer.toHexString(mNextAppTransitionExit));
2074 break;
Winson Chung044d5292014-11-06 11:05:19 -08002075 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002076 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Winson Chung044d5292014-11-06 11:05:19 -08002077 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002078 pw.print(prefix); pw.print("mNextAppTransitionInPlace=0x");
Winson Chung044d5292014-11-06 11:05:19 -08002079 pw.print(Integer.toHexString(mNextAppTransitionInPlace));
2080 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002081 case NEXT_TRANSIT_TYPE_SCALE_UP: {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002082 getDefaultNextAppTransitionStartRect(mTmpRect);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002083 pw.print(prefix); pw.print("mNextAppTransitionStartX=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002084 pw.print(mTmpRect.left);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002085 pw.print(" mNextAppTransitionStartY=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002086 pw.println(mTmpRect.top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002087 pw.print(prefix); pw.print("mNextAppTransitionStartWidth=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002088 pw.print(mTmpRect.width());
Craig Mautner164d4bb2012-11-26 13:51:23 -08002089 pw.print(" mNextAppTransitionStartHeight=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002090 pw.println(mTmpRect.height());
Craig Mautner164d4bb2012-11-26 13:51:23 -08002091 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002092 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002093 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
2094 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
Winson Chunga4ccb862014-08-22 15:26:27 -07002095 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002096 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN: {
2097 pw.print(prefix); pw.print("mDefaultNextAppTransitionAnimationSpec=");
2098 pw.println(mDefaultNextAppTransitionAnimationSpec);
2099 pw.print(prefix); pw.print("mNextAppTransitionAnimationsSpecs=");
2100 pw.println(mNextAppTransitionAnimationsSpecs);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002101 pw.print(prefix); pw.print("mNextAppTransitionScaleUp=");
2102 pw.println(mNextAppTransitionScaleUp);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002103 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002104 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002105 }
2106 if (mNextAppTransitionCallback != null) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002107 pw.print(prefix); pw.print("mNextAppTransitionCallback=");
2108 pw.println(mNextAppTransitionCallback);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002109 }
Chong Zhang60091a92016-07-27 17:52:45 -07002110 if (mLastUsedAppTransition != TRANSIT_NONE) {
2111 pw.print(prefix); pw.print("mLastUsedAppTransition=");
2112 pw.println(appTransitionToString(mLastUsedAppTransition));
2113 pw.print(prefix); pw.print("mLastOpeningApp=");
2114 pw.println(mLastOpeningApp);
2115 pw.print(prefix); pw.print("mLastClosingApp=");
2116 pw.println(mLastClosingApp);
2117 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002118 }
Amith Yamasani4befbec2013-07-10 16:18:01 -07002119
2120 public void setCurrentUser(int newUserId) {
2121 mCurrentUserId = newUserId;
2122 }
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002123
2124 /**
2125 * @return true if transition is not running and should not be skipped, false if transition is
2126 * already running
2127 */
Jorim Jaggif84e2f62018-01-16 14:17:59 +01002128 boolean prepareAppTransitionLocked(@TransitionType int transit, boolean alwaysKeepCurrent,
2129 @TransitionFlags int flags, boolean forceOverride) {
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002130 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Prepare app transition:"
2131 + " transit=" + appTransitionToString(transit)
2132 + " " + this
2133 + " alwaysKeepCurrent=" + alwaysKeepCurrent
2134 + " Callers=" + Debug.getCallers(3));
Jorim Jaggife762342016-10-13 14:33:27 +02002135 if (forceOverride || isKeyguardTransit(transit) || !isTransitionSet()
2136 || mNextAppTransition == TRANSIT_NONE) {
2137 setAppTransition(transit, flags);
Jorim Jaggia69243a2017-06-15 15:10:38 -04002138 }
2139 // We never want to change from a Keyguard transit to a non-Keyguard transit, as our logic
Adrian Roos93577212018-04-10 14:12:10 -07002140 // relies on the fact that we always execute a Keyguard transition after preparing one. We
2141 // also don't want to change away from a crashing transition.
2142 else if (!alwaysKeepCurrent && !isKeyguardTransit(transit)
2143 && transit != TRANSIT_CRASHING_ACTIVITY_CLOSE) {
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002144 if (transit == TRANSIT_TASK_OPEN && isTransitionEqual(TRANSIT_TASK_CLOSE)) {
2145 // Opening a new task always supersedes a close for the anim.
Jorim Jaggife762342016-10-13 14:33:27 +02002146 setAppTransition(transit, flags);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002147 } else if (transit == TRANSIT_ACTIVITY_OPEN
2148 && isTransitionEqual(TRANSIT_ACTIVITY_CLOSE)) {
2149 // Opening a new activity always supersedes a close for the anim.
Jorim Jaggife762342016-10-13 14:33:27 +02002150 setAppTransition(transit, flags);
Jorim Jaggicecf4242018-02-21 18:46:53 +01002151 } else if (isTaskTransit(transit) && isActivityTransit(mNextAppTransition)) {
2152 // Task animations always supersede activity animations, because if we have both, it
2153 // usually means that activity transition were just trampoline activities.
2154 setAppTransition(transit, flags);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002155 }
2156 }
2157 boolean prepared = prepare();
2158 if (isTransitionSet()) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08002159 mService.mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
2160 mService.mH.sendEmptyMessageDelayed(H.APP_TRANSITION_TIMEOUT, APP_TRANSITION_TIMEOUT_MS);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002161 }
2162 return prepared;
2163 }
Winsonb2024762016-04-05 17:32:30 -07002164
2165 /**
Jorim Jaggife762342016-10-13 14:33:27 +02002166 * @return true if {@param transit} is representing a transition in which Keyguard is going
2167 * away, false otherwise
2168 */
2169 public static boolean isKeyguardGoingAwayTransit(int transit) {
2170 return transit == TRANSIT_KEYGUARD_GOING_AWAY
2171 || transit == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER;
2172 }
2173
2174 private static boolean isKeyguardTransit(int transit) {
2175 return isKeyguardGoingAwayTransit(transit) || transit == TRANSIT_KEYGUARD_OCCLUDE
2176 || transit == TRANSIT_KEYGUARD_UNOCCLUDE;
2177 }
2178
Jorim Jaggi98a9d202018-03-26 16:17:07 +02002179 static boolean isTaskTransit(int transit) {
2180 return isTaskOpenTransit(transit)
Jorim Jaggicecf4242018-02-21 18:46:53 +01002181 || transit == TRANSIT_TASK_CLOSE
Jorim Jaggicecf4242018-02-21 18:46:53 +01002182 || transit == TRANSIT_TASK_TO_BACK
Jorim Jaggicecf4242018-02-21 18:46:53 +01002183 || transit == TRANSIT_TASK_IN_PLACE;
2184 }
2185
Jorim Jaggi98a9d202018-03-26 16:17:07 +02002186 private static boolean isTaskOpenTransit(int transit) {
2187 return transit == TRANSIT_TASK_OPEN
2188 || transit == TRANSIT_TASK_OPEN_BEHIND
2189 || transit == TRANSIT_TASK_TO_FRONT;
2190 }
2191
2192 static boolean isActivityTransit(int transit) {
Jorim Jaggicecf4242018-02-21 18:46:53 +01002193 return transit == TRANSIT_ACTIVITY_OPEN
2194 || transit == TRANSIT_ACTIVITY_CLOSE
2195 || transit == TRANSIT_ACTIVITY_RELAUNCH;
2196 }
2197
Jorim Jaggife762342016-10-13 14:33:27 +02002198 /**
Manu Cornetd7376802017-01-13 13:44:07 -08002199 * @return whether the transition should show the thumbnail being scaled down.
2200 */
2201 private boolean shouldScaleDownThumbnailTransition(int uiMode, int orientation) {
Sid Soundararajan0e88d322017-03-07 15:37:30 -08002202 return mGridLayoutRecentsEnabled
Manu Cornetd7376802017-01-13 13:44:07 -08002203 || orientation == Configuration.ORIENTATION_PORTRAIT;
2204 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002205}