blob: e0c5fd055e7ed7af00723e8d71005033f3f7e63c [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;
Adrian Roos93577212018-04-10 14:12:10 -070023import static android.view.WindowManager.TRANSIT_CRASHING_ACTIVITY_CLOSE;
Jorim Jaggif84e2f62018-01-16 14:17:59 +010024import static android.view.WindowManager.TRANSIT_DOCK_TASK_FROM_RECENTS;
25import static android.view.WindowManager.TRANSIT_FLAG_KEYGUARD_GOING_AWAY_NO_ANIMATION;
Issei Suzuki5609ccb2019-06-13 15:04:08 +020026import static android.view.WindowManager.TRANSIT_FLAG_KEYGUARD_GOING_AWAY_SUBTLE_ANIMATION;
Jorim Jaggif84e2f62018-01-16 14:17:59 +010027import static android.view.WindowManager.TRANSIT_FLAG_KEYGUARD_GOING_AWAY_TO_SHADE;
28import static android.view.WindowManager.TRANSIT_KEYGUARD_GOING_AWAY;
29import static android.view.WindowManager.TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER;
30import static android.view.WindowManager.TRANSIT_KEYGUARD_OCCLUDE;
31import static android.view.WindowManager.TRANSIT_KEYGUARD_UNOCCLUDE;
32import static android.view.WindowManager.TRANSIT_NONE;
Issei Suzukicac2a502019-04-16 16:52:50 +020033import static android.view.WindowManager.TRANSIT_SHOW_SINGLE_TASK_DISPLAY;
Evan Roskycf76bed2019-01-15 10:33:58 -080034import static android.view.WindowManager.TRANSIT_TASK_CHANGE_WINDOWING_MODE;
Jorim Jaggif84e2f62018-01-16 14:17:59 +010035import static android.view.WindowManager.TRANSIT_TASK_CLOSE;
36import static android.view.WindowManager.TRANSIT_TASK_OPEN;
37import static android.view.WindowManager.TRANSIT_TASK_OPEN_BEHIND;
38import static android.view.WindowManager.TRANSIT_TASK_TO_BACK;
39import static android.view.WindowManager.TRANSIT_TASK_TO_FRONT;
Jorim Jaggi98a9d202018-03-26 16:17:07 +020040import static android.view.WindowManager.TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE;
41import static android.view.WindowManager.TRANSIT_TRANSLUCENT_ACTIVITY_OPEN;
Jorim Jaggif84e2f62018-01-16 14:17:59 +010042import static android.view.WindowManager.TRANSIT_UNSET;
43import static android.view.WindowManager.TRANSIT_WALLPAPER_CLOSE;
44import static android.view.WindowManager.TRANSIT_WALLPAPER_INTRA_CLOSE;
45import static android.view.WindowManager.TRANSIT_WALLPAPER_INTRA_OPEN;
46import static android.view.WindowManager.TRANSIT_WALLPAPER_OPEN;
Tony Mak83546a82018-01-22 13:56:20 +000047
Filip Gruszczynski82861362015-10-16 14:21:09 -070048import static com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation;
49import static com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
50import static com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation;
51import static com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
52import static com.android.internal.R.styleable.WindowAnimation_launchTaskBehindSourceAnimation;
53import static com.android.internal.R.styleable.WindowAnimation_launchTaskBehindTargetAnimation;
54import static com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation;
55import static com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
56import static com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation;
57import static com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
58import static com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation;
59import static com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
60import static com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation;
61import static com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
62import static com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation;
63import static com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
64import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation;
65import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
66import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation;
67import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
68import static com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation;
69import static com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Aurimas Liutikasd8ebfef2019-01-16 12:46:42 -080070import static com.android.server.wm.AppTransitionProto.APP_TRANSITION_STATE;
71import static com.android.server.wm.AppTransitionProto.LAST_USED_APP_TRANSITION;
Adrian Roosb125e0b2019-10-02 14:55:14 +020072import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_APP_TRANSITIONS;
73import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_APP_TRANSITIONS_ANIM;
Filip Gruszczynski198dcbf2016-01-18 10:02:00 -080074import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080075import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
76import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Adrian Roose99bc052017-11-20 17:55:31 +010077import static com.android.server.wm.WindowManagerInternal.AppTransitionListener;
Tony Mak089c35e2017-12-18 20:34:14 +000078import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_AFTER_ANIM;
Matthew Ngbf1d9852017-03-14 12:23:09 -070079import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_BEFORE_ANIM;
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +010080import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_NONE;
Filip Gruszczynski82861362015-10-16 14:21:09 -070081
Tony Mak64b8d562017-12-28 17:44:02 +000082import android.annotation.DrawableRes;
lumark23b54592018-10-02 17:17:23 +080083import android.annotation.NonNull;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -070084import android.annotation.Nullable;
Matthew Ng43db6d22017-06-27 15:29:39 -070085import android.app.ActivityManager;
Tony Mak089c35e2017-12-18 20:34:14 +000086import android.content.ComponentName;
Craig Mautner164d4bb2012-11-26 13:51:23 -080087import android.content.Context;
Winson21700932016-03-24 17:26:23 -070088import android.content.res.Configuration;
Todd Kennedy64c57a82018-04-19 15:17:24 -070089import android.content.res.ResourceId;
Aurimas Liutikasd8ebfef2019-01-16 12:46:42 -080090import android.content.res.Resources;
Jorim Jaggib142f572019-03-01 16:08:54 +010091import android.content.res.Resources.NotFoundException;
lumarkce596d32019-06-12 16:58:35 +080092import android.content.res.TypedArray;
John Reck519ad482018-02-12 17:08:48 -080093import android.graphics.Bitmap;
94import android.graphics.Canvas;
Tony Mak64b8d562017-12-28 17:44:02 +000095import android.graphics.Color;
Winson Chungaa7fa012017-05-24 15:50:06 -070096import android.graphics.GraphicBuffer;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +010097import android.graphics.Path;
John Reck519ad482018-02-12 17:08:48 -080098import android.graphics.Picture;
Winson Chung399f6202014-03-19 10:47:20 -070099import android.graphics.Rect;
Tony Mak64b8d562017-12-28 17:44:02 +0000100import android.graphics.drawable.Drawable;
Jorim Jaggied410b62017-05-05 15:16:14 +0200101import android.os.Binder;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800102import android.os.Debug;
lumark23b54592018-10-02 17:17:23 +0800103import android.os.Handler;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100104import android.os.IBinder;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800105import android.os.IRemoteCallback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100106import android.os.RemoteException;
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200107import android.os.SystemClock;
Manu Cornetd7376802017-01-13 13:44:07 -0800108import android.os.SystemProperties;
Tony Mak089c35e2017-12-18 20:34:14 +0000109import android.os.UserHandle;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800110import android.util.ArraySet;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800111import android.util.Slog;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700112import android.util.SparseArray;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700113import android.util.proto.ProtoOutputStream;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700114import android.view.AppTransitionAnimationSpec;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100115import android.view.IAppTransitionAnimationSpecsFuture;
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100116import android.view.RemoteAnimationAdapter;
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100117import android.view.WindowManager.TransitionFlags;
118import android.view.WindowManager.TransitionType;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800119import android.view.animation.AlphaAnimation;
120import android.view.animation.Animation;
121import android.view.animation.AnimationSet;
122import android.view.animation.AnimationUtils;
Winson Chung399f6202014-03-19 10:47:20 -0700123import android.view.animation.ClipRectAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800124import android.view.animation.Interpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700125import android.view.animation.PathInterpolator;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800126import android.view.animation.ScaleAnimation;
Winson Chung399f6202014-03-19 10:47:20 -0700127import android.view.animation.TranslateAnimation;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700128
Jorim Jaggi98a9d202018-03-26 16:17:07 +0200129import com.android.internal.R;
Jorim Jaggib142f572019-03-01 16:08:54 +0100130import com.android.internal.annotations.VisibleForTesting;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800131import com.android.internal.util.DumpUtils.Dump;
lumark23b54592018-10-02 17:17:23 +0800132import com.android.internal.util.function.pooled.PooledLambda;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800133import com.android.server.AttributeCache;
Adrian Roosb125e0b2019-10-02 14:55:14 +0200134import com.android.server.protolog.common.ProtoLog;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800135import com.android.server.wm.animation.ClipRectLRAnimation;
136import com.android.server.wm.animation.ClipRectTBAnimation;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100137import com.android.server.wm.animation.CurvedTranslateAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800138
139import java.io.PrintWriter;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100140import java.util.ArrayList;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100141import java.util.concurrent.ExecutorService;
142import java.util.concurrent.Executors;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800143
Craig Mautner164d4bb2012-11-26 13:51:23 -0800144// State management of app transitions. When we are preparing for a
145// transition, mNextAppTransition will be the kind of transition to
146// perform or TRANSIT_NONE if we are not waiting. If we are waiting,
147// mOpeningApps and mClosingApps are the lists of tokens that will be
148// made visible or hidden at the next transition.
149public class AppTransition implements Dump {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800150 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppTransition" : TAG_WM;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700151 private static final int CLIP_REVEAL_TRANSLATION_Y_DP = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800152
Winson Chunga4ccb862014-08-22 15:26:27 -0700153 /** Fraction of animation at which the recents thumbnail stays completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700154 private static final float RECENTS_THUMBNAIL_FADEIN_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800155 /** Fraction of animation at which the recents thumbnail becomes completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700156 private static final float RECENTS_THUMBNAIL_FADEOUT_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800157
Filip Gruszczynski84fa3352016-01-25 16:28:49 -0800158 static final int DEFAULT_APP_TRANSITION_DURATION = 336;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800159
160 /** Interpolator to be used for animations that respond directly to a touch */
161 static final Interpolator TOUCH_RESPONSE_INTERPOLATOR =
162 new PathInterpolator(0.3f, 0f, 0.1f, 1f);
163
Jorim Jaggic69bd222016-03-15 14:38:37 +0100164 private static final Interpolator THUMBNAIL_DOCK_INTERPOLATOR =
165 new PathInterpolator(0.85f, 0f, 1f, 1f);
166
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800167 /**
168 * Maximum duration for the clip reveal animation. This is used when there is a lot of movement
169 * involved, to make it more understandable.
170 */
171 private static final int MAX_CLIP_REVEAL_TRANSITION_DURATION = 420;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700172 private static final int THUMBNAIL_APP_TRANSITION_DURATION = 336;
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700173 private static final long APP_TRANSITION_TIMEOUT_MS = 5000;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800174
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800175 private final Context mContext;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800176 private final WindowManagerService mService;
lumark588a3e82018-07-20 18:53:54 +0800177 private final DisplayContent mDisplayContent;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800178
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100179 private @TransitionType int mNextAppTransition = TRANSIT_UNSET;
180 private @TransitionFlags int mNextAppTransitionFlags = 0;
Chong Zhang60091a92016-07-27 17:52:45 -0700181 private int mLastUsedAppTransition = TRANSIT_UNSET;
182 private String mLastOpeningApp;
183 private String mLastClosingApp;
Evan Rosky2289ba12018-11-19 18:28:18 -0800184 private String mLastChangingApp;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800185
186 private static final int NEXT_TRANSIT_TYPE_NONE = 0;
187 private static final int NEXT_TRANSIT_TYPE_CUSTOM = 1;
188 private static final int NEXT_TRANSIT_TYPE_SCALE_UP = 2;
189 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP = 3;
190 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN = 4;
Winson Chunga4ccb862014-08-22 15:26:27 -0700191 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP = 5;
192 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN = 6;
Winson Chung044d5292014-11-06 11:05:19 -0800193 private static final int NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE = 7;
Chet Haase10e23ab2015-02-11 15:08:38 -0800194 private static final int NEXT_TRANSIT_TYPE_CLIP_REVEAL = 8;
Tony Mak089c35e2017-12-18 20:34:14 +0000195
196 /**
197 * Refers to the transition to activity started by using {@link
198 * android.content.pm.crossprofile.CrossProfileApps#startMainActivity(ComponentName, UserHandle)
199 * }.
200 */
201 private static final int NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS = 9;
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100202 private static final int NEXT_TRANSIT_TYPE_REMOTE = 10;
203
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800204 private int mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
205
Winson Chung399f6202014-03-19 10:47:20 -0700206 // These are the possible states for the enter/exit activities during a thumbnail transition
207 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_UP = 0;
208 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_UP = 1;
209 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN = 2;
210 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN = 3;
211
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800212 private String mNextAppTransitionPackage;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800213 // Used for thumbnail transitions. True if we're scaling up, false if scaling down
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800214 private boolean mNextAppTransitionScaleUp;
215 private IRemoteCallback mNextAppTransitionCallback;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +0100216 private IRemoteCallback mNextAppTransitionFutureCallback;
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -0700217 private IRemoteCallback mAnimationFinishedCallback;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800218 private int mNextAppTransitionEnter;
219 private int mNextAppTransitionExit;
Winson Chung044d5292014-11-06 11:05:19 -0800220 private int mNextAppTransitionInPlace;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700221
lumark19a5d2e2019-10-11 16:19:30 +0800222 // Keyed by WindowContainer hashCode.
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700223 private final SparseArray<AppTransitionAnimationSpec> mNextAppTransitionAnimationsSpecs
224 = new SparseArray<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100225 private IAppTransitionAnimationSpecsFuture mNextAppTransitionAnimationsSpecsFuture;
226 private boolean mNextAppTransitionAnimationsSpecsPending;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700227 private AppTransitionAnimationSpec mDefaultNextAppTransitionAnimationSpec;
228
Winson Chunga4ccb862014-08-22 15:26:27 -0700229 private Rect mNextAppTransitionInsets = new Rect();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800230
Winson Chung2820c452014-04-15 15:34:44 -0700231 private Rect mTmpFromClipRect = new Rect();
232 private Rect mTmpToClipRect = new Rect();
233
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700234 private final Rect mTmpRect = new Rect();
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700235
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800236 private final static int APP_STATE_IDLE = 0;
237 private final static int APP_STATE_READY = 1;
238 private final static int APP_STATE_RUNNING = 2;
239 private final static int APP_STATE_TIMEOUT = 3;
240 private int mAppTransitionState = APP_STATE_IDLE;
241
242 private final int mConfigShortAnimTime;
Craig Mautner321bdf52012-12-18 09:53:24 -0800243 private final Interpolator mDecelerateInterpolator;
Winson Chunga4ccb862014-08-22 15:26:27 -0700244 private final Interpolator mThumbnailFadeInInterpolator;
245 private final Interpolator mThumbnailFadeOutInterpolator;
Chet Haase10e23ab2015-02-11 15:08:38 -0800246 private final Interpolator mLinearOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700247 private final Interpolator mFastOutLinearInInterpolator;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100248 private final Interpolator mFastOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700249 private final Interpolator mClipHorizontalInterpolator = new PathInterpolator(0, 0, 0.4f, 1f);
250
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700251 private final int mClipRevealTranslationY;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800252
Amith Yamasani4befbec2013-07-10 16:18:01 -0700253 private int mCurrentUserId = 0;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800254 private long mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Amith Yamasani4befbec2013-07-10 16:18:01 -0700255
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100256 private final ArrayList<AppTransitionListener> mListeners = new ArrayList<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100257 private final ExecutorService mDefaultExecutor = Executors.newSingleThreadExecutor();
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100258
Jorim Jaggif97ed922016-02-18 18:57:07 -0800259 private int mLastClipRevealMaxTranslation;
260 private boolean mLastHadClipReveal;
261
Manu Cornetd7376802017-01-13 13:44:07 -0800262 private final boolean mGridLayoutRecentsEnabled;
Matthew Ng43db6d22017-06-27 15:29:39 -0700263 private final boolean mLowRamRecentsEnabled;
Manu Cornetd7376802017-01-13 13:44:07 -0800264
lumarkce596d32019-06-12 16:58:35 +0800265 private final int mDefaultWindowAnimationStyleResId;
266
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100267 private RemoteAnimationController mRemoteAnimationController;
268
lumark23b54592018-10-02 17:17:23 +0800269 final Handler mHandler;
270 final Runnable mHandleAppTransitionTimeoutRunnable = () -> handleAppTransitionTimeout();
271
lumark588a3e82018-07-20 18:53:54 +0800272 AppTransition(Context context, WindowManagerService service, DisplayContent displayContent) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800273 mContext = context;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800274 mService = service;
lumark23b54592018-10-02 17:17:23 +0800275 mHandler = new Handler(service.mH.getLooper());
lumark588a3e82018-07-20 18:53:54 +0800276 mDisplayContent = displayContent;
Chet Haase10e23ab2015-02-11 15:08:38 -0800277 mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
278 com.android.internal.R.interpolator.linear_out_slow_in);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700279 mFastOutLinearInInterpolator = AnimationUtils.loadInterpolator(context,
280 com.android.internal.R.interpolator.fast_out_linear_in);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100281 mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
282 com.android.internal.R.interpolator.fast_out_slow_in);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800283 mConfigShortAnimTime = context.getResources().getInteger(
284 com.android.internal.R.integer.config_shortAnimTime);
Craig Mautner321bdf52012-12-18 09:53:24 -0800285 mDecelerateInterpolator = AnimationUtils.loadInterpolator(context,
286 com.android.internal.R.interpolator.decelerate_cubic);
Winson Chunga4ccb862014-08-22 15:26:27 -0700287 mThumbnailFadeInInterpolator = new Interpolator() {
288 @Override
289 public float getInterpolation(float input) {
290 // Linear response for first fraction, then complete after that.
291 if (input < RECENTS_THUMBNAIL_FADEIN_FRACTION) {
292 return 0f;
293 }
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700294 float t = (input - RECENTS_THUMBNAIL_FADEIN_FRACTION) /
Winson Chunga4ccb862014-08-22 15:26:27 -0700295 (1f - RECENTS_THUMBNAIL_FADEIN_FRACTION);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700296 return mFastOutLinearInInterpolator.getInterpolation(t);
Winson Chunga4ccb862014-08-22 15:26:27 -0700297 }
298 };
299 mThumbnailFadeOutInterpolator = new Interpolator() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800300 @Override
301 public float getInterpolation(float input) {
302 // Linear response for first fraction, then complete after that.
303 if (input < RECENTS_THUMBNAIL_FADEOUT_FRACTION) {
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700304 float t = input / RECENTS_THUMBNAIL_FADEOUT_FRACTION;
305 return mLinearOutSlowInInterpolator.getInterpolation(t);
Craig Mautner321bdf52012-12-18 09:53:24 -0800306 }
Winson Chunga4ccb862014-08-22 15:26:27 -0700307 return 1f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800308 }
309 };
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700310 mClipRevealTranslationY = (int) (CLIP_REVEAL_TRANSLATION_Y_DP
311 * mContext.getResources().getDisplayMetrics().density);
Manu Cornetd7376802017-01-13 13:44:07 -0800312 mGridLayoutRecentsEnabled = SystemProperties.getBoolean("ro.recents.grid", false);
Matthew Ng43db6d22017-06-27 15:29:39 -0700313 mLowRamRecentsEnabled = ActivityManager.isLowRamDeviceStatic();
lumarkce596d32019-06-12 16:58:35 +0800314
315 final TypedArray windowStyle = mContext.getTheme().obtainStyledAttributes(
316 com.android.internal.R.styleable.Window);
317 mDefaultWindowAnimationStyleResId = windowStyle.getResourceId(
318 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
319 windowStyle.recycle();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800320 }
321
322 boolean isTransitionSet() {
323 return mNextAppTransition != TRANSIT_UNSET;
324 }
325
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100326 boolean isTransitionEqual(@TransitionType int transit) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800327 return mNextAppTransition == transit;
328 }
329
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100330 @TransitionType int getAppTransition() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800331 return mNextAppTransition;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800332 }
333
Jorim Jaggife762342016-10-13 14:33:27 +0200334 private void setAppTransition(int transit, int flags) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800335 mNextAppTransition = transit;
Jorim Jaggife762342016-10-13 14:33:27 +0200336 mNextAppTransitionFlags |= flags;
Evan Rosky2289ba12018-11-19 18:28:18 -0800337 setLastAppTransition(TRANSIT_UNSET, null, null, null);
Jorim Jaggi245281c2017-06-07 14:33:04 -0700338 updateBooster();
Chong Zhang60091a92016-07-27 17:52:45 -0700339 }
340
Garfield Tane8d84ab2019-10-11 09:49:40 -0700341 void setLastAppTransition(int transit, ActivityRecord openingApp, ActivityRecord closingApp,
342 ActivityRecord changingApp) {
Chong Zhang60091a92016-07-27 17:52:45 -0700343 mLastUsedAppTransition = transit;
344 mLastOpeningApp = "" + openingApp;
345 mLastClosingApp = "" + closingApp;
Evan Rosky2289ba12018-11-19 18:28:18 -0800346 mLastChangingApp = "" + changingApp;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800347 }
348
349 boolean isReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800350 return mAppTransitionState == APP_STATE_READY
351 || mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800352 }
353
Craig Mautnerae446592012-12-06 19:05:05 -0800354 void setReady() {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700355 setAppTransitionState(APP_STATE_READY);
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100356 fetchAppTransitionSpecsFromFuture();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800357 }
358
359 boolean isRunning() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800360 return mAppTransitionState == APP_STATE_RUNNING;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800361 }
362
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800363 void setIdle() {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700364 setAppTransitionState(APP_STATE_IDLE);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800365 }
366
367 boolean isTimeout() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800368 return mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800369 }
370
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800371 void setTimeout() {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700372 setAppTransitionState(APP_STATE_TIMEOUT);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800373 }
374
lumark19a5d2e2019-10-11 16:19:30 +0800375 GraphicBuffer getAppTransitionThumbnailHeader(WindowContainer container) {
376 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(
377 container.hashCode());
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800378 if (spec == null) {
379 spec = mDefaultNextAppTransitionAnimationSpec;
380 }
Winson Chungaa7fa012017-05-24 15:50:06 -0700381 return spec != null ? spec.buffer : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800382 }
383
Winson Chunga4ccb862014-08-22 15:26:27 -0700384 /** Returns whether the next thumbnail transition is aspect scaled up. */
385 boolean isNextThumbnailTransitionAspectScaled() {
386 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
387 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
388 }
389
390 /** Returns whether the next thumbnail transition is scaling up. */
391 boolean isNextThumbnailTransitionScaleUp() {
392 return mNextAppTransitionScaleUp;
393 }
394
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -0800395 boolean isNextAppTransitionThumbnailUp() {
396 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
397 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP;
398 }
399
400 boolean isNextAppTransitionThumbnailDown() {
401 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN ||
402 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
403 }
404
Tony Mak64b8d562017-12-28 17:44:02 +0000405
406 boolean isNextAppTransitionOpenCrossProfileApps() {
407 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS;
408 }
409
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100410 /**
411 * @return true if and only if we are currently fetching app transition specs from the future
412 * passed into {@link #overridePendingAppTransitionMultiThumbFuture}
413 */
414 boolean isFetchingAppTransitionsSpecs() {
415 return mNextAppTransitionAnimationsSpecsPending;
416 }
417
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700418 private boolean prepare() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800419 if (!isRunning()) {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700420 setAppTransitionState(APP_STATE_IDLE);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100421 notifyAppTransitionPendingLocked();
Jorim Jaggif97ed922016-02-18 18:57:07 -0800422 mLastHadClipReveal = false;
423 mLastClipRevealMaxTranslation = 0;
424 mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700425 return true;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800426 }
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700427 return false;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800428 }
429
Jorim Jaggife762342016-10-13 14:33:27 +0200430 /**
431 * @return bit-map of WindowManagerPolicy#FINISH_LAYOUT_REDO_* to indicate whether another
432 * layout pass needs to be done
433 */
Garfield Tane8d84ab2019-10-11 09:49:40 -0700434 int goodToGo(int transit, ActivityRecord topOpeningApp, ArraySet<ActivityRecord> openingApps) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800435 mNextAppTransition = TRANSIT_UNSET;
Jorim Jaggife762342016-10-13 14:33:27 +0200436 mNextAppTransitionFlags = 0;
Jorim Jaggi245281c2017-06-07 14:33:04 -0700437 setAppTransitionState(APP_STATE_RUNNING);
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200438 final AnimationAdapter topOpeningAnim = topOpeningApp != null
439 ? topOpeningApp.getAnimation()
440 : null;
Jorim Jaggife762342016-10-13 14:33:27 +0200441 int redoLayout = notifyAppTransitionStartingLocked(transit,
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200442 topOpeningAnim != null ? topOpeningAnim.getDurationHint() : 0,
443 topOpeningAnim != null
444 ? topOpeningAnim.getStatusBarTransitionsStartTime()
445 : SystemClock.uptimeMillis(),
446 AnimationAdapter.STATUS_BAR_TRANSITION_DURATION);
lumark588a3e82018-07-20 18:53:54 +0800447 mDisplayContent.getDockedDividerController()
Jorim Jaggife762342016-10-13 14:33:27 +0200448 .notifyAppTransitionStarting(openingApps, transit);
Jorim Jaggi363ab982016-04-26 19:51:20 -0700449
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100450 if (mRemoteAnimationController != null) {
451 mRemoteAnimationController.goodToGo();
452 }
Jorim Jaggife762342016-10-13 14:33:27 +0200453 return redoLayout;
Jorim Jaggi363ab982016-04-26 19:51:20 -0700454 }
455
Craig Mautner164d4bb2012-11-26 13:51:23 -0800456 void clear() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800457 mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800458 mNextAppTransitionPackage = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700459 mNextAppTransitionAnimationsSpecs.clear();
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100460 mRemoteAnimationController = null;
Jorim Jaggi65193992015-11-23 16:49:59 -0800461 mNextAppTransitionAnimationsSpecsFuture = null;
462 mDefaultNextAppTransitionAnimationSpec = null;
463 mAnimationFinishedCallback = null;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800464 }
465
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800466 void freeze() {
Jorim Jaggife762342016-10-13 14:33:27 +0200467 final int transit = mNextAppTransition;
Arthur Hung442aff22019-05-07 19:49:31 +0800468 // The RemoteAnimationControl didn't register AppTransitionListener and
469 // only initialized the finish and timeout callback when goodToGo().
470 // So cancel the remote animation here to prevent the animation can't do
471 // finish after transition state cleared.
472 if (mRemoteAnimationController != null) {
473 mRemoteAnimationController.cancelAnimation("freeze");
474 }
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100475 setAppTransition(TRANSIT_UNSET, 0 /* flags */);
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800476 clear();
477 setReady();
Jorim Jaggife762342016-10-13 14:33:27 +0200478 notifyAppTransitionCancelledLocked(transit);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100479 }
480
Jorim Jaggi245281c2017-06-07 14:33:04 -0700481 private void setAppTransitionState(int state) {
482 mAppTransitionState = state;
483 updateBooster();
484 }
485
486 /**
487 * Updates whether we currently boost wm locked sections and the animation thread. We want to
488 * boost the priorities to a more important value whenever an app transition is going to happen
489 * soon or an app transition is running.
490 */
Jorim Jaggic8cc2292018-03-15 20:16:15 +0100491 void updateBooster() {
492 WindowManagerService.sThreadPriorityBooster.setAppTransitionRunning(needsBoosting());
493 }
494
495 private boolean needsBoosting() {
496 final boolean recentsAnimRunning = mService.getRecentsAnimationController() != null;
497 return mNextAppTransition != TRANSIT_UNSET
498 || mAppTransitionState == APP_STATE_READY
499 || mAppTransitionState == APP_STATE_RUNNING
500 || recentsAnimRunning;
Jorim Jaggi245281c2017-06-07 14:33:04 -0700501 }
502
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100503 void registerListenerLocked(AppTransitionListener listener) {
504 mListeners.add(listener);
505 }
506
lumark54284462019-03-05 20:44:27 +0800507 void unregisterListener(AppTransitionListener listener) {
508 mListeners.remove(listener);
509 }
510
Wale Ogunwalea48eadb2015-05-14 17:43:12 -0700511 public void notifyAppTransitionFinishedLocked(IBinder token) {
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100512 for (int i = 0; i < mListeners.size(); i++) {
513 mListeners.get(i).onAppTransitionFinishedLocked(token);
514 }
515 }
516
517 private void notifyAppTransitionPendingLocked() {
518 for (int i = 0; i < mListeners.size(); i++) {
519 mListeners.get(i).onAppTransitionPendingLocked();
520 }
521 }
522
Jorim Jaggife762342016-10-13 14:33:27 +0200523 private void notifyAppTransitionCancelledLocked(int transit) {
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100524 for (int i = 0; i < mListeners.size(); i++) {
Jorim Jaggife762342016-10-13 14:33:27 +0200525 mListeners.get(i).onAppTransitionCancelledLocked(transit);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100526 }
527 }
528
Evan Rosky2289ba12018-11-19 18:28:18 -0800529 private int notifyAppTransitionStartingLocked(int transit, long duration,
530 long statusBarAnimationStartTime, long statusBarAnimationDuration) {
Jorim Jaggife762342016-10-13 14:33:27 +0200531 int redoLayout = 0;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100532 for (int i = 0; i < mListeners.size(); i++) {
Evan Rosky2289ba12018-11-19 18:28:18 -0800533 redoLayout |= mListeners.get(i).onAppTransitionStartingLocked(transit, duration,
534 statusBarAnimationStartTime, statusBarAnimationDuration);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100535 }
Jorim Jaggife762342016-10-13 14:33:27 +0200536 return redoLayout;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800537 }
538
lumarkce596d32019-06-12 16:58:35 +0800539 @VisibleForTesting
540 int getDefaultWindowAnimationStyleResId() {
541 return mDefaultWindowAnimationStyleResId;
542 }
543
544 /** Returns window animation style ID from {@link LayoutParams} or from system in some cases */
545 @VisibleForTesting
546 int getAnimationStyleResId(@NonNull LayoutParams lp) {
547 int resId = lp.windowAnimations;
548 if (lp.type == LayoutParams.TYPE_APPLICATION_STARTING) {
549 // Note that we don't want application to customize starting window animation.
550 // Since this window is specific for displaying while app starting,
551 // application should not change its animation directly.
552 // In this case, it will use system resource to get default animation.
553 resId = mDefaultWindowAnimationStyleResId;
554 }
555 return resId;
556 }
557
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100558 private AttributeCache.Entry getCachedAnimations(LayoutParams lp) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800559 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg="
560 + (lp != null ? lp.packageName : null)
561 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
562 if (lp != null && lp.windowAnimations != 0) {
563 // If this is a system resource, don't try to load it from the
564 // application resources. It is nice to avoid loading application
565 // resources if we can.
566 String packageName = lp.packageName != null ? lp.packageName : "android";
lumarkce596d32019-06-12 16:58:35 +0800567 int resId = getAnimationStyleResId(lp);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800568 if ((resId&0xFF000000) == 0x01000000) {
569 packageName = "android";
570 }
571 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
572 + packageName);
573 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700574 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800575 }
576 return null;
577 }
578
579 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
580 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package="
581 + packageName + " resId=0x" + Integer.toHexString(resId));
582 if (packageName != null) {
583 if ((resId&0xFF000000) == 0x01000000) {
584 packageName = "android";
585 }
586 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
587 + packageName);
588 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700589 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800590 }
591 return null;
592 }
593
Jorim Jaggi0a1523d2018-04-19 17:48:38 +0200594 Animation loadAnimationAttr(LayoutParams lp, int animAttr, int transit) {
Aurimas Liutikasd8ebfef2019-01-16 12:46:42 -0800595 int resId = Resources.ID_NULL;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800596 Context context = mContext;
Jorim Jaggi5f95b002018-04-19 13:27:52 +0000597 if (animAttr >= 0) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800598 AttributeCache.Entry ent = getCachedAnimations(lp);
599 if (ent != null) {
600 context = ent.context;
Todd Kennedy64c57a82018-04-19 15:17:24 -0700601 resId = ent.array.getResourceId(animAttr, 0);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800602 }
603 }
Todd Kennedy64c57a82018-04-19 15:17:24 -0700604 resId = updateToTranslucentAnimIfNeeded(resId, transit);
605 if (ResourceId.isValid(resId)) {
Jorim Jaggib142f572019-03-01 16:08:54 +0100606 return loadAnimationSafely(context, resId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800607 }
608 return null;
609 }
610
Jorim Jaggib142f572019-03-01 16:08:54 +0100611 private Animation loadAnimationRes(LayoutParams lp, int resId) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700612 Context context = mContext;
Todd Kennedy64c57a82018-04-19 15:17:24 -0700613 if (ResourceId.isValid(resId)) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700614 AttributeCache.Entry ent = getCachedAnimations(lp);
615 if (ent != null) {
616 context = ent.context;
617 }
Jorim Jaggib142f572019-03-01 16:08:54 +0100618 return loadAnimationSafely(context, resId);
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700619 }
620 return null;
621 }
622
623 private Animation loadAnimationRes(String packageName, int resId) {
Todd Kennedy64c57a82018-04-19 15:17:24 -0700624 if (ResourceId.isValid(resId)) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800625 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
626 if (ent != null) {
Jorim Jaggib142f572019-03-01 16:08:54 +0100627 return loadAnimationSafely(ent.context, resId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800628 }
629 }
Craig Mautner164d4bb2012-11-26 13:51:23 -0800630 return null;
631 }
632
Jorim Jaggib142f572019-03-01 16:08:54 +0100633 @VisibleForTesting
634 Animation loadAnimationSafely(Context context, int resId) {
635 try {
636 return AnimationUtils.loadAnimation(context, resId);
637 } catch (NotFoundException e) {
638 Slog.w(TAG, "Unable to load animation resource", e);
639 return null;
640 }
641 }
642
Jorim Jaggi0a1523d2018-04-19 17:48:38 +0200643 private int updateToTranslucentAnimIfNeeded(int anim, int transit) {
644 if (transit == TRANSIT_TRANSLUCENT_ACTIVITY_OPEN && anim == R.anim.activity_open_enter) {
645 return R.anim.activity_translucent_open_enter;
646 }
647 if (transit == TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE && anim == R.anim.activity_close_exit) {
648 return R.anim.activity_translucent_close_exit;
649 }
650 return anim;
651 }
652
Craig Mautner164d4bb2012-11-26 13:51:23 -0800653 /**
654 * Compute the pivot point for an animation that is scaling from a small
655 * rect on screen to a larger rect. The pivot point varies depending on
656 * the distance between the inner and outer edges on both sides. This
657 * function computes the pivot point for one dimension.
658 * @param startPos Offset from left/top edge of outer rectangle to
659 * left/top edge of inner rectangle.
660 * @param finalScale The scaling factor between the size of the outer
661 * and inner rectangles.
662 */
663 private static float computePivot(int startPos, float finalScale) {
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800664
665 /*
666 Theorem of intercepting lines:
667
668 + + +-----------------------------------------------+
669 | | | |
670 | | | |
671 | | | |
672 | | | |
673 x | y | | |
674 | | | |
675 | | | |
676 | | | |
677 | | | |
678 | + | +--------------------+ |
679 | | | | |
680 | | | | |
681 | | | | |
682 | | | | |
683 | | | | |
684 | | | | |
685 | | | | |
686 | | | | |
687 | | | | |
688 | | | | |
689 | | | | |
690 | | | | |
691 | | | | |
692 | | | | |
693 | | | | |
694 | | | | |
695 | | | | |
696 | | +--------------------+ |
697 | | |
698 | | |
699 | | |
700 | | |
701 | | |
702 | | |
703 | | |
704 | +-----------------------------------------------+
705 |
706 |
707 |
708 |
709 |
710 |
711 |
712 |
713 |
714 + ++
715 p ++
716
717 scale = (x - y) / x
718 <=> x = -y / (scale - 1)
719 */
Craig Mautner164d4bb2012-11-26 13:51:23 -0800720 final float denom = finalScale-1;
721 if (Math.abs(denom) < .0001f) {
722 return startPos;
723 }
724 return -startPos / denom;
725 }
726
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700727 private Animation createScaleUpAnimationLocked(int transit, boolean enter,
728 Rect containingFrame) {
729 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700730 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700731 final int appWidth = containingFrame.width();
732 final int appHeight = containingFrame.height();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800733 if (enter) {
734 // Entering app zooms out from the center of the initial rect.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700735 float scaleW = mTmpRect.width() / (float) appWidth;
736 float scaleH = mTmpRect.height() / (float) appHeight;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800737 Animation scale = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700738 computePivot(mTmpRect.left, scaleW),
Winson4c3fecd2016-07-13 12:29:48 -0700739 computePivot(mTmpRect.top, scaleH));
Craig Mautner321bdf52012-12-18 09:53:24 -0800740 scale.setInterpolator(mDecelerateInterpolator);
741
Craig Mautner164d4bb2012-11-26 13:51:23 -0800742 Animation alpha = new AlphaAnimation(0, 1);
Winson Chunga4ccb862014-08-22 15:26:27 -0700743 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
Craig Mautner321bdf52012-12-18 09:53:24 -0800744
745 AnimationSet set = new AnimationSet(false);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800746 set.addAnimation(scale);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800747 set.addAnimation(alpha);
748 set.setDetachWallpaper(true);
749 a = set;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800750 } else if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
751 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800752 // If we are on top of the wallpaper, we need an animation that
753 // correctly handles the wallpaper staying static behind all of
754 // the animated elements. To do this, will just have the existing
755 // element fade out.
756 a = new AlphaAnimation(1, 0);
757 a.setDetachWallpaper(true);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800758 } else {
Craig Mautner321bdf52012-12-18 09:53:24 -0800759 // For normal animations, the exiting element just holds in place.
760 a = new AlphaAnimation(1, 1);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800761 }
Craig Mautner321bdf52012-12-18 09:53:24 -0800762
763 // Pick the desired duration. If this is an inter-activity transition,
764 // it is the standard duration for that. Otherwise we use the longer
765 // task transition duration.
766 final long duration;
767 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800768 case TRANSIT_ACTIVITY_OPEN:
769 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800770 duration = mConfigShortAnimTime;
771 break;
772 default:
773 duration = DEFAULT_APP_TRANSITION_DURATION;
774 break;
775 }
776 a.setDuration(duration);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800777 a.setFillAfter(true);
Craig Mautner321bdf52012-12-18 09:53:24 -0800778 a.setInterpolator(mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800779 a.initialize(appWidth, appHeight, appWidth, appHeight);
780 return a;
781 }
782
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700783 private void getDefaultNextAppTransitionStartRect(Rect rect) {
784 if (mDefaultNextAppTransitionAnimationSpec == null ||
785 mDefaultNextAppTransitionAnimationSpec.rect == null) {
Jorim Jaggi2550f3f2017-03-14 20:15:59 +0100786 Slog.e(TAG, "Starting rect for app requested, but none available", new Throwable());
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700787 rect.setEmpty();
788 } else {
789 rect.set(mDefaultNextAppTransitionAnimationSpec.rect);
790 }
791 }
792
lumark19a5d2e2019-10-11 16:19:30 +0800793 void getNextAppTransitionStartRect(WindowContainer container, Rect rect) {
794 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(
795 container.hashCode());
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800796 if (spec == null) {
797 spec = mDefaultNextAppTransitionAnimationSpec;
798 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700799 if (spec == null || spec.rect == null) {
lumark19a5d2e2019-10-11 16:19:30 +0800800 Slog.e(TAG, "Starting rect for container: " + container
801 + " requested, but not available", new Throwable());
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700802 rect.setEmpty();
803 } else {
804 rect.set(spec.rect);
805 }
806 }
807
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800808 private void putDefaultNextAppTransitionCoordinates(int left, int top, int width, int height,
Winson Chungaa7fa012017-05-24 15:50:06 -0700809 GraphicBuffer buffer) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700810 mDefaultNextAppTransitionAnimationSpec = new AppTransitionAnimationSpec(-1 /* taskId */,
Winson Chungaa7fa012017-05-24 15:50:06 -0700811 buffer, new Rect(left, top, left + width, top + height));
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700812 }
813
Jorim Jaggif97ed922016-02-18 18:57:07 -0800814 /**
815 * @return the duration of the last clip reveal animation
816 */
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800817 long getLastClipRevealTransitionDuration() {
818 return mLastClipRevealTransitionDuration;
819 }
820
821 /**
Jorim Jaggif97ed922016-02-18 18:57:07 -0800822 * @return the maximum distance the app surface is traveling of the last clip reveal animation
823 */
824 int getLastClipRevealMaxTranslation() {
825 return mLastClipRevealMaxTranslation;
826 }
827
828 /**
829 * @return true if in the last app transition had a clip reveal animation, false otherwise
830 */
831 boolean hadClipRevealAnimation() {
832 return mLastHadClipReveal;
833 }
834
835 /**
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800836 * Calculates the duration for the clip reveal animation. If the clip is "cut off", meaning that
837 * the start rect is outside of the target rect, and there is a lot of movement going on.
838 *
839 * @param cutOff whether the start rect was not fully contained by the end rect
840 * @param translationX the total translation the surface moves in x direction
841 * @param translationY the total translation the surfaces moves in y direction
842 * @param displayFrame our display frame
843 *
844 * @return the duration of the clip reveal animation, in milliseconds
845 */
846 private long calculateClipRevealTransitionDuration(boolean cutOff, float translationX,
847 float translationY, Rect displayFrame) {
848 if (!cutOff) {
849 return DEFAULT_APP_TRANSITION_DURATION;
850 }
851 final float fraction = Math.max(Math.abs(translationX) / displayFrame.width(),
852 Math.abs(translationY) / displayFrame.height());
853 return (long) (DEFAULT_APP_TRANSITION_DURATION + fraction *
854 (MAX_CLIP_REVEAL_TRANSITION_DURATION - DEFAULT_APP_TRANSITION_DURATION));
855 }
856
857 private Animation createClipRevealAnimationLocked(int transit, boolean enter, Rect appFrame,
858 Rect displayFrame) {
Chet Haase10e23ab2015-02-11 15:08:38 -0800859 final Animation anim;
860 if (enter) {
Craig Mautner80b1f642015-04-22 10:59:09 -0700861 final int appWidth = appFrame.width();
862 final int appHeight = appFrame.height();
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800863
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700864 // mTmpRect will contain an area around the launcher icon that was pressed. We will
Filip Gruszczynski82861362015-10-16 14:21:09 -0700865 // clip reveal from that area in the final area of the app.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700866 getDefaultNextAppTransitionStartRect(mTmpRect);
Craig Mautner80b1f642015-04-22 10:59:09 -0700867
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700868 float t = 0f;
869 if (appHeight > 0) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800870 t = (float) mTmpRect.top / displayFrame.height();
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700871 }
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800872 int translationY = mClipRevealTranslationY + (int)(displayFrame.height() / 7f * t);
873 int translationX = 0;
874 int translationYCorrection = translationY;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700875 int centerX = mTmpRect.centerX();
876 int centerY = mTmpRect.centerY();
877 int halfWidth = mTmpRect.width() / 2;
878 int halfHeight = mTmpRect.height() / 2;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800879 int clipStartX = centerX - halfWidth - appFrame.left;
880 int clipStartY = centerY - halfHeight - appFrame.top;
881 boolean cutOff = false;
882
883 // If the starting rectangle is fully or partially outside of the target rectangle, we
884 // need to start the clipping at the edge and then achieve the rest with translation
885 // and extending the clip rect from that edge.
886 if (appFrame.top > centerY - halfHeight) {
887 translationY = (centerY - halfHeight) - appFrame.top;
888 translationYCorrection = 0;
889 clipStartY = 0;
890 cutOff = true;
891 }
892 if (appFrame.left > centerX - halfWidth) {
893 translationX = (centerX - halfWidth) - appFrame.left;
894 clipStartX = 0;
895 cutOff = true;
896 }
897 if (appFrame.right < centerX + halfWidth) {
898 translationX = (centerX + halfWidth) - appFrame.right;
899 clipStartX = appWidth - mTmpRect.width();
900 cutOff = true;
901 }
902 final long duration = calculateClipRevealTransitionDuration(cutOff, translationX,
903 translationY, displayFrame);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700904
905 // Clip third of the from size of launch icon, expand to full width/height
Chet Haase10e23ab2015-02-11 15:08:38 -0800906 Animation clipAnimLR = new ClipRectLRAnimation(
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800907 clipStartX, clipStartX + mTmpRect.width(), 0, appWidth);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700908 clipAnimLR.setInterpolator(mClipHorizontalInterpolator);
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800909 clipAnimLR.setDuration((long) (duration / 2.5f));
Filip Gruszczynski82861362015-10-16 14:21:09 -0700910
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800911 TranslateAnimation translate = new TranslateAnimation(translationX, 0, translationY, 0);
912 translate.setInterpolator(cutOff ? TOUCH_RESPONSE_INTERPOLATOR
913 : mLinearOutSlowInInterpolator);
914 translate.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800915
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800916 Animation clipAnimTB = new ClipRectTBAnimation(
917 clipStartY, clipStartY + mTmpRect.height(),
918 0, appHeight,
919 translationYCorrection, 0,
920 mLinearOutSlowInInterpolator);
921 clipAnimTB.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
922 clipAnimTB.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800923
924 // Quick fade-in from icon to app window
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800925 final long alphaDuration = duration / 4;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700926 AlphaAnimation alpha = new AlphaAnimation(0.5f, 1);
Chet Haase10e23ab2015-02-11 15:08:38 -0800927 alpha.setDuration(alphaDuration);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700928 alpha.setInterpolator(mLinearOutSlowInInterpolator);
Chet Haase10e23ab2015-02-11 15:08:38 -0800929
930 AnimationSet set = new AnimationSet(false);
931 set.addAnimation(clipAnimLR);
932 set.addAnimation(clipAnimTB);
Filip Gruszczynski82861362015-10-16 14:21:09 -0700933 set.addAnimation(translate);
Chet Haase10e23ab2015-02-11 15:08:38 -0800934 set.addAnimation(alpha);
Filip Gruszczynski9e2cf5b2015-07-31 12:20:40 -0700935 set.setZAdjustment(Animation.ZORDER_TOP);
Chet Haase10e23ab2015-02-11 15:08:38 -0800936 set.initialize(appWidth, appHeight, appWidth, appHeight);
937 anim = set;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800938 mLastHadClipReveal = true;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800939 mLastClipRevealTransitionDuration = duration;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800940
941 // If the start rect was full inside the target rect (cutOff == false), we don't need
942 // to store the translation, because it's only used if cutOff == true.
943 mLastClipRevealMaxTranslation = cutOff
944 ? Math.max(Math.abs(translationY), Math.abs(translationX)) : 0;
Chet Haase10e23ab2015-02-11 15:08:38 -0800945 } else {
946 final long duration;
947 switch (transit) {
948 case TRANSIT_ACTIVITY_OPEN:
949 case TRANSIT_ACTIVITY_CLOSE:
950 duration = mConfigShortAnimTime;
951 break;
952 default:
953 duration = DEFAULT_APP_TRANSITION_DURATION;
954 break;
955 }
956 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
957 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
958 // If we are on top of the wallpaper, we need an animation that
959 // correctly handles the wallpaper staying static behind all of
960 // the animated elements. To do this, will just have the existing
961 // element fade out.
962 anim = new AlphaAnimation(1, 0);
963 anim.setDetachWallpaper(true);
964 } else {
965 // For normal animations, the exiting element just holds in place.
966 anim = new AlphaAnimation(1, 1);
967 }
968 anim.setInterpolator(mDecelerateInterpolator);
969 anim.setDuration(duration);
970 anim.setFillAfter(true);
971 }
972 return anim;
973 }
974
Winson Chung399f6202014-03-19 10:47:20 -0700975 /**
976 * Prepares the specified animation with a standard duration, interpolator, etc.
977 */
Winson Chung5393dff2014-05-08 14:25:43 -0700978 Animation prepareThumbnailAnimationWithDuration(Animation a, int appWidth, int appHeight,
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100979 long duration, Interpolator interpolator) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700980 if (duration > 0) {
981 a.setDuration(duration);
982 }
Winson Chung5393dff2014-05-08 14:25:43 -0700983 a.setFillAfter(true);
Jorim Jaggic69bd222016-03-15 14:38:37 +0100984 if (interpolator != null) {
985 a.setInterpolator(interpolator);
986 }
Winson Chung5393dff2014-05-08 14:25:43 -0700987 a.initialize(appWidth, appHeight, appWidth, appHeight);
988 return a;
989 }
990
991 /**
992 * Prepares the specified animation with a standard duration, interpolator, etc.
993 */
Winson Chung399f6202014-03-19 10:47:20 -0700994 Animation prepareThumbnailAnimation(Animation a, int appWidth, int appHeight, int transit) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800995 // Pick the desired duration. If this is an inter-activity transition,
996 // it is the standard duration for that. Otherwise we use the longer
997 // task transition duration.
Winson Chung5393dff2014-05-08 14:25:43 -0700998 final int duration;
Craig Mautner321bdf52012-12-18 09:53:24 -0800999 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001000 case TRANSIT_ACTIVITY_OPEN:
1001 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -08001002 duration = mConfigShortAnimTime;
1003 break;
1004 default:
1005 duration = DEFAULT_APP_TRANSITION_DURATION;
1006 break;
1007 }
Winson Chung5393dff2014-05-08 14:25:43 -07001008 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, duration,
1009 mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001010 }
1011
Winson Chung399f6202014-03-19 10:47:20 -07001012 /**
1013 * Return the current thumbnail transition state.
1014 */
1015 int getThumbnailTransitionState(boolean enter) {
1016 if (enter) {
1017 if (mNextAppTransitionScaleUp) {
1018 return THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
1019 } else {
1020 return THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN;
1021 }
1022 } else {
1023 if (mNextAppTransitionScaleUp) {
1024 return THUMBNAIL_TRANSITION_EXIT_SCALE_UP;
1025 } else {
1026 return THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN;
1027 }
1028 }
1029 }
1030
1031 /**
Tony Mak64b8d562017-12-28 17:44:02 +00001032 * Creates an overlay with a background color and a thumbnail for the cross profile apps
1033 * animation.
1034 */
1035 GraphicBuffer createCrossProfileAppsThumbnail(
1036 @DrawableRes int thumbnailDrawableRes, Rect frame) {
1037 final int width = frame.width();
1038 final int height = frame.height();
1039
John Reck519ad482018-02-12 17:08:48 -08001040 final Picture picture = new Picture();
1041 final Canvas canvas = picture.beginRecording(width, height);
Tony Mak64b8d562017-12-28 17:44:02 +00001042 canvas.drawColor(Color.argb(0.6f, 0, 0, 0));
1043 final int thumbnailSize = mService.mContext.getResources().getDimensionPixelSize(
1044 com.android.internal.R.dimen.cross_profile_apps_thumbnail_size);
1045 final Drawable drawable = mService.mContext.getDrawable(thumbnailDrawableRes);
1046 drawable.setBounds(
1047 (width - thumbnailSize) / 2,
1048 (height - thumbnailSize) / 2,
1049 (width + thumbnailSize) / 2,
1050 (height + thumbnailSize) / 2);
Tony Makda4af232018-04-27 11:01:10 +01001051 drawable.setTint(mContext.getColor(android.R.color.white));
Tony Mak64b8d562017-12-28 17:44:02 +00001052 drawable.draw(canvas);
John Reck519ad482018-02-12 17:08:48 -08001053 picture.endRecording();
Tony Mak64b8d562017-12-28 17:44:02 +00001054
John Reck519ad482018-02-12 17:08:48 -08001055 return Bitmap.createBitmap(picture).createGraphicBufferHandle();
Tony Mak64b8d562017-12-28 17:44:02 +00001056 }
1057
1058 Animation createCrossProfileAppsThumbnailAnimationLocked(Rect appRect) {
1059 final Animation animation = loadAnimationRes(
1060 "android", com.android.internal.R.anim.cross_profile_apps_thumbnail_enter);
1061 return prepareThumbnailAnimationWithDuration(animation, appRect.width(),
1062 appRect.height(), 0, null);
1063 }
1064
1065 /**
Winson Chung399f6202014-03-19 10:47:20 -07001066 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001067 * when a thumbnail is specified with the pending animation override.
Winson Chung399f6202014-03-19 10:47:20 -07001068 */
Jorim Jaggide63d442016-03-14 14:56:56 +01001069 Animation createThumbnailAspectScaleAnimationLocked(Rect appRect, @Nullable Rect contentInsets,
lumark19a5d2e2019-10-11 16:19:30 +08001070 GraphicBuffer thumbnailHeader, WindowContainer container, int uiMode, int orientation) {
Winson Chung399f6202014-03-19 10:47:20 -07001071 Animation a;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001072 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chung399f6202014-03-19 10:47:20 -07001073 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001074 final int thumbHeightI = thumbnailHeader.getHeight();
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -07001075 final int appWidth = appRect.width();
Winson Chung399f6202014-03-19 10:47:20 -07001076
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -07001077 float scaleW = appWidth / thumbWidth;
lumark19a5d2e2019-10-11 16:19:30 +08001078 getNextAppTransitionStartRect(container, mTmpRect);
Jorim Jaggi09072002016-03-25 16:48:42 -07001079 final float fromX;
Manu Cornet57b61492017-01-24 18:19:05 +09001080 float fromY;
Jorim Jaggi09072002016-03-25 16:48:42 -07001081 final float toX;
Manu Cornet57b61492017-01-24 18:19:05 +09001082 float toY;
Jorim Jaggi09072002016-03-25 16:48:42 -07001083 final float pivotX;
1084 final float pivotY;
Manu Cornetd7376802017-01-13 13:44:07 -08001085 if (shouldScaleDownThumbnailTransition(uiMode, orientation)) {
Jorim Jaggi09072002016-03-25 16:48:42 -07001086 fromX = mTmpRect.left;
1087 fromY = mTmpRect.top;
1088
1089 // For the curved translate animation to work, the pivot points needs to be at the
1090 // same absolute position as the one from the real surface.
1091 toX = mTmpRect.width() / 2 * (scaleW - 1f) + appRect.left;
1092 toY = appRect.height() / 2 * (1 - 1 / scaleW) + appRect.top;
1093 pivotX = mTmpRect.width() / 2;
1094 pivotY = appRect.height() / 2 / scaleW;
Manu Cornet57b61492017-01-24 18:19:05 +09001095 if (mGridLayoutRecentsEnabled) {
1096 // In the grid layout, the header is displayed above the thumbnail instead of
1097 // overlapping it.
1098 fromY -= thumbHeightI;
1099 toY -= thumbHeightI * scaleW;
1100 }
Jorim Jaggi09072002016-03-25 16:48:42 -07001101 } else {
1102 pivotX = 0;
1103 pivotY = 0;
1104 fromX = mTmpRect.left;
1105 fromY = mTmpRect.top;
1106 toX = appRect.left;
1107 toY = appRect.top;
1108 }
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001109 final long duration = getAspectScaleDuration();
1110 final Interpolator interpolator = getAspectScaleInterpolator();
Winson Chung399f6202014-03-19 10:47:20 -07001111 if (mNextAppTransitionScaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001112 // Animation up from the thumbnail to the full screen
Jorim Jaggi8448f332016-03-14 17:50:37 +01001113 Animation scale = new ScaleAnimation(1f, scaleW, 1f, scaleW, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001114 scale.setInterpolator(interpolator);
1115 scale.setDuration(duration);
Jorim Jaggic6c89a82016-01-28 17:48:21 -08001116 Animation alpha = new AlphaAnimation(1f, 0f);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001117 alpha.setInterpolator(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
1118 ? THUMBNAIL_DOCK_INTERPOLATOR : mThumbnailFadeOutInterpolator);
1119 alpha.setDuration(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
1120 ? duration / 2
1121 : duration);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001122 Animation translate = createCurvedMotion(fromX, toX, fromY, toY);
1123 translate.setInterpolator(interpolator);
1124 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -07001125
Jorim Jaggide63d442016-03-14 14:56:56 +01001126 mTmpFromClipRect.set(0, 0, thumbWidthI, thumbHeightI);
1127 mTmpToClipRect.set(appRect);
1128
1129 // Containing frame is in screen space, but we need the clip rect in the
1130 // app space.
1131 mTmpToClipRect.offsetTo(0, 0);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001132 mTmpToClipRect.right = (int) (mTmpToClipRect.right / scaleW);
1133 mTmpToClipRect.bottom = (int) (mTmpToClipRect.bottom / scaleW);
Jorim Jaggide63d442016-03-14 14:56:56 +01001134
1135 if (contentInsets != null) {
Jorim Jaggi8448f332016-03-14 17:50:37 +01001136 mTmpToClipRect.inset((int) (-contentInsets.left * scaleW),
1137 (int) (-contentInsets.top * scaleW),
1138 (int) (-contentInsets.right * scaleW),
1139 (int) (-contentInsets.bottom * scaleW));
Jorim Jaggide63d442016-03-14 14:56:56 +01001140 }
1141
1142 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001143 clipAnim.setInterpolator(interpolator);
1144 clipAnim.setDuration(duration);
Jorim Jaggide63d442016-03-14 14:56:56 +01001145
Winson Chung399f6202014-03-19 10:47:20 -07001146 // This AnimationSet uses the Interpolators assigned above.
1147 AnimationSet set = new AnimationSet(false);
1148 set.addAnimation(scale);
Manu Cornet57b61492017-01-24 18:19:05 +09001149 if (!mGridLayoutRecentsEnabled) {
1150 // In the grid layout, the header should be shown for the whole animation.
1151 set.addAnimation(alpha);
1152 }
Winson Chunga4ccb862014-08-22 15:26:27 -07001153 set.addAnimation(translate);
Jorim Jaggide63d442016-03-14 14:56:56 +01001154 set.addAnimation(clipAnim);
Winson Chung399f6202014-03-19 10:47:20 -07001155 a = set;
1156 } else {
Winson Chunga4ccb862014-08-22 15:26:27 -07001157 // Animation down from the full screen to the thumbnail
Jorim Jaggi8448f332016-03-14 17:50:37 +01001158 Animation scale = new ScaleAnimation(scaleW, 1f, scaleW, 1f, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001159 scale.setInterpolator(interpolator);
1160 scale.setDuration(duration);
Winson Chunga4ccb862014-08-22 15:26:27 -07001161 Animation alpha = new AlphaAnimation(0f, 1f);
1162 alpha.setInterpolator(mThumbnailFadeInInterpolator);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001163 alpha.setDuration(duration);
1164 Animation translate = createCurvedMotion(toX, fromX, toY, fromY);
1165 translate.setInterpolator(interpolator);
1166 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -07001167
Winson Chunga4ccb862014-08-22 15:26:27 -07001168 // This AnimationSet uses the Interpolators assigned above.
1169 AnimationSet set = new AnimationSet(false);
1170 set.addAnimation(scale);
Manu Cornet57b61492017-01-24 18:19:05 +09001171 if (!mGridLayoutRecentsEnabled) {
1172 // In the grid layout, the header should be shown for the whole animation.
1173 set.addAnimation(alpha);
1174 }
Winson Chunga4ccb862014-08-22 15:26:27 -07001175 set.addAnimation(translate);
1176 a = set;
1177
1178 }
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -07001179 return prepareThumbnailAnimationWithDuration(a, appWidth, appRect.height(), 0,
Jorim Jaggic69bd222016-03-15 14:38:37 +01001180 null);
Winson Chung399f6202014-03-19 10:47:20 -07001181 }
1182
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001183 private Animation createCurvedMotion(float fromX, float toX, float fromY, float toY) {
1184
1185 // Almost no x-change - use linear animation
Jorim Jaggic69bd222016-03-15 14:38:37 +01001186 if (Math.abs(toX - fromX) < 1f || mNextAppTransition != TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001187 return new TranslateAnimation(fromX, toX, fromY, toY);
1188 } else {
1189 final Path path = createCurvedPath(fromX, toX, fromY, toY);
1190 return new CurvedTranslateAnimation(path);
1191 }
1192 }
1193
1194 private Path createCurvedPath(float fromX, float toX, float fromY, float toY) {
1195 final Path path = new Path();
1196 path.moveTo(fromX, fromY);
Jorim Jaggi1f458fb2016-03-25 17:36:37 -07001197
1198 if (fromY > toY) {
1199 // If the object needs to go up, move it in horizontal direction first, then vertical.
1200 path.cubicTo(fromX, fromY, toX, 0.9f * fromY + 0.1f * toY, toX, toY);
1201 } else {
1202 // If the object needs to go down, move it in vertical direction first, then horizontal.
1203 path.cubicTo(fromX, fromY, fromX, 0.1f * fromY + 0.9f * toY, toX, toY);
1204 }
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001205 return path;
1206 }
1207
1208 private long getAspectScaleDuration() {
1209 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggic69bd222016-03-15 14:38:37 +01001210 return (long) (THUMBNAIL_APP_TRANSITION_DURATION * 1.35f);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001211 } else {
1212 return THUMBNAIL_APP_TRANSITION_DURATION;
1213 }
1214 }
1215
1216 private Interpolator getAspectScaleInterpolator() {
1217 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
1218 return mFastOutSlowInInterpolator;
1219 } else {
1220 return TOUCH_RESPONSE_INTERPOLATOR;
1221 }
1222 }
1223
Winson Chung399f6202014-03-19 10:47:20 -07001224 /**
1225 * This alternate animation is created when we are doing a thumbnail transition, for the
1226 * activity that is leaving, and the activity that is entering.
1227 */
Winson Chunga4ccb862014-08-22 15:26:27 -07001228 Animation createAspectScaledThumbnailEnterExitAnimationLocked(int thumbTransitState,
Winsonb2024762016-04-05 17:32:30 -07001229 int uiMode, int orientation, int transit, Rect containingFrame, Rect contentInsets,
Matthew Ng43db6d22017-06-27 15:29:39 -07001230 @Nullable Rect surfaceInsets, @Nullable Rect stableInsets, boolean freeform,
lumark19a5d2e2019-10-11 16:19:30 +08001231 WindowContainer container) {
Winson Chung399f6202014-03-19 10:47:20 -07001232 Animation a;
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001233 final int appWidth = containingFrame.width();
1234 final int appHeight = containingFrame.height();
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001235 getDefaultNextAppTransitionStartRect(mTmpRect);
1236 final int thumbWidthI = mTmpRect.width();
Winson Chung399f6202014-03-19 10:47:20 -07001237 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001238 final int thumbHeightI = mTmpRect.height();
Winson Chung399f6202014-03-19 10:47:20 -07001239 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
Winsoncbb625b2016-07-06 15:24:15 -07001240 final int thumbStartX = mTmpRect.left - containingFrame.left - contentInsets.left;
Winson21700932016-03-24 17:26:23 -07001241 final int thumbStartY = mTmpRect.top - containingFrame.top;
Winson Chung399f6202014-03-19 10:47:20 -07001242
1243 switch (thumbTransitState) {
Jorim Jaggi8448f332016-03-14 17:50:37 +01001244 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP:
1245 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1246 final boolean scaleUp = thumbTransitState == THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
1247 if (freeform && scaleUp) {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001248 a = createAspectScaledThumbnailEnterFreeformAnimationLocked(
lumark19a5d2e2019-10-11 16:19:30 +08001249 containingFrame, surfaceInsets, container);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001250 } else if (freeform) {
1251 a = createAspectScaledThumbnailExitFreeformAnimationLocked(
lumark19a5d2e2019-10-11 16:19:30 +08001252 containingFrame, surfaceInsets, container);
Winson Chung2820c452014-04-15 15:34:44 -07001253 } else {
Winson21700932016-03-24 17:26:23 -07001254 AnimationSet set = new AnimationSet(true);
1255
1256 // In portrait, we scale to fit the width
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001257 mTmpFromClipRect.set(containingFrame);
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001258 mTmpToClipRect.set(containingFrame);
Jorim Jaggic6c89a82016-01-28 17:48:21 -08001259
1260 // Containing frame is in screen space, but we need the clip rect in the
1261 // app space.
1262 mTmpFromClipRect.offsetTo(0, 0);
1263 mTmpToClipRect.offsetTo(0, 0);
1264
1265 // Exclude insets region from the source clip.
1266 mTmpFromClipRect.inset(contentInsets);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001267 mNextAppTransitionInsets.set(contentInsets);
1268
Manu Cornetd7376802017-01-13 13:44:07 -08001269 if (shouldScaleDownThumbnailTransition(uiMode, orientation)) {
Jorim Jaggic69bd222016-03-15 14:38:37 +01001270 // We scale the width and clip to the top/left square
1271 float scale = thumbWidth /
1272 (appWidth - contentInsets.left - contentInsets.right);
Manu Cornetb68b7652017-01-23 19:37:53 +09001273 if (!mGridLayoutRecentsEnabled) {
1274 int unscaledThumbHeight = (int) (thumbHeight / scale);
1275 mTmpFromClipRect.bottom = mTmpFromClipRect.top + unscaledThumbHeight;
1276 }
Jorim Jaggic69bd222016-03-15 14:38:37 +01001277
1278 mNextAppTransitionInsets.set(contentInsets);
1279
Jorim Jaggi8448f332016-03-14 17:50:37 +01001280 Animation scaleAnim = new ScaleAnimation(
1281 scaleUp ? scale : 1, scaleUp ? 1 : scale,
1282 scaleUp ? scale : 1, scaleUp ? 1 : scale,
Jorim Jaggic69bd222016-03-15 14:38:37 +01001283 containingFrame.width() / 2f,
1284 containingFrame.height() / 2f + contentInsets.top);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001285 final float targetX = (mTmpRect.left - containingFrame.left);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001286 final float x = containingFrame.width() / 2f
1287 - containingFrame.width() / 2f * scale;
Jorim Jaggi8448f332016-03-14 17:50:37 +01001288 final float targetY = (mTmpRect.top - containingFrame.top);
Matthew Ng43db6d22017-06-27 15:29:39 -07001289 float y = containingFrame.height() / 2f
Jorim Jaggic69bd222016-03-15 14:38:37 +01001290 - containingFrame.height() / 2f * scale;
Matthew Ng43db6d22017-06-27 15:29:39 -07001291
1292 // During transition may require clipping offset from any top stable insets
1293 // such as the statusbar height when statusbar is hidden
1294 if (mLowRamRecentsEnabled && contentInsets.top == 0 && scaleUp) {
1295 mTmpFromClipRect.top += stableInsets.top;
1296 y += stableInsets.top;
1297 }
Jorim Jaggi8448f332016-03-14 17:50:37 +01001298 final float startX = targetX - x;
1299 final float startY = targetY - y;
1300 Animation clipAnim = scaleUp
1301 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1302 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1303 Animation translateAnim = scaleUp
Jorim Jaggic69bd222016-03-15 14:38:37 +01001304 ? createCurvedMotion(startX, 0, startY - contentInsets.top, 0)
1305 : createCurvedMotion(0, startX, 0, startY - contentInsets.top);
1306
Winson21700932016-03-24 17:26:23 -07001307 set.addAnimation(clipAnim);
1308 set.addAnimation(scaleAnim);
1309 set.addAnimation(translateAnim);
1310
1311 } else {
1312 // In landscape, we don't scale at all and only crop
1313 mTmpFromClipRect.bottom = mTmpFromClipRect.top + thumbHeightI;
1314 mTmpFromClipRect.right = mTmpFromClipRect.left + thumbWidthI;
1315
Jorim Jaggi8448f332016-03-14 17:50:37 +01001316 Animation clipAnim = scaleUp
1317 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1318 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1319 Animation translateAnim = scaleUp
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001320 ? createCurvedMotion(thumbStartX, 0,
1321 thumbStartY - contentInsets.top, 0)
1322 : createCurvedMotion(0, thumbStartX, 0,
1323 thumbStartY - contentInsets.top);
Winson21700932016-03-24 17:26:23 -07001324
1325 set.addAnimation(clipAnim);
1326 set.addAnimation(translateAnim);
1327 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001328 a = set;
Winson21700932016-03-24 17:26:23 -07001329 a.setZAdjustment(Animation.ZORDER_TOP);
Winson Chung2820c452014-04-15 15:34:44 -07001330 }
Winson Chung399f6202014-03-19 10:47:20 -07001331 break;
1332 }
1333 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001334 // Previous app window during the scale up
Winson Chung399f6202014-03-19 10:47:20 -07001335 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001336 // Fade out the source activity if we are animating to a wallpaper
Winson Chung399f6202014-03-19 10:47:20 -07001337 // activity.
1338 a = new AlphaAnimation(1, 0);
1339 } else {
Winson Chung399f6202014-03-19 10:47:20 -07001340 a = new AlphaAnimation(1, 1);
1341 }
1342 break;
1343 }
1344 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001345 // Target app window during the scale down
1346 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1347 // Fade in the destination activity if we are animating from a wallpaper
1348 // activity.
1349 a = new AlphaAnimation(0, 1);
1350 } else {
1351 a = new AlphaAnimation(1, 1);
1352 }
Winson Chung399f6202014-03-19 10:47:20 -07001353 break;
1354 }
Winson Chung399f6202014-03-19 10:47:20 -07001355 default:
1356 throw new RuntimeException("Invalid thumbnail transition state");
1357 }
1358
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001359 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight,
1360 getAspectScaleDuration(), getAspectScaleInterpolator());
Winson Chung399f6202014-03-19 10:47:20 -07001361 }
1362
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001363 private Animation createAspectScaledThumbnailEnterFreeformAnimationLocked(Rect frame,
lumark19a5d2e2019-10-11 16:19:30 +08001364 @Nullable Rect surfaceInsets, WindowContainer container) {
1365 getNextAppTransitionStartRect(container, mTmpRect);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001366 return createAspectScaledThumbnailFreeformAnimationLocked(mTmpRect, frame, surfaceInsets,
1367 true);
1368 }
1369
1370 private Animation createAspectScaledThumbnailExitFreeformAnimationLocked(Rect frame,
lumark19a5d2e2019-10-11 16:19:30 +08001371 @Nullable Rect surfaceInsets, WindowContainer container) {
1372 getNextAppTransitionStartRect(container, mTmpRect);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001373 return createAspectScaledThumbnailFreeformAnimationLocked(frame, mTmpRect, surfaceInsets,
1374 false);
1375 }
1376
1377 private AnimationSet createAspectScaledThumbnailFreeformAnimationLocked(Rect sourceFrame,
1378 Rect destFrame, @Nullable Rect surfaceInsets, boolean enter) {
1379 final float sourceWidth = sourceFrame.width();
1380 final float sourceHeight = sourceFrame.height();
1381 final float destWidth = destFrame.width();
1382 final float destHeight = destFrame.height();
1383 final float scaleH = enter ? sourceWidth / destWidth : destWidth / sourceWidth;
1384 final float scaleV = enter ? sourceHeight / destHeight : destHeight / sourceHeight;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001385 AnimationSet set = new AnimationSet(true);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001386 final int surfaceInsetsH = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001387 ? 0 : surfaceInsets.left + surfaceInsets.right;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001388 final int surfaceInsetsV = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001389 ? 0 : surfaceInsets.top + surfaceInsets.bottom;
1390 // We want the scaling to happen from the center of the surface. In order to achieve that,
1391 // we need to account for surface insets that will be used to enlarge the surface.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001392 final float scaleHCenter = ((enter ? destWidth : sourceWidth) + surfaceInsetsH) / 2;
1393 final float scaleVCenter = ((enter ? destHeight : sourceHeight) + surfaceInsetsV) / 2;
1394 final ScaleAnimation scale = enter ?
1395 new ScaleAnimation(scaleH, 1, scaleV, 1, scaleHCenter, scaleVCenter)
1396 : new ScaleAnimation(1, scaleH, 1, scaleV, scaleHCenter, scaleVCenter);
1397 final int sourceHCenter = sourceFrame.left + sourceFrame.width() / 2;
1398 final int sourceVCenter = sourceFrame.top + sourceFrame.height() / 2;
1399 final int destHCenter = destFrame.left + destFrame.width() / 2;
1400 final int destVCenter = destFrame.top + destFrame.height() / 2;
1401 final int fromX = enter ? sourceHCenter - destHCenter : destHCenter - sourceHCenter;
1402 final int fromY = enter ? sourceVCenter - destVCenter : destVCenter - sourceVCenter;
1403 final TranslateAnimation translation = enter ? new TranslateAnimation(fromX, 0, fromY, 0)
1404 : new TranslateAnimation(0, fromX, 0, fromY);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001405 set.addAnimation(scale);
1406 set.addAnimation(translation);
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001407
1408 final IRemoteCallback callback = mAnimationFinishedCallback;
1409 if (callback != null) {
1410 set.setAnimationListener(new Animation.AnimationListener() {
1411 @Override
1412 public void onAnimationStart(Animation animation) { }
1413
1414 @Override
1415 public void onAnimationEnd(Animation animation) {
lumark23b54592018-10-02 17:17:23 +08001416 mHandler.sendMessage(PooledLambda.obtainMessage(
1417 AppTransition::doAnimationCallback, callback));
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001418 }
1419
1420 @Override
1421 public void onAnimationRepeat(Animation animation) { }
1422 });
1423 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001424 return set;
1425 }
1426
Winson Chung399f6202014-03-19 10:47:20 -07001427 /**
Winson Chunga4ccb862014-08-22 15:26:27 -07001428 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001429 * when a thumbnail is specified with the pending animation override.
Winson Chunga4ccb862014-08-22 15:26:27 -07001430 */
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001431 Animation createThumbnailScaleAnimationLocked(int appWidth, int appHeight, int transit,
Winson Chungaa7fa012017-05-24 15:50:06 -07001432 GraphicBuffer thumbnailHeader) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001433 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001434 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001435 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chunga4ccb862014-08-22 15:26:27 -07001436 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001437 final int thumbHeightI = thumbnailHeader.getHeight();
Winson Chunga4ccb862014-08-22 15:26:27 -07001438 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1439
1440 if (mNextAppTransitionScaleUp) {
1441 // Animation for the thumbnail zooming from its initial size to the full screen
1442 float scaleW = appWidth / thumbWidth;
1443 float scaleH = appHeight / thumbHeight;
1444 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001445 computePivot(mTmpRect.left, 1 / scaleW),
1446 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001447 scale.setInterpolator(mDecelerateInterpolator);
1448
1449 Animation alpha = new AlphaAnimation(1, 0);
1450 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
1451
1452 // This AnimationSet uses the Interpolators assigned above.
1453 AnimationSet set = new AnimationSet(false);
1454 set.addAnimation(scale);
1455 set.addAnimation(alpha);
1456 a = set;
1457 } else {
1458 // Animation for the thumbnail zooming down from the full screen to its final size
1459 float scaleW = appWidth / thumbWidth;
1460 float scaleH = appHeight / thumbHeight;
1461 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001462 computePivot(mTmpRect.left, 1 / scaleW),
1463 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001464 }
1465
1466 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1467 }
1468
1469 /**
Winson Chung399f6202014-03-19 10:47:20 -07001470 * This animation is created when we are doing a thumbnail transition, for the activity that is
1471 * leaving, and the activity that is entering.
1472 */
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001473 Animation createThumbnailEnterExitAnimationLocked(int thumbTransitState, Rect containingFrame,
lumark19a5d2e2019-10-11 16:19:30 +08001474 int transit, WindowContainer container) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001475 final int appWidth = containingFrame.width();
1476 final int appHeight = containingFrame.height();
lumark19a5d2e2019-10-11 16:19:30 +08001477 final GraphicBuffer thumbnailHeader = getAppTransitionThumbnailHeader(container);
Winson Chung399f6202014-03-19 10:47:20 -07001478 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001479 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001480 final int thumbWidthI = thumbnailHeader != null ? thumbnailHeader.getWidth() : appWidth;
Winson Chung399f6202014-03-19 10:47:20 -07001481 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001482 final int thumbHeightI = thumbnailHeader != null ? thumbnailHeader.getHeight() : appHeight;
Winson Chung399f6202014-03-19 10:47:20 -07001483 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1484
1485 switch (thumbTransitState) {
1486 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
1487 // Entering app scales up with the thumbnail
1488 float scaleW = thumbWidth / appWidth;
1489 float scaleH = thumbHeight / appHeight;
1490 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001491 computePivot(mTmpRect.left, scaleW),
1492 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001493 break;
1494 }
1495 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
1496 // Exiting app while the thumbnail is scaling up should fade or stay in place
1497 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1498 // Fade out while bringing up selected activity. This keeps the
1499 // current activity from showing through a launching wallpaper
1500 // activity.
1501 a = new AlphaAnimation(1, 0);
1502 } else {
1503 // noop animation
1504 a = new AlphaAnimation(1, 1);
1505 }
1506 break;
1507 }
1508 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
1509 // Entering the other app, it should just be visible while we scale the thumbnail
1510 // down above it
1511 a = new AlphaAnimation(1, 1);
1512 break;
1513 }
1514 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1515 // Exiting the current app, the app should scale down with the thumbnail
1516 float scaleW = thumbWidth / appWidth;
1517 float scaleH = thumbHeight / appHeight;
1518 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001519 computePivot(mTmpRect.left, scaleW),
1520 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001521
1522 Animation alpha = new AlphaAnimation(1, 0);
1523
1524 AnimationSet set = new AnimationSet(true);
1525 set.addAnimation(scale);
1526 set.addAnimation(alpha);
1527 set.setZAdjustment(Animation.ZORDER_TOP);
1528 a = set;
1529 break;
1530 }
1531 default:
1532 throw new RuntimeException("Invalid thumbnail transition state");
1533 }
1534
1535 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1536 }
1537
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001538 private Animation createRelaunchAnimation(Rect containingFrame, Rect contentInsets) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001539 getDefaultNextAppTransitionStartRect(mTmpFromClipRect);
1540 final int left = mTmpFromClipRect.left;
1541 final int top = mTmpFromClipRect.top;
1542 mTmpFromClipRect.offset(-left, -top);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001543 // TODO: Isn't that strange that we ignore exact position of the containingFrame?
1544 mTmpToClipRect.set(0, 0, containingFrame.width(), containingFrame.height());
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001545 AnimationSet set = new AnimationSet(true);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001546 float fromWidth = mTmpFromClipRect.width();
1547 float toWidth = mTmpToClipRect.width();
1548 float fromHeight = mTmpFromClipRect.height();
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001549 // While the window might span the whole display, the actual content will be cropped to the
1550 // system decoration frame, for example when the window is docked. We need to take into
1551 // account the visible height when constructing the animation.
1552 float toHeight = mTmpToClipRect.height() - contentInsets.top - contentInsets.bottom;
1553 int translateAdjustment = 0;
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001554 if (fromWidth <= toWidth && fromHeight <= toHeight) {
1555 // The final window is larger in both dimensions than current window (e.g. we are
1556 // maximizing), so we can simply unclip the new window and there will be no disappearing
1557 // frame.
1558 set.addAnimation(new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect));
1559 } else {
1560 // The disappearing window has one larger dimension. We need to apply scaling, so the
1561 // first frame of the entry animation matches the old window.
1562 set.addAnimation(new ScaleAnimation(fromWidth / toWidth, 1, fromHeight / toHeight, 1));
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001563 // We might not be going exactly full screen, but instead be aligned under the status
1564 // bar using cropping. We still need to account for the cropped part, which will also
1565 // be scaled.
1566 translateAdjustment = (int) (contentInsets.top * fromHeight / toHeight);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001567 }
1568
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001569 // We animate the translation from the old position of the removed window, to the new
1570 // position of the added window. The latter might not be full screen, for example docked for
1571 // docked windows.
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001572 TranslateAnimation translate = new TranslateAnimation(left - containingFrame.left,
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001573 0, top - containingFrame.top - translateAdjustment, 0);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001574 set.addAnimation(translate);
1575 set.setDuration(DEFAULT_APP_TRANSITION_DURATION);
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07001576 set.setZAdjustment(Animation.ZORDER_TOP);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001577 return set;
1578 }
1579
Jorim Jaggic554b772015-06-04 16:07:57 -07001580 /**
1581 * @return true if and only if the first frame of the transition can be skipped, i.e. the first
1582 * frame of the transition doesn't change the visuals on screen, so we can start
1583 * directly with the second one
1584 */
1585 boolean canSkipFirstFrame() {
1586 return mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM
1587 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE
Jorim Jaggife762342016-10-13 14:33:27 +02001588 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CLIP_REVEAL
1589 && mNextAppTransition != TRANSIT_KEYGUARD_GOING_AWAY;
Jorim Jaggic554b772015-06-04 16:07:57 -07001590 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001591
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001592 RemoteAnimationController getRemoteAnimationController() {
1593 return mRemoteAnimationController;
1594 }
1595
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001596 /**
1597 *
1598 * @param frame These are the bounds of the window when it finishes the animation. This is where
1599 * the animation must usually finish in entrance animation, as the next frame will
1600 * display the window at these coordinates. In case of exit animation, this is
1601 * where the animation must start, as the frame before the animation is displaying
1602 * the window at these bounds.
1603 * @param insets Knowing where the window will be positioned is not enough. Some parts of the
1604 * window might be obscured, usually by the system windows (status bar and
1605 * navigation bar) and we use content insets to convey that information. This
1606 * usually affects the animation aspects vertically, as the system decoration is
1607 * at the top and the bottom. For example when we animate from full screen to
1608 * recents, we want to exclude the covered parts, because they won't match the
1609 * thumbnail after the last frame is executed.
1610 * @param surfaceInsets In rare situation the surface is larger than the content and we need to
1611 * know about this to make the animation frames match. We currently use
1612 * this for freeform windows, which have larger surfaces to display
1613 * shadows. When we animate them from recents, we want to match the content
1614 * to the recents thumbnail and hence need to account for the surface being
1615 * bigger.
1616 */
Jorim Jaggif84e2f62018-01-16 14:17:59 +01001617 Animation loadAnimation(LayoutParams lp, int transit, boolean enter, int uiMode,
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001618 int orientation, Rect frame, Rect displayFrame, Rect insets,
Matthew Ng43db6d22017-06-27 15:29:39 -07001619 @Nullable Rect surfaceInsets, @Nullable Rect stableInsets, boolean isVoiceInteraction,
lumark19a5d2e2019-10-11 16:19:30 +08001620 boolean freeform, WindowContainer container) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001621 Animation a;
Jorim Jaggife762342016-10-13 14:33:27 +02001622 if (isKeyguardGoingAwayTransit(transit) && enter) {
1623 a = loadKeyguardExitAnimation(transit);
1624 } else if (transit == TRANSIT_KEYGUARD_OCCLUDE) {
Selim Cinekdbf172e2018-08-08 18:31:45 +00001625 a = null;
Jorim Jaggife762342016-10-13 14:33:27 +02001626 } else if (transit == TRANSIT_KEYGUARD_UNOCCLUDE && !enter) {
1627 a = loadAnimationRes(lp, com.android.internal.R.anim.wallpaper_open_exit);
Adrian Roos93577212018-04-10 14:12:10 -07001628 } else if (transit == TRANSIT_CRASHING_ACTIVITY_CLOSE) {
1629 a = null;
Jorim Jaggife762342016-10-13 14:33:27 +02001630 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_OPEN
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001631 || transit == TRANSIT_TASK_OPEN
1632 || transit == TRANSIT_TASK_TO_FRONT)) {
1633 a = loadAnimationRes(lp, enter
1634 ? com.android.internal.R.anim.voice_activity_open_enter
1635 : com.android.internal.R.anim.voice_activity_open_exit);
Adrian Roosb125e0b2019-10-02 14:55:14 +02001636 ProtoLog.v(WM_DEBUG_APP_TRANSITIONS_ANIM,
1637 "applyAnimation voice: anim=%s transit=%s isEntrance=%b Callers=%s", a,
1638 appTransitionToString(transit), enter, Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001639 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_CLOSE
1640 || transit == TRANSIT_TASK_CLOSE
1641 || transit == TRANSIT_TASK_TO_BACK)) {
1642 a = loadAnimationRes(lp, enter
1643 ? com.android.internal.R.anim.voice_activity_close_enter
1644 : com.android.internal.R.anim.voice_activity_close_exit);
Adrian Roosb125e0b2019-10-02 14:55:14 +02001645 ProtoLog.v(WM_DEBUG_APP_TRANSITIONS_ANIM,
1646 "applyAnimation voice: anim=%s transit=%s isEntrance=%b Callers=%s", a,
1647 appTransitionToString(transit), enter, Debug.getCallers(3));
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001648 } else if (transit == TRANSIT_ACTIVITY_RELAUNCH) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001649 a = createRelaunchAnimation(frame, insets);
Adrian Roosb125e0b2019-10-02 14:55:14 +02001650 ProtoLog.v(WM_DEBUG_APP_TRANSITIONS_ANIM,
1651 "applyAnimation: anim=%s nextAppTransition=%d transit=%s Callers=%s", a,
1652 mNextAppTransition, appTransitionToString(transit),
1653 Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001654 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM) {
1655 a = loadAnimationRes(mNextAppTransitionPackage, enter ?
Craig Mautner164d4bb2012-11-26 13:51:23 -08001656 mNextAppTransitionEnter : mNextAppTransitionExit);
Adrian Roosb125e0b2019-10-02 14:55:14 +02001657 ProtoLog.v(WM_DEBUG_APP_TRANSITIONS_ANIM,
1658 "applyAnimation: anim=%s nextAppTransition=ANIM_CUSTOM transit=%s "
1659 + "isEntrance=%b Callers=%s",
1660 a, appTransitionToString(transit), enter, Debug.getCallers(3));
Winson Chung044d5292014-11-06 11:05:19 -08001661 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE) {
1662 a = loadAnimationRes(mNextAppTransitionPackage, mNextAppTransitionInPlace);
Adrian Roosb125e0b2019-10-02 14:55:14 +02001663 ProtoLog.v(WM_DEBUG_APP_TRANSITIONS_ANIM,
1664 "applyAnimation: anim=%s nextAppTransition=ANIM_CUSTOM_IN_PLACE "
1665 + "transit=%s Callers=%s",
1666 a, appTransitionToString(transit), Debug.getCallers(3));
Chet Haase10e23ab2015-02-11 15:08:38 -08001667 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001668 a = createClipRevealAnimationLocked(transit, enter, frame, displayFrame);
Adrian Roosb125e0b2019-10-02 14:55:14 +02001669 ProtoLog.v(WM_DEBUG_APP_TRANSITIONS_ANIM,
1670 "applyAnimation: anim=%s nextAppTransition=ANIM_CLIP_REVEAL "
1671 + "transit=%s Callers=%s",
1672 a, appTransitionToString(transit), Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001673 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_SCALE_UP) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001674 a = createScaleUpAnimationLocked(transit, enter, frame);
Adrian Roosb125e0b2019-10-02 14:55:14 +02001675 ProtoLog.v(WM_DEBUG_APP_TRANSITIONS_ANIM,
1676 "applyAnimation: anim=%s nextAppTransition=ANIM_SCALE_UP transit=%s "
1677 + "isEntrance=%s Callers=%s",
1678 a, appTransitionToString(transit), enter, Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001679 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
1680 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001681 mNextAppTransitionScaleUp =
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001682 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP);
Winson Chunga4ccb862014-08-22 15:26:27 -07001683 a = createThumbnailEnterExitAnimationLocked(getThumbnailTransitionState(enter),
lumark19a5d2e2019-10-11 16:19:30 +08001684 frame, transit, container);
Adrian Roosb125e0b2019-10-02 14:55:14 +02001685 ProtoLog.v(WM_DEBUG_APP_TRANSITIONS_ANIM,
1686 "applyAnimation: anim=%s nextAppTransition=%s transit=%s isEntrance=%b "
1687 + "Callers=%s",
1688 a, mNextAppTransitionScaleUp
1689 ? "ANIM_THUMBNAIL_SCALE_UP" : "ANIM_THUMBNAIL_SCALE_DOWN",
1690 appTransitionToString(transit), enter, Debug.getCallers(3));
Winson Chunga4ccb862014-08-22 15:26:27 -07001691 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
1692 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN) {
1693 mNextAppTransitionScaleUp =
1694 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP);
1695 a = createAspectScaledThumbnailEnterExitAnimationLocked(
Winsonb2024762016-04-05 17:32:30 -07001696 getThumbnailTransitionState(enter), uiMode, orientation, transit, frame,
lumark19a5d2e2019-10-11 16:19:30 +08001697 insets, surfaceInsets, stableInsets, freeform, container);
Adrian Roosb125e0b2019-10-02 14:55:14 +02001698 ProtoLog.v(WM_DEBUG_APP_TRANSITIONS_ANIM,
1699 "applyAnimation: anim=%s nextAppTransition=%s transit=%s isEntrance=%b "
1700 + "Callers=%s",
1701 a, mNextAppTransitionScaleUp
1702 ? "ANIM_THUMBNAIL_ASPECT_SCALE_UP"
1703 : "ANIM_THUMBNAIL_ASPECT_SCALE_DOWN",
1704 appTransitionToString(transit), enter, Debug.getCallers(3));
Tony Mak83546a82018-01-22 13:56:20 +00001705 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS && enter) {
Jorim Jaggi98a9d202018-03-26 16:17:07 +02001706 a = loadAnimationRes("android",
1707 com.android.internal.R.anim.task_open_enter_cross_profile_apps);
Adrian Roosb125e0b2019-10-02 14:55:14 +02001708 ProtoLog.v(WM_DEBUG_APP_TRANSITIONS_ANIM,
1709 "applyAnimation NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS: "
1710 + "anim=%s transit=%s isEntrance=true Callers=%s",
1711 a, appTransitionToString(transit), Debug.getCallers(3));
Evan Roskycf76bed2019-01-15 10:33:58 -08001712 } else if (transit == TRANSIT_TASK_CHANGE_WINDOWING_MODE) {
1713 // In the absence of a specific adapter, we just want to keep everything stationary.
1714 a = new AlphaAnimation(1.f, 1.f);
1715 a.setDuration(WindowChangeAnimationSpec.ANIMATION_DURATION);
Adrian Roosb125e0b2019-10-02 14:55:14 +02001716 ProtoLog.v(WM_DEBUG_APP_TRANSITIONS_ANIM,
1717 "applyAnimation: anim=%s transit=%s isEntrance=%b Callers=%s",
1718 a, appTransitionToString(transit), enter, Debug.getCallers(3));
Craig Mautner164d4bb2012-11-26 13:51:23 -08001719 } else {
1720 int animAttr = 0;
1721 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001722 case TRANSIT_ACTIVITY_OPEN:
Jorim Jaggi0a1523d2018-04-19 17:48:38 +02001723 case TRANSIT_TRANSLUCENT_ACTIVITY_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001724 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001725 ? WindowAnimation_activityOpenEnterAnimation
1726 : WindowAnimation_activityOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001727 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001728 case TRANSIT_ACTIVITY_CLOSE:
Jorim Jaggi0a1523d2018-04-19 17:48:38 +02001729 case TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001730 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001731 ? WindowAnimation_activityCloseEnterAnimation
1732 : WindowAnimation_activityCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001733 break;
Jorim Jaggi192086e2016-03-11 17:17:03 +01001734 case TRANSIT_DOCK_TASK_FROM_RECENTS:
Craig Mautner4b71aa12012-12-27 17:20:01 -08001735 case TRANSIT_TASK_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001736 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001737 ? WindowAnimation_taskOpenEnterAnimation
1738 : WindowAnimation_taskOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001739 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001740 case TRANSIT_TASK_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001741 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001742 ? WindowAnimation_taskCloseEnterAnimation
1743 : WindowAnimation_taskCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001744 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001745 case TRANSIT_TASK_TO_FRONT:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001746 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001747 ? WindowAnimation_taskToFrontEnterAnimation
1748 : WindowAnimation_taskToFrontExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001749 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001750 case TRANSIT_TASK_TO_BACK:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001751 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001752 ? WindowAnimation_taskToBackEnterAnimation
1753 : WindowAnimation_taskToBackExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001754 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001755 case TRANSIT_WALLPAPER_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001756 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001757 ? WindowAnimation_wallpaperOpenEnterAnimation
1758 : WindowAnimation_wallpaperOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001759 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001760 case TRANSIT_WALLPAPER_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001761 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001762 ? WindowAnimation_wallpaperCloseEnterAnimation
1763 : WindowAnimation_wallpaperCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001764 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001765 case TRANSIT_WALLPAPER_INTRA_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001766 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001767 ? WindowAnimation_wallpaperIntraOpenEnterAnimation
1768 : WindowAnimation_wallpaperIntraOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001769 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001770 case TRANSIT_WALLPAPER_INTRA_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001771 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001772 ? WindowAnimation_wallpaperIntraCloseEnterAnimation
1773 : WindowAnimation_wallpaperIntraCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001774 break;
Craig Mautnerbb742462014-07-07 15:28:55 -07001775 case TRANSIT_TASK_OPEN_BEHIND:
1776 animAttr = enter
1777 ? WindowAnimation_launchTaskBehindSourceAnimation
Craig Mautner3b2cd1d2014-08-25 14:25:54 -07001778 : WindowAnimation_launchTaskBehindTargetAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001779 }
Jorim Jaggi0a1523d2018-04-19 17:48:38 +02001780 a = animAttr != 0 ? loadAnimationAttr(lp, animAttr, transit) : null;
Adrian Roosb125e0b2019-10-02 14:55:14 +02001781 ProtoLog.v(WM_DEBUG_APP_TRANSITIONS_ANIM,
1782 "applyAnimation: anim=%s animAttr=0x%x transit=%s isEntrance=%b "
1783 + "Callers=%s",
1784 a, animAttr, appTransitionToString(transit), enter,
1785 Debug.getCallers(3));
Craig Mautner164d4bb2012-11-26 13:51:23 -08001786 }
1787 return a;
1788 }
1789
Jorim Jaggife762342016-10-13 14:33:27 +02001790 private Animation loadKeyguardExitAnimation(int transit) {
1791 if ((mNextAppTransitionFlags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_NO_ANIMATION) != 0) {
1792 return null;
1793 }
1794 final boolean toShade =
1795 (mNextAppTransitionFlags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_TO_SHADE) != 0;
Issei Suzuki5609ccb2019-06-13 15:04:08 +02001796 final boolean subtle =
1797 (mNextAppTransitionFlags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_SUBTLE_ANIMATION) != 0;
Jorim Jaggife762342016-10-13 14:33:27 +02001798 return mService.mPolicy.createHiddenByKeyguardExit(
Issei Suzuki5609ccb2019-06-13 15:04:08 +02001799 transit == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER, toShade, subtle);
Jorim Jaggife762342016-10-13 14:33:27 +02001800 }
1801
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001802 int getAppStackClipMode() {
Matthew Ngbf1d9852017-03-14 12:23:09 -07001803 // When dismiss keyguard animation occurs, clip before the animation to prevent docked
1804 // app from showing beyond the divider
1805 if (mNextAppTransition == TRANSIT_KEYGUARD_GOING_AWAY
1806 || mNextAppTransition == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER) {
1807 return STACK_CLIP_BEFORE_ANIM;
1808 }
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001809 return mNextAppTransition == TRANSIT_ACTIVITY_RELAUNCH
Jorim Jaggic69bd222016-03-15 14:38:37 +01001810 || mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
Jorim Jaggi1f458fb2016-03-25 17:36:37 -07001811 || mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001812 ? STACK_CLIP_NONE
1813 : STACK_CLIP_AFTER_ANIM;
1814 }
1815
Jorim Jaggife762342016-10-13 14:33:27 +02001816 public int getTransitFlags() {
1817 return mNextAppTransitionFlags;
1818 }
1819
Craig Mautner164d4bb2012-11-26 13:51:23 -08001820 void postAnimationCallback() {
1821 if (mNextAppTransitionCallback != null) {
lumark23b54592018-10-02 17:17:23 +08001822 mHandler.sendMessage(PooledLambda.obtainMessage(AppTransition::doAnimationCallback,
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001823 mNextAppTransitionCallback));
Craig Mautner164d4bb2012-11-26 13:51:23 -08001824 mNextAppTransitionCallback = null;
1825 }
1826 }
1827
1828 void overridePendingAppTransition(String packageName, int enterAnim, int exitAnim,
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001829 IRemoteCallback startedCallback) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001830 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001831 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001832 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001833 mNextAppTransitionPackage = packageName;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001834 mNextAppTransitionEnter = enterAnim;
1835 mNextAppTransitionExit = exitAnim;
1836 postAnimationCallback();
1837 mNextAppTransitionCallback = startedCallback;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001838 }
1839 }
1840
1841 void overridePendingAppTransitionScaleUp(int startX, int startY, int startWidth,
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001842 int startHeight) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001843 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001844 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001845 mNextAppTransitionType = NEXT_TRANSIT_TYPE_SCALE_UP;
Winson4c3fecd2016-07-13 12:29:48 -07001846 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001847 postAnimationCallback();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001848 }
1849 }
1850
Chet Haase10e23ab2015-02-11 15:08:38 -08001851 void overridePendingAppTransitionClipReveal(int startX, int startY,
1852 int startWidth, int startHeight) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001853 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001854 clear();
Chet Haase10e23ab2015-02-11 15:08:38 -08001855 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CLIP_REVEAL;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001856 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Chet Haase10e23ab2015-02-11 15:08:38 -08001857 postAnimationCallback();
Chet Haase10e23ab2015-02-11 15:08:38 -08001858 }
1859 }
1860
Winson Chungaa7fa012017-05-24 15:50:06 -07001861 void overridePendingAppTransitionThumb(GraphicBuffer srcThumb, int startX, int startY,
Craig Mautner164d4bb2012-11-26 13:51:23 -08001862 IRemoteCallback startedCallback, boolean scaleUp) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001863 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001864 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001865 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP
1866 : NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001867 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001868 putDefaultNextAppTransitionCoordinates(startX, startY, 0, 0, srcThumb);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001869 postAnimationCallback();
1870 mNextAppTransitionCallback = startedCallback;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001871 }
1872 }
1873
Winson Chungaa7fa012017-05-24 15:50:06 -07001874 void overridePendingAppTransitionAspectScaledThumb(GraphicBuffer srcThumb, int startX, int startY,
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001875 int targetWidth, int targetHeight, IRemoteCallback startedCallback, boolean scaleUp) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001876 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001877 clear();
Winson Chunga4ccb862014-08-22 15:26:27 -07001878 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1879 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Winson Chunga4ccb862014-08-22 15:26:27 -07001880 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001881 putDefaultNextAppTransitionCoordinates(startX, startY, targetWidth, targetHeight,
1882 srcThumb);
Winson Chunga4ccb862014-08-22 15:26:27 -07001883 postAnimationCallback();
1884 mNextAppTransitionCallback = startedCallback;
Winson Chunga4ccb862014-08-22 15:26:27 -07001885 }
1886 }
1887
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001888 void overridePendingAppTransitionMultiThumb(AppTransitionAnimationSpec[] specs,
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001889 IRemoteCallback onAnimationStartedCallback, IRemoteCallback onAnimationFinishedCallback,
1890 boolean scaleUp) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001891 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001892 clear();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001893 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1894 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001895 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi43102412015-11-11 16:28:37 +01001896 if (specs != null) {
1897 for (int i = 0; i < specs.length; i++) {
1898 AppTransitionAnimationSpec spec = specs[i];
1899 if (spec != null) {
lumark19a5d2e2019-10-11 16:19:30 +08001900 final WindowContainer container = findTask(spec.taskId);
1901 if (container == null) {
1902 continue;
1903 }
1904 mNextAppTransitionAnimationsSpecs.put(container.hashCode(), spec);
Jorim Jaggi43102412015-11-11 16:28:37 +01001905 if (i == 0) {
1906 // In full screen mode, the transition code depends on the default spec
1907 // to be set.
1908 Rect rect = spec.rect;
1909 putDefaultNextAppTransitionCoordinates(rect.left, rect.top,
Winson Chungaa7fa012017-05-24 15:50:06 -07001910 rect.width(), rect.height(), spec.buffer);
Jorim Jaggi43102412015-11-11 16:28:37 +01001911 }
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001912 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001913 }
1914 }
1915 postAnimationCallback();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001916 mNextAppTransitionCallback = onAnimationStartedCallback;
1917 mAnimationFinishedCallback = onAnimationFinishedCallback;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001918 }
1919 }
1920
lumark19a5d2e2019-10-11 16:19:30 +08001921 private Task findTask(int taskId) {
1922 if (taskId < 0) {
1923 return null;
1924 }
lumarkbc0032a2019-11-01 21:38:13 +08001925 final ArrayList<Task> tasks = new ArrayList<>();
lumark19a5d2e2019-10-11 16:19:30 +08001926 mDisplayContent.forAllTasks(task -> {
1927 if (task.mTaskId == taskId) {
1928 tasks.add(task);
lumarkbc0032a2019-11-01 21:38:13 +08001929 return true;
lumark19a5d2e2019-10-11 16:19:30 +08001930 }
lumarkbc0032a2019-11-01 21:38:13 +08001931 return false;
lumark19a5d2e2019-10-11 16:19:30 +08001932 });
1933 return tasks.size() == 1 ? tasks.get(0) : null;
1934 }
1935
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001936 void overridePendingAppTransitionMultiThumbFuture(
1937 IAppTransitionAnimationSpecsFuture specsFuture, IRemoteCallback callback,
1938 boolean scaleUp) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001939 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001940 clear();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001941 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1942 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001943 mNextAppTransitionAnimationsSpecsFuture = specsFuture;
1944 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001945 mNextAppTransitionFutureCallback = callback;
Riddle Hsuec6467c2019-02-15 00:10:56 +08001946 if (isReady()) {
1947 fetchAppTransitionSpecsFromFuture();
1948 }
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001949 }
1950 }
1951
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001952 void overridePendingAppTransitionRemote(RemoteAnimationAdapter remoteAnimationAdapter) {
Adrian Roosb125e0b2019-10-02 14:55:14 +02001953 ProtoLog.i(WM_DEBUG_APP_TRANSITIONS, "Override pending remote transitionSet=%b adapter=%s",
1954 isTransitionSet(), remoteAnimationAdapter);
Winson Chung044d5292014-11-06 11:05:19 -08001955 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001956 clear();
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001957 mNextAppTransitionType = NEXT_TRANSIT_TYPE_REMOTE;
1958 mRemoteAnimationController = new RemoteAnimationController(mService,
lumark23b54592018-10-02 17:17:23 +08001959 remoteAnimationAdapter, mHandler);
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001960 }
1961 }
1962
1963 void overrideInPlaceAppTransition(String packageName, int anim) {
1964 if (canOverridePendingAppTransition()) {
1965 clear();
Winson Chung044d5292014-11-06 11:05:19 -08001966 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE;
1967 mNextAppTransitionPackage = packageName;
1968 mNextAppTransitionInPlace = anim;
Winson Chung044d5292014-11-06 11:05:19 -08001969 }
1970 }
1971
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001972 /**
Tony Mak089c35e2017-12-18 20:34:14 +00001973 * @see {@link #NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS}
1974 */
1975 void overridePendingAppTransitionStartCrossProfileApps() {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001976 if (canOverridePendingAppTransition()) {
Tony Mak089c35e2017-12-18 20:34:14 +00001977 clear();
1978 mNextAppTransitionType = NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS;
1979 postAnimationCallback();
1980 }
1981 }
1982
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001983 private boolean canOverridePendingAppTransition() {
1984 // Remote animations always take precedence
1985 return isTransitionSet() && mNextAppTransitionType != NEXT_TRANSIT_TYPE_REMOTE;
1986 }
1987
Tony Mak089c35e2017-12-18 20:34:14 +00001988 /**
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001989 * If a future is set for the app transition specs, fetch it in another thread.
1990 */
1991 private void fetchAppTransitionSpecsFromFuture() {
1992 if (mNextAppTransitionAnimationsSpecsFuture != null) {
1993 mNextAppTransitionAnimationsSpecsPending = true;
1994 final IAppTransitionAnimationSpecsFuture future
1995 = mNextAppTransitionAnimationsSpecsFuture;
1996 mNextAppTransitionAnimationsSpecsFuture = null;
Jorim Jaggied410b62017-05-05 15:16:14 +02001997 mDefaultExecutor.execute(() -> {
1998 AppTransitionAnimationSpec[] specs = null;
1999 try {
2000 Binder.allowBlocking(future.asBinder());
2001 specs = future.get();
2002 } catch (RemoteException e) {
2003 Slog.w(TAG, "Failed to fetch app transition specs: " + e);
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01002004 }
Wale Ogunwaledb485de2018-10-29 09:47:07 -07002005 synchronized (mService.mGlobalLock) {
Jorim Jaggied410b62017-05-05 15:16:14 +02002006 mNextAppTransitionAnimationsSpecsPending = false;
2007 overridePendingAppTransitionMultiThumb(specs,
2008 mNextAppTransitionFutureCallback, null /* finishedCallback */,
2009 mNextAppTransitionScaleUp);
2010 mNextAppTransitionFutureCallback = null;
Riddle Hsu8419e4b2019-09-18 23:28:01 +08002011 mService.requestTraversal();
Jorim Jaggied410b62017-05-05 15:16:14 +02002012 }
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01002013 });
2014 }
2015 }
2016
Craig Mautner164d4bb2012-11-26 13:51:23 -08002017 @Override
2018 public String toString() {
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07002019 return "mNextAppTransition=" + appTransitionToString(mNextAppTransition);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002020 }
2021
Craig Mautner4b71aa12012-12-27 17:20:01 -08002022 /**
2023 * Returns the human readable name of a window transition.
2024 *
2025 * @param transition The window transition.
2026 * @return The transition symbolic name.
2027 */
2028 public static String appTransitionToString(int transition) {
2029 switch (transition) {
2030 case TRANSIT_UNSET: {
2031 return "TRANSIT_UNSET";
2032 }
2033 case TRANSIT_NONE: {
2034 return "TRANSIT_NONE";
2035 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002036 case TRANSIT_ACTIVITY_OPEN: {
2037 return "TRANSIT_ACTIVITY_OPEN";
2038 }
2039 case TRANSIT_ACTIVITY_CLOSE: {
2040 return "TRANSIT_ACTIVITY_CLOSE";
2041 }
2042 case TRANSIT_TASK_OPEN: {
2043 return "TRANSIT_TASK_OPEN";
2044 }
2045 case TRANSIT_TASK_CLOSE: {
2046 return "TRANSIT_TASK_CLOSE";
2047 }
2048 case TRANSIT_TASK_TO_FRONT: {
2049 return "TRANSIT_TASK_TO_FRONT";
2050 }
2051 case TRANSIT_TASK_TO_BACK: {
2052 return "TRANSIT_TASK_TO_BACK";
2053 }
2054 case TRANSIT_WALLPAPER_CLOSE: {
2055 return "TRANSIT_WALLPAPER_CLOSE";
2056 }
2057 case TRANSIT_WALLPAPER_OPEN: {
2058 return "TRANSIT_WALLPAPER_OPEN";
2059 }
2060 case TRANSIT_WALLPAPER_INTRA_OPEN: {
2061 return "TRANSIT_WALLPAPER_INTRA_OPEN";
2062 }
2063 case TRANSIT_WALLPAPER_INTRA_CLOSE: {
2064 return "TRANSIT_WALLPAPER_INTRA_CLOSE";
2065 }
Craig Mautnerbb742462014-07-07 15:28:55 -07002066 case TRANSIT_TASK_OPEN_BEHIND: {
2067 return "TRANSIT_TASK_OPEN_BEHIND";
2068 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07002069 case TRANSIT_ACTIVITY_RELAUNCH: {
2070 return "TRANSIT_ACTIVITY_RELAUNCH";
2071 }
Jorim Jaggi192086e2016-03-11 17:17:03 +01002072 case TRANSIT_DOCK_TASK_FROM_RECENTS: {
2073 return "TRANSIT_DOCK_TASK_FROM_RECENTS";
2074 }
Jorim Jaggife762342016-10-13 14:33:27 +02002075 case TRANSIT_KEYGUARD_GOING_AWAY: {
2076 return "TRANSIT_KEYGUARD_GOING_AWAY";
2077 }
2078 case TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER: {
2079 return "TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER";
2080 }
2081 case TRANSIT_KEYGUARD_OCCLUDE: {
2082 return "TRANSIT_KEYGUARD_OCCLUDE";
2083 }
2084 case TRANSIT_KEYGUARD_UNOCCLUDE: {
2085 return "TRANSIT_KEYGUARD_UNOCCLUDE";
2086 }
Jorim Jaggi98a9d202018-03-26 16:17:07 +02002087 case TRANSIT_TRANSLUCENT_ACTIVITY_OPEN: {
2088 return "TRANSIT_TRANSLUCENT_ACTIVITY_OPEN";
2089 }
2090 case TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE: {
2091 return "TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE";
2092 }
Jorim Jaggi9c52ebb2018-06-01 14:45:24 +02002093 case TRANSIT_CRASHING_ACTIVITY_CLOSE: {
2094 return "TRANSIT_CRASHING_ACTIVITY_CLOSE";
2095 }
Issei Suzukicac2a502019-04-16 16:52:50 +02002096 case TRANSIT_SHOW_SINGLE_TASK_DISPLAY: {
2097 return "TRANSIT_SHOW_SINGLE_TASK_DISPLAY";
2098 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002099 default: {
Jorim Jaggi9c52ebb2018-06-01 14:45:24 +02002100 return "<UNKNOWN: " + transition + ">";
Craig Mautner4b71aa12012-12-27 17:20:01 -08002101 }
2102 }
2103 }
2104
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002105 private String appStateToString() {
2106 switch (mAppTransitionState) {
2107 case APP_STATE_IDLE:
2108 return "APP_STATE_IDLE";
2109 case APP_STATE_READY:
2110 return "APP_STATE_READY";
2111 case APP_STATE_RUNNING:
2112 return "APP_STATE_RUNNING";
2113 case APP_STATE_TIMEOUT:
2114 return "APP_STATE_TIMEOUT";
2115 default:
2116 return "unknown state=" + mAppTransitionState;
2117 }
2118 }
2119
2120 private String transitTypeToString() {
2121 switch (mNextAppTransitionType) {
2122 case NEXT_TRANSIT_TYPE_NONE:
2123 return "NEXT_TRANSIT_TYPE_NONE";
2124 case NEXT_TRANSIT_TYPE_CUSTOM:
2125 return "NEXT_TRANSIT_TYPE_CUSTOM";
Winson Chung044d5292014-11-06 11:05:19 -08002126 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
2127 return "NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002128 case NEXT_TRANSIT_TYPE_SCALE_UP:
2129 return "NEXT_TRANSIT_TYPE_SCALE_UP";
2130 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
2131 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP";
2132 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
2133 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN";
Winson Chunga4ccb862014-08-22 15:26:27 -07002134 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
2135 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP";
2136 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN:
2137 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN";
Tony Mak64b8d562017-12-28 17:44:02 +00002138 case NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS:
2139 return "NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002140 default:
2141 return "unknown type=" + mNextAppTransitionType;
2142 }
2143 }
2144
Jeffrey Huangcb782852019-12-05 11:28:11 -08002145 void dumpDebug(ProtoOutputStream proto, long fieldId) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07002146 final long token = proto.start(fieldId);
2147 proto.write(APP_TRANSITION_STATE, mAppTransitionState);
2148 proto.write(LAST_USED_APP_TRANSITION, mLastUsedAppTransition);
2149 proto.end(token);
2150 }
2151
Craig Mautner164d4bb2012-11-26 13:51:23 -08002152 @Override
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002153 public void dump(PrintWriter pw, String prefix) {
2154 pw.print(prefix); pw.println(this);
2155 pw.print(prefix); pw.print("mAppTransitionState="); pw.println(appStateToString());
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002156 if (mNextAppTransitionType != NEXT_TRANSIT_TYPE_NONE) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002157 pw.print(prefix); pw.print("mNextAppTransitionType=");
2158 pw.println(transitTypeToString());
Craig Mautner164d4bb2012-11-26 13:51:23 -08002159 }
2160 switch (mNextAppTransitionType) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002161 case NEXT_TRANSIT_TYPE_CUSTOM:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002162 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Craig Mautner164d4bb2012-11-26 13:51:23 -08002163 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002164 pw.print(prefix); pw.print("mNextAppTransitionEnter=0x");
Craig Mautner164d4bb2012-11-26 13:51:23 -08002165 pw.print(Integer.toHexString(mNextAppTransitionEnter));
2166 pw.print(" mNextAppTransitionExit=0x");
2167 pw.println(Integer.toHexString(mNextAppTransitionExit));
2168 break;
Winson Chung044d5292014-11-06 11:05:19 -08002169 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002170 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Winson Chung044d5292014-11-06 11:05:19 -08002171 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002172 pw.print(prefix); pw.print("mNextAppTransitionInPlace=0x");
Winson Chung044d5292014-11-06 11:05:19 -08002173 pw.print(Integer.toHexString(mNextAppTransitionInPlace));
2174 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002175 case NEXT_TRANSIT_TYPE_SCALE_UP: {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002176 getDefaultNextAppTransitionStartRect(mTmpRect);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002177 pw.print(prefix); pw.print("mNextAppTransitionStartX=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002178 pw.print(mTmpRect.left);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002179 pw.print(" mNextAppTransitionStartY=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002180 pw.println(mTmpRect.top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002181 pw.print(prefix); pw.print("mNextAppTransitionStartWidth=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002182 pw.print(mTmpRect.width());
Craig Mautner164d4bb2012-11-26 13:51:23 -08002183 pw.print(" mNextAppTransitionStartHeight=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002184 pw.println(mTmpRect.height());
Craig Mautner164d4bb2012-11-26 13:51:23 -08002185 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002186 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002187 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
2188 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
Winson Chunga4ccb862014-08-22 15:26:27 -07002189 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002190 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN: {
2191 pw.print(prefix); pw.print("mDefaultNextAppTransitionAnimationSpec=");
2192 pw.println(mDefaultNextAppTransitionAnimationSpec);
2193 pw.print(prefix); pw.print("mNextAppTransitionAnimationsSpecs=");
2194 pw.println(mNextAppTransitionAnimationsSpecs);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002195 pw.print(prefix); pw.print("mNextAppTransitionScaleUp=");
2196 pw.println(mNextAppTransitionScaleUp);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002197 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002198 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002199 }
2200 if (mNextAppTransitionCallback != null) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002201 pw.print(prefix); pw.print("mNextAppTransitionCallback=");
2202 pw.println(mNextAppTransitionCallback);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002203 }
Chong Zhang60091a92016-07-27 17:52:45 -07002204 if (mLastUsedAppTransition != TRANSIT_NONE) {
2205 pw.print(prefix); pw.print("mLastUsedAppTransition=");
2206 pw.println(appTransitionToString(mLastUsedAppTransition));
2207 pw.print(prefix); pw.print("mLastOpeningApp=");
2208 pw.println(mLastOpeningApp);
2209 pw.print(prefix); pw.print("mLastClosingApp=");
2210 pw.println(mLastClosingApp);
Evan Rosky2289ba12018-11-19 18:28:18 -08002211 pw.print(prefix); pw.print("mLastChangingApp=");
2212 pw.println(mLastChangingApp);
Chong Zhang60091a92016-07-27 17:52:45 -07002213 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002214 }
Amith Yamasani4befbec2013-07-10 16:18:01 -07002215
2216 public void setCurrentUser(int newUserId) {
2217 mCurrentUserId = newUserId;
2218 }
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002219
2220 /**
2221 * @return true if transition is not running and should not be skipped, false if transition is
2222 * already running
2223 */
Jorim Jaggif84e2f62018-01-16 14:17:59 +01002224 boolean prepareAppTransitionLocked(@TransitionType int transit, boolean alwaysKeepCurrent,
2225 @TransitionFlags int flags, boolean forceOverride) {
Adrian Roosb125e0b2019-10-02 14:55:14 +02002226 ProtoLog.v(WM_DEBUG_APP_TRANSITIONS,
2227 "Prepare app transition: transit=%s %s alwaysKeepCurrent=%b displayId=%d "
2228 + "Callers=%s",
2229 appTransitionToString(transit), this, alwaysKeepCurrent,
2230 mDisplayContent.getDisplayId(), Debug.getCallers(5));
Jorim Jaggi9c52ebb2018-06-01 14:45:24 +02002231 final boolean allowSetCrashing = !isKeyguardTransit(mNextAppTransition)
2232 && transit == TRANSIT_CRASHING_ACTIVITY_CLOSE;
Jorim Jaggife762342016-10-13 14:33:27 +02002233 if (forceOverride || isKeyguardTransit(transit) || !isTransitionSet()
Jorim Jaggi9c52ebb2018-06-01 14:45:24 +02002234 || mNextAppTransition == TRANSIT_NONE || allowSetCrashing) {
Jorim Jaggife762342016-10-13 14:33:27 +02002235 setAppTransition(transit, flags);
Jorim Jaggia69243a2017-06-15 15:10:38 -04002236 }
2237 // We never want to change from a Keyguard transit to a non-Keyguard transit, as our logic
Adrian Roos93577212018-04-10 14:12:10 -07002238 // relies on the fact that we always execute a Keyguard transition after preparing one. We
2239 // also don't want to change away from a crashing transition.
Jorim Jaggi9c52ebb2018-06-01 14:45:24 +02002240 else if (!alwaysKeepCurrent && !isKeyguardTransit(mNextAppTransition)
2241 && mNextAppTransition != TRANSIT_CRASHING_ACTIVITY_CLOSE) {
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002242 if (transit == TRANSIT_TASK_OPEN && isTransitionEqual(TRANSIT_TASK_CLOSE)) {
2243 // Opening a new task always supersedes a close for the anim.
Jorim Jaggife762342016-10-13 14:33:27 +02002244 setAppTransition(transit, flags);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002245 } else if (transit == TRANSIT_ACTIVITY_OPEN
2246 && isTransitionEqual(TRANSIT_ACTIVITY_CLOSE)) {
2247 // Opening a new activity always supersedes a close for the anim.
Jorim Jaggife762342016-10-13 14:33:27 +02002248 setAppTransition(transit, flags);
Jorim Jaggicecf4242018-02-21 18:46:53 +01002249 } else if (isTaskTransit(transit) && isActivityTransit(mNextAppTransition)) {
2250 // Task animations always supersede activity animations, because if we have both, it
2251 // usually means that activity transition were just trampoline activities.
2252 setAppTransition(transit, flags);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002253 }
2254 }
2255 boolean prepared = prepare();
2256 if (isTransitionSet()) {
lumark23b54592018-10-02 17:17:23 +08002257 removeAppTransitionTimeoutCallbacks();
2258 mHandler.postDelayed(mHandleAppTransitionTimeoutRunnable, APP_TRANSITION_TIMEOUT_MS);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002259 }
2260 return prepared;
2261 }
Winsonb2024762016-04-05 17:32:30 -07002262
2263 /**
Jorim Jaggife762342016-10-13 14:33:27 +02002264 * @return true if {@param transit} is representing a transition in which Keyguard is going
2265 * away, false otherwise
2266 */
2267 public static boolean isKeyguardGoingAwayTransit(int transit) {
2268 return transit == TRANSIT_KEYGUARD_GOING_AWAY
2269 || transit == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER;
2270 }
2271
2272 private static boolean isKeyguardTransit(int transit) {
2273 return isKeyguardGoingAwayTransit(transit) || transit == TRANSIT_KEYGUARD_OCCLUDE
2274 || transit == TRANSIT_KEYGUARD_UNOCCLUDE;
2275 }
2276
Jorim Jaggi98a9d202018-03-26 16:17:07 +02002277 static boolean isTaskTransit(int transit) {
2278 return isTaskOpenTransit(transit)
Jorim Jaggicecf4242018-02-21 18:46:53 +01002279 || transit == TRANSIT_TASK_CLOSE
Issei Suzukid1966372019-10-10 15:06:20 +02002280 || transit == TRANSIT_TASK_TO_BACK;
Jorim Jaggicecf4242018-02-21 18:46:53 +01002281 }
2282
Jorim Jaggi98a9d202018-03-26 16:17:07 +02002283 private static boolean isTaskOpenTransit(int transit) {
2284 return transit == TRANSIT_TASK_OPEN
2285 || transit == TRANSIT_TASK_OPEN_BEHIND
2286 || transit == TRANSIT_TASK_TO_FRONT;
2287 }
2288
2289 static boolean isActivityTransit(int transit) {
Jorim Jaggicecf4242018-02-21 18:46:53 +01002290 return transit == TRANSIT_ACTIVITY_OPEN
2291 || transit == TRANSIT_ACTIVITY_CLOSE
2292 || transit == TRANSIT_ACTIVITY_RELAUNCH;
2293 }
2294
Evan Roskyec9488c2019-03-01 19:32:12 -08002295 static boolean isChangeTransit(int transit) {
2296 return transit == TRANSIT_TASK_CHANGE_WINDOWING_MODE;
2297 }
2298
Jorim Jaggife762342016-10-13 14:33:27 +02002299 /**
Manu Cornetd7376802017-01-13 13:44:07 -08002300 * @return whether the transition should show the thumbnail being scaled down.
2301 */
2302 private boolean shouldScaleDownThumbnailTransition(int uiMode, int orientation) {
Sid Soundararajan0e88d322017-03-07 15:37:30 -08002303 return mGridLayoutRecentsEnabled
Manu Cornetd7376802017-01-13 13:44:07 -08002304 || orientation == Configuration.ORIENTATION_PORTRAIT;
2305 }
lumark23b54592018-10-02 17:17:23 +08002306
2307 private void handleAppTransitionTimeout() {
Wale Ogunwaledb485de2018-10-29 09:47:07 -07002308 synchronized (mService.mGlobalLock) {
lumark588a3e82018-07-20 18:53:54 +08002309 final DisplayContent dc = mDisplayContent;
2310 if (dc == null) {
2311 return;
2312 }
Evan Rosky2289ba12018-11-19 18:28:18 -08002313 if (isTransitionSet() || !dc.mOpeningApps.isEmpty() || !dc.mClosingApps.isEmpty()
2314 || !dc.mChangingApps.isEmpty()) {
Adrian Roosb125e0b2019-10-02 14:55:14 +02002315 ProtoLog.v(WM_DEBUG_APP_TRANSITIONS,
2316 "*** APP TRANSITION TIMEOUT. displayId=%d isTransitionSet()=%b "
2317 + "mOpeningApps.size()=%d mClosingApps.size()=%d "
2318 + "mChangingApps.size()=%d",
2319 dc.getDisplayId(), dc.mAppTransition.isTransitionSet(),
2320 dc.mOpeningApps.size(), dc.mClosingApps.size(),
2321 dc.mChangingApps.size());
2322
lumark23b54592018-10-02 17:17:23 +08002323 setTimeout();
2324 mService.mWindowPlacerLocked.performSurfacePlacement();
2325 }
2326 }
2327 }
2328
2329 private static void doAnimationCallback(@NonNull IRemoteCallback callback) {
2330 try {
2331 ((IRemoteCallback) callback).sendResult(null);
2332 } catch (RemoteException e) {
2333 }
2334 }
2335
2336 void removeAppTransitionTimeoutCallbacks() {
2337 mHandler.removeCallbacks(mHandleAppTransitionTimeoutRunnable);
2338 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002339}