blob: fc7ad09d51826c0d2214a5697d0facb200894ecd [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
Jorim Jaggif84e2f62018-01-16 14:17:59 +010019import static android.view.WindowManager.LayoutParams;
20import static android.view.WindowManager.TRANSIT_ACTIVITY_CLOSE;
21import static android.view.WindowManager.TRANSIT_ACTIVITY_OPEN;
22import static android.view.WindowManager.TRANSIT_ACTIVITY_RELAUNCH;
23import static android.view.WindowManager.TRANSIT_DOCK_TASK_FROM_RECENTS;
24import static android.view.WindowManager.TRANSIT_FLAG_KEYGUARD_GOING_AWAY_NO_ANIMATION;
25import static android.view.WindowManager.TRANSIT_FLAG_KEYGUARD_GOING_AWAY_TO_SHADE;
26import static android.view.WindowManager.TRANSIT_KEYGUARD_GOING_AWAY;
27import static android.view.WindowManager.TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER;
28import static android.view.WindowManager.TRANSIT_KEYGUARD_OCCLUDE;
29import static android.view.WindowManager.TRANSIT_KEYGUARD_UNOCCLUDE;
30import static android.view.WindowManager.TRANSIT_NONE;
31import static android.view.WindowManager.TRANSIT_TASK_CLOSE;
32import static android.view.WindowManager.TRANSIT_TASK_OPEN;
33import static android.view.WindowManager.TRANSIT_TASK_OPEN_BEHIND;
34import static android.view.WindowManager.TRANSIT_TASK_TO_BACK;
35import static android.view.WindowManager.TRANSIT_TASK_TO_FRONT;
36import static android.view.WindowManager.TRANSIT_UNSET;
37import static android.view.WindowManager.TRANSIT_WALLPAPER_CLOSE;
38import static android.view.WindowManager.TRANSIT_WALLPAPER_INTRA_CLOSE;
39import static android.view.WindowManager.TRANSIT_WALLPAPER_INTRA_OPEN;
40import static android.view.WindowManager.TRANSIT_WALLPAPER_OPEN;
Filip Gruszczynski82861362015-10-16 14:21:09 -070041import static com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation;
42import static com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
43import static com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation;
44import static com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
45import static com.android.internal.R.styleable.WindowAnimation_launchTaskBehindSourceAnimation;
46import static com.android.internal.R.styleable.WindowAnimation_launchTaskBehindTargetAnimation;
47import static com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation;
48import static com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
49import static com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation;
50import static com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
51import static com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation;
52import static com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
53import static com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation;
54import static com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
55import static com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation;
56import static com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
57import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation;
58import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
59import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation;
60import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
61import static com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation;
62import static com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Filip Gruszczynski198dcbf2016-01-18 10:02:00 -080063import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
64import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080065import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
66import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Adrian Roose99bc052017-11-20 17:55:31 +010067import static com.android.server.wm.WindowManagerInternal.AppTransitionListener;
Tony Mak089c35e2017-12-18 20:34:14 +000068import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_AFTER_ANIM;
Matthew Ngbf1d9852017-03-14 12:23:09 -070069import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_BEFORE_ANIM;
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +010070import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_NONE;
Steven Timotiusaf03df62017-07-18 16:56:43 -070071import static com.android.server.wm.proto.AppTransitionProto.APP_TRANSITION_STATE;
72import static com.android.server.wm.proto.AppTransitionProto.LAST_USED_APP_TRANSITION;
Filip Gruszczynski82861362015-10-16 14:21:09 -070073
Tony Mak64b8d562017-12-28 17:44:02 +000074import android.annotation.DrawableRes;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -070075import android.annotation.Nullable;
Matthew Ng43db6d22017-06-27 15:29:39 -070076import android.app.ActivityManager;
Tony Mak089c35e2017-12-18 20:34:14 +000077import android.content.ComponentName;
Craig Mautner164d4bb2012-11-26 13:51:23 -080078import android.content.Context;
Winson21700932016-03-24 17:26:23 -070079import android.content.res.Configuration;
Tony Mak64b8d562017-12-28 17:44:02 +000080import android.graphics.Color;
Winson Chungaa7fa012017-05-24 15:50:06 -070081import android.graphics.GraphicBuffer;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +010082import android.graphics.Path;
Winson Chung399f6202014-03-19 10:47:20 -070083import android.graphics.Rect;
Tony Mak64b8d562017-12-28 17:44:02 +000084import android.graphics.drawable.Drawable;
Jorim Jaggied410b62017-05-05 15:16:14 +020085import android.os.Binder;
Craig Mautner164d4bb2012-11-26 13:51:23 -080086import android.os.Debug;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010087import android.os.IBinder;
Craig Mautner164d4bb2012-11-26 13:51:23 -080088import android.os.IRemoteCallback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010089import android.os.RemoteException;
Jorim Jaggif5f9e122017-10-24 18:21:09 +020090import android.os.SystemClock;
Manu Cornetd7376802017-01-13 13:44:07 -080091import android.os.SystemProperties;
Tony Mak089c35e2017-12-18 20:34:14 +000092import android.os.UserHandle;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -080093import android.util.ArraySet;
Craig Mautner164d4bb2012-11-26 13:51:23 -080094import android.util.Slog;
Filip Gruszczynski170192a2015-08-16 17:46:34 -070095import android.util.SparseArray;
Steven Timotiusaf03df62017-07-18 16:56:43 -070096import android.util.proto.ProtoOutputStream;
Filip Gruszczynski170192a2015-08-16 17:46:34 -070097import android.view.AppTransitionAnimationSpec;
Tony Mak64b8d562017-12-28 17:44:02 +000098import android.view.DisplayListCanvas;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010099import android.view.IAppTransitionAnimationSpecsFuture;
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100100import android.view.RemoteAnimationAdapter;
Tony Mak64b8d562017-12-28 17:44:02 +0000101import android.view.RenderNode;
102import android.view.ThreadedRenderer;
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100103import android.view.WindowManager.TransitionFlags;
104import android.view.WindowManager.TransitionType;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800105import android.view.animation.AlphaAnimation;
106import android.view.animation.Animation;
107import android.view.animation.AnimationSet;
108import android.view.animation.AnimationUtils;
Winson Chung399f6202014-03-19 10:47:20 -0700109import android.view.animation.ClipRectAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800110import android.view.animation.Interpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700111import android.view.animation.PathInterpolator;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800112import android.view.animation.ScaleAnimation;
Winson Chung399f6202014-03-19 10:47:20 -0700113import android.view.animation.TranslateAnimation;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700114
Craig Mautner164d4bb2012-11-26 13:51:23 -0800115import com.android.internal.util.DumpUtils.Dump;
116import com.android.server.AttributeCache;
117import com.android.server.wm.WindowManagerService.H;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800118import com.android.server.wm.animation.ClipRectLRAnimation;
119import com.android.server.wm.animation.ClipRectTBAnimation;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100120import com.android.server.wm.animation.CurvedTranslateAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800121
122import java.io.PrintWriter;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100123import java.util.ArrayList;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100124import java.util.concurrent.ExecutorService;
125import java.util.concurrent.Executors;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800126
Craig Mautner164d4bb2012-11-26 13:51:23 -0800127// State management of app transitions. When we are preparing for a
128// transition, mNextAppTransition will be the kind of transition to
129// perform or TRANSIT_NONE if we are not waiting. If we are waiting,
130// mOpeningApps and mClosingApps are the lists of tokens that will be
131// made visible or hidden at the next transition.
132public class AppTransition implements Dump {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800133 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppTransition" : TAG_WM;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700134 private static final int CLIP_REVEAL_TRANSLATION_Y_DP = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800135
Winson Chunga4ccb862014-08-22 15:26:27 -0700136 /** Fraction of animation at which the recents thumbnail stays completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700137 private static final float RECENTS_THUMBNAIL_FADEIN_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800138 /** Fraction of animation at which the recents thumbnail becomes completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700139 private static final float RECENTS_THUMBNAIL_FADEOUT_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800140
Filip Gruszczynski84fa3352016-01-25 16:28:49 -0800141 static final int DEFAULT_APP_TRANSITION_DURATION = 336;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800142
143 /** Interpolator to be used for animations that respond directly to a touch */
144 static final Interpolator TOUCH_RESPONSE_INTERPOLATOR =
145 new PathInterpolator(0.3f, 0f, 0.1f, 1f);
146
Jorim Jaggic69bd222016-03-15 14:38:37 +0100147 private static final Interpolator THUMBNAIL_DOCK_INTERPOLATOR =
148 new PathInterpolator(0.85f, 0f, 1f, 1f);
149
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800150 /**
151 * Maximum duration for the clip reveal animation. This is used when there is a lot of movement
152 * involved, to make it more understandable.
153 */
154 private static final int MAX_CLIP_REVEAL_TRANSITION_DURATION = 420;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700155 private static final int THUMBNAIL_APP_TRANSITION_DURATION = 336;
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700156 private static final long APP_TRANSITION_TIMEOUT_MS = 5000;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800157
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800158 private final Context mContext;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800159 private final WindowManagerService mService;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800160
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100161 private @TransitionType int mNextAppTransition = TRANSIT_UNSET;
162 private @TransitionFlags int mNextAppTransitionFlags = 0;
Chong Zhang60091a92016-07-27 17:52:45 -0700163 private int mLastUsedAppTransition = TRANSIT_UNSET;
164 private String mLastOpeningApp;
165 private String mLastClosingApp;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800166
167 private static final int NEXT_TRANSIT_TYPE_NONE = 0;
168 private static final int NEXT_TRANSIT_TYPE_CUSTOM = 1;
169 private static final int NEXT_TRANSIT_TYPE_SCALE_UP = 2;
170 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP = 3;
171 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN = 4;
Winson Chunga4ccb862014-08-22 15:26:27 -0700172 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP = 5;
173 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN = 6;
Winson Chung044d5292014-11-06 11:05:19 -0800174 private static final int NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE = 7;
Chet Haase10e23ab2015-02-11 15:08:38 -0800175 private static final int NEXT_TRANSIT_TYPE_CLIP_REVEAL = 8;
Tony Mak089c35e2017-12-18 20:34:14 +0000176
177 /**
178 * Refers to the transition to activity started by using {@link
179 * android.content.pm.crossprofile.CrossProfileApps#startMainActivity(ComponentName, UserHandle)
180 * }.
181 */
182 private static final int NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS = 9;
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100183 private static final int NEXT_TRANSIT_TYPE_REMOTE = 10;
184
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800185 private int mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
186
Winson Chung399f6202014-03-19 10:47:20 -0700187 // These are the possible states for the enter/exit activities during a thumbnail transition
188 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_UP = 0;
189 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_UP = 1;
190 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN = 2;
191 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN = 3;
192
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800193 private String mNextAppTransitionPackage;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800194 // Used for thumbnail transitions. True if we're scaling up, false if scaling down
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800195 private boolean mNextAppTransitionScaleUp;
196 private IRemoteCallback mNextAppTransitionCallback;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +0100197 private IRemoteCallback mNextAppTransitionFutureCallback;
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -0700198 private IRemoteCallback mAnimationFinishedCallback;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800199 private int mNextAppTransitionEnter;
200 private int mNextAppTransitionExit;
Winson Chung044d5292014-11-06 11:05:19 -0800201 private int mNextAppTransitionInPlace;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700202
203 // Keyed by task id.
204 private final SparseArray<AppTransitionAnimationSpec> mNextAppTransitionAnimationsSpecs
205 = new SparseArray<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100206 private IAppTransitionAnimationSpecsFuture mNextAppTransitionAnimationsSpecsFuture;
207 private boolean mNextAppTransitionAnimationsSpecsPending;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700208 private AppTransitionAnimationSpec mDefaultNextAppTransitionAnimationSpec;
209
Winson Chunga4ccb862014-08-22 15:26:27 -0700210 private Rect mNextAppTransitionInsets = new Rect();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800211
Winson Chung2820c452014-04-15 15:34:44 -0700212 private Rect mTmpFromClipRect = new Rect();
213 private Rect mTmpToClipRect = new Rect();
214
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700215 private final Rect mTmpRect = new Rect();
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700216
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800217 private final static int APP_STATE_IDLE = 0;
218 private final static int APP_STATE_READY = 1;
219 private final static int APP_STATE_RUNNING = 2;
220 private final static int APP_STATE_TIMEOUT = 3;
221 private int mAppTransitionState = APP_STATE_IDLE;
222
223 private final int mConfigShortAnimTime;
Craig Mautner321bdf52012-12-18 09:53:24 -0800224 private final Interpolator mDecelerateInterpolator;
Winson Chunga4ccb862014-08-22 15:26:27 -0700225 private final Interpolator mThumbnailFadeInInterpolator;
226 private final Interpolator mThumbnailFadeOutInterpolator;
Chet Haase10e23ab2015-02-11 15:08:38 -0800227 private final Interpolator mLinearOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700228 private final Interpolator mFastOutLinearInInterpolator;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100229 private final Interpolator mFastOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700230 private final Interpolator mClipHorizontalInterpolator = new PathInterpolator(0, 0, 0.4f, 1f);
231
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700232 private final int mClipRevealTranslationY;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800233
Amith Yamasani4befbec2013-07-10 16:18:01 -0700234 private int mCurrentUserId = 0;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800235 private long mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Amith Yamasani4befbec2013-07-10 16:18:01 -0700236
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100237 private final ArrayList<AppTransitionListener> mListeners = new ArrayList<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100238 private final ExecutorService mDefaultExecutor = Executors.newSingleThreadExecutor();
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100239
Jorim Jaggif97ed922016-02-18 18:57:07 -0800240 private int mLastClipRevealMaxTranslation;
241 private boolean mLastHadClipReveal;
Jorim Jaggi363ab982016-04-26 19:51:20 -0700242 private boolean mProlongedAnimationsEnded;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800243
Manu Cornetd7376802017-01-13 13:44:07 -0800244 private final boolean mGridLayoutRecentsEnabled;
Matthew Ng43db6d22017-06-27 15:29:39 -0700245 private final boolean mLowRamRecentsEnabled;
Manu Cornetd7376802017-01-13 13:44:07 -0800246
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100247 private RemoteAnimationController mRemoteAnimationController;
248
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800249 AppTransition(Context context, WindowManagerService service) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800250 mContext = context;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800251 mService = service;
Chet Haase10e23ab2015-02-11 15:08:38 -0800252 mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
253 com.android.internal.R.interpolator.linear_out_slow_in);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700254 mFastOutLinearInInterpolator = AnimationUtils.loadInterpolator(context,
255 com.android.internal.R.interpolator.fast_out_linear_in);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100256 mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
257 com.android.internal.R.interpolator.fast_out_slow_in);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800258 mConfigShortAnimTime = context.getResources().getInteger(
259 com.android.internal.R.integer.config_shortAnimTime);
Craig Mautner321bdf52012-12-18 09:53:24 -0800260 mDecelerateInterpolator = AnimationUtils.loadInterpolator(context,
261 com.android.internal.R.interpolator.decelerate_cubic);
Winson Chunga4ccb862014-08-22 15:26:27 -0700262 mThumbnailFadeInInterpolator = new Interpolator() {
263 @Override
264 public float getInterpolation(float input) {
265 // Linear response for first fraction, then complete after that.
266 if (input < RECENTS_THUMBNAIL_FADEIN_FRACTION) {
267 return 0f;
268 }
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700269 float t = (input - RECENTS_THUMBNAIL_FADEIN_FRACTION) /
Winson Chunga4ccb862014-08-22 15:26:27 -0700270 (1f - RECENTS_THUMBNAIL_FADEIN_FRACTION);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700271 return mFastOutLinearInInterpolator.getInterpolation(t);
Winson Chunga4ccb862014-08-22 15:26:27 -0700272 }
273 };
274 mThumbnailFadeOutInterpolator = new Interpolator() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800275 @Override
276 public float getInterpolation(float input) {
277 // Linear response for first fraction, then complete after that.
278 if (input < RECENTS_THUMBNAIL_FADEOUT_FRACTION) {
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700279 float t = input / RECENTS_THUMBNAIL_FADEOUT_FRACTION;
280 return mLinearOutSlowInInterpolator.getInterpolation(t);
Craig Mautner321bdf52012-12-18 09:53:24 -0800281 }
Winson Chunga4ccb862014-08-22 15:26:27 -0700282 return 1f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800283 }
284 };
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700285 mClipRevealTranslationY = (int) (CLIP_REVEAL_TRANSLATION_Y_DP
286 * mContext.getResources().getDisplayMetrics().density);
Manu Cornetd7376802017-01-13 13:44:07 -0800287 mGridLayoutRecentsEnabled = SystemProperties.getBoolean("ro.recents.grid", false);
Matthew Ng43db6d22017-06-27 15:29:39 -0700288 mLowRamRecentsEnabled = ActivityManager.isLowRamDeviceStatic();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800289 }
290
291 boolean isTransitionSet() {
292 return mNextAppTransition != TRANSIT_UNSET;
293 }
294
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100295 boolean isTransitionEqual(@TransitionType int transit) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800296 return mNextAppTransition == transit;
297 }
298
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100299 @TransitionType int getAppTransition() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800300 return mNextAppTransition;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800301 }
302
Jorim Jaggife762342016-10-13 14:33:27 +0200303 private void setAppTransition(int transit, int flags) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800304 mNextAppTransition = transit;
Jorim Jaggife762342016-10-13 14:33:27 +0200305 mNextAppTransitionFlags |= flags;
Chong Zhang60091a92016-07-27 17:52:45 -0700306 setLastAppTransition(TRANSIT_UNSET, null, null);
Jorim Jaggi245281c2017-06-07 14:33:04 -0700307 updateBooster();
Chong Zhang60091a92016-07-27 17:52:45 -0700308 }
309
310 void setLastAppTransition(int transit, AppWindowToken openingApp, AppWindowToken closingApp) {
311 mLastUsedAppTransition = transit;
312 mLastOpeningApp = "" + openingApp;
313 mLastClosingApp = "" + closingApp;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800314 }
315
316 boolean isReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800317 return mAppTransitionState == APP_STATE_READY
318 || mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800319 }
320
Craig Mautnerae446592012-12-06 19:05:05 -0800321 void setReady() {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700322 setAppTransitionState(APP_STATE_READY);
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100323 fetchAppTransitionSpecsFromFuture();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800324 }
325
326 boolean isRunning() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800327 return mAppTransitionState == APP_STATE_RUNNING;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800328 }
329
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800330 void setIdle() {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700331 setAppTransitionState(APP_STATE_IDLE);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800332 }
333
334 boolean isTimeout() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800335 return mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800336 }
337
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800338 void setTimeout() {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700339 setAppTransitionState(APP_STATE_TIMEOUT);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800340 }
341
Winson Chungaa7fa012017-05-24 15:50:06 -0700342 GraphicBuffer getAppTransitionThumbnailHeader(int taskId) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700343 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800344 if (spec == null) {
345 spec = mDefaultNextAppTransitionAnimationSpec;
346 }
Winson Chungaa7fa012017-05-24 15:50:06 -0700347 return spec != null ? spec.buffer : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800348 }
349
Winson Chunga4ccb862014-08-22 15:26:27 -0700350 /** Returns whether the next thumbnail transition is aspect scaled up. */
351 boolean isNextThumbnailTransitionAspectScaled() {
352 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
353 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
354 }
355
356 /** Returns whether the next thumbnail transition is scaling up. */
357 boolean isNextThumbnailTransitionScaleUp() {
358 return mNextAppTransitionScaleUp;
359 }
360
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -0800361 boolean isNextAppTransitionThumbnailUp() {
362 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
363 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP;
364 }
365
366 boolean isNextAppTransitionThumbnailDown() {
367 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN ||
368 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
369 }
370
Tony Mak64b8d562017-12-28 17:44:02 +0000371
372 boolean isNextAppTransitionOpenCrossProfileApps() {
373 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS;
374 }
375
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100376 /**
377 * @return true if and only if we are currently fetching app transition specs from the future
378 * passed into {@link #overridePendingAppTransitionMultiThumbFuture}
379 */
380 boolean isFetchingAppTransitionsSpecs() {
381 return mNextAppTransitionAnimationsSpecsPending;
382 }
383
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700384 private boolean prepare() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800385 if (!isRunning()) {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700386 setAppTransitionState(APP_STATE_IDLE);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100387 notifyAppTransitionPendingLocked();
Jorim Jaggif97ed922016-02-18 18:57:07 -0800388 mLastHadClipReveal = false;
389 mLastClipRevealMaxTranslation = 0;
390 mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700391 return true;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800392 }
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700393 return false;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800394 }
395
Jorim Jaggife762342016-10-13 14:33:27 +0200396 /**
397 * @return bit-map of WindowManagerPolicy#FINISH_LAYOUT_REDO_* to indicate whether another
398 * layout pass needs to be done
399 */
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200400 int goodToGo(int transit, AppWindowToken topOpeningApp,
401 AppWindowToken topClosingApp, ArraySet<AppWindowToken> openingApps,
Jorim Jaggife762342016-10-13 14:33:27 +0200402 ArraySet<AppWindowToken> closingApps) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800403 mNextAppTransition = TRANSIT_UNSET;
Jorim Jaggife762342016-10-13 14:33:27 +0200404 mNextAppTransitionFlags = 0;
Jorim Jaggi245281c2017-06-07 14:33:04 -0700405 setAppTransitionState(APP_STATE_RUNNING);
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200406 final AnimationAdapter topOpeningAnim = topOpeningApp != null
407 ? topOpeningApp.getAnimation()
408 : null;
Jorim Jaggife762342016-10-13 14:33:27 +0200409 int redoLayout = notifyAppTransitionStartingLocked(transit,
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200410 topOpeningApp != null ? topOpeningApp.token : null,
411 topClosingApp != null ? topClosingApp.token : null,
412 topOpeningAnim != null ? topOpeningAnim.getDurationHint() : 0,
413 topOpeningAnim != null
414 ? topOpeningAnim.getStatusBarTransitionsStartTime()
415 : SystemClock.uptimeMillis(),
416 AnimationAdapter.STATUS_BAR_TRANSITION_DURATION);
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800417 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Jorim Jaggife762342016-10-13 14:33:27 +0200418 .notifyAppTransitionStarting(openingApps, transit);
Jorim Jaggi363ab982016-04-26 19:51:20 -0700419
420 // Prolong the start for the transition when docking a task from recents, unless recents
421 // ended it already then we don't need to wait.
Jorim Jaggife762342016-10-13 14:33:27 +0200422 if (transit == TRANSIT_DOCK_TASK_FROM_RECENTS && !mProlongedAnimationsEnded) {
Jorim Jaggi363ab982016-04-26 19:51:20 -0700423 for (int i = openingApps.size() - 1; i >= 0; i--) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200424 final AppWindowToken app = openingApps.valueAt(i);
425 app.startDelayingAnimationStart();
Jorim Jaggi363ab982016-04-26 19:51:20 -0700426 }
427 }
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100428 if (mRemoteAnimationController != null) {
429 mRemoteAnimationController.goodToGo();
430 }
Jorim Jaggife762342016-10-13 14:33:27 +0200431 return redoLayout;
Jorim Jaggi363ab982016-04-26 19:51:20 -0700432 }
433
434 /**
435 * Let the transitions manager know that the somebody wanted to end the prolonged animations.
436 */
437 void notifyProlongedAnimationsEnded() {
438 mProlongedAnimationsEnded = true;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800439 }
440
441 void clear() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800442 mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800443 mNextAppTransitionPackage = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700444 mNextAppTransitionAnimationsSpecs.clear();
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100445 mRemoteAnimationController = null;
Jorim Jaggi65193992015-11-23 16:49:59 -0800446 mNextAppTransitionAnimationsSpecsFuture = null;
447 mDefaultNextAppTransitionAnimationSpec = null;
448 mAnimationFinishedCallback = null;
Jorim Jaggi363ab982016-04-26 19:51:20 -0700449 mProlongedAnimationsEnded = false;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800450 }
451
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800452 void freeze() {
Jorim Jaggife762342016-10-13 14:33:27 +0200453 final int transit = mNextAppTransition;
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100454 setAppTransition(TRANSIT_UNSET, 0 /* flags */);
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800455 clear();
456 setReady();
Jorim Jaggife762342016-10-13 14:33:27 +0200457 notifyAppTransitionCancelledLocked(transit);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100458 }
459
Jorim Jaggi245281c2017-06-07 14:33:04 -0700460 private void setAppTransitionState(int state) {
461 mAppTransitionState = state;
462 updateBooster();
463 }
464
465 /**
466 * Updates whether we currently boost wm locked sections and the animation thread. We want to
467 * boost the priorities to a more important value whenever an app transition is going to happen
468 * soon or an app transition is running.
469 */
470 private void updateBooster() {
471 WindowManagerService.sThreadPriorityBooster.setAppTransitionRunning(
472 mNextAppTransition != TRANSIT_UNSET || mAppTransitionState == APP_STATE_READY
473 || mAppTransitionState == APP_STATE_RUNNING);
474 }
475
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100476 void registerListenerLocked(AppTransitionListener listener) {
477 mListeners.add(listener);
478 }
479
Wale Ogunwalea48eadb2015-05-14 17:43:12 -0700480 public void notifyAppTransitionFinishedLocked(IBinder token) {
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100481 for (int i = 0; i < mListeners.size(); i++) {
482 mListeners.get(i).onAppTransitionFinishedLocked(token);
483 }
484 }
485
486 private void notifyAppTransitionPendingLocked() {
487 for (int i = 0; i < mListeners.size(); i++) {
488 mListeners.get(i).onAppTransitionPendingLocked();
489 }
490 }
491
Jorim Jaggife762342016-10-13 14:33:27 +0200492 private void notifyAppTransitionCancelledLocked(int transit) {
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100493 for (int i = 0; i < mListeners.size(); i++) {
Jorim Jaggife762342016-10-13 14:33:27 +0200494 mListeners.get(i).onAppTransitionCancelledLocked(transit);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100495 }
496 }
497
Jorim Jaggife762342016-10-13 14:33:27 +0200498 private int notifyAppTransitionStartingLocked(int transit, IBinder openToken,
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200499 IBinder closeToken, long duration, long statusBarAnimationStartTime,
500 long statusBarAnimationDuration) {
Jorim Jaggife762342016-10-13 14:33:27 +0200501 int redoLayout = 0;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100502 for (int i = 0; i < mListeners.size(); i++) {
Jorim Jaggife762342016-10-13 14:33:27 +0200503 redoLayout |= mListeners.get(i).onAppTransitionStartingLocked(transit, openToken,
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200504 closeToken, duration, statusBarAnimationStartTime, statusBarAnimationDuration);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100505 }
Jorim Jaggife762342016-10-13 14:33:27 +0200506 return redoLayout;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800507 }
508
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100509 private AttributeCache.Entry getCachedAnimations(LayoutParams lp) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800510 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg="
511 + (lp != null ? lp.packageName : null)
512 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
513 if (lp != null && lp.windowAnimations != 0) {
514 // If this is a system resource, don't try to load it from the
515 // application resources. It is nice to avoid loading application
516 // resources if we can.
517 String packageName = lp.packageName != null ? lp.packageName : "android";
518 int resId = lp.windowAnimations;
519 if ((resId&0xFF000000) == 0x01000000) {
520 packageName = "android";
521 }
522 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
523 + packageName);
524 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700525 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800526 }
527 return null;
528 }
529
530 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
531 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package="
532 + packageName + " resId=0x" + Integer.toHexString(resId));
533 if (packageName != null) {
534 if ((resId&0xFF000000) == 0x01000000) {
535 packageName = "android";
536 }
537 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
538 + packageName);
539 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700540 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800541 }
542 return null;
543 }
544
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100545 Animation loadAnimationAttr(LayoutParams lp, int animAttr) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800546 int anim = 0;
547 Context context = mContext;
548 if (animAttr >= 0) {
549 AttributeCache.Entry ent = getCachedAnimations(lp);
550 if (ent != null) {
551 context = ent.context;
552 anim = ent.array.getResourceId(animAttr, 0);
553 }
554 }
555 if (anim != 0) {
556 return AnimationUtils.loadAnimation(context, anim);
557 }
558 return null;
559 }
560
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100561 Animation loadAnimationRes(LayoutParams lp, int resId) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700562 Context context = mContext;
563 if (resId >= 0) {
564 AttributeCache.Entry ent = getCachedAnimations(lp);
565 if (ent != null) {
566 context = ent.context;
567 }
568 return AnimationUtils.loadAnimation(context, resId);
569 }
570 return null;
571 }
572
573 private Animation loadAnimationRes(String packageName, int resId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800574 int anim = 0;
575 Context context = mContext;
576 if (resId >= 0) {
577 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
578 if (ent != null) {
579 context = ent.context;
580 anim = resId;
581 }
582 }
583 if (anim != 0) {
584 return AnimationUtils.loadAnimation(context, anim);
585 }
586 return null;
587 }
588
Craig Mautner164d4bb2012-11-26 13:51:23 -0800589 /**
590 * Compute the pivot point for an animation that is scaling from a small
591 * rect on screen to a larger rect. The pivot point varies depending on
592 * the distance between the inner and outer edges on both sides. This
593 * function computes the pivot point for one dimension.
594 * @param startPos Offset from left/top edge of outer rectangle to
595 * left/top edge of inner rectangle.
596 * @param finalScale The scaling factor between the size of the outer
597 * and inner rectangles.
598 */
599 private static float computePivot(int startPos, float finalScale) {
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800600
601 /*
602 Theorem of intercepting lines:
603
604 + + +-----------------------------------------------+
605 | | | |
606 | | | |
607 | | | |
608 | | | |
609 x | y | | |
610 | | | |
611 | | | |
612 | | | |
613 | | | |
614 | + | +--------------------+ |
615 | | | | |
616 | | | | |
617 | | | | |
618 | | | | |
619 | | | | |
620 | | | | |
621 | | | | |
622 | | | | |
623 | | | | |
624 | | | | |
625 | | | | |
626 | | | | |
627 | | | | |
628 | | | | |
629 | | | | |
630 | | | | |
631 | | | | |
632 | | +--------------------+ |
633 | | |
634 | | |
635 | | |
636 | | |
637 | | |
638 | | |
639 | | |
640 | +-----------------------------------------------+
641 |
642 |
643 |
644 |
645 |
646 |
647 |
648 |
649 |
650 + ++
651 p ++
652
653 scale = (x - y) / x
654 <=> x = -y / (scale - 1)
655 */
Craig Mautner164d4bb2012-11-26 13:51:23 -0800656 final float denom = finalScale-1;
657 if (Math.abs(denom) < .0001f) {
658 return startPos;
659 }
660 return -startPos / denom;
661 }
662
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700663 private Animation createScaleUpAnimationLocked(int transit, boolean enter,
664 Rect containingFrame) {
665 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700666 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700667 final int appWidth = containingFrame.width();
668 final int appHeight = containingFrame.height();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800669 if (enter) {
670 // Entering app zooms out from the center of the initial rect.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700671 float scaleW = mTmpRect.width() / (float) appWidth;
672 float scaleH = mTmpRect.height() / (float) appHeight;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800673 Animation scale = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700674 computePivot(mTmpRect.left, scaleW),
Winson4c3fecd2016-07-13 12:29:48 -0700675 computePivot(mTmpRect.top, scaleH));
Craig Mautner321bdf52012-12-18 09:53:24 -0800676 scale.setInterpolator(mDecelerateInterpolator);
677
Craig Mautner164d4bb2012-11-26 13:51:23 -0800678 Animation alpha = new AlphaAnimation(0, 1);
Winson Chunga4ccb862014-08-22 15:26:27 -0700679 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
Craig Mautner321bdf52012-12-18 09:53:24 -0800680
681 AnimationSet set = new AnimationSet(false);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800682 set.addAnimation(scale);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800683 set.addAnimation(alpha);
684 set.setDetachWallpaper(true);
685 a = set;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800686 } else if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
687 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800688 // If we are on top of the wallpaper, we need an animation that
689 // correctly handles the wallpaper staying static behind all of
690 // the animated elements. To do this, will just have the existing
691 // element fade out.
692 a = new AlphaAnimation(1, 0);
693 a.setDetachWallpaper(true);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800694 } else {
Craig Mautner321bdf52012-12-18 09:53:24 -0800695 // For normal animations, the exiting element just holds in place.
696 a = new AlphaAnimation(1, 1);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800697 }
Craig Mautner321bdf52012-12-18 09:53:24 -0800698
699 // Pick the desired duration. If this is an inter-activity transition,
700 // it is the standard duration for that. Otherwise we use the longer
701 // task transition duration.
702 final long duration;
703 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800704 case TRANSIT_ACTIVITY_OPEN:
705 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800706 duration = mConfigShortAnimTime;
707 break;
708 default:
709 duration = DEFAULT_APP_TRANSITION_DURATION;
710 break;
711 }
712 a.setDuration(duration);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800713 a.setFillAfter(true);
Craig Mautner321bdf52012-12-18 09:53:24 -0800714 a.setInterpolator(mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800715 a.initialize(appWidth, appHeight, appWidth, appHeight);
716 return a;
717 }
718
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700719 private void getDefaultNextAppTransitionStartRect(Rect rect) {
720 if (mDefaultNextAppTransitionAnimationSpec == null ||
721 mDefaultNextAppTransitionAnimationSpec.rect == null) {
Jorim Jaggi2550f3f2017-03-14 20:15:59 +0100722 Slog.e(TAG, "Starting rect for app requested, but none available", new Throwable());
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700723 rect.setEmpty();
724 } else {
725 rect.set(mDefaultNextAppTransitionAnimationSpec.rect);
726 }
727 }
728
729 void getNextAppTransitionStartRect(int taskId, Rect rect) {
730 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800731 if (spec == null) {
732 spec = mDefaultNextAppTransitionAnimationSpec;
733 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700734 if (spec == null || spec.rect == null) {
Jorim Jaggi2550f3f2017-03-14 20:15:59 +0100735 Slog.e(TAG, "Starting rect for task: " + taskId + " requested, but not available",
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700736 new Throwable());
737 rect.setEmpty();
738 } else {
739 rect.set(spec.rect);
740 }
741 }
742
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800743 private void putDefaultNextAppTransitionCoordinates(int left, int top, int width, int height,
Winson Chungaa7fa012017-05-24 15:50:06 -0700744 GraphicBuffer buffer) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700745 mDefaultNextAppTransitionAnimationSpec = new AppTransitionAnimationSpec(-1 /* taskId */,
Winson Chungaa7fa012017-05-24 15:50:06 -0700746 buffer, new Rect(left, top, left + width, top + height));
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700747 }
748
Jorim Jaggif97ed922016-02-18 18:57:07 -0800749 /**
750 * @return the duration of the last clip reveal animation
751 */
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800752 long getLastClipRevealTransitionDuration() {
753 return mLastClipRevealTransitionDuration;
754 }
755
756 /**
Jorim Jaggif97ed922016-02-18 18:57:07 -0800757 * @return the maximum distance the app surface is traveling of the last clip reveal animation
758 */
759 int getLastClipRevealMaxTranslation() {
760 return mLastClipRevealMaxTranslation;
761 }
762
763 /**
764 * @return true if in the last app transition had a clip reveal animation, false otherwise
765 */
766 boolean hadClipRevealAnimation() {
767 return mLastHadClipReveal;
768 }
769
770 /**
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800771 * Calculates the duration for the clip reveal animation. If the clip is "cut off", meaning that
772 * the start rect is outside of the target rect, and there is a lot of movement going on.
773 *
774 * @param cutOff whether the start rect was not fully contained by the end rect
775 * @param translationX the total translation the surface moves in x direction
776 * @param translationY the total translation the surfaces moves in y direction
777 * @param displayFrame our display frame
778 *
779 * @return the duration of the clip reveal animation, in milliseconds
780 */
781 private long calculateClipRevealTransitionDuration(boolean cutOff, float translationX,
782 float translationY, Rect displayFrame) {
783 if (!cutOff) {
784 return DEFAULT_APP_TRANSITION_DURATION;
785 }
786 final float fraction = Math.max(Math.abs(translationX) / displayFrame.width(),
787 Math.abs(translationY) / displayFrame.height());
788 return (long) (DEFAULT_APP_TRANSITION_DURATION + fraction *
789 (MAX_CLIP_REVEAL_TRANSITION_DURATION - DEFAULT_APP_TRANSITION_DURATION));
790 }
791
792 private Animation createClipRevealAnimationLocked(int transit, boolean enter, Rect appFrame,
793 Rect displayFrame) {
Chet Haase10e23ab2015-02-11 15:08:38 -0800794 final Animation anim;
795 if (enter) {
Craig Mautner80b1f642015-04-22 10:59:09 -0700796 final int appWidth = appFrame.width();
797 final int appHeight = appFrame.height();
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800798
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700799 // mTmpRect will contain an area around the launcher icon that was pressed. We will
Filip Gruszczynski82861362015-10-16 14:21:09 -0700800 // clip reveal from that area in the final area of the app.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700801 getDefaultNextAppTransitionStartRect(mTmpRect);
Craig Mautner80b1f642015-04-22 10:59:09 -0700802
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700803 float t = 0f;
804 if (appHeight > 0) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800805 t = (float) mTmpRect.top / displayFrame.height();
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700806 }
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800807 int translationY = mClipRevealTranslationY + (int)(displayFrame.height() / 7f * t);
808 int translationX = 0;
809 int translationYCorrection = translationY;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700810 int centerX = mTmpRect.centerX();
811 int centerY = mTmpRect.centerY();
812 int halfWidth = mTmpRect.width() / 2;
813 int halfHeight = mTmpRect.height() / 2;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800814 int clipStartX = centerX - halfWidth - appFrame.left;
815 int clipStartY = centerY - halfHeight - appFrame.top;
816 boolean cutOff = false;
817
818 // If the starting rectangle is fully or partially outside of the target rectangle, we
819 // need to start the clipping at the edge and then achieve the rest with translation
820 // and extending the clip rect from that edge.
821 if (appFrame.top > centerY - halfHeight) {
822 translationY = (centerY - halfHeight) - appFrame.top;
823 translationYCorrection = 0;
824 clipStartY = 0;
825 cutOff = true;
826 }
827 if (appFrame.left > centerX - halfWidth) {
828 translationX = (centerX - halfWidth) - appFrame.left;
829 clipStartX = 0;
830 cutOff = true;
831 }
832 if (appFrame.right < centerX + halfWidth) {
833 translationX = (centerX + halfWidth) - appFrame.right;
834 clipStartX = appWidth - mTmpRect.width();
835 cutOff = true;
836 }
837 final long duration = calculateClipRevealTransitionDuration(cutOff, translationX,
838 translationY, displayFrame);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700839
840 // Clip third of the from size of launch icon, expand to full width/height
Chet Haase10e23ab2015-02-11 15:08:38 -0800841 Animation clipAnimLR = new ClipRectLRAnimation(
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800842 clipStartX, clipStartX + mTmpRect.width(), 0, appWidth);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700843 clipAnimLR.setInterpolator(mClipHorizontalInterpolator);
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800844 clipAnimLR.setDuration((long) (duration / 2.5f));
Filip Gruszczynski82861362015-10-16 14:21:09 -0700845
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800846 TranslateAnimation translate = new TranslateAnimation(translationX, 0, translationY, 0);
847 translate.setInterpolator(cutOff ? TOUCH_RESPONSE_INTERPOLATOR
848 : mLinearOutSlowInInterpolator);
849 translate.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800850
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800851 Animation clipAnimTB = new ClipRectTBAnimation(
852 clipStartY, clipStartY + mTmpRect.height(),
853 0, appHeight,
854 translationYCorrection, 0,
855 mLinearOutSlowInInterpolator);
856 clipAnimTB.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
857 clipAnimTB.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800858
859 // Quick fade-in from icon to app window
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800860 final long alphaDuration = duration / 4;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700861 AlphaAnimation alpha = new AlphaAnimation(0.5f, 1);
Chet Haase10e23ab2015-02-11 15:08:38 -0800862 alpha.setDuration(alphaDuration);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700863 alpha.setInterpolator(mLinearOutSlowInInterpolator);
Chet Haase10e23ab2015-02-11 15:08:38 -0800864
865 AnimationSet set = new AnimationSet(false);
866 set.addAnimation(clipAnimLR);
867 set.addAnimation(clipAnimTB);
Filip Gruszczynski82861362015-10-16 14:21:09 -0700868 set.addAnimation(translate);
Chet Haase10e23ab2015-02-11 15:08:38 -0800869 set.addAnimation(alpha);
Filip Gruszczynski9e2cf5b2015-07-31 12:20:40 -0700870 set.setZAdjustment(Animation.ZORDER_TOP);
Chet Haase10e23ab2015-02-11 15:08:38 -0800871 set.initialize(appWidth, appHeight, appWidth, appHeight);
872 anim = set;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800873 mLastHadClipReveal = true;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800874 mLastClipRevealTransitionDuration = duration;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800875
876 // If the start rect was full inside the target rect (cutOff == false), we don't need
877 // to store the translation, because it's only used if cutOff == true.
878 mLastClipRevealMaxTranslation = cutOff
879 ? Math.max(Math.abs(translationY), Math.abs(translationX)) : 0;
Chet Haase10e23ab2015-02-11 15:08:38 -0800880 } else {
881 final long duration;
882 switch (transit) {
883 case TRANSIT_ACTIVITY_OPEN:
884 case TRANSIT_ACTIVITY_CLOSE:
885 duration = mConfigShortAnimTime;
886 break;
887 default:
888 duration = DEFAULT_APP_TRANSITION_DURATION;
889 break;
890 }
891 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
892 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
893 // If we are on top of the wallpaper, we need an animation that
894 // correctly handles the wallpaper staying static behind all of
895 // the animated elements. To do this, will just have the existing
896 // element fade out.
897 anim = new AlphaAnimation(1, 0);
898 anim.setDetachWallpaper(true);
899 } else {
900 // For normal animations, the exiting element just holds in place.
901 anim = new AlphaAnimation(1, 1);
902 }
903 anim.setInterpolator(mDecelerateInterpolator);
904 anim.setDuration(duration);
905 anim.setFillAfter(true);
906 }
907 return anim;
908 }
909
Winson Chung399f6202014-03-19 10:47:20 -0700910 /**
911 * Prepares the specified animation with a standard duration, interpolator, etc.
912 */
Winson Chung5393dff2014-05-08 14:25:43 -0700913 Animation prepareThumbnailAnimationWithDuration(Animation a, int appWidth, int appHeight,
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100914 long duration, Interpolator interpolator) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700915 if (duration > 0) {
916 a.setDuration(duration);
917 }
Winson Chung5393dff2014-05-08 14:25:43 -0700918 a.setFillAfter(true);
Jorim Jaggic69bd222016-03-15 14:38:37 +0100919 if (interpolator != null) {
920 a.setInterpolator(interpolator);
921 }
Winson Chung5393dff2014-05-08 14:25:43 -0700922 a.initialize(appWidth, appHeight, appWidth, appHeight);
923 return a;
924 }
925
926 /**
927 * Prepares the specified animation with a standard duration, interpolator, etc.
928 */
Winson Chung399f6202014-03-19 10:47:20 -0700929 Animation prepareThumbnailAnimation(Animation a, int appWidth, int appHeight, int transit) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800930 // Pick the desired duration. If this is an inter-activity transition,
931 // it is the standard duration for that. Otherwise we use the longer
932 // task transition duration.
Winson Chung5393dff2014-05-08 14:25:43 -0700933 final int duration;
Craig Mautner321bdf52012-12-18 09:53:24 -0800934 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800935 case TRANSIT_ACTIVITY_OPEN:
936 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800937 duration = mConfigShortAnimTime;
938 break;
939 default:
940 duration = DEFAULT_APP_TRANSITION_DURATION;
941 break;
942 }
Winson Chung5393dff2014-05-08 14:25:43 -0700943 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, duration,
944 mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800945 }
946
Winson Chung399f6202014-03-19 10:47:20 -0700947 /**
948 * Return the current thumbnail transition state.
949 */
950 int getThumbnailTransitionState(boolean enter) {
951 if (enter) {
952 if (mNextAppTransitionScaleUp) {
953 return THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
954 } else {
955 return THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN;
956 }
957 } else {
958 if (mNextAppTransitionScaleUp) {
959 return THUMBNAIL_TRANSITION_EXIT_SCALE_UP;
960 } else {
961 return THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN;
962 }
963 }
964 }
965
966 /**
Tony Mak64b8d562017-12-28 17:44:02 +0000967 * Creates an overlay with a background color and a thumbnail for the cross profile apps
968 * animation.
969 */
970 GraphicBuffer createCrossProfileAppsThumbnail(
971 @DrawableRes int thumbnailDrawableRes, Rect frame) {
972 final int width = frame.width();
973 final int height = frame.height();
974
975 final RenderNode node = RenderNode.create("CrossProfileAppsThumbnail", null);
976 node.setLeftTopRightBottom(0, 0, width, height);
977 node.setClipToBounds(false);
978
979 final DisplayListCanvas canvas = node.start(width, height);
980 canvas.drawColor(Color.argb(0.6f, 0, 0, 0));
981 final int thumbnailSize = mService.mContext.getResources().getDimensionPixelSize(
982 com.android.internal.R.dimen.cross_profile_apps_thumbnail_size);
983 final Drawable drawable = mService.mContext.getDrawable(thumbnailDrawableRes);
984 drawable.setBounds(
985 (width - thumbnailSize) / 2,
986 (height - thumbnailSize) / 2,
987 (width + thumbnailSize) / 2,
988 (height + thumbnailSize) / 2);
989 drawable.draw(canvas);
990 node.end(canvas);
991
992 return ThreadedRenderer.createHardwareBitmap(node, width, height)
993 .createGraphicBufferHandle();
994 }
995
996 Animation createCrossProfileAppsThumbnailAnimationLocked(Rect appRect) {
997 final Animation animation = loadAnimationRes(
998 "android", com.android.internal.R.anim.cross_profile_apps_thumbnail_enter);
999 return prepareThumbnailAnimationWithDuration(animation, appRect.width(),
1000 appRect.height(), 0, null);
1001 }
1002
1003 /**
Winson Chung399f6202014-03-19 10:47:20 -07001004 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001005 * when a thumbnail is specified with the pending animation override.
Winson Chung399f6202014-03-19 10:47:20 -07001006 */
Jorim Jaggide63d442016-03-14 14:56:56 +01001007 Animation createThumbnailAspectScaleAnimationLocked(Rect appRect, @Nullable Rect contentInsets,
Winson Chungaa7fa012017-05-24 15:50:06 -07001008 GraphicBuffer thumbnailHeader, final int taskId, int uiMode, int orientation) {
Winson Chung399f6202014-03-19 10:47:20 -07001009 Animation a;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001010 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chung399f6202014-03-19 10:47:20 -07001011 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001012 final int thumbHeightI = thumbnailHeader.getHeight();
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -07001013 final int appWidth = appRect.width();
Winson Chung399f6202014-03-19 10:47:20 -07001014
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -07001015 float scaleW = appWidth / thumbWidth;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001016 getNextAppTransitionStartRect(taskId, mTmpRect);
Jorim Jaggi09072002016-03-25 16:48:42 -07001017 final float fromX;
Manu Cornet57b61492017-01-24 18:19:05 +09001018 float fromY;
Jorim Jaggi09072002016-03-25 16:48:42 -07001019 final float toX;
Manu Cornet57b61492017-01-24 18:19:05 +09001020 float toY;
Jorim Jaggi09072002016-03-25 16:48:42 -07001021 final float pivotX;
1022 final float pivotY;
Manu Cornetd7376802017-01-13 13:44:07 -08001023 if (shouldScaleDownThumbnailTransition(uiMode, orientation)) {
Jorim Jaggi09072002016-03-25 16:48:42 -07001024 fromX = mTmpRect.left;
1025 fromY = mTmpRect.top;
1026
1027 // For the curved translate animation to work, the pivot points needs to be at the
1028 // same absolute position as the one from the real surface.
1029 toX = mTmpRect.width() / 2 * (scaleW - 1f) + appRect.left;
1030 toY = appRect.height() / 2 * (1 - 1 / scaleW) + appRect.top;
1031 pivotX = mTmpRect.width() / 2;
1032 pivotY = appRect.height() / 2 / scaleW;
Manu Cornet57b61492017-01-24 18:19:05 +09001033 if (mGridLayoutRecentsEnabled) {
1034 // In the grid layout, the header is displayed above the thumbnail instead of
1035 // overlapping it.
1036 fromY -= thumbHeightI;
1037 toY -= thumbHeightI * scaleW;
1038 }
Jorim Jaggi09072002016-03-25 16:48:42 -07001039 } else {
1040 pivotX = 0;
1041 pivotY = 0;
1042 fromX = mTmpRect.left;
1043 fromY = mTmpRect.top;
1044 toX = appRect.left;
1045 toY = appRect.top;
1046 }
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001047 final long duration = getAspectScaleDuration();
1048 final Interpolator interpolator = getAspectScaleInterpolator();
Winson Chung399f6202014-03-19 10:47:20 -07001049 if (mNextAppTransitionScaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001050 // Animation up from the thumbnail to the full screen
Jorim Jaggi8448f332016-03-14 17:50:37 +01001051 Animation scale = new ScaleAnimation(1f, scaleW, 1f, scaleW, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001052 scale.setInterpolator(interpolator);
1053 scale.setDuration(duration);
Jorim Jaggic6c89a82016-01-28 17:48:21 -08001054 Animation alpha = new AlphaAnimation(1f, 0f);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001055 alpha.setInterpolator(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
1056 ? THUMBNAIL_DOCK_INTERPOLATOR : mThumbnailFadeOutInterpolator);
1057 alpha.setDuration(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
1058 ? duration / 2
1059 : duration);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001060 Animation translate = createCurvedMotion(fromX, toX, fromY, toY);
1061 translate.setInterpolator(interpolator);
1062 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -07001063
Jorim Jaggide63d442016-03-14 14:56:56 +01001064 mTmpFromClipRect.set(0, 0, thumbWidthI, thumbHeightI);
1065 mTmpToClipRect.set(appRect);
1066
1067 // Containing frame is in screen space, but we need the clip rect in the
1068 // app space.
1069 mTmpToClipRect.offsetTo(0, 0);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001070 mTmpToClipRect.right = (int) (mTmpToClipRect.right / scaleW);
1071 mTmpToClipRect.bottom = (int) (mTmpToClipRect.bottom / scaleW);
Jorim Jaggide63d442016-03-14 14:56:56 +01001072
1073 if (contentInsets != null) {
Jorim Jaggi8448f332016-03-14 17:50:37 +01001074 mTmpToClipRect.inset((int) (-contentInsets.left * scaleW),
1075 (int) (-contentInsets.top * scaleW),
1076 (int) (-contentInsets.right * scaleW),
1077 (int) (-contentInsets.bottom * scaleW));
Jorim Jaggide63d442016-03-14 14:56:56 +01001078 }
1079
1080 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001081 clipAnim.setInterpolator(interpolator);
1082 clipAnim.setDuration(duration);
Jorim Jaggide63d442016-03-14 14:56:56 +01001083
Winson Chung399f6202014-03-19 10:47:20 -07001084 // This AnimationSet uses the Interpolators assigned above.
1085 AnimationSet set = new AnimationSet(false);
1086 set.addAnimation(scale);
Manu Cornet57b61492017-01-24 18:19:05 +09001087 if (!mGridLayoutRecentsEnabled) {
1088 // In the grid layout, the header should be shown for the whole animation.
1089 set.addAnimation(alpha);
1090 }
Winson Chunga4ccb862014-08-22 15:26:27 -07001091 set.addAnimation(translate);
Jorim Jaggide63d442016-03-14 14:56:56 +01001092 set.addAnimation(clipAnim);
Winson Chung399f6202014-03-19 10:47:20 -07001093 a = set;
1094 } else {
Winson Chunga4ccb862014-08-22 15:26:27 -07001095 // Animation down from the full screen to the thumbnail
Jorim Jaggi8448f332016-03-14 17:50:37 +01001096 Animation scale = new ScaleAnimation(scaleW, 1f, scaleW, 1f, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001097 scale.setInterpolator(interpolator);
1098 scale.setDuration(duration);
Winson Chunga4ccb862014-08-22 15:26:27 -07001099 Animation alpha = new AlphaAnimation(0f, 1f);
1100 alpha.setInterpolator(mThumbnailFadeInInterpolator);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001101 alpha.setDuration(duration);
1102 Animation translate = createCurvedMotion(toX, fromX, toY, fromY);
1103 translate.setInterpolator(interpolator);
1104 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -07001105
Winson Chunga4ccb862014-08-22 15:26:27 -07001106 // This AnimationSet uses the Interpolators assigned above.
1107 AnimationSet set = new AnimationSet(false);
1108 set.addAnimation(scale);
Manu Cornet57b61492017-01-24 18:19:05 +09001109 if (!mGridLayoutRecentsEnabled) {
1110 // In the grid layout, the header should be shown for the whole animation.
1111 set.addAnimation(alpha);
1112 }
Winson Chunga4ccb862014-08-22 15:26:27 -07001113 set.addAnimation(translate);
1114 a = set;
1115
1116 }
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -07001117 return prepareThumbnailAnimationWithDuration(a, appWidth, appRect.height(), 0,
Jorim Jaggic69bd222016-03-15 14:38:37 +01001118 null);
Winson Chung399f6202014-03-19 10:47:20 -07001119 }
1120
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001121 private Animation createCurvedMotion(float fromX, float toX, float fromY, float toY) {
1122
1123 // Almost no x-change - use linear animation
Jorim Jaggic69bd222016-03-15 14:38:37 +01001124 if (Math.abs(toX - fromX) < 1f || mNextAppTransition != TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001125 return new TranslateAnimation(fromX, toX, fromY, toY);
1126 } else {
1127 final Path path = createCurvedPath(fromX, toX, fromY, toY);
1128 return new CurvedTranslateAnimation(path);
1129 }
1130 }
1131
1132 private Path createCurvedPath(float fromX, float toX, float fromY, float toY) {
1133 final Path path = new Path();
1134 path.moveTo(fromX, fromY);
Jorim Jaggi1f458fb2016-03-25 17:36:37 -07001135
1136 if (fromY > toY) {
1137 // If the object needs to go up, move it in horizontal direction first, then vertical.
1138 path.cubicTo(fromX, fromY, toX, 0.9f * fromY + 0.1f * toY, toX, toY);
1139 } else {
1140 // If the object needs to go down, move it in vertical direction first, then horizontal.
1141 path.cubicTo(fromX, fromY, fromX, 0.1f * fromY + 0.9f * toY, toX, toY);
1142 }
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001143 return path;
1144 }
1145
1146 private long getAspectScaleDuration() {
1147 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggic69bd222016-03-15 14:38:37 +01001148 return (long) (THUMBNAIL_APP_TRANSITION_DURATION * 1.35f);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001149 } else {
1150 return THUMBNAIL_APP_TRANSITION_DURATION;
1151 }
1152 }
1153
1154 private Interpolator getAspectScaleInterpolator() {
1155 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
1156 return mFastOutSlowInInterpolator;
1157 } else {
1158 return TOUCH_RESPONSE_INTERPOLATOR;
1159 }
1160 }
1161
Winson Chung399f6202014-03-19 10:47:20 -07001162 /**
1163 * This alternate animation is created when we are doing a thumbnail transition, for the
1164 * activity that is leaving, and the activity that is entering.
1165 */
Winson Chunga4ccb862014-08-22 15:26:27 -07001166 Animation createAspectScaledThumbnailEnterExitAnimationLocked(int thumbTransitState,
Winsonb2024762016-04-05 17:32:30 -07001167 int uiMode, int orientation, int transit, Rect containingFrame, Rect contentInsets,
Matthew Ng43db6d22017-06-27 15:29:39 -07001168 @Nullable Rect surfaceInsets, @Nullable Rect stableInsets, boolean freeform,
1169 int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -07001170 Animation a;
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001171 final int appWidth = containingFrame.width();
1172 final int appHeight = containingFrame.height();
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001173 getDefaultNextAppTransitionStartRect(mTmpRect);
1174 final int thumbWidthI = mTmpRect.width();
Winson Chung399f6202014-03-19 10:47:20 -07001175 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001176 final int thumbHeightI = mTmpRect.height();
Winson Chung399f6202014-03-19 10:47:20 -07001177 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
Winsoncbb625b2016-07-06 15:24:15 -07001178 final int thumbStartX = mTmpRect.left - containingFrame.left - contentInsets.left;
Winson21700932016-03-24 17:26:23 -07001179 final int thumbStartY = mTmpRect.top - containingFrame.top;
Winson Chung399f6202014-03-19 10:47:20 -07001180
1181 switch (thumbTransitState) {
Jorim Jaggi8448f332016-03-14 17:50:37 +01001182 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP:
1183 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1184 final boolean scaleUp = thumbTransitState == THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
1185 if (freeform && scaleUp) {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001186 a = createAspectScaledThumbnailEnterFreeformAnimationLocked(
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001187 containingFrame, surfaceInsets, taskId);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001188 } else if (freeform) {
1189 a = createAspectScaledThumbnailExitFreeformAnimationLocked(
1190 containingFrame, surfaceInsets, taskId);
Winson Chung2820c452014-04-15 15:34:44 -07001191 } else {
Winson21700932016-03-24 17:26:23 -07001192 AnimationSet set = new AnimationSet(true);
1193
1194 // In portrait, we scale to fit the width
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001195 mTmpFromClipRect.set(containingFrame);
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001196 mTmpToClipRect.set(containingFrame);
Jorim Jaggic6c89a82016-01-28 17:48:21 -08001197
1198 // Containing frame is in screen space, but we need the clip rect in the
1199 // app space.
1200 mTmpFromClipRect.offsetTo(0, 0);
1201 mTmpToClipRect.offsetTo(0, 0);
1202
1203 // Exclude insets region from the source clip.
1204 mTmpFromClipRect.inset(contentInsets);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001205 mNextAppTransitionInsets.set(contentInsets);
1206
Manu Cornetd7376802017-01-13 13:44:07 -08001207 if (shouldScaleDownThumbnailTransition(uiMode, orientation)) {
Jorim Jaggic69bd222016-03-15 14:38:37 +01001208 // We scale the width and clip to the top/left square
1209 float scale = thumbWidth /
1210 (appWidth - contentInsets.left - contentInsets.right);
Manu Cornetb68b7652017-01-23 19:37:53 +09001211 if (!mGridLayoutRecentsEnabled) {
1212 int unscaledThumbHeight = (int) (thumbHeight / scale);
1213 mTmpFromClipRect.bottom = mTmpFromClipRect.top + unscaledThumbHeight;
1214 }
Jorim Jaggic69bd222016-03-15 14:38:37 +01001215
1216 mNextAppTransitionInsets.set(contentInsets);
1217
Jorim Jaggi8448f332016-03-14 17:50:37 +01001218 Animation scaleAnim = new ScaleAnimation(
1219 scaleUp ? scale : 1, scaleUp ? 1 : scale,
1220 scaleUp ? scale : 1, scaleUp ? 1 : scale,
Jorim Jaggic69bd222016-03-15 14:38:37 +01001221 containingFrame.width() / 2f,
1222 containingFrame.height() / 2f + contentInsets.top);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001223 final float targetX = (mTmpRect.left - containingFrame.left);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001224 final float x = containingFrame.width() / 2f
1225 - containingFrame.width() / 2f * scale;
Jorim Jaggi8448f332016-03-14 17:50:37 +01001226 final float targetY = (mTmpRect.top - containingFrame.top);
Matthew Ng43db6d22017-06-27 15:29:39 -07001227 float y = containingFrame.height() / 2f
Jorim Jaggic69bd222016-03-15 14:38:37 +01001228 - containingFrame.height() / 2f * scale;
Matthew Ng43db6d22017-06-27 15:29:39 -07001229
1230 // During transition may require clipping offset from any top stable insets
1231 // such as the statusbar height when statusbar is hidden
1232 if (mLowRamRecentsEnabled && contentInsets.top == 0 && scaleUp) {
1233 mTmpFromClipRect.top += stableInsets.top;
1234 y += stableInsets.top;
1235 }
Jorim Jaggi8448f332016-03-14 17:50:37 +01001236 final float startX = targetX - x;
1237 final float startY = targetY - y;
1238 Animation clipAnim = scaleUp
1239 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1240 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1241 Animation translateAnim = scaleUp
Jorim Jaggic69bd222016-03-15 14:38:37 +01001242 ? createCurvedMotion(startX, 0, startY - contentInsets.top, 0)
1243 : createCurvedMotion(0, startX, 0, startY - contentInsets.top);
1244
Winson21700932016-03-24 17:26:23 -07001245 set.addAnimation(clipAnim);
1246 set.addAnimation(scaleAnim);
1247 set.addAnimation(translateAnim);
1248
1249 } else {
1250 // In landscape, we don't scale at all and only crop
1251 mTmpFromClipRect.bottom = mTmpFromClipRect.top + thumbHeightI;
1252 mTmpFromClipRect.right = mTmpFromClipRect.left + thumbWidthI;
1253
Jorim Jaggi8448f332016-03-14 17:50:37 +01001254 Animation clipAnim = scaleUp
1255 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1256 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1257 Animation translateAnim = scaleUp
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001258 ? createCurvedMotion(thumbStartX, 0,
1259 thumbStartY - contentInsets.top, 0)
1260 : createCurvedMotion(0, thumbStartX, 0,
1261 thumbStartY - contentInsets.top);
Winson21700932016-03-24 17:26:23 -07001262
1263 set.addAnimation(clipAnim);
1264 set.addAnimation(translateAnim);
1265 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001266 a = set;
Winson21700932016-03-24 17:26:23 -07001267 a.setZAdjustment(Animation.ZORDER_TOP);
Winson Chung2820c452014-04-15 15:34:44 -07001268 }
Winson Chung399f6202014-03-19 10:47:20 -07001269 break;
1270 }
1271 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001272 // Previous app window during the scale up
Winson Chung399f6202014-03-19 10:47:20 -07001273 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001274 // Fade out the source activity if we are animating to a wallpaper
Winson Chung399f6202014-03-19 10:47:20 -07001275 // activity.
1276 a = new AlphaAnimation(1, 0);
1277 } else {
Winson Chung399f6202014-03-19 10:47:20 -07001278 a = new AlphaAnimation(1, 1);
1279 }
1280 break;
1281 }
1282 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001283 // Target app window during the scale down
1284 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1285 // Fade in the destination activity if we are animating from a wallpaper
1286 // activity.
1287 a = new AlphaAnimation(0, 1);
1288 } else {
1289 a = new AlphaAnimation(1, 1);
1290 }
Winson Chung399f6202014-03-19 10:47:20 -07001291 break;
1292 }
Winson Chung399f6202014-03-19 10:47:20 -07001293 default:
1294 throw new RuntimeException("Invalid thumbnail transition state");
1295 }
1296
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001297 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight,
1298 getAspectScaleDuration(), getAspectScaleInterpolator());
Winson Chung399f6202014-03-19 10:47:20 -07001299 }
1300
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001301 private Animation createAspectScaledThumbnailEnterFreeformAnimationLocked(Rect frame,
1302 @Nullable Rect surfaceInsets, int taskId) {
1303 getNextAppTransitionStartRect(taskId, mTmpRect);
1304 return createAspectScaledThumbnailFreeformAnimationLocked(mTmpRect, frame, surfaceInsets,
1305 true);
1306 }
1307
1308 private Animation createAspectScaledThumbnailExitFreeformAnimationLocked(Rect frame,
1309 @Nullable Rect surfaceInsets, int taskId) {
1310 getNextAppTransitionStartRect(taskId, mTmpRect);
1311 return createAspectScaledThumbnailFreeformAnimationLocked(frame, mTmpRect, surfaceInsets,
1312 false);
1313 }
1314
1315 private AnimationSet createAspectScaledThumbnailFreeformAnimationLocked(Rect sourceFrame,
1316 Rect destFrame, @Nullable Rect surfaceInsets, boolean enter) {
1317 final float sourceWidth = sourceFrame.width();
1318 final float sourceHeight = sourceFrame.height();
1319 final float destWidth = destFrame.width();
1320 final float destHeight = destFrame.height();
1321 final float scaleH = enter ? sourceWidth / destWidth : destWidth / sourceWidth;
1322 final float scaleV = enter ? sourceHeight / destHeight : destHeight / sourceHeight;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001323 AnimationSet set = new AnimationSet(true);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001324 final int surfaceInsetsH = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001325 ? 0 : surfaceInsets.left + surfaceInsets.right;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001326 final int surfaceInsetsV = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001327 ? 0 : surfaceInsets.top + surfaceInsets.bottom;
1328 // We want the scaling to happen from the center of the surface. In order to achieve that,
1329 // we need to account for surface insets that will be used to enlarge the surface.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001330 final float scaleHCenter = ((enter ? destWidth : sourceWidth) + surfaceInsetsH) / 2;
1331 final float scaleVCenter = ((enter ? destHeight : sourceHeight) + surfaceInsetsV) / 2;
1332 final ScaleAnimation scale = enter ?
1333 new ScaleAnimation(scaleH, 1, scaleV, 1, scaleHCenter, scaleVCenter)
1334 : new ScaleAnimation(1, scaleH, 1, scaleV, scaleHCenter, scaleVCenter);
1335 final int sourceHCenter = sourceFrame.left + sourceFrame.width() / 2;
1336 final int sourceVCenter = sourceFrame.top + sourceFrame.height() / 2;
1337 final int destHCenter = destFrame.left + destFrame.width() / 2;
1338 final int destVCenter = destFrame.top + destFrame.height() / 2;
1339 final int fromX = enter ? sourceHCenter - destHCenter : destHCenter - sourceHCenter;
1340 final int fromY = enter ? sourceVCenter - destVCenter : destVCenter - sourceVCenter;
1341 final TranslateAnimation translation = enter ? new TranslateAnimation(fromX, 0, fromY, 0)
1342 : new TranslateAnimation(0, fromX, 0, fromY);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001343 set.addAnimation(scale);
1344 set.addAnimation(translation);
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001345
1346 final IRemoteCallback callback = mAnimationFinishedCallback;
1347 if (callback != null) {
1348 set.setAnimationListener(new Animation.AnimationListener() {
1349 @Override
1350 public void onAnimationStart(Animation animation) { }
1351
1352 @Override
1353 public void onAnimationEnd(Animation animation) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001354 mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK, callback).sendToTarget();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001355 }
1356
1357 @Override
1358 public void onAnimationRepeat(Animation animation) { }
1359 });
1360 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001361 return set;
1362 }
1363
Winson Chung399f6202014-03-19 10:47:20 -07001364 /**
Winson Chunga4ccb862014-08-22 15:26:27 -07001365 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001366 * when a thumbnail is specified with the pending animation override.
Winson Chunga4ccb862014-08-22 15:26:27 -07001367 */
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001368 Animation createThumbnailScaleAnimationLocked(int appWidth, int appHeight, int transit,
Winson Chungaa7fa012017-05-24 15:50:06 -07001369 GraphicBuffer thumbnailHeader) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001370 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001371 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001372 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chunga4ccb862014-08-22 15:26:27 -07001373 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001374 final int thumbHeightI = thumbnailHeader.getHeight();
Winson Chunga4ccb862014-08-22 15:26:27 -07001375 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1376
1377 if (mNextAppTransitionScaleUp) {
1378 // Animation for the thumbnail zooming from its initial size to the full screen
1379 float scaleW = appWidth / thumbWidth;
1380 float scaleH = appHeight / thumbHeight;
1381 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001382 computePivot(mTmpRect.left, 1 / scaleW),
1383 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001384 scale.setInterpolator(mDecelerateInterpolator);
1385
1386 Animation alpha = new AlphaAnimation(1, 0);
1387 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
1388
1389 // This AnimationSet uses the Interpolators assigned above.
1390 AnimationSet set = new AnimationSet(false);
1391 set.addAnimation(scale);
1392 set.addAnimation(alpha);
1393 a = set;
1394 } else {
1395 // Animation for the thumbnail zooming down from the full screen to its final size
1396 float scaleW = appWidth / thumbWidth;
1397 float scaleH = appHeight / thumbHeight;
1398 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001399 computePivot(mTmpRect.left, 1 / scaleW),
1400 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001401 }
1402
1403 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1404 }
1405
1406 /**
Winson Chung399f6202014-03-19 10:47:20 -07001407 * This animation is created when we are doing a thumbnail transition, for the activity that is
1408 * leaving, and the activity that is entering.
1409 */
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001410 Animation createThumbnailEnterExitAnimationLocked(int thumbTransitState, Rect containingFrame,
1411 int transit, int taskId) {
1412 final int appWidth = containingFrame.width();
1413 final int appHeight = containingFrame.height();
Winson Chungaa7fa012017-05-24 15:50:06 -07001414 final GraphicBuffer thumbnailHeader = getAppTransitionThumbnailHeader(taskId);
Winson Chung399f6202014-03-19 10:47:20 -07001415 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001416 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001417 final int thumbWidthI = thumbnailHeader != null ? thumbnailHeader.getWidth() : appWidth;
Winson Chung399f6202014-03-19 10:47:20 -07001418 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001419 final int thumbHeightI = thumbnailHeader != null ? thumbnailHeader.getHeight() : appHeight;
Winson Chung399f6202014-03-19 10:47:20 -07001420 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1421
1422 switch (thumbTransitState) {
1423 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
1424 // Entering app scales up with the thumbnail
1425 float scaleW = thumbWidth / appWidth;
1426 float scaleH = thumbHeight / appHeight;
1427 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001428 computePivot(mTmpRect.left, scaleW),
1429 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001430 break;
1431 }
1432 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
1433 // Exiting app while the thumbnail is scaling up should fade or stay in place
1434 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1435 // Fade out while bringing up selected activity. This keeps the
1436 // current activity from showing through a launching wallpaper
1437 // activity.
1438 a = new AlphaAnimation(1, 0);
1439 } else {
1440 // noop animation
1441 a = new AlphaAnimation(1, 1);
1442 }
1443 break;
1444 }
1445 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
1446 // Entering the other app, it should just be visible while we scale the thumbnail
1447 // down above it
1448 a = new AlphaAnimation(1, 1);
1449 break;
1450 }
1451 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1452 // Exiting the current app, the app should scale down with the thumbnail
1453 float scaleW = thumbWidth / appWidth;
1454 float scaleH = thumbHeight / appHeight;
1455 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001456 computePivot(mTmpRect.left, scaleW),
1457 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001458
1459 Animation alpha = new AlphaAnimation(1, 0);
1460
1461 AnimationSet set = new AnimationSet(true);
1462 set.addAnimation(scale);
1463 set.addAnimation(alpha);
1464 set.setZAdjustment(Animation.ZORDER_TOP);
1465 a = set;
1466 break;
1467 }
1468 default:
1469 throw new RuntimeException("Invalid thumbnail transition state");
1470 }
1471
1472 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1473 }
1474
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001475 private Animation createRelaunchAnimation(Rect containingFrame, Rect contentInsets) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001476 getDefaultNextAppTransitionStartRect(mTmpFromClipRect);
1477 final int left = mTmpFromClipRect.left;
1478 final int top = mTmpFromClipRect.top;
1479 mTmpFromClipRect.offset(-left, -top);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001480 // TODO: Isn't that strange that we ignore exact position of the containingFrame?
1481 mTmpToClipRect.set(0, 0, containingFrame.width(), containingFrame.height());
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001482 AnimationSet set = new AnimationSet(true);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001483 float fromWidth = mTmpFromClipRect.width();
1484 float toWidth = mTmpToClipRect.width();
1485 float fromHeight = mTmpFromClipRect.height();
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001486 // While the window might span the whole display, the actual content will be cropped to the
1487 // system decoration frame, for example when the window is docked. We need to take into
1488 // account the visible height when constructing the animation.
1489 float toHeight = mTmpToClipRect.height() - contentInsets.top - contentInsets.bottom;
1490 int translateAdjustment = 0;
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001491 if (fromWidth <= toWidth && fromHeight <= toHeight) {
1492 // The final window is larger in both dimensions than current window (e.g. we are
1493 // maximizing), so we can simply unclip the new window and there will be no disappearing
1494 // frame.
1495 set.addAnimation(new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect));
1496 } else {
1497 // The disappearing window has one larger dimension. We need to apply scaling, so the
1498 // first frame of the entry animation matches the old window.
1499 set.addAnimation(new ScaleAnimation(fromWidth / toWidth, 1, fromHeight / toHeight, 1));
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001500 // We might not be going exactly full screen, but instead be aligned under the status
1501 // bar using cropping. We still need to account for the cropped part, which will also
1502 // be scaled.
1503 translateAdjustment = (int) (contentInsets.top * fromHeight / toHeight);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001504 }
1505
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001506 // We animate the translation from the old position of the removed window, to the new
1507 // position of the added window. The latter might not be full screen, for example docked for
1508 // docked windows.
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001509 TranslateAnimation translate = new TranslateAnimation(left - containingFrame.left,
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001510 0, top - containingFrame.top - translateAdjustment, 0);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001511 set.addAnimation(translate);
1512 set.setDuration(DEFAULT_APP_TRANSITION_DURATION);
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07001513 set.setZAdjustment(Animation.ZORDER_TOP);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001514 return set;
1515 }
1516
Jorim Jaggic554b772015-06-04 16:07:57 -07001517 /**
1518 * @return true if and only if the first frame of the transition can be skipped, i.e. the first
1519 * frame of the transition doesn't change the visuals on screen, so we can start
1520 * directly with the second one
1521 */
1522 boolean canSkipFirstFrame() {
1523 return mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM
1524 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE
Jorim Jaggife762342016-10-13 14:33:27 +02001525 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CLIP_REVEAL
1526 && mNextAppTransition != TRANSIT_KEYGUARD_GOING_AWAY;
Jorim Jaggic554b772015-06-04 16:07:57 -07001527 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001528
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001529 RemoteAnimationController getRemoteAnimationController() {
1530 return mRemoteAnimationController;
1531 }
1532
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001533 /**
1534 *
1535 * @param frame These are the bounds of the window when it finishes the animation. This is where
1536 * the animation must usually finish in entrance animation, as the next frame will
1537 * display the window at these coordinates. In case of exit animation, this is
1538 * where the animation must start, as the frame before the animation is displaying
1539 * the window at these bounds.
1540 * @param insets Knowing where the window will be positioned is not enough. Some parts of the
1541 * window might be obscured, usually by the system windows (status bar and
1542 * navigation bar) and we use content insets to convey that information. This
1543 * usually affects the animation aspects vertically, as the system decoration is
1544 * at the top and the bottom. For example when we animate from full screen to
1545 * recents, we want to exclude the covered parts, because they won't match the
1546 * thumbnail after the last frame is executed.
1547 * @param surfaceInsets In rare situation the surface is larger than the content and we need to
1548 * know about this to make the animation frames match. We currently use
1549 * this for freeform windows, which have larger surfaces to display
1550 * shadows. When we animate them from recents, we want to match the content
1551 * to the recents thumbnail and hence need to account for the surface being
1552 * bigger.
1553 */
Jorim Jaggif84e2f62018-01-16 14:17:59 +01001554 Animation loadAnimation(LayoutParams lp, int transit, boolean enter, int uiMode,
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001555 int orientation, Rect frame, Rect displayFrame, Rect insets,
Matthew Ng43db6d22017-06-27 15:29:39 -07001556 @Nullable Rect surfaceInsets, @Nullable Rect stableInsets, boolean isVoiceInteraction,
1557 boolean freeform, int taskId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001558 Animation a;
Jorim Jaggife762342016-10-13 14:33:27 +02001559 if (isKeyguardGoingAwayTransit(transit) && enter) {
1560 a = loadKeyguardExitAnimation(transit);
1561 } else if (transit == TRANSIT_KEYGUARD_OCCLUDE) {
1562 a = null;
1563 } else if (transit == TRANSIT_KEYGUARD_UNOCCLUDE && !enter) {
1564 a = loadAnimationRes(lp, com.android.internal.R.anim.wallpaper_open_exit);
1565 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_OPEN
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001566 || transit == TRANSIT_TASK_OPEN
1567 || transit == TRANSIT_TASK_TO_FRONT)) {
1568 a = loadAnimationRes(lp, enter
1569 ? com.android.internal.R.anim.voice_activity_open_enter
1570 : com.android.internal.R.anim.voice_activity_open_exit);
1571 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1572 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001573 + " anim=" + a + " transit=" + appTransitionToString(transit)
1574 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001575 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_CLOSE
1576 || transit == TRANSIT_TASK_CLOSE
1577 || transit == TRANSIT_TASK_TO_BACK)) {
1578 a = loadAnimationRes(lp, enter
1579 ? com.android.internal.R.anim.voice_activity_close_enter
1580 : com.android.internal.R.anim.voice_activity_close_exit);
1581 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1582 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001583 + " anim=" + a + " transit=" + appTransitionToString(transit)
1584 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001585 } else if (transit == TRANSIT_ACTIVITY_RELAUNCH) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001586 a = createRelaunchAnimation(frame, insets);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001587 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1588 "applyAnimation:"
1589 + " anim=" + a + " nextAppTransition=" + mNextAppTransition
1590 + " transit=" + appTransitionToString(transit)
1591 + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001592 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM) {
1593 a = loadAnimationRes(mNextAppTransitionPackage, enter ?
Craig Mautner164d4bb2012-11-26 13:51:23 -08001594 mNextAppTransitionEnter : mNextAppTransitionExit);
1595 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1596 "applyAnimation:"
1597 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001598 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001599 + " Callers=" + Debug.getCallers(3));
Winson Chung044d5292014-11-06 11:05:19 -08001600 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE) {
1601 a = loadAnimationRes(mNextAppTransitionPackage, mNextAppTransitionInPlace);
1602 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1603 "applyAnimation:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001604 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM_IN_PLACE"
1605 + " transit=" + appTransitionToString(transit)
1606 + " Callers=" + Debug.getCallers(3));
Chet Haase10e23ab2015-02-11 15:08:38 -08001607 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001608 a = createClipRevealAnimationLocked(transit, enter, frame, displayFrame);
Chet Haase10e23ab2015-02-11 15:08:38 -08001609 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1610 "applyAnimation:"
1611 + " anim=" + a + " nextAppTransition=ANIM_CLIP_REVEAL"
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001612 + " transit=" + appTransitionToString(transit)
Chet Haase10e23ab2015-02-11 15:08:38 -08001613 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001614 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_SCALE_UP) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001615 a = createScaleUpAnimationLocked(transit, enter, frame);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001616 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1617 "applyAnimation:"
1618 + " anim=" + a + " nextAppTransition=ANIM_SCALE_UP"
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));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001621 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
1622 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001623 mNextAppTransitionScaleUp =
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001624 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP);
Winson Chunga4ccb862014-08-22 15:26:27 -07001625 a = createThumbnailEnterExitAnimationLocked(getThumbnailTransitionState(enter),
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001626 frame, transit, taskId);
Winson Chunga4ccb862014-08-22 15:26:27 -07001627 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1628 String animName = mNextAppTransitionScaleUp ?
1629 "ANIM_THUMBNAIL_SCALE_UP" : "ANIM_THUMBNAIL_SCALE_DOWN";
1630 Slog.v(TAG, "applyAnimation:"
1631 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001632 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Winson Chunga4ccb862014-08-22 15:26:27 -07001633 + " Callers=" + Debug.getCallers(3));
1634 }
1635 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
1636 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN) {
1637 mNextAppTransitionScaleUp =
1638 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP);
1639 a = createAspectScaledThumbnailEnterExitAnimationLocked(
Winsonb2024762016-04-05 17:32:30 -07001640 getThumbnailTransitionState(enter), uiMode, orientation, transit, frame,
Matthew Ng43db6d22017-06-27 15:29:39 -07001641 insets, surfaceInsets, stableInsets, freeform, taskId);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001642 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1643 String animName = mNextAppTransitionScaleUp ?
Winson Chunga4ccb862014-08-22 15:26:27 -07001644 "ANIM_THUMBNAIL_ASPECT_SCALE_UP" : "ANIM_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner164d4bb2012-11-26 13:51:23 -08001645 Slog.v(TAG, "applyAnimation:"
1646 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001647 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001648 + " Callers=" + Debug.getCallers(3));
1649 }
Tony Mak089c35e2017-12-18 20:34:14 +00001650 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS
1651 && (transit == TRANSIT_ACTIVITY_OPEN
1652 || transit == TRANSIT_TASK_OPEN
1653 || transit == TRANSIT_TASK_TO_FRONT)) {
Tony Mak64b8d562017-12-28 17:44:02 +00001654
Tony Mak089c35e2017-12-18 20:34:14 +00001655 a = loadAnimationRes("android", enter
Tony Mak64b8d562017-12-28 17:44:02 +00001656 ? com.android.internal.R.anim.task_open_enter_cross_profile_apps
1657 : com.android.internal.R.anim.task_open_exit);
Tony Mak089c35e2017-12-18 20:34:14 +00001658 Slog.v(TAG,
1659 "applyAnimation NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS:"
1660 + " anim=" + a + " transit=" + appTransitionToString(transit)
1661 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Craig Mautner164d4bb2012-11-26 13:51:23 -08001662 } else {
1663 int animAttr = 0;
1664 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001665 case TRANSIT_ACTIVITY_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001666 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001667 ? WindowAnimation_activityOpenEnterAnimation
1668 : WindowAnimation_activityOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001669 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001670 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001671 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001672 ? WindowAnimation_activityCloseEnterAnimation
1673 : WindowAnimation_activityCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001674 break;
Jorim Jaggi192086e2016-03-11 17:17:03 +01001675 case TRANSIT_DOCK_TASK_FROM_RECENTS:
Craig Mautner4b71aa12012-12-27 17:20:01 -08001676 case TRANSIT_TASK_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001677 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001678 ? WindowAnimation_taskOpenEnterAnimation
1679 : WindowAnimation_taskOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001680 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001681 case TRANSIT_TASK_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001682 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001683 ? WindowAnimation_taskCloseEnterAnimation
1684 : WindowAnimation_taskCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001685 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001686 case TRANSIT_TASK_TO_FRONT:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001687 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001688 ? WindowAnimation_taskToFrontEnterAnimation
1689 : WindowAnimation_taskToFrontExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001690 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001691 case TRANSIT_TASK_TO_BACK:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001692 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001693 ? WindowAnimation_taskToBackEnterAnimation
1694 : WindowAnimation_taskToBackExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001695 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001696 case TRANSIT_WALLPAPER_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001697 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001698 ? WindowAnimation_wallpaperOpenEnterAnimation
1699 : WindowAnimation_wallpaperOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001700 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001701 case TRANSIT_WALLPAPER_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001702 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001703 ? WindowAnimation_wallpaperCloseEnterAnimation
1704 : WindowAnimation_wallpaperCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001705 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001706 case TRANSIT_WALLPAPER_INTRA_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001707 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001708 ? WindowAnimation_wallpaperIntraOpenEnterAnimation
1709 : WindowAnimation_wallpaperIntraOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001710 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001711 case TRANSIT_WALLPAPER_INTRA_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001712 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001713 ? WindowAnimation_wallpaperIntraCloseEnterAnimation
1714 : WindowAnimation_wallpaperIntraCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001715 break;
Craig Mautnerbb742462014-07-07 15:28:55 -07001716 case TRANSIT_TASK_OPEN_BEHIND:
1717 animAttr = enter
1718 ? WindowAnimation_launchTaskBehindSourceAnimation
Craig Mautner3b2cd1d2014-08-25 14:25:54 -07001719 : WindowAnimation_launchTaskBehindTargetAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001720 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001721 a = animAttr != 0 ? loadAnimationAttr(lp, animAttr) : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001722 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1723 "applyAnimation:"
1724 + " anim=" + a
1725 + " animAttr=0x" + Integer.toHexString(animAttr)
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001726 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001727 + " Callers=" + Debug.getCallers(3));
1728 }
1729 return a;
1730 }
1731
Jorim Jaggife762342016-10-13 14:33:27 +02001732 private Animation loadKeyguardExitAnimation(int transit) {
1733 if ((mNextAppTransitionFlags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_NO_ANIMATION) != 0) {
1734 return null;
1735 }
1736 final boolean toShade =
1737 (mNextAppTransitionFlags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_TO_SHADE) != 0;
1738 return mService.mPolicy.createHiddenByKeyguardExit(
1739 transit == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER, toShade);
1740 }
1741
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001742 int getAppStackClipMode() {
Matthew Ngbf1d9852017-03-14 12:23:09 -07001743 // When dismiss keyguard animation occurs, clip before the animation to prevent docked
1744 // app from showing beyond the divider
1745 if (mNextAppTransition == TRANSIT_KEYGUARD_GOING_AWAY
1746 || mNextAppTransition == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER) {
1747 return STACK_CLIP_BEFORE_ANIM;
1748 }
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001749 return mNextAppTransition == TRANSIT_ACTIVITY_RELAUNCH
Jorim Jaggic69bd222016-03-15 14:38:37 +01001750 || mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
Jorim Jaggi1f458fb2016-03-25 17:36:37 -07001751 || mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001752 ? STACK_CLIP_NONE
1753 : STACK_CLIP_AFTER_ANIM;
1754 }
1755
Jorim Jaggife762342016-10-13 14:33:27 +02001756 public int getTransitFlags() {
1757 return mNextAppTransitionFlags;
1758 }
1759
Craig Mautner164d4bb2012-11-26 13:51:23 -08001760 void postAnimationCallback() {
1761 if (mNextAppTransitionCallback != null) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001762 mService.mH.sendMessage(mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK,
1763 mNextAppTransitionCallback));
Craig Mautner164d4bb2012-11-26 13:51:23 -08001764 mNextAppTransitionCallback = null;
1765 }
1766 }
1767
1768 void overridePendingAppTransition(String packageName, int enterAnim, int exitAnim,
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001769 IRemoteCallback startedCallback) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001770 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001771 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001772 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001773 mNextAppTransitionPackage = packageName;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001774 mNextAppTransitionEnter = enterAnim;
1775 mNextAppTransitionExit = exitAnim;
1776 postAnimationCallback();
1777 mNextAppTransitionCallback = startedCallback;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001778 }
1779 }
1780
1781 void overridePendingAppTransitionScaleUp(int startX, int startY, int startWidth,
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001782 int startHeight) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001783 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001784 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001785 mNextAppTransitionType = NEXT_TRANSIT_TYPE_SCALE_UP;
Winson4c3fecd2016-07-13 12:29:48 -07001786 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001787 postAnimationCallback();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001788 }
1789 }
1790
Chet Haase10e23ab2015-02-11 15:08:38 -08001791 void overridePendingAppTransitionClipReveal(int startX, int startY,
1792 int startWidth, int startHeight) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001793 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001794 clear();
Chet Haase10e23ab2015-02-11 15:08:38 -08001795 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CLIP_REVEAL;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001796 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Chet Haase10e23ab2015-02-11 15:08:38 -08001797 postAnimationCallback();
Chet Haase10e23ab2015-02-11 15:08:38 -08001798 }
1799 }
1800
Winson Chungaa7fa012017-05-24 15:50:06 -07001801 void overridePendingAppTransitionThumb(GraphicBuffer srcThumb, int startX, int startY,
Craig Mautner164d4bb2012-11-26 13:51:23 -08001802 IRemoteCallback startedCallback, boolean scaleUp) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001803 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001804 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001805 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP
1806 : NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001807 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001808 putDefaultNextAppTransitionCoordinates(startX, startY, 0, 0, srcThumb);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001809 postAnimationCallback();
1810 mNextAppTransitionCallback = startedCallback;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001811 }
1812 }
1813
Winson Chungaa7fa012017-05-24 15:50:06 -07001814 void overridePendingAppTransitionAspectScaledThumb(GraphicBuffer srcThumb, int startX, int startY,
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001815 int targetWidth, int targetHeight, IRemoteCallback startedCallback, boolean scaleUp) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001816 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001817 clear();
Winson Chunga4ccb862014-08-22 15:26:27 -07001818 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1819 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Winson Chunga4ccb862014-08-22 15:26:27 -07001820 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001821 putDefaultNextAppTransitionCoordinates(startX, startY, targetWidth, targetHeight,
1822 srcThumb);
Winson Chunga4ccb862014-08-22 15:26:27 -07001823 postAnimationCallback();
1824 mNextAppTransitionCallback = startedCallback;
Winson Chunga4ccb862014-08-22 15:26:27 -07001825 }
1826 }
1827
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001828 void overridePendingAppTransitionMultiThumb(AppTransitionAnimationSpec[] specs,
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001829 IRemoteCallback onAnimationStartedCallback, IRemoteCallback onAnimationFinishedCallback,
1830 boolean scaleUp) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001831 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001832 clear();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001833 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1834 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001835 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi43102412015-11-11 16:28:37 +01001836 if (specs != null) {
1837 for (int i = 0; i < specs.length; i++) {
1838 AppTransitionAnimationSpec spec = specs[i];
1839 if (spec != null) {
1840 mNextAppTransitionAnimationsSpecs.put(spec.taskId, spec);
1841 if (i == 0) {
1842 // In full screen mode, the transition code depends on the default spec
1843 // to be set.
1844 Rect rect = spec.rect;
1845 putDefaultNextAppTransitionCoordinates(rect.left, rect.top,
Winson Chungaa7fa012017-05-24 15:50:06 -07001846 rect.width(), rect.height(), spec.buffer);
Jorim Jaggi43102412015-11-11 16:28:37 +01001847 }
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001848 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001849 }
1850 }
1851 postAnimationCallback();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001852 mNextAppTransitionCallback = onAnimationStartedCallback;
1853 mAnimationFinishedCallback = onAnimationFinishedCallback;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001854 }
1855 }
1856
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001857 void overridePendingAppTransitionMultiThumbFuture(
1858 IAppTransitionAnimationSpecsFuture specsFuture, IRemoteCallback callback,
1859 boolean scaleUp) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001860 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001861 clear();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001862 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1863 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001864 mNextAppTransitionAnimationsSpecsFuture = specsFuture;
1865 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001866 mNextAppTransitionFutureCallback = callback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001867 }
1868 }
1869
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001870 void overridePendingAppTransitionRemote(RemoteAnimationAdapter remoteAnimationAdapter) {
Winson Chung044d5292014-11-06 11:05:19 -08001871 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001872 clear();
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001873 mNextAppTransitionType = NEXT_TRANSIT_TYPE_REMOTE;
1874 mRemoteAnimationController = new RemoteAnimationController(mService,
1875 remoteAnimationAdapter, mService.mH);
1876 }
1877 }
1878
1879 void overrideInPlaceAppTransition(String packageName, int anim) {
1880 if (canOverridePendingAppTransition()) {
1881 clear();
Winson Chung044d5292014-11-06 11:05:19 -08001882 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE;
1883 mNextAppTransitionPackage = packageName;
1884 mNextAppTransitionInPlace = anim;
Winson Chung044d5292014-11-06 11:05:19 -08001885 }
1886 }
1887
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001888 /**
Tony Mak089c35e2017-12-18 20:34:14 +00001889 * @see {@link #NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS}
1890 */
1891 void overridePendingAppTransitionStartCrossProfileApps() {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001892 if (canOverridePendingAppTransition()) {
Tony Mak089c35e2017-12-18 20:34:14 +00001893 clear();
1894 mNextAppTransitionType = NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS;
1895 postAnimationCallback();
1896 }
1897 }
1898
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001899 private boolean canOverridePendingAppTransition() {
1900 // Remote animations always take precedence
1901 return isTransitionSet() && mNextAppTransitionType != NEXT_TRANSIT_TYPE_REMOTE;
1902 }
1903
Tony Mak089c35e2017-12-18 20:34:14 +00001904 /**
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001905 * If a future is set for the app transition specs, fetch it in another thread.
1906 */
1907 private void fetchAppTransitionSpecsFromFuture() {
1908 if (mNextAppTransitionAnimationsSpecsFuture != null) {
1909 mNextAppTransitionAnimationsSpecsPending = true;
1910 final IAppTransitionAnimationSpecsFuture future
1911 = mNextAppTransitionAnimationsSpecsFuture;
1912 mNextAppTransitionAnimationsSpecsFuture = null;
Jorim Jaggied410b62017-05-05 15:16:14 +02001913 mDefaultExecutor.execute(() -> {
1914 AppTransitionAnimationSpec[] specs = null;
1915 try {
1916 Binder.allowBlocking(future.asBinder());
1917 specs = future.get();
1918 } catch (RemoteException e) {
1919 Slog.w(TAG, "Failed to fetch app transition specs: " + e);
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001920 }
Jorim Jaggied410b62017-05-05 15:16:14 +02001921 synchronized (mService.mWindowMap) {
1922 mNextAppTransitionAnimationsSpecsPending = false;
1923 overridePendingAppTransitionMultiThumb(specs,
1924 mNextAppTransitionFutureCallback, null /* finishedCallback */,
1925 mNextAppTransitionScaleUp);
1926 mNextAppTransitionFutureCallback = null;
Jorim Jaggied410b62017-05-05 15:16:14 +02001927 }
1928 mService.requestTraversal();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001929 });
1930 }
1931 }
1932
Craig Mautner164d4bb2012-11-26 13:51:23 -08001933 @Override
1934 public String toString() {
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001935 return "mNextAppTransition=" + appTransitionToString(mNextAppTransition);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001936 }
1937
Craig Mautner4b71aa12012-12-27 17:20:01 -08001938 /**
1939 * Returns the human readable name of a window transition.
1940 *
1941 * @param transition The window transition.
1942 * @return The transition symbolic name.
1943 */
1944 public static String appTransitionToString(int transition) {
1945 switch (transition) {
1946 case TRANSIT_UNSET: {
1947 return "TRANSIT_UNSET";
1948 }
1949 case TRANSIT_NONE: {
1950 return "TRANSIT_NONE";
1951 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001952 case TRANSIT_ACTIVITY_OPEN: {
1953 return "TRANSIT_ACTIVITY_OPEN";
1954 }
1955 case TRANSIT_ACTIVITY_CLOSE: {
1956 return "TRANSIT_ACTIVITY_CLOSE";
1957 }
1958 case TRANSIT_TASK_OPEN: {
1959 return "TRANSIT_TASK_OPEN";
1960 }
1961 case TRANSIT_TASK_CLOSE: {
1962 return "TRANSIT_TASK_CLOSE";
1963 }
1964 case TRANSIT_TASK_TO_FRONT: {
1965 return "TRANSIT_TASK_TO_FRONT";
1966 }
1967 case TRANSIT_TASK_TO_BACK: {
1968 return "TRANSIT_TASK_TO_BACK";
1969 }
1970 case TRANSIT_WALLPAPER_CLOSE: {
1971 return "TRANSIT_WALLPAPER_CLOSE";
1972 }
1973 case TRANSIT_WALLPAPER_OPEN: {
1974 return "TRANSIT_WALLPAPER_OPEN";
1975 }
1976 case TRANSIT_WALLPAPER_INTRA_OPEN: {
1977 return "TRANSIT_WALLPAPER_INTRA_OPEN";
1978 }
1979 case TRANSIT_WALLPAPER_INTRA_CLOSE: {
1980 return "TRANSIT_WALLPAPER_INTRA_CLOSE";
1981 }
Craig Mautnerbb742462014-07-07 15:28:55 -07001982 case TRANSIT_TASK_OPEN_BEHIND: {
1983 return "TRANSIT_TASK_OPEN_BEHIND";
1984 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001985 case TRANSIT_ACTIVITY_RELAUNCH: {
1986 return "TRANSIT_ACTIVITY_RELAUNCH";
1987 }
Jorim Jaggi192086e2016-03-11 17:17:03 +01001988 case TRANSIT_DOCK_TASK_FROM_RECENTS: {
1989 return "TRANSIT_DOCK_TASK_FROM_RECENTS";
1990 }
Jorim Jaggife762342016-10-13 14:33:27 +02001991 case TRANSIT_KEYGUARD_GOING_AWAY: {
1992 return "TRANSIT_KEYGUARD_GOING_AWAY";
1993 }
1994 case TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER: {
1995 return "TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER";
1996 }
1997 case TRANSIT_KEYGUARD_OCCLUDE: {
1998 return "TRANSIT_KEYGUARD_OCCLUDE";
1999 }
2000 case TRANSIT_KEYGUARD_UNOCCLUDE: {
2001 return "TRANSIT_KEYGUARD_UNOCCLUDE";
2002 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002003 default: {
2004 return "<UNKNOWN>";
2005 }
2006 }
2007 }
2008
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002009 private String appStateToString() {
2010 switch (mAppTransitionState) {
2011 case APP_STATE_IDLE:
2012 return "APP_STATE_IDLE";
2013 case APP_STATE_READY:
2014 return "APP_STATE_READY";
2015 case APP_STATE_RUNNING:
2016 return "APP_STATE_RUNNING";
2017 case APP_STATE_TIMEOUT:
2018 return "APP_STATE_TIMEOUT";
2019 default:
2020 return "unknown state=" + mAppTransitionState;
2021 }
2022 }
2023
2024 private String transitTypeToString() {
2025 switch (mNextAppTransitionType) {
2026 case NEXT_TRANSIT_TYPE_NONE:
2027 return "NEXT_TRANSIT_TYPE_NONE";
2028 case NEXT_TRANSIT_TYPE_CUSTOM:
2029 return "NEXT_TRANSIT_TYPE_CUSTOM";
Winson Chung044d5292014-11-06 11:05:19 -08002030 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
2031 return "NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002032 case NEXT_TRANSIT_TYPE_SCALE_UP:
2033 return "NEXT_TRANSIT_TYPE_SCALE_UP";
2034 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
2035 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP";
2036 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
2037 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN";
Winson Chunga4ccb862014-08-22 15:26:27 -07002038 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
2039 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP";
2040 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN:
2041 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN";
Tony Mak64b8d562017-12-28 17:44:02 +00002042 case NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS:
2043 return "NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002044 default:
2045 return "unknown type=" + mNextAppTransitionType;
2046 }
2047 }
2048
Steven Timotiusaf03df62017-07-18 16:56:43 -07002049 void writeToProto(ProtoOutputStream proto, long fieldId) {
2050 final long token = proto.start(fieldId);
2051 proto.write(APP_TRANSITION_STATE, mAppTransitionState);
2052 proto.write(LAST_USED_APP_TRANSITION, mLastUsedAppTransition);
2053 proto.end(token);
2054 }
2055
Craig Mautner164d4bb2012-11-26 13:51:23 -08002056 @Override
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002057 public void dump(PrintWriter pw, String prefix) {
2058 pw.print(prefix); pw.println(this);
2059 pw.print(prefix); pw.print("mAppTransitionState="); pw.println(appStateToString());
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002060 if (mNextAppTransitionType != NEXT_TRANSIT_TYPE_NONE) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002061 pw.print(prefix); pw.print("mNextAppTransitionType=");
2062 pw.println(transitTypeToString());
Craig Mautner164d4bb2012-11-26 13:51:23 -08002063 }
2064 switch (mNextAppTransitionType) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002065 case NEXT_TRANSIT_TYPE_CUSTOM:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002066 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Craig Mautner164d4bb2012-11-26 13:51:23 -08002067 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002068 pw.print(prefix); pw.print("mNextAppTransitionEnter=0x");
Craig Mautner164d4bb2012-11-26 13:51:23 -08002069 pw.print(Integer.toHexString(mNextAppTransitionEnter));
2070 pw.print(" mNextAppTransitionExit=0x");
2071 pw.println(Integer.toHexString(mNextAppTransitionExit));
2072 break;
Winson Chung044d5292014-11-06 11:05:19 -08002073 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002074 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Winson Chung044d5292014-11-06 11:05:19 -08002075 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002076 pw.print(prefix); pw.print("mNextAppTransitionInPlace=0x");
Winson Chung044d5292014-11-06 11:05:19 -08002077 pw.print(Integer.toHexString(mNextAppTransitionInPlace));
2078 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002079 case NEXT_TRANSIT_TYPE_SCALE_UP: {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002080 getDefaultNextAppTransitionStartRect(mTmpRect);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002081 pw.print(prefix); pw.print("mNextAppTransitionStartX=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002082 pw.print(mTmpRect.left);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002083 pw.print(" mNextAppTransitionStartY=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002084 pw.println(mTmpRect.top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002085 pw.print(prefix); pw.print("mNextAppTransitionStartWidth=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002086 pw.print(mTmpRect.width());
Craig Mautner164d4bb2012-11-26 13:51:23 -08002087 pw.print(" mNextAppTransitionStartHeight=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002088 pw.println(mTmpRect.height());
Craig Mautner164d4bb2012-11-26 13:51:23 -08002089 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002090 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002091 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
2092 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
Winson Chunga4ccb862014-08-22 15:26:27 -07002093 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002094 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN: {
2095 pw.print(prefix); pw.print("mDefaultNextAppTransitionAnimationSpec=");
2096 pw.println(mDefaultNextAppTransitionAnimationSpec);
2097 pw.print(prefix); pw.print("mNextAppTransitionAnimationsSpecs=");
2098 pw.println(mNextAppTransitionAnimationsSpecs);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002099 pw.print(prefix); pw.print("mNextAppTransitionScaleUp=");
2100 pw.println(mNextAppTransitionScaleUp);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002101 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002102 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002103 }
2104 if (mNextAppTransitionCallback != null) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002105 pw.print(prefix); pw.print("mNextAppTransitionCallback=");
2106 pw.println(mNextAppTransitionCallback);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002107 }
Chong Zhang60091a92016-07-27 17:52:45 -07002108 if (mLastUsedAppTransition != TRANSIT_NONE) {
2109 pw.print(prefix); pw.print("mLastUsedAppTransition=");
2110 pw.println(appTransitionToString(mLastUsedAppTransition));
2111 pw.print(prefix); pw.print("mLastOpeningApp=");
2112 pw.println(mLastOpeningApp);
2113 pw.print(prefix); pw.print("mLastClosingApp=");
2114 pw.println(mLastClosingApp);
2115 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002116 }
Amith Yamasani4befbec2013-07-10 16:18:01 -07002117
2118 public void setCurrentUser(int newUserId) {
2119 mCurrentUserId = newUserId;
2120 }
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002121
2122 /**
2123 * @return true if transition is not running and should not be skipped, false if transition is
2124 * already running
2125 */
Jorim Jaggif84e2f62018-01-16 14:17:59 +01002126 boolean prepareAppTransitionLocked(@TransitionType int transit, boolean alwaysKeepCurrent,
2127 @TransitionFlags int flags, boolean forceOverride) {
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002128 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Prepare app transition:"
2129 + " transit=" + appTransitionToString(transit)
2130 + " " + this
2131 + " alwaysKeepCurrent=" + alwaysKeepCurrent
2132 + " Callers=" + Debug.getCallers(3));
Jorim Jaggife762342016-10-13 14:33:27 +02002133 if (forceOverride || isKeyguardTransit(transit) || !isTransitionSet()
2134 || mNextAppTransition == TRANSIT_NONE) {
2135 setAppTransition(transit, flags);
Jorim Jaggia69243a2017-06-15 15:10:38 -04002136 }
2137 // We never want to change from a Keyguard transit to a non-Keyguard transit, as our logic
2138 // relies on the fact that we always execute a Keyguard transition after preparing one.
2139 else if (!alwaysKeepCurrent && !isKeyguardTransit(transit)) {
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002140 if (transit == TRANSIT_TASK_OPEN && isTransitionEqual(TRANSIT_TASK_CLOSE)) {
2141 // Opening a new task always supersedes a close for the anim.
Jorim Jaggife762342016-10-13 14:33:27 +02002142 setAppTransition(transit, flags);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002143 } else if (transit == TRANSIT_ACTIVITY_OPEN
2144 && isTransitionEqual(TRANSIT_ACTIVITY_CLOSE)) {
2145 // Opening a new activity always supersedes a close for the anim.
Jorim Jaggife762342016-10-13 14:33:27 +02002146 setAppTransition(transit, flags);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002147 }
2148 }
2149 boolean prepared = prepare();
2150 if (isTransitionSet()) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08002151 mService.mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
2152 mService.mH.sendEmptyMessageDelayed(H.APP_TRANSITION_TIMEOUT, APP_TRANSITION_TIMEOUT_MS);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002153 }
2154 return prepared;
2155 }
Winsonb2024762016-04-05 17:32:30 -07002156
2157 /**
Jorim Jaggife762342016-10-13 14:33:27 +02002158 * @return true if {@param transit} is representing a transition in which Keyguard is going
2159 * away, false otherwise
2160 */
2161 public static boolean isKeyguardGoingAwayTransit(int transit) {
2162 return transit == TRANSIT_KEYGUARD_GOING_AWAY
2163 || transit == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER;
2164 }
2165
2166 private static boolean isKeyguardTransit(int transit) {
2167 return isKeyguardGoingAwayTransit(transit) || transit == TRANSIT_KEYGUARD_OCCLUDE
2168 || transit == TRANSIT_KEYGUARD_UNOCCLUDE;
2169 }
2170
2171 /**
Manu Cornetd7376802017-01-13 13:44:07 -08002172 * @return whether the transition should show the thumbnail being scaled down.
2173 */
2174 private boolean shouldScaleDownThumbnailTransition(int uiMode, int orientation) {
Sid Soundararajan0e88d322017-03-07 15:37:30 -08002175 return mGridLayoutRecentsEnabled
Manu Cornetd7376802017-01-13 13:44:07 -08002176 || orientation == Configuration.ORIENTATION_PORTRAIT;
2177 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002178}