blob: c2cbced2311cfd2d893e235fc8cace8b9c3825a8 [file] [log] [blame]
Craig Mautner164d4bb2012-11-26 13:51:23 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server.wm;
18
Filip Gruszczynski82861362015-10-16 14:21:09 -070019import static com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation;
20import static com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
21import static com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation;
22import static com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
23import static com.android.internal.R.styleable.WindowAnimation_launchTaskBehindSourceAnimation;
24import static com.android.internal.R.styleable.WindowAnimation_launchTaskBehindTargetAnimation;
25import static com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation;
26import static com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
27import static com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation;
28import static com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
29import static com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation;
30import static com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
31import static com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation;
32import static com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
33import static com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation;
34import static com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
35import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation;
36import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
37import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation;
38import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
39import static com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation;
40import static com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Jorim Jaggi363ab982016-04-26 19:51:20 -070041import static com.android.server.wm.AppWindowAnimator.PROLONG_ANIMATION_AT_START;
Filip Gruszczynski198dcbf2016-01-18 10:02:00 -080042import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
43import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080044import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
45import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Adrian Roose99bc052017-11-20 17:55:31 +010046import static com.android.server.wm.WindowManagerInternal.AppTransitionListener;
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;
Steven Timotiusaf03df62017-07-18 16:56:43 -070050import static com.android.server.wm.proto.AppTransitionProto.APP_TRANSITION_STATE;
51import static com.android.server.wm.proto.AppTransitionProto.LAST_USED_APP_TRANSITION;
Filip Gruszczynski82861362015-10-16 14:21:09 -070052
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -070053import android.annotation.Nullable;
Matthew Ng43db6d22017-06-27 15:29:39 -070054import android.app.ActivityManager;
Craig Mautner164d4bb2012-11-26 13:51:23 -080055import android.content.Context;
Winson21700932016-03-24 17:26:23 -070056import android.content.res.Configuration;
Craig Mautner164d4bb2012-11-26 13:51:23 -080057import android.graphics.Bitmap;
Winson Chungaa7fa012017-05-24 15:50:06 -070058import android.graphics.GraphicBuffer;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +010059import android.graphics.Path;
Winson Chung399f6202014-03-19 10:47:20 -070060import android.graphics.Rect;
Jorim Jaggied410b62017-05-05 15:16:14 +020061import android.os.Binder;
Craig Mautner164d4bb2012-11-26 13:51:23 -080062import android.os.Debug;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010063import android.os.IBinder;
Craig Mautner164d4bb2012-11-26 13:51:23 -080064import android.os.IRemoteCallback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010065import android.os.RemoteException;
Manu Cornetd7376802017-01-13 13:44:07 -080066import android.os.SystemProperties;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -080067import android.util.ArraySet;
Craig Mautner164d4bb2012-11-26 13:51:23 -080068import android.util.Slog;
Filip Gruszczynski170192a2015-08-16 17:46:34 -070069import android.util.SparseArray;
Steven Timotiusaf03df62017-07-18 16:56:43 -070070import android.util.proto.ProtoOutputStream;
Filip Gruszczynski170192a2015-08-16 17:46:34 -070071import android.view.AppTransitionAnimationSpec;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010072import android.view.IAppTransitionAnimationSpecsFuture;
Craig Mautner164d4bb2012-11-26 13:51:23 -080073import android.view.WindowManager;
Craig Mautner164d4bb2012-11-26 13:51:23 -080074import android.view.animation.AlphaAnimation;
75import android.view.animation.Animation;
76import android.view.animation.AnimationSet;
77import android.view.animation.AnimationUtils;
Winson Chung399f6202014-03-19 10:47:20 -070078import android.view.animation.ClipRectAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -080079import android.view.animation.Interpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070080import android.view.animation.PathInterpolator;
Craig Mautner164d4bb2012-11-26 13:51:23 -080081import android.view.animation.ScaleAnimation;
Winson Chung399f6202014-03-19 10:47:20 -070082import android.view.animation.TranslateAnimation;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070083
Craig Mautner164d4bb2012-11-26 13:51:23 -080084import com.android.internal.util.DumpUtils.Dump;
85import com.android.server.AttributeCache;
86import com.android.server.wm.WindowManagerService.H;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -080087import com.android.server.wm.animation.ClipRectLRAnimation;
88import com.android.server.wm.animation.ClipRectTBAnimation;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +010089import com.android.server.wm.animation.CurvedTranslateAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -080090
91import java.io.PrintWriter;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010092import java.util.ArrayList;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010093import java.util.concurrent.ExecutorService;
94import java.util.concurrent.Executors;
Craig Mautner164d4bb2012-11-26 13:51:23 -080095
Craig Mautner164d4bb2012-11-26 13:51:23 -080096// State management of app transitions. When we are preparing for a
97// transition, mNextAppTransition will be the kind of transition to
98// perform or TRANSIT_NONE if we are not waiting. If we are waiting,
99// mOpeningApps and mClosingApps are the lists of tokens that will be
100// made visible or hidden at the next transition.
101public class AppTransition implements Dump {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800102 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppTransition" : TAG_WM;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700103 private static final int CLIP_REVEAL_TRANSLATION_Y_DP = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800104
Craig Mautner4b71aa12012-12-27 17:20:01 -0800105 /** Not set up for a transition. */
106 public static final int TRANSIT_UNSET = -1;
107 /** No animation for transition. */
108 public static final int TRANSIT_NONE = 0;
109 /** 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 -0700110 public static final int TRANSIT_ACTIVITY_OPEN = 6;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800111 /** The window in the top-most activity is being closed to reveal the
112 * previous activity in the same task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700113 public static final int TRANSIT_ACTIVITY_CLOSE = 7;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800114 /** A window in a new task is being opened on top of an existing one
115 * in another activity's task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700116 public static final int TRANSIT_TASK_OPEN = 8;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800117 /** A window in the top-most activity is being closed to reveal the
118 * previous activity in a different task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700119 public static final int TRANSIT_TASK_CLOSE = 9;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800120 /** A window in an existing task is being displayed on top of an existing one
121 * in another activity's task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700122 public static final int TRANSIT_TASK_TO_FRONT = 10;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800123 /** A window in an existing task is being put below all other tasks. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700124 public static final int TRANSIT_TASK_TO_BACK = 11;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800125 /** A window in a new activity that doesn't have a wallpaper is being opened on top of one that
126 * does, effectively closing the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700127 public static final int TRANSIT_WALLPAPER_CLOSE = 12;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800128 /** A window in a new activity that does have a wallpaper is being opened on one that didn't,
129 * effectively opening the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700130 public static final int TRANSIT_WALLPAPER_OPEN = 13;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800131 /** A window in a new activity is being opened on top of an existing one, and both are on top
132 * of the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700133 public static final int TRANSIT_WALLPAPER_INTRA_OPEN = 14;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800134 /** The window in the top-most activity is being closed to reveal the previous activity, and
135 * both are on top of the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700136 public static final int TRANSIT_WALLPAPER_INTRA_CLOSE = 15;
137 /** A window in a new task is being opened behind an existing one in another activity's task.
138 * The new window will show briefly and then be gone. */
139 public static final int TRANSIT_TASK_OPEN_BEHIND = 16;
Winson Chung044d5292014-11-06 11:05:19 -0800140 /** A window in a task is being animated in-place. */
141 public static final int TRANSIT_TASK_IN_PLACE = 17;
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700142 /** An activity is being relaunched (e.g. due to configuration change). */
143 public static final int TRANSIT_ACTIVITY_RELAUNCH = 18;
Jorim Jaggi192086e2016-03-11 17:17:03 +0100144 /** A task is being docked from recents. */
145 public static final int TRANSIT_DOCK_TASK_FROM_RECENTS = 19;
Jorim Jaggife762342016-10-13 14:33:27 +0200146 /** Keyguard is going away */
147 public static final int TRANSIT_KEYGUARD_GOING_AWAY = 20;
148 /** Keyguard is going away with showing an activity behind that requests wallpaper */
149 public static final int TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER = 21;
150 /** Keyguard is being occluded */
151 public static final int TRANSIT_KEYGUARD_OCCLUDE = 22;
152 /** Keyguard is being unoccluded */
153 public static final int TRANSIT_KEYGUARD_UNOCCLUDE = 23;
154
155 /** Transition flag: Keyguard is going away, but keeping the notification shade open */
156 public static final int TRANSIT_FLAG_KEYGUARD_GOING_AWAY_TO_SHADE = 0x1;
157 /** Transition flag: Keyguard is going away, but doesn't want an animation for it */
158 public static final int TRANSIT_FLAG_KEYGUARD_GOING_AWAY_NO_ANIMATION = 0x2;
159 /** Transition flag: Keyguard is going away while it was showing the system wallpaper. */
160 public static final int TRANSIT_FLAG_KEYGUARD_GOING_AWAY_WITH_WALLPAPER = 0x4;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800161
Winson Chunga4ccb862014-08-22 15:26:27 -0700162 /** Fraction of animation at which the recents thumbnail stays completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700163 private static final float RECENTS_THUMBNAIL_FADEIN_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800164 /** Fraction of animation at which the recents thumbnail becomes completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700165 private static final float RECENTS_THUMBNAIL_FADEOUT_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800166
Filip Gruszczynski84fa3352016-01-25 16:28:49 -0800167 static final int DEFAULT_APP_TRANSITION_DURATION = 336;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800168
169 /** Interpolator to be used for animations that respond directly to a touch */
170 static final Interpolator TOUCH_RESPONSE_INTERPOLATOR =
171 new PathInterpolator(0.3f, 0f, 0.1f, 1f);
172
Jorim Jaggic69bd222016-03-15 14:38:37 +0100173 private static final Interpolator THUMBNAIL_DOCK_INTERPOLATOR =
174 new PathInterpolator(0.85f, 0f, 1f, 1f);
175
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800176 /**
177 * Maximum duration for the clip reveal animation. This is used when there is a lot of movement
178 * involved, to make it more understandable.
179 */
180 private static final int MAX_CLIP_REVEAL_TRANSITION_DURATION = 420;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700181 private static final int THUMBNAIL_APP_TRANSITION_DURATION = 336;
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700182 private static final long APP_TRANSITION_TIMEOUT_MS = 5000;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800183
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800184 private final Context mContext;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800185 private final WindowManagerService mService;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800186
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800187 private int mNextAppTransition = TRANSIT_UNSET;
Jorim Jaggife762342016-10-13 14:33:27 +0200188 private int mNextAppTransitionFlags = 0;
Chong Zhang60091a92016-07-27 17:52:45 -0700189 private int mLastUsedAppTransition = TRANSIT_UNSET;
190 private String mLastOpeningApp;
191 private String mLastClosingApp;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800192
193 private static final int NEXT_TRANSIT_TYPE_NONE = 0;
194 private static final int NEXT_TRANSIT_TYPE_CUSTOM = 1;
195 private static final int NEXT_TRANSIT_TYPE_SCALE_UP = 2;
196 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP = 3;
197 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN = 4;
Winson Chunga4ccb862014-08-22 15:26:27 -0700198 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP = 5;
199 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN = 6;
Winson Chung044d5292014-11-06 11:05:19 -0800200 private static final int NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE = 7;
Chet Haase10e23ab2015-02-11 15:08:38 -0800201 private static final int NEXT_TRANSIT_TYPE_CLIP_REVEAL = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800202 private int mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
203
Winson Chung399f6202014-03-19 10:47:20 -0700204 // These are the possible states for the enter/exit activities during a thumbnail transition
205 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_UP = 0;
206 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_UP = 1;
207 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN = 2;
208 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN = 3;
209
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800210 private String mNextAppTransitionPackage;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800211 // Used for thumbnail transitions. True if we're scaling up, false if scaling down
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800212 private boolean mNextAppTransitionScaleUp;
213 private IRemoteCallback mNextAppTransitionCallback;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +0100214 private IRemoteCallback mNextAppTransitionFutureCallback;
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -0700215 private IRemoteCallback mAnimationFinishedCallback;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800216 private int mNextAppTransitionEnter;
217 private int mNextAppTransitionExit;
Winson Chung044d5292014-11-06 11:05:19 -0800218 private int mNextAppTransitionInPlace;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700219
220 // Keyed by task id.
221 private final SparseArray<AppTransitionAnimationSpec> mNextAppTransitionAnimationsSpecs
222 = new SparseArray<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100223 private IAppTransitionAnimationSpecsFuture mNextAppTransitionAnimationsSpecsFuture;
224 private boolean mNextAppTransitionAnimationsSpecsPending;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700225 private AppTransitionAnimationSpec mDefaultNextAppTransitionAnimationSpec;
226
Winson Chunga4ccb862014-08-22 15:26:27 -0700227 private Rect mNextAppTransitionInsets = new Rect();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800228
Winson Chung2820c452014-04-15 15:34:44 -0700229 private Rect mTmpFromClipRect = new Rect();
230 private Rect mTmpToClipRect = new Rect();
231
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700232 private final Rect mTmpRect = new Rect();
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700233
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800234 private final static int APP_STATE_IDLE = 0;
235 private final static int APP_STATE_READY = 1;
236 private final static int APP_STATE_RUNNING = 2;
237 private final static int APP_STATE_TIMEOUT = 3;
238 private int mAppTransitionState = APP_STATE_IDLE;
239
240 private final int mConfigShortAnimTime;
Craig Mautner321bdf52012-12-18 09:53:24 -0800241 private final Interpolator mDecelerateInterpolator;
Winson Chunga4ccb862014-08-22 15:26:27 -0700242 private final Interpolator mThumbnailFadeInInterpolator;
243 private final Interpolator mThumbnailFadeOutInterpolator;
Chet Haase10e23ab2015-02-11 15:08:38 -0800244 private final Interpolator mLinearOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700245 private final Interpolator mFastOutLinearInInterpolator;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100246 private final Interpolator mFastOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700247 private final Interpolator mClipHorizontalInterpolator = new PathInterpolator(0, 0, 0.4f, 1f);
248
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700249 private final int mClipRevealTranslationY;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800250
Amith Yamasani4befbec2013-07-10 16:18:01 -0700251 private int mCurrentUserId = 0;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800252 private long mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Amith Yamasani4befbec2013-07-10 16:18:01 -0700253
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100254 private final ArrayList<AppTransitionListener> mListeners = new ArrayList<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100255 private final ExecutorService mDefaultExecutor = Executors.newSingleThreadExecutor();
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100256
Jorim Jaggif97ed922016-02-18 18:57:07 -0800257 private int mLastClipRevealMaxTranslation;
258 private boolean mLastHadClipReveal;
Jorim Jaggi363ab982016-04-26 19:51:20 -0700259 private boolean mProlongedAnimationsEnded;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800260
Manu Cornetd7376802017-01-13 13:44:07 -0800261 private final boolean mGridLayoutRecentsEnabled;
Matthew Ng43db6d22017-06-27 15:29:39 -0700262 private final boolean mLowRamRecentsEnabled;
Manu Cornetd7376802017-01-13 13:44:07 -0800263
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800264 AppTransition(Context context, WindowManagerService service) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800265 mContext = context;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800266 mService = service;
Chet Haase10e23ab2015-02-11 15:08:38 -0800267 mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
268 com.android.internal.R.interpolator.linear_out_slow_in);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700269 mFastOutLinearInInterpolator = AnimationUtils.loadInterpolator(context,
270 com.android.internal.R.interpolator.fast_out_linear_in);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100271 mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
272 com.android.internal.R.interpolator.fast_out_slow_in);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800273 mConfigShortAnimTime = context.getResources().getInteger(
274 com.android.internal.R.integer.config_shortAnimTime);
Craig Mautner321bdf52012-12-18 09:53:24 -0800275 mDecelerateInterpolator = AnimationUtils.loadInterpolator(context,
276 com.android.internal.R.interpolator.decelerate_cubic);
Winson Chunga4ccb862014-08-22 15:26:27 -0700277 mThumbnailFadeInInterpolator = new Interpolator() {
278 @Override
279 public float getInterpolation(float input) {
280 // Linear response for first fraction, then complete after that.
281 if (input < RECENTS_THUMBNAIL_FADEIN_FRACTION) {
282 return 0f;
283 }
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700284 float t = (input - RECENTS_THUMBNAIL_FADEIN_FRACTION) /
Winson Chunga4ccb862014-08-22 15:26:27 -0700285 (1f - RECENTS_THUMBNAIL_FADEIN_FRACTION);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700286 return mFastOutLinearInInterpolator.getInterpolation(t);
Winson Chunga4ccb862014-08-22 15:26:27 -0700287 }
288 };
289 mThumbnailFadeOutInterpolator = new Interpolator() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800290 @Override
291 public float getInterpolation(float input) {
292 // Linear response for first fraction, then complete after that.
293 if (input < RECENTS_THUMBNAIL_FADEOUT_FRACTION) {
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700294 float t = input / RECENTS_THUMBNAIL_FADEOUT_FRACTION;
295 return mLinearOutSlowInInterpolator.getInterpolation(t);
Craig Mautner321bdf52012-12-18 09:53:24 -0800296 }
Winson Chunga4ccb862014-08-22 15:26:27 -0700297 return 1f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800298 }
299 };
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700300 mClipRevealTranslationY = (int) (CLIP_REVEAL_TRANSLATION_Y_DP
301 * mContext.getResources().getDisplayMetrics().density);
Manu Cornetd7376802017-01-13 13:44:07 -0800302 mGridLayoutRecentsEnabled = SystemProperties.getBoolean("ro.recents.grid", false);
Matthew Ng43db6d22017-06-27 15:29:39 -0700303 mLowRamRecentsEnabled = ActivityManager.isLowRamDeviceStatic();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800304 }
305
306 boolean isTransitionSet() {
307 return mNextAppTransition != TRANSIT_UNSET;
308 }
309
Craig Mautner164d4bb2012-11-26 13:51:23 -0800310 boolean isTransitionEqual(int transit) {
311 return mNextAppTransition == transit;
312 }
313
314 int getAppTransition() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800315 return mNextAppTransition;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800316 }
317
Jorim Jaggife762342016-10-13 14:33:27 +0200318 private void setAppTransition(int transit, int flags) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800319 mNextAppTransition = transit;
Jorim Jaggife762342016-10-13 14:33:27 +0200320 mNextAppTransitionFlags |= flags;
Chong Zhang60091a92016-07-27 17:52:45 -0700321 setLastAppTransition(TRANSIT_UNSET, null, null);
Jorim Jaggi245281c2017-06-07 14:33:04 -0700322 updateBooster();
Chong Zhang60091a92016-07-27 17:52:45 -0700323 }
324
325 void setLastAppTransition(int transit, AppWindowToken openingApp, AppWindowToken closingApp) {
326 mLastUsedAppTransition = transit;
327 mLastOpeningApp = "" + openingApp;
328 mLastClosingApp = "" + closingApp;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800329 }
330
331 boolean isReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800332 return mAppTransitionState == APP_STATE_READY
333 || mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800334 }
335
Craig Mautnerae446592012-12-06 19:05:05 -0800336 void setReady() {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700337 setAppTransitionState(APP_STATE_READY);
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100338 fetchAppTransitionSpecsFromFuture();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800339 }
340
341 boolean isRunning() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800342 return mAppTransitionState == APP_STATE_RUNNING;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800343 }
344
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800345 void setIdle() {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700346 setAppTransitionState(APP_STATE_IDLE);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800347 }
348
349 boolean isTimeout() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800350 return mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800351 }
352
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800353 void setTimeout() {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700354 setAppTransitionState(APP_STATE_TIMEOUT);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800355 }
356
Winson Chungaa7fa012017-05-24 15:50:06 -0700357 GraphicBuffer getAppTransitionThumbnailHeader(int taskId) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700358 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800359 if (spec == null) {
360 spec = mDefaultNextAppTransitionAnimationSpec;
361 }
Winson Chungaa7fa012017-05-24 15:50:06 -0700362 return spec != null ? spec.buffer : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800363 }
364
Winson Chunga4ccb862014-08-22 15:26:27 -0700365 /** Returns whether the next thumbnail transition is aspect scaled up. */
366 boolean isNextThumbnailTransitionAspectScaled() {
367 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
368 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
369 }
370
371 /** Returns whether the next thumbnail transition is scaling up. */
372 boolean isNextThumbnailTransitionScaleUp() {
373 return mNextAppTransitionScaleUp;
374 }
375
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -0800376 boolean isNextAppTransitionThumbnailUp() {
377 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
378 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP;
379 }
380
381 boolean isNextAppTransitionThumbnailDown() {
382 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN ||
383 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
384 }
385
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100386 /**
387 * @return true if and only if we are currently fetching app transition specs from the future
388 * passed into {@link #overridePendingAppTransitionMultiThumbFuture}
389 */
390 boolean isFetchingAppTransitionsSpecs() {
391 return mNextAppTransitionAnimationsSpecsPending;
392 }
393
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700394 private boolean prepare() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800395 if (!isRunning()) {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700396 setAppTransitionState(APP_STATE_IDLE);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100397 notifyAppTransitionPendingLocked();
Jorim Jaggif97ed922016-02-18 18:57:07 -0800398 mLastHadClipReveal = false;
399 mLastClipRevealMaxTranslation = 0;
400 mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700401 return true;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800402 }
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700403 return false;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800404 }
405
Jorim Jaggife762342016-10-13 14:33:27 +0200406 /**
407 * @return bit-map of WindowManagerPolicy#FINISH_LAYOUT_REDO_* to indicate whether another
408 * layout pass needs to be done
409 */
410 int goodToGo(int transit, AppWindowAnimator topOpeningAppAnimator,
411 AppWindowAnimator topClosingAppAnimator, ArraySet<AppWindowToken> openingApps,
412 ArraySet<AppWindowToken> closingApps) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800413 mNextAppTransition = TRANSIT_UNSET;
Jorim Jaggife762342016-10-13 14:33:27 +0200414 mNextAppTransitionFlags = 0;
Jorim Jaggi245281c2017-06-07 14:33:04 -0700415 setAppTransitionState(APP_STATE_RUNNING);
Jorim Jaggife762342016-10-13 14:33:27 +0200416 int redoLayout = notifyAppTransitionStartingLocked(transit,
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800417 topOpeningAppAnimator != null ? topOpeningAppAnimator.mAppToken.token : null,
418 topClosingAppAnimator != null ? topClosingAppAnimator.mAppToken.token : null,
419 topOpeningAppAnimator != null ? topOpeningAppAnimator.animation : null,
420 topClosingAppAnimator != null ? topClosingAppAnimator.animation : null);
421 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Jorim Jaggife762342016-10-13 14:33:27 +0200422 .notifyAppTransitionStarting(openingApps, transit);
Jorim Jaggi363ab982016-04-26 19:51:20 -0700423
424 // Prolong the start for the transition when docking a task from recents, unless recents
425 // ended it already then we don't need to wait.
Jorim Jaggife762342016-10-13 14:33:27 +0200426 if (transit == TRANSIT_DOCK_TASK_FROM_RECENTS && !mProlongedAnimationsEnded) {
Jorim Jaggi363ab982016-04-26 19:51:20 -0700427 for (int i = openingApps.size() - 1; i >= 0; i--) {
428 final AppWindowAnimator appAnimator = openingApps.valueAt(i).mAppAnimator;
429 appAnimator.startProlongAnimation(PROLONG_ANIMATION_AT_START);
430 }
431 }
Jorim Jaggife762342016-10-13 14:33:27 +0200432 return redoLayout;
Jorim Jaggi363ab982016-04-26 19:51:20 -0700433 }
434
435 /**
436 * Let the transitions manager know that the somebody wanted to end the prolonged animations.
437 */
438 void notifyProlongedAnimationsEnded() {
439 mProlongedAnimationsEnded = true;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800440 }
441
442 void clear() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800443 mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800444 mNextAppTransitionPackage = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700445 mNextAppTransitionAnimationsSpecs.clear();
Jorim Jaggi65193992015-11-23 16:49:59 -0800446 mNextAppTransitionAnimationsSpecsFuture = null;
447 mDefaultNextAppTransitionAnimationSpec = null;
448 mAnimationFinishedCallback = null;
Jorim Jaggi363ab982016-04-26 19:51:20 -0700449 mProlongedAnimationsEnded = false;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800450 }
451
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800452 void freeze() {
Jorim Jaggife762342016-10-13 14:33:27 +0200453 final int transit = mNextAppTransition;
454 setAppTransition(AppTransition.TRANSIT_UNSET, 0 /* flags */);
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800455 clear();
456 setReady();
Jorim Jaggife762342016-10-13 14:33:27 +0200457 notifyAppTransitionCancelledLocked(transit);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100458 }
459
Jorim Jaggi245281c2017-06-07 14:33:04 -0700460 private void setAppTransitionState(int state) {
461 mAppTransitionState = state;
462 updateBooster();
463 }
464
465 /**
466 * Updates whether we currently boost wm locked sections and the animation thread. We want to
467 * boost the priorities to a more important value whenever an app transition is going to happen
468 * soon or an app transition is running.
469 */
470 private void updateBooster() {
471 WindowManagerService.sThreadPriorityBooster.setAppTransitionRunning(
472 mNextAppTransition != TRANSIT_UNSET || mAppTransitionState == APP_STATE_READY
473 || mAppTransitionState == APP_STATE_RUNNING);
474 }
475
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100476 void registerListenerLocked(AppTransitionListener listener) {
477 mListeners.add(listener);
478 }
479
Wale Ogunwalea48eadb2015-05-14 17:43:12 -0700480 public void notifyAppTransitionFinishedLocked(IBinder token) {
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100481 for (int i = 0; i < mListeners.size(); i++) {
482 mListeners.get(i).onAppTransitionFinishedLocked(token);
483 }
484 }
485
486 private void notifyAppTransitionPendingLocked() {
487 for (int i = 0; i < mListeners.size(); i++) {
488 mListeners.get(i).onAppTransitionPendingLocked();
489 }
490 }
491
Jorim Jaggife762342016-10-13 14:33:27 +0200492 private void notifyAppTransitionCancelledLocked(int transit) {
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100493 for (int i = 0; i < mListeners.size(); i++) {
Jorim Jaggife762342016-10-13 14:33:27 +0200494 mListeners.get(i).onAppTransitionCancelledLocked(transit);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100495 }
496 }
497
Jorim Jaggife762342016-10-13 14:33:27 +0200498 private int notifyAppTransitionStartingLocked(int transit, IBinder openToken,
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100499 IBinder closeToken, Animation openAnimation, Animation closeAnimation) {
Jorim Jaggife762342016-10-13 14:33:27 +0200500 int redoLayout = 0;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100501 for (int i = 0; i < mListeners.size(); i++) {
Jorim Jaggife762342016-10-13 14:33:27 +0200502 redoLayout |= mListeners.get(i).onAppTransitionStartingLocked(transit, openToken,
503 closeToken, openAnimation, closeAnimation);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100504 }
Jorim Jaggife762342016-10-13 14:33:27 +0200505 return redoLayout;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800506 }
507
Craig Mautner164d4bb2012-11-26 13:51:23 -0800508 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
509 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg="
510 + (lp != null ? lp.packageName : null)
511 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
512 if (lp != null && lp.windowAnimations != 0) {
513 // If this is a system resource, don't try to load it from the
514 // application resources. It is nice to avoid loading application
515 // resources if we can.
516 String packageName = lp.packageName != null ? lp.packageName : "android";
517 int resId = lp.windowAnimations;
518 if ((resId&0xFF000000) == 0x01000000) {
519 packageName = "android";
520 }
521 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
522 + packageName);
523 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700524 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800525 }
526 return null;
527 }
528
529 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
530 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package="
531 + packageName + " resId=0x" + Integer.toHexString(resId));
532 if (packageName != null) {
533 if ((resId&0xFF000000) == 0x01000000) {
534 packageName = "android";
535 }
536 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
537 + packageName);
538 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700539 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800540 }
541 return null;
542 }
543
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700544 Animation loadAnimationAttr(WindowManager.LayoutParams lp, int animAttr) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800545 int anim = 0;
546 Context context = mContext;
547 if (animAttr >= 0) {
548 AttributeCache.Entry ent = getCachedAnimations(lp);
549 if (ent != null) {
550 context = ent.context;
551 anim = ent.array.getResourceId(animAttr, 0);
552 }
553 }
554 if (anim != 0) {
555 return AnimationUtils.loadAnimation(context, anim);
556 }
557 return null;
558 }
559
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700560 Animation loadAnimationRes(WindowManager.LayoutParams lp, int resId) {
561 Context context = mContext;
562 if (resId >= 0) {
563 AttributeCache.Entry ent = getCachedAnimations(lp);
564 if (ent != null) {
565 context = ent.context;
566 }
567 return AnimationUtils.loadAnimation(context, resId);
568 }
569 return null;
570 }
571
572 private Animation loadAnimationRes(String packageName, int resId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800573 int anim = 0;
574 Context context = mContext;
575 if (resId >= 0) {
576 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
577 if (ent != null) {
578 context = ent.context;
579 anim = resId;
580 }
581 }
582 if (anim != 0) {
583 return AnimationUtils.loadAnimation(context, anim);
584 }
585 return null;
586 }
587
Craig Mautner164d4bb2012-11-26 13:51:23 -0800588 /**
589 * Compute the pivot point for an animation that is scaling from a small
590 * rect on screen to a larger rect. The pivot point varies depending on
591 * the distance between the inner and outer edges on both sides. This
592 * function computes the pivot point for one dimension.
593 * @param startPos Offset from left/top edge of outer rectangle to
594 * left/top edge of inner rectangle.
595 * @param finalScale The scaling factor between the size of the outer
596 * and inner rectangles.
597 */
598 private static float computePivot(int startPos, float finalScale) {
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800599
600 /*
601 Theorem of intercepting lines:
602
603 + + +-----------------------------------------------+
604 | | | |
605 | | | |
606 | | | |
607 | | | |
608 x | y | | |
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 |
648 |
649 + ++
650 p ++
651
652 scale = (x - y) / x
653 <=> x = -y / (scale - 1)
654 */
Craig Mautner164d4bb2012-11-26 13:51:23 -0800655 final float denom = finalScale-1;
656 if (Math.abs(denom) < .0001f) {
657 return startPos;
658 }
659 return -startPos / denom;
660 }
661
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700662 private Animation createScaleUpAnimationLocked(int transit, boolean enter,
663 Rect containingFrame) {
664 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700665 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700666 final int appWidth = containingFrame.width();
667 final int appHeight = containingFrame.height();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800668 if (enter) {
669 // Entering app zooms out from the center of the initial rect.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700670 float scaleW = mTmpRect.width() / (float) appWidth;
671 float scaleH = mTmpRect.height() / (float) appHeight;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800672 Animation scale = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700673 computePivot(mTmpRect.left, scaleW),
Winson4c3fecd2016-07-13 12:29:48 -0700674 computePivot(mTmpRect.top, scaleH));
Craig Mautner321bdf52012-12-18 09:53:24 -0800675 scale.setInterpolator(mDecelerateInterpolator);
676
Craig Mautner164d4bb2012-11-26 13:51:23 -0800677 Animation alpha = new AlphaAnimation(0, 1);
Winson Chunga4ccb862014-08-22 15:26:27 -0700678 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
Craig Mautner321bdf52012-12-18 09:53:24 -0800679
680 AnimationSet set = new AnimationSet(false);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800681 set.addAnimation(scale);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800682 set.addAnimation(alpha);
683 set.setDetachWallpaper(true);
684 a = set;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800685 } else if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
686 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800687 // If we are on top of the wallpaper, we need an animation that
688 // correctly handles the wallpaper staying static behind all of
689 // the animated elements. To do this, will just have the existing
690 // element fade out.
691 a = new AlphaAnimation(1, 0);
692 a.setDetachWallpaper(true);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800693 } else {
Craig Mautner321bdf52012-12-18 09:53:24 -0800694 // For normal animations, the exiting element just holds in place.
695 a = new AlphaAnimation(1, 1);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800696 }
Craig Mautner321bdf52012-12-18 09:53:24 -0800697
698 // Pick the desired duration. If this is an inter-activity transition,
699 // it is the standard duration for that. Otherwise we use the longer
700 // task transition duration.
701 final long duration;
702 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800703 case TRANSIT_ACTIVITY_OPEN:
704 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800705 duration = mConfigShortAnimTime;
706 break;
707 default:
708 duration = DEFAULT_APP_TRANSITION_DURATION;
709 break;
710 }
711 a.setDuration(duration);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800712 a.setFillAfter(true);
Craig Mautner321bdf52012-12-18 09:53:24 -0800713 a.setInterpolator(mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800714 a.initialize(appWidth, appHeight, appWidth, appHeight);
715 return a;
716 }
717
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700718 private void getDefaultNextAppTransitionStartRect(Rect rect) {
719 if (mDefaultNextAppTransitionAnimationSpec == null ||
720 mDefaultNextAppTransitionAnimationSpec.rect == null) {
Jorim Jaggi2550f3f2017-03-14 20:15:59 +0100721 Slog.e(TAG, "Starting rect for app requested, but none available", new Throwable());
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700722 rect.setEmpty();
723 } else {
724 rect.set(mDefaultNextAppTransitionAnimationSpec.rect);
725 }
726 }
727
728 void getNextAppTransitionStartRect(int taskId, Rect rect) {
729 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800730 if (spec == null) {
731 spec = mDefaultNextAppTransitionAnimationSpec;
732 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700733 if (spec == null || spec.rect == null) {
Jorim Jaggi2550f3f2017-03-14 20:15:59 +0100734 Slog.e(TAG, "Starting rect for task: " + taskId + " requested, but not available",
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700735 new Throwable());
736 rect.setEmpty();
737 } else {
738 rect.set(spec.rect);
739 }
740 }
741
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800742 private void putDefaultNextAppTransitionCoordinates(int left, int top, int width, int height,
Winson Chungaa7fa012017-05-24 15:50:06 -0700743 GraphicBuffer buffer) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700744 mDefaultNextAppTransitionAnimationSpec = new AppTransitionAnimationSpec(-1 /* taskId */,
Winson Chungaa7fa012017-05-24 15:50:06 -0700745 buffer, new Rect(left, top, left + width, top + height));
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700746 }
747
Jorim Jaggif97ed922016-02-18 18:57:07 -0800748 /**
749 * @return the duration of the last clip reveal animation
750 */
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800751 long getLastClipRevealTransitionDuration() {
752 return mLastClipRevealTransitionDuration;
753 }
754
755 /**
Jorim Jaggif97ed922016-02-18 18:57:07 -0800756 * @return the maximum distance the app surface is traveling of the last clip reveal animation
757 */
758 int getLastClipRevealMaxTranslation() {
759 return mLastClipRevealMaxTranslation;
760 }
761
762 /**
763 * @return true if in the last app transition had a clip reveal animation, false otherwise
764 */
765 boolean hadClipRevealAnimation() {
766 return mLastHadClipReveal;
767 }
768
769 /**
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800770 * Calculates the duration for the clip reveal animation. If the clip is "cut off", meaning that
771 * the start rect is outside of the target rect, and there is a lot of movement going on.
772 *
773 * @param cutOff whether the start rect was not fully contained by the end rect
774 * @param translationX the total translation the surface moves in x direction
775 * @param translationY the total translation the surfaces moves in y direction
776 * @param displayFrame our display frame
777 *
778 * @return the duration of the clip reveal animation, in milliseconds
779 */
780 private long calculateClipRevealTransitionDuration(boolean cutOff, float translationX,
781 float translationY, Rect displayFrame) {
782 if (!cutOff) {
783 return DEFAULT_APP_TRANSITION_DURATION;
784 }
785 final float fraction = Math.max(Math.abs(translationX) / displayFrame.width(),
786 Math.abs(translationY) / displayFrame.height());
787 return (long) (DEFAULT_APP_TRANSITION_DURATION + fraction *
788 (MAX_CLIP_REVEAL_TRANSITION_DURATION - DEFAULT_APP_TRANSITION_DURATION));
789 }
790
791 private Animation createClipRevealAnimationLocked(int transit, boolean enter, Rect appFrame,
792 Rect displayFrame) {
Chet Haase10e23ab2015-02-11 15:08:38 -0800793 final Animation anim;
794 if (enter) {
Craig Mautner80b1f642015-04-22 10:59:09 -0700795 final int appWidth = appFrame.width();
796 final int appHeight = appFrame.height();
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800797
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700798 // mTmpRect will contain an area around the launcher icon that was pressed. We will
Filip Gruszczynski82861362015-10-16 14:21:09 -0700799 // clip reveal from that area in the final area of the app.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700800 getDefaultNextAppTransitionStartRect(mTmpRect);
Craig Mautner80b1f642015-04-22 10:59:09 -0700801
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700802 float t = 0f;
803 if (appHeight > 0) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800804 t = (float) mTmpRect.top / displayFrame.height();
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700805 }
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800806 int translationY = mClipRevealTranslationY + (int)(displayFrame.height() / 7f * t);
807 int translationX = 0;
808 int translationYCorrection = translationY;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700809 int centerX = mTmpRect.centerX();
810 int centerY = mTmpRect.centerY();
811 int halfWidth = mTmpRect.width() / 2;
812 int halfHeight = mTmpRect.height() / 2;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800813 int clipStartX = centerX - halfWidth - appFrame.left;
814 int clipStartY = centerY - halfHeight - appFrame.top;
815 boolean cutOff = false;
816
817 // If the starting rectangle is fully or partially outside of the target rectangle, we
818 // need to start the clipping at the edge and then achieve the rest with translation
819 // and extending the clip rect from that edge.
820 if (appFrame.top > centerY - halfHeight) {
821 translationY = (centerY - halfHeight) - appFrame.top;
822 translationYCorrection = 0;
823 clipStartY = 0;
824 cutOff = true;
825 }
826 if (appFrame.left > centerX - halfWidth) {
827 translationX = (centerX - halfWidth) - appFrame.left;
828 clipStartX = 0;
829 cutOff = true;
830 }
831 if (appFrame.right < centerX + halfWidth) {
832 translationX = (centerX + halfWidth) - appFrame.right;
833 clipStartX = appWidth - mTmpRect.width();
834 cutOff = true;
835 }
836 final long duration = calculateClipRevealTransitionDuration(cutOff, translationX,
837 translationY, displayFrame);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700838
839 // Clip third of the from size of launch icon, expand to full width/height
Chet Haase10e23ab2015-02-11 15:08:38 -0800840 Animation clipAnimLR = new ClipRectLRAnimation(
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800841 clipStartX, clipStartX + mTmpRect.width(), 0, appWidth);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700842 clipAnimLR.setInterpolator(mClipHorizontalInterpolator);
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800843 clipAnimLR.setDuration((long) (duration / 2.5f));
Filip Gruszczynski82861362015-10-16 14:21:09 -0700844
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800845 TranslateAnimation translate = new TranslateAnimation(translationX, 0, translationY, 0);
846 translate.setInterpolator(cutOff ? TOUCH_RESPONSE_INTERPOLATOR
847 : mLinearOutSlowInInterpolator);
848 translate.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800849
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800850 Animation clipAnimTB = new ClipRectTBAnimation(
851 clipStartY, clipStartY + mTmpRect.height(),
852 0, appHeight,
853 translationYCorrection, 0,
854 mLinearOutSlowInInterpolator);
855 clipAnimTB.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
856 clipAnimTB.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800857
858 // Quick fade-in from icon to app window
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800859 final long alphaDuration = duration / 4;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700860 AlphaAnimation alpha = new AlphaAnimation(0.5f, 1);
Chet Haase10e23ab2015-02-11 15:08:38 -0800861 alpha.setDuration(alphaDuration);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700862 alpha.setInterpolator(mLinearOutSlowInInterpolator);
Chet Haase10e23ab2015-02-11 15:08:38 -0800863
864 AnimationSet set = new AnimationSet(false);
865 set.addAnimation(clipAnimLR);
866 set.addAnimation(clipAnimTB);
Filip Gruszczynski82861362015-10-16 14:21:09 -0700867 set.addAnimation(translate);
Chet Haase10e23ab2015-02-11 15:08:38 -0800868 set.addAnimation(alpha);
Filip Gruszczynski9e2cf5b2015-07-31 12:20:40 -0700869 set.setZAdjustment(Animation.ZORDER_TOP);
Chet Haase10e23ab2015-02-11 15:08:38 -0800870 set.initialize(appWidth, appHeight, appWidth, appHeight);
871 anim = set;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800872 mLastHadClipReveal = true;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800873 mLastClipRevealTransitionDuration = duration;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800874
875 // If the start rect was full inside the target rect (cutOff == false), we don't need
876 // to store the translation, because it's only used if cutOff == true.
877 mLastClipRevealMaxTranslation = cutOff
878 ? Math.max(Math.abs(translationY), Math.abs(translationX)) : 0;
Chet Haase10e23ab2015-02-11 15:08:38 -0800879 } else {
880 final long duration;
881 switch (transit) {
882 case TRANSIT_ACTIVITY_OPEN:
883 case TRANSIT_ACTIVITY_CLOSE:
884 duration = mConfigShortAnimTime;
885 break;
886 default:
887 duration = DEFAULT_APP_TRANSITION_DURATION;
888 break;
889 }
890 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
891 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
892 // If we are on top of the wallpaper, we need an animation that
893 // correctly handles the wallpaper staying static behind all of
894 // the animated elements. To do this, will just have the existing
895 // element fade out.
896 anim = new AlphaAnimation(1, 0);
897 anim.setDetachWallpaper(true);
898 } else {
899 // For normal animations, the exiting element just holds in place.
900 anim = new AlphaAnimation(1, 1);
901 }
902 anim.setInterpolator(mDecelerateInterpolator);
903 anim.setDuration(duration);
904 anim.setFillAfter(true);
905 }
906 return anim;
907 }
908
Winson Chung399f6202014-03-19 10:47:20 -0700909 /**
910 * Prepares the specified animation with a standard duration, interpolator, etc.
911 */
Winson Chung5393dff2014-05-08 14:25:43 -0700912 Animation prepareThumbnailAnimationWithDuration(Animation a, int appWidth, int appHeight,
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100913 long duration, Interpolator interpolator) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700914 if (duration > 0) {
915 a.setDuration(duration);
916 }
Winson Chung5393dff2014-05-08 14:25:43 -0700917 a.setFillAfter(true);
Jorim Jaggic69bd222016-03-15 14:38:37 +0100918 if (interpolator != null) {
919 a.setInterpolator(interpolator);
920 }
Winson Chung5393dff2014-05-08 14:25:43 -0700921 a.initialize(appWidth, appHeight, appWidth, appHeight);
922 return a;
923 }
924
925 /**
926 * Prepares the specified animation with a standard duration, interpolator, etc.
927 */
Winson Chung399f6202014-03-19 10:47:20 -0700928 Animation prepareThumbnailAnimation(Animation a, int appWidth, int appHeight, int transit) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800929 // Pick the desired duration. If this is an inter-activity transition,
930 // it is the standard duration for that. Otherwise we use the longer
931 // task transition duration.
Winson Chung5393dff2014-05-08 14:25:43 -0700932 final int duration;
Craig Mautner321bdf52012-12-18 09:53:24 -0800933 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800934 case TRANSIT_ACTIVITY_OPEN:
935 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800936 duration = mConfigShortAnimTime;
937 break;
938 default:
939 duration = DEFAULT_APP_TRANSITION_DURATION;
940 break;
941 }
Winson Chung5393dff2014-05-08 14:25:43 -0700942 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, duration,
943 mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800944 }
945
Winson Chung399f6202014-03-19 10:47:20 -0700946 /**
947 * Return the current thumbnail transition state.
948 */
949 int getThumbnailTransitionState(boolean enter) {
950 if (enter) {
951 if (mNextAppTransitionScaleUp) {
952 return THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
953 } else {
954 return THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN;
955 }
956 } else {
957 if (mNextAppTransitionScaleUp) {
958 return THUMBNAIL_TRANSITION_EXIT_SCALE_UP;
959 } else {
960 return THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN;
961 }
962 }
963 }
964
965 /**
966 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700967 * when a thumbnail is specified with the pending animation override.
Winson Chung399f6202014-03-19 10:47:20 -0700968 */
Jorim Jaggide63d442016-03-14 14:56:56 +0100969 Animation createThumbnailAspectScaleAnimationLocked(Rect appRect, @Nullable Rect contentInsets,
Winson Chungaa7fa012017-05-24 15:50:06 -0700970 GraphicBuffer thumbnailHeader, final int taskId, int uiMode, int orientation) {
Winson Chung399f6202014-03-19 10:47:20 -0700971 Animation a;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700972 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chung399f6202014-03-19 10:47:20 -0700973 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700974 final int thumbHeightI = thumbnailHeader.getHeight();
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700975 final int appWidth = appRect.width();
Winson Chung399f6202014-03-19 10:47:20 -0700976
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700977 float scaleW = appWidth / thumbWidth;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700978 getNextAppTransitionStartRect(taskId, mTmpRect);
Jorim Jaggi09072002016-03-25 16:48:42 -0700979 final float fromX;
Manu Cornet57b61492017-01-24 18:19:05 +0900980 float fromY;
Jorim Jaggi09072002016-03-25 16:48:42 -0700981 final float toX;
Manu Cornet57b61492017-01-24 18:19:05 +0900982 float toY;
Jorim Jaggi09072002016-03-25 16:48:42 -0700983 final float pivotX;
984 final float pivotY;
Manu Cornetd7376802017-01-13 13:44:07 -0800985 if (shouldScaleDownThumbnailTransition(uiMode, orientation)) {
Jorim Jaggi09072002016-03-25 16:48:42 -0700986 fromX = mTmpRect.left;
987 fromY = mTmpRect.top;
988
989 // For the curved translate animation to work, the pivot points needs to be at the
990 // same absolute position as the one from the real surface.
991 toX = mTmpRect.width() / 2 * (scaleW - 1f) + appRect.left;
992 toY = appRect.height() / 2 * (1 - 1 / scaleW) + appRect.top;
993 pivotX = mTmpRect.width() / 2;
994 pivotY = appRect.height() / 2 / scaleW;
Manu Cornet57b61492017-01-24 18:19:05 +0900995 if (mGridLayoutRecentsEnabled) {
996 // In the grid layout, the header is displayed above the thumbnail instead of
997 // overlapping it.
998 fromY -= thumbHeightI;
999 toY -= thumbHeightI * scaleW;
1000 }
Jorim Jaggi09072002016-03-25 16:48:42 -07001001 } else {
1002 pivotX = 0;
1003 pivotY = 0;
1004 fromX = mTmpRect.left;
1005 fromY = mTmpRect.top;
1006 toX = appRect.left;
1007 toY = appRect.top;
1008 }
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001009 final long duration = getAspectScaleDuration();
1010 final Interpolator interpolator = getAspectScaleInterpolator();
Winson Chung399f6202014-03-19 10:47:20 -07001011 if (mNextAppTransitionScaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001012 // Animation up from the thumbnail to the full screen
Jorim Jaggi8448f332016-03-14 17:50:37 +01001013 Animation scale = new ScaleAnimation(1f, scaleW, 1f, scaleW, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001014 scale.setInterpolator(interpolator);
1015 scale.setDuration(duration);
Jorim Jaggic6c89a82016-01-28 17:48:21 -08001016 Animation alpha = new AlphaAnimation(1f, 0f);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001017 alpha.setInterpolator(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
1018 ? THUMBNAIL_DOCK_INTERPOLATOR : mThumbnailFadeOutInterpolator);
1019 alpha.setDuration(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
1020 ? duration / 2
1021 : duration);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001022 Animation translate = createCurvedMotion(fromX, toX, fromY, toY);
1023 translate.setInterpolator(interpolator);
1024 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -07001025
Jorim Jaggide63d442016-03-14 14:56:56 +01001026 mTmpFromClipRect.set(0, 0, thumbWidthI, thumbHeightI);
1027 mTmpToClipRect.set(appRect);
1028
1029 // Containing frame is in screen space, but we need the clip rect in the
1030 // app space.
1031 mTmpToClipRect.offsetTo(0, 0);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001032 mTmpToClipRect.right = (int) (mTmpToClipRect.right / scaleW);
1033 mTmpToClipRect.bottom = (int) (mTmpToClipRect.bottom / scaleW);
Jorim Jaggide63d442016-03-14 14:56:56 +01001034
1035 if (contentInsets != null) {
Jorim Jaggi8448f332016-03-14 17:50:37 +01001036 mTmpToClipRect.inset((int) (-contentInsets.left * scaleW),
1037 (int) (-contentInsets.top * scaleW),
1038 (int) (-contentInsets.right * scaleW),
1039 (int) (-contentInsets.bottom * scaleW));
Jorim Jaggide63d442016-03-14 14:56:56 +01001040 }
1041
1042 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001043 clipAnim.setInterpolator(interpolator);
1044 clipAnim.setDuration(duration);
Jorim Jaggide63d442016-03-14 14:56:56 +01001045
Winson Chung399f6202014-03-19 10:47:20 -07001046 // This AnimationSet uses the Interpolators assigned above.
1047 AnimationSet set = new AnimationSet(false);
1048 set.addAnimation(scale);
Manu Cornet57b61492017-01-24 18:19:05 +09001049 if (!mGridLayoutRecentsEnabled) {
1050 // In the grid layout, the header should be shown for the whole animation.
1051 set.addAnimation(alpha);
1052 }
Winson Chunga4ccb862014-08-22 15:26:27 -07001053 set.addAnimation(translate);
Jorim Jaggide63d442016-03-14 14:56:56 +01001054 set.addAnimation(clipAnim);
Winson Chung399f6202014-03-19 10:47:20 -07001055 a = set;
1056 } else {
Winson Chunga4ccb862014-08-22 15:26:27 -07001057 // Animation down from the full screen to the thumbnail
Jorim Jaggi8448f332016-03-14 17:50:37 +01001058 Animation scale = new ScaleAnimation(scaleW, 1f, scaleW, 1f, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001059 scale.setInterpolator(interpolator);
1060 scale.setDuration(duration);
Winson Chunga4ccb862014-08-22 15:26:27 -07001061 Animation alpha = new AlphaAnimation(0f, 1f);
1062 alpha.setInterpolator(mThumbnailFadeInInterpolator);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001063 alpha.setDuration(duration);
1064 Animation translate = createCurvedMotion(toX, fromX, toY, fromY);
1065 translate.setInterpolator(interpolator);
1066 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -07001067
Winson Chunga4ccb862014-08-22 15:26:27 -07001068 // This AnimationSet uses the Interpolators assigned above.
1069 AnimationSet set = new AnimationSet(false);
1070 set.addAnimation(scale);
Manu Cornet57b61492017-01-24 18:19:05 +09001071 if (!mGridLayoutRecentsEnabled) {
1072 // In the grid layout, the header should be shown for the whole animation.
1073 set.addAnimation(alpha);
1074 }
Winson Chunga4ccb862014-08-22 15:26:27 -07001075 set.addAnimation(translate);
1076 a = set;
1077
1078 }
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -07001079 return prepareThumbnailAnimationWithDuration(a, appWidth, appRect.height(), 0,
Jorim Jaggic69bd222016-03-15 14:38:37 +01001080 null);
Winson Chung399f6202014-03-19 10:47:20 -07001081 }
1082
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001083 private Animation createCurvedMotion(float fromX, float toX, float fromY, float toY) {
1084
1085 // Almost no x-change - use linear animation
Jorim Jaggic69bd222016-03-15 14:38:37 +01001086 if (Math.abs(toX - fromX) < 1f || mNextAppTransition != TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001087 return new TranslateAnimation(fromX, toX, fromY, toY);
1088 } else {
1089 final Path path = createCurvedPath(fromX, toX, fromY, toY);
1090 return new CurvedTranslateAnimation(path);
1091 }
1092 }
1093
1094 private Path createCurvedPath(float fromX, float toX, float fromY, float toY) {
1095 final Path path = new Path();
1096 path.moveTo(fromX, fromY);
Jorim Jaggi1f458fb2016-03-25 17:36:37 -07001097
1098 if (fromY > toY) {
1099 // If the object needs to go up, move it in horizontal direction first, then vertical.
1100 path.cubicTo(fromX, fromY, toX, 0.9f * fromY + 0.1f * toY, toX, toY);
1101 } else {
1102 // If the object needs to go down, move it in vertical direction first, then horizontal.
1103 path.cubicTo(fromX, fromY, fromX, 0.1f * fromY + 0.9f * toY, toX, toY);
1104 }
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001105 return path;
1106 }
1107
1108 private long getAspectScaleDuration() {
1109 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggic69bd222016-03-15 14:38:37 +01001110 return (long) (THUMBNAIL_APP_TRANSITION_DURATION * 1.35f);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001111 } else {
1112 return THUMBNAIL_APP_TRANSITION_DURATION;
1113 }
1114 }
1115
1116 private Interpolator getAspectScaleInterpolator() {
1117 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
1118 return mFastOutSlowInInterpolator;
1119 } else {
1120 return TOUCH_RESPONSE_INTERPOLATOR;
1121 }
1122 }
1123
Winson Chung399f6202014-03-19 10:47:20 -07001124 /**
1125 * This alternate animation is created when we are doing a thumbnail transition, for the
1126 * activity that is leaving, and the activity that is entering.
1127 */
Winson Chunga4ccb862014-08-22 15:26:27 -07001128 Animation createAspectScaledThumbnailEnterExitAnimationLocked(int thumbTransitState,
Winsonb2024762016-04-05 17:32:30 -07001129 int uiMode, int orientation, int transit, Rect containingFrame, Rect contentInsets,
Matthew Ng43db6d22017-06-27 15:29:39 -07001130 @Nullable Rect surfaceInsets, @Nullable Rect stableInsets, boolean freeform,
1131 int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -07001132 Animation a;
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001133 final int appWidth = containingFrame.width();
1134 final int appHeight = containingFrame.height();
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001135 getDefaultNextAppTransitionStartRect(mTmpRect);
1136 final int thumbWidthI = mTmpRect.width();
Winson Chung399f6202014-03-19 10:47:20 -07001137 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001138 final int thumbHeightI = mTmpRect.height();
Winson Chung399f6202014-03-19 10:47:20 -07001139 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
Winsoncbb625b2016-07-06 15:24:15 -07001140 final int thumbStartX = mTmpRect.left - containingFrame.left - contentInsets.left;
Winson21700932016-03-24 17:26:23 -07001141 final int thumbStartY = mTmpRect.top - containingFrame.top;
Winson Chung399f6202014-03-19 10:47:20 -07001142
1143 switch (thumbTransitState) {
Jorim Jaggi8448f332016-03-14 17:50:37 +01001144 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP:
1145 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1146 final boolean scaleUp = thumbTransitState == THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
1147 if (freeform && scaleUp) {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001148 a = createAspectScaledThumbnailEnterFreeformAnimationLocked(
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001149 containingFrame, surfaceInsets, taskId);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001150 } else if (freeform) {
1151 a = createAspectScaledThumbnailExitFreeformAnimationLocked(
1152 containingFrame, surfaceInsets, taskId);
Winson Chung2820c452014-04-15 15:34:44 -07001153 } else {
Winson21700932016-03-24 17:26:23 -07001154 AnimationSet set = new AnimationSet(true);
1155
1156 // In portrait, we scale to fit the width
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001157 mTmpFromClipRect.set(containingFrame);
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001158 mTmpToClipRect.set(containingFrame);
Jorim Jaggic6c89a82016-01-28 17:48:21 -08001159
1160 // Containing frame is in screen space, but we need the clip rect in the
1161 // app space.
1162 mTmpFromClipRect.offsetTo(0, 0);
1163 mTmpToClipRect.offsetTo(0, 0);
1164
1165 // Exclude insets region from the source clip.
1166 mTmpFromClipRect.inset(contentInsets);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001167 mNextAppTransitionInsets.set(contentInsets);
1168
Manu Cornetd7376802017-01-13 13:44:07 -08001169 if (shouldScaleDownThumbnailTransition(uiMode, orientation)) {
Jorim Jaggic69bd222016-03-15 14:38:37 +01001170 // We scale the width and clip to the top/left square
1171 float scale = thumbWidth /
1172 (appWidth - contentInsets.left - contentInsets.right);
Manu Cornetb68b7652017-01-23 19:37:53 +09001173 if (!mGridLayoutRecentsEnabled) {
1174 int unscaledThumbHeight = (int) (thumbHeight / scale);
1175 mTmpFromClipRect.bottom = mTmpFromClipRect.top + unscaledThumbHeight;
1176 }
Jorim Jaggic69bd222016-03-15 14:38:37 +01001177
1178 mNextAppTransitionInsets.set(contentInsets);
1179
Jorim Jaggi8448f332016-03-14 17:50:37 +01001180 Animation scaleAnim = new ScaleAnimation(
1181 scaleUp ? scale : 1, scaleUp ? 1 : scale,
1182 scaleUp ? scale : 1, scaleUp ? 1 : scale,
Jorim Jaggic69bd222016-03-15 14:38:37 +01001183 containingFrame.width() / 2f,
1184 containingFrame.height() / 2f + contentInsets.top);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001185 final float targetX = (mTmpRect.left - containingFrame.left);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001186 final float x = containingFrame.width() / 2f
1187 - containingFrame.width() / 2f * scale;
Jorim Jaggi8448f332016-03-14 17:50:37 +01001188 final float targetY = (mTmpRect.top - containingFrame.top);
Matthew Ng43db6d22017-06-27 15:29:39 -07001189 float y = containingFrame.height() / 2f
Jorim Jaggic69bd222016-03-15 14:38:37 +01001190 - containingFrame.height() / 2f * scale;
Matthew Ng43db6d22017-06-27 15:29:39 -07001191
1192 // During transition may require clipping offset from any top stable insets
1193 // such as the statusbar height when statusbar is hidden
1194 if (mLowRamRecentsEnabled && contentInsets.top == 0 && scaleUp) {
1195 mTmpFromClipRect.top += stableInsets.top;
1196 y += stableInsets.top;
1197 }
Jorim Jaggi8448f332016-03-14 17:50:37 +01001198 final float startX = targetX - x;
1199 final float startY = targetY - y;
1200 Animation clipAnim = scaleUp
1201 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1202 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1203 Animation translateAnim = scaleUp
Jorim Jaggic69bd222016-03-15 14:38:37 +01001204 ? createCurvedMotion(startX, 0, startY - contentInsets.top, 0)
1205 : createCurvedMotion(0, startX, 0, startY - contentInsets.top);
1206
Winson21700932016-03-24 17:26:23 -07001207 set.addAnimation(clipAnim);
1208 set.addAnimation(scaleAnim);
1209 set.addAnimation(translateAnim);
1210
1211 } else {
1212 // In landscape, we don't scale at all and only crop
1213 mTmpFromClipRect.bottom = mTmpFromClipRect.top + thumbHeightI;
1214 mTmpFromClipRect.right = mTmpFromClipRect.left + thumbWidthI;
1215
Jorim Jaggi8448f332016-03-14 17:50:37 +01001216 Animation clipAnim = scaleUp
1217 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1218 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1219 Animation translateAnim = scaleUp
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001220 ? createCurvedMotion(thumbStartX, 0,
1221 thumbStartY - contentInsets.top, 0)
1222 : createCurvedMotion(0, thumbStartX, 0,
1223 thumbStartY - contentInsets.top);
Winson21700932016-03-24 17:26:23 -07001224
1225 set.addAnimation(clipAnim);
1226 set.addAnimation(translateAnim);
1227 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001228 a = set;
Winson21700932016-03-24 17:26:23 -07001229 a.setZAdjustment(Animation.ZORDER_TOP);
Winson Chung2820c452014-04-15 15:34:44 -07001230 }
Winson Chung399f6202014-03-19 10:47:20 -07001231 break;
1232 }
1233 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001234 // Previous app window during the scale up
Winson Chung399f6202014-03-19 10:47:20 -07001235 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001236 // Fade out the source activity if we are animating to a wallpaper
Winson Chung399f6202014-03-19 10:47:20 -07001237 // activity.
1238 a = new AlphaAnimation(1, 0);
1239 } else {
Winson Chung399f6202014-03-19 10:47:20 -07001240 a = new AlphaAnimation(1, 1);
1241 }
1242 break;
1243 }
1244 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001245 // Target app window during the scale down
1246 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1247 // Fade in the destination activity if we are animating from a wallpaper
1248 // activity.
1249 a = new AlphaAnimation(0, 1);
1250 } else {
1251 a = new AlphaAnimation(1, 1);
1252 }
Winson Chung399f6202014-03-19 10:47:20 -07001253 break;
1254 }
Winson Chung399f6202014-03-19 10:47:20 -07001255 default:
1256 throw new RuntimeException("Invalid thumbnail transition state");
1257 }
1258
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001259 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight,
1260 getAspectScaleDuration(), getAspectScaleInterpolator());
Winson Chung399f6202014-03-19 10:47:20 -07001261 }
1262
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001263 private Animation createAspectScaledThumbnailEnterFreeformAnimationLocked(Rect frame,
1264 @Nullable Rect surfaceInsets, int taskId) {
1265 getNextAppTransitionStartRect(taskId, mTmpRect);
1266 return createAspectScaledThumbnailFreeformAnimationLocked(mTmpRect, frame, surfaceInsets,
1267 true);
1268 }
1269
1270 private Animation createAspectScaledThumbnailExitFreeformAnimationLocked(Rect frame,
1271 @Nullable Rect surfaceInsets, int taskId) {
1272 getNextAppTransitionStartRect(taskId, mTmpRect);
1273 return createAspectScaledThumbnailFreeformAnimationLocked(frame, mTmpRect, surfaceInsets,
1274 false);
1275 }
1276
1277 private AnimationSet createAspectScaledThumbnailFreeformAnimationLocked(Rect sourceFrame,
1278 Rect destFrame, @Nullable Rect surfaceInsets, boolean enter) {
1279 final float sourceWidth = sourceFrame.width();
1280 final float sourceHeight = sourceFrame.height();
1281 final float destWidth = destFrame.width();
1282 final float destHeight = destFrame.height();
1283 final float scaleH = enter ? sourceWidth / destWidth : destWidth / sourceWidth;
1284 final float scaleV = enter ? sourceHeight / destHeight : destHeight / sourceHeight;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001285 AnimationSet set = new AnimationSet(true);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001286 final int surfaceInsetsH = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001287 ? 0 : surfaceInsets.left + surfaceInsets.right;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001288 final int surfaceInsetsV = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001289 ? 0 : surfaceInsets.top + surfaceInsets.bottom;
1290 // We want the scaling to happen from the center of the surface. In order to achieve that,
1291 // we need to account for surface insets that will be used to enlarge the surface.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001292 final float scaleHCenter = ((enter ? destWidth : sourceWidth) + surfaceInsetsH) / 2;
1293 final float scaleVCenter = ((enter ? destHeight : sourceHeight) + surfaceInsetsV) / 2;
1294 final ScaleAnimation scale = enter ?
1295 new ScaleAnimation(scaleH, 1, scaleV, 1, scaleHCenter, scaleVCenter)
1296 : new ScaleAnimation(1, scaleH, 1, scaleV, scaleHCenter, scaleVCenter);
1297 final int sourceHCenter = sourceFrame.left + sourceFrame.width() / 2;
1298 final int sourceVCenter = sourceFrame.top + sourceFrame.height() / 2;
1299 final int destHCenter = destFrame.left + destFrame.width() / 2;
1300 final int destVCenter = destFrame.top + destFrame.height() / 2;
1301 final int fromX = enter ? sourceHCenter - destHCenter : destHCenter - sourceHCenter;
1302 final int fromY = enter ? sourceVCenter - destVCenter : destVCenter - sourceVCenter;
1303 final TranslateAnimation translation = enter ? new TranslateAnimation(fromX, 0, fromY, 0)
1304 : new TranslateAnimation(0, fromX, 0, fromY);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001305 set.addAnimation(scale);
1306 set.addAnimation(translation);
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001307
1308 final IRemoteCallback callback = mAnimationFinishedCallback;
1309 if (callback != null) {
1310 set.setAnimationListener(new Animation.AnimationListener() {
1311 @Override
1312 public void onAnimationStart(Animation animation) { }
1313
1314 @Override
1315 public void onAnimationEnd(Animation animation) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001316 mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK, callback).sendToTarget();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001317 }
1318
1319 @Override
1320 public void onAnimationRepeat(Animation animation) { }
1321 });
1322 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001323 return set;
1324 }
1325
Winson Chung399f6202014-03-19 10:47:20 -07001326 /**
Winson Chunga4ccb862014-08-22 15:26:27 -07001327 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001328 * when a thumbnail is specified with the pending animation override.
Winson Chunga4ccb862014-08-22 15:26:27 -07001329 */
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001330 Animation createThumbnailScaleAnimationLocked(int appWidth, int appHeight, int transit,
Winson Chungaa7fa012017-05-24 15:50:06 -07001331 GraphicBuffer thumbnailHeader) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001332 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001333 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001334 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chunga4ccb862014-08-22 15:26:27 -07001335 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001336 final int thumbHeightI = thumbnailHeader.getHeight();
Winson Chunga4ccb862014-08-22 15:26:27 -07001337 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1338
1339 if (mNextAppTransitionScaleUp) {
1340 // Animation for the thumbnail zooming from its initial size to the full screen
1341 float scaleW = appWidth / thumbWidth;
1342 float scaleH = appHeight / thumbHeight;
1343 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001344 computePivot(mTmpRect.left, 1 / scaleW),
1345 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001346 scale.setInterpolator(mDecelerateInterpolator);
1347
1348 Animation alpha = new AlphaAnimation(1, 0);
1349 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
1350
1351 // This AnimationSet uses the Interpolators assigned above.
1352 AnimationSet set = new AnimationSet(false);
1353 set.addAnimation(scale);
1354 set.addAnimation(alpha);
1355 a = set;
1356 } else {
1357 // Animation for the thumbnail zooming down from the full screen to its final size
1358 float scaleW = appWidth / thumbWidth;
1359 float scaleH = appHeight / thumbHeight;
1360 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001361 computePivot(mTmpRect.left, 1 / scaleW),
1362 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001363 }
1364
1365 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1366 }
1367
1368 /**
Winson Chung399f6202014-03-19 10:47:20 -07001369 * This animation is created when we are doing a thumbnail transition, for the activity that is
1370 * leaving, and the activity that is entering.
1371 */
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001372 Animation createThumbnailEnterExitAnimationLocked(int thumbTransitState, Rect containingFrame,
1373 int transit, int taskId) {
1374 final int appWidth = containingFrame.width();
1375 final int appHeight = containingFrame.height();
Winson Chungaa7fa012017-05-24 15:50:06 -07001376 final GraphicBuffer thumbnailHeader = getAppTransitionThumbnailHeader(taskId);
Winson Chung399f6202014-03-19 10:47:20 -07001377 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001378 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001379 final int thumbWidthI = thumbnailHeader != null ? thumbnailHeader.getWidth() : appWidth;
Winson Chung399f6202014-03-19 10:47:20 -07001380 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001381 final int thumbHeightI = thumbnailHeader != null ? thumbnailHeader.getHeight() : appHeight;
Winson Chung399f6202014-03-19 10:47:20 -07001382 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1383
1384 switch (thumbTransitState) {
1385 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
1386 // Entering app scales up with the thumbnail
1387 float scaleW = thumbWidth / appWidth;
1388 float scaleH = thumbHeight / appHeight;
1389 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001390 computePivot(mTmpRect.left, scaleW),
1391 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001392 break;
1393 }
1394 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
1395 // Exiting app while the thumbnail is scaling up should fade or stay in place
1396 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1397 // Fade out while bringing up selected activity. This keeps the
1398 // current activity from showing through a launching wallpaper
1399 // activity.
1400 a = new AlphaAnimation(1, 0);
1401 } else {
1402 // noop animation
1403 a = new AlphaAnimation(1, 1);
1404 }
1405 break;
1406 }
1407 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
1408 // Entering the other app, it should just be visible while we scale the thumbnail
1409 // down above it
1410 a = new AlphaAnimation(1, 1);
1411 break;
1412 }
1413 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1414 // Exiting the current app, the app should scale down with the thumbnail
1415 float scaleW = thumbWidth / appWidth;
1416 float scaleH = thumbHeight / appHeight;
1417 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001418 computePivot(mTmpRect.left, scaleW),
1419 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001420
1421 Animation alpha = new AlphaAnimation(1, 0);
1422
1423 AnimationSet set = new AnimationSet(true);
1424 set.addAnimation(scale);
1425 set.addAnimation(alpha);
1426 set.setZAdjustment(Animation.ZORDER_TOP);
1427 a = set;
1428 break;
1429 }
1430 default:
1431 throw new RuntimeException("Invalid thumbnail transition state");
1432 }
1433
1434 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1435 }
1436
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001437 private Animation createRelaunchAnimation(Rect containingFrame, Rect contentInsets) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001438 getDefaultNextAppTransitionStartRect(mTmpFromClipRect);
1439 final int left = mTmpFromClipRect.left;
1440 final int top = mTmpFromClipRect.top;
1441 mTmpFromClipRect.offset(-left, -top);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001442 // TODO: Isn't that strange that we ignore exact position of the containingFrame?
1443 mTmpToClipRect.set(0, 0, containingFrame.width(), containingFrame.height());
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001444 AnimationSet set = new AnimationSet(true);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001445 float fromWidth = mTmpFromClipRect.width();
1446 float toWidth = mTmpToClipRect.width();
1447 float fromHeight = mTmpFromClipRect.height();
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001448 // While the window might span the whole display, the actual content will be cropped to the
1449 // system decoration frame, for example when the window is docked. We need to take into
1450 // account the visible height when constructing the animation.
1451 float toHeight = mTmpToClipRect.height() - contentInsets.top - contentInsets.bottom;
1452 int translateAdjustment = 0;
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001453 if (fromWidth <= toWidth && fromHeight <= toHeight) {
1454 // The final window is larger in both dimensions than current window (e.g. we are
1455 // maximizing), so we can simply unclip the new window and there will be no disappearing
1456 // frame.
1457 set.addAnimation(new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect));
1458 } else {
1459 // The disappearing window has one larger dimension. We need to apply scaling, so the
1460 // first frame of the entry animation matches the old window.
1461 set.addAnimation(new ScaleAnimation(fromWidth / toWidth, 1, fromHeight / toHeight, 1));
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001462 // We might not be going exactly full screen, but instead be aligned under the status
1463 // bar using cropping. We still need to account for the cropped part, which will also
1464 // be scaled.
1465 translateAdjustment = (int) (contentInsets.top * fromHeight / toHeight);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001466 }
1467
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001468 // We animate the translation from the old position of the removed window, to the new
1469 // position of the added window. The latter might not be full screen, for example docked for
1470 // docked windows.
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001471 TranslateAnimation translate = new TranslateAnimation(left - containingFrame.left,
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001472 0, top - containingFrame.top - translateAdjustment, 0);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001473 set.addAnimation(translate);
1474 set.setDuration(DEFAULT_APP_TRANSITION_DURATION);
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07001475 set.setZAdjustment(Animation.ZORDER_TOP);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001476 return set;
1477 }
1478
Jorim Jaggic554b772015-06-04 16:07:57 -07001479 /**
1480 * @return true if and only if the first frame of the transition can be skipped, i.e. the first
1481 * frame of the transition doesn't change the visuals on screen, so we can start
1482 * directly with the second one
1483 */
1484 boolean canSkipFirstFrame() {
1485 return mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM
1486 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE
Jorim Jaggife762342016-10-13 14:33:27 +02001487 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CLIP_REVEAL
1488 && mNextAppTransition != TRANSIT_KEYGUARD_GOING_AWAY;
Jorim Jaggic554b772015-06-04 16:07:57 -07001489 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001490
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001491 /**
1492 *
1493 * @param frame These are the bounds of the window when it finishes the animation. This is where
1494 * the animation must usually finish in entrance animation, as the next frame will
1495 * display the window at these coordinates. In case of exit animation, this is
1496 * where the animation must start, as the frame before the animation is displaying
1497 * the window at these bounds.
1498 * @param insets Knowing where the window will be positioned is not enough. Some parts of the
1499 * window might be obscured, usually by the system windows (status bar and
1500 * navigation bar) and we use content insets to convey that information. This
1501 * usually affects the animation aspects vertically, as the system decoration is
1502 * at the top and the bottom. For example when we animate from full screen to
1503 * recents, we want to exclude the covered parts, because they won't match the
1504 * thumbnail after the last frame is executed.
1505 * @param surfaceInsets In rare situation the surface is larger than the content and we need to
1506 * know about this to make the animation frames match. We currently use
1507 * this for freeform windows, which have larger surfaces to display
1508 * shadows. When we animate them from recents, we want to match the content
1509 * to the recents thumbnail and hence need to account for the surface being
1510 * bigger.
1511 */
Winsonb2024762016-04-05 17:32:30 -07001512 Animation loadAnimation(WindowManager.LayoutParams lp, int transit, boolean enter, int uiMode,
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001513 int orientation, Rect frame, Rect displayFrame, Rect insets,
Matthew Ng43db6d22017-06-27 15:29:39 -07001514 @Nullable Rect surfaceInsets, @Nullable Rect stableInsets, boolean isVoiceInteraction,
1515 boolean freeform, int taskId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001516 Animation a;
Jorim Jaggife762342016-10-13 14:33:27 +02001517 if (isKeyguardGoingAwayTransit(transit) && enter) {
1518 a = loadKeyguardExitAnimation(transit);
1519 } else if (transit == TRANSIT_KEYGUARD_OCCLUDE) {
1520 a = null;
1521 } else if (transit == TRANSIT_KEYGUARD_UNOCCLUDE && !enter) {
1522 a = loadAnimationRes(lp, com.android.internal.R.anim.wallpaper_open_exit);
1523 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_OPEN
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001524 || transit == TRANSIT_TASK_OPEN
1525 || transit == TRANSIT_TASK_TO_FRONT)) {
1526 a = loadAnimationRes(lp, enter
1527 ? com.android.internal.R.anim.voice_activity_open_enter
1528 : com.android.internal.R.anim.voice_activity_open_exit);
1529 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1530 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001531 + " anim=" + a + " transit=" + appTransitionToString(transit)
1532 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001533 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_CLOSE
1534 || transit == TRANSIT_TASK_CLOSE
1535 || transit == TRANSIT_TASK_TO_BACK)) {
1536 a = loadAnimationRes(lp, enter
1537 ? com.android.internal.R.anim.voice_activity_close_enter
1538 : com.android.internal.R.anim.voice_activity_close_exit);
1539 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1540 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001541 + " anim=" + a + " transit=" + appTransitionToString(transit)
1542 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001543 } else if (transit == TRANSIT_ACTIVITY_RELAUNCH) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001544 a = createRelaunchAnimation(frame, insets);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001545 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1546 "applyAnimation:"
1547 + " anim=" + a + " nextAppTransition=" + mNextAppTransition
1548 + " transit=" + appTransitionToString(transit)
1549 + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001550 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM) {
1551 a = loadAnimationRes(mNextAppTransitionPackage, enter ?
Craig Mautner164d4bb2012-11-26 13:51:23 -08001552 mNextAppTransitionEnter : mNextAppTransitionExit);
1553 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1554 "applyAnimation:"
1555 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001556 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001557 + " Callers=" + Debug.getCallers(3));
Winson Chung044d5292014-11-06 11:05:19 -08001558 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE) {
1559 a = loadAnimationRes(mNextAppTransitionPackage, mNextAppTransitionInPlace);
1560 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1561 "applyAnimation:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001562 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM_IN_PLACE"
1563 + " transit=" + appTransitionToString(transit)
1564 + " Callers=" + Debug.getCallers(3));
Chet Haase10e23ab2015-02-11 15:08:38 -08001565 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001566 a = createClipRevealAnimationLocked(transit, enter, frame, displayFrame);
Chet Haase10e23ab2015-02-11 15:08:38 -08001567 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1568 "applyAnimation:"
1569 + " anim=" + a + " nextAppTransition=ANIM_CLIP_REVEAL"
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001570 + " transit=" + appTransitionToString(transit)
Chet Haase10e23ab2015-02-11 15:08:38 -08001571 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001572 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_SCALE_UP) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001573 a = createScaleUpAnimationLocked(transit, enter, frame);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001574 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1575 "applyAnimation:"
1576 + " anim=" + a + " nextAppTransition=ANIM_SCALE_UP"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001577 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001578 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001579 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
1580 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001581 mNextAppTransitionScaleUp =
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001582 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP);
Winson Chunga4ccb862014-08-22 15:26:27 -07001583 a = createThumbnailEnterExitAnimationLocked(getThumbnailTransitionState(enter),
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001584 frame, transit, taskId);
Winson Chunga4ccb862014-08-22 15:26:27 -07001585 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1586 String animName = mNextAppTransitionScaleUp ?
1587 "ANIM_THUMBNAIL_SCALE_UP" : "ANIM_THUMBNAIL_SCALE_DOWN";
1588 Slog.v(TAG, "applyAnimation:"
1589 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001590 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Winson Chunga4ccb862014-08-22 15:26:27 -07001591 + " Callers=" + Debug.getCallers(3));
1592 }
1593 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
1594 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN) {
1595 mNextAppTransitionScaleUp =
1596 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP);
1597 a = createAspectScaledThumbnailEnterExitAnimationLocked(
Winsonb2024762016-04-05 17:32:30 -07001598 getThumbnailTransitionState(enter), uiMode, orientation, transit, frame,
Matthew Ng43db6d22017-06-27 15:29:39 -07001599 insets, surfaceInsets, stableInsets, freeform, taskId);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001600 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1601 String animName = mNextAppTransitionScaleUp ?
Winson Chunga4ccb862014-08-22 15:26:27 -07001602 "ANIM_THUMBNAIL_ASPECT_SCALE_UP" : "ANIM_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner164d4bb2012-11-26 13:51:23 -08001603 Slog.v(TAG, "applyAnimation:"
1604 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001605 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001606 + " Callers=" + Debug.getCallers(3));
1607 }
1608 } else {
1609 int animAttr = 0;
1610 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001611 case TRANSIT_ACTIVITY_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001612 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001613 ? WindowAnimation_activityOpenEnterAnimation
1614 : WindowAnimation_activityOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001615 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001616 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001617 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001618 ? WindowAnimation_activityCloseEnterAnimation
1619 : WindowAnimation_activityCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001620 break;
Jorim Jaggi192086e2016-03-11 17:17:03 +01001621 case TRANSIT_DOCK_TASK_FROM_RECENTS:
Craig Mautner4b71aa12012-12-27 17:20:01 -08001622 case TRANSIT_TASK_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001623 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001624 ? WindowAnimation_taskOpenEnterAnimation
1625 : WindowAnimation_taskOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001626 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001627 case TRANSIT_TASK_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001628 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001629 ? WindowAnimation_taskCloseEnterAnimation
1630 : WindowAnimation_taskCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001631 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001632 case TRANSIT_TASK_TO_FRONT:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001633 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001634 ? WindowAnimation_taskToFrontEnterAnimation
1635 : WindowAnimation_taskToFrontExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001636 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001637 case TRANSIT_TASK_TO_BACK:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001638 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001639 ? WindowAnimation_taskToBackEnterAnimation
1640 : WindowAnimation_taskToBackExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001641 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001642 case TRANSIT_WALLPAPER_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001643 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001644 ? WindowAnimation_wallpaperOpenEnterAnimation
1645 : WindowAnimation_wallpaperOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001646 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001647 case TRANSIT_WALLPAPER_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001648 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001649 ? WindowAnimation_wallpaperCloseEnterAnimation
1650 : WindowAnimation_wallpaperCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001651 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001652 case TRANSIT_WALLPAPER_INTRA_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001653 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001654 ? WindowAnimation_wallpaperIntraOpenEnterAnimation
1655 : WindowAnimation_wallpaperIntraOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001656 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001657 case TRANSIT_WALLPAPER_INTRA_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001658 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001659 ? WindowAnimation_wallpaperIntraCloseEnterAnimation
1660 : WindowAnimation_wallpaperIntraCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001661 break;
Craig Mautnerbb742462014-07-07 15:28:55 -07001662 case TRANSIT_TASK_OPEN_BEHIND:
1663 animAttr = enter
1664 ? WindowAnimation_launchTaskBehindSourceAnimation
Craig Mautner3b2cd1d2014-08-25 14:25:54 -07001665 : WindowAnimation_launchTaskBehindTargetAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001666 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001667 a = animAttr != 0 ? loadAnimationAttr(lp, animAttr) : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001668 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1669 "applyAnimation:"
1670 + " anim=" + a
1671 + " animAttr=0x" + Integer.toHexString(animAttr)
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001672 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001673 + " Callers=" + Debug.getCallers(3));
1674 }
1675 return a;
1676 }
1677
Jorim Jaggife762342016-10-13 14:33:27 +02001678 private Animation loadKeyguardExitAnimation(int transit) {
1679 if ((mNextAppTransitionFlags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_NO_ANIMATION) != 0) {
1680 return null;
1681 }
1682 final boolean toShade =
1683 (mNextAppTransitionFlags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_TO_SHADE) != 0;
1684 return mService.mPolicy.createHiddenByKeyguardExit(
1685 transit == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER, toShade);
1686 }
1687
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001688 int getAppStackClipMode() {
Matthew Ngbf1d9852017-03-14 12:23:09 -07001689 // When dismiss keyguard animation occurs, clip before the animation to prevent docked
1690 // app from showing beyond the divider
1691 if (mNextAppTransition == TRANSIT_KEYGUARD_GOING_AWAY
1692 || mNextAppTransition == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER) {
1693 return STACK_CLIP_BEFORE_ANIM;
1694 }
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001695 return mNextAppTransition == TRANSIT_ACTIVITY_RELAUNCH
Jorim Jaggic69bd222016-03-15 14:38:37 +01001696 || mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
Jorim Jaggi1f458fb2016-03-25 17:36:37 -07001697 || mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001698 ? STACK_CLIP_NONE
1699 : STACK_CLIP_AFTER_ANIM;
1700 }
1701
Jorim Jaggife762342016-10-13 14:33:27 +02001702 public int getTransitFlags() {
1703 return mNextAppTransitionFlags;
1704 }
1705
Craig Mautner164d4bb2012-11-26 13:51:23 -08001706 void postAnimationCallback() {
1707 if (mNextAppTransitionCallback != null) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001708 mService.mH.sendMessage(mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK,
1709 mNextAppTransitionCallback));
Craig Mautner164d4bb2012-11-26 13:51:23 -08001710 mNextAppTransitionCallback = null;
1711 }
1712 }
1713
1714 void overridePendingAppTransition(String packageName, int enterAnim, int exitAnim,
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001715 IRemoteCallback startedCallback) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001716 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001717 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001718 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001719 mNextAppTransitionPackage = packageName;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001720 mNextAppTransitionEnter = enterAnim;
1721 mNextAppTransitionExit = exitAnim;
1722 postAnimationCallback();
1723 mNextAppTransitionCallback = startedCallback;
1724 } else {
1725 postAnimationCallback();
1726 }
1727 }
1728
1729 void overridePendingAppTransitionScaleUp(int startX, int startY, int startWidth,
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001730 int startHeight) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001731 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001732 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001733 mNextAppTransitionType = NEXT_TRANSIT_TYPE_SCALE_UP;
Winson4c3fecd2016-07-13 12:29:48 -07001734 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001735 postAnimationCallback();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001736 }
1737 }
1738
Chet Haase10e23ab2015-02-11 15:08:38 -08001739 void overridePendingAppTransitionClipReveal(int startX, int startY,
1740 int startWidth, int startHeight) {
1741 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001742 clear();
Chet Haase10e23ab2015-02-11 15:08:38 -08001743 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CLIP_REVEAL;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001744 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Chet Haase10e23ab2015-02-11 15:08:38 -08001745 postAnimationCallback();
Chet Haase10e23ab2015-02-11 15:08:38 -08001746 }
1747 }
1748
Winson Chungaa7fa012017-05-24 15:50:06 -07001749 void overridePendingAppTransitionThumb(GraphicBuffer srcThumb, int startX, int startY,
Craig Mautner164d4bb2012-11-26 13:51:23 -08001750 IRemoteCallback startedCallback, boolean scaleUp) {
1751 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001752 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001753 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP
1754 : NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001755 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001756 putDefaultNextAppTransitionCoordinates(startX, startY, 0, 0, srcThumb);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001757 postAnimationCallback();
1758 mNextAppTransitionCallback = startedCallback;
1759 } else {
1760 postAnimationCallback();
1761 }
1762 }
1763
Winson Chungaa7fa012017-05-24 15:50:06 -07001764 void overridePendingAppTransitionAspectScaledThumb(GraphicBuffer srcThumb, int startX, int startY,
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001765 int targetWidth, int targetHeight, IRemoteCallback startedCallback, boolean scaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001766 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001767 clear();
Winson Chunga4ccb862014-08-22 15:26:27 -07001768 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1769 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Winson Chunga4ccb862014-08-22 15:26:27 -07001770 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001771 putDefaultNextAppTransitionCoordinates(startX, startY, targetWidth, targetHeight,
1772 srcThumb);
Winson Chunga4ccb862014-08-22 15:26:27 -07001773 postAnimationCallback();
1774 mNextAppTransitionCallback = startedCallback;
1775 } else {
1776 postAnimationCallback();
1777 }
1778 }
1779
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001780 public void overridePendingAppTransitionMultiThumb(AppTransitionAnimationSpec[] specs,
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001781 IRemoteCallback onAnimationStartedCallback, IRemoteCallback onAnimationFinishedCallback,
1782 boolean scaleUp) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001783 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001784 clear();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001785 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1786 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001787 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi43102412015-11-11 16:28:37 +01001788 if (specs != null) {
1789 for (int i = 0; i < specs.length; i++) {
1790 AppTransitionAnimationSpec spec = specs[i];
1791 if (spec != null) {
1792 mNextAppTransitionAnimationsSpecs.put(spec.taskId, spec);
1793 if (i == 0) {
1794 // In full screen mode, the transition code depends on the default spec
1795 // to be set.
1796 Rect rect = spec.rect;
1797 putDefaultNextAppTransitionCoordinates(rect.left, rect.top,
Winson Chungaa7fa012017-05-24 15:50:06 -07001798 rect.width(), rect.height(), spec.buffer);
Jorim Jaggi43102412015-11-11 16:28:37 +01001799 }
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001800 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001801 }
1802 }
1803 postAnimationCallback();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001804 mNextAppTransitionCallback = onAnimationStartedCallback;
1805 mAnimationFinishedCallback = onAnimationFinishedCallback;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001806 } else {
1807 postAnimationCallback();
1808 }
1809 }
1810
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001811 void overridePendingAppTransitionMultiThumbFuture(
1812 IAppTransitionAnimationSpecsFuture specsFuture, IRemoteCallback callback,
1813 boolean scaleUp) {
1814 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001815 clear();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001816 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1817 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001818 mNextAppTransitionAnimationsSpecsFuture = specsFuture;
1819 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001820 mNextAppTransitionFutureCallback = callback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001821 }
1822 }
1823
Winson Chung044d5292014-11-06 11:05:19 -08001824 void overrideInPlaceAppTransition(String packageName, int anim) {
1825 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001826 clear();
Winson Chung044d5292014-11-06 11:05:19 -08001827 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE;
1828 mNextAppTransitionPackage = packageName;
1829 mNextAppTransitionInPlace = anim;
1830 } else {
1831 postAnimationCallback();
1832 }
1833 }
1834
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001835 /**
1836 * If a future is set for the app transition specs, fetch it in another thread.
1837 */
1838 private void fetchAppTransitionSpecsFromFuture() {
1839 if (mNextAppTransitionAnimationsSpecsFuture != null) {
1840 mNextAppTransitionAnimationsSpecsPending = true;
1841 final IAppTransitionAnimationSpecsFuture future
1842 = mNextAppTransitionAnimationsSpecsFuture;
1843 mNextAppTransitionAnimationsSpecsFuture = null;
Jorim Jaggied410b62017-05-05 15:16:14 +02001844 mDefaultExecutor.execute(() -> {
1845 AppTransitionAnimationSpec[] specs = null;
1846 try {
1847 Binder.allowBlocking(future.asBinder());
1848 specs = future.get();
1849 } catch (RemoteException e) {
1850 Slog.w(TAG, "Failed to fetch app transition specs: " + e);
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001851 }
Jorim Jaggied410b62017-05-05 15:16:14 +02001852 synchronized (mService.mWindowMap) {
1853 mNextAppTransitionAnimationsSpecsPending = false;
1854 overridePendingAppTransitionMultiThumb(specs,
1855 mNextAppTransitionFutureCallback, null /* finishedCallback */,
1856 mNextAppTransitionScaleUp);
1857 mNextAppTransitionFutureCallback = null;
1858 if (specs != null) {
1859 mService.prolongAnimationsFromSpecs(specs, mNextAppTransitionScaleUp);
1860 }
1861 }
1862 mService.requestTraversal();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001863 });
1864 }
1865 }
1866
Craig Mautner164d4bb2012-11-26 13:51:23 -08001867 @Override
1868 public String toString() {
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001869 return "mNextAppTransition=" + appTransitionToString(mNextAppTransition);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001870 }
1871
Craig Mautner4b71aa12012-12-27 17:20:01 -08001872 /**
1873 * Returns the human readable name of a window transition.
1874 *
1875 * @param transition The window transition.
1876 * @return The transition symbolic name.
1877 */
1878 public static String appTransitionToString(int transition) {
1879 switch (transition) {
1880 case TRANSIT_UNSET: {
1881 return "TRANSIT_UNSET";
1882 }
1883 case TRANSIT_NONE: {
1884 return "TRANSIT_NONE";
1885 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001886 case TRANSIT_ACTIVITY_OPEN: {
1887 return "TRANSIT_ACTIVITY_OPEN";
1888 }
1889 case TRANSIT_ACTIVITY_CLOSE: {
1890 return "TRANSIT_ACTIVITY_CLOSE";
1891 }
1892 case TRANSIT_TASK_OPEN: {
1893 return "TRANSIT_TASK_OPEN";
1894 }
1895 case TRANSIT_TASK_CLOSE: {
1896 return "TRANSIT_TASK_CLOSE";
1897 }
1898 case TRANSIT_TASK_TO_FRONT: {
1899 return "TRANSIT_TASK_TO_FRONT";
1900 }
1901 case TRANSIT_TASK_TO_BACK: {
1902 return "TRANSIT_TASK_TO_BACK";
1903 }
1904 case TRANSIT_WALLPAPER_CLOSE: {
1905 return "TRANSIT_WALLPAPER_CLOSE";
1906 }
1907 case TRANSIT_WALLPAPER_OPEN: {
1908 return "TRANSIT_WALLPAPER_OPEN";
1909 }
1910 case TRANSIT_WALLPAPER_INTRA_OPEN: {
1911 return "TRANSIT_WALLPAPER_INTRA_OPEN";
1912 }
1913 case TRANSIT_WALLPAPER_INTRA_CLOSE: {
1914 return "TRANSIT_WALLPAPER_INTRA_CLOSE";
1915 }
Craig Mautnerbb742462014-07-07 15:28:55 -07001916 case TRANSIT_TASK_OPEN_BEHIND: {
1917 return "TRANSIT_TASK_OPEN_BEHIND";
1918 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001919 case TRANSIT_ACTIVITY_RELAUNCH: {
1920 return "TRANSIT_ACTIVITY_RELAUNCH";
1921 }
Jorim Jaggi192086e2016-03-11 17:17:03 +01001922 case TRANSIT_DOCK_TASK_FROM_RECENTS: {
1923 return "TRANSIT_DOCK_TASK_FROM_RECENTS";
1924 }
Jorim Jaggife762342016-10-13 14:33:27 +02001925 case TRANSIT_KEYGUARD_GOING_AWAY: {
1926 return "TRANSIT_KEYGUARD_GOING_AWAY";
1927 }
1928 case TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER: {
1929 return "TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER";
1930 }
1931 case TRANSIT_KEYGUARD_OCCLUDE: {
1932 return "TRANSIT_KEYGUARD_OCCLUDE";
1933 }
1934 case TRANSIT_KEYGUARD_UNOCCLUDE: {
1935 return "TRANSIT_KEYGUARD_UNOCCLUDE";
1936 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001937 default: {
1938 return "<UNKNOWN>";
1939 }
1940 }
1941 }
1942
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001943 private String appStateToString() {
1944 switch (mAppTransitionState) {
1945 case APP_STATE_IDLE:
1946 return "APP_STATE_IDLE";
1947 case APP_STATE_READY:
1948 return "APP_STATE_READY";
1949 case APP_STATE_RUNNING:
1950 return "APP_STATE_RUNNING";
1951 case APP_STATE_TIMEOUT:
1952 return "APP_STATE_TIMEOUT";
1953 default:
1954 return "unknown state=" + mAppTransitionState;
1955 }
1956 }
1957
1958 private String transitTypeToString() {
1959 switch (mNextAppTransitionType) {
1960 case NEXT_TRANSIT_TYPE_NONE:
1961 return "NEXT_TRANSIT_TYPE_NONE";
1962 case NEXT_TRANSIT_TYPE_CUSTOM:
1963 return "NEXT_TRANSIT_TYPE_CUSTOM";
Winson Chung044d5292014-11-06 11:05:19 -08001964 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
1965 return "NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001966 case NEXT_TRANSIT_TYPE_SCALE_UP:
1967 return "NEXT_TRANSIT_TYPE_SCALE_UP";
1968 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1969 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP";
1970 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
1971 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN";
Winson Chunga4ccb862014-08-22 15:26:27 -07001972 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
1973 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP";
1974 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN:
1975 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001976 default:
1977 return "unknown type=" + mNextAppTransitionType;
1978 }
1979 }
1980
Steven Timotiusaf03df62017-07-18 16:56:43 -07001981 void writeToProto(ProtoOutputStream proto, long fieldId) {
1982 final long token = proto.start(fieldId);
1983 proto.write(APP_TRANSITION_STATE, mAppTransitionState);
1984 proto.write(LAST_USED_APP_TRANSITION, mLastUsedAppTransition);
1985 proto.end(token);
1986 }
1987
Craig Mautner164d4bb2012-11-26 13:51:23 -08001988 @Override
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001989 public void dump(PrintWriter pw, String prefix) {
1990 pw.print(prefix); pw.println(this);
1991 pw.print(prefix); pw.print("mAppTransitionState="); pw.println(appStateToString());
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001992 if (mNextAppTransitionType != NEXT_TRANSIT_TYPE_NONE) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001993 pw.print(prefix); pw.print("mNextAppTransitionType=");
1994 pw.println(transitTypeToString());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001995 }
1996 switch (mNextAppTransitionType) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001997 case NEXT_TRANSIT_TYPE_CUSTOM:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001998 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001999 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002000 pw.print(prefix); pw.print("mNextAppTransitionEnter=0x");
Craig Mautner164d4bb2012-11-26 13:51:23 -08002001 pw.print(Integer.toHexString(mNextAppTransitionEnter));
2002 pw.print(" mNextAppTransitionExit=0x");
2003 pw.println(Integer.toHexString(mNextAppTransitionExit));
2004 break;
Winson Chung044d5292014-11-06 11:05:19 -08002005 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002006 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Winson Chung044d5292014-11-06 11:05:19 -08002007 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002008 pw.print(prefix); pw.print("mNextAppTransitionInPlace=0x");
Winson Chung044d5292014-11-06 11:05:19 -08002009 pw.print(Integer.toHexString(mNextAppTransitionInPlace));
2010 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002011 case NEXT_TRANSIT_TYPE_SCALE_UP: {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002012 getDefaultNextAppTransitionStartRect(mTmpRect);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002013 pw.print(prefix); pw.print("mNextAppTransitionStartX=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002014 pw.print(mTmpRect.left);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002015 pw.print(" mNextAppTransitionStartY=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002016 pw.println(mTmpRect.top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002017 pw.print(prefix); pw.print("mNextAppTransitionStartWidth=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002018 pw.print(mTmpRect.width());
Craig Mautner164d4bb2012-11-26 13:51:23 -08002019 pw.print(" mNextAppTransitionStartHeight=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002020 pw.println(mTmpRect.height());
Craig Mautner164d4bb2012-11-26 13:51:23 -08002021 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002022 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002023 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
2024 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
Winson Chunga4ccb862014-08-22 15:26:27 -07002025 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002026 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN: {
2027 pw.print(prefix); pw.print("mDefaultNextAppTransitionAnimationSpec=");
2028 pw.println(mDefaultNextAppTransitionAnimationSpec);
2029 pw.print(prefix); pw.print("mNextAppTransitionAnimationsSpecs=");
2030 pw.println(mNextAppTransitionAnimationsSpecs);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002031 pw.print(prefix); pw.print("mNextAppTransitionScaleUp=");
2032 pw.println(mNextAppTransitionScaleUp);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002033 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002034 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002035 }
2036 if (mNextAppTransitionCallback != null) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002037 pw.print(prefix); pw.print("mNextAppTransitionCallback=");
2038 pw.println(mNextAppTransitionCallback);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002039 }
Chong Zhang60091a92016-07-27 17:52:45 -07002040 if (mLastUsedAppTransition != TRANSIT_NONE) {
2041 pw.print(prefix); pw.print("mLastUsedAppTransition=");
2042 pw.println(appTransitionToString(mLastUsedAppTransition));
2043 pw.print(prefix); pw.print("mLastOpeningApp=");
2044 pw.println(mLastOpeningApp);
2045 pw.print(prefix); pw.print("mLastClosingApp=");
2046 pw.println(mLastClosingApp);
2047 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002048 }
Amith Yamasani4befbec2013-07-10 16:18:01 -07002049
2050 public void setCurrentUser(int newUserId) {
2051 mCurrentUserId = newUserId;
2052 }
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002053
2054 /**
2055 * @return true if transition is not running and should not be skipped, false if transition is
2056 * already running
2057 */
Jorim Jaggife762342016-10-13 14:33:27 +02002058 boolean prepareAppTransitionLocked(int transit, boolean alwaysKeepCurrent, int flags,
2059 boolean forceOverride) {
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002060 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Prepare app transition:"
2061 + " transit=" + appTransitionToString(transit)
2062 + " " + this
2063 + " alwaysKeepCurrent=" + alwaysKeepCurrent
2064 + " Callers=" + Debug.getCallers(3));
Jorim Jaggife762342016-10-13 14:33:27 +02002065 if (forceOverride || isKeyguardTransit(transit) || !isTransitionSet()
2066 || mNextAppTransition == TRANSIT_NONE) {
2067 setAppTransition(transit, flags);
Jorim Jaggia69243a2017-06-15 15:10:38 -04002068 }
2069 // We never want to change from a Keyguard transit to a non-Keyguard transit, as our logic
2070 // relies on the fact that we always execute a Keyguard transition after preparing one.
2071 else if (!alwaysKeepCurrent && !isKeyguardTransit(transit)) {
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002072 if (transit == TRANSIT_TASK_OPEN && isTransitionEqual(TRANSIT_TASK_CLOSE)) {
2073 // Opening a new task always supersedes a close for the anim.
Jorim Jaggife762342016-10-13 14:33:27 +02002074 setAppTransition(transit, flags);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002075 } else if (transit == TRANSIT_ACTIVITY_OPEN
2076 && isTransitionEqual(TRANSIT_ACTIVITY_CLOSE)) {
2077 // Opening a new activity always supersedes a close for the anim.
Jorim Jaggife762342016-10-13 14:33:27 +02002078 setAppTransition(transit, flags);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002079 }
2080 }
2081 boolean prepared = prepare();
2082 if (isTransitionSet()) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08002083 mService.mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
2084 mService.mH.sendEmptyMessageDelayed(H.APP_TRANSITION_TIMEOUT, APP_TRANSITION_TIMEOUT_MS);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002085 }
2086 return prepared;
2087 }
Winsonb2024762016-04-05 17:32:30 -07002088
2089 /**
Jorim Jaggife762342016-10-13 14:33:27 +02002090 * @return true if {@param transit} is representing a transition in which Keyguard is going
2091 * away, false otherwise
2092 */
2093 public static boolean isKeyguardGoingAwayTransit(int transit) {
2094 return transit == TRANSIT_KEYGUARD_GOING_AWAY
2095 || transit == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER;
2096 }
2097
2098 private static boolean isKeyguardTransit(int transit) {
2099 return isKeyguardGoingAwayTransit(transit) || transit == TRANSIT_KEYGUARD_OCCLUDE
2100 || transit == TRANSIT_KEYGUARD_UNOCCLUDE;
2101 }
2102
2103 /**
Manu Cornetd7376802017-01-13 13:44:07 -08002104 * @return whether the transition should show the thumbnail being scaled down.
2105 */
2106 private boolean shouldScaleDownThumbnailTransition(int uiMode, int orientation) {
Sid Soundararajan0e88d322017-03-07 15:37:30 -08002107 return mGridLayoutRecentsEnabled
Manu Cornetd7376802017-01-13 13:44:07 -08002108 || orientation == Configuration.ORIENTATION_PORTRAIT;
2109 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002110}