blob: b1ed35867dcf13576ceb61f3f8f6a486a3bb7f48 [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 android.view.WindowManagerInternal.AppTransitionListener;
20import static com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation;
21import static com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
22import static com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation;
23import static com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
24import static com.android.internal.R.styleable.WindowAnimation_launchTaskBehindSourceAnimation;
25import static com.android.internal.R.styleable.WindowAnimation_launchTaskBehindTargetAnimation;
26import static com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation;
27import static com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
28import static com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation;
29import static com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
30import static com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation;
31import static com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
32import static com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation;
33import static com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
34import static com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation;
35import static com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
36import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation;
37import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
38import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation;
39import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
40import static com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation;
41import static com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Jorim Jaggi363ab982016-04-26 19:51:20 -070042import static com.android.server.wm.AppWindowAnimator.PROLONG_ANIMATION_AT_START;
Filip Gruszczynski198dcbf2016-01-18 10:02:00 -080043import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
44import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080045import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
46import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Matthew Ngbf1d9852017-03-14 12:23:09 -070047import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_BEFORE_ANIM;
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +010048import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_NONE;
49import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_AFTER_ANIM;
Filip Gruszczynski82861362015-10-16 14:21:09 -070050
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -070051import android.annotation.Nullable;
Craig Mautner164d4bb2012-11-26 13:51:23 -080052import android.content.Context;
Winson21700932016-03-24 17:26:23 -070053import android.content.res.Configuration;
Craig Mautner164d4bb2012-11-26 13:51:23 -080054import android.graphics.Bitmap;
Winson Chungaa7fa012017-05-24 15:50:06 -070055import android.graphics.GraphicBuffer;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +010056import android.graphics.Path;
Winson Chung399f6202014-03-19 10:47:20 -070057import android.graphics.Rect;
Jorim Jaggied410b62017-05-05 15:16:14 +020058import android.os.Binder;
Craig Mautner164d4bb2012-11-26 13:51:23 -080059import android.os.Debug;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010060import android.os.IBinder;
Craig Mautner164d4bb2012-11-26 13:51:23 -080061import android.os.IRemoteCallback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010062import android.os.RemoteException;
Manu Cornetd7376802017-01-13 13:44:07 -080063import android.os.SystemProperties;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -080064import android.util.ArraySet;
Craig Mautner164d4bb2012-11-26 13:51:23 -080065import android.util.Slog;
Filip Gruszczynski170192a2015-08-16 17:46:34 -070066import android.util.SparseArray;
67import android.view.AppTransitionAnimationSpec;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010068import android.view.IAppTransitionAnimationSpecsFuture;
Craig Mautner164d4bb2012-11-26 13:51:23 -080069import android.view.WindowManager;
Craig Mautner164d4bb2012-11-26 13:51:23 -080070import android.view.animation.AlphaAnimation;
71import android.view.animation.Animation;
72import android.view.animation.AnimationSet;
73import android.view.animation.AnimationUtils;
Winson Chung399f6202014-03-19 10:47:20 -070074import android.view.animation.ClipRectAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -080075import android.view.animation.Interpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070076import android.view.animation.PathInterpolator;
Craig Mautner164d4bb2012-11-26 13:51:23 -080077import android.view.animation.ScaleAnimation;
Winson Chung399f6202014-03-19 10:47:20 -070078import android.view.animation.TranslateAnimation;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070079
Craig Mautner164d4bb2012-11-26 13:51:23 -080080import com.android.internal.util.DumpUtils.Dump;
81import com.android.server.AttributeCache;
82import com.android.server.wm.WindowManagerService.H;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -080083import com.android.server.wm.animation.ClipRectLRAnimation;
84import com.android.server.wm.animation.ClipRectTBAnimation;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +010085import com.android.server.wm.animation.CurvedTranslateAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -080086
87import java.io.PrintWriter;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010088import java.util.ArrayList;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010089import java.util.concurrent.ExecutorService;
90import java.util.concurrent.Executors;
Craig Mautner164d4bb2012-11-26 13:51:23 -080091
Craig Mautner164d4bb2012-11-26 13:51:23 -080092// State management of app transitions. When we are preparing for a
93// transition, mNextAppTransition will be the kind of transition to
94// perform or TRANSIT_NONE if we are not waiting. If we are waiting,
95// mOpeningApps and mClosingApps are the lists of tokens that will be
96// made visible or hidden at the next transition.
97public class AppTransition implements Dump {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080098 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppTransition" : TAG_WM;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070099 private static final int CLIP_REVEAL_TRANSLATION_Y_DP = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800100
Craig Mautner4b71aa12012-12-27 17:20:01 -0800101 /** Not set up for a transition. */
102 public static final int TRANSIT_UNSET = -1;
103 /** No animation for transition. */
104 public static final int TRANSIT_NONE = 0;
105 /** 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 -0700106 public static final int TRANSIT_ACTIVITY_OPEN = 6;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800107 /** The window in the top-most activity is being closed to reveal the
108 * previous activity in the same task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700109 public static final int TRANSIT_ACTIVITY_CLOSE = 7;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800110 /** A window in a new task is being opened on top of an existing one
111 * in another activity's task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700112 public static final int TRANSIT_TASK_OPEN = 8;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800113 /** A window in the top-most activity is being closed to reveal the
114 * previous activity in a different task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700115 public static final int TRANSIT_TASK_CLOSE = 9;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800116 /** A window in an existing task is being displayed on top of an existing one
117 * in another activity's task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700118 public static final int TRANSIT_TASK_TO_FRONT = 10;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800119 /** A window in an existing task is being put below all other tasks. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700120 public static final int TRANSIT_TASK_TO_BACK = 11;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800121 /** A window in a new activity that doesn't have a wallpaper is being opened on top of one that
122 * does, effectively closing the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700123 public static final int TRANSIT_WALLPAPER_CLOSE = 12;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800124 /** A window in a new activity that does have a wallpaper is being opened on one that didn't,
125 * effectively opening the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700126 public static final int TRANSIT_WALLPAPER_OPEN = 13;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800127 /** A window in a new activity is being opened on top of an existing one, and both are on top
128 * of the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700129 public static final int TRANSIT_WALLPAPER_INTRA_OPEN = 14;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800130 /** The window in the top-most activity is being closed to reveal the previous activity, and
131 * both are on top of the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700132 public static final int TRANSIT_WALLPAPER_INTRA_CLOSE = 15;
133 /** A window in a new task is being opened behind an existing one in another activity's task.
134 * The new window will show briefly and then be gone. */
135 public static final int TRANSIT_TASK_OPEN_BEHIND = 16;
Winson Chung044d5292014-11-06 11:05:19 -0800136 /** A window in a task is being animated in-place. */
137 public static final int TRANSIT_TASK_IN_PLACE = 17;
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700138 /** An activity is being relaunched (e.g. due to configuration change). */
139 public static final int TRANSIT_ACTIVITY_RELAUNCH = 18;
Jorim Jaggi192086e2016-03-11 17:17:03 +0100140 /** A task is being docked from recents. */
141 public static final int TRANSIT_DOCK_TASK_FROM_RECENTS = 19;
Jorim Jaggife762342016-10-13 14:33:27 +0200142 /** Keyguard is going away */
143 public static final int TRANSIT_KEYGUARD_GOING_AWAY = 20;
144 /** Keyguard is going away with showing an activity behind that requests wallpaper */
145 public static final int TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER = 21;
146 /** Keyguard is being occluded */
147 public static final int TRANSIT_KEYGUARD_OCCLUDE = 22;
148 /** Keyguard is being unoccluded */
149 public static final int TRANSIT_KEYGUARD_UNOCCLUDE = 23;
150
151 /** Transition flag: Keyguard is going away, but keeping the notification shade open */
152 public static final int TRANSIT_FLAG_KEYGUARD_GOING_AWAY_TO_SHADE = 0x1;
153 /** Transition flag: Keyguard is going away, but doesn't want an animation for it */
154 public static final int TRANSIT_FLAG_KEYGUARD_GOING_AWAY_NO_ANIMATION = 0x2;
155 /** Transition flag: Keyguard is going away while it was showing the system wallpaper. */
156 public static final int TRANSIT_FLAG_KEYGUARD_GOING_AWAY_WITH_WALLPAPER = 0x4;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800157
Winson Chunga4ccb862014-08-22 15:26:27 -0700158 /** Fraction of animation at which the recents thumbnail stays completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700159 private static final float RECENTS_THUMBNAIL_FADEIN_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800160 /** Fraction of animation at which the recents thumbnail becomes completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700161 private static final float RECENTS_THUMBNAIL_FADEOUT_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800162
Filip Gruszczynski84fa3352016-01-25 16:28:49 -0800163 static final int DEFAULT_APP_TRANSITION_DURATION = 336;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800164
165 /** Interpolator to be used for animations that respond directly to a touch */
166 static final Interpolator TOUCH_RESPONSE_INTERPOLATOR =
167 new PathInterpolator(0.3f, 0f, 0.1f, 1f);
168
Jorim Jaggic69bd222016-03-15 14:38:37 +0100169 private static final Interpolator THUMBNAIL_DOCK_INTERPOLATOR =
170 new PathInterpolator(0.85f, 0f, 1f, 1f);
171
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800172 /**
173 * Maximum duration for the clip reveal animation. This is used when there is a lot of movement
174 * involved, to make it more understandable.
175 */
176 private static final int MAX_CLIP_REVEAL_TRANSITION_DURATION = 420;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700177 private static final int THUMBNAIL_APP_TRANSITION_DURATION = 336;
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700178 private static final long APP_TRANSITION_TIMEOUT_MS = 5000;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800179
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800180 private final Context mContext;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800181 private final WindowManagerService mService;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800182
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800183 private int mNextAppTransition = TRANSIT_UNSET;
Jorim Jaggife762342016-10-13 14:33:27 +0200184 private int mNextAppTransitionFlags = 0;
Chong Zhang60091a92016-07-27 17:52:45 -0700185 private int mLastUsedAppTransition = TRANSIT_UNSET;
186 private String mLastOpeningApp;
187 private String mLastClosingApp;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800188
189 private static final int NEXT_TRANSIT_TYPE_NONE = 0;
190 private static final int NEXT_TRANSIT_TYPE_CUSTOM = 1;
191 private static final int NEXT_TRANSIT_TYPE_SCALE_UP = 2;
192 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP = 3;
193 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN = 4;
Winson Chunga4ccb862014-08-22 15:26:27 -0700194 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP = 5;
195 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN = 6;
Winson Chung044d5292014-11-06 11:05:19 -0800196 private static final int NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE = 7;
Chet Haase10e23ab2015-02-11 15:08:38 -0800197 private static final int NEXT_TRANSIT_TYPE_CLIP_REVEAL = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800198 private int mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
199
Winson Chung399f6202014-03-19 10:47:20 -0700200 // These are the possible states for the enter/exit activities during a thumbnail transition
201 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_UP = 0;
202 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_UP = 1;
203 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN = 2;
204 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN = 3;
205
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800206 private String mNextAppTransitionPackage;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800207 // Used for thumbnail transitions. True if we're scaling up, false if scaling down
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800208 private boolean mNextAppTransitionScaleUp;
209 private IRemoteCallback mNextAppTransitionCallback;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +0100210 private IRemoteCallback mNextAppTransitionFutureCallback;
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -0700211 private IRemoteCallback mAnimationFinishedCallback;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800212 private int mNextAppTransitionEnter;
213 private int mNextAppTransitionExit;
Winson Chung044d5292014-11-06 11:05:19 -0800214 private int mNextAppTransitionInPlace;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700215
216 // Keyed by task id.
217 private final SparseArray<AppTransitionAnimationSpec> mNextAppTransitionAnimationsSpecs
218 = new SparseArray<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100219 private IAppTransitionAnimationSpecsFuture mNextAppTransitionAnimationsSpecsFuture;
220 private boolean mNextAppTransitionAnimationsSpecsPending;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700221 private AppTransitionAnimationSpec mDefaultNextAppTransitionAnimationSpec;
222
Winson Chunga4ccb862014-08-22 15:26:27 -0700223 private Rect mNextAppTransitionInsets = new Rect();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800224
Winson Chung2820c452014-04-15 15:34:44 -0700225 private Rect mTmpFromClipRect = new Rect();
226 private Rect mTmpToClipRect = new Rect();
227
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700228 private final Rect mTmpRect = new Rect();
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700229
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800230 private final static int APP_STATE_IDLE = 0;
231 private final static int APP_STATE_READY = 1;
232 private final static int APP_STATE_RUNNING = 2;
233 private final static int APP_STATE_TIMEOUT = 3;
234 private int mAppTransitionState = APP_STATE_IDLE;
235
236 private final int mConfigShortAnimTime;
Craig Mautner321bdf52012-12-18 09:53:24 -0800237 private final Interpolator mDecelerateInterpolator;
Winson Chunga4ccb862014-08-22 15:26:27 -0700238 private final Interpolator mThumbnailFadeInInterpolator;
239 private final Interpolator mThumbnailFadeOutInterpolator;
Chet Haase10e23ab2015-02-11 15:08:38 -0800240 private final Interpolator mLinearOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700241 private final Interpolator mFastOutLinearInInterpolator;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100242 private final Interpolator mFastOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700243 private final Interpolator mClipHorizontalInterpolator = new PathInterpolator(0, 0, 0.4f, 1f);
244
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700245 private final int mClipRevealTranslationY;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800246
Amith Yamasani4befbec2013-07-10 16:18:01 -0700247 private int mCurrentUserId = 0;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800248 private long mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Amith Yamasani4befbec2013-07-10 16:18:01 -0700249
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100250 private final ArrayList<AppTransitionListener> mListeners = new ArrayList<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100251 private final ExecutorService mDefaultExecutor = Executors.newSingleThreadExecutor();
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100252
Jorim Jaggif97ed922016-02-18 18:57:07 -0800253 private int mLastClipRevealMaxTranslation;
254 private boolean mLastHadClipReveal;
Jorim Jaggi363ab982016-04-26 19:51:20 -0700255 private boolean mProlongedAnimationsEnded;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800256
Manu Cornetd7376802017-01-13 13:44:07 -0800257 private final boolean mGridLayoutRecentsEnabled;
258
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800259 AppTransition(Context context, WindowManagerService service) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800260 mContext = context;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800261 mService = service;
Chet Haase10e23ab2015-02-11 15:08:38 -0800262 mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
263 com.android.internal.R.interpolator.linear_out_slow_in);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700264 mFastOutLinearInInterpolator = AnimationUtils.loadInterpolator(context,
265 com.android.internal.R.interpolator.fast_out_linear_in);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100266 mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
267 com.android.internal.R.interpolator.fast_out_slow_in);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800268 mConfigShortAnimTime = context.getResources().getInteger(
269 com.android.internal.R.integer.config_shortAnimTime);
Craig Mautner321bdf52012-12-18 09:53:24 -0800270 mDecelerateInterpolator = AnimationUtils.loadInterpolator(context,
271 com.android.internal.R.interpolator.decelerate_cubic);
Winson Chunga4ccb862014-08-22 15:26:27 -0700272 mThumbnailFadeInInterpolator = new Interpolator() {
273 @Override
274 public float getInterpolation(float input) {
275 // Linear response for first fraction, then complete after that.
276 if (input < RECENTS_THUMBNAIL_FADEIN_FRACTION) {
277 return 0f;
278 }
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700279 float t = (input - RECENTS_THUMBNAIL_FADEIN_FRACTION) /
Winson Chunga4ccb862014-08-22 15:26:27 -0700280 (1f - RECENTS_THUMBNAIL_FADEIN_FRACTION);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700281 return mFastOutLinearInInterpolator.getInterpolation(t);
Winson Chunga4ccb862014-08-22 15:26:27 -0700282 }
283 };
284 mThumbnailFadeOutInterpolator = new Interpolator() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800285 @Override
286 public float getInterpolation(float input) {
287 // Linear response for first fraction, then complete after that.
288 if (input < RECENTS_THUMBNAIL_FADEOUT_FRACTION) {
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700289 float t = input / RECENTS_THUMBNAIL_FADEOUT_FRACTION;
290 return mLinearOutSlowInInterpolator.getInterpolation(t);
Craig Mautner321bdf52012-12-18 09:53:24 -0800291 }
Winson Chunga4ccb862014-08-22 15:26:27 -0700292 return 1f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800293 }
294 };
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700295 mClipRevealTranslationY = (int) (CLIP_REVEAL_TRANSLATION_Y_DP
296 * mContext.getResources().getDisplayMetrics().density);
Manu Cornetd7376802017-01-13 13:44:07 -0800297 mGridLayoutRecentsEnabled = SystemProperties.getBoolean("ro.recents.grid", false);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800298 }
299
300 boolean isTransitionSet() {
301 return mNextAppTransition != TRANSIT_UNSET;
302 }
303
Craig Mautner164d4bb2012-11-26 13:51:23 -0800304 boolean isTransitionEqual(int transit) {
305 return mNextAppTransition == transit;
306 }
307
308 int getAppTransition() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800309 return mNextAppTransition;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800310 }
311
Jorim Jaggife762342016-10-13 14:33:27 +0200312 private void setAppTransition(int transit, int flags) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800313 mNextAppTransition = transit;
Jorim Jaggife762342016-10-13 14:33:27 +0200314 mNextAppTransitionFlags |= flags;
Chong Zhang60091a92016-07-27 17:52:45 -0700315 setLastAppTransition(TRANSIT_UNSET, null, null);
Jorim Jaggi245281c2017-06-07 14:33:04 -0700316 updateBooster();
Chong Zhang60091a92016-07-27 17:52:45 -0700317 }
318
319 void setLastAppTransition(int transit, AppWindowToken openingApp, AppWindowToken closingApp) {
320 mLastUsedAppTransition = transit;
321 mLastOpeningApp = "" + openingApp;
322 mLastClosingApp = "" + closingApp;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800323 }
324
325 boolean isReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800326 return mAppTransitionState == APP_STATE_READY
327 || mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800328 }
329
Craig Mautnerae446592012-12-06 19:05:05 -0800330 void setReady() {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700331 setAppTransitionState(APP_STATE_READY);
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100332 fetchAppTransitionSpecsFromFuture();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800333 }
334
335 boolean isRunning() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800336 return mAppTransitionState == APP_STATE_RUNNING;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800337 }
338
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800339 void setIdle() {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700340 setAppTransitionState(APP_STATE_IDLE);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800341 }
342
343 boolean isTimeout() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800344 return mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800345 }
346
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800347 void setTimeout() {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700348 setAppTransitionState(APP_STATE_TIMEOUT);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800349 }
350
Winson Chungaa7fa012017-05-24 15:50:06 -0700351 GraphicBuffer getAppTransitionThumbnailHeader(int taskId) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700352 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800353 if (spec == null) {
354 spec = mDefaultNextAppTransitionAnimationSpec;
355 }
Winson Chungaa7fa012017-05-24 15:50:06 -0700356 return spec != null ? spec.buffer : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800357 }
358
Winson Chunga4ccb862014-08-22 15:26:27 -0700359 /** Returns whether the next thumbnail transition is aspect scaled up. */
360 boolean isNextThumbnailTransitionAspectScaled() {
361 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
362 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
363 }
364
365 /** Returns whether the next thumbnail transition is scaling up. */
366 boolean isNextThumbnailTransitionScaleUp() {
367 return mNextAppTransitionScaleUp;
368 }
369
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -0800370 boolean isNextAppTransitionThumbnailUp() {
371 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
372 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP;
373 }
374
375 boolean isNextAppTransitionThumbnailDown() {
376 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN ||
377 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
378 }
379
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100380 /**
381 * @return true if and only if we are currently fetching app transition specs from the future
382 * passed into {@link #overridePendingAppTransitionMultiThumbFuture}
383 */
384 boolean isFetchingAppTransitionsSpecs() {
385 return mNextAppTransitionAnimationsSpecsPending;
386 }
387
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700388 private boolean prepare() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800389 if (!isRunning()) {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700390 setAppTransitionState(APP_STATE_IDLE);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100391 notifyAppTransitionPendingLocked();
Jorim Jaggif97ed922016-02-18 18:57:07 -0800392 mLastHadClipReveal = false;
393 mLastClipRevealMaxTranslation = 0;
394 mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700395 return true;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800396 }
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700397 return false;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800398 }
399
Jorim Jaggife762342016-10-13 14:33:27 +0200400 /**
401 * @return bit-map of WindowManagerPolicy#FINISH_LAYOUT_REDO_* to indicate whether another
402 * layout pass needs to be done
403 */
404 int goodToGo(int transit, AppWindowAnimator topOpeningAppAnimator,
405 AppWindowAnimator topClosingAppAnimator, ArraySet<AppWindowToken> openingApps,
406 ArraySet<AppWindowToken> closingApps) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800407 mNextAppTransition = TRANSIT_UNSET;
Jorim Jaggife762342016-10-13 14:33:27 +0200408 mNextAppTransitionFlags = 0;
Jorim Jaggi245281c2017-06-07 14:33:04 -0700409 setAppTransitionState(APP_STATE_RUNNING);
Jorim Jaggife762342016-10-13 14:33:27 +0200410 int redoLayout = notifyAppTransitionStartingLocked(transit,
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800411 topOpeningAppAnimator != null ? topOpeningAppAnimator.mAppToken.token : null,
412 topClosingAppAnimator != null ? topClosingAppAnimator.mAppToken.token : null,
413 topOpeningAppAnimator != null ? topOpeningAppAnimator.animation : null,
414 topClosingAppAnimator != null ? topClosingAppAnimator.animation : null);
415 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Jorim Jaggife762342016-10-13 14:33:27 +0200416 .notifyAppTransitionStarting(openingApps, transit);
Jorim Jaggi363ab982016-04-26 19:51:20 -0700417
418 // Prolong the start for the transition when docking a task from recents, unless recents
419 // ended it already then we don't need to wait.
Jorim Jaggife762342016-10-13 14:33:27 +0200420 if (transit == TRANSIT_DOCK_TASK_FROM_RECENTS && !mProlongedAnimationsEnded) {
Jorim Jaggi363ab982016-04-26 19:51:20 -0700421 for (int i = openingApps.size() - 1; i >= 0; i--) {
422 final AppWindowAnimator appAnimator = openingApps.valueAt(i).mAppAnimator;
423 appAnimator.startProlongAnimation(PROLONG_ANIMATION_AT_START);
424 }
425 }
Jorim Jaggife762342016-10-13 14:33:27 +0200426 return redoLayout;
Jorim Jaggi363ab982016-04-26 19:51:20 -0700427 }
428
429 /**
430 * Let the transitions manager know that the somebody wanted to end the prolonged animations.
431 */
432 void notifyProlongedAnimationsEnded() {
433 mProlongedAnimationsEnded = true;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800434 }
435
436 void clear() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800437 mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800438 mNextAppTransitionPackage = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700439 mNextAppTransitionAnimationsSpecs.clear();
Jorim Jaggi65193992015-11-23 16:49:59 -0800440 mNextAppTransitionAnimationsSpecsFuture = null;
441 mDefaultNextAppTransitionAnimationSpec = null;
442 mAnimationFinishedCallback = null;
Jorim Jaggi363ab982016-04-26 19:51:20 -0700443 mProlongedAnimationsEnded = false;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800444 }
445
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800446 void freeze() {
Jorim Jaggife762342016-10-13 14:33:27 +0200447 final int transit = mNextAppTransition;
448 setAppTransition(AppTransition.TRANSIT_UNSET, 0 /* flags */);
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800449 clear();
450 setReady();
Jorim Jaggife762342016-10-13 14:33:27 +0200451 notifyAppTransitionCancelledLocked(transit);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100452 }
453
Jorim Jaggi245281c2017-06-07 14:33:04 -0700454 private void setAppTransitionState(int state) {
455 mAppTransitionState = state;
456 updateBooster();
457 }
458
459 /**
460 * Updates whether we currently boost wm locked sections and the animation thread. We want to
461 * boost the priorities to a more important value whenever an app transition is going to happen
462 * soon or an app transition is running.
463 */
464 private void updateBooster() {
465 WindowManagerService.sThreadPriorityBooster.setAppTransitionRunning(
466 mNextAppTransition != TRANSIT_UNSET || mAppTransitionState == APP_STATE_READY
467 || mAppTransitionState == APP_STATE_RUNNING);
468 }
469
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100470 void registerListenerLocked(AppTransitionListener listener) {
471 mListeners.add(listener);
472 }
473
Wale Ogunwalea48eadb2015-05-14 17:43:12 -0700474 public void notifyAppTransitionFinishedLocked(IBinder token) {
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100475 for (int i = 0; i < mListeners.size(); i++) {
476 mListeners.get(i).onAppTransitionFinishedLocked(token);
477 }
478 }
479
480 private void notifyAppTransitionPendingLocked() {
481 for (int i = 0; i < mListeners.size(); i++) {
482 mListeners.get(i).onAppTransitionPendingLocked();
483 }
484 }
485
Jorim Jaggife762342016-10-13 14:33:27 +0200486 private void notifyAppTransitionCancelledLocked(int transit) {
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100487 for (int i = 0; i < mListeners.size(); i++) {
Jorim Jaggife762342016-10-13 14:33:27 +0200488 mListeners.get(i).onAppTransitionCancelledLocked(transit);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100489 }
490 }
491
Jorim Jaggife762342016-10-13 14:33:27 +0200492 private int notifyAppTransitionStartingLocked(int transit, IBinder openToken,
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100493 IBinder closeToken, Animation openAnimation, Animation closeAnimation) {
Jorim Jaggife762342016-10-13 14:33:27 +0200494 int redoLayout = 0;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100495 for (int i = 0; i < mListeners.size(); i++) {
Jorim Jaggife762342016-10-13 14:33:27 +0200496 redoLayout |= mListeners.get(i).onAppTransitionStartingLocked(transit, openToken,
497 closeToken, openAnimation, closeAnimation);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100498 }
Jorim Jaggife762342016-10-13 14:33:27 +0200499 return redoLayout;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800500 }
501
Craig Mautner164d4bb2012-11-26 13:51:23 -0800502 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
503 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg="
504 + (lp != null ? lp.packageName : null)
505 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
506 if (lp != null && lp.windowAnimations != 0) {
507 // If this is a system resource, don't try to load it from the
508 // application resources. It is nice to avoid loading application
509 // resources if we can.
510 String packageName = lp.packageName != null ? lp.packageName : "android";
511 int resId = lp.windowAnimations;
512 if ((resId&0xFF000000) == 0x01000000) {
513 packageName = "android";
514 }
515 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
516 + packageName);
517 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700518 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800519 }
520 return null;
521 }
522
523 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
524 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package="
525 + packageName + " resId=0x" + Integer.toHexString(resId));
526 if (packageName != null) {
527 if ((resId&0xFF000000) == 0x01000000) {
528 packageName = "android";
529 }
530 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
531 + packageName);
532 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700533 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800534 }
535 return null;
536 }
537
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700538 Animation loadAnimationAttr(WindowManager.LayoutParams lp, int animAttr) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800539 int anim = 0;
540 Context context = mContext;
541 if (animAttr >= 0) {
542 AttributeCache.Entry ent = getCachedAnimations(lp);
543 if (ent != null) {
544 context = ent.context;
545 anim = ent.array.getResourceId(animAttr, 0);
546 }
547 }
548 if (anim != 0) {
549 return AnimationUtils.loadAnimation(context, anim);
550 }
551 return null;
552 }
553
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700554 Animation loadAnimationRes(WindowManager.LayoutParams lp, int resId) {
555 Context context = mContext;
556 if (resId >= 0) {
557 AttributeCache.Entry ent = getCachedAnimations(lp);
558 if (ent != null) {
559 context = ent.context;
560 }
561 return AnimationUtils.loadAnimation(context, resId);
562 }
563 return null;
564 }
565
566 private Animation loadAnimationRes(String packageName, int resId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800567 int anim = 0;
568 Context context = mContext;
569 if (resId >= 0) {
570 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
571 if (ent != null) {
572 context = ent.context;
573 anim = resId;
574 }
575 }
576 if (anim != 0) {
577 return AnimationUtils.loadAnimation(context, anim);
578 }
579 return null;
580 }
581
Craig Mautner164d4bb2012-11-26 13:51:23 -0800582 /**
583 * Compute the pivot point for an animation that is scaling from a small
584 * rect on screen to a larger rect. The pivot point varies depending on
585 * the distance between the inner and outer edges on both sides. This
586 * function computes the pivot point for one dimension.
587 * @param startPos Offset from left/top edge of outer rectangle to
588 * left/top edge of inner rectangle.
589 * @param finalScale The scaling factor between the size of the outer
590 * and inner rectangles.
591 */
592 private static float computePivot(int startPos, float finalScale) {
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800593
594 /*
595 Theorem of intercepting lines:
596
597 + + +-----------------------------------------------+
598 | | | |
599 | | | |
600 | | | |
601 | | | |
602 x | y | | |
603 | | | |
604 | | | |
605 | | | |
606 | | | |
607 | + | +--------------------+ |
608 | | | | |
609 | | | | |
610 | | | | |
611 | | | | |
612 | | | | |
613 | | | | |
614 | | | | |
615 | | | | |
616 | | | | |
617 | | | | |
618 | | | | |
619 | | | | |
620 | | | | |
621 | | | | |
622 | | | | |
623 | | | | |
624 | | | | |
625 | | +--------------------+ |
626 | | |
627 | | |
628 | | |
629 | | |
630 | | |
631 | | |
632 | | |
633 | +-----------------------------------------------+
634 |
635 |
636 |
637 |
638 |
639 |
640 |
641 |
642 |
643 + ++
644 p ++
645
646 scale = (x - y) / x
647 <=> x = -y / (scale - 1)
648 */
Craig Mautner164d4bb2012-11-26 13:51:23 -0800649 final float denom = finalScale-1;
650 if (Math.abs(denom) < .0001f) {
651 return startPos;
652 }
653 return -startPos / denom;
654 }
655
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700656 private Animation createScaleUpAnimationLocked(int transit, boolean enter,
657 Rect containingFrame) {
658 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700659 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700660 final int appWidth = containingFrame.width();
661 final int appHeight = containingFrame.height();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800662 if (enter) {
663 // Entering app zooms out from the center of the initial rect.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700664 float scaleW = mTmpRect.width() / (float) appWidth;
665 float scaleH = mTmpRect.height() / (float) appHeight;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800666 Animation scale = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700667 computePivot(mTmpRect.left, scaleW),
Winson4c3fecd2016-07-13 12:29:48 -0700668 computePivot(mTmpRect.top, scaleH));
Craig Mautner321bdf52012-12-18 09:53:24 -0800669 scale.setInterpolator(mDecelerateInterpolator);
670
Craig Mautner164d4bb2012-11-26 13:51:23 -0800671 Animation alpha = new AlphaAnimation(0, 1);
Winson Chunga4ccb862014-08-22 15:26:27 -0700672 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
Craig Mautner321bdf52012-12-18 09:53:24 -0800673
674 AnimationSet set = new AnimationSet(false);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800675 set.addAnimation(scale);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800676 set.addAnimation(alpha);
677 set.setDetachWallpaper(true);
678 a = set;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800679 } else if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
680 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800681 // If we are on top of the wallpaper, we need an animation that
682 // correctly handles the wallpaper staying static behind all of
683 // the animated elements. To do this, will just have the existing
684 // element fade out.
685 a = new AlphaAnimation(1, 0);
686 a.setDetachWallpaper(true);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800687 } else {
Craig Mautner321bdf52012-12-18 09:53:24 -0800688 // For normal animations, the exiting element just holds in place.
689 a = new AlphaAnimation(1, 1);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800690 }
Craig Mautner321bdf52012-12-18 09:53:24 -0800691
692 // Pick the desired duration. If this is an inter-activity transition,
693 // it is the standard duration for that. Otherwise we use the longer
694 // task transition duration.
695 final long duration;
696 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800697 case TRANSIT_ACTIVITY_OPEN:
698 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800699 duration = mConfigShortAnimTime;
700 break;
701 default:
702 duration = DEFAULT_APP_TRANSITION_DURATION;
703 break;
704 }
705 a.setDuration(duration);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800706 a.setFillAfter(true);
Craig Mautner321bdf52012-12-18 09:53:24 -0800707 a.setInterpolator(mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800708 a.initialize(appWidth, appHeight, appWidth, appHeight);
709 return a;
710 }
711
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700712 private void getDefaultNextAppTransitionStartRect(Rect rect) {
713 if (mDefaultNextAppTransitionAnimationSpec == null ||
714 mDefaultNextAppTransitionAnimationSpec.rect == null) {
Jorim Jaggi2550f3f2017-03-14 20:15:59 +0100715 Slog.e(TAG, "Starting rect for app requested, but none available", new Throwable());
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700716 rect.setEmpty();
717 } else {
718 rect.set(mDefaultNextAppTransitionAnimationSpec.rect);
719 }
720 }
721
722 void getNextAppTransitionStartRect(int taskId, Rect rect) {
723 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800724 if (spec == null) {
725 spec = mDefaultNextAppTransitionAnimationSpec;
726 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700727 if (spec == null || spec.rect == null) {
Jorim Jaggi2550f3f2017-03-14 20:15:59 +0100728 Slog.e(TAG, "Starting rect for task: " + taskId + " requested, but not available",
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700729 new Throwable());
730 rect.setEmpty();
731 } else {
732 rect.set(spec.rect);
733 }
734 }
735
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800736 private void putDefaultNextAppTransitionCoordinates(int left, int top, int width, int height,
Winson Chungaa7fa012017-05-24 15:50:06 -0700737 GraphicBuffer buffer) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700738 mDefaultNextAppTransitionAnimationSpec = new AppTransitionAnimationSpec(-1 /* taskId */,
Winson Chungaa7fa012017-05-24 15:50:06 -0700739 buffer, new Rect(left, top, left + width, top + height));
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700740 }
741
Jorim Jaggif97ed922016-02-18 18:57:07 -0800742 /**
743 * @return the duration of the last clip reveal animation
744 */
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800745 long getLastClipRevealTransitionDuration() {
746 return mLastClipRevealTransitionDuration;
747 }
748
749 /**
Jorim Jaggif97ed922016-02-18 18:57:07 -0800750 * @return the maximum distance the app surface is traveling of the last clip reveal animation
751 */
752 int getLastClipRevealMaxTranslation() {
753 return mLastClipRevealMaxTranslation;
754 }
755
756 /**
757 * @return true if in the last app transition had a clip reveal animation, false otherwise
758 */
759 boolean hadClipRevealAnimation() {
760 return mLastHadClipReveal;
761 }
762
763 /**
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800764 * Calculates the duration for the clip reveal animation. If the clip is "cut off", meaning that
765 * the start rect is outside of the target rect, and there is a lot of movement going on.
766 *
767 * @param cutOff whether the start rect was not fully contained by the end rect
768 * @param translationX the total translation the surface moves in x direction
769 * @param translationY the total translation the surfaces moves in y direction
770 * @param displayFrame our display frame
771 *
772 * @return the duration of the clip reveal animation, in milliseconds
773 */
774 private long calculateClipRevealTransitionDuration(boolean cutOff, float translationX,
775 float translationY, Rect displayFrame) {
776 if (!cutOff) {
777 return DEFAULT_APP_TRANSITION_DURATION;
778 }
779 final float fraction = Math.max(Math.abs(translationX) / displayFrame.width(),
780 Math.abs(translationY) / displayFrame.height());
781 return (long) (DEFAULT_APP_TRANSITION_DURATION + fraction *
782 (MAX_CLIP_REVEAL_TRANSITION_DURATION - DEFAULT_APP_TRANSITION_DURATION));
783 }
784
785 private Animation createClipRevealAnimationLocked(int transit, boolean enter, Rect appFrame,
786 Rect displayFrame) {
Chet Haase10e23ab2015-02-11 15:08:38 -0800787 final Animation anim;
788 if (enter) {
Craig Mautner80b1f642015-04-22 10:59:09 -0700789 final int appWidth = appFrame.width();
790 final int appHeight = appFrame.height();
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800791
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700792 // mTmpRect will contain an area around the launcher icon that was pressed. We will
Filip Gruszczynski82861362015-10-16 14:21:09 -0700793 // clip reveal from that area in the final area of the app.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700794 getDefaultNextAppTransitionStartRect(mTmpRect);
Craig Mautner80b1f642015-04-22 10:59:09 -0700795
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700796 float t = 0f;
797 if (appHeight > 0) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800798 t = (float) mTmpRect.top / displayFrame.height();
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700799 }
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800800 int translationY = mClipRevealTranslationY + (int)(displayFrame.height() / 7f * t);
801 int translationX = 0;
802 int translationYCorrection = translationY;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700803 int centerX = mTmpRect.centerX();
804 int centerY = mTmpRect.centerY();
805 int halfWidth = mTmpRect.width() / 2;
806 int halfHeight = mTmpRect.height() / 2;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800807 int clipStartX = centerX - halfWidth - appFrame.left;
808 int clipStartY = centerY - halfHeight - appFrame.top;
809 boolean cutOff = false;
810
811 // If the starting rectangle is fully or partially outside of the target rectangle, we
812 // need to start the clipping at the edge and then achieve the rest with translation
813 // and extending the clip rect from that edge.
814 if (appFrame.top > centerY - halfHeight) {
815 translationY = (centerY - halfHeight) - appFrame.top;
816 translationYCorrection = 0;
817 clipStartY = 0;
818 cutOff = true;
819 }
820 if (appFrame.left > centerX - halfWidth) {
821 translationX = (centerX - halfWidth) - appFrame.left;
822 clipStartX = 0;
823 cutOff = true;
824 }
825 if (appFrame.right < centerX + halfWidth) {
826 translationX = (centerX + halfWidth) - appFrame.right;
827 clipStartX = appWidth - mTmpRect.width();
828 cutOff = true;
829 }
830 final long duration = calculateClipRevealTransitionDuration(cutOff, translationX,
831 translationY, displayFrame);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700832
833 // Clip third of the from size of launch icon, expand to full width/height
Chet Haase10e23ab2015-02-11 15:08:38 -0800834 Animation clipAnimLR = new ClipRectLRAnimation(
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800835 clipStartX, clipStartX + mTmpRect.width(), 0, appWidth);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700836 clipAnimLR.setInterpolator(mClipHorizontalInterpolator);
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800837 clipAnimLR.setDuration((long) (duration / 2.5f));
Filip Gruszczynski82861362015-10-16 14:21:09 -0700838
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800839 TranslateAnimation translate = new TranslateAnimation(translationX, 0, translationY, 0);
840 translate.setInterpolator(cutOff ? TOUCH_RESPONSE_INTERPOLATOR
841 : mLinearOutSlowInInterpolator);
842 translate.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800843
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800844 Animation clipAnimTB = new ClipRectTBAnimation(
845 clipStartY, clipStartY + mTmpRect.height(),
846 0, appHeight,
847 translationYCorrection, 0,
848 mLinearOutSlowInInterpolator);
849 clipAnimTB.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
850 clipAnimTB.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800851
852 // Quick fade-in from icon to app window
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800853 final long alphaDuration = duration / 4;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700854 AlphaAnimation alpha = new AlphaAnimation(0.5f, 1);
Chet Haase10e23ab2015-02-11 15:08:38 -0800855 alpha.setDuration(alphaDuration);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700856 alpha.setInterpolator(mLinearOutSlowInInterpolator);
Chet Haase10e23ab2015-02-11 15:08:38 -0800857
858 AnimationSet set = new AnimationSet(false);
859 set.addAnimation(clipAnimLR);
860 set.addAnimation(clipAnimTB);
Filip Gruszczynski82861362015-10-16 14:21:09 -0700861 set.addAnimation(translate);
Chet Haase10e23ab2015-02-11 15:08:38 -0800862 set.addAnimation(alpha);
Filip Gruszczynski9e2cf5b2015-07-31 12:20:40 -0700863 set.setZAdjustment(Animation.ZORDER_TOP);
Chet Haase10e23ab2015-02-11 15:08:38 -0800864 set.initialize(appWidth, appHeight, appWidth, appHeight);
865 anim = set;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800866 mLastHadClipReveal = true;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800867 mLastClipRevealTransitionDuration = duration;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800868
869 // If the start rect was full inside the target rect (cutOff == false), we don't need
870 // to store the translation, because it's only used if cutOff == true.
871 mLastClipRevealMaxTranslation = cutOff
872 ? Math.max(Math.abs(translationY), Math.abs(translationX)) : 0;
Chet Haase10e23ab2015-02-11 15:08:38 -0800873 } else {
874 final long duration;
875 switch (transit) {
876 case TRANSIT_ACTIVITY_OPEN:
877 case TRANSIT_ACTIVITY_CLOSE:
878 duration = mConfigShortAnimTime;
879 break;
880 default:
881 duration = DEFAULT_APP_TRANSITION_DURATION;
882 break;
883 }
884 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
885 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
886 // If we are on top of the wallpaper, we need an animation that
887 // correctly handles the wallpaper staying static behind all of
888 // the animated elements. To do this, will just have the existing
889 // element fade out.
890 anim = new AlphaAnimation(1, 0);
891 anim.setDetachWallpaper(true);
892 } else {
893 // For normal animations, the exiting element just holds in place.
894 anim = new AlphaAnimation(1, 1);
895 }
896 anim.setInterpolator(mDecelerateInterpolator);
897 anim.setDuration(duration);
898 anim.setFillAfter(true);
899 }
900 return anim;
901 }
902
Winson Chung399f6202014-03-19 10:47:20 -0700903 /**
904 * Prepares the specified animation with a standard duration, interpolator, etc.
905 */
Winson Chung5393dff2014-05-08 14:25:43 -0700906 Animation prepareThumbnailAnimationWithDuration(Animation a, int appWidth, int appHeight,
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100907 long duration, Interpolator interpolator) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700908 if (duration > 0) {
909 a.setDuration(duration);
910 }
Winson Chung5393dff2014-05-08 14:25:43 -0700911 a.setFillAfter(true);
Jorim Jaggic69bd222016-03-15 14:38:37 +0100912 if (interpolator != null) {
913 a.setInterpolator(interpolator);
914 }
Winson Chung5393dff2014-05-08 14:25:43 -0700915 a.initialize(appWidth, appHeight, appWidth, appHeight);
916 return a;
917 }
918
919 /**
920 * Prepares the specified animation with a standard duration, interpolator, etc.
921 */
Winson Chung399f6202014-03-19 10:47:20 -0700922 Animation prepareThumbnailAnimation(Animation a, int appWidth, int appHeight, int transit) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800923 // Pick the desired duration. If this is an inter-activity transition,
924 // it is the standard duration for that. Otherwise we use the longer
925 // task transition duration.
Winson Chung5393dff2014-05-08 14:25:43 -0700926 final int duration;
Craig Mautner321bdf52012-12-18 09:53:24 -0800927 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800928 case TRANSIT_ACTIVITY_OPEN:
929 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800930 duration = mConfigShortAnimTime;
931 break;
932 default:
933 duration = DEFAULT_APP_TRANSITION_DURATION;
934 break;
935 }
Winson Chung5393dff2014-05-08 14:25:43 -0700936 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, duration,
937 mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800938 }
939
Winson Chung399f6202014-03-19 10:47:20 -0700940 /**
941 * Return the current thumbnail transition state.
942 */
943 int getThumbnailTransitionState(boolean enter) {
944 if (enter) {
945 if (mNextAppTransitionScaleUp) {
946 return THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
947 } else {
948 return THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN;
949 }
950 } else {
951 if (mNextAppTransitionScaleUp) {
952 return THUMBNAIL_TRANSITION_EXIT_SCALE_UP;
953 } else {
954 return THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN;
955 }
956 }
957 }
958
959 /**
960 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700961 * when a thumbnail is specified with the pending animation override.
Winson Chung399f6202014-03-19 10:47:20 -0700962 */
Jorim Jaggide63d442016-03-14 14:56:56 +0100963 Animation createThumbnailAspectScaleAnimationLocked(Rect appRect, @Nullable Rect contentInsets,
Winson Chungaa7fa012017-05-24 15:50:06 -0700964 GraphicBuffer thumbnailHeader, final int taskId, int uiMode, int orientation) {
Winson Chung399f6202014-03-19 10:47:20 -0700965 Animation a;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700966 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chung399f6202014-03-19 10:47:20 -0700967 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700968 final int thumbHeightI = thumbnailHeader.getHeight();
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700969 final int appWidth = appRect.width();
Winson Chung399f6202014-03-19 10:47:20 -0700970
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700971 float scaleW = appWidth / thumbWidth;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700972 getNextAppTransitionStartRect(taskId, mTmpRect);
Jorim Jaggi09072002016-03-25 16:48:42 -0700973 final float fromX;
Manu Cornet57b61492017-01-24 18:19:05 +0900974 float fromY;
Jorim Jaggi09072002016-03-25 16:48:42 -0700975 final float toX;
Manu Cornet57b61492017-01-24 18:19:05 +0900976 float toY;
Jorim Jaggi09072002016-03-25 16:48:42 -0700977 final float pivotX;
978 final float pivotY;
Manu Cornetd7376802017-01-13 13:44:07 -0800979 if (shouldScaleDownThumbnailTransition(uiMode, orientation)) {
Jorim Jaggi09072002016-03-25 16:48:42 -0700980 fromX = mTmpRect.left;
981 fromY = mTmpRect.top;
982
983 // For the curved translate animation to work, the pivot points needs to be at the
984 // same absolute position as the one from the real surface.
985 toX = mTmpRect.width() / 2 * (scaleW - 1f) + appRect.left;
986 toY = appRect.height() / 2 * (1 - 1 / scaleW) + appRect.top;
987 pivotX = mTmpRect.width() / 2;
988 pivotY = appRect.height() / 2 / scaleW;
Manu Cornet57b61492017-01-24 18:19:05 +0900989 if (mGridLayoutRecentsEnabled) {
990 // In the grid layout, the header is displayed above the thumbnail instead of
991 // overlapping it.
992 fromY -= thumbHeightI;
993 toY -= thumbHeightI * scaleW;
994 }
Jorim Jaggi09072002016-03-25 16:48:42 -0700995 } else {
996 pivotX = 0;
997 pivotY = 0;
998 fromX = mTmpRect.left;
999 fromY = mTmpRect.top;
1000 toX = appRect.left;
1001 toY = appRect.top;
1002 }
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001003 final long duration = getAspectScaleDuration();
1004 final Interpolator interpolator = getAspectScaleInterpolator();
Winson Chung399f6202014-03-19 10:47:20 -07001005 if (mNextAppTransitionScaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001006 // Animation up from the thumbnail to the full screen
Jorim Jaggi8448f332016-03-14 17:50:37 +01001007 Animation scale = new ScaleAnimation(1f, scaleW, 1f, scaleW, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001008 scale.setInterpolator(interpolator);
1009 scale.setDuration(duration);
Jorim Jaggic6c89a82016-01-28 17:48:21 -08001010 Animation alpha = new AlphaAnimation(1f, 0f);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001011 alpha.setInterpolator(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
1012 ? THUMBNAIL_DOCK_INTERPOLATOR : mThumbnailFadeOutInterpolator);
1013 alpha.setDuration(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
1014 ? duration / 2
1015 : duration);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001016 Animation translate = createCurvedMotion(fromX, toX, fromY, toY);
1017 translate.setInterpolator(interpolator);
1018 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -07001019
Jorim Jaggide63d442016-03-14 14:56:56 +01001020 mTmpFromClipRect.set(0, 0, thumbWidthI, thumbHeightI);
1021 mTmpToClipRect.set(appRect);
1022
1023 // Containing frame is in screen space, but we need the clip rect in the
1024 // app space.
1025 mTmpToClipRect.offsetTo(0, 0);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001026 mTmpToClipRect.right = (int) (mTmpToClipRect.right / scaleW);
1027 mTmpToClipRect.bottom = (int) (mTmpToClipRect.bottom / scaleW);
Jorim Jaggide63d442016-03-14 14:56:56 +01001028
1029 if (contentInsets != null) {
Jorim Jaggi8448f332016-03-14 17:50:37 +01001030 mTmpToClipRect.inset((int) (-contentInsets.left * scaleW),
1031 (int) (-contentInsets.top * scaleW),
1032 (int) (-contentInsets.right * scaleW),
1033 (int) (-contentInsets.bottom * scaleW));
Jorim Jaggide63d442016-03-14 14:56:56 +01001034 }
1035
1036 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001037 clipAnim.setInterpolator(interpolator);
1038 clipAnim.setDuration(duration);
Jorim Jaggide63d442016-03-14 14:56:56 +01001039
Winson Chung399f6202014-03-19 10:47:20 -07001040 // This AnimationSet uses the Interpolators assigned above.
1041 AnimationSet set = new AnimationSet(false);
1042 set.addAnimation(scale);
Manu Cornet57b61492017-01-24 18:19:05 +09001043 if (!mGridLayoutRecentsEnabled) {
1044 // In the grid layout, the header should be shown for the whole animation.
1045 set.addAnimation(alpha);
1046 }
Winson Chunga4ccb862014-08-22 15:26:27 -07001047 set.addAnimation(translate);
Jorim Jaggide63d442016-03-14 14:56:56 +01001048 set.addAnimation(clipAnim);
Winson Chung399f6202014-03-19 10:47:20 -07001049 a = set;
1050 } else {
Winson Chunga4ccb862014-08-22 15:26:27 -07001051 // Animation down from the full screen to the thumbnail
Jorim Jaggi8448f332016-03-14 17:50:37 +01001052 Animation scale = new ScaleAnimation(scaleW, 1f, scaleW, 1f, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001053 scale.setInterpolator(interpolator);
1054 scale.setDuration(duration);
Winson Chunga4ccb862014-08-22 15:26:27 -07001055 Animation alpha = new AlphaAnimation(0f, 1f);
1056 alpha.setInterpolator(mThumbnailFadeInInterpolator);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001057 alpha.setDuration(duration);
1058 Animation translate = createCurvedMotion(toX, fromX, toY, fromY);
1059 translate.setInterpolator(interpolator);
1060 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -07001061
Winson Chunga4ccb862014-08-22 15:26:27 -07001062 // This AnimationSet uses the Interpolators assigned above.
1063 AnimationSet set = new AnimationSet(false);
1064 set.addAnimation(scale);
Manu Cornet57b61492017-01-24 18:19:05 +09001065 if (!mGridLayoutRecentsEnabled) {
1066 // In the grid layout, the header should be shown for the whole animation.
1067 set.addAnimation(alpha);
1068 }
Winson Chunga4ccb862014-08-22 15:26:27 -07001069 set.addAnimation(translate);
1070 a = set;
1071
1072 }
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -07001073 return prepareThumbnailAnimationWithDuration(a, appWidth, appRect.height(), 0,
Jorim Jaggic69bd222016-03-15 14:38:37 +01001074 null);
Winson Chung399f6202014-03-19 10:47:20 -07001075 }
1076
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001077 private Animation createCurvedMotion(float fromX, float toX, float fromY, float toY) {
1078
1079 // Almost no x-change - use linear animation
Jorim Jaggic69bd222016-03-15 14:38:37 +01001080 if (Math.abs(toX - fromX) < 1f || mNextAppTransition != TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001081 return new TranslateAnimation(fromX, toX, fromY, toY);
1082 } else {
1083 final Path path = createCurvedPath(fromX, toX, fromY, toY);
1084 return new CurvedTranslateAnimation(path);
1085 }
1086 }
1087
1088 private Path createCurvedPath(float fromX, float toX, float fromY, float toY) {
1089 final Path path = new Path();
1090 path.moveTo(fromX, fromY);
Jorim Jaggi1f458fb2016-03-25 17:36:37 -07001091
1092 if (fromY > toY) {
1093 // If the object needs to go up, move it in horizontal direction first, then vertical.
1094 path.cubicTo(fromX, fromY, toX, 0.9f * fromY + 0.1f * toY, toX, toY);
1095 } else {
1096 // If the object needs to go down, move it in vertical direction first, then horizontal.
1097 path.cubicTo(fromX, fromY, fromX, 0.1f * fromY + 0.9f * toY, toX, toY);
1098 }
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001099 return path;
1100 }
1101
1102 private long getAspectScaleDuration() {
1103 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggic69bd222016-03-15 14:38:37 +01001104 return (long) (THUMBNAIL_APP_TRANSITION_DURATION * 1.35f);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001105 } else {
1106 return THUMBNAIL_APP_TRANSITION_DURATION;
1107 }
1108 }
1109
1110 private Interpolator getAspectScaleInterpolator() {
1111 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
1112 return mFastOutSlowInInterpolator;
1113 } else {
1114 return TOUCH_RESPONSE_INTERPOLATOR;
1115 }
1116 }
1117
Winson Chung399f6202014-03-19 10:47:20 -07001118 /**
1119 * This alternate animation is created when we are doing a thumbnail transition, for the
1120 * activity that is leaving, and the activity that is entering.
1121 */
Winson Chunga4ccb862014-08-22 15:26:27 -07001122 Animation createAspectScaledThumbnailEnterExitAnimationLocked(int thumbTransitState,
Winsonb2024762016-04-05 17:32:30 -07001123 int uiMode, int orientation, int transit, Rect containingFrame, Rect contentInsets,
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001124 @Nullable Rect surfaceInsets, boolean freeform, int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -07001125 Animation a;
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001126 final int appWidth = containingFrame.width();
1127 final int appHeight = containingFrame.height();
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001128 getDefaultNextAppTransitionStartRect(mTmpRect);
1129 final int thumbWidthI = mTmpRect.width();
Winson Chung399f6202014-03-19 10:47:20 -07001130 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001131 final int thumbHeightI = mTmpRect.height();
Winson Chung399f6202014-03-19 10:47:20 -07001132 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
Winsoncbb625b2016-07-06 15:24:15 -07001133 final int thumbStartX = mTmpRect.left - containingFrame.left - contentInsets.left;
Winson21700932016-03-24 17:26:23 -07001134 final int thumbStartY = mTmpRect.top - containingFrame.top;
Winson Chung399f6202014-03-19 10:47:20 -07001135
1136 switch (thumbTransitState) {
Jorim Jaggi8448f332016-03-14 17:50:37 +01001137 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP:
1138 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1139 final boolean scaleUp = thumbTransitState == THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
1140 if (freeform && scaleUp) {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001141 a = createAspectScaledThumbnailEnterFreeformAnimationLocked(
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001142 containingFrame, surfaceInsets, taskId);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001143 } else if (freeform) {
1144 a = createAspectScaledThumbnailExitFreeformAnimationLocked(
1145 containingFrame, surfaceInsets, taskId);
Winson Chung2820c452014-04-15 15:34:44 -07001146 } else {
Winson21700932016-03-24 17:26:23 -07001147 AnimationSet set = new AnimationSet(true);
1148
1149 // In portrait, we scale to fit the width
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001150 mTmpFromClipRect.set(containingFrame);
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001151 mTmpToClipRect.set(containingFrame);
Jorim Jaggic6c89a82016-01-28 17:48:21 -08001152
1153 // Containing frame is in screen space, but we need the clip rect in the
1154 // app space.
1155 mTmpFromClipRect.offsetTo(0, 0);
1156 mTmpToClipRect.offsetTo(0, 0);
1157
1158 // Exclude insets region from the source clip.
1159 mTmpFromClipRect.inset(contentInsets);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001160 mNextAppTransitionInsets.set(contentInsets);
1161
Manu Cornetd7376802017-01-13 13:44:07 -08001162 if (shouldScaleDownThumbnailTransition(uiMode, orientation)) {
Jorim Jaggic69bd222016-03-15 14:38:37 +01001163 // We scale the width and clip to the top/left square
1164 float scale = thumbWidth /
1165 (appWidth - contentInsets.left - contentInsets.right);
Manu Cornetb68b7652017-01-23 19:37:53 +09001166 if (!mGridLayoutRecentsEnabled) {
1167 int unscaledThumbHeight = (int) (thumbHeight / scale);
1168 mTmpFromClipRect.bottom = mTmpFromClipRect.top + unscaledThumbHeight;
1169 }
Jorim Jaggic69bd222016-03-15 14:38:37 +01001170
1171 mNextAppTransitionInsets.set(contentInsets);
1172
Jorim Jaggi8448f332016-03-14 17:50:37 +01001173 Animation scaleAnim = new ScaleAnimation(
1174 scaleUp ? scale : 1, scaleUp ? 1 : scale,
1175 scaleUp ? scale : 1, scaleUp ? 1 : scale,
Jorim Jaggic69bd222016-03-15 14:38:37 +01001176 containingFrame.width() / 2f,
1177 containingFrame.height() / 2f + contentInsets.top);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001178 final float targetX = (mTmpRect.left - containingFrame.left);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001179 final float x = containingFrame.width() / 2f
1180 - containingFrame.width() / 2f * scale;
Jorim Jaggi8448f332016-03-14 17:50:37 +01001181 final float targetY = (mTmpRect.top - containingFrame.top);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001182 final float y = containingFrame.height() / 2f
1183 - containingFrame.height() / 2f * scale;
Jorim Jaggi8448f332016-03-14 17:50:37 +01001184 final float startX = targetX - x;
1185 final float startY = targetY - y;
1186 Animation clipAnim = scaleUp
1187 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1188 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1189 Animation translateAnim = scaleUp
Jorim Jaggic69bd222016-03-15 14:38:37 +01001190 ? createCurvedMotion(startX, 0, startY - contentInsets.top, 0)
1191 : createCurvedMotion(0, startX, 0, startY - contentInsets.top);
1192
Winson21700932016-03-24 17:26:23 -07001193 set.addAnimation(clipAnim);
1194 set.addAnimation(scaleAnim);
1195 set.addAnimation(translateAnim);
1196
1197 } else {
1198 // In landscape, we don't scale at all and only crop
1199 mTmpFromClipRect.bottom = mTmpFromClipRect.top + thumbHeightI;
1200 mTmpFromClipRect.right = mTmpFromClipRect.left + thumbWidthI;
1201
Jorim Jaggi8448f332016-03-14 17:50:37 +01001202 Animation clipAnim = scaleUp
1203 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1204 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1205 Animation translateAnim = scaleUp
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001206 ? createCurvedMotion(thumbStartX, 0,
1207 thumbStartY - contentInsets.top, 0)
1208 : createCurvedMotion(0, thumbStartX, 0,
1209 thumbStartY - contentInsets.top);
Winson21700932016-03-24 17:26:23 -07001210
1211 set.addAnimation(clipAnim);
1212 set.addAnimation(translateAnim);
1213 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001214 a = set;
Winson21700932016-03-24 17:26:23 -07001215 a.setZAdjustment(Animation.ZORDER_TOP);
Winson Chung2820c452014-04-15 15:34:44 -07001216 }
Winson Chung399f6202014-03-19 10:47:20 -07001217 break;
1218 }
1219 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001220 // Previous app window during the scale up
Winson Chung399f6202014-03-19 10:47:20 -07001221 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001222 // Fade out the source activity if we are animating to a wallpaper
Winson Chung399f6202014-03-19 10:47:20 -07001223 // activity.
1224 a = new AlphaAnimation(1, 0);
1225 } else {
Winson Chung399f6202014-03-19 10:47:20 -07001226 a = new AlphaAnimation(1, 1);
1227 }
1228 break;
1229 }
1230 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001231 // Target app window during the scale down
1232 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1233 // Fade in the destination activity if we are animating from a wallpaper
1234 // activity.
1235 a = new AlphaAnimation(0, 1);
1236 } else {
1237 a = new AlphaAnimation(1, 1);
1238 }
Winson Chung399f6202014-03-19 10:47:20 -07001239 break;
1240 }
Winson Chung399f6202014-03-19 10:47:20 -07001241 default:
1242 throw new RuntimeException("Invalid thumbnail transition state");
1243 }
1244
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001245 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight,
1246 getAspectScaleDuration(), getAspectScaleInterpolator());
Winson Chung399f6202014-03-19 10:47:20 -07001247 }
1248
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001249 private Animation createAspectScaledThumbnailEnterFreeformAnimationLocked(Rect frame,
1250 @Nullable Rect surfaceInsets, int taskId) {
1251 getNextAppTransitionStartRect(taskId, mTmpRect);
1252 return createAspectScaledThumbnailFreeformAnimationLocked(mTmpRect, frame, surfaceInsets,
1253 true);
1254 }
1255
1256 private Animation createAspectScaledThumbnailExitFreeformAnimationLocked(Rect frame,
1257 @Nullable Rect surfaceInsets, int taskId) {
1258 getNextAppTransitionStartRect(taskId, mTmpRect);
1259 return createAspectScaledThumbnailFreeformAnimationLocked(frame, mTmpRect, surfaceInsets,
1260 false);
1261 }
1262
1263 private AnimationSet createAspectScaledThumbnailFreeformAnimationLocked(Rect sourceFrame,
1264 Rect destFrame, @Nullable Rect surfaceInsets, boolean enter) {
1265 final float sourceWidth = sourceFrame.width();
1266 final float sourceHeight = sourceFrame.height();
1267 final float destWidth = destFrame.width();
1268 final float destHeight = destFrame.height();
1269 final float scaleH = enter ? sourceWidth / destWidth : destWidth / sourceWidth;
1270 final float scaleV = enter ? sourceHeight / destHeight : destHeight / sourceHeight;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001271 AnimationSet set = new AnimationSet(true);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001272 final int surfaceInsetsH = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001273 ? 0 : surfaceInsets.left + surfaceInsets.right;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001274 final int surfaceInsetsV = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001275 ? 0 : surfaceInsets.top + surfaceInsets.bottom;
1276 // We want the scaling to happen from the center of the surface. In order to achieve that,
1277 // we need to account for surface insets that will be used to enlarge the surface.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001278 final float scaleHCenter = ((enter ? destWidth : sourceWidth) + surfaceInsetsH) / 2;
1279 final float scaleVCenter = ((enter ? destHeight : sourceHeight) + surfaceInsetsV) / 2;
1280 final ScaleAnimation scale = enter ?
1281 new ScaleAnimation(scaleH, 1, scaleV, 1, scaleHCenter, scaleVCenter)
1282 : new ScaleAnimation(1, scaleH, 1, scaleV, scaleHCenter, scaleVCenter);
1283 final int sourceHCenter = sourceFrame.left + sourceFrame.width() / 2;
1284 final int sourceVCenter = sourceFrame.top + sourceFrame.height() / 2;
1285 final int destHCenter = destFrame.left + destFrame.width() / 2;
1286 final int destVCenter = destFrame.top + destFrame.height() / 2;
1287 final int fromX = enter ? sourceHCenter - destHCenter : destHCenter - sourceHCenter;
1288 final int fromY = enter ? sourceVCenter - destVCenter : destVCenter - sourceVCenter;
1289 final TranslateAnimation translation = enter ? new TranslateAnimation(fromX, 0, fromY, 0)
1290 : new TranslateAnimation(0, fromX, 0, fromY);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001291 set.addAnimation(scale);
1292 set.addAnimation(translation);
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001293
1294 final IRemoteCallback callback = mAnimationFinishedCallback;
1295 if (callback != null) {
1296 set.setAnimationListener(new Animation.AnimationListener() {
1297 @Override
1298 public void onAnimationStart(Animation animation) { }
1299
1300 @Override
1301 public void onAnimationEnd(Animation animation) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001302 mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK, callback).sendToTarget();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001303 }
1304
1305 @Override
1306 public void onAnimationRepeat(Animation animation) { }
1307 });
1308 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001309 return set;
1310 }
1311
Winson Chung399f6202014-03-19 10:47:20 -07001312 /**
Winson Chunga4ccb862014-08-22 15:26:27 -07001313 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001314 * when a thumbnail is specified with the pending animation override.
Winson Chunga4ccb862014-08-22 15:26:27 -07001315 */
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001316 Animation createThumbnailScaleAnimationLocked(int appWidth, int appHeight, int transit,
Winson Chungaa7fa012017-05-24 15:50:06 -07001317 GraphicBuffer thumbnailHeader) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001318 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001319 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001320 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chunga4ccb862014-08-22 15:26:27 -07001321 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001322 final int thumbHeightI = thumbnailHeader.getHeight();
Winson Chunga4ccb862014-08-22 15:26:27 -07001323 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1324
1325 if (mNextAppTransitionScaleUp) {
1326 // Animation for the thumbnail zooming from its initial size to the full screen
1327 float scaleW = appWidth / thumbWidth;
1328 float scaleH = appHeight / thumbHeight;
1329 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001330 computePivot(mTmpRect.left, 1 / scaleW),
1331 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001332 scale.setInterpolator(mDecelerateInterpolator);
1333
1334 Animation alpha = new AlphaAnimation(1, 0);
1335 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
1336
1337 // This AnimationSet uses the Interpolators assigned above.
1338 AnimationSet set = new AnimationSet(false);
1339 set.addAnimation(scale);
1340 set.addAnimation(alpha);
1341 a = set;
1342 } else {
1343 // Animation for the thumbnail zooming down from the full screen to its final size
1344 float scaleW = appWidth / thumbWidth;
1345 float scaleH = appHeight / thumbHeight;
1346 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001347 computePivot(mTmpRect.left, 1 / scaleW),
1348 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001349 }
1350
1351 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1352 }
1353
1354 /**
Winson Chung399f6202014-03-19 10:47:20 -07001355 * This animation is created when we are doing a thumbnail transition, for the activity that is
1356 * leaving, and the activity that is entering.
1357 */
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001358 Animation createThumbnailEnterExitAnimationLocked(int thumbTransitState, Rect containingFrame,
1359 int transit, int taskId) {
1360 final int appWidth = containingFrame.width();
1361 final int appHeight = containingFrame.height();
Winson Chungaa7fa012017-05-24 15:50:06 -07001362 final GraphicBuffer thumbnailHeader = getAppTransitionThumbnailHeader(taskId);
Winson Chung399f6202014-03-19 10:47:20 -07001363 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001364 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001365 final int thumbWidthI = thumbnailHeader != null ? thumbnailHeader.getWidth() : appWidth;
Winson Chung399f6202014-03-19 10:47:20 -07001366 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001367 final int thumbHeightI = thumbnailHeader != null ? thumbnailHeader.getHeight() : appHeight;
Winson Chung399f6202014-03-19 10:47:20 -07001368 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1369
1370 switch (thumbTransitState) {
1371 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
1372 // Entering app scales up with the thumbnail
1373 float scaleW = thumbWidth / appWidth;
1374 float scaleH = thumbHeight / appHeight;
1375 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001376 computePivot(mTmpRect.left, scaleW),
1377 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001378 break;
1379 }
1380 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
1381 // Exiting app while the thumbnail is scaling up should fade or stay in place
1382 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1383 // Fade out while bringing up selected activity. This keeps the
1384 // current activity from showing through a launching wallpaper
1385 // activity.
1386 a = new AlphaAnimation(1, 0);
1387 } else {
1388 // noop animation
1389 a = new AlphaAnimation(1, 1);
1390 }
1391 break;
1392 }
1393 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
1394 // Entering the other app, it should just be visible while we scale the thumbnail
1395 // down above it
1396 a = new AlphaAnimation(1, 1);
1397 break;
1398 }
1399 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1400 // Exiting the current app, the app should scale down with the thumbnail
1401 float scaleW = thumbWidth / appWidth;
1402 float scaleH = thumbHeight / appHeight;
1403 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001404 computePivot(mTmpRect.left, scaleW),
1405 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001406
1407 Animation alpha = new AlphaAnimation(1, 0);
1408
1409 AnimationSet set = new AnimationSet(true);
1410 set.addAnimation(scale);
1411 set.addAnimation(alpha);
1412 set.setZAdjustment(Animation.ZORDER_TOP);
1413 a = set;
1414 break;
1415 }
1416 default:
1417 throw new RuntimeException("Invalid thumbnail transition state");
1418 }
1419
1420 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1421 }
1422
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001423 private Animation createRelaunchAnimation(Rect containingFrame, Rect contentInsets) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001424 getDefaultNextAppTransitionStartRect(mTmpFromClipRect);
1425 final int left = mTmpFromClipRect.left;
1426 final int top = mTmpFromClipRect.top;
1427 mTmpFromClipRect.offset(-left, -top);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001428 // TODO: Isn't that strange that we ignore exact position of the containingFrame?
1429 mTmpToClipRect.set(0, 0, containingFrame.width(), containingFrame.height());
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001430 AnimationSet set = new AnimationSet(true);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001431 float fromWidth = mTmpFromClipRect.width();
1432 float toWidth = mTmpToClipRect.width();
1433 float fromHeight = mTmpFromClipRect.height();
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001434 // While the window might span the whole display, the actual content will be cropped to the
1435 // system decoration frame, for example when the window is docked. We need to take into
1436 // account the visible height when constructing the animation.
1437 float toHeight = mTmpToClipRect.height() - contentInsets.top - contentInsets.bottom;
1438 int translateAdjustment = 0;
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001439 if (fromWidth <= toWidth && fromHeight <= toHeight) {
1440 // The final window is larger in both dimensions than current window (e.g. we are
1441 // maximizing), so we can simply unclip the new window and there will be no disappearing
1442 // frame.
1443 set.addAnimation(new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect));
1444 } else {
1445 // The disappearing window has one larger dimension. We need to apply scaling, so the
1446 // first frame of the entry animation matches the old window.
1447 set.addAnimation(new ScaleAnimation(fromWidth / toWidth, 1, fromHeight / toHeight, 1));
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001448 // We might not be going exactly full screen, but instead be aligned under the status
1449 // bar using cropping. We still need to account for the cropped part, which will also
1450 // be scaled.
1451 translateAdjustment = (int) (contentInsets.top * fromHeight / toHeight);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001452 }
1453
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001454 // We animate the translation from the old position of the removed window, to the new
1455 // position of the added window. The latter might not be full screen, for example docked for
1456 // docked windows.
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001457 TranslateAnimation translate = new TranslateAnimation(left - containingFrame.left,
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001458 0, top - containingFrame.top - translateAdjustment, 0);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001459 set.addAnimation(translate);
1460 set.setDuration(DEFAULT_APP_TRANSITION_DURATION);
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07001461 set.setZAdjustment(Animation.ZORDER_TOP);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001462 return set;
1463 }
1464
Jorim Jaggic554b772015-06-04 16:07:57 -07001465 /**
1466 * @return true if and only if the first frame of the transition can be skipped, i.e. the first
1467 * frame of the transition doesn't change the visuals on screen, so we can start
1468 * directly with the second one
1469 */
1470 boolean canSkipFirstFrame() {
1471 return mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM
1472 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE
Jorim Jaggife762342016-10-13 14:33:27 +02001473 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CLIP_REVEAL
1474 && mNextAppTransition != TRANSIT_KEYGUARD_GOING_AWAY;
Jorim Jaggic554b772015-06-04 16:07:57 -07001475 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001476
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001477 /**
1478 *
1479 * @param frame These are the bounds of the window when it finishes the animation. This is where
1480 * the animation must usually finish in entrance animation, as the next frame will
1481 * display the window at these coordinates. In case of exit animation, this is
1482 * where the animation must start, as the frame before the animation is displaying
1483 * the window at these bounds.
1484 * @param insets Knowing where the window will be positioned is not enough. Some parts of the
1485 * window might be obscured, usually by the system windows (status bar and
1486 * navigation bar) and we use content insets to convey that information. This
1487 * usually affects the animation aspects vertically, as the system decoration is
1488 * at the top and the bottom. For example when we animate from full screen to
1489 * recents, we want to exclude the covered parts, because they won't match the
1490 * thumbnail after the last frame is executed.
1491 * @param surfaceInsets In rare situation the surface is larger than the content and we need to
1492 * know about this to make the animation frames match. We currently use
1493 * this for freeform windows, which have larger surfaces to display
1494 * shadows. When we animate them from recents, we want to match the content
1495 * to the recents thumbnail and hence need to account for the surface being
1496 * bigger.
1497 */
Winsonb2024762016-04-05 17:32:30 -07001498 Animation loadAnimation(WindowManager.LayoutParams lp, int transit, boolean enter, int uiMode,
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001499 int orientation, Rect frame, Rect displayFrame, Rect insets,
1500 @Nullable Rect surfaceInsets, boolean isVoiceInteraction, boolean freeform,
1501 int taskId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001502 Animation a;
Jorim Jaggife762342016-10-13 14:33:27 +02001503 if (isKeyguardGoingAwayTransit(transit) && enter) {
1504 a = loadKeyguardExitAnimation(transit);
1505 } else if (transit == TRANSIT_KEYGUARD_OCCLUDE) {
1506 a = null;
1507 } else if (transit == TRANSIT_KEYGUARD_UNOCCLUDE && !enter) {
1508 a = loadAnimationRes(lp, com.android.internal.R.anim.wallpaper_open_exit);
1509 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_OPEN
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001510 || transit == TRANSIT_TASK_OPEN
1511 || transit == TRANSIT_TASK_TO_FRONT)) {
1512 a = loadAnimationRes(lp, enter
1513 ? com.android.internal.R.anim.voice_activity_open_enter
1514 : com.android.internal.R.anim.voice_activity_open_exit);
1515 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1516 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001517 + " anim=" + a + " transit=" + appTransitionToString(transit)
1518 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001519 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_CLOSE
1520 || transit == TRANSIT_TASK_CLOSE
1521 || transit == TRANSIT_TASK_TO_BACK)) {
1522 a = loadAnimationRes(lp, enter
1523 ? com.android.internal.R.anim.voice_activity_close_enter
1524 : com.android.internal.R.anim.voice_activity_close_exit);
1525 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1526 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001527 + " anim=" + a + " transit=" + appTransitionToString(transit)
1528 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001529 } else if (transit == TRANSIT_ACTIVITY_RELAUNCH) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001530 a = createRelaunchAnimation(frame, insets);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001531 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1532 "applyAnimation:"
1533 + " anim=" + a + " nextAppTransition=" + mNextAppTransition
1534 + " transit=" + appTransitionToString(transit)
1535 + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001536 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM) {
1537 a = loadAnimationRes(mNextAppTransitionPackage, enter ?
Craig Mautner164d4bb2012-11-26 13:51:23 -08001538 mNextAppTransitionEnter : mNextAppTransitionExit);
1539 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1540 "applyAnimation:"
1541 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001542 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001543 + " Callers=" + Debug.getCallers(3));
Winson Chung044d5292014-11-06 11:05:19 -08001544 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE) {
1545 a = loadAnimationRes(mNextAppTransitionPackage, mNextAppTransitionInPlace);
1546 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1547 "applyAnimation:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001548 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM_IN_PLACE"
1549 + " transit=" + appTransitionToString(transit)
1550 + " Callers=" + Debug.getCallers(3));
Chet Haase10e23ab2015-02-11 15:08:38 -08001551 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001552 a = createClipRevealAnimationLocked(transit, enter, frame, displayFrame);
Chet Haase10e23ab2015-02-11 15:08:38 -08001553 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1554 "applyAnimation:"
1555 + " anim=" + a + " nextAppTransition=ANIM_CLIP_REVEAL"
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001556 + " transit=" + appTransitionToString(transit)
Chet Haase10e23ab2015-02-11 15:08:38 -08001557 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001558 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_SCALE_UP) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001559 a = createScaleUpAnimationLocked(transit, enter, frame);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001560 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1561 "applyAnimation:"
1562 + " anim=" + a + " nextAppTransition=ANIM_SCALE_UP"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001563 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001564 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001565 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
1566 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001567 mNextAppTransitionScaleUp =
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001568 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP);
Winson Chunga4ccb862014-08-22 15:26:27 -07001569 a = createThumbnailEnterExitAnimationLocked(getThumbnailTransitionState(enter),
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001570 frame, transit, taskId);
Winson Chunga4ccb862014-08-22 15:26:27 -07001571 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1572 String animName = mNextAppTransitionScaleUp ?
1573 "ANIM_THUMBNAIL_SCALE_UP" : "ANIM_THUMBNAIL_SCALE_DOWN";
1574 Slog.v(TAG, "applyAnimation:"
1575 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001576 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Winson Chunga4ccb862014-08-22 15:26:27 -07001577 + " Callers=" + Debug.getCallers(3));
1578 }
1579 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
1580 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN) {
1581 mNextAppTransitionScaleUp =
1582 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP);
1583 a = createAspectScaledThumbnailEnterExitAnimationLocked(
Winsonb2024762016-04-05 17:32:30 -07001584 getThumbnailTransitionState(enter), uiMode, orientation, transit, frame,
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001585 insets, surfaceInsets, freeform, taskId);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001586 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1587 String animName = mNextAppTransitionScaleUp ?
Winson Chunga4ccb862014-08-22 15:26:27 -07001588 "ANIM_THUMBNAIL_ASPECT_SCALE_UP" : "ANIM_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner164d4bb2012-11-26 13:51:23 -08001589 Slog.v(TAG, "applyAnimation:"
1590 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001591 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001592 + " Callers=" + Debug.getCallers(3));
1593 }
1594 } else {
1595 int animAttr = 0;
1596 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001597 case TRANSIT_ACTIVITY_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001598 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001599 ? WindowAnimation_activityOpenEnterAnimation
1600 : WindowAnimation_activityOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001601 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001602 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001603 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001604 ? WindowAnimation_activityCloseEnterAnimation
1605 : WindowAnimation_activityCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001606 break;
Jorim Jaggi192086e2016-03-11 17:17:03 +01001607 case TRANSIT_DOCK_TASK_FROM_RECENTS:
Craig Mautner4b71aa12012-12-27 17:20:01 -08001608 case TRANSIT_TASK_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001609 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001610 ? WindowAnimation_taskOpenEnterAnimation
1611 : WindowAnimation_taskOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001612 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001613 case TRANSIT_TASK_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001614 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001615 ? WindowAnimation_taskCloseEnterAnimation
1616 : WindowAnimation_taskCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001617 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001618 case TRANSIT_TASK_TO_FRONT:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001619 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001620 ? WindowAnimation_taskToFrontEnterAnimation
1621 : WindowAnimation_taskToFrontExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001622 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001623 case TRANSIT_TASK_TO_BACK:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001624 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001625 ? WindowAnimation_taskToBackEnterAnimation
1626 : WindowAnimation_taskToBackExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001627 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001628 case TRANSIT_WALLPAPER_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001629 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001630 ? WindowAnimation_wallpaperOpenEnterAnimation
1631 : WindowAnimation_wallpaperOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001632 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001633 case TRANSIT_WALLPAPER_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001634 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001635 ? WindowAnimation_wallpaperCloseEnterAnimation
1636 : WindowAnimation_wallpaperCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001637 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001638 case TRANSIT_WALLPAPER_INTRA_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001639 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001640 ? WindowAnimation_wallpaperIntraOpenEnterAnimation
1641 : WindowAnimation_wallpaperIntraOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001642 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001643 case TRANSIT_WALLPAPER_INTRA_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001644 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001645 ? WindowAnimation_wallpaperIntraCloseEnterAnimation
1646 : WindowAnimation_wallpaperIntraCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001647 break;
Craig Mautnerbb742462014-07-07 15:28:55 -07001648 case TRANSIT_TASK_OPEN_BEHIND:
1649 animAttr = enter
1650 ? WindowAnimation_launchTaskBehindSourceAnimation
Craig Mautner3b2cd1d2014-08-25 14:25:54 -07001651 : WindowAnimation_launchTaskBehindTargetAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001652 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001653 a = animAttr != 0 ? loadAnimationAttr(lp, animAttr) : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001654 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1655 "applyAnimation:"
1656 + " anim=" + a
1657 + " animAttr=0x" + Integer.toHexString(animAttr)
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001658 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001659 + " Callers=" + Debug.getCallers(3));
1660 }
1661 return a;
1662 }
1663
Jorim Jaggife762342016-10-13 14:33:27 +02001664 private Animation loadKeyguardExitAnimation(int transit) {
1665 if ((mNextAppTransitionFlags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_NO_ANIMATION) != 0) {
1666 return null;
1667 }
1668 final boolean toShade =
1669 (mNextAppTransitionFlags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_TO_SHADE) != 0;
1670 return mService.mPolicy.createHiddenByKeyguardExit(
1671 transit == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER, toShade);
1672 }
1673
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001674 int getAppStackClipMode() {
Matthew Ngbf1d9852017-03-14 12:23:09 -07001675 // When dismiss keyguard animation occurs, clip before the animation to prevent docked
1676 // app from showing beyond the divider
1677 if (mNextAppTransition == TRANSIT_KEYGUARD_GOING_AWAY
1678 || mNextAppTransition == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER) {
1679 return STACK_CLIP_BEFORE_ANIM;
1680 }
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001681 return mNextAppTransition == TRANSIT_ACTIVITY_RELAUNCH
Jorim Jaggic69bd222016-03-15 14:38:37 +01001682 || mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
Jorim Jaggi1f458fb2016-03-25 17:36:37 -07001683 || mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001684 ? STACK_CLIP_NONE
1685 : STACK_CLIP_AFTER_ANIM;
1686 }
1687
Jorim Jaggife762342016-10-13 14:33:27 +02001688 public int getTransitFlags() {
1689 return mNextAppTransitionFlags;
1690 }
1691
Craig Mautner164d4bb2012-11-26 13:51:23 -08001692 void postAnimationCallback() {
1693 if (mNextAppTransitionCallback != null) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001694 mService.mH.sendMessage(mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK,
1695 mNextAppTransitionCallback));
Craig Mautner164d4bb2012-11-26 13:51:23 -08001696 mNextAppTransitionCallback = null;
1697 }
1698 }
1699
1700 void overridePendingAppTransition(String packageName, int enterAnim, int exitAnim,
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001701 IRemoteCallback startedCallback) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001702 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001703 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001704 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001705 mNextAppTransitionPackage = packageName;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001706 mNextAppTransitionEnter = enterAnim;
1707 mNextAppTransitionExit = exitAnim;
1708 postAnimationCallback();
1709 mNextAppTransitionCallback = startedCallback;
1710 } else {
1711 postAnimationCallback();
1712 }
1713 }
1714
1715 void overridePendingAppTransitionScaleUp(int startX, int startY, int startWidth,
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001716 int startHeight) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001717 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001718 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001719 mNextAppTransitionType = NEXT_TRANSIT_TYPE_SCALE_UP;
Winson4c3fecd2016-07-13 12:29:48 -07001720 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001721 postAnimationCallback();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001722 }
1723 }
1724
Chet Haase10e23ab2015-02-11 15:08:38 -08001725 void overridePendingAppTransitionClipReveal(int startX, int startY,
1726 int startWidth, int startHeight) {
1727 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001728 clear();
Chet Haase10e23ab2015-02-11 15:08:38 -08001729 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CLIP_REVEAL;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001730 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Chet Haase10e23ab2015-02-11 15:08:38 -08001731 postAnimationCallback();
Chet Haase10e23ab2015-02-11 15:08:38 -08001732 }
1733 }
1734
Winson Chungaa7fa012017-05-24 15:50:06 -07001735 void overridePendingAppTransitionThumb(GraphicBuffer srcThumb, int startX, int startY,
Craig Mautner164d4bb2012-11-26 13:51:23 -08001736 IRemoteCallback startedCallback, boolean scaleUp) {
1737 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001738 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001739 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP
1740 : NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001741 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001742 putDefaultNextAppTransitionCoordinates(startX, startY, 0, 0, srcThumb);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001743 postAnimationCallback();
1744 mNextAppTransitionCallback = startedCallback;
1745 } else {
1746 postAnimationCallback();
1747 }
1748 }
1749
Winson Chungaa7fa012017-05-24 15:50:06 -07001750 void overridePendingAppTransitionAspectScaledThumb(GraphicBuffer srcThumb, int startX, int startY,
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001751 int targetWidth, int targetHeight, IRemoteCallback startedCallback, boolean scaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001752 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001753 clear();
Winson Chunga4ccb862014-08-22 15:26:27 -07001754 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1755 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Winson Chunga4ccb862014-08-22 15:26:27 -07001756 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001757 putDefaultNextAppTransitionCoordinates(startX, startY, targetWidth, targetHeight,
1758 srcThumb);
Winson Chunga4ccb862014-08-22 15:26:27 -07001759 postAnimationCallback();
1760 mNextAppTransitionCallback = startedCallback;
1761 } else {
1762 postAnimationCallback();
1763 }
1764 }
1765
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001766 public void overridePendingAppTransitionMultiThumb(AppTransitionAnimationSpec[] specs,
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001767 IRemoteCallback onAnimationStartedCallback, IRemoteCallback onAnimationFinishedCallback,
1768 boolean scaleUp) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001769 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001770 clear();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001771 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1772 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001773 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi43102412015-11-11 16:28:37 +01001774 if (specs != null) {
1775 for (int i = 0; i < specs.length; i++) {
1776 AppTransitionAnimationSpec spec = specs[i];
1777 if (spec != null) {
1778 mNextAppTransitionAnimationsSpecs.put(spec.taskId, spec);
1779 if (i == 0) {
1780 // In full screen mode, the transition code depends on the default spec
1781 // to be set.
1782 Rect rect = spec.rect;
1783 putDefaultNextAppTransitionCoordinates(rect.left, rect.top,
Winson Chungaa7fa012017-05-24 15:50:06 -07001784 rect.width(), rect.height(), spec.buffer);
Jorim Jaggi43102412015-11-11 16:28:37 +01001785 }
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001786 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001787 }
1788 }
1789 postAnimationCallback();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001790 mNextAppTransitionCallback = onAnimationStartedCallback;
1791 mAnimationFinishedCallback = onAnimationFinishedCallback;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001792 } else {
1793 postAnimationCallback();
1794 }
1795 }
1796
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001797 void overridePendingAppTransitionMultiThumbFuture(
1798 IAppTransitionAnimationSpecsFuture specsFuture, IRemoteCallback callback,
1799 boolean scaleUp) {
1800 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001801 clear();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001802 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1803 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001804 mNextAppTransitionAnimationsSpecsFuture = specsFuture;
1805 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001806 mNextAppTransitionFutureCallback = callback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001807 }
1808 }
1809
Winson Chung044d5292014-11-06 11:05:19 -08001810 void overrideInPlaceAppTransition(String packageName, int anim) {
1811 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001812 clear();
Winson Chung044d5292014-11-06 11:05:19 -08001813 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE;
1814 mNextAppTransitionPackage = packageName;
1815 mNextAppTransitionInPlace = anim;
1816 } else {
1817 postAnimationCallback();
1818 }
1819 }
1820
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001821 /**
1822 * If a future is set for the app transition specs, fetch it in another thread.
1823 */
1824 private void fetchAppTransitionSpecsFromFuture() {
1825 if (mNextAppTransitionAnimationsSpecsFuture != null) {
1826 mNextAppTransitionAnimationsSpecsPending = true;
1827 final IAppTransitionAnimationSpecsFuture future
1828 = mNextAppTransitionAnimationsSpecsFuture;
1829 mNextAppTransitionAnimationsSpecsFuture = null;
Jorim Jaggied410b62017-05-05 15:16:14 +02001830 mDefaultExecutor.execute(() -> {
1831 AppTransitionAnimationSpec[] specs = null;
1832 try {
1833 Binder.allowBlocking(future.asBinder());
1834 specs = future.get();
1835 } catch (RemoteException e) {
1836 Slog.w(TAG, "Failed to fetch app transition specs: " + e);
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001837 }
Jorim Jaggied410b62017-05-05 15:16:14 +02001838 synchronized (mService.mWindowMap) {
1839 mNextAppTransitionAnimationsSpecsPending = false;
1840 overridePendingAppTransitionMultiThumb(specs,
1841 mNextAppTransitionFutureCallback, null /* finishedCallback */,
1842 mNextAppTransitionScaleUp);
1843 mNextAppTransitionFutureCallback = null;
1844 if (specs != null) {
1845 mService.prolongAnimationsFromSpecs(specs, mNextAppTransitionScaleUp);
1846 }
1847 }
1848 mService.requestTraversal();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001849 });
1850 }
1851 }
1852
Craig Mautner164d4bb2012-11-26 13:51:23 -08001853 @Override
1854 public String toString() {
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001855 return "mNextAppTransition=" + appTransitionToString(mNextAppTransition);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001856 }
1857
Craig Mautner4b71aa12012-12-27 17:20:01 -08001858 /**
1859 * Returns the human readable name of a window transition.
1860 *
1861 * @param transition The window transition.
1862 * @return The transition symbolic name.
1863 */
1864 public static String appTransitionToString(int transition) {
1865 switch (transition) {
1866 case TRANSIT_UNSET: {
1867 return "TRANSIT_UNSET";
1868 }
1869 case TRANSIT_NONE: {
1870 return "TRANSIT_NONE";
1871 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001872 case TRANSIT_ACTIVITY_OPEN: {
1873 return "TRANSIT_ACTIVITY_OPEN";
1874 }
1875 case TRANSIT_ACTIVITY_CLOSE: {
1876 return "TRANSIT_ACTIVITY_CLOSE";
1877 }
1878 case TRANSIT_TASK_OPEN: {
1879 return "TRANSIT_TASK_OPEN";
1880 }
1881 case TRANSIT_TASK_CLOSE: {
1882 return "TRANSIT_TASK_CLOSE";
1883 }
1884 case TRANSIT_TASK_TO_FRONT: {
1885 return "TRANSIT_TASK_TO_FRONT";
1886 }
1887 case TRANSIT_TASK_TO_BACK: {
1888 return "TRANSIT_TASK_TO_BACK";
1889 }
1890 case TRANSIT_WALLPAPER_CLOSE: {
1891 return "TRANSIT_WALLPAPER_CLOSE";
1892 }
1893 case TRANSIT_WALLPAPER_OPEN: {
1894 return "TRANSIT_WALLPAPER_OPEN";
1895 }
1896 case TRANSIT_WALLPAPER_INTRA_OPEN: {
1897 return "TRANSIT_WALLPAPER_INTRA_OPEN";
1898 }
1899 case TRANSIT_WALLPAPER_INTRA_CLOSE: {
1900 return "TRANSIT_WALLPAPER_INTRA_CLOSE";
1901 }
Craig Mautnerbb742462014-07-07 15:28:55 -07001902 case TRANSIT_TASK_OPEN_BEHIND: {
1903 return "TRANSIT_TASK_OPEN_BEHIND";
1904 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001905 case TRANSIT_ACTIVITY_RELAUNCH: {
1906 return "TRANSIT_ACTIVITY_RELAUNCH";
1907 }
Jorim Jaggi192086e2016-03-11 17:17:03 +01001908 case TRANSIT_DOCK_TASK_FROM_RECENTS: {
1909 return "TRANSIT_DOCK_TASK_FROM_RECENTS";
1910 }
Jorim Jaggife762342016-10-13 14:33:27 +02001911 case TRANSIT_KEYGUARD_GOING_AWAY: {
1912 return "TRANSIT_KEYGUARD_GOING_AWAY";
1913 }
1914 case TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER: {
1915 return "TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER";
1916 }
1917 case TRANSIT_KEYGUARD_OCCLUDE: {
1918 return "TRANSIT_KEYGUARD_OCCLUDE";
1919 }
1920 case TRANSIT_KEYGUARD_UNOCCLUDE: {
1921 return "TRANSIT_KEYGUARD_UNOCCLUDE";
1922 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001923 default: {
1924 return "<UNKNOWN>";
1925 }
1926 }
1927 }
1928
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001929 private String appStateToString() {
1930 switch (mAppTransitionState) {
1931 case APP_STATE_IDLE:
1932 return "APP_STATE_IDLE";
1933 case APP_STATE_READY:
1934 return "APP_STATE_READY";
1935 case APP_STATE_RUNNING:
1936 return "APP_STATE_RUNNING";
1937 case APP_STATE_TIMEOUT:
1938 return "APP_STATE_TIMEOUT";
1939 default:
1940 return "unknown state=" + mAppTransitionState;
1941 }
1942 }
1943
1944 private String transitTypeToString() {
1945 switch (mNextAppTransitionType) {
1946 case NEXT_TRANSIT_TYPE_NONE:
1947 return "NEXT_TRANSIT_TYPE_NONE";
1948 case NEXT_TRANSIT_TYPE_CUSTOM:
1949 return "NEXT_TRANSIT_TYPE_CUSTOM";
Winson Chung044d5292014-11-06 11:05:19 -08001950 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
1951 return "NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001952 case NEXT_TRANSIT_TYPE_SCALE_UP:
1953 return "NEXT_TRANSIT_TYPE_SCALE_UP";
1954 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1955 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP";
1956 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
1957 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN";
Winson Chunga4ccb862014-08-22 15:26:27 -07001958 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
1959 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP";
1960 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN:
1961 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001962 default:
1963 return "unknown type=" + mNextAppTransitionType;
1964 }
1965 }
1966
Craig Mautner164d4bb2012-11-26 13:51:23 -08001967 @Override
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001968 public void dump(PrintWriter pw, String prefix) {
1969 pw.print(prefix); pw.println(this);
1970 pw.print(prefix); pw.print("mAppTransitionState="); pw.println(appStateToString());
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001971 if (mNextAppTransitionType != NEXT_TRANSIT_TYPE_NONE) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001972 pw.print(prefix); pw.print("mNextAppTransitionType=");
1973 pw.println(transitTypeToString());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001974 }
1975 switch (mNextAppTransitionType) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001976 case NEXT_TRANSIT_TYPE_CUSTOM:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001977 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001978 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001979 pw.print(prefix); pw.print("mNextAppTransitionEnter=0x");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001980 pw.print(Integer.toHexString(mNextAppTransitionEnter));
1981 pw.print(" mNextAppTransitionExit=0x");
1982 pw.println(Integer.toHexString(mNextAppTransitionExit));
1983 break;
Winson Chung044d5292014-11-06 11:05:19 -08001984 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001985 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Winson Chung044d5292014-11-06 11:05:19 -08001986 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001987 pw.print(prefix); pw.print("mNextAppTransitionInPlace=0x");
Winson Chung044d5292014-11-06 11:05:19 -08001988 pw.print(Integer.toHexString(mNextAppTransitionInPlace));
1989 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001990 case NEXT_TRANSIT_TYPE_SCALE_UP: {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001991 getDefaultNextAppTransitionStartRect(mTmpRect);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001992 pw.print(prefix); pw.print("mNextAppTransitionStartX=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001993 pw.print(mTmpRect.left);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001994 pw.print(" mNextAppTransitionStartY=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001995 pw.println(mTmpRect.top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001996 pw.print(prefix); pw.print("mNextAppTransitionStartWidth=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001997 pw.print(mTmpRect.width());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001998 pw.print(" mNextAppTransitionStartHeight=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001999 pw.println(mTmpRect.height());
Craig Mautner164d4bb2012-11-26 13:51:23 -08002000 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002001 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002002 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
2003 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
Winson Chunga4ccb862014-08-22 15:26:27 -07002004 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002005 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN: {
2006 pw.print(prefix); pw.print("mDefaultNextAppTransitionAnimationSpec=");
2007 pw.println(mDefaultNextAppTransitionAnimationSpec);
2008 pw.print(prefix); pw.print("mNextAppTransitionAnimationsSpecs=");
2009 pw.println(mNextAppTransitionAnimationsSpecs);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002010 pw.print(prefix); pw.print("mNextAppTransitionScaleUp=");
2011 pw.println(mNextAppTransitionScaleUp);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002012 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002013 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002014 }
2015 if (mNextAppTransitionCallback != null) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002016 pw.print(prefix); pw.print("mNextAppTransitionCallback=");
2017 pw.println(mNextAppTransitionCallback);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002018 }
Chong Zhang60091a92016-07-27 17:52:45 -07002019 if (mLastUsedAppTransition != TRANSIT_NONE) {
2020 pw.print(prefix); pw.print("mLastUsedAppTransition=");
2021 pw.println(appTransitionToString(mLastUsedAppTransition));
2022 pw.print(prefix); pw.print("mLastOpeningApp=");
2023 pw.println(mLastOpeningApp);
2024 pw.print(prefix); pw.print("mLastClosingApp=");
2025 pw.println(mLastClosingApp);
2026 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002027 }
Amith Yamasani4befbec2013-07-10 16:18:01 -07002028
2029 public void setCurrentUser(int newUserId) {
2030 mCurrentUserId = newUserId;
2031 }
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002032
2033 /**
2034 * @return true if transition is not running and should not be skipped, false if transition is
2035 * already running
2036 */
Jorim Jaggife762342016-10-13 14:33:27 +02002037 boolean prepareAppTransitionLocked(int transit, boolean alwaysKeepCurrent, int flags,
2038 boolean forceOverride) {
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002039 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Prepare app transition:"
2040 + " transit=" + appTransitionToString(transit)
2041 + " " + this
2042 + " alwaysKeepCurrent=" + alwaysKeepCurrent
2043 + " Callers=" + Debug.getCallers(3));
Jorim Jaggife762342016-10-13 14:33:27 +02002044 if (forceOverride || isKeyguardTransit(transit) || !isTransitionSet()
2045 || mNextAppTransition == TRANSIT_NONE) {
2046 setAppTransition(transit, flags);
Jorim Jaggia69243a2017-06-15 15:10:38 -04002047 }
2048 // We never want to change from a Keyguard transit to a non-Keyguard transit, as our logic
2049 // relies on the fact that we always execute a Keyguard transition after preparing one.
2050 else if (!alwaysKeepCurrent && !isKeyguardTransit(transit)) {
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002051 if (transit == TRANSIT_TASK_OPEN && isTransitionEqual(TRANSIT_TASK_CLOSE)) {
2052 // Opening a new task always supersedes a close for the anim.
Jorim Jaggife762342016-10-13 14:33:27 +02002053 setAppTransition(transit, flags);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002054 } else if (transit == TRANSIT_ACTIVITY_OPEN
2055 && isTransitionEqual(TRANSIT_ACTIVITY_CLOSE)) {
2056 // Opening a new activity always supersedes a close for the anim.
Jorim Jaggife762342016-10-13 14:33:27 +02002057 setAppTransition(transit, flags);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002058 }
2059 }
2060 boolean prepared = prepare();
2061 if (isTransitionSet()) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08002062 mService.mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
2063 mService.mH.sendEmptyMessageDelayed(H.APP_TRANSITION_TIMEOUT, APP_TRANSITION_TIMEOUT_MS);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002064 }
2065 return prepared;
2066 }
Winsonb2024762016-04-05 17:32:30 -07002067
2068 /**
Jorim Jaggife762342016-10-13 14:33:27 +02002069 * @return true if {@param transit} is representing a transition in which Keyguard is going
2070 * away, false otherwise
2071 */
2072 public static boolean isKeyguardGoingAwayTransit(int transit) {
2073 return transit == TRANSIT_KEYGUARD_GOING_AWAY
2074 || transit == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER;
2075 }
2076
2077 private static boolean isKeyguardTransit(int transit) {
2078 return isKeyguardGoingAwayTransit(transit) || transit == TRANSIT_KEYGUARD_OCCLUDE
2079 || transit == TRANSIT_KEYGUARD_UNOCCLUDE;
2080 }
2081
2082 /**
Manu Cornetd7376802017-01-13 13:44:07 -08002083 * @return whether the transition should show the thumbnail being scaled down.
2084 */
2085 private boolean shouldScaleDownThumbnailTransition(int uiMode, int orientation) {
Sid Soundararajan0e88d322017-03-07 15:37:30 -08002086 return mGridLayoutRecentsEnabled
Manu Cornetd7376802017-01-13 13:44:07 -08002087 || orientation == Configuration.ORIENTATION_PORTRAIT;
2088 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002089}