blob: 93ca4dc48319fa67e1568d77452f9db2a0e71508 [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 */
Jorim Jaggic8cc2292018-03-15 20:16:15 +0100472 void updateBooster() {
473 WindowManagerService.sThreadPriorityBooster.setAppTransitionRunning(needsBoosting());
474 }
475
476 private boolean needsBoosting() {
477 final boolean recentsAnimRunning = mService.getRecentsAnimationController() != null;
478 return mNextAppTransition != TRANSIT_UNSET
479 || mAppTransitionState == APP_STATE_READY
480 || mAppTransitionState == APP_STATE_RUNNING
481 || recentsAnimRunning;
Jorim Jaggi245281c2017-06-07 14:33:04 -0700482 }
483
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100484 void registerListenerLocked(AppTransitionListener listener) {
485 mListeners.add(listener);
486 }
487
Wale Ogunwalea48eadb2015-05-14 17:43:12 -0700488 public void notifyAppTransitionFinishedLocked(IBinder token) {
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100489 for (int i = 0; i < mListeners.size(); i++) {
490 mListeners.get(i).onAppTransitionFinishedLocked(token);
491 }
492 }
493
494 private void notifyAppTransitionPendingLocked() {
495 for (int i = 0; i < mListeners.size(); i++) {
496 mListeners.get(i).onAppTransitionPendingLocked();
497 }
498 }
499
Jorim Jaggife762342016-10-13 14:33:27 +0200500 private void notifyAppTransitionCancelledLocked(int transit) {
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100501 for (int i = 0; i < mListeners.size(); i++) {
Jorim Jaggife762342016-10-13 14:33:27 +0200502 mListeners.get(i).onAppTransitionCancelledLocked(transit);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100503 }
504 }
505
Jorim Jaggife762342016-10-13 14:33:27 +0200506 private int notifyAppTransitionStartingLocked(int transit, IBinder openToken,
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200507 IBinder closeToken, long duration, long statusBarAnimationStartTime,
508 long statusBarAnimationDuration) {
Jorim Jaggife762342016-10-13 14:33:27 +0200509 int redoLayout = 0;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100510 for (int i = 0; i < mListeners.size(); i++) {
Jorim Jaggife762342016-10-13 14:33:27 +0200511 redoLayout |= mListeners.get(i).onAppTransitionStartingLocked(transit, openToken,
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200512 closeToken, duration, statusBarAnimationStartTime, statusBarAnimationDuration);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100513 }
Jorim Jaggife762342016-10-13 14:33:27 +0200514 return redoLayout;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800515 }
516
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100517 private AttributeCache.Entry getCachedAnimations(LayoutParams lp) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800518 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg="
519 + (lp != null ? lp.packageName : null)
520 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
521 if (lp != null && lp.windowAnimations != 0) {
522 // If this is a system resource, don't try to load it from the
523 // application resources. It is nice to avoid loading application
524 // resources if we can.
525 String packageName = lp.packageName != null ? lp.packageName : "android";
526 int resId = lp.windowAnimations;
527 if ((resId&0xFF000000) == 0x01000000) {
528 packageName = "android";
529 }
530 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
531 + packageName);
532 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700533 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800534 }
535 return null;
536 }
537
538 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
539 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package="
540 + packageName + " resId=0x" + Integer.toHexString(resId));
541 if (packageName != null) {
542 if ((resId&0xFF000000) == 0x01000000) {
543 packageName = "android";
544 }
545 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
546 + packageName);
547 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700548 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800549 }
550 return null;
551 }
552
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100553 Animation loadAnimationAttr(LayoutParams lp, int animAttr) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800554 int anim = 0;
555 Context context = mContext;
556 if (animAttr >= 0) {
557 AttributeCache.Entry ent = getCachedAnimations(lp);
558 if (ent != null) {
559 context = ent.context;
560 anim = ent.array.getResourceId(animAttr, 0);
561 }
562 }
563 if (anim != 0) {
564 return AnimationUtils.loadAnimation(context, anim);
565 }
566 return null;
567 }
568
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100569 Animation loadAnimationRes(LayoutParams lp, int resId) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700570 Context context = mContext;
571 if (resId >= 0) {
572 AttributeCache.Entry ent = getCachedAnimations(lp);
573 if (ent != null) {
574 context = ent.context;
575 }
576 return AnimationUtils.loadAnimation(context, resId);
577 }
578 return null;
579 }
580
581 private Animation loadAnimationRes(String packageName, int resId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800582 int anim = 0;
583 Context context = mContext;
584 if (resId >= 0) {
585 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
586 if (ent != null) {
587 context = ent.context;
588 anim = resId;
589 }
590 }
591 if (anim != 0) {
592 return AnimationUtils.loadAnimation(context, anim);
593 }
594 return null;
595 }
596
Craig Mautner164d4bb2012-11-26 13:51:23 -0800597 /**
598 * Compute the pivot point for an animation that is scaling from a small
599 * rect on screen to a larger rect. The pivot point varies depending on
600 * the distance between the inner and outer edges on both sides. This
601 * function computes the pivot point for one dimension.
602 * @param startPos Offset from left/top edge of outer rectangle to
603 * left/top edge of inner rectangle.
604 * @param finalScale The scaling factor between the size of the outer
605 * and inner rectangles.
606 */
607 private static float computePivot(int startPos, float finalScale) {
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800608
609 /*
610 Theorem of intercepting lines:
611
612 + + +-----------------------------------------------+
613 | | | |
614 | | | |
615 | | | |
616 | | | |
617 x | y | | |
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 |
654 |
655 |
656 |
657 |
658 + ++
659 p ++
660
661 scale = (x - y) / x
662 <=> x = -y / (scale - 1)
663 */
Craig Mautner164d4bb2012-11-26 13:51:23 -0800664 final float denom = finalScale-1;
665 if (Math.abs(denom) < .0001f) {
666 return startPos;
667 }
668 return -startPos / denom;
669 }
670
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700671 private Animation createScaleUpAnimationLocked(int transit, boolean enter,
672 Rect containingFrame) {
673 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700674 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700675 final int appWidth = containingFrame.width();
676 final int appHeight = containingFrame.height();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800677 if (enter) {
678 // Entering app zooms out from the center of the initial rect.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700679 float scaleW = mTmpRect.width() / (float) appWidth;
680 float scaleH = mTmpRect.height() / (float) appHeight;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800681 Animation scale = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700682 computePivot(mTmpRect.left, scaleW),
Winson4c3fecd2016-07-13 12:29:48 -0700683 computePivot(mTmpRect.top, scaleH));
Craig Mautner321bdf52012-12-18 09:53:24 -0800684 scale.setInterpolator(mDecelerateInterpolator);
685
Craig Mautner164d4bb2012-11-26 13:51:23 -0800686 Animation alpha = new AlphaAnimation(0, 1);
Winson Chunga4ccb862014-08-22 15:26:27 -0700687 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
Craig Mautner321bdf52012-12-18 09:53:24 -0800688
689 AnimationSet set = new AnimationSet(false);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800690 set.addAnimation(scale);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800691 set.addAnimation(alpha);
692 set.setDetachWallpaper(true);
693 a = set;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800694 } else if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
695 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800696 // If we are on top of the wallpaper, we need an animation that
697 // correctly handles the wallpaper staying static behind all of
698 // the animated elements. To do this, will just have the existing
699 // element fade out.
700 a = new AlphaAnimation(1, 0);
701 a.setDetachWallpaper(true);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800702 } else {
Craig Mautner321bdf52012-12-18 09:53:24 -0800703 // For normal animations, the exiting element just holds in place.
704 a = new AlphaAnimation(1, 1);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800705 }
Craig Mautner321bdf52012-12-18 09:53:24 -0800706
707 // Pick the desired duration. If this is an inter-activity transition,
708 // it is the standard duration for that. Otherwise we use the longer
709 // task transition duration.
710 final long duration;
711 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800712 case TRANSIT_ACTIVITY_OPEN:
713 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800714 duration = mConfigShortAnimTime;
715 break;
716 default:
717 duration = DEFAULT_APP_TRANSITION_DURATION;
718 break;
719 }
720 a.setDuration(duration);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800721 a.setFillAfter(true);
Craig Mautner321bdf52012-12-18 09:53:24 -0800722 a.setInterpolator(mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800723 a.initialize(appWidth, appHeight, appWidth, appHeight);
724 return a;
725 }
726
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700727 private void getDefaultNextAppTransitionStartRect(Rect rect) {
728 if (mDefaultNextAppTransitionAnimationSpec == null ||
729 mDefaultNextAppTransitionAnimationSpec.rect == null) {
Jorim Jaggi2550f3f2017-03-14 20:15:59 +0100730 Slog.e(TAG, "Starting rect for app requested, but none available", new Throwable());
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700731 rect.setEmpty();
732 } else {
733 rect.set(mDefaultNextAppTransitionAnimationSpec.rect);
734 }
735 }
736
737 void getNextAppTransitionStartRect(int taskId, Rect rect) {
738 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800739 if (spec == null) {
740 spec = mDefaultNextAppTransitionAnimationSpec;
741 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700742 if (spec == null || spec.rect == null) {
Jorim Jaggi2550f3f2017-03-14 20:15:59 +0100743 Slog.e(TAG, "Starting rect for task: " + taskId + " requested, but not available",
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700744 new Throwable());
745 rect.setEmpty();
746 } else {
747 rect.set(spec.rect);
748 }
749 }
750
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800751 private void putDefaultNextAppTransitionCoordinates(int left, int top, int width, int height,
Winson Chungaa7fa012017-05-24 15:50:06 -0700752 GraphicBuffer buffer) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700753 mDefaultNextAppTransitionAnimationSpec = new AppTransitionAnimationSpec(-1 /* taskId */,
Winson Chungaa7fa012017-05-24 15:50:06 -0700754 buffer, new Rect(left, top, left + width, top + height));
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700755 }
756
Jorim Jaggif97ed922016-02-18 18:57:07 -0800757 /**
758 * @return the duration of the last clip reveal animation
759 */
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800760 long getLastClipRevealTransitionDuration() {
761 return mLastClipRevealTransitionDuration;
762 }
763
764 /**
Jorim Jaggif97ed922016-02-18 18:57:07 -0800765 * @return the maximum distance the app surface is traveling of the last clip reveal animation
766 */
767 int getLastClipRevealMaxTranslation() {
768 return mLastClipRevealMaxTranslation;
769 }
770
771 /**
772 * @return true if in the last app transition had a clip reveal animation, false otherwise
773 */
774 boolean hadClipRevealAnimation() {
775 return mLastHadClipReveal;
776 }
777
778 /**
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800779 * Calculates the duration for the clip reveal animation. If the clip is "cut off", meaning that
780 * the start rect is outside of the target rect, and there is a lot of movement going on.
781 *
782 * @param cutOff whether the start rect was not fully contained by the end rect
783 * @param translationX the total translation the surface moves in x direction
784 * @param translationY the total translation the surfaces moves in y direction
785 * @param displayFrame our display frame
786 *
787 * @return the duration of the clip reveal animation, in milliseconds
788 */
789 private long calculateClipRevealTransitionDuration(boolean cutOff, float translationX,
790 float translationY, Rect displayFrame) {
791 if (!cutOff) {
792 return DEFAULT_APP_TRANSITION_DURATION;
793 }
794 final float fraction = Math.max(Math.abs(translationX) / displayFrame.width(),
795 Math.abs(translationY) / displayFrame.height());
796 return (long) (DEFAULT_APP_TRANSITION_DURATION + fraction *
797 (MAX_CLIP_REVEAL_TRANSITION_DURATION - DEFAULT_APP_TRANSITION_DURATION));
798 }
799
800 private Animation createClipRevealAnimationLocked(int transit, boolean enter, Rect appFrame,
801 Rect displayFrame) {
Chet Haase10e23ab2015-02-11 15:08:38 -0800802 final Animation anim;
803 if (enter) {
Craig Mautner80b1f642015-04-22 10:59:09 -0700804 final int appWidth = appFrame.width();
805 final int appHeight = appFrame.height();
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800806
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700807 // mTmpRect will contain an area around the launcher icon that was pressed. We will
Filip Gruszczynski82861362015-10-16 14:21:09 -0700808 // clip reveal from that area in the final area of the app.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700809 getDefaultNextAppTransitionStartRect(mTmpRect);
Craig Mautner80b1f642015-04-22 10:59:09 -0700810
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700811 float t = 0f;
812 if (appHeight > 0) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800813 t = (float) mTmpRect.top / displayFrame.height();
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700814 }
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800815 int translationY = mClipRevealTranslationY + (int)(displayFrame.height() / 7f * t);
816 int translationX = 0;
817 int translationYCorrection = translationY;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700818 int centerX = mTmpRect.centerX();
819 int centerY = mTmpRect.centerY();
820 int halfWidth = mTmpRect.width() / 2;
821 int halfHeight = mTmpRect.height() / 2;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800822 int clipStartX = centerX - halfWidth - appFrame.left;
823 int clipStartY = centerY - halfHeight - appFrame.top;
824 boolean cutOff = false;
825
826 // If the starting rectangle is fully or partially outside of the target rectangle, we
827 // need to start the clipping at the edge and then achieve the rest with translation
828 // and extending the clip rect from that edge.
829 if (appFrame.top > centerY - halfHeight) {
830 translationY = (centerY - halfHeight) - appFrame.top;
831 translationYCorrection = 0;
832 clipStartY = 0;
833 cutOff = true;
834 }
835 if (appFrame.left > centerX - halfWidth) {
836 translationX = (centerX - halfWidth) - appFrame.left;
837 clipStartX = 0;
838 cutOff = true;
839 }
840 if (appFrame.right < centerX + halfWidth) {
841 translationX = (centerX + halfWidth) - appFrame.right;
842 clipStartX = appWidth - mTmpRect.width();
843 cutOff = true;
844 }
845 final long duration = calculateClipRevealTransitionDuration(cutOff, translationX,
846 translationY, displayFrame);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700847
848 // Clip third of the from size of launch icon, expand to full width/height
Chet Haase10e23ab2015-02-11 15:08:38 -0800849 Animation clipAnimLR = new ClipRectLRAnimation(
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800850 clipStartX, clipStartX + mTmpRect.width(), 0, appWidth);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700851 clipAnimLR.setInterpolator(mClipHorizontalInterpolator);
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800852 clipAnimLR.setDuration((long) (duration / 2.5f));
Filip Gruszczynski82861362015-10-16 14:21:09 -0700853
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800854 TranslateAnimation translate = new TranslateAnimation(translationX, 0, translationY, 0);
855 translate.setInterpolator(cutOff ? TOUCH_RESPONSE_INTERPOLATOR
856 : mLinearOutSlowInInterpolator);
857 translate.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800858
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800859 Animation clipAnimTB = new ClipRectTBAnimation(
860 clipStartY, clipStartY + mTmpRect.height(),
861 0, appHeight,
862 translationYCorrection, 0,
863 mLinearOutSlowInInterpolator);
864 clipAnimTB.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
865 clipAnimTB.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800866
867 // Quick fade-in from icon to app window
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800868 final long alphaDuration = duration / 4;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700869 AlphaAnimation alpha = new AlphaAnimation(0.5f, 1);
Chet Haase10e23ab2015-02-11 15:08:38 -0800870 alpha.setDuration(alphaDuration);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700871 alpha.setInterpolator(mLinearOutSlowInInterpolator);
Chet Haase10e23ab2015-02-11 15:08:38 -0800872
873 AnimationSet set = new AnimationSet(false);
874 set.addAnimation(clipAnimLR);
875 set.addAnimation(clipAnimTB);
Filip Gruszczynski82861362015-10-16 14:21:09 -0700876 set.addAnimation(translate);
Chet Haase10e23ab2015-02-11 15:08:38 -0800877 set.addAnimation(alpha);
Filip Gruszczynski9e2cf5b2015-07-31 12:20:40 -0700878 set.setZAdjustment(Animation.ZORDER_TOP);
Chet Haase10e23ab2015-02-11 15:08:38 -0800879 set.initialize(appWidth, appHeight, appWidth, appHeight);
880 anim = set;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800881 mLastHadClipReveal = true;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800882 mLastClipRevealTransitionDuration = duration;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800883
884 // If the start rect was full inside the target rect (cutOff == false), we don't need
885 // to store the translation, because it's only used if cutOff == true.
886 mLastClipRevealMaxTranslation = cutOff
887 ? Math.max(Math.abs(translationY), Math.abs(translationX)) : 0;
Chet Haase10e23ab2015-02-11 15:08:38 -0800888 } else {
889 final long duration;
890 switch (transit) {
891 case TRANSIT_ACTIVITY_OPEN:
892 case TRANSIT_ACTIVITY_CLOSE:
893 duration = mConfigShortAnimTime;
894 break;
895 default:
896 duration = DEFAULT_APP_TRANSITION_DURATION;
897 break;
898 }
899 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
900 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
901 // If we are on top of the wallpaper, we need an animation that
902 // correctly handles the wallpaper staying static behind all of
903 // the animated elements. To do this, will just have the existing
904 // element fade out.
905 anim = new AlphaAnimation(1, 0);
906 anim.setDetachWallpaper(true);
907 } else {
908 // For normal animations, the exiting element just holds in place.
909 anim = new AlphaAnimation(1, 1);
910 }
911 anim.setInterpolator(mDecelerateInterpolator);
912 anim.setDuration(duration);
913 anim.setFillAfter(true);
914 }
915 return anim;
916 }
917
Winson Chung399f6202014-03-19 10:47:20 -0700918 /**
919 * Prepares the specified animation with a standard duration, interpolator, etc.
920 */
Winson Chung5393dff2014-05-08 14:25:43 -0700921 Animation prepareThumbnailAnimationWithDuration(Animation a, int appWidth, int appHeight,
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100922 long duration, Interpolator interpolator) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700923 if (duration > 0) {
924 a.setDuration(duration);
925 }
Winson Chung5393dff2014-05-08 14:25:43 -0700926 a.setFillAfter(true);
Jorim Jaggic69bd222016-03-15 14:38:37 +0100927 if (interpolator != null) {
928 a.setInterpolator(interpolator);
929 }
Winson Chung5393dff2014-05-08 14:25:43 -0700930 a.initialize(appWidth, appHeight, appWidth, appHeight);
931 return a;
932 }
933
934 /**
935 * Prepares the specified animation with a standard duration, interpolator, etc.
936 */
Winson Chung399f6202014-03-19 10:47:20 -0700937 Animation prepareThumbnailAnimation(Animation a, int appWidth, int appHeight, int transit) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800938 // Pick the desired duration. If this is an inter-activity transition,
939 // it is the standard duration for that. Otherwise we use the longer
940 // task transition duration.
Winson Chung5393dff2014-05-08 14:25:43 -0700941 final int duration;
Craig Mautner321bdf52012-12-18 09:53:24 -0800942 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800943 case TRANSIT_ACTIVITY_OPEN:
944 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800945 duration = mConfigShortAnimTime;
946 break;
947 default:
948 duration = DEFAULT_APP_TRANSITION_DURATION;
949 break;
950 }
Winson Chung5393dff2014-05-08 14:25:43 -0700951 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, duration,
952 mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800953 }
954
Winson Chung399f6202014-03-19 10:47:20 -0700955 /**
956 * Return the current thumbnail transition state.
957 */
958 int getThumbnailTransitionState(boolean enter) {
959 if (enter) {
960 if (mNextAppTransitionScaleUp) {
961 return THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
962 } else {
963 return THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN;
964 }
965 } else {
966 if (mNextAppTransitionScaleUp) {
967 return THUMBNAIL_TRANSITION_EXIT_SCALE_UP;
968 } else {
969 return THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN;
970 }
971 }
972 }
973
974 /**
Tony Mak64b8d562017-12-28 17:44:02 +0000975 * Creates an overlay with a background color and a thumbnail for the cross profile apps
976 * animation.
977 */
978 GraphicBuffer createCrossProfileAppsThumbnail(
979 @DrawableRes int thumbnailDrawableRes, Rect frame) {
980 final int width = frame.width();
981 final int height = frame.height();
982
John Reck519ad482018-02-12 17:08:48 -0800983 final Picture picture = new Picture();
984 final Canvas canvas = picture.beginRecording(width, height);
Tony Mak64b8d562017-12-28 17:44:02 +0000985 canvas.drawColor(Color.argb(0.6f, 0, 0, 0));
986 final int thumbnailSize = mService.mContext.getResources().getDimensionPixelSize(
987 com.android.internal.R.dimen.cross_profile_apps_thumbnail_size);
988 final Drawable drawable = mService.mContext.getDrawable(thumbnailDrawableRes);
989 drawable.setBounds(
990 (width - thumbnailSize) / 2,
991 (height - thumbnailSize) / 2,
992 (width + thumbnailSize) / 2,
993 (height + thumbnailSize) / 2);
994 drawable.draw(canvas);
John Reck519ad482018-02-12 17:08:48 -0800995 picture.endRecording();
Tony Mak64b8d562017-12-28 17:44:02 +0000996
John Reck519ad482018-02-12 17:08:48 -0800997 return Bitmap.createBitmap(picture).createGraphicBufferHandle();
Tony Mak64b8d562017-12-28 17:44:02 +0000998 }
999
1000 Animation createCrossProfileAppsThumbnailAnimationLocked(Rect appRect) {
1001 final Animation animation = loadAnimationRes(
1002 "android", com.android.internal.R.anim.cross_profile_apps_thumbnail_enter);
1003 return prepareThumbnailAnimationWithDuration(animation, appRect.width(),
1004 appRect.height(), 0, null);
1005 }
1006
1007 /**
Winson Chung399f6202014-03-19 10:47:20 -07001008 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001009 * when a thumbnail is specified with the pending animation override.
Winson Chung399f6202014-03-19 10:47:20 -07001010 */
Jorim Jaggide63d442016-03-14 14:56:56 +01001011 Animation createThumbnailAspectScaleAnimationLocked(Rect appRect, @Nullable Rect contentInsets,
Winson Chungaa7fa012017-05-24 15:50:06 -07001012 GraphicBuffer thumbnailHeader, final int taskId, int uiMode, int orientation) {
Winson Chung399f6202014-03-19 10:47:20 -07001013 Animation a;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001014 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chung399f6202014-03-19 10:47:20 -07001015 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001016 final int thumbHeightI = thumbnailHeader.getHeight();
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -07001017 final int appWidth = appRect.width();
Winson Chung399f6202014-03-19 10:47:20 -07001018
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -07001019 float scaleW = appWidth / thumbWidth;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001020 getNextAppTransitionStartRect(taskId, mTmpRect);
Jorim Jaggi09072002016-03-25 16:48:42 -07001021 final float fromX;
Manu Cornet57b61492017-01-24 18:19:05 +09001022 float fromY;
Jorim Jaggi09072002016-03-25 16:48:42 -07001023 final float toX;
Manu Cornet57b61492017-01-24 18:19:05 +09001024 float toY;
Jorim Jaggi09072002016-03-25 16:48:42 -07001025 final float pivotX;
1026 final float pivotY;
Manu Cornetd7376802017-01-13 13:44:07 -08001027 if (shouldScaleDownThumbnailTransition(uiMode, orientation)) {
Jorim Jaggi09072002016-03-25 16:48:42 -07001028 fromX = mTmpRect.left;
1029 fromY = mTmpRect.top;
1030
1031 // For the curved translate animation to work, the pivot points needs to be at the
1032 // same absolute position as the one from the real surface.
1033 toX = mTmpRect.width() / 2 * (scaleW - 1f) + appRect.left;
1034 toY = appRect.height() / 2 * (1 - 1 / scaleW) + appRect.top;
1035 pivotX = mTmpRect.width() / 2;
1036 pivotY = appRect.height() / 2 / scaleW;
Manu Cornet57b61492017-01-24 18:19:05 +09001037 if (mGridLayoutRecentsEnabled) {
1038 // In the grid layout, the header is displayed above the thumbnail instead of
1039 // overlapping it.
1040 fromY -= thumbHeightI;
1041 toY -= thumbHeightI * scaleW;
1042 }
Jorim Jaggi09072002016-03-25 16:48:42 -07001043 } else {
1044 pivotX = 0;
1045 pivotY = 0;
1046 fromX = mTmpRect.left;
1047 fromY = mTmpRect.top;
1048 toX = appRect.left;
1049 toY = appRect.top;
1050 }
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001051 final long duration = getAspectScaleDuration();
1052 final Interpolator interpolator = getAspectScaleInterpolator();
Winson Chung399f6202014-03-19 10:47:20 -07001053 if (mNextAppTransitionScaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001054 // Animation up from the thumbnail to the full screen
Jorim Jaggi8448f332016-03-14 17:50:37 +01001055 Animation scale = new ScaleAnimation(1f, scaleW, 1f, scaleW, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001056 scale.setInterpolator(interpolator);
1057 scale.setDuration(duration);
Jorim Jaggic6c89a82016-01-28 17:48:21 -08001058 Animation alpha = new AlphaAnimation(1f, 0f);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001059 alpha.setInterpolator(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
1060 ? THUMBNAIL_DOCK_INTERPOLATOR : mThumbnailFadeOutInterpolator);
1061 alpha.setDuration(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
1062 ? duration / 2
1063 : duration);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001064 Animation translate = createCurvedMotion(fromX, toX, fromY, toY);
1065 translate.setInterpolator(interpolator);
1066 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -07001067
Jorim Jaggide63d442016-03-14 14:56:56 +01001068 mTmpFromClipRect.set(0, 0, thumbWidthI, thumbHeightI);
1069 mTmpToClipRect.set(appRect);
1070
1071 // Containing frame is in screen space, but we need the clip rect in the
1072 // app space.
1073 mTmpToClipRect.offsetTo(0, 0);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001074 mTmpToClipRect.right = (int) (mTmpToClipRect.right / scaleW);
1075 mTmpToClipRect.bottom = (int) (mTmpToClipRect.bottom / scaleW);
Jorim Jaggide63d442016-03-14 14:56:56 +01001076
1077 if (contentInsets != null) {
Jorim Jaggi8448f332016-03-14 17:50:37 +01001078 mTmpToClipRect.inset((int) (-contentInsets.left * scaleW),
1079 (int) (-contentInsets.top * scaleW),
1080 (int) (-contentInsets.right * scaleW),
1081 (int) (-contentInsets.bottom * scaleW));
Jorim Jaggide63d442016-03-14 14:56:56 +01001082 }
1083
1084 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001085 clipAnim.setInterpolator(interpolator);
1086 clipAnim.setDuration(duration);
Jorim Jaggide63d442016-03-14 14:56:56 +01001087
Winson Chung399f6202014-03-19 10:47:20 -07001088 // This AnimationSet uses the Interpolators assigned above.
1089 AnimationSet set = new AnimationSet(false);
1090 set.addAnimation(scale);
Manu Cornet57b61492017-01-24 18:19:05 +09001091 if (!mGridLayoutRecentsEnabled) {
1092 // In the grid layout, the header should be shown for the whole animation.
1093 set.addAnimation(alpha);
1094 }
Winson Chunga4ccb862014-08-22 15:26:27 -07001095 set.addAnimation(translate);
Jorim Jaggide63d442016-03-14 14:56:56 +01001096 set.addAnimation(clipAnim);
Winson Chung399f6202014-03-19 10:47:20 -07001097 a = set;
1098 } else {
Winson Chunga4ccb862014-08-22 15:26:27 -07001099 // Animation down from the full screen to the thumbnail
Jorim Jaggi8448f332016-03-14 17:50:37 +01001100 Animation scale = new ScaleAnimation(scaleW, 1f, scaleW, 1f, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001101 scale.setInterpolator(interpolator);
1102 scale.setDuration(duration);
Winson Chunga4ccb862014-08-22 15:26:27 -07001103 Animation alpha = new AlphaAnimation(0f, 1f);
1104 alpha.setInterpolator(mThumbnailFadeInInterpolator);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001105 alpha.setDuration(duration);
1106 Animation translate = createCurvedMotion(toX, fromX, toY, fromY);
1107 translate.setInterpolator(interpolator);
1108 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -07001109
Winson Chunga4ccb862014-08-22 15:26:27 -07001110 // This AnimationSet uses the Interpolators assigned above.
1111 AnimationSet set = new AnimationSet(false);
1112 set.addAnimation(scale);
Manu Cornet57b61492017-01-24 18:19:05 +09001113 if (!mGridLayoutRecentsEnabled) {
1114 // In the grid layout, the header should be shown for the whole animation.
1115 set.addAnimation(alpha);
1116 }
Winson Chunga4ccb862014-08-22 15:26:27 -07001117 set.addAnimation(translate);
1118 a = set;
1119
1120 }
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -07001121 return prepareThumbnailAnimationWithDuration(a, appWidth, appRect.height(), 0,
Jorim Jaggic69bd222016-03-15 14:38:37 +01001122 null);
Winson Chung399f6202014-03-19 10:47:20 -07001123 }
1124
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001125 private Animation createCurvedMotion(float fromX, float toX, float fromY, float toY) {
1126
1127 // Almost no x-change - use linear animation
Jorim Jaggic69bd222016-03-15 14:38:37 +01001128 if (Math.abs(toX - fromX) < 1f || mNextAppTransition != TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001129 return new TranslateAnimation(fromX, toX, fromY, toY);
1130 } else {
1131 final Path path = createCurvedPath(fromX, toX, fromY, toY);
1132 return new CurvedTranslateAnimation(path);
1133 }
1134 }
1135
1136 private Path createCurvedPath(float fromX, float toX, float fromY, float toY) {
1137 final Path path = new Path();
1138 path.moveTo(fromX, fromY);
Jorim Jaggi1f458fb2016-03-25 17:36:37 -07001139
1140 if (fromY > toY) {
1141 // If the object needs to go up, move it in horizontal direction first, then vertical.
1142 path.cubicTo(fromX, fromY, toX, 0.9f * fromY + 0.1f * toY, toX, toY);
1143 } else {
1144 // If the object needs to go down, move it in vertical direction first, then horizontal.
1145 path.cubicTo(fromX, fromY, fromX, 0.1f * fromY + 0.9f * toY, toX, toY);
1146 }
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001147 return path;
1148 }
1149
1150 private long getAspectScaleDuration() {
1151 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggic69bd222016-03-15 14:38:37 +01001152 return (long) (THUMBNAIL_APP_TRANSITION_DURATION * 1.35f);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001153 } else {
1154 return THUMBNAIL_APP_TRANSITION_DURATION;
1155 }
1156 }
1157
1158 private Interpolator getAspectScaleInterpolator() {
1159 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
1160 return mFastOutSlowInInterpolator;
1161 } else {
1162 return TOUCH_RESPONSE_INTERPOLATOR;
1163 }
1164 }
1165
Winson Chung399f6202014-03-19 10:47:20 -07001166 /**
1167 * This alternate animation is created when we are doing a thumbnail transition, for the
1168 * activity that is leaving, and the activity that is entering.
1169 */
Winson Chunga4ccb862014-08-22 15:26:27 -07001170 Animation createAspectScaledThumbnailEnterExitAnimationLocked(int thumbTransitState,
Winsonb2024762016-04-05 17:32:30 -07001171 int uiMode, int orientation, int transit, Rect containingFrame, Rect contentInsets,
Matthew Ng43db6d22017-06-27 15:29:39 -07001172 @Nullable Rect surfaceInsets, @Nullable Rect stableInsets, boolean freeform,
1173 int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -07001174 Animation a;
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001175 final int appWidth = containingFrame.width();
1176 final int appHeight = containingFrame.height();
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001177 getDefaultNextAppTransitionStartRect(mTmpRect);
1178 final int thumbWidthI = mTmpRect.width();
Winson Chung399f6202014-03-19 10:47:20 -07001179 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001180 final int thumbHeightI = mTmpRect.height();
Winson Chung399f6202014-03-19 10:47:20 -07001181 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
Winsoncbb625b2016-07-06 15:24:15 -07001182 final int thumbStartX = mTmpRect.left - containingFrame.left - contentInsets.left;
Winson21700932016-03-24 17:26:23 -07001183 final int thumbStartY = mTmpRect.top - containingFrame.top;
Winson Chung399f6202014-03-19 10:47:20 -07001184
1185 switch (thumbTransitState) {
Jorim Jaggi8448f332016-03-14 17:50:37 +01001186 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP:
1187 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1188 final boolean scaleUp = thumbTransitState == THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
1189 if (freeform && scaleUp) {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001190 a = createAspectScaledThumbnailEnterFreeformAnimationLocked(
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001191 containingFrame, surfaceInsets, taskId);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001192 } else if (freeform) {
1193 a = createAspectScaledThumbnailExitFreeformAnimationLocked(
1194 containingFrame, surfaceInsets, taskId);
Winson Chung2820c452014-04-15 15:34:44 -07001195 } else {
Winson21700932016-03-24 17:26:23 -07001196 AnimationSet set = new AnimationSet(true);
1197
1198 // In portrait, we scale to fit the width
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001199 mTmpFromClipRect.set(containingFrame);
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001200 mTmpToClipRect.set(containingFrame);
Jorim Jaggic6c89a82016-01-28 17:48:21 -08001201
1202 // Containing frame is in screen space, but we need the clip rect in the
1203 // app space.
1204 mTmpFromClipRect.offsetTo(0, 0);
1205 mTmpToClipRect.offsetTo(0, 0);
1206
1207 // Exclude insets region from the source clip.
1208 mTmpFromClipRect.inset(contentInsets);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001209 mNextAppTransitionInsets.set(contentInsets);
1210
Manu Cornetd7376802017-01-13 13:44:07 -08001211 if (shouldScaleDownThumbnailTransition(uiMode, orientation)) {
Jorim Jaggic69bd222016-03-15 14:38:37 +01001212 // We scale the width and clip to the top/left square
1213 float scale = thumbWidth /
1214 (appWidth - contentInsets.left - contentInsets.right);
Manu Cornetb68b7652017-01-23 19:37:53 +09001215 if (!mGridLayoutRecentsEnabled) {
1216 int unscaledThumbHeight = (int) (thumbHeight / scale);
1217 mTmpFromClipRect.bottom = mTmpFromClipRect.top + unscaledThumbHeight;
1218 }
Jorim Jaggic69bd222016-03-15 14:38:37 +01001219
1220 mNextAppTransitionInsets.set(contentInsets);
1221
Jorim Jaggi8448f332016-03-14 17:50:37 +01001222 Animation scaleAnim = new ScaleAnimation(
1223 scaleUp ? scale : 1, scaleUp ? 1 : scale,
1224 scaleUp ? scale : 1, scaleUp ? 1 : scale,
Jorim Jaggic69bd222016-03-15 14:38:37 +01001225 containingFrame.width() / 2f,
1226 containingFrame.height() / 2f + contentInsets.top);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001227 final float targetX = (mTmpRect.left - containingFrame.left);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001228 final float x = containingFrame.width() / 2f
1229 - containingFrame.width() / 2f * scale;
Jorim Jaggi8448f332016-03-14 17:50:37 +01001230 final float targetY = (mTmpRect.top - containingFrame.top);
Matthew Ng43db6d22017-06-27 15:29:39 -07001231 float y = containingFrame.height() / 2f
Jorim Jaggic69bd222016-03-15 14:38:37 +01001232 - containingFrame.height() / 2f * scale;
Matthew Ng43db6d22017-06-27 15:29:39 -07001233
1234 // During transition may require clipping offset from any top stable insets
1235 // such as the statusbar height when statusbar is hidden
1236 if (mLowRamRecentsEnabled && contentInsets.top == 0 && scaleUp) {
1237 mTmpFromClipRect.top += stableInsets.top;
1238 y += stableInsets.top;
1239 }
Jorim Jaggi8448f332016-03-14 17:50:37 +01001240 final float startX = targetX - x;
1241 final float startY = targetY - y;
1242 Animation clipAnim = scaleUp
1243 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1244 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1245 Animation translateAnim = scaleUp
Jorim Jaggic69bd222016-03-15 14:38:37 +01001246 ? createCurvedMotion(startX, 0, startY - contentInsets.top, 0)
1247 : createCurvedMotion(0, startX, 0, startY - contentInsets.top);
1248
Winson21700932016-03-24 17:26:23 -07001249 set.addAnimation(clipAnim);
1250 set.addAnimation(scaleAnim);
1251 set.addAnimation(translateAnim);
1252
1253 } else {
1254 // In landscape, we don't scale at all and only crop
1255 mTmpFromClipRect.bottom = mTmpFromClipRect.top + thumbHeightI;
1256 mTmpFromClipRect.right = mTmpFromClipRect.left + thumbWidthI;
1257
Jorim Jaggi8448f332016-03-14 17:50:37 +01001258 Animation clipAnim = scaleUp
1259 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1260 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1261 Animation translateAnim = scaleUp
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001262 ? createCurvedMotion(thumbStartX, 0,
1263 thumbStartY - contentInsets.top, 0)
1264 : createCurvedMotion(0, thumbStartX, 0,
1265 thumbStartY - contentInsets.top);
Winson21700932016-03-24 17:26:23 -07001266
1267 set.addAnimation(clipAnim);
1268 set.addAnimation(translateAnim);
1269 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001270 a = set;
Winson21700932016-03-24 17:26:23 -07001271 a.setZAdjustment(Animation.ZORDER_TOP);
Winson Chung2820c452014-04-15 15:34:44 -07001272 }
Winson Chung399f6202014-03-19 10:47:20 -07001273 break;
1274 }
1275 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001276 // Previous app window during the scale up
Winson Chung399f6202014-03-19 10:47:20 -07001277 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001278 // Fade out the source activity if we are animating to a wallpaper
Winson Chung399f6202014-03-19 10:47:20 -07001279 // activity.
1280 a = new AlphaAnimation(1, 0);
1281 } else {
Winson Chung399f6202014-03-19 10:47:20 -07001282 a = new AlphaAnimation(1, 1);
1283 }
1284 break;
1285 }
1286 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001287 // Target app window during the scale down
1288 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1289 // Fade in the destination activity if we are animating from a wallpaper
1290 // activity.
1291 a = new AlphaAnimation(0, 1);
1292 } else {
1293 a = new AlphaAnimation(1, 1);
1294 }
Winson Chung399f6202014-03-19 10:47:20 -07001295 break;
1296 }
Winson Chung399f6202014-03-19 10:47:20 -07001297 default:
1298 throw new RuntimeException("Invalid thumbnail transition state");
1299 }
1300
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001301 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight,
1302 getAspectScaleDuration(), getAspectScaleInterpolator());
Winson Chung399f6202014-03-19 10:47:20 -07001303 }
1304
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001305 private Animation createAspectScaledThumbnailEnterFreeformAnimationLocked(Rect frame,
1306 @Nullable Rect surfaceInsets, int taskId) {
1307 getNextAppTransitionStartRect(taskId, mTmpRect);
1308 return createAspectScaledThumbnailFreeformAnimationLocked(mTmpRect, frame, surfaceInsets,
1309 true);
1310 }
1311
1312 private Animation createAspectScaledThumbnailExitFreeformAnimationLocked(Rect frame,
1313 @Nullable Rect surfaceInsets, int taskId) {
1314 getNextAppTransitionStartRect(taskId, mTmpRect);
1315 return createAspectScaledThumbnailFreeformAnimationLocked(frame, mTmpRect, surfaceInsets,
1316 false);
1317 }
1318
1319 private AnimationSet createAspectScaledThumbnailFreeformAnimationLocked(Rect sourceFrame,
1320 Rect destFrame, @Nullable Rect surfaceInsets, boolean enter) {
1321 final float sourceWidth = sourceFrame.width();
1322 final float sourceHeight = sourceFrame.height();
1323 final float destWidth = destFrame.width();
1324 final float destHeight = destFrame.height();
1325 final float scaleH = enter ? sourceWidth / destWidth : destWidth / sourceWidth;
1326 final float scaleV = enter ? sourceHeight / destHeight : destHeight / sourceHeight;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001327 AnimationSet set = new AnimationSet(true);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001328 final int surfaceInsetsH = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001329 ? 0 : surfaceInsets.left + surfaceInsets.right;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001330 final int surfaceInsetsV = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001331 ? 0 : surfaceInsets.top + surfaceInsets.bottom;
1332 // We want the scaling to happen from the center of the surface. In order to achieve that,
1333 // we need to account for surface insets that will be used to enlarge the surface.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001334 final float scaleHCenter = ((enter ? destWidth : sourceWidth) + surfaceInsetsH) / 2;
1335 final float scaleVCenter = ((enter ? destHeight : sourceHeight) + surfaceInsetsV) / 2;
1336 final ScaleAnimation scale = enter ?
1337 new ScaleAnimation(scaleH, 1, scaleV, 1, scaleHCenter, scaleVCenter)
1338 : new ScaleAnimation(1, scaleH, 1, scaleV, scaleHCenter, scaleVCenter);
1339 final int sourceHCenter = sourceFrame.left + sourceFrame.width() / 2;
1340 final int sourceVCenter = sourceFrame.top + sourceFrame.height() / 2;
1341 final int destHCenter = destFrame.left + destFrame.width() / 2;
1342 final int destVCenter = destFrame.top + destFrame.height() / 2;
1343 final int fromX = enter ? sourceHCenter - destHCenter : destHCenter - sourceHCenter;
1344 final int fromY = enter ? sourceVCenter - destVCenter : destVCenter - sourceVCenter;
1345 final TranslateAnimation translation = enter ? new TranslateAnimation(fromX, 0, fromY, 0)
1346 : new TranslateAnimation(0, fromX, 0, fromY);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001347 set.addAnimation(scale);
1348 set.addAnimation(translation);
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001349
1350 final IRemoteCallback callback = mAnimationFinishedCallback;
1351 if (callback != null) {
1352 set.setAnimationListener(new Animation.AnimationListener() {
1353 @Override
1354 public void onAnimationStart(Animation animation) { }
1355
1356 @Override
1357 public void onAnimationEnd(Animation animation) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001358 mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK, callback).sendToTarget();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001359 }
1360
1361 @Override
1362 public void onAnimationRepeat(Animation animation) { }
1363 });
1364 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001365 return set;
1366 }
1367
Winson Chung399f6202014-03-19 10:47:20 -07001368 /**
Winson Chunga4ccb862014-08-22 15:26:27 -07001369 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001370 * when a thumbnail is specified with the pending animation override.
Winson Chunga4ccb862014-08-22 15:26:27 -07001371 */
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001372 Animation createThumbnailScaleAnimationLocked(int appWidth, int appHeight, int transit,
Winson Chungaa7fa012017-05-24 15:50:06 -07001373 GraphicBuffer thumbnailHeader) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001374 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001375 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001376 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chunga4ccb862014-08-22 15:26:27 -07001377 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001378 final int thumbHeightI = thumbnailHeader.getHeight();
Winson Chunga4ccb862014-08-22 15:26:27 -07001379 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1380
1381 if (mNextAppTransitionScaleUp) {
1382 // Animation for the thumbnail zooming from its initial size to the full screen
1383 float scaleW = appWidth / thumbWidth;
1384 float scaleH = appHeight / thumbHeight;
1385 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001386 computePivot(mTmpRect.left, 1 / scaleW),
1387 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001388 scale.setInterpolator(mDecelerateInterpolator);
1389
1390 Animation alpha = new AlphaAnimation(1, 0);
1391 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
1392
1393 // This AnimationSet uses the Interpolators assigned above.
1394 AnimationSet set = new AnimationSet(false);
1395 set.addAnimation(scale);
1396 set.addAnimation(alpha);
1397 a = set;
1398 } else {
1399 // Animation for the thumbnail zooming down from the full screen to its final size
1400 float scaleW = appWidth / thumbWidth;
1401 float scaleH = appHeight / thumbHeight;
1402 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001403 computePivot(mTmpRect.left, 1 / scaleW),
1404 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001405 }
1406
1407 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1408 }
1409
1410 /**
Winson Chung399f6202014-03-19 10:47:20 -07001411 * This animation is created when we are doing a thumbnail transition, for the activity that is
1412 * leaving, and the activity that is entering.
1413 */
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001414 Animation createThumbnailEnterExitAnimationLocked(int thumbTransitState, Rect containingFrame,
1415 int transit, int taskId) {
1416 final int appWidth = containingFrame.width();
1417 final int appHeight = containingFrame.height();
Winson Chungaa7fa012017-05-24 15:50:06 -07001418 final GraphicBuffer thumbnailHeader = getAppTransitionThumbnailHeader(taskId);
Winson Chung399f6202014-03-19 10:47:20 -07001419 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001420 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001421 final int thumbWidthI = thumbnailHeader != null ? thumbnailHeader.getWidth() : appWidth;
Winson Chung399f6202014-03-19 10:47:20 -07001422 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001423 final int thumbHeightI = thumbnailHeader != null ? thumbnailHeader.getHeight() : appHeight;
Winson Chung399f6202014-03-19 10:47:20 -07001424 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1425
1426 switch (thumbTransitState) {
1427 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
1428 // Entering app scales up with the thumbnail
1429 float scaleW = thumbWidth / appWidth;
1430 float scaleH = thumbHeight / appHeight;
1431 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001432 computePivot(mTmpRect.left, scaleW),
1433 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001434 break;
1435 }
1436 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
1437 // Exiting app while the thumbnail is scaling up should fade or stay in place
1438 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1439 // Fade out while bringing up selected activity. This keeps the
1440 // current activity from showing through a launching wallpaper
1441 // activity.
1442 a = new AlphaAnimation(1, 0);
1443 } else {
1444 // noop animation
1445 a = new AlphaAnimation(1, 1);
1446 }
1447 break;
1448 }
1449 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
1450 // Entering the other app, it should just be visible while we scale the thumbnail
1451 // down above it
1452 a = new AlphaAnimation(1, 1);
1453 break;
1454 }
1455 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1456 // Exiting the current app, the app should scale down with the thumbnail
1457 float scaleW = thumbWidth / appWidth;
1458 float scaleH = thumbHeight / appHeight;
1459 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001460 computePivot(mTmpRect.left, scaleW),
1461 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001462
1463 Animation alpha = new AlphaAnimation(1, 0);
1464
1465 AnimationSet set = new AnimationSet(true);
1466 set.addAnimation(scale);
1467 set.addAnimation(alpha);
1468 set.setZAdjustment(Animation.ZORDER_TOP);
1469 a = set;
1470 break;
1471 }
1472 default:
1473 throw new RuntimeException("Invalid thumbnail transition state");
1474 }
1475
1476 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1477 }
1478
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001479 private Animation createRelaunchAnimation(Rect containingFrame, Rect contentInsets) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001480 getDefaultNextAppTransitionStartRect(mTmpFromClipRect);
1481 final int left = mTmpFromClipRect.left;
1482 final int top = mTmpFromClipRect.top;
1483 mTmpFromClipRect.offset(-left, -top);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001484 // TODO: Isn't that strange that we ignore exact position of the containingFrame?
1485 mTmpToClipRect.set(0, 0, containingFrame.width(), containingFrame.height());
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001486 AnimationSet set = new AnimationSet(true);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001487 float fromWidth = mTmpFromClipRect.width();
1488 float toWidth = mTmpToClipRect.width();
1489 float fromHeight = mTmpFromClipRect.height();
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001490 // While the window might span the whole display, the actual content will be cropped to the
1491 // system decoration frame, for example when the window is docked. We need to take into
1492 // account the visible height when constructing the animation.
1493 float toHeight = mTmpToClipRect.height() - contentInsets.top - contentInsets.bottom;
1494 int translateAdjustment = 0;
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001495 if (fromWidth <= toWidth && fromHeight <= toHeight) {
1496 // The final window is larger in both dimensions than current window (e.g. we are
1497 // maximizing), so we can simply unclip the new window and there will be no disappearing
1498 // frame.
1499 set.addAnimation(new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect));
1500 } else {
1501 // The disappearing window has one larger dimension. We need to apply scaling, so the
1502 // first frame of the entry animation matches the old window.
1503 set.addAnimation(new ScaleAnimation(fromWidth / toWidth, 1, fromHeight / toHeight, 1));
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001504 // We might not be going exactly full screen, but instead be aligned under the status
1505 // bar using cropping. We still need to account for the cropped part, which will also
1506 // be scaled.
1507 translateAdjustment = (int) (contentInsets.top * fromHeight / toHeight);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001508 }
1509
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001510 // We animate the translation from the old position of the removed window, to the new
1511 // position of the added window. The latter might not be full screen, for example docked for
1512 // docked windows.
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001513 TranslateAnimation translate = new TranslateAnimation(left - containingFrame.left,
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001514 0, top - containingFrame.top - translateAdjustment, 0);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001515 set.addAnimation(translate);
1516 set.setDuration(DEFAULT_APP_TRANSITION_DURATION);
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07001517 set.setZAdjustment(Animation.ZORDER_TOP);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001518 return set;
1519 }
1520
Jorim Jaggic554b772015-06-04 16:07:57 -07001521 /**
1522 * @return true if and only if the first frame of the transition can be skipped, i.e. the first
1523 * frame of the transition doesn't change the visuals on screen, so we can start
1524 * directly with the second one
1525 */
1526 boolean canSkipFirstFrame() {
1527 return mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM
1528 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE
Jorim Jaggife762342016-10-13 14:33:27 +02001529 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CLIP_REVEAL
1530 && mNextAppTransition != TRANSIT_KEYGUARD_GOING_AWAY;
Jorim Jaggic554b772015-06-04 16:07:57 -07001531 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001532
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001533 RemoteAnimationController getRemoteAnimationController() {
1534 return mRemoteAnimationController;
1535 }
1536
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001537 /**
1538 *
1539 * @param frame These are the bounds of the window when it finishes the animation. This is where
1540 * the animation must usually finish in entrance animation, as the next frame will
1541 * display the window at these coordinates. In case of exit animation, this is
1542 * where the animation must start, as the frame before the animation is displaying
1543 * the window at these bounds.
1544 * @param insets Knowing where the window will be positioned is not enough. Some parts of the
1545 * window might be obscured, usually by the system windows (status bar and
1546 * navigation bar) and we use content insets to convey that information. This
1547 * usually affects the animation aspects vertically, as the system decoration is
1548 * at the top and the bottom. For example when we animate from full screen to
1549 * recents, we want to exclude the covered parts, because they won't match the
1550 * thumbnail after the last frame is executed.
1551 * @param surfaceInsets In rare situation the surface is larger than the content and we need to
1552 * know about this to make the animation frames match. We currently use
1553 * this for freeform windows, which have larger surfaces to display
1554 * shadows. When we animate them from recents, we want to match the content
1555 * to the recents thumbnail and hence need to account for the surface being
1556 * bigger.
1557 */
Jorim Jaggif84e2f62018-01-16 14:17:59 +01001558 Animation loadAnimation(LayoutParams lp, int transit, boolean enter, int uiMode,
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001559 int orientation, Rect frame, Rect displayFrame, Rect insets,
Matthew Ng43db6d22017-06-27 15:29:39 -07001560 @Nullable Rect surfaceInsets, @Nullable Rect stableInsets, boolean isVoiceInteraction,
1561 boolean freeform, int taskId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001562 Animation a;
Jorim Jaggife762342016-10-13 14:33:27 +02001563 if (isKeyguardGoingAwayTransit(transit) && enter) {
1564 a = loadKeyguardExitAnimation(transit);
1565 } else if (transit == TRANSIT_KEYGUARD_OCCLUDE) {
1566 a = null;
1567 } else if (transit == TRANSIT_KEYGUARD_UNOCCLUDE && !enter) {
1568 a = loadAnimationRes(lp, com.android.internal.R.anim.wallpaper_open_exit);
1569 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_OPEN
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001570 || transit == TRANSIT_TASK_OPEN
1571 || transit == TRANSIT_TASK_TO_FRONT)) {
1572 a = loadAnimationRes(lp, enter
1573 ? com.android.internal.R.anim.voice_activity_open_enter
1574 : com.android.internal.R.anim.voice_activity_open_exit);
1575 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1576 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001577 + " anim=" + a + " transit=" + appTransitionToString(transit)
1578 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001579 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_CLOSE
1580 || transit == TRANSIT_TASK_CLOSE
1581 || transit == TRANSIT_TASK_TO_BACK)) {
1582 a = loadAnimationRes(lp, enter
1583 ? com.android.internal.R.anim.voice_activity_close_enter
1584 : com.android.internal.R.anim.voice_activity_close_exit);
1585 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1586 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001587 + " anim=" + a + " transit=" + appTransitionToString(transit)
1588 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001589 } else if (transit == TRANSIT_ACTIVITY_RELAUNCH) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001590 a = createRelaunchAnimation(frame, insets);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001591 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1592 "applyAnimation:"
1593 + " anim=" + a + " nextAppTransition=" + mNextAppTransition
1594 + " transit=" + appTransitionToString(transit)
1595 + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001596 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM) {
1597 a = loadAnimationRes(mNextAppTransitionPackage, enter ?
Craig Mautner164d4bb2012-11-26 13:51:23 -08001598 mNextAppTransitionEnter : mNextAppTransitionExit);
1599 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1600 "applyAnimation:"
1601 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001602 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001603 + " Callers=" + Debug.getCallers(3));
Winson Chung044d5292014-11-06 11:05:19 -08001604 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE) {
1605 a = loadAnimationRes(mNextAppTransitionPackage, mNextAppTransitionInPlace);
1606 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1607 "applyAnimation:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001608 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM_IN_PLACE"
1609 + " transit=" + appTransitionToString(transit)
1610 + " Callers=" + Debug.getCallers(3));
Chet Haase10e23ab2015-02-11 15:08:38 -08001611 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001612 a = createClipRevealAnimationLocked(transit, enter, frame, displayFrame);
Chet Haase10e23ab2015-02-11 15:08:38 -08001613 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1614 "applyAnimation:"
1615 + " anim=" + a + " nextAppTransition=ANIM_CLIP_REVEAL"
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001616 + " transit=" + appTransitionToString(transit)
Chet Haase10e23ab2015-02-11 15:08:38 -08001617 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001618 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_SCALE_UP) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001619 a = createScaleUpAnimationLocked(transit, enter, frame);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001620 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1621 "applyAnimation:"
1622 + " anim=" + a + " nextAppTransition=ANIM_SCALE_UP"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001623 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001624 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001625 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
1626 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001627 mNextAppTransitionScaleUp =
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001628 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP);
Winson Chunga4ccb862014-08-22 15:26:27 -07001629 a = createThumbnailEnterExitAnimationLocked(getThumbnailTransitionState(enter),
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001630 frame, transit, taskId);
Winson Chunga4ccb862014-08-22 15:26:27 -07001631 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1632 String animName = mNextAppTransitionScaleUp ?
1633 "ANIM_THUMBNAIL_SCALE_UP" : "ANIM_THUMBNAIL_SCALE_DOWN";
1634 Slog.v(TAG, "applyAnimation:"
1635 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001636 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Winson Chunga4ccb862014-08-22 15:26:27 -07001637 + " Callers=" + Debug.getCallers(3));
1638 }
1639 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
1640 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN) {
1641 mNextAppTransitionScaleUp =
1642 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP);
1643 a = createAspectScaledThumbnailEnterExitAnimationLocked(
Winsonb2024762016-04-05 17:32:30 -07001644 getThumbnailTransitionState(enter), uiMode, orientation, transit, frame,
Matthew Ng43db6d22017-06-27 15:29:39 -07001645 insets, surfaceInsets, stableInsets, freeform, taskId);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001646 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1647 String animName = mNextAppTransitionScaleUp ?
Winson Chunga4ccb862014-08-22 15:26:27 -07001648 "ANIM_THUMBNAIL_ASPECT_SCALE_UP" : "ANIM_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner164d4bb2012-11-26 13:51:23 -08001649 Slog.v(TAG, "applyAnimation:"
1650 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001651 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001652 + " Callers=" + Debug.getCallers(3));
1653 }
Tony Mak83546a82018-01-22 13:56:20 +00001654 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS && enter) {
Tony Mak64b8d562017-12-28 17:44:02 +00001655
Tony Mak089c35e2017-12-18 20:34:14 +00001656 a = loadAnimationRes("android", enter
Tony Mak64b8d562017-12-28 17:44:02 +00001657 ? com.android.internal.R.anim.task_open_enter_cross_profile_apps
1658 : com.android.internal.R.anim.task_open_exit);
Tony Mak089c35e2017-12-18 20:34:14 +00001659 Slog.v(TAG,
1660 "applyAnimation NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS:"
1661 + " anim=" + a + " transit=" + appTransitionToString(transit)
1662 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Craig Mautner164d4bb2012-11-26 13:51:23 -08001663 } else {
1664 int animAttr = 0;
1665 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001666 case TRANSIT_ACTIVITY_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001667 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001668 ? WindowAnimation_activityOpenEnterAnimation
1669 : WindowAnimation_activityOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001670 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001671 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001672 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001673 ? WindowAnimation_activityCloseEnterAnimation
1674 : WindowAnimation_activityCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001675 break;
Jorim Jaggi192086e2016-03-11 17:17:03 +01001676 case TRANSIT_DOCK_TASK_FROM_RECENTS:
Craig Mautner4b71aa12012-12-27 17:20:01 -08001677 case TRANSIT_TASK_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001678 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001679 ? WindowAnimation_taskOpenEnterAnimation
1680 : WindowAnimation_taskOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001681 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001682 case TRANSIT_TASK_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001683 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001684 ? WindowAnimation_taskCloseEnterAnimation
1685 : WindowAnimation_taskCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001686 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001687 case TRANSIT_TASK_TO_FRONT:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001688 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001689 ? WindowAnimation_taskToFrontEnterAnimation
1690 : WindowAnimation_taskToFrontExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001691 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001692 case TRANSIT_TASK_TO_BACK:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001693 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001694 ? WindowAnimation_taskToBackEnterAnimation
1695 : WindowAnimation_taskToBackExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001696 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001697 case TRANSIT_WALLPAPER_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001698 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001699 ? WindowAnimation_wallpaperOpenEnterAnimation
1700 : WindowAnimation_wallpaperOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001701 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001702 case TRANSIT_WALLPAPER_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001703 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001704 ? WindowAnimation_wallpaperCloseEnterAnimation
1705 : WindowAnimation_wallpaperCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001706 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001707 case TRANSIT_WALLPAPER_INTRA_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001708 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001709 ? WindowAnimation_wallpaperIntraOpenEnterAnimation
1710 : WindowAnimation_wallpaperIntraOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001711 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001712 case TRANSIT_WALLPAPER_INTRA_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001713 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001714 ? WindowAnimation_wallpaperIntraCloseEnterAnimation
1715 : WindowAnimation_wallpaperIntraCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001716 break;
Craig Mautnerbb742462014-07-07 15:28:55 -07001717 case TRANSIT_TASK_OPEN_BEHIND:
1718 animAttr = enter
1719 ? WindowAnimation_launchTaskBehindSourceAnimation
Craig Mautner3b2cd1d2014-08-25 14:25:54 -07001720 : WindowAnimation_launchTaskBehindTargetAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001721 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001722 a = animAttr != 0 ? loadAnimationAttr(lp, animAttr) : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001723 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1724 "applyAnimation:"
1725 + " anim=" + a
1726 + " animAttr=0x" + Integer.toHexString(animAttr)
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001727 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001728 + " Callers=" + Debug.getCallers(3));
1729 }
1730 return a;
1731 }
1732
Jorim Jaggife762342016-10-13 14:33:27 +02001733 private Animation loadKeyguardExitAnimation(int transit) {
1734 if ((mNextAppTransitionFlags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_NO_ANIMATION) != 0) {
1735 return null;
1736 }
1737 final boolean toShade =
1738 (mNextAppTransitionFlags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_TO_SHADE) != 0;
1739 return mService.mPolicy.createHiddenByKeyguardExit(
1740 transit == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER, toShade);
1741 }
1742
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001743 int getAppStackClipMode() {
Matthew Ngbf1d9852017-03-14 12:23:09 -07001744 // When dismiss keyguard animation occurs, clip before the animation to prevent docked
1745 // app from showing beyond the divider
1746 if (mNextAppTransition == TRANSIT_KEYGUARD_GOING_AWAY
1747 || mNextAppTransition == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER) {
1748 return STACK_CLIP_BEFORE_ANIM;
1749 }
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001750 return mNextAppTransition == TRANSIT_ACTIVITY_RELAUNCH
Jorim Jaggic69bd222016-03-15 14:38:37 +01001751 || mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
Jorim Jaggi1f458fb2016-03-25 17:36:37 -07001752 || mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001753 ? STACK_CLIP_NONE
1754 : STACK_CLIP_AFTER_ANIM;
1755 }
1756
Jorim Jaggife762342016-10-13 14:33:27 +02001757 public int getTransitFlags() {
1758 return mNextAppTransitionFlags;
1759 }
1760
Craig Mautner164d4bb2012-11-26 13:51:23 -08001761 void postAnimationCallback() {
1762 if (mNextAppTransitionCallback != null) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001763 mService.mH.sendMessage(mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK,
1764 mNextAppTransitionCallback));
Craig Mautner164d4bb2012-11-26 13:51:23 -08001765 mNextAppTransitionCallback = null;
1766 }
1767 }
1768
1769 void overridePendingAppTransition(String packageName, int enterAnim, int exitAnim,
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001770 IRemoteCallback startedCallback) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001771 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001772 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001773 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001774 mNextAppTransitionPackage = packageName;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001775 mNextAppTransitionEnter = enterAnim;
1776 mNextAppTransitionExit = exitAnim;
1777 postAnimationCallback();
1778 mNextAppTransitionCallback = startedCallback;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001779 }
1780 }
1781
1782 void overridePendingAppTransitionScaleUp(int startX, int startY, int startWidth,
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001783 int startHeight) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001784 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001785 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001786 mNextAppTransitionType = NEXT_TRANSIT_TYPE_SCALE_UP;
Winson4c3fecd2016-07-13 12:29:48 -07001787 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001788 postAnimationCallback();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001789 }
1790 }
1791
Chet Haase10e23ab2015-02-11 15:08:38 -08001792 void overridePendingAppTransitionClipReveal(int startX, int startY,
1793 int startWidth, int startHeight) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001794 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001795 clear();
Chet Haase10e23ab2015-02-11 15:08:38 -08001796 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CLIP_REVEAL;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001797 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Chet Haase10e23ab2015-02-11 15:08:38 -08001798 postAnimationCallback();
Chet Haase10e23ab2015-02-11 15:08:38 -08001799 }
1800 }
1801
Winson Chungaa7fa012017-05-24 15:50:06 -07001802 void overridePendingAppTransitionThumb(GraphicBuffer srcThumb, int startX, int startY,
Craig Mautner164d4bb2012-11-26 13:51:23 -08001803 IRemoteCallback startedCallback, boolean scaleUp) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001804 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001805 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001806 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP
1807 : NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001808 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001809 putDefaultNextAppTransitionCoordinates(startX, startY, 0, 0, srcThumb);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001810 postAnimationCallback();
1811 mNextAppTransitionCallback = startedCallback;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001812 }
1813 }
1814
Winson Chungaa7fa012017-05-24 15:50:06 -07001815 void overridePendingAppTransitionAspectScaledThumb(GraphicBuffer srcThumb, int startX, int startY,
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001816 int targetWidth, int targetHeight, IRemoteCallback startedCallback, boolean scaleUp) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001817 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001818 clear();
Winson Chunga4ccb862014-08-22 15:26:27 -07001819 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1820 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Winson Chunga4ccb862014-08-22 15:26:27 -07001821 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001822 putDefaultNextAppTransitionCoordinates(startX, startY, targetWidth, targetHeight,
1823 srcThumb);
Winson Chunga4ccb862014-08-22 15:26:27 -07001824 postAnimationCallback();
1825 mNextAppTransitionCallback = startedCallback;
Winson Chunga4ccb862014-08-22 15:26:27 -07001826 }
1827 }
1828
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001829 void overridePendingAppTransitionMultiThumb(AppTransitionAnimationSpec[] specs,
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001830 IRemoteCallback onAnimationStartedCallback, IRemoteCallback onAnimationFinishedCallback,
1831 boolean scaleUp) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001832 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001833 clear();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001834 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1835 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001836 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi43102412015-11-11 16:28:37 +01001837 if (specs != null) {
1838 for (int i = 0; i < specs.length; i++) {
1839 AppTransitionAnimationSpec spec = specs[i];
1840 if (spec != null) {
1841 mNextAppTransitionAnimationsSpecs.put(spec.taskId, spec);
1842 if (i == 0) {
1843 // In full screen mode, the transition code depends on the default spec
1844 // to be set.
1845 Rect rect = spec.rect;
1846 putDefaultNextAppTransitionCoordinates(rect.left, rect.top,
Winson Chungaa7fa012017-05-24 15:50:06 -07001847 rect.width(), rect.height(), spec.buffer);
Jorim Jaggi43102412015-11-11 16:28:37 +01001848 }
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001849 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001850 }
1851 }
1852 postAnimationCallback();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001853 mNextAppTransitionCallback = onAnimationStartedCallback;
1854 mAnimationFinishedCallback = onAnimationFinishedCallback;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001855 }
1856 }
1857
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001858 void overridePendingAppTransitionMultiThumbFuture(
1859 IAppTransitionAnimationSpecsFuture specsFuture, IRemoteCallback callback,
1860 boolean scaleUp) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001861 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001862 clear();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001863 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1864 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001865 mNextAppTransitionAnimationsSpecsFuture = specsFuture;
1866 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001867 mNextAppTransitionFutureCallback = callback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001868 }
1869 }
1870
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001871 void overridePendingAppTransitionRemote(RemoteAnimationAdapter remoteAnimationAdapter) {
Winson Chung044d5292014-11-06 11:05:19 -08001872 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001873 clear();
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001874 mNextAppTransitionType = NEXT_TRANSIT_TYPE_REMOTE;
1875 mRemoteAnimationController = new RemoteAnimationController(mService,
1876 remoteAnimationAdapter, mService.mH);
1877 }
1878 }
1879
1880 void overrideInPlaceAppTransition(String packageName, int anim) {
1881 if (canOverridePendingAppTransition()) {
1882 clear();
Winson Chung044d5292014-11-06 11:05:19 -08001883 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE;
1884 mNextAppTransitionPackage = packageName;
1885 mNextAppTransitionInPlace = anim;
Winson Chung044d5292014-11-06 11:05:19 -08001886 }
1887 }
1888
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001889 /**
Tony Mak089c35e2017-12-18 20:34:14 +00001890 * @see {@link #NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS}
1891 */
1892 void overridePendingAppTransitionStartCrossProfileApps() {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001893 if (canOverridePendingAppTransition()) {
Tony Mak089c35e2017-12-18 20:34:14 +00001894 clear();
1895 mNextAppTransitionType = NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS;
1896 postAnimationCallback();
1897 }
1898 }
1899
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001900 private boolean canOverridePendingAppTransition() {
1901 // Remote animations always take precedence
1902 return isTransitionSet() && mNextAppTransitionType != NEXT_TRANSIT_TYPE_REMOTE;
1903 }
1904
Tony Mak089c35e2017-12-18 20:34:14 +00001905 /**
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001906 * If a future is set for the app transition specs, fetch it in another thread.
1907 */
1908 private void fetchAppTransitionSpecsFromFuture() {
1909 if (mNextAppTransitionAnimationsSpecsFuture != null) {
1910 mNextAppTransitionAnimationsSpecsPending = true;
1911 final IAppTransitionAnimationSpecsFuture future
1912 = mNextAppTransitionAnimationsSpecsFuture;
1913 mNextAppTransitionAnimationsSpecsFuture = null;
Jorim Jaggied410b62017-05-05 15:16:14 +02001914 mDefaultExecutor.execute(() -> {
1915 AppTransitionAnimationSpec[] specs = null;
1916 try {
1917 Binder.allowBlocking(future.asBinder());
1918 specs = future.get();
1919 } catch (RemoteException e) {
1920 Slog.w(TAG, "Failed to fetch app transition specs: " + e);
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001921 }
Jorim Jaggied410b62017-05-05 15:16:14 +02001922 synchronized (mService.mWindowMap) {
1923 mNextAppTransitionAnimationsSpecsPending = false;
1924 overridePendingAppTransitionMultiThumb(specs,
1925 mNextAppTransitionFutureCallback, null /* finishedCallback */,
1926 mNextAppTransitionScaleUp);
1927 mNextAppTransitionFutureCallback = null;
Jorim Jaggied410b62017-05-05 15:16:14 +02001928 }
1929 mService.requestTraversal();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001930 });
1931 }
1932 }
1933
Craig Mautner164d4bb2012-11-26 13:51:23 -08001934 @Override
1935 public String toString() {
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001936 return "mNextAppTransition=" + appTransitionToString(mNextAppTransition);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001937 }
1938
Craig Mautner4b71aa12012-12-27 17:20:01 -08001939 /**
1940 * Returns the human readable name of a window transition.
1941 *
1942 * @param transition The window transition.
1943 * @return The transition symbolic name.
1944 */
1945 public static String appTransitionToString(int transition) {
1946 switch (transition) {
1947 case TRANSIT_UNSET: {
1948 return "TRANSIT_UNSET";
1949 }
1950 case TRANSIT_NONE: {
1951 return "TRANSIT_NONE";
1952 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001953 case TRANSIT_ACTIVITY_OPEN: {
1954 return "TRANSIT_ACTIVITY_OPEN";
1955 }
1956 case TRANSIT_ACTIVITY_CLOSE: {
1957 return "TRANSIT_ACTIVITY_CLOSE";
1958 }
1959 case TRANSIT_TASK_OPEN: {
1960 return "TRANSIT_TASK_OPEN";
1961 }
1962 case TRANSIT_TASK_CLOSE: {
1963 return "TRANSIT_TASK_CLOSE";
1964 }
1965 case TRANSIT_TASK_TO_FRONT: {
1966 return "TRANSIT_TASK_TO_FRONT";
1967 }
1968 case TRANSIT_TASK_TO_BACK: {
1969 return "TRANSIT_TASK_TO_BACK";
1970 }
1971 case TRANSIT_WALLPAPER_CLOSE: {
1972 return "TRANSIT_WALLPAPER_CLOSE";
1973 }
1974 case TRANSIT_WALLPAPER_OPEN: {
1975 return "TRANSIT_WALLPAPER_OPEN";
1976 }
1977 case TRANSIT_WALLPAPER_INTRA_OPEN: {
1978 return "TRANSIT_WALLPAPER_INTRA_OPEN";
1979 }
1980 case TRANSIT_WALLPAPER_INTRA_CLOSE: {
1981 return "TRANSIT_WALLPAPER_INTRA_CLOSE";
1982 }
Craig Mautnerbb742462014-07-07 15:28:55 -07001983 case TRANSIT_TASK_OPEN_BEHIND: {
1984 return "TRANSIT_TASK_OPEN_BEHIND";
1985 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001986 case TRANSIT_ACTIVITY_RELAUNCH: {
1987 return "TRANSIT_ACTIVITY_RELAUNCH";
1988 }
Jorim Jaggi192086e2016-03-11 17:17:03 +01001989 case TRANSIT_DOCK_TASK_FROM_RECENTS: {
1990 return "TRANSIT_DOCK_TASK_FROM_RECENTS";
1991 }
Jorim Jaggife762342016-10-13 14:33:27 +02001992 case TRANSIT_KEYGUARD_GOING_AWAY: {
1993 return "TRANSIT_KEYGUARD_GOING_AWAY";
1994 }
1995 case TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER: {
1996 return "TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER";
1997 }
1998 case TRANSIT_KEYGUARD_OCCLUDE: {
1999 return "TRANSIT_KEYGUARD_OCCLUDE";
2000 }
2001 case TRANSIT_KEYGUARD_UNOCCLUDE: {
2002 return "TRANSIT_KEYGUARD_UNOCCLUDE";
2003 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002004 default: {
2005 return "<UNKNOWN>";
2006 }
2007 }
2008 }
2009
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002010 private String appStateToString() {
2011 switch (mAppTransitionState) {
2012 case APP_STATE_IDLE:
2013 return "APP_STATE_IDLE";
2014 case APP_STATE_READY:
2015 return "APP_STATE_READY";
2016 case APP_STATE_RUNNING:
2017 return "APP_STATE_RUNNING";
2018 case APP_STATE_TIMEOUT:
2019 return "APP_STATE_TIMEOUT";
2020 default:
2021 return "unknown state=" + mAppTransitionState;
2022 }
2023 }
2024
2025 private String transitTypeToString() {
2026 switch (mNextAppTransitionType) {
2027 case NEXT_TRANSIT_TYPE_NONE:
2028 return "NEXT_TRANSIT_TYPE_NONE";
2029 case NEXT_TRANSIT_TYPE_CUSTOM:
2030 return "NEXT_TRANSIT_TYPE_CUSTOM";
Winson Chung044d5292014-11-06 11:05:19 -08002031 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
2032 return "NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002033 case NEXT_TRANSIT_TYPE_SCALE_UP:
2034 return "NEXT_TRANSIT_TYPE_SCALE_UP";
2035 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
2036 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP";
2037 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
2038 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN";
Winson Chunga4ccb862014-08-22 15:26:27 -07002039 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
2040 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP";
2041 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN:
2042 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN";
Tony Mak64b8d562017-12-28 17:44:02 +00002043 case NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS:
2044 return "NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002045 default:
2046 return "unknown type=" + mNextAppTransitionType;
2047 }
2048 }
2049
Steven Timotiusaf03df62017-07-18 16:56:43 -07002050 void writeToProto(ProtoOutputStream proto, long fieldId) {
2051 final long token = proto.start(fieldId);
2052 proto.write(APP_TRANSITION_STATE, mAppTransitionState);
2053 proto.write(LAST_USED_APP_TRANSITION, mLastUsedAppTransition);
2054 proto.end(token);
2055 }
2056
Craig Mautner164d4bb2012-11-26 13:51:23 -08002057 @Override
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002058 public void dump(PrintWriter pw, String prefix) {
2059 pw.print(prefix); pw.println(this);
2060 pw.print(prefix); pw.print("mAppTransitionState="); pw.println(appStateToString());
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002061 if (mNextAppTransitionType != NEXT_TRANSIT_TYPE_NONE) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002062 pw.print(prefix); pw.print("mNextAppTransitionType=");
2063 pw.println(transitTypeToString());
Craig Mautner164d4bb2012-11-26 13:51:23 -08002064 }
2065 switch (mNextAppTransitionType) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002066 case NEXT_TRANSIT_TYPE_CUSTOM:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002067 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Craig Mautner164d4bb2012-11-26 13:51:23 -08002068 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002069 pw.print(prefix); pw.print("mNextAppTransitionEnter=0x");
Craig Mautner164d4bb2012-11-26 13:51:23 -08002070 pw.print(Integer.toHexString(mNextAppTransitionEnter));
2071 pw.print(" mNextAppTransitionExit=0x");
2072 pw.println(Integer.toHexString(mNextAppTransitionExit));
2073 break;
Winson Chung044d5292014-11-06 11:05:19 -08002074 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002075 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Winson Chung044d5292014-11-06 11:05:19 -08002076 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002077 pw.print(prefix); pw.print("mNextAppTransitionInPlace=0x");
Winson Chung044d5292014-11-06 11:05:19 -08002078 pw.print(Integer.toHexString(mNextAppTransitionInPlace));
2079 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002080 case NEXT_TRANSIT_TYPE_SCALE_UP: {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002081 getDefaultNextAppTransitionStartRect(mTmpRect);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002082 pw.print(prefix); pw.print("mNextAppTransitionStartX=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002083 pw.print(mTmpRect.left);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002084 pw.print(" mNextAppTransitionStartY=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002085 pw.println(mTmpRect.top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002086 pw.print(prefix); pw.print("mNextAppTransitionStartWidth=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002087 pw.print(mTmpRect.width());
Craig Mautner164d4bb2012-11-26 13:51:23 -08002088 pw.print(" mNextAppTransitionStartHeight=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002089 pw.println(mTmpRect.height());
Craig Mautner164d4bb2012-11-26 13:51:23 -08002090 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002091 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002092 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
2093 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
Winson Chunga4ccb862014-08-22 15:26:27 -07002094 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002095 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN: {
2096 pw.print(prefix); pw.print("mDefaultNextAppTransitionAnimationSpec=");
2097 pw.println(mDefaultNextAppTransitionAnimationSpec);
2098 pw.print(prefix); pw.print("mNextAppTransitionAnimationsSpecs=");
2099 pw.println(mNextAppTransitionAnimationsSpecs);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002100 pw.print(prefix); pw.print("mNextAppTransitionScaleUp=");
2101 pw.println(mNextAppTransitionScaleUp);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002102 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002103 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002104 }
2105 if (mNextAppTransitionCallback != null) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002106 pw.print(prefix); pw.print("mNextAppTransitionCallback=");
2107 pw.println(mNextAppTransitionCallback);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002108 }
Chong Zhang60091a92016-07-27 17:52:45 -07002109 if (mLastUsedAppTransition != TRANSIT_NONE) {
2110 pw.print(prefix); pw.print("mLastUsedAppTransition=");
2111 pw.println(appTransitionToString(mLastUsedAppTransition));
2112 pw.print(prefix); pw.print("mLastOpeningApp=");
2113 pw.println(mLastOpeningApp);
2114 pw.print(prefix); pw.print("mLastClosingApp=");
2115 pw.println(mLastClosingApp);
2116 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002117 }
Amith Yamasani4befbec2013-07-10 16:18:01 -07002118
2119 public void setCurrentUser(int newUserId) {
2120 mCurrentUserId = newUserId;
2121 }
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002122
2123 /**
2124 * @return true if transition is not running and should not be skipped, false if transition is
2125 * already running
2126 */
Jorim Jaggif84e2f62018-01-16 14:17:59 +01002127 boolean prepareAppTransitionLocked(@TransitionType int transit, boolean alwaysKeepCurrent,
2128 @TransitionFlags int flags, boolean forceOverride) {
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002129 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Prepare app transition:"
2130 + " transit=" + appTransitionToString(transit)
2131 + " " + this
2132 + " alwaysKeepCurrent=" + alwaysKeepCurrent
2133 + " Callers=" + Debug.getCallers(3));
Jorim Jaggife762342016-10-13 14:33:27 +02002134 if (forceOverride || isKeyguardTransit(transit) || !isTransitionSet()
2135 || mNextAppTransition == TRANSIT_NONE) {
2136 setAppTransition(transit, flags);
Jorim Jaggia69243a2017-06-15 15:10:38 -04002137 }
2138 // We never want to change from a Keyguard transit to a non-Keyguard transit, as our logic
2139 // relies on the fact that we always execute a Keyguard transition after preparing one.
2140 else if (!alwaysKeepCurrent && !isKeyguardTransit(transit)) {
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002141 if (transit == TRANSIT_TASK_OPEN && isTransitionEqual(TRANSIT_TASK_CLOSE)) {
2142 // Opening a new task always supersedes a close for the anim.
Jorim Jaggife762342016-10-13 14:33:27 +02002143 setAppTransition(transit, flags);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002144 } else if (transit == TRANSIT_ACTIVITY_OPEN
2145 && isTransitionEqual(TRANSIT_ACTIVITY_CLOSE)) {
2146 // Opening a new activity always supersedes a close for the anim.
Jorim Jaggife762342016-10-13 14:33:27 +02002147 setAppTransition(transit, flags);
Jorim Jaggicecf4242018-02-21 18:46:53 +01002148 } else if (isTaskTransit(transit) && isActivityTransit(mNextAppTransition)) {
2149 // Task animations always supersede activity animations, because if we have both, it
2150 // usually means that activity transition were just trampoline activities.
2151 setAppTransition(transit, flags);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002152 }
2153 }
2154 boolean prepared = prepare();
2155 if (isTransitionSet()) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08002156 mService.mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
2157 mService.mH.sendEmptyMessageDelayed(H.APP_TRANSITION_TIMEOUT, APP_TRANSITION_TIMEOUT_MS);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002158 }
2159 return prepared;
2160 }
Winsonb2024762016-04-05 17:32:30 -07002161
2162 /**
Jorim Jaggife762342016-10-13 14:33:27 +02002163 * @return true if {@param transit} is representing a transition in which Keyguard is going
2164 * away, false otherwise
2165 */
2166 public static boolean isKeyguardGoingAwayTransit(int transit) {
2167 return transit == TRANSIT_KEYGUARD_GOING_AWAY
2168 || transit == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER;
2169 }
2170
2171 private static boolean isKeyguardTransit(int transit) {
2172 return isKeyguardGoingAwayTransit(transit) || transit == TRANSIT_KEYGUARD_OCCLUDE
2173 || transit == TRANSIT_KEYGUARD_UNOCCLUDE;
2174 }
2175
Jorim Jaggicecf4242018-02-21 18:46:53 +01002176 private static boolean isTaskTransit(int transit) {
2177 return transit == TRANSIT_TASK_OPEN
2178 || transit == TRANSIT_TASK_CLOSE
2179 || transit == TRANSIT_TASK_OPEN_BEHIND
2180 || transit == TRANSIT_TASK_TO_BACK
2181 || transit == TRANSIT_TASK_TO_FRONT
2182 || transit == TRANSIT_TASK_IN_PLACE;
2183 }
2184
2185 private static boolean isActivityTransit(int transit) {
2186 return transit == TRANSIT_ACTIVITY_OPEN
2187 || transit == TRANSIT_ACTIVITY_CLOSE
2188 || transit == TRANSIT_ACTIVITY_RELAUNCH;
2189 }
2190
Jorim Jaggife762342016-10-13 14:33:27 +02002191 /**
Manu Cornetd7376802017-01-13 13:44:07 -08002192 * @return whether the transition should show the thumbnail being scaled down.
2193 */
2194 private boolean shouldScaleDownThumbnailTransition(int uiMode, int orientation) {
Sid Soundararajan0e88d322017-03-07 15:37:30 -08002195 return mGridLayoutRecentsEnabled
Manu Cornetd7376802017-01-13 13:44:07 -08002196 || orientation == Configuration.ORIENTATION_PORTRAIT;
2197 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002198}