blob: cda3efdf886fa4f0e3b851ce1aba23709872e50b [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;
Matthew Ng43db6d22017-06-27 15:29:39 -070052import android.app.ActivityManager;
Craig Mautner164d4bb2012-11-26 13:51:23 -080053import android.content.Context;
Winson21700932016-03-24 17:26:23 -070054import android.content.res.Configuration;
Craig Mautner164d4bb2012-11-26 13:51:23 -080055import android.graphics.Bitmap;
Winson Chungaa7fa012017-05-24 15:50:06 -070056import android.graphics.GraphicBuffer;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +010057import android.graphics.Path;
Winson Chung399f6202014-03-19 10:47:20 -070058import android.graphics.Rect;
Jorim Jaggied410b62017-05-05 15:16:14 +020059import android.os.Binder;
Craig Mautner164d4bb2012-11-26 13:51:23 -080060import android.os.Debug;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010061import android.os.IBinder;
Craig Mautner164d4bb2012-11-26 13:51:23 -080062import android.os.IRemoteCallback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010063import android.os.RemoteException;
Manu Cornetd7376802017-01-13 13:44:07 -080064import android.os.SystemProperties;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -080065import android.util.ArraySet;
Craig Mautner164d4bb2012-11-26 13:51:23 -080066import android.util.Slog;
Filip Gruszczynski170192a2015-08-16 17:46:34 -070067import android.util.SparseArray;
68import android.view.AppTransitionAnimationSpec;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010069import android.view.IAppTransitionAnimationSpecsFuture;
Craig Mautner164d4bb2012-11-26 13:51:23 -080070import android.view.WindowManager;
Craig Mautner164d4bb2012-11-26 13:51:23 -080071import android.view.animation.AlphaAnimation;
72import android.view.animation.Animation;
73import android.view.animation.AnimationSet;
74import android.view.animation.AnimationUtils;
Winson Chung399f6202014-03-19 10:47:20 -070075import android.view.animation.ClipRectAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -080076import android.view.animation.Interpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070077import android.view.animation.PathInterpolator;
Craig Mautner164d4bb2012-11-26 13:51:23 -080078import android.view.animation.ScaleAnimation;
Winson Chung399f6202014-03-19 10:47:20 -070079import android.view.animation.TranslateAnimation;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070080
Craig Mautner164d4bb2012-11-26 13:51:23 -080081import com.android.internal.util.DumpUtils.Dump;
82import com.android.server.AttributeCache;
83import com.android.server.wm.WindowManagerService.H;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -080084import com.android.server.wm.animation.ClipRectLRAnimation;
85import com.android.server.wm.animation.ClipRectTBAnimation;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +010086import com.android.server.wm.animation.CurvedTranslateAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -080087
88import java.io.PrintWriter;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010089import java.util.ArrayList;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010090import java.util.concurrent.ExecutorService;
91import java.util.concurrent.Executors;
Craig Mautner164d4bb2012-11-26 13:51:23 -080092
Craig Mautner164d4bb2012-11-26 13:51:23 -080093// State management of app transitions. When we are preparing for a
94// transition, mNextAppTransition will be the kind of transition to
95// perform or TRANSIT_NONE if we are not waiting. If we are waiting,
96// mOpeningApps and mClosingApps are the lists of tokens that will be
97// made visible or hidden at the next transition.
98public class AppTransition implements Dump {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080099 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppTransition" : TAG_WM;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700100 private static final int CLIP_REVEAL_TRANSLATION_Y_DP = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800101
Craig Mautner4b71aa12012-12-27 17:20:01 -0800102 /** Not set up for a transition. */
103 public static final int TRANSIT_UNSET = -1;
104 /** No animation for transition. */
105 public static final int TRANSIT_NONE = 0;
106 /** 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 -0700107 public static final int TRANSIT_ACTIVITY_OPEN = 6;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800108 /** The window in the top-most activity is being closed to reveal the
109 * previous activity in the same task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700110 public static final int TRANSIT_ACTIVITY_CLOSE = 7;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800111 /** A window in a new task is being opened on top of an existing one
112 * in another activity's task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700113 public static final int TRANSIT_TASK_OPEN = 8;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800114 /** A window in the top-most activity is being closed to reveal the
115 * previous activity in a different task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700116 public static final int TRANSIT_TASK_CLOSE = 9;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800117 /** A window in an existing task is being displayed on top of an existing one
118 * in another activity's task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700119 public static final int TRANSIT_TASK_TO_FRONT = 10;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800120 /** A window in an existing task is being put below all other tasks. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700121 public static final int TRANSIT_TASK_TO_BACK = 11;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800122 /** A window in a new activity that doesn't have a wallpaper is being opened on top of one that
123 * does, effectively closing the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700124 public static final int TRANSIT_WALLPAPER_CLOSE = 12;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800125 /** A window in a new activity that does have a wallpaper is being opened on one that didn't,
126 * effectively opening the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700127 public static final int TRANSIT_WALLPAPER_OPEN = 13;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800128 /** A window in a new activity is being opened on top of an existing one, and both are on top
129 * of the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700130 public static final int TRANSIT_WALLPAPER_INTRA_OPEN = 14;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800131 /** The window in the top-most activity is being closed to reveal the previous activity, and
132 * both are on top of the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700133 public static final int TRANSIT_WALLPAPER_INTRA_CLOSE = 15;
134 /** A window in a new task is being opened behind an existing one in another activity's task.
135 * The new window will show briefly and then be gone. */
136 public static final int TRANSIT_TASK_OPEN_BEHIND = 16;
Winson Chung044d5292014-11-06 11:05:19 -0800137 /** A window in a task is being animated in-place. */
138 public static final int TRANSIT_TASK_IN_PLACE = 17;
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700139 /** An activity is being relaunched (e.g. due to configuration change). */
140 public static final int TRANSIT_ACTIVITY_RELAUNCH = 18;
Jorim Jaggi192086e2016-03-11 17:17:03 +0100141 /** A task is being docked from recents. */
142 public static final int TRANSIT_DOCK_TASK_FROM_RECENTS = 19;
Jorim Jaggife762342016-10-13 14:33:27 +0200143 /** Keyguard is going away */
144 public static final int TRANSIT_KEYGUARD_GOING_AWAY = 20;
145 /** Keyguard is going away with showing an activity behind that requests wallpaper */
146 public static final int TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER = 21;
147 /** Keyguard is being occluded */
148 public static final int TRANSIT_KEYGUARD_OCCLUDE = 22;
149 /** Keyguard is being unoccluded */
150 public static final int TRANSIT_KEYGUARD_UNOCCLUDE = 23;
151
152 /** Transition flag: Keyguard is going away, but keeping the notification shade open */
153 public static final int TRANSIT_FLAG_KEYGUARD_GOING_AWAY_TO_SHADE = 0x1;
154 /** Transition flag: Keyguard is going away, but doesn't want an animation for it */
155 public static final int TRANSIT_FLAG_KEYGUARD_GOING_AWAY_NO_ANIMATION = 0x2;
156 /** Transition flag: Keyguard is going away while it was showing the system wallpaper. */
157 public static final int TRANSIT_FLAG_KEYGUARD_GOING_AWAY_WITH_WALLPAPER = 0x4;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800158
Winson Chunga4ccb862014-08-22 15:26:27 -0700159 /** Fraction of animation at which the recents thumbnail stays completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700160 private static final float RECENTS_THUMBNAIL_FADEIN_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800161 /** Fraction of animation at which the recents thumbnail becomes completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700162 private static final float RECENTS_THUMBNAIL_FADEOUT_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800163
Filip Gruszczynski84fa3352016-01-25 16:28:49 -0800164 static final int DEFAULT_APP_TRANSITION_DURATION = 336;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800165
166 /** Interpolator to be used for animations that respond directly to a touch */
167 static final Interpolator TOUCH_RESPONSE_INTERPOLATOR =
168 new PathInterpolator(0.3f, 0f, 0.1f, 1f);
169
Jorim Jaggic69bd222016-03-15 14:38:37 +0100170 private static final Interpolator THUMBNAIL_DOCK_INTERPOLATOR =
171 new PathInterpolator(0.85f, 0f, 1f, 1f);
172
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800173 /**
174 * Maximum duration for the clip reveal animation. This is used when there is a lot of movement
175 * involved, to make it more understandable.
176 */
177 private static final int MAX_CLIP_REVEAL_TRANSITION_DURATION = 420;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700178 private static final int THUMBNAIL_APP_TRANSITION_DURATION = 336;
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700179 private static final long APP_TRANSITION_TIMEOUT_MS = 5000;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800180
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800181 private final Context mContext;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800182 private final WindowManagerService mService;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800183
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800184 private int mNextAppTransition = TRANSIT_UNSET;
Jorim Jaggife762342016-10-13 14:33:27 +0200185 private int mNextAppTransitionFlags = 0;
Chong Zhang60091a92016-07-27 17:52:45 -0700186 private int mLastUsedAppTransition = TRANSIT_UNSET;
187 private String mLastOpeningApp;
188 private String mLastClosingApp;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800189
190 private static final int NEXT_TRANSIT_TYPE_NONE = 0;
191 private static final int NEXT_TRANSIT_TYPE_CUSTOM = 1;
192 private static final int NEXT_TRANSIT_TYPE_SCALE_UP = 2;
193 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP = 3;
194 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN = 4;
Winson Chunga4ccb862014-08-22 15:26:27 -0700195 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP = 5;
196 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN = 6;
Winson Chung044d5292014-11-06 11:05:19 -0800197 private static final int NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE = 7;
Chet Haase10e23ab2015-02-11 15:08:38 -0800198 private static final int NEXT_TRANSIT_TYPE_CLIP_REVEAL = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800199 private int mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
200
Winson Chung399f6202014-03-19 10:47:20 -0700201 // These are the possible states for the enter/exit activities during a thumbnail transition
202 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_UP = 0;
203 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_UP = 1;
204 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN = 2;
205 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN = 3;
206
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800207 private String mNextAppTransitionPackage;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800208 // Used for thumbnail transitions. True if we're scaling up, false if scaling down
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800209 private boolean mNextAppTransitionScaleUp;
210 private IRemoteCallback mNextAppTransitionCallback;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +0100211 private IRemoteCallback mNextAppTransitionFutureCallback;
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -0700212 private IRemoteCallback mAnimationFinishedCallback;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800213 private int mNextAppTransitionEnter;
214 private int mNextAppTransitionExit;
Winson Chung044d5292014-11-06 11:05:19 -0800215 private int mNextAppTransitionInPlace;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700216
217 // Keyed by task id.
218 private final SparseArray<AppTransitionAnimationSpec> mNextAppTransitionAnimationsSpecs
219 = new SparseArray<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100220 private IAppTransitionAnimationSpecsFuture mNextAppTransitionAnimationsSpecsFuture;
221 private boolean mNextAppTransitionAnimationsSpecsPending;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700222 private AppTransitionAnimationSpec mDefaultNextAppTransitionAnimationSpec;
223
Winson Chunga4ccb862014-08-22 15:26:27 -0700224 private Rect mNextAppTransitionInsets = new Rect();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800225
Winson Chung2820c452014-04-15 15:34:44 -0700226 private Rect mTmpFromClipRect = new Rect();
227 private Rect mTmpToClipRect = new Rect();
228
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700229 private final Rect mTmpRect = new Rect();
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700230
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800231 private final static int APP_STATE_IDLE = 0;
232 private final static int APP_STATE_READY = 1;
233 private final static int APP_STATE_RUNNING = 2;
234 private final static int APP_STATE_TIMEOUT = 3;
235 private int mAppTransitionState = APP_STATE_IDLE;
236
237 private final int mConfigShortAnimTime;
Craig Mautner321bdf52012-12-18 09:53:24 -0800238 private final Interpolator mDecelerateInterpolator;
Winson Chunga4ccb862014-08-22 15:26:27 -0700239 private final Interpolator mThumbnailFadeInInterpolator;
240 private final Interpolator mThumbnailFadeOutInterpolator;
Chet Haase10e23ab2015-02-11 15:08:38 -0800241 private final Interpolator mLinearOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700242 private final Interpolator mFastOutLinearInInterpolator;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100243 private final Interpolator mFastOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700244 private final Interpolator mClipHorizontalInterpolator = new PathInterpolator(0, 0, 0.4f, 1f);
245
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700246 private final int mClipRevealTranslationY;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800247
Amith Yamasani4befbec2013-07-10 16:18:01 -0700248 private int mCurrentUserId = 0;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800249 private long mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Amith Yamasani4befbec2013-07-10 16:18:01 -0700250
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100251 private final ArrayList<AppTransitionListener> mListeners = new ArrayList<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100252 private final ExecutorService mDefaultExecutor = Executors.newSingleThreadExecutor();
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100253
Jorim Jaggif97ed922016-02-18 18:57:07 -0800254 private int mLastClipRevealMaxTranslation;
255 private boolean mLastHadClipReveal;
Jorim Jaggi363ab982016-04-26 19:51:20 -0700256 private boolean mProlongedAnimationsEnded;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800257
Manu Cornetd7376802017-01-13 13:44:07 -0800258 private final boolean mGridLayoutRecentsEnabled;
Matthew Ng43db6d22017-06-27 15:29:39 -0700259 private final boolean mLowRamRecentsEnabled;
Manu Cornetd7376802017-01-13 13:44:07 -0800260
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800261 AppTransition(Context context, WindowManagerService service) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800262 mContext = context;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800263 mService = service;
Chet Haase10e23ab2015-02-11 15:08:38 -0800264 mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
265 com.android.internal.R.interpolator.linear_out_slow_in);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700266 mFastOutLinearInInterpolator = AnimationUtils.loadInterpolator(context,
267 com.android.internal.R.interpolator.fast_out_linear_in);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100268 mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
269 com.android.internal.R.interpolator.fast_out_slow_in);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800270 mConfigShortAnimTime = context.getResources().getInteger(
271 com.android.internal.R.integer.config_shortAnimTime);
Craig Mautner321bdf52012-12-18 09:53:24 -0800272 mDecelerateInterpolator = AnimationUtils.loadInterpolator(context,
273 com.android.internal.R.interpolator.decelerate_cubic);
Winson Chunga4ccb862014-08-22 15:26:27 -0700274 mThumbnailFadeInInterpolator = new Interpolator() {
275 @Override
276 public float getInterpolation(float input) {
277 // Linear response for first fraction, then complete after that.
278 if (input < RECENTS_THUMBNAIL_FADEIN_FRACTION) {
279 return 0f;
280 }
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700281 float t = (input - RECENTS_THUMBNAIL_FADEIN_FRACTION) /
Winson Chunga4ccb862014-08-22 15:26:27 -0700282 (1f - RECENTS_THUMBNAIL_FADEIN_FRACTION);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700283 return mFastOutLinearInInterpolator.getInterpolation(t);
Winson Chunga4ccb862014-08-22 15:26:27 -0700284 }
285 };
286 mThumbnailFadeOutInterpolator = new Interpolator() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800287 @Override
288 public float getInterpolation(float input) {
289 // Linear response for first fraction, then complete after that.
290 if (input < RECENTS_THUMBNAIL_FADEOUT_FRACTION) {
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700291 float t = input / RECENTS_THUMBNAIL_FADEOUT_FRACTION;
292 return mLinearOutSlowInInterpolator.getInterpolation(t);
Craig Mautner321bdf52012-12-18 09:53:24 -0800293 }
Winson Chunga4ccb862014-08-22 15:26:27 -0700294 return 1f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800295 }
296 };
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700297 mClipRevealTranslationY = (int) (CLIP_REVEAL_TRANSLATION_Y_DP
298 * mContext.getResources().getDisplayMetrics().density);
Manu Cornetd7376802017-01-13 13:44:07 -0800299 mGridLayoutRecentsEnabled = SystemProperties.getBoolean("ro.recents.grid", false);
Matthew Ng43db6d22017-06-27 15:29:39 -0700300 mLowRamRecentsEnabled = ActivityManager.isLowRamDeviceStatic();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800301 }
302
303 boolean isTransitionSet() {
304 return mNextAppTransition != TRANSIT_UNSET;
305 }
306
Craig Mautner164d4bb2012-11-26 13:51:23 -0800307 boolean isTransitionEqual(int transit) {
308 return mNextAppTransition == transit;
309 }
310
311 int getAppTransition() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800312 return mNextAppTransition;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800313 }
314
Jorim Jaggife762342016-10-13 14:33:27 +0200315 private void setAppTransition(int transit, int flags) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800316 mNextAppTransition = transit;
Jorim Jaggife762342016-10-13 14:33:27 +0200317 mNextAppTransitionFlags |= flags;
Chong Zhang60091a92016-07-27 17:52:45 -0700318 setLastAppTransition(TRANSIT_UNSET, null, null);
Jorim Jaggi245281c2017-06-07 14:33:04 -0700319 updateBooster();
Chong Zhang60091a92016-07-27 17:52:45 -0700320 }
321
322 void setLastAppTransition(int transit, AppWindowToken openingApp, AppWindowToken closingApp) {
323 mLastUsedAppTransition = transit;
324 mLastOpeningApp = "" + openingApp;
325 mLastClosingApp = "" + closingApp;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800326 }
327
328 boolean isReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800329 return mAppTransitionState == APP_STATE_READY
330 || mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800331 }
332
Craig Mautnerae446592012-12-06 19:05:05 -0800333 void setReady() {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700334 setAppTransitionState(APP_STATE_READY);
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100335 fetchAppTransitionSpecsFromFuture();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800336 }
337
338 boolean isRunning() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800339 return mAppTransitionState == APP_STATE_RUNNING;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800340 }
341
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800342 void setIdle() {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700343 setAppTransitionState(APP_STATE_IDLE);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800344 }
345
346 boolean isTimeout() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800347 return mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800348 }
349
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800350 void setTimeout() {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700351 setAppTransitionState(APP_STATE_TIMEOUT);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800352 }
353
Winson Chungaa7fa012017-05-24 15:50:06 -0700354 GraphicBuffer getAppTransitionThumbnailHeader(int taskId) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700355 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800356 if (spec == null) {
357 spec = mDefaultNextAppTransitionAnimationSpec;
358 }
Winson Chungaa7fa012017-05-24 15:50:06 -0700359 return spec != null ? spec.buffer : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800360 }
361
Winson Chunga4ccb862014-08-22 15:26:27 -0700362 /** Returns whether the next thumbnail transition is aspect scaled up. */
363 boolean isNextThumbnailTransitionAspectScaled() {
364 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
365 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
366 }
367
368 /** Returns whether the next thumbnail transition is scaling up. */
369 boolean isNextThumbnailTransitionScaleUp() {
370 return mNextAppTransitionScaleUp;
371 }
372
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -0800373 boolean isNextAppTransitionThumbnailUp() {
374 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
375 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP;
376 }
377
378 boolean isNextAppTransitionThumbnailDown() {
379 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN ||
380 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
381 }
382
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100383 /**
384 * @return true if and only if we are currently fetching app transition specs from the future
385 * passed into {@link #overridePendingAppTransitionMultiThumbFuture}
386 */
387 boolean isFetchingAppTransitionsSpecs() {
388 return mNextAppTransitionAnimationsSpecsPending;
389 }
390
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700391 private boolean prepare() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800392 if (!isRunning()) {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700393 setAppTransitionState(APP_STATE_IDLE);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100394 notifyAppTransitionPendingLocked();
Jorim Jaggif97ed922016-02-18 18:57:07 -0800395 mLastHadClipReveal = false;
396 mLastClipRevealMaxTranslation = 0;
397 mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700398 return true;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800399 }
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700400 return false;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800401 }
402
Jorim Jaggife762342016-10-13 14:33:27 +0200403 /**
404 * @return bit-map of WindowManagerPolicy#FINISH_LAYOUT_REDO_* to indicate whether another
405 * layout pass needs to be done
406 */
407 int goodToGo(int transit, AppWindowAnimator topOpeningAppAnimator,
408 AppWindowAnimator topClosingAppAnimator, ArraySet<AppWindowToken> openingApps,
409 ArraySet<AppWindowToken> closingApps) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800410 mNextAppTransition = TRANSIT_UNSET;
Jorim Jaggife762342016-10-13 14:33:27 +0200411 mNextAppTransitionFlags = 0;
Jorim Jaggi245281c2017-06-07 14:33:04 -0700412 setAppTransitionState(APP_STATE_RUNNING);
Jorim Jaggife762342016-10-13 14:33:27 +0200413 int redoLayout = notifyAppTransitionStartingLocked(transit,
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800414 topOpeningAppAnimator != null ? topOpeningAppAnimator.mAppToken.token : null,
415 topClosingAppAnimator != null ? topClosingAppAnimator.mAppToken.token : null,
416 topOpeningAppAnimator != null ? topOpeningAppAnimator.animation : null,
417 topClosingAppAnimator != null ? topClosingAppAnimator.animation : null);
418 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Jorim Jaggife762342016-10-13 14:33:27 +0200419 .notifyAppTransitionStarting(openingApps, transit);
Jorim Jaggi363ab982016-04-26 19:51:20 -0700420
421 // Prolong the start for the transition when docking a task from recents, unless recents
422 // ended it already then we don't need to wait.
Jorim Jaggife762342016-10-13 14:33:27 +0200423 if (transit == TRANSIT_DOCK_TASK_FROM_RECENTS && !mProlongedAnimationsEnded) {
Jorim Jaggi363ab982016-04-26 19:51:20 -0700424 for (int i = openingApps.size() - 1; i >= 0; i--) {
425 final AppWindowAnimator appAnimator = openingApps.valueAt(i).mAppAnimator;
426 appAnimator.startProlongAnimation(PROLONG_ANIMATION_AT_START);
427 }
428 }
Jorim Jaggife762342016-10-13 14:33:27 +0200429 return redoLayout;
Jorim Jaggi363ab982016-04-26 19:51:20 -0700430 }
431
432 /**
433 * Let the transitions manager know that the somebody wanted to end the prolonged animations.
434 */
435 void notifyProlongedAnimationsEnded() {
436 mProlongedAnimationsEnded = true;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800437 }
438
439 void clear() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800440 mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800441 mNextAppTransitionPackage = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700442 mNextAppTransitionAnimationsSpecs.clear();
Jorim Jaggi65193992015-11-23 16:49:59 -0800443 mNextAppTransitionAnimationsSpecsFuture = null;
444 mDefaultNextAppTransitionAnimationSpec = null;
445 mAnimationFinishedCallback = null;
Jorim Jaggi363ab982016-04-26 19:51:20 -0700446 mProlongedAnimationsEnded = false;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800447 }
448
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800449 void freeze() {
Jorim Jaggife762342016-10-13 14:33:27 +0200450 final int transit = mNextAppTransition;
451 setAppTransition(AppTransition.TRANSIT_UNSET, 0 /* flags */);
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800452 clear();
453 setReady();
Jorim Jaggife762342016-10-13 14:33:27 +0200454 notifyAppTransitionCancelledLocked(transit);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100455 }
456
Jorim Jaggi245281c2017-06-07 14:33:04 -0700457 private void setAppTransitionState(int state) {
458 mAppTransitionState = state;
459 updateBooster();
460 }
461
462 /**
463 * Updates whether we currently boost wm locked sections and the animation thread. We want to
464 * boost the priorities to a more important value whenever an app transition is going to happen
465 * soon or an app transition is running.
466 */
467 private void updateBooster() {
468 WindowManagerService.sThreadPriorityBooster.setAppTransitionRunning(
469 mNextAppTransition != TRANSIT_UNSET || mAppTransitionState == APP_STATE_READY
470 || mAppTransitionState == APP_STATE_RUNNING);
471 }
472
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100473 void registerListenerLocked(AppTransitionListener listener) {
474 mListeners.add(listener);
475 }
476
Wale Ogunwalea48eadb2015-05-14 17:43:12 -0700477 public void notifyAppTransitionFinishedLocked(IBinder token) {
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100478 for (int i = 0; i < mListeners.size(); i++) {
479 mListeners.get(i).onAppTransitionFinishedLocked(token);
480 }
481 }
482
483 private void notifyAppTransitionPendingLocked() {
484 for (int i = 0; i < mListeners.size(); i++) {
485 mListeners.get(i).onAppTransitionPendingLocked();
486 }
487 }
488
Jorim Jaggife762342016-10-13 14:33:27 +0200489 private void notifyAppTransitionCancelledLocked(int transit) {
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100490 for (int i = 0; i < mListeners.size(); i++) {
Jorim Jaggife762342016-10-13 14:33:27 +0200491 mListeners.get(i).onAppTransitionCancelledLocked(transit);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100492 }
493 }
494
Jorim Jaggife762342016-10-13 14:33:27 +0200495 private int notifyAppTransitionStartingLocked(int transit, IBinder openToken,
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100496 IBinder closeToken, Animation openAnimation, Animation closeAnimation) {
Jorim Jaggife762342016-10-13 14:33:27 +0200497 int redoLayout = 0;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100498 for (int i = 0; i < mListeners.size(); i++) {
Jorim Jaggife762342016-10-13 14:33:27 +0200499 redoLayout |= mListeners.get(i).onAppTransitionStartingLocked(transit, openToken,
500 closeToken, openAnimation, closeAnimation);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100501 }
Jorim Jaggife762342016-10-13 14:33:27 +0200502 return redoLayout;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800503 }
504
Craig Mautner164d4bb2012-11-26 13:51:23 -0800505 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
506 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg="
507 + (lp != null ? lp.packageName : null)
508 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
509 if (lp != null && lp.windowAnimations != 0) {
510 // If this is a system resource, don't try to load it from the
511 // application resources. It is nice to avoid loading application
512 // resources if we can.
513 String packageName = lp.packageName != null ? lp.packageName : "android";
514 int resId = lp.windowAnimations;
515 if ((resId&0xFF000000) == 0x01000000) {
516 packageName = "android";
517 }
518 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
519 + packageName);
520 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700521 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800522 }
523 return null;
524 }
525
526 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
527 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package="
528 + packageName + " resId=0x" + Integer.toHexString(resId));
529 if (packageName != null) {
530 if ((resId&0xFF000000) == 0x01000000) {
531 packageName = "android";
532 }
533 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
534 + packageName);
535 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700536 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800537 }
538 return null;
539 }
540
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700541 Animation loadAnimationAttr(WindowManager.LayoutParams lp, int animAttr) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800542 int anim = 0;
543 Context context = mContext;
544 if (animAttr >= 0) {
545 AttributeCache.Entry ent = getCachedAnimations(lp);
546 if (ent != null) {
547 context = ent.context;
548 anim = ent.array.getResourceId(animAttr, 0);
549 }
550 }
551 if (anim != 0) {
552 return AnimationUtils.loadAnimation(context, anim);
553 }
554 return null;
555 }
556
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700557 Animation loadAnimationRes(WindowManager.LayoutParams lp, int resId) {
558 Context context = mContext;
559 if (resId >= 0) {
560 AttributeCache.Entry ent = getCachedAnimations(lp);
561 if (ent != null) {
562 context = ent.context;
563 }
564 return AnimationUtils.loadAnimation(context, resId);
565 }
566 return null;
567 }
568
569 private Animation loadAnimationRes(String packageName, int resId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800570 int anim = 0;
571 Context context = mContext;
572 if (resId >= 0) {
573 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
574 if (ent != null) {
575 context = ent.context;
576 anim = resId;
577 }
578 }
579 if (anim != 0) {
580 return AnimationUtils.loadAnimation(context, anim);
581 }
582 return null;
583 }
584
Craig Mautner164d4bb2012-11-26 13:51:23 -0800585 /**
586 * Compute the pivot point for an animation that is scaling from a small
587 * rect on screen to a larger rect. The pivot point varies depending on
588 * the distance between the inner and outer edges on both sides. This
589 * function computes the pivot point for one dimension.
590 * @param startPos Offset from left/top edge of outer rectangle to
591 * left/top edge of inner rectangle.
592 * @param finalScale The scaling factor between the size of the outer
593 * and inner rectangles.
594 */
595 private static float computePivot(int startPos, float finalScale) {
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800596
597 /*
598 Theorem of intercepting lines:
599
600 + + +-----------------------------------------------+
601 | | | |
602 | | | |
603 | | | |
604 | | | |
605 x | y | | |
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 |
645 |
646 + ++
647 p ++
648
649 scale = (x - y) / x
650 <=> x = -y / (scale - 1)
651 */
Craig Mautner164d4bb2012-11-26 13:51:23 -0800652 final float denom = finalScale-1;
653 if (Math.abs(denom) < .0001f) {
654 return startPos;
655 }
656 return -startPos / denom;
657 }
658
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700659 private Animation createScaleUpAnimationLocked(int transit, boolean enter,
660 Rect containingFrame) {
661 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700662 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700663 final int appWidth = containingFrame.width();
664 final int appHeight = containingFrame.height();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800665 if (enter) {
666 // Entering app zooms out from the center of the initial rect.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700667 float scaleW = mTmpRect.width() / (float) appWidth;
668 float scaleH = mTmpRect.height() / (float) appHeight;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800669 Animation scale = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700670 computePivot(mTmpRect.left, scaleW),
Winson4c3fecd2016-07-13 12:29:48 -0700671 computePivot(mTmpRect.top, scaleH));
Craig Mautner321bdf52012-12-18 09:53:24 -0800672 scale.setInterpolator(mDecelerateInterpolator);
673
Craig Mautner164d4bb2012-11-26 13:51:23 -0800674 Animation alpha = new AlphaAnimation(0, 1);
Winson Chunga4ccb862014-08-22 15:26:27 -0700675 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
Craig Mautner321bdf52012-12-18 09:53:24 -0800676
677 AnimationSet set = new AnimationSet(false);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800678 set.addAnimation(scale);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800679 set.addAnimation(alpha);
680 set.setDetachWallpaper(true);
681 a = set;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800682 } else if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
683 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800684 // If we are on top of the wallpaper, we need an animation that
685 // correctly handles the wallpaper staying static behind all of
686 // the animated elements. To do this, will just have the existing
687 // element fade out.
688 a = new AlphaAnimation(1, 0);
689 a.setDetachWallpaper(true);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800690 } else {
Craig Mautner321bdf52012-12-18 09:53:24 -0800691 // For normal animations, the exiting element just holds in place.
692 a = new AlphaAnimation(1, 1);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800693 }
Craig Mautner321bdf52012-12-18 09:53:24 -0800694
695 // Pick the desired duration. If this is an inter-activity transition,
696 // it is the standard duration for that. Otherwise we use the longer
697 // task transition duration.
698 final long duration;
699 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800700 case TRANSIT_ACTIVITY_OPEN:
701 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800702 duration = mConfigShortAnimTime;
703 break;
704 default:
705 duration = DEFAULT_APP_TRANSITION_DURATION;
706 break;
707 }
708 a.setDuration(duration);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800709 a.setFillAfter(true);
Craig Mautner321bdf52012-12-18 09:53:24 -0800710 a.setInterpolator(mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800711 a.initialize(appWidth, appHeight, appWidth, appHeight);
712 return a;
713 }
714
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700715 private void getDefaultNextAppTransitionStartRect(Rect rect) {
716 if (mDefaultNextAppTransitionAnimationSpec == null ||
717 mDefaultNextAppTransitionAnimationSpec.rect == null) {
Jorim Jaggi2550f3f2017-03-14 20:15:59 +0100718 Slog.e(TAG, "Starting rect for app requested, but none available", new Throwable());
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700719 rect.setEmpty();
720 } else {
721 rect.set(mDefaultNextAppTransitionAnimationSpec.rect);
722 }
723 }
724
725 void getNextAppTransitionStartRect(int taskId, Rect rect) {
726 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800727 if (spec == null) {
728 spec = mDefaultNextAppTransitionAnimationSpec;
729 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700730 if (spec == null || spec.rect == null) {
Jorim Jaggi2550f3f2017-03-14 20:15:59 +0100731 Slog.e(TAG, "Starting rect for task: " + taskId + " requested, but not available",
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700732 new Throwable());
733 rect.setEmpty();
734 } else {
735 rect.set(spec.rect);
736 }
737 }
738
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800739 private void putDefaultNextAppTransitionCoordinates(int left, int top, int width, int height,
Winson Chungaa7fa012017-05-24 15:50:06 -0700740 GraphicBuffer buffer) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700741 mDefaultNextAppTransitionAnimationSpec = new AppTransitionAnimationSpec(-1 /* taskId */,
Winson Chungaa7fa012017-05-24 15:50:06 -0700742 buffer, new Rect(left, top, left + width, top + height));
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700743 }
744
Jorim Jaggif97ed922016-02-18 18:57:07 -0800745 /**
746 * @return the duration of the last clip reveal animation
747 */
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800748 long getLastClipRevealTransitionDuration() {
749 return mLastClipRevealTransitionDuration;
750 }
751
752 /**
Jorim Jaggif97ed922016-02-18 18:57:07 -0800753 * @return the maximum distance the app surface is traveling of the last clip reveal animation
754 */
755 int getLastClipRevealMaxTranslation() {
756 return mLastClipRevealMaxTranslation;
757 }
758
759 /**
760 * @return true if in the last app transition had a clip reveal animation, false otherwise
761 */
762 boolean hadClipRevealAnimation() {
763 return mLastHadClipReveal;
764 }
765
766 /**
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800767 * Calculates the duration for the clip reveal animation. If the clip is "cut off", meaning that
768 * the start rect is outside of the target rect, and there is a lot of movement going on.
769 *
770 * @param cutOff whether the start rect was not fully contained by the end rect
771 * @param translationX the total translation the surface moves in x direction
772 * @param translationY the total translation the surfaces moves in y direction
773 * @param displayFrame our display frame
774 *
775 * @return the duration of the clip reveal animation, in milliseconds
776 */
777 private long calculateClipRevealTransitionDuration(boolean cutOff, float translationX,
778 float translationY, Rect displayFrame) {
779 if (!cutOff) {
780 return DEFAULT_APP_TRANSITION_DURATION;
781 }
782 final float fraction = Math.max(Math.abs(translationX) / displayFrame.width(),
783 Math.abs(translationY) / displayFrame.height());
784 return (long) (DEFAULT_APP_TRANSITION_DURATION + fraction *
785 (MAX_CLIP_REVEAL_TRANSITION_DURATION - DEFAULT_APP_TRANSITION_DURATION));
786 }
787
788 private Animation createClipRevealAnimationLocked(int transit, boolean enter, Rect appFrame,
789 Rect displayFrame) {
Chet Haase10e23ab2015-02-11 15:08:38 -0800790 final Animation anim;
791 if (enter) {
Craig Mautner80b1f642015-04-22 10:59:09 -0700792 final int appWidth = appFrame.width();
793 final int appHeight = appFrame.height();
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800794
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700795 // mTmpRect will contain an area around the launcher icon that was pressed. We will
Filip Gruszczynski82861362015-10-16 14:21:09 -0700796 // clip reveal from that area in the final area of the app.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700797 getDefaultNextAppTransitionStartRect(mTmpRect);
Craig Mautner80b1f642015-04-22 10:59:09 -0700798
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700799 float t = 0f;
800 if (appHeight > 0) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800801 t = (float) mTmpRect.top / displayFrame.height();
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700802 }
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800803 int translationY = mClipRevealTranslationY + (int)(displayFrame.height() / 7f * t);
804 int translationX = 0;
805 int translationYCorrection = translationY;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700806 int centerX = mTmpRect.centerX();
807 int centerY = mTmpRect.centerY();
808 int halfWidth = mTmpRect.width() / 2;
809 int halfHeight = mTmpRect.height() / 2;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800810 int clipStartX = centerX - halfWidth - appFrame.left;
811 int clipStartY = centerY - halfHeight - appFrame.top;
812 boolean cutOff = false;
813
814 // If the starting rectangle is fully or partially outside of the target rectangle, we
815 // need to start the clipping at the edge and then achieve the rest with translation
816 // and extending the clip rect from that edge.
817 if (appFrame.top > centerY - halfHeight) {
818 translationY = (centerY - halfHeight) - appFrame.top;
819 translationYCorrection = 0;
820 clipStartY = 0;
821 cutOff = true;
822 }
823 if (appFrame.left > centerX - halfWidth) {
824 translationX = (centerX - halfWidth) - appFrame.left;
825 clipStartX = 0;
826 cutOff = true;
827 }
828 if (appFrame.right < centerX + halfWidth) {
829 translationX = (centerX + halfWidth) - appFrame.right;
830 clipStartX = appWidth - mTmpRect.width();
831 cutOff = true;
832 }
833 final long duration = calculateClipRevealTransitionDuration(cutOff, translationX,
834 translationY, displayFrame);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700835
836 // Clip third of the from size of launch icon, expand to full width/height
Chet Haase10e23ab2015-02-11 15:08:38 -0800837 Animation clipAnimLR = new ClipRectLRAnimation(
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800838 clipStartX, clipStartX + mTmpRect.width(), 0, appWidth);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700839 clipAnimLR.setInterpolator(mClipHorizontalInterpolator);
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800840 clipAnimLR.setDuration((long) (duration / 2.5f));
Filip Gruszczynski82861362015-10-16 14:21:09 -0700841
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800842 TranslateAnimation translate = new TranslateAnimation(translationX, 0, translationY, 0);
843 translate.setInterpolator(cutOff ? TOUCH_RESPONSE_INTERPOLATOR
844 : mLinearOutSlowInInterpolator);
845 translate.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800846
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800847 Animation clipAnimTB = new ClipRectTBAnimation(
848 clipStartY, clipStartY + mTmpRect.height(),
849 0, appHeight,
850 translationYCorrection, 0,
851 mLinearOutSlowInInterpolator);
852 clipAnimTB.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
853 clipAnimTB.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800854
855 // Quick fade-in from icon to app window
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800856 final long alphaDuration = duration / 4;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700857 AlphaAnimation alpha = new AlphaAnimation(0.5f, 1);
Chet Haase10e23ab2015-02-11 15:08:38 -0800858 alpha.setDuration(alphaDuration);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700859 alpha.setInterpolator(mLinearOutSlowInInterpolator);
Chet Haase10e23ab2015-02-11 15:08:38 -0800860
861 AnimationSet set = new AnimationSet(false);
862 set.addAnimation(clipAnimLR);
863 set.addAnimation(clipAnimTB);
Filip Gruszczynski82861362015-10-16 14:21:09 -0700864 set.addAnimation(translate);
Chet Haase10e23ab2015-02-11 15:08:38 -0800865 set.addAnimation(alpha);
Filip Gruszczynski9e2cf5b2015-07-31 12:20:40 -0700866 set.setZAdjustment(Animation.ZORDER_TOP);
Chet Haase10e23ab2015-02-11 15:08:38 -0800867 set.initialize(appWidth, appHeight, appWidth, appHeight);
868 anim = set;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800869 mLastHadClipReveal = true;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800870 mLastClipRevealTransitionDuration = duration;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800871
872 // If the start rect was full inside the target rect (cutOff == false), we don't need
873 // to store the translation, because it's only used if cutOff == true.
874 mLastClipRevealMaxTranslation = cutOff
875 ? Math.max(Math.abs(translationY), Math.abs(translationX)) : 0;
Chet Haase10e23ab2015-02-11 15:08:38 -0800876 } else {
877 final long duration;
878 switch (transit) {
879 case TRANSIT_ACTIVITY_OPEN:
880 case TRANSIT_ACTIVITY_CLOSE:
881 duration = mConfigShortAnimTime;
882 break;
883 default:
884 duration = DEFAULT_APP_TRANSITION_DURATION;
885 break;
886 }
887 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
888 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
889 // If we are on top of the wallpaper, we need an animation that
890 // correctly handles the wallpaper staying static behind all of
891 // the animated elements. To do this, will just have the existing
892 // element fade out.
893 anim = new AlphaAnimation(1, 0);
894 anim.setDetachWallpaper(true);
895 } else {
896 // For normal animations, the exiting element just holds in place.
897 anim = new AlphaAnimation(1, 1);
898 }
899 anim.setInterpolator(mDecelerateInterpolator);
900 anim.setDuration(duration);
901 anim.setFillAfter(true);
902 }
903 return anim;
904 }
905
Winson Chung399f6202014-03-19 10:47:20 -0700906 /**
907 * Prepares the specified animation with a standard duration, interpolator, etc.
908 */
Winson Chung5393dff2014-05-08 14:25:43 -0700909 Animation prepareThumbnailAnimationWithDuration(Animation a, int appWidth, int appHeight,
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100910 long duration, Interpolator interpolator) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700911 if (duration > 0) {
912 a.setDuration(duration);
913 }
Winson Chung5393dff2014-05-08 14:25:43 -0700914 a.setFillAfter(true);
Jorim Jaggic69bd222016-03-15 14:38:37 +0100915 if (interpolator != null) {
916 a.setInterpolator(interpolator);
917 }
Winson Chung5393dff2014-05-08 14:25:43 -0700918 a.initialize(appWidth, appHeight, appWidth, appHeight);
919 return a;
920 }
921
922 /**
923 * Prepares the specified animation with a standard duration, interpolator, etc.
924 */
Winson Chung399f6202014-03-19 10:47:20 -0700925 Animation prepareThumbnailAnimation(Animation a, int appWidth, int appHeight, int transit) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800926 // Pick the desired duration. If this is an inter-activity transition,
927 // it is the standard duration for that. Otherwise we use the longer
928 // task transition duration.
Winson Chung5393dff2014-05-08 14:25:43 -0700929 final int duration;
Craig Mautner321bdf52012-12-18 09:53:24 -0800930 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800931 case TRANSIT_ACTIVITY_OPEN:
932 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800933 duration = mConfigShortAnimTime;
934 break;
935 default:
936 duration = DEFAULT_APP_TRANSITION_DURATION;
937 break;
938 }
Winson Chung5393dff2014-05-08 14:25:43 -0700939 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, duration,
940 mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800941 }
942
Winson Chung399f6202014-03-19 10:47:20 -0700943 /**
944 * Return the current thumbnail transition state.
945 */
946 int getThumbnailTransitionState(boolean enter) {
947 if (enter) {
948 if (mNextAppTransitionScaleUp) {
949 return THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
950 } else {
951 return THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN;
952 }
953 } else {
954 if (mNextAppTransitionScaleUp) {
955 return THUMBNAIL_TRANSITION_EXIT_SCALE_UP;
956 } else {
957 return THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN;
958 }
959 }
960 }
961
962 /**
963 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700964 * when a thumbnail is specified with the pending animation override.
Winson Chung399f6202014-03-19 10:47:20 -0700965 */
Jorim Jaggide63d442016-03-14 14:56:56 +0100966 Animation createThumbnailAspectScaleAnimationLocked(Rect appRect, @Nullable Rect contentInsets,
Winson Chungaa7fa012017-05-24 15:50:06 -0700967 GraphicBuffer thumbnailHeader, final int taskId, int uiMode, int orientation) {
Winson Chung399f6202014-03-19 10:47:20 -0700968 Animation a;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700969 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chung399f6202014-03-19 10:47:20 -0700970 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700971 final int thumbHeightI = thumbnailHeader.getHeight();
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700972 final int appWidth = appRect.width();
Winson Chung399f6202014-03-19 10:47:20 -0700973
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700974 float scaleW = appWidth / thumbWidth;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700975 getNextAppTransitionStartRect(taskId, mTmpRect);
Jorim Jaggi09072002016-03-25 16:48:42 -0700976 final float fromX;
Manu Cornet57b61492017-01-24 18:19:05 +0900977 float fromY;
Jorim Jaggi09072002016-03-25 16:48:42 -0700978 final float toX;
Manu Cornet57b61492017-01-24 18:19:05 +0900979 float toY;
Jorim Jaggi09072002016-03-25 16:48:42 -0700980 final float pivotX;
981 final float pivotY;
Manu Cornetd7376802017-01-13 13:44:07 -0800982 if (shouldScaleDownThumbnailTransition(uiMode, orientation)) {
Jorim Jaggi09072002016-03-25 16:48:42 -0700983 fromX = mTmpRect.left;
984 fromY = mTmpRect.top;
985
986 // For the curved translate animation to work, the pivot points needs to be at the
987 // same absolute position as the one from the real surface.
988 toX = mTmpRect.width() / 2 * (scaleW - 1f) + appRect.left;
989 toY = appRect.height() / 2 * (1 - 1 / scaleW) + appRect.top;
990 pivotX = mTmpRect.width() / 2;
991 pivotY = appRect.height() / 2 / scaleW;
Manu Cornet57b61492017-01-24 18:19:05 +0900992 if (mGridLayoutRecentsEnabled) {
993 // In the grid layout, the header is displayed above the thumbnail instead of
994 // overlapping it.
995 fromY -= thumbHeightI;
996 toY -= thumbHeightI * scaleW;
997 }
Jorim Jaggi09072002016-03-25 16:48:42 -0700998 } else {
999 pivotX = 0;
1000 pivotY = 0;
1001 fromX = mTmpRect.left;
1002 fromY = mTmpRect.top;
1003 toX = appRect.left;
1004 toY = appRect.top;
1005 }
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001006 final long duration = getAspectScaleDuration();
1007 final Interpolator interpolator = getAspectScaleInterpolator();
Winson Chung399f6202014-03-19 10:47:20 -07001008 if (mNextAppTransitionScaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001009 // Animation up from the thumbnail to the full screen
Jorim Jaggi8448f332016-03-14 17:50:37 +01001010 Animation scale = new ScaleAnimation(1f, scaleW, 1f, scaleW, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001011 scale.setInterpolator(interpolator);
1012 scale.setDuration(duration);
Jorim Jaggic6c89a82016-01-28 17:48:21 -08001013 Animation alpha = new AlphaAnimation(1f, 0f);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001014 alpha.setInterpolator(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
1015 ? THUMBNAIL_DOCK_INTERPOLATOR : mThumbnailFadeOutInterpolator);
1016 alpha.setDuration(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
1017 ? duration / 2
1018 : duration);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001019 Animation translate = createCurvedMotion(fromX, toX, fromY, toY);
1020 translate.setInterpolator(interpolator);
1021 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -07001022
Jorim Jaggide63d442016-03-14 14:56:56 +01001023 mTmpFromClipRect.set(0, 0, thumbWidthI, thumbHeightI);
1024 mTmpToClipRect.set(appRect);
1025
1026 // Containing frame is in screen space, but we need the clip rect in the
1027 // app space.
1028 mTmpToClipRect.offsetTo(0, 0);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001029 mTmpToClipRect.right = (int) (mTmpToClipRect.right / scaleW);
1030 mTmpToClipRect.bottom = (int) (mTmpToClipRect.bottom / scaleW);
Jorim Jaggide63d442016-03-14 14:56:56 +01001031
1032 if (contentInsets != null) {
Jorim Jaggi8448f332016-03-14 17:50:37 +01001033 mTmpToClipRect.inset((int) (-contentInsets.left * scaleW),
1034 (int) (-contentInsets.top * scaleW),
1035 (int) (-contentInsets.right * scaleW),
1036 (int) (-contentInsets.bottom * scaleW));
Jorim Jaggide63d442016-03-14 14:56:56 +01001037 }
1038
1039 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001040 clipAnim.setInterpolator(interpolator);
1041 clipAnim.setDuration(duration);
Jorim Jaggide63d442016-03-14 14:56:56 +01001042
Winson Chung399f6202014-03-19 10:47:20 -07001043 // This AnimationSet uses the Interpolators assigned above.
1044 AnimationSet set = new AnimationSet(false);
1045 set.addAnimation(scale);
Manu Cornet57b61492017-01-24 18:19:05 +09001046 if (!mGridLayoutRecentsEnabled) {
1047 // In the grid layout, the header should be shown for the whole animation.
1048 set.addAnimation(alpha);
1049 }
Winson Chunga4ccb862014-08-22 15:26:27 -07001050 set.addAnimation(translate);
Jorim Jaggide63d442016-03-14 14:56:56 +01001051 set.addAnimation(clipAnim);
Winson Chung399f6202014-03-19 10:47:20 -07001052 a = set;
1053 } else {
Winson Chunga4ccb862014-08-22 15:26:27 -07001054 // Animation down from the full screen to the thumbnail
Jorim Jaggi8448f332016-03-14 17:50:37 +01001055 Animation scale = new ScaleAnimation(scaleW, 1f, scaleW, 1f, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001056 scale.setInterpolator(interpolator);
1057 scale.setDuration(duration);
Winson Chunga4ccb862014-08-22 15:26:27 -07001058 Animation alpha = new AlphaAnimation(0f, 1f);
1059 alpha.setInterpolator(mThumbnailFadeInInterpolator);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001060 alpha.setDuration(duration);
1061 Animation translate = createCurvedMotion(toX, fromX, toY, fromY);
1062 translate.setInterpolator(interpolator);
1063 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -07001064
Winson Chunga4ccb862014-08-22 15:26:27 -07001065 // This AnimationSet uses the Interpolators assigned above.
1066 AnimationSet set = new AnimationSet(false);
1067 set.addAnimation(scale);
Manu Cornet57b61492017-01-24 18:19:05 +09001068 if (!mGridLayoutRecentsEnabled) {
1069 // In the grid layout, the header should be shown for the whole animation.
1070 set.addAnimation(alpha);
1071 }
Winson Chunga4ccb862014-08-22 15:26:27 -07001072 set.addAnimation(translate);
1073 a = set;
1074
1075 }
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -07001076 return prepareThumbnailAnimationWithDuration(a, appWidth, appRect.height(), 0,
Jorim Jaggic69bd222016-03-15 14:38:37 +01001077 null);
Winson Chung399f6202014-03-19 10:47:20 -07001078 }
1079
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001080 private Animation createCurvedMotion(float fromX, float toX, float fromY, float toY) {
1081
1082 // Almost no x-change - use linear animation
Jorim Jaggic69bd222016-03-15 14:38:37 +01001083 if (Math.abs(toX - fromX) < 1f || mNextAppTransition != TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001084 return new TranslateAnimation(fromX, toX, fromY, toY);
1085 } else {
1086 final Path path = createCurvedPath(fromX, toX, fromY, toY);
1087 return new CurvedTranslateAnimation(path);
1088 }
1089 }
1090
1091 private Path createCurvedPath(float fromX, float toX, float fromY, float toY) {
1092 final Path path = new Path();
1093 path.moveTo(fromX, fromY);
Jorim Jaggi1f458fb2016-03-25 17:36:37 -07001094
1095 if (fromY > toY) {
1096 // If the object needs to go up, move it in horizontal direction first, then vertical.
1097 path.cubicTo(fromX, fromY, toX, 0.9f * fromY + 0.1f * toY, toX, toY);
1098 } else {
1099 // If the object needs to go down, move it in vertical direction first, then horizontal.
1100 path.cubicTo(fromX, fromY, fromX, 0.1f * fromY + 0.9f * toY, toX, toY);
1101 }
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001102 return path;
1103 }
1104
1105 private long getAspectScaleDuration() {
1106 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggic69bd222016-03-15 14:38:37 +01001107 return (long) (THUMBNAIL_APP_TRANSITION_DURATION * 1.35f);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001108 } else {
1109 return THUMBNAIL_APP_TRANSITION_DURATION;
1110 }
1111 }
1112
1113 private Interpolator getAspectScaleInterpolator() {
1114 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
1115 return mFastOutSlowInInterpolator;
1116 } else {
1117 return TOUCH_RESPONSE_INTERPOLATOR;
1118 }
1119 }
1120
Winson Chung399f6202014-03-19 10:47:20 -07001121 /**
1122 * This alternate animation is created when we are doing a thumbnail transition, for the
1123 * activity that is leaving, and the activity that is entering.
1124 */
Winson Chunga4ccb862014-08-22 15:26:27 -07001125 Animation createAspectScaledThumbnailEnterExitAnimationLocked(int thumbTransitState,
Winsonb2024762016-04-05 17:32:30 -07001126 int uiMode, int orientation, int transit, Rect containingFrame, Rect contentInsets,
Matthew Ng43db6d22017-06-27 15:29:39 -07001127 @Nullable Rect surfaceInsets, @Nullable Rect stableInsets, boolean freeform,
1128 int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -07001129 Animation a;
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001130 final int appWidth = containingFrame.width();
1131 final int appHeight = containingFrame.height();
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001132 getDefaultNextAppTransitionStartRect(mTmpRect);
1133 final int thumbWidthI = mTmpRect.width();
Winson Chung399f6202014-03-19 10:47:20 -07001134 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001135 final int thumbHeightI = mTmpRect.height();
Winson Chung399f6202014-03-19 10:47:20 -07001136 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
Winsoncbb625b2016-07-06 15:24:15 -07001137 final int thumbStartX = mTmpRect.left - containingFrame.left - contentInsets.left;
Winson21700932016-03-24 17:26:23 -07001138 final int thumbStartY = mTmpRect.top - containingFrame.top;
Winson Chung399f6202014-03-19 10:47:20 -07001139
1140 switch (thumbTransitState) {
Jorim Jaggi8448f332016-03-14 17:50:37 +01001141 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP:
1142 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1143 final boolean scaleUp = thumbTransitState == THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
1144 if (freeform && scaleUp) {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001145 a = createAspectScaledThumbnailEnterFreeformAnimationLocked(
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001146 containingFrame, surfaceInsets, taskId);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001147 } else if (freeform) {
1148 a = createAspectScaledThumbnailExitFreeformAnimationLocked(
1149 containingFrame, surfaceInsets, taskId);
Winson Chung2820c452014-04-15 15:34:44 -07001150 } else {
Winson21700932016-03-24 17:26:23 -07001151 AnimationSet set = new AnimationSet(true);
1152
1153 // In portrait, we scale to fit the width
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001154 mTmpFromClipRect.set(containingFrame);
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001155 mTmpToClipRect.set(containingFrame);
Jorim Jaggic6c89a82016-01-28 17:48:21 -08001156
1157 // Containing frame is in screen space, but we need the clip rect in the
1158 // app space.
1159 mTmpFromClipRect.offsetTo(0, 0);
1160 mTmpToClipRect.offsetTo(0, 0);
1161
1162 // Exclude insets region from the source clip.
1163 mTmpFromClipRect.inset(contentInsets);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001164 mNextAppTransitionInsets.set(contentInsets);
1165
Manu Cornetd7376802017-01-13 13:44:07 -08001166 if (shouldScaleDownThumbnailTransition(uiMode, orientation)) {
Jorim Jaggic69bd222016-03-15 14:38:37 +01001167 // We scale the width and clip to the top/left square
1168 float scale = thumbWidth /
1169 (appWidth - contentInsets.left - contentInsets.right);
Manu Cornetb68b7652017-01-23 19:37:53 +09001170 if (!mGridLayoutRecentsEnabled) {
1171 int unscaledThumbHeight = (int) (thumbHeight / scale);
1172 mTmpFromClipRect.bottom = mTmpFromClipRect.top + unscaledThumbHeight;
1173 }
Jorim Jaggic69bd222016-03-15 14:38:37 +01001174
1175 mNextAppTransitionInsets.set(contentInsets);
1176
Jorim Jaggi8448f332016-03-14 17:50:37 +01001177 Animation scaleAnim = new ScaleAnimation(
1178 scaleUp ? scale : 1, scaleUp ? 1 : scale,
1179 scaleUp ? scale : 1, scaleUp ? 1 : scale,
Jorim Jaggic69bd222016-03-15 14:38:37 +01001180 containingFrame.width() / 2f,
1181 containingFrame.height() / 2f + contentInsets.top);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001182 final float targetX = (mTmpRect.left - containingFrame.left);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001183 final float x = containingFrame.width() / 2f
1184 - containingFrame.width() / 2f * scale;
Jorim Jaggi8448f332016-03-14 17:50:37 +01001185 final float targetY = (mTmpRect.top - containingFrame.top);
Matthew Ng43db6d22017-06-27 15:29:39 -07001186 float y = containingFrame.height() / 2f
Jorim Jaggic69bd222016-03-15 14:38:37 +01001187 - containingFrame.height() / 2f * scale;
Matthew Ng43db6d22017-06-27 15:29:39 -07001188
1189 // During transition may require clipping offset from any top stable insets
1190 // such as the statusbar height when statusbar is hidden
1191 if (mLowRamRecentsEnabled && contentInsets.top == 0 && scaleUp) {
1192 mTmpFromClipRect.top += stableInsets.top;
1193 y += stableInsets.top;
1194 }
Jorim Jaggi8448f332016-03-14 17:50:37 +01001195 final float startX = targetX - x;
1196 final float startY = targetY - y;
1197 Animation clipAnim = scaleUp
1198 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1199 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1200 Animation translateAnim = scaleUp
Jorim Jaggic69bd222016-03-15 14:38:37 +01001201 ? createCurvedMotion(startX, 0, startY - contentInsets.top, 0)
1202 : createCurvedMotion(0, startX, 0, startY - contentInsets.top);
1203
Winson21700932016-03-24 17:26:23 -07001204 set.addAnimation(clipAnim);
1205 set.addAnimation(scaleAnim);
1206 set.addAnimation(translateAnim);
1207
1208 } else {
1209 // In landscape, we don't scale at all and only crop
1210 mTmpFromClipRect.bottom = mTmpFromClipRect.top + thumbHeightI;
1211 mTmpFromClipRect.right = mTmpFromClipRect.left + thumbWidthI;
1212
Jorim Jaggi8448f332016-03-14 17:50:37 +01001213 Animation clipAnim = scaleUp
1214 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1215 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1216 Animation translateAnim = scaleUp
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001217 ? createCurvedMotion(thumbStartX, 0,
1218 thumbStartY - contentInsets.top, 0)
1219 : createCurvedMotion(0, thumbStartX, 0,
1220 thumbStartY - contentInsets.top);
Winson21700932016-03-24 17:26:23 -07001221
1222 set.addAnimation(clipAnim);
1223 set.addAnimation(translateAnim);
1224 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001225 a = set;
Winson21700932016-03-24 17:26:23 -07001226 a.setZAdjustment(Animation.ZORDER_TOP);
Winson Chung2820c452014-04-15 15:34:44 -07001227 }
Winson Chung399f6202014-03-19 10:47:20 -07001228 break;
1229 }
1230 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001231 // Previous app window during the scale up
Winson Chung399f6202014-03-19 10:47:20 -07001232 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001233 // Fade out the source activity if we are animating to a wallpaper
Winson Chung399f6202014-03-19 10:47:20 -07001234 // activity.
1235 a = new AlphaAnimation(1, 0);
1236 } else {
Winson Chung399f6202014-03-19 10:47:20 -07001237 a = new AlphaAnimation(1, 1);
1238 }
1239 break;
1240 }
1241 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001242 // Target app window during the scale down
1243 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1244 // Fade in the destination activity if we are animating from a wallpaper
1245 // activity.
1246 a = new AlphaAnimation(0, 1);
1247 } else {
1248 a = new AlphaAnimation(1, 1);
1249 }
Winson Chung399f6202014-03-19 10:47:20 -07001250 break;
1251 }
Winson Chung399f6202014-03-19 10:47:20 -07001252 default:
1253 throw new RuntimeException("Invalid thumbnail transition state");
1254 }
1255
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001256 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight,
1257 getAspectScaleDuration(), getAspectScaleInterpolator());
Winson Chung399f6202014-03-19 10:47:20 -07001258 }
1259
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001260 private Animation createAspectScaledThumbnailEnterFreeformAnimationLocked(Rect frame,
1261 @Nullable Rect surfaceInsets, int taskId) {
1262 getNextAppTransitionStartRect(taskId, mTmpRect);
1263 return createAspectScaledThumbnailFreeformAnimationLocked(mTmpRect, frame, surfaceInsets,
1264 true);
1265 }
1266
1267 private Animation createAspectScaledThumbnailExitFreeformAnimationLocked(Rect frame,
1268 @Nullable Rect surfaceInsets, int taskId) {
1269 getNextAppTransitionStartRect(taskId, mTmpRect);
1270 return createAspectScaledThumbnailFreeformAnimationLocked(frame, mTmpRect, surfaceInsets,
1271 false);
1272 }
1273
1274 private AnimationSet createAspectScaledThumbnailFreeformAnimationLocked(Rect sourceFrame,
1275 Rect destFrame, @Nullable Rect surfaceInsets, boolean enter) {
1276 final float sourceWidth = sourceFrame.width();
1277 final float sourceHeight = sourceFrame.height();
1278 final float destWidth = destFrame.width();
1279 final float destHeight = destFrame.height();
1280 final float scaleH = enter ? sourceWidth / destWidth : destWidth / sourceWidth;
1281 final float scaleV = enter ? sourceHeight / destHeight : destHeight / sourceHeight;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001282 AnimationSet set = new AnimationSet(true);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001283 final int surfaceInsetsH = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001284 ? 0 : surfaceInsets.left + surfaceInsets.right;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001285 final int surfaceInsetsV = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001286 ? 0 : surfaceInsets.top + surfaceInsets.bottom;
1287 // We want the scaling to happen from the center of the surface. In order to achieve that,
1288 // we need to account for surface insets that will be used to enlarge the surface.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001289 final float scaleHCenter = ((enter ? destWidth : sourceWidth) + surfaceInsetsH) / 2;
1290 final float scaleVCenter = ((enter ? destHeight : sourceHeight) + surfaceInsetsV) / 2;
1291 final ScaleAnimation scale = enter ?
1292 new ScaleAnimation(scaleH, 1, scaleV, 1, scaleHCenter, scaleVCenter)
1293 : new ScaleAnimation(1, scaleH, 1, scaleV, scaleHCenter, scaleVCenter);
1294 final int sourceHCenter = sourceFrame.left + sourceFrame.width() / 2;
1295 final int sourceVCenter = sourceFrame.top + sourceFrame.height() / 2;
1296 final int destHCenter = destFrame.left + destFrame.width() / 2;
1297 final int destVCenter = destFrame.top + destFrame.height() / 2;
1298 final int fromX = enter ? sourceHCenter - destHCenter : destHCenter - sourceHCenter;
1299 final int fromY = enter ? sourceVCenter - destVCenter : destVCenter - sourceVCenter;
1300 final TranslateAnimation translation = enter ? new TranslateAnimation(fromX, 0, fromY, 0)
1301 : new TranslateAnimation(0, fromX, 0, fromY);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001302 set.addAnimation(scale);
1303 set.addAnimation(translation);
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001304
1305 final IRemoteCallback callback = mAnimationFinishedCallback;
1306 if (callback != null) {
1307 set.setAnimationListener(new Animation.AnimationListener() {
1308 @Override
1309 public void onAnimationStart(Animation animation) { }
1310
1311 @Override
1312 public void onAnimationEnd(Animation animation) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001313 mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK, callback).sendToTarget();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001314 }
1315
1316 @Override
1317 public void onAnimationRepeat(Animation animation) { }
1318 });
1319 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001320 return set;
1321 }
1322
Winson Chung399f6202014-03-19 10:47:20 -07001323 /**
Winson Chunga4ccb862014-08-22 15:26:27 -07001324 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001325 * when a thumbnail is specified with the pending animation override.
Winson Chunga4ccb862014-08-22 15:26:27 -07001326 */
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001327 Animation createThumbnailScaleAnimationLocked(int appWidth, int appHeight, int transit,
Winson Chungaa7fa012017-05-24 15:50:06 -07001328 GraphicBuffer thumbnailHeader) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001329 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001330 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001331 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chunga4ccb862014-08-22 15:26:27 -07001332 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001333 final int thumbHeightI = thumbnailHeader.getHeight();
Winson Chunga4ccb862014-08-22 15:26:27 -07001334 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1335
1336 if (mNextAppTransitionScaleUp) {
1337 // Animation for the thumbnail zooming from its initial size to the full screen
1338 float scaleW = appWidth / thumbWidth;
1339 float scaleH = appHeight / thumbHeight;
1340 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001341 computePivot(mTmpRect.left, 1 / scaleW),
1342 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001343 scale.setInterpolator(mDecelerateInterpolator);
1344
1345 Animation alpha = new AlphaAnimation(1, 0);
1346 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
1347
1348 // This AnimationSet uses the Interpolators assigned above.
1349 AnimationSet set = new AnimationSet(false);
1350 set.addAnimation(scale);
1351 set.addAnimation(alpha);
1352 a = set;
1353 } else {
1354 // Animation for the thumbnail zooming down from the full screen to its final size
1355 float scaleW = appWidth / thumbWidth;
1356 float scaleH = appHeight / thumbHeight;
1357 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001358 computePivot(mTmpRect.left, 1 / scaleW),
1359 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001360 }
1361
1362 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1363 }
1364
1365 /**
Winson Chung399f6202014-03-19 10:47:20 -07001366 * This animation is created when we are doing a thumbnail transition, for the activity that is
1367 * leaving, and the activity that is entering.
1368 */
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001369 Animation createThumbnailEnterExitAnimationLocked(int thumbTransitState, Rect containingFrame,
1370 int transit, int taskId) {
1371 final int appWidth = containingFrame.width();
1372 final int appHeight = containingFrame.height();
Winson Chungaa7fa012017-05-24 15:50:06 -07001373 final GraphicBuffer thumbnailHeader = getAppTransitionThumbnailHeader(taskId);
Winson Chung399f6202014-03-19 10:47:20 -07001374 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001375 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001376 final int thumbWidthI = thumbnailHeader != null ? thumbnailHeader.getWidth() : appWidth;
Winson Chung399f6202014-03-19 10:47:20 -07001377 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001378 final int thumbHeightI = thumbnailHeader != null ? thumbnailHeader.getHeight() : appHeight;
Winson Chung399f6202014-03-19 10:47:20 -07001379 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1380
1381 switch (thumbTransitState) {
1382 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
1383 // Entering app scales up with the thumbnail
1384 float scaleW = thumbWidth / appWidth;
1385 float scaleH = thumbHeight / appHeight;
1386 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001387 computePivot(mTmpRect.left, scaleW),
1388 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001389 break;
1390 }
1391 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
1392 // Exiting app while the thumbnail is scaling up should fade or stay in place
1393 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1394 // Fade out while bringing up selected activity. This keeps the
1395 // current activity from showing through a launching wallpaper
1396 // activity.
1397 a = new AlphaAnimation(1, 0);
1398 } else {
1399 // noop animation
1400 a = new AlphaAnimation(1, 1);
1401 }
1402 break;
1403 }
1404 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
1405 // Entering the other app, it should just be visible while we scale the thumbnail
1406 // down above it
1407 a = new AlphaAnimation(1, 1);
1408 break;
1409 }
1410 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1411 // Exiting the current app, the app should scale down with the thumbnail
1412 float scaleW = thumbWidth / appWidth;
1413 float scaleH = thumbHeight / appHeight;
1414 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001415 computePivot(mTmpRect.left, scaleW),
1416 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001417
1418 Animation alpha = new AlphaAnimation(1, 0);
1419
1420 AnimationSet set = new AnimationSet(true);
1421 set.addAnimation(scale);
1422 set.addAnimation(alpha);
1423 set.setZAdjustment(Animation.ZORDER_TOP);
1424 a = set;
1425 break;
1426 }
1427 default:
1428 throw new RuntimeException("Invalid thumbnail transition state");
1429 }
1430
1431 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1432 }
1433
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001434 private Animation createRelaunchAnimation(Rect containingFrame, Rect contentInsets) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001435 getDefaultNextAppTransitionStartRect(mTmpFromClipRect);
1436 final int left = mTmpFromClipRect.left;
1437 final int top = mTmpFromClipRect.top;
1438 mTmpFromClipRect.offset(-left, -top);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001439 // TODO: Isn't that strange that we ignore exact position of the containingFrame?
1440 mTmpToClipRect.set(0, 0, containingFrame.width(), containingFrame.height());
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001441 AnimationSet set = new AnimationSet(true);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001442 float fromWidth = mTmpFromClipRect.width();
1443 float toWidth = mTmpToClipRect.width();
1444 float fromHeight = mTmpFromClipRect.height();
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001445 // While the window might span the whole display, the actual content will be cropped to the
1446 // system decoration frame, for example when the window is docked. We need to take into
1447 // account the visible height when constructing the animation.
1448 float toHeight = mTmpToClipRect.height() - contentInsets.top - contentInsets.bottom;
1449 int translateAdjustment = 0;
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001450 if (fromWidth <= toWidth && fromHeight <= toHeight) {
1451 // The final window is larger in both dimensions than current window (e.g. we are
1452 // maximizing), so we can simply unclip the new window and there will be no disappearing
1453 // frame.
1454 set.addAnimation(new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect));
1455 } else {
1456 // The disappearing window has one larger dimension. We need to apply scaling, so the
1457 // first frame of the entry animation matches the old window.
1458 set.addAnimation(new ScaleAnimation(fromWidth / toWidth, 1, fromHeight / toHeight, 1));
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001459 // We might not be going exactly full screen, but instead be aligned under the status
1460 // bar using cropping. We still need to account for the cropped part, which will also
1461 // be scaled.
1462 translateAdjustment = (int) (contentInsets.top * fromHeight / toHeight);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001463 }
1464
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001465 // We animate the translation from the old position of the removed window, to the new
1466 // position of the added window. The latter might not be full screen, for example docked for
1467 // docked windows.
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001468 TranslateAnimation translate = new TranslateAnimation(left - containingFrame.left,
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001469 0, top - containingFrame.top - translateAdjustment, 0);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001470 set.addAnimation(translate);
1471 set.setDuration(DEFAULT_APP_TRANSITION_DURATION);
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07001472 set.setZAdjustment(Animation.ZORDER_TOP);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001473 return set;
1474 }
1475
Jorim Jaggic554b772015-06-04 16:07:57 -07001476 /**
1477 * @return true if and only if the first frame of the transition can be skipped, i.e. the first
1478 * frame of the transition doesn't change the visuals on screen, so we can start
1479 * directly with the second one
1480 */
1481 boolean canSkipFirstFrame() {
1482 return mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM
1483 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE
Jorim Jaggife762342016-10-13 14:33:27 +02001484 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CLIP_REVEAL
1485 && mNextAppTransition != TRANSIT_KEYGUARD_GOING_AWAY;
Jorim Jaggic554b772015-06-04 16:07:57 -07001486 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001487
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001488 /**
1489 *
1490 * @param frame These are the bounds of the window when it finishes the animation. This is where
1491 * the animation must usually finish in entrance animation, as the next frame will
1492 * display the window at these coordinates. In case of exit animation, this is
1493 * where the animation must start, as the frame before the animation is displaying
1494 * the window at these bounds.
1495 * @param insets Knowing where the window will be positioned is not enough. Some parts of the
1496 * window might be obscured, usually by the system windows (status bar and
1497 * navigation bar) and we use content insets to convey that information. This
1498 * usually affects the animation aspects vertically, as the system decoration is
1499 * at the top and the bottom. For example when we animate from full screen to
1500 * recents, we want to exclude the covered parts, because they won't match the
1501 * thumbnail after the last frame is executed.
1502 * @param surfaceInsets In rare situation the surface is larger than the content and we need to
1503 * know about this to make the animation frames match. We currently use
1504 * this for freeform windows, which have larger surfaces to display
1505 * shadows. When we animate them from recents, we want to match the content
1506 * to the recents thumbnail and hence need to account for the surface being
1507 * bigger.
1508 */
Winsonb2024762016-04-05 17:32:30 -07001509 Animation loadAnimation(WindowManager.LayoutParams lp, int transit, boolean enter, int uiMode,
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001510 int orientation, Rect frame, Rect displayFrame, Rect insets,
Matthew Ng43db6d22017-06-27 15:29:39 -07001511 @Nullable Rect surfaceInsets, @Nullable Rect stableInsets, boolean isVoiceInteraction,
1512 boolean freeform, int taskId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001513 Animation a;
Jorim Jaggife762342016-10-13 14:33:27 +02001514 if (isKeyguardGoingAwayTransit(transit) && enter) {
1515 a = loadKeyguardExitAnimation(transit);
1516 } else if (transit == TRANSIT_KEYGUARD_OCCLUDE) {
1517 a = null;
1518 } else if (transit == TRANSIT_KEYGUARD_UNOCCLUDE && !enter) {
1519 a = loadAnimationRes(lp, com.android.internal.R.anim.wallpaper_open_exit);
1520 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_OPEN
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001521 || transit == TRANSIT_TASK_OPEN
1522 || transit == TRANSIT_TASK_TO_FRONT)) {
1523 a = loadAnimationRes(lp, enter
1524 ? com.android.internal.R.anim.voice_activity_open_enter
1525 : com.android.internal.R.anim.voice_activity_open_exit);
1526 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1527 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001528 + " anim=" + a + " transit=" + appTransitionToString(transit)
1529 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001530 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_CLOSE
1531 || transit == TRANSIT_TASK_CLOSE
1532 || transit == TRANSIT_TASK_TO_BACK)) {
1533 a = loadAnimationRes(lp, enter
1534 ? com.android.internal.R.anim.voice_activity_close_enter
1535 : com.android.internal.R.anim.voice_activity_close_exit);
1536 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1537 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001538 + " anim=" + a + " transit=" + appTransitionToString(transit)
1539 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001540 } else if (transit == TRANSIT_ACTIVITY_RELAUNCH) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001541 a = createRelaunchAnimation(frame, insets);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001542 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1543 "applyAnimation:"
1544 + " anim=" + a + " nextAppTransition=" + mNextAppTransition
1545 + " transit=" + appTransitionToString(transit)
1546 + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001547 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM) {
1548 a = loadAnimationRes(mNextAppTransitionPackage, enter ?
Craig Mautner164d4bb2012-11-26 13:51:23 -08001549 mNextAppTransitionEnter : mNextAppTransitionExit);
1550 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1551 "applyAnimation:"
1552 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001553 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001554 + " Callers=" + Debug.getCallers(3));
Winson Chung044d5292014-11-06 11:05:19 -08001555 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE) {
1556 a = loadAnimationRes(mNextAppTransitionPackage, mNextAppTransitionInPlace);
1557 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1558 "applyAnimation:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001559 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM_IN_PLACE"
1560 + " transit=" + appTransitionToString(transit)
1561 + " Callers=" + Debug.getCallers(3));
Chet Haase10e23ab2015-02-11 15:08:38 -08001562 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001563 a = createClipRevealAnimationLocked(transit, enter, frame, displayFrame);
Chet Haase10e23ab2015-02-11 15:08:38 -08001564 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1565 "applyAnimation:"
1566 + " anim=" + a + " nextAppTransition=ANIM_CLIP_REVEAL"
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001567 + " transit=" + appTransitionToString(transit)
Chet Haase10e23ab2015-02-11 15:08:38 -08001568 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001569 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_SCALE_UP) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001570 a = createScaleUpAnimationLocked(transit, enter, frame);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001571 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1572 "applyAnimation:"
1573 + " anim=" + a + " nextAppTransition=ANIM_SCALE_UP"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001574 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001575 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001576 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
1577 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001578 mNextAppTransitionScaleUp =
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001579 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP);
Winson Chunga4ccb862014-08-22 15:26:27 -07001580 a = createThumbnailEnterExitAnimationLocked(getThumbnailTransitionState(enter),
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001581 frame, transit, taskId);
Winson Chunga4ccb862014-08-22 15:26:27 -07001582 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1583 String animName = mNextAppTransitionScaleUp ?
1584 "ANIM_THUMBNAIL_SCALE_UP" : "ANIM_THUMBNAIL_SCALE_DOWN";
1585 Slog.v(TAG, "applyAnimation:"
1586 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001587 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Winson Chunga4ccb862014-08-22 15:26:27 -07001588 + " Callers=" + Debug.getCallers(3));
1589 }
1590 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
1591 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN) {
1592 mNextAppTransitionScaleUp =
1593 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP);
1594 a = createAspectScaledThumbnailEnterExitAnimationLocked(
Winsonb2024762016-04-05 17:32:30 -07001595 getThumbnailTransitionState(enter), uiMode, orientation, transit, frame,
Matthew Ng43db6d22017-06-27 15:29:39 -07001596 insets, surfaceInsets, stableInsets, freeform, taskId);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001597 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1598 String animName = mNextAppTransitionScaleUp ?
Winson Chunga4ccb862014-08-22 15:26:27 -07001599 "ANIM_THUMBNAIL_ASPECT_SCALE_UP" : "ANIM_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner164d4bb2012-11-26 13:51:23 -08001600 Slog.v(TAG, "applyAnimation:"
1601 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001602 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001603 + " Callers=" + Debug.getCallers(3));
1604 }
1605 } else {
1606 int animAttr = 0;
1607 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001608 case TRANSIT_ACTIVITY_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001609 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001610 ? WindowAnimation_activityOpenEnterAnimation
1611 : WindowAnimation_activityOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001612 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001613 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001614 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001615 ? WindowAnimation_activityCloseEnterAnimation
1616 : WindowAnimation_activityCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001617 break;
Jorim Jaggi192086e2016-03-11 17:17:03 +01001618 case TRANSIT_DOCK_TASK_FROM_RECENTS:
Craig Mautner4b71aa12012-12-27 17:20:01 -08001619 case TRANSIT_TASK_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001620 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001621 ? WindowAnimation_taskOpenEnterAnimation
1622 : WindowAnimation_taskOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001623 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001624 case TRANSIT_TASK_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001625 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001626 ? WindowAnimation_taskCloseEnterAnimation
1627 : WindowAnimation_taskCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001628 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001629 case TRANSIT_TASK_TO_FRONT:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001630 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001631 ? WindowAnimation_taskToFrontEnterAnimation
1632 : WindowAnimation_taskToFrontExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001633 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001634 case TRANSIT_TASK_TO_BACK:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001635 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001636 ? WindowAnimation_taskToBackEnterAnimation
1637 : WindowAnimation_taskToBackExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001638 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001639 case TRANSIT_WALLPAPER_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001640 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001641 ? WindowAnimation_wallpaperOpenEnterAnimation
1642 : WindowAnimation_wallpaperOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001643 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001644 case TRANSIT_WALLPAPER_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001645 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001646 ? WindowAnimation_wallpaperCloseEnterAnimation
1647 : WindowAnimation_wallpaperCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001648 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001649 case TRANSIT_WALLPAPER_INTRA_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001650 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001651 ? WindowAnimation_wallpaperIntraOpenEnterAnimation
1652 : WindowAnimation_wallpaperIntraOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001653 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001654 case TRANSIT_WALLPAPER_INTRA_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001655 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001656 ? WindowAnimation_wallpaperIntraCloseEnterAnimation
1657 : WindowAnimation_wallpaperIntraCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001658 break;
Craig Mautnerbb742462014-07-07 15:28:55 -07001659 case TRANSIT_TASK_OPEN_BEHIND:
1660 animAttr = enter
1661 ? WindowAnimation_launchTaskBehindSourceAnimation
Craig Mautner3b2cd1d2014-08-25 14:25:54 -07001662 : WindowAnimation_launchTaskBehindTargetAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001663 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001664 a = animAttr != 0 ? loadAnimationAttr(lp, animAttr) : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001665 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1666 "applyAnimation:"
1667 + " anim=" + a
1668 + " animAttr=0x" + Integer.toHexString(animAttr)
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001669 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001670 + " Callers=" + Debug.getCallers(3));
1671 }
1672 return a;
1673 }
1674
Jorim Jaggife762342016-10-13 14:33:27 +02001675 private Animation loadKeyguardExitAnimation(int transit) {
1676 if ((mNextAppTransitionFlags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_NO_ANIMATION) != 0) {
1677 return null;
1678 }
1679 final boolean toShade =
1680 (mNextAppTransitionFlags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_TO_SHADE) != 0;
1681 return mService.mPolicy.createHiddenByKeyguardExit(
1682 transit == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER, toShade);
1683 }
1684
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001685 int getAppStackClipMode() {
Matthew Ngbf1d9852017-03-14 12:23:09 -07001686 // When dismiss keyguard animation occurs, clip before the animation to prevent docked
1687 // app from showing beyond the divider
1688 if (mNextAppTransition == TRANSIT_KEYGUARD_GOING_AWAY
1689 || mNextAppTransition == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER) {
1690 return STACK_CLIP_BEFORE_ANIM;
1691 }
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001692 return mNextAppTransition == TRANSIT_ACTIVITY_RELAUNCH
Jorim Jaggic69bd222016-03-15 14:38:37 +01001693 || mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
Jorim Jaggi1f458fb2016-03-25 17:36:37 -07001694 || mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001695 ? STACK_CLIP_NONE
1696 : STACK_CLIP_AFTER_ANIM;
1697 }
1698
Jorim Jaggife762342016-10-13 14:33:27 +02001699 public int getTransitFlags() {
1700 return mNextAppTransitionFlags;
1701 }
1702
Craig Mautner164d4bb2012-11-26 13:51:23 -08001703 void postAnimationCallback() {
1704 if (mNextAppTransitionCallback != null) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001705 mService.mH.sendMessage(mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK,
1706 mNextAppTransitionCallback));
Craig Mautner164d4bb2012-11-26 13:51:23 -08001707 mNextAppTransitionCallback = null;
1708 }
1709 }
1710
1711 void overridePendingAppTransition(String packageName, int enterAnim, int exitAnim,
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001712 IRemoteCallback startedCallback) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001713 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001714 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001715 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001716 mNextAppTransitionPackage = packageName;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001717 mNextAppTransitionEnter = enterAnim;
1718 mNextAppTransitionExit = exitAnim;
1719 postAnimationCallback();
1720 mNextAppTransitionCallback = startedCallback;
1721 } else {
1722 postAnimationCallback();
1723 }
1724 }
1725
1726 void overridePendingAppTransitionScaleUp(int startX, int startY, int startWidth,
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001727 int startHeight) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001728 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001729 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001730 mNextAppTransitionType = NEXT_TRANSIT_TYPE_SCALE_UP;
Winson4c3fecd2016-07-13 12:29:48 -07001731 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001732 postAnimationCallback();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001733 }
1734 }
1735
Chet Haase10e23ab2015-02-11 15:08:38 -08001736 void overridePendingAppTransitionClipReveal(int startX, int startY,
1737 int startWidth, int startHeight) {
1738 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001739 clear();
Chet Haase10e23ab2015-02-11 15:08:38 -08001740 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CLIP_REVEAL;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001741 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Chet Haase10e23ab2015-02-11 15:08:38 -08001742 postAnimationCallback();
Chet Haase10e23ab2015-02-11 15:08:38 -08001743 }
1744 }
1745
Winson Chungaa7fa012017-05-24 15:50:06 -07001746 void overridePendingAppTransitionThumb(GraphicBuffer srcThumb, int startX, int startY,
Craig Mautner164d4bb2012-11-26 13:51:23 -08001747 IRemoteCallback startedCallback, boolean scaleUp) {
1748 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001749 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001750 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP
1751 : NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001752 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001753 putDefaultNextAppTransitionCoordinates(startX, startY, 0, 0, srcThumb);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001754 postAnimationCallback();
1755 mNextAppTransitionCallback = startedCallback;
1756 } else {
1757 postAnimationCallback();
1758 }
1759 }
1760
Winson Chungaa7fa012017-05-24 15:50:06 -07001761 void overridePendingAppTransitionAspectScaledThumb(GraphicBuffer srcThumb, int startX, int startY,
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001762 int targetWidth, int targetHeight, IRemoteCallback startedCallback, boolean scaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001763 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001764 clear();
Winson Chunga4ccb862014-08-22 15:26:27 -07001765 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1766 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Winson Chunga4ccb862014-08-22 15:26:27 -07001767 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001768 putDefaultNextAppTransitionCoordinates(startX, startY, targetWidth, targetHeight,
1769 srcThumb);
Winson Chunga4ccb862014-08-22 15:26:27 -07001770 postAnimationCallback();
1771 mNextAppTransitionCallback = startedCallback;
1772 } else {
1773 postAnimationCallback();
1774 }
1775 }
1776
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001777 public void overridePendingAppTransitionMultiThumb(AppTransitionAnimationSpec[] specs,
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001778 IRemoteCallback onAnimationStartedCallback, IRemoteCallback onAnimationFinishedCallback,
1779 boolean scaleUp) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001780 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001781 clear();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001782 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1783 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001784 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi43102412015-11-11 16:28:37 +01001785 if (specs != null) {
1786 for (int i = 0; i < specs.length; i++) {
1787 AppTransitionAnimationSpec spec = specs[i];
1788 if (spec != null) {
1789 mNextAppTransitionAnimationsSpecs.put(spec.taskId, spec);
1790 if (i == 0) {
1791 // In full screen mode, the transition code depends on the default spec
1792 // to be set.
1793 Rect rect = spec.rect;
1794 putDefaultNextAppTransitionCoordinates(rect.left, rect.top,
Winson Chungaa7fa012017-05-24 15:50:06 -07001795 rect.width(), rect.height(), spec.buffer);
Jorim Jaggi43102412015-11-11 16:28:37 +01001796 }
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001797 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001798 }
1799 }
1800 postAnimationCallback();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001801 mNextAppTransitionCallback = onAnimationStartedCallback;
1802 mAnimationFinishedCallback = onAnimationFinishedCallback;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001803 } else {
1804 postAnimationCallback();
1805 }
1806 }
1807
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001808 void overridePendingAppTransitionMultiThumbFuture(
1809 IAppTransitionAnimationSpecsFuture specsFuture, IRemoteCallback callback,
1810 boolean scaleUp) {
1811 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001812 clear();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001813 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1814 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001815 mNextAppTransitionAnimationsSpecsFuture = specsFuture;
1816 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001817 mNextAppTransitionFutureCallback = callback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001818 }
1819 }
1820
Winson Chung044d5292014-11-06 11:05:19 -08001821 void overrideInPlaceAppTransition(String packageName, int anim) {
1822 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001823 clear();
Winson Chung044d5292014-11-06 11:05:19 -08001824 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE;
1825 mNextAppTransitionPackage = packageName;
1826 mNextAppTransitionInPlace = anim;
1827 } else {
1828 postAnimationCallback();
1829 }
1830 }
1831
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001832 /**
1833 * If a future is set for the app transition specs, fetch it in another thread.
1834 */
1835 private void fetchAppTransitionSpecsFromFuture() {
1836 if (mNextAppTransitionAnimationsSpecsFuture != null) {
1837 mNextAppTransitionAnimationsSpecsPending = true;
1838 final IAppTransitionAnimationSpecsFuture future
1839 = mNextAppTransitionAnimationsSpecsFuture;
1840 mNextAppTransitionAnimationsSpecsFuture = null;
Jorim Jaggied410b62017-05-05 15:16:14 +02001841 mDefaultExecutor.execute(() -> {
1842 AppTransitionAnimationSpec[] specs = null;
1843 try {
1844 Binder.allowBlocking(future.asBinder());
1845 specs = future.get();
1846 } catch (RemoteException e) {
1847 Slog.w(TAG, "Failed to fetch app transition specs: " + e);
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001848 }
Jorim Jaggied410b62017-05-05 15:16:14 +02001849 synchronized (mService.mWindowMap) {
1850 mNextAppTransitionAnimationsSpecsPending = false;
1851 overridePendingAppTransitionMultiThumb(specs,
1852 mNextAppTransitionFutureCallback, null /* finishedCallback */,
1853 mNextAppTransitionScaleUp);
1854 mNextAppTransitionFutureCallback = null;
1855 if (specs != null) {
1856 mService.prolongAnimationsFromSpecs(specs, mNextAppTransitionScaleUp);
1857 }
1858 }
1859 mService.requestTraversal();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001860 });
1861 }
1862 }
1863
Craig Mautner164d4bb2012-11-26 13:51:23 -08001864 @Override
1865 public String toString() {
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001866 return "mNextAppTransition=" + appTransitionToString(mNextAppTransition);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001867 }
1868
Craig Mautner4b71aa12012-12-27 17:20:01 -08001869 /**
1870 * Returns the human readable name of a window transition.
1871 *
1872 * @param transition The window transition.
1873 * @return The transition symbolic name.
1874 */
1875 public static String appTransitionToString(int transition) {
1876 switch (transition) {
1877 case TRANSIT_UNSET: {
1878 return "TRANSIT_UNSET";
1879 }
1880 case TRANSIT_NONE: {
1881 return "TRANSIT_NONE";
1882 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001883 case TRANSIT_ACTIVITY_OPEN: {
1884 return "TRANSIT_ACTIVITY_OPEN";
1885 }
1886 case TRANSIT_ACTIVITY_CLOSE: {
1887 return "TRANSIT_ACTIVITY_CLOSE";
1888 }
1889 case TRANSIT_TASK_OPEN: {
1890 return "TRANSIT_TASK_OPEN";
1891 }
1892 case TRANSIT_TASK_CLOSE: {
1893 return "TRANSIT_TASK_CLOSE";
1894 }
1895 case TRANSIT_TASK_TO_FRONT: {
1896 return "TRANSIT_TASK_TO_FRONT";
1897 }
1898 case TRANSIT_TASK_TO_BACK: {
1899 return "TRANSIT_TASK_TO_BACK";
1900 }
1901 case TRANSIT_WALLPAPER_CLOSE: {
1902 return "TRANSIT_WALLPAPER_CLOSE";
1903 }
1904 case TRANSIT_WALLPAPER_OPEN: {
1905 return "TRANSIT_WALLPAPER_OPEN";
1906 }
1907 case TRANSIT_WALLPAPER_INTRA_OPEN: {
1908 return "TRANSIT_WALLPAPER_INTRA_OPEN";
1909 }
1910 case TRANSIT_WALLPAPER_INTRA_CLOSE: {
1911 return "TRANSIT_WALLPAPER_INTRA_CLOSE";
1912 }
Craig Mautnerbb742462014-07-07 15:28:55 -07001913 case TRANSIT_TASK_OPEN_BEHIND: {
1914 return "TRANSIT_TASK_OPEN_BEHIND";
1915 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001916 case TRANSIT_ACTIVITY_RELAUNCH: {
1917 return "TRANSIT_ACTIVITY_RELAUNCH";
1918 }
Jorim Jaggi192086e2016-03-11 17:17:03 +01001919 case TRANSIT_DOCK_TASK_FROM_RECENTS: {
1920 return "TRANSIT_DOCK_TASK_FROM_RECENTS";
1921 }
Jorim Jaggife762342016-10-13 14:33:27 +02001922 case TRANSIT_KEYGUARD_GOING_AWAY: {
1923 return "TRANSIT_KEYGUARD_GOING_AWAY";
1924 }
1925 case TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER: {
1926 return "TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER";
1927 }
1928 case TRANSIT_KEYGUARD_OCCLUDE: {
1929 return "TRANSIT_KEYGUARD_OCCLUDE";
1930 }
1931 case TRANSIT_KEYGUARD_UNOCCLUDE: {
1932 return "TRANSIT_KEYGUARD_UNOCCLUDE";
1933 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001934 default: {
1935 return "<UNKNOWN>";
1936 }
1937 }
1938 }
1939
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001940 private String appStateToString() {
1941 switch (mAppTransitionState) {
1942 case APP_STATE_IDLE:
1943 return "APP_STATE_IDLE";
1944 case APP_STATE_READY:
1945 return "APP_STATE_READY";
1946 case APP_STATE_RUNNING:
1947 return "APP_STATE_RUNNING";
1948 case APP_STATE_TIMEOUT:
1949 return "APP_STATE_TIMEOUT";
1950 default:
1951 return "unknown state=" + mAppTransitionState;
1952 }
1953 }
1954
1955 private String transitTypeToString() {
1956 switch (mNextAppTransitionType) {
1957 case NEXT_TRANSIT_TYPE_NONE:
1958 return "NEXT_TRANSIT_TYPE_NONE";
1959 case NEXT_TRANSIT_TYPE_CUSTOM:
1960 return "NEXT_TRANSIT_TYPE_CUSTOM";
Winson Chung044d5292014-11-06 11:05:19 -08001961 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
1962 return "NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001963 case NEXT_TRANSIT_TYPE_SCALE_UP:
1964 return "NEXT_TRANSIT_TYPE_SCALE_UP";
1965 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1966 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP";
1967 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
1968 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN";
Winson Chunga4ccb862014-08-22 15:26:27 -07001969 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
1970 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP";
1971 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN:
1972 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001973 default:
1974 return "unknown type=" + mNextAppTransitionType;
1975 }
1976 }
1977
Craig Mautner164d4bb2012-11-26 13:51:23 -08001978 @Override
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001979 public void dump(PrintWriter pw, String prefix) {
1980 pw.print(prefix); pw.println(this);
1981 pw.print(prefix); pw.print("mAppTransitionState="); pw.println(appStateToString());
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001982 if (mNextAppTransitionType != NEXT_TRANSIT_TYPE_NONE) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001983 pw.print(prefix); pw.print("mNextAppTransitionType=");
1984 pw.println(transitTypeToString());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001985 }
1986 switch (mNextAppTransitionType) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001987 case NEXT_TRANSIT_TYPE_CUSTOM:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001988 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001989 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001990 pw.print(prefix); pw.print("mNextAppTransitionEnter=0x");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001991 pw.print(Integer.toHexString(mNextAppTransitionEnter));
1992 pw.print(" mNextAppTransitionExit=0x");
1993 pw.println(Integer.toHexString(mNextAppTransitionExit));
1994 break;
Winson Chung044d5292014-11-06 11:05:19 -08001995 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001996 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Winson Chung044d5292014-11-06 11:05:19 -08001997 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001998 pw.print(prefix); pw.print("mNextAppTransitionInPlace=0x");
Winson Chung044d5292014-11-06 11:05:19 -08001999 pw.print(Integer.toHexString(mNextAppTransitionInPlace));
2000 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002001 case NEXT_TRANSIT_TYPE_SCALE_UP: {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002002 getDefaultNextAppTransitionStartRect(mTmpRect);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002003 pw.print(prefix); pw.print("mNextAppTransitionStartX=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002004 pw.print(mTmpRect.left);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002005 pw.print(" mNextAppTransitionStartY=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002006 pw.println(mTmpRect.top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002007 pw.print(prefix); pw.print("mNextAppTransitionStartWidth=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002008 pw.print(mTmpRect.width());
Craig Mautner164d4bb2012-11-26 13:51:23 -08002009 pw.print(" mNextAppTransitionStartHeight=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002010 pw.println(mTmpRect.height());
Craig Mautner164d4bb2012-11-26 13:51:23 -08002011 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002012 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002013 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
2014 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
Winson Chunga4ccb862014-08-22 15:26:27 -07002015 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002016 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN: {
2017 pw.print(prefix); pw.print("mDefaultNextAppTransitionAnimationSpec=");
2018 pw.println(mDefaultNextAppTransitionAnimationSpec);
2019 pw.print(prefix); pw.print("mNextAppTransitionAnimationsSpecs=");
2020 pw.println(mNextAppTransitionAnimationsSpecs);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002021 pw.print(prefix); pw.print("mNextAppTransitionScaleUp=");
2022 pw.println(mNextAppTransitionScaleUp);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002023 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002024 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002025 }
2026 if (mNextAppTransitionCallback != null) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002027 pw.print(prefix); pw.print("mNextAppTransitionCallback=");
2028 pw.println(mNextAppTransitionCallback);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002029 }
Chong Zhang60091a92016-07-27 17:52:45 -07002030 if (mLastUsedAppTransition != TRANSIT_NONE) {
2031 pw.print(prefix); pw.print("mLastUsedAppTransition=");
2032 pw.println(appTransitionToString(mLastUsedAppTransition));
2033 pw.print(prefix); pw.print("mLastOpeningApp=");
2034 pw.println(mLastOpeningApp);
2035 pw.print(prefix); pw.print("mLastClosingApp=");
2036 pw.println(mLastClosingApp);
2037 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002038 }
Amith Yamasani4befbec2013-07-10 16:18:01 -07002039
2040 public void setCurrentUser(int newUserId) {
2041 mCurrentUserId = newUserId;
2042 }
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002043
2044 /**
2045 * @return true if transition is not running and should not be skipped, false if transition is
2046 * already running
2047 */
Jorim Jaggife762342016-10-13 14:33:27 +02002048 boolean prepareAppTransitionLocked(int transit, boolean alwaysKeepCurrent, int flags,
2049 boolean forceOverride) {
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002050 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Prepare app transition:"
2051 + " transit=" + appTransitionToString(transit)
2052 + " " + this
2053 + " alwaysKeepCurrent=" + alwaysKeepCurrent
2054 + " Callers=" + Debug.getCallers(3));
Jorim Jaggife762342016-10-13 14:33:27 +02002055 if (forceOverride || isKeyguardTransit(transit) || !isTransitionSet()
2056 || mNextAppTransition == TRANSIT_NONE) {
2057 setAppTransition(transit, flags);
Jorim Jaggia69243a2017-06-15 15:10:38 -04002058 }
2059 // We never want to change from a Keyguard transit to a non-Keyguard transit, as our logic
2060 // relies on the fact that we always execute a Keyguard transition after preparing one.
2061 else if (!alwaysKeepCurrent && !isKeyguardTransit(transit)) {
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002062 if (transit == TRANSIT_TASK_OPEN && isTransitionEqual(TRANSIT_TASK_CLOSE)) {
2063 // Opening a new task always supersedes a close for the anim.
Jorim Jaggife762342016-10-13 14:33:27 +02002064 setAppTransition(transit, flags);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002065 } else if (transit == TRANSIT_ACTIVITY_OPEN
2066 && isTransitionEqual(TRANSIT_ACTIVITY_CLOSE)) {
2067 // Opening a new activity always supersedes a close for the anim.
Jorim Jaggife762342016-10-13 14:33:27 +02002068 setAppTransition(transit, flags);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002069 }
2070 }
2071 boolean prepared = prepare();
2072 if (isTransitionSet()) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08002073 mService.mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
2074 mService.mH.sendEmptyMessageDelayed(H.APP_TRANSITION_TIMEOUT, APP_TRANSITION_TIMEOUT_MS);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002075 }
2076 return prepared;
2077 }
Winsonb2024762016-04-05 17:32:30 -07002078
2079 /**
Jorim Jaggife762342016-10-13 14:33:27 +02002080 * @return true if {@param transit} is representing a transition in which Keyguard is going
2081 * away, false otherwise
2082 */
2083 public static boolean isKeyguardGoingAwayTransit(int transit) {
2084 return transit == TRANSIT_KEYGUARD_GOING_AWAY
2085 || transit == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER;
2086 }
2087
2088 private static boolean isKeyguardTransit(int transit) {
2089 return isKeyguardGoingAwayTransit(transit) || transit == TRANSIT_KEYGUARD_OCCLUDE
2090 || transit == TRANSIT_KEYGUARD_UNOCCLUDE;
2091 }
2092
2093 /**
Manu Cornetd7376802017-01-13 13:44:07 -08002094 * @return whether the transition should show the thumbnail being scaled down.
2095 */
2096 private boolean shouldScaleDownThumbnailTransition(int uiMode, int orientation) {
Sid Soundararajan0e88d322017-03-07 15:37:30 -08002097 return mGridLayoutRecentsEnabled
Manu Cornetd7376802017-01-13 13:44:07 -08002098 || orientation == Configuration.ORIENTATION_PORTRAIT;
2099 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002100}