blob: 4a74e295c8fcd4541091f369d01b1bfcea454321 [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
Filip Gruszczynski82861362015-10-16 14:21:09 -070019import static com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation;
20import static com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
21import static com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation;
22import static com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
23import static com.android.internal.R.styleable.WindowAnimation_launchTaskBehindSourceAnimation;
24import static com.android.internal.R.styleable.WindowAnimation_launchTaskBehindTargetAnimation;
25import static com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation;
26import static com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
27import static com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation;
28import static com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
29import static com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation;
30import static com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
31import static com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation;
32import static com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
33import static com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation;
34import static com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
35import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation;
36import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
37import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation;
38import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
39import static com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation;
40import static com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Jorim Jaggi363ab982016-04-26 19:51:20 -070041import static com.android.server.wm.AppWindowAnimator.PROLONG_ANIMATION_AT_START;
Filip Gruszczynski198dcbf2016-01-18 10:02:00 -080042import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
43import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080044import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
45import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Adrian Roose99bc052017-11-20 17:55:31 +010046import static com.android.server.wm.WindowManagerInternal.AppTransitionListener;
Tony Mak089c35e2017-12-18 20:34:14 +000047import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_AFTER_ANIM;
Matthew Ngbf1d9852017-03-14 12:23:09 -070048import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_BEFORE_ANIM;
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +010049import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_NONE;
Steven Timotiusaf03df62017-07-18 16:56:43 -070050import static com.android.server.wm.proto.AppTransitionProto.APP_TRANSITION_STATE;
51import static com.android.server.wm.proto.AppTransitionProto.LAST_USED_APP_TRANSITION;
Filip Gruszczynski82861362015-10-16 14:21:09 -070052
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -070053import android.annotation.Nullable;
Matthew Ng43db6d22017-06-27 15:29:39 -070054import android.app.ActivityManager;
Tony Mak089c35e2017-12-18 20:34:14 +000055import android.content.ComponentName;
Craig Mautner164d4bb2012-11-26 13:51:23 -080056import android.content.Context;
Winson21700932016-03-24 17:26:23 -070057import android.content.res.Configuration;
Winson Chungaa7fa012017-05-24 15:50:06 -070058import android.graphics.GraphicBuffer;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +010059import android.graphics.Path;
Winson Chung399f6202014-03-19 10:47:20 -070060import android.graphics.Rect;
Jorim Jaggied410b62017-05-05 15:16:14 +020061import android.os.Binder;
Craig Mautner164d4bb2012-11-26 13:51:23 -080062import android.os.Debug;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010063import android.os.IBinder;
Craig Mautner164d4bb2012-11-26 13:51:23 -080064import android.os.IRemoteCallback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010065import android.os.RemoteException;
Manu Cornetd7376802017-01-13 13:44:07 -080066import android.os.SystemProperties;
Tony Mak089c35e2017-12-18 20:34:14 +000067import android.os.UserHandle;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -080068import android.util.ArraySet;
Craig Mautner164d4bb2012-11-26 13:51:23 -080069import android.util.Slog;
Filip Gruszczynski170192a2015-08-16 17:46:34 -070070import android.util.SparseArray;
Steven Timotiusaf03df62017-07-18 16:56:43 -070071import android.util.proto.ProtoOutputStream;
Filip Gruszczynski170192a2015-08-16 17:46:34 -070072import android.view.AppTransitionAnimationSpec;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010073import android.view.IAppTransitionAnimationSpecsFuture;
Craig Mautner164d4bb2012-11-26 13:51:23 -080074import android.view.WindowManager;
Craig Mautner164d4bb2012-11-26 13:51:23 -080075import android.view.animation.AlphaAnimation;
76import android.view.animation.Animation;
77import android.view.animation.AnimationSet;
78import android.view.animation.AnimationUtils;
Winson Chung399f6202014-03-19 10:47:20 -070079import android.view.animation.ClipRectAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -080080import android.view.animation.Interpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070081import android.view.animation.PathInterpolator;
Craig Mautner164d4bb2012-11-26 13:51:23 -080082import android.view.animation.ScaleAnimation;
Winson Chung399f6202014-03-19 10:47:20 -070083import android.view.animation.TranslateAnimation;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070084
Craig Mautner164d4bb2012-11-26 13:51:23 -080085import com.android.internal.util.DumpUtils.Dump;
86import com.android.server.AttributeCache;
87import com.android.server.wm.WindowManagerService.H;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -080088import com.android.server.wm.animation.ClipRectLRAnimation;
89import com.android.server.wm.animation.ClipRectTBAnimation;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +010090import com.android.server.wm.animation.CurvedTranslateAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -080091
92import java.io.PrintWriter;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010093import java.util.ArrayList;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010094import java.util.concurrent.ExecutorService;
95import java.util.concurrent.Executors;
Craig Mautner164d4bb2012-11-26 13:51:23 -080096
Craig Mautner164d4bb2012-11-26 13:51:23 -080097// State management of app transitions. When we are preparing for a
98// transition, mNextAppTransition will be the kind of transition to
99// perform or TRANSIT_NONE if we are not waiting. If we are waiting,
100// mOpeningApps and mClosingApps are the lists of tokens that will be
101// made visible or hidden at the next transition.
102public class AppTransition implements Dump {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800103 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppTransition" : TAG_WM;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700104 private static final int CLIP_REVEAL_TRANSLATION_Y_DP = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800105
Craig Mautner4b71aa12012-12-27 17:20:01 -0800106 /** Not set up for a transition. */
107 public static final int TRANSIT_UNSET = -1;
108 /** No animation for transition. */
109 public static final int TRANSIT_NONE = 0;
110 /** A window in a new activity is being opened on top of an existing one in the same task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700111 public static final int TRANSIT_ACTIVITY_OPEN = 6;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800112 /** The window in the top-most activity is being closed to reveal the
113 * previous activity in the same task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700114 public static final int TRANSIT_ACTIVITY_CLOSE = 7;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800115 /** A window in a new task is being opened on top of an existing one
116 * in another activity's task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700117 public static final int TRANSIT_TASK_OPEN = 8;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800118 /** A window in the top-most activity is being closed to reveal the
119 * previous activity in a different task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700120 public static final int TRANSIT_TASK_CLOSE = 9;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800121 /** A window in an existing task is being displayed on top of an existing one
122 * in another activity's task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700123 public static final int TRANSIT_TASK_TO_FRONT = 10;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800124 /** A window in an existing task is being put below all other tasks. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700125 public static final int TRANSIT_TASK_TO_BACK = 11;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800126 /** A window in a new activity that doesn't have a wallpaper is being opened on top of one that
127 * does, effectively closing the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700128 public static final int TRANSIT_WALLPAPER_CLOSE = 12;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800129 /** A window in a new activity that does have a wallpaper is being opened on one that didn't,
130 * effectively opening the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700131 public static final int TRANSIT_WALLPAPER_OPEN = 13;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800132 /** A window in a new activity is being opened on top of an existing one, and both are on top
133 * of the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700134 public static final int TRANSIT_WALLPAPER_INTRA_OPEN = 14;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800135 /** The window in the top-most activity is being closed to reveal the previous activity, and
136 * both are on top of the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700137 public static final int TRANSIT_WALLPAPER_INTRA_CLOSE = 15;
138 /** A window in a new task is being opened behind an existing one in another activity's task.
139 * The new window will show briefly and then be gone. */
140 public static final int TRANSIT_TASK_OPEN_BEHIND = 16;
Winson Chung044d5292014-11-06 11:05:19 -0800141 /** A window in a task is being animated in-place. */
142 public static final int TRANSIT_TASK_IN_PLACE = 17;
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700143 /** An activity is being relaunched (e.g. due to configuration change). */
144 public static final int TRANSIT_ACTIVITY_RELAUNCH = 18;
Jorim Jaggi192086e2016-03-11 17:17:03 +0100145 /** A task is being docked from recents. */
146 public static final int TRANSIT_DOCK_TASK_FROM_RECENTS = 19;
Jorim Jaggife762342016-10-13 14:33:27 +0200147 /** Keyguard is going away */
148 public static final int TRANSIT_KEYGUARD_GOING_AWAY = 20;
149 /** Keyguard is going away with showing an activity behind that requests wallpaper */
150 public static final int TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER = 21;
151 /** Keyguard is being occluded */
152 public static final int TRANSIT_KEYGUARD_OCCLUDE = 22;
153 /** Keyguard is being unoccluded */
154 public static final int TRANSIT_KEYGUARD_UNOCCLUDE = 23;
155
156 /** Transition flag: Keyguard is going away, but keeping the notification shade open */
157 public static final int TRANSIT_FLAG_KEYGUARD_GOING_AWAY_TO_SHADE = 0x1;
158 /** Transition flag: Keyguard is going away, but doesn't want an animation for it */
159 public static final int TRANSIT_FLAG_KEYGUARD_GOING_AWAY_NO_ANIMATION = 0x2;
160 /** Transition flag: Keyguard is going away while it was showing the system wallpaper. */
161 public static final int TRANSIT_FLAG_KEYGUARD_GOING_AWAY_WITH_WALLPAPER = 0x4;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800162
Winson Chunga4ccb862014-08-22 15:26:27 -0700163 /** Fraction of animation at which the recents thumbnail stays completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700164 private static final float RECENTS_THUMBNAIL_FADEIN_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800165 /** Fraction of animation at which the recents thumbnail becomes completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700166 private static final float RECENTS_THUMBNAIL_FADEOUT_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800167
Filip Gruszczynski84fa3352016-01-25 16:28:49 -0800168 static final int DEFAULT_APP_TRANSITION_DURATION = 336;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800169
170 /** Interpolator to be used for animations that respond directly to a touch */
171 static final Interpolator TOUCH_RESPONSE_INTERPOLATOR =
172 new PathInterpolator(0.3f, 0f, 0.1f, 1f);
173
Jorim Jaggic69bd222016-03-15 14:38:37 +0100174 private static final Interpolator THUMBNAIL_DOCK_INTERPOLATOR =
175 new PathInterpolator(0.85f, 0f, 1f, 1f);
176
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800177 /**
178 * Maximum duration for the clip reveal animation. This is used when there is a lot of movement
179 * involved, to make it more understandable.
180 */
181 private static final int MAX_CLIP_REVEAL_TRANSITION_DURATION = 420;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700182 private static final int THUMBNAIL_APP_TRANSITION_DURATION = 336;
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700183 private static final long APP_TRANSITION_TIMEOUT_MS = 5000;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800184
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800185 private final Context mContext;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800186 private final WindowManagerService mService;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800187
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800188 private int mNextAppTransition = TRANSIT_UNSET;
Jorim Jaggife762342016-10-13 14:33:27 +0200189 private int mNextAppTransitionFlags = 0;
Chong Zhang60091a92016-07-27 17:52:45 -0700190 private int mLastUsedAppTransition = TRANSIT_UNSET;
191 private String mLastOpeningApp;
192 private String mLastClosingApp;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800193
194 private static final int NEXT_TRANSIT_TYPE_NONE = 0;
195 private static final int NEXT_TRANSIT_TYPE_CUSTOM = 1;
196 private static final int NEXT_TRANSIT_TYPE_SCALE_UP = 2;
197 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP = 3;
198 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN = 4;
Winson Chunga4ccb862014-08-22 15:26:27 -0700199 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP = 5;
200 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN = 6;
Winson Chung044d5292014-11-06 11:05:19 -0800201 private static final int NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE = 7;
Chet Haase10e23ab2015-02-11 15:08:38 -0800202 private static final int NEXT_TRANSIT_TYPE_CLIP_REVEAL = 8;
Tony Mak089c35e2017-12-18 20:34:14 +0000203
204 /**
205 * Refers to the transition to activity started by using {@link
206 * android.content.pm.crossprofile.CrossProfileApps#startMainActivity(ComponentName, UserHandle)
207 * }.
208 */
209 private static final int NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS = 9;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800210 private int mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
211
Winson Chung399f6202014-03-19 10:47:20 -0700212 // These are the possible states for the enter/exit activities during a thumbnail transition
213 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_UP = 0;
214 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_UP = 1;
215 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN = 2;
216 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN = 3;
217
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800218 private String mNextAppTransitionPackage;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800219 // Used for thumbnail transitions. True if we're scaling up, false if scaling down
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800220 private boolean mNextAppTransitionScaleUp;
221 private IRemoteCallback mNextAppTransitionCallback;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +0100222 private IRemoteCallback mNextAppTransitionFutureCallback;
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -0700223 private IRemoteCallback mAnimationFinishedCallback;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800224 private int mNextAppTransitionEnter;
225 private int mNextAppTransitionExit;
Winson Chung044d5292014-11-06 11:05:19 -0800226 private int mNextAppTransitionInPlace;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700227
228 // Keyed by task id.
229 private final SparseArray<AppTransitionAnimationSpec> mNextAppTransitionAnimationsSpecs
230 = new SparseArray<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100231 private IAppTransitionAnimationSpecsFuture mNextAppTransitionAnimationsSpecsFuture;
232 private boolean mNextAppTransitionAnimationsSpecsPending;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700233 private AppTransitionAnimationSpec mDefaultNextAppTransitionAnimationSpec;
234
Winson Chunga4ccb862014-08-22 15:26:27 -0700235 private Rect mNextAppTransitionInsets = new Rect();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800236
Winson Chung2820c452014-04-15 15:34:44 -0700237 private Rect mTmpFromClipRect = new Rect();
238 private Rect mTmpToClipRect = new Rect();
239
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700240 private final Rect mTmpRect = new Rect();
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700241
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800242 private final static int APP_STATE_IDLE = 0;
243 private final static int APP_STATE_READY = 1;
244 private final static int APP_STATE_RUNNING = 2;
245 private final static int APP_STATE_TIMEOUT = 3;
246 private int mAppTransitionState = APP_STATE_IDLE;
247
248 private final int mConfigShortAnimTime;
Craig Mautner321bdf52012-12-18 09:53:24 -0800249 private final Interpolator mDecelerateInterpolator;
Winson Chunga4ccb862014-08-22 15:26:27 -0700250 private final Interpolator mThumbnailFadeInInterpolator;
251 private final Interpolator mThumbnailFadeOutInterpolator;
Chet Haase10e23ab2015-02-11 15:08:38 -0800252 private final Interpolator mLinearOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700253 private final Interpolator mFastOutLinearInInterpolator;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100254 private final Interpolator mFastOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700255 private final Interpolator mClipHorizontalInterpolator = new PathInterpolator(0, 0, 0.4f, 1f);
256
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700257 private final int mClipRevealTranslationY;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800258
Amith Yamasani4befbec2013-07-10 16:18:01 -0700259 private int mCurrentUserId = 0;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800260 private long mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Amith Yamasani4befbec2013-07-10 16:18:01 -0700261
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100262 private final ArrayList<AppTransitionListener> mListeners = new ArrayList<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100263 private final ExecutorService mDefaultExecutor = Executors.newSingleThreadExecutor();
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100264
Jorim Jaggif97ed922016-02-18 18:57:07 -0800265 private int mLastClipRevealMaxTranslation;
266 private boolean mLastHadClipReveal;
Jorim Jaggi363ab982016-04-26 19:51:20 -0700267 private boolean mProlongedAnimationsEnded;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800268
Manu Cornetd7376802017-01-13 13:44:07 -0800269 private final boolean mGridLayoutRecentsEnabled;
Matthew Ng43db6d22017-06-27 15:29:39 -0700270 private final boolean mLowRamRecentsEnabled;
Manu Cornetd7376802017-01-13 13:44:07 -0800271
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800272 AppTransition(Context context, WindowManagerService service) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800273 mContext = context;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800274 mService = service;
Chet Haase10e23ab2015-02-11 15:08:38 -0800275 mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
276 com.android.internal.R.interpolator.linear_out_slow_in);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700277 mFastOutLinearInInterpolator = AnimationUtils.loadInterpolator(context,
278 com.android.internal.R.interpolator.fast_out_linear_in);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100279 mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
280 com.android.internal.R.interpolator.fast_out_slow_in);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800281 mConfigShortAnimTime = context.getResources().getInteger(
282 com.android.internal.R.integer.config_shortAnimTime);
Craig Mautner321bdf52012-12-18 09:53:24 -0800283 mDecelerateInterpolator = AnimationUtils.loadInterpolator(context,
284 com.android.internal.R.interpolator.decelerate_cubic);
Winson Chunga4ccb862014-08-22 15:26:27 -0700285 mThumbnailFadeInInterpolator = new Interpolator() {
286 @Override
287 public float getInterpolation(float input) {
288 // Linear response for first fraction, then complete after that.
289 if (input < RECENTS_THUMBNAIL_FADEIN_FRACTION) {
290 return 0f;
291 }
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700292 float t = (input - RECENTS_THUMBNAIL_FADEIN_FRACTION) /
Winson Chunga4ccb862014-08-22 15:26:27 -0700293 (1f - RECENTS_THUMBNAIL_FADEIN_FRACTION);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700294 return mFastOutLinearInInterpolator.getInterpolation(t);
Winson Chunga4ccb862014-08-22 15:26:27 -0700295 }
296 };
297 mThumbnailFadeOutInterpolator = new Interpolator() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800298 @Override
299 public float getInterpolation(float input) {
300 // Linear response for first fraction, then complete after that.
301 if (input < RECENTS_THUMBNAIL_FADEOUT_FRACTION) {
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700302 float t = input / RECENTS_THUMBNAIL_FADEOUT_FRACTION;
303 return mLinearOutSlowInInterpolator.getInterpolation(t);
Craig Mautner321bdf52012-12-18 09:53:24 -0800304 }
Winson Chunga4ccb862014-08-22 15:26:27 -0700305 return 1f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800306 }
307 };
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700308 mClipRevealTranslationY = (int) (CLIP_REVEAL_TRANSLATION_Y_DP
309 * mContext.getResources().getDisplayMetrics().density);
Manu Cornetd7376802017-01-13 13:44:07 -0800310 mGridLayoutRecentsEnabled = SystemProperties.getBoolean("ro.recents.grid", false);
Matthew Ng43db6d22017-06-27 15:29:39 -0700311 mLowRamRecentsEnabled = ActivityManager.isLowRamDeviceStatic();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800312 }
313
314 boolean isTransitionSet() {
315 return mNextAppTransition != TRANSIT_UNSET;
316 }
317
Craig Mautner164d4bb2012-11-26 13:51:23 -0800318 boolean isTransitionEqual(int transit) {
319 return mNextAppTransition == transit;
320 }
321
322 int getAppTransition() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800323 return mNextAppTransition;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800324 }
325
Jorim Jaggife762342016-10-13 14:33:27 +0200326 private void setAppTransition(int transit, int flags) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800327 mNextAppTransition = transit;
Jorim Jaggife762342016-10-13 14:33:27 +0200328 mNextAppTransitionFlags |= flags;
Chong Zhang60091a92016-07-27 17:52:45 -0700329 setLastAppTransition(TRANSIT_UNSET, null, null);
Jorim Jaggi245281c2017-06-07 14:33:04 -0700330 updateBooster();
Chong Zhang60091a92016-07-27 17:52:45 -0700331 }
332
333 void setLastAppTransition(int transit, AppWindowToken openingApp, AppWindowToken closingApp) {
334 mLastUsedAppTransition = transit;
335 mLastOpeningApp = "" + openingApp;
336 mLastClosingApp = "" + closingApp;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800337 }
338
339 boolean isReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800340 return mAppTransitionState == APP_STATE_READY
341 || mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800342 }
343
Craig Mautnerae446592012-12-06 19:05:05 -0800344 void setReady() {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700345 setAppTransitionState(APP_STATE_READY);
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100346 fetchAppTransitionSpecsFromFuture();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800347 }
348
349 boolean isRunning() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800350 return mAppTransitionState == APP_STATE_RUNNING;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800351 }
352
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800353 void setIdle() {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700354 setAppTransitionState(APP_STATE_IDLE);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800355 }
356
357 boolean isTimeout() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800358 return mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800359 }
360
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800361 void setTimeout() {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700362 setAppTransitionState(APP_STATE_TIMEOUT);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800363 }
364
Winson Chungaa7fa012017-05-24 15:50:06 -0700365 GraphicBuffer getAppTransitionThumbnailHeader(int taskId) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700366 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800367 if (spec == null) {
368 spec = mDefaultNextAppTransitionAnimationSpec;
369 }
Winson Chungaa7fa012017-05-24 15:50:06 -0700370 return spec != null ? spec.buffer : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800371 }
372
Winson Chunga4ccb862014-08-22 15:26:27 -0700373 /** Returns whether the next thumbnail transition is aspect scaled up. */
374 boolean isNextThumbnailTransitionAspectScaled() {
375 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
376 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
377 }
378
379 /** Returns whether the next thumbnail transition is scaling up. */
380 boolean isNextThumbnailTransitionScaleUp() {
381 return mNextAppTransitionScaleUp;
382 }
383
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -0800384 boolean isNextAppTransitionThumbnailUp() {
385 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
386 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP;
387 }
388
389 boolean isNextAppTransitionThumbnailDown() {
390 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN ||
391 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
392 }
393
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100394 /**
395 * @return true if and only if we are currently fetching app transition specs from the future
396 * passed into {@link #overridePendingAppTransitionMultiThumbFuture}
397 */
398 boolean isFetchingAppTransitionsSpecs() {
399 return mNextAppTransitionAnimationsSpecsPending;
400 }
401
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700402 private boolean prepare() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800403 if (!isRunning()) {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700404 setAppTransitionState(APP_STATE_IDLE);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100405 notifyAppTransitionPendingLocked();
Jorim Jaggif97ed922016-02-18 18:57:07 -0800406 mLastHadClipReveal = false;
407 mLastClipRevealMaxTranslation = 0;
408 mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700409 return true;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800410 }
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700411 return false;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800412 }
413
Jorim Jaggife762342016-10-13 14:33:27 +0200414 /**
415 * @return bit-map of WindowManagerPolicy#FINISH_LAYOUT_REDO_* to indicate whether another
416 * layout pass needs to be done
417 */
418 int goodToGo(int transit, AppWindowAnimator topOpeningAppAnimator,
419 AppWindowAnimator topClosingAppAnimator, ArraySet<AppWindowToken> openingApps,
420 ArraySet<AppWindowToken> closingApps) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800421 mNextAppTransition = TRANSIT_UNSET;
Jorim Jaggife762342016-10-13 14:33:27 +0200422 mNextAppTransitionFlags = 0;
Jorim Jaggi245281c2017-06-07 14:33:04 -0700423 setAppTransitionState(APP_STATE_RUNNING);
Jorim Jaggife762342016-10-13 14:33:27 +0200424 int redoLayout = notifyAppTransitionStartingLocked(transit,
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800425 topOpeningAppAnimator != null ? topOpeningAppAnimator.mAppToken.token : null,
426 topClosingAppAnimator != null ? topClosingAppAnimator.mAppToken.token : null,
427 topOpeningAppAnimator != null ? topOpeningAppAnimator.animation : null,
428 topClosingAppAnimator != null ? topClosingAppAnimator.animation : null);
429 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Jorim Jaggife762342016-10-13 14:33:27 +0200430 .notifyAppTransitionStarting(openingApps, transit);
Jorim Jaggi363ab982016-04-26 19:51:20 -0700431
432 // Prolong the start for the transition when docking a task from recents, unless recents
433 // ended it already then we don't need to wait.
Jorim Jaggife762342016-10-13 14:33:27 +0200434 if (transit == TRANSIT_DOCK_TASK_FROM_RECENTS && !mProlongedAnimationsEnded) {
Jorim Jaggi363ab982016-04-26 19:51:20 -0700435 for (int i = openingApps.size() - 1; i >= 0; i--) {
436 final AppWindowAnimator appAnimator = openingApps.valueAt(i).mAppAnimator;
437 appAnimator.startProlongAnimation(PROLONG_ANIMATION_AT_START);
438 }
439 }
Jorim Jaggife762342016-10-13 14:33:27 +0200440 return redoLayout;
Jorim Jaggi363ab982016-04-26 19:51:20 -0700441 }
442
443 /**
444 * Let the transitions manager know that the somebody wanted to end the prolonged animations.
445 */
446 void notifyProlongedAnimationsEnded() {
447 mProlongedAnimationsEnded = true;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800448 }
449
450 void clear() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800451 mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800452 mNextAppTransitionPackage = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700453 mNextAppTransitionAnimationsSpecs.clear();
Jorim Jaggi65193992015-11-23 16:49:59 -0800454 mNextAppTransitionAnimationsSpecsFuture = null;
455 mDefaultNextAppTransitionAnimationSpec = null;
456 mAnimationFinishedCallback = null;
Jorim Jaggi363ab982016-04-26 19:51:20 -0700457 mProlongedAnimationsEnded = false;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800458 }
459
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800460 void freeze() {
Jorim Jaggife762342016-10-13 14:33:27 +0200461 final int transit = mNextAppTransition;
462 setAppTransition(AppTransition.TRANSIT_UNSET, 0 /* flags */);
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800463 clear();
464 setReady();
Jorim Jaggife762342016-10-13 14:33:27 +0200465 notifyAppTransitionCancelledLocked(transit);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100466 }
467
Jorim Jaggi245281c2017-06-07 14:33:04 -0700468 private void setAppTransitionState(int state) {
469 mAppTransitionState = state;
470 updateBooster();
471 }
472
473 /**
474 * Updates whether we currently boost wm locked sections and the animation thread. We want to
475 * boost the priorities to a more important value whenever an app transition is going to happen
476 * soon or an app transition is running.
477 */
478 private void updateBooster() {
479 WindowManagerService.sThreadPriorityBooster.setAppTransitionRunning(
480 mNextAppTransition != TRANSIT_UNSET || mAppTransitionState == APP_STATE_READY
481 || mAppTransitionState == APP_STATE_RUNNING);
482 }
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 Jaggi77ba4802015-02-18 13:57:50 +0100507 IBinder closeToken, Animation openAnimation, Animation closeAnimation) {
Jorim Jaggife762342016-10-13 14:33:27 +0200508 int redoLayout = 0;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100509 for (int i = 0; i < mListeners.size(); i++) {
Jorim Jaggife762342016-10-13 14:33:27 +0200510 redoLayout |= mListeners.get(i).onAppTransitionStartingLocked(transit, openToken,
511 closeToken, openAnimation, closeAnimation);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100512 }
Jorim Jaggife762342016-10-13 14:33:27 +0200513 return redoLayout;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800514 }
515
Craig Mautner164d4bb2012-11-26 13:51:23 -0800516 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
517 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg="
518 + (lp != null ? lp.packageName : null)
519 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
520 if (lp != null && lp.windowAnimations != 0) {
521 // If this is a system resource, don't try to load it from the
522 // application resources. It is nice to avoid loading application
523 // resources if we can.
524 String packageName = lp.packageName != null ? lp.packageName : "android";
525 int resId = lp.windowAnimations;
526 if ((resId&0xFF000000) == 0x01000000) {
527 packageName = "android";
528 }
529 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
530 + packageName);
531 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700532 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800533 }
534 return null;
535 }
536
537 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
538 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package="
539 + packageName + " resId=0x" + Integer.toHexString(resId));
540 if (packageName != null) {
541 if ((resId&0xFF000000) == 0x01000000) {
542 packageName = "android";
543 }
544 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
545 + packageName);
546 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700547 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800548 }
549 return null;
550 }
551
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700552 Animation loadAnimationAttr(WindowManager.LayoutParams lp, int animAttr) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800553 int anim = 0;
554 Context context = mContext;
555 if (animAttr >= 0) {
556 AttributeCache.Entry ent = getCachedAnimations(lp);
557 if (ent != null) {
558 context = ent.context;
559 anim = ent.array.getResourceId(animAttr, 0);
560 }
561 }
562 if (anim != 0) {
563 return AnimationUtils.loadAnimation(context, anim);
564 }
565 return null;
566 }
567
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700568 Animation loadAnimationRes(WindowManager.LayoutParams lp, int resId) {
569 Context context = mContext;
570 if (resId >= 0) {
571 AttributeCache.Entry ent = getCachedAnimations(lp);
572 if (ent != null) {
573 context = ent.context;
574 }
575 return AnimationUtils.loadAnimation(context, resId);
576 }
577 return null;
578 }
579
580 private Animation loadAnimationRes(String packageName, int resId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800581 int anim = 0;
582 Context context = mContext;
583 if (resId >= 0) {
584 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
585 if (ent != null) {
586 context = ent.context;
587 anim = resId;
588 }
589 }
590 if (anim != 0) {
591 return AnimationUtils.loadAnimation(context, anim);
592 }
593 return null;
594 }
595
Craig Mautner164d4bb2012-11-26 13:51:23 -0800596 /**
597 * Compute the pivot point for an animation that is scaling from a small
598 * rect on screen to a larger rect. The pivot point varies depending on
599 * the distance between the inner and outer edges on both sides. This
600 * function computes the pivot point for one dimension.
601 * @param startPos Offset from left/top edge of outer rectangle to
602 * left/top edge of inner rectangle.
603 * @param finalScale The scaling factor between the size of the outer
604 * and inner rectangles.
605 */
606 private static float computePivot(int startPos, float finalScale) {
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800607
608 /*
609 Theorem of intercepting lines:
610
611 + + +-----------------------------------------------+
612 | | | |
613 | | | |
614 | | | |
615 | | | |
616 x | y | | |
617 | | | |
618 | | | |
619 | | | |
620 | | | |
621 | + | +--------------------+ |
622 | | | | |
623 | | | | |
624 | | | | |
625 | | | | |
626 | | | | |
627 | | | | |
628 | | | | |
629 | | | | |
630 | | | | |
631 | | | | |
632 | | | | |
633 | | | | |
634 | | | | |
635 | | | | |
636 | | | | |
637 | | | | |
638 | | | | |
639 | | +--------------------+ |
640 | | |
641 | | |
642 | | |
643 | | |
644 | | |
645 | | |
646 | | |
647 | +-----------------------------------------------+
648 |
649 |
650 |
651 |
652 |
653 |
654 |
655 |
656 |
657 + ++
658 p ++
659
660 scale = (x - y) / x
661 <=> x = -y / (scale - 1)
662 */
Craig Mautner164d4bb2012-11-26 13:51:23 -0800663 final float denom = finalScale-1;
664 if (Math.abs(denom) < .0001f) {
665 return startPos;
666 }
667 return -startPos / denom;
668 }
669
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700670 private Animation createScaleUpAnimationLocked(int transit, boolean enter,
671 Rect containingFrame) {
672 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700673 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700674 final int appWidth = containingFrame.width();
675 final int appHeight = containingFrame.height();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800676 if (enter) {
677 // Entering app zooms out from the center of the initial rect.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700678 float scaleW = mTmpRect.width() / (float) appWidth;
679 float scaleH = mTmpRect.height() / (float) appHeight;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800680 Animation scale = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700681 computePivot(mTmpRect.left, scaleW),
Winson4c3fecd2016-07-13 12:29:48 -0700682 computePivot(mTmpRect.top, scaleH));
Craig Mautner321bdf52012-12-18 09:53:24 -0800683 scale.setInterpolator(mDecelerateInterpolator);
684
Craig Mautner164d4bb2012-11-26 13:51:23 -0800685 Animation alpha = new AlphaAnimation(0, 1);
Winson Chunga4ccb862014-08-22 15:26:27 -0700686 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
Craig Mautner321bdf52012-12-18 09:53:24 -0800687
688 AnimationSet set = new AnimationSet(false);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800689 set.addAnimation(scale);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800690 set.addAnimation(alpha);
691 set.setDetachWallpaper(true);
692 a = set;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800693 } else if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
694 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800695 // If we are on top of the wallpaper, we need an animation that
696 // correctly handles the wallpaper staying static behind all of
697 // the animated elements. To do this, will just have the existing
698 // element fade out.
699 a = new AlphaAnimation(1, 0);
700 a.setDetachWallpaper(true);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800701 } else {
Craig Mautner321bdf52012-12-18 09:53:24 -0800702 // For normal animations, the exiting element just holds in place.
703 a = new AlphaAnimation(1, 1);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800704 }
Craig Mautner321bdf52012-12-18 09:53:24 -0800705
706 // Pick the desired duration. If this is an inter-activity transition,
707 // it is the standard duration for that. Otherwise we use the longer
708 // task transition duration.
709 final long duration;
710 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800711 case TRANSIT_ACTIVITY_OPEN:
712 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800713 duration = mConfigShortAnimTime;
714 break;
715 default:
716 duration = DEFAULT_APP_TRANSITION_DURATION;
717 break;
718 }
719 a.setDuration(duration);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800720 a.setFillAfter(true);
Craig Mautner321bdf52012-12-18 09:53:24 -0800721 a.setInterpolator(mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800722 a.initialize(appWidth, appHeight, appWidth, appHeight);
723 return a;
724 }
725
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700726 private void getDefaultNextAppTransitionStartRect(Rect rect) {
727 if (mDefaultNextAppTransitionAnimationSpec == null ||
728 mDefaultNextAppTransitionAnimationSpec.rect == null) {
Jorim Jaggi2550f3f2017-03-14 20:15:59 +0100729 Slog.e(TAG, "Starting rect for app requested, but none available", new Throwable());
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700730 rect.setEmpty();
731 } else {
732 rect.set(mDefaultNextAppTransitionAnimationSpec.rect);
733 }
734 }
735
736 void getNextAppTransitionStartRect(int taskId, Rect rect) {
737 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800738 if (spec == null) {
739 spec = mDefaultNextAppTransitionAnimationSpec;
740 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700741 if (spec == null || spec.rect == null) {
Jorim Jaggi2550f3f2017-03-14 20:15:59 +0100742 Slog.e(TAG, "Starting rect for task: " + taskId + " requested, but not available",
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700743 new Throwable());
744 rect.setEmpty();
745 } else {
746 rect.set(spec.rect);
747 }
748 }
749
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800750 private void putDefaultNextAppTransitionCoordinates(int left, int top, int width, int height,
Winson Chungaa7fa012017-05-24 15:50:06 -0700751 GraphicBuffer buffer) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700752 mDefaultNextAppTransitionAnimationSpec = new AppTransitionAnimationSpec(-1 /* taskId */,
Winson Chungaa7fa012017-05-24 15:50:06 -0700753 buffer, new Rect(left, top, left + width, top + height));
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700754 }
755
Jorim Jaggif97ed922016-02-18 18:57:07 -0800756 /**
757 * @return the duration of the last clip reveal animation
758 */
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800759 long getLastClipRevealTransitionDuration() {
760 return mLastClipRevealTransitionDuration;
761 }
762
763 /**
Jorim Jaggif97ed922016-02-18 18:57:07 -0800764 * @return the maximum distance the app surface is traveling of the last clip reveal animation
765 */
766 int getLastClipRevealMaxTranslation() {
767 return mLastClipRevealMaxTranslation;
768 }
769
770 /**
771 * @return true if in the last app transition had a clip reveal animation, false otherwise
772 */
773 boolean hadClipRevealAnimation() {
774 return mLastHadClipReveal;
775 }
776
777 /**
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800778 * Calculates the duration for the clip reveal animation. If the clip is "cut off", meaning that
779 * the start rect is outside of the target rect, and there is a lot of movement going on.
780 *
781 * @param cutOff whether the start rect was not fully contained by the end rect
782 * @param translationX the total translation the surface moves in x direction
783 * @param translationY the total translation the surfaces moves in y direction
784 * @param displayFrame our display frame
785 *
786 * @return the duration of the clip reveal animation, in milliseconds
787 */
788 private long calculateClipRevealTransitionDuration(boolean cutOff, float translationX,
789 float translationY, Rect displayFrame) {
790 if (!cutOff) {
791 return DEFAULT_APP_TRANSITION_DURATION;
792 }
793 final float fraction = Math.max(Math.abs(translationX) / displayFrame.width(),
794 Math.abs(translationY) / displayFrame.height());
795 return (long) (DEFAULT_APP_TRANSITION_DURATION + fraction *
796 (MAX_CLIP_REVEAL_TRANSITION_DURATION - DEFAULT_APP_TRANSITION_DURATION));
797 }
798
799 private Animation createClipRevealAnimationLocked(int transit, boolean enter, Rect appFrame,
800 Rect displayFrame) {
Chet Haase10e23ab2015-02-11 15:08:38 -0800801 final Animation anim;
802 if (enter) {
Craig Mautner80b1f642015-04-22 10:59:09 -0700803 final int appWidth = appFrame.width();
804 final int appHeight = appFrame.height();
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800805
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700806 // mTmpRect will contain an area around the launcher icon that was pressed. We will
Filip Gruszczynski82861362015-10-16 14:21:09 -0700807 // clip reveal from that area in the final area of the app.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700808 getDefaultNextAppTransitionStartRect(mTmpRect);
Craig Mautner80b1f642015-04-22 10:59:09 -0700809
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700810 float t = 0f;
811 if (appHeight > 0) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800812 t = (float) mTmpRect.top / displayFrame.height();
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700813 }
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800814 int translationY = mClipRevealTranslationY + (int)(displayFrame.height() / 7f * t);
815 int translationX = 0;
816 int translationYCorrection = translationY;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700817 int centerX = mTmpRect.centerX();
818 int centerY = mTmpRect.centerY();
819 int halfWidth = mTmpRect.width() / 2;
820 int halfHeight = mTmpRect.height() / 2;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800821 int clipStartX = centerX - halfWidth - appFrame.left;
822 int clipStartY = centerY - halfHeight - appFrame.top;
823 boolean cutOff = false;
824
825 // If the starting rectangle is fully or partially outside of the target rectangle, we
826 // need to start the clipping at the edge and then achieve the rest with translation
827 // and extending the clip rect from that edge.
828 if (appFrame.top > centerY - halfHeight) {
829 translationY = (centerY - halfHeight) - appFrame.top;
830 translationYCorrection = 0;
831 clipStartY = 0;
832 cutOff = true;
833 }
834 if (appFrame.left > centerX - halfWidth) {
835 translationX = (centerX - halfWidth) - appFrame.left;
836 clipStartX = 0;
837 cutOff = true;
838 }
839 if (appFrame.right < centerX + halfWidth) {
840 translationX = (centerX + halfWidth) - appFrame.right;
841 clipStartX = appWidth - mTmpRect.width();
842 cutOff = true;
843 }
844 final long duration = calculateClipRevealTransitionDuration(cutOff, translationX,
845 translationY, displayFrame);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700846
847 // Clip third of the from size of launch icon, expand to full width/height
Chet Haase10e23ab2015-02-11 15:08:38 -0800848 Animation clipAnimLR = new ClipRectLRAnimation(
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800849 clipStartX, clipStartX + mTmpRect.width(), 0, appWidth);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700850 clipAnimLR.setInterpolator(mClipHorizontalInterpolator);
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800851 clipAnimLR.setDuration((long) (duration / 2.5f));
Filip Gruszczynski82861362015-10-16 14:21:09 -0700852
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800853 TranslateAnimation translate = new TranslateAnimation(translationX, 0, translationY, 0);
854 translate.setInterpolator(cutOff ? TOUCH_RESPONSE_INTERPOLATOR
855 : mLinearOutSlowInInterpolator);
856 translate.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800857
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800858 Animation clipAnimTB = new ClipRectTBAnimation(
859 clipStartY, clipStartY + mTmpRect.height(),
860 0, appHeight,
861 translationYCorrection, 0,
862 mLinearOutSlowInInterpolator);
863 clipAnimTB.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
864 clipAnimTB.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800865
866 // Quick fade-in from icon to app window
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800867 final long alphaDuration = duration / 4;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700868 AlphaAnimation alpha = new AlphaAnimation(0.5f, 1);
Chet Haase10e23ab2015-02-11 15:08:38 -0800869 alpha.setDuration(alphaDuration);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700870 alpha.setInterpolator(mLinearOutSlowInInterpolator);
Chet Haase10e23ab2015-02-11 15:08:38 -0800871
872 AnimationSet set = new AnimationSet(false);
873 set.addAnimation(clipAnimLR);
874 set.addAnimation(clipAnimTB);
Filip Gruszczynski82861362015-10-16 14:21:09 -0700875 set.addAnimation(translate);
Chet Haase10e23ab2015-02-11 15:08:38 -0800876 set.addAnimation(alpha);
Filip Gruszczynski9e2cf5b2015-07-31 12:20:40 -0700877 set.setZAdjustment(Animation.ZORDER_TOP);
Chet Haase10e23ab2015-02-11 15:08:38 -0800878 set.initialize(appWidth, appHeight, appWidth, appHeight);
879 anim = set;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800880 mLastHadClipReveal = true;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800881 mLastClipRevealTransitionDuration = duration;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800882
883 // If the start rect was full inside the target rect (cutOff == false), we don't need
884 // to store the translation, because it's only used if cutOff == true.
885 mLastClipRevealMaxTranslation = cutOff
886 ? Math.max(Math.abs(translationY), Math.abs(translationX)) : 0;
Chet Haase10e23ab2015-02-11 15:08:38 -0800887 } else {
888 final long duration;
889 switch (transit) {
890 case TRANSIT_ACTIVITY_OPEN:
891 case TRANSIT_ACTIVITY_CLOSE:
892 duration = mConfigShortAnimTime;
893 break;
894 default:
895 duration = DEFAULT_APP_TRANSITION_DURATION;
896 break;
897 }
898 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
899 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
900 // If we are on top of the wallpaper, we need an animation that
901 // correctly handles the wallpaper staying static behind all of
902 // the animated elements. To do this, will just have the existing
903 // element fade out.
904 anim = new AlphaAnimation(1, 0);
905 anim.setDetachWallpaper(true);
906 } else {
907 // For normal animations, the exiting element just holds in place.
908 anim = new AlphaAnimation(1, 1);
909 }
910 anim.setInterpolator(mDecelerateInterpolator);
911 anim.setDuration(duration);
912 anim.setFillAfter(true);
913 }
914 return anim;
915 }
916
Winson Chung399f6202014-03-19 10:47:20 -0700917 /**
918 * Prepares the specified animation with a standard duration, interpolator, etc.
919 */
Winson Chung5393dff2014-05-08 14:25:43 -0700920 Animation prepareThumbnailAnimationWithDuration(Animation a, int appWidth, int appHeight,
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100921 long duration, Interpolator interpolator) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700922 if (duration > 0) {
923 a.setDuration(duration);
924 }
Winson Chung5393dff2014-05-08 14:25:43 -0700925 a.setFillAfter(true);
Jorim Jaggic69bd222016-03-15 14:38:37 +0100926 if (interpolator != null) {
927 a.setInterpolator(interpolator);
928 }
Winson Chung5393dff2014-05-08 14:25:43 -0700929 a.initialize(appWidth, appHeight, appWidth, appHeight);
930 return a;
931 }
932
933 /**
934 * Prepares the specified animation with a standard duration, interpolator, etc.
935 */
Winson Chung399f6202014-03-19 10:47:20 -0700936 Animation prepareThumbnailAnimation(Animation a, int appWidth, int appHeight, int transit) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800937 // Pick the desired duration. If this is an inter-activity transition,
938 // it is the standard duration for that. Otherwise we use the longer
939 // task transition duration.
Winson Chung5393dff2014-05-08 14:25:43 -0700940 final int duration;
Craig Mautner321bdf52012-12-18 09:53:24 -0800941 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800942 case TRANSIT_ACTIVITY_OPEN:
943 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800944 duration = mConfigShortAnimTime;
945 break;
946 default:
947 duration = DEFAULT_APP_TRANSITION_DURATION;
948 break;
949 }
Winson Chung5393dff2014-05-08 14:25:43 -0700950 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, duration,
951 mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800952 }
953
Winson Chung399f6202014-03-19 10:47:20 -0700954 /**
955 * Return the current thumbnail transition state.
956 */
957 int getThumbnailTransitionState(boolean enter) {
958 if (enter) {
959 if (mNextAppTransitionScaleUp) {
960 return THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
961 } else {
962 return THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN;
963 }
964 } else {
965 if (mNextAppTransitionScaleUp) {
966 return THUMBNAIL_TRANSITION_EXIT_SCALE_UP;
967 } else {
968 return THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN;
969 }
970 }
971 }
972
973 /**
974 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700975 * when a thumbnail is specified with the pending animation override.
Winson Chung399f6202014-03-19 10:47:20 -0700976 */
Jorim Jaggide63d442016-03-14 14:56:56 +0100977 Animation createThumbnailAspectScaleAnimationLocked(Rect appRect, @Nullable Rect contentInsets,
Winson Chungaa7fa012017-05-24 15:50:06 -0700978 GraphicBuffer thumbnailHeader, final int taskId, int uiMode, int orientation) {
Winson Chung399f6202014-03-19 10:47:20 -0700979 Animation a;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700980 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chung399f6202014-03-19 10:47:20 -0700981 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700982 final int thumbHeightI = thumbnailHeader.getHeight();
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700983 final int appWidth = appRect.width();
Winson Chung399f6202014-03-19 10:47:20 -0700984
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700985 float scaleW = appWidth / thumbWidth;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700986 getNextAppTransitionStartRect(taskId, mTmpRect);
Jorim Jaggi09072002016-03-25 16:48:42 -0700987 final float fromX;
Manu Cornet57b61492017-01-24 18:19:05 +0900988 float fromY;
Jorim Jaggi09072002016-03-25 16:48:42 -0700989 final float toX;
Manu Cornet57b61492017-01-24 18:19:05 +0900990 float toY;
Jorim Jaggi09072002016-03-25 16:48:42 -0700991 final float pivotX;
992 final float pivotY;
Manu Cornetd7376802017-01-13 13:44:07 -0800993 if (shouldScaleDownThumbnailTransition(uiMode, orientation)) {
Jorim Jaggi09072002016-03-25 16:48:42 -0700994 fromX = mTmpRect.left;
995 fromY = mTmpRect.top;
996
997 // For the curved translate animation to work, the pivot points needs to be at the
998 // same absolute position as the one from the real surface.
999 toX = mTmpRect.width() / 2 * (scaleW - 1f) + appRect.left;
1000 toY = appRect.height() / 2 * (1 - 1 / scaleW) + appRect.top;
1001 pivotX = mTmpRect.width() / 2;
1002 pivotY = appRect.height() / 2 / scaleW;
Manu Cornet57b61492017-01-24 18:19:05 +09001003 if (mGridLayoutRecentsEnabled) {
1004 // In the grid layout, the header is displayed above the thumbnail instead of
1005 // overlapping it.
1006 fromY -= thumbHeightI;
1007 toY -= thumbHeightI * scaleW;
1008 }
Jorim Jaggi09072002016-03-25 16:48:42 -07001009 } else {
1010 pivotX = 0;
1011 pivotY = 0;
1012 fromX = mTmpRect.left;
1013 fromY = mTmpRect.top;
1014 toX = appRect.left;
1015 toY = appRect.top;
1016 }
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001017 final long duration = getAspectScaleDuration();
1018 final Interpolator interpolator = getAspectScaleInterpolator();
Winson Chung399f6202014-03-19 10:47:20 -07001019 if (mNextAppTransitionScaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001020 // Animation up from the thumbnail to the full screen
Jorim Jaggi8448f332016-03-14 17:50:37 +01001021 Animation scale = new ScaleAnimation(1f, scaleW, 1f, scaleW, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001022 scale.setInterpolator(interpolator);
1023 scale.setDuration(duration);
Jorim Jaggic6c89a82016-01-28 17:48:21 -08001024 Animation alpha = new AlphaAnimation(1f, 0f);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001025 alpha.setInterpolator(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
1026 ? THUMBNAIL_DOCK_INTERPOLATOR : mThumbnailFadeOutInterpolator);
1027 alpha.setDuration(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
1028 ? duration / 2
1029 : duration);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001030 Animation translate = createCurvedMotion(fromX, toX, fromY, toY);
1031 translate.setInterpolator(interpolator);
1032 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -07001033
Jorim Jaggide63d442016-03-14 14:56:56 +01001034 mTmpFromClipRect.set(0, 0, thumbWidthI, thumbHeightI);
1035 mTmpToClipRect.set(appRect);
1036
1037 // Containing frame is in screen space, but we need the clip rect in the
1038 // app space.
1039 mTmpToClipRect.offsetTo(0, 0);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001040 mTmpToClipRect.right = (int) (mTmpToClipRect.right / scaleW);
1041 mTmpToClipRect.bottom = (int) (mTmpToClipRect.bottom / scaleW);
Jorim Jaggide63d442016-03-14 14:56:56 +01001042
1043 if (contentInsets != null) {
Jorim Jaggi8448f332016-03-14 17:50:37 +01001044 mTmpToClipRect.inset((int) (-contentInsets.left * scaleW),
1045 (int) (-contentInsets.top * scaleW),
1046 (int) (-contentInsets.right * scaleW),
1047 (int) (-contentInsets.bottom * scaleW));
Jorim Jaggide63d442016-03-14 14:56:56 +01001048 }
1049
1050 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001051 clipAnim.setInterpolator(interpolator);
1052 clipAnim.setDuration(duration);
Jorim Jaggide63d442016-03-14 14:56:56 +01001053
Winson Chung399f6202014-03-19 10:47:20 -07001054 // This AnimationSet uses the Interpolators assigned above.
1055 AnimationSet set = new AnimationSet(false);
1056 set.addAnimation(scale);
Manu Cornet57b61492017-01-24 18:19:05 +09001057 if (!mGridLayoutRecentsEnabled) {
1058 // In the grid layout, the header should be shown for the whole animation.
1059 set.addAnimation(alpha);
1060 }
Winson Chunga4ccb862014-08-22 15:26:27 -07001061 set.addAnimation(translate);
Jorim Jaggide63d442016-03-14 14:56:56 +01001062 set.addAnimation(clipAnim);
Winson Chung399f6202014-03-19 10:47:20 -07001063 a = set;
1064 } else {
Winson Chunga4ccb862014-08-22 15:26:27 -07001065 // Animation down from the full screen to the thumbnail
Jorim Jaggi8448f332016-03-14 17:50:37 +01001066 Animation scale = new ScaleAnimation(scaleW, 1f, scaleW, 1f, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001067 scale.setInterpolator(interpolator);
1068 scale.setDuration(duration);
Winson Chunga4ccb862014-08-22 15:26:27 -07001069 Animation alpha = new AlphaAnimation(0f, 1f);
1070 alpha.setInterpolator(mThumbnailFadeInInterpolator);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001071 alpha.setDuration(duration);
1072 Animation translate = createCurvedMotion(toX, fromX, toY, fromY);
1073 translate.setInterpolator(interpolator);
1074 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -07001075
Winson Chunga4ccb862014-08-22 15:26:27 -07001076 // This AnimationSet uses the Interpolators assigned above.
1077 AnimationSet set = new AnimationSet(false);
1078 set.addAnimation(scale);
Manu Cornet57b61492017-01-24 18:19:05 +09001079 if (!mGridLayoutRecentsEnabled) {
1080 // In the grid layout, the header should be shown for the whole animation.
1081 set.addAnimation(alpha);
1082 }
Winson Chunga4ccb862014-08-22 15:26:27 -07001083 set.addAnimation(translate);
1084 a = set;
1085
1086 }
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -07001087 return prepareThumbnailAnimationWithDuration(a, appWidth, appRect.height(), 0,
Jorim Jaggic69bd222016-03-15 14:38:37 +01001088 null);
Winson Chung399f6202014-03-19 10:47:20 -07001089 }
1090
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001091 private Animation createCurvedMotion(float fromX, float toX, float fromY, float toY) {
1092
1093 // Almost no x-change - use linear animation
Jorim Jaggic69bd222016-03-15 14:38:37 +01001094 if (Math.abs(toX - fromX) < 1f || mNextAppTransition != TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001095 return new TranslateAnimation(fromX, toX, fromY, toY);
1096 } else {
1097 final Path path = createCurvedPath(fromX, toX, fromY, toY);
1098 return new CurvedTranslateAnimation(path);
1099 }
1100 }
1101
1102 private Path createCurvedPath(float fromX, float toX, float fromY, float toY) {
1103 final Path path = new Path();
1104 path.moveTo(fromX, fromY);
Jorim Jaggi1f458fb2016-03-25 17:36:37 -07001105
1106 if (fromY > toY) {
1107 // If the object needs to go up, move it in horizontal direction first, then vertical.
1108 path.cubicTo(fromX, fromY, toX, 0.9f * fromY + 0.1f * toY, toX, toY);
1109 } else {
1110 // If the object needs to go down, move it in vertical direction first, then horizontal.
1111 path.cubicTo(fromX, fromY, fromX, 0.1f * fromY + 0.9f * toY, toX, toY);
1112 }
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001113 return path;
1114 }
1115
1116 private long getAspectScaleDuration() {
1117 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggic69bd222016-03-15 14:38:37 +01001118 return (long) (THUMBNAIL_APP_TRANSITION_DURATION * 1.35f);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001119 } else {
1120 return THUMBNAIL_APP_TRANSITION_DURATION;
1121 }
1122 }
1123
1124 private Interpolator getAspectScaleInterpolator() {
1125 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
1126 return mFastOutSlowInInterpolator;
1127 } else {
1128 return TOUCH_RESPONSE_INTERPOLATOR;
1129 }
1130 }
1131
Winson Chung399f6202014-03-19 10:47:20 -07001132 /**
1133 * This alternate animation is created when we are doing a thumbnail transition, for the
1134 * activity that is leaving, and the activity that is entering.
1135 */
Winson Chunga4ccb862014-08-22 15:26:27 -07001136 Animation createAspectScaledThumbnailEnterExitAnimationLocked(int thumbTransitState,
Winsonb2024762016-04-05 17:32:30 -07001137 int uiMode, int orientation, int transit, Rect containingFrame, Rect contentInsets,
Matthew Ng43db6d22017-06-27 15:29:39 -07001138 @Nullable Rect surfaceInsets, @Nullable Rect stableInsets, boolean freeform,
1139 int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -07001140 Animation a;
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001141 final int appWidth = containingFrame.width();
1142 final int appHeight = containingFrame.height();
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001143 getDefaultNextAppTransitionStartRect(mTmpRect);
1144 final int thumbWidthI = mTmpRect.width();
Winson Chung399f6202014-03-19 10:47:20 -07001145 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001146 final int thumbHeightI = mTmpRect.height();
Winson Chung399f6202014-03-19 10:47:20 -07001147 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
Winsoncbb625b2016-07-06 15:24:15 -07001148 final int thumbStartX = mTmpRect.left - containingFrame.left - contentInsets.left;
Winson21700932016-03-24 17:26:23 -07001149 final int thumbStartY = mTmpRect.top - containingFrame.top;
Winson Chung399f6202014-03-19 10:47:20 -07001150
1151 switch (thumbTransitState) {
Jorim Jaggi8448f332016-03-14 17:50:37 +01001152 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP:
1153 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1154 final boolean scaleUp = thumbTransitState == THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
1155 if (freeform && scaleUp) {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001156 a = createAspectScaledThumbnailEnterFreeformAnimationLocked(
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001157 containingFrame, surfaceInsets, taskId);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001158 } else if (freeform) {
1159 a = createAspectScaledThumbnailExitFreeformAnimationLocked(
1160 containingFrame, surfaceInsets, taskId);
Winson Chung2820c452014-04-15 15:34:44 -07001161 } else {
Winson21700932016-03-24 17:26:23 -07001162 AnimationSet set = new AnimationSet(true);
1163
1164 // In portrait, we scale to fit the width
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001165 mTmpFromClipRect.set(containingFrame);
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001166 mTmpToClipRect.set(containingFrame);
Jorim Jaggic6c89a82016-01-28 17:48:21 -08001167
1168 // Containing frame is in screen space, but we need the clip rect in the
1169 // app space.
1170 mTmpFromClipRect.offsetTo(0, 0);
1171 mTmpToClipRect.offsetTo(0, 0);
1172
1173 // Exclude insets region from the source clip.
1174 mTmpFromClipRect.inset(contentInsets);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001175 mNextAppTransitionInsets.set(contentInsets);
1176
Manu Cornetd7376802017-01-13 13:44:07 -08001177 if (shouldScaleDownThumbnailTransition(uiMode, orientation)) {
Jorim Jaggic69bd222016-03-15 14:38:37 +01001178 // We scale the width and clip to the top/left square
1179 float scale = thumbWidth /
1180 (appWidth - contentInsets.left - contentInsets.right);
Manu Cornetb68b7652017-01-23 19:37:53 +09001181 if (!mGridLayoutRecentsEnabled) {
1182 int unscaledThumbHeight = (int) (thumbHeight / scale);
1183 mTmpFromClipRect.bottom = mTmpFromClipRect.top + unscaledThumbHeight;
1184 }
Jorim Jaggic69bd222016-03-15 14:38:37 +01001185
1186 mNextAppTransitionInsets.set(contentInsets);
1187
Jorim Jaggi8448f332016-03-14 17:50:37 +01001188 Animation scaleAnim = new ScaleAnimation(
1189 scaleUp ? scale : 1, scaleUp ? 1 : scale,
1190 scaleUp ? scale : 1, scaleUp ? 1 : scale,
Jorim Jaggic69bd222016-03-15 14:38:37 +01001191 containingFrame.width() / 2f,
1192 containingFrame.height() / 2f + contentInsets.top);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001193 final float targetX = (mTmpRect.left - containingFrame.left);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001194 final float x = containingFrame.width() / 2f
1195 - containingFrame.width() / 2f * scale;
Jorim Jaggi8448f332016-03-14 17:50:37 +01001196 final float targetY = (mTmpRect.top - containingFrame.top);
Matthew Ng43db6d22017-06-27 15:29:39 -07001197 float y = containingFrame.height() / 2f
Jorim Jaggic69bd222016-03-15 14:38:37 +01001198 - containingFrame.height() / 2f * scale;
Matthew Ng43db6d22017-06-27 15:29:39 -07001199
1200 // During transition may require clipping offset from any top stable insets
1201 // such as the statusbar height when statusbar is hidden
1202 if (mLowRamRecentsEnabled && contentInsets.top == 0 && scaleUp) {
1203 mTmpFromClipRect.top += stableInsets.top;
1204 y += stableInsets.top;
1205 }
Jorim Jaggi8448f332016-03-14 17:50:37 +01001206 final float startX = targetX - x;
1207 final float startY = targetY - y;
1208 Animation clipAnim = scaleUp
1209 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1210 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1211 Animation translateAnim = scaleUp
Jorim Jaggic69bd222016-03-15 14:38:37 +01001212 ? createCurvedMotion(startX, 0, startY - contentInsets.top, 0)
1213 : createCurvedMotion(0, startX, 0, startY - contentInsets.top);
1214
Winson21700932016-03-24 17:26:23 -07001215 set.addAnimation(clipAnim);
1216 set.addAnimation(scaleAnim);
1217 set.addAnimation(translateAnim);
1218
1219 } else {
1220 // In landscape, we don't scale at all and only crop
1221 mTmpFromClipRect.bottom = mTmpFromClipRect.top + thumbHeightI;
1222 mTmpFromClipRect.right = mTmpFromClipRect.left + thumbWidthI;
1223
Jorim Jaggi8448f332016-03-14 17:50:37 +01001224 Animation clipAnim = scaleUp
1225 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1226 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1227 Animation translateAnim = scaleUp
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001228 ? createCurvedMotion(thumbStartX, 0,
1229 thumbStartY - contentInsets.top, 0)
1230 : createCurvedMotion(0, thumbStartX, 0,
1231 thumbStartY - contentInsets.top);
Winson21700932016-03-24 17:26:23 -07001232
1233 set.addAnimation(clipAnim);
1234 set.addAnimation(translateAnim);
1235 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001236 a = set;
Winson21700932016-03-24 17:26:23 -07001237 a.setZAdjustment(Animation.ZORDER_TOP);
Winson Chung2820c452014-04-15 15:34:44 -07001238 }
Winson Chung399f6202014-03-19 10:47:20 -07001239 break;
1240 }
1241 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001242 // Previous app window during the scale up
Winson Chung399f6202014-03-19 10:47:20 -07001243 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001244 // Fade out the source activity if we are animating to a wallpaper
Winson Chung399f6202014-03-19 10:47:20 -07001245 // activity.
1246 a = new AlphaAnimation(1, 0);
1247 } else {
Winson Chung399f6202014-03-19 10:47:20 -07001248 a = new AlphaAnimation(1, 1);
1249 }
1250 break;
1251 }
1252 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001253 // Target app window during the scale down
1254 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1255 // Fade in the destination activity if we are animating from a wallpaper
1256 // activity.
1257 a = new AlphaAnimation(0, 1);
1258 } else {
1259 a = new AlphaAnimation(1, 1);
1260 }
Winson Chung399f6202014-03-19 10:47:20 -07001261 break;
1262 }
Winson Chung399f6202014-03-19 10:47:20 -07001263 default:
1264 throw new RuntimeException("Invalid thumbnail transition state");
1265 }
1266
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001267 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight,
1268 getAspectScaleDuration(), getAspectScaleInterpolator());
Winson Chung399f6202014-03-19 10:47:20 -07001269 }
1270
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001271 private Animation createAspectScaledThumbnailEnterFreeformAnimationLocked(Rect frame,
1272 @Nullable Rect surfaceInsets, int taskId) {
1273 getNextAppTransitionStartRect(taskId, mTmpRect);
1274 return createAspectScaledThumbnailFreeformAnimationLocked(mTmpRect, frame, surfaceInsets,
1275 true);
1276 }
1277
1278 private Animation createAspectScaledThumbnailExitFreeformAnimationLocked(Rect frame,
1279 @Nullable Rect surfaceInsets, int taskId) {
1280 getNextAppTransitionStartRect(taskId, mTmpRect);
1281 return createAspectScaledThumbnailFreeformAnimationLocked(frame, mTmpRect, surfaceInsets,
1282 false);
1283 }
1284
1285 private AnimationSet createAspectScaledThumbnailFreeformAnimationLocked(Rect sourceFrame,
1286 Rect destFrame, @Nullable Rect surfaceInsets, boolean enter) {
1287 final float sourceWidth = sourceFrame.width();
1288 final float sourceHeight = sourceFrame.height();
1289 final float destWidth = destFrame.width();
1290 final float destHeight = destFrame.height();
1291 final float scaleH = enter ? sourceWidth / destWidth : destWidth / sourceWidth;
1292 final float scaleV = enter ? sourceHeight / destHeight : destHeight / sourceHeight;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001293 AnimationSet set = new AnimationSet(true);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001294 final int surfaceInsetsH = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001295 ? 0 : surfaceInsets.left + surfaceInsets.right;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001296 final int surfaceInsetsV = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001297 ? 0 : surfaceInsets.top + surfaceInsets.bottom;
1298 // We want the scaling to happen from the center of the surface. In order to achieve that,
1299 // we need to account for surface insets that will be used to enlarge the surface.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001300 final float scaleHCenter = ((enter ? destWidth : sourceWidth) + surfaceInsetsH) / 2;
1301 final float scaleVCenter = ((enter ? destHeight : sourceHeight) + surfaceInsetsV) / 2;
1302 final ScaleAnimation scale = enter ?
1303 new ScaleAnimation(scaleH, 1, scaleV, 1, scaleHCenter, scaleVCenter)
1304 : new ScaleAnimation(1, scaleH, 1, scaleV, scaleHCenter, scaleVCenter);
1305 final int sourceHCenter = sourceFrame.left + sourceFrame.width() / 2;
1306 final int sourceVCenter = sourceFrame.top + sourceFrame.height() / 2;
1307 final int destHCenter = destFrame.left + destFrame.width() / 2;
1308 final int destVCenter = destFrame.top + destFrame.height() / 2;
1309 final int fromX = enter ? sourceHCenter - destHCenter : destHCenter - sourceHCenter;
1310 final int fromY = enter ? sourceVCenter - destVCenter : destVCenter - sourceVCenter;
1311 final TranslateAnimation translation = enter ? new TranslateAnimation(fromX, 0, fromY, 0)
1312 : new TranslateAnimation(0, fromX, 0, fromY);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001313 set.addAnimation(scale);
1314 set.addAnimation(translation);
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001315
1316 final IRemoteCallback callback = mAnimationFinishedCallback;
1317 if (callback != null) {
1318 set.setAnimationListener(new Animation.AnimationListener() {
1319 @Override
1320 public void onAnimationStart(Animation animation) { }
1321
1322 @Override
1323 public void onAnimationEnd(Animation animation) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001324 mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK, callback).sendToTarget();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001325 }
1326
1327 @Override
1328 public void onAnimationRepeat(Animation animation) { }
1329 });
1330 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001331 return set;
1332 }
1333
Winson Chung399f6202014-03-19 10:47:20 -07001334 /**
Winson Chunga4ccb862014-08-22 15:26:27 -07001335 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001336 * when a thumbnail is specified with the pending animation override.
Winson Chunga4ccb862014-08-22 15:26:27 -07001337 */
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001338 Animation createThumbnailScaleAnimationLocked(int appWidth, int appHeight, int transit,
Winson Chungaa7fa012017-05-24 15:50:06 -07001339 GraphicBuffer thumbnailHeader) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001340 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001341 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001342 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chunga4ccb862014-08-22 15:26:27 -07001343 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001344 final int thumbHeightI = thumbnailHeader.getHeight();
Winson Chunga4ccb862014-08-22 15:26:27 -07001345 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1346
1347 if (mNextAppTransitionScaleUp) {
1348 // Animation for the thumbnail zooming from its initial size to the full screen
1349 float scaleW = appWidth / thumbWidth;
1350 float scaleH = appHeight / thumbHeight;
1351 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001352 computePivot(mTmpRect.left, 1 / scaleW),
1353 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001354 scale.setInterpolator(mDecelerateInterpolator);
1355
1356 Animation alpha = new AlphaAnimation(1, 0);
1357 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
1358
1359 // This AnimationSet uses the Interpolators assigned above.
1360 AnimationSet set = new AnimationSet(false);
1361 set.addAnimation(scale);
1362 set.addAnimation(alpha);
1363 a = set;
1364 } else {
1365 // Animation for the thumbnail zooming down from the full screen to its final size
1366 float scaleW = appWidth / thumbWidth;
1367 float scaleH = appHeight / thumbHeight;
1368 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001369 computePivot(mTmpRect.left, 1 / scaleW),
1370 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001371 }
1372
1373 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1374 }
1375
1376 /**
Winson Chung399f6202014-03-19 10:47:20 -07001377 * This animation is created when we are doing a thumbnail transition, for the activity that is
1378 * leaving, and the activity that is entering.
1379 */
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001380 Animation createThumbnailEnterExitAnimationLocked(int thumbTransitState, Rect containingFrame,
1381 int transit, int taskId) {
1382 final int appWidth = containingFrame.width();
1383 final int appHeight = containingFrame.height();
Winson Chungaa7fa012017-05-24 15:50:06 -07001384 final GraphicBuffer thumbnailHeader = getAppTransitionThumbnailHeader(taskId);
Winson Chung399f6202014-03-19 10:47:20 -07001385 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001386 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001387 final int thumbWidthI = thumbnailHeader != null ? thumbnailHeader.getWidth() : appWidth;
Winson Chung399f6202014-03-19 10:47:20 -07001388 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001389 final int thumbHeightI = thumbnailHeader != null ? thumbnailHeader.getHeight() : appHeight;
Winson Chung399f6202014-03-19 10:47:20 -07001390 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1391
1392 switch (thumbTransitState) {
1393 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
1394 // Entering app scales up with the thumbnail
1395 float scaleW = thumbWidth / appWidth;
1396 float scaleH = thumbHeight / appHeight;
1397 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001398 computePivot(mTmpRect.left, scaleW),
1399 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001400 break;
1401 }
1402 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
1403 // Exiting app while the thumbnail is scaling up should fade or stay in place
1404 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1405 // Fade out while bringing up selected activity. This keeps the
1406 // current activity from showing through a launching wallpaper
1407 // activity.
1408 a = new AlphaAnimation(1, 0);
1409 } else {
1410 // noop animation
1411 a = new AlphaAnimation(1, 1);
1412 }
1413 break;
1414 }
1415 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
1416 // Entering the other app, it should just be visible while we scale the thumbnail
1417 // down above it
1418 a = new AlphaAnimation(1, 1);
1419 break;
1420 }
1421 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1422 // Exiting the current app, the app should scale down with the thumbnail
1423 float scaleW = thumbWidth / appWidth;
1424 float scaleH = thumbHeight / appHeight;
1425 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001426 computePivot(mTmpRect.left, scaleW),
1427 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001428
1429 Animation alpha = new AlphaAnimation(1, 0);
1430
1431 AnimationSet set = new AnimationSet(true);
1432 set.addAnimation(scale);
1433 set.addAnimation(alpha);
1434 set.setZAdjustment(Animation.ZORDER_TOP);
1435 a = set;
1436 break;
1437 }
1438 default:
1439 throw new RuntimeException("Invalid thumbnail transition state");
1440 }
1441
1442 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1443 }
1444
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001445 private Animation createRelaunchAnimation(Rect containingFrame, Rect contentInsets) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001446 getDefaultNextAppTransitionStartRect(mTmpFromClipRect);
1447 final int left = mTmpFromClipRect.left;
1448 final int top = mTmpFromClipRect.top;
1449 mTmpFromClipRect.offset(-left, -top);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001450 // TODO: Isn't that strange that we ignore exact position of the containingFrame?
1451 mTmpToClipRect.set(0, 0, containingFrame.width(), containingFrame.height());
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001452 AnimationSet set = new AnimationSet(true);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001453 float fromWidth = mTmpFromClipRect.width();
1454 float toWidth = mTmpToClipRect.width();
1455 float fromHeight = mTmpFromClipRect.height();
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001456 // While the window might span the whole display, the actual content will be cropped to the
1457 // system decoration frame, for example when the window is docked. We need to take into
1458 // account the visible height when constructing the animation.
1459 float toHeight = mTmpToClipRect.height() - contentInsets.top - contentInsets.bottom;
1460 int translateAdjustment = 0;
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001461 if (fromWidth <= toWidth && fromHeight <= toHeight) {
1462 // The final window is larger in both dimensions than current window (e.g. we are
1463 // maximizing), so we can simply unclip the new window and there will be no disappearing
1464 // frame.
1465 set.addAnimation(new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect));
1466 } else {
1467 // The disappearing window has one larger dimension. We need to apply scaling, so the
1468 // first frame of the entry animation matches the old window.
1469 set.addAnimation(new ScaleAnimation(fromWidth / toWidth, 1, fromHeight / toHeight, 1));
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001470 // We might not be going exactly full screen, but instead be aligned under the status
1471 // bar using cropping. We still need to account for the cropped part, which will also
1472 // be scaled.
1473 translateAdjustment = (int) (contentInsets.top * fromHeight / toHeight);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001474 }
1475
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001476 // We animate the translation from the old position of the removed window, to the new
1477 // position of the added window. The latter might not be full screen, for example docked for
1478 // docked windows.
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001479 TranslateAnimation translate = new TranslateAnimation(left - containingFrame.left,
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001480 0, top - containingFrame.top - translateAdjustment, 0);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001481 set.addAnimation(translate);
1482 set.setDuration(DEFAULT_APP_TRANSITION_DURATION);
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07001483 set.setZAdjustment(Animation.ZORDER_TOP);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001484 return set;
1485 }
1486
Jorim Jaggic554b772015-06-04 16:07:57 -07001487 /**
1488 * @return true if and only if the first frame of the transition can be skipped, i.e. the first
1489 * frame of the transition doesn't change the visuals on screen, so we can start
1490 * directly with the second one
1491 */
1492 boolean canSkipFirstFrame() {
1493 return mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM
1494 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE
Jorim Jaggife762342016-10-13 14:33:27 +02001495 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CLIP_REVEAL
1496 && mNextAppTransition != TRANSIT_KEYGUARD_GOING_AWAY;
Jorim Jaggic554b772015-06-04 16:07:57 -07001497 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001498
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001499 /**
1500 *
1501 * @param frame These are the bounds of the window when it finishes the animation. This is where
1502 * the animation must usually finish in entrance animation, as the next frame will
1503 * display the window at these coordinates. In case of exit animation, this is
1504 * where the animation must start, as the frame before the animation is displaying
1505 * the window at these bounds.
1506 * @param insets Knowing where the window will be positioned is not enough. Some parts of the
1507 * window might be obscured, usually by the system windows (status bar and
1508 * navigation bar) and we use content insets to convey that information. This
1509 * usually affects the animation aspects vertically, as the system decoration is
1510 * at the top and the bottom. For example when we animate from full screen to
1511 * recents, we want to exclude the covered parts, because they won't match the
1512 * thumbnail after the last frame is executed.
1513 * @param surfaceInsets In rare situation the surface is larger than the content and we need to
1514 * know about this to make the animation frames match. We currently use
1515 * this for freeform windows, which have larger surfaces to display
1516 * shadows. When we animate them from recents, we want to match the content
1517 * to the recents thumbnail and hence need to account for the surface being
1518 * bigger.
1519 */
Winsonb2024762016-04-05 17:32:30 -07001520 Animation loadAnimation(WindowManager.LayoutParams lp, int transit, boolean enter, int uiMode,
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001521 int orientation, Rect frame, Rect displayFrame, Rect insets,
Matthew Ng43db6d22017-06-27 15:29:39 -07001522 @Nullable Rect surfaceInsets, @Nullable Rect stableInsets, boolean isVoiceInteraction,
1523 boolean freeform, int taskId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001524 Animation a;
Jorim Jaggife762342016-10-13 14:33:27 +02001525 if (isKeyguardGoingAwayTransit(transit) && enter) {
1526 a = loadKeyguardExitAnimation(transit);
1527 } else if (transit == TRANSIT_KEYGUARD_OCCLUDE) {
1528 a = null;
1529 } else if (transit == TRANSIT_KEYGUARD_UNOCCLUDE && !enter) {
1530 a = loadAnimationRes(lp, com.android.internal.R.anim.wallpaper_open_exit);
1531 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_OPEN
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001532 || transit == TRANSIT_TASK_OPEN
1533 || transit == TRANSIT_TASK_TO_FRONT)) {
1534 a = loadAnimationRes(lp, enter
1535 ? com.android.internal.R.anim.voice_activity_open_enter
1536 : com.android.internal.R.anim.voice_activity_open_exit);
1537 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1538 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001539 + " anim=" + a + " transit=" + appTransitionToString(transit)
1540 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001541 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_CLOSE
1542 || transit == TRANSIT_TASK_CLOSE
1543 || transit == TRANSIT_TASK_TO_BACK)) {
1544 a = loadAnimationRes(lp, enter
1545 ? com.android.internal.R.anim.voice_activity_close_enter
1546 : com.android.internal.R.anim.voice_activity_close_exit);
1547 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1548 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001549 + " anim=" + a + " transit=" + appTransitionToString(transit)
1550 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001551 } else if (transit == TRANSIT_ACTIVITY_RELAUNCH) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001552 a = createRelaunchAnimation(frame, insets);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001553 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1554 "applyAnimation:"
1555 + " anim=" + a + " nextAppTransition=" + mNextAppTransition
1556 + " transit=" + appTransitionToString(transit)
1557 + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001558 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM) {
1559 a = loadAnimationRes(mNextAppTransitionPackage, enter ?
Craig Mautner164d4bb2012-11-26 13:51:23 -08001560 mNextAppTransitionEnter : mNextAppTransitionExit);
1561 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1562 "applyAnimation:"
1563 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001564 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001565 + " Callers=" + Debug.getCallers(3));
Winson Chung044d5292014-11-06 11:05:19 -08001566 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE) {
1567 a = loadAnimationRes(mNextAppTransitionPackage, mNextAppTransitionInPlace);
1568 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1569 "applyAnimation:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001570 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM_IN_PLACE"
1571 + " transit=" + appTransitionToString(transit)
1572 + " Callers=" + Debug.getCallers(3));
Chet Haase10e23ab2015-02-11 15:08:38 -08001573 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001574 a = createClipRevealAnimationLocked(transit, enter, frame, displayFrame);
Chet Haase10e23ab2015-02-11 15:08:38 -08001575 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1576 "applyAnimation:"
1577 + " anim=" + a + " nextAppTransition=ANIM_CLIP_REVEAL"
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001578 + " transit=" + appTransitionToString(transit)
Chet Haase10e23ab2015-02-11 15:08:38 -08001579 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001580 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_SCALE_UP) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001581 a = createScaleUpAnimationLocked(transit, enter, frame);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001582 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1583 "applyAnimation:"
1584 + " anim=" + a + " nextAppTransition=ANIM_SCALE_UP"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001585 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001586 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001587 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
1588 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001589 mNextAppTransitionScaleUp =
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001590 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP);
Winson Chunga4ccb862014-08-22 15:26:27 -07001591 a = createThumbnailEnterExitAnimationLocked(getThumbnailTransitionState(enter),
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001592 frame, transit, taskId);
Winson Chunga4ccb862014-08-22 15:26:27 -07001593 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1594 String animName = mNextAppTransitionScaleUp ?
1595 "ANIM_THUMBNAIL_SCALE_UP" : "ANIM_THUMBNAIL_SCALE_DOWN";
1596 Slog.v(TAG, "applyAnimation:"
1597 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001598 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Winson Chunga4ccb862014-08-22 15:26:27 -07001599 + " Callers=" + Debug.getCallers(3));
1600 }
1601 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
1602 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN) {
1603 mNextAppTransitionScaleUp =
1604 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP);
1605 a = createAspectScaledThumbnailEnterExitAnimationLocked(
Winsonb2024762016-04-05 17:32:30 -07001606 getThumbnailTransitionState(enter), uiMode, orientation, transit, frame,
Matthew Ng43db6d22017-06-27 15:29:39 -07001607 insets, surfaceInsets, stableInsets, freeform, taskId);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001608 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1609 String animName = mNextAppTransitionScaleUp ?
Winson Chunga4ccb862014-08-22 15:26:27 -07001610 "ANIM_THUMBNAIL_ASPECT_SCALE_UP" : "ANIM_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner164d4bb2012-11-26 13:51:23 -08001611 Slog.v(TAG, "applyAnimation:"
1612 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001613 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001614 + " Callers=" + Debug.getCallers(3));
1615 }
Tony Mak089c35e2017-12-18 20:34:14 +00001616 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS
1617 && (transit == TRANSIT_ACTIVITY_OPEN
1618 || transit == TRANSIT_TASK_OPEN
1619 || transit == TRANSIT_TASK_TO_FRONT)) {
1620 a = loadAnimationRes("android", enter
1621 ? com.android.internal.R.anim.activity_open_enter
1622 : com.android.internal.R.anim.activity_open_exit);
1623 Slog.v(TAG,
1624 "applyAnimation NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS:"
1625 + " anim=" + a + " transit=" + appTransitionToString(transit)
1626 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Craig Mautner164d4bb2012-11-26 13:51:23 -08001627 } else {
1628 int animAttr = 0;
1629 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001630 case TRANSIT_ACTIVITY_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001631 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001632 ? WindowAnimation_activityOpenEnterAnimation
1633 : WindowAnimation_activityOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001634 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001635 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001636 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001637 ? WindowAnimation_activityCloseEnterAnimation
1638 : WindowAnimation_activityCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001639 break;
Jorim Jaggi192086e2016-03-11 17:17:03 +01001640 case TRANSIT_DOCK_TASK_FROM_RECENTS:
Craig Mautner4b71aa12012-12-27 17:20:01 -08001641 case TRANSIT_TASK_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001642 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001643 ? WindowAnimation_taskOpenEnterAnimation
1644 : WindowAnimation_taskOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001645 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001646 case TRANSIT_TASK_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001647 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001648 ? WindowAnimation_taskCloseEnterAnimation
1649 : WindowAnimation_taskCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001650 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001651 case TRANSIT_TASK_TO_FRONT:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001652 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001653 ? WindowAnimation_taskToFrontEnterAnimation
1654 : WindowAnimation_taskToFrontExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001655 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001656 case TRANSIT_TASK_TO_BACK:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001657 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001658 ? WindowAnimation_taskToBackEnterAnimation
1659 : WindowAnimation_taskToBackExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001660 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001661 case TRANSIT_WALLPAPER_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001662 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001663 ? WindowAnimation_wallpaperOpenEnterAnimation
1664 : WindowAnimation_wallpaperOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001665 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001666 case TRANSIT_WALLPAPER_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001667 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001668 ? WindowAnimation_wallpaperCloseEnterAnimation
1669 : WindowAnimation_wallpaperCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001670 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001671 case TRANSIT_WALLPAPER_INTRA_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001672 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001673 ? WindowAnimation_wallpaperIntraOpenEnterAnimation
1674 : WindowAnimation_wallpaperIntraOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001675 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001676 case TRANSIT_WALLPAPER_INTRA_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001677 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001678 ? WindowAnimation_wallpaperIntraCloseEnterAnimation
1679 : WindowAnimation_wallpaperIntraCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001680 break;
Craig Mautnerbb742462014-07-07 15:28:55 -07001681 case TRANSIT_TASK_OPEN_BEHIND:
1682 animAttr = enter
1683 ? WindowAnimation_launchTaskBehindSourceAnimation
Craig Mautner3b2cd1d2014-08-25 14:25:54 -07001684 : WindowAnimation_launchTaskBehindTargetAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001685 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001686 a = animAttr != 0 ? loadAnimationAttr(lp, animAttr) : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001687 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1688 "applyAnimation:"
1689 + " anim=" + a
1690 + " animAttr=0x" + Integer.toHexString(animAttr)
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001691 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001692 + " Callers=" + Debug.getCallers(3));
1693 }
1694 return a;
1695 }
1696
Jorim Jaggife762342016-10-13 14:33:27 +02001697 private Animation loadKeyguardExitAnimation(int transit) {
1698 if ((mNextAppTransitionFlags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_NO_ANIMATION) != 0) {
1699 return null;
1700 }
1701 final boolean toShade =
1702 (mNextAppTransitionFlags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_TO_SHADE) != 0;
1703 return mService.mPolicy.createHiddenByKeyguardExit(
1704 transit == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER, toShade);
1705 }
1706
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001707 int getAppStackClipMode() {
Matthew Ngbf1d9852017-03-14 12:23:09 -07001708 // When dismiss keyguard animation occurs, clip before the animation to prevent docked
1709 // app from showing beyond the divider
1710 if (mNextAppTransition == TRANSIT_KEYGUARD_GOING_AWAY
1711 || mNextAppTransition == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER) {
1712 return STACK_CLIP_BEFORE_ANIM;
1713 }
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001714 return mNextAppTransition == TRANSIT_ACTIVITY_RELAUNCH
Jorim Jaggic69bd222016-03-15 14:38:37 +01001715 || mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
Jorim Jaggi1f458fb2016-03-25 17:36:37 -07001716 || mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001717 ? STACK_CLIP_NONE
1718 : STACK_CLIP_AFTER_ANIM;
1719 }
1720
Jorim Jaggife762342016-10-13 14:33:27 +02001721 public int getTransitFlags() {
1722 return mNextAppTransitionFlags;
1723 }
1724
Craig Mautner164d4bb2012-11-26 13:51:23 -08001725 void postAnimationCallback() {
1726 if (mNextAppTransitionCallback != null) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001727 mService.mH.sendMessage(mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK,
1728 mNextAppTransitionCallback));
Craig Mautner164d4bb2012-11-26 13:51:23 -08001729 mNextAppTransitionCallback = null;
1730 }
1731 }
1732
1733 void overridePendingAppTransition(String packageName, int enterAnim, int exitAnim,
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001734 IRemoteCallback startedCallback) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001735 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001736 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001737 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001738 mNextAppTransitionPackage = packageName;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001739 mNextAppTransitionEnter = enterAnim;
1740 mNextAppTransitionExit = exitAnim;
1741 postAnimationCallback();
1742 mNextAppTransitionCallback = startedCallback;
1743 } else {
1744 postAnimationCallback();
1745 }
1746 }
1747
1748 void overridePendingAppTransitionScaleUp(int startX, int startY, int startWidth,
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001749 int startHeight) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001750 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001751 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001752 mNextAppTransitionType = NEXT_TRANSIT_TYPE_SCALE_UP;
Winson4c3fecd2016-07-13 12:29:48 -07001753 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001754 postAnimationCallback();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001755 }
1756 }
1757
Chet Haase10e23ab2015-02-11 15:08:38 -08001758 void overridePendingAppTransitionClipReveal(int startX, int startY,
1759 int startWidth, int startHeight) {
1760 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001761 clear();
Chet Haase10e23ab2015-02-11 15:08:38 -08001762 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CLIP_REVEAL;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001763 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Chet Haase10e23ab2015-02-11 15:08:38 -08001764 postAnimationCallback();
Chet Haase10e23ab2015-02-11 15:08:38 -08001765 }
1766 }
1767
Winson Chungaa7fa012017-05-24 15:50:06 -07001768 void overridePendingAppTransitionThumb(GraphicBuffer srcThumb, int startX, int startY,
Craig Mautner164d4bb2012-11-26 13:51:23 -08001769 IRemoteCallback startedCallback, boolean scaleUp) {
1770 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001771 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001772 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP
1773 : NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001774 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001775 putDefaultNextAppTransitionCoordinates(startX, startY, 0, 0, srcThumb);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001776 postAnimationCallback();
1777 mNextAppTransitionCallback = startedCallback;
1778 } else {
1779 postAnimationCallback();
1780 }
1781 }
1782
Winson Chungaa7fa012017-05-24 15:50:06 -07001783 void overridePendingAppTransitionAspectScaledThumb(GraphicBuffer srcThumb, int startX, int startY,
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001784 int targetWidth, int targetHeight, IRemoteCallback startedCallback, boolean scaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001785 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001786 clear();
Winson Chunga4ccb862014-08-22 15:26:27 -07001787 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1788 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Winson Chunga4ccb862014-08-22 15:26:27 -07001789 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001790 putDefaultNextAppTransitionCoordinates(startX, startY, targetWidth, targetHeight,
1791 srcThumb);
Winson Chunga4ccb862014-08-22 15:26:27 -07001792 postAnimationCallback();
1793 mNextAppTransitionCallback = startedCallback;
1794 } else {
1795 postAnimationCallback();
1796 }
1797 }
1798
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001799 public void overridePendingAppTransitionMultiThumb(AppTransitionAnimationSpec[] specs,
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001800 IRemoteCallback onAnimationStartedCallback, IRemoteCallback onAnimationFinishedCallback,
1801 boolean scaleUp) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001802 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001803 clear();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001804 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1805 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001806 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi43102412015-11-11 16:28:37 +01001807 if (specs != null) {
1808 for (int i = 0; i < specs.length; i++) {
1809 AppTransitionAnimationSpec spec = specs[i];
1810 if (spec != null) {
1811 mNextAppTransitionAnimationsSpecs.put(spec.taskId, spec);
1812 if (i == 0) {
1813 // In full screen mode, the transition code depends on the default spec
1814 // to be set.
1815 Rect rect = spec.rect;
1816 putDefaultNextAppTransitionCoordinates(rect.left, rect.top,
Winson Chungaa7fa012017-05-24 15:50:06 -07001817 rect.width(), rect.height(), spec.buffer);
Jorim Jaggi43102412015-11-11 16:28:37 +01001818 }
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001819 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001820 }
1821 }
1822 postAnimationCallback();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001823 mNextAppTransitionCallback = onAnimationStartedCallback;
1824 mAnimationFinishedCallback = onAnimationFinishedCallback;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001825 } else {
1826 postAnimationCallback();
1827 }
1828 }
1829
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001830 void overridePendingAppTransitionMultiThumbFuture(
1831 IAppTransitionAnimationSpecsFuture specsFuture, IRemoteCallback callback,
1832 boolean scaleUp) {
1833 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001834 clear();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001835 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1836 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001837 mNextAppTransitionAnimationsSpecsFuture = specsFuture;
1838 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001839 mNextAppTransitionFutureCallback = callback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001840 }
1841 }
1842
Winson Chung044d5292014-11-06 11:05:19 -08001843 void overrideInPlaceAppTransition(String packageName, int anim) {
1844 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001845 clear();
Winson Chung044d5292014-11-06 11:05:19 -08001846 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE;
1847 mNextAppTransitionPackage = packageName;
1848 mNextAppTransitionInPlace = anim;
1849 } else {
1850 postAnimationCallback();
1851 }
1852 }
1853
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001854 /**
Tony Mak089c35e2017-12-18 20:34:14 +00001855 * @see {@link #NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS}
1856 */
1857 void overridePendingAppTransitionStartCrossProfileApps() {
1858 if (isTransitionSet()) {
1859 clear();
1860 mNextAppTransitionType = NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS;
1861 postAnimationCallback();
1862 }
1863 }
1864
1865 /**
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001866 * If a future is set for the app transition specs, fetch it in another thread.
1867 */
1868 private void fetchAppTransitionSpecsFromFuture() {
1869 if (mNextAppTransitionAnimationsSpecsFuture != null) {
1870 mNextAppTransitionAnimationsSpecsPending = true;
1871 final IAppTransitionAnimationSpecsFuture future
1872 = mNextAppTransitionAnimationsSpecsFuture;
1873 mNextAppTransitionAnimationsSpecsFuture = null;
Jorim Jaggied410b62017-05-05 15:16:14 +02001874 mDefaultExecutor.execute(() -> {
1875 AppTransitionAnimationSpec[] specs = null;
1876 try {
1877 Binder.allowBlocking(future.asBinder());
1878 specs = future.get();
1879 } catch (RemoteException e) {
1880 Slog.w(TAG, "Failed to fetch app transition specs: " + e);
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001881 }
Jorim Jaggied410b62017-05-05 15:16:14 +02001882 synchronized (mService.mWindowMap) {
1883 mNextAppTransitionAnimationsSpecsPending = false;
1884 overridePendingAppTransitionMultiThumb(specs,
1885 mNextAppTransitionFutureCallback, null /* finishedCallback */,
1886 mNextAppTransitionScaleUp);
1887 mNextAppTransitionFutureCallback = null;
1888 if (specs != null) {
1889 mService.prolongAnimationsFromSpecs(specs, mNextAppTransitionScaleUp);
1890 }
1891 }
1892 mService.requestTraversal();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001893 });
1894 }
1895 }
1896
Craig Mautner164d4bb2012-11-26 13:51:23 -08001897 @Override
1898 public String toString() {
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001899 return "mNextAppTransition=" + appTransitionToString(mNextAppTransition);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001900 }
1901
Craig Mautner4b71aa12012-12-27 17:20:01 -08001902 /**
1903 * Returns the human readable name of a window transition.
1904 *
1905 * @param transition The window transition.
1906 * @return The transition symbolic name.
1907 */
1908 public static String appTransitionToString(int transition) {
1909 switch (transition) {
1910 case TRANSIT_UNSET: {
1911 return "TRANSIT_UNSET";
1912 }
1913 case TRANSIT_NONE: {
1914 return "TRANSIT_NONE";
1915 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001916 case TRANSIT_ACTIVITY_OPEN: {
1917 return "TRANSIT_ACTIVITY_OPEN";
1918 }
1919 case TRANSIT_ACTIVITY_CLOSE: {
1920 return "TRANSIT_ACTIVITY_CLOSE";
1921 }
1922 case TRANSIT_TASK_OPEN: {
1923 return "TRANSIT_TASK_OPEN";
1924 }
1925 case TRANSIT_TASK_CLOSE: {
1926 return "TRANSIT_TASK_CLOSE";
1927 }
1928 case TRANSIT_TASK_TO_FRONT: {
1929 return "TRANSIT_TASK_TO_FRONT";
1930 }
1931 case TRANSIT_TASK_TO_BACK: {
1932 return "TRANSIT_TASK_TO_BACK";
1933 }
1934 case TRANSIT_WALLPAPER_CLOSE: {
1935 return "TRANSIT_WALLPAPER_CLOSE";
1936 }
1937 case TRANSIT_WALLPAPER_OPEN: {
1938 return "TRANSIT_WALLPAPER_OPEN";
1939 }
1940 case TRANSIT_WALLPAPER_INTRA_OPEN: {
1941 return "TRANSIT_WALLPAPER_INTRA_OPEN";
1942 }
1943 case TRANSIT_WALLPAPER_INTRA_CLOSE: {
1944 return "TRANSIT_WALLPAPER_INTRA_CLOSE";
1945 }
Craig Mautnerbb742462014-07-07 15:28:55 -07001946 case TRANSIT_TASK_OPEN_BEHIND: {
1947 return "TRANSIT_TASK_OPEN_BEHIND";
1948 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001949 case TRANSIT_ACTIVITY_RELAUNCH: {
1950 return "TRANSIT_ACTIVITY_RELAUNCH";
1951 }
Jorim Jaggi192086e2016-03-11 17:17:03 +01001952 case TRANSIT_DOCK_TASK_FROM_RECENTS: {
1953 return "TRANSIT_DOCK_TASK_FROM_RECENTS";
1954 }
Jorim Jaggife762342016-10-13 14:33:27 +02001955 case TRANSIT_KEYGUARD_GOING_AWAY: {
1956 return "TRANSIT_KEYGUARD_GOING_AWAY";
1957 }
1958 case TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER: {
1959 return "TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER";
1960 }
1961 case TRANSIT_KEYGUARD_OCCLUDE: {
1962 return "TRANSIT_KEYGUARD_OCCLUDE";
1963 }
1964 case TRANSIT_KEYGUARD_UNOCCLUDE: {
1965 return "TRANSIT_KEYGUARD_UNOCCLUDE";
1966 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001967 default: {
1968 return "<UNKNOWN>";
1969 }
1970 }
1971 }
1972
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001973 private String appStateToString() {
1974 switch (mAppTransitionState) {
1975 case APP_STATE_IDLE:
1976 return "APP_STATE_IDLE";
1977 case APP_STATE_READY:
1978 return "APP_STATE_READY";
1979 case APP_STATE_RUNNING:
1980 return "APP_STATE_RUNNING";
1981 case APP_STATE_TIMEOUT:
1982 return "APP_STATE_TIMEOUT";
1983 default:
1984 return "unknown state=" + mAppTransitionState;
1985 }
1986 }
1987
1988 private String transitTypeToString() {
1989 switch (mNextAppTransitionType) {
1990 case NEXT_TRANSIT_TYPE_NONE:
1991 return "NEXT_TRANSIT_TYPE_NONE";
1992 case NEXT_TRANSIT_TYPE_CUSTOM:
1993 return "NEXT_TRANSIT_TYPE_CUSTOM";
Winson Chung044d5292014-11-06 11:05:19 -08001994 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
1995 return "NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001996 case NEXT_TRANSIT_TYPE_SCALE_UP:
1997 return "NEXT_TRANSIT_TYPE_SCALE_UP";
1998 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1999 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP";
2000 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
2001 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN";
Winson Chunga4ccb862014-08-22 15:26:27 -07002002 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
2003 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP";
2004 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN:
2005 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002006 default:
2007 return "unknown type=" + mNextAppTransitionType;
2008 }
2009 }
2010
Steven Timotiusaf03df62017-07-18 16:56:43 -07002011 void writeToProto(ProtoOutputStream proto, long fieldId) {
2012 final long token = proto.start(fieldId);
2013 proto.write(APP_TRANSITION_STATE, mAppTransitionState);
2014 proto.write(LAST_USED_APP_TRANSITION, mLastUsedAppTransition);
2015 proto.end(token);
2016 }
2017
Craig Mautner164d4bb2012-11-26 13:51:23 -08002018 @Override
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002019 public void dump(PrintWriter pw, String prefix) {
2020 pw.print(prefix); pw.println(this);
2021 pw.print(prefix); pw.print("mAppTransitionState="); pw.println(appStateToString());
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002022 if (mNextAppTransitionType != NEXT_TRANSIT_TYPE_NONE) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002023 pw.print(prefix); pw.print("mNextAppTransitionType=");
2024 pw.println(transitTypeToString());
Craig Mautner164d4bb2012-11-26 13:51:23 -08002025 }
2026 switch (mNextAppTransitionType) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002027 case NEXT_TRANSIT_TYPE_CUSTOM:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002028 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Craig Mautner164d4bb2012-11-26 13:51:23 -08002029 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002030 pw.print(prefix); pw.print("mNextAppTransitionEnter=0x");
Craig Mautner164d4bb2012-11-26 13:51:23 -08002031 pw.print(Integer.toHexString(mNextAppTransitionEnter));
2032 pw.print(" mNextAppTransitionExit=0x");
2033 pw.println(Integer.toHexString(mNextAppTransitionExit));
2034 break;
Winson Chung044d5292014-11-06 11:05:19 -08002035 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002036 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Winson Chung044d5292014-11-06 11:05:19 -08002037 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002038 pw.print(prefix); pw.print("mNextAppTransitionInPlace=0x");
Winson Chung044d5292014-11-06 11:05:19 -08002039 pw.print(Integer.toHexString(mNextAppTransitionInPlace));
2040 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002041 case NEXT_TRANSIT_TYPE_SCALE_UP: {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002042 getDefaultNextAppTransitionStartRect(mTmpRect);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002043 pw.print(prefix); pw.print("mNextAppTransitionStartX=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002044 pw.print(mTmpRect.left);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002045 pw.print(" mNextAppTransitionStartY=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002046 pw.println(mTmpRect.top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002047 pw.print(prefix); pw.print("mNextAppTransitionStartWidth=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002048 pw.print(mTmpRect.width());
Craig Mautner164d4bb2012-11-26 13:51:23 -08002049 pw.print(" mNextAppTransitionStartHeight=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002050 pw.println(mTmpRect.height());
Craig Mautner164d4bb2012-11-26 13:51:23 -08002051 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002052 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002053 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
2054 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
Winson Chunga4ccb862014-08-22 15:26:27 -07002055 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002056 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN: {
2057 pw.print(prefix); pw.print("mDefaultNextAppTransitionAnimationSpec=");
2058 pw.println(mDefaultNextAppTransitionAnimationSpec);
2059 pw.print(prefix); pw.print("mNextAppTransitionAnimationsSpecs=");
2060 pw.println(mNextAppTransitionAnimationsSpecs);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002061 pw.print(prefix); pw.print("mNextAppTransitionScaleUp=");
2062 pw.println(mNextAppTransitionScaleUp);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002063 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002064 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002065 }
2066 if (mNextAppTransitionCallback != null) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002067 pw.print(prefix); pw.print("mNextAppTransitionCallback=");
2068 pw.println(mNextAppTransitionCallback);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002069 }
Chong Zhang60091a92016-07-27 17:52:45 -07002070 if (mLastUsedAppTransition != TRANSIT_NONE) {
2071 pw.print(prefix); pw.print("mLastUsedAppTransition=");
2072 pw.println(appTransitionToString(mLastUsedAppTransition));
2073 pw.print(prefix); pw.print("mLastOpeningApp=");
2074 pw.println(mLastOpeningApp);
2075 pw.print(prefix); pw.print("mLastClosingApp=");
2076 pw.println(mLastClosingApp);
2077 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002078 }
Amith Yamasani4befbec2013-07-10 16:18:01 -07002079
2080 public void setCurrentUser(int newUserId) {
2081 mCurrentUserId = newUserId;
2082 }
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002083
2084 /**
2085 * @return true if transition is not running and should not be skipped, false if transition is
2086 * already running
2087 */
Jorim Jaggife762342016-10-13 14:33:27 +02002088 boolean prepareAppTransitionLocked(int transit, boolean alwaysKeepCurrent, int flags,
2089 boolean forceOverride) {
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002090 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Prepare app transition:"
2091 + " transit=" + appTransitionToString(transit)
2092 + " " + this
2093 + " alwaysKeepCurrent=" + alwaysKeepCurrent
2094 + " Callers=" + Debug.getCallers(3));
Jorim Jaggife762342016-10-13 14:33:27 +02002095 if (forceOverride || isKeyguardTransit(transit) || !isTransitionSet()
2096 || mNextAppTransition == TRANSIT_NONE) {
2097 setAppTransition(transit, flags);
Jorim Jaggia69243a2017-06-15 15:10:38 -04002098 }
2099 // We never want to change from a Keyguard transit to a non-Keyguard transit, as our logic
2100 // relies on the fact that we always execute a Keyguard transition after preparing one.
2101 else if (!alwaysKeepCurrent && !isKeyguardTransit(transit)) {
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002102 if (transit == TRANSIT_TASK_OPEN && isTransitionEqual(TRANSIT_TASK_CLOSE)) {
2103 // Opening a new task always supersedes a close for the anim.
Jorim Jaggife762342016-10-13 14:33:27 +02002104 setAppTransition(transit, flags);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002105 } else if (transit == TRANSIT_ACTIVITY_OPEN
2106 && isTransitionEqual(TRANSIT_ACTIVITY_CLOSE)) {
2107 // Opening a new activity always supersedes a close for the anim.
Jorim Jaggife762342016-10-13 14:33:27 +02002108 setAppTransition(transit, flags);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002109 }
2110 }
2111 boolean prepared = prepare();
2112 if (isTransitionSet()) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08002113 mService.mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
2114 mService.mH.sendEmptyMessageDelayed(H.APP_TRANSITION_TIMEOUT, APP_TRANSITION_TIMEOUT_MS);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002115 }
2116 return prepared;
2117 }
Winsonb2024762016-04-05 17:32:30 -07002118
2119 /**
Jorim Jaggife762342016-10-13 14:33:27 +02002120 * @return true if {@param transit} is representing a transition in which Keyguard is going
2121 * away, false otherwise
2122 */
2123 public static boolean isKeyguardGoingAwayTransit(int transit) {
2124 return transit == TRANSIT_KEYGUARD_GOING_AWAY
2125 || transit == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER;
2126 }
2127
2128 private static boolean isKeyguardTransit(int transit) {
2129 return isKeyguardGoingAwayTransit(transit) || transit == TRANSIT_KEYGUARD_OCCLUDE
2130 || transit == TRANSIT_KEYGUARD_UNOCCLUDE;
2131 }
2132
2133 /**
Manu Cornetd7376802017-01-13 13:44:07 -08002134 * @return whether the transition should show the thumbnail being scaled down.
2135 */
2136 private boolean shouldScaleDownThumbnailTransition(int uiMode, int orientation) {
Sid Soundararajan0e88d322017-03-07 15:37:30 -08002137 return mGridLayoutRecentsEnabled
Manu Cornetd7376802017-01-13 13:44:07 -08002138 || orientation == Configuration.ORIENTATION_PORTRAIT;
2139 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002140}