blob: f0ca2ef1747bdafe58ce390d8c335407f4d806aa [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;
23import static android.view.WindowManager.TRANSIT_DOCK_TASK_FROM_RECENTS;
24import static android.view.WindowManager.TRANSIT_FLAG_KEYGUARD_GOING_AWAY_NO_ANIMATION;
25import static android.view.WindowManager.TRANSIT_FLAG_KEYGUARD_GOING_AWAY_TO_SHADE;
26import static android.view.WindowManager.TRANSIT_KEYGUARD_GOING_AWAY;
27import static android.view.WindowManager.TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER;
28import static android.view.WindowManager.TRANSIT_KEYGUARD_OCCLUDE;
29import static android.view.WindowManager.TRANSIT_KEYGUARD_UNOCCLUDE;
30import static android.view.WindowManager.TRANSIT_NONE;
31import static android.view.WindowManager.TRANSIT_TASK_CLOSE;
Jorim Jaggicecf4242018-02-21 18:46:53 +010032import static android.view.WindowManager.TRANSIT_TASK_IN_PLACE;
Jorim Jaggif84e2f62018-01-16 14:17:59 +010033import static android.view.WindowManager.TRANSIT_TASK_OPEN;
34import static android.view.WindowManager.TRANSIT_TASK_OPEN_BEHIND;
35import static android.view.WindowManager.TRANSIT_TASK_TO_BACK;
36import static android.view.WindowManager.TRANSIT_TASK_TO_FRONT;
37import static android.view.WindowManager.TRANSIT_UNSET;
38import static android.view.WindowManager.TRANSIT_WALLPAPER_CLOSE;
39import static android.view.WindowManager.TRANSIT_WALLPAPER_INTRA_CLOSE;
40import static android.view.WindowManager.TRANSIT_WALLPAPER_INTRA_OPEN;
41import static android.view.WindowManager.TRANSIT_WALLPAPER_OPEN;
Tony Mak83546a82018-01-22 13:56:20 +000042
Filip Gruszczynski82861362015-10-16 14:21:09 -070043import static com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation;
44import static com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
45import static com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation;
46import static com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
47import static com.android.internal.R.styleable.WindowAnimation_launchTaskBehindSourceAnimation;
48import static com.android.internal.R.styleable.WindowAnimation_launchTaskBehindTargetAnimation;
49import static com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation;
50import static com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
51import static com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation;
52import static com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
53import static com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation;
54import static com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
55import static com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation;
56import static com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
57import static com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation;
58import static com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
59import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation;
60import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
61import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation;
62import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
63import static com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation;
64import static com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Filip Gruszczynski198dcbf2016-01-18 10:02:00 -080065import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
66import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080067import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
68import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Adrian Roose99bc052017-11-20 17:55:31 +010069import static com.android.server.wm.WindowManagerInternal.AppTransitionListener;
Tony Mak089c35e2017-12-18 20:34:14 +000070import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_AFTER_ANIM;
Matthew Ngbf1d9852017-03-14 12:23:09 -070071import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_BEFORE_ANIM;
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +010072import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_NONE;
Steven Timotiusaf03df62017-07-18 16:56:43 -070073import static com.android.server.wm.proto.AppTransitionProto.APP_TRANSITION_STATE;
74import static com.android.server.wm.proto.AppTransitionProto.LAST_USED_APP_TRANSITION;
Filip Gruszczynski82861362015-10-16 14:21:09 -070075
Tony Mak64b8d562017-12-28 17:44:02 +000076import android.annotation.DrawableRes;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -070077import android.annotation.Nullable;
Matthew Ng43db6d22017-06-27 15:29:39 -070078import android.app.ActivityManager;
Tony Mak089c35e2017-12-18 20:34:14 +000079import android.content.ComponentName;
Craig Mautner164d4bb2012-11-26 13:51:23 -080080import android.content.Context;
Winson21700932016-03-24 17:26:23 -070081import android.content.res.Configuration;
John Reck519ad482018-02-12 17:08:48 -080082import android.graphics.Bitmap;
83import android.graphics.Canvas;
Tony Mak64b8d562017-12-28 17:44:02 +000084import android.graphics.Color;
Winson Chungaa7fa012017-05-24 15:50:06 -070085import android.graphics.GraphicBuffer;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +010086import android.graphics.Path;
John Reck519ad482018-02-12 17:08:48 -080087import android.graphics.Picture;
Winson Chung399f6202014-03-19 10:47:20 -070088import android.graphics.Rect;
Tony Mak64b8d562017-12-28 17:44:02 +000089import android.graphics.drawable.Drawable;
Jorim Jaggied410b62017-05-05 15:16:14 +020090import android.os.Binder;
Craig Mautner164d4bb2012-11-26 13:51:23 -080091import android.os.Debug;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010092import android.os.IBinder;
Craig Mautner164d4bb2012-11-26 13:51:23 -080093import android.os.IRemoteCallback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010094import android.os.RemoteException;
Jorim Jaggif5f9e122017-10-24 18:21:09 +020095import android.os.SystemClock;
Manu Cornetd7376802017-01-13 13:44:07 -080096import android.os.SystemProperties;
Tony Mak089c35e2017-12-18 20:34:14 +000097import android.os.UserHandle;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -080098import android.util.ArraySet;
Craig Mautner164d4bb2012-11-26 13:51:23 -080099import android.util.Slog;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700100import android.util.SparseArray;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700101import android.util.proto.ProtoOutputStream;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700102import android.view.AppTransitionAnimationSpec;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100103import android.view.IAppTransitionAnimationSpecsFuture;
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100104import android.view.RemoteAnimationAdapter;
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100105import android.view.WindowManager.TransitionFlags;
106import android.view.WindowManager.TransitionType;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800107import android.view.animation.AlphaAnimation;
108import android.view.animation.Animation;
109import android.view.animation.AnimationSet;
110import android.view.animation.AnimationUtils;
Winson Chung399f6202014-03-19 10:47:20 -0700111import android.view.animation.ClipRectAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800112import android.view.animation.Interpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700113import android.view.animation.PathInterpolator;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800114import android.view.animation.ScaleAnimation;
Winson Chung399f6202014-03-19 10:47:20 -0700115import android.view.animation.TranslateAnimation;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700116
Craig Mautner164d4bb2012-11-26 13:51:23 -0800117import com.android.internal.util.DumpUtils.Dump;
118import com.android.server.AttributeCache;
119import com.android.server.wm.WindowManagerService.H;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800120import com.android.server.wm.animation.ClipRectLRAnimation;
121import com.android.server.wm.animation.ClipRectTBAnimation;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100122import com.android.server.wm.animation.CurvedTranslateAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800123
124import java.io.PrintWriter;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100125import java.util.ArrayList;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100126import java.util.concurrent.ExecutorService;
127import java.util.concurrent.Executors;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800128
Craig Mautner164d4bb2012-11-26 13:51:23 -0800129// State management of app transitions. When we are preparing for a
130// transition, mNextAppTransition will be the kind of transition to
131// perform or TRANSIT_NONE if we are not waiting. If we are waiting,
132// mOpeningApps and mClosingApps are the lists of tokens that will be
133// made visible or hidden at the next transition.
134public class AppTransition implements Dump {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800135 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppTransition" : TAG_WM;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700136 private static final int CLIP_REVEAL_TRANSLATION_Y_DP = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800137
Winson Chunga4ccb862014-08-22 15:26:27 -0700138 /** Fraction of animation at which the recents thumbnail stays completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700139 private static final float RECENTS_THUMBNAIL_FADEIN_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800140 /** Fraction of animation at which the recents thumbnail becomes completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700141 private static final float RECENTS_THUMBNAIL_FADEOUT_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800142
Filip Gruszczynski84fa3352016-01-25 16:28:49 -0800143 static final int DEFAULT_APP_TRANSITION_DURATION = 336;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800144
145 /** Interpolator to be used for animations that respond directly to a touch */
146 static final Interpolator TOUCH_RESPONSE_INTERPOLATOR =
147 new PathInterpolator(0.3f, 0f, 0.1f, 1f);
148
Jorim Jaggic69bd222016-03-15 14:38:37 +0100149 private static final Interpolator THUMBNAIL_DOCK_INTERPOLATOR =
150 new PathInterpolator(0.85f, 0f, 1f, 1f);
151
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800152 /**
153 * Maximum duration for the clip reveal animation. This is used when there is a lot of movement
154 * involved, to make it more understandable.
155 */
156 private static final int MAX_CLIP_REVEAL_TRANSITION_DURATION = 420;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700157 private static final int THUMBNAIL_APP_TRANSITION_DURATION = 336;
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700158 private static final long APP_TRANSITION_TIMEOUT_MS = 5000;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800159
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800160 private final Context mContext;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800161 private final WindowManagerService mService;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800162
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100163 private @TransitionType int mNextAppTransition = TRANSIT_UNSET;
164 private @TransitionFlags int mNextAppTransitionFlags = 0;
Chong Zhang60091a92016-07-27 17:52:45 -0700165 private int mLastUsedAppTransition = TRANSIT_UNSET;
166 private String mLastOpeningApp;
167 private String mLastClosingApp;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800168
169 private static final int NEXT_TRANSIT_TYPE_NONE = 0;
170 private static final int NEXT_TRANSIT_TYPE_CUSTOM = 1;
171 private static final int NEXT_TRANSIT_TYPE_SCALE_UP = 2;
172 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP = 3;
173 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN = 4;
Winson Chunga4ccb862014-08-22 15:26:27 -0700174 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP = 5;
175 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN = 6;
Winson Chung044d5292014-11-06 11:05:19 -0800176 private static final int NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE = 7;
Chet Haase10e23ab2015-02-11 15:08:38 -0800177 private static final int NEXT_TRANSIT_TYPE_CLIP_REVEAL = 8;
Tony Mak089c35e2017-12-18 20:34:14 +0000178
179 /**
180 * Refers to the transition to activity started by using {@link
181 * android.content.pm.crossprofile.CrossProfileApps#startMainActivity(ComponentName, UserHandle)
182 * }.
183 */
184 private static final int NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS = 9;
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100185 private static final int NEXT_TRANSIT_TYPE_REMOTE = 10;
186
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800187 private int mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
188
Winson Chung399f6202014-03-19 10:47:20 -0700189 // These are the possible states for the enter/exit activities during a thumbnail transition
190 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_UP = 0;
191 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_UP = 1;
192 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN = 2;
193 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN = 3;
194
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800195 private String mNextAppTransitionPackage;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800196 // Used for thumbnail transitions. True if we're scaling up, false if scaling down
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800197 private boolean mNextAppTransitionScaleUp;
198 private IRemoteCallback mNextAppTransitionCallback;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +0100199 private IRemoteCallback mNextAppTransitionFutureCallback;
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -0700200 private IRemoteCallback mAnimationFinishedCallback;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800201 private int mNextAppTransitionEnter;
202 private int mNextAppTransitionExit;
Winson Chung044d5292014-11-06 11:05:19 -0800203 private int mNextAppTransitionInPlace;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700204
205 // Keyed by task id.
206 private final SparseArray<AppTransitionAnimationSpec> mNextAppTransitionAnimationsSpecs
207 = new SparseArray<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100208 private IAppTransitionAnimationSpecsFuture mNextAppTransitionAnimationsSpecsFuture;
209 private boolean mNextAppTransitionAnimationsSpecsPending;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700210 private AppTransitionAnimationSpec mDefaultNextAppTransitionAnimationSpec;
211
Winson Chunga4ccb862014-08-22 15:26:27 -0700212 private Rect mNextAppTransitionInsets = new Rect();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800213
Winson Chung2820c452014-04-15 15:34:44 -0700214 private Rect mTmpFromClipRect = new Rect();
215 private Rect mTmpToClipRect = new Rect();
216
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700217 private final Rect mTmpRect = new Rect();
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700218
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800219 private final static int APP_STATE_IDLE = 0;
220 private final static int APP_STATE_READY = 1;
221 private final static int APP_STATE_RUNNING = 2;
222 private final static int APP_STATE_TIMEOUT = 3;
223 private int mAppTransitionState = APP_STATE_IDLE;
224
225 private final int mConfigShortAnimTime;
Craig Mautner321bdf52012-12-18 09:53:24 -0800226 private final Interpolator mDecelerateInterpolator;
Winson Chunga4ccb862014-08-22 15:26:27 -0700227 private final Interpolator mThumbnailFadeInInterpolator;
228 private final Interpolator mThumbnailFadeOutInterpolator;
Chet Haase10e23ab2015-02-11 15:08:38 -0800229 private final Interpolator mLinearOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700230 private final Interpolator mFastOutLinearInInterpolator;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100231 private final Interpolator mFastOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700232 private final Interpolator mClipHorizontalInterpolator = new PathInterpolator(0, 0, 0.4f, 1f);
233
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700234 private final int mClipRevealTranslationY;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800235
Amith Yamasani4befbec2013-07-10 16:18:01 -0700236 private int mCurrentUserId = 0;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800237 private long mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Amith Yamasani4befbec2013-07-10 16:18:01 -0700238
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100239 private final ArrayList<AppTransitionListener> mListeners = new ArrayList<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100240 private final ExecutorService mDefaultExecutor = Executors.newSingleThreadExecutor();
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100241
Jorim Jaggif97ed922016-02-18 18:57:07 -0800242 private int mLastClipRevealMaxTranslation;
243 private boolean mLastHadClipReveal;
Jorim Jaggi363ab982016-04-26 19:51:20 -0700244 private boolean mProlongedAnimationsEnded;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800245
Manu Cornetd7376802017-01-13 13:44:07 -0800246 private final boolean mGridLayoutRecentsEnabled;
Matthew Ng43db6d22017-06-27 15:29:39 -0700247 private final boolean mLowRamRecentsEnabled;
Manu Cornetd7376802017-01-13 13:44:07 -0800248
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100249 private RemoteAnimationController mRemoteAnimationController;
250
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800251 AppTransition(Context context, WindowManagerService service) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800252 mContext = context;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800253 mService = service;
Chet Haase10e23ab2015-02-11 15:08:38 -0800254 mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
255 com.android.internal.R.interpolator.linear_out_slow_in);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700256 mFastOutLinearInInterpolator = AnimationUtils.loadInterpolator(context,
257 com.android.internal.R.interpolator.fast_out_linear_in);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100258 mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
259 com.android.internal.R.interpolator.fast_out_slow_in);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800260 mConfigShortAnimTime = context.getResources().getInteger(
261 com.android.internal.R.integer.config_shortAnimTime);
Craig Mautner321bdf52012-12-18 09:53:24 -0800262 mDecelerateInterpolator = AnimationUtils.loadInterpolator(context,
263 com.android.internal.R.interpolator.decelerate_cubic);
Winson Chunga4ccb862014-08-22 15:26:27 -0700264 mThumbnailFadeInInterpolator = new Interpolator() {
265 @Override
266 public float getInterpolation(float input) {
267 // Linear response for first fraction, then complete after that.
268 if (input < RECENTS_THUMBNAIL_FADEIN_FRACTION) {
269 return 0f;
270 }
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700271 float t = (input - RECENTS_THUMBNAIL_FADEIN_FRACTION) /
Winson Chunga4ccb862014-08-22 15:26:27 -0700272 (1f - RECENTS_THUMBNAIL_FADEIN_FRACTION);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700273 return mFastOutLinearInInterpolator.getInterpolation(t);
Winson Chunga4ccb862014-08-22 15:26:27 -0700274 }
275 };
276 mThumbnailFadeOutInterpolator = new Interpolator() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800277 @Override
278 public float getInterpolation(float input) {
279 // Linear response for first fraction, then complete after that.
280 if (input < RECENTS_THUMBNAIL_FADEOUT_FRACTION) {
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700281 float t = input / RECENTS_THUMBNAIL_FADEOUT_FRACTION;
282 return mLinearOutSlowInInterpolator.getInterpolation(t);
Craig Mautner321bdf52012-12-18 09:53:24 -0800283 }
Winson Chunga4ccb862014-08-22 15:26:27 -0700284 return 1f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800285 }
286 };
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700287 mClipRevealTranslationY = (int) (CLIP_REVEAL_TRANSLATION_Y_DP
288 * mContext.getResources().getDisplayMetrics().density);
Manu Cornetd7376802017-01-13 13:44:07 -0800289 mGridLayoutRecentsEnabled = SystemProperties.getBoolean("ro.recents.grid", false);
Matthew Ng43db6d22017-06-27 15:29:39 -0700290 mLowRamRecentsEnabled = ActivityManager.isLowRamDeviceStatic();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800291 }
292
293 boolean isTransitionSet() {
294 return mNextAppTransition != TRANSIT_UNSET;
295 }
296
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100297 boolean isTransitionEqual(@TransitionType int transit) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800298 return mNextAppTransition == transit;
299 }
300
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100301 @TransitionType int getAppTransition() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800302 return mNextAppTransition;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800303 }
304
Jorim Jaggife762342016-10-13 14:33:27 +0200305 private void setAppTransition(int transit, int flags) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800306 mNextAppTransition = transit;
Jorim Jaggife762342016-10-13 14:33:27 +0200307 mNextAppTransitionFlags |= flags;
Chong Zhang60091a92016-07-27 17:52:45 -0700308 setLastAppTransition(TRANSIT_UNSET, null, null);
Jorim Jaggi245281c2017-06-07 14:33:04 -0700309 updateBooster();
Chong Zhang60091a92016-07-27 17:52:45 -0700310 }
311
312 void setLastAppTransition(int transit, AppWindowToken openingApp, AppWindowToken closingApp) {
313 mLastUsedAppTransition = transit;
314 mLastOpeningApp = "" + openingApp;
315 mLastClosingApp = "" + closingApp;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800316 }
317
318 boolean isReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800319 return mAppTransitionState == APP_STATE_READY
320 || mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800321 }
322
Craig Mautnerae446592012-12-06 19:05:05 -0800323 void setReady() {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700324 setAppTransitionState(APP_STATE_READY);
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100325 fetchAppTransitionSpecsFromFuture();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800326 }
327
328 boolean isRunning() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800329 return mAppTransitionState == APP_STATE_RUNNING;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800330 }
331
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800332 void setIdle() {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700333 setAppTransitionState(APP_STATE_IDLE);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800334 }
335
336 boolean isTimeout() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800337 return mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800338 }
339
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800340 void setTimeout() {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700341 setAppTransitionState(APP_STATE_TIMEOUT);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800342 }
343
Winson Chungaa7fa012017-05-24 15:50:06 -0700344 GraphicBuffer getAppTransitionThumbnailHeader(int taskId) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700345 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800346 if (spec == null) {
347 spec = mDefaultNextAppTransitionAnimationSpec;
348 }
Winson Chungaa7fa012017-05-24 15:50:06 -0700349 return spec != null ? spec.buffer : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800350 }
351
Winson Chunga4ccb862014-08-22 15:26:27 -0700352 /** Returns whether the next thumbnail transition is aspect scaled up. */
353 boolean isNextThumbnailTransitionAspectScaled() {
354 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
355 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
356 }
357
358 /** Returns whether the next thumbnail transition is scaling up. */
359 boolean isNextThumbnailTransitionScaleUp() {
360 return mNextAppTransitionScaleUp;
361 }
362
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -0800363 boolean isNextAppTransitionThumbnailUp() {
364 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
365 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP;
366 }
367
368 boolean isNextAppTransitionThumbnailDown() {
369 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN ||
370 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
371 }
372
Tony Mak64b8d562017-12-28 17:44:02 +0000373
374 boolean isNextAppTransitionOpenCrossProfileApps() {
375 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS;
376 }
377
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100378 /**
379 * @return true if and only if we are currently fetching app transition specs from the future
380 * passed into {@link #overridePendingAppTransitionMultiThumbFuture}
381 */
382 boolean isFetchingAppTransitionsSpecs() {
383 return mNextAppTransitionAnimationsSpecsPending;
384 }
385
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700386 private boolean prepare() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800387 if (!isRunning()) {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700388 setAppTransitionState(APP_STATE_IDLE);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100389 notifyAppTransitionPendingLocked();
Jorim Jaggif97ed922016-02-18 18:57:07 -0800390 mLastHadClipReveal = false;
391 mLastClipRevealMaxTranslation = 0;
392 mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700393 return true;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800394 }
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700395 return false;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800396 }
397
Jorim Jaggife762342016-10-13 14:33:27 +0200398 /**
399 * @return bit-map of WindowManagerPolicy#FINISH_LAYOUT_REDO_* to indicate whether another
400 * layout pass needs to be done
401 */
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200402 int goodToGo(int transit, AppWindowToken topOpeningApp,
403 AppWindowToken topClosingApp, ArraySet<AppWindowToken> openingApps,
Jorim Jaggife762342016-10-13 14:33:27 +0200404 ArraySet<AppWindowToken> closingApps) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800405 mNextAppTransition = TRANSIT_UNSET;
Jorim Jaggife762342016-10-13 14:33:27 +0200406 mNextAppTransitionFlags = 0;
Jorim Jaggi245281c2017-06-07 14:33:04 -0700407 setAppTransitionState(APP_STATE_RUNNING);
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200408 final AnimationAdapter topOpeningAnim = topOpeningApp != null
409 ? topOpeningApp.getAnimation()
410 : null;
Jorim Jaggife762342016-10-13 14:33:27 +0200411 int redoLayout = notifyAppTransitionStartingLocked(transit,
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200412 topOpeningApp != null ? topOpeningApp.token : null,
413 topClosingApp != null ? topClosingApp.token : null,
414 topOpeningAnim != null ? topOpeningAnim.getDurationHint() : 0,
415 topOpeningAnim != null
416 ? topOpeningAnim.getStatusBarTransitionsStartTime()
417 : SystemClock.uptimeMillis(),
418 AnimationAdapter.STATUS_BAR_TRANSITION_DURATION);
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800419 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Jorim Jaggife762342016-10-13 14:33:27 +0200420 .notifyAppTransitionStarting(openingApps, transit);
Jorim Jaggi363ab982016-04-26 19:51:20 -0700421
422 // Prolong the start for the transition when docking a task from recents, unless recents
423 // ended it already then we don't need to wait.
Jorim Jaggife762342016-10-13 14:33:27 +0200424 if (transit == TRANSIT_DOCK_TASK_FROM_RECENTS && !mProlongedAnimationsEnded) {
Jorim Jaggi363ab982016-04-26 19:51:20 -0700425 for (int i = openingApps.size() - 1; i >= 0; i--) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200426 final AppWindowToken app = openingApps.valueAt(i);
427 app.startDelayingAnimationStart();
Jorim Jaggi363ab982016-04-26 19:51:20 -0700428 }
429 }
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100430 if (mRemoteAnimationController != null) {
431 mRemoteAnimationController.goodToGo();
432 }
Jorim Jaggife762342016-10-13 14:33:27 +0200433 return redoLayout;
Jorim Jaggi363ab982016-04-26 19:51:20 -0700434 }
435
436 /**
437 * Let the transitions manager know that the somebody wanted to end the prolonged animations.
438 */
439 void notifyProlongedAnimationsEnded() {
440 mProlongedAnimationsEnded = true;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800441 }
442
443 void clear() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800444 mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800445 mNextAppTransitionPackage = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700446 mNextAppTransitionAnimationsSpecs.clear();
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100447 mRemoteAnimationController = null;
Jorim Jaggi65193992015-11-23 16:49:59 -0800448 mNextAppTransitionAnimationsSpecsFuture = null;
449 mDefaultNextAppTransitionAnimationSpec = null;
450 mAnimationFinishedCallback = null;
Jorim Jaggi363ab982016-04-26 19:51:20 -0700451 mProlongedAnimationsEnded = false;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800452 }
453
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800454 void freeze() {
Jorim Jaggife762342016-10-13 14:33:27 +0200455 final int transit = mNextAppTransition;
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100456 setAppTransition(TRANSIT_UNSET, 0 /* flags */);
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800457 clear();
458 setReady();
Jorim Jaggife762342016-10-13 14:33:27 +0200459 notifyAppTransitionCancelledLocked(transit);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100460 }
461
Jorim Jaggi245281c2017-06-07 14:33:04 -0700462 private void setAppTransitionState(int state) {
463 mAppTransitionState = state;
464 updateBooster();
465 }
466
467 /**
468 * Updates whether we currently boost wm locked sections and the animation thread. We want to
469 * boost the priorities to a more important value whenever an app transition is going to happen
470 * soon or an app transition is running.
471 */
472 private void updateBooster() {
473 WindowManagerService.sThreadPriorityBooster.setAppTransitionRunning(
474 mNextAppTransition != TRANSIT_UNSET || mAppTransitionState == APP_STATE_READY
475 || mAppTransitionState == APP_STATE_RUNNING);
476 }
477
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100478 void registerListenerLocked(AppTransitionListener listener) {
479 mListeners.add(listener);
480 }
481
Wale Ogunwalea48eadb2015-05-14 17:43:12 -0700482 public void notifyAppTransitionFinishedLocked(IBinder token) {
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100483 for (int i = 0; i < mListeners.size(); i++) {
484 mListeners.get(i).onAppTransitionFinishedLocked(token);
485 }
486 }
487
488 private void notifyAppTransitionPendingLocked() {
489 for (int i = 0; i < mListeners.size(); i++) {
490 mListeners.get(i).onAppTransitionPendingLocked();
491 }
492 }
493
Jorim Jaggife762342016-10-13 14:33:27 +0200494 private void notifyAppTransitionCancelledLocked(int transit) {
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100495 for (int i = 0; i < mListeners.size(); i++) {
Jorim Jaggife762342016-10-13 14:33:27 +0200496 mListeners.get(i).onAppTransitionCancelledLocked(transit);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100497 }
498 }
499
Jorim Jaggife762342016-10-13 14:33:27 +0200500 private int notifyAppTransitionStartingLocked(int transit, IBinder openToken,
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200501 IBinder closeToken, long duration, long statusBarAnimationStartTime,
502 long statusBarAnimationDuration) {
Jorim Jaggife762342016-10-13 14:33:27 +0200503 int redoLayout = 0;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100504 for (int i = 0; i < mListeners.size(); i++) {
Jorim Jaggife762342016-10-13 14:33:27 +0200505 redoLayout |= mListeners.get(i).onAppTransitionStartingLocked(transit, openToken,
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200506 closeToken, duration, statusBarAnimationStartTime, statusBarAnimationDuration);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100507 }
Jorim Jaggife762342016-10-13 14:33:27 +0200508 return redoLayout;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800509 }
510
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100511 private AttributeCache.Entry getCachedAnimations(LayoutParams lp) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800512 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg="
513 + (lp != null ? lp.packageName : null)
514 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
515 if (lp != null && lp.windowAnimations != 0) {
516 // If this is a system resource, don't try to load it from the
517 // application resources. It is nice to avoid loading application
518 // resources if we can.
519 String packageName = lp.packageName != null ? lp.packageName : "android";
520 int resId = lp.windowAnimations;
521 if ((resId&0xFF000000) == 0x01000000) {
522 packageName = "android";
523 }
524 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
525 + packageName);
526 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700527 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800528 }
529 return null;
530 }
531
532 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
533 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package="
534 + packageName + " resId=0x" + Integer.toHexString(resId));
535 if (packageName != null) {
536 if ((resId&0xFF000000) == 0x01000000) {
537 packageName = "android";
538 }
539 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
540 + packageName);
541 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700542 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800543 }
544 return null;
545 }
546
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100547 Animation loadAnimationAttr(LayoutParams lp, int animAttr) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800548 int anim = 0;
549 Context context = mContext;
550 if (animAttr >= 0) {
551 AttributeCache.Entry ent = getCachedAnimations(lp);
552 if (ent != null) {
553 context = ent.context;
554 anim = ent.array.getResourceId(animAttr, 0);
555 }
556 }
557 if (anim != 0) {
558 return AnimationUtils.loadAnimation(context, anim);
559 }
560 return null;
561 }
562
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100563 Animation loadAnimationRes(LayoutParams lp, int resId) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700564 Context context = mContext;
565 if (resId >= 0) {
566 AttributeCache.Entry ent = getCachedAnimations(lp);
567 if (ent != null) {
568 context = ent.context;
569 }
570 return AnimationUtils.loadAnimation(context, resId);
571 }
572 return null;
573 }
574
575 private Animation loadAnimationRes(String packageName, int resId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800576 int anim = 0;
577 Context context = mContext;
578 if (resId >= 0) {
579 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
580 if (ent != null) {
581 context = ent.context;
582 anim = resId;
583 }
584 }
585 if (anim != 0) {
586 return AnimationUtils.loadAnimation(context, anim);
587 }
588 return null;
589 }
590
Craig Mautner164d4bb2012-11-26 13:51:23 -0800591 /**
592 * Compute the pivot point for an animation that is scaling from a small
593 * rect on screen to a larger rect. The pivot point varies depending on
594 * the distance between the inner and outer edges on both sides. This
595 * function computes the pivot point for one dimension.
596 * @param startPos Offset from left/top edge of outer rectangle to
597 * left/top edge of inner rectangle.
598 * @param finalScale The scaling factor between the size of the outer
599 * and inner rectangles.
600 */
601 private static float computePivot(int startPos, float finalScale) {
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800602
603 /*
604 Theorem of intercepting lines:
605
606 + + +-----------------------------------------------+
607 | | | |
608 | | | |
609 | | | |
610 | | | |
611 x | y | | |
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 + ++
653 p ++
654
655 scale = (x - y) / x
656 <=> x = -y / (scale - 1)
657 */
Craig Mautner164d4bb2012-11-26 13:51:23 -0800658 final float denom = finalScale-1;
659 if (Math.abs(denom) < .0001f) {
660 return startPos;
661 }
662 return -startPos / denom;
663 }
664
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700665 private Animation createScaleUpAnimationLocked(int transit, boolean enter,
666 Rect containingFrame) {
667 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700668 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700669 final int appWidth = containingFrame.width();
670 final int appHeight = containingFrame.height();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800671 if (enter) {
672 // Entering app zooms out from the center of the initial rect.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700673 float scaleW = mTmpRect.width() / (float) appWidth;
674 float scaleH = mTmpRect.height() / (float) appHeight;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800675 Animation scale = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700676 computePivot(mTmpRect.left, scaleW),
Winson4c3fecd2016-07-13 12:29:48 -0700677 computePivot(mTmpRect.top, scaleH));
Craig Mautner321bdf52012-12-18 09:53:24 -0800678 scale.setInterpolator(mDecelerateInterpolator);
679
Craig Mautner164d4bb2012-11-26 13:51:23 -0800680 Animation alpha = new AlphaAnimation(0, 1);
Winson Chunga4ccb862014-08-22 15:26:27 -0700681 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
Craig Mautner321bdf52012-12-18 09:53:24 -0800682
683 AnimationSet set = new AnimationSet(false);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800684 set.addAnimation(scale);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800685 set.addAnimation(alpha);
686 set.setDetachWallpaper(true);
687 a = set;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800688 } else if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
689 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800690 // If we are on top of the wallpaper, we need an animation that
691 // correctly handles the wallpaper staying static behind all of
692 // the animated elements. To do this, will just have the existing
693 // element fade out.
694 a = new AlphaAnimation(1, 0);
695 a.setDetachWallpaper(true);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800696 } else {
Craig Mautner321bdf52012-12-18 09:53:24 -0800697 // For normal animations, the exiting element just holds in place.
698 a = new AlphaAnimation(1, 1);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800699 }
Craig Mautner321bdf52012-12-18 09:53:24 -0800700
701 // Pick the desired duration. If this is an inter-activity transition,
702 // it is the standard duration for that. Otherwise we use the longer
703 // task transition duration.
704 final long duration;
705 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800706 case TRANSIT_ACTIVITY_OPEN:
707 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800708 duration = mConfigShortAnimTime;
709 break;
710 default:
711 duration = DEFAULT_APP_TRANSITION_DURATION;
712 break;
713 }
714 a.setDuration(duration);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800715 a.setFillAfter(true);
Craig Mautner321bdf52012-12-18 09:53:24 -0800716 a.setInterpolator(mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800717 a.initialize(appWidth, appHeight, appWidth, appHeight);
718 return a;
719 }
720
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700721 private void getDefaultNextAppTransitionStartRect(Rect rect) {
722 if (mDefaultNextAppTransitionAnimationSpec == null ||
723 mDefaultNextAppTransitionAnimationSpec.rect == null) {
Jorim Jaggi2550f3f2017-03-14 20:15:59 +0100724 Slog.e(TAG, "Starting rect for app requested, but none available", new Throwable());
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700725 rect.setEmpty();
726 } else {
727 rect.set(mDefaultNextAppTransitionAnimationSpec.rect);
728 }
729 }
730
731 void getNextAppTransitionStartRect(int taskId, Rect rect) {
732 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800733 if (spec == null) {
734 spec = mDefaultNextAppTransitionAnimationSpec;
735 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700736 if (spec == null || spec.rect == null) {
Jorim Jaggi2550f3f2017-03-14 20:15:59 +0100737 Slog.e(TAG, "Starting rect for task: " + taskId + " requested, but not available",
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700738 new Throwable());
739 rect.setEmpty();
740 } else {
741 rect.set(spec.rect);
742 }
743 }
744
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800745 private void putDefaultNextAppTransitionCoordinates(int left, int top, int width, int height,
Winson Chungaa7fa012017-05-24 15:50:06 -0700746 GraphicBuffer buffer) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700747 mDefaultNextAppTransitionAnimationSpec = new AppTransitionAnimationSpec(-1 /* taskId */,
Winson Chungaa7fa012017-05-24 15:50:06 -0700748 buffer, new Rect(left, top, left + width, top + height));
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700749 }
750
Jorim Jaggif97ed922016-02-18 18:57:07 -0800751 /**
752 * @return the duration of the last clip reveal animation
753 */
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800754 long getLastClipRevealTransitionDuration() {
755 return mLastClipRevealTransitionDuration;
756 }
757
758 /**
Jorim Jaggif97ed922016-02-18 18:57:07 -0800759 * @return the maximum distance the app surface is traveling of the last clip reveal animation
760 */
761 int getLastClipRevealMaxTranslation() {
762 return mLastClipRevealMaxTranslation;
763 }
764
765 /**
766 * @return true if in the last app transition had a clip reveal animation, false otherwise
767 */
768 boolean hadClipRevealAnimation() {
769 return mLastHadClipReveal;
770 }
771
772 /**
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800773 * Calculates the duration for the clip reveal animation. If the clip is "cut off", meaning that
774 * the start rect is outside of the target rect, and there is a lot of movement going on.
775 *
776 * @param cutOff whether the start rect was not fully contained by the end rect
777 * @param translationX the total translation the surface moves in x direction
778 * @param translationY the total translation the surfaces moves in y direction
779 * @param displayFrame our display frame
780 *
781 * @return the duration of the clip reveal animation, in milliseconds
782 */
783 private long calculateClipRevealTransitionDuration(boolean cutOff, float translationX,
784 float translationY, Rect displayFrame) {
785 if (!cutOff) {
786 return DEFAULT_APP_TRANSITION_DURATION;
787 }
788 final float fraction = Math.max(Math.abs(translationX) / displayFrame.width(),
789 Math.abs(translationY) / displayFrame.height());
790 return (long) (DEFAULT_APP_TRANSITION_DURATION + fraction *
791 (MAX_CLIP_REVEAL_TRANSITION_DURATION - DEFAULT_APP_TRANSITION_DURATION));
792 }
793
794 private Animation createClipRevealAnimationLocked(int transit, boolean enter, Rect appFrame,
795 Rect displayFrame) {
Chet Haase10e23ab2015-02-11 15:08:38 -0800796 final Animation anim;
797 if (enter) {
Craig Mautner80b1f642015-04-22 10:59:09 -0700798 final int appWidth = appFrame.width();
799 final int appHeight = appFrame.height();
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800800
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700801 // mTmpRect will contain an area around the launcher icon that was pressed. We will
Filip Gruszczynski82861362015-10-16 14:21:09 -0700802 // clip reveal from that area in the final area of the app.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700803 getDefaultNextAppTransitionStartRect(mTmpRect);
Craig Mautner80b1f642015-04-22 10:59:09 -0700804
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700805 float t = 0f;
806 if (appHeight > 0) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800807 t = (float) mTmpRect.top / displayFrame.height();
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700808 }
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800809 int translationY = mClipRevealTranslationY + (int)(displayFrame.height() / 7f * t);
810 int translationX = 0;
811 int translationYCorrection = translationY;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700812 int centerX = mTmpRect.centerX();
813 int centerY = mTmpRect.centerY();
814 int halfWidth = mTmpRect.width() / 2;
815 int halfHeight = mTmpRect.height() / 2;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800816 int clipStartX = centerX - halfWidth - appFrame.left;
817 int clipStartY = centerY - halfHeight - appFrame.top;
818 boolean cutOff = false;
819
820 // If the starting rectangle is fully or partially outside of the target rectangle, we
821 // need to start the clipping at the edge and then achieve the rest with translation
822 // and extending the clip rect from that edge.
823 if (appFrame.top > centerY - halfHeight) {
824 translationY = (centerY - halfHeight) - appFrame.top;
825 translationYCorrection = 0;
826 clipStartY = 0;
827 cutOff = true;
828 }
829 if (appFrame.left > centerX - halfWidth) {
830 translationX = (centerX - halfWidth) - appFrame.left;
831 clipStartX = 0;
832 cutOff = true;
833 }
834 if (appFrame.right < centerX + halfWidth) {
835 translationX = (centerX + halfWidth) - appFrame.right;
836 clipStartX = appWidth - mTmpRect.width();
837 cutOff = true;
838 }
839 final long duration = calculateClipRevealTransitionDuration(cutOff, translationX,
840 translationY, displayFrame);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700841
842 // Clip third of the from size of launch icon, expand to full width/height
Chet Haase10e23ab2015-02-11 15:08:38 -0800843 Animation clipAnimLR = new ClipRectLRAnimation(
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800844 clipStartX, clipStartX + mTmpRect.width(), 0, appWidth);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700845 clipAnimLR.setInterpolator(mClipHorizontalInterpolator);
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800846 clipAnimLR.setDuration((long) (duration / 2.5f));
Filip Gruszczynski82861362015-10-16 14:21:09 -0700847
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800848 TranslateAnimation translate = new TranslateAnimation(translationX, 0, translationY, 0);
849 translate.setInterpolator(cutOff ? TOUCH_RESPONSE_INTERPOLATOR
850 : mLinearOutSlowInInterpolator);
851 translate.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800852
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800853 Animation clipAnimTB = new ClipRectTBAnimation(
854 clipStartY, clipStartY + mTmpRect.height(),
855 0, appHeight,
856 translationYCorrection, 0,
857 mLinearOutSlowInInterpolator);
858 clipAnimTB.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
859 clipAnimTB.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800860
861 // Quick fade-in from icon to app window
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800862 final long alphaDuration = duration / 4;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700863 AlphaAnimation alpha = new AlphaAnimation(0.5f, 1);
Chet Haase10e23ab2015-02-11 15:08:38 -0800864 alpha.setDuration(alphaDuration);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700865 alpha.setInterpolator(mLinearOutSlowInInterpolator);
Chet Haase10e23ab2015-02-11 15:08:38 -0800866
867 AnimationSet set = new AnimationSet(false);
868 set.addAnimation(clipAnimLR);
869 set.addAnimation(clipAnimTB);
Filip Gruszczynski82861362015-10-16 14:21:09 -0700870 set.addAnimation(translate);
Chet Haase10e23ab2015-02-11 15:08:38 -0800871 set.addAnimation(alpha);
Filip Gruszczynski9e2cf5b2015-07-31 12:20:40 -0700872 set.setZAdjustment(Animation.ZORDER_TOP);
Chet Haase10e23ab2015-02-11 15:08:38 -0800873 set.initialize(appWidth, appHeight, appWidth, appHeight);
874 anim = set;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800875 mLastHadClipReveal = true;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800876 mLastClipRevealTransitionDuration = duration;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800877
878 // If the start rect was full inside the target rect (cutOff == false), we don't need
879 // to store the translation, because it's only used if cutOff == true.
880 mLastClipRevealMaxTranslation = cutOff
881 ? Math.max(Math.abs(translationY), Math.abs(translationX)) : 0;
Chet Haase10e23ab2015-02-11 15:08:38 -0800882 } else {
883 final long duration;
884 switch (transit) {
885 case TRANSIT_ACTIVITY_OPEN:
886 case TRANSIT_ACTIVITY_CLOSE:
887 duration = mConfigShortAnimTime;
888 break;
889 default:
890 duration = DEFAULT_APP_TRANSITION_DURATION;
891 break;
892 }
893 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
894 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
895 // If we are on top of the wallpaper, we need an animation that
896 // correctly handles the wallpaper staying static behind all of
897 // the animated elements. To do this, will just have the existing
898 // element fade out.
899 anim = new AlphaAnimation(1, 0);
900 anim.setDetachWallpaper(true);
901 } else {
902 // For normal animations, the exiting element just holds in place.
903 anim = new AlphaAnimation(1, 1);
904 }
905 anim.setInterpolator(mDecelerateInterpolator);
906 anim.setDuration(duration);
907 anim.setFillAfter(true);
908 }
909 return anim;
910 }
911
Winson Chung399f6202014-03-19 10:47:20 -0700912 /**
913 * Prepares the specified animation with a standard duration, interpolator, etc.
914 */
Winson Chung5393dff2014-05-08 14:25:43 -0700915 Animation prepareThumbnailAnimationWithDuration(Animation a, int appWidth, int appHeight,
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100916 long duration, Interpolator interpolator) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700917 if (duration > 0) {
918 a.setDuration(duration);
919 }
Winson Chung5393dff2014-05-08 14:25:43 -0700920 a.setFillAfter(true);
Jorim Jaggic69bd222016-03-15 14:38:37 +0100921 if (interpolator != null) {
922 a.setInterpolator(interpolator);
923 }
Winson Chung5393dff2014-05-08 14:25:43 -0700924 a.initialize(appWidth, appHeight, appWidth, appHeight);
925 return a;
926 }
927
928 /**
929 * Prepares the specified animation with a standard duration, interpolator, etc.
930 */
Winson Chung399f6202014-03-19 10:47:20 -0700931 Animation prepareThumbnailAnimation(Animation a, int appWidth, int appHeight, int transit) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800932 // Pick the desired duration. If this is an inter-activity transition,
933 // it is the standard duration for that. Otherwise we use the longer
934 // task transition duration.
Winson Chung5393dff2014-05-08 14:25:43 -0700935 final int duration;
Craig Mautner321bdf52012-12-18 09:53:24 -0800936 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800937 case TRANSIT_ACTIVITY_OPEN:
938 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800939 duration = mConfigShortAnimTime;
940 break;
941 default:
942 duration = DEFAULT_APP_TRANSITION_DURATION;
943 break;
944 }
Winson Chung5393dff2014-05-08 14:25:43 -0700945 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, duration,
946 mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800947 }
948
Winson Chung399f6202014-03-19 10:47:20 -0700949 /**
950 * Return the current thumbnail transition state.
951 */
952 int getThumbnailTransitionState(boolean enter) {
953 if (enter) {
954 if (mNextAppTransitionScaleUp) {
955 return THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
956 } else {
957 return THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN;
958 }
959 } else {
960 if (mNextAppTransitionScaleUp) {
961 return THUMBNAIL_TRANSITION_EXIT_SCALE_UP;
962 } else {
963 return THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN;
964 }
965 }
966 }
967
968 /**
Tony Mak64b8d562017-12-28 17:44:02 +0000969 * Creates an overlay with a background color and a thumbnail for the cross profile apps
970 * animation.
971 */
972 GraphicBuffer createCrossProfileAppsThumbnail(
973 @DrawableRes int thumbnailDrawableRes, Rect frame) {
974 final int width = frame.width();
975 final int height = frame.height();
976
John Reck519ad482018-02-12 17:08:48 -0800977 final Picture picture = new Picture();
978 final Canvas canvas = picture.beginRecording(width, height);
Tony Mak64b8d562017-12-28 17:44:02 +0000979 canvas.drawColor(Color.argb(0.6f, 0, 0, 0));
980 final int thumbnailSize = mService.mContext.getResources().getDimensionPixelSize(
981 com.android.internal.R.dimen.cross_profile_apps_thumbnail_size);
982 final Drawable drawable = mService.mContext.getDrawable(thumbnailDrawableRes);
983 drawable.setBounds(
984 (width - thumbnailSize) / 2,
985 (height - thumbnailSize) / 2,
986 (width + thumbnailSize) / 2,
987 (height + thumbnailSize) / 2);
988 drawable.draw(canvas);
John Reck519ad482018-02-12 17:08:48 -0800989 picture.endRecording();
Tony Mak64b8d562017-12-28 17:44:02 +0000990
John Reck519ad482018-02-12 17:08:48 -0800991 return Bitmap.createBitmap(picture).createGraphicBufferHandle();
Tony Mak64b8d562017-12-28 17:44:02 +0000992 }
993
994 Animation createCrossProfileAppsThumbnailAnimationLocked(Rect appRect) {
995 final Animation animation = loadAnimationRes(
996 "android", com.android.internal.R.anim.cross_profile_apps_thumbnail_enter);
997 return prepareThumbnailAnimationWithDuration(animation, appRect.width(),
998 appRect.height(), 0, null);
999 }
1000
1001 /**
Winson Chung399f6202014-03-19 10:47:20 -07001002 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001003 * when a thumbnail is specified with the pending animation override.
Winson Chung399f6202014-03-19 10:47:20 -07001004 */
Jorim Jaggide63d442016-03-14 14:56:56 +01001005 Animation createThumbnailAspectScaleAnimationLocked(Rect appRect, @Nullable Rect contentInsets,
Winson Chungaa7fa012017-05-24 15:50:06 -07001006 GraphicBuffer thumbnailHeader, final int taskId, int uiMode, int orientation) {
Winson Chung399f6202014-03-19 10:47:20 -07001007 Animation a;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001008 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chung399f6202014-03-19 10:47:20 -07001009 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001010 final int thumbHeightI = thumbnailHeader.getHeight();
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -07001011 final int appWidth = appRect.width();
Winson Chung399f6202014-03-19 10:47:20 -07001012
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -07001013 float scaleW = appWidth / thumbWidth;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001014 getNextAppTransitionStartRect(taskId, mTmpRect);
Jorim Jaggi09072002016-03-25 16:48:42 -07001015 final float fromX;
Manu Cornet57b61492017-01-24 18:19:05 +09001016 float fromY;
Jorim Jaggi09072002016-03-25 16:48:42 -07001017 final float toX;
Manu Cornet57b61492017-01-24 18:19:05 +09001018 float toY;
Jorim Jaggi09072002016-03-25 16:48:42 -07001019 final float pivotX;
1020 final float pivotY;
Manu Cornetd7376802017-01-13 13:44:07 -08001021 if (shouldScaleDownThumbnailTransition(uiMode, orientation)) {
Jorim Jaggi09072002016-03-25 16:48:42 -07001022 fromX = mTmpRect.left;
1023 fromY = mTmpRect.top;
1024
1025 // For the curved translate animation to work, the pivot points needs to be at the
1026 // same absolute position as the one from the real surface.
1027 toX = mTmpRect.width() / 2 * (scaleW - 1f) + appRect.left;
1028 toY = appRect.height() / 2 * (1 - 1 / scaleW) + appRect.top;
1029 pivotX = mTmpRect.width() / 2;
1030 pivotY = appRect.height() / 2 / scaleW;
Manu Cornet57b61492017-01-24 18:19:05 +09001031 if (mGridLayoutRecentsEnabled) {
1032 // In the grid layout, the header is displayed above the thumbnail instead of
1033 // overlapping it.
1034 fromY -= thumbHeightI;
1035 toY -= thumbHeightI * scaleW;
1036 }
Jorim Jaggi09072002016-03-25 16:48:42 -07001037 } else {
1038 pivotX = 0;
1039 pivotY = 0;
1040 fromX = mTmpRect.left;
1041 fromY = mTmpRect.top;
1042 toX = appRect.left;
1043 toY = appRect.top;
1044 }
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001045 final long duration = getAspectScaleDuration();
1046 final Interpolator interpolator = getAspectScaleInterpolator();
Winson Chung399f6202014-03-19 10:47:20 -07001047 if (mNextAppTransitionScaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001048 // Animation up from the thumbnail to the full screen
Jorim Jaggi8448f332016-03-14 17:50:37 +01001049 Animation scale = new ScaleAnimation(1f, scaleW, 1f, scaleW, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001050 scale.setInterpolator(interpolator);
1051 scale.setDuration(duration);
Jorim Jaggic6c89a82016-01-28 17:48:21 -08001052 Animation alpha = new AlphaAnimation(1f, 0f);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001053 alpha.setInterpolator(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
1054 ? THUMBNAIL_DOCK_INTERPOLATOR : mThumbnailFadeOutInterpolator);
1055 alpha.setDuration(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
1056 ? duration / 2
1057 : duration);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001058 Animation translate = createCurvedMotion(fromX, toX, fromY, toY);
1059 translate.setInterpolator(interpolator);
1060 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -07001061
Jorim Jaggide63d442016-03-14 14:56:56 +01001062 mTmpFromClipRect.set(0, 0, thumbWidthI, thumbHeightI);
1063 mTmpToClipRect.set(appRect);
1064
1065 // Containing frame is in screen space, but we need the clip rect in the
1066 // app space.
1067 mTmpToClipRect.offsetTo(0, 0);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001068 mTmpToClipRect.right = (int) (mTmpToClipRect.right / scaleW);
1069 mTmpToClipRect.bottom = (int) (mTmpToClipRect.bottom / scaleW);
Jorim Jaggide63d442016-03-14 14:56:56 +01001070
1071 if (contentInsets != null) {
Jorim Jaggi8448f332016-03-14 17:50:37 +01001072 mTmpToClipRect.inset((int) (-contentInsets.left * scaleW),
1073 (int) (-contentInsets.top * scaleW),
1074 (int) (-contentInsets.right * scaleW),
1075 (int) (-contentInsets.bottom * scaleW));
Jorim Jaggide63d442016-03-14 14:56:56 +01001076 }
1077
1078 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001079 clipAnim.setInterpolator(interpolator);
1080 clipAnim.setDuration(duration);
Jorim Jaggide63d442016-03-14 14:56:56 +01001081
Winson Chung399f6202014-03-19 10:47:20 -07001082 // This AnimationSet uses the Interpolators assigned above.
1083 AnimationSet set = new AnimationSet(false);
1084 set.addAnimation(scale);
Manu Cornet57b61492017-01-24 18:19:05 +09001085 if (!mGridLayoutRecentsEnabled) {
1086 // In the grid layout, the header should be shown for the whole animation.
1087 set.addAnimation(alpha);
1088 }
Winson Chunga4ccb862014-08-22 15:26:27 -07001089 set.addAnimation(translate);
Jorim Jaggide63d442016-03-14 14:56:56 +01001090 set.addAnimation(clipAnim);
Winson Chung399f6202014-03-19 10:47:20 -07001091 a = set;
1092 } else {
Winson Chunga4ccb862014-08-22 15:26:27 -07001093 // Animation down from the full screen to the thumbnail
Jorim Jaggi8448f332016-03-14 17:50:37 +01001094 Animation scale = new ScaleAnimation(scaleW, 1f, scaleW, 1f, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001095 scale.setInterpolator(interpolator);
1096 scale.setDuration(duration);
Winson Chunga4ccb862014-08-22 15:26:27 -07001097 Animation alpha = new AlphaAnimation(0f, 1f);
1098 alpha.setInterpolator(mThumbnailFadeInInterpolator);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001099 alpha.setDuration(duration);
1100 Animation translate = createCurvedMotion(toX, fromX, toY, fromY);
1101 translate.setInterpolator(interpolator);
1102 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -07001103
Winson Chunga4ccb862014-08-22 15:26:27 -07001104 // This AnimationSet uses the Interpolators assigned above.
1105 AnimationSet set = new AnimationSet(false);
1106 set.addAnimation(scale);
Manu Cornet57b61492017-01-24 18:19:05 +09001107 if (!mGridLayoutRecentsEnabled) {
1108 // In the grid layout, the header should be shown for the whole animation.
1109 set.addAnimation(alpha);
1110 }
Winson Chunga4ccb862014-08-22 15:26:27 -07001111 set.addAnimation(translate);
1112 a = set;
1113
1114 }
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -07001115 return prepareThumbnailAnimationWithDuration(a, appWidth, appRect.height(), 0,
Jorim Jaggic69bd222016-03-15 14:38:37 +01001116 null);
Winson Chung399f6202014-03-19 10:47:20 -07001117 }
1118
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001119 private Animation createCurvedMotion(float fromX, float toX, float fromY, float toY) {
1120
1121 // Almost no x-change - use linear animation
Jorim Jaggic69bd222016-03-15 14:38:37 +01001122 if (Math.abs(toX - fromX) < 1f || mNextAppTransition != TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001123 return new TranslateAnimation(fromX, toX, fromY, toY);
1124 } else {
1125 final Path path = createCurvedPath(fromX, toX, fromY, toY);
1126 return new CurvedTranslateAnimation(path);
1127 }
1128 }
1129
1130 private Path createCurvedPath(float fromX, float toX, float fromY, float toY) {
1131 final Path path = new Path();
1132 path.moveTo(fromX, fromY);
Jorim Jaggi1f458fb2016-03-25 17:36:37 -07001133
1134 if (fromY > toY) {
1135 // If the object needs to go up, move it in horizontal direction first, then vertical.
1136 path.cubicTo(fromX, fromY, toX, 0.9f * fromY + 0.1f * toY, toX, toY);
1137 } else {
1138 // If the object needs to go down, move it in vertical direction first, then horizontal.
1139 path.cubicTo(fromX, fromY, fromX, 0.1f * fromY + 0.9f * toY, toX, toY);
1140 }
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001141 return path;
1142 }
1143
1144 private long getAspectScaleDuration() {
1145 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggic69bd222016-03-15 14:38:37 +01001146 return (long) (THUMBNAIL_APP_TRANSITION_DURATION * 1.35f);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001147 } else {
1148 return THUMBNAIL_APP_TRANSITION_DURATION;
1149 }
1150 }
1151
1152 private Interpolator getAspectScaleInterpolator() {
1153 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
1154 return mFastOutSlowInInterpolator;
1155 } else {
1156 return TOUCH_RESPONSE_INTERPOLATOR;
1157 }
1158 }
1159
Winson Chung399f6202014-03-19 10:47:20 -07001160 /**
1161 * This alternate animation is created when we are doing a thumbnail transition, for the
1162 * activity that is leaving, and the activity that is entering.
1163 */
Winson Chunga4ccb862014-08-22 15:26:27 -07001164 Animation createAspectScaledThumbnailEnterExitAnimationLocked(int thumbTransitState,
Winsonb2024762016-04-05 17:32:30 -07001165 int uiMode, int orientation, int transit, Rect containingFrame, Rect contentInsets,
Matthew Ng43db6d22017-06-27 15:29:39 -07001166 @Nullable Rect surfaceInsets, @Nullable Rect stableInsets, boolean freeform,
1167 int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -07001168 Animation a;
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001169 final int appWidth = containingFrame.width();
1170 final int appHeight = containingFrame.height();
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001171 getDefaultNextAppTransitionStartRect(mTmpRect);
1172 final int thumbWidthI = mTmpRect.width();
Winson Chung399f6202014-03-19 10:47:20 -07001173 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001174 final int thumbHeightI = mTmpRect.height();
Winson Chung399f6202014-03-19 10:47:20 -07001175 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
Winsoncbb625b2016-07-06 15:24:15 -07001176 final int thumbStartX = mTmpRect.left - containingFrame.left - contentInsets.left;
Winson21700932016-03-24 17:26:23 -07001177 final int thumbStartY = mTmpRect.top - containingFrame.top;
Winson Chung399f6202014-03-19 10:47:20 -07001178
1179 switch (thumbTransitState) {
Jorim Jaggi8448f332016-03-14 17:50:37 +01001180 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP:
1181 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1182 final boolean scaleUp = thumbTransitState == THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
1183 if (freeform && scaleUp) {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001184 a = createAspectScaledThumbnailEnterFreeformAnimationLocked(
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001185 containingFrame, surfaceInsets, taskId);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001186 } else if (freeform) {
1187 a = createAspectScaledThumbnailExitFreeformAnimationLocked(
1188 containingFrame, surfaceInsets, taskId);
Winson Chung2820c452014-04-15 15:34:44 -07001189 } else {
Winson21700932016-03-24 17:26:23 -07001190 AnimationSet set = new AnimationSet(true);
1191
1192 // In portrait, we scale to fit the width
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001193 mTmpFromClipRect.set(containingFrame);
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001194 mTmpToClipRect.set(containingFrame);
Jorim Jaggic6c89a82016-01-28 17:48:21 -08001195
1196 // Containing frame is in screen space, but we need the clip rect in the
1197 // app space.
1198 mTmpFromClipRect.offsetTo(0, 0);
1199 mTmpToClipRect.offsetTo(0, 0);
1200
1201 // Exclude insets region from the source clip.
1202 mTmpFromClipRect.inset(contentInsets);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001203 mNextAppTransitionInsets.set(contentInsets);
1204
Manu Cornetd7376802017-01-13 13:44:07 -08001205 if (shouldScaleDownThumbnailTransition(uiMode, orientation)) {
Jorim Jaggic69bd222016-03-15 14:38:37 +01001206 // We scale the width and clip to the top/left square
1207 float scale = thumbWidth /
1208 (appWidth - contentInsets.left - contentInsets.right);
Manu Cornetb68b7652017-01-23 19:37:53 +09001209 if (!mGridLayoutRecentsEnabled) {
1210 int unscaledThumbHeight = (int) (thumbHeight / scale);
1211 mTmpFromClipRect.bottom = mTmpFromClipRect.top + unscaledThumbHeight;
1212 }
Jorim Jaggic69bd222016-03-15 14:38:37 +01001213
1214 mNextAppTransitionInsets.set(contentInsets);
1215
Jorim Jaggi8448f332016-03-14 17:50:37 +01001216 Animation scaleAnim = new ScaleAnimation(
1217 scaleUp ? scale : 1, scaleUp ? 1 : scale,
1218 scaleUp ? scale : 1, scaleUp ? 1 : scale,
Jorim Jaggic69bd222016-03-15 14:38:37 +01001219 containingFrame.width() / 2f,
1220 containingFrame.height() / 2f + contentInsets.top);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001221 final float targetX = (mTmpRect.left - containingFrame.left);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001222 final float x = containingFrame.width() / 2f
1223 - containingFrame.width() / 2f * scale;
Jorim Jaggi8448f332016-03-14 17:50:37 +01001224 final float targetY = (mTmpRect.top - containingFrame.top);
Matthew Ng43db6d22017-06-27 15:29:39 -07001225 float y = containingFrame.height() / 2f
Jorim Jaggic69bd222016-03-15 14:38:37 +01001226 - containingFrame.height() / 2f * scale;
Matthew Ng43db6d22017-06-27 15:29:39 -07001227
1228 // During transition may require clipping offset from any top stable insets
1229 // such as the statusbar height when statusbar is hidden
1230 if (mLowRamRecentsEnabled && contentInsets.top == 0 && scaleUp) {
1231 mTmpFromClipRect.top += stableInsets.top;
1232 y += stableInsets.top;
1233 }
Jorim Jaggi8448f332016-03-14 17:50:37 +01001234 final float startX = targetX - x;
1235 final float startY = targetY - y;
1236 Animation clipAnim = scaleUp
1237 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1238 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1239 Animation translateAnim = scaleUp
Jorim Jaggic69bd222016-03-15 14:38:37 +01001240 ? createCurvedMotion(startX, 0, startY - contentInsets.top, 0)
1241 : createCurvedMotion(0, startX, 0, startY - contentInsets.top);
1242
Winson21700932016-03-24 17:26:23 -07001243 set.addAnimation(clipAnim);
1244 set.addAnimation(scaleAnim);
1245 set.addAnimation(translateAnim);
1246
1247 } else {
1248 // In landscape, we don't scale at all and only crop
1249 mTmpFromClipRect.bottom = mTmpFromClipRect.top + thumbHeightI;
1250 mTmpFromClipRect.right = mTmpFromClipRect.left + thumbWidthI;
1251
Jorim Jaggi8448f332016-03-14 17:50:37 +01001252 Animation clipAnim = scaleUp
1253 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1254 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1255 Animation translateAnim = scaleUp
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001256 ? createCurvedMotion(thumbStartX, 0,
1257 thumbStartY - contentInsets.top, 0)
1258 : createCurvedMotion(0, thumbStartX, 0,
1259 thumbStartY - contentInsets.top);
Winson21700932016-03-24 17:26:23 -07001260
1261 set.addAnimation(clipAnim);
1262 set.addAnimation(translateAnim);
1263 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001264 a = set;
Winson21700932016-03-24 17:26:23 -07001265 a.setZAdjustment(Animation.ZORDER_TOP);
Winson Chung2820c452014-04-15 15:34:44 -07001266 }
Winson Chung399f6202014-03-19 10:47:20 -07001267 break;
1268 }
1269 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001270 // Previous app window during the scale up
Winson Chung399f6202014-03-19 10:47:20 -07001271 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001272 // Fade out the source activity if we are animating to a wallpaper
Winson Chung399f6202014-03-19 10:47:20 -07001273 // activity.
1274 a = new AlphaAnimation(1, 0);
1275 } else {
Winson Chung399f6202014-03-19 10:47:20 -07001276 a = new AlphaAnimation(1, 1);
1277 }
1278 break;
1279 }
1280 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001281 // Target app window during the scale down
1282 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1283 // Fade in the destination activity if we are animating from a wallpaper
1284 // activity.
1285 a = new AlphaAnimation(0, 1);
1286 } else {
1287 a = new AlphaAnimation(1, 1);
1288 }
Winson Chung399f6202014-03-19 10:47:20 -07001289 break;
1290 }
Winson Chung399f6202014-03-19 10:47:20 -07001291 default:
1292 throw new RuntimeException("Invalid thumbnail transition state");
1293 }
1294
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001295 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight,
1296 getAspectScaleDuration(), getAspectScaleInterpolator());
Winson Chung399f6202014-03-19 10:47:20 -07001297 }
1298
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001299 private Animation createAspectScaledThumbnailEnterFreeformAnimationLocked(Rect frame,
1300 @Nullable Rect surfaceInsets, int taskId) {
1301 getNextAppTransitionStartRect(taskId, mTmpRect);
1302 return createAspectScaledThumbnailFreeformAnimationLocked(mTmpRect, frame, surfaceInsets,
1303 true);
1304 }
1305
1306 private Animation createAspectScaledThumbnailExitFreeformAnimationLocked(Rect frame,
1307 @Nullable Rect surfaceInsets, int taskId) {
1308 getNextAppTransitionStartRect(taskId, mTmpRect);
1309 return createAspectScaledThumbnailFreeformAnimationLocked(frame, mTmpRect, surfaceInsets,
1310 false);
1311 }
1312
1313 private AnimationSet createAspectScaledThumbnailFreeformAnimationLocked(Rect sourceFrame,
1314 Rect destFrame, @Nullable Rect surfaceInsets, boolean enter) {
1315 final float sourceWidth = sourceFrame.width();
1316 final float sourceHeight = sourceFrame.height();
1317 final float destWidth = destFrame.width();
1318 final float destHeight = destFrame.height();
1319 final float scaleH = enter ? sourceWidth / destWidth : destWidth / sourceWidth;
1320 final float scaleV = enter ? sourceHeight / destHeight : destHeight / sourceHeight;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001321 AnimationSet set = new AnimationSet(true);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001322 final int surfaceInsetsH = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001323 ? 0 : surfaceInsets.left + surfaceInsets.right;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001324 final int surfaceInsetsV = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001325 ? 0 : surfaceInsets.top + surfaceInsets.bottom;
1326 // We want the scaling to happen from the center of the surface. In order to achieve that,
1327 // we need to account for surface insets that will be used to enlarge the surface.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001328 final float scaleHCenter = ((enter ? destWidth : sourceWidth) + surfaceInsetsH) / 2;
1329 final float scaleVCenter = ((enter ? destHeight : sourceHeight) + surfaceInsetsV) / 2;
1330 final ScaleAnimation scale = enter ?
1331 new ScaleAnimation(scaleH, 1, scaleV, 1, scaleHCenter, scaleVCenter)
1332 : new ScaleAnimation(1, scaleH, 1, scaleV, scaleHCenter, scaleVCenter);
1333 final int sourceHCenter = sourceFrame.left + sourceFrame.width() / 2;
1334 final int sourceVCenter = sourceFrame.top + sourceFrame.height() / 2;
1335 final int destHCenter = destFrame.left + destFrame.width() / 2;
1336 final int destVCenter = destFrame.top + destFrame.height() / 2;
1337 final int fromX = enter ? sourceHCenter - destHCenter : destHCenter - sourceHCenter;
1338 final int fromY = enter ? sourceVCenter - destVCenter : destVCenter - sourceVCenter;
1339 final TranslateAnimation translation = enter ? new TranslateAnimation(fromX, 0, fromY, 0)
1340 : new TranslateAnimation(0, fromX, 0, fromY);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001341 set.addAnimation(scale);
1342 set.addAnimation(translation);
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001343
1344 final IRemoteCallback callback = mAnimationFinishedCallback;
1345 if (callback != null) {
1346 set.setAnimationListener(new Animation.AnimationListener() {
1347 @Override
1348 public void onAnimationStart(Animation animation) { }
1349
1350 @Override
1351 public void onAnimationEnd(Animation animation) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001352 mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK, callback).sendToTarget();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001353 }
1354
1355 @Override
1356 public void onAnimationRepeat(Animation animation) { }
1357 });
1358 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001359 return set;
1360 }
1361
Winson Chung399f6202014-03-19 10:47:20 -07001362 /**
Winson Chunga4ccb862014-08-22 15:26:27 -07001363 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001364 * when a thumbnail is specified with the pending animation override.
Winson Chunga4ccb862014-08-22 15:26:27 -07001365 */
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001366 Animation createThumbnailScaleAnimationLocked(int appWidth, int appHeight, int transit,
Winson Chungaa7fa012017-05-24 15:50:06 -07001367 GraphicBuffer thumbnailHeader) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001368 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001369 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001370 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chunga4ccb862014-08-22 15:26:27 -07001371 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001372 final int thumbHeightI = thumbnailHeader.getHeight();
Winson Chunga4ccb862014-08-22 15:26:27 -07001373 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1374
1375 if (mNextAppTransitionScaleUp) {
1376 // Animation for the thumbnail zooming from its initial size to the full screen
1377 float scaleW = appWidth / thumbWidth;
1378 float scaleH = appHeight / thumbHeight;
1379 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001380 computePivot(mTmpRect.left, 1 / scaleW),
1381 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001382 scale.setInterpolator(mDecelerateInterpolator);
1383
1384 Animation alpha = new AlphaAnimation(1, 0);
1385 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
1386
1387 // This AnimationSet uses the Interpolators assigned above.
1388 AnimationSet set = new AnimationSet(false);
1389 set.addAnimation(scale);
1390 set.addAnimation(alpha);
1391 a = set;
1392 } else {
1393 // Animation for the thumbnail zooming down from the full screen to its final size
1394 float scaleW = appWidth / thumbWidth;
1395 float scaleH = appHeight / thumbHeight;
1396 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001397 computePivot(mTmpRect.left, 1 / scaleW),
1398 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001399 }
1400
1401 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1402 }
1403
1404 /**
Winson Chung399f6202014-03-19 10:47:20 -07001405 * This animation is created when we are doing a thumbnail transition, for the activity that is
1406 * leaving, and the activity that is entering.
1407 */
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001408 Animation createThumbnailEnterExitAnimationLocked(int thumbTransitState, Rect containingFrame,
1409 int transit, int taskId) {
1410 final int appWidth = containingFrame.width();
1411 final int appHeight = containingFrame.height();
Winson Chungaa7fa012017-05-24 15:50:06 -07001412 final GraphicBuffer thumbnailHeader = getAppTransitionThumbnailHeader(taskId);
Winson Chung399f6202014-03-19 10:47:20 -07001413 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001414 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001415 final int thumbWidthI = thumbnailHeader != null ? thumbnailHeader.getWidth() : appWidth;
Winson Chung399f6202014-03-19 10:47:20 -07001416 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001417 final int thumbHeightI = thumbnailHeader != null ? thumbnailHeader.getHeight() : appHeight;
Winson Chung399f6202014-03-19 10:47:20 -07001418 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1419
1420 switch (thumbTransitState) {
1421 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
1422 // Entering app scales up with the thumbnail
1423 float scaleW = thumbWidth / appWidth;
1424 float scaleH = thumbHeight / appHeight;
1425 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001426 computePivot(mTmpRect.left, scaleW),
1427 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001428 break;
1429 }
1430 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
1431 // Exiting app while the thumbnail is scaling up should fade or stay in place
1432 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1433 // Fade out while bringing up selected activity. This keeps the
1434 // current activity from showing through a launching wallpaper
1435 // activity.
1436 a = new AlphaAnimation(1, 0);
1437 } else {
1438 // noop animation
1439 a = new AlphaAnimation(1, 1);
1440 }
1441 break;
1442 }
1443 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
1444 // Entering the other app, it should just be visible while we scale the thumbnail
1445 // down above it
1446 a = new AlphaAnimation(1, 1);
1447 break;
1448 }
1449 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1450 // Exiting the current app, the app should scale down with the thumbnail
1451 float scaleW = thumbWidth / appWidth;
1452 float scaleH = thumbHeight / appHeight;
1453 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001454 computePivot(mTmpRect.left, scaleW),
1455 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001456
1457 Animation alpha = new AlphaAnimation(1, 0);
1458
1459 AnimationSet set = new AnimationSet(true);
1460 set.addAnimation(scale);
1461 set.addAnimation(alpha);
1462 set.setZAdjustment(Animation.ZORDER_TOP);
1463 a = set;
1464 break;
1465 }
1466 default:
1467 throw new RuntimeException("Invalid thumbnail transition state");
1468 }
1469
1470 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1471 }
1472
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001473 private Animation createRelaunchAnimation(Rect containingFrame, Rect contentInsets) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001474 getDefaultNextAppTransitionStartRect(mTmpFromClipRect);
1475 final int left = mTmpFromClipRect.left;
1476 final int top = mTmpFromClipRect.top;
1477 mTmpFromClipRect.offset(-left, -top);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001478 // TODO: Isn't that strange that we ignore exact position of the containingFrame?
1479 mTmpToClipRect.set(0, 0, containingFrame.width(), containingFrame.height());
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001480 AnimationSet set = new AnimationSet(true);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001481 float fromWidth = mTmpFromClipRect.width();
1482 float toWidth = mTmpToClipRect.width();
1483 float fromHeight = mTmpFromClipRect.height();
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001484 // While the window might span the whole display, the actual content will be cropped to the
1485 // system decoration frame, for example when the window is docked. We need to take into
1486 // account the visible height when constructing the animation.
1487 float toHeight = mTmpToClipRect.height() - contentInsets.top - contentInsets.bottom;
1488 int translateAdjustment = 0;
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001489 if (fromWidth <= toWidth && fromHeight <= toHeight) {
1490 // The final window is larger in both dimensions than current window (e.g. we are
1491 // maximizing), so we can simply unclip the new window and there will be no disappearing
1492 // frame.
1493 set.addAnimation(new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect));
1494 } else {
1495 // The disappearing window has one larger dimension. We need to apply scaling, so the
1496 // first frame of the entry animation matches the old window.
1497 set.addAnimation(new ScaleAnimation(fromWidth / toWidth, 1, fromHeight / toHeight, 1));
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001498 // We might not be going exactly full screen, but instead be aligned under the status
1499 // bar using cropping. We still need to account for the cropped part, which will also
1500 // be scaled.
1501 translateAdjustment = (int) (contentInsets.top * fromHeight / toHeight);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001502 }
1503
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001504 // We animate the translation from the old position of the removed window, to the new
1505 // position of the added window. The latter might not be full screen, for example docked for
1506 // docked windows.
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001507 TranslateAnimation translate = new TranslateAnimation(left - containingFrame.left,
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001508 0, top - containingFrame.top - translateAdjustment, 0);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001509 set.addAnimation(translate);
1510 set.setDuration(DEFAULT_APP_TRANSITION_DURATION);
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07001511 set.setZAdjustment(Animation.ZORDER_TOP);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001512 return set;
1513 }
1514
Jorim Jaggic554b772015-06-04 16:07:57 -07001515 /**
1516 * @return true if and only if the first frame of the transition can be skipped, i.e. the first
1517 * frame of the transition doesn't change the visuals on screen, so we can start
1518 * directly with the second one
1519 */
1520 boolean canSkipFirstFrame() {
1521 return mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM
1522 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE
Jorim Jaggife762342016-10-13 14:33:27 +02001523 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CLIP_REVEAL
1524 && mNextAppTransition != TRANSIT_KEYGUARD_GOING_AWAY;
Jorim Jaggic554b772015-06-04 16:07:57 -07001525 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001526
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001527 RemoteAnimationController getRemoteAnimationController() {
1528 return mRemoteAnimationController;
1529 }
1530
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001531 /**
1532 *
1533 * @param frame These are the bounds of the window when it finishes the animation. This is where
1534 * the animation must usually finish in entrance animation, as the next frame will
1535 * display the window at these coordinates. In case of exit animation, this is
1536 * where the animation must start, as the frame before the animation is displaying
1537 * the window at these bounds.
1538 * @param insets Knowing where the window will be positioned is not enough. Some parts of the
1539 * window might be obscured, usually by the system windows (status bar and
1540 * navigation bar) and we use content insets to convey that information. This
1541 * usually affects the animation aspects vertically, as the system decoration is
1542 * at the top and the bottom. For example when we animate from full screen to
1543 * recents, we want to exclude the covered parts, because they won't match the
1544 * thumbnail after the last frame is executed.
1545 * @param surfaceInsets In rare situation the surface is larger than the content and we need to
1546 * know about this to make the animation frames match. We currently use
1547 * this for freeform windows, which have larger surfaces to display
1548 * shadows. When we animate them from recents, we want to match the content
1549 * to the recents thumbnail and hence need to account for the surface being
1550 * bigger.
1551 */
Jorim Jaggif84e2f62018-01-16 14:17:59 +01001552 Animation loadAnimation(LayoutParams lp, int transit, boolean enter, int uiMode,
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001553 int orientation, Rect frame, Rect displayFrame, Rect insets,
Matthew Ng43db6d22017-06-27 15:29:39 -07001554 @Nullable Rect surfaceInsets, @Nullable Rect stableInsets, boolean isVoiceInteraction,
1555 boolean freeform, int taskId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001556 Animation a;
Jorim Jaggife762342016-10-13 14:33:27 +02001557 if (isKeyguardGoingAwayTransit(transit) && enter) {
1558 a = loadKeyguardExitAnimation(transit);
1559 } else if (transit == TRANSIT_KEYGUARD_OCCLUDE) {
1560 a = null;
1561 } else if (transit == TRANSIT_KEYGUARD_UNOCCLUDE && !enter) {
1562 a = loadAnimationRes(lp, com.android.internal.R.anim.wallpaper_open_exit);
1563 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_OPEN
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001564 || transit == TRANSIT_TASK_OPEN
1565 || transit == TRANSIT_TASK_TO_FRONT)) {
1566 a = loadAnimationRes(lp, enter
1567 ? com.android.internal.R.anim.voice_activity_open_enter
1568 : com.android.internal.R.anim.voice_activity_open_exit);
1569 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1570 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001571 + " anim=" + a + " transit=" + appTransitionToString(transit)
1572 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001573 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_CLOSE
1574 || transit == TRANSIT_TASK_CLOSE
1575 || transit == TRANSIT_TASK_TO_BACK)) {
1576 a = loadAnimationRes(lp, enter
1577 ? com.android.internal.R.anim.voice_activity_close_enter
1578 : com.android.internal.R.anim.voice_activity_close_exit);
1579 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1580 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001581 + " anim=" + a + " transit=" + appTransitionToString(transit)
1582 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001583 } else if (transit == TRANSIT_ACTIVITY_RELAUNCH) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001584 a = createRelaunchAnimation(frame, insets);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001585 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1586 "applyAnimation:"
1587 + " anim=" + a + " nextAppTransition=" + mNextAppTransition
1588 + " transit=" + appTransitionToString(transit)
1589 + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001590 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM) {
1591 a = loadAnimationRes(mNextAppTransitionPackage, enter ?
Craig Mautner164d4bb2012-11-26 13:51:23 -08001592 mNextAppTransitionEnter : mNextAppTransitionExit);
1593 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1594 "applyAnimation:"
1595 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001596 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001597 + " Callers=" + Debug.getCallers(3));
Winson Chung044d5292014-11-06 11:05:19 -08001598 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE) {
1599 a = loadAnimationRes(mNextAppTransitionPackage, mNextAppTransitionInPlace);
1600 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1601 "applyAnimation:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001602 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM_IN_PLACE"
1603 + " transit=" + appTransitionToString(transit)
1604 + " Callers=" + Debug.getCallers(3));
Chet Haase10e23ab2015-02-11 15:08:38 -08001605 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001606 a = createClipRevealAnimationLocked(transit, enter, frame, displayFrame);
Chet Haase10e23ab2015-02-11 15:08:38 -08001607 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1608 "applyAnimation:"
1609 + " anim=" + a + " nextAppTransition=ANIM_CLIP_REVEAL"
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001610 + " transit=" + appTransitionToString(transit)
Chet Haase10e23ab2015-02-11 15:08:38 -08001611 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001612 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_SCALE_UP) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001613 a = createScaleUpAnimationLocked(transit, enter, frame);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001614 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1615 "applyAnimation:"
1616 + " anim=" + a + " nextAppTransition=ANIM_SCALE_UP"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001617 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001618 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001619 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
1620 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001621 mNextAppTransitionScaleUp =
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001622 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP);
Winson Chunga4ccb862014-08-22 15:26:27 -07001623 a = createThumbnailEnterExitAnimationLocked(getThumbnailTransitionState(enter),
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001624 frame, transit, taskId);
Winson Chunga4ccb862014-08-22 15:26:27 -07001625 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1626 String animName = mNextAppTransitionScaleUp ?
1627 "ANIM_THUMBNAIL_SCALE_UP" : "ANIM_THUMBNAIL_SCALE_DOWN";
1628 Slog.v(TAG, "applyAnimation:"
1629 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001630 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Winson Chunga4ccb862014-08-22 15:26:27 -07001631 + " Callers=" + Debug.getCallers(3));
1632 }
1633 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
1634 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN) {
1635 mNextAppTransitionScaleUp =
1636 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP);
1637 a = createAspectScaledThumbnailEnterExitAnimationLocked(
Winsonb2024762016-04-05 17:32:30 -07001638 getThumbnailTransitionState(enter), uiMode, orientation, transit, frame,
Matthew Ng43db6d22017-06-27 15:29:39 -07001639 insets, surfaceInsets, stableInsets, freeform, taskId);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001640 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1641 String animName = mNextAppTransitionScaleUp ?
Winson Chunga4ccb862014-08-22 15:26:27 -07001642 "ANIM_THUMBNAIL_ASPECT_SCALE_UP" : "ANIM_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner164d4bb2012-11-26 13:51:23 -08001643 Slog.v(TAG, "applyAnimation:"
1644 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001645 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001646 + " Callers=" + Debug.getCallers(3));
1647 }
Tony Mak83546a82018-01-22 13:56:20 +00001648 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS && enter) {
Tony Mak64b8d562017-12-28 17:44:02 +00001649
Tony Mak089c35e2017-12-18 20:34:14 +00001650 a = loadAnimationRes("android", enter
Tony Mak64b8d562017-12-28 17:44:02 +00001651 ? com.android.internal.R.anim.task_open_enter_cross_profile_apps
1652 : com.android.internal.R.anim.task_open_exit);
Tony Mak089c35e2017-12-18 20:34:14 +00001653 Slog.v(TAG,
1654 "applyAnimation NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS:"
1655 + " anim=" + a + " transit=" + appTransitionToString(transit)
1656 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Craig Mautner164d4bb2012-11-26 13:51:23 -08001657 } else {
1658 int animAttr = 0;
1659 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001660 case TRANSIT_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:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001666 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001667 ? WindowAnimation_activityCloseEnterAnimation
1668 : WindowAnimation_activityCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001669 break;
Jorim Jaggi192086e2016-03-11 17:17:03 +01001670 case TRANSIT_DOCK_TASK_FROM_RECENTS:
Craig Mautner4b71aa12012-12-27 17:20:01 -08001671 case TRANSIT_TASK_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001672 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001673 ? WindowAnimation_taskOpenEnterAnimation
1674 : WindowAnimation_taskOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001675 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001676 case TRANSIT_TASK_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001677 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001678 ? WindowAnimation_taskCloseEnterAnimation
1679 : WindowAnimation_taskCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001680 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001681 case TRANSIT_TASK_TO_FRONT:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001682 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001683 ? WindowAnimation_taskToFrontEnterAnimation
1684 : WindowAnimation_taskToFrontExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001685 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001686 case TRANSIT_TASK_TO_BACK:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001687 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001688 ? WindowAnimation_taskToBackEnterAnimation
1689 : WindowAnimation_taskToBackExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001690 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001691 case TRANSIT_WALLPAPER_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001692 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001693 ? WindowAnimation_wallpaperOpenEnterAnimation
1694 : WindowAnimation_wallpaperOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001695 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001696 case TRANSIT_WALLPAPER_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001697 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001698 ? WindowAnimation_wallpaperCloseEnterAnimation
1699 : WindowAnimation_wallpaperCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001700 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001701 case TRANSIT_WALLPAPER_INTRA_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001702 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001703 ? WindowAnimation_wallpaperIntraOpenEnterAnimation
1704 : WindowAnimation_wallpaperIntraOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001705 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001706 case TRANSIT_WALLPAPER_INTRA_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001707 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001708 ? WindowAnimation_wallpaperIntraCloseEnterAnimation
1709 : WindowAnimation_wallpaperIntraCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001710 break;
Craig Mautnerbb742462014-07-07 15:28:55 -07001711 case TRANSIT_TASK_OPEN_BEHIND:
1712 animAttr = enter
1713 ? WindowAnimation_launchTaskBehindSourceAnimation
Craig Mautner3b2cd1d2014-08-25 14:25:54 -07001714 : WindowAnimation_launchTaskBehindTargetAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001715 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001716 a = animAttr != 0 ? loadAnimationAttr(lp, animAttr) : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001717 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1718 "applyAnimation:"
1719 + " anim=" + a
1720 + " animAttr=0x" + Integer.toHexString(animAttr)
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001721 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001722 + " Callers=" + Debug.getCallers(3));
1723 }
1724 return a;
1725 }
1726
Jorim Jaggife762342016-10-13 14:33:27 +02001727 private Animation loadKeyguardExitAnimation(int transit) {
1728 if ((mNextAppTransitionFlags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_NO_ANIMATION) != 0) {
1729 return null;
1730 }
1731 final boolean toShade =
1732 (mNextAppTransitionFlags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_TO_SHADE) != 0;
1733 return mService.mPolicy.createHiddenByKeyguardExit(
1734 transit == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER, toShade);
1735 }
1736
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001737 int getAppStackClipMode() {
Matthew Ngbf1d9852017-03-14 12:23:09 -07001738 // When dismiss keyguard animation occurs, clip before the animation to prevent docked
1739 // app from showing beyond the divider
1740 if (mNextAppTransition == TRANSIT_KEYGUARD_GOING_AWAY
1741 || mNextAppTransition == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER) {
1742 return STACK_CLIP_BEFORE_ANIM;
1743 }
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001744 return mNextAppTransition == TRANSIT_ACTIVITY_RELAUNCH
Jorim Jaggic69bd222016-03-15 14:38:37 +01001745 || mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
Jorim Jaggi1f458fb2016-03-25 17:36:37 -07001746 || mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001747 ? STACK_CLIP_NONE
1748 : STACK_CLIP_AFTER_ANIM;
1749 }
1750
Jorim Jaggife762342016-10-13 14:33:27 +02001751 public int getTransitFlags() {
1752 return mNextAppTransitionFlags;
1753 }
1754
Craig Mautner164d4bb2012-11-26 13:51:23 -08001755 void postAnimationCallback() {
1756 if (mNextAppTransitionCallback != null) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001757 mService.mH.sendMessage(mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK,
1758 mNextAppTransitionCallback));
Craig Mautner164d4bb2012-11-26 13:51:23 -08001759 mNextAppTransitionCallback = null;
1760 }
1761 }
1762
1763 void overridePendingAppTransition(String packageName, int enterAnim, int exitAnim,
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001764 IRemoteCallback startedCallback) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001765 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001766 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001767 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001768 mNextAppTransitionPackage = packageName;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001769 mNextAppTransitionEnter = enterAnim;
1770 mNextAppTransitionExit = exitAnim;
1771 postAnimationCallback();
1772 mNextAppTransitionCallback = startedCallback;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001773 }
1774 }
1775
1776 void overridePendingAppTransitionScaleUp(int startX, int startY, int startWidth,
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001777 int startHeight) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001778 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001779 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001780 mNextAppTransitionType = NEXT_TRANSIT_TYPE_SCALE_UP;
Winson4c3fecd2016-07-13 12:29:48 -07001781 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001782 postAnimationCallback();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001783 }
1784 }
1785
Chet Haase10e23ab2015-02-11 15:08:38 -08001786 void overridePendingAppTransitionClipReveal(int startX, int startY,
1787 int startWidth, int startHeight) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001788 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001789 clear();
Chet Haase10e23ab2015-02-11 15:08:38 -08001790 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CLIP_REVEAL;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001791 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Chet Haase10e23ab2015-02-11 15:08:38 -08001792 postAnimationCallback();
Chet Haase10e23ab2015-02-11 15:08:38 -08001793 }
1794 }
1795
Winson Chungaa7fa012017-05-24 15:50:06 -07001796 void overridePendingAppTransitionThumb(GraphicBuffer srcThumb, int startX, int startY,
Craig Mautner164d4bb2012-11-26 13:51:23 -08001797 IRemoteCallback startedCallback, boolean scaleUp) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001798 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001799 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001800 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP
1801 : NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001802 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001803 putDefaultNextAppTransitionCoordinates(startX, startY, 0, 0, srcThumb);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001804 postAnimationCallback();
1805 mNextAppTransitionCallback = startedCallback;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001806 }
1807 }
1808
Winson Chungaa7fa012017-05-24 15:50:06 -07001809 void overridePendingAppTransitionAspectScaledThumb(GraphicBuffer srcThumb, int startX, int startY,
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001810 int targetWidth, int targetHeight, IRemoteCallback startedCallback, boolean scaleUp) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001811 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001812 clear();
Winson Chunga4ccb862014-08-22 15:26:27 -07001813 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1814 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Winson Chunga4ccb862014-08-22 15:26:27 -07001815 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001816 putDefaultNextAppTransitionCoordinates(startX, startY, targetWidth, targetHeight,
1817 srcThumb);
Winson Chunga4ccb862014-08-22 15:26:27 -07001818 postAnimationCallback();
1819 mNextAppTransitionCallback = startedCallback;
Winson Chunga4ccb862014-08-22 15:26:27 -07001820 }
1821 }
1822
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001823 void overridePendingAppTransitionMultiThumb(AppTransitionAnimationSpec[] specs,
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001824 IRemoteCallback onAnimationStartedCallback, IRemoteCallback onAnimationFinishedCallback,
1825 boolean scaleUp) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001826 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001827 clear();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001828 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1829 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001830 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi43102412015-11-11 16:28:37 +01001831 if (specs != null) {
1832 for (int i = 0; i < specs.length; i++) {
1833 AppTransitionAnimationSpec spec = specs[i];
1834 if (spec != null) {
1835 mNextAppTransitionAnimationsSpecs.put(spec.taskId, spec);
1836 if (i == 0) {
1837 // In full screen mode, the transition code depends on the default spec
1838 // to be set.
1839 Rect rect = spec.rect;
1840 putDefaultNextAppTransitionCoordinates(rect.left, rect.top,
Winson Chungaa7fa012017-05-24 15:50:06 -07001841 rect.width(), rect.height(), spec.buffer);
Jorim Jaggi43102412015-11-11 16:28:37 +01001842 }
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001843 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001844 }
1845 }
1846 postAnimationCallback();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001847 mNextAppTransitionCallback = onAnimationStartedCallback;
1848 mAnimationFinishedCallback = onAnimationFinishedCallback;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001849 }
1850 }
1851
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001852 void overridePendingAppTransitionMultiThumbFuture(
1853 IAppTransitionAnimationSpecsFuture specsFuture, IRemoteCallback callback,
1854 boolean scaleUp) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001855 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001856 clear();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001857 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1858 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001859 mNextAppTransitionAnimationsSpecsFuture = specsFuture;
1860 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001861 mNextAppTransitionFutureCallback = callback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001862 }
1863 }
1864
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001865 void overridePendingAppTransitionRemote(RemoteAnimationAdapter remoteAnimationAdapter) {
Winson Chung044d5292014-11-06 11:05:19 -08001866 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001867 clear();
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001868 mNextAppTransitionType = NEXT_TRANSIT_TYPE_REMOTE;
1869 mRemoteAnimationController = new RemoteAnimationController(mService,
1870 remoteAnimationAdapter, mService.mH);
1871 }
1872 }
1873
1874 void overrideInPlaceAppTransition(String packageName, int anim) {
1875 if (canOverridePendingAppTransition()) {
1876 clear();
Winson Chung044d5292014-11-06 11:05:19 -08001877 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE;
1878 mNextAppTransitionPackage = packageName;
1879 mNextAppTransitionInPlace = anim;
Winson Chung044d5292014-11-06 11:05:19 -08001880 }
1881 }
1882
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001883 /**
Tony Mak089c35e2017-12-18 20:34:14 +00001884 * @see {@link #NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS}
1885 */
1886 void overridePendingAppTransitionStartCrossProfileApps() {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001887 if (canOverridePendingAppTransition()) {
Tony Mak089c35e2017-12-18 20:34:14 +00001888 clear();
1889 mNextAppTransitionType = NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS;
1890 postAnimationCallback();
1891 }
1892 }
1893
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001894 private boolean canOverridePendingAppTransition() {
1895 // Remote animations always take precedence
1896 return isTransitionSet() && mNextAppTransitionType != NEXT_TRANSIT_TYPE_REMOTE;
1897 }
1898
Tony Mak089c35e2017-12-18 20:34:14 +00001899 /**
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001900 * If a future is set for the app transition specs, fetch it in another thread.
1901 */
1902 private void fetchAppTransitionSpecsFromFuture() {
1903 if (mNextAppTransitionAnimationsSpecsFuture != null) {
1904 mNextAppTransitionAnimationsSpecsPending = true;
1905 final IAppTransitionAnimationSpecsFuture future
1906 = mNextAppTransitionAnimationsSpecsFuture;
1907 mNextAppTransitionAnimationsSpecsFuture = null;
Jorim Jaggied410b62017-05-05 15:16:14 +02001908 mDefaultExecutor.execute(() -> {
1909 AppTransitionAnimationSpec[] specs = null;
1910 try {
1911 Binder.allowBlocking(future.asBinder());
1912 specs = future.get();
1913 } catch (RemoteException e) {
1914 Slog.w(TAG, "Failed to fetch app transition specs: " + e);
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001915 }
Jorim Jaggied410b62017-05-05 15:16:14 +02001916 synchronized (mService.mWindowMap) {
1917 mNextAppTransitionAnimationsSpecsPending = false;
1918 overridePendingAppTransitionMultiThumb(specs,
1919 mNextAppTransitionFutureCallback, null /* finishedCallback */,
1920 mNextAppTransitionScaleUp);
1921 mNextAppTransitionFutureCallback = null;
Jorim Jaggied410b62017-05-05 15:16:14 +02001922 }
1923 mService.requestTraversal();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001924 });
1925 }
1926 }
1927
Craig Mautner164d4bb2012-11-26 13:51:23 -08001928 @Override
1929 public String toString() {
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001930 return "mNextAppTransition=" + appTransitionToString(mNextAppTransition);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001931 }
1932
Craig Mautner4b71aa12012-12-27 17:20:01 -08001933 /**
1934 * Returns the human readable name of a window transition.
1935 *
1936 * @param transition The window transition.
1937 * @return The transition symbolic name.
1938 */
1939 public static String appTransitionToString(int transition) {
1940 switch (transition) {
1941 case TRANSIT_UNSET: {
1942 return "TRANSIT_UNSET";
1943 }
1944 case TRANSIT_NONE: {
1945 return "TRANSIT_NONE";
1946 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001947 case TRANSIT_ACTIVITY_OPEN: {
1948 return "TRANSIT_ACTIVITY_OPEN";
1949 }
1950 case TRANSIT_ACTIVITY_CLOSE: {
1951 return "TRANSIT_ACTIVITY_CLOSE";
1952 }
1953 case TRANSIT_TASK_OPEN: {
1954 return "TRANSIT_TASK_OPEN";
1955 }
1956 case TRANSIT_TASK_CLOSE: {
1957 return "TRANSIT_TASK_CLOSE";
1958 }
1959 case TRANSIT_TASK_TO_FRONT: {
1960 return "TRANSIT_TASK_TO_FRONT";
1961 }
1962 case TRANSIT_TASK_TO_BACK: {
1963 return "TRANSIT_TASK_TO_BACK";
1964 }
1965 case TRANSIT_WALLPAPER_CLOSE: {
1966 return "TRANSIT_WALLPAPER_CLOSE";
1967 }
1968 case TRANSIT_WALLPAPER_OPEN: {
1969 return "TRANSIT_WALLPAPER_OPEN";
1970 }
1971 case TRANSIT_WALLPAPER_INTRA_OPEN: {
1972 return "TRANSIT_WALLPAPER_INTRA_OPEN";
1973 }
1974 case TRANSIT_WALLPAPER_INTRA_CLOSE: {
1975 return "TRANSIT_WALLPAPER_INTRA_CLOSE";
1976 }
Craig Mautnerbb742462014-07-07 15:28:55 -07001977 case TRANSIT_TASK_OPEN_BEHIND: {
1978 return "TRANSIT_TASK_OPEN_BEHIND";
1979 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001980 case TRANSIT_ACTIVITY_RELAUNCH: {
1981 return "TRANSIT_ACTIVITY_RELAUNCH";
1982 }
Jorim Jaggi192086e2016-03-11 17:17:03 +01001983 case TRANSIT_DOCK_TASK_FROM_RECENTS: {
1984 return "TRANSIT_DOCK_TASK_FROM_RECENTS";
1985 }
Jorim Jaggife762342016-10-13 14:33:27 +02001986 case TRANSIT_KEYGUARD_GOING_AWAY: {
1987 return "TRANSIT_KEYGUARD_GOING_AWAY";
1988 }
1989 case TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER: {
1990 return "TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER";
1991 }
1992 case TRANSIT_KEYGUARD_OCCLUDE: {
1993 return "TRANSIT_KEYGUARD_OCCLUDE";
1994 }
1995 case TRANSIT_KEYGUARD_UNOCCLUDE: {
1996 return "TRANSIT_KEYGUARD_UNOCCLUDE";
1997 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001998 default: {
1999 return "<UNKNOWN>";
2000 }
2001 }
2002 }
2003
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002004 private String appStateToString() {
2005 switch (mAppTransitionState) {
2006 case APP_STATE_IDLE:
2007 return "APP_STATE_IDLE";
2008 case APP_STATE_READY:
2009 return "APP_STATE_READY";
2010 case APP_STATE_RUNNING:
2011 return "APP_STATE_RUNNING";
2012 case APP_STATE_TIMEOUT:
2013 return "APP_STATE_TIMEOUT";
2014 default:
2015 return "unknown state=" + mAppTransitionState;
2016 }
2017 }
2018
2019 private String transitTypeToString() {
2020 switch (mNextAppTransitionType) {
2021 case NEXT_TRANSIT_TYPE_NONE:
2022 return "NEXT_TRANSIT_TYPE_NONE";
2023 case NEXT_TRANSIT_TYPE_CUSTOM:
2024 return "NEXT_TRANSIT_TYPE_CUSTOM";
Winson Chung044d5292014-11-06 11:05:19 -08002025 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
2026 return "NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002027 case NEXT_TRANSIT_TYPE_SCALE_UP:
2028 return "NEXT_TRANSIT_TYPE_SCALE_UP";
2029 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
2030 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP";
2031 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
2032 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN";
Winson Chunga4ccb862014-08-22 15:26:27 -07002033 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
2034 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP";
2035 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN:
2036 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN";
Tony Mak64b8d562017-12-28 17:44:02 +00002037 case NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS:
2038 return "NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002039 default:
2040 return "unknown type=" + mNextAppTransitionType;
2041 }
2042 }
2043
Steven Timotiusaf03df62017-07-18 16:56:43 -07002044 void writeToProto(ProtoOutputStream proto, long fieldId) {
2045 final long token = proto.start(fieldId);
2046 proto.write(APP_TRANSITION_STATE, mAppTransitionState);
2047 proto.write(LAST_USED_APP_TRANSITION, mLastUsedAppTransition);
2048 proto.end(token);
2049 }
2050
Craig Mautner164d4bb2012-11-26 13:51:23 -08002051 @Override
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002052 public void dump(PrintWriter pw, String prefix) {
2053 pw.print(prefix); pw.println(this);
2054 pw.print(prefix); pw.print("mAppTransitionState="); pw.println(appStateToString());
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002055 if (mNextAppTransitionType != NEXT_TRANSIT_TYPE_NONE) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002056 pw.print(prefix); pw.print("mNextAppTransitionType=");
2057 pw.println(transitTypeToString());
Craig Mautner164d4bb2012-11-26 13:51:23 -08002058 }
2059 switch (mNextAppTransitionType) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002060 case NEXT_TRANSIT_TYPE_CUSTOM:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002061 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Craig Mautner164d4bb2012-11-26 13:51:23 -08002062 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002063 pw.print(prefix); pw.print("mNextAppTransitionEnter=0x");
Craig Mautner164d4bb2012-11-26 13:51:23 -08002064 pw.print(Integer.toHexString(mNextAppTransitionEnter));
2065 pw.print(" mNextAppTransitionExit=0x");
2066 pw.println(Integer.toHexString(mNextAppTransitionExit));
2067 break;
Winson Chung044d5292014-11-06 11:05:19 -08002068 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002069 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Winson Chung044d5292014-11-06 11:05:19 -08002070 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002071 pw.print(prefix); pw.print("mNextAppTransitionInPlace=0x");
Winson Chung044d5292014-11-06 11:05:19 -08002072 pw.print(Integer.toHexString(mNextAppTransitionInPlace));
2073 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002074 case NEXT_TRANSIT_TYPE_SCALE_UP: {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002075 getDefaultNextAppTransitionStartRect(mTmpRect);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002076 pw.print(prefix); pw.print("mNextAppTransitionStartX=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002077 pw.print(mTmpRect.left);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002078 pw.print(" mNextAppTransitionStartY=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002079 pw.println(mTmpRect.top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002080 pw.print(prefix); pw.print("mNextAppTransitionStartWidth=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002081 pw.print(mTmpRect.width());
Craig Mautner164d4bb2012-11-26 13:51:23 -08002082 pw.print(" mNextAppTransitionStartHeight=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002083 pw.println(mTmpRect.height());
Craig Mautner164d4bb2012-11-26 13:51:23 -08002084 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002085 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002086 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
2087 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
Winson Chunga4ccb862014-08-22 15:26:27 -07002088 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002089 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN: {
2090 pw.print(prefix); pw.print("mDefaultNextAppTransitionAnimationSpec=");
2091 pw.println(mDefaultNextAppTransitionAnimationSpec);
2092 pw.print(prefix); pw.print("mNextAppTransitionAnimationsSpecs=");
2093 pw.println(mNextAppTransitionAnimationsSpecs);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002094 pw.print(prefix); pw.print("mNextAppTransitionScaleUp=");
2095 pw.println(mNextAppTransitionScaleUp);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002096 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002097 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002098 }
2099 if (mNextAppTransitionCallback != null) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002100 pw.print(prefix); pw.print("mNextAppTransitionCallback=");
2101 pw.println(mNextAppTransitionCallback);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002102 }
Chong Zhang60091a92016-07-27 17:52:45 -07002103 if (mLastUsedAppTransition != TRANSIT_NONE) {
2104 pw.print(prefix); pw.print("mLastUsedAppTransition=");
2105 pw.println(appTransitionToString(mLastUsedAppTransition));
2106 pw.print(prefix); pw.print("mLastOpeningApp=");
2107 pw.println(mLastOpeningApp);
2108 pw.print(prefix); pw.print("mLastClosingApp=");
2109 pw.println(mLastClosingApp);
2110 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002111 }
Amith Yamasani4befbec2013-07-10 16:18:01 -07002112
2113 public void setCurrentUser(int newUserId) {
2114 mCurrentUserId = newUserId;
2115 }
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002116
2117 /**
2118 * @return true if transition is not running and should not be skipped, false if transition is
2119 * already running
2120 */
Jorim Jaggif84e2f62018-01-16 14:17:59 +01002121 boolean prepareAppTransitionLocked(@TransitionType int transit, boolean alwaysKeepCurrent,
2122 @TransitionFlags int flags, boolean forceOverride) {
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002123 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Prepare app transition:"
2124 + " transit=" + appTransitionToString(transit)
2125 + " " + this
2126 + " alwaysKeepCurrent=" + alwaysKeepCurrent
2127 + " Callers=" + Debug.getCallers(3));
Jorim Jaggife762342016-10-13 14:33:27 +02002128 if (forceOverride || isKeyguardTransit(transit) || !isTransitionSet()
2129 || mNextAppTransition == TRANSIT_NONE) {
2130 setAppTransition(transit, flags);
Jorim Jaggia69243a2017-06-15 15:10:38 -04002131 }
2132 // We never want to change from a Keyguard transit to a non-Keyguard transit, as our logic
2133 // relies on the fact that we always execute a Keyguard transition after preparing one.
2134 else if (!alwaysKeepCurrent && !isKeyguardTransit(transit)) {
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002135 if (transit == TRANSIT_TASK_OPEN && isTransitionEqual(TRANSIT_TASK_CLOSE)) {
2136 // Opening a new task always supersedes a close for the anim.
Jorim Jaggife762342016-10-13 14:33:27 +02002137 setAppTransition(transit, flags);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002138 } else if (transit == TRANSIT_ACTIVITY_OPEN
2139 && isTransitionEqual(TRANSIT_ACTIVITY_CLOSE)) {
2140 // Opening a new activity always supersedes a close for the anim.
Jorim Jaggife762342016-10-13 14:33:27 +02002141 setAppTransition(transit, flags);
Jorim Jaggicecf4242018-02-21 18:46:53 +01002142 } else if (isTaskTransit(transit) && isActivityTransit(mNextAppTransition)) {
2143 // Task animations always supersede activity animations, because if we have both, it
2144 // usually means that activity transition were just trampoline activities.
2145 setAppTransition(transit, flags);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002146 }
2147 }
2148 boolean prepared = prepare();
2149 if (isTransitionSet()) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08002150 mService.mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
2151 mService.mH.sendEmptyMessageDelayed(H.APP_TRANSITION_TIMEOUT, APP_TRANSITION_TIMEOUT_MS);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002152 }
2153 return prepared;
2154 }
Winsonb2024762016-04-05 17:32:30 -07002155
2156 /**
Jorim Jaggife762342016-10-13 14:33:27 +02002157 * @return true if {@param transit} is representing a transition in which Keyguard is going
2158 * away, false otherwise
2159 */
2160 public static boolean isKeyguardGoingAwayTransit(int transit) {
2161 return transit == TRANSIT_KEYGUARD_GOING_AWAY
2162 || transit == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER;
2163 }
2164
2165 private static boolean isKeyguardTransit(int transit) {
2166 return isKeyguardGoingAwayTransit(transit) || transit == TRANSIT_KEYGUARD_OCCLUDE
2167 || transit == TRANSIT_KEYGUARD_UNOCCLUDE;
2168 }
2169
Jorim Jaggicecf4242018-02-21 18:46:53 +01002170 private static boolean isTaskTransit(int transit) {
2171 return transit == TRANSIT_TASK_OPEN
2172 || transit == TRANSIT_TASK_CLOSE
2173 || transit == TRANSIT_TASK_OPEN_BEHIND
2174 || transit == TRANSIT_TASK_TO_BACK
2175 || transit == TRANSIT_TASK_TO_FRONT
2176 || transit == TRANSIT_TASK_IN_PLACE;
2177 }
2178
2179 private static boolean isActivityTransit(int transit) {
2180 return transit == TRANSIT_ACTIVITY_OPEN
2181 || transit == TRANSIT_ACTIVITY_CLOSE
2182 || transit == TRANSIT_ACTIVITY_RELAUNCH;
2183 }
2184
Jorim Jaggife762342016-10-13 14:33:27 +02002185 /**
Manu Cornetd7376802017-01-13 13:44:07 -08002186 * @return whether the transition should show the thumbnail being scaled down.
2187 */
2188 private boolean shouldScaleDownThumbnailTransition(int uiMode, int orientation) {
Sid Soundararajan0e88d322017-03-07 15:37:30 -08002189 return mGridLayoutRecentsEnabled
Manu Cornetd7376802017-01-13 13:44:07 -08002190 || orientation == Configuration.ORIENTATION_PORTRAIT;
2191 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002192}