blob: 557a609dbc7b0ccad8929feb5dec207fbc326542 [file] [log] [blame]
Craig Mautner164d4bb2012-11-26 13:51:23 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server.wm;
18
Jorim Jaggif84e2f62018-01-16 14:17:59 +010019import static android.view.WindowManager.LayoutParams;
20import static android.view.WindowManager.TRANSIT_ACTIVITY_CLOSE;
21import static android.view.WindowManager.TRANSIT_ACTIVITY_OPEN;
22import static android.view.WindowManager.TRANSIT_ACTIVITY_RELAUNCH;
Adrian Roos93577212018-04-10 14:12:10 -070023import static android.view.WindowManager.TRANSIT_CRASHING_ACTIVITY_CLOSE;
Jorim Jaggif84e2f62018-01-16 14:17:59 +010024import static android.view.WindowManager.TRANSIT_DOCK_TASK_FROM_RECENTS;
25import static android.view.WindowManager.TRANSIT_FLAG_KEYGUARD_GOING_AWAY_NO_ANIMATION;
Issei Suzuki5609ccb2019-06-13 15:04:08 +020026import static android.view.WindowManager.TRANSIT_FLAG_KEYGUARD_GOING_AWAY_SUBTLE_ANIMATION;
Jorim Jaggif84e2f62018-01-16 14:17:59 +010027import static android.view.WindowManager.TRANSIT_FLAG_KEYGUARD_GOING_AWAY_TO_SHADE;
28import static android.view.WindowManager.TRANSIT_KEYGUARD_GOING_AWAY;
29import static android.view.WindowManager.TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER;
30import static android.view.WindowManager.TRANSIT_KEYGUARD_OCCLUDE;
31import static android.view.WindowManager.TRANSIT_KEYGUARD_UNOCCLUDE;
32import static android.view.WindowManager.TRANSIT_NONE;
Issei Suzukicac2a502019-04-16 16:52:50 +020033import static android.view.WindowManager.TRANSIT_SHOW_SINGLE_TASK_DISPLAY;
Evan Roskycf76bed2019-01-15 10:33:58 -080034import static android.view.WindowManager.TRANSIT_TASK_CHANGE_WINDOWING_MODE;
Jorim Jaggif84e2f62018-01-16 14:17:59 +010035import static android.view.WindowManager.TRANSIT_TASK_CLOSE;
Jorim Jaggicecf4242018-02-21 18:46:53 +010036import static android.view.WindowManager.TRANSIT_TASK_IN_PLACE;
Jorim Jaggif84e2f62018-01-16 14:17:59 +010037import static android.view.WindowManager.TRANSIT_TASK_OPEN;
38import static android.view.WindowManager.TRANSIT_TASK_OPEN_BEHIND;
39import static android.view.WindowManager.TRANSIT_TASK_TO_BACK;
40import static android.view.WindowManager.TRANSIT_TASK_TO_FRONT;
Jorim Jaggi98a9d202018-03-26 16:17:07 +020041import static android.view.WindowManager.TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE;
42import static android.view.WindowManager.TRANSIT_TRANSLUCENT_ACTIVITY_OPEN;
Jorim Jaggif84e2f62018-01-16 14:17:59 +010043import static android.view.WindowManager.TRANSIT_UNSET;
44import static android.view.WindowManager.TRANSIT_WALLPAPER_CLOSE;
45import static android.view.WindowManager.TRANSIT_WALLPAPER_INTRA_CLOSE;
46import static android.view.WindowManager.TRANSIT_WALLPAPER_INTRA_OPEN;
47import static android.view.WindowManager.TRANSIT_WALLPAPER_OPEN;
Tony Mak83546a82018-01-22 13:56:20 +000048
Filip Gruszczynski82861362015-10-16 14:21:09 -070049import static com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation;
50import static com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
51import static com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation;
52import static com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
53import static com.android.internal.R.styleable.WindowAnimation_launchTaskBehindSourceAnimation;
54import static com.android.internal.R.styleable.WindowAnimation_launchTaskBehindTargetAnimation;
55import static com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation;
56import static com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
57import static com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation;
58import static com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
59import static com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation;
60import static com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
61import static com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation;
62import static com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
63import static com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation;
64import static com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
65import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation;
66import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
67import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation;
68import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
69import static com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation;
70import static com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Aurimas Liutikasd8ebfef2019-01-16 12:46:42 -080071import static com.android.server.wm.AppTransitionProto.APP_TRANSITION_STATE;
72import static com.android.server.wm.AppTransitionProto.LAST_USED_APP_TRANSITION;
Filip Gruszczynski198dcbf2016-01-18 10:02:00 -080073import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
74import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080075import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
76import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Adrian Roose99bc052017-11-20 17:55:31 +010077import static com.android.server.wm.WindowManagerInternal.AppTransitionListener;
Tony Mak089c35e2017-12-18 20:34:14 +000078import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_AFTER_ANIM;
Matthew Ngbf1d9852017-03-14 12:23:09 -070079import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_BEFORE_ANIM;
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +010080import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_NONE;
Filip Gruszczynski82861362015-10-16 14:21:09 -070081
Tony Mak64b8d562017-12-28 17:44:02 +000082import android.annotation.DrawableRes;
lumark23b54592018-10-02 17:17:23 +080083import android.annotation.NonNull;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -070084import android.annotation.Nullable;
Matthew Ng43db6d22017-06-27 15:29:39 -070085import android.app.ActivityManager;
Tony Mak089c35e2017-12-18 20:34:14 +000086import android.content.ComponentName;
Craig Mautner164d4bb2012-11-26 13:51:23 -080087import android.content.Context;
Winson21700932016-03-24 17:26:23 -070088import android.content.res.Configuration;
Todd Kennedy64c57a82018-04-19 15:17:24 -070089import android.content.res.ResourceId;
Aurimas Liutikasd8ebfef2019-01-16 12:46:42 -080090import android.content.res.Resources;
Jorim Jaggib142f572019-03-01 16:08:54 +010091import android.content.res.Resources.NotFoundException;
lumarkce596d32019-06-12 16:58:35 +080092import android.content.res.TypedArray;
John Reck519ad482018-02-12 17:08:48 -080093import android.graphics.Bitmap;
94import android.graphics.Canvas;
Tony Mak64b8d562017-12-28 17:44:02 +000095import android.graphics.Color;
Winson Chungaa7fa012017-05-24 15:50:06 -070096import android.graphics.GraphicBuffer;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +010097import android.graphics.Path;
John Reck519ad482018-02-12 17:08:48 -080098import android.graphics.Picture;
Winson Chung399f6202014-03-19 10:47:20 -070099import android.graphics.Rect;
Tony Mak64b8d562017-12-28 17:44:02 +0000100import android.graphics.drawable.Drawable;
Jorim Jaggied410b62017-05-05 15:16:14 +0200101import android.os.Binder;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800102import android.os.Debug;
lumark23b54592018-10-02 17:17:23 +0800103import android.os.Handler;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100104import android.os.IBinder;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800105import android.os.IRemoteCallback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100106import android.os.RemoteException;
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200107import android.os.SystemClock;
Manu Cornetd7376802017-01-13 13:44:07 -0800108import android.os.SystemProperties;
Tony Mak089c35e2017-12-18 20:34:14 +0000109import android.os.UserHandle;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800110import android.util.ArraySet;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800111import android.util.Slog;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700112import android.util.SparseArray;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700113import android.util.proto.ProtoOutputStream;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700114import android.view.AppTransitionAnimationSpec;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100115import android.view.IAppTransitionAnimationSpecsFuture;
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100116import android.view.RemoteAnimationAdapter;
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100117import android.view.WindowManager.TransitionFlags;
118import android.view.WindowManager.TransitionType;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800119import android.view.animation.AlphaAnimation;
120import android.view.animation.Animation;
121import android.view.animation.AnimationSet;
122import android.view.animation.AnimationUtils;
Winson Chung399f6202014-03-19 10:47:20 -0700123import android.view.animation.ClipRectAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800124import android.view.animation.Interpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700125import android.view.animation.PathInterpolator;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800126import android.view.animation.ScaleAnimation;
Winson Chung399f6202014-03-19 10:47:20 -0700127import android.view.animation.TranslateAnimation;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700128
Jorim Jaggi98a9d202018-03-26 16:17:07 +0200129import com.android.internal.R;
Jorim Jaggib142f572019-03-01 16:08:54 +0100130import com.android.internal.annotations.VisibleForTesting;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800131import com.android.internal.util.DumpUtils.Dump;
lumark23b54592018-10-02 17:17:23 +0800132import com.android.internal.util.function.pooled.PooledLambda;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800133import com.android.server.AttributeCache;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800134import com.android.server.wm.animation.ClipRectLRAnimation;
135import com.android.server.wm.animation.ClipRectTBAnimation;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100136import com.android.server.wm.animation.CurvedTranslateAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800137
138import java.io.PrintWriter;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100139import java.util.ArrayList;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100140import java.util.concurrent.ExecutorService;
141import java.util.concurrent.Executors;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800142
Craig Mautner164d4bb2012-11-26 13:51:23 -0800143// State management of app transitions. When we are preparing for a
144// transition, mNextAppTransition will be the kind of transition to
145// perform or TRANSIT_NONE if we are not waiting. If we are waiting,
146// mOpeningApps and mClosingApps are the lists of tokens that will be
147// made visible or hidden at the next transition.
148public class AppTransition implements Dump {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800149 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppTransition" : TAG_WM;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700150 private static final int CLIP_REVEAL_TRANSLATION_Y_DP = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800151
Winson Chunga4ccb862014-08-22 15:26:27 -0700152 /** Fraction of animation at which the recents thumbnail stays completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700153 private static final float RECENTS_THUMBNAIL_FADEIN_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800154 /** Fraction of animation at which the recents thumbnail becomes completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700155 private static final float RECENTS_THUMBNAIL_FADEOUT_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800156
Filip Gruszczynski84fa3352016-01-25 16:28:49 -0800157 static final int DEFAULT_APP_TRANSITION_DURATION = 336;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800158
159 /** Interpolator to be used for animations that respond directly to a touch */
160 static final Interpolator TOUCH_RESPONSE_INTERPOLATOR =
161 new PathInterpolator(0.3f, 0f, 0.1f, 1f);
162
Jorim Jaggic69bd222016-03-15 14:38:37 +0100163 private static final Interpolator THUMBNAIL_DOCK_INTERPOLATOR =
164 new PathInterpolator(0.85f, 0f, 1f, 1f);
165
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800166 /**
167 * Maximum duration for the clip reveal animation. This is used when there is a lot of movement
168 * involved, to make it more understandable.
169 */
170 private static final int MAX_CLIP_REVEAL_TRANSITION_DURATION = 420;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700171 private static final int THUMBNAIL_APP_TRANSITION_DURATION = 336;
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700172 private static final long APP_TRANSITION_TIMEOUT_MS = 5000;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800173
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800174 private final Context mContext;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800175 private final WindowManagerService mService;
lumark588a3e82018-07-20 18:53:54 +0800176 private final DisplayContent mDisplayContent;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800177
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100178 private @TransitionType int mNextAppTransition = TRANSIT_UNSET;
179 private @TransitionFlags int mNextAppTransitionFlags = 0;
Chong Zhang60091a92016-07-27 17:52:45 -0700180 private int mLastUsedAppTransition = TRANSIT_UNSET;
181 private String mLastOpeningApp;
182 private String mLastClosingApp;
Evan Rosky2289ba12018-11-19 18:28:18 -0800183 private String mLastChangingApp;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800184
185 private static final int NEXT_TRANSIT_TYPE_NONE = 0;
186 private static final int NEXT_TRANSIT_TYPE_CUSTOM = 1;
187 private static final int NEXT_TRANSIT_TYPE_SCALE_UP = 2;
188 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP = 3;
189 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN = 4;
Winson Chunga4ccb862014-08-22 15:26:27 -0700190 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP = 5;
191 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN = 6;
Winson Chung044d5292014-11-06 11:05:19 -0800192 private static final int NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE = 7;
Chet Haase10e23ab2015-02-11 15:08:38 -0800193 private static final int NEXT_TRANSIT_TYPE_CLIP_REVEAL = 8;
Tony Mak089c35e2017-12-18 20:34:14 +0000194
195 /**
196 * Refers to the transition to activity started by using {@link
197 * android.content.pm.crossprofile.CrossProfileApps#startMainActivity(ComponentName, UserHandle)
198 * }.
199 */
200 private static final int NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS = 9;
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100201 private static final int NEXT_TRANSIT_TYPE_REMOTE = 10;
202
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800203 private int mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
204
Winson Chung399f6202014-03-19 10:47:20 -0700205 // These are the possible states for the enter/exit activities during a thumbnail transition
206 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_UP = 0;
207 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_UP = 1;
208 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN = 2;
209 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN = 3;
210
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800211 private String mNextAppTransitionPackage;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800212 // Used for thumbnail transitions. True if we're scaling up, false if scaling down
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800213 private boolean mNextAppTransitionScaleUp;
214 private IRemoteCallback mNextAppTransitionCallback;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +0100215 private IRemoteCallback mNextAppTransitionFutureCallback;
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -0700216 private IRemoteCallback mAnimationFinishedCallback;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800217 private int mNextAppTransitionEnter;
218 private int mNextAppTransitionExit;
Winson Chung044d5292014-11-06 11:05:19 -0800219 private int mNextAppTransitionInPlace;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700220
221 // Keyed by task id.
222 private final SparseArray<AppTransitionAnimationSpec> mNextAppTransitionAnimationsSpecs
223 = new SparseArray<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100224 private IAppTransitionAnimationSpecsFuture mNextAppTransitionAnimationsSpecsFuture;
225 private boolean mNextAppTransitionAnimationsSpecsPending;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700226 private AppTransitionAnimationSpec mDefaultNextAppTransitionAnimationSpec;
227
Winson Chunga4ccb862014-08-22 15:26:27 -0700228 private Rect mNextAppTransitionInsets = new Rect();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800229
Winson Chung2820c452014-04-15 15:34:44 -0700230 private Rect mTmpFromClipRect = new Rect();
231 private Rect mTmpToClipRect = new Rect();
232
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700233 private final Rect mTmpRect = new Rect();
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700234
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800235 private final static int APP_STATE_IDLE = 0;
236 private final static int APP_STATE_READY = 1;
237 private final static int APP_STATE_RUNNING = 2;
238 private final static int APP_STATE_TIMEOUT = 3;
239 private int mAppTransitionState = APP_STATE_IDLE;
240
241 private final int mConfigShortAnimTime;
Craig Mautner321bdf52012-12-18 09:53:24 -0800242 private final Interpolator mDecelerateInterpolator;
Winson Chunga4ccb862014-08-22 15:26:27 -0700243 private final Interpolator mThumbnailFadeInInterpolator;
244 private final Interpolator mThumbnailFadeOutInterpolator;
Chet Haase10e23ab2015-02-11 15:08:38 -0800245 private final Interpolator mLinearOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700246 private final Interpolator mFastOutLinearInInterpolator;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100247 private final Interpolator mFastOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700248 private final Interpolator mClipHorizontalInterpolator = new PathInterpolator(0, 0, 0.4f, 1f);
249
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700250 private final int mClipRevealTranslationY;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800251
Amith Yamasani4befbec2013-07-10 16:18:01 -0700252 private int mCurrentUserId = 0;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800253 private long mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Amith Yamasani4befbec2013-07-10 16:18:01 -0700254
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100255 private final ArrayList<AppTransitionListener> mListeners = new ArrayList<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100256 private final ExecutorService mDefaultExecutor = Executors.newSingleThreadExecutor();
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100257
Jorim Jaggif97ed922016-02-18 18:57:07 -0800258 private int mLastClipRevealMaxTranslation;
259 private boolean mLastHadClipReveal;
260
Manu Cornetd7376802017-01-13 13:44:07 -0800261 private final boolean mGridLayoutRecentsEnabled;
Matthew Ng43db6d22017-06-27 15:29:39 -0700262 private final boolean mLowRamRecentsEnabled;
Manu Cornetd7376802017-01-13 13:44:07 -0800263
lumarkce596d32019-06-12 16:58:35 +0800264 private final int mDefaultWindowAnimationStyleResId;
265
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100266 private RemoteAnimationController mRemoteAnimationController;
267
lumark23b54592018-10-02 17:17:23 +0800268 final Handler mHandler;
269 final Runnable mHandleAppTransitionTimeoutRunnable = () -> handleAppTransitionTimeout();
270
lumark588a3e82018-07-20 18:53:54 +0800271 AppTransition(Context context, WindowManagerService service, DisplayContent displayContent) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800272 mContext = context;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800273 mService = service;
lumark23b54592018-10-02 17:17:23 +0800274 mHandler = new Handler(service.mH.getLooper());
lumark588a3e82018-07-20 18:53:54 +0800275 mDisplayContent = displayContent;
Chet Haase10e23ab2015-02-11 15:08:38 -0800276 mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
277 com.android.internal.R.interpolator.linear_out_slow_in);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700278 mFastOutLinearInInterpolator = AnimationUtils.loadInterpolator(context,
279 com.android.internal.R.interpolator.fast_out_linear_in);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100280 mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
281 com.android.internal.R.interpolator.fast_out_slow_in);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800282 mConfigShortAnimTime = context.getResources().getInteger(
283 com.android.internal.R.integer.config_shortAnimTime);
Craig Mautner321bdf52012-12-18 09:53:24 -0800284 mDecelerateInterpolator = AnimationUtils.loadInterpolator(context,
285 com.android.internal.R.interpolator.decelerate_cubic);
Winson Chunga4ccb862014-08-22 15:26:27 -0700286 mThumbnailFadeInInterpolator = new Interpolator() {
287 @Override
288 public float getInterpolation(float input) {
289 // Linear response for first fraction, then complete after that.
290 if (input < RECENTS_THUMBNAIL_FADEIN_FRACTION) {
291 return 0f;
292 }
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700293 float t = (input - RECENTS_THUMBNAIL_FADEIN_FRACTION) /
Winson Chunga4ccb862014-08-22 15:26:27 -0700294 (1f - RECENTS_THUMBNAIL_FADEIN_FRACTION);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700295 return mFastOutLinearInInterpolator.getInterpolation(t);
Winson Chunga4ccb862014-08-22 15:26:27 -0700296 }
297 };
298 mThumbnailFadeOutInterpolator = new Interpolator() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800299 @Override
300 public float getInterpolation(float input) {
301 // Linear response for first fraction, then complete after that.
302 if (input < RECENTS_THUMBNAIL_FADEOUT_FRACTION) {
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700303 float t = input / RECENTS_THUMBNAIL_FADEOUT_FRACTION;
304 return mLinearOutSlowInInterpolator.getInterpolation(t);
Craig Mautner321bdf52012-12-18 09:53:24 -0800305 }
Winson Chunga4ccb862014-08-22 15:26:27 -0700306 return 1f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800307 }
308 };
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700309 mClipRevealTranslationY = (int) (CLIP_REVEAL_TRANSLATION_Y_DP
310 * mContext.getResources().getDisplayMetrics().density);
Manu Cornetd7376802017-01-13 13:44:07 -0800311 mGridLayoutRecentsEnabled = SystemProperties.getBoolean("ro.recents.grid", false);
Matthew Ng43db6d22017-06-27 15:29:39 -0700312 mLowRamRecentsEnabled = ActivityManager.isLowRamDeviceStatic();
lumarkce596d32019-06-12 16:58:35 +0800313
314 final TypedArray windowStyle = mContext.getTheme().obtainStyledAttributes(
315 com.android.internal.R.styleable.Window);
316 mDefaultWindowAnimationStyleResId = windowStyle.getResourceId(
317 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
318 windowStyle.recycle();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800319 }
320
321 boolean isTransitionSet() {
322 return mNextAppTransition != TRANSIT_UNSET;
323 }
324
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100325 boolean isTransitionEqual(@TransitionType int transit) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800326 return mNextAppTransition == transit;
327 }
328
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100329 @TransitionType int getAppTransition() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800330 return mNextAppTransition;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800331 }
332
Jorim Jaggife762342016-10-13 14:33:27 +0200333 private void setAppTransition(int transit, int flags) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800334 mNextAppTransition = transit;
Jorim Jaggife762342016-10-13 14:33:27 +0200335 mNextAppTransitionFlags |= flags;
Evan Rosky2289ba12018-11-19 18:28:18 -0800336 setLastAppTransition(TRANSIT_UNSET, null, null, null);
Jorim Jaggi245281c2017-06-07 14:33:04 -0700337 updateBooster();
Chong Zhang60091a92016-07-27 17:52:45 -0700338 }
339
Evan Rosky2289ba12018-11-19 18:28:18 -0800340 void setLastAppTransition(int transit, AppWindowToken openingApp, AppWindowToken closingApp,
341 AppWindowToken changingApp) {
Chong Zhang60091a92016-07-27 17:52:45 -0700342 mLastUsedAppTransition = transit;
343 mLastOpeningApp = "" + openingApp;
344 mLastClosingApp = "" + closingApp;
Evan Rosky2289ba12018-11-19 18:28:18 -0800345 mLastChangingApp = "" + changingApp;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800346 }
347
348 boolean isReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800349 return mAppTransitionState == APP_STATE_READY
350 || mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800351 }
352
Craig Mautnerae446592012-12-06 19:05:05 -0800353 void setReady() {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700354 setAppTransitionState(APP_STATE_READY);
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100355 fetchAppTransitionSpecsFromFuture();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800356 }
357
358 boolean isRunning() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800359 return mAppTransitionState == APP_STATE_RUNNING;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800360 }
361
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800362 void setIdle() {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700363 setAppTransitionState(APP_STATE_IDLE);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800364 }
365
366 boolean isTimeout() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800367 return mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800368 }
369
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800370 void setTimeout() {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700371 setAppTransitionState(APP_STATE_TIMEOUT);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800372 }
373
Winson Chungaa7fa012017-05-24 15:50:06 -0700374 GraphicBuffer getAppTransitionThumbnailHeader(int taskId) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700375 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800376 if (spec == null) {
377 spec = mDefaultNextAppTransitionAnimationSpec;
378 }
Winson Chungaa7fa012017-05-24 15:50:06 -0700379 return spec != null ? spec.buffer : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800380 }
381
Winson Chunga4ccb862014-08-22 15:26:27 -0700382 /** Returns whether the next thumbnail transition is aspect scaled up. */
383 boolean isNextThumbnailTransitionAspectScaled() {
384 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
385 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
386 }
387
388 /** Returns whether the next thumbnail transition is scaling up. */
389 boolean isNextThumbnailTransitionScaleUp() {
390 return mNextAppTransitionScaleUp;
391 }
392
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -0800393 boolean isNextAppTransitionThumbnailUp() {
394 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
395 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP;
396 }
397
398 boolean isNextAppTransitionThumbnailDown() {
399 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN ||
400 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
401 }
402
Tony Mak64b8d562017-12-28 17:44:02 +0000403
404 boolean isNextAppTransitionOpenCrossProfileApps() {
405 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS;
406 }
407
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100408 /**
409 * @return true if and only if we are currently fetching app transition specs from the future
410 * passed into {@link #overridePendingAppTransitionMultiThumbFuture}
411 */
412 boolean isFetchingAppTransitionsSpecs() {
413 return mNextAppTransitionAnimationsSpecsPending;
414 }
415
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700416 private boolean prepare() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800417 if (!isRunning()) {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700418 setAppTransitionState(APP_STATE_IDLE);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100419 notifyAppTransitionPendingLocked();
Jorim Jaggif97ed922016-02-18 18:57:07 -0800420 mLastHadClipReveal = false;
421 mLastClipRevealMaxTranslation = 0;
422 mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700423 return true;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800424 }
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700425 return false;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800426 }
427
Jorim Jaggife762342016-10-13 14:33:27 +0200428 /**
429 * @return bit-map of WindowManagerPolicy#FINISH_LAYOUT_REDO_* to indicate whether another
430 * layout pass needs to be done
431 */
Evan Rosky2289ba12018-11-19 18:28:18 -0800432 int goodToGo(int transit, AppWindowToken topOpeningApp, ArraySet<AppWindowToken> openingApps) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800433 mNextAppTransition = TRANSIT_UNSET;
Jorim Jaggife762342016-10-13 14:33:27 +0200434 mNextAppTransitionFlags = 0;
Jorim Jaggi245281c2017-06-07 14:33:04 -0700435 setAppTransitionState(APP_STATE_RUNNING);
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200436 final AnimationAdapter topOpeningAnim = topOpeningApp != null
437 ? topOpeningApp.getAnimation()
438 : null;
Jorim Jaggife762342016-10-13 14:33:27 +0200439 int redoLayout = notifyAppTransitionStartingLocked(transit,
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200440 topOpeningAnim != null ? topOpeningAnim.getDurationHint() : 0,
441 topOpeningAnim != null
442 ? topOpeningAnim.getStatusBarTransitionsStartTime()
443 : SystemClock.uptimeMillis(),
444 AnimationAdapter.STATUS_BAR_TRANSITION_DURATION);
lumark588a3e82018-07-20 18:53:54 +0800445 mDisplayContent.getDockedDividerController()
Jorim Jaggife762342016-10-13 14:33:27 +0200446 .notifyAppTransitionStarting(openingApps, transit);
Jorim Jaggi363ab982016-04-26 19:51:20 -0700447
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100448 if (mRemoteAnimationController != null) {
449 mRemoteAnimationController.goodToGo();
450 }
Jorim Jaggife762342016-10-13 14:33:27 +0200451 return redoLayout;
Jorim Jaggi363ab982016-04-26 19:51:20 -0700452 }
453
Craig Mautner164d4bb2012-11-26 13:51:23 -0800454 void clear() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800455 mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800456 mNextAppTransitionPackage = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700457 mNextAppTransitionAnimationsSpecs.clear();
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100458 mRemoteAnimationController = null;
Jorim Jaggi65193992015-11-23 16:49:59 -0800459 mNextAppTransitionAnimationsSpecsFuture = null;
460 mDefaultNextAppTransitionAnimationSpec = null;
461 mAnimationFinishedCallback = null;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800462 }
463
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800464 void freeze() {
Jorim Jaggife762342016-10-13 14:33:27 +0200465 final int transit = mNextAppTransition;
Arthur Hung442aff22019-05-07 19:49:31 +0800466 // The RemoteAnimationControl didn't register AppTransitionListener and
467 // only initialized the finish and timeout callback when goodToGo().
468 // So cancel the remote animation here to prevent the animation can't do
469 // finish after transition state cleared.
470 if (mRemoteAnimationController != null) {
471 mRemoteAnimationController.cancelAnimation("freeze");
472 }
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100473 setAppTransition(TRANSIT_UNSET, 0 /* flags */);
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800474 clear();
475 setReady();
Jorim Jaggife762342016-10-13 14:33:27 +0200476 notifyAppTransitionCancelledLocked(transit);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100477 }
478
Jorim Jaggi245281c2017-06-07 14:33:04 -0700479 private void setAppTransitionState(int state) {
480 mAppTransitionState = state;
481 updateBooster();
482 }
483
484 /**
485 * Updates whether we currently boost wm locked sections and the animation thread. We want to
486 * boost the priorities to a more important value whenever an app transition is going to happen
487 * soon or an app transition is running.
488 */
Jorim Jaggic8cc2292018-03-15 20:16:15 +0100489 void updateBooster() {
490 WindowManagerService.sThreadPriorityBooster.setAppTransitionRunning(needsBoosting());
491 }
492
493 private boolean needsBoosting() {
494 final boolean recentsAnimRunning = mService.getRecentsAnimationController() != null;
495 return mNextAppTransition != TRANSIT_UNSET
496 || mAppTransitionState == APP_STATE_READY
497 || mAppTransitionState == APP_STATE_RUNNING
498 || recentsAnimRunning;
Jorim Jaggi245281c2017-06-07 14:33:04 -0700499 }
500
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100501 void registerListenerLocked(AppTransitionListener listener) {
502 mListeners.add(listener);
503 }
504
lumark54284462019-03-05 20:44:27 +0800505 void unregisterListener(AppTransitionListener listener) {
506 mListeners.remove(listener);
507 }
508
Wale Ogunwalea48eadb2015-05-14 17:43:12 -0700509 public void notifyAppTransitionFinishedLocked(IBinder token) {
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100510 for (int i = 0; i < mListeners.size(); i++) {
511 mListeners.get(i).onAppTransitionFinishedLocked(token);
512 }
513 }
514
515 private void notifyAppTransitionPendingLocked() {
516 for (int i = 0; i < mListeners.size(); i++) {
517 mListeners.get(i).onAppTransitionPendingLocked();
518 }
519 }
520
Jorim Jaggife762342016-10-13 14:33:27 +0200521 private void notifyAppTransitionCancelledLocked(int transit) {
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100522 for (int i = 0; i < mListeners.size(); i++) {
Jorim Jaggife762342016-10-13 14:33:27 +0200523 mListeners.get(i).onAppTransitionCancelledLocked(transit);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100524 }
525 }
526
Evan Rosky2289ba12018-11-19 18:28:18 -0800527 private int notifyAppTransitionStartingLocked(int transit, long duration,
528 long statusBarAnimationStartTime, long statusBarAnimationDuration) {
Jorim Jaggife762342016-10-13 14:33:27 +0200529 int redoLayout = 0;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100530 for (int i = 0; i < mListeners.size(); i++) {
Evan Rosky2289ba12018-11-19 18:28:18 -0800531 redoLayout |= mListeners.get(i).onAppTransitionStartingLocked(transit, duration,
532 statusBarAnimationStartTime, statusBarAnimationDuration);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100533 }
Jorim Jaggife762342016-10-13 14:33:27 +0200534 return redoLayout;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800535 }
536
lumarkce596d32019-06-12 16:58:35 +0800537 @VisibleForTesting
538 int getDefaultWindowAnimationStyleResId() {
539 return mDefaultWindowAnimationStyleResId;
540 }
541
542 /** Returns window animation style ID from {@link LayoutParams} or from system in some cases */
543 @VisibleForTesting
544 int getAnimationStyleResId(@NonNull LayoutParams lp) {
545 int resId = lp.windowAnimations;
546 if (lp.type == LayoutParams.TYPE_APPLICATION_STARTING) {
547 // Note that we don't want application to customize starting window animation.
548 // Since this window is specific for displaying while app starting,
549 // application should not change its animation directly.
550 // In this case, it will use system resource to get default animation.
551 resId = mDefaultWindowAnimationStyleResId;
552 }
553 return resId;
554 }
555
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100556 private AttributeCache.Entry getCachedAnimations(LayoutParams lp) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800557 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg="
558 + (lp != null ? lp.packageName : null)
559 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
560 if (lp != null && lp.windowAnimations != 0) {
561 // If this is a system resource, don't try to load it from the
562 // application resources. It is nice to avoid loading application
563 // resources if we can.
564 String packageName = lp.packageName != null ? lp.packageName : "android";
lumarkce596d32019-06-12 16:58:35 +0800565 int resId = getAnimationStyleResId(lp);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800566 if ((resId&0xFF000000) == 0x01000000) {
567 packageName = "android";
568 }
569 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
570 + packageName);
571 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700572 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800573 }
574 return null;
575 }
576
577 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
578 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package="
579 + packageName + " resId=0x" + Integer.toHexString(resId));
580 if (packageName != null) {
581 if ((resId&0xFF000000) == 0x01000000) {
582 packageName = "android";
583 }
584 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
585 + packageName);
586 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700587 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800588 }
589 return null;
590 }
591
Jorim Jaggi0a1523d2018-04-19 17:48:38 +0200592 Animation loadAnimationAttr(LayoutParams lp, int animAttr, int transit) {
Aurimas Liutikasd8ebfef2019-01-16 12:46:42 -0800593 int resId = Resources.ID_NULL;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800594 Context context = mContext;
Jorim Jaggi5f95b002018-04-19 13:27:52 +0000595 if (animAttr >= 0) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800596 AttributeCache.Entry ent = getCachedAnimations(lp);
597 if (ent != null) {
598 context = ent.context;
Todd Kennedy64c57a82018-04-19 15:17:24 -0700599 resId = ent.array.getResourceId(animAttr, 0);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800600 }
601 }
Todd Kennedy64c57a82018-04-19 15:17:24 -0700602 resId = updateToTranslucentAnimIfNeeded(resId, transit);
603 if (ResourceId.isValid(resId)) {
Jorim Jaggib142f572019-03-01 16:08:54 +0100604 return loadAnimationSafely(context, resId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800605 }
606 return null;
607 }
608
Jorim Jaggib142f572019-03-01 16:08:54 +0100609 private Animation loadAnimationRes(LayoutParams lp, int resId) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700610 Context context = mContext;
Todd Kennedy64c57a82018-04-19 15:17:24 -0700611 if (ResourceId.isValid(resId)) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700612 AttributeCache.Entry ent = getCachedAnimations(lp);
613 if (ent != null) {
614 context = ent.context;
615 }
Jorim Jaggib142f572019-03-01 16:08:54 +0100616 return loadAnimationSafely(context, resId);
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700617 }
618 return null;
619 }
620
621 private Animation loadAnimationRes(String packageName, int resId) {
Todd Kennedy64c57a82018-04-19 15:17:24 -0700622 if (ResourceId.isValid(resId)) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800623 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
624 if (ent != null) {
Jorim Jaggib142f572019-03-01 16:08:54 +0100625 return loadAnimationSafely(ent.context, resId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800626 }
627 }
Craig Mautner164d4bb2012-11-26 13:51:23 -0800628 return null;
629 }
630
Jorim Jaggib142f572019-03-01 16:08:54 +0100631 @VisibleForTesting
632 Animation loadAnimationSafely(Context context, int resId) {
633 try {
634 return AnimationUtils.loadAnimation(context, resId);
635 } catch (NotFoundException e) {
636 Slog.w(TAG, "Unable to load animation resource", e);
637 return null;
638 }
639 }
640
Jorim Jaggi0a1523d2018-04-19 17:48:38 +0200641 private int updateToTranslucentAnimIfNeeded(int anim, int transit) {
642 if (transit == TRANSIT_TRANSLUCENT_ACTIVITY_OPEN && anim == R.anim.activity_open_enter) {
643 return R.anim.activity_translucent_open_enter;
644 }
645 if (transit == TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE && anim == R.anim.activity_close_exit) {
646 return R.anim.activity_translucent_close_exit;
647 }
648 return anim;
649 }
650
Craig Mautner164d4bb2012-11-26 13:51:23 -0800651 /**
652 * Compute the pivot point for an animation that is scaling from a small
653 * rect on screen to a larger rect. The pivot point varies depending on
654 * the distance between the inner and outer edges on both sides. This
655 * function computes the pivot point for one dimension.
656 * @param startPos Offset from left/top edge of outer rectangle to
657 * left/top edge of inner rectangle.
658 * @param finalScale The scaling factor between the size of the outer
659 * and inner rectangles.
660 */
661 private static float computePivot(int startPos, float finalScale) {
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800662
663 /*
664 Theorem of intercepting lines:
665
666 + + +-----------------------------------------------+
667 | | | |
668 | | | |
669 | | | |
670 | | | |
671 x | y | | |
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 |
712 + ++
713 p ++
714
715 scale = (x - y) / x
716 <=> x = -y / (scale - 1)
717 */
Craig Mautner164d4bb2012-11-26 13:51:23 -0800718 final float denom = finalScale-1;
719 if (Math.abs(denom) < .0001f) {
720 return startPos;
721 }
722 return -startPos / denom;
723 }
724
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700725 private Animation createScaleUpAnimationLocked(int transit, boolean enter,
726 Rect containingFrame) {
727 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700728 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700729 final int appWidth = containingFrame.width();
730 final int appHeight = containingFrame.height();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800731 if (enter) {
732 // Entering app zooms out from the center of the initial rect.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700733 float scaleW = mTmpRect.width() / (float) appWidth;
734 float scaleH = mTmpRect.height() / (float) appHeight;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800735 Animation scale = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700736 computePivot(mTmpRect.left, scaleW),
Winson4c3fecd2016-07-13 12:29:48 -0700737 computePivot(mTmpRect.top, scaleH));
Craig Mautner321bdf52012-12-18 09:53:24 -0800738 scale.setInterpolator(mDecelerateInterpolator);
739
Craig Mautner164d4bb2012-11-26 13:51:23 -0800740 Animation alpha = new AlphaAnimation(0, 1);
Winson Chunga4ccb862014-08-22 15:26:27 -0700741 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
Craig Mautner321bdf52012-12-18 09:53:24 -0800742
743 AnimationSet set = new AnimationSet(false);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800744 set.addAnimation(scale);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800745 set.addAnimation(alpha);
746 set.setDetachWallpaper(true);
747 a = set;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800748 } else if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
749 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800750 // If we are on top of the wallpaper, we need an animation that
751 // correctly handles the wallpaper staying static behind all of
752 // the animated elements. To do this, will just have the existing
753 // element fade out.
754 a = new AlphaAnimation(1, 0);
755 a.setDetachWallpaper(true);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800756 } else {
Craig Mautner321bdf52012-12-18 09:53:24 -0800757 // For normal animations, the exiting element just holds in place.
758 a = new AlphaAnimation(1, 1);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800759 }
Craig Mautner321bdf52012-12-18 09:53:24 -0800760
761 // Pick the desired duration. If this is an inter-activity transition,
762 // it is the standard duration for that. Otherwise we use the longer
763 // task transition duration.
764 final long duration;
765 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800766 case TRANSIT_ACTIVITY_OPEN:
767 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800768 duration = mConfigShortAnimTime;
769 break;
770 default:
771 duration = DEFAULT_APP_TRANSITION_DURATION;
772 break;
773 }
774 a.setDuration(duration);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800775 a.setFillAfter(true);
Craig Mautner321bdf52012-12-18 09:53:24 -0800776 a.setInterpolator(mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800777 a.initialize(appWidth, appHeight, appWidth, appHeight);
778 return a;
779 }
780
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700781 private void getDefaultNextAppTransitionStartRect(Rect rect) {
782 if (mDefaultNextAppTransitionAnimationSpec == null ||
783 mDefaultNextAppTransitionAnimationSpec.rect == null) {
Jorim Jaggi2550f3f2017-03-14 20:15:59 +0100784 Slog.e(TAG, "Starting rect for app requested, but none available", new Throwable());
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700785 rect.setEmpty();
786 } else {
787 rect.set(mDefaultNextAppTransitionAnimationSpec.rect);
788 }
789 }
790
791 void getNextAppTransitionStartRect(int taskId, Rect rect) {
792 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800793 if (spec == null) {
794 spec = mDefaultNextAppTransitionAnimationSpec;
795 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700796 if (spec == null || spec.rect == null) {
Jorim Jaggi2550f3f2017-03-14 20:15:59 +0100797 Slog.e(TAG, "Starting rect for task: " + taskId + " requested, but not available",
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700798 new Throwable());
799 rect.setEmpty();
800 } else {
801 rect.set(spec.rect);
802 }
803 }
804
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800805 private void putDefaultNextAppTransitionCoordinates(int left, int top, int width, int height,
Winson Chungaa7fa012017-05-24 15:50:06 -0700806 GraphicBuffer buffer) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700807 mDefaultNextAppTransitionAnimationSpec = new AppTransitionAnimationSpec(-1 /* taskId */,
Winson Chungaa7fa012017-05-24 15:50:06 -0700808 buffer, new Rect(left, top, left + width, top + height));
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700809 }
810
Jorim Jaggif97ed922016-02-18 18:57:07 -0800811 /**
812 * @return the duration of the last clip reveal animation
813 */
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800814 long getLastClipRevealTransitionDuration() {
815 return mLastClipRevealTransitionDuration;
816 }
817
818 /**
Jorim Jaggif97ed922016-02-18 18:57:07 -0800819 * @return the maximum distance the app surface is traveling of the last clip reveal animation
820 */
821 int getLastClipRevealMaxTranslation() {
822 return mLastClipRevealMaxTranslation;
823 }
824
825 /**
826 * @return true if in the last app transition had a clip reveal animation, false otherwise
827 */
828 boolean hadClipRevealAnimation() {
829 return mLastHadClipReveal;
830 }
831
832 /**
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800833 * Calculates the duration for the clip reveal animation. If the clip is "cut off", meaning that
834 * the start rect is outside of the target rect, and there is a lot of movement going on.
835 *
836 * @param cutOff whether the start rect was not fully contained by the end rect
837 * @param translationX the total translation the surface moves in x direction
838 * @param translationY the total translation the surfaces moves in y direction
839 * @param displayFrame our display frame
840 *
841 * @return the duration of the clip reveal animation, in milliseconds
842 */
843 private long calculateClipRevealTransitionDuration(boolean cutOff, float translationX,
844 float translationY, Rect displayFrame) {
845 if (!cutOff) {
846 return DEFAULT_APP_TRANSITION_DURATION;
847 }
848 final float fraction = Math.max(Math.abs(translationX) / displayFrame.width(),
849 Math.abs(translationY) / displayFrame.height());
850 return (long) (DEFAULT_APP_TRANSITION_DURATION + fraction *
851 (MAX_CLIP_REVEAL_TRANSITION_DURATION - DEFAULT_APP_TRANSITION_DURATION));
852 }
853
854 private Animation createClipRevealAnimationLocked(int transit, boolean enter, Rect appFrame,
855 Rect displayFrame) {
Chet Haase10e23ab2015-02-11 15:08:38 -0800856 final Animation anim;
857 if (enter) {
Craig Mautner80b1f642015-04-22 10:59:09 -0700858 final int appWidth = appFrame.width();
859 final int appHeight = appFrame.height();
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800860
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700861 // mTmpRect will contain an area around the launcher icon that was pressed. We will
Filip Gruszczynski82861362015-10-16 14:21:09 -0700862 // clip reveal from that area in the final area of the app.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700863 getDefaultNextAppTransitionStartRect(mTmpRect);
Craig Mautner80b1f642015-04-22 10:59:09 -0700864
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700865 float t = 0f;
866 if (appHeight > 0) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800867 t = (float) mTmpRect.top / displayFrame.height();
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700868 }
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800869 int translationY = mClipRevealTranslationY + (int)(displayFrame.height() / 7f * t);
870 int translationX = 0;
871 int translationYCorrection = translationY;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700872 int centerX = mTmpRect.centerX();
873 int centerY = mTmpRect.centerY();
874 int halfWidth = mTmpRect.width() / 2;
875 int halfHeight = mTmpRect.height() / 2;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800876 int clipStartX = centerX - halfWidth - appFrame.left;
877 int clipStartY = centerY - halfHeight - appFrame.top;
878 boolean cutOff = false;
879
880 // If the starting rectangle is fully or partially outside of the target rectangle, we
881 // need to start the clipping at the edge and then achieve the rest with translation
882 // and extending the clip rect from that edge.
883 if (appFrame.top > centerY - halfHeight) {
884 translationY = (centerY - halfHeight) - appFrame.top;
885 translationYCorrection = 0;
886 clipStartY = 0;
887 cutOff = true;
888 }
889 if (appFrame.left > centerX - halfWidth) {
890 translationX = (centerX - halfWidth) - appFrame.left;
891 clipStartX = 0;
892 cutOff = true;
893 }
894 if (appFrame.right < centerX + halfWidth) {
895 translationX = (centerX + halfWidth) - appFrame.right;
896 clipStartX = appWidth - mTmpRect.width();
897 cutOff = true;
898 }
899 final long duration = calculateClipRevealTransitionDuration(cutOff, translationX,
900 translationY, displayFrame);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700901
902 // Clip third of the from size of launch icon, expand to full width/height
Chet Haase10e23ab2015-02-11 15:08:38 -0800903 Animation clipAnimLR = new ClipRectLRAnimation(
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800904 clipStartX, clipStartX + mTmpRect.width(), 0, appWidth);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700905 clipAnimLR.setInterpolator(mClipHorizontalInterpolator);
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800906 clipAnimLR.setDuration((long) (duration / 2.5f));
Filip Gruszczynski82861362015-10-16 14:21:09 -0700907
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800908 TranslateAnimation translate = new TranslateAnimation(translationX, 0, translationY, 0);
909 translate.setInterpolator(cutOff ? TOUCH_RESPONSE_INTERPOLATOR
910 : mLinearOutSlowInInterpolator);
911 translate.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800912
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800913 Animation clipAnimTB = new ClipRectTBAnimation(
914 clipStartY, clipStartY + mTmpRect.height(),
915 0, appHeight,
916 translationYCorrection, 0,
917 mLinearOutSlowInInterpolator);
918 clipAnimTB.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
919 clipAnimTB.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800920
921 // Quick fade-in from icon to app window
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800922 final long alphaDuration = duration / 4;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700923 AlphaAnimation alpha = new AlphaAnimation(0.5f, 1);
Chet Haase10e23ab2015-02-11 15:08:38 -0800924 alpha.setDuration(alphaDuration);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700925 alpha.setInterpolator(mLinearOutSlowInInterpolator);
Chet Haase10e23ab2015-02-11 15:08:38 -0800926
927 AnimationSet set = new AnimationSet(false);
928 set.addAnimation(clipAnimLR);
929 set.addAnimation(clipAnimTB);
Filip Gruszczynski82861362015-10-16 14:21:09 -0700930 set.addAnimation(translate);
Chet Haase10e23ab2015-02-11 15:08:38 -0800931 set.addAnimation(alpha);
Filip Gruszczynski9e2cf5b2015-07-31 12:20:40 -0700932 set.setZAdjustment(Animation.ZORDER_TOP);
Chet Haase10e23ab2015-02-11 15:08:38 -0800933 set.initialize(appWidth, appHeight, appWidth, appHeight);
934 anim = set;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800935 mLastHadClipReveal = true;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800936 mLastClipRevealTransitionDuration = duration;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800937
938 // If the start rect was full inside the target rect (cutOff == false), we don't need
939 // to store the translation, because it's only used if cutOff == true.
940 mLastClipRevealMaxTranslation = cutOff
941 ? Math.max(Math.abs(translationY), Math.abs(translationX)) : 0;
Chet Haase10e23ab2015-02-11 15:08:38 -0800942 } else {
943 final long duration;
944 switch (transit) {
945 case TRANSIT_ACTIVITY_OPEN:
946 case TRANSIT_ACTIVITY_CLOSE:
947 duration = mConfigShortAnimTime;
948 break;
949 default:
950 duration = DEFAULT_APP_TRANSITION_DURATION;
951 break;
952 }
953 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
954 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
955 // If we are on top of the wallpaper, we need an animation that
956 // correctly handles the wallpaper staying static behind all of
957 // the animated elements. To do this, will just have the existing
958 // element fade out.
959 anim = new AlphaAnimation(1, 0);
960 anim.setDetachWallpaper(true);
961 } else {
962 // For normal animations, the exiting element just holds in place.
963 anim = new AlphaAnimation(1, 1);
964 }
965 anim.setInterpolator(mDecelerateInterpolator);
966 anim.setDuration(duration);
967 anim.setFillAfter(true);
968 }
969 return anim;
970 }
971
Winson Chung399f6202014-03-19 10:47:20 -0700972 /**
973 * Prepares the specified animation with a standard duration, interpolator, etc.
974 */
Winson Chung5393dff2014-05-08 14:25:43 -0700975 Animation prepareThumbnailAnimationWithDuration(Animation a, int appWidth, int appHeight,
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100976 long duration, Interpolator interpolator) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700977 if (duration > 0) {
978 a.setDuration(duration);
979 }
Winson Chung5393dff2014-05-08 14:25:43 -0700980 a.setFillAfter(true);
Jorim Jaggic69bd222016-03-15 14:38:37 +0100981 if (interpolator != null) {
982 a.setInterpolator(interpolator);
983 }
Winson Chung5393dff2014-05-08 14:25:43 -0700984 a.initialize(appWidth, appHeight, appWidth, appHeight);
985 return a;
986 }
987
988 /**
989 * Prepares the specified animation with a standard duration, interpolator, etc.
990 */
Winson Chung399f6202014-03-19 10:47:20 -0700991 Animation prepareThumbnailAnimation(Animation a, int appWidth, int appHeight, int transit) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800992 // Pick the desired duration. If this is an inter-activity transition,
993 // it is the standard duration for that. Otherwise we use the longer
994 // task transition duration.
Winson Chung5393dff2014-05-08 14:25:43 -0700995 final int duration;
Craig Mautner321bdf52012-12-18 09:53:24 -0800996 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800997 case TRANSIT_ACTIVITY_OPEN:
998 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800999 duration = mConfigShortAnimTime;
1000 break;
1001 default:
1002 duration = DEFAULT_APP_TRANSITION_DURATION;
1003 break;
1004 }
Winson Chung5393dff2014-05-08 14:25:43 -07001005 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, duration,
1006 mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001007 }
1008
Winson Chung399f6202014-03-19 10:47:20 -07001009 /**
1010 * Return the current thumbnail transition state.
1011 */
1012 int getThumbnailTransitionState(boolean enter) {
1013 if (enter) {
1014 if (mNextAppTransitionScaleUp) {
1015 return THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
1016 } else {
1017 return THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN;
1018 }
1019 } else {
1020 if (mNextAppTransitionScaleUp) {
1021 return THUMBNAIL_TRANSITION_EXIT_SCALE_UP;
1022 } else {
1023 return THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN;
1024 }
1025 }
1026 }
1027
1028 /**
Tony Mak64b8d562017-12-28 17:44:02 +00001029 * Creates an overlay with a background color and a thumbnail for the cross profile apps
1030 * animation.
1031 */
1032 GraphicBuffer createCrossProfileAppsThumbnail(
1033 @DrawableRes int thumbnailDrawableRes, Rect frame) {
1034 final int width = frame.width();
1035 final int height = frame.height();
1036
John Reck519ad482018-02-12 17:08:48 -08001037 final Picture picture = new Picture();
1038 final Canvas canvas = picture.beginRecording(width, height);
Tony Mak64b8d562017-12-28 17:44:02 +00001039 canvas.drawColor(Color.argb(0.6f, 0, 0, 0));
1040 final int thumbnailSize = mService.mContext.getResources().getDimensionPixelSize(
1041 com.android.internal.R.dimen.cross_profile_apps_thumbnail_size);
1042 final Drawable drawable = mService.mContext.getDrawable(thumbnailDrawableRes);
1043 drawable.setBounds(
1044 (width - thumbnailSize) / 2,
1045 (height - thumbnailSize) / 2,
1046 (width + thumbnailSize) / 2,
1047 (height + thumbnailSize) / 2);
Tony Makda4af232018-04-27 11:01:10 +01001048 drawable.setTint(mContext.getColor(android.R.color.white));
Tony Mak64b8d562017-12-28 17:44:02 +00001049 drawable.draw(canvas);
John Reck519ad482018-02-12 17:08:48 -08001050 picture.endRecording();
Tony Mak64b8d562017-12-28 17:44:02 +00001051
John Reck519ad482018-02-12 17:08:48 -08001052 return Bitmap.createBitmap(picture).createGraphicBufferHandle();
Tony Mak64b8d562017-12-28 17:44:02 +00001053 }
1054
1055 Animation createCrossProfileAppsThumbnailAnimationLocked(Rect appRect) {
1056 final Animation animation = loadAnimationRes(
1057 "android", com.android.internal.R.anim.cross_profile_apps_thumbnail_enter);
1058 return prepareThumbnailAnimationWithDuration(animation, appRect.width(),
1059 appRect.height(), 0, null);
1060 }
1061
1062 /**
Winson Chung399f6202014-03-19 10:47:20 -07001063 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001064 * when a thumbnail is specified with the pending animation override.
Winson Chung399f6202014-03-19 10:47:20 -07001065 */
Jorim Jaggide63d442016-03-14 14:56:56 +01001066 Animation createThumbnailAspectScaleAnimationLocked(Rect appRect, @Nullable Rect contentInsets,
Winson Chungaa7fa012017-05-24 15:50:06 -07001067 GraphicBuffer thumbnailHeader, final int taskId, int uiMode, int orientation) {
Winson Chung399f6202014-03-19 10:47:20 -07001068 Animation a;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001069 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chung399f6202014-03-19 10:47:20 -07001070 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001071 final int thumbHeightI = thumbnailHeader.getHeight();
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -07001072 final int appWidth = appRect.width();
Winson Chung399f6202014-03-19 10:47:20 -07001073
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -07001074 float scaleW = appWidth / thumbWidth;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001075 getNextAppTransitionStartRect(taskId, mTmpRect);
Jorim Jaggi09072002016-03-25 16:48:42 -07001076 final float fromX;
Manu Cornet57b61492017-01-24 18:19:05 +09001077 float fromY;
Jorim Jaggi09072002016-03-25 16:48:42 -07001078 final float toX;
Manu Cornet57b61492017-01-24 18:19:05 +09001079 float toY;
Jorim Jaggi09072002016-03-25 16:48:42 -07001080 final float pivotX;
1081 final float pivotY;
Manu Cornetd7376802017-01-13 13:44:07 -08001082 if (shouldScaleDownThumbnailTransition(uiMode, orientation)) {
Jorim Jaggi09072002016-03-25 16:48:42 -07001083 fromX = mTmpRect.left;
1084 fromY = mTmpRect.top;
1085
1086 // For the curved translate animation to work, the pivot points needs to be at the
1087 // same absolute position as the one from the real surface.
1088 toX = mTmpRect.width() / 2 * (scaleW - 1f) + appRect.left;
1089 toY = appRect.height() / 2 * (1 - 1 / scaleW) + appRect.top;
1090 pivotX = mTmpRect.width() / 2;
1091 pivotY = appRect.height() / 2 / scaleW;
Manu Cornet57b61492017-01-24 18:19:05 +09001092 if (mGridLayoutRecentsEnabled) {
1093 // In the grid layout, the header is displayed above the thumbnail instead of
1094 // overlapping it.
1095 fromY -= thumbHeightI;
1096 toY -= thumbHeightI * scaleW;
1097 }
Jorim Jaggi09072002016-03-25 16:48:42 -07001098 } else {
1099 pivotX = 0;
1100 pivotY = 0;
1101 fromX = mTmpRect.left;
1102 fromY = mTmpRect.top;
1103 toX = appRect.left;
1104 toY = appRect.top;
1105 }
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001106 final long duration = getAspectScaleDuration();
1107 final Interpolator interpolator = getAspectScaleInterpolator();
Winson Chung399f6202014-03-19 10:47:20 -07001108 if (mNextAppTransitionScaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001109 // Animation up from the thumbnail to the full screen
Jorim Jaggi8448f332016-03-14 17:50:37 +01001110 Animation scale = new ScaleAnimation(1f, scaleW, 1f, scaleW, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001111 scale.setInterpolator(interpolator);
1112 scale.setDuration(duration);
Jorim Jaggic6c89a82016-01-28 17:48:21 -08001113 Animation alpha = new AlphaAnimation(1f, 0f);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001114 alpha.setInterpolator(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
1115 ? THUMBNAIL_DOCK_INTERPOLATOR : mThumbnailFadeOutInterpolator);
1116 alpha.setDuration(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
1117 ? duration / 2
1118 : duration);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001119 Animation translate = createCurvedMotion(fromX, toX, fromY, toY);
1120 translate.setInterpolator(interpolator);
1121 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -07001122
Jorim Jaggide63d442016-03-14 14:56:56 +01001123 mTmpFromClipRect.set(0, 0, thumbWidthI, thumbHeightI);
1124 mTmpToClipRect.set(appRect);
1125
1126 // Containing frame is in screen space, but we need the clip rect in the
1127 // app space.
1128 mTmpToClipRect.offsetTo(0, 0);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001129 mTmpToClipRect.right = (int) (mTmpToClipRect.right / scaleW);
1130 mTmpToClipRect.bottom = (int) (mTmpToClipRect.bottom / scaleW);
Jorim Jaggide63d442016-03-14 14:56:56 +01001131
1132 if (contentInsets != null) {
Jorim Jaggi8448f332016-03-14 17:50:37 +01001133 mTmpToClipRect.inset((int) (-contentInsets.left * scaleW),
1134 (int) (-contentInsets.top * scaleW),
1135 (int) (-contentInsets.right * scaleW),
1136 (int) (-contentInsets.bottom * scaleW));
Jorim Jaggide63d442016-03-14 14:56:56 +01001137 }
1138
1139 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001140 clipAnim.setInterpolator(interpolator);
1141 clipAnim.setDuration(duration);
Jorim Jaggide63d442016-03-14 14:56:56 +01001142
Winson Chung399f6202014-03-19 10:47:20 -07001143 // This AnimationSet uses the Interpolators assigned above.
1144 AnimationSet set = new AnimationSet(false);
1145 set.addAnimation(scale);
Manu Cornet57b61492017-01-24 18:19:05 +09001146 if (!mGridLayoutRecentsEnabled) {
1147 // In the grid layout, the header should be shown for the whole animation.
1148 set.addAnimation(alpha);
1149 }
Winson Chunga4ccb862014-08-22 15:26:27 -07001150 set.addAnimation(translate);
Jorim Jaggide63d442016-03-14 14:56:56 +01001151 set.addAnimation(clipAnim);
Winson Chung399f6202014-03-19 10:47:20 -07001152 a = set;
1153 } else {
Winson Chunga4ccb862014-08-22 15:26:27 -07001154 // Animation down from the full screen to the thumbnail
Jorim Jaggi8448f332016-03-14 17:50:37 +01001155 Animation scale = new ScaleAnimation(scaleW, 1f, scaleW, 1f, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001156 scale.setInterpolator(interpolator);
1157 scale.setDuration(duration);
Winson Chunga4ccb862014-08-22 15:26:27 -07001158 Animation alpha = new AlphaAnimation(0f, 1f);
1159 alpha.setInterpolator(mThumbnailFadeInInterpolator);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001160 alpha.setDuration(duration);
1161 Animation translate = createCurvedMotion(toX, fromX, toY, fromY);
1162 translate.setInterpolator(interpolator);
1163 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -07001164
Winson Chunga4ccb862014-08-22 15:26:27 -07001165 // This AnimationSet uses the Interpolators assigned above.
1166 AnimationSet set = new AnimationSet(false);
1167 set.addAnimation(scale);
Manu Cornet57b61492017-01-24 18:19:05 +09001168 if (!mGridLayoutRecentsEnabled) {
1169 // In the grid layout, the header should be shown for the whole animation.
1170 set.addAnimation(alpha);
1171 }
Winson Chunga4ccb862014-08-22 15:26:27 -07001172 set.addAnimation(translate);
1173 a = set;
1174
1175 }
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -07001176 return prepareThumbnailAnimationWithDuration(a, appWidth, appRect.height(), 0,
Jorim Jaggic69bd222016-03-15 14:38:37 +01001177 null);
Winson Chung399f6202014-03-19 10:47:20 -07001178 }
1179
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001180 private Animation createCurvedMotion(float fromX, float toX, float fromY, float toY) {
1181
1182 // Almost no x-change - use linear animation
Jorim Jaggic69bd222016-03-15 14:38:37 +01001183 if (Math.abs(toX - fromX) < 1f || mNextAppTransition != TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001184 return new TranslateAnimation(fromX, toX, fromY, toY);
1185 } else {
1186 final Path path = createCurvedPath(fromX, toX, fromY, toY);
1187 return new CurvedTranslateAnimation(path);
1188 }
1189 }
1190
1191 private Path createCurvedPath(float fromX, float toX, float fromY, float toY) {
1192 final Path path = new Path();
1193 path.moveTo(fromX, fromY);
Jorim Jaggi1f458fb2016-03-25 17:36:37 -07001194
1195 if (fromY > toY) {
1196 // If the object needs to go up, move it in horizontal direction first, then vertical.
1197 path.cubicTo(fromX, fromY, toX, 0.9f * fromY + 0.1f * toY, toX, toY);
1198 } else {
1199 // If the object needs to go down, move it in vertical direction first, then horizontal.
1200 path.cubicTo(fromX, fromY, fromX, 0.1f * fromY + 0.9f * toY, toX, toY);
1201 }
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001202 return path;
1203 }
1204
1205 private long getAspectScaleDuration() {
1206 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggic69bd222016-03-15 14:38:37 +01001207 return (long) (THUMBNAIL_APP_TRANSITION_DURATION * 1.35f);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001208 } else {
1209 return THUMBNAIL_APP_TRANSITION_DURATION;
1210 }
1211 }
1212
1213 private Interpolator getAspectScaleInterpolator() {
1214 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
1215 return mFastOutSlowInInterpolator;
1216 } else {
1217 return TOUCH_RESPONSE_INTERPOLATOR;
1218 }
1219 }
1220
Winson Chung399f6202014-03-19 10:47:20 -07001221 /**
1222 * This alternate animation is created when we are doing a thumbnail transition, for the
1223 * activity that is leaving, and the activity that is entering.
1224 */
Winson Chunga4ccb862014-08-22 15:26:27 -07001225 Animation createAspectScaledThumbnailEnterExitAnimationLocked(int thumbTransitState,
Winsonb2024762016-04-05 17:32:30 -07001226 int uiMode, int orientation, int transit, Rect containingFrame, Rect contentInsets,
Matthew Ng43db6d22017-06-27 15:29:39 -07001227 @Nullable Rect surfaceInsets, @Nullable Rect stableInsets, boolean freeform,
1228 int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -07001229 Animation a;
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001230 final int appWidth = containingFrame.width();
1231 final int appHeight = containingFrame.height();
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001232 getDefaultNextAppTransitionStartRect(mTmpRect);
1233 final int thumbWidthI = mTmpRect.width();
Winson Chung399f6202014-03-19 10:47:20 -07001234 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001235 final int thumbHeightI = mTmpRect.height();
Winson Chung399f6202014-03-19 10:47:20 -07001236 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
Winsoncbb625b2016-07-06 15:24:15 -07001237 final int thumbStartX = mTmpRect.left - containingFrame.left - contentInsets.left;
Winson21700932016-03-24 17:26:23 -07001238 final int thumbStartY = mTmpRect.top - containingFrame.top;
Winson Chung399f6202014-03-19 10:47:20 -07001239
1240 switch (thumbTransitState) {
Jorim Jaggi8448f332016-03-14 17:50:37 +01001241 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP:
1242 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1243 final boolean scaleUp = thumbTransitState == THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
1244 if (freeform && scaleUp) {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001245 a = createAspectScaledThumbnailEnterFreeformAnimationLocked(
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001246 containingFrame, surfaceInsets, taskId);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001247 } else if (freeform) {
1248 a = createAspectScaledThumbnailExitFreeformAnimationLocked(
1249 containingFrame, surfaceInsets, taskId);
Winson Chung2820c452014-04-15 15:34:44 -07001250 } else {
Winson21700932016-03-24 17:26:23 -07001251 AnimationSet set = new AnimationSet(true);
1252
1253 // In portrait, we scale to fit the width
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001254 mTmpFromClipRect.set(containingFrame);
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001255 mTmpToClipRect.set(containingFrame);
Jorim Jaggic6c89a82016-01-28 17:48:21 -08001256
1257 // Containing frame is in screen space, but we need the clip rect in the
1258 // app space.
1259 mTmpFromClipRect.offsetTo(0, 0);
1260 mTmpToClipRect.offsetTo(0, 0);
1261
1262 // Exclude insets region from the source clip.
1263 mTmpFromClipRect.inset(contentInsets);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001264 mNextAppTransitionInsets.set(contentInsets);
1265
Manu Cornetd7376802017-01-13 13:44:07 -08001266 if (shouldScaleDownThumbnailTransition(uiMode, orientation)) {
Jorim Jaggic69bd222016-03-15 14:38:37 +01001267 // We scale the width and clip to the top/left square
1268 float scale = thumbWidth /
1269 (appWidth - contentInsets.left - contentInsets.right);
Manu Cornetb68b7652017-01-23 19:37:53 +09001270 if (!mGridLayoutRecentsEnabled) {
1271 int unscaledThumbHeight = (int) (thumbHeight / scale);
1272 mTmpFromClipRect.bottom = mTmpFromClipRect.top + unscaledThumbHeight;
1273 }
Jorim Jaggic69bd222016-03-15 14:38:37 +01001274
1275 mNextAppTransitionInsets.set(contentInsets);
1276
Jorim Jaggi8448f332016-03-14 17:50:37 +01001277 Animation scaleAnim = new ScaleAnimation(
1278 scaleUp ? scale : 1, scaleUp ? 1 : scale,
1279 scaleUp ? scale : 1, scaleUp ? 1 : scale,
Jorim Jaggic69bd222016-03-15 14:38:37 +01001280 containingFrame.width() / 2f,
1281 containingFrame.height() / 2f + contentInsets.top);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001282 final float targetX = (mTmpRect.left - containingFrame.left);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001283 final float x = containingFrame.width() / 2f
1284 - containingFrame.width() / 2f * scale;
Jorim Jaggi8448f332016-03-14 17:50:37 +01001285 final float targetY = (mTmpRect.top - containingFrame.top);
Matthew Ng43db6d22017-06-27 15:29:39 -07001286 float y = containingFrame.height() / 2f
Jorim Jaggic69bd222016-03-15 14:38:37 +01001287 - containingFrame.height() / 2f * scale;
Matthew Ng43db6d22017-06-27 15:29:39 -07001288
1289 // During transition may require clipping offset from any top stable insets
1290 // such as the statusbar height when statusbar is hidden
1291 if (mLowRamRecentsEnabled && contentInsets.top == 0 && scaleUp) {
1292 mTmpFromClipRect.top += stableInsets.top;
1293 y += stableInsets.top;
1294 }
Jorim Jaggi8448f332016-03-14 17:50:37 +01001295 final float startX = targetX - x;
1296 final float startY = targetY - y;
1297 Animation clipAnim = scaleUp
1298 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1299 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1300 Animation translateAnim = scaleUp
Jorim Jaggic69bd222016-03-15 14:38:37 +01001301 ? createCurvedMotion(startX, 0, startY - contentInsets.top, 0)
1302 : createCurvedMotion(0, startX, 0, startY - contentInsets.top);
1303
Winson21700932016-03-24 17:26:23 -07001304 set.addAnimation(clipAnim);
1305 set.addAnimation(scaleAnim);
1306 set.addAnimation(translateAnim);
1307
1308 } else {
1309 // In landscape, we don't scale at all and only crop
1310 mTmpFromClipRect.bottom = mTmpFromClipRect.top + thumbHeightI;
1311 mTmpFromClipRect.right = mTmpFromClipRect.left + thumbWidthI;
1312
Jorim Jaggi8448f332016-03-14 17:50:37 +01001313 Animation clipAnim = scaleUp
1314 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1315 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1316 Animation translateAnim = scaleUp
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001317 ? createCurvedMotion(thumbStartX, 0,
1318 thumbStartY - contentInsets.top, 0)
1319 : createCurvedMotion(0, thumbStartX, 0,
1320 thumbStartY - contentInsets.top);
Winson21700932016-03-24 17:26:23 -07001321
1322 set.addAnimation(clipAnim);
1323 set.addAnimation(translateAnim);
1324 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001325 a = set;
Winson21700932016-03-24 17:26:23 -07001326 a.setZAdjustment(Animation.ZORDER_TOP);
Winson Chung2820c452014-04-15 15:34:44 -07001327 }
Winson Chung399f6202014-03-19 10:47:20 -07001328 break;
1329 }
1330 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001331 // Previous app window during the scale up
Winson Chung399f6202014-03-19 10:47:20 -07001332 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001333 // Fade out the source activity if we are animating to a wallpaper
Winson Chung399f6202014-03-19 10:47:20 -07001334 // activity.
1335 a = new AlphaAnimation(1, 0);
1336 } else {
Winson Chung399f6202014-03-19 10:47:20 -07001337 a = new AlphaAnimation(1, 1);
1338 }
1339 break;
1340 }
1341 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001342 // Target app window during the scale down
1343 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1344 // Fade in the destination activity if we are animating from a wallpaper
1345 // activity.
1346 a = new AlphaAnimation(0, 1);
1347 } else {
1348 a = new AlphaAnimation(1, 1);
1349 }
Winson Chung399f6202014-03-19 10:47:20 -07001350 break;
1351 }
Winson Chung399f6202014-03-19 10:47:20 -07001352 default:
1353 throw new RuntimeException("Invalid thumbnail transition state");
1354 }
1355
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001356 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight,
1357 getAspectScaleDuration(), getAspectScaleInterpolator());
Winson Chung399f6202014-03-19 10:47:20 -07001358 }
1359
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001360 private Animation createAspectScaledThumbnailEnterFreeformAnimationLocked(Rect frame,
1361 @Nullable Rect surfaceInsets, int taskId) {
1362 getNextAppTransitionStartRect(taskId, mTmpRect);
1363 return createAspectScaledThumbnailFreeformAnimationLocked(mTmpRect, frame, surfaceInsets,
1364 true);
1365 }
1366
1367 private Animation createAspectScaledThumbnailExitFreeformAnimationLocked(Rect frame,
1368 @Nullable Rect surfaceInsets, int taskId) {
1369 getNextAppTransitionStartRect(taskId, mTmpRect);
1370 return createAspectScaledThumbnailFreeformAnimationLocked(frame, mTmpRect, surfaceInsets,
1371 false);
1372 }
1373
1374 private AnimationSet createAspectScaledThumbnailFreeformAnimationLocked(Rect sourceFrame,
1375 Rect destFrame, @Nullable Rect surfaceInsets, boolean enter) {
1376 final float sourceWidth = sourceFrame.width();
1377 final float sourceHeight = sourceFrame.height();
1378 final float destWidth = destFrame.width();
1379 final float destHeight = destFrame.height();
1380 final float scaleH = enter ? sourceWidth / destWidth : destWidth / sourceWidth;
1381 final float scaleV = enter ? sourceHeight / destHeight : destHeight / sourceHeight;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001382 AnimationSet set = new AnimationSet(true);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001383 final int surfaceInsetsH = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001384 ? 0 : surfaceInsets.left + surfaceInsets.right;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001385 final int surfaceInsetsV = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001386 ? 0 : surfaceInsets.top + surfaceInsets.bottom;
1387 // We want the scaling to happen from the center of the surface. In order to achieve that,
1388 // we need to account for surface insets that will be used to enlarge the surface.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001389 final float scaleHCenter = ((enter ? destWidth : sourceWidth) + surfaceInsetsH) / 2;
1390 final float scaleVCenter = ((enter ? destHeight : sourceHeight) + surfaceInsetsV) / 2;
1391 final ScaleAnimation scale = enter ?
1392 new ScaleAnimation(scaleH, 1, scaleV, 1, scaleHCenter, scaleVCenter)
1393 : new ScaleAnimation(1, scaleH, 1, scaleV, scaleHCenter, scaleVCenter);
1394 final int sourceHCenter = sourceFrame.left + sourceFrame.width() / 2;
1395 final int sourceVCenter = sourceFrame.top + sourceFrame.height() / 2;
1396 final int destHCenter = destFrame.left + destFrame.width() / 2;
1397 final int destVCenter = destFrame.top + destFrame.height() / 2;
1398 final int fromX = enter ? sourceHCenter - destHCenter : destHCenter - sourceHCenter;
1399 final int fromY = enter ? sourceVCenter - destVCenter : destVCenter - sourceVCenter;
1400 final TranslateAnimation translation = enter ? new TranslateAnimation(fromX, 0, fromY, 0)
1401 : new TranslateAnimation(0, fromX, 0, fromY);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001402 set.addAnimation(scale);
1403 set.addAnimation(translation);
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001404
1405 final IRemoteCallback callback = mAnimationFinishedCallback;
1406 if (callback != null) {
1407 set.setAnimationListener(new Animation.AnimationListener() {
1408 @Override
1409 public void onAnimationStart(Animation animation) { }
1410
1411 @Override
1412 public void onAnimationEnd(Animation animation) {
lumark23b54592018-10-02 17:17:23 +08001413 mHandler.sendMessage(PooledLambda.obtainMessage(
1414 AppTransition::doAnimationCallback, callback));
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001415 }
1416
1417 @Override
1418 public void onAnimationRepeat(Animation animation) { }
1419 });
1420 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001421 return set;
1422 }
1423
Winson Chung399f6202014-03-19 10:47:20 -07001424 /**
Winson Chunga4ccb862014-08-22 15:26:27 -07001425 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001426 * when a thumbnail is specified with the pending animation override.
Winson Chunga4ccb862014-08-22 15:26:27 -07001427 */
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001428 Animation createThumbnailScaleAnimationLocked(int appWidth, int appHeight, int transit,
Winson Chungaa7fa012017-05-24 15:50:06 -07001429 GraphicBuffer thumbnailHeader) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001430 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001431 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001432 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chunga4ccb862014-08-22 15:26:27 -07001433 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001434 final int thumbHeightI = thumbnailHeader.getHeight();
Winson Chunga4ccb862014-08-22 15:26:27 -07001435 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1436
1437 if (mNextAppTransitionScaleUp) {
1438 // Animation for the thumbnail zooming from its initial size to the full screen
1439 float scaleW = appWidth / thumbWidth;
1440 float scaleH = appHeight / thumbHeight;
1441 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001442 computePivot(mTmpRect.left, 1 / scaleW),
1443 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001444 scale.setInterpolator(mDecelerateInterpolator);
1445
1446 Animation alpha = new AlphaAnimation(1, 0);
1447 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
1448
1449 // This AnimationSet uses the Interpolators assigned above.
1450 AnimationSet set = new AnimationSet(false);
1451 set.addAnimation(scale);
1452 set.addAnimation(alpha);
1453 a = set;
1454 } else {
1455 // Animation for the thumbnail zooming down from the full screen to its final size
1456 float scaleW = appWidth / thumbWidth;
1457 float scaleH = appHeight / thumbHeight;
1458 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001459 computePivot(mTmpRect.left, 1 / scaleW),
1460 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001461 }
1462
1463 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1464 }
1465
1466 /**
Winson Chung399f6202014-03-19 10:47:20 -07001467 * This animation is created when we are doing a thumbnail transition, for the activity that is
1468 * leaving, and the activity that is entering.
1469 */
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001470 Animation createThumbnailEnterExitAnimationLocked(int thumbTransitState, Rect containingFrame,
1471 int transit, int taskId) {
1472 final int appWidth = containingFrame.width();
1473 final int appHeight = containingFrame.height();
Winson Chungaa7fa012017-05-24 15:50:06 -07001474 final GraphicBuffer thumbnailHeader = getAppTransitionThumbnailHeader(taskId);
Winson Chung399f6202014-03-19 10:47:20 -07001475 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001476 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001477 final int thumbWidthI = thumbnailHeader != null ? thumbnailHeader.getWidth() : appWidth;
Winson Chung399f6202014-03-19 10:47:20 -07001478 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001479 final int thumbHeightI = thumbnailHeader != null ? thumbnailHeader.getHeight() : appHeight;
Winson Chung399f6202014-03-19 10:47:20 -07001480 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1481
1482 switch (thumbTransitState) {
1483 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
1484 // Entering app scales up with the thumbnail
1485 float scaleW = thumbWidth / appWidth;
1486 float scaleH = thumbHeight / appHeight;
1487 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001488 computePivot(mTmpRect.left, scaleW),
1489 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001490 break;
1491 }
1492 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
1493 // Exiting app while the thumbnail is scaling up should fade or stay in place
1494 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1495 // Fade out while bringing up selected activity. This keeps the
1496 // current activity from showing through a launching wallpaper
1497 // activity.
1498 a = new AlphaAnimation(1, 0);
1499 } else {
1500 // noop animation
1501 a = new AlphaAnimation(1, 1);
1502 }
1503 break;
1504 }
1505 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
1506 // Entering the other app, it should just be visible while we scale the thumbnail
1507 // down above it
1508 a = new AlphaAnimation(1, 1);
1509 break;
1510 }
1511 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1512 // Exiting the current app, the app should scale down with the thumbnail
1513 float scaleW = thumbWidth / appWidth;
1514 float scaleH = thumbHeight / appHeight;
1515 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001516 computePivot(mTmpRect.left, scaleW),
1517 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001518
1519 Animation alpha = new AlphaAnimation(1, 0);
1520
1521 AnimationSet set = new AnimationSet(true);
1522 set.addAnimation(scale);
1523 set.addAnimation(alpha);
1524 set.setZAdjustment(Animation.ZORDER_TOP);
1525 a = set;
1526 break;
1527 }
1528 default:
1529 throw new RuntimeException("Invalid thumbnail transition state");
1530 }
1531
1532 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1533 }
1534
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001535 private Animation createRelaunchAnimation(Rect containingFrame, Rect contentInsets) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001536 getDefaultNextAppTransitionStartRect(mTmpFromClipRect);
1537 final int left = mTmpFromClipRect.left;
1538 final int top = mTmpFromClipRect.top;
1539 mTmpFromClipRect.offset(-left, -top);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001540 // TODO: Isn't that strange that we ignore exact position of the containingFrame?
1541 mTmpToClipRect.set(0, 0, containingFrame.width(), containingFrame.height());
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001542 AnimationSet set = new AnimationSet(true);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001543 float fromWidth = mTmpFromClipRect.width();
1544 float toWidth = mTmpToClipRect.width();
1545 float fromHeight = mTmpFromClipRect.height();
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001546 // While the window might span the whole display, the actual content will be cropped to the
1547 // system decoration frame, for example when the window is docked. We need to take into
1548 // account the visible height when constructing the animation.
1549 float toHeight = mTmpToClipRect.height() - contentInsets.top - contentInsets.bottom;
1550 int translateAdjustment = 0;
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001551 if (fromWidth <= toWidth && fromHeight <= toHeight) {
1552 // The final window is larger in both dimensions than current window (e.g. we are
1553 // maximizing), so we can simply unclip the new window and there will be no disappearing
1554 // frame.
1555 set.addAnimation(new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect));
1556 } else {
1557 // The disappearing window has one larger dimension. We need to apply scaling, so the
1558 // first frame of the entry animation matches the old window.
1559 set.addAnimation(new ScaleAnimation(fromWidth / toWidth, 1, fromHeight / toHeight, 1));
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001560 // We might not be going exactly full screen, but instead be aligned under the status
1561 // bar using cropping. We still need to account for the cropped part, which will also
1562 // be scaled.
1563 translateAdjustment = (int) (contentInsets.top * fromHeight / toHeight);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001564 }
1565
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001566 // We animate the translation from the old position of the removed window, to the new
1567 // position of the added window. The latter might not be full screen, for example docked for
1568 // docked windows.
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001569 TranslateAnimation translate = new TranslateAnimation(left - containingFrame.left,
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001570 0, top - containingFrame.top - translateAdjustment, 0);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001571 set.addAnimation(translate);
1572 set.setDuration(DEFAULT_APP_TRANSITION_DURATION);
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07001573 set.setZAdjustment(Animation.ZORDER_TOP);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001574 return set;
1575 }
1576
Jorim Jaggic554b772015-06-04 16:07:57 -07001577 /**
1578 * @return true if and only if the first frame of the transition can be skipped, i.e. the first
1579 * frame of the transition doesn't change the visuals on screen, so we can start
1580 * directly with the second one
1581 */
1582 boolean canSkipFirstFrame() {
1583 return mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM
1584 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE
Jorim Jaggife762342016-10-13 14:33:27 +02001585 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CLIP_REVEAL
1586 && mNextAppTransition != TRANSIT_KEYGUARD_GOING_AWAY;
Jorim Jaggic554b772015-06-04 16:07:57 -07001587 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001588
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001589 RemoteAnimationController getRemoteAnimationController() {
1590 return mRemoteAnimationController;
1591 }
1592
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001593 /**
1594 *
1595 * @param frame These are the bounds of the window when it finishes the animation. This is where
1596 * the animation must usually finish in entrance animation, as the next frame will
1597 * display the window at these coordinates. In case of exit animation, this is
1598 * where the animation must start, as the frame before the animation is displaying
1599 * the window at these bounds.
1600 * @param insets Knowing where the window will be positioned is not enough. Some parts of the
1601 * window might be obscured, usually by the system windows (status bar and
1602 * navigation bar) and we use content insets to convey that information. This
1603 * usually affects the animation aspects vertically, as the system decoration is
1604 * at the top and the bottom. For example when we animate from full screen to
1605 * recents, we want to exclude the covered parts, because they won't match the
1606 * thumbnail after the last frame is executed.
1607 * @param surfaceInsets In rare situation the surface is larger than the content and we need to
1608 * know about this to make the animation frames match. We currently use
1609 * this for freeform windows, which have larger surfaces to display
1610 * shadows. When we animate them from recents, we want to match the content
1611 * to the recents thumbnail and hence need to account for the surface being
1612 * bigger.
1613 */
Jorim Jaggif84e2f62018-01-16 14:17:59 +01001614 Animation loadAnimation(LayoutParams lp, int transit, boolean enter, int uiMode,
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001615 int orientation, Rect frame, Rect displayFrame, Rect insets,
Matthew Ng43db6d22017-06-27 15:29:39 -07001616 @Nullable Rect surfaceInsets, @Nullable Rect stableInsets, boolean isVoiceInteraction,
1617 boolean freeform, int taskId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001618 Animation a;
Jorim Jaggife762342016-10-13 14:33:27 +02001619 if (isKeyguardGoingAwayTransit(transit) && enter) {
1620 a = loadKeyguardExitAnimation(transit);
1621 } else if (transit == TRANSIT_KEYGUARD_OCCLUDE) {
Selim Cinekdbf172e2018-08-08 18:31:45 +00001622 a = null;
Jorim Jaggife762342016-10-13 14:33:27 +02001623 } else if (transit == TRANSIT_KEYGUARD_UNOCCLUDE && !enter) {
1624 a = loadAnimationRes(lp, com.android.internal.R.anim.wallpaper_open_exit);
Adrian Roos93577212018-04-10 14:12:10 -07001625 } else if (transit == TRANSIT_CRASHING_ACTIVITY_CLOSE) {
1626 a = null;
Jorim Jaggife762342016-10-13 14:33:27 +02001627 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_OPEN
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001628 || transit == TRANSIT_TASK_OPEN
1629 || transit == TRANSIT_TASK_TO_FRONT)) {
1630 a = loadAnimationRes(lp, enter
1631 ? com.android.internal.R.anim.voice_activity_open_enter
1632 : com.android.internal.R.anim.voice_activity_open_exit);
1633 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1634 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001635 + " anim=" + a + " transit=" + appTransitionToString(transit)
1636 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001637 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_CLOSE
1638 || transit == TRANSIT_TASK_CLOSE
1639 || transit == TRANSIT_TASK_TO_BACK)) {
1640 a = loadAnimationRes(lp, enter
1641 ? com.android.internal.R.anim.voice_activity_close_enter
1642 : com.android.internal.R.anim.voice_activity_close_exit);
1643 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1644 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001645 + " anim=" + a + " transit=" + appTransitionToString(transit)
1646 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001647 } else if (transit == TRANSIT_ACTIVITY_RELAUNCH) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001648 a = createRelaunchAnimation(frame, insets);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001649 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1650 "applyAnimation:"
1651 + " anim=" + a + " nextAppTransition=" + mNextAppTransition
1652 + " transit=" + appTransitionToString(transit)
1653 + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001654 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM) {
1655 a = loadAnimationRes(mNextAppTransitionPackage, enter ?
Craig Mautner164d4bb2012-11-26 13:51:23 -08001656 mNextAppTransitionEnter : mNextAppTransitionExit);
1657 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1658 "applyAnimation:"
1659 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001660 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001661 + " Callers=" + Debug.getCallers(3));
Winson Chung044d5292014-11-06 11:05:19 -08001662 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE) {
1663 a = loadAnimationRes(mNextAppTransitionPackage, mNextAppTransitionInPlace);
1664 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1665 "applyAnimation:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001666 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM_IN_PLACE"
1667 + " transit=" + appTransitionToString(transit)
1668 + " Callers=" + Debug.getCallers(3));
Chet Haase10e23ab2015-02-11 15:08:38 -08001669 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001670 a = createClipRevealAnimationLocked(transit, enter, frame, displayFrame);
Chet Haase10e23ab2015-02-11 15:08:38 -08001671 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1672 "applyAnimation:"
1673 + " anim=" + a + " nextAppTransition=ANIM_CLIP_REVEAL"
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001674 + " transit=" + appTransitionToString(transit)
Chet Haase10e23ab2015-02-11 15:08:38 -08001675 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001676 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_SCALE_UP) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001677 a = createScaleUpAnimationLocked(transit, enter, frame);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001678 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1679 "applyAnimation:"
1680 + " anim=" + a + " nextAppTransition=ANIM_SCALE_UP"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001681 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001682 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001683 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
1684 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001685 mNextAppTransitionScaleUp =
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001686 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP);
Winson Chunga4ccb862014-08-22 15:26:27 -07001687 a = createThumbnailEnterExitAnimationLocked(getThumbnailTransitionState(enter),
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001688 frame, transit, taskId);
Winson Chunga4ccb862014-08-22 15:26:27 -07001689 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1690 String animName = mNextAppTransitionScaleUp ?
1691 "ANIM_THUMBNAIL_SCALE_UP" : "ANIM_THUMBNAIL_SCALE_DOWN";
1692 Slog.v(TAG, "applyAnimation:"
1693 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001694 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Winson Chunga4ccb862014-08-22 15:26:27 -07001695 + " Callers=" + Debug.getCallers(3));
1696 }
1697 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
1698 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN) {
1699 mNextAppTransitionScaleUp =
1700 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP);
1701 a = createAspectScaledThumbnailEnterExitAnimationLocked(
Winsonb2024762016-04-05 17:32:30 -07001702 getThumbnailTransitionState(enter), uiMode, orientation, transit, frame,
Matthew Ng43db6d22017-06-27 15:29:39 -07001703 insets, surfaceInsets, stableInsets, freeform, taskId);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001704 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1705 String animName = mNextAppTransitionScaleUp ?
Winson Chunga4ccb862014-08-22 15:26:27 -07001706 "ANIM_THUMBNAIL_ASPECT_SCALE_UP" : "ANIM_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner164d4bb2012-11-26 13:51:23 -08001707 Slog.v(TAG, "applyAnimation:"
1708 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001709 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001710 + " Callers=" + Debug.getCallers(3));
1711 }
Tony Mak83546a82018-01-22 13:56:20 +00001712 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS && enter) {
Jorim Jaggi98a9d202018-03-26 16:17:07 +02001713 a = loadAnimationRes("android",
1714 com.android.internal.R.anim.task_open_enter_cross_profile_apps);
Tony Mak089c35e2017-12-18 20:34:14 +00001715 Slog.v(TAG,
1716 "applyAnimation NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS:"
1717 + " anim=" + a + " transit=" + appTransitionToString(transit)
Jorim Jaggi98a9d202018-03-26 16:17:07 +02001718 + " isEntrance=true" + " Callers=" + Debug.getCallers(3));
Evan Roskycf76bed2019-01-15 10:33:58 -08001719 } else if (transit == TRANSIT_TASK_CHANGE_WINDOWING_MODE) {
1720 // In the absence of a specific adapter, we just want to keep everything stationary.
1721 a = new AlphaAnimation(1.f, 1.f);
1722 a.setDuration(WindowChangeAnimationSpec.ANIMATION_DURATION);
1723 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1724 Slog.v(TAG, "applyAnimation:"
1725 + " anim=" + a + " transit=" + appTransitionToString(transit)
1726 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
1727 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001728 } else {
1729 int animAttr = 0;
1730 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001731 case TRANSIT_ACTIVITY_OPEN:
Jorim Jaggi0a1523d2018-04-19 17:48:38 +02001732 case TRANSIT_TRANSLUCENT_ACTIVITY_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001733 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001734 ? WindowAnimation_activityOpenEnterAnimation
1735 : WindowAnimation_activityOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001736 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001737 case TRANSIT_ACTIVITY_CLOSE:
Jorim Jaggi0a1523d2018-04-19 17:48:38 +02001738 case TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001739 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001740 ? WindowAnimation_activityCloseEnterAnimation
1741 : WindowAnimation_activityCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001742 break;
Jorim Jaggi192086e2016-03-11 17:17:03 +01001743 case TRANSIT_DOCK_TASK_FROM_RECENTS:
Craig Mautner4b71aa12012-12-27 17:20:01 -08001744 case TRANSIT_TASK_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001745 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001746 ? WindowAnimation_taskOpenEnterAnimation
1747 : WindowAnimation_taskOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001748 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001749 case TRANSIT_TASK_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001750 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001751 ? WindowAnimation_taskCloseEnterAnimation
1752 : WindowAnimation_taskCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001753 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001754 case TRANSIT_TASK_TO_FRONT:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001755 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001756 ? WindowAnimation_taskToFrontEnterAnimation
1757 : WindowAnimation_taskToFrontExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001758 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001759 case TRANSIT_TASK_TO_BACK:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001760 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001761 ? WindowAnimation_taskToBackEnterAnimation
1762 : WindowAnimation_taskToBackExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001763 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001764 case TRANSIT_WALLPAPER_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001765 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001766 ? WindowAnimation_wallpaperOpenEnterAnimation
1767 : WindowAnimation_wallpaperOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001768 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001769 case TRANSIT_WALLPAPER_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001770 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001771 ? WindowAnimation_wallpaperCloseEnterAnimation
1772 : WindowAnimation_wallpaperCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001773 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001774 case TRANSIT_WALLPAPER_INTRA_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001775 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001776 ? WindowAnimation_wallpaperIntraOpenEnterAnimation
1777 : WindowAnimation_wallpaperIntraOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001778 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001779 case TRANSIT_WALLPAPER_INTRA_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001780 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001781 ? WindowAnimation_wallpaperIntraCloseEnterAnimation
1782 : WindowAnimation_wallpaperIntraCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001783 break;
Craig Mautnerbb742462014-07-07 15:28:55 -07001784 case TRANSIT_TASK_OPEN_BEHIND:
1785 animAttr = enter
1786 ? WindowAnimation_launchTaskBehindSourceAnimation
Craig Mautner3b2cd1d2014-08-25 14:25:54 -07001787 : WindowAnimation_launchTaskBehindTargetAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001788 }
Jorim Jaggi0a1523d2018-04-19 17:48:38 +02001789 a = animAttr != 0 ? loadAnimationAttr(lp, animAttr, transit) : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001790 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1791 "applyAnimation:"
1792 + " anim=" + a
1793 + " animAttr=0x" + Integer.toHexString(animAttr)
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001794 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001795 + " Callers=" + Debug.getCallers(3));
1796 }
1797 return a;
1798 }
1799
Jorim Jaggife762342016-10-13 14:33:27 +02001800 private Animation loadKeyguardExitAnimation(int transit) {
1801 if ((mNextAppTransitionFlags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_NO_ANIMATION) != 0) {
1802 return null;
1803 }
1804 final boolean toShade =
1805 (mNextAppTransitionFlags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_TO_SHADE) != 0;
Issei Suzuki5609ccb2019-06-13 15:04:08 +02001806 final boolean subtle =
1807 (mNextAppTransitionFlags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_SUBTLE_ANIMATION) != 0;
Jorim Jaggife762342016-10-13 14:33:27 +02001808 return mService.mPolicy.createHiddenByKeyguardExit(
Issei Suzuki5609ccb2019-06-13 15:04:08 +02001809 transit == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER, toShade, subtle);
Jorim Jaggife762342016-10-13 14:33:27 +02001810 }
1811
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001812 int getAppStackClipMode() {
Matthew Ngbf1d9852017-03-14 12:23:09 -07001813 // When dismiss keyguard animation occurs, clip before the animation to prevent docked
1814 // app from showing beyond the divider
1815 if (mNextAppTransition == TRANSIT_KEYGUARD_GOING_AWAY
1816 || mNextAppTransition == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER) {
1817 return STACK_CLIP_BEFORE_ANIM;
1818 }
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001819 return mNextAppTransition == TRANSIT_ACTIVITY_RELAUNCH
Jorim Jaggic69bd222016-03-15 14:38:37 +01001820 || mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
Jorim Jaggi1f458fb2016-03-25 17:36:37 -07001821 || mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001822 ? STACK_CLIP_NONE
1823 : STACK_CLIP_AFTER_ANIM;
1824 }
1825
Jorim Jaggife762342016-10-13 14:33:27 +02001826 public int getTransitFlags() {
1827 return mNextAppTransitionFlags;
1828 }
1829
Craig Mautner164d4bb2012-11-26 13:51:23 -08001830 void postAnimationCallback() {
1831 if (mNextAppTransitionCallback != null) {
lumark23b54592018-10-02 17:17:23 +08001832 mHandler.sendMessage(PooledLambda.obtainMessage(AppTransition::doAnimationCallback,
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001833 mNextAppTransitionCallback));
Craig Mautner164d4bb2012-11-26 13:51:23 -08001834 mNextAppTransitionCallback = null;
1835 }
1836 }
1837
1838 void overridePendingAppTransition(String packageName, int enterAnim, int exitAnim,
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001839 IRemoteCallback startedCallback) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001840 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001841 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001842 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001843 mNextAppTransitionPackage = packageName;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001844 mNextAppTransitionEnter = enterAnim;
1845 mNextAppTransitionExit = exitAnim;
1846 postAnimationCallback();
1847 mNextAppTransitionCallback = startedCallback;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001848 }
1849 }
1850
1851 void overridePendingAppTransitionScaleUp(int startX, int startY, int startWidth,
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001852 int startHeight) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001853 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001854 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001855 mNextAppTransitionType = NEXT_TRANSIT_TYPE_SCALE_UP;
Winson4c3fecd2016-07-13 12:29:48 -07001856 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001857 postAnimationCallback();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001858 }
1859 }
1860
Chet Haase10e23ab2015-02-11 15:08:38 -08001861 void overridePendingAppTransitionClipReveal(int startX, int startY,
1862 int startWidth, int startHeight) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001863 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001864 clear();
Chet Haase10e23ab2015-02-11 15:08:38 -08001865 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CLIP_REVEAL;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001866 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Chet Haase10e23ab2015-02-11 15:08:38 -08001867 postAnimationCallback();
Chet Haase10e23ab2015-02-11 15:08:38 -08001868 }
1869 }
1870
Winson Chungaa7fa012017-05-24 15:50:06 -07001871 void overridePendingAppTransitionThumb(GraphicBuffer srcThumb, int startX, int startY,
Craig Mautner164d4bb2012-11-26 13:51:23 -08001872 IRemoteCallback startedCallback, boolean scaleUp) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001873 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001874 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001875 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP
1876 : NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001877 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001878 putDefaultNextAppTransitionCoordinates(startX, startY, 0, 0, srcThumb);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001879 postAnimationCallback();
1880 mNextAppTransitionCallback = startedCallback;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001881 }
1882 }
1883
Winson Chungaa7fa012017-05-24 15:50:06 -07001884 void overridePendingAppTransitionAspectScaledThumb(GraphicBuffer srcThumb, int startX, int startY,
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001885 int targetWidth, int targetHeight, IRemoteCallback startedCallback, boolean scaleUp) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001886 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001887 clear();
Winson Chunga4ccb862014-08-22 15:26:27 -07001888 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1889 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Winson Chunga4ccb862014-08-22 15:26:27 -07001890 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001891 putDefaultNextAppTransitionCoordinates(startX, startY, targetWidth, targetHeight,
1892 srcThumb);
Winson Chunga4ccb862014-08-22 15:26:27 -07001893 postAnimationCallback();
1894 mNextAppTransitionCallback = startedCallback;
Winson Chunga4ccb862014-08-22 15:26:27 -07001895 }
1896 }
1897
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001898 void overridePendingAppTransitionMultiThumb(AppTransitionAnimationSpec[] specs,
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001899 IRemoteCallback onAnimationStartedCallback, IRemoteCallback onAnimationFinishedCallback,
1900 boolean scaleUp) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001901 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001902 clear();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001903 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1904 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001905 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi43102412015-11-11 16:28:37 +01001906 if (specs != null) {
1907 for (int i = 0; i < specs.length; i++) {
1908 AppTransitionAnimationSpec spec = specs[i];
1909 if (spec != null) {
1910 mNextAppTransitionAnimationsSpecs.put(spec.taskId, spec);
1911 if (i == 0) {
1912 // In full screen mode, the transition code depends on the default spec
1913 // to be set.
1914 Rect rect = spec.rect;
1915 putDefaultNextAppTransitionCoordinates(rect.left, rect.top,
Winson Chungaa7fa012017-05-24 15:50:06 -07001916 rect.width(), rect.height(), spec.buffer);
Jorim Jaggi43102412015-11-11 16:28:37 +01001917 }
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001918 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001919 }
1920 }
1921 postAnimationCallback();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001922 mNextAppTransitionCallback = onAnimationStartedCallback;
1923 mAnimationFinishedCallback = onAnimationFinishedCallback;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001924 }
1925 }
1926
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001927 void overridePendingAppTransitionMultiThumbFuture(
1928 IAppTransitionAnimationSpecsFuture specsFuture, IRemoteCallback callback,
1929 boolean scaleUp) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001930 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001931 clear();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001932 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1933 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001934 mNextAppTransitionAnimationsSpecsFuture = specsFuture;
1935 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001936 mNextAppTransitionFutureCallback = callback;
Riddle Hsuec6467c2019-02-15 00:10:56 +08001937 if (isReady()) {
1938 fetchAppTransitionSpecsFromFuture();
1939 }
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001940 }
1941 }
1942
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001943 void overridePendingAppTransitionRemote(RemoteAnimationAdapter remoteAnimationAdapter) {
Jorim Jaggi346702a2019-05-08 17:49:33 +02001944 if (DEBUG_APP_TRANSITIONS) Slog.i(TAG, "Override pending remote transitionSet="
1945 + isTransitionSet() + " adapter=" + remoteAnimationAdapter);
Winson Chung044d5292014-11-06 11:05:19 -08001946 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001947 clear();
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001948 mNextAppTransitionType = NEXT_TRANSIT_TYPE_REMOTE;
1949 mRemoteAnimationController = new RemoteAnimationController(mService,
lumark23b54592018-10-02 17:17:23 +08001950 remoteAnimationAdapter, mHandler);
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001951 }
1952 }
1953
1954 void overrideInPlaceAppTransition(String packageName, int anim) {
1955 if (canOverridePendingAppTransition()) {
1956 clear();
Winson Chung044d5292014-11-06 11:05:19 -08001957 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE;
1958 mNextAppTransitionPackage = packageName;
1959 mNextAppTransitionInPlace = anim;
Winson Chung044d5292014-11-06 11:05:19 -08001960 }
1961 }
1962
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001963 /**
Tony Mak089c35e2017-12-18 20:34:14 +00001964 * @see {@link #NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS}
1965 */
1966 void overridePendingAppTransitionStartCrossProfileApps() {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001967 if (canOverridePendingAppTransition()) {
Tony Mak089c35e2017-12-18 20:34:14 +00001968 clear();
1969 mNextAppTransitionType = NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS;
1970 postAnimationCallback();
1971 }
1972 }
1973
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001974 private boolean canOverridePendingAppTransition() {
1975 // Remote animations always take precedence
1976 return isTransitionSet() && mNextAppTransitionType != NEXT_TRANSIT_TYPE_REMOTE;
1977 }
1978
Tony Mak089c35e2017-12-18 20:34:14 +00001979 /**
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001980 * If a future is set for the app transition specs, fetch it in another thread.
1981 */
1982 private void fetchAppTransitionSpecsFromFuture() {
1983 if (mNextAppTransitionAnimationsSpecsFuture != null) {
1984 mNextAppTransitionAnimationsSpecsPending = true;
1985 final IAppTransitionAnimationSpecsFuture future
1986 = mNextAppTransitionAnimationsSpecsFuture;
1987 mNextAppTransitionAnimationsSpecsFuture = null;
Jorim Jaggied410b62017-05-05 15:16:14 +02001988 mDefaultExecutor.execute(() -> {
1989 AppTransitionAnimationSpec[] specs = null;
1990 try {
1991 Binder.allowBlocking(future.asBinder());
1992 specs = future.get();
1993 } catch (RemoteException e) {
1994 Slog.w(TAG, "Failed to fetch app transition specs: " + e);
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001995 }
Wale Ogunwaledb485de2018-10-29 09:47:07 -07001996 synchronized (mService.mGlobalLock) {
Jorim Jaggied410b62017-05-05 15:16:14 +02001997 mNextAppTransitionAnimationsSpecsPending = false;
1998 overridePendingAppTransitionMultiThumb(specs,
1999 mNextAppTransitionFutureCallback, null /* finishedCallback */,
2000 mNextAppTransitionScaleUp);
2001 mNextAppTransitionFutureCallback = null;
Jorim Jaggied410b62017-05-05 15:16:14 +02002002 }
2003 mService.requestTraversal();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01002004 });
2005 }
2006 }
2007
Craig Mautner164d4bb2012-11-26 13:51:23 -08002008 @Override
2009 public String toString() {
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07002010 return "mNextAppTransition=" + appTransitionToString(mNextAppTransition);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002011 }
2012
Craig Mautner4b71aa12012-12-27 17:20:01 -08002013 /**
2014 * Returns the human readable name of a window transition.
2015 *
2016 * @param transition The window transition.
2017 * @return The transition symbolic name.
2018 */
2019 public static String appTransitionToString(int transition) {
2020 switch (transition) {
2021 case TRANSIT_UNSET: {
2022 return "TRANSIT_UNSET";
2023 }
2024 case TRANSIT_NONE: {
2025 return "TRANSIT_NONE";
2026 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002027 case TRANSIT_ACTIVITY_OPEN: {
2028 return "TRANSIT_ACTIVITY_OPEN";
2029 }
2030 case TRANSIT_ACTIVITY_CLOSE: {
2031 return "TRANSIT_ACTIVITY_CLOSE";
2032 }
2033 case TRANSIT_TASK_OPEN: {
2034 return "TRANSIT_TASK_OPEN";
2035 }
2036 case TRANSIT_TASK_CLOSE: {
2037 return "TRANSIT_TASK_CLOSE";
2038 }
2039 case TRANSIT_TASK_TO_FRONT: {
2040 return "TRANSIT_TASK_TO_FRONT";
2041 }
2042 case TRANSIT_TASK_TO_BACK: {
2043 return "TRANSIT_TASK_TO_BACK";
2044 }
2045 case TRANSIT_WALLPAPER_CLOSE: {
2046 return "TRANSIT_WALLPAPER_CLOSE";
2047 }
2048 case TRANSIT_WALLPAPER_OPEN: {
2049 return "TRANSIT_WALLPAPER_OPEN";
2050 }
2051 case TRANSIT_WALLPAPER_INTRA_OPEN: {
2052 return "TRANSIT_WALLPAPER_INTRA_OPEN";
2053 }
2054 case TRANSIT_WALLPAPER_INTRA_CLOSE: {
2055 return "TRANSIT_WALLPAPER_INTRA_CLOSE";
2056 }
Craig Mautnerbb742462014-07-07 15:28:55 -07002057 case TRANSIT_TASK_OPEN_BEHIND: {
2058 return "TRANSIT_TASK_OPEN_BEHIND";
2059 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07002060 case TRANSIT_ACTIVITY_RELAUNCH: {
2061 return "TRANSIT_ACTIVITY_RELAUNCH";
2062 }
Jorim Jaggi192086e2016-03-11 17:17:03 +01002063 case TRANSIT_DOCK_TASK_FROM_RECENTS: {
2064 return "TRANSIT_DOCK_TASK_FROM_RECENTS";
2065 }
Jorim Jaggife762342016-10-13 14:33:27 +02002066 case TRANSIT_KEYGUARD_GOING_AWAY: {
2067 return "TRANSIT_KEYGUARD_GOING_AWAY";
2068 }
2069 case TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER: {
2070 return "TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER";
2071 }
2072 case TRANSIT_KEYGUARD_OCCLUDE: {
2073 return "TRANSIT_KEYGUARD_OCCLUDE";
2074 }
2075 case TRANSIT_KEYGUARD_UNOCCLUDE: {
2076 return "TRANSIT_KEYGUARD_UNOCCLUDE";
2077 }
Jorim Jaggi98a9d202018-03-26 16:17:07 +02002078 case TRANSIT_TRANSLUCENT_ACTIVITY_OPEN: {
2079 return "TRANSIT_TRANSLUCENT_ACTIVITY_OPEN";
2080 }
2081 case TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE: {
2082 return "TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE";
2083 }
Jorim Jaggi9c52ebb2018-06-01 14:45:24 +02002084 case TRANSIT_CRASHING_ACTIVITY_CLOSE: {
2085 return "TRANSIT_CRASHING_ACTIVITY_CLOSE";
2086 }
Issei Suzukicac2a502019-04-16 16:52:50 +02002087 case TRANSIT_SHOW_SINGLE_TASK_DISPLAY: {
2088 return "TRANSIT_SHOW_SINGLE_TASK_DISPLAY";
2089 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002090 default: {
Jorim Jaggi9c52ebb2018-06-01 14:45:24 +02002091 return "<UNKNOWN: " + transition + ">";
Craig Mautner4b71aa12012-12-27 17:20:01 -08002092 }
2093 }
2094 }
2095
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002096 private String appStateToString() {
2097 switch (mAppTransitionState) {
2098 case APP_STATE_IDLE:
2099 return "APP_STATE_IDLE";
2100 case APP_STATE_READY:
2101 return "APP_STATE_READY";
2102 case APP_STATE_RUNNING:
2103 return "APP_STATE_RUNNING";
2104 case APP_STATE_TIMEOUT:
2105 return "APP_STATE_TIMEOUT";
2106 default:
2107 return "unknown state=" + mAppTransitionState;
2108 }
2109 }
2110
2111 private String transitTypeToString() {
2112 switch (mNextAppTransitionType) {
2113 case NEXT_TRANSIT_TYPE_NONE:
2114 return "NEXT_TRANSIT_TYPE_NONE";
2115 case NEXT_TRANSIT_TYPE_CUSTOM:
2116 return "NEXT_TRANSIT_TYPE_CUSTOM";
Winson Chung044d5292014-11-06 11:05:19 -08002117 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
2118 return "NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002119 case NEXT_TRANSIT_TYPE_SCALE_UP:
2120 return "NEXT_TRANSIT_TYPE_SCALE_UP";
2121 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
2122 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP";
2123 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
2124 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN";
Winson Chunga4ccb862014-08-22 15:26:27 -07002125 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
2126 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP";
2127 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN:
2128 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN";
Tony Mak64b8d562017-12-28 17:44:02 +00002129 case NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS:
2130 return "NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002131 default:
2132 return "unknown type=" + mNextAppTransitionType;
2133 }
2134 }
2135
Steven Timotiusaf03df62017-07-18 16:56:43 -07002136 void writeToProto(ProtoOutputStream proto, long fieldId) {
2137 final long token = proto.start(fieldId);
2138 proto.write(APP_TRANSITION_STATE, mAppTransitionState);
2139 proto.write(LAST_USED_APP_TRANSITION, mLastUsedAppTransition);
2140 proto.end(token);
2141 }
2142
Craig Mautner164d4bb2012-11-26 13:51:23 -08002143 @Override
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002144 public void dump(PrintWriter pw, String prefix) {
2145 pw.print(prefix); pw.println(this);
2146 pw.print(prefix); pw.print("mAppTransitionState="); pw.println(appStateToString());
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002147 if (mNextAppTransitionType != NEXT_TRANSIT_TYPE_NONE) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002148 pw.print(prefix); pw.print("mNextAppTransitionType=");
2149 pw.println(transitTypeToString());
Craig Mautner164d4bb2012-11-26 13:51:23 -08002150 }
2151 switch (mNextAppTransitionType) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002152 case NEXT_TRANSIT_TYPE_CUSTOM:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002153 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Craig Mautner164d4bb2012-11-26 13:51:23 -08002154 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002155 pw.print(prefix); pw.print("mNextAppTransitionEnter=0x");
Craig Mautner164d4bb2012-11-26 13:51:23 -08002156 pw.print(Integer.toHexString(mNextAppTransitionEnter));
2157 pw.print(" mNextAppTransitionExit=0x");
2158 pw.println(Integer.toHexString(mNextAppTransitionExit));
2159 break;
Winson Chung044d5292014-11-06 11:05:19 -08002160 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002161 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Winson Chung044d5292014-11-06 11:05:19 -08002162 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002163 pw.print(prefix); pw.print("mNextAppTransitionInPlace=0x");
Winson Chung044d5292014-11-06 11:05:19 -08002164 pw.print(Integer.toHexString(mNextAppTransitionInPlace));
2165 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002166 case NEXT_TRANSIT_TYPE_SCALE_UP: {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002167 getDefaultNextAppTransitionStartRect(mTmpRect);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002168 pw.print(prefix); pw.print("mNextAppTransitionStartX=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002169 pw.print(mTmpRect.left);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002170 pw.print(" mNextAppTransitionStartY=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002171 pw.println(mTmpRect.top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002172 pw.print(prefix); pw.print("mNextAppTransitionStartWidth=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002173 pw.print(mTmpRect.width());
Craig Mautner164d4bb2012-11-26 13:51:23 -08002174 pw.print(" mNextAppTransitionStartHeight=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002175 pw.println(mTmpRect.height());
Craig Mautner164d4bb2012-11-26 13:51:23 -08002176 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002177 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002178 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
2179 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
Winson Chunga4ccb862014-08-22 15:26:27 -07002180 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002181 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN: {
2182 pw.print(prefix); pw.print("mDefaultNextAppTransitionAnimationSpec=");
2183 pw.println(mDefaultNextAppTransitionAnimationSpec);
2184 pw.print(prefix); pw.print("mNextAppTransitionAnimationsSpecs=");
2185 pw.println(mNextAppTransitionAnimationsSpecs);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002186 pw.print(prefix); pw.print("mNextAppTransitionScaleUp=");
2187 pw.println(mNextAppTransitionScaleUp);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002188 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002189 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002190 }
2191 if (mNextAppTransitionCallback != null) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002192 pw.print(prefix); pw.print("mNextAppTransitionCallback=");
2193 pw.println(mNextAppTransitionCallback);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002194 }
Chong Zhang60091a92016-07-27 17:52:45 -07002195 if (mLastUsedAppTransition != TRANSIT_NONE) {
2196 pw.print(prefix); pw.print("mLastUsedAppTransition=");
2197 pw.println(appTransitionToString(mLastUsedAppTransition));
2198 pw.print(prefix); pw.print("mLastOpeningApp=");
2199 pw.println(mLastOpeningApp);
2200 pw.print(prefix); pw.print("mLastClosingApp=");
2201 pw.println(mLastClosingApp);
Evan Rosky2289ba12018-11-19 18:28:18 -08002202 pw.print(prefix); pw.print("mLastChangingApp=");
2203 pw.println(mLastChangingApp);
Chong Zhang60091a92016-07-27 17:52:45 -07002204 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002205 }
Amith Yamasani4befbec2013-07-10 16:18:01 -07002206
2207 public void setCurrentUser(int newUserId) {
2208 mCurrentUserId = newUserId;
2209 }
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002210
2211 /**
2212 * @return true if transition is not running and should not be skipped, false if transition is
2213 * already running
2214 */
Jorim Jaggif84e2f62018-01-16 14:17:59 +01002215 boolean prepareAppTransitionLocked(@TransitionType int transit, boolean alwaysKeepCurrent,
2216 @TransitionFlags int flags, boolean forceOverride) {
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002217 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Prepare app transition:"
2218 + " transit=" + appTransitionToString(transit)
2219 + " " + this
2220 + " alwaysKeepCurrent=" + alwaysKeepCurrent
lumark588a3e82018-07-20 18:53:54 +08002221 + " displayId=" + mDisplayContent.getDisplayId()
2222 + " Callers=" + Debug.getCallers(5));
Jorim Jaggi9c52ebb2018-06-01 14:45:24 +02002223 final boolean allowSetCrashing = !isKeyguardTransit(mNextAppTransition)
2224 && transit == TRANSIT_CRASHING_ACTIVITY_CLOSE;
Jorim Jaggife762342016-10-13 14:33:27 +02002225 if (forceOverride || isKeyguardTransit(transit) || !isTransitionSet()
Jorim Jaggi9c52ebb2018-06-01 14:45:24 +02002226 || mNextAppTransition == TRANSIT_NONE || allowSetCrashing) {
Jorim Jaggife762342016-10-13 14:33:27 +02002227 setAppTransition(transit, flags);
Jorim Jaggia69243a2017-06-15 15:10:38 -04002228 }
2229 // We never want to change from a Keyguard transit to a non-Keyguard transit, as our logic
Adrian Roos93577212018-04-10 14:12:10 -07002230 // relies on the fact that we always execute a Keyguard transition after preparing one. We
2231 // also don't want to change away from a crashing transition.
Jorim Jaggi9c52ebb2018-06-01 14:45:24 +02002232 else if (!alwaysKeepCurrent && !isKeyguardTransit(mNextAppTransition)
2233 && mNextAppTransition != TRANSIT_CRASHING_ACTIVITY_CLOSE) {
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002234 if (transit == TRANSIT_TASK_OPEN && isTransitionEqual(TRANSIT_TASK_CLOSE)) {
2235 // Opening a new task always supersedes a close for the anim.
Jorim Jaggife762342016-10-13 14:33:27 +02002236 setAppTransition(transit, flags);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002237 } else if (transit == TRANSIT_ACTIVITY_OPEN
2238 && isTransitionEqual(TRANSIT_ACTIVITY_CLOSE)) {
2239 // Opening a new activity always supersedes a close for the anim.
Jorim Jaggife762342016-10-13 14:33:27 +02002240 setAppTransition(transit, flags);
Jorim Jaggicecf4242018-02-21 18:46:53 +01002241 } else if (isTaskTransit(transit) && isActivityTransit(mNextAppTransition)) {
2242 // Task animations always supersede activity animations, because if we have both, it
2243 // usually means that activity transition were just trampoline activities.
2244 setAppTransition(transit, flags);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002245 }
2246 }
2247 boolean prepared = prepare();
2248 if (isTransitionSet()) {
lumark23b54592018-10-02 17:17:23 +08002249 removeAppTransitionTimeoutCallbacks();
2250 mHandler.postDelayed(mHandleAppTransitionTimeoutRunnable, APP_TRANSITION_TIMEOUT_MS);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002251 }
2252 return prepared;
2253 }
Winsonb2024762016-04-05 17:32:30 -07002254
2255 /**
Jorim Jaggife762342016-10-13 14:33:27 +02002256 * @return true if {@param transit} is representing a transition in which Keyguard is going
2257 * away, false otherwise
2258 */
2259 public static boolean isKeyguardGoingAwayTransit(int transit) {
2260 return transit == TRANSIT_KEYGUARD_GOING_AWAY
2261 || transit == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER;
2262 }
2263
2264 private static boolean isKeyguardTransit(int transit) {
2265 return isKeyguardGoingAwayTransit(transit) || transit == TRANSIT_KEYGUARD_OCCLUDE
2266 || transit == TRANSIT_KEYGUARD_UNOCCLUDE;
2267 }
2268
Jorim Jaggi98a9d202018-03-26 16:17:07 +02002269 static boolean isTaskTransit(int transit) {
2270 return isTaskOpenTransit(transit)
Jorim Jaggicecf4242018-02-21 18:46:53 +01002271 || transit == TRANSIT_TASK_CLOSE
Jorim Jaggicecf4242018-02-21 18:46:53 +01002272 || transit == TRANSIT_TASK_TO_BACK
Jorim Jaggicecf4242018-02-21 18:46:53 +01002273 || transit == TRANSIT_TASK_IN_PLACE;
2274 }
2275
Jorim Jaggi98a9d202018-03-26 16:17:07 +02002276 private static boolean isTaskOpenTransit(int transit) {
2277 return transit == TRANSIT_TASK_OPEN
2278 || transit == TRANSIT_TASK_OPEN_BEHIND
2279 || transit == TRANSIT_TASK_TO_FRONT;
2280 }
2281
2282 static boolean isActivityTransit(int transit) {
Jorim Jaggicecf4242018-02-21 18:46:53 +01002283 return transit == TRANSIT_ACTIVITY_OPEN
2284 || transit == TRANSIT_ACTIVITY_CLOSE
2285 || transit == TRANSIT_ACTIVITY_RELAUNCH;
2286 }
2287
Evan Roskyec9488c2019-03-01 19:32:12 -08002288 static boolean isChangeTransit(int transit) {
2289 return transit == TRANSIT_TASK_CHANGE_WINDOWING_MODE;
2290 }
2291
Jorim Jaggife762342016-10-13 14:33:27 +02002292 /**
Manu Cornetd7376802017-01-13 13:44:07 -08002293 * @return whether the transition should show the thumbnail being scaled down.
2294 */
2295 private boolean shouldScaleDownThumbnailTransition(int uiMode, int orientation) {
Sid Soundararajan0e88d322017-03-07 15:37:30 -08002296 return mGridLayoutRecentsEnabled
Manu Cornetd7376802017-01-13 13:44:07 -08002297 || orientation == Configuration.ORIENTATION_PORTRAIT;
2298 }
lumark23b54592018-10-02 17:17:23 +08002299
2300 private void handleAppTransitionTimeout() {
Wale Ogunwaledb485de2018-10-29 09:47:07 -07002301 synchronized (mService.mGlobalLock) {
lumark588a3e82018-07-20 18:53:54 +08002302 final DisplayContent dc = mDisplayContent;
2303 if (dc == null) {
2304 return;
2305 }
Evan Rosky2289ba12018-11-19 18:28:18 -08002306 if (isTransitionSet() || !dc.mOpeningApps.isEmpty() || !dc.mClosingApps.isEmpty()
2307 || !dc.mChangingApps.isEmpty()) {
lumark23b54592018-10-02 17:17:23 +08002308 if (DEBUG_APP_TRANSITIONS) {
2309 Slog.v(TAG_WM, "*** APP TRANSITION TIMEOUT."
lumark588a3e82018-07-20 18:53:54 +08002310 + " displayId=" + dc.getDisplayId()
lumark23b54592018-10-02 17:17:23 +08002311 + " isTransitionSet()="
lumark588a3e82018-07-20 18:53:54 +08002312 + dc.mAppTransition.isTransitionSet()
2313 + " mOpeningApps.size()=" + dc.mOpeningApps.size()
Evan Rosky2289ba12018-11-19 18:28:18 -08002314 + " mClosingApps.size()=" + dc.mClosingApps.size()
2315 + " mChangingApps.size()=" + dc.mChangingApps.size());
lumark23b54592018-10-02 17:17:23 +08002316 }
2317 setTimeout();
2318 mService.mWindowPlacerLocked.performSurfacePlacement();
2319 }
2320 }
2321 }
2322
2323 private static void doAnimationCallback(@NonNull IRemoteCallback callback) {
2324 try {
2325 ((IRemoteCallback) callback).sendResult(null);
2326 } catch (RemoteException e) {
2327 }
2328 }
2329
2330 void removeAppTransitionTimeoutCallbacks() {
2331 mHandler.removeCallbacks(mHandleAppTransitionTimeoutRunnable);
2332 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002333}