blob: e6a83dedded9017e20320a24cd160ef62c0a42e0 [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;
26import static android.view.WindowManager.TRANSIT_FLAG_KEYGUARD_GOING_AWAY_TO_SHADE;
27import static android.view.WindowManager.TRANSIT_KEYGUARD_GOING_AWAY;
28import static android.view.WindowManager.TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER;
29import static android.view.WindowManager.TRANSIT_KEYGUARD_OCCLUDE;
30import static android.view.WindowManager.TRANSIT_KEYGUARD_UNOCCLUDE;
31import static android.view.WindowManager.TRANSIT_NONE;
Evan Roskycf76bed2019-01-15 10:33:58 -080032import static android.view.WindowManager.TRANSIT_TASK_CHANGE_WINDOWING_MODE;
Jorim Jaggif84e2f62018-01-16 14:17:59 +010033import static android.view.WindowManager.TRANSIT_TASK_CLOSE;
Jorim Jaggicecf4242018-02-21 18:46:53 +010034import static android.view.WindowManager.TRANSIT_TASK_IN_PLACE;
Jorim Jaggif84e2f62018-01-16 14:17:59 +010035import static android.view.WindowManager.TRANSIT_TASK_OPEN;
36import static android.view.WindowManager.TRANSIT_TASK_OPEN_BEHIND;
37import static android.view.WindowManager.TRANSIT_TASK_TO_BACK;
38import static android.view.WindowManager.TRANSIT_TASK_TO_FRONT;
Jorim Jaggi98a9d202018-03-26 16:17:07 +020039import static android.view.WindowManager.TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE;
40import static android.view.WindowManager.TRANSIT_TRANSLUCENT_ACTIVITY_OPEN;
Jorim Jaggif84e2f62018-01-16 14:17:59 +010041import static android.view.WindowManager.TRANSIT_UNSET;
42import static android.view.WindowManager.TRANSIT_WALLPAPER_CLOSE;
43import static android.view.WindowManager.TRANSIT_WALLPAPER_INTRA_CLOSE;
44import static android.view.WindowManager.TRANSIT_WALLPAPER_INTRA_OPEN;
45import static android.view.WindowManager.TRANSIT_WALLPAPER_OPEN;
Tony Mak83546a82018-01-22 13:56:20 +000046
Filip Gruszczynski82861362015-10-16 14:21:09 -070047import static com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation;
48import static com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
49import static com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation;
50import static com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
51import static com.android.internal.R.styleable.WindowAnimation_launchTaskBehindSourceAnimation;
52import static com.android.internal.R.styleable.WindowAnimation_launchTaskBehindTargetAnimation;
53import static com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation;
54import static com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
55import static com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation;
56import static com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
57import static com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation;
58import static com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
59import static com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation;
60import static com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
61import static com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation;
62import static com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
63import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation;
64import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
65import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation;
66import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
67import static com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation;
68import static com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Aurimas Liutikasd8ebfef2019-01-16 12:46:42 -080069import static com.android.server.wm.AppTransitionProto.APP_TRANSITION_STATE;
70import static com.android.server.wm.AppTransitionProto.LAST_USED_APP_TRANSITION;
Filip Gruszczynski198dcbf2016-01-18 10:02:00 -080071import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
72import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080073import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
74import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Adrian Roose99bc052017-11-20 17:55:31 +010075import static com.android.server.wm.WindowManagerInternal.AppTransitionListener;
Tony Mak089c35e2017-12-18 20:34:14 +000076import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_AFTER_ANIM;
Matthew Ngbf1d9852017-03-14 12:23:09 -070077import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_BEFORE_ANIM;
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +010078import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_NONE;
Filip Gruszczynski82861362015-10-16 14:21:09 -070079
Tony Mak64b8d562017-12-28 17:44:02 +000080import android.annotation.DrawableRes;
lumark23b54592018-10-02 17:17:23 +080081import android.annotation.NonNull;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -070082import android.annotation.Nullable;
Matthew Ng43db6d22017-06-27 15:29:39 -070083import android.app.ActivityManager;
Tony Mak089c35e2017-12-18 20:34:14 +000084import android.content.ComponentName;
Craig Mautner164d4bb2012-11-26 13:51:23 -080085import android.content.Context;
Winson21700932016-03-24 17:26:23 -070086import android.content.res.Configuration;
Todd Kennedy64c57a82018-04-19 15:17:24 -070087import android.content.res.ResourceId;
Aurimas Liutikasd8ebfef2019-01-16 12:46:42 -080088import android.content.res.Resources;
Jorim Jaggib142f572019-03-01 16:08:54 +010089import android.content.res.Resources.NotFoundException;
lumarkce596d32019-06-12 16:58:35 +080090import android.content.res.TypedArray;
John Reck519ad482018-02-12 17:08:48 -080091import android.graphics.Bitmap;
92import android.graphics.Canvas;
Tony Mak64b8d562017-12-28 17:44:02 +000093import android.graphics.Color;
Winson Chungaa7fa012017-05-24 15:50:06 -070094import android.graphics.GraphicBuffer;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +010095import android.graphics.Path;
John Reck519ad482018-02-12 17:08:48 -080096import android.graphics.Picture;
Winson Chung399f6202014-03-19 10:47:20 -070097import android.graphics.Rect;
Tony Mak64b8d562017-12-28 17:44:02 +000098import android.graphics.drawable.Drawable;
Jorim Jaggied410b62017-05-05 15:16:14 +020099import android.os.Binder;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800100import android.os.Debug;
lumark23b54592018-10-02 17:17:23 +0800101import android.os.Handler;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100102import android.os.IBinder;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800103import android.os.IRemoteCallback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100104import android.os.RemoteException;
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200105import android.os.SystemClock;
Manu Cornetd7376802017-01-13 13:44:07 -0800106import android.os.SystemProperties;
Tony Mak089c35e2017-12-18 20:34:14 +0000107import android.os.UserHandle;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800108import android.util.ArraySet;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800109import android.util.Slog;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700110import android.util.SparseArray;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700111import android.util.proto.ProtoOutputStream;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700112import android.view.AppTransitionAnimationSpec;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100113import android.view.IAppTransitionAnimationSpecsFuture;
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100114import android.view.RemoteAnimationAdapter;
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100115import android.view.WindowManager.TransitionFlags;
116import android.view.WindowManager.TransitionType;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800117import android.view.animation.AlphaAnimation;
118import android.view.animation.Animation;
119import android.view.animation.AnimationSet;
120import android.view.animation.AnimationUtils;
Winson Chung399f6202014-03-19 10:47:20 -0700121import android.view.animation.ClipRectAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800122import android.view.animation.Interpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700123import android.view.animation.PathInterpolator;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800124import android.view.animation.ScaleAnimation;
Winson Chung399f6202014-03-19 10:47:20 -0700125import android.view.animation.TranslateAnimation;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700126
Jorim Jaggi98a9d202018-03-26 16:17:07 +0200127import com.android.internal.R;
Jorim Jaggib142f572019-03-01 16:08:54 +0100128import com.android.internal.annotations.VisibleForTesting;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800129import com.android.internal.util.DumpUtils.Dump;
lumark23b54592018-10-02 17:17:23 +0800130import com.android.internal.util.function.pooled.PooledLambda;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800131import com.android.server.AttributeCache;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800132import com.android.server.wm.animation.ClipRectLRAnimation;
133import com.android.server.wm.animation.ClipRectTBAnimation;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100134import com.android.server.wm.animation.CurvedTranslateAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800135
136import java.io.PrintWriter;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100137import java.util.ArrayList;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100138import java.util.concurrent.ExecutorService;
139import java.util.concurrent.Executors;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800140
Craig Mautner164d4bb2012-11-26 13:51:23 -0800141// State management of app transitions. When we are preparing for a
142// transition, mNextAppTransition will be the kind of transition to
143// perform or TRANSIT_NONE if we are not waiting. If we are waiting,
144// mOpeningApps and mClosingApps are the lists of tokens that will be
145// made visible or hidden at the next transition.
146public class AppTransition implements Dump {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800147 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppTransition" : TAG_WM;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700148 private static final int CLIP_REVEAL_TRANSLATION_Y_DP = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800149
Winson Chunga4ccb862014-08-22 15:26:27 -0700150 /** Fraction of animation at which the recents thumbnail stays completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700151 private static final float RECENTS_THUMBNAIL_FADEIN_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800152 /** Fraction of animation at which the recents thumbnail becomes completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700153 private static final float RECENTS_THUMBNAIL_FADEOUT_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800154
Filip Gruszczynski84fa3352016-01-25 16:28:49 -0800155 static final int DEFAULT_APP_TRANSITION_DURATION = 336;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800156
157 /** Interpolator to be used for animations that respond directly to a touch */
158 static final Interpolator TOUCH_RESPONSE_INTERPOLATOR =
159 new PathInterpolator(0.3f, 0f, 0.1f, 1f);
160
Jorim Jaggic69bd222016-03-15 14:38:37 +0100161 private static final Interpolator THUMBNAIL_DOCK_INTERPOLATOR =
162 new PathInterpolator(0.85f, 0f, 1f, 1f);
163
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800164 /**
165 * Maximum duration for the clip reveal animation. This is used when there is a lot of movement
166 * involved, to make it more understandable.
167 */
168 private static final int MAX_CLIP_REVEAL_TRANSITION_DURATION = 420;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700169 private static final int THUMBNAIL_APP_TRANSITION_DURATION = 336;
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700170 private static final long APP_TRANSITION_TIMEOUT_MS = 5000;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800171
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800172 private final Context mContext;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800173 private final WindowManagerService mService;
lumark588a3e82018-07-20 18:53:54 +0800174 private final DisplayContent mDisplayContent;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800175
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100176 private @TransitionType int mNextAppTransition = TRANSIT_UNSET;
177 private @TransitionFlags int mNextAppTransitionFlags = 0;
Chong Zhang60091a92016-07-27 17:52:45 -0700178 private int mLastUsedAppTransition = TRANSIT_UNSET;
179 private String mLastOpeningApp;
180 private String mLastClosingApp;
Evan Rosky2289ba12018-11-19 18:28:18 -0800181 private String mLastChangingApp;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800182
183 private static final int NEXT_TRANSIT_TYPE_NONE = 0;
184 private static final int NEXT_TRANSIT_TYPE_CUSTOM = 1;
185 private static final int NEXT_TRANSIT_TYPE_SCALE_UP = 2;
186 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP = 3;
187 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN = 4;
Winson Chunga4ccb862014-08-22 15:26:27 -0700188 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP = 5;
189 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN = 6;
Winson Chung044d5292014-11-06 11:05:19 -0800190 private static final int NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE = 7;
Chet Haase10e23ab2015-02-11 15:08:38 -0800191 private static final int NEXT_TRANSIT_TYPE_CLIP_REVEAL = 8;
Tony Mak089c35e2017-12-18 20:34:14 +0000192
193 /**
194 * Refers to the transition to activity started by using {@link
195 * android.content.pm.crossprofile.CrossProfileApps#startMainActivity(ComponentName, UserHandle)
196 * }.
197 */
198 private static final int NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS = 9;
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100199 private static final int NEXT_TRANSIT_TYPE_REMOTE = 10;
200
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800201 private int mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
202
Winson Chung399f6202014-03-19 10:47:20 -0700203 // These are the possible states for the enter/exit activities during a thumbnail transition
204 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_UP = 0;
205 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_UP = 1;
206 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN = 2;
207 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN = 3;
208
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800209 private String mNextAppTransitionPackage;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800210 // Used for thumbnail transitions. True if we're scaling up, false if scaling down
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800211 private boolean mNextAppTransitionScaleUp;
212 private IRemoteCallback mNextAppTransitionCallback;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +0100213 private IRemoteCallback mNextAppTransitionFutureCallback;
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -0700214 private IRemoteCallback mAnimationFinishedCallback;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800215 private int mNextAppTransitionEnter;
216 private int mNextAppTransitionExit;
Winson Chung044d5292014-11-06 11:05:19 -0800217 private int mNextAppTransitionInPlace;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700218
219 // Keyed by task id.
220 private final SparseArray<AppTransitionAnimationSpec> mNextAppTransitionAnimationsSpecs
221 = new SparseArray<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100222 private IAppTransitionAnimationSpecsFuture mNextAppTransitionAnimationsSpecsFuture;
223 private boolean mNextAppTransitionAnimationsSpecsPending;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700224 private AppTransitionAnimationSpec mDefaultNextAppTransitionAnimationSpec;
225
Winson Chunga4ccb862014-08-22 15:26:27 -0700226 private Rect mNextAppTransitionInsets = new Rect();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800227
Winson Chung2820c452014-04-15 15:34:44 -0700228 private Rect mTmpFromClipRect = new Rect();
229 private Rect mTmpToClipRect = new Rect();
230
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700231 private final Rect mTmpRect = new Rect();
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700232
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800233 private final static int APP_STATE_IDLE = 0;
234 private final static int APP_STATE_READY = 1;
235 private final static int APP_STATE_RUNNING = 2;
236 private final static int APP_STATE_TIMEOUT = 3;
237 private int mAppTransitionState = APP_STATE_IDLE;
238
239 private final int mConfigShortAnimTime;
Craig Mautner321bdf52012-12-18 09:53:24 -0800240 private final Interpolator mDecelerateInterpolator;
Winson Chunga4ccb862014-08-22 15:26:27 -0700241 private final Interpolator mThumbnailFadeInInterpolator;
242 private final Interpolator mThumbnailFadeOutInterpolator;
Chet Haase10e23ab2015-02-11 15:08:38 -0800243 private final Interpolator mLinearOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700244 private final Interpolator mFastOutLinearInInterpolator;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100245 private final Interpolator mFastOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700246 private final Interpolator mClipHorizontalInterpolator = new PathInterpolator(0, 0, 0.4f, 1f);
247
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700248 private final int mClipRevealTranslationY;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800249
Amith Yamasani4befbec2013-07-10 16:18:01 -0700250 private int mCurrentUserId = 0;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800251 private long mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Amith Yamasani4befbec2013-07-10 16:18:01 -0700252
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100253 private final ArrayList<AppTransitionListener> mListeners = new ArrayList<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100254 private final ExecutorService mDefaultExecutor = Executors.newSingleThreadExecutor();
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100255
Jorim Jaggif97ed922016-02-18 18:57:07 -0800256 private int mLastClipRevealMaxTranslation;
257 private boolean mLastHadClipReveal;
258
Manu Cornetd7376802017-01-13 13:44:07 -0800259 private final boolean mGridLayoutRecentsEnabled;
Matthew Ng43db6d22017-06-27 15:29:39 -0700260 private final boolean mLowRamRecentsEnabled;
Manu Cornetd7376802017-01-13 13:44:07 -0800261
lumarkce596d32019-06-12 16:58:35 +0800262 private final int mDefaultWindowAnimationStyleResId;
263
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100264 private RemoteAnimationController mRemoteAnimationController;
265
lumark23b54592018-10-02 17:17:23 +0800266 final Handler mHandler;
267 final Runnable mHandleAppTransitionTimeoutRunnable = () -> handleAppTransitionTimeout();
268
lumark588a3e82018-07-20 18:53:54 +0800269 AppTransition(Context context, WindowManagerService service, DisplayContent displayContent) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800270 mContext = context;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800271 mService = service;
lumark23b54592018-10-02 17:17:23 +0800272 mHandler = new Handler(service.mH.getLooper());
lumark588a3e82018-07-20 18:53:54 +0800273 mDisplayContent = displayContent;
Chet Haase10e23ab2015-02-11 15:08:38 -0800274 mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
275 com.android.internal.R.interpolator.linear_out_slow_in);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700276 mFastOutLinearInInterpolator = AnimationUtils.loadInterpolator(context,
277 com.android.internal.R.interpolator.fast_out_linear_in);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100278 mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
279 com.android.internal.R.interpolator.fast_out_slow_in);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800280 mConfigShortAnimTime = context.getResources().getInteger(
281 com.android.internal.R.integer.config_shortAnimTime);
Craig Mautner321bdf52012-12-18 09:53:24 -0800282 mDecelerateInterpolator = AnimationUtils.loadInterpolator(context,
283 com.android.internal.R.interpolator.decelerate_cubic);
Winson Chunga4ccb862014-08-22 15:26:27 -0700284 mThumbnailFadeInInterpolator = new Interpolator() {
285 @Override
286 public float getInterpolation(float input) {
287 // Linear response for first fraction, then complete after that.
288 if (input < RECENTS_THUMBNAIL_FADEIN_FRACTION) {
289 return 0f;
290 }
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700291 float t = (input - RECENTS_THUMBNAIL_FADEIN_FRACTION) /
Winson Chunga4ccb862014-08-22 15:26:27 -0700292 (1f - RECENTS_THUMBNAIL_FADEIN_FRACTION);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700293 return mFastOutLinearInInterpolator.getInterpolation(t);
Winson Chunga4ccb862014-08-22 15:26:27 -0700294 }
295 };
296 mThumbnailFadeOutInterpolator = new Interpolator() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800297 @Override
298 public float getInterpolation(float input) {
299 // Linear response for first fraction, then complete after that.
300 if (input < RECENTS_THUMBNAIL_FADEOUT_FRACTION) {
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700301 float t = input / RECENTS_THUMBNAIL_FADEOUT_FRACTION;
302 return mLinearOutSlowInInterpolator.getInterpolation(t);
Craig Mautner321bdf52012-12-18 09:53:24 -0800303 }
Winson Chunga4ccb862014-08-22 15:26:27 -0700304 return 1f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800305 }
306 };
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700307 mClipRevealTranslationY = (int) (CLIP_REVEAL_TRANSLATION_Y_DP
308 * mContext.getResources().getDisplayMetrics().density);
Manu Cornetd7376802017-01-13 13:44:07 -0800309 mGridLayoutRecentsEnabled = SystemProperties.getBoolean("ro.recents.grid", false);
Matthew Ng43db6d22017-06-27 15:29:39 -0700310 mLowRamRecentsEnabled = ActivityManager.isLowRamDeviceStatic();
lumarkce596d32019-06-12 16:58:35 +0800311
312 final TypedArray windowStyle = mContext.getTheme().obtainStyledAttributes(
313 com.android.internal.R.styleable.Window);
314 mDefaultWindowAnimationStyleResId = windowStyle.getResourceId(
315 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
316 windowStyle.recycle();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800317 }
318
319 boolean isTransitionSet() {
320 return mNextAppTransition != TRANSIT_UNSET;
321 }
322
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100323 boolean isTransitionEqual(@TransitionType int transit) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800324 return mNextAppTransition == transit;
325 }
326
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100327 @TransitionType int getAppTransition() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800328 return mNextAppTransition;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800329 }
330
Jorim Jaggife762342016-10-13 14:33:27 +0200331 private void setAppTransition(int transit, int flags) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800332 mNextAppTransition = transit;
Jorim Jaggife762342016-10-13 14:33:27 +0200333 mNextAppTransitionFlags |= flags;
Evan Rosky2289ba12018-11-19 18:28:18 -0800334 setLastAppTransition(TRANSIT_UNSET, null, null, null);
Jorim Jaggi245281c2017-06-07 14:33:04 -0700335 updateBooster();
Chong Zhang60091a92016-07-27 17:52:45 -0700336 }
337
Evan Rosky2289ba12018-11-19 18:28:18 -0800338 void setLastAppTransition(int transit, AppWindowToken openingApp, AppWindowToken closingApp,
339 AppWindowToken changingApp) {
Chong Zhang60091a92016-07-27 17:52:45 -0700340 mLastUsedAppTransition = transit;
341 mLastOpeningApp = "" + openingApp;
342 mLastClosingApp = "" + closingApp;
Evan Rosky2289ba12018-11-19 18:28:18 -0800343 mLastChangingApp = "" + changingApp;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800344 }
345
346 boolean isReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800347 return mAppTransitionState == APP_STATE_READY
348 || mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800349 }
350
Craig Mautnerae446592012-12-06 19:05:05 -0800351 void setReady() {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700352 setAppTransitionState(APP_STATE_READY);
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100353 fetchAppTransitionSpecsFromFuture();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800354 }
355
356 boolean isRunning() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800357 return mAppTransitionState == APP_STATE_RUNNING;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800358 }
359
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800360 void setIdle() {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700361 setAppTransitionState(APP_STATE_IDLE);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800362 }
363
364 boolean isTimeout() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800365 return mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800366 }
367
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800368 void setTimeout() {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700369 setAppTransitionState(APP_STATE_TIMEOUT);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800370 }
371
Winson Chungaa7fa012017-05-24 15:50:06 -0700372 GraphicBuffer getAppTransitionThumbnailHeader(int taskId) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700373 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800374 if (spec == null) {
375 spec = mDefaultNextAppTransitionAnimationSpec;
376 }
Winson Chungaa7fa012017-05-24 15:50:06 -0700377 return spec != null ? spec.buffer : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800378 }
379
Winson Chunga4ccb862014-08-22 15:26:27 -0700380 /** Returns whether the next thumbnail transition is aspect scaled up. */
381 boolean isNextThumbnailTransitionAspectScaled() {
382 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
383 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
384 }
385
386 /** Returns whether the next thumbnail transition is scaling up. */
387 boolean isNextThumbnailTransitionScaleUp() {
388 return mNextAppTransitionScaleUp;
389 }
390
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -0800391 boolean isNextAppTransitionThumbnailUp() {
392 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
393 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP;
394 }
395
396 boolean isNextAppTransitionThumbnailDown() {
397 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN ||
398 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
399 }
400
Tony Mak64b8d562017-12-28 17:44:02 +0000401
402 boolean isNextAppTransitionOpenCrossProfileApps() {
403 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS;
404 }
405
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100406 /**
407 * @return true if and only if we are currently fetching app transition specs from the future
408 * passed into {@link #overridePendingAppTransitionMultiThumbFuture}
409 */
410 boolean isFetchingAppTransitionsSpecs() {
411 return mNextAppTransitionAnimationsSpecsPending;
412 }
413
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700414 private boolean prepare() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800415 if (!isRunning()) {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700416 setAppTransitionState(APP_STATE_IDLE);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100417 notifyAppTransitionPendingLocked();
Jorim Jaggif97ed922016-02-18 18:57:07 -0800418 mLastHadClipReveal = false;
419 mLastClipRevealMaxTranslation = 0;
420 mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700421 return true;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800422 }
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700423 return false;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800424 }
425
Jorim Jaggife762342016-10-13 14:33:27 +0200426 /**
427 * @return bit-map of WindowManagerPolicy#FINISH_LAYOUT_REDO_* to indicate whether another
428 * layout pass needs to be done
429 */
Evan Rosky2289ba12018-11-19 18:28:18 -0800430 int goodToGo(int transit, AppWindowToken topOpeningApp, ArraySet<AppWindowToken> openingApps) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800431 mNextAppTransition = TRANSIT_UNSET;
Jorim Jaggife762342016-10-13 14:33:27 +0200432 mNextAppTransitionFlags = 0;
Jorim Jaggi245281c2017-06-07 14:33:04 -0700433 setAppTransitionState(APP_STATE_RUNNING);
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200434 final AnimationAdapter topOpeningAnim = topOpeningApp != null
435 ? topOpeningApp.getAnimation()
436 : null;
Jorim Jaggife762342016-10-13 14:33:27 +0200437 int redoLayout = notifyAppTransitionStartingLocked(transit,
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200438 topOpeningAnim != null ? topOpeningAnim.getDurationHint() : 0,
439 topOpeningAnim != null
440 ? topOpeningAnim.getStatusBarTransitionsStartTime()
441 : SystemClock.uptimeMillis(),
442 AnimationAdapter.STATUS_BAR_TRANSITION_DURATION);
lumark588a3e82018-07-20 18:53:54 +0800443 mDisplayContent.getDockedDividerController()
Jorim Jaggife762342016-10-13 14:33:27 +0200444 .notifyAppTransitionStarting(openingApps, transit);
Jorim Jaggi363ab982016-04-26 19:51:20 -0700445
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100446 if (mRemoteAnimationController != null) {
447 mRemoteAnimationController.goodToGo();
448 }
Jorim Jaggife762342016-10-13 14:33:27 +0200449 return redoLayout;
Jorim Jaggi363ab982016-04-26 19:51:20 -0700450 }
451
Craig Mautner164d4bb2012-11-26 13:51:23 -0800452 void clear() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800453 mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800454 mNextAppTransitionPackage = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700455 mNextAppTransitionAnimationsSpecs.clear();
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100456 mRemoteAnimationController = null;
Jorim Jaggi65193992015-11-23 16:49:59 -0800457 mNextAppTransitionAnimationsSpecsFuture = null;
458 mDefaultNextAppTransitionAnimationSpec = null;
459 mAnimationFinishedCallback = null;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800460 }
461
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800462 void freeze() {
Jorim Jaggife762342016-10-13 14:33:27 +0200463 final int transit = mNextAppTransition;
Arthur Hung442aff22019-05-07 19:49:31 +0800464 // The RemoteAnimationControl didn't register AppTransitionListener and
465 // only initialized the finish and timeout callback when goodToGo().
466 // So cancel the remote animation here to prevent the animation can't do
467 // finish after transition state cleared.
468 if (mRemoteAnimationController != null) {
469 mRemoteAnimationController.cancelAnimation("freeze");
470 }
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100471 setAppTransition(TRANSIT_UNSET, 0 /* flags */);
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800472 clear();
473 setReady();
Jorim Jaggife762342016-10-13 14:33:27 +0200474 notifyAppTransitionCancelledLocked(transit);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100475 }
476
Jorim Jaggi245281c2017-06-07 14:33:04 -0700477 private void setAppTransitionState(int state) {
478 mAppTransitionState = state;
479 updateBooster();
480 }
481
482 /**
483 * Updates whether we currently boost wm locked sections and the animation thread. We want to
484 * boost the priorities to a more important value whenever an app transition is going to happen
485 * soon or an app transition is running.
486 */
Jorim Jaggic8cc2292018-03-15 20:16:15 +0100487 void updateBooster() {
488 WindowManagerService.sThreadPriorityBooster.setAppTransitionRunning(needsBoosting());
489 }
490
491 private boolean needsBoosting() {
492 final boolean recentsAnimRunning = mService.getRecentsAnimationController() != null;
493 return mNextAppTransition != TRANSIT_UNSET
494 || mAppTransitionState == APP_STATE_READY
495 || mAppTransitionState == APP_STATE_RUNNING
496 || recentsAnimRunning;
Jorim Jaggi245281c2017-06-07 14:33:04 -0700497 }
498
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100499 void registerListenerLocked(AppTransitionListener listener) {
500 mListeners.add(listener);
501 }
502
lumark54284462019-03-05 20:44:27 +0800503 void unregisterListener(AppTransitionListener listener) {
504 mListeners.remove(listener);
505 }
506
Wale Ogunwalea48eadb2015-05-14 17:43:12 -0700507 public void notifyAppTransitionFinishedLocked(IBinder token) {
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100508 for (int i = 0; i < mListeners.size(); i++) {
509 mListeners.get(i).onAppTransitionFinishedLocked(token);
510 }
511 }
512
513 private void notifyAppTransitionPendingLocked() {
514 for (int i = 0; i < mListeners.size(); i++) {
515 mListeners.get(i).onAppTransitionPendingLocked();
516 }
517 }
518
Jorim Jaggife762342016-10-13 14:33:27 +0200519 private void notifyAppTransitionCancelledLocked(int transit) {
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100520 for (int i = 0; i < mListeners.size(); i++) {
Jorim Jaggife762342016-10-13 14:33:27 +0200521 mListeners.get(i).onAppTransitionCancelledLocked(transit);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100522 }
523 }
524
Evan Rosky2289ba12018-11-19 18:28:18 -0800525 private int notifyAppTransitionStartingLocked(int transit, long duration,
526 long statusBarAnimationStartTime, long statusBarAnimationDuration) {
Jorim Jaggife762342016-10-13 14:33:27 +0200527 int redoLayout = 0;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100528 for (int i = 0; i < mListeners.size(); i++) {
Evan Rosky2289ba12018-11-19 18:28:18 -0800529 redoLayout |= mListeners.get(i).onAppTransitionStartingLocked(transit, duration,
530 statusBarAnimationStartTime, statusBarAnimationDuration);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100531 }
Jorim Jaggife762342016-10-13 14:33:27 +0200532 return redoLayout;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800533 }
534
lumarkce596d32019-06-12 16:58:35 +0800535 @VisibleForTesting
536 int getDefaultWindowAnimationStyleResId() {
537 return mDefaultWindowAnimationStyleResId;
538 }
539
540 /** Returns window animation style ID from {@link LayoutParams} or from system in some cases */
541 @VisibleForTesting
542 int getAnimationStyleResId(@NonNull LayoutParams lp) {
543 int resId = lp.windowAnimations;
544 if (lp.type == LayoutParams.TYPE_APPLICATION_STARTING) {
545 // Note that we don't want application to customize starting window animation.
546 // Since this window is specific for displaying while app starting,
547 // application should not change its animation directly.
548 // In this case, it will use system resource to get default animation.
549 resId = mDefaultWindowAnimationStyleResId;
550 }
551 return resId;
552 }
553
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100554 private AttributeCache.Entry getCachedAnimations(LayoutParams lp) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800555 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg="
556 + (lp != null ? lp.packageName : null)
557 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
558 if (lp != null && lp.windowAnimations != 0) {
559 // If this is a system resource, don't try to load it from the
560 // application resources. It is nice to avoid loading application
561 // resources if we can.
562 String packageName = lp.packageName != null ? lp.packageName : "android";
lumarkce596d32019-06-12 16:58:35 +0800563 int resId = getAnimationStyleResId(lp);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800564 if ((resId&0xFF000000) == 0x01000000) {
565 packageName = "android";
566 }
567 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
568 + packageName);
569 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700570 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800571 }
572 return null;
573 }
574
575 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
576 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package="
577 + packageName + " resId=0x" + Integer.toHexString(resId));
578 if (packageName != null) {
579 if ((resId&0xFF000000) == 0x01000000) {
580 packageName = "android";
581 }
582 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
583 + packageName);
584 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700585 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800586 }
587 return null;
588 }
589
Jorim Jaggi0a1523d2018-04-19 17:48:38 +0200590 Animation loadAnimationAttr(LayoutParams lp, int animAttr, int transit) {
Aurimas Liutikasd8ebfef2019-01-16 12:46:42 -0800591 int resId = Resources.ID_NULL;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800592 Context context = mContext;
Jorim Jaggi5f95b002018-04-19 13:27:52 +0000593 if (animAttr >= 0) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800594 AttributeCache.Entry ent = getCachedAnimations(lp);
595 if (ent != null) {
596 context = ent.context;
Todd Kennedy64c57a82018-04-19 15:17:24 -0700597 resId = ent.array.getResourceId(animAttr, 0);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800598 }
599 }
Todd Kennedy64c57a82018-04-19 15:17:24 -0700600 resId = updateToTranslucentAnimIfNeeded(resId, transit);
601 if (ResourceId.isValid(resId)) {
Jorim Jaggib142f572019-03-01 16:08:54 +0100602 return loadAnimationSafely(context, resId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800603 }
604 return null;
605 }
606
Jorim Jaggib142f572019-03-01 16:08:54 +0100607 private Animation loadAnimationRes(LayoutParams lp, int resId) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700608 Context context = mContext;
Todd Kennedy64c57a82018-04-19 15:17:24 -0700609 if (ResourceId.isValid(resId)) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700610 AttributeCache.Entry ent = getCachedAnimations(lp);
611 if (ent != null) {
612 context = ent.context;
613 }
Jorim Jaggib142f572019-03-01 16:08:54 +0100614 return loadAnimationSafely(context, resId);
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700615 }
616 return null;
617 }
618
619 private Animation loadAnimationRes(String packageName, int resId) {
Todd Kennedy64c57a82018-04-19 15:17:24 -0700620 if (ResourceId.isValid(resId)) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800621 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
622 if (ent != null) {
Jorim Jaggib142f572019-03-01 16:08:54 +0100623 return loadAnimationSafely(ent.context, resId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800624 }
625 }
Craig Mautner164d4bb2012-11-26 13:51:23 -0800626 return null;
627 }
628
Jorim Jaggib142f572019-03-01 16:08:54 +0100629 @VisibleForTesting
630 Animation loadAnimationSafely(Context context, int resId) {
631 try {
632 return AnimationUtils.loadAnimation(context, resId);
633 } catch (NotFoundException e) {
634 Slog.w(TAG, "Unable to load animation resource", e);
635 return null;
636 }
637 }
638
Jorim Jaggi0a1523d2018-04-19 17:48:38 +0200639 private int updateToTranslucentAnimIfNeeded(int anim, int transit) {
640 if (transit == TRANSIT_TRANSLUCENT_ACTIVITY_OPEN && anim == R.anim.activity_open_enter) {
641 return R.anim.activity_translucent_open_enter;
642 }
643 if (transit == TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE && anim == R.anim.activity_close_exit) {
644 return R.anim.activity_translucent_close_exit;
645 }
646 return anim;
647 }
648
Craig Mautner164d4bb2012-11-26 13:51:23 -0800649 /**
650 * Compute the pivot point for an animation that is scaling from a small
651 * rect on screen to a larger rect. The pivot point varies depending on
652 * the distance between the inner and outer edges on both sides. This
653 * function computes the pivot point for one dimension.
654 * @param startPos Offset from left/top edge of outer rectangle to
655 * left/top edge of inner rectangle.
656 * @param finalScale The scaling factor between the size of the outer
657 * and inner rectangles.
658 */
659 private static float computePivot(int startPos, float finalScale) {
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800660
661 /*
662 Theorem of intercepting lines:
663
664 + + +-----------------------------------------------+
665 | | | |
666 | | | |
667 | | | |
668 | | | |
669 x | y | | |
670 | | | |
671 | | | |
672 | | | |
673 | | | |
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 p ++
712
713 scale = (x - y) / x
714 <=> x = -y / (scale - 1)
715 */
Craig Mautner164d4bb2012-11-26 13:51:23 -0800716 final float denom = finalScale-1;
717 if (Math.abs(denom) < .0001f) {
718 return startPos;
719 }
720 return -startPos / denom;
721 }
722
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700723 private Animation createScaleUpAnimationLocked(int transit, boolean enter,
724 Rect containingFrame) {
725 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700726 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700727 final int appWidth = containingFrame.width();
728 final int appHeight = containingFrame.height();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800729 if (enter) {
730 // Entering app zooms out from the center of the initial rect.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700731 float scaleW = mTmpRect.width() / (float) appWidth;
732 float scaleH = mTmpRect.height() / (float) appHeight;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800733 Animation scale = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700734 computePivot(mTmpRect.left, scaleW),
Winson4c3fecd2016-07-13 12:29:48 -0700735 computePivot(mTmpRect.top, scaleH));
Craig Mautner321bdf52012-12-18 09:53:24 -0800736 scale.setInterpolator(mDecelerateInterpolator);
737
Craig Mautner164d4bb2012-11-26 13:51:23 -0800738 Animation alpha = new AlphaAnimation(0, 1);
Winson Chunga4ccb862014-08-22 15:26:27 -0700739 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
Craig Mautner321bdf52012-12-18 09:53:24 -0800740
741 AnimationSet set = new AnimationSet(false);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800742 set.addAnimation(scale);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800743 set.addAnimation(alpha);
744 set.setDetachWallpaper(true);
745 a = set;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800746 } else if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
747 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800748 // If we are on top of the wallpaper, we need an animation that
749 // correctly handles the wallpaper staying static behind all of
750 // the animated elements. To do this, will just have the existing
751 // element fade out.
752 a = new AlphaAnimation(1, 0);
753 a.setDetachWallpaper(true);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800754 } else {
Craig Mautner321bdf52012-12-18 09:53:24 -0800755 // For normal animations, the exiting element just holds in place.
756 a = new AlphaAnimation(1, 1);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800757 }
Craig Mautner321bdf52012-12-18 09:53:24 -0800758
759 // Pick the desired duration. If this is an inter-activity transition,
760 // it is the standard duration for that. Otherwise we use the longer
761 // task transition duration.
762 final long duration;
763 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800764 case TRANSIT_ACTIVITY_OPEN:
765 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800766 duration = mConfigShortAnimTime;
767 break;
768 default:
769 duration = DEFAULT_APP_TRANSITION_DURATION;
770 break;
771 }
772 a.setDuration(duration);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800773 a.setFillAfter(true);
Craig Mautner321bdf52012-12-18 09:53:24 -0800774 a.setInterpolator(mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800775 a.initialize(appWidth, appHeight, appWidth, appHeight);
776 return a;
777 }
778
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700779 private void getDefaultNextAppTransitionStartRect(Rect rect) {
780 if (mDefaultNextAppTransitionAnimationSpec == null ||
781 mDefaultNextAppTransitionAnimationSpec.rect == null) {
Jorim Jaggi2550f3f2017-03-14 20:15:59 +0100782 Slog.e(TAG, "Starting rect for app requested, but none available", new Throwable());
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700783 rect.setEmpty();
784 } else {
785 rect.set(mDefaultNextAppTransitionAnimationSpec.rect);
786 }
787 }
788
789 void getNextAppTransitionStartRect(int taskId, Rect rect) {
790 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800791 if (spec == null) {
792 spec = mDefaultNextAppTransitionAnimationSpec;
793 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700794 if (spec == null || spec.rect == null) {
Jorim Jaggi2550f3f2017-03-14 20:15:59 +0100795 Slog.e(TAG, "Starting rect for task: " + taskId + " requested, but not available",
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700796 new Throwable());
797 rect.setEmpty();
798 } else {
799 rect.set(spec.rect);
800 }
801 }
802
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800803 private void putDefaultNextAppTransitionCoordinates(int left, int top, int width, int height,
Winson Chungaa7fa012017-05-24 15:50:06 -0700804 GraphicBuffer buffer) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700805 mDefaultNextAppTransitionAnimationSpec = new AppTransitionAnimationSpec(-1 /* taskId */,
Winson Chungaa7fa012017-05-24 15:50:06 -0700806 buffer, new Rect(left, top, left + width, top + height));
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700807 }
808
Jorim Jaggif97ed922016-02-18 18:57:07 -0800809 /**
810 * @return the duration of the last clip reveal animation
811 */
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800812 long getLastClipRevealTransitionDuration() {
813 return mLastClipRevealTransitionDuration;
814 }
815
816 /**
Jorim Jaggif97ed922016-02-18 18:57:07 -0800817 * @return the maximum distance the app surface is traveling of the last clip reveal animation
818 */
819 int getLastClipRevealMaxTranslation() {
820 return mLastClipRevealMaxTranslation;
821 }
822
823 /**
824 * @return true if in the last app transition had a clip reveal animation, false otherwise
825 */
826 boolean hadClipRevealAnimation() {
827 return mLastHadClipReveal;
828 }
829
830 /**
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800831 * Calculates the duration for the clip reveal animation. If the clip is "cut off", meaning that
832 * the start rect is outside of the target rect, and there is a lot of movement going on.
833 *
834 * @param cutOff whether the start rect was not fully contained by the end rect
835 * @param translationX the total translation the surface moves in x direction
836 * @param translationY the total translation the surfaces moves in y direction
837 * @param displayFrame our display frame
838 *
839 * @return the duration of the clip reveal animation, in milliseconds
840 */
841 private long calculateClipRevealTransitionDuration(boolean cutOff, float translationX,
842 float translationY, Rect displayFrame) {
843 if (!cutOff) {
844 return DEFAULT_APP_TRANSITION_DURATION;
845 }
846 final float fraction = Math.max(Math.abs(translationX) / displayFrame.width(),
847 Math.abs(translationY) / displayFrame.height());
848 return (long) (DEFAULT_APP_TRANSITION_DURATION + fraction *
849 (MAX_CLIP_REVEAL_TRANSITION_DURATION - DEFAULT_APP_TRANSITION_DURATION));
850 }
851
852 private Animation createClipRevealAnimationLocked(int transit, boolean enter, Rect appFrame,
853 Rect displayFrame) {
Chet Haase10e23ab2015-02-11 15:08:38 -0800854 final Animation anim;
855 if (enter) {
Craig Mautner80b1f642015-04-22 10:59:09 -0700856 final int appWidth = appFrame.width();
857 final int appHeight = appFrame.height();
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800858
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700859 // mTmpRect will contain an area around the launcher icon that was pressed. We will
Filip Gruszczynski82861362015-10-16 14:21:09 -0700860 // clip reveal from that area in the final area of the app.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700861 getDefaultNextAppTransitionStartRect(mTmpRect);
Craig Mautner80b1f642015-04-22 10:59:09 -0700862
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700863 float t = 0f;
864 if (appHeight > 0) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800865 t = (float) mTmpRect.top / displayFrame.height();
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700866 }
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800867 int translationY = mClipRevealTranslationY + (int)(displayFrame.height() / 7f * t);
868 int translationX = 0;
869 int translationYCorrection = translationY;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700870 int centerX = mTmpRect.centerX();
871 int centerY = mTmpRect.centerY();
872 int halfWidth = mTmpRect.width() / 2;
873 int halfHeight = mTmpRect.height() / 2;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800874 int clipStartX = centerX - halfWidth - appFrame.left;
875 int clipStartY = centerY - halfHeight - appFrame.top;
876 boolean cutOff = false;
877
878 // If the starting rectangle is fully or partially outside of the target rectangle, we
879 // need to start the clipping at the edge and then achieve the rest with translation
880 // and extending the clip rect from that edge.
881 if (appFrame.top > centerY - halfHeight) {
882 translationY = (centerY - halfHeight) - appFrame.top;
883 translationYCorrection = 0;
884 clipStartY = 0;
885 cutOff = true;
886 }
887 if (appFrame.left > centerX - halfWidth) {
888 translationX = (centerX - halfWidth) - appFrame.left;
889 clipStartX = 0;
890 cutOff = true;
891 }
892 if (appFrame.right < centerX + halfWidth) {
893 translationX = (centerX + halfWidth) - appFrame.right;
894 clipStartX = appWidth - mTmpRect.width();
895 cutOff = true;
896 }
897 final long duration = calculateClipRevealTransitionDuration(cutOff, translationX,
898 translationY, displayFrame);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700899
900 // Clip third of the from size of launch icon, expand to full width/height
Chet Haase10e23ab2015-02-11 15:08:38 -0800901 Animation clipAnimLR = new ClipRectLRAnimation(
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800902 clipStartX, clipStartX + mTmpRect.width(), 0, appWidth);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700903 clipAnimLR.setInterpolator(mClipHorizontalInterpolator);
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800904 clipAnimLR.setDuration((long) (duration / 2.5f));
Filip Gruszczynski82861362015-10-16 14:21:09 -0700905
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800906 TranslateAnimation translate = new TranslateAnimation(translationX, 0, translationY, 0);
907 translate.setInterpolator(cutOff ? TOUCH_RESPONSE_INTERPOLATOR
908 : mLinearOutSlowInInterpolator);
909 translate.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800910
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800911 Animation clipAnimTB = new ClipRectTBAnimation(
912 clipStartY, clipStartY + mTmpRect.height(),
913 0, appHeight,
914 translationYCorrection, 0,
915 mLinearOutSlowInInterpolator);
916 clipAnimTB.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
917 clipAnimTB.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800918
919 // Quick fade-in from icon to app window
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800920 final long alphaDuration = duration / 4;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700921 AlphaAnimation alpha = new AlphaAnimation(0.5f, 1);
Chet Haase10e23ab2015-02-11 15:08:38 -0800922 alpha.setDuration(alphaDuration);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700923 alpha.setInterpolator(mLinearOutSlowInInterpolator);
Chet Haase10e23ab2015-02-11 15:08:38 -0800924
925 AnimationSet set = new AnimationSet(false);
926 set.addAnimation(clipAnimLR);
927 set.addAnimation(clipAnimTB);
Filip Gruszczynski82861362015-10-16 14:21:09 -0700928 set.addAnimation(translate);
Chet Haase10e23ab2015-02-11 15:08:38 -0800929 set.addAnimation(alpha);
Filip Gruszczynski9e2cf5b2015-07-31 12:20:40 -0700930 set.setZAdjustment(Animation.ZORDER_TOP);
Chet Haase10e23ab2015-02-11 15:08:38 -0800931 set.initialize(appWidth, appHeight, appWidth, appHeight);
932 anim = set;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800933 mLastHadClipReveal = true;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800934 mLastClipRevealTransitionDuration = duration;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800935
936 // If the start rect was full inside the target rect (cutOff == false), we don't need
937 // to store the translation, because it's only used if cutOff == true.
938 mLastClipRevealMaxTranslation = cutOff
939 ? Math.max(Math.abs(translationY), Math.abs(translationX)) : 0;
Chet Haase10e23ab2015-02-11 15:08:38 -0800940 } else {
941 final long duration;
942 switch (transit) {
943 case TRANSIT_ACTIVITY_OPEN:
944 case TRANSIT_ACTIVITY_CLOSE:
945 duration = mConfigShortAnimTime;
946 break;
947 default:
948 duration = DEFAULT_APP_TRANSITION_DURATION;
949 break;
950 }
951 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
952 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
953 // If we are on top of the wallpaper, we need an animation that
954 // correctly handles the wallpaper staying static behind all of
955 // the animated elements. To do this, will just have the existing
956 // element fade out.
957 anim = new AlphaAnimation(1, 0);
958 anim.setDetachWallpaper(true);
959 } else {
960 // For normal animations, the exiting element just holds in place.
961 anim = new AlphaAnimation(1, 1);
962 }
963 anim.setInterpolator(mDecelerateInterpolator);
964 anim.setDuration(duration);
965 anim.setFillAfter(true);
966 }
967 return anim;
968 }
969
Winson Chung399f6202014-03-19 10:47:20 -0700970 /**
971 * Prepares the specified animation with a standard duration, interpolator, etc.
972 */
Winson Chung5393dff2014-05-08 14:25:43 -0700973 Animation prepareThumbnailAnimationWithDuration(Animation a, int appWidth, int appHeight,
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100974 long duration, Interpolator interpolator) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700975 if (duration > 0) {
976 a.setDuration(duration);
977 }
Winson Chung5393dff2014-05-08 14:25:43 -0700978 a.setFillAfter(true);
Jorim Jaggic69bd222016-03-15 14:38:37 +0100979 if (interpolator != null) {
980 a.setInterpolator(interpolator);
981 }
Winson Chung5393dff2014-05-08 14:25:43 -0700982 a.initialize(appWidth, appHeight, appWidth, appHeight);
983 return a;
984 }
985
986 /**
987 * Prepares the specified animation with a standard duration, interpolator, etc.
988 */
Winson Chung399f6202014-03-19 10:47:20 -0700989 Animation prepareThumbnailAnimation(Animation a, int appWidth, int appHeight, int transit) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800990 // Pick the desired duration. If this is an inter-activity transition,
991 // it is the standard duration for that. Otherwise we use the longer
992 // task transition duration.
Winson Chung5393dff2014-05-08 14:25:43 -0700993 final int duration;
Craig Mautner321bdf52012-12-18 09:53:24 -0800994 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800995 case TRANSIT_ACTIVITY_OPEN:
996 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800997 duration = mConfigShortAnimTime;
998 break;
999 default:
1000 duration = DEFAULT_APP_TRANSITION_DURATION;
1001 break;
1002 }
Winson Chung5393dff2014-05-08 14:25:43 -07001003 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, duration,
1004 mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001005 }
1006
Winson Chung399f6202014-03-19 10:47:20 -07001007 /**
1008 * Return the current thumbnail transition state.
1009 */
1010 int getThumbnailTransitionState(boolean enter) {
1011 if (enter) {
1012 if (mNextAppTransitionScaleUp) {
1013 return THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
1014 } else {
1015 return THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN;
1016 }
1017 } else {
1018 if (mNextAppTransitionScaleUp) {
1019 return THUMBNAIL_TRANSITION_EXIT_SCALE_UP;
1020 } else {
1021 return THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN;
1022 }
1023 }
1024 }
1025
1026 /**
Tony Mak64b8d562017-12-28 17:44:02 +00001027 * Creates an overlay with a background color and a thumbnail for the cross profile apps
1028 * animation.
1029 */
1030 GraphicBuffer createCrossProfileAppsThumbnail(
1031 @DrawableRes int thumbnailDrawableRes, Rect frame) {
1032 final int width = frame.width();
1033 final int height = frame.height();
1034
John Reck519ad482018-02-12 17:08:48 -08001035 final Picture picture = new Picture();
1036 final Canvas canvas = picture.beginRecording(width, height);
Tony Mak64b8d562017-12-28 17:44:02 +00001037 canvas.drawColor(Color.argb(0.6f, 0, 0, 0));
1038 final int thumbnailSize = mService.mContext.getResources().getDimensionPixelSize(
1039 com.android.internal.R.dimen.cross_profile_apps_thumbnail_size);
1040 final Drawable drawable = mService.mContext.getDrawable(thumbnailDrawableRes);
1041 drawable.setBounds(
1042 (width - thumbnailSize) / 2,
1043 (height - thumbnailSize) / 2,
1044 (width + thumbnailSize) / 2,
1045 (height + thumbnailSize) / 2);
Tony Makda4af232018-04-27 11:01:10 +01001046 drawable.setTint(mContext.getColor(android.R.color.white));
Tony Mak64b8d562017-12-28 17:44:02 +00001047 drawable.draw(canvas);
John Reck519ad482018-02-12 17:08:48 -08001048 picture.endRecording();
Tony Mak64b8d562017-12-28 17:44:02 +00001049
John Reck519ad482018-02-12 17:08:48 -08001050 return Bitmap.createBitmap(picture).createGraphicBufferHandle();
Tony Mak64b8d562017-12-28 17:44:02 +00001051 }
1052
1053 Animation createCrossProfileAppsThumbnailAnimationLocked(Rect appRect) {
1054 final Animation animation = loadAnimationRes(
1055 "android", com.android.internal.R.anim.cross_profile_apps_thumbnail_enter);
1056 return prepareThumbnailAnimationWithDuration(animation, appRect.width(),
1057 appRect.height(), 0, null);
1058 }
1059
1060 /**
Winson Chung399f6202014-03-19 10:47:20 -07001061 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001062 * when a thumbnail is specified with the pending animation override.
Winson Chung399f6202014-03-19 10:47:20 -07001063 */
Jorim Jaggide63d442016-03-14 14:56:56 +01001064 Animation createThumbnailAspectScaleAnimationLocked(Rect appRect, @Nullable Rect contentInsets,
Winson Chungaa7fa012017-05-24 15:50:06 -07001065 GraphicBuffer thumbnailHeader, final int taskId, int uiMode, int orientation) {
Winson Chung399f6202014-03-19 10:47:20 -07001066 Animation a;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001067 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chung399f6202014-03-19 10:47:20 -07001068 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001069 final int thumbHeightI = thumbnailHeader.getHeight();
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -07001070 final int appWidth = appRect.width();
Winson Chung399f6202014-03-19 10:47:20 -07001071
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -07001072 float scaleW = appWidth / thumbWidth;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001073 getNextAppTransitionStartRect(taskId, mTmpRect);
Jorim Jaggi09072002016-03-25 16:48:42 -07001074 final float fromX;
Manu Cornet57b61492017-01-24 18:19:05 +09001075 float fromY;
Jorim Jaggi09072002016-03-25 16:48:42 -07001076 final float toX;
Manu Cornet57b61492017-01-24 18:19:05 +09001077 float toY;
Jorim Jaggi09072002016-03-25 16:48:42 -07001078 final float pivotX;
1079 final float pivotY;
Manu Cornetd7376802017-01-13 13:44:07 -08001080 if (shouldScaleDownThumbnailTransition(uiMode, orientation)) {
Jorim Jaggi09072002016-03-25 16:48:42 -07001081 fromX = mTmpRect.left;
1082 fromY = mTmpRect.top;
1083
1084 // For the curved translate animation to work, the pivot points needs to be at the
1085 // same absolute position as the one from the real surface.
1086 toX = mTmpRect.width() / 2 * (scaleW - 1f) + appRect.left;
1087 toY = appRect.height() / 2 * (1 - 1 / scaleW) + appRect.top;
1088 pivotX = mTmpRect.width() / 2;
1089 pivotY = appRect.height() / 2 / scaleW;
Manu Cornet57b61492017-01-24 18:19:05 +09001090 if (mGridLayoutRecentsEnabled) {
1091 // In the grid layout, the header is displayed above the thumbnail instead of
1092 // overlapping it.
1093 fromY -= thumbHeightI;
1094 toY -= thumbHeightI * scaleW;
1095 }
Jorim Jaggi09072002016-03-25 16:48:42 -07001096 } else {
1097 pivotX = 0;
1098 pivotY = 0;
1099 fromX = mTmpRect.left;
1100 fromY = mTmpRect.top;
1101 toX = appRect.left;
1102 toY = appRect.top;
1103 }
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001104 final long duration = getAspectScaleDuration();
1105 final Interpolator interpolator = getAspectScaleInterpolator();
Winson Chung399f6202014-03-19 10:47:20 -07001106 if (mNextAppTransitionScaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001107 // Animation up from the thumbnail to the full screen
Jorim Jaggi8448f332016-03-14 17:50:37 +01001108 Animation scale = new ScaleAnimation(1f, scaleW, 1f, scaleW, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001109 scale.setInterpolator(interpolator);
1110 scale.setDuration(duration);
Jorim Jaggic6c89a82016-01-28 17:48:21 -08001111 Animation alpha = new AlphaAnimation(1f, 0f);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001112 alpha.setInterpolator(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
1113 ? THUMBNAIL_DOCK_INTERPOLATOR : mThumbnailFadeOutInterpolator);
1114 alpha.setDuration(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
1115 ? duration / 2
1116 : duration);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001117 Animation translate = createCurvedMotion(fromX, toX, fromY, toY);
1118 translate.setInterpolator(interpolator);
1119 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -07001120
Jorim Jaggide63d442016-03-14 14:56:56 +01001121 mTmpFromClipRect.set(0, 0, thumbWidthI, thumbHeightI);
1122 mTmpToClipRect.set(appRect);
1123
1124 // Containing frame is in screen space, but we need the clip rect in the
1125 // app space.
1126 mTmpToClipRect.offsetTo(0, 0);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001127 mTmpToClipRect.right = (int) (mTmpToClipRect.right / scaleW);
1128 mTmpToClipRect.bottom = (int) (mTmpToClipRect.bottom / scaleW);
Jorim Jaggide63d442016-03-14 14:56:56 +01001129
1130 if (contentInsets != null) {
Jorim Jaggi8448f332016-03-14 17:50:37 +01001131 mTmpToClipRect.inset((int) (-contentInsets.left * scaleW),
1132 (int) (-contentInsets.top * scaleW),
1133 (int) (-contentInsets.right * scaleW),
1134 (int) (-contentInsets.bottom * scaleW));
Jorim Jaggide63d442016-03-14 14:56:56 +01001135 }
1136
1137 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001138 clipAnim.setInterpolator(interpolator);
1139 clipAnim.setDuration(duration);
Jorim Jaggide63d442016-03-14 14:56:56 +01001140
Winson Chung399f6202014-03-19 10:47:20 -07001141 // This AnimationSet uses the Interpolators assigned above.
1142 AnimationSet set = new AnimationSet(false);
1143 set.addAnimation(scale);
Manu Cornet57b61492017-01-24 18:19:05 +09001144 if (!mGridLayoutRecentsEnabled) {
1145 // In the grid layout, the header should be shown for the whole animation.
1146 set.addAnimation(alpha);
1147 }
Winson Chunga4ccb862014-08-22 15:26:27 -07001148 set.addAnimation(translate);
Jorim Jaggide63d442016-03-14 14:56:56 +01001149 set.addAnimation(clipAnim);
Winson Chung399f6202014-03-19 10:47:20 -07001150 a = set;
1151 } else {
Winson Chunga4ccb862014-08-22 15:26:27 -07001152 // Animation down from the full screen to the thumbnail
Jorim Jaggi8448f332016-03-14 17:50:37 +01001153 Animation scale = new ScaleAnimation(scaleW, 1f, scaleW, 1f, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001154 scale.setInterpolator(interpolator);
1155 scale.setDuration(duration);
Winson Chunga4ccb862014-08-22 15:26:27 -07001156 Animation alpha = new AlphaAnimation(0f, 1f);
1157 alpha.setInterpolator(mThumbnailFadeInInterpolator);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001158 alpha.setDuration(duration);
1159 Animation translate = createCurvedMotion(toX, fromX, toY, fromY);
1160 translate.setInterpolator(interpolator);
1161 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -07001162
Winson Chunga4ccb862014-08-22 15:26:27 -07001163 // This AnimationSet uses the Interpolators assigned above.
1164 AnimationSet set = new AnimationSet(false);
1165 set.addAnimation(scale);
Manu Cornet57b61492017-01-24 18:19:05 +09001166 if (!mGridLayoutRecentsEnabled) {
1167 // In the grid layout, the header should be shown for the whole animation.
1168 set.addAnimation(alpha);
1169 }
Winson Chunga4ccb862014-08-22 15:26:27 -07001170 set.addAnimation(translate);
1171 a = set;
1172
1173 }
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -07001174 return prepareThumbnailAnimationWithDuration(a, appWidth, appRect.height(), 0,
Jorim Jaggic69bd222016-03-15 14:38:37 +01001175 null);
Winson Chung399f6202014-03-19 10:47:20 -07001176 }
1177
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001178 private Animation createCurvedMotion(float fromX, float toX, float fromY, float toY) {
1179
1180 // Almost no x-change - use linear animation
Jorim Jaggic69bd222016-03-15 14:38:37 +01001181 if (Math.abs(toX - fromX) < 1f || mNextAppTransition != TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001182 return new TranslateAnimation(fromX, toX, fromY, toY);
1183 } else {
1184 final Path path = createCurvedPath(fromX, toX, fromY, toY);
1185 return new CurvedTranslateAnimation(path);
1186 }
1187 }
1188
1189 private Path createCurvedPath(float fromX, float toX, float fromY, float toY) {
1190 final Path path = new Path();
1191 path.moveTo(fromX, fromY);
Jorim Jaggi1f458fb2016-03-25 17:36:37 -07001192
1193 if (fromY > toY) {
1194 // If the object needs to go up, move it in horizontal direction first, then vertical.
1195 path.cubicTo(fromX, fromY, toX, 0.9f * fromY + 0.1f * toY, toX, toY);
1196 } else {
1197 // If the object needs to go down, move it in vertical direction first, then horizontal.
1198 path.cubicTo(fromX, fromY, fromX, 0.1f * fromY + 0.9f * toY, toX, toY);
1199 }
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001200 return path;
1201 }
1202
1203 private long getAspectScaleDuration() {
1204 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggic69bd222016-03-15 14:38:37 +01001205 return (long) (THUMBNAIL_APP_TRANSITION_DURATION * 1.35f);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001206 } else {
1207 return THUMBNAIL_APP_TRANSITION_DURATION;
1208 }
1209 }
1210
1211 private Interpolator getAspectScaleInterpolator() {
1212 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
1213 return mFastOutSlowInInterpolator;
1214 } else {
1215 return TOUCH_RESPONSE_INTERPOLATOR;
1216 }
1217 }
1218
Winson Chung399f6202014-03-19 10:47:20 -07001219 /**
1220 * This alternate animation is created when we are doing a thumbnail transition, for the
1221 * activity that is leaving, and the activity that is entering.
1222 */
Winson Chunga4ccb862014-08-22 15:26:27 -07001223 Animation createAspectScaledThumbnailEnterExitAnimationLocked(int thumbTransitState,
Winsonb2024762016-04-05 17:32:30 -07001224 int uiMode, int orientation, int transit, Rect containingFrame, Rect contentInsets,
Matthew Ng43db6d22017-06-27 15:29:39 -07001225 @Nullable Rect surfaceInsets, @Nullable Rect stableInsets, boolean freeform,
1226 int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -07001227 Animation a;
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001228 final int appWidth = containingFrame.width();
1229 final int appHeight = containingFrame.height();
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001230 getDefaultNextAppTransitionStartRect(mTmpRect);
1231 final int thumbWidthI = mTmpRect.width();
Winson Chung399f6202014-03-19 10:47:20 -07001232 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001233 final int thumbHeightI = mTmpRect.height();
Winson Chung399f6202014-03-19 10:47:20 -07001234 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
Winsoncbb625b2016-07-06 15:24:15 -07001235 final int thumbStartX = mTmpRect.left - containingFrame.left - contentInsets.left;
Winson21700932016-03-24 17:26:23 -07001236 final int thumbStartY = mTmpRect.top - containingFrame.top;
Winson Chung399f6202014-03-19 10:47:20 -07001237
1238 switch (thumbTransitState) {
Jorim Jaggi8448f332016-03-14 17:50:37 +01001239 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP:
1240 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1241 final boolean scaleUp = thumbTransitState == THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
1242 if (freeform && scaleUp) {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001243 a = createAspectScaledThumbnailEnterFreeformAnimationLocked(
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001244 containingFrame, surfaceInsets, taskId);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001245 } else if (freeform) {
1246 a = createAspectScaledThumbnailExitFreeformAnimationLocked(
1247 containingFrame, surfaceInsets, taskId);
Winson Chung2820c452014-04-15 15:34:44 -07001248 } else {
Winson21700932016-03-24 17:26:23 -07001249 AnimationSet set = new AnimationSet(true);
1250
1251 // In portrait, we scale to fit the width
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001252 mTmpFromClipRect.set(containingFrame);
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001253 mTmpToClipRect.set(containingFrame);
Jorim Jaggic6c89a82016-01-28 17:48:21 -08001254
1255 // Containing frame is in screen space, but we need the clip rect in the
1256 // app space.
1257 mTmpFromClipRect.offsetTo(0, 0);
1258 mTmpToClipRect.offsetTo(0, 0);
1259
1260 // Exclude insets region from the source clip.
1261 mTmpFromClipRect.inset(contentInsets);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001262 mNextAppTransitionInsets.set(contentInsets);
1263
Manu Cornetd7376802017-01-13 13:44:07 -08001264 if (shouldScaleDownThumbnailTransition(uiMode, orientation)) {
Jorim Jaggic69bd222016-03-15 14:38:37 +01001265 // We scale the width and clip to the top/left square
1266 float scale = thumbWidth /
1267 (appWidth - contentInsets.left - contentInsets.right);
Manu Cornetb68b7652017-01-23 19:37:53 +09001268 if (!mGridLayoutRecentsEnabled) {
1269 int unscaledThumbHeight = (int) (thumbHeight / scale);
1270 mTmpFromClipRect.bottom = mTmpFromClipRect.top + unscaledThumbHeight;
1271 }
Jorim Jaggic69bd222016-03-15 14:38:37 +01001272
1273 mNextAppTransitionInsets.set(contentInsets);
1274
Jorim Jaggi8448f332016-03-14 17:50:37 +01001275 Animation scaleAnim = new ScaleAnimation(
1276 scaleUp ? scale : 1, scaleUp ? 1 : scale,
1277 scaleUp ? scale : 1, scaleUp ? 1 : scale,
Jorim Jaggic69bd222016-03-15 14:38:37 +01001278 containingFrame.width() / 2f,
1279 containingFrame.height() / 2f + contentInsets.top);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001280 final float targetX = (mTmpRect.left - containingFrame.left);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001281 final float x = containingFrame.width() / 2f
1282 - containingFrame.width() / 2f * scale;
Jorim Jaggi8448f332016-03-14 17:50:37 +01001283 final float targetY = (mTmpRect.top - containingFrame.top);
Matthew Ng43db6d22017-06-27 15:29:39 -07001284 float y = containingFrame.height() / 2f
Jorim Jaggic69bd222016-03-15 14:38:37 +01001285 - containingFrame.height() / 2f * scale;
Matthew Ng43db6d22017-06-27 15:29:39 -07001286
1287 // During transition may require clipping offset from any top stable insets
1288 // such as the statusbar height when statusbar is hidden
1289 if (mLowRamRecentsEnabled && contentInsets.top == 0 && scaleUp) {
1290 mTmpFromClipRect.top += stableInsets.top;
1291 y += stableInsets.top;
1292 }
Jorim Jaggi8448f332016-03-14 17:50:37 +01001293 final float startX = targetX - x;
1294 final float startY = targetY - y;
1295 Animation clipAnim = scaleUp
1296 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1297 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1298 Animation translateAnim = scaleUp
Jorim Jaggic69bd222016-03-15 14:38:37 +01001299 ? createCurvedMotion(startX, 0, startY - contentInsets.top, 0)
1300 : createCurvedMotion(0, startX, 0, startY - contentInsets.top);
1301
Winson21700932016-03-24 17:26:23 -07001302 set.addAnimation(clipAnim);
1303 set.addAnimation(scaleAnim);
1304 set.addAnimation(translateAnim);
1305
1306 } else {
1307 // In landscape, we don't scale at all and only crop
1308 mTmpFromClipRect.bottom = mTmpFromClipRect.top + thumbHeightI;
1309 mTmpFromClipRect.right = mTmpFromClipRect.left + thumbWidthI;
1310
Jorim Jaggi8448f332016-03-14 17:50:37 +01001311 Animation clipAnim = scaleUp
1312 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1313 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1314 Animation translateAnim = scaleUp
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001315 ? createCurvedMotion(thumbStartX, 0,
1316 thumbStartY - contentInsets.top, 0)
1317 : createCurvedMotion(0, thumbStartX, 0,
1318 thumbStartY - contentInsets.top);
Winson21700932016-03-24 17:26:23 -07001319
1320 set.addAnimation(clipAnim);
1321 set.addAnimation(translateAnim);
1322 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001323 a = set;
Winson21700932016-03-24 17:26:23 -07001324 a.setZAdjustment(Animation.ZORDER_TOP);
Winson Chung2820c452014-04-15 15:34:44 -07001325 }
Winson Chung399f6202014-03-19 10:47:20 -07001326 break;
1327 }
1328 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001329 // Previous app window during the scale up
Winson Chung399f6202014-03-19 10:47:20 -07001330 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001331 // Fade out the source activity if we are animating to a wallpaper
Winson Chung399f6202014-03-19 10:47:20 -07001332 // activity.
1333 a = new AlphaAnimation(1, 0);
1334 } else {
Winson Chung399f6202014-03-19 10:47:20 -07001335 a = new AlphaAnimation(1, 1);
1336 }
1337 break;
1338 }
1339 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001340 // Target app window during the scale down
1341 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1342 // Fade in the destination activity if we are animating from a wallpaper
1343 // activity.
1344 a = new AlphaAnimation(0, 1);
1345 } else {
1346 a = new AlphaAnimation(1, 1);
1347 }
Winson Chung399f6202014-03-19 10:47:20 -07001348 break;
1349 }
Winson Chung399f6202014-03-19 10:47:20 -07001350 default:
1351 throw new RuntimeException("Invalid thumbnail transition state");
1352 }
1353
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001354 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight,
1355 getAspectScaleDuration(), getAspectScaleInterpolator());
Winson Chung399f6202014-03-19 10:47:20 -07001356 }
1357
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001358 private Animation createAspectScaledThumbnailEnterFreeformAnimationLocked(Rect frame,
1359 @Nullable Rect surfaceInsets, int taskId) {
1360 getNextAppTransitionStartRect(taskId, mTmpRect);
1361 return createAspectScaledThumbnailFreeformAnimationLocked(mTmpRect, frame, surfaceInsets,
1362 true);
1363 }
1364
1365 private Animation createAspectScaledThumbnailExitFreeformAnimationLocked(Rect frame,
1366 @Nullable Rect surfaceInsets, int taskId) {
1367 getNextAppTransitionStartRect(taskId, mTmpRect);
1368 return createAspectScaledThumbnailFreeformAnimationLocked(frame, mTmpRect, surfaceInsets,
1369 false);
1370 }
1371
1372 private AnimationSet createAspectScaledThumbnailFreeformAnimationLocked(Rect sourceFrame,
1373 Rect destFrame, @Nullable Rect surfaceInsets, boolean enter) {
1374 final float sourceWidth = sourceFrame.width();
1375 final float sourceHeight = sourceFrame.height();
1376 final float destWidth = destFrame.width();
1377 final float destHeight = destFrame.height();
1378 final float scaleH = enter ? sourceWidth / destWidth : destWidth / sourceWidth;
1379 final float scaleV = enter ? sourceHeight / destHeight : destHeight / sourceHeight;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001380 AnimationSet set = new AnimationSet(true);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001381 final int surfaceInsetsH = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001382 ? 0 : surfaceInsets.left + surfaceInsets.right;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001383 final int surfaceInsetsV = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001384 ? 0 : surfaceInsets.top + surfaceInsets.bottom;
1385 // We want the scaling to happen from the center of the surface. In order to achieve that,
1386 // we need to account for surface insets that will be used to enlarge the surface.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001387 final float scaleHCenter = ((enter ? destWidth : sourceWidth) + surfaceInsetsH) / 2;
1388 final float scaleVCenter = ((enter ? destHeight : sourceHeight) + surfaceInsetsV) / 2;
1389 final ScaleAnimation scale = enter ?
1390 new ScaleAnimation(scaleH, 1, scaleV, 1, scaleHCenter, scaleVCenter)
1391 : new ScaleAnimation(1, scaleH, 1, scaleV, scaleHCenter, scaleVCenter);
1392 final int sourceHCenter = sourceFrame.left + sourceFrame.width() / 2;
1393 final int sourceVCenter = sourceFrame.top + sourceFrame.height() / 2;
1394 final int destHCenter = destFrame.left + destFrame.width() / 2;
1395 final int destVCenter = destFrame.top + destFrame.height() / 2;
1396 final int fromX = enter ? sourceHCenter - destHCenter : destHCenter - sourceHCenter;
1397 final int fromY = enter ? sourceVCenter - destVCenter : destVCenter - sourceVCenter;
1398 final TranslateAnimation translation = enter ? new TranslateAnimation(fromX, 0, fromY, 0)
1399 : new TranslateAnimation(0, fromX, 0, fromY);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001400 set.addAnimation(scale);
1401 set.addAnimation(translation);
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001402
1403 final IRemoteCallback callback = mAnimationFinishedCallback;
1404 if (callback != null) {
1405 set.setAnimationListener(new Animation.AnimationListener() {
1406 @Override
1407 public void onAnimationStart(Animation animation) { }
1408
1409 @Override
1410 public void onAnimationEnd(Animation animation) {
lumark23b54592018-10-02 17:17:23 +08001411 mHandler.sendMessage(PooledLambda.obtainMessage(
1412 AppTransition::doAnimationCallback, callback));
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001413 }
1414
1415 @Override
1416 public void onAnimationRepeat(Animation animation) { }
1417 });
1418 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001419 return set;
1420 }
1421
Winson Chung399f6202014-03-19 10:47:20 -07001422 /**
Winson Chunga4ccb862014-08-22 15:26:27 -07001423 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001424 * when a thumbnail is specified with the pending animation override.
Winson Chunga4ccb862014-08-22 15:26:27 -07001425 */
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001426 Animation createThumbnailScaleAnimationLocked(int appWidth, int appHeight, int transit,
Winson Chungaa7fa012017-05-24 15:50:06 -07001427 GraphicBuffer thumbnailHeader) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001428 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001429 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001430 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chunga4ccb862014-08-22 15:26:27 -07001431 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001432 final int thumbHeightI = thumbnailHeader.getHeight();
Winson Chunga4ccb862014-08-22 15:26:27 -07001433 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1434
1435 if (mNextAppTransitionScaleUp) {
1436 // Animation for the thumbnail zooming from its initial size to the full screen
1437 float scaleW = appWidth / thumbWidth;
1438 float scaleH = appHeight / thumbHeight;
1439 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001440 computePivot(mTmpRect.left, 1 / scaleW),
1441 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001442 scale.setInterpolator(mDecelerateInterpolator);
1443
1444 Animation alpha = new AlphaAnimation(1, 0);
1445 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
1446
1447 // This AnimationSet uses the Interpolators assigned above.
1448 AnimationSet set = new AnimationSet(false);
1449 set.addAnimation(scale);
1450 set.addAnimation(alpha);
1451 a = set;
1452 } else {
1453 // Animation for the thumbnail zooming down from the full screen to its final size
1454 float scaleW = appWidth / thumbWidth;
1455 float scaleH = appHeight / thumbHeight;
1456 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001457 computePivot(mTmpRect.left, 1 / scaleW),
1458 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001459 }
1460
1461 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1462 }
1463
1464 /**
Winson Chung399f6202014-03-19 10:47:20 -07001465 * This animation is created when we are doing a thumbnail transition, for the activity that is
1466 * leaving, and the activity that is entering.
1467 */
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001468 Animation createThumbnailEnterExitAnimationLocked(int thumbTransitState, Rect containingFrame,
1469 int transit, int taskId) {
1470 final int appWidth = containingFrame.width();
1471 final int appHeight = containingFrame.height();
Winson Chungaa7fa012017-05-24 15:50:06 -07001472 final GraphicBuffer thumbnailHeader = getAppTransitionThumbnailHeader(taskId);
Winson Chung399f6202014-03-19 10:47:20 -07001473 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001474 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001475 final int thumbWidthI = thumbnailHeader != null ? thumbnailHeader.getWidth() : appWidth;
Winson Chung399f6202014-03-19 10:47:20 -07001476 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001477 final int thumbHeightI = thumbnailHeader != null ? thumbnailHeader.getHeight() : appHeight;
Winson Chung399f6202014-03-19 10:47:20 -07001478 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1479
1480 switch (thumbTransitState) {
1481 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
1482 // Entering app scales up with the thumbnail
1483 float scaleW = thumbWidth / appWidth;
1484 float scaleH = thumbHeight / appHeight;
1485 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001486 computePivot(mTmpRect.left, scaleW),
1487 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001488 break;
1489 }
1490 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
1491 // Exiting app while the thumbnail is scaling up should fade or stay in place
1492 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1493 // Fade out while bringing up selected activity. This keeps the
1494 // current activity from showing through a launching wallpaper
1495 // activity.
1496 a = new AlphaAnimation(1, 0);
1497 } else {
1498 // noop animation
1499 a = new AlphaAnimation(1, 1);
1500 }
1501 break;
1502 }
1503 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
1504 // Entering the other app, it should just be visible while we scale the thumbnail
1505 // down above it
1506 a = new AlphaAnimation(1, 1);
1507 break;
1508 }
1509 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1510 // Exiting the current app, the app should scale down with the thumbnail
1511 float scaleW = thumbWidth / appWidth;
1512 float scaleH = thumbHeight / appHeight;
1513 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001514 computePivot(mTmpRect.left, scaleW),
1515 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001516
1517 Animation alpha = new AlphaAnimation(1, 0);
1518
1519 AnimationSet set = new AnimationSet(true);
1520 set.addAnimation(scale);
1521 set.addAnimation(alpha);
1522 set.setZAdjustment(Animation.ZORDER_TOP);
1523 a = set;
1524 break;
1525 }
1526 default:
1527 throw new RuntimeException("Invalid thumbnail transition state");
1528 }
1529
1530 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1531 }
1532
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001533 private Animation createRelaunchAnimation(Rect containingFrame, Rect contentInsets) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001534 getDefaultNextAppTransitionStartRect(mTmpFromClipRect);
1535 final int left = mTmpFromClipRect.left;
1536 final int top = mTmpFromClipRect.top;
1537 mTmpFromClipRect.offset(-left, -top);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001538 // TODO: Isn't that strange that we ignore exact position of the containingFrame?
1539 mTmpToClipRect.set(0, 0, containingFrame.width(), containingFrame.height());
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001540 AnimationSet set = new AnimationSet(true);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001541 float fromWidth = mTmpFromClipRect.width();
1542 float toWidth = mTmpToClipRect.width();
1543 float fromHeight = mTmpFromClipRect.height();
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001544 // While the window might span the whole display, the actual content will be cropped to the
1545 // system decoration frame, for example when the window is docked. We need to take into
1546 // account the visible height when constructing the animation.
1547 float toHeight = mTmpToClipRect.height() - contentInsets.top - contentInsets.bottom;
1548 int translateAdjustment = 0;
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001549 if (fromWidth <= toWidth && fromHeight <= toHeight) {
1550 // The final window is larger in both dimensions than current window (e.g. we are
1551 // maximizing), so we can simply unclip the new window and there will be no disappearing
1552 // frame.
1553 set.addAnimation(new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect));
1554 } else {
1555 // The disappearing window has one larger dimension. We need to apply scaling, so the
1556 // first frame of the entry animation matches the old window.
1557 set.addAnimation(new ScaleAnimation(fromWidth / toWidth, 1, fromHeight / toHeight, 1));
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001558 // We might not be going exactly full screen, but instead be aligned under the status
1559 // bar using cropping. We still need to account for the cropped part, which will also
1560 // be scaled.
1561 translateAdjustment = (int) (contentInsets.top * fromHeight / toHeight);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001562 }
1563
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001564 // We animate the translation from the old position of the removed window, to the new
1565 // position of the added window. The latter might not be full screen, for example docked for
1566 // docked windows.
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001567 TranslateAnimation translate = new TranslateAnimation(left - containingFrame.left,
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001568 0, top - containingFrame.top - translateAdjustment, 0);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001569 set.addAnimation(translate);
1570 set.setDuration(DEFAULT_APP_TRANSITION_DURATION);
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07001571 set.setZAdjustment(Animation.ZORDER_TOP);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001572 return set;
1573 }
1574
Jorim Jaggic554b772015-06-04 16:07:57 -07001575 /**
1576 * @return true if and only if the first frame of the transition can be skipped, i.e. the first
1577 * frame of the transition doesn't change the visuals on screen, so we can start
1578 * directly with the second one
1579 */
1580 boolean canSkipFirstFrame() {
1581 return mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM
1582 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE
Jorim Jaggife762342016-10-13 14:33:27 +02001583 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CLIP_REVEAL
1584 && mNextAppTransition != TRANSIT_KEYGUARD_GOING_AWAY;
Jorim Jaggic554b772015-06-04 16:07:57 -07001585 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001586
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001587 RemoteAnimationController getRemoteAnimationController() {
1588 return mRemoteAnimationController;
1589 }
1590
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001591 /**
1592 *
1593 * @param frame These are the bounds of the window when it finishes the animation. This is where
1594 * the animation must usually finish in entrance animation, as the next frame will
1595 * display the window at these coordinates. In case of exit animation, this is
1596 * where the animation must start, as the frame before the animation is displaying
1597 * the window at these bounds.
1598 * @param insets Knowing where the window will be positioned is not enough. Some parts of the
1599 * window might be obscured, usually by the system windows (status bar and
1600 * navigation bar) and we use content insets to convey that information. This
1601 * usually affects the animation aspects vertically, as the system decoration is
1602 * at the top and the bottom. For example when we animate from full screen to
1603 * recents, we want to exclude the covered parts, because they won't match the
1604 * thumbnail after the last frame is executed.
1605 * @param surfaceInsets In rare situation the surface is larger than the content and we need to
1606 * know about this to make the animation frames match. We currently use
1607 * this for freeform windows, which have larger surfaces to display
1608 * shadows. When we animate them from recents, we want to match the content
1609 * to the recents thumbnail and hence need to account for the surface being
1610 * bigger.
1611 */
Jorim Jaggif84e2f62018-01-16 14:17:59 +01001612 Animation loadAnimation(LayoutParams lp, int transit, boolean enter, int uiMode,
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001613 int orientation, Rect frame, Rect displayFrame, Rect insets,
Matthew Ng43db6d22017-06-27 15:29:39 -07001614 @Nullable Rect surfaceInsets, @Nullable Rect stableInsets, boolean isVoiceInteraction,
1615 boolean freeform, int taskId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001616 Animation a;
Jorim Jaggife762342016-10-13 14:33:27 +02001617 if (isKeyguardGoingAwayTransit(transit) && enter) {
1618 a = loadKeyguardExitAnimation(transit);
1619 } else if (transit == TRANSIT_KEYGUARD_OCCLUDE) {
Selim Cinekdbf172e2018-08-08 18:31:45 +00001620 a = null;
Jorim Jaggife762342016-10-13 14:33:27 +02001621 } else if (transit == TRANSIT_KEYGUARD_UNOCCLUDE && !enter) {
1622 a = loadAnimationRes(lp, com.android.internal.R.anim.wallpaper_open_exit);
Adrian Roos93577212018-04-10 14:12:10 -07001623 } else if (transit == TRANSIT_CRASHING_ACTIVITY_CLOSE) {
1624 a = null;
Jorim Jaggife762342016-10-13 14:33:27 +02001625 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_OPEN
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001626 || transit == TRANSIT_TASK_OPEN
1627 || transit == TRANSIT_TASK_TO_FRONT)) {
1628 a = loadAnimationRes(lp, enter
1629 ? com.android.internal.R.anim.voice_activity_open_enter
1630 : com.android.internal.R.anim.voice_activity_open_exit);
1631 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1632 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001633 + " anim=" + a + " transit=" + appTransitionToString(transit)
1634 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001635 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_CLOSE
1636 || transit == TRANSIT_TASK_CLOSE
1637 || transit == TRANSIT_TASK_TO_BACK)) {
1638 a = loadAnimationRes(lp, enter
1639 ? com.android.internal.R.anim.voice_activity_close_enter
1640 : com.android.internal.R.anim.voice_activity_close_exit);
1641 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1642 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001643 + " anim=" + a + " transit=" + appTransitionToString(transit)
1644 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001645 } else if (transit == TRANSIT_ACTIVITY_RELAUNCH) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001646 a = createRelaunchAnimation(frame, insets);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001647 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1648 "applyAnimation:"
1649 + " anim=" + a + " nextAppTransition=" + mNextAppTransition
1650 + " transit=" + appTransitionToString(transit)
1651 + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001652 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM) {
1653 a = loadAnimationRes(mNextAppTransitionPackage, enter ?
Craig Mautner164d4bb2012-11-26 13:51:23 -08001654 mNextAppTransitionEnter : mNextAppTransitionExit);
1655 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1656 "applyAnimation:"
1657 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001658 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001659 + " Callers=" + Debug.getCallers(3));
Winson Chung044d5292014-11-06 11:05:19 -08001660 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE) {
1661 a = loadAnimationRes(mNextAppTransitionPackage, mNextAppTransitionInPlace);
1662 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1663 "applyAnimation:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001664 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM_IN_PLACE"
1665 + " transit=" + appTransitionToString(transit)
1666 + " Callers=" + 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);
Chet Haase10e23ab2015-02-11 15:08:38 -08001669 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1670 "applyAnimation:"
1671 + " anim=" + a + " nextAppTransition=ANIM_CLIP_REVEAL"
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001672 + " transit=" + appTransitionToString(transit)
Chet Haase10e23ab2015-02-11 15:08:38 -08001673 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001674 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_SCALE_UP) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001675 a = createScaleUpAnimationLocked(transit, enter, frame);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001676 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1677 "applyAnimation:"
1678 + " anim=" + a + " nextAppTransition=ANIM_SCALE_UP"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001679 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001680 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001681 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
1682 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001683 mNextAppTransitionScaleUp =
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001684 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP);
Winson Chunga4ccb862014-08-22 15:26:27 -07001685 a = createThumbnailEnterExitAnimationLocked(getThumbnailTransitionState(enter),
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001686 frame, transit, taskId);
Winson Chunga4ccb862014-08-22 15:26:27 -07001687 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1688 String animName = mNextAppTransitionScaleUp ?
1689 "ANIM_THUMBNAIL_SCALE_UP" : "ANIM_THUMBNAIL_SCALE_DOWN";
1690 Slog.v(TAG, "applyAnimation:"
1691 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001692 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Winson Chunga4ccb862014-08-22 15:26:27 -07001693 + " Callers=" + Debug.getCallers(3));
1694 }
1695 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
1696 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN) {
1697 mNextAppTransitionScaleUp =
1698 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP);
1699 a = createAspectScaledThumbnailEnterExitAnimationLocked(
Winsonb2024762016-04-05 17:32:30 -07001700 getThumbnailTransitionState(enter), uiMode, orientation, transit, frame,
Matthew Ng43db6d22017-06-27 15:29:39 -07001701 insets, surfaceInsets, stableInsets, freeform, taskId);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001702 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1703 String animName = mNextAppTransitionScaleUp ?
Winson Chunga4ccb862014-08-22 15:26:27 -07001704 "ANIM_THUMBNAIL_ASPECT_SCALE_UP" : "ANIM_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner164d4bb2012-11-26 13:51:23 -08001705 Slog.v(TAG, "applyAnimation:"
1706 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001707 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001708 + " Callers=" + Debug.getCallers(3));
1709 }
Tony Mak83546a82018-01-22 13:56:20 +00001710 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS && enter) {
Jorim Jaggi98a9d202018-03-26 16:17:07 +02001711 a = loadAnimationRes("android",
1712 com.android.internal.R.anim.task_open_enter_cross_profile_apps);
Tony Mak089c35e2017-12-18 20:34:14 +00001713 Slog.v(TAG,
1714 "applyAnimation NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS:"
1715 + " anim=" + a + " transit=" + appTransitionToString(transit)
Jorim Jaggi98a9d202018-03-26 16:17:07 +02001716 + " isEntrance=true" + " Callers=" + Debug.getCallers(3));
Evan Roskycf76bed2019-01-15 10:33:58 -08001717 } else if (transit == TRANSIT_TASK_CHANGE_WINDOWING_MODE) {
1718 // In the absence of a specific adapter, we just want to keep everything stationary.
1719 a = new AlphaAnimation(1.f, 1.f);
1720 a.setDuration(WindowChangeAnimationSpec.ANIMATION_DURATION);
1721 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1722 Slog.v(TAG, "applyAnimation:"
1723 + " anim=" + a + " transit=" + appTransitionToString(transit)
1724 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
1725 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001726 } else {
1727 int animAttr = 0;
1728 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001729 case TRANSIT_ACTIVITY_OPEN:
Jorim Jaggi0a1523d2018-04-19 17:48:38 +02001730 case TRANSIT_TRANSLUCENT_ACTIVITY_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001731 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001732 ? WindowAnimation_activityOpenEnterAnimation
1733 : WindowAnimation_activityOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001734 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001735 case TRANSIT_ACTIVITY_CLOSE:
Jorim Jaggi0a1523d2018-04-19 17:48:38 +02001736 case TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001737 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001738 ? WindowAnimation_activityCloseEnterAnimation
1739 : WindowAnimation_activityCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001740 break;
Jorim Jaggi192086e2016-03-11 17:17:03 +01001741 case TRANSIT_DOCK_TASK_FROM_RECENTS:
Craig Mautner4b71aa12012-12-27 17:20:01 -08001742 case TRANSIT_TASK_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001743 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001744 ? WindowAnimation_taskOpenEnterAnimation
1745 : WindowAnimation_taskOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001746 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001747 case TRANSIT_TASK_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001748 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001749 ? WindowAnimation_taskCloseEnterAnimation
1750 : WindowAnimation_taskCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001751 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001752 case TRANSIT_TASK_TO_FRONT:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001753 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001754 ? WindowAnimation_taskToFrontEnterAnimation
1755 : WindowAnimation_taskToFrontExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001756 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001757 case TRANSIT_TASK_TO_BACK:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001758 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001759 ? WindowAnimation_taskToBackEnterAnimation
1760 : WindowAnimation_taskToBackExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001761 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001762 case TRANSIT_WALLPAPER_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001763 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001764 ? WindowAnimation_wallpaperOpenEnterAnimation
1765 : WindowAnimation_wallpaperOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001766 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001767 case TRANSIT_WALLPAPER_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001768 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001769 ? WindowAnimation_wallpaperCloseEnterAnimation
1770 : WindowAnimation_wallpaperCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001771 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001772 case TRANSIT_WALLPAPER_INTRA_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001773 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001774 ? WindowAnimation_wallpaperIntraOpenEnterAnimation
1775 : WindowAnimation_wallpaperIntraOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001776 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001777 case TRANSIT_WALLPAPER_INTRA_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001778 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001779 ? WindowAnimation_wallpaperIntraCloseEnterAnimation
1780 : WindowAnimation_wallpaperIntraCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001781 break;
Craig Mautnerbb742462014-07-07 15:28:55 -07001782 case TRANSIT_TASK_OPEN_BEHIND:
1783 animAttr = enter
1784 ? WindowAnimation_launchTaskBehindSourceAnimation
Craig Mautner3b2cd1d2014-08-25 14:25:54 -07001785 : WindowAnimation_launchTaskBehindTargetAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001786 }
Jorim Jaggi0a1523d2018-04-19 17:48:38 +02001787 a = animAttr != 0 ? loadAnimationAttr(lp, animAttr, transit) : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001788 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1789 "applyAnimation:"
1790 + " anim=" + a
1791 + " animAttr=0x" + Integer.toHexString(animAttr)
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001792 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001793 + " Callers=" + Debug.getCallers(3));
1794 }
1795 return a;
1796 }
1797
Jorim Jaggife762342016-10-13 14:33:27 +02001798 private Animation loadKeyguardExitAnimation(int transit) {
1799 if ((mNextAppTransitionFlags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_NO_ANIMATION) != 0) {
1800 return null;
1801 }
1802 final boolean toShade =
1803 (mNextAppTransitionFlags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_TO_SHADE) != 0;
1804 return mService.mPolicy.createHiddenByKeyguardExit(
1805 transit == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER, toShade);
1806 }
1807
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001808 int getAppStackClipMode() {
Matthew Ngbf1d9852017-03-14 12:23:09 -07001809 // When dismiss keyguard animation occurs, clip before the animation to prevent docked
1810 // app from showing beyond the divider
1811 if (mNextAppTransition == TRANSIT_KEYGUARD_GOING_AWAY
1812 || mNextAppTransition == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER) {
1813 return STACK_CLIP_BEFORE_ANIM;
1814 }
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001815 return mNextAppTransition == TRANSIT_ACTIVITY_RELAUNCH
Jorim Jaggic69bd222016-03-15 14:38:37 +01001816 || mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
Jorim Jaggi1f458fb2016-03-25 17:36:37 -07001817 || mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001818 ? STACK_CLIP_NONE
1819 : STACK_CLIP_AFTER_ANIM;
1820 }
1821
Jorim Jaggife762342016-10-13 14:33:27 +02001822 public int getTransitFlags() {
1823 return mNextAppTransitionFlags;
1824 }
1825
Craig Mautner164d4bb2012-11-26 13:51:23 -08001826 void postAnimationCallback() {
1827 if (mNextAppTransitionCallback != null) {
lumark23b54592018-10-02 17:17:23 +08001828 mHandler.sendMessage(PooledLambda.obtainMessage(AppTransition::doAnimationCallback,
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001829 mNextAppTransitionCallback));
Craig Mautner164d4bb2012-11-26 13:51:23 -08001830 mNextAppTransitionCallback = null;
1831 }
1832 }
1833
1834 void overridePendingAppTransition(String packageName, int enterAnim, int exitAnim,
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001835 IRemoteCallback startedCallback) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001836 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001837 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001838 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001839 mNextAppTransitionPackage = packageName;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001840 mNextAppTransitionEnter = enterAnim;
1841 mNextAppTransitionExit = exitAnim;
1842 postAnimationCallback();
1843 mNextAppTransitionCallback = startedCallback;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001844 }
1845 }
1846
1847 void overridePendingAppTransitionScaleUp(int startX, int startY, int startWidth,
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001848 int startHeight) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001849 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001850 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001851 mNextAppTransitionType = NEXT_TRANSIT_TYPE_SCALE_UP;
Winson4c3fecd2016-07-13 12:29:48 -07001852 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001853 postAnimationCallback();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001854 }
1855 }
1856
Chet Haase10e23ab2015-02-11 15:08:38 -08001857 void overridePendingAppTransitionClipReveal(int startX, int startY,
1858 int startWidth, int startHeight) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001859 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001860 clear();
Chet Haase10e23ab2015-02-11 15:08:38 -08001861 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CLIP_REVEAL;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001862 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Chet Haase10e23ab2015-02-11 15:08:38 -08001863 postAnimationCallback();
Chet Haase10e23ab2015-02-11 15:08:38 -08001864 }
1865 }
1866
Winson Chungaa7fa012017-05-24 15:50:06 -07001867 void overridePendingAppTransitionThumb(GraphicBuffer srcThumb, int startX, int startY,
Craig Mautner164d4bb2012-11-26 13:51:23 -08001868 IRemoteCallback startedCallback, boolean scaleUp) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001869 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001870 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001871 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP
1872 : NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001873 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001874 putDefaultNextAppTransitionCoordinates(startX, startY, 0, 0, srcThumb);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001875 postAnimationCallback();
1876 mNextAppTransitionCallback = startedCallback;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001877 }
1878 }
1879
Winson Chungaa7fa012017-05-24 15:50:06 -07001880 void overridePendingAppTransitionAspectScaledThumb(GraphicBuffer srcThumb, int startX, int startY,
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001881 int targetWidth, int targetHeight, IRemoteCallback startedCallback, boolean scaleUp) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001882 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001883 clear();
Winson Chunga4ccb862014-08-22 15:26:27 -07001884 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1885 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Winson Chunga4ccb862014-08-22 15:26:27 -07001886 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001887 putDefaultNextAppTransitionCoordinates(startX, startY, targetWidth, targetHeight,
1888 srcThumb);
Winson Chunga4ccb862014-08-22 15:26:27 -07001889 postAnimationCallback();
1890 mNextAppTransitionCallback = startedCallback;
Winson Chunga4ccb862014-08-22 15:26:27 -07001891 }
1892 }
1893
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001894 void overridePendingAppTransitionMultiThumb(AppTransitionAnimationSpec[] specs,
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001895 IRemoteCallback onAnimationStartedCallback, IRemoteCallback onAnimationFinishedCallback,
1896 boolean scaleUp) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001897 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001898 clear();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001899 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1900 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001901 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi43102412015-11-11 16:28:37 +01001902 if (specs != null) {
1903 for (int i = 0; i < specs.length; i++) {
1904 AppTransitionAnimationSpec spec = specs[i];
1905 if (spec != null) {
1906 mNextAppTransitionAnimationsSpecs.put(spec.taskId, spec);
1907 if (i == 0) {
1908 // In full screen mode, the transition code depends on the default spec
1909 // to be set.
1910 Rect rect = spec.rect;
1911 putDefaultNextAppTransitionCoordinates(rect.left, rect.top,
Winson Chungaa7fa012017-05-24 15:50:06 -07001912 rect.width(), rect.height(), spec.buffer);
Jorim Jaggi43102412015-11-11 16:28:37 +01001913 }
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001914 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001915 }
1916 }
1917 postAnimationCallback();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001918 mNextAppTransitionCallback = onAnimationStartedCallback;
1919 mAnimationFinishedCallback = onAnimationFinishedCallback;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001920 }
1921 }
1922
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001923 void overridePendingAppTransitionMultiThumbFuture(
1924 IAppTransitionAnimationSpecsFuture specsFuture, IRemoteCallback callback,
1925 boolean scaleUp) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001926 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001927 clear();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001928 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1929 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001930 mNextAppTransitionAnimationsSpecsFuture = specsFuture;
1931 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001932 mNextAppTransitionFutureCallback = callback;
Riddle Hsuec6467c2019-02-15 00:10:56 +08001933 if (isReady()) {
1934 fetchAppTransitionSpecsFromFuture();
1935 }
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001936 }
1937 }
1938
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001939 void overridePendingAppTransitionRemote(RemoteAnimationAdapter remoteAnimationAdapter) {
Jorim Jaggi346702a2019-05-08 17:49:33 +02001940 if (DEBUG_APP_TRANSITIONS) Slog.i(TAG, "Override pending remote transitionSet="
1941 + isTransitionSet() + " adapter=" + remoteAnimationAdapter);
Winson Chung044d5292014-11-06 11:05:19 -08001942 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001943 clear();
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001944 mNextAppTransitionType = NEXT_TRANSIT_TYPE_REMOTE;
1945 mRemoteAnimationController = new RemoteAnimationController(mService,
lumark23b54592018-10-02 17:17:23 +08001946 remoteAnimationAdapter, mHandler);
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001947 }
1948 }
1949
1950 void overrideInPlaceAppTransition(String packageName, int anim) {
1951 if (canOverridePendingAppTransition()) {
1952 clear();
Winson Chung044d5292014-11-06 11:05:19 -08001953 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE;
1954 mNextAppTransitionPackage = packageName;
1955 mNextAppTransitionInPlace = anim;
Winson Chung044d5292014-11-06 11:05:19 -08001956 }
1957 }
1958
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001959 /**
Tony Mak089c35e2017-12-18 20:34:14 +00001960 * @see {@link #NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS}
1961 */
1962 void overridePendingAppTransitionStartCrossProfileApps() {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001963 if (canOverridePendingAppTransition()) {
Tony Mak089c35e2017-12-18 20:34:14 +00001964 clear();
1965 mNextAppTransitionType = NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS;
1966 postAnimationCallback();
1967 }
1968 }
1969
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001970 private boolean canOverridePendingAppTransition() {
1971 // Remote animations always take precedence
1972 return isTransitionSet() && mNextAppTransitionType != NEXT_TRANSIT_TYPE_REMOTE;
1973 }
1974
Tony Mak089c35e2017-12-18 20:34:14 +00001975 /**
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001976 * If a future is set for the app transition specs, fetch it in another thread.
1977 */
1978 private void fetchAppTransitionSpecsFromFuture() {
1979 if (mNextAppTransitionAnimationsSpecsFuture != null) {
1980 mNextAppTransitionAnimationsSpecsPending = true;
1981 final IAppTransitionAnimationSpecsFuture future
1982 = mNextAppTransitionAnimationsSpecsFuture;
1983 mNextAppTransitionAnimationsSpecsFuture = null;
Jorim Jaggied410b62017-05-05 15:16:14 +02001984 mDefaultExecutor.execute(() -> {
1985 AppTransitionAnimationSpec[] specs = null;
1986 try {
1987 Binder.allowBlocking(future.asBinder());
1988 specs = future.get();
1989 } catch (RemoteException e) {
1990 Slog.w(TAG, "Failed to fetch app transition specs: " + e);
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001991 }
Wale Ogunwaledb485de2018-10-29 09:47:07 -07001992 synchronized (mService.mGlobalLock) {
Jorim Jaggied410b62017-05-05 15:16:14 +02001993 mNextAppTransitionAnimationsSpecsPending = false;
1994 overridePendingAppTransitionMultiThumb(specs,
1995 mNextAppTransitionFutureCallback, null /* finishedCallback */,
1996 mNextAppTransitionScaleUp);
1997 mNextAppTransitionFutureCallback = null;
Jorim Jaggied410b62017-05-05 15:16:14 +02001998 }
1999 mService.requestTraversal();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01002000 });
2001 }
2002 }
2003
Craig Mautner164d4bb2012-11-26 13:51:23 -08002004 @Override
2005 public String toString() {
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07002006 return "mNextAppTransition=" + appTransitionToString(mNextAppTransition);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002007 }
2008
Craig Mautner4b71aa12012-12-27 17:20:01 -08002009 /**
2010 * Returns the human readable name of a window transition.
2011 *
2012 * @param transition The window transition.
2013 * @return The transition symbolic name.
2014 */
2015 public static String appTransitionToString(int transition) {
2016 switch (transition) {
2017 case TRANSIT_UNSET: {
2018 return "TRANSIT_UNSET";
2019 }
2020 case TRANSIT_NONE: {
2021 return "TRANSIT_NONE";
2022 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002023 case TRANSIT_ACTIVITY_OPEN: {
2024 return "TRANSIT_ACTIVITY_OPEN";
2025 }
2026 case TRANSIT_ACTIVITY_CLOSE: {
2027 return "TRANSIT_ACTIVITY_CLOSE";
2028 }
2029 case TRANSIT_TASK_OPEN: {
2030 return "TRANSIT_TASK_OPEN";
2031 }
2032 case TRANSIT_TASK_CLOSE: {
2033 return "TRANSIT_TASK_CLOSE";
2034 }
2035 case TRANSIT_TASK_TO_FRONT: {
2036 return "TRANSIT_TASK_TO_FRONT";
2037 }
2038 case TRANSIT_TASK_TO_BACK: {
2039 return "TRANSIT_TASK_TO_BACK";
2040 }
2041 case TRANSIT_WALLPAPER_CLOSE: {
2042 return "TRANSIT_WALLPAPER_CLOSE";
2043 }
2044 case TRANSIT_WALLPAPER_OPEN: {
2045 return "TRANSIT_WALLPAPER_OPEN";
2046 }
2047 case TRANSIT_WALLPAPER_INTRA_OPEN: {
2048 return "TRANSIT_WALLPAPER_INTRA_OPEN";
2049 }
2050 case TRANSIT_WALLPAPER_INTRA_CLOSE: {
2051 return "TRANSIT_WALLPAPER_INTRA_CLOSE";
2052 }
Craig Mautnerbb742462014-07-07 15:28:55 -07002053 case TRANSIT_TASK_OPEN_BEHIND: {
2054 return "TRANSIT_TASK_OPEN_BEHIND";
2055 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07002056 case TRANSIT_ACTIVITY_RELAUNCH: {
2057 return "TRANSIT_ACTIVITY_RELAUNCH";
2058 }
Jorim Jaggi192086e2016-03-11 17:17:03 +01002059 case TRANSIT_DOCK_TASK_FROM_RECENTS: {
2060 return "TRANSIT_DOCK_TASK_FROM_RECENTS";
2061 }
Jorim Jaggife762342016-10-13 14:33:27 +02002062 case TRANSIT_KEYGUARD_GOING_AWAY: {
2063 return "TRANSIT_KEYGUARD_GOING_AWAY";
2064 }
2065 case TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER: {
2066 return "TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER";
2067 }
2068 case TRANSIT_KEYGUARD_OCCLUDE: {
2069 return "TRANSIT_KEYGUARD_OCCLUDE";
2070 }
2071 case TRANSIT_KEYGUARD_UNOCCLUDE: {
2072 return "TRANSIT_KEYGUARD_UNOCCLUDE";
2073 }
Jorim Jaggi98a9d202018-03-26 16:17:07 +02002074 case TRANSIT_TRANSLUCENT_ACTIVITY_OPEN: {
2075 return "TRANSIT_TRANSLUCENT_ACTIVITY_OPEN";
2076 }
2077 case TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE: {
2078 return "TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE";
2079 }
Jorim Jaggi9c52ebb2018-06-01 14:45:24 +02002080 case TRANSIT_CRASHING_ACTIVITY_CLOSE: {
2081 return "TRANSIT_CRASHING_ACTIVITY_CLOSE";
2082 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002083 default: {
Jorim Jaggi9c52ebb2018-06-01 14:45:24 +02002084 return "<UNKNOWN: " + transition + ">";
Craig Mautner4b71aa12012-12-27 17:20:01 -08002085 }
2086 }
2087 }
2088
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002089 private String appStateToString() {
2090 switch (mAppTransitionState) {
2091 case APP_STATE_IDLE:
2092 return "APP_STATE_IDLE";
2093 case APP_STATE_READY:
2094 return "APP_STATE_READY";
2095 case APP_STATE_RUNNING:
2096 return "APP_STATE_RUNNING";
2097 case APP_STATE_TIMEOUT:
2098 return "APP_STATE_TIMEOUT";
2099 default:
2100 return "unknown state=" + mAppTransitionState;
2101 }
2102 }
2103
2104 private String transitTypeToString() {
2105 switch (mNextAppTransitionType) {
2106 case NEXT_TRANSIT_TYPE_NONE:
2107 return "NEXT_TRANSIT_TYPE_NONE";
2108 case NEXT_TRANSIT_TYPE_CUSTOM:
2109 return "NEXT_TRANSIT_TYPE_CUSTOM";
Winson Chung044d5292014-11-06 11:05:19 -08002110 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
2111 return "NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002112 case NEXT_TRANSIT_TYPE_SCALE_UP:
2113 return "NEXT_TRANSIT_TYPE_SCALE_UP";
2114 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
2115 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP";
2116 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
2117 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN";
Winson Chunga4ccb862014-08-22 15:26:27 -07002118 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
2119 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP";
2120 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN:
2121 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN";
Tony Mak64b8d562017-12-28 17:44:02 +00002122 case NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS:
2123 return "NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002124 default:
2125 return "unknown type=" + mNextAppTransitionType;
2126 }
2127 }
2128
Steven Timotiusaf03df62017-07-18 16:56:43 -07002129 void writeToProto(ProtoOutputStream proto, long fieldId) {
2130 final long token = proto.start(fieldId);
2131 proto.write(APP_TRANSITION_STATE, mAppTransitionState);
2132 proto.write(LAST_USED_APP_TRANSITION, mLastUsedAppTransition);
2133 proto.end(token);
2134 }
2135
Craig Mautner164d4bb2012-11-26 13:51:23 -08002136 @Override
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002137 public void dump(PrintWriter pw, String prefix) {
2138 pw.print(prefix); pw.println(this);
2139 pw.print(prefix); pw.print("mAppTransitionState="); pw.println(appStateToString());
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002140 if (mNextAppTransitionType != NEXT_TRANSIT_TYPE_NONE) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002141 pw.print(prefix); pw.print("mNextAppTransitionType=");
2142 pw.println(transitTypeToString());
Craig Mautner164d4bb2012-11-26 13:51:23 -08002143 }
2144 switch (mNextAppTransitionType) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002145 case NEXT_TRANSIT_TYPE_CUSTOM:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002146 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Craig Mautner164d4bb2012-11-26 13:51:23 -08002147 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002148 pw.print(prefix); pw.print("mNextAppTransitionEnter=0x");
Craig Mautner164d4bb2012-11-26 13:51:23 -08002149 pw.print(Integer.toHexString(mNextAppTransitionEnter));
2150 pw.print(" mNextAppTransitionExit=0x");
2151 pw.println(Integer.toHexString(mNextAppTransitionExit));
2152 break;
Winson Chung044d5292014-11-06 11:05:19 -08002153 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002154 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Winson Chung044d5292014-11-06 11:05:19 -08002155 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002156 pw.print(prefix); pw.print("mNextAppTransitionInPlace=0x");
Winson Chung044d5292014-11-06 11:05:19 -08002157 pw.print(Integer.toHexString(mNextAppTransitionInPlace));
2158 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002159 case NEXT_TRANSIT_TYPE_SCALE_UP: {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002160 getDefaultNextAppTransitionStartRect(mTmpRect);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002161 pw.print(prefix); pw.print("mNextAppTransitionStartX=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002162 pw.print(mTmpRect.left);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002163 pw.print(" mNextAppTransitionStartY=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002164 pw.println(mTmpRect.top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002165 pw.print(prefix); pw.print("mNextAppTransitionStartWidth=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002166 pw.print(mTmpRect.width());
Craig Mautner164d4bb2012-11-26 13:51:23 -08002167 pw.print(" mNextAppTransitionStartHeight=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002168 pw.println(mTmpRect.height());
Craig Mautner164d4bb2012-11-26 13:51:23 -08002169 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002170 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002171 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
2172 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
Winson Chunga4ccb862014-08-22 15:26:27 -07002173 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002174 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN: {
2175 pw.print(prefix); pw.print("mDefaultNextAppTransitionAnimationSpec=");
2176 pw.println(mDefaultNextAppTransitionAnimationSpec);
2177 pw.print(prefix); pw.print("mNextAppTransitionAnimationsSpecs=");
2178 pw.println(mNextAppTransitionAnimationsSpecs);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002179 pw.print(prefix); pw.print("mNextAppTransitionScaleUp=");
2180 pw.println(mNextAppTransitionScaleUp);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002181 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002182 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002183 }
2184 if (mNextAppTransitionCallback != null) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002185 pw.print(prefix); pw.print("mNextAppTransitionCallback=");
2186 pw.println(mNextAppTransitionCallback);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002187 }
Chong Zhang60091a92016-07-27 17:52:45 -07002188 if (mLastUsedAppTransition != TRANSIT_NONE) {
2189 pw.print(prefix); pw.print("mLastUsedAppTransition=");
2190 pw.println(appTransitionToString(mLastUsedAppTransition));
2191 pw.print(prefix); pw.print("mLastOpeningApp=");
2192 pw.println(mLastOpeningApp);
2193 pw.print(prefix); pw.print("mLastClosingApp=");
2194 pw.println(mLastClosingApp);
Evan Rosky2289ba12018-11-19 18:28:18 -08002195 pw.print(prefix); pw.print("mLastChangingApp=");
2196 pw.println(mLastChangingApp);
Chong Zhang60091a92016-07-27 17:52:45 -07002197 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002198 }
Amith Yamasani4befbec2013-07-10 16:18:01 -07002199
2200 public void setCurrentUser(int newUserId) {
2201 mCurrentUserId = newUserId;
2202 }
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002203
2204 /**
2205 * @return true if transition is not running and should not be skipped, false if transition is
2206 * already running
2207 */
Jorim Jaggif84e2f62018-01-16 14:17:59 +01002208 boolean prepareAppTransitionLocked(@TransitionType int transit, boolean alwaysKeepCurrent,
2209 @TransitionFlags int flags, boolean forceOverride) {
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002210 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Prepare app transition:"
2211 + " transit=" + appTransitionToString(transit)
2212 + " " + this
2213 + " alwaysKeepCurrent=" + alwaysKeepCurrent
lumark588a3e82018-07-20 18:53:54 +08002214 + " displayId=" + mDisplayContent.getDisplayId()
2215 + " Callers=" + Debug.getCallers(5));
Jorim Jaggi9c52ebb2018-06-01 14:45:24 +02002216 final boolean allowSetCrashing = !isKeyguardTransit(mNextAppTransition)
2217 && transit == TRANSIT_CRASHING_ACTIVITY_CLOSE;
Jorim Jaggife762342016-10-13 14:33:27 +02002218 if (forceOverride || isKeyguardTransit(transit) || !isTransitionSet()
Jorim Jaggi9c52ebb2018-06-01 14:45:24 +02002219 || mNextAppTransition == TRANSIT_NONE || allowSetCrashing) {
Jorim Jaggife762342016-10-13 14:33:27 +02002220 setAppTransition(transit, flags);
Jorim Jaggia69243a2017-06-15 15:10:38 -04002221 }
2222 // We never want to change from a Keyguard transit to a non-Keyguard transit, as our logic
Adrian Roos93577212018-04-10 14:12:10 -07002223 // relies on the fact that we always execute a Keyguard transition after preparing one. We
2224 // also don't want to change away from a crashing transition.
Jorim Jaggi9c52ebb2018-06-01 14:45:24 +02002225 else if (!alwaysKeepCurrent && !isKeyguardTransit(mNextAppTransition)
2226 && mNextAppTransition != TRANSIT_CRASHING_ACTIVITY_CLOSE) {
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002227 if (transit == TRANSIT_TASK_OPEN && isTransitionEqual(TRANSIT_TASK_CLOSE)) {
2228 // Opening a new task always supersedes a close for the anim.
Jorim Jaggife762342016-10-13 14:33:27 +02002229 setAppTransition(transit, flags);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002230 } else if (transit == TRANSIT_ACTIVITY_OPEN
2231 && isTransitionEqual(TRANSIT_ACTIVITY_CLOSE)) {
2232 // Opening a new activity always supersedes a close for the anim.
Jorim Jaggife762342016-10-13 14:33:27 +02002233 setAppTransition(transit, flags);
Jorim Jaggicecf4242018-02-21 18:46:53 +01002234 } else if (isTaskTransit(transit) && isActivityTransit(mNextAppTransition)) {
2235 // Task animations always supersede activity animations, because if we have both, it
2236 // usually means that activity transition were just trampoline activities.
2237 setAppTransition(transit, flags);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002238 }
2239 }
2240 boolean prepared = prepare();
2241 if (isTransitionSet()) {
lumark23b54592018-10-02 17:17:23 +08002242 removeAppTransitionTimeoutCallbacks();
2243 mHandler.postDelayed(mHandleAppTransitionTimeoutRunnable, APP_TRANSITION_TIMEOUT_MS);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002244 }
2245 return prepared;
2246 }
Winsonb2024762016-04-05 17:32:30 -07002247
2248 /**
Jorim Jaggife762342016-10-13 14:33:27 +02002249 * @return true if {@param transit} is representing a transition in which Keyguard is going
2250 * away, false otherwise
2251 */
2252 public static boolean isKeyguardGoingAwayTransit(int transit) {
2253 return transit == TRANSIT_KEYGUARD_GOING_AWAY
2254 || transit == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER;
2255 }
2256
2257 private static boolean isKeyguardTransit(int transit) {
2258 return isKeyguardGoingAwayTransit(transit) || transit == TRANSIT_KEYGUARD_OCCLUDE
2259 || transit == TRANSIT_KEYGUARD_UNOCCLUDE;
2260 }
2261
Jorim Jaggi98a9d202018-03-26 16:17:07 +02002262 static boolean isTaskTransit(int transit) {
2263 return isTaskOpenTransit(transit)
Jorim Jaggicecf4242018-02-21 18:46:53 +01002264 || transit == TRANSIT_TASK_CLOSE
Jorim Jaggicecf4242018-02-21 18:46:53 +01002265 || transit == TRANSIT_TASK_TO_BACK
Jorim Jaggicecf4242018-02-21 18:46:53 +01002266 || transit == TRANSIT_TASK_IN_PLACE;
2267 }
2268
Jorim Jaggi98a9d202018-03-26 16:17:07 +02002269 private static boolean isTaskOpenTransit(int transit) {
2270 return transit == TRANSIT_TASK_OPEN
2271 || transit == TRANSIT_TASK_OPEN_BEHIND
2272 || transit == TRANSIT_TASK_TO_FRONT;
2273 }
2274
2275 static boolean isActivityTransit(int transit) {
Jorim Jaggicecf4242018-02-21 18:46:53 +01002276 return transit == TRANSIT_ACTIVITY_OPEN
2277 || transit == TRANSIT_ACTIVITY_CLOSE
2278 || transit == TRANSIT_ACTIVITY_RELAUNCH;
2279 }
2280
Evan Roskyec9488c2019-03-01 19:32:12 -08002281 static boolean isChangeTransit(int transit) {
2282 return transit == TRANSIT_TASK_CHANGE_WINDOWING_MODE;
2283 }
2284
Jorim Jaggife762342016-10-13 14:33:27 +02002285 /**
Manu Cornetd7376802017-01-13 13:44:07 -08002286 * @return whether the transition should show the thumbnail being scaled down.
2287 */
2288 private boolean shouldScaleDownThumbnailTransition(int uiMode, int orientation) {
Sid Soundararajan0e88d322017-03-07 15:37:30 -08002289 return mGridLayoutRecentsEnabled
Manu Cornetd7376802017-01-13 13:44:07 -08002290 || orientation == Configuration.ORIENTATION_PORTRAIT;
2291 }
lumark23b54592018-10-02 17:17:23 +08002292
2293 private void handleAppTransitionTimeout() {
Wale Ogunwaledb485de2018-10-29 09:47:07 -07002294 synchronized (mService.mGlobalLock) {
lumark588a3e82018-07-20 18:53:54 +08002295 final DisplayContent dc = mDisplayContent;
2296 if (dc == null) {
2297 return;
2298 }
Evan Rosky2289ba12018-11-19 18:28:18 -08002299 if (isTransitionSet() || !dc.mOpeningApps.isEmpty() || !dc.mClosingApps.isEmpty()
2300 || !dc.mChangingApps.isEmpty()) {
lumark23b54592018-10-02 17:17:23 +08002301 if (DEBUG_APP_TRANSITIONS) {
2302 Slog.v(TAG_WM, "*** APP TRANSITION TIMEOUT."
lumark588a3e82018-07-20 18:53:54 +08002303 + " displayId=" + dc.getDisplayId()
lumark23b54592018-10-02 17:17:23 +08002304 + " isTransitionSet()="
lumark588a3e82018-07-20 18:53:54 +08002305 + dc.mAppTransition.isTransitionSet()
2306 + " mOpeningApps.size()=" + dc.mOpeningApps.size()
Evan Rosky2289ba12018-11-19 18:28:18 -08002307 + " mClosingApps.size()=" + dc.mClosingApps.size()
2308 + " mChangingApps.size()=" + dc.mChangingApps.size());
lumark23b54592018-10-02 17:17:23 +08002309 }
2310 setTimeout();
2311 mService.mWindowPlacerLocked.performSurfacePlacement();
2312 }
2313 }
2314 }
2315
2316 private static void doAnimationCallback(@NonNull IRemoteCallback callback) {
2317 try {
2318 ((IRemoteCallback) callback).sendResult(null);
2319 } catch (RemoteException e) {
2320 }
2321 }
2322
2323 void removeAppTransitionTimeoutCallbacks() {
2324 mHandler.removeCallbacks(mHandleAppTransitionTimeoutRunnable);
2325 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002326}