blob: d4b437a5a25e1113e6b06d7a1383b4b9c2c46c1c [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;
Filip Gruszczynski198dcbf2016-01-18 10:02:00 -080041import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
42import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080043import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
44import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Adrian Roose99bc052017-11-20 17:55:31 +010045import static com.android.server.wm.WindowManagerInternal.AppTransitionListener;
Tony Mak089c35e2017-12-18 20:34:14 +000046import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_AFTER_ANIM;
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;
Steven Timotiusaf03df62017-07-18 16:56:43 -070049import static com.android.server.wm.proto.AppTransitionProto.APP_TRANSITION_STATE;
50import static com.android.server.wm.proto.AppTransitionProto.LAST_USED_APP_TRANSITION;
Filip Gruszczynski82861362015-10-16 14:21:09 -070051
Tony Mak64b8d562017-12-28 17:44:02 +000052import android.annotation.DrawableRes;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -070053import android.annotation.Nullable;
Matthew Ng43db6d22017-06-27 15:29:39 -070054import android.app.ActivityManager;
Tony Mak089c35e2017-12-18 20:34:14 +000055import android.content.ComponentName;
Craig Mautner164d4bb2012-11-26 13:51:23 -080056import android.content.Context;
Winson21700932016-03-24 17:26:23 -070057import android.content.res.Configuration;
Tony Mak64b8d562017-12-28 17:44:02 +000058import android.graphics.Color;
Winson Chungaa7fa012017-05-24 15:50:06 -070059import android.graphics.GraphicBuffer;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +010060import android.graphics.Path;
Winson Chung399f6202014-03-19 10:47:20 -070061import android.graphics.Rect;
Tony Mak64b8d562017-12-28 17:44:02 +000062import android.graphics.drawable.Drawable;
Jorim Jaggied410b62017-05-05 15:16:14 +020063import android.os.Binder;
Craig Mautner164d4bb2012-11-26 13:51:23 -080064import android.os.Debug;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010065import android.os.IBinder;
Craig Mautner164d4bb2012-11-26 13:51:23 -080066import android.os.IRemoteCallback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010067import android.os.RemoteException;
Jorim Jaggif5f9e122017-10-24 18:21:09 +020068import android.os.SystemClock;
Manu Cornetd7376802017-01-13 13:44:07 -080069import android.os.SystemProperties;
Tony Mak089c35e2017-12-18 20:34:14 +000070import android.os.UserHandle;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -080071import android.util.ArraySet;
Craig Mautner164d4bb2012-11-26 13:51:23 -080072import android.util.Slog;
Filip Gruszczynski170192a2015-08-16 17:46:34 -070073import android.util.SparseArray;
Steven Timotiusaf03df62017-07-18 16:56:43 -070074import android.util.proto.ProtoOutputStream;
Filip Gruszczynski170192a2015-08-16 17:46:34 -070075import android.view.AppTransitionAnimationSpec;
Tony Mak64b8d562017-12-28 17:44:02 +000076import android.view.DisplayListCanvas;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010077import android.view.IAppTransitionAnimationSpecsFuture;
Tony Mak64b8d562017-12-28 17:44:02 +000078import android.view.RenderNode;
79import android.view.ThreadedRenderer;
Craig Mautner164d4bb2012-11-26 13:51:23 -080080import android.view.WindowManager;
Craig Mautner164d4bb2012-11-26 13:51:23 -080081import android.view.animation.AlphaAnimation;
82import android.view.animation.Animation;
83import android.view.animation.AnimationSet;
84import android.view.animation.AnimationUtils;
Winson Chung399f6202014-03-19 10:47:20 -070085import android.view.animation.ClipRectAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -080086import android.view.animation.Interpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070087import android.view.animation.PathInterpolator;
Craig Mautner164d4bb2012-11-26 13:51:23 -080088import android.view.animation.ScaleAnimation;
Winson Chung399f6202014-03-19 10:47:20 -070089import android.view.animation.TranslateAnimation;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070090
Craig Mautner164d4bb2012-11-26 13:51:23 -080091import com.android.internal.util.DumpUtils.Dump;
92import com.android.server.AttributeCache;
93import com.android.server.wm.WindowManagerService.H;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -080094import com.android.server.wm.animation.ClipRectLRAnimation;
95import com.android.server.wm.animation.ClipRectTBAnimation;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +010096import com.android.server.wm.animation.CurvedTranslateAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -080097
98import java.io.PrintWriter;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010099import java.util.ArrayList;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100100import java.util.concurrent.ExecutorService;
101import java.util.concurrent.Executors;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800102
Craig Mautner164d4bb2012-11-26 13:51:23 -0800103// State management of app transitions. When we are preparing for a
104// transition, mNextAppTransition will be the kind of transition to
105// perform or TRANSIT_NONE if we are not waiting. If we are waiting,
106// mOpeningApps and mClosingApps are the lists of tokens that will be
107// made visible or hidden at the next transition.
108public class AppTransition implements Dump {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800109 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppTransition" : TAG_WM;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700110 private static final int CLIP_REVEAL_TRANSLATION_Y_DP = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800111
Craig Mautner4b71aa12012-12-27 17:20:01 -0800112 /** Not set up for a transition. */
113 public static final int TRANSIT_UNSET = -1;
114 /** No animation for transition. */
115 public static final int TRANSIT_NONE = 0;
116 /** 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 -0700117 public static final int TRANSIT_ACTIVITY_OPEN = 6;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800118 /** The window in the top-most activity is being closed to reveal the
119 * previous activity in the same task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700120 public static final int TRANSIT_ACTIVITY_CLOSE = 7;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800121 /** A window in a new task is being opened on top of an existing one
122 * in another activity's task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700123 public static final int TRANSIT_TASK_OPEN = 8;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800124 /** A window in the top-most activity is being closed to reveal the
125 * previous activity in a different task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700126 public static final int TRANSIT_TASK_CLOSE = 9;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800127 /** A window in an existing task is being displayed on top of an existing one
128 * in another activity's task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700129 public static final int TRANSIT_TASK_TO_FRONT = 10;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800130 /** A window in an existing task is being put below all other tasks. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700131 public static final int TRANSIT_TASK_TO_BACK = 11;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800132 /** A window in a new activity that doesn't have a wallpaper is being opened on top of one that
133 * does, effectively closing the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700134 public static final int TRANSIT_WALLPAPER_CLOSE = 12;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800135 /** A window in a new activity that does have a wallpaper is being opened on one that didn't,
136 * effectively opening the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700137 public static final int TRANSIT_WALLPAPER_OPEN = 13;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800138 /** A window in a new activity is being opened on top of an existing one, and both are on top
139 * of the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700140 public static final int TRANSIT_WALLPAPER_INTRA_OPEN = 14;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800141 /** The window in the top-most activity is being closed to reveal the previous activity, and
142 * both are on top of the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700143 public static final int TRANSIT_WALLPAPER_INTRA_CLOSE = 15;
144 /** A window in a new task is being opened behind an existing one in another activity's task.
145 * The new window will show briefly and then be gone. */
146 public static final int TRANSIT_TASK_OPEN_BEHIND = 16;
Winson Chung044d5292014-11-06 11:05:19 -0800147 /** A window in a task is being animated in-place. */
148 public static final int TRANSIT_TASK_IN_PLACE = 17;
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700149 /** An activity is being relaunched (e.g. due to configuration change). */
150 public static final int TRANSIT_ACTIVITY_RELAUNCH = 18;
Jorim Jaggi192086e2016-03-11 17:17:03 +0100151 /** A task is being docked from recents. */
152 public static final int TRANSIT_DOCK_TASK_FROM_RECENTS = 19;
Jorim Jaggife762342016-10-13 14:33:27 +0200153 /** Keyguard is going away */
154 public static final int TRANSIT_KEYGUARD_GOING_AWAY = 20;
155 /** Keyguard is going away with showing an activity behind that requests wallpaper */
156 public static final int TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER = 21;
157 /** Keyguard is being occluded */
158 public static final int TRANSIT_KEYGUARD_OCCLUDE = 22;
159 /** Keyguard is being unoccluded */
160 public static final int TRANSIT_KEYGUARD_UNOCCLUDE = 23;
161
162 /** Transition flag: Keyguard is going away, but keeping the notification shade open */
163 public static final int TRANSIT_FLAG_KEYGUARD_GOING_AWAY_TO_SHADE = 0x1;
164 /** Transition flag: Keyguard is going away, but doesn't want an animation for it */
165 public static final int TRANSIT_FLAG_KEYGUARD_GOING_AWAY_NO_ANIMATION = 0x2;
166 /** Transition flag: Keyguard is going away while it was showing the system wallpaper. */
167 public static final int TRANSIT_FLAG_KEYGUARD_GOING_AWAY_WITH_WALLPAPER = 0x4;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800168
Winson Chunga4ccb862014-08-22 15:26:27 -0700169 /** Fraction of animation at which the recents thumbnail stays completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700170 private static final float RECENTS_THUMBNAIL_FADEIN_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800171 /** Fraction of animation at which the recents thumbnail becomes completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700172 private static final float RECENTS_THUMBNAIL_FADEOUT_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800173
Filip Gruszczynski84fa3352016-01-25 16:28:49 -0800174 static final int DEFAULT_APP_TRANSITION_DURATION = 336;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800175
176 /** Interpolator to be used for animations that respond directly to a touch */
177 static final Interpolator TOUCH_RESPONSE_INTERPOLATOR =
178 new PathInterpolator(0.3f, 0f, 0.1f, 1f);
179
Jorim Jaggic69bd222016-03-15 14:38:37 +0100180 private static final Interpolator THUMBNAIL_DOCK_INTERPOLATOR =
181 new PathInterpolator(0.85f, 0f, 1f, 1f);
182
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800183 /**
184 * Maximum duration for the clip reveal animation. This is used when there is a lot of movement
185 * involved, to make it more understandable.
186 */
187 private static final int MAX_CLIP_REVEAL_TRANSITION_DURATION = 420;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700188 private static final int THUMBNAIL_APP_TRANSITION_DURATION = 336;
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700189 private static final long APP_TRANSITION_TIMEOUT_MS = 5000;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800190
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800191 private final Context mContext;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800192 private final WindowManagerService mService;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800193
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800194 private int mNextAppTransition = TRANSIT_UNSET;
Jorim Jaggife762342016-10-13 14:33:27 +0200195 private int mNextAppTransitionFlags = 0;
Chong Zhang60091a92016-07-27 17:52:45 -0700196 private int mLastUsedAppTransition = TRANSIT_UNSET;
197 private String mLastOpeningApp;
198 private String mLastClosingApp;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800199
200 private static final int NEXT_TRANSIT_TYPE_NONE = 0;
201 private static final int NEXT_TRANSIT_TYPE_CUSTOM = 1;
202 private static final int NEXT_TRANSIT_TYPE_SCALE_UP = 2;
203 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP = 3;
204 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN = 4;
Winson Chunga4ccb862014-08-22 15:26:27 -0700205 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP = 5;
206 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN = 6;
Winson Chung044d5292014-11-06 11:05:19 -0800207 private static final int NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE = 7;
Chet Haase10e23ab2015-02-11 15:08:38 -0800208 private static final int NEXT_TRANSIT_TYPE_CLIP_REVEAL = 8;
Tony Mak089c35e2017-12-18 20:34:14 +0000209
210 /**
211 * Refers to the transition to activity started by using {@link
212 * android.content.pm.crossprofile.CrossProfileApps#startMainActivity(ComponentName, UserHandle)
213 * }.
214 */
215 private static final int NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS = 9;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800216 private int mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
217
Winson Chung399f6202014-03-19 10:47:20 -0700218 // These are the possible states for the enter/exit activities during a thumbnail transition
219 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_UP = 0;
220 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_UP = 1;
221 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN = 2;
222 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN = 3;
223
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800224 private String mNextAppTransitionPackage;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800225 // Used for thumbnail transitions. True if we're scaling up, false if scaling down
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800226 private boolean mNextAppTransitionScaleUp;
227 private IRemoteCallback mNextAppTransitionCallback;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +0100228 private IRemoteCallback mNextAppTransitionFutureCallback;
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -0700229 private IRemoteCallback mAnimationFinishedCallback;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800230 private int mNextAppTransitionEnter;
231 private int mNextAppTransitionExit;
Winson Chung044d5292014-11-06 11:05:19 -0800232 private int mNextAppTransitionInPlace;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700233
234 // Keyed by task id.
235 private final SparseArray<AppTransitionAnimationSpec> mNextAppTransitionAnimationsSpecs
236 = new SparseArray<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100237 private IAppTransitionAnimationSpecsFuture mNextAppTransitionAnimationsSpecsFuture;
238 private boolean mNextAppTransitionAnimationsSpecsPending;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700239 private AppTransitionAnimationSpec mDefaultNextAppTransitionAnimationSpec;
240
Winson Chunga4ccb862014-08-22 15:26:27 -0700241 private Rect mNextAppTransitionInsets = new Rect();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800242
Winson Chung2820c452014-04-15 15:34:44 -0700243 private Rect mTmpFromClipRect = new Rect();
244 private Rect mTmpToClipRect = new Rect();
245
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700246 private final Rect mTmpRect = new Rect();
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700247
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800248 private final static int APP_STATE_IDLE = 0;
249 private final static int APP_STATE_READY = 1;
250 private final static int APP_STATE_RUNNING = 2;
251 private final static int APP_STATE_TIMEOUT = 3;
252 private int mAppTransitionState = APP_STATE_IDLE;
253
254 private final int mConfigShortAnimTime;
Craig Mautner321bdf52012-12-18 09:53:24 -0800255 private final Interpolator mDecelerateInterpolator;
Winson Chunga4ccb862014-08-22 15:26:27 -0700256 private final Interpolator mThumbnailFadeInInterpolator;
257 private final Interpolator mThumbnailFadeOutInterpolator;
Chet Haase10e23ab2015-02-11 15:08:38 -0800258 private final Interpolator mLinearOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700259 private final Interpolator mFastOutLinearInInterpolator;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100260 private final Interpolator mFastOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700261 private final Interpolator mClipHorizontalInterpolator = new PathInterpolator(0, 0, 0.4f, 1f);
262
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700263 private final int mClipRevealTranslationY;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800264
Amith Yamasani4befbec2013-07-10 16:18:01 -0700265 private int mCurrentUserId = 0;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800266 private long mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Amith Yamasani4befbec2013-07-10 16:18:01 -0700267
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100268 private final ArrayList<AppTransitionListener> mListeners = new ArrayList<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100269 private final ExecutorService mDefaultExecutor = Executors.newSingleThreadExecutor();
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100270
Jorim Jaggif97ed922016-02-18 18:57:07 -0800271 private int mLastClipRevealMaxTranslation;
272 private boolean mLastHadClipReveal;
Jorim Jaggi363ab982016-04-26 19:51:20 -0700273 private boolean mProlongedAnimationsEnded;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800274
Manu Cornetd7376802017-01-13 13:44:07 -0800275 private final boolean mGridLayoutRecentsEnabled;
Matthew Ng43db6d22017-06-27 15:29:39 -0700276 private final boolean mLowRamRecentsEnabled;
Manu Cornetd7376802017-01-13 13:44:07 -0800277
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800278 AppTransition(Context context, WindowManagerService service) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800279 mContext = context;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800280 mService = service;
Chet Haase10e23ab2015-02-11 15:08:38 -0800281 mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
282 com.android.internal.R.interpolator.linear_out_slow_in);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700283 mFastOutLinearInInterpolator = AnimationUtils.loadInterpolator(context,
284 com.android.internal.R.interpolator.fast_out_linear_in);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100285 mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
286 com.android.internal.R.interpolator.fast_out_slow_in);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800287 mConfigShortAnimTime = context.getResources().getInteger(
288 com.android.internal.R.integer.config_shortAnimTime);
Craig Mautner321bdf52012-12-18 09:53:24 -0800289 mDecelerateInterpolator = AnimationUtils.loadInterpolator(context,
290 com.android.internal.R.interpolator.decelerate_cubic);
Winson Chunga4ccb862014-08-22 15:26:27 -0700291 mThumbnailFadeInInterpolator = new Interpolator() {
292 @Override
293 public float getInterpolation(float input) {
294 // Linear response for first fraction, then complete after that.
295 if (input < RECENTS_THUMBNAIL_FADEIN_FRACTION) {
296 return 0f;
297 }
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700298 float t = (input - RECENTS_THUMBNAIL_FADEIN_FRACTION) /
Winson Chunga4ccb862014-08-22 15:26:27 -0700299 (1f - RECENTS_THUMBNAIL_FADEIN_FRACTION);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700300 return mFastOutLinearInInterpolator.getInterpolation(t);
Winson Chunga4ccb862014-08-22 15:26:27 -0700301 }
302 };
303 mThumbnailFadeOutInterpolator = new Interpolator() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800304 @Override
305 public float getInterpolation(float input) {
306 // Linear response for first fraction, then complete after that.
307 if (input < RECENTS_THUMBNAIL_FADEOUT_FRACTION) {
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700308 float t = input / RECENTS_THUMBNAIL_FADEOUT_FRACTION;
309 return mLinearOutSlowInInterpolator.getInterpolation(t);
Craig Mautner321bdf52012-12-18 09:53:24 -0800310 }
Winson Chunga4ccb862014-08-22 15:26:27 -0700311 return 1f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800312 }
313 };
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700314 mClipRevealTranslationY = (int) (CLIP_REVEAL_TRANSLATION_Y_DP
315 * mContext.getResources().getDisplayMetrics().density);
Manu Cornetd7376802017-01-13 13:44:07 -0800316 mGridLayoutRecentsEnabled = SystemProperties.getBoolean("ro.recents.grid", false);
Matthew Ng43db6d22017-06-27 15:29:39 -0700317 mLowRamRecentsEnabled = ActivityManager.isLowRamDeviceStatic();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800318 }
319
320 boolean isTransitionSet() {
321 return mNextAppTransition != TRANSIT_UNSET;
322 }
323
Craig Mautner164d4bb2012-11-26 13:51:23 -0800324 boolean isTransitionEqual(int transit) {
325 return mNextAppTransition == transit;
326 }
327
328 int getAppTransition() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800329 return mNextAppTransition;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800330 }
331
Jorim Jaggife762342016-10-13 14:33:27 +0200332 private void setAppTransition(int transit, int flags) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800333 mNextAppTransition = transit;
Jorim Jaggife762342016-10-13 14:33:27 +0200334 mNextAppTransitionFlags |= flags;
Chong Zhang60091a92016-07-27 17:52:45 -0700335 setLastAppTransition(TRANSIT_UNSET, null, null);
Jorim Jaggi245281c2017-06-07 14:33:04 -0700336 updateBooster();
Chong Zhang60091a92016-07-27 17:52:45 -0700337 }
338
339 void setLastAppTransition(int transit, AppWindowToken openingApp, AppWindowToken closingApp) {
340 mLastUsedAppTransition = transit;
341 mLastOpeningApp = "" + openingApp;
342 mLastClosingApp = "" + closingApp;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800343 }
344
345 boolean isReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800346 return mAppTransitionState == APP_STATE_READY
347 || mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800348 }
349
Craig Mautnerae446592012-12-06 19:05:05 -0800350 void setReady() {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700351 setAppTransitionState(APP_STATE_READY);
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100352 fetchAppTransitionSpecsFromFuture();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800353 }
354
355 boolean isRunning() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800356 return mAppTransitionState == APP_STATE_RUNNING;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800357 }
358
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800359 void setIdle() {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700360 setAppTransitionState(APP_STATE_IDLE);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800361 }
362
363 boolean isTimeout() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800364 return mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800365 }
366
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800367 void setTimeout() {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700368 setAppTransitionState(APP_STATE_TIMEOUT);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800369 }
370
Winson Chungaa7fa012017-05-24 15:50:06 -0700371 GraphicBuffer getAppTransitionThumbnailHeader(int taskId) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700372 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800373 if (spec == null) {
374 spec = mDefaultNextAppTransitionAnimationSpec;
375 }
Winson Chungaa7fa012017-05-24 15:50:06 -0700376 return spec != null ? spec.buffer : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800377 }
378
Winson Chunga4ccb862014-08-22 15:26:27 -0700379 /** Returns whether the next thumbnail transition is aspect scaled up. */
380 boolean isNextThumbnailTransitionAspectScaled() {
381 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
382 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
383 }
384
385 /** Returns whether the next thumbnail transition is scaling up. */
386 boolean isNextThumbnailTransitionScaleUp() {
387 return mNextAppTransitionScaleUp;
388 }
389
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -0800390 boolean isNextAppTransitionThumbnailUp() {
391 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
392 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP;
393 }
394
395 boolean isNextAppTransitionThumbnailDown() {
396 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN ||
397 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
398 }
399
Tony Mak64b8d562017-12-28 17:44:02 +0000400
401 boolean isNextAppTransitionOpenCrossProfileApps() {
402 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS;
403 }
404
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100405 /**
406 * @return true if and only if we are currently fetching app transition specs from the future
407 * passed into {@link #overridePendingAppTransitionMultiThumbFuture}
408 */
409 boolean isFetchingAppTransitionsSpecs() {
410 return mNextAppTransitionAnimationsSpecsPending;
411 }
412
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700413 private boolean prepare() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800414 if (!isRunning()) {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700415 setAppTransitionState(APP_STATE_IDLE);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100416 notifyAppTransitionPendingLocked();
Jorim Jaggif97ed922016-02-18 18:57:07 -0800417 mLastHadClipReveal = false;
418 mLastClipRevealMaxTranslation = 0;
419 mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700420 return true;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800421 }
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700422 return false;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800423 }
424
Jorim Jaggife762342016-10-13 14:33:27 +0200425 /**
426 * @return bit-map of WindowManagerPolicy#FINISH_LAYOUT_REDO_* to indicate whether another
427 * layout pass needs to be done
428 */
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200429 int goodToGo(int transit, AppWindowToken topOpeningApp,
430 AppWindowToken topClosingApp, ArraySet<AppWindowToken> openingApps,
Jorim Jaggife762342016-10-13 14:33:27 +0200431 ArraySet<AppWindowToken> closingApps) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800432 mNextAppTransition = TRANSIT_UNSET;
Jorim Jaggife762342016-10-13 14:33:27 +0200433 mNextAppTransitionFlags = 0;
Jorim Jaggi245281c2017-06-07 14:33:04 -0700434 setAppTransitionState(APP_STATE_RUNNING);
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200435 final AnimationAdapter topOpeningAnim = topOpeningApp != null
436 ? topOpeningApp.getAnimation()
437 : null;
Jorim Jaggife762342016-10-13 14:33:27 +0200438 int redoLayout = notifyAppTransitionStartingLocked(transit,
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200439 topOpeningApp != null ? topOpeningApp.token : null,
440 topClosingApp != null ? topClosingApp.token : null,
441 topOpeningAnim != null ? topOpeningAnim.getDurationHint() : 0,
442 topOpeningAnim != null
443 ? topOpeningAnim.getStatusBarTransitionsStartTime()
444 : SystemClock.uptimeMillis(),
445 AnimationAdapter.STATUS_BAR_TRANSITION_DURATION);
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800446 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Jorim Jaggife762342016-10-13 14:33:27 +0200447 .notifyAppTransitionStarting(openingApps, transit);
Jorim Jaggi363ab982016-04-26 19:51:20 -0700448
449 // Prolong the start for the transition when docking a task from recents, unless recents
450 // ended it already then we don't need to wait.
Jorim Jaggife762342016-10-13 14:33:27 +0200451 if (transit == TRANSIT_DOCK_TASK_FROM_RECENTS && !mProlongedAnimationsEnded) {
Jorim Jaggi363ab982016-04-26 19:51:20 -0700452 for (int i = openingApps.size() - 1; i >= 0; i--) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200453 final AppWindowToken app = openingApps.valueAt(i);
454 app.startDelayingAnimationStart();
Jorim Jaggi363ab982016-04-26 19:51:20 -0700455 }
456 }
Jorim Jaggife762342016-10-13 14:33:27 +0200457 return redoLayout;
Jorim Jaggi363ab982016-04-26 19:51:20 -0700458 }
459
460 /**
461 * Let the transitions manager know that the somebody wanted to end the prolonged animations.
462 */
463 void notifyProlongedAnimationsEnded() {
464 mProlongedAnimationsEnded = true;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800465 }
466
467 void clear() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800468 mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800469 mNextAppTransitionPackage = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700470 mNextAppTransitionAnimationsSpecs.clear();
Jorim Jaggi65193992015-11-23 16:49:59 -0800471 mNextAppTransitionAnimationsSpecsFuture = null;
472 mDefaultNextAppTransitionAnimationSpec = null;
473 mAnimationFinishedCallback = null;
Jorim Jaggi363ab982016-04-26 19:51:20 -0700474 mProlongedAnimationsEnded = false;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800475 }
476
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800477 void freeze() {
Jorim Jaggife762342016-10-13 14:33:27 +0200478 final int transit = mNextAppTransition;
479 setAppTransition(AppTransition.TRANSIT_UNSET, 0 /* flags */);
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800480 clear();
481 setReady();
Jorim Jaggife762342016-10-13 14:33:27 +0200482 notifyAppTransitionCancelledLocked(transit);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100483 }
484
Jorim Jaggi245281c2017-06-07 14:33:04 -0700485 private void setAppTransitionState(int state) {
486 mAppTransitionState = state;
487 updateBooster();
488 }
489
490 /**
491 * Updates whether we currently boost wm locked sections and the animation thread. We want to
492 * boost the priorities to a more important value whenever an app transition is going to happen
493 * soon or an app transition is running.
494 */
495 private void updateBooster() {
496 WindowManagerService.sThreadPriorityBooster.setAppTransitionRunning(
497 mNextAppTransition != TRANSIT_UNSET || mAppTransitionState == APP_STATE_READY
498 || mAppTransitionState == APP_STATE_RUNNING);
499 }
500
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100501 void registerListenerLocked(AppTransitionListener listener) {
502 mListeners.add(listener);
503 }
504
Wale Ogunwalea48eadb2015-05-14 17:43:12 -0700505 public void notifyAppTransitionFinishedLocked(IBinder token) {
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100506 for (int i = 0; i < mListeners.size(); i++) {
507 mListeners.get(i).onAppTransitionFinishedLocked(token);
508 }
509 }
510
511 private void notifyAppTransitionPendingLocked() {
512 for (int i = 0; i < mListeners.size(); i++) {
513 mListeners.get(i).onAppTransitionPendingLocked();
514 }
515 }
516
Jorim Jaggife762342016-10-13 14:33:27 +0200517 private void notifyAppTransitionCancelledLocked(int transit) {
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100518 for (int i = 0; i < mListeners.size(); i++) {
Jorim Jaggife762342016-10-13 14:33:27 +0200519 mListeners.get(i).onAppTransitionCancelledLocked(transit);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100520 }
521 }
522
Jorim Jaggife762342016-10-13 14:33:27 +0200523 private int notifyAppTransitionStartingLocked(int transit, IBinder openToken,
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200524 IBinder closeToken, long duration, long statusBarAnimationStartTime,
525 long statusBarAnimationDuration) {
Jorim Jaggife762342016-10-13 14:33:27 +0200526 int redoLayout = 0;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100527 for (int i = 0; i < mListeners.size(); i++) {
Jorim Jaggife762342016-10-13 14:33:27 +0200528 redoLayout |= mListeners.get(i).onAppTransitionStartingLocked(transit, openToken,
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200529 closeToken, duration, statusBarAnimationStartTime, statusBarAnimationDuration);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100530 }
Jorim Jaggife762342016-10-13 14:33:27 +0200531 return redoLayout;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800532 }
533
Craig Mautner164d4bb2012-11-26 13:51:23 -0800534 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
535 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg="
536 + (lp != null ? lp.packageName : null)
537 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
538 if (lp != null && lp.windowAnimations != 0) {
539 // If this is a system resource, don't try to load it from the
540 // application resources. It is nice to avoid loading application
541 // resources if we can.
542 String packageName = lp.packageName != null ? lp.packageName : "android";
543 int resId = lp.windowAnimations;
544 if ((resId&0xFF000000) == 0x01000000) {
545 packageName = "android";
546 }
547 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
548 + packageName);
549 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700550 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800551 }
552 return null;
553 }
554
555 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
556 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package="
557 + packageName + " resId=0x" + Integer.toHexString(resId));
558 if (packageName != null) {
559 if ((resId&0xFF000000) == 0x01000000) {
560 packageName = "android";
561 }
562 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
563 + packageName);
564 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700565 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800566 }
567 return null;
568 }
569
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700570 Animation loadAnimationAttr(WindowManager.LayoutParams lp, int animAttr) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800571 int anim = 0;
572 Context context = mContext;
573 if (animAttr >= 0) {
574 AttributeCache.Entry ent = getCachedAnimations(lp);
575 if (ent != null) {
576 context = ent.context;
577 anim = ent.array.getResourceId(animAttr, 0);
578 }
579 }
580 if (anim != 0) {
581 return AnimationUtils.loadAnimation(context, anim);
582 }
583 return null;
584 }
585
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700586 Animation loadAnimationRes(WindowManager.LayoutParams lp, int resId) {
587 Context context = mContext;
588 if (resId >= 0) {
589 AttributeCache.Entry ent = getCachedAnimations(lp);
590 if (ent != null) {
591 context = ent.context;
592 }
593 return AnimationUtils.loadAnimation(context, resId);
594 }
595 return null;
596 }
597
598 private Animation loadAnimationRes(String packageName, int resId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800599 int anim = 0;
600 Context context = mContext;
601 if (resId >= 0) {
602 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
603 if (ent != null) {
604 context = ent.context;
605 anim = resId;
606 }
607 }
608 if (anim != 0) {
609 return AnimationUtils.loadAnimation(context, anim);
610 }
611 return null;
612 }
613
Craig Mautner164d4bb2012-11-26 13:51:23 -0800614 /**
615 * Compute the pivot point for an animation that is scaling from a small
616 * rect on screen to a larger rect. The pivot point varies depending on
617 * the distance between the inner and outer edges on both sides. This
618 * function computes the pivot point for one dimension.
619 * @param startPos Offset from left/top edge of outer rectangle to
620 * left/top edge of inner rectangle.
621 * @param finalScale The scaling factor between the size of the outer
622 * and inner rectangles.
623 */
624 private static float computePivot(int startPos, float finalScale) {
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800625
626 /*
627 Theorem of intercepting lines:
628
629 + + +-----------------------------------------------+
630 | | | |
631 | | | |
632 | | | |
633 | | | |
634 x | y | | |
635 | | | |
636 | | | |
637 | | | |
638 | | | |
639 | + | +--------------------+ |
640 | | | | |
641 | | | | |
642 | | | | |
643 | | | | |
644 | | | | |
645 | | | | |
646 | | | | |
647 | | | | |
648 | | | | |
649 | | | | |
650 | | | | |
651 | | | | |
652 | | | | |
653 | | | | |
654 | | | | |
655 | | | | |
656 | | | | |
657 | | +--------------------+ |
658 | | |
659 | | |
660 | | |
661 | | |
662 | | |
663 | | |
664 | | |
665 | +-----------------------------------------------+
666 |
667 |
668 |
669 |
670 |
671 |
672 |
673 |
674 |
675 + ++
676 p ++
677
678 scale = (x - y) / x
679 <=> x = -y / (scale - 1)
680 */
Craig Mautner164d4bb2012-11-26 13:51:23 -0800681 final float denom = finalScale-1;
682 if (Math.abs(denom) < .0001f) {
683 return startPos;
684 }
685 return -startPos / denom;
686 }
687
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700688 private Animation createScaleUpAnimationLocked(int transit, boolean enter,
689 Rect containingFrame) {
690 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700691 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700692 final int appWidth = containingFrame.width();
693 final int appHeight = containingFrame.height();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800694 if (enter) {
695 // Entering app zooms out from the center of the initial rect.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700696 float scaleW = mTmpRect.width() / (float) appWidth;
697 float scaleH = mTmpRect.height() / (float) appHeight;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800698 Animation scale = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700699 computePivot(mTmpRect.left, scaleW),
Winson4c3fecd2016-07-13 12:29:48 -0700700 computePivot(mTmpRect.top, scaleH));
Craig Mautner321bdf52012-12-18 09:53:24 -0800701 scale.setInterpolator(mDecelerateInterpolator);
702
Craig Mautner164d4bb2012-11-26 13:51:23 -0800703 Animation alpha = new AlphaAnimation(0, 1);
Winson Chunga4ccb862014-08-22 15:26:27 -0700704 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
Craig Mautner321bdf52012-12-18 09:53:24 -0800705
706 AnimationSet set = new AnimationSet(false);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800707 set.addAnimation(scale);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800708 set.addAnimation(alpha);
709 set.setDetachWallpaper(true);
710 a = set;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800711 } else if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
712 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800713 // If we are on top of the wallpaper, we need an animation that
714 // correctly handles the wallpaper staying static behind all of
715 // the animated elements. To do this, will just have the existing
716 // element fade out.
717 a = new AlphaAnimation(1, 0);
718 a.setDetachWallpaper(true);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800719 } else {
Craig Mautner321bdf52012-12-18 09:53:24 -0800720 // For normal animations, the exiting element just holds in place.
721 a = new AlphaAnimation(1, 1);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800722 }
Craig Mautner321bdf52012-12-18 09:53:24 -0800723
724 // Pick the desired duration. If this is an inter-activity transition,
725 // it is the standard duration for that. Otherwise we use the longer
726 // task transition duration.
727 final long duration;
728 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800729 case TRANSIT_ACTIVITY_OPEN:
730 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800731 duration = mConfigShortAnimTime;
732 break;
733 default:
734 duration = DEFAULT_APP_TRANSITION_DURATION;
735 break;
736 }
737 a.setDuration(duration);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800738 a.setFillAfter(true);
Craig Mautner321bdf52012-12-18 09:53:24 -0800739 a.setInterpolator(mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800740 a.initialize(appWidth, appHeight, appWidth, appHeight);
741 return a;
742 }
743
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700744 private void getDefaultNextAppTransitionStartRect(Rect rect) {
745 if (mDefaultNextAppTransitionAnimationSpec == null ||
746 mDefaultNextAppTransitionAnimationSpec.rect == null) {
Jorim Jaggi2550f3f2017-03-14 20:15:59 +0100747 Slog.e(TAG, "Starting rect for app requested, but none available", new Throwable());
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700748 rect.setEmpty();
749 } else {
750 rect.set(mDefaultNextAppTransitionAnimationSpec.rect);
751 }
752 }
753
754 void getNextAppTransitionStartRect(int taskId, Rect rect) {
755 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800756 if (spec == null) {
757 spec = mDefaultNextAppTransitionAnimationSpec;
758 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700759 if (spec == null || spec.rect == null) {
Jorim Jaggi2550f3f2017-03-14 20:15:59 +0100760 Slog.e(TAG, "Starting rect for task: " + taskId + " requested, but not available",
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700761 new Throwable());
762 rect.setEmpty();
763 } else {
764 rect.set(spec.rect);
765 }
766 }
767
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800768 private void putDefaultNextAppTransitionCoordinates(int left, int top, int width, int height,
Winson Chungaa7fa012017-05-24 15:50:06 -0700769 GraphicBuffer buffer) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700770 mDefaultNextAppTransitionAnimationSpec = new AppTransitionAnimationSpec(-1 /* taskId */,
Winson Chungaa7fa012017-05-24 15:50:06 -0700771 buffer, new Rect(left, top, left + width, top + height));
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700772 }
773
Jorim Jaggif97ed922016-02-18 18:57:07 -0800774 /**
775 * @return the duration of the last clip reveal animation
776 */
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800777 long getLastClipRevealTransitionDuration() {
778 return mLastClipRevealTransitionDuration;
779 }
780
781 /**
Jorim Jaggif97ed922016-02-18 18:57:07 -0800782 * @return the maximum distance the app surface is traveling of the last clip reveal animation
783 */
784 int getLastClipRevealMaxTranslation() {
785 return mLastClipRevealMaxTranslation;
786 }
787
788 /**
789 * @return true if in the last app transition had a clip reveal animation, false otherwise
790 */
791 boolean hadClipRevealAnimation() {
792 return mLastHadClipReveal;
793 }
794
795 /**
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800796 * Calculates the duration for the clip reveal animation. If the clip is "cut off", meaning that
797 * the start rect is outside of the target rect, and there is a lot of movement going on.
798 *
799 * @param cutOff whether the start rect was not fully contained by the end rect
800 * @param translationX the total translation the surface moves in x direction
801 * @param translationY the total translation the surfaces moves in y direction
802 * @param displayFrame our display frame
803 *
804 * @return the duration of the clip reveal animation, in milliseconds
805 */
806 private long calculateClipRevealTransitionDuration(boolean cutOff, float translationX,
807 float translationY, Rect displayFrame) {
808 if (!cutOff) {
809 return DEFAULT_APP_TRANSITION_DURATION;
810 }
811 final float fraction = Math.max(Math.abs(translationX) / displayFrame.width(),
812 Math.abs(translationY) / displayFrame.height());
813 return (long) (DEFAULT_APP_TRANSITION_DURATION + fraction *
814 (MAX_CLIP_REVEAL_TRANSITION_DURATION - DEFAULT_APP_TRANSITION_DURATION));
815 }
816
817 private Animation createClipRevealAnimationLocked(int transit, boolean enter, Rect appFrame,
818 Rect displayFrame) {
Chet Haase10e23ab2015-02-11 15:08:38 -0800819 final Animation anim;
820 if (enter) {
Craig Mautner80b1f642015-04-22 10:59:09 -0700821 final int appWidth = appFrame.width();
822 final int appHeight = appFrame.height();
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800823
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700824 // mTmpRect will contain an area around the launcher icon that was pressed. We will
Filip Gruszczynski82861362015-10-16 14:21:09 -0700825 // clip reveal from that area in the final area of the app.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700826 getDefaultNextAppTransitionStartRect(mTmpRect);
Craig Mautner80b1f642015-04-22 10:59:09 -0700827
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700828 float t = 0f;
829 if (appHeight > 0) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800830 t = (float) mTmpRect.top / displayFrame.height();
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700831 }
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800832 int translationY = mClipRevealTranslationY + (int)(displayFrame.height() / 7f * t);
833 int translationX = 0;
834 int translationYCorrection = translationY;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700835 int centerX = mTmpRect.centerX();
836 int centerY = mTmpRect.centerY();
837 int halfWidth = mTmpRect.width() / 2;
838 int halfHeight = mTmpRect.height() / 2;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800839 int clipStartX = centerX - halfWidth - appFrame.left;
840 int clipStartY = centerY - halfHeight - appFrame.top;
841 boolean cutOff = false;
842
843 // If the starting rectangle is fully or partially outside of the target rectangle, we
844 // need to start the clipping at the edge and then achieve the rest with translation
845 // and extending the clip rect from that edge.
846 if (appFrame.top > centerY - halfHeight) {
847 translationY = (centerY - halfHeight) - appFrame.top;
848 translationYCorrection = 0;
849 clipStartY = 0;
850 cutOff = true;
851 }
852 if (appFrame.left > centerX - halfWidth) {
853 translationX = (centerX - halfWidth) - appFrame.left;
854 clipStartX = 0;
855 cutOff = true;
856 }
857 if (appFrame.right < centerX + halfWidth) {
858 translationX = (centerX + halfWidth) - appFrame.right;
859 clipStartX = appWidth - mTmpRect.width();
860 cutOff = true;
861 }
862 final long duration = calculateClipRevealTransitionDuration(cutOff, translationX,
863 translationY, displayFrame);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700864
865 // Clip third of the from size of launch icon, expand to full width/height
Chet Haase10e23ab2015-02-11 15:08:38 -0800866 Animation clipAnimLR = new ClipRectLRAnimation(
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800867 clipStartX, clipStartX + mTmpRect.width(), 0, appWidth);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700868 clipAnimLR.setInterpolator(mClipHorizontalInterpolator);
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800869 clipAnimLR.setDuration((long) (duration / 2.5f));
Filip Gruszczynski82861362015-10-16 14:21:09 -0700870
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800871 TranslateAnimation translate = new TranslateAnimation(translationX, 0, translationY, 0);
872 translate.setInterpolator(cutOff ? TOUCH_RESPONSE_INTERPOLATOR
873 : mLinearOutSlowInInterpolator);
874 translate.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800875
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800876 Animation clipAnimTB = new ClipRectTBAnimation(
877 clipStartY, clipStartY + mTmpRect.height(),
878 0, appHeight,
879 translationYCorrection, 0,
880 mLinearOutSlowInInterpolator);
881 clipAnimTB.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
882 clipAnimTB.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800883
884 // Quick fade-in from icon to app window
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800885 final long alphaDuration = duration / 4;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700886 AlphaAnimation alpha = new AlphaAnimation(0.5f, 1);
Chet Haase10e23ab2015-02-11 15:08:38 -0800887 alpha.setDuration(alphaDuration);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700888 alpha.setInterpolator(mLinearOutSlowInInterpolator);
Chet Haase10e23ab2015-02-11 15:08:38 -0800889
890 AnimationSet set = new AnimationSet(false);
891 set.addAnimation(clipAnimLR);
892 set.addAnimation(clipAnimTB);
Filip Gruszczynski82861362015-10-16 14:21:09 -0700893 set.addAnimation(translate);
Chet Haase10e23ab2015-02-11 15:08:38 -0800894 set.addAnimation(alpha);
Filip Gruszczynski9e2cf5b2015-07-31 12:20:40 -0700895 set.setZAdjustment(Animation.ZORDER_TOP);
Chet Haase10e23ab2015-02-11 15:08:38 -0800896 set.initialize(appWidth, appHeight, appWidth, appHeight);
897 anim = set;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800898 mLastHadClipReveal = true;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800899 mLastClipRevealTransitionDuration = duration;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800900
901 // If the start rect was full inside the target rect (cutOff == false), we don't need
902 // to store the translation, because it's only used if cutOff == true.
903 mLastClipRevealMaxTranslation = cutOff
904 ? Math.max(Math.abs(translationY), Math.abs(translationX)) : 0;
Chet Haase10e23ab2015-02-11 15:08:38 -0800905 } else {
906 final long duration;
907 switch (transit) {
908 case TRANSIT_ACTIVITY_OPEN:
909 case TRANSIT_ACTIVITY_CLOSE:
910 duration = mConfigShortAnimTime;
911 break;
912 default:
913 duration = DEFAULT_APP_TRANSITION_DURATION;
914 break;
915 }
916 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
917 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
918 // If we are on top of the wallpaper, we need an animation that
919 // correctly handles the wallpaper staying static behind all of
920 // the animated elements. To do this, will just have the existing
921 // element fade out.
922 anim = new AlphaAnimation(1, 0);
923 anim.setDetachWallpaper(true);
924 } else {
925 // For normal animations, the exiting element just holds in place.
926 anim = new AlphaAnimation(1, 1);
927 }
928 anim.setInterpolator(mDecelerateInterpolator);
929 anim.setDuration(duration);
930 anim.setFillAfter(true);
931 }
932 return anim;
933 }
934
Winson Chung399f6202014-03-19 10:47:20 -0700935 /**
936 * Prepares the specified animation with a standard duration, interpolator, etc.
937 */
Winson Chung5393dff2014-05-08 14:25:43 -0700938 Animation prepareThumbnailAnimationWithDuration(Animation a, int appWidth, int appHeight,
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100939 long duration, Interpolator interpolator) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700940 if (duration > 0) {
941 a.setDuration(duration);
942 }
Winson Chung5393dff2014-05-08 14:25:43 -0700943 a.setFillAfter(true);
Jorim Jaggic69bd222016-03-15 14:38:37 +0100944 if (interpolator != null) {
945 a.setInterpolator(interpolator);
946 }
Winson Chung5393dff2014-05-08 14:25:43 -0700947 a.initialize(appWidth, appHeight, appWidth, appHeight);
948 return a;
949 }
950
951 /**
952 * Prepares the specified animation with a standard duration, interpolator, etc.
953 */
Winson Chung399f6202014-03-19 10:47:20 -0700954 Animation prepareThumbnailAnimation(Animation a, int appWidth, int appHeight, int transit) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800955 // Pick the desired duration. If this is an inter-activity transition,
956 // it is the standard duration for that. Otherwise we use the longer
957 // task transition duration.
Winson Chung5393dff2014-05-08 14:25:43 -0700958 final int duration;
Craig Mautner321bdf52012-12-18 09:53:24 -0800959 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800960 case TRANSIT_ACTIVITY_OPEN:
961 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800962 duration = mConfigShortAnimTime;
963 break;
964 default:
965 duration = DEFAULT_APP_TRANSITION_DURATION;
966 break;
967 }
Winson Chung5393dff2014-05-08 14:25:43 -0700968 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, duration,
969 mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800970 }
971
Winson Chung399f6202014-03-19 10:47:20 -0700972 /**
973 * Return the current thumbnail transition state.
974 */
975 int getThumbnailTransitionState(boolean enter) {
976 if (enter) {
977 if (mNextAppTransitionScaleUp) {
978 return THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
979 } else {
980 return THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN;
981 }
982 } else {
983 if (mNextAppTransitionScaleUp) {
984 return THUMBNAIL_TRANSITION_EXIT_SCALE_UP;
985 } else {
986 return THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN;
987 }
988 }
989 }
990
991 /**
Tony Mak64b8d562017-12-28 17:44:02 +0000992 * Creates an overlay with a background color and a thumbnail for the cross profile apps
993 * animation.
994 */
995 GraphicBuffer createCrossProfileAppsThumbnail(
996 @DrawableRes int thumbnailDrawableRes, Rect frame) {
997 final int width = frame.width();
998 final int height = frame.height();
999
1000 final RenderNode node = RenderNode.create("CrossProfileAppsThumbnail", null);
1001 node.setLeftTopRightBottom(0, 0, width, height);
1002 node.setClipToBounds(false);
1003
1004 final DisplayListCanvas canvas = node.start(width, height);
1005 canvas.drawColor(Color.argb(0.6f, 0, 0, 0));
1006 final int thumbnailSize = mService.mContext.getResources().getDimensionPixelSize(
1007 com.android.internal.R.dimen.cross_profile_apps_thumbnail_size);
1008 final Drawable drawable = mService.mContext.getDrawable(thumbnailDrawableRes);
1009 drawable.setBounds(
1010 (width - thumbnailSize) / 2,
1011 (height - thumbnailSize) / 2,
1012 (width + thumbnailSize) / 2,
1013 (height + thumbnailSize) / 2);
1014 drawable.draw(canvas);
1015 node.end(canvas);
1016
1017 return ThreadedRenderer.createHardwareBitmap(node, width, height)
1018 .createGraphicBufferHandle();
1019 }
1020
1021 Animation createCrossProfileAppsThumbnailAnimationLocked(Rect appRect) {
1022 final Animation animation = loadAnimationRes(
1023 "android", com.android.internal.R.anim.cross_profile_apps_thumbnail_enter);
1024 return prepareThumbnailAnimationWithDuration(animation, appRect.width(),
1025 appRect.height(), 0, null);
1026 }
1027
1028 /**
Winson Chung399f6202014-03-19 10:47:20 -07001029 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001030 * when a thumbnail is specified with the pending animation override.
Winson Chung399f6202014-03-19 10:47:20 -07001031 */
Jorim Jaggide63d442016-03-14 14:56:56 +01001032 Animation createThumbnailAspectScaleAnimationLocked(Rect appRect, @Nullable Rect contentInsets,
Winson Chungaa7fa012017-05-24 15:50:06 -07001033 GraphicBuffer thumbnailHeader, final int taskId, int uiMode, int orientation) {
Winson Chung399f6202014-03-19 10:47:20 -07001034 Animation a;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001035 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chung399f6202014-03-19 10:47:20 -07001036 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001037 final int thumbHeightI = thumbnailHeader.getHeight();
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -07001038 final int appWidth = appRect.width();
Winson Chung399f6202014-03-19 10:47:20 -07001039
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -07001040 float scaleW = appWidth / thumbWidth;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001041 getNextAppTransitionStartRect(taskId, mTmpRect);
Jorim Jaggi09072002016-03-25 16:48:42 -07001042 final float fromX;
Manu Cornet57b61492017-01-24 18:19:05 +09001043 float fromY;
Jorim Jaggi09072002016-03-25 16:48:42 -07001044 final float toX;
Manu Cornet57b61492017-01-24 18:19:05 +09001045 float toY;
Jorim Jaggi09072002016-03-25 16:48:42 -07001046 final float pivotX;
1047 final float pivotY;
Manu Cornetd7376802017-01-13 13:44:07 -08001048 if (shouldScaleDownThumbnailTransition(uiMode, orientation)) {
Jorim Jaggi09072002016-03-25 16:48:42 -07001049 fromX = mTmpRect.left;
1050 fromY = mTmpRect.top;
1051
1052 // For the curved translate animation to work, the pivot points needs to be at the
1053 // same absolute position as the one from the real surface.
1054 toX = mTmpRect.width() / 2 * (scaleW - 1f) + appRect.left;
1055 toY = appRect.height() / 2 * (1 - 1 / scaleW) + appRect.top;
1056 pivotX = mTmpRect.width() / 2;
1057 pivotY = appRect.height() / 2 / scaleW;
Manu Cornet57b61492017-01-24 18:19:05 +09001058 if (mGridLayoutRecentsEnabled) {
1059 // In the grid layout, the header is displayed above the thumbnail instead of
1060 // overlapping it.
1061 fromY -= thumbHeightI;
1062 toY -= thumbHeightI * scaleW;
1063 }
Jorim Jaggi09072002016-03-25 16:48:42 -07001064 } else {
1065 pivotX = 0;
1066 pivotY = 0;
1067 fromX = mTmpRect.left;
1068 fromY = mTmpRect.top;
1069 toX = appRect.left;
1070 toY = appRect.top;
1071 }
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001072 final long duration = getAspectScaleDuration();
1073 final Interpolator interpolator = getAspectScaleInterpolator();
Winson Chung399f6202014-03-19 10:47:20 -07001074 if (mNextAppTransitionScaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001075 // Animation up from the thumbnail to the full screen
Jorim Jaggi8448f332016-03-14 17:50:37 +01001076 Animation scale = new ScaleAnimation(1f, scaleW, 1f, scaleW, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001077 scale.setInterpolator(interpolator);
1078 scale.setDuration(duration);
Jorim Jaggic6c89a82016-01-28 17:48:21 -08001079 Animation alpha = new AlphaAnimation(1f, 0f);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001080 alpha.setInterpolator(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
1081 ? THUMBNAIL_DOCK_INTERPOLATOR : mThumbnailFadeOutInterpolator);
1082 alpha.setDuration(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
1083 ? duration / 2
1084 : duration);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001085 Animation translate = createCurvedMotion(fromX, toX, fromY, toY);
1086 translate.setInterpolator(interpolator);
1087 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -07001088
Jorim Jaggide63d442016-03-14 14:56:56 +01001089 mTmpFromClipRect.set(0, 0, thumbWidthI, thumbHeightI);
1090 mTmpToClipRect.set(appRect);
1091
1092 // Containing frame is in screen space, but we need the clip rect in the
1093 // app space.
1094 mTmpToClipRect.offsetTo(0, 0);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001095 mTmpToClipRect.right = (int) (mTmpToClipRect.right / scaleW);
1096 mTmpToClipRect.bottom = (int) (mTmpToClipRect.bottom / scaleW);
Jorim Jaggide63d442016-03-14 14:56:56 +01001097
1098 if (contentInsets != null) {
Jorim Jaggi8448f332016-03-14 17:50:37 +01001099 mTmpToClipRect.inset((int) (-contentInsets.left * scaleW),
1100 (int) (-contentInsets.top * scaleW),
1101 (int) (-contentInsets.right * scaleW),
1102 (int) (-contentInsets.bottom * scaleW));
Jorim Jaggide63d442016-03-14 14:56:56 +01001103 }
1104
1105 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001106 clipAnim.setInterpolator(interpolator);
1107 clipAnim.setDuration(duration);
Jorim Jaggide63d442016-03-14 14:56:56 +01001108
Winson Chung399f6202014-03-19 10:47:20 -07001109 // This AnimationSet uses the Interpolators assigned above.
1110 AnimationSet set = new AnimationSet(false);
1111 set.addAnimation(scale);
Manu Cornet57b61492017-01-24 18:19:05 +09001112 if (!mGridLayoutRecentsEnabled) {
1113 // In the grid layout, the header should be shown for the whole animation.
1114 set.addAnimation(alpha);
1115 }
Winson Chunga4ccb862014-08-22 15:26:27 -07001116 set.addAnimation(translate);
Jorim Jaggide63d442016-03-14 14:56:56 +01001117 set.addAnimation(clipAnim);
Winson Chung399f6202014-03-19 10:47:20 -07001118 a = set;
1119 } else {
Winson Chunga4ccb862014-08-22 15:26:27 -07001120 // Animation down from the full screen to the thumbnail
Jorim Jaggi8448f332016-03-14 17:50:37 +01001121 Animation scale = new ScaleAnimation(scaleW, 1f, scaleW, 1f, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001122 scale.setInterpolator(interpolator);
1123 scale.setDuration(duration);
Winson Chunga4ccb862014-08-22 15:26:27 -07001124 Animation alpha = new AlphaAnimation(0f, 1f);
1125 alpha.setInterpolator(mThumbnailFadeInInterpolator);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001126 alpha.setDuration(duration);
1127 Animation translate = createCurvedMotion(toX, fromX, toY, fromY);
1128 translate.setInterpolator(interpolator);
1129 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -07001130
Winson Chunga4ccb862014-08-22 15:26:27 -07001131 // This AnimationSet uses the Interpolators assigned above.
1132 AnimationSet set = new AnimationSet(false);
1133 set.addAnimation(scale);
Manu Cornet57b61492017-01-24 18:19:05 +09001134 if (!mGridLayoutRecentsEnabled) {
1135 // In the grid layout, the header should be shown for the whole animation.
1136 set.addAnimation(alpha);
1137 }
Winson Chunga4ccb862014-08-22 15:26:27 -07001138 set.addAnimation(translate);
1139 a = set;
1140
1141 }
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -07001142 return prepareThumbnailAnimationWithDuration(a, appWidth, appRect.height(), 0,
Jorim Jaggic69bd222016-03-15 14:38:37 +01001143 null);
Winson Chung399f6202014-03-19 10:47:20 -07001144 }
1145
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001146 private Animation createCurvedMotion(float fromX, float toX, float fromY, float toY) {
1147
1148 // Almost no x-change - use linear animation
Jorim Jaggic69bd222016-03-15 14:38:37 +01001149 if (Math.abs(toX - fromX) < 1f || mNextAppTransition != TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001150 return new TranslateAnimation(fromX, toX, fromY, toY);
1151 } else {
1152 final Path path = createCurvedPath(fromX, toX, fromY, toY);
1153 return new CurvedTranslateAnimation(path);
1154 }
1155 }
1156
1157 private Path createCurvedPath(float fromX, float toX, float fromY, float toY) {
1158 final Path path = new Path();
1159 path.moveTo(fromX, fromY);
Jorim Jaggi1f458fb2016-03-25 17:36:37 -07001160
1161 if (fromY > toY) {
1162 // If the object needs to go up, move it in horizontal direction first, then vertical.
1163 path.cubicTo(fromX, fromY, toX, 0.9f * fromY + 0.1f * toY, toX, toY);
1164 } else {
1165 // If the object needs to go down, move it in vertical direction first, then horizontal.
1166 path.cubicTo(fromX, fromY, fromX, 0.1f * fromY + 0.9f * toY, toX, toY);
1167 }
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001168 return path;
1169 }
1170
1171 private long getAspectScaleDuration() {
1172 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggic69bd222016-03-15 14:38:37 +01001173 return (long) (THUMBNAIL_APP_TRANSITION_DURATION * 1.35f);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001174 } else {
1175 return THUMBNAIL_APP_TRANSITION_DURATION;
1176 }
1177 }
1178
1179 private Interpolator getAspectScaleInterpolator() {
1180 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
1181 return mFastOutSlowInInterpolator;
1182 } else {
1183 return TOUCH_RESPONSE_INTERPOLATOR;
1184 }
1185 }
1186
Winson Chung399f6202014-03-19 10:47:20 -07001187 /**
1188 * This alternate animation is created when we are doing a thumbnail transition, for the
1189 * activity that is leaving, and the activity that is entering.
1190 */
Winson Chunga4ccb862014-08-22 15:26:27 -07001191 Animation createAspectScaledThumbnailEnterExitAnimationLocked(int thumbTransitState,
Winsonb2024762016-04-05 17:32:30 -07001192 int uiMode, int orientation, int transit, Rect containingFrame, Rect contentInsets,
Matthew Ng43db6d22017-06-27 15:29:39 -07001193 @Nullable Rect surfaceInsets, @Nullable Rect stableInsets, boolean freeform,
1194 int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -07001195 Animation a;
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001196 final int appWidth = containingFrame.width();
1197 final int appHeight = containingFrame.height();
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001198 getDefaultNextAppTransitionStartRect(mTmpRect);
1199 final int thumbWidthI = mTmpRect.width();
Winson Chung399f6202014-03-19 10:47:20 -07001200 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001201 final int thumbHeightI = mTmpRect.height();
Winson Chung399f6202014-03-19 10:47:20 -07001202 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
Winsoncbb625b2016-07-06 15:24:15 -07001203 final int thumbStartX = mTmpRect.left - containingFrame.left - contentInsets.left;
Winson21700932016-03-24 17:26:23 -07001204 final int thumbStartY = mTmpRect.top - containingFrame.top;
Winson Chung399f6202014-03-19 10:47:20 -07001205
1206 switch (thumbTransitState) {
Jorim Jaggi8448f332016-03-14 17:50:37 +01001207 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP:
1208 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1209 final boolean scaleUp = thumbTransitState == THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
1210 if (freeform && scaleUp) {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001211 a = createAspectScaledThumbnailEnterFreeformAnimationLocked(
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001212 containingFrame, surfaceInsets, taskId);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001213 } else if (freeform) {
1214 a = createAspectScaledThumbnailExitFreeformAnimationLocked(
1215 containingFrame, surfaceInsets, taskId);
Winson Chung2820c452014-04-15 15:34:44 -07001216 } else {
Winson21700932016-03-24 17:26:23 -07001217 AnimationSet set = new AnimationSet(true);
1218
1219 // In portrait, we scale to fit the width
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001220 mTmpFromClipRect.set(containingFrame);
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001221 mTmpToClipRect.set(containingFrame);
Jorim Jaggic6c89a82016-01-28 17:48:21 -08001222
1223 // Containing frame is in screen space, but we need the clip rect in the
1224 // app space.
1225 mTmpFromClipRect.offsetTo(0, 0);
1226 mTmpToClipRect.offsetTo(0, 0);
1227
1228 // Exclude insets region from the source clip.
1229 mTmpFromClipRect.inset(contentInsets);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001230 mNextAppTransitionInsets.set(contentInsets);
1231
Manu Cornetd7376802017-01-13 13:44:07 -08001232 if (shouldScaleDownThumbnailTransition(uiMode, orientation)) {
Jorim Jaggic69bd222016-03-15 14:38:37 +01001233 // We scale the width and clip to the top/left square
1234 float scale = thumbWidth /
1235 (appWidth - contentInsets.left - contentInsets.right);
Manu Cornetb68b7652017-01-23 19:37:53 +09001236 if (!mGridLayoutRecentsEnabled) {
1237 int unscaledThumbHeight = (int) (thumbHeight / scale);
1238 mTmpFromClipRect.bottom = mTmpFromClipRect.top + unscaledThumbHeight;
1239 }
Jorim Jaggic69bd222016-03-15 14:38:37 +01001240
1241 mNextAppTransitionInsets.set(contentInsets);
1242
Jorim Jaggi8448f332016-03-14 17:50:37 +01001243 Animation scaleAnim = new ScaleAnimation(
1244 scaleUp ? scale : 1, scaleUp ? 1 : scale,
1245 scaleUp ? scale : 1, scaleUp ? 1 : scale,
Jorim Jaggic69bd222016-03-15 14:38:37 +01001246 containingFrame.width() / 2f,
1247 containingFrame.height() / 2f + contentInsets.top);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001248 final float targetX = (mTmpRect.left - containingFrame.left);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001249 final float x = containingFrame.width() / 2f
1250 - containingFrame.width() / 2f * scale;
Jorim Jaggi8448f332016-03-14 17:50:37 +01001251 final float targetY = (mTmpRect.top - containingFrame.top);
Matthew Ng43db6d22017-06-27 15:29:39 -07001252 float y = containingFrame.height() / 2f
Jorim Jaggic69bd222016-03-15 14:38:37 +01001253 - containingFrame.height() / 2f * scale;
Matthew Ng43db6d22017-06-27 15:29:39 -07001254
1255 // During transition may require clipping offset from any top stable insets
1256 // such as the statusbar height when statusbar is hidden
1257 if (mLowRamRecentsEnabled && contentInsets.top == 0 && scaleUp) {
1258 mTmpFromClipRect.top += stableInsets.top;
1259 y += stableInsets.top;
1260 }
Jorim Jaggi8448f332016-03-14 17:50:37 +01001261 final float startX = targetX - x;
1262 final float startY = targetY - y;
1263 Animation clipAnim = scaleUp
1264 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1265 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1266 Animation translateAnim = scaleUp
Jorim Jaggic69bd222016-03-15 14:38:37 +01001267 ? createCurvedMotion(startX, 0, startY - contentInsets.top, 0)
1268 : createCurvedMotion(0, startX, 0, startY - contentInsets.top);
1269
Winson21700932016-03-24 17:26:23 -07001270 set.addAnimation(clipAnim);
1271 set.addAnimation(scaleAnim);
1272 set.addAnimation(translateAnim);
1273
1274 } else {
1275 // In landscape, we don't scale at all and only crop
1276 mTmpFromClipRect.bottom = mTmpFromClipRect.top + thumbHeightI;
1277 mTmpFromClipRect.right = mTmpFromClipRect.left + thumbWidthI;
1278
Jorim Jaggi8448f332016-03-14 17:50:37 +01001279 Animation clipAnim = scaleUp
1280 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1281 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1282 Animation translateAnim = scaleUp
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001283 ? createCurvedMotion(thumbStartX, 0,
1284 thumbStartY - contentInsets.top, 0)
1285 : createCurvedMotion(0, thumbStartX, 0,
1286 thumbStartY - contentInsets.top);
Winson21700932016-03-24 17:26:23 -07001287
1288 set.addAnimation(clipAnim);
1289 set.addAnimation(translateAnim);
1290 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001291 a = set;
Winson21700932016-03-24 17:26:23 -07001292 a.setZAdjustment(Animation.ZORDER_TOP);
Winson Chung2820c452014-04-15 15:34:44 -07001293 }
Winson Chung399f6202014-03-19 10:47:20 -07001294 break;
1295 }
1296 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001297 // Previous app window during the scale up
Winson Chung399f6202014-03-19 10:47:20 -07001298 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001299 // Fade out the source activity if we are animating to a wallpaper
Winson Chung399f6202014-03-19 10:47:20 -07001300 // activity.
1301 a = new AlphaAnimation(1, 0);
1302 } else {
Winson Chung399f6202014-03-19 10:47:20 -07001303 a = new AlphaAnimation(1, 1);
1304 }
1305 break;
1306 }
1307 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001308 // Target app window during the scale down
1309 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1310 // Fade in the destination activity if we are animating from a wallpaper
1311 // activity.
1312 a = new AlphaAnimation(0, 1);
1313 } else {
1314 a = new AlphaAnimation(1, 1);
1315 }
Winson Chung399f6202014-03-19 10:47:20 -07001316 break;
1317 }
Winson Chung399f6202014-03-19 10:47:20 -07001318 default:
1319 throw new RuntimeException("Invalid thumbnail transition state");
1320 }
1321
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001322 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight,
1323 getAspectScaleDuration(), getAspectScaleInterpolator());
Winson Chung399f6202014-03-19 10:47:20 -07001324 }
1325
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001326 private Animation createAspectScaledThumbnailEnterFreeformAnimationLocked(Rect frame,
1327 @Nullable Rect surfaceInsets, int taskId) {
1328 getNextAppTransitionStartRect(taskId, mTmpRect);
1329 return createAspectScaledThumbnailFreeformAnimationLocked(mTmpRect, frame, surfaceInsets,
1330 true);
1331 }
1332
1333 private Animation createAspectScaledThumbnailExitFreeformAnimationLocked(Rect frame,
1334 @Nullable Rect surfaceInsets, int taskId) {
1335 getNextAppTransitionStartRect(taskId, mTmpRect);
1336 return createAspectScaledThumbnailFreeformAnimationLocked(frame, mTmpRect, surfaceInsets,
1337 false);
1338 }
1339
1340 private AnimationSet createAspectScaledThumbnailFreeformAnimationLocked(Rect sourceFrame,
1341 Rect destFrame, @Nullable Rect surfaceInsets, boolean enter) {
1342 final float sourceWidth = sourceFrame.width();
1343 final float sourceHeight = sourceFrame.height();
1344 final float destWidth = destFrame.width();
1345 final float destHeight = destFrame.height();
1346 final float scaleH = enter ? sourceWidth / destWidth : destWidth / sourceWidth;
1347 final float scaleV = enter ? sourceHeight / destHeight : destHeight / sourceHeight;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001348 AnimationSet set = new AnimationSet(true);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001349 final int surfaceInsetsH = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001350 ? 0 : surfaceInsets.left + surfaceInsets.right;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001351 final int surfaceInsetsV = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001352 ? 0 : surfaceInsets.top + surfaceInsets.bottom;
1353 // We want the scaling to happen from the center of the surface. In order to achieve that,
1354 // we need to account for surface insets that will be used to enlarge the surface.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001355 final float scaleHCenter = ((enter ? destWidth : sourceWidth) + surfaceInsetsH) / 2;
1356 final float scaleVCenter = ((enter ? destHeight : sourceHeight) + surfaceInsetsV) / 2;
1357 final ScaleAnimation scale = enter ?
1358 new ScaleAnimation(scaleH, 1, scaleV, 1, scaleHCenter, scaleVCenter)
1359 : new ScaleAnimation(1, scaleH, 1, scaleV, scaleHCenter, scaleVCenter);
1360 final int sourceHCenter = sourceFrame.left + sourceFrame.width() / 2;
1361 final int sourceVCenter = sourceFrame.top + sourceFrame.height() / 2;
1362 final int destHCenter = destFrame.left + destFrame.width() / 2;
1363 final int destVCenter = destFrame.top + destFrame.height() / 2;
1364 final int fromX = enter ? sourceHCenter - destHCenter : destHCenter - sourceHCenter;
1365 final int fromY = enter ? sourceVCenter - destVCenter : destVCenter - sourceVCenter;
1366 final TranslateAnimation translation = enter ? new TranslateAnimation(fromX, 0, fromY, 0)
1367 : new TranslateAnimation(0, fromX, 0, fromY);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001368 set.addAnimation(scale);
1369 set.addAnimation(translation);
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001370
1371 final IRemoteCallback callback = mAnimationFinishedCallback;
1372 if (callback != null) {
1373 set.setAnimationListener(new Animation.AnimationListener() {
1374 @Override
1375 public void onAnimationStart(Animation animation) { }
1376
1377 @Override
1378 public void onAnimationEnd(Animation animation) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001379 mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK, callback).sendToTarget();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001380 }
1381
1382 @Override
1383 public void onAnimationRepeat(Animation animation) { }
1384 });
1385 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001386 return set;
1387 }
1388
Winson Chung399f6202014-03-19 10:47:20 -07001389 /**
Winson Chunga4ccb862014-08-22 15:26:27 -07001390 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001391 * when a thumbnail is specified with the pending animation override.
Winson Chunga4ccb862014-08-22 15:26:27 -07001392 */
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001393 Animation createThumbnailScaleAnimationLocked(int appWidth, int appHeight, int transit,
Winson Chungaa7fa012017-05-24 15:50:06 -07001394 GraphicBuffer thumbnailHeader) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001395 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001396 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001397 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chunga4ccb862014-08-22 15:26:27 -07001398 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001399 final int thumbHeightI = thumbnailHeader.getHeight();
Winson Chunga4ccb862014-08-22 15:26:27 -07001400 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1401
1402 if (mNextAppTransitionScaleUp) {
1403 // Animation for the thumbnail zooming from its initial size to the full screen
1404 float scaleW = appWidth / thumbWidth;
1405 float scaleH = appHeight / thumbHeight;
1406 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001407 computePivot(mTmpRect.left, 1 / scaleW),
1408 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001409 scale.setInterpolator(mDecelerateInterpolator);
1410
1411 Animation alpha = new AlphaAnimation(1, 0);
1412 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
1413
1414 // This AnimationSet uses the Interpolators assigned above.
1415 AnimationSet set = new AnimationSet(false);
1416 set.addAnimation(scale);
1417 set.addAnimation(alpha);
1418 a = set;
1419 } else {
1420 // Animation for the thumbnail zooming down from the full screen to its final size
1421 float scaleW = appWidth / thumbWidth;
1422 float scaleH = appHeight / thumbHeight;
1423 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001424 computePivot(mTmpRect.left, 1 / scaleW),
1425 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001426 }
1427
1428 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1429 }
1430
1431 /**
Winson Chung399f6202014-03-19 10:47:20 -07001432 * This animation is created when we are doing a thumbnail transition, for the activity that is
1433 * leaving, and the activity that is entering.
1434 */
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001435 Animation createThumbnailEnterExitAnimationLocked(int thumbTransitState, Rect containingFrame,
1436 int transit, int taskId) {
1437 final int appWidth = containingFrame.width();
1438 final int appHeight = containingFrame.height();
Winson Chungaa7fa012017-05-24 15:50:06 -07001439 final GraphicBuffer thumbnailHeader = getAppTransitionThumbnailHeader(taskId);
Winson Chung399f6202014-03-19 10:47:20 -07001440 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001441 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001442 final int thumbWidthI = thumbnailHeader != null ? thumbnailHeader.getWidth() : appWidth;
Winson Chung399f6202014-03-19 10:47:20 -07001443 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001444 final int thumbHeightI = thumbnailHeader != null ? thumbnailHeader.getHeight() : appHeight;
Winson Chung399f6202014-03-19 10:47:20 -07001445 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1446
1447 switch (thumbTransitState) {
1448 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
1449 // Entering app scales up with the thumbnail
1450 float scaleW = thumbWidth / appWidth;
1451 float scaleH = thumbHeight / appHeight;
1452 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001453 computePivot(mTmpRect.left, scaleW),
1454 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001455 break;
1456 }
1457 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
1458 // Exiting app while the thumbnail is scaling up should fade or stay in place
1459 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1460 // Fade out while bringing up selected activity. This keeps the
1461 // current activity from showing through a launching wallpaper
1462 // activity.
1463 a = new AlphaAnimation(1, 0);
1464 } else {
1465 // noop animation
1466 a = new AlphaAnimation(1, 1);
1467 }
1468 break;
1469 }
1470 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
1471 // Entering the other app, it should just be visible while we scale the thumbnail
1472 // down above it
1473 a = new AlphaAnimation(1, 1);
1474 break;
1475 }
1476 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1477 // Exiting the current app, the app should scale down with the thumbnail
1478 float scaleW = thumbWidth / appWidth;
1479 float scaleH = thumbHeight / appHeight;
1480 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001481 computePivot(mTmpRect.left, scaleW),
1482 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001483
1484 Animation alpha = new AlphaAnimation(1, 0);
1485
1486 AnimationSet set = new AnimationSet(true);
1487 set.addAnimation(scale);
1488 set.addAnimation(alpha);
1489 set.setZAdjustment(Animation.ZORDER_TOP);
1490 a = set;
1491 break;
1492 }
1493 default:
1494 throw new RuntimeException("Invalid thumbnail transition state");
1495 }
1496
1497 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1498 }
1499
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001500 private Animation createRelaunchAnimation(Rect containingFrame, Rect contentInsets) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001501 getDefaultNextAppTransitionStartRect(mTmpFromClipRect);
1502 final int left = mTmpFromClipRect.left;
1503 final int top = mTmpFromClipRect.top;
1504 mTmpFromClipRect.offset(-left, -top);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001505 // TODO: Isn't that strange that we ignore exact position of the containingFrame?
1506 mTmpToClipRect.set(0, 0, containingFrame.width(), containingFrame.height());
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001507 AnimationSet set = new AnimationSet(true);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001508 float fromWidth = mTmpFromClipRect.width();
1509 float toWidth = mTmpToClipRect.width();
1510 float fromHeight = mTmpFromClipRect.height();
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001511 // While the window might span the whole display, the actual content will be cropped to the
1512 // system decoration frame, for example when the window is docked. We need to take into
1513 // account the visible height when constructing the animation.
1514 float toHeight = mTmpToClipRect.height() - contentInsets.top - contentInsets.bottom;
1515 int translateAdjustment = 0;
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001516 if (fromWidth <= toWidth && fromHeight <= toHeight) {
1517 // The final window is larger in both dimensions than current window (e.g. we are
1518 // maximizing), so we can simply unclip the new window and there will be no disappearing
1519 // frame.
1520 set.addAnimation(new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect));
1521 } else {
1522 // The disappearing window has one larger dimension. We need to apply scaling, so the
1523 // first frame of the entry animation matches the old window.
1524 set.addAnimation(new ScaleAnimation(fromWidth / toWidth, 1, fromHeight / toHeight, 1));
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001525 // We might not be going exactly full screen, but instead be aligned under the status
1526 // bar using cropping. We still need to account for the cropped part, which will also
1527 // be scaled.
1528 translateAdjustment = (int) (contentInsets.top * fromHeight / toHeight);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001529 }
1530
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001531 // We animate the translation from the old position of the removed window, to the new
1532 // position of the added window. The latter might not be full screen, for example docked for
1533 // docked windows.
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001534 TranslateAnimation translate = new TranslateAnimation(left - containingFrame.left,
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001535 0, top - containingFrame.top - translateAdjustment, 0);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001536 set.addAnimation(translate);
1537 set.setDuration(DEFAULT_APP_TRANSITION_DURATION);
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07001538 set.setZAdjustment(Animation.ZORDER_TOP);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001539 return set;
1540 }
1541
Jorim Jaggic554b772015-06-04 16:07:57 -07001542 /**
1543 * @return true if and only if the first frame of the transition can be skipped, i.e. the first
1544 * frame of the transition doesn't change the visuals on screen, so we can start
1545 * directly with the second one
1546 */
1547 boolean canSkipFirstFrame() {
1548 return mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM
1549 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE
Jorim Jaggife762342016-10-13 14:33:27 +02001550 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CLIP_REVEAL
1551 && mNextAppTransition != TRANSIT_KEYGUARD_GOING_AWAY;
Jorim Jaggic554b772015-06-04 16:07:57 -07001552 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001553
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001554 /**
1555 *
1556 * @param frame These are the bounds of the window when it finishes the animation. This is where
1557 * the animation must usually finish in entrance animation, as the next frame will
1558 * display the window at these coordinates. In case of exit animation, this is
1559 * where the animation must start, as the frame before the animation is displaying
1560 * the window at these bounds.
1561 * @param insets Knowing where the window will be positioned is not enough. Some parts of the
1562 * window might be obscured, usually by the system windows (status bar and
1563 * navigation bar) and we use content insets to convey that information. This
1564 * usually affects the animation aspects vertically, as the system decoration is
1565 * at the top and the bottom. For example when we animate from full screen to
1566 * recents, we want to exclude the covered parts, because they won't match the
1567 * thumbnail after the last frame is executed.
1568 * @param surfaceInsets In rare situation the surface is larger than the content and we need to
1569 * know about this to make the animation frames match. We currently use
1570 * this for freeform windows, which have larger surfaces to display
1571 * shadows. When we animate them from recents, we want to match the content
1572 * to the recents thumbnail and hence need to account for the surface being
1573 * bigger.
1574 */
Winsonb2024762016-04-05 17:32:30 -07001575 Animation loadAnimation(WindowManager.LayoutParams lp, int transit, boolean enter, int uiMode,
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001576 int orientation, Rect frame, Rect displayFrame, Rect insets,
Matthew Ng43db6d22017-06-27 15:29:39 -07001577 @Nullable Rect surfaceInsets, @Nullable Rect stableInsets, boolean isVoiceInteraction,
1578 boolean freeform, int taskId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001579 Animation a;
Jorim Jaggife762342016-10-13 14:33:27 +02001580 if (isKeyguardGoingAwayTransit(transit) && enter) {
1581 a = loadKeyguardExitAnimation(transit);
1582 } else if (transit == TRANSIT_KEYGUARD_OCCLUDE) {
1583 a = null;
1584 } else if (transit == TRANSIT_KEYGUARD_UNOCCLUDE && !enter) {
1585 a = loadAnimationRes(lp, com.android.internal.R.anim.wallpaper_open_exit);
1586 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_OPEN
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001587 || transit == TRANSIT_TASK_OPEN
1588 || transit == TRANSIT_TASK_TO_FRONT)) {
1589 a = loadAnimationRes(lp, enter
1590 ? com.android.internal.R.anim.voice_activity_open_enter
1591 : com.android.internal.R.anim.voice_activity_open_exit);
1592 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1593 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001594 + " anim=" + a + " transit=" + appTransitionToString(transit)
1595 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001596 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_CLOSE
1597 || transit == TRANSIT_TASK_CLOSE
1598 || transit == TRANSIT_TASK_TO_BACK)) {
1599 a = loadAnimationRes(lp, enter
1600 ? com.android.internal.R.anim.voice_activity_close_enter
1601 : com.android.internal.R.anim.voice_activity_close_exit);
1602 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1603 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001604 + " anim=" + a + " transit=" + appTransitionToString(transit)
1605 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001606 } else if (transit == TRANSIT_ACTIVITY_RELAUNCH) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001607 a = createRelaunchAnimation(frame, insets);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001608 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1609 "applyAnimation:"
1610 + " anim=" + a + " nextAppTransition=" + mNextAppTransition
1611 + " transit=" + appTransitionToString(transit)
1612 + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001613 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM) {
1614 a = loadAnimationRes(mNextAppTransitionPackage, enter ?
Craig Mautner164d4bb2012-11-26 13:51:23 -08001615 mNextAppTransitionEnter : mNextAppTransitionExit);
1616 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1617 "applyAnimation:"
1618 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001619 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001620 + " Callers=" + Debug.getCallers(3));
Winson Chung044d5292014-11-06 11:05:19 -08001621 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE) {
1622 a = loadAnimationRes(mNextAppTransitionPackage, mNextAppTransitionInPlace);
1623 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1624 "applyAnimation:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001625 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM_IN_PLACE"
1626 + " transit=" + appTransitionToString(transit)
1627 + " Callers=" + Debug.getCallers(3));
Chet Haase10e23ab2015-02-11 15:08:38 -08001628 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001629 a = createClipRevealAnimationLocked(transit, enter, frame, displayFrame);
Chet Haase10e23ab2015-02-11 15:08:38 -08001630 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1631 "applyAnimation:"
1632 + " anim=" + a + " nextAppTransition=ANIM_CLIP_REVEAL"
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001633 + " transit=" + appTransitionToString(transit)
Chet Haase10e23ab2015-02-11 15:08:38 -08001634 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001635 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_SCALE_UP) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001636 a = createScaleUpAnimationLocked(transit, enter, frame);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001637 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1638 "applyAnimation:"
1639 + " anim=" + a + " nextAppTransition=ANIM_SCALE_UP"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001640 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001641 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001642 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
1643 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001644 mNextAppTransitionScaleUp =
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001645 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP);
Winson Chunga4ccb862014-08-22 15:26:27 -07001646 a = createThumbnailEnterExitAnimationLocked(getThumbnailTransitionState(enter),
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001647 frame, transit, taskId);
Winson Chunga4ccb862014-08-22 15:26:27 -07001648 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1649 String animName = mNextAppTransitionScaleUp ?
1650 "ANIM_THUMBNAIL_SCALE_UP" : "ANIM_THUMBNAIL_SCALE_DOWN";
1651 Slog.v(TAG, "applyAnimation:"
1652 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001653 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Winson Chunga4ccb862014-08-22 15:26:27 -07001654 + " Callers=" + Debug.getCallers(3));
1655 }
1656 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
1657 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN) {
1658 mNextAppTransitionScaleUp =
1659 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP);
1660 a = createAspectScaledThumbnailEnterExitAnimationLocked(
Winsonb2024762016-04-05 17:32:30 -07001661 getThumbnailTransitionState(enter), uiMode, orientation, transit, frame,
Matthew Ng43db6d22017-06-27 15:29:39 -07001662 insets, surfaceInsets, stableInsets, freeform, taskId);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001663 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1664 String animName = mNextAppTransitionScaleUp ?
Winson Chunga4ccb862014-08-22 15:26:27 -07001665 "ANIM_THUMBNAIL_ASPECT_SCALE_UP" : "ANIM_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner164d4bb2012-11-26 13:51:23 -08001666 Slog.v(TAG, "applyAnimation:"
1667 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001668 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001669 + " Callers=" + Debug.getCallers(3));
1670 }
Tony Mak089c35e2017-12-18 20:34:14 +00001671 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS
1672 && (transit == TRANSIT_ACTIVITY_OPEN
1673 || transit == TRANSIT_TASK_OPEN
1674 || transit == TRANSIT_TASK_TO_FRONT)) {
Tony Mak64b8d562017-12-28 17:44:02 +00001675
Tony Mak089c35e2017-12-18 20:34:14 +00001676 a = loadAnimationRes("android", enter
Tony Mak64b8d562017-12-28 17:44:02 +00001677 ? com.android.internal.R.anim.task_open_enter_cross_profile_apps
1678 : com.android.internal.R.anim.task_open_exit);
Tony Mak089c35e2017-12-18 20:34:14 +00001679 Slog.v(TAG,
1680 "applyAnimation NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS:"
1681 + " anim=" + a + " transit=" + appTransitionToString(transit)
1682 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Craig Mautner164d4bb2012-11-26 13:51:23 -08001683 } else {
1684 int animAttr = 0;
1685 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001686 case TRANSIT_ACTIVITY_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001687 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001688 ? WindowAnimation_activityOpenEnterAnimation
1689 : WindowAnimation_activityOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001690 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001691 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001692 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001693 ? WindowAnimation_activityCloseEnterAnimation
1694 : WindowAnimation_activityCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001695 break;
Jorim Jaggi192086e2016-03-11 17:17:03 +01001696 case TRANSIT_DOCK_TASK_FROM_RECENTS:
Craig Mautner4b71aa12012-12-27 17:20:01 -08001697 case TRANSIT_TASK_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001698 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001699 ? WindowAnimation_taskOpenEnterAnimation
1700 : WindowAnimation_taskOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001701 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001702 case TRANSIT_TASK_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001703 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001704 ? WindowAnimation_taskCloseEnterAnimation
1705 : WindowAnimation_taskCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001706 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001707 case TRANSIT_TASK_TO_FRONT:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001708 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001709 ? WindowAnimation_taskToFrontEnterAnimation
1710 : WindowAnimation_taskToFrontExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001711 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001712 case TRANSIT_TASK_TO_BACK:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001713 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001714 ? WindowAnimation_taskToBackEnterAnimation
1715 : WindowAnimation_taskToBackExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001716 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001717 case TRANSIT_WALLPAPER_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001718 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001719 ? WindowAnimation_wallpaperOpenEnterAnimation
1720 : WindowAnimation_wallpaperOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001721 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001722 case TRANSIT_WALLPAPER_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001723 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001724 ? WindowAnimation_wallpaperCloseEnterAnimation
1725 : WindowAnimation_wallpaperCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001726 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001727 case TRANSIT_WALLPAPER_INTRA_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001728 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001729 ? WindowAnimation_wallpaperIntraOpenEnterAnimation
1730 : WindowAnimation_wallpaperIntraOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001731 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001732 case TRANSIT_WALLPAPER_INTRA_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001733 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001734 ? WindowAnimation_wallpaperIntraCloseEnterAnimation
1735 : WindowAnimation_wallpaperIntraCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001736 break;
Craig Mautnerbb742462014-07-07 15:28:55 -07001737 case TRANSIT_TASK_OPEN_BEHIND:
1738 animAttr = enter
1739 ? WindowAnimation_launchTaskBehindSourceAnimation
Craig Mautner3b2cd1d2014-08-25 14:25:54 -07001740 : WindowAnimation_launchTaskBehindTargetAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001741 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001742 a = animAttr != 0 ? loadAnimationAttr(lp, animAttr) : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001743 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1744 "applyAnimation:"
1745 + " anim=" + a
1746 + " animAttr=0x" + Integer.toHexString(animAttr)
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001747 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001748 + " Callers=" + Debug.getCallers(3));
1749 }
1750 return a;
1751 }
1752
Jorim Jaggife762342016-10-13 14:33:27 +02001753 private Animation loadKeyguardExitAnimation(int transit) {
1754 if ((mNextAppTransitionFlags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_NO_ANIMATION) != 0) {
1755 return null;
1756 }
1757 final boolean toShade =
1758 (mNextAppTransitionFlags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_TO_SHADE) != 0;
1759 return mService.mPolicy.createHiddenByKeyguardExit(
1760 transit == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER, toShade);
1761 }
1762
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001763 int getAppStackClipMode() {
Matthew Ngbf1d9852017-03-14 12:23:09 -07001764 // When dismiss keyguard animation occurs, clip before the animation to prevent docked
1765 // app from showing beyond the divider
1766 if (mNextAppTransition == TRANSIT_KEYGUARD_GOING_AWAY
1767 || mNextAppTransition == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER) {
1768 return STACK_CLIP_BEFORE_ANIM;
1769 }
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001770 return mNextAppTransition == TRANSIT_ACTIVITY_RELAUNCH
Jorim Jaggic69bd222016-03-15 14:38:37 +01001771 || mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
Jorim Jaggi1f458fb2016-03-25 17:36:37 -07001772 || mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001773 ? STACK_CLIP_NONE
1774 : STACK_CLIP_AFTER_ANIM;
1775 }
1776
Jorim Jaggife762342016-10-13 14:33:27 +02001777 public int getTransitFlags() {
1778 return mNextAppTransitionFlags;
1779 }
1780
Craig Mautner164d4bb2012-11-26 13:51:23 -08001781 void postAnimationCallback() {
1782 if (mNextAppTransitionCallback != null) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001783 mService.mH.sendMessage(mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK,
1784 mNextAppTransitionCallback));
Craig Mautner164d4bb2012-11-26 13:51:23 -08001785 mNextAppTransitionCallback = null;
1786 }
1787 }
1788
1789 void overridePendingAppTransition(String packageName, int enterAnim, int exitAnim,
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001790 IRemoteCallback startedCallback) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001791 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001792 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001793 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001794 mNextAppTransitionPackage = packageName;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001795 mNextAppTransitionEnter = enterAnim;
1796 mNextAppTransitionExit = exitAnim;
1797 postAnimationCallback();
1798 mNextAppTransitionCallback = startedCallback;
1799 } else {
1800 postAnimationCallback();
1801 }
1802 }
1803
1804 void overridePendingAppTransitionScaleUp(int startX, int startY, int startWidth,
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001805 int startHeight) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001806 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001807 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001808 mNextAppTransitionType = NEXT_TRANSIT_TYPE_SCALE_UP;
Winson4c3fecd2016-07-13 12:29:48 -07001809 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001810 postAnimationCallback();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001811 }
1812 }
1813
Chet Haase10e23ab2015-02-11 15:08:38 -08001814 void overridePendingAppTransitionClipReveal(int startX, int startY,
1815 int startWidth, int startHeight) {
1816 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001817 clear();
Chet Haase10e23ab2015-02-11 15:08:38 -08001818 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CLIP_REVEAL;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001819 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Chet Haase10e23ab2015-02-11 15:08:38 -08001820 postAnimationCallback();
Chet Haase10e23ab2015-02-11 15:08:38 -08001821 }
1822 }
1823
Winson Chungaa7fa012017-05-24 15:50:06 -07001824 void overridePendingAppTransitionThumb(GraphicBuffer srcThumb, int startX, int startY,
Craig Mautner164d4bb2012-11-26 13:51:23 -08001825 IRemoteCallback startedCallback, boolean scaleUp) {
1826 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001827 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001828 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP
1829 : NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001830 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001831 putDefaultNextAppTransitionCoordinates(startX, startY, 0, 0, srcThumb);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001832 postAnimationCallback();
1833 mNextAppTransitionCallback = startedCallback;
1834 } else {
1835 postAnimationCallback();
1836 }
1837 }
1838
Winson Chungaa7fa012017-05-24 15:50:06 -07001839 void overridePendingAppTransitionAspectScaledThumb(GraphicBuffer srcThumb, int startX, int startY,
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001840 int targetWidth, int targetHeight, IRemoteCallback startedCallback, boolean scaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001841 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001842 clear();
Winson Chunga4ccb862014-08-22 15:26:27 -07001843 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1844 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Winson Chunga4ccb862014-08-22 15:26:27 -07001845 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001846 putDefaultNextAppTransitionCoordinates(startX, startY, targetWidth, targetHeight,
1847 srcThumb);
Winson Chunga4ccb862014-08-22 15:26:27 -07001848 postAnimationCallback();
1849 mNextAppTransitionCallback = startedCallback;
1850 } else {
1851 postAnimationCallback();
1852 }
1853 }
1854
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001855 public void overridePendingAppTransitionMultiThumb(AppTransitionAnimationSpec[] specs,
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001856 IRemoteCallback onAnimationStartedCallback, IRemoteCallback onAnimationFinishedCallback,
1857 boolean scaleUp) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001858 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001859 clear();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001860 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1861 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001862 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi43102412015-11-11 16:28:37 +01001863 if (specs != null) {
1864 for (int i = 0; i < specs.length; i++) {
1865 AppTransitionAnimationSpec spec = specs[i];
1866 if (spec != null) {
1867 mNextAppTransitionAnimationsSpecs.put(spec.taskId, spec);
1868 if (i == 0) {
1869 // In full screen mode, the transition code depends on the default spec
1870 // to be set.
1871 Rect rect = spec.rect;
1872 putDefaultNextAppTransitionCoordinates(rect.left, rect.top,
Winson Chungaa7fa012017-05-24 15:50:06 -07001873 rect.width(), rect.height(), spec.buffer);
Jorim Jaggi43102412015-11-11 16:28:37 +01001874 }
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001875 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001876 }
1877 }
1878 postAnimationCallback();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001879 mNextAppTransitionCallback = onAnimationStartedCallback;
1880 mAnimationFinishedCallback = onAnimationFinishedCallback;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001881 } else {
1882 postAnimationCallback();
1883 }
1884 }
1885
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001886 void overridePendingAppTransitionMultiThumbFuture(
1887 IAppTransitionAnimationSpecsFuture specsFuture, IRemoteCallback callback,
1888 boolean scaleUp) {
1889 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001890 clear();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001891 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1892 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001893 mNextAppTransitionAnimationsSpecsFuture = specsFuture;
1894 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001895 mNextAppTransitionFutureCallback = callback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001896 }
1897 }
1898
Winson Chung044d5292014-11-06 11:05:19 -08001899 void overrideInPlaceAppTransition(String packageName, int anim) {
1900 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001901 clear();
Winson Chung044d5292014-11-06 11:05:19 -08001902 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE;
1903 mNextAppTransitionPackage = packageName;
1904 mNextAppTransitionInPlace = anim;
1905 } else {
1906 postAnimationCallback();
1907 }
1908 }
1909
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001910 /**
Tony Mak089c35e2017-12-18 20:34:14 +00001911 * @see {@link #NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS}
1912 */
1913 void overridePendingAppTransitionStartCrossProfileApps() {
1914 if (isTransitionSet()) {
1915 clear();
1916 mNextAppTransitionType = NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS;
1917 postAnimationCallback();
1918 }
1919 }
1920
1921 /**
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001922 * If a future is set for the app transition specs, fetch it in another thread.
1923 */
1924 private void fetchAppTransitionSpecsFromFuture() {
1925 if (mNextAppTransitionAnimationsSpecsFuture != null) {
1926 mNextAppTransitionAnimationsSpecsPending = true;
1927 final IAppTransitionAnimationSpecsFuture future
1928 = mNextAppTransitionAnimationsSpecsFuture;
1929 mNextAppTransitionAnimationsSpecsFuture = null;
Jorim Jaggied410b62017-05-05 15:16:14 +02001930 mDefaultExecutor.execute(() -> {
1931 AppTransitionAnimationSpec[] specs = null;
1932 try {
1933 Binder.allowBlocking(future.asBinder());
1934 specs = future.get();
1935 } catch (RemoteException e) {
1936 Slog.w(TAG, "Failed to fetch app transition specs: " + e);
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001937 }
Jorim Jaggied410b62017-05-05 15:16:14 +02001938 synchronized (mService.mWindowMap) {
1939 mNextAppTransitionAnimationsSpecsPending = false;
1940 overridePendingAppTransitionMultiThumb(specs,
1941 mNextAppTransitionFutureCallback, null /* finishedCallback */,
1942 mNextAppTransitionScaleUp);
1943 mNextAppTransitionFutureCallback = null;
Jorim Jaggied410b62017-05-05 15:16:14 +02001944 }
1945 mService.requestTraversal();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001946 });
1947 }
1948 }
1949
Craig Mautner164d4bb2012-11-26 13:51:23 -08001950 @Override
1951 public String toString() {
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001952 return "mNextAppTransition=" + appTransitionToString(mNextAppTransition);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001953 }
1954
Craig Mautner4b71aa12012-12-27 17:20:01 -08001955 /**
1956 * Returns the human readable name of a window transition.
1957 *
1958 * @param transition The window transition.
1959 * @return The transition symbolic name.
1960 */
1961 public static String appTransitionToString(int transition) {
1962 switch (transition) {
1963 case TRANSIT_UNSET: {
1964 return "TRANSIT_UNSET";
1965 }
1966 case TRANSIT_NONE: {
1967 return "TRANSIT_NONE";
1968 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001969 case TRANSIT_ACTIVITY_OPEN: {
1970 return "TRANSIT_ACTIVITY_OPEN";
1971 }
1972 case TRANSIT_ACTIVITY_CLOSE: {
1973 return "TRANSIT_ACTIVITY_CLOSE";
1974 }
1975 case TRANSIT_TASK_OPEN: {
1976 return "TRANSIT_TASK_OPEN";
1977 }
1978 case TRANSIT_TASK_CLOSE: {
1979 return "TRANSIT_TASK_CLOSE";
1980 }
1981 case TRANSIT_TASK_TO_FRONT: {
1982 return "TRANSIT_TASK_TO_FRONT";
1983 }
1984 case TRANSIT_TASK_TO_BACK: {
1985 return "TRANSIT_TASK_TO_BACK";
1986 }
1987 case TRANSIT_WALLPAPER_CLOSE: {
1988 return "TRANSIT_WALLPAPER_CLOSE";
1989 }
1990 case TRANSIT_WALLPAPER_OPEN: {
1991 return "TRANSIT_WALLPAPER_OPEN";
1992 }
1993 case TRANSIT_WALLPAPER_INTRA_OPEN: {
1994 return "TRANSIT_WALLPAPER_INTRA_OPEN";
1995 }
1996 case TRANSIT_WALLPAPER_INTRA_CLOSE: {
1997 return "TRANSIT_WALLPAPER_INTRA_CLOSE";
1998 }
Craig Mautnerbb742462014-07-07 15:28:55 -07001999 case TRANSIT_TASK_OPEN_BEHIND: {
2000 return "TRANSIT_TASK_OPEN_BEHIND";
2001 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07002002 case TRANSIT_ACTIVITY_RELAUNCH: {
2003 return "TRANSIT_ACTIVITY_RELAUNCH";
2004 }
Jorim Jaggi192086e2016-03-11 17:17:03 +01002005 case TRANSIT_DOCK_TASK_FROM_RECENTS: {
2006 return "TRANSIT_DOCK_TASK_FROM_RECENTS";
2007 }
Jorim Jaggife762342016-10-13 14:33:27 +02002008 case TRANSIT_KEYGUARD_GOING_AWAY: {
2009 return "TRANSIT_KEYGUARD_GOING_AWAY";
2010 }
2011 case TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER: {
2012 return "TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER";
2013 }
2014 case TRANSIT_KEYGUARD_OCCLUDE: {
2015 return "TRANSIT_KEYGUARD_OCCLUDE";
2016 }
2017 case TRANSIT_KEYGUARD_UNOCCLUDE: {
2018 return "TRANSIT_KEYGUARD_UNOCCLUDE";
2019 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002020 default: {
2021 return "<UNKNOWN>";
2022 }
2023 }
2024 }
2025
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002026 private String appStateToString() {
2027 switch (mAppTransitionState) {
2028 case APP_STATE_IDLE:
2029 return "APP_STATE_IDLE";
2030 case APP_STATE_READY:
2031 return "APP_STATE_READY";
2032 case APP_STATE_RUNNING:
2033 return "APP_STATE_RUNNING";
2034 case APP_STATE_TIMEOUT:
2035 return "APP_STATE_TIMEOUT";
2036 default:
2037 return "unknown state=" + mAppTransitionState;
2038 }
2039 }
2040
2041 private String transitTypeToString() {
2042 switch (mNextAppTransitionType) {
2043 case NEXT_TRANSIT_TYPE_NONE:
2044 return "NEXT_TRANSIT_TYPE_NONE";
2045 case NEXT_TRANSIT_TYPE_CUSTOM:
2046 return "NEXT_TRANSIT_TYPE_CUSTOM";
Winson Chung044d5292014-11-06 11:05:19 -08002047 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
2048 return "NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002049 case NEXT_TRANSIT_TYPE_SCALE_UP:
2050 return "NEXT_TRANSIT_TYPE_SCALE_UP";
2051 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
2052 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP";
2053 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
2054 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN";
Winson Chunga4ccb862014-08-22 15:26:27 -07002055 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
2056 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP";
2057 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN:
2058 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN";
Tony Mak64b8d562017-12-28 17:44:02 +00002059 case NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS:
2060 return "NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002061 default:
2062 return "unknown type=" + mNextAppTransitionType;
2063 }
2064 }
2065
Steven Timotiusaf03df62017-07-18 16:56:43 -07002066 void writeToProto(ProtoOutputStream proto, long fieldId) {
2067 final long token = proto.start(fieldId);
2068 proto.write(APP_TRANSITION_STATE, mAppTransitionState);
2069 proto.write(LAST_USED_APP_TRANSITION, mLastUsedAppTransition);
2070 proto.end(token);
2071 }
2072
Craig Mautner164d4bb2012-11-26 13:51:23 -08002073 @Override
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002074 public void dump(PrintWriter pw, String prefix) {
2075 pw.print(prefix); pw.println(this);
2076 pw.print(prefix); pw.print("mAppTransitionState="); pw.println(appStateToString());
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002077 if (mNextAppTransitionType != NEXT_TRANSIT_TYPE_NONE) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002078 pw.print(prefix); pw.print("mNextAppTransitionType=");
2079 pw.println(transitTypeToString());
Craig Mautner164d4bb2012-11-26 13:51:23 -08002080 }
2081 switch (mNextAppTransitionType) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002082 case NEXT_TRANSIT_TYPE_CUSTOM:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002083 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Craig Mautner164d4bb2012-11-26 13:51:23 -08002084 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002085 pw.print(prefix); pw.print("mNextAppTransitionEnter=0x");
Craig Mautner164d4bb2012-11-26 13:51:23 -08002086 pw.print(Integer.toHexString(mNextAppTransitionEnter));
2087 pw.print(" mNextAppTransitionExit=0x");
2088 pw.println(Integer.toHexString(mNextAppTransitionExit));
2089 break;
Winson Chung044d5292014-11-06 11:05:19 -08002090 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002091 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Winson Chung044d5292014-11-06 11:05:19 -08002092 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002093 pw.print(prefix); pw.print("mNextAppTransitionInPlace=0x");
Winson Chung044d5292014-11-06 11:05:19 -08002094 pw.print(Integer.toHexString(mNextAppTransitionInPlace));
2095 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002096 case NEXT_TRANSIT_TYPE_SCALE_UP: {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002097 getDefaultNextAppTransitionStartRect(mTmpRect);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002098 pw.print(prefix); pw.print("mNextAppTransitionStartX=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002099 pw.print(mTmpRect.left);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002100 pw.print(" mNextAppTransitionStartY=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002101 pw.println(mTmpRect.top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002102 pw.print(prefix); pw.print("mNextAppTransitionStartWidth=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002103 pw.print(mTmpRect.width());
Craig Mautner164d4bb2012-11-26 13:51:23 -08002104 pw.print(" mNextAppTransitionStartHeight=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002105 pw.println(mTmpRect.height());
Craig Mautner164d4bb2012-11-26 13:51:23 -08002106 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002107 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002108 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
2109 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
Winson Chunga4ccb862014-08-22 15:26:27 -07002110 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002111 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN: {
2112 pw.print(prefix); pw.print("mDefaultNextAppTransitionAnimationSpec=");
2113 pw.println(mDefaultNextAppTransitionAnimationSpec);
2114 pw.print(prefix); pw.print("mNextAppTransitionAnimationsSpecs=");
2115 pw.println(mNextAppTransitionAnimationsSpecs);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002116 pw.print(prefix); pw.print("mNextAppTransitionScaleUp=");
2117 pw.println(mNextAppTransitionScaleUp);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002118 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002119 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002120 }
2121 if (mNextAppTransitionCallback != null) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002122 pw.print(prefix); pw.print("mNextAppTransitionCallback=");
2123 pw.println(mNextAppTransitionCallback);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002124 }
Chong Zhang60091a92016-07-27 17:52:45 -07002125 if (mLastUsedAppTransition != TRANSIT_NONE) {
2126 pw.print(prefix); pw.print("mLastUsedAppTransition=");
2127 pw.println(appTransitionToString(mLastUsedAppTransition));
2128 pw.print(prefix); pw.print("mLastOpeningApp=");
2129 pw.println(mLastOpeningApp);
2130 pw.print(prefix); pw.print("mLastClosingApp=");
2131 pw.println(mLastClosingApp);
2132 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002133 }
Amith Yamasani4befbec2013-07-10 16:18:01 -07002134
2135 public void setCurrentUser(int newUserId) {
2136 mCurrentUserId = newUserId;
2137 }
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002138
2139 /**
2140 * @return true if transition is not running and should not be skipped, false if transition is
2141 * already running
2142 */
Jorim Jaggife762342016-10-13 14:33:27 +02002143 boolean prepareAppTransitionLocked(int transit, boolean alwaysKeepCurrent, int flags,
2144 boolean forceOverride) {
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002145 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Prepare app transition:"
2146 + " transit=" + appTransitionToString(transit)
2147 + " " + this
2148 + " alwaysKeepCurrent=" + alwaysKeepCurrent
2149 + " Callers=" + Debug.getCallers(3));
Jorim Jaggife762342016-10-13 14:33:27 +02002150 if (forceOverride || isKeyguardTransit(transit) || !isTransitionSet()
2151 || mNextAppTransition == TRANSIT_NONE) {
2152 setAppTransition(transit, flags);
Jorim Jaggia69243a2017-06-15 15:10:38 -04002153 }
2154 // We never want to change from a Keyguard transit to a non-Keyguard transit, as our logic
2155 // relies on the fact that we always execute a Keyguard transition after preparing one.
2156 else if (!alwaysKeepCurrent && !isKeyguardTransit(transit)) {
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002157 if (transit == TRANSIT_TASK_OPEN && isTransitionEqual(TRANSIT_TASK_CLOSE)) {
2158 // Opening a new task always supersedes a close for the anim.
Jorim Jaggife762342016-10-13 14:33:27 +02002159 setAppTransition(transit, flags);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002160 } else if (transit == TRANSIT_ACTIVITY_OPEN
2161 && isTransitionEqual(TRANSIT_ACTIVITY_CLOSE)) {
2162 // Opening a new activity always supersedes a close for the anim.
Jorim Jaggife762342016-10-13 14:33:27 +02002163 setAppTransition(transit, flags);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002164 }
2165 }
2166 boolean prepared = prepare();
2167 if (isTransitionSet()) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08002168 mService.mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
2169 mService.mH.sendEmptyMessageDelayed(H.APP_TRANSITION_TIMEOUT, APP_TRANSITION_TIMEOUT_MS);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002170 }
2171 return prepared;
2172 }
Winsonb2024762016-04-05 17:32:30 -07002173
2174 /**
Jorim Jaggife762342016-10-13 14:33:27 +02002175 * @return true if {@param transit} is representing a transition in which Keyguard is going
2176 * away, false otherwise
2177 */
2178 public static boolean isKeyguardGoingAwayTransit(int transit) {
2179 return transit == TRANSIT_KEYGUARD_GOING_AWAY
2180 || transit == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER;
2181 }
2182
2183 private static boolean isKeyguardTransit(int transit) {
2184 return isKeyguardGoingAwayTransit(transit) || transit == TRANSIT_KEYGUARD_OCCLUDE
2185 || transit == TRANSIT_KEYGUARD_UNOCCLUDE;
2186 }
2187
2188 /**
Manu Cornetd7376802017-01-13 13:44:07 -08002189 * @return whether the transition should show the thumbnail being scaled down.
2190 */
2191 private boolean shouldScaleDownThumbnailTransition(int uiMode, int orientation) {
Sid Soundararajan0e88d322017-03-07 15:37:30 -08002192 return mGridLayoutRecentsEnabled
Manu Cornetd7376802017-01-13 13:44:07 -08002193 || orientation == Configuration.ORIENTATION_PORTRAIT;
2194 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002195}