blob: 2f174c2f51708e0a6a70ddf8670c8c32ae42521e [file] [log] [blame]
Craig Mautner164d4bb2012-11-26 13:51:23 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server.wm;
18
Jorim Jaggif84e2f62018-01-16 14:17:59 +010019import static android.view.WindowManager.LayoutParams;
20import static android.view.WindowManager.TRANSIT_ACTIVITY_CLOSE;
21import static android.view.WindowManager.TRANSIT_ACTIVITY_OPEN;
22import static android.view.WindowManager.TRANSIT_ACTIVITY_RELAUNCH;
Adrian Roos93577212018-04-10 14:12:10 -070023import static android.view.WindowManager.TRANSIT_CRASHING_ACTIVITY_CLOSE;
Jorim Jaggif84e2f62018-01-16 14:17:59 +010024import static android.view.WindowManager.TRANSIT_DOCK_TASK_FROM_RECENTS;
25import static android.view.WindowManager.TRANSIT_FLAG_KEYGUARD_GOING_AWAY_NO_ANIMATION;
26import static android.view.WindowManager.TRANSIT_FLAG_KEYGUARD_GOING_AWAY_TO_SHADE;
27import static android.view.WindowManager.TRANSIT_KEYGUARD_GOING_AWAY;
28import static android.view.WindowManager.TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER;
29import static android.view.WindowManager.TRANSIT_KEYGUARD_OCCLUDE;
30import static android.view.WindowManager.TRANSIT_KEYGUARD_UNOCCLUDE;
31import static android.view.WindowManager.TRANSIT_NONE;
32import static android.view.WindowManager.TRANSIT_TASK_CLOSE;
Jorim Jaggicecf4242018-02-21 18:46:53 +010033import static android.view.WindowManager.TRANSIT_TASK_IN_PLACE;
Jorim Jaggif84e2f62018-01-16 14:17:59 +010034import static android.view.WindowManager.TRANSIT_TASK_OPEN;
35import static android.view.WindowManager.TRANSIT_TASK_OPEN_BEHIND;
36import static android.view.WindowManager.TRANSIT_TASK_TO_BACK;
37import static android.view.WindowManager.TRANSIT_TASK_TO_FRONT;
Jorim Jaggi98a9d202018-03-26 16:17:07 +020038import static android.view.WindowManager.TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE;
39import static android.view.WindowManager.TRANSIT_TRANSLUCENT_ACTIVITY_OPEN;
Jorim Jaggif84e2f62018-01-16 14:17:59 +010040import static android.view.WindowManager.TRANSIT_UNSET;
41import static android.view.WindowManager.TRANSIT_WALLPAPER_CLOSE;
42import static android.view.WindowManager.TRANSIT_WALLPAPER_INTRA_CLOSE;
43import static android.view.WindowManager.TRANSIT_WALLPAPER_INTRA_OPEN;
44import static android.view.WindowManager.TRANSIT_WALLPAPER_OPEN;
Tony Mak83546a82018-01-22 13:56:20 +000045
Filip Gruszczynski82861362015-10-16 14:21:09 -070046import static com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation;
47import static com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
48import static com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation;
49import static com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
50import static com.android.internal.R.styleable.WindowAnimation_launchTaskBehindSourceAnimation;
51import static com.android.internal.R.styleable.WindowAnimation_launchTaskBehindTargetAnimation;
52import static com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation;
53import static com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
54import static com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation;
55import static com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
56import static com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation;
57import static com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
58import static com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation;
59import static com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
60import static com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation;
61import static com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
62import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation;
63import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
64import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation;
65import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
66import static com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation;
67import static com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Filip Gruszczynski198dcbf2016-01-18 10:02:00 -080068import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
69import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080070import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
71import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Adrian Roose99bc052017-11-20 17:55:31 +010072import static com.android.server.wm.WindowManagerInternal.AppTransitionListener;
Tony Mak089c35e2017-12-18 20:34:14 +000073import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_AFTER_ANIM;
Matthew Ngbf1d9852017-03-14 12:23:09 -070074import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_BEFORE_ANIM;
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +010075import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_NONE;
Yi Jin6c6e9ca2018-03-20 16:53:35 -070076import static com.android.server.wm.AppTransitionProto.APP_TRANSITION_STATE;
77import static com.android.server.wm.AppTransitionProto.LAST_USED_APP_TRANSITION;
Filip Gruszczynski82861362015-10-16 14:21:09 -070078
Tony Mak64b8d562017-12-28 17:44:02 +000079import android.annotation.DrawableRes;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -070080import android.annotation.Nullable;
Matthew Ng43db6d22017-06-27 15:29:39 -070081import android.app.ActivityManager;
Tony Mak089c35e2017-12-18 20:34:14 +000082import android.content.ComponentName;
Craig Mautner164d4bb2012-11-26 13:51:23 -080083import android.content.Context;
Winson21700932016-03-24 17:26:23 -070084import android.content.res.Configuration;
Todd Kennedy64c57a82018-04-19 15:17:24 -070085import android.content.res.ResourceId;
John Reck519ad482018-02-12 17:08:48 -080086import android.graphics.Bitmap;
87import android.graphics.Canvas;
Tony Mak64b8d562017-12-28 17:44:02 +000088import android.graphics.Color;
Winson Chungaa7fa012017-05-24 15:50:06 -070089import android.graphics.GraphicBuffer;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +010090import android.graphics.Path;
John Reck519ad482018-02-12 17:08:48 -080091import android.graphics.Picture;
Winson Chung399f6202014-03-19 10:47:20 -070092import android.graphics.Rect;
Tony Mak64b8d562017-12-28 17:44:02 +000093import android.graphics.drawable.Drawable;
Jorim Jaggied410b62017-05-05 15:16:14 +020094import android.os.Binder;
Craig Mautner164d4bb2012-11-26 13:51:23 -080095import android.os.Debug;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010096import android.os.IBinder;
Craig Mautner164d4bb2012-11-26 13:51:23 -080097import android.os.IRemoteCallback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010098import android.os.RemoteException;
Jorim Jaggif5f9e122017-10-24 18:21:09 +020099import android.os.SystemClock;
Manu Cornetd7376802017-01-13 13:44:07 -0800100import android.os.SystemProperties;
Tony Mak089c35e2017-12-18 20:34:14 +0000101import android.os.UserHandle;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800102import android.util.ArraySet;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800103import android.util.Slog;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700104import android.util.SparseArray;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700105import android.util.proto.ProtoOutputStream;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700106import android.view.AppTransitionAnimationSpec;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100107import android.view.IAppTransitionAnimationSpecsFuture;
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100108import android.view.RemoteAnimationAdapter;
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100109import android.view.WindowManager.TransitionFlags;
110import android.view.WindowManager.TransitionType;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800111import android.view.animation.AlphaAnimation;
112import android.view.animation.Animation;
113import android.view.animation.AnimationSet;
114import android.view.animation.AnimationUtils;
Winson Chung399f6202014-03-19 10:47:20 -0700115import android.view.animation.ClipRectAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800116import android.view.animation.Interpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700117import android.view.animation.PathInterpolator;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800118import android.view.animation.ScaleAnimation;
Winson Chung399f6202014-03-19 10:47:20 -0700119import android.view.animation.TranslateAnimation;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700120
Jorim Jaggi98a9d202018-03-26 16:17:07 +0200121import com.android.internal.R;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800122import com.android.internal.util.DumpUtils.Dump;
123import com.android.server.AttributeCache;
124import com.android.server.wm.WindowManagerService.H;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800125import com.android.server.wm.animation.ClipRectLRAnimation;
126import com.android.server.wm.animation.ClipRectTBAnimation;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100127import com.android.server.wm.animation.CurvedTranslateAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800128
129import java.io.PrintWriter;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100130import java.util.ArrayList;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100131import java.util.concurrent.ExecutorService;
132import java.util.concurrent.Executors;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800133
Craig Mautner164d4bb2012-11-26 13:51:23 -0800134// State management of app transitions. When we are preparing for a
135// transition, mNextAppTransition will be the kind of transition to
136// perform or TRANSIT_NONE if we are not waiting. If we are waiting,
137// mOpeningApps and mClosingApps are the lists of tokens that will be
138// made visible or hidden at the next transition.
139public class AppTransition implements Dump {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800140 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppTransition" : TAG_WM;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700141 private static final int CLIP_REVEAL_TRANSLATION_Y_DP = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800142
Winson Chunga4ccb862014-08-22 15:26:27 -0700143 /** Fraction of animation at which the recents thumbnail stays completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700144 private static final float RECENTS_THUMBNAIL_FADEIN_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800145 /** Fraction of animation at which the recents thumbnail becomes completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700146 private static final float RECENTS_THUMBNAIL_FADEOUT_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800147
Filip Gruszczynski84fa3352016-01-25 16:28:49 -0800148 static final int DEFAULT_APP_TRANSITION_DURATION = 336;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800149
150 /** Interpolator to be used for animations that respond directly to a touch */
151 static final Interpolator TOUCH_RESPONSE_INTERPOLATOR =
152 new PathInterpolator(0.3f, 0f, 0.1f, 1f);
153
Jorim Jaggic69bd222016-03-15 14:38:37 +0100154 private static final Interpolator THUMBNAIL_DOCK_INTERPOLATOR =
155 new PathInterpolator(0.85f, 0f, 1f, 1f);
156
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800157 /**
158 * Maximum duration for the clip reveal animation. This is used when there is a lot of movement
159 * involved, to make it more understandable.
160 */
161 private static final int MAX_CLIP_REVEAL_TRANSITION_DURATION = 420;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700162 private static final int THUMBNAIL_APP_TRANSITION_DURATION = 336;
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700163 private static final long APP_TRANSITION_TIMEOUT_MS = 5000;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800164
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800165 private final Context mContext;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800166 private final WindowManagerService mService;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800167
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100168 private @TransitionType int mNextAppTransition = TRANSIT_UNSET;
169 private @TransitionFlags int mNextAppTransitionFlags = 0;
Chong Zhang60091a92016-07-27 17:52:45 -0700170 private int mLastUsedAppTransition = TRANSIT_UNSET;
171 private String mLastOpeningApp;
172 private String mLastClosingApp;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800173
174 private static final int NEXT_TRANSIT_TYPE_NONE = 0;
175 private static final int NEXT_TRANSIT_TYPE_CUSTOM = 1;
176 private static final int NEXT_TRANSIT_TYPE_SCALE_UP = 2;
177 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP = 3;
178 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN = 4;
Winson Chunga4ccb862014-08-22 15:26:27 -0700179 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP = 5;
180 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN = 6;
Winson Chung044d5292014-11-06 11:05:19 -0800181 private static final int NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE = 7;
Chet Haase10e23ab2015-02-11 15:08:38 -0800182 private static final int NEXT_TRANSIT_TYPE_CLIP_REVEAL = 8;
Tony Mak089c35e2017-12-18 20:34:14 +0000183
184 /**
185 * Refers to the transition to activity started by using {@link
186 * android.content.pm.crossprofile.CrossProfileApps#startMainActivity(ComponentName, UserHandle)
187 * }.
188 */
189 private static final int NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS = 9;
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100190 private static final int NEXT_TRANSIT_TYPE_REMOTE = 10;
191
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800192 private int mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
193
Winson Chung399f6202014-03-19 10:47:20 -0700194 // These are the possible states for the enter/exit activities during a thumbnail transition
195 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_UP = 0;
196 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_UP = 1;
197 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN = 2;
198 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN = 3;
199
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800200 private String mNextAppTransitionPackage;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800201 // Used for thumbnail transitions. True if we're scaling up, false if scaling down
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800202 private boolean mNextAppTransitionScaleUp;
203 private IRemoteCallback mNextAppTransitionCallback;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +0100204 private IRemoteCallback mNextAppTransitionFutureCallback;
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -0700205 private IRemoteCallback mAnimationFinishedCallback;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800206 private int mNextAppTransitionEnter;
207 private int mNextAppTransitionExit;
Winson Chung044d5292014-11-06 11:05:19 -0800208 private int mNextAppTransitionInPlace;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700209
210 // Keyed by task id.
211 private final SparseArray<AppTransitionAnimationSpec> mNextAppTransitionAnimationsSpecs
212 = new SparseArray<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100213 private IAppTransitionAnimationSpecsFuture mNextAppTransitionAnimationsSpecsFuture;
214 private boolean mNextAppTransitionAnimationsSpecsPending;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700215 private AppTransitionAnimationSpec mDefaultNextAppTransitionAnimationSpec;
216
Winson Chunga4ccb862014-08-22 15:26:27 -0700217 private Rect mNextAppTransitionInsets = new Rect();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800218
Winson Chung2820c452014-04-15 15:34:44 -0700219 private Rect mTmpFromClipRect = new Rect();
220 private Rect mTmpToClipRect = new Rect();
221
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700222 private final Rect mTmpRect = new Rect();
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700223
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800224 private final static int APP_STATE_IDLE = 0;
225 private final static int APP_STATE_READY = 1;
226 private final static int APP_STATE_RUNNING = 2;
227 private final static int APP_STATE_TIMEOUT = 3;
228 private int mAppTransitionState = APP_STATE_IDLE;
229
230 private final int mConfigShortAnimTime;
Craig Mautner321bdf52012-12-18 09:53:24 -0800231 private final Interpolator mDecelerateInterpolator;
Winson Chunga4ccb862014-08-22 15:26:27 -0700232 private final Interpolator mThumbnailFadeInInterpolator;
233 private final Interpolator mThumbnailFadeOutInterpolator;
Chet Haase10e23ab2015-02-11 15:08:38 -0800234 private final Interpolator mLinearOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700235 private final Interpolator mFastOutLinearInInterpolator;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100236 private final Interpolator mFastOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700237 private final Interpolator mClipHorizontalInterpolator = new PathInterpolator(0, 0, 0.4f, 1f);
238
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700239 private final int mClipRevealTranslationY;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800240
Amith Yamasani4befbec2013-07-10 16:18:01 -0700241 private int mCurrentUserId = 0;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800242 private long mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Amith Yamasani4befbec2013-07-10 16:18:01 -0700243
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100244 private final ArrayList<AppTransitionListener> mListeners = new ArrayList<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100245 private final ExecutorService mDefaultExecutor = Executors.newSingleThreadExecutor();
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100246
Jorim Jaggif97ed922016-02-18 18:57:07 -0800247 private int mLastClipRevealMaxTranslation;
248 private boolean mLastHadClipReveal;
249
Manu Cornetd7376802017-01-13 13:44:07 -0800250 private final boolean mGridLayoutRecentsEnabled;
Matthew Ng43db6d22017-06-27 15:29:39 -0700251 private final boolean mLowRamRecentsEnabled;
Manu Cornetd7376802017-01-13 13:44:07 -0800252
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100253 private RemoteAnimationController mRemoteAnimationController;
254
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800255 AppTransition(Context context, WindowManagerService service) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800256 mContext = context;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800257 mService = service;
Chet Haase10e23ab2015-02-11 15:08:38 -0800258 mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
259 com.android.internal.R.interpolator.linear_out_slow_in);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700260 mFastOutLinearInInterpolator = AnimationUtils.loadInterpolator(context,
261 com.android.internal.R.interpolator.fast_out_linear_in);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100262 mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
263 com.android.internal.R.interpolator.fast_out_slow_in);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800264 mConfigShortAnimTime = context.getResources().getInteger(
265 com.android.internal.R.integer.config_shortAnimTime);
Craig Mautner321bdf52012-12-18 09:53:24 -0800266 mDecelerateInterpolator = AnimationUtils.loadInterpolator(context,
267 com.android.internal.R.interpolator.decelerate_cubic);
Winson Chunga4ccb862014-08-22 15:26:27 -0700268 mThumbnailFadeInInterpolator = new Interpolator() {
269 @Override
270 public float getInterpolation(float input) {
271 // Linear response for first fraction, then complete after that.
272 if (input < RECENTS_THUMBNAIL_FADEIN_FRACTION) {
273 return 0f;
274 }
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700275 float t = (input - RECENTS_THUMBNAIL_FADEIN_FRACTION) /
Winson Chunga4ccb862014-08-22 15:26:27 -0700276 (1f - RECENTS_THUMBNAIL_FADEIN_FRACTION);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700277 return mFastOutLinearInInterpolator.getInterpolation(t);
Winson Chunga4ccb862014-08-22 15:26:27 -0700278 }
279 };
280 mThumbnailFadeOutInterpolator = new Interpolator() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800281 @Override
282 public float getInterpolation(float input) {
283 // Linear response for first fraction, then complete after that.
284 if (input < RECENTS_THUMBNAIL_FADEOUT_FRACTION) {
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700285 float t = input / RECENTS_THUMBNAIL_FADEOUT_FRACTION;
286 return mLinearOutSlowInInterpolator.getInterpolation(t);
Craig Mautner321bdf52012-12-18 09:53:24 -0800287 }
Winson Chunga4ccb862014-08-22 15:26:27 -0700288 return 1f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800289 }
290 };
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700291 mClipRevealTranslationY = (int) (CLIP_REVEAL_TRANSLATION_Y_DP
292 * mContext.getResources().getDisplayMetrics().density);
Manu Cornetd7376802017-01-13 13:44:07 -0800293 mGridLayoutRecentsEnabled = SystemProperties.getBoolean("ro.recents.grid", false);
Matthew Ng43db6d22017-06-27 15:29:39 -0700294 mLowRamRecentsEnabled = ActivityManager.isLowRamDeviceStatic();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800295 }
296
297 boolean isTransitionSet() {
298 return mNextAppTransition != TRANSIT_UNSET;
299 }
300
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100301 boolean isTransitionEqual(@TransitionType int transit) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800302 return mNextAppTransition == transit;
303 }
304
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100305 @TransitionType int getAppTransition() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800306 return mNextAppTransition;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800307 }
308
Jorim Jaggife762342016-10-13 14:33:27 +0200309 private void setAppTransition(int transit, int flags) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800310 mNextAppTransition = transit;
Jorim Jaggife762342016-10-13 14:33:27 +0200311 mNextAppTransitionFlags |= flags;
Chong Zhang60091a92016-07-27 17:52:45 -0700312 setLastAppTransition(TRANSIT_UNSET, null, null);
Jorim Jaggi245281c2017-06-07 14:33:04 -0700313 updateBooster();
Chong Zhang60091a92016-07-27 17:52:45 -0700314 }
315
316 void setLastAppTransition(int transit, AppWindowToken openingApp, AppWindowToken closingApp) {
317 mLastUsedAppTransition = transit;
318 mLastOpeningApp = "" + openingApp;
319 mLastClosingApp = "" + closingApp;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800320 }
321
322 boolean isReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800323 return mAppTransitionState == APP_STATE_READY
324 || mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800325 }
326
Craig Mautnerae446592012-12-06 19:05:05 -0800327 void setReady() {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700328 setAppTransitionState(APP_STATE_READY);
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100329 fetchAppTransitionSpecsFromFuture();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800330 }
331
332 boolean isRunning() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800333 return mAppTransitionState == APP_STATE_RUNNING;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800334 }
335
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800336 void setIdle() {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700337 setAppTransitionState(APP_STATE_IDLE);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800338 }
339
340 boolean isTimeout() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800341 return mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800342 }
343
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800344 void setTimeout() {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700345 setAppTransitionState(APP_STATE_TIMEOUT);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800346 }
347
Winson Chungaa7fa012017-05-24 15:50:06 -0700348 GraphicBuffer getAppTransitionThumbnailHeader(int taskId) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700349 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800350 if (spec == null) {
351 spec = mDefaultNextAppTransitionAnimationSpec;
352 }
Winson Chungaa7fa012017-05-24 15:50:06 -0700353 return spec != null ? spec.buffer : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800354 }
355
Winson Chunga4ccb862014-08-22 15:26:27 -0700356 /** Returns whether the next thumbnail transition is aspect scaled up. */
357 boolean isNextThumbnailTransitionAspectScaled() {
358 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
359 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
360 }
361
362 /** Returns whether the next thumbnail transition is scaling up. */
363 boolean isNextThumbnailTransitionScaleUp() {
364 return mNextAppTransitionScaleUp;
365 }
366
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -0800367 boolean isNextAppTransitionThumbnailUp() {
368 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
369 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP;
370 }
371
372 boolean isNextAppTransitionThumbnailDown() {
373 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN ||
374 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
375 }
376
Tony Mak64b8d562017-12-28 17:44:02 +0000377
378 boolean isNextAppTransitionOpenCrossProfileApps() {
379 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS;
380 }
381
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100382 /**
383 * @return true if and only if we are currently fetching app transition specs from the future
384 * passed into {@link #overridePendingAppTransitionMultiThumbFuture}
385 */
386 boolean isFetchingAppTransitionsSpecs() {
387 return mNextAppTransitionAnimationsSpecsPending;
388 }
389
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700390 private boolean prepare() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800391 if (!isRunning()) {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700392 setAppTransitionState(APP_STATE_IDLE);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100393 notifyAppTransitionPendingLocked();
Jorim Jaggif97ed922016-02-18 18:57:07 -0800394 mLastHadClipReveal = false;
395 mLastClipRevealMaxTranslation = 0;
396 mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700397 return true;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800398 }
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700399 return false;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800400 }
401
Jorim Jaggife762342016-10-13 14:33:27 +0200402 /**
403 * @return bit-map of WindowManagerPolicy#FINISH_LAYOUT_REDO_* to indicate whether another
404 * layout pass needs to be done
405 */
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200406 int goodToGo(int transit, AppWindowToken topOpeningApp,
407 AppWindowToken topClosingApp, ArraySet<AppWindowToken> openingApps,
Jorim Jaggife762342016-10-13 14:33:27 +0200408 ArraySet<AppWindowToken> closingApps) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800409 mNextAppTransition = TRANSIT_UNSET;
Jorim Jaggife762342016-10-13 14:33:27 +0200410 mNextAppTransitionFlags = 0;
Jorim Jaggi245281c2017-06-07 14:33:04 -0700411 setAppTransitionState(APP_STATE_RUNNING);
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200412 final AnimationAdapter topOpeningAnim = topOpeningApp != null
413 ? topOpeningApp.getAnimation()
414 : null;
Jorim Jaggife762342016-10-13 14:33:27 +0200415 int redoLayout = notifyAppTransitionStartingLocked(transit,
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200416 topOpeningApp != null ? topOpeningApp.token : null,
417 topClosingApp != null ? topClosingApp.token : null,
418 topOpeningAnim != null ? topOpeningAnim.getDurationHint() : 0,
419 topOpeningAnim != null
420 ? topOpeningAnim.getStatusBarTransitionsStartTime()
421 : SystemClock.uptimeMillis(),
422 AnimationAdapter.STATUS_BAR_TRANSITION_DURATION);
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800423 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Jorim Jaggife762342016-10-13 14:33:27 +0200424 .notifyAppTransitionStarting(openingApps, transit);
Jorim Jaggi363ab982016-04-26 19:51:20 -0700425
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100426 if (mRemoteAnimationController != null) {
427 mRemoteAnimationController.goodToGo();
428 }
Jorim Jaggife762342016-10-13 14:33:27 +0200429 return redoLayout;
Jorim Jaggi363ab982016-04-26 19:51:20 -0700430 }
431
Craig Mautner164d4bb2012-11-26 13:51:23 -0800432 void clear() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800433 mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800434 mNextAppTransitionPackage = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700435 mNextAppTransitionAnimationsSpecs.clear();
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100436 mRemoteAnimationController = null;
Jorim Jaggi65193992015-11-23 16:49:59 -0800437 mNextAppTransitionAnimationsSpecsFuture = null;
438 mDefaultNextAppTransitionAnimationSpec = null;
439 mAnimationFinishedCallback = null;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800440 }
441
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800442 void freeze() {
Jorim Jaggife762342016-10-13 14:33:27 +0200443 final int transit = mNextAppTransition;
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100444 setAppTransition(TRANSIT_UNSET, 0 /* flags */);
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800445 clear();
446 setReady();
Jorim Jaggife762342016-10-13 14:33:27 +0200447 notifyAppTransitionCancelledLocked(transit);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100448 }
449
Jorim Jaggi245281c2017-06-07 14:33:04 -0700450 private void setAppTransitionState(int state) {
451 mAppTransitionState = state;
452 updateBooster();
453 }
454
455 /**
456 * Updates whether we currently boost wm locked sections and the animation thread. We want to
457 * boost the priorities to a more important value whenever an app transition is going to happen
458 * soon or an app transition is running.
459 */
Jorim Jaggic8cc2292018-03-15 20:16:15 +0100460 void updateBooster() {
461 WindowManagerService.sThreadPriorityBooster.setAppTransitionRunning(needsBoosting());
462 }
463
464 private boolean needsBoosting() {
465 final boolean recentsAnimRunning = mService.getRecentsAnimationController() != null;
466 return mNextAppTransition != TRANSIT_UNSET
467 || mAppTransitionState == APP_STATE_READY
468 || mAppTransitionState == APP_STATE_RUNNING
469 || recentsAnimRunning;
Jorim Jaggi245281c2017-06-07 14:33:04 -0700470 }
471
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100472 void registerListenerLocked(AppTransitionListener listener) {
473 mListeners.add(listener);
474 }
475
Wale Ogunwalea48eadb2015-05-14 17:43:12 -0700476 public void notifyAppTransitionFinishedLocked(IBinder token) {
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100477 for (int i = 0; i < mListeners.size(); i++) {
478 mListeners.get(i).onAppTransitionFinishedLocked(token);
479 }
480 }
481
482 private void notifyAppTransitionPendingLocked() {
483 for (int i = 0; i < mListeners.size(); i++) {
484 mListeners.get(i).onAppTransitionPendingLocked();
485 }
486 }
487
Jorim Jaggife762342016-10-13 14:33:27 +0200488 private void notifyAppTransitionCancelledLocked(int transit) {
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100489 for (int i = 0; i < mListeners.size(); i++) {
Jorim Jaggife762342016-10-13 14:33:27 +0200490 mListeners.get(i).onAppTransitionCancelledLocked(transit);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100491 }
492 }
493
Jorim Jaggife762342016-10-13 14:33:27 +0200494 private int notifyAppTransitionStartingLocked(int transit, IBinder openToken,
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200495 IBinder closeToken, long duration, long statusBarAnimationStartTime,
496 long statusBarAnimationDuration) {
Jorim Jaggife762342016-10-13 14:33:27 +0200497 int redoLayout = 0;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100498 for (int i = 0; i < mListeners.size(); i++) {
Jorim Jaggife762342016-10-13 14:33:27 +0200499 redoLayout |= mListeners.get(i).onAppTransitionStartingLocked(transit, openToken,
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200500 closeToken, duration, statusBarAnimationStartTime, statusBarAnimationDuration);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100501 }
Jorim Jaggife762342016-10-13 14:33:27 +0200502 return redoLayout;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800503 }
504
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100505 private AttributeCache.Entry getCachedAnimations(LayoutParams lp) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800506 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg="
507 + (lp != null ? lp.packageName : null)
508 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
509 if (lp != null && lp.windowAnimations != 0) {
510 // If this is a system resource, don't try to load it from the
511 // application resources. It is nice to avoid loading application
512 // resources if we can.
513 String packageName = lp.packageName != null ? lp.packageName : "android";
514 int resId = lp.windowAnimations;
515 if ((resId&0xFF000000) == 0x01000000) {
516 packageName = "android";
517 }
518 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
519 + packageName);
520 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700521 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800522 }
523 return null;
524 }
525
526 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
527 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package="
528 + packageName + " resId=0x" + Integer.toHexString(resId));
529 if (packageName != null) {
530 if ((resId&0xFF000000) == 0x01000000) {
531 packageName = "android";
532 }
533 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
534 + packageName);
535 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700536 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800537 }
538 return null;
539 }
540
Jorim Jaggi0a1523d2018-04-19 17:48:38 +0200541 Animation loadAnimationAttr(LayoutParams lp, int animAttr, int transit) {
Todd Kennedy64c57a82018-04-19 15:17:24 -0700542 int resId = ResourceId.ID_NULL;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800543 Context context = mContext;
Jorim Jaggi5f95b002018-04-19 13:27:52 +0000544 if (animAttr >= 0) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800545 AttributeCache.Entry ent = getCachedAnimations(lp);
546 if (ent != null) {
547 context = ent.context;
Todd Kennedy64c57a82018-04-19 15:17:24 -0700548 resId = ent.array.getResourceId(animAttr, 0);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800549 }
550 }
Todd Kennedy64c57a82018-04-19 15:17:24 -0700551 resId = updateToTranslucentAnimIfNeeded(resId, transit);
552 if (ResourceId.isValid(resId)) {
553 return AnimationUtils.loadAnimation(context, resId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800554 }
555 return null;
556 }
557
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100558 Animation loadAnimationRes(LayoutParams lp, int resId) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700559 Context context = mContext;
Todd Kennedy64c57a82018-04-19 15:17:24 -0700560 if (ResourceId.isValid(resId)) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700561 AttributeCache.Entry ent = getCachedAnimations(lp);
562 if (ent != null) {
563 context = ent.context;
564 }
565 return AnimationUtils.loadAnimation(context, resId);
566 }
567 return null;
568 }
569
570 private Animation loadAnimationRes(String packageName, int resId) {
Todd Kennedy64c57a82018-04-19 15:17:24 -0700571 if (ResourceId.isValid(resId)) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800572 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
573 if (ent != null) {
Todd Kennedy64c57a82018-04-19 15:17:24 -0700574 return AnimationUtils.loadAnimation(ent.context, resId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800575 }
576 }
Craig Mautner164d4bb2012-11-26 13:51:23 -0800577 return null;
578 }
579
Jorim Jaggi0a1523d2018-04-19 17:48:38 +0200580 private int updateToTranslucentAnimIfNeeded(int anim, int transit) {
581 if (transit == TRANSIT_TRANSLUCENT_ACTIVITY_OPEN && anim == R.anim.activity_open_enter) {
582 return R.anim.activity_translucent_open_enter;
583 }
584 if (transit == TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE && anim == R.anim.activity_close_exit) {
585 return R.anim.activity_translucent_close_exit;
586 }
587 return anim;
588 }
589
Craig Mautner164d4bb2012-11-26 13:51:23 -0800590 /**
591 * Compute the pivot point for an animation that is scaling from a small
592 * rect on screen to a larger rect. The pivot point varies depending on
593 * the distance between the inner and outer edges on both sides. This
594 * function computes the pivot point for one dimension.
595 * @param startPos Offset from left/top edge of outer rectangle to
596 * left/top edge of inner rectangle.
597 * @param finalScale The scaling factor between the size of the outer
598 * and inner rectangles.
599 */
600 private static float computePivot(int startPos, float finalScale) {
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800601
602 /*
603 Theorem of intercepting lines:
604
605 + + +-----------------------------------------------+
606 | | | |
607 | | | |
608 | | | |
609 | | | |
610 x | y | | |
611 | | | |
612 | | | |
613 | | | |
614 | | | |
615 | + | +--------------------+ |
616 | | | | |
617 | | | | |
618 | | | | |
619 | | | | |
620 | | | | |
621 | | | | |
622 | | | | |
623 | | | | |
624 | | | | |
625 | | | | |
626 | | | | |
627 | | | | |
628 | | | | |
629 | | | | |
630 | | | | |
631 | | | | |
632 | | | | |
633 | | +--------------------+ |
634 | | |
635 | | |
636 | | |
637 | | |
638 | | |
639 | | |
640 | | |
641 | +-----------------------------------------------+
642 |
643 |
644 |
645 |
646 |
647 |
648 |
649 |
650 |
651 + ++
652 p ++
653
654 scale = (x - y) / x
655 <=> x = -y / (scale - 1)
656 */
Craig Mautner164d4bb2012-11-26 13:51:23 -0800657 final float denom = finalScale-1;
658 if (Math.abs(denom) < .0001f) {
659 return startPos;
660 }
661 return -startPos / denom;
662 }
663
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700664 private Animation createScaleUpAnimationLocked(int transit, boolean enter,
665 Rect containingFrame) {
666 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700667 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700668 final int appWidth = containingFrame.width();
669 final int appHeight = containingFrame.height();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800670 if (enter) {
671 // Entering app zooms out from the center of the initial rect.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700672 float scaleW = mTmpRect.width() / (float) appWidth;
673 float scaleH = mTmpRect.height() / (float) appHeight;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800674 Animation scale = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700675 computePivot(mTmpRect.left, scaleW),
Winson4c3fecd2016-07-13 12:29:48 -0700676 computePivot(mTmpRect.top, scaleH));
Craig Mautner321bdf52012-12-18 09:53:24 -0800677 scale.setInterpolator(mDecelerateInterpolator);
678
Craig Mautner164d4bb2012-11-26 13:51:23 -0800679 Animation alpha = new AlphaAnimation(0, 1);
Winson Chunga4ccb862014-08-22 15:26:27 -0700680 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
Craig Mautner321bdf52012-12-18 09:53:24 -0800681
682 AnimationSet set = new AnimationSet(false);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800683 set.addAnimation(scale);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800684 set.addAnimation(alpha);
685 set.setDetachWallpaper(true);
686 a = set;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800687 } else if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
688 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800689 // If we are on top of the wallpaper, we need an animation that
690 // correctly handles the wallpaper staying static behind all of
691 // the animated elements. To do this, will just have the existing
692 // element fade out.
693 a = new AlphaAnimation(1, 0);
694 a.setDetachWallpaper(true);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800695 } else {
Craig Mautner321bdf52012-12-18 09:53:24 -0800696 // For normal animations, the exiting element just holds in place.
697 a = new AlphaAnimation(1, 1);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800698 }
Craig Mautner321bdf52012-12-18 09:53:24 -0800699
700 // Pick the desired duration. If this is an inter-activity transition,
701 // it is the standard duration for that. Otherwise we use the longer
702 // task transition duration.
703 final long duration;
704 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800705 case TRANSIT_ACTIVITY_OPEN:
706 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800707 duration = mConfigShortAnimTime;
708 break;
709 default:
710 duration = DEFAULT_APP_TRANSITION_DURATION;
711 break;
712 }
713 a.setDuration(duration);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800714 a.setFillAfter(true);
Craig Mautner321bdf52012-12-18 09:53:24 -0800715 a.setInterpolator(mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800716 a.initialize(appWidth, appHeight, appWidth, appHeight);
717 return a;
718 }
719
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700720 private void getDefaultNextAppTransitionStartRect(Rect rect) {
721 if (mDefaultNextAppTransitionAnimationSpec == null ||
722 mDefaultNextAppTransitionAnimationSpec.rect == null) {
Jorim Jaggi2550f3f2017-03-14 20:15:59 +0100723 Slog.e(TAG, "Starting rect for app requested, but none available", new Throwable());
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700724 rect.setEmpty();
725 } else {
726 rect.set(mDefaultNextAppTransitionAnimationSpec.rect);
727 }
728 }
729
730 void getNextAppTransitionStartRect(int taskId, Rect rect) {
731 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800732 if (spec == null) {
733 spec = mDefaultNextAppTransitionAnimationSpec;
734 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700735 if (spec == null || spec.rect == null) {
Jorim Jaggi2550f3f2017-03-14 20:15:59 +0100736 Slog.e(TAG, "Starting rect for task: " + taskId + " requested, but not available",
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700737 new Throwable());
738 rect.setEmpty();
739 } else {
740 rect.set(spec.rect);
741 }
742 }
743
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800744 private void putDefaultNextAppTransitionCoordinates(int left, int top, int width, int height,
Winson Chungaa7fa012017-05-24 15:50:06 -0700745 GraphicBuffer buffer) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700746 mDefaultNextAppTransitionAnimationSpec = new AppTransitionAnimationSpec(-1 /* taskId */,
Winson Chungaa7fa012017-05-24 15:50:06 -0700747 buffer, new Rect(left, top, left + width, top + height));
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700748 }
749
Jorim Jaggif97ed922016-02-18 18:57:07 -0800750 /**
751 * @return the duration of the last clip reveal animation
752 */
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800753 long getLastClipRevealTransitionDuration() {
754 return mLastClipRevealTransitionDuration;
755 }
756
757 /**
Jorim Jaggif97ed922016-02-18 18:57:07 -0800758 * @return the maximum distance the app surface is traveling of the last clip reveal animation
759 */
760 int getLastClipRevealMaxTranslation() {
761 return mLastClipRevealMaxTranslation;
762 }
763
764 /**
765 * @return true if in the last app transition had a clip reveal animation, false otherwise
766 */
767 boolean hadClipRevealAnimation() {
768 return mLastHadClipReveal;
769 }
770
771 /**
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800772 * Calculates the duration for the clip reveal animation. If the clip is "cut off", meaning that
773 * the start rect is outside of the target rect, and there is a lot of movement going on.
774 *
775 * @param cutOff whether the start rect was not fully contained by the end rect
776 * @param translationX the total translation the surface moves in x direction
777 * @param translationY the total translation the surfaces moves in y direction
778 * @param displayFrame our display frame
779 *
780 * @return the duration of the clip reveal animation, in milliseconds
781 */
782 private long calculateClipRevealTransitionDuration(boolean cutOff, float translationX,
783 float translationY, Rect displayFrame) {
784 if (!cutOff) {
785 return DEFAULT_APP_TRANSITION_DURATION;
786 }
787 final float fraction = Math.max(Math.abs(translationX) / displayFrame.width(),
788 Math.abs(translationY) / displayFrame.height());
789 return (long) (DEFAULT_APP_TRANSITION_DURATION + fraction *
790 (MAX_CLIP_REVEAL_TRANSITION_DURATION - DEFAULT_APP_TRANSITION_DURATION));
791 }
792
793 private Animation createClipRevealAnimationLocked(int transit, boolean enter, Rect appFrame,
794 Rect displayFrame) {
Chet Haase10e23ab2015-02-11 15:08:38 -0800795 final Animation anim;
796 if (enter) {
Craig Mautner80b1f642015-04-22 10:59:09 -0700797 final int appWidth = appFrame.width();
798 final int appHeight = appFrame.height();
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800799
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700800 // mTmpRect will contain an area around the launcher icon that was pressed. We will
Filip Gruszczynski82861362015-10-16 14:21:09 -0700801 // clip reveal from that area in the final area of the app.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700802 getDefaultNextAppTransitionStartRect(mTmpRect);
Craig Mautner80b1f642015-04-22 10:59:09 -0700803
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700804 float t = 0f;
805 if (appHeight > 0) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800806 t = (float) mTmpRect.top / displayFrame.height();
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700807 }
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800808 int translationY = mClipRevealTranslationY + (int)(displayFrame.height() / 7f * t);
809 int translationX = 0;
810 int translationYCorrection = translationY;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700811 int centerX = mTmpRect.centerX();
812 int centerY = mTmpRect.centerY();
813 int halfWidth = mTmpRect.width() / 2;
814 int halfHeight = mTmpRect.height() / 2;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800815 int clipStartX = centerX - halfWidth - appFrame.left;
816 int clipStartY = centerY - halfHeight - appFrame.top;
817 boolean cutOff = false;
818
819 // If the starting rectangle is fully or partially outside of the target rectangle, we
820 // need to start the clipping at the edge and then achieve the rest with translation
821 // and extending the clip rect from that edge.
822 if (appFrame.top > centerY - halfHeight) {
823 translationY = (centerY - halfHeight) - appFrame.top;
824 translationYCorrection = 0;
825 clipStartY = 0;
826 cutOff = true;
827 }
828 if (appFrame.left > centerX - halfWidth) {
829 translationX = (centerX - halfWidth) - appFrame.left;
830 clipStartX = 0;
831 cutOff = true;
832 }
833 if (appFrame.right < centerX + halfWidth) {
834 translationX = (centerX + halfWidth) - appFrame.right;
835 clipStartX = appWidth - mTmpRect.width();
836 cutOff = true;
837 }
838 final long duration = calculateClipRevealTransitionDuration(cutOff, translationX,
839 translationY, displayFrame);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700840
841 // Clip third of the from size of launch icon, expand to full width/height
Chet Haase10e23ab2015-02-11 15:08:38 -0800842 Animation clipAnimLR = new ClipRectLRAnimation(
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800843 clipStartX, clipStartX + mTmpRect.width(), 0, appWidth);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700844 clipAnimLR.setInterpolator(mClipHorizontalInterpolator);
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800845 clipAnimLR.setDuration((long) (duration / 2.5f));
Filip Gruszczynski82861362015-10-16 14:21:09 -0700846
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800847 TranslateAnimation translate = new TranslateAnimation(translationX, 0, translationY, 0);
848 translate.setInterpolator(cutOff ? TOUCH_RESPONSE_INTERPOLATOR
849 : mLinearOutSlowInInterpolator);
850 translate.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800851
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800852 Animation clipAnimTB = new ClipRectTBAnimation(
853 clipStartY, clipStartY + mTmpRect.height(),
854 0, appHeight,
855 translationYCorrection, 0,
856 mLinearOutSlowInInterpolator);
857 clipAnimTB.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
858 clipAnimTB.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800859
860 // Quick fade-in from icon to app window
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800861 final long alphaDuration = duration / 4;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700862 AlphaAnimation alpha = new AlphaAnimation(0.5f, 1);
Chet Haase10e23ab2015-02-11 15:08:38 -0800863 alpha.setDuration(alphaDuration);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700864 alpha.setInterpolator(mLinearOutSlowInInterpolator);
Chet Haase10e23ab2015-02-11 15:08:38 -0800865
866 AnimationSet set = new AnimationSet(false);
867 set.addAnimation(clipAnimLR);
868 set.addAnimation(clipAnimTB);
Filip Gruszczynski82861362015-10-16 14:21:09 -0700869 set.addAnimation(translate);
Chet Haase10e23ab2015-02-11 15:08:38 -0800870 set.addAnimation(alpha);
Filip Gruszczynski9e2cf5b2015-07-31 12:20:40 -0700871 set.setZAdjustment(Animation.ZORDER_TOP);
Chet Haase10e23ab2015-02-11 15:08:38 -0800872 set.initialize(appWidth, appHeight, appWidth, appHeight);
873 anim = set;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800874 mLastHadClipReveal = true;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800875 mLastClipRevealTransitionDuration = duration;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800876
877 // If the start rect was full inside the target rect (cutOff == false), we don't need
878 // to store the translation, because it's only used if cutOff == true.
879 mLastClipRevealMaxTranslation = cutOff
880 ? Math.max(Math.abs(translationY), Math.abs(translationX)) : 0;
Chet Haase10e23ab2015-02-11 15:08:38 -0800881 } else {
882 final long duration;
883 switch (transit) {
884 case TRANSIT_ACTIVITY_OPEN:
885 case TRANSIT_ACTIVITY_CLOSE:
886 duration = mConfigShortAnimTime;
887 break;
888 default:
889 duration = DEFAULT_APP_TRANSITION_DURATION;
890 break;
891 }
892 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
893 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
894 // If we are on top of the wallpaper, we need an animation that
895 // correctly handles the wallpaper staying static behind all of
896 // the animated elements. To do this, will just have the existing
897 // element fade out.
898 anim = new AlphaAnimation(1, 0);
899 anim.setDetachWallpaper(true);
900 } else {
901 // For normal animations, the exiting element just holds in place.
902 anim = new AlphaAnimation(1, 1);
903 }
904 anim.setInterpolator(mDecelerateInterpolator);
905 anim.setDuration(duration);
906 anim.setFillAfter(true);
907 }
908 return anim;
909 }
910
Winson Chung399f6202014-03-19 10:47:20 -0700911 /**
912 * Prepares the specified animation with a standard duration, interpolator, etc.
913 */
Winson Chung5393dff2014-05-08 14:25:43 -0700914 Animation prepareThumbnailAnimationWithDuration(Animation a, int appWidth, int appHeight,
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100915 long duration, Interpolator interpolator) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700916 if (duration > 0) {
917 a.setDuration(duration);
918 }
Winson Chung5393dff2014-05-08 14:25:43 -0700919 a.setFillAfter(true);
Jorim Jaggic69bd222016-03-15 14:38:37 +0100920 if (interpolator != null) {
921 a.setInterpolator(interpolator);
922 }
Winson Chung5393dff2014-05-08 14:25:43 -0700923 a.initialize(appWidth, appHeight, appWidth, appHeight);
924 return a;
925 }
926
927 /**
928 * Prepares the specified animation with a standard duration, interpolator, etc.
929 */
Winson Chung399f6202014-03-19 10:47:20 -0700930 Animation prepareThumbnailAnimation(Animation a, int appWidth, int appHeight, int transit) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800931 // Pick the desired duration. If this is an inter-activity transition,
932 // it is the standard duration for that. Otherwise we use the longer
933 // task transition duration.
Winson Chung5393dff2014-05-08 14:25:43 -0700934 final int duration;
Craig Mautner321bdf52012-12-18 09:53:24 -0800935 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800936 case TRANSIT_ACTIVITY_OPEN:
937 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800938 duration = mConfigShortAnimTime;
939 break;
940 default:
941 duration = DEFAULT_APP_TRANSITION_DURATION;
942 break;
943 }
Winson Chung5393dff2014-05-08 14:25:43 -0700944 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, duration,
945 mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800946 }
947
Winson Chung399f6202014-03-19 10:47:20 -0700948 /**
949 * Return the current thumbnail transition state.
950 */
951 int getThumbnailTransitionState(boolean enter) {
952 if (enter) {
953 if (mNextAppTransitionScaleUp) {
954 return THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
955 } else {
956 return THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN;
957 }
958 } else {
959 if (mNextAppTransitionScaleUp) {
960 return THUMBNAIL_TRANSITION_EXIT_SCALE_UP;
961 } else {
962 return THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN;
963 }
964 }
965 }
966
967 /**
Tony Mak64b8d562017-12-28 17:44:02 +0000968 * Creates an overlay with a background color and a thumbnail for the cross profile apps
969 * animation.
970 */
971 GraphicBuffer createCrossProfileAppsThumbnail(
972 @DrawableRes int thumbnailDrawableRes, Rect frame) {
973 final int width = frame.width();
974 final int height = frame.height();
975
John Reck519ad482018-02-12 17:08:48 -0800976 final Picture picture = new Picture();
977 final Canvas canvas = picture.beginRecording(width, height);
Tony Mak64b8d562017-12-28 17:44:02 +0000978 canvas.drawColor(Color.argb(0.6f, 0, 0, 0));
979 final int thumbnailSize = mService.mContext.getResources().getDimensionPixelSize(
980 com.android.internal.R.dimen.cross_profile_apps_thumbnail_size);
981 final Drawable drawable = mService.mContext.getDrawable(thumbnailDrawableRes);
982 drawable.setBounds(
983 (width - thumbnailSize) / 2,
984 (height - thumbnailSize) / 2,
985 (width + thumbnailSize) / 2,
986 (height + thumbnailSize) / 2);
Tony Makda4af232018-04-27 11:01:10 +0100987 drawable.setTint(mContext.getColor(android.R.color.white));
Tony Mak64b8d562017-12-28 17:44:02 +0000988 drawable.draw(canvas);
John Reck519ad482018-02-12 17:08:48 -0800989 picture.endRecording();
Tony Mak64b8d562017-12-28 17:44:02 +0000990
John Reck519ad482018-02-12 17:08:48 -0800991 return Bitmap.createBitmap(picture).createGraphicBufferHandle();
Tony Mak64b8d562017-12-28 17:44:02 +0000992 }
993
994 Animation createCrossProfileAppsThumbnailAnimationLocked(Rect appRect) {
995 final Animation animation = loadAnimationRes(
996 "android", com.android.internal.R.anim.cross_profile_apps_thumbnail_enter);
997 return prepareThumbnailAnimationWithDuration(animation, appRect.width(),
998 appRect.height(), 0, null);
999 }
1000
1001 /**
Winson Chung399f6202014-03-19 10:47:20 -07001002 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001003 * when a thumbnail is specified with the pending animation override.
Winson Chung399f6202014-03-19 10:47:20 -07001004 */
Jorim Jaggide63d442016-03-14 14:56:56 +01001005 Animation createThumbnailAspectScaleAnimationLocked(Rect appRect, @Nullable Rect contentInsets,
Winson Chungaa7fa012017-05-24 15:50:06 -07001006 GraphicBuffer thumbnailHeader, final int taskId, int uiMode, int orientation) {
Winson Chung399f6202014-03-19 10:47:20 -07001007 Animation a;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001008 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chung399f6202014-03-19 10:47:20 -07001009 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001010 final int thumbHeightI = thumbnailHeader.getHeight();
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -07001011 final int appWidth = appRect.width();
Winson Chung399f6202014-03-19 10:47:20 -07001012
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -07001013 float scaleW = appWidth / thumbWidth;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001014 getNextAppTransitionStartRect(taskId, mTmpRect);
Jorim Jaggi09072002016-03-25 16:48:42 -07001015 final float fromX;
Manu Cornet57b61492017-01-24 18:19:05 +09001016 float fromY;
Jorim Jaggi09072002016-03-25 16:48:42 -07001017 final float toX;
Manu Cornet57b61492017-01-24 18:19:05 +09001018 float toY;
Jorim Jaggi09072002016-03-25 16:48:42 -07001019 final float pivotX;
1020 final float pivotY;
Manu Cornetd7376802017-01-13 13:44:07 -08001021 if (shouldScaleDownThumbnailTransition(uiMode, orientation)) {
Jorim Jaggi09072002016-03-25 16:48:42 -07001022 fromX = mTmpRect.left;
1023 fromY = mTmpRect.top;
1024
1025 // For the curved translate animation to work, the pivot points needs to be at the
1026 // same absolute position as the one from the real surface.
1027 toX = mTmpRect.width() / 2 * (scaleW - 1f) + appRect.left;
1028 toY = appRect.height() / 2 * (1 - 1 / scaleW) + appRect.top;
1029 pivotX = mTmpRect.width() / 2;
1030 pivotY = appRect.height() / 2 / scaleW;
Manu Cornet57b61492017-01-24 18:19:05 +09001031 if (mGridLayoutRecentsEnabled) {
1032 // In the grid layout, the header is displayed above the thumbnail instead of
1033 // overlapping it.
1034 fromY -= thumbHeightI;
1035 toY -= thumbHeightI * scaleW;
1036 }
Jorim Jaggi09072002016-03-25 16:48:42 -07001037 } else {
1038 pivotX = 0;
1039 pivotY = 0;
1040 fromX = mTmpRect.left;
1041 fromY = mTmpRect.top;
1042 toX = appRect.left;
1043 toY = appRect.top;
1044 }
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001045 final long duration = getAspectScaleDuration();
1046 final Interpolator interpolator = getAspectScaleInterpolator();
Winson Chung399f6202014-03-19 10:47:20 -07001047 if (mNextAppTransitionScaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001048 // Animation up from the thumbnail to the full screen
Jorim Jaggi8448f332016-03-14 17:50:37 +01001049 Animation scale = new ScaleAnimation(1f, scaleW, 1f, scaleW, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001050 scale.setInterpolator(interpolator);
1051 scale.setDuration(duration);
Jorim Jaggic6c89a82016-01-28 17:48:21 -08001052 Animation alpha = new AlphaAnimation(1f, 0f);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001053 alpha.setInterpolator(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
1054 ? THUMBNAIL_DOCK_INTERPOLATOR : mThumbnailFadeOutInterpolator);
1055 alpha.setDuration(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
1056 ? duration / 2
1057 : duration);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001058 Animation translate = createCurvedMotion(fromX, toX, fromY, toY);
1059 translate.setInterpolator(interpolator);
1060 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -07001061
Jorim Jaggide63d442016-03-14 14:56:56 +01001062 mTmpFromClipRect.set(0, 0, thumbWidthI, thumbHeightI);
1063 mTmpToClipRect.set(appRect);
1064
1065 // Containing frame is in screen space, but we need the clip rect in the
1066 // app space.
1067 mTmpToClipRect.offsetTo(0, 0);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001068 mTmpToClipRect.right = (int) (mTmpToClipRect.right / scaleW);
1069 mTmpToClipRect.bottom = (int) (mTmpToClipRect.bottom / scaleW);
Jorim Jaggide63d442016-03-14 14:56:56 +01001070
1071 if (contentInsets != null) {
Jorim Jaggi8448f332016-03-14 17:50:37 +01001072 mTmpToClipRect.inset((int) (-contentInsets.left * scaleW),
1073 (int) (-contentInsets.top * scaleW),
1074 (int) (-contentInsets.right * scaleW),
1075 (int) (-contentInsets.bottom * scaleW));
Jorim Jaggide63d442016-03-14 14:56:56 +01001076 }
1077
1078 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001079 clipAnim.setInterpolator(interpolator);
1080 clipAnim.setDuration(duration);
Jorim Jaggide63d442016-03-14 14:56:56 +01001081
Winson Chung399f6202014-03-19 10:47:20 -07001082 // This AnimationSet uses the Interpolators assigned above.
1083 AnimationSet set = new AnimationSet(false);
1084 set.addAnimation(scale);
Manu Cornet57b61492017-01-24 18:19:05 +09001085 if (!mGridLayoutRecentsEnabled) {
1086 // In the grid layout, the header should be shown for the whole animation.
1087 set.addAnimation(alpha);
1088 }
Winson Chunga4ccb862014-08-22 15:26:27 -07001089 set.addAnimation(translate);
Jorim Jaggide63d442016-03-14 14:56:56 +01001090 set.addAnimation(clipAnim);
Winson Chung399f6202014-03-19 10:47:20 -07001091 a = set;
1092 } else {
Winson Chunga4ccb862014-08-22 15:26:27 -07001093 // Animation down from the full screen to the thumbnail
Jorim Jaggi8448f332016-03-14 17:50:37 +01001094 Animation scale = new ScaleAnimation(scaleW, 1f, scaleW, 1f, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001095 scale.setInterpolator(interpolator);
1096 scale.setDuration(duration);
Winson Chunga4ccb862014-08-22 15:26:27 -07001097 Animation alpha = new AlphaAnimation(0f, 1f);
1098 alpha.setInterpolator(mThumbnailFadeInInterpolator);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001099 alpha.setDuration(duration);
1100 Animation translate = createCurvedMotion(toX, fromX, toY, fromY);
1101 translate.setInterpolator(interpolator);
1102 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -07001103
Winson Chunga4ccb862014-08-22 15:26:27 -07001104 // This AnimationSet uses the Interpolators assigned above.
1105 AnimationSet set = new AnimationSet(false);
1106 set.addAnimation(scale);
Manu Cornet57b61492017-01-24 18:19:05 +09001107 if (!mGridLayoutRecentsEnabled) {
1108 // In the grid layout, the header should be shown for the whole animation.
1109 set.addAnimation(alpha);
1110 }
Winson Chunga4ccb862014-08-22 15:26:27 -07001111 set.addAnimation(translate);
1112 a = set;
1113
1114 }
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -07001115 return prepareThumbnailAnimationWithDuration(a, appWidth, appRect.height(), 0,
Jorim Jaggic69bd222016-03-15 14:38:37 +01001116 null);
Winson Chung399f6202014-03-19 10:47:20 -07001117 }
1118
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001119 private Animation createCurvedMotion(float fromX, float toX, float fromY, float toY) {
1120
1121 // Almost no x-change - use linear animation
Jorim Jaggic69bd222016-03-15 14:38:37 +01001122 if (Math.abs(toX - fromX) < 1f || mNextAppTransition != TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001123 return new TranslateAnimation(fromX, toX, fromY, toY);
1124 } else {
1125 final Path path = createCurvedPath(fromX, toX, fromY, toY);
1126 return new CurvedTranslateAnimation(path);
1127 }
1128 }
1129
1130 private Path createCurvedPath(float fromX, float toX, float fromY, float toY) {
1131 final Path path = new Path();
1132 path.moveTo(fromX, fromY);
Jorim Jaggi1f458fb2016-03-25 17:36:37 -07001133
1134 if (fromY > toY) {
1135 // If the object needs to go up, move it in horizontal direction first, then vertical.
1136 path.cubicTo(fromX, fromY, toX, 0.9f * fromY + 0.1f * toY, toX, toY);
1137 } else {
1138 // If the object needs to go down, move it in vertical direction first, then horizontal.
1139 path.cubicTo(fromX, fromY, fromX, 0.1f * fromY + 0.9f * toY, toX, toY);
1140 }
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001141 return path;
1142 }
1143
1144 private long getAspectScaleDuration() {
1145 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggic69bd222016-03-15 14:38:37 +01001146 return (long) (THUMBNAIL_APP_TRANSITION_DURATION * 1.35f);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001147 } else {
1148 return THUMBNAIL_APP_TRANSITION_DURATION;
1149 }
1150 }
1151
1152 private Interpolator getAspectScaleInterpolator() {
1153 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
1154 return mFastOutSlowInInterpolator;
1155 } else {
1156 return TOUCH_RESPONSE_INTERPOLATOR;
1157 }
1158 }
1159
Winson Chung399f6202014-03-19 10:47:20 -07001160 /**
1161 * This alternate animation is created when we are doing a thumbnail transition, for the
1162 * activity that is leaving, and the activity that is entering.
1163 */
Winson Chunga4ccb862014-08-22 15:26:27 -07001164 Animation createAspectScaledThumbnailEnterExitAnimationLocked(int thumbTransitState,
Winsonb2024762016-04-05 17:32:30 -07001165 int uiMode, int orientation, int transit, Rect containingFrame, Rect contentInsets,
Matthew Ng43db6d22017-06-27 15:29:39 -07001166 @Nullable Rect surfaceInsets, @Nullable Rect stableInsets, boolean freeform,
1167 int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -07001168 Animation a;
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001169 final int appWidth = containingFrame.width();
1170 final int appHeight = containingFrame.height();
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001171 getDefaultNextAppTransitionStartRect(mTmpRect);
1172 final int thumbWidthI = mTmpRect.width();
Winson Chung399f6202014-03-19 10:47:20 -07001173 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001174 final int thumbHeightI = mTmpRect.height();
Winson Chung399f6202014-03-19 10:47:20 -07001175 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
Winsoncbb625b2016-07-06 15:24:15 -07001176 final int thumbStartX = mTmpRect.left - containingFrame.left - contentInsets.left;
Winson21700932016-03-24 17:26:23 -07001177 final int thumbStartY = mTmpRect.top - containingFrame.top;
Winson Chung399f6202014-03-19 10:47:20 -07001178
1179 switch (thumbTransitState) {
Jorim Jaggi8448f332016-03-14 17:50:37 +01001180 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP:
1181 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1182 final boolean scaleUp = thumbTransitState == THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
1183 if (freeform && scaleUp) {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001184 a = createAspectScaledThumbnailEnterFreeformAnimationLocked(
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001185 containingFrame, surfaceInsets, taskId);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001186 } else if (freeform) {
1187 a = createAspectScaledThumbnailExitFreeformAnimationLocked(
1188 containingFrame, surfaceInsets, taskId);
Winson Chung2820c452014-04-15 15:34:44 -07001189 } else {
Winson21700932016-03-24 17:26:23 -07001190 AnimationSet set = new AnimationSet(true);
1191
1192 // In portrait, we scale to fit the width
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001193 mTmpFromClipRect.set(containingFrame);
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001194 mTmpToClipRect.set(containingFrame);
Jorim Jaggic6c89a82016-01-28 17:48:21 -08001195
1196 // Containing frame is in screen space, but we need the clip rect in the
1197 // app space.
1198 mTmpFromClipRect.offsetTo(0, 0);
1199 mTmpToClipRect.offsetTo(0, 0);
1200
1201 // Exclude insets region from the source clip.
1202 mTmpFromClipRect.inset(contentInsets);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001203 mNextAppTransitionInsets.set(contentInsets);
1204
Manu Cornetd7376802017-01-13 13:44:07 -08001205 if (shouldScaleDownThumbnailTransition(uiMode, orientation)) {
Jorim Jaggic69bd222016-03-15 14:38:37 +01001206 // We scale the width and clip to the top/left square
1207 float scale = thumbWidth /
1208 (appWidth - contentInsets.left - contentInsets.right);
Manu Cornetb68b7652017-01-23 19:37:53 +09001209 if (!mGridLayoutRecentsEnabled) {
1210 int unscaledThumbHeight = (int) (thumbHeight / scale);
1211 mTmpFromClipRect.bottom = mTmpFromClipRect.top + unscaledThumbHeight;
1212 }
Jorim Jaggic69bd222016-03-15 14:38:37 +01001213
1214 mNextAppTransitionInsets.set(contentInsets);
1215
Jorim Jaggi8448f332016-03-14 17:50:37 +01001216 Animation scaleAnim = new ScaleAnimation(
1217 scaleUp ? scale : 1, scaleUp ? 1 : scale,
1218 scaleUp ? scale : 1, scaleUp ? 1 : scale,
Jorim Jaggic69bd222016-03-15 14:38:37 +01001219 containingFrame.width() / 2f,
1220 containingFrame.height() / 2f + contentInsets.top);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001221 final float targetX = (mTmpRect.left - containingFrame.left);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001222 final float x = containingFrame.width() / 2f
1223 - containingFrame.width() / 2f * scale;
Jorim Jaggi8448f332016-03-14 17:50:37 +01001224 final float targetY = (mTmpRect.top - containingFrame.top);
Matthew Ng43db6d22017-06-27 15:29:39 -07001225 float y = containingFrame.height() / 2f
Jorim Jaggic69bd222016-03-15 14:38:37 +01001226 - containingFrame.height() / 2f * scale;
Matthew Ng43db6d22017-06-27 15:29:39 -07001227
1228 // During transition may require clipping offset from any top stable insets
1229 // such as the statusbar height when statusbar is hidden
1230 if (mLowRamRecentsEnabled && contentInsets.top == 0 && scaleUp) {
1231 mTmpFromClipRect.top += stableInsets.top;
1232 y += stableInsets.top;
1233 }
Jorim Jaggi8448f332016-03-14 17:50:37 +01001234 final float startX = targetX - x;
1235 final float startY = targetY - y;
1236 Animation clipAnim = scaleUp
1237 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1238 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1239 Animation translateAnim = scaleUp
Jorim Jaggic69bd222016-03-15 14:38:37 +01001240 ? createCurvedMotion(startX, 0, startY - contentInsets.top, 0)
1241 : createCurvedMotion(0, startX, 0, startY - contentInsets.top);
1242
Winson21700932016-03-24 17:26:23 -07001243 set.addAnimation(clipAnim);
1244 set.addAnimation(scaleAnim);
1245 set.addAnimation(translateAnim);
1246
1247 } else {
1248 // In landscape, we don't scale at all and only crop
1249 mTmpFromClipRect.bottom = mTmpFromClipRect.top + thumbHeightI;
1250 mTmpFromClipRect.right = mTmpFromClipRect.left + thumbWidthI;
1251
Jorim Jaggi8448f332016-03-14 17:50:37 +01001252 Animation clipAnim = scaleUp
1253 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1254 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1255 Animation translateAnim = scaleUp
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001256 ? createCurvedMotion(thumbStartX, 0,
1257 thumbStartY - contentInsets.top, 0)
1258 : createCurvedMotion(0, thumbStartX, 0,
1259 thumbStartY - contentInsets.top);
Winson21700932016-03-24 17:26:23 -07001260
1261 set.addAnimation(clipAnim);
1262 set.addAnimation(translateAnim);
1263 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001264 a = set;
Winson21700932016-03-24 17:26:23 -07001265 a.setZAdjustment(Animation.ZORDER_TOP);
Winson Chung2820c452014-04-15 15:34:44 -07001266 }
Winson Chung399f6202014-03-19 10:47:20 -07001267 break;
1268 }
1269 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001270 // Previous app window during the scale up
Winson Chung399f6202014-03-19 10:47:20 -07001271 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001272 // Fade out the source activity if we are animating to a wallpaper
Winson Chung399f6202014-03-19 10:47:20 -07001273 // activity.
1274 a = new AlphaAnimation(1, 0);
1275 } else {
Winson Chung399f6202014-03-19 10:47:20 -07001276 a = new AlphaAnimation(1, 1);
1277 }
1278 break;
1279 }
1280 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001281 // Target app window during the scale down
1282 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1283 // Fade in the destination activity if we are animating from a wallpaper
1284 // activity.
1285 a = new AlphaAnimation(0, 1);
1286 } else {
1287 a = new AlphaAnimation(1, 1);
1288 }
Winson Chung399f6202014-03-19 10:47:20 -07001289 break;
1290 }
Winson Chung399f6202014-03-19 10:47:20 -07001291 default:
1292 throw new RuntimeException("Invalid thumbnail transition state");
1293 }
1294
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001295 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight,
1296 getAspectScaleDuration(), getAspectScaleInterpolator());
Winson Chung399f6202014-03-19 10:47:20 -07001297 }
1298
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001299 private Animation createAspectScaledThumbnailEnterFreeformAnimationLocked(Rect frame,
1300 @Nullable Rect surfaceInsets, int taskId) {
1301 getNextAppTransitionStartRect(taskId, mTmpRect);
1302 return createAspectScaledThumbnailFreeformAnimationLocked(mTmpRect, frame, surfaceInsets,
1303 true);
1304 }
1305
1306 private Animation createAspectScaledThumbnailExitFreeformAnimationLocked(Rect frame,
1307 @Nullable Rect surfaceInsets, int taskId) {
1308 getNextAppTransitionStartRect(taskId, mTmpRect);
1309 return createAspectScaledThumbnailFreeformAnimationLocked(frame, mTmpRect, surfaceInsets,
1310 false);
1311 }
1312
1313 private AnimationSet createAspectScaledThumbnailFreeformAnimationLocked(Rect sourceFrame,
1314 Rect destFrame, @Nullable Rect surfaceInsets, boolean enter) {
1315 final float sourceWidth = sourceFrame.width();
1316 final float sourceHeight = sourceFrame.height();
1317 final float destWidth = destFrame.width();
1318 final float destHeight = destFrame.height();
1319 final float scaleH = enter ? sourceWidth / destWidth : destWidth / sourceWidth;
1320 final float scaleV = enter ? sourceHeight / destHeight : destHeight / sourceHeight;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001321 AnimationSet set = new AnimationSet(true);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001322 final int surfaceInsetsH = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001323 ? 0 : surfaceInsets.left + surfaceInsets.right;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001324 final int surfaceInsetsV = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001325 ? 0 : surfaceInsets.top + surfaceInsets.bottom;
1326 // We want the scaling to happen from the center of the surface. In order to achieve that,
1327 // we need to account for surface insets that will be used to enlarge the surface.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001328 final float scaleHCenter = ((enter ? destWidth : sourceWidth) + surfaceInsetsH) / 2;
1329 final float scaleVCenter = ((enter ? destHeight : sourceHeight) + surfaceInsetsV) / 2;
1330 final ScaleAnimation scale = enter ?
1331 new ScaleAnimation(scaleH, 1, scaleV, 1, scaleHCenter, scaleVCenter)
1332 : new ScaleAnimation(1, scaleH, 1, scaleV, scaleHCenter, scaleVCenter);
1333 final int sourceHCenter = sourceFrame.left + sourceFrame.width() / 2;
1334 final int sourceVCenter = sourceFrame.top + sourceFrame.height() / 2;
1335 final int destHCenter = destFrame.left + destFrame.width() / 2;
1336 final int destVCenter = destFrame.top + destFrame.height() / 2;
1337 final int fromX = enter ? sourceHCenter - destHCenter : destHCenter - sourceHCenter;
1338 final int fromY = enter ? sourceVCenter - destVCenter : destVCenter - sourceVCenter;
1339 final TranslateAnimation translation = enter ? new TranslateAnimation(fromX, 0, fromY, 0)
1340 : new TranslateAnimation(0, fromX, 0, fromY);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001341 set.addAnimation(scale);
1342 set.addAnimation(translation);
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001343
1344 final IRemoteCallback callback = mAnimationFinishedCallback;
1345 if (callback != null) {
1346 set.setAnimationListener(new Animation.AnimationListener() {
1347 @Override
1348 public void onAnimationStart(Animation animation) { }
1349
1350 @Override
1351 public void onAnimationEnd(Animation animation) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001352 mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK, callback).sendToTarget();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001353 }
1354
1355 @Override
1356 public void onAnimationRepeat(Animation animation) { }
1357 });
1358 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001359 return set;
1360 }
1361
Winson Chung399f6202014-03-19 10:47:20 -07001362 /**
Winson Chunga4ccb862014-08-22 15:26:27 -07001363 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001364 * when a thumbnail is specified with the pending animation override.
Winson Chunga4ccb862014-08-22 15:26:27 -07001365 */
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001366 Animation createThumbnailScaleAnimationLocked(int appWidth, int appHeight, int transit,
Winson Chungaa7fa012017-05-24 15:50:06 -07001367 GraphicBuffer thumbnailHeader) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001368 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001369 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001370 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chunga4ccb862014-08-22 15:26:27 -07001371 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001372 final int thumbHeightI = thumbnailHeader.getHeight();
Winson Chunga4ccb862014-08-22 15:26:27 -07001373 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1374
1375 if (mNextAppTransitionScaleUp) {
1376 // Animation for the thumbnail zooming from its initial size to the full screen
1377 float scaleW = appWidth / thumbWidth;
1378 float scaleH = appHeight / thumbHeight;
1379 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001380 computePivot(mTmpRect.left, 1 / scaleW),
1381 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001382 scale.setInterpolator(mDecelerateInterpolator);
1383
1384 Animation alpha = new AlphaAnimation(1, 0);
1385 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
1386
1387 // This AnimationSet uses the Interpolators assigned above.
1388 AnimationSet set = new AnimationSet(false);
1389 set.addAnimation(scale);
1390 set.addAnimation(alpha);
1391 a = set;
1392 } else {
1393 // Animation for the thumbnail zooming down from the full screen to its final size
1394 float scaleW = appWidth / thumbWidth;
1395 float scaleH = appHeight / thumbHeight;
1396 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001397 computePivot(mTmpRect.left, 1 / scaleW),
1398 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001399 }
1400
1401 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1402 }
1403
1404 /**
Winson Chung399f6202014-03-19 10:47:20 -07001405 * This animation is created when we are doing a thumbnail transition, for the activity that is
1406 * leaving, and the activity that is entering.
1407 */
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001408 Animation createThumbnailEnterExitAnimationLocked(int thumbTransitState, Rect containingFrame,
1409 int transit, int taskId) {
1410 final int appWidth = containingFrame.width();
1411 final int appHeight = containingFrame.height();
Winson Chungaa7fa012017-05-24 15:50:06 -07001412 final GraphicBuffer thumbnailHeader = getAppTransitionThumbnailHeader(taskId);
Winson Chung399f6202014-03-19 10:47:20 -07001413 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001414 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001415 final int thumbWidthI = thumbnailHeader != null ? thumbnailHeader.getWidth() : appWidth;
Winson Chung399f6202014-03-19 10:47:20 -07001416 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001417 final int thumbHeightI = thumbnailHeader != null ? thumbnailHeader.getHeight() : appHeight;
Winson Chung399f6202014-03-19 10:47:20 -07001418 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1419
1420 switch (thumbTransitState) {
1421 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
1422 // Entering app scales up with the thumbnail
1423 float scaleW = thumbWidth / appWidth;
1424 float scaleH = thumbHeight / appHeight;
1425 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001426 computePivot(mTmpRect.left, scaleW),
1427 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001428 break;
1429 }
1430 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
1431 // Exiting app while the thumbnail is scaling up should fade or stay in place
1432 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1433 // Fade out while bringing up selected activity. This keeps the
1434 // current activity from showing through a launching wallpaper
1435 // activity.
1436 a = new AlphaAnimation(1, 0);
1437 } else {
1438 // noop animation
1439 a = new AlphaAnimation(1, 1);
1440 }
1441 break;
1442 }
1443 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
1444 // Entering the other app, it should just be visible while we scale the thumbnail
1445 // down above it
1446 a = new AlphaAnimation(1, 1);
1447 break;
1448 }
1449 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1450 // Exiting the current app, the app should scale down with the thumbnail
1451 float scaleW = thumbWidth / appWidth;
1452 float scaleH = thumbHeight / appHeight;
1453 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001454 computePivot(mTmpRect.left, scaleW),
1455 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001456
1457 Animation alpha = new AlphaAnimation(1, 0);
1458
1459 AnimationSet set = new AnimationSet(true);
1460 set.addAnimation(scale);
1461 set.addAnimation(alpha);
1462 set.setZAdjustment(Animation.ZORDER_TOP);
1463 a = set;
1464 break;
1465 }
1466 default:
1467 throw new RuntimeException("Invalid thumbnail transition state");
1468 }
1469
1470 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1471 }
1472
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001473 private Animation createRelaunchAnimation(Rect containingFrame, Rect contentInsets) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001474 getDefaultNextAppTransitionStartRect(mTmpFromClipRect);
1475 final int left = mTmpFromClipRect.left;
1476 final int top = mTmpFromClipRect.top;
1477 mTmpFromClipRect.offset(-left, -top);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001478 // TODO: Isn't that strange that we ignore exact position of the containingFrame?
1479 mTmpToClipRect.set(0, 0, containingFrame.width(), containingFrame.height());
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001480 AnimationSet set = new AnimationSet(true);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001481 float fromWidth = mTmpFromClipRect.width();
1482 float toWidth = mTmpToClipRect.width();
1483 float fromHeight = mTmpFromClipRect.height();
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001484 // While the window might span the whole display, the actual content will be cropped to the
1485 // system decoration frame, for example when the window is docked. We need to take into
1486 // account the visible height when constructing the animation.
1487 float toHeight = mTmpToClipRect.height() - contentInsets.top - contentInsets.bottom;
1488 int translateAdjustment = 0;
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001489 if (fromWidth <= toWidth && fromHeight <= toHeight) {
1490 // The final window is larger in both dimensions than current window (e.g. we are
1491 // maximizing), so we can simply unclip the new window and there will be no disappearing
1492 // frame.
1493 set.addAnimation(new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect));
1494 } else {
1495 // The disappearing window has one larger dimension. We need to apply scaling, so the
1496 // first frame of the entry animation matches the old window.
1497 set.addAnimation(new ScaleAnimation(fromWidth / toWidth, 1, fromHeight / toHeight, 1));
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001498 // We might not be going exactly full screen, but instead be aligned under the status
1499 // bar using cropping. We still need to account for the cropped part, which will also
1500 // be scaled.
1501 translateAdjustment = (int) (contentInsets.top * fromHeight / toHeight);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001502 }
1503
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001504 // We animate the translation from the old position of the removed window, to the new
1505 // position of the added window. The latter might not be full screen, for example docked for
1506 // docked windows.
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001507 TranslateAnimation translate = new TranslateAnimation(left - containingFrame.left,
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001508 0, top - containingFrame.top - translateAdjustment, 0);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001509 set.addAnimation(translate);
1510 set.setDuration(DEFAULT_APP_TRANSITION_DURATION);
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07001511 set.setZAdjustment(Animation.ZORDER_TOP);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001512 return set;
1513 }
1514
Jorim Jaggic554b772015-06-04 16:07:57 -07001515 /**
1516 * @return true if and only if the first frame of the transition can be skipped, i.e. the first
1517 * frame of the transition doesn't change the visuals on screen, so we can start
1518 * directly with the second one
1519 */
1520 boolean canSkipFirstFrame() {
1521 return mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM
1522 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE
Jorim Jaggife762342016-10-13 14:33:27 +02001523 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CLIP_REVEAL
1524 && mNextAppTransition != TRANSIT_KEYGUARD_GOING_AWAY;
Jorim Jaggic554b772015-06-04 16:07:57 -07001525 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001526
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001527 RemoteAnimationController getRemoteAnimationController() {
1528 return mRemoteAnimationController;
1529 }
1530
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001531 /**
1532 *
1533 * @param frame These are the bounds of the window when it finishes the animation. This is where
1534 * the animation must usually finish in entrance animation, as the next frame will
1535 * display the window at these coordinates. In case of exit animation, this is
1536 * where the animation must start, as the frame before the animation is displaying
1537 * the window at these bounds.
1538 * @param insets Knowing where the window will be positioned is not enough. Some parts of the
1539 * window might be obscured, usually by the system windows (status bar and
1540 * navigation bar) and we use content insets to convey that information. This
1541 * usually affects the animation aspects vertically, as the system decoration is
1542 * at the top and the bottom. For example when we animate from full screen to
1543 * recents, we want to exclude the covered parts, because they won't match the
1544 * thumbnail after the last frame is executed.
1545 * @param surfaceInsets In rare situation the surface is larger than the content and we need to
1546 * know about this to make the animation frames match. We currently use
1547 * this for freeform windows, which have larger surfaces to display
1548 * shadows. When we animate them from recents, we want to match the content
1549 * to the recents thumbnail and hence need to account for the surface being
1550 * bigger.
1551 */
Jorim Jaggif84e2f62018-01-16 14:17:59 +01001552 Animation loadAnimation(LayoutParams lp, int transit, boolean enter, int uiMode,
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001553 int orientation, Rect frame, Rect displayFrame, Rect insets,
Matthew Ng43db6d22017-06-27 15:29:39 -07001554 @Nullable Rect surfaceInsets, @Nullable Rect stableInsets, boolean isVoiceInteraction,
1555 boolean freeform, int taskId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001556 Animation a;
Jorim Jaggife762342016-10-13 14:33:27 +02001557 if (isKeyguardGoingAwayTransit(transit) && enter) {
1558 a = loadKeyguardExitAnimation(transit);
1559 } else if (transit == TRANSIT_KEYGUARD_OCCLUDE) {
1560 a = null;
1561 } else if (transit == TRANSIT_KEYGUARD_UNOCCLUDE && !enter) {
1562 a = loadAnimationRes(lp, com.android.internal.R.anim.wallpaper_open_exit);
Adrian Roos93577212018-04-10 14:12:10 -07001563 } else if (transit == TRANSIT_CRASHING_ACTIVITY_CLOSE) {
1564 a = null;
Jorim Jaggife762342016-10-13 14:33:27 +02001565 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_OPEN
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001566 || transit == TRANSIT_TASK_OPEN
1567 || transit == TRANSIT_TASK_TO_FRONT)) {
1568 a = loadAnimationRes(lp, enter
1569 ? com.android.internal.R.anim.voice_activity_open_enter
1570 : com.android.internal.R.anim.voice_activity_open_exit);
1571 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1572 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001573 + " anim=" + a + " transit=" + appTransitionToString(transit)
1574 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001575 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_CLOSE
1576 || transit == TRANSIT_TASK_CLOSE
1577 || transit == TRANSIT_TASK_TO_BACK)) {
1578 a = loadAnimationRes(lp, enter
1579 ? com.android.internal.R.anim.voice_activity_close_enter
1580 : com.android.internal.R.anim.voice_activity_close_exit);
1581 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1582 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001583 + " anim=" + a + " transit=" + appTransitionToString(transit)
1584 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001585 } else if (transit == TRANSIT_ACTIVITY_RELAUNCH) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001586 a = createRelaunchAnimation(frame, insets);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001587 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1588 "applyAnimation:"
1589 + " anim=" + a + " nextAppTransition=" + mNextAppTransition
1590 + " transit=" + appTransitionToString(transit)
1591 + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001592 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM) {
1593 a = loadAnimationRes(mNextAppTransitionPackage, enter ?
Craig Mautner164d4bb2012-11-26 13:51:23 -08001594 mNextAppTransitionEnter : mNextAppTransitionExit);
1595 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1596 "applyAnimation:"
1597 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001598 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001599 + " Callers=" + Debug.getCallers(3));
Winson Chung044d5292014-11-06 11:05:19 -08001600 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE) {
1601 a = loadAnimationRes(mNextAppTransitionPackage, mNextAppTransitionInPlace);
1602 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1603 "applyAnimation:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001604 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM_IN_PLACE"
1605 + " transit=" + appTransitionToString(transit)
1606 + " Callers=" + Debug.getCallers(3));
Chet Haase10e23ab2015-02-11 15:08:38 -08001607 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001608 a = createClipRevealAnimationLocked(transit, enter, frame, displayFrame);
Chet Haase10e23ab2015-02-11 15:08:38 -08001609 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1610 "applyAnimation:"
1611 + " anim=" + a + " nextAppTransition=ANIM_CLIP_REVEAL"
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001612 + " transit=" + appTransitionToString(transit)
Chet Haase10e23ab2015-02-11 15:08:38 -08001613 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001614 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_SCALE_UP) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001615 a = createScaleUpAnimationLocked(transit, enter, frame);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001616 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1617 "applyAnimation:"
1618 + " anim=" + a + " nextAppTransition=ANIM_SCALE_UP"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001619 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001620 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001621 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
1622 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001623 mNextAppTransitionScaleUp =
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001624 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP);
Winson Chunga4ccb862014-08-22 15:26:27 -07001625 a = createThumbnailEnterExitAnimationLocked(getThumbnailTransitionState(enter),
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001626 frame, transit, taskId);
Winson Chunga4ccb862014-08-22 15:26:27 -07001627 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1628 String animName = mNextAppTransitionScaleUp ?
1629 "ANIM_THUMBNAIL_SCALE_UP" : "ANIM_THUMBNAIL_SCALE_DOWN";
1630 Slog.v(TAG, "applyAnimation:"
1631 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001632 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Winson Chunga4ccb862014-08-22 15:26:27 -07001633 + " Callers=" + Debug.getCallers(3));
1634 }
1635 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
1636 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN) {
1637 mNextAppTransitionScaleUp =
1638 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP);
1639 a = createAspectScaledThumbnailEnterExitAnimationLocked(
Winsonb2024762016-04-05 17:32:30 -07001640 getThumbnailTransitionState(enter), uiMode, orientation, transit, frame,
Matthew Ng43db6d22017-06-27 15:29:39 -07001641 insets, surfaceInsets, stableInsets, freeform, taskId);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001642 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1643 String animName = mNextAppTransitionScaleUp ?
Winson Chunga4ccb862014-08-22 15:26:27 -07001644 "ANIM_THUMBNAIL_ASPECT_SCALE_UP" : "ANIM_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner164d4bb2012-11-26 13:51:23 -08001645 Slog.v(TAG, "applyAnimation:"
1646 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001647 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001648 + " Callers=" + Debug.getCallers(3));
1649 }
Tony Mak83546a82018-01-22 13:56:20 +00001650 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS && enter) {
Jorim Jaggi98a9d202018-03-26 16:17:07 +02001651 a = loadAnimationRes("android",
1652 com.android.internal.R.anim.task_open_enter_cross_profile_apps);
Tony Mak089c35e2017-12-18 20:34:14 +00001653 Slog.v(TAG,
1654 "applyAnimation NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS:"
1655 + " anim=" + a + " transit=" + appTransitionToString(transit)
Jorim Jaggi98a9d202018-03-26 16:17:07 +02001656 + " isEntrance=true" + " Callers=" + Debug.getCallers(3));
Craig Mautner164d4bb2012-11-26 13:51:23 -08001657 } else {
1658 int animAttr = 0;
1659 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001660 case TRANSIT_ACTIVITY_OPEN:
Jorim Jaggi0a1523d2018-04-19 17:48:38 +02001661 case TRANSIT_TRANSLUCENT_ACTIVITY_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001662 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001663 ? WindowAnimation_activityOpenEnterAnimation
1664 : WindowAnimation_activityOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001665 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001666 case TRANSIT_ACTIVITY_CLOSE:
Jorim Jaggi0a1523d2018-04-19 17:48:38 +02001667 case TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001668 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001669 ? WindowAnimation_activityCloseEnterAnimation
1670 : WindowAnimation_activityCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001671 break;
Jorim Jaggi192086e2016-03-11 17:17:03 +01001672 case TRANSIT_DOCK_TASK_FROM_RECENTS:
Craig Mautner4b71aa12012-12-27 17:20:01 -08001673 case TRANSIT_TASK_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001674 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001675 ? WindowAnimation_taskOpenEnterAnimation
1676 : WindowAnimation_taskOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001677 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001678 case TRANSIT_TASK_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001679 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001680 ? WindowAnimation_taskCloseEnterAnimation
1681 : WindowAnimation_taskCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001682 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001683 case TRANSIT_TASK_TO_FRONT:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001684 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001685 ? WindowAnimation_taskToFrontEnterAnimation
1686 : WindowAnimation_taskToFrontExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001687 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001688 case TRANSIT_TASK_TO_BACK:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001689 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001690 ? WindowAnimation_taskToBackEnterAnimation
1691 : WindowAnimation_taskToBackExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001692 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001693 case TRANSIT_WALLPAPER_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001694 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001695 ? WindowAnimation_wallpaperOpenEnterAnimation
1696 : WindowAnimation_wallpaperOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001697 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001698 case TRANSIT_WALLPAPER_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001699 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001700 ? WindowAnimation_wallpaperCloseEnterAnimation
1701 : WindowAnimation_wallpaperCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001702 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001703 case TRANSIT_WALLPAPER_INTRA_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001704 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001705 ? WindowAnimation_wallpaperIntraOpenEnterAnimation
1706 : WindowAnimation_wallpaperIntraOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001707 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001708 case TRANSIT_WALLPAPER_INTRA_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001709 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001710 ? WindowAnimation_wallpaperIntraCloseEnterAnimation
1711 : WindowAnimation_wallpaperIntraCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001712 break;
Craig Mautnerbb742462014-07-07 15:28:55 -07001713 case TRANSIT_TASK_OPEN_BEHIND:
1714 animAttr = enter
1715 ? WindowAnimation_launchTaskBehindSourceAnimation
Craig Mautner3b2cd1d2014-08-25 14:25:54 -07001716 : WindowAnimation_launchTaskBehindTargetAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001717 }
Jorim Jaggi0a1523d2018-04-19 17:48:38 +02001718 a = animAttr != 0 ? loadAnimationAttr(lp, animAttr, transit) : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001719 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1720 "applyAnimation:"
1721 + " anim=" + a
1722 + " animAttr=0x" + Integer.toHexString(animAttr)
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001723 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001724 + " Callers=" + Debug.getCallers(3));
1725 }
1726 return a;
1727 }
1728
Jorim Jaggife762342016-10-13 14:33:27 +02001729 private Animation loadKeyguardExitAnimation(int transit) {
1730 if ((mNextAppTransitionFlags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_NO_ANIMATION) != 0) {
1731 return null;
1732 }
1733 final boolean toShade =
1734 (mNextAppTransitionFlags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_TO_SHADE) != 0;
1735 return mService.mPolicy.createHiddenByKeyguardExit(
1736 transit == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER, toShade);
1737 }
1738
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001739 int getAppStackClipMode() {
Matthew Ngbf1d9852017-03-14 12:23:09 -07001740 // When dismiss keyguard animation occurs, clip before the animation to prevent docked
1741 // app from showing beyond the divider
1742 if (mNextAppTransition == TRANSIT_KEYGUARD_GOING_AWAY
1743 || mNextAppTransition == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER) {
1744 return STACK_CLIP_BEFORE_ANIM;
1745 }
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001746 return mNextAppTransition == TRANSIT_ACTIVITY_RELAUNCH
Jorim Jaggic69bd222016-03-15 14:38:37 +01001747 || mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
Jorim Jaggi1f458fb2016-03-25 17:36:37 -07001748 || mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001749 ? STACK_CLIP_NONE
1750 : STACK_CLIP_AFTER_ANIM;
1751 }
1752
Jorim Jaggife762342016-10-13 14:33:27 +02001753 public int getTransitFlags() {
1754 return mNextAppTransitionFlags;
1755 }
1756
Craig Mautner164d4bb2012-11-26 13:51:23 -08001757 void postAnimationCallback() {
1758 if (mNextAppTransitionCallback != null) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001759 mService.mH.sendMessage(mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK,
1760 mNextAppTransitionCallback));
Craig Mautner164d4bb2012-11-26 13:51:23 -08001761 mNextAppTransitionCallback = null;
1762 }
1763 }
1764
1765 void overridePendingAppTransition(String packageName, int enterAnim, int exitAnim,
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001766 IRemoteCallback startedCallback) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001767 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001768 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001769 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001770 mNextAppTransitionPackage = packageName;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001771 mNextAppTransitionEnter = enterAnim;
1772 mNextAppTransitionExit = exitAnim;
1773 postAnimationCallback();
1774 mNextAppTransitionCallback = startedCallback;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001775 }
1776 }
1777
1778 void overridePendingAppTransitionScaleUp(int startX, int startY, int startWidth,
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001779 int startHeight) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001780 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001781 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001782 mNextAppTransitionType = NEXT_TRANSIT_TYPE_SCALE_UP;
Winson4c3fecd2016-07-13 12:29:48 -07001783 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001784 postAnimationCallback();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001785 }
1786 }
1787
Chet Haase10e23ab2015-02-11 15:08:38 -08001788 void overridePendingAppTransitionClipReveal(int startX, int startY,
1789 int startWidth, int startHeight) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001790 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001791 clear();
Chet Haase10e23ab2015-02-11 15:08:38 -08001792 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CLIP_REVEAL;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001793 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Chet Haase10e23ab2015-02-11 15:08:38 -08001794 postAnimationCallback();
Chet Haase10e23ab2015-02-11 15:08:38 -08001795 }
1796 }
1797
Winson Chungaa7fa012017-05-24 15:50:06 -07001798 void overridePendingAppTransitionThumb(GraphicBuffer srcThumb, int startX, int startY,
Craig Mautner164d4bb2012-11-26 13:51:23 -08001799 IRemoteCallback startedCallback, boolean scaleUp) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001800 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001801 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001802 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP
1803 : NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001804 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001805 putDefaultNextAppTransitionCoordinates(startX, startY, 0, 0, srcThumb);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001806 postAnimationCallback();
1807 mNextAppTransitionCallback = startedCallback;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001808 }
1809 }
1810
Winson Chungaa7fa012017-05-24 15:50:06 -07001811 void overridePendingAppTransitionAspectScaledThumb(GraphicBuffer srcThumb, int startX, int startY,
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001812 int targetWidth, int targetHeight, IRemoteCallback startedCallback, boolean scaleUp) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001813 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001814 clear();
Winson Chunga4ccb862014-08-22 15:26:27 -07001815 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1816 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Winson Chunga4ccb862014-08-22 15:26:27 -07001817 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001818 putDefaultNextAppTransitionCoordinates(startX, startY, targetWidth, targetHeight,
1819 srcThumb);
Winson Chunga4ccb862014-08-22 15:26:27 -07001820 postAnimationCallback();
1821 mNextAppTransitionCallback = startedCallback;
Winson Chunga4ccb862014-08-22 15:26:27 -07001822 }
1823 }
1824
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001825 void overridePendingAppTransitionMultiThumb(AppTransitionAnimationSpec[] specs,
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001826 IRemoteCallback onAnimationStartedCallback, IRemoteCallback onAnimationFinishedCallback,
1827 boolean scaleUp) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001828 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001829 clear();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001830 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1831 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001832 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi43102412015-11-11 16:28:37 +01001833 if (specs != null) {
1834 for (int i = 0; i < specs.length; i++) {
1835 AppTransitionAnimationSpec spec = specs[i];
1836 if (spec != null) {
1837 mNextAppTransitionAnimationsSpecs.put(spec.taskId, spec);
1838 if (i == 0) {
1839 // In full screen mode, the transition code depends on the default spec
1840 // to be set.
1841 Rect rect = spec.rect;
1842 putDefaultNextAppTransitionCoordinates(rect.left, rect.top,
Winson Chungaa7fa012017-05-24 15:50:06 -07001843 rect.width(), rect.height(), spec.buffer);
Jorim Jaggi43102412015-11-11 16:28:37 +01001844 }
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001845 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001846 }
1847 }
1848 postAnimationCallback();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001849 mNextAppTransitionCallback = onAnimationStartedCallback;
1850 mAnimationFinishedCallback = onAnimationFinishedCallback;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001851 }
1852 }
1853
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001854 void overridePendingAppTransitionMultiThumbFuture(
1855 IAppTransitionAnimationSpecsFuture specsFuture, IRemoteCallback callback,
1856 boolean scaleUp) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001857 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001858 clear();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001859 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1860 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001861 mNextAppTransitionAnimationsSpecsFuture = specsFuture;
1862 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001863 mNextAppTransitionFutureCallback = callback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001864 }
1865 }
1866
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001867 void overridePendingAppTransitionRemote(RemoteAnimationAdapter remoteAnimationAdapter) {
Winson Chung044d5292014-11-06 11:05:19 -08001868 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001869 clear();
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001870 mNextAppTransitionType = NEXT_TRANSIT_TYPE_REMOTE;
1871 mRemoteAnimationController = new RemoteAnimationController(mService,
1872 remoteAnimationAdapter, mService.mH);
1873 }
1874 }
1875
1876 void overrideInPlaceAppTransition(String packageName, int anim) {
1877 if (canOverridePendingAppTransition()) {
1878 clear();
Winson Chung044d5292014-11-06 11:05:19 -08001879 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE;
1880 mNextAppTransitionPackage = packageName;
1881 mNextAppTransitionInPlace = anim;
Winson Chung044d5292014-11-06 11:05:19 -08001882 }
1883 }
1884
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001885 /**
Tony Mak089c35e2017-12-18 20:34:14 +00001886 * @see {@link #NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS}
1887 */
1888 void overridePendingAppTransitionStartCrossProfileApps() {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001889 if (canOverridePendingAppTransition()) {
Tony Mak089c35e2017-12-18 20:34:14 +00001890 clear();
1891 mNextAppTransitionType = NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS;
1892 postAnimationCallback();
1893 }
1894 }
1895
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001896 private boolean canOverridePendingAppTransition() {
1897 // Remote animations always take precedence
1898 return isTransitionSet() && mNextAppTransitionType != NEXT_TRANSIT_TYPE_REMOTE;
1899 }
1900
Tony Mak089c35e2017-12-18 20:34:14 +00001901 /**
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001902 * If a future is set for the app transition specs, fetch it in another thread.
1903 */
1904 private void fetchAppTransitionSpecsFromFuture() {
1905 if (mNextAppTransitionAnimationsSpecsFuture != null) {
1906 mNextAppTransitionAnimationsSpecsPending = true;
1907 final IAppTransitionAnimationSpecsFuture future
1908 = mNextAppTransitionAnimationsSpecsFuture;
1909 mNextAppTransitionAnimationsSpecsFuture = null;
Jorim Jaggied410b62017-05-05 15:16:14 +02001910 mDefaultExecutor.execute(() -> {
1911 AppTransitionAnimationSpec[] specs = null;
1912 try {
1913 Binder.allowBlocking(future.asBinder());
1914 specs = future.get();
1915 } catch (RemoteException e) {
1916 Slog.w(TAG, "Failed to fetch app transition specs: " + e);
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001917 }
Jorim Jaggied410b62017-05-05 15:16:14 +02001918 synchronized (mService.mWindowMap) {
1919 mNextAppTransitionAnimationsSpecsPending = false;
1920 overridePendingAppTransitionMultiThumb(specs,
1921 mNextAppTransitionFutureCallback, null /* finishedCallback */,
1922 mNextAppTransitionScaleUp);
1923 mNextAppTransitionFutureCallback = null;
Jorim Jaggied410b62017-05-05 15:16:14 +02001924 }
1925 mService.requestTraversal();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001926 });
1927 }
1928 }
1929
Craig Mautner164d4bb2012-11-26 13:51:23 -08001930 @Override
1931 public String toString() {
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001932 return "mNextAppTransition=" + appTransitionToString(mNextAppTransition);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001933 }
1934
Craig Mautner4b71aa12012-12-27 17:20:01 -08001935 /**
1936 * Returns the human readable name of a window transition.
1937 *
1938 * @param transition The window transition.
1939 * @return The transition symbolic name.
1940 */
1941 public static String appTransitionToString(int transition) {
1942 switch (transition) {
1943 case TRANSIT_UNSET: {
1944 return "TRANSIT_UNSET";
1945 }
1946 case TRANSIT_NONE: {
1947 return "TRANSIT_NONE";
1948 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001949 case TRANSIT_ACTIVITY_OPEN: {
1950 return "TRANSIT_ACTIVITY_OPEN";
1951 }
1952 case TRANSIT_ACTIVITY_CLOSE: {
1953 return "TRANSIT_ACTIVITY_CLOSE";
1954 }
1955 case TRANSIT_TASK_OPEN: {
1956 return "TRANSIT_TASK_OPEN";
1957 }
1958 case TRANSIT_TASK_CLOSE: {
1959 return "TRANSIT_TASK_CLOSE";
1960 }
1961 case TRANSIT_TASK_TO_FRONT: {
1962 return "TRANSIT_TASK_TO_FRONT";
1963 }
1964 case TRANSIT_TASK_TO_BACK: {
1965 return "TRANSIT_TASK_TO_BACK";
1966 }
1967 case TRANSIT_WALLPAPER_CLOSE: {
1968 return "TRANSIT_WALLPAPER_CLOSE";
1969 }
1970 case TRANSIT_WALLPAPER_OPEN: {
1971 return "TRANSIT_WALLPAPER_OPEN";
1972 }
1973 case TRANSIT_WALLPAPER_INTRA_OPEN: {
1974 return "TRANSIT_WALLPAPER_INTRA_OPEN";
1975 }
1976 case TRANSIT_WALLPAPER_INTRA_CLOSE: {
1977 return "TRANSIT_WALLPAPER_INTRA_CLOSE";
1978 }
Craig Mautnerbb742462014-07-07 15:28:55 -07001979 case TRANSIT_TASK_OPEN_BEHIND: {
1980 return "TRANSIT_TASK_OPEN_BEHIND";
1981 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001982 case TRANSIT_ACTIVITY_RELAUNCH: {
1983 return "TRANSIT_ACTIVITY_RELAUNCH";
1984 }
Jorim Jaggi192086e2016-03-11 17:17:03 +01001985 case TRANSIT_DOCK_TASK_FROM_RECENTS: {
1986 return "TRANSIT_DOCK_TASK_FROM_RECENTS";
1987 }
Jorim Jaggife762342016-10-13 14:33:27 +02001988 case TRANSIT_KEYGUARD_GOING_AWAY: {
1989 return "TRANSIT_KEYGUARD_GOING_AWAY";
1990 }
1991 case TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER: {
1992 return "TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER";
1993 }
1994 case TRANSIT_KEYGUARD_OCCLUDE: {
1995 return "TRANSIT_KEYGUARD_OCCLUDE";
1996 }
1997 case TRANSIT_KEYGUARD_UNOCCLUDE: {
1998 return "TRANSIT_KEYGUARD_UNOCCLUDE";
1999 }
Jorim Jaggi98a9d202018-03-26 16:17:07 +02002000 case TRANSIT_TRANSLUCENT_ACTIVITY_OPEN: {
2001 return "TRANSIT_TRANSLUCENT_ACTIVITY_OPEN";
2002 }
2003 case TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE: {
2004 return "TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE";
2005 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002006 default: {
2007 return "<UNKNOWN>";
2008 }
2009 }
2010 }
2011
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002012 private String appStateToString() {
2013 switch (mAppTransitionState) {
2014 case APP_STATE_IDLE:
2015 return "APP_STATE_IDLE";
2016 case APP_STATE_READY:
2017 return "APP_STATE_READY";
2018 case APP_STATE_RUNNING:
2019 return "APP_STATE_RUNNING";
2020 case APP_STATE_TIMEOUT:
2021 return "APP_STATE_TIMEOUT";
2022 default:
2023 return "unknown state=" + mAppTransitionState;
2024 }
2025 }
2026
2027 private String transitTypeToString() {
2028 switch (mNextAppTransitionType) {
2029 case NEXT_TRANSIT_TYPE_NONE:
2030 return "NEXT_TRANSIT_TYPE_NONE";
2031 case NEXT_TRANSIT_TYPE_CUSTOM:
2032 return "NEXT_TRANSIT_TYPE_CUSTOM";
Winson Chung044d5292014-11-06 11:05:19 -08002033 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
2034 return "NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002035 case NEXT_TRANSIT_TYPE_SCALE_UP:
2036 return "NEXT_TRANSIT_TYPE_SCALE_UP";
2037 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
2038 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP";
2039 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
2040 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN";
Winson Chunga4ccb862014-08-22 15:26:27 -07002041 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
2042 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP";
2043 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN:
2044 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN";
Tony Mak64b8d562017-12-28 17:44:02 +00002045 case NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS:
2046 return "NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002047 default:
2048 return "unknown type=" + mNextAppTransitionType;
2049 }
2050 }
2051
Steven Timotiusaf03df62017-07-18 16:56:43 -07002052 void writeToProto(ProtoOutputStream proto, long fieldId) {
2053 final long token = proto.start(fieldId);
2054 proto.write(APP_TRANSITION_STATE, mAppTransitionState);
2055 proto.write(LAST_USED_APP_TRANSITION, mLastUsedAppTransition);
2056 proto.end(token);
2057 }
2058
Craig Mautner164d4bb2012-11-26 13:51:23 -08002059 @Override
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002060 public void dump(PrintWriter pw, String prefix) {
2061 pw.print(prefix); pw.println(this);
2062 pw.print(prefix); pw.print("mAppTransitionState="); pw.println(appStateToString());
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002063 if (mNextAppTransitionType != NEXT_TRANSIT_TYPE_NONE) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002064 pw.print(prefix); pw.print("mNextAppTransitionType=");
2065 pw.println(transitTypeToString());
Craig Mautner164d4bb2012-11-26 13:51:23 -08002066 }
2067 switch (mNextAppTransitionType) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002068 case NEXT_TRANSIT_TYPE_CUSTOM:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002069 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Craig Mautner164d4bb2012-11-26 13:51:23 -08002070 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002071 pw.print(prefix); pw.print("mNextAppTransitionEnter=0x");
Craig Mautner164d4bb2012-11-26 13:51:23 -08002072 pw.print(Integer.toHexString(mNextAppTransitionEnter));
2073 pw.print(" mNextAppTransitionExit=0x");
2074 pw.println(Integer.toHexString(mNextAppTransitionExit));
2075 break;
Winson Chung044d5292014-11-06 11:05:19 -08002076 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002077 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Winson Chung044d5292014-11-06 11:05:19 -08002078 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002079 pw.print(prefix); pw.print("mNextAppTransitionInPlace=0x");
Winson Chung044d5292014-11-06 11:05:19 -08002080 pw.print(Integer.toHexString(mNextAppTransitionInPlace));
2081 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002082 case NEXT_TRANSIT_TYPE_SCALE_UP: {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002083 getDefaultNextAppTransitionStartRect(mTmpRect);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002084 pw.print(prefix); pw.print("mNextAppTransitionStartX=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002085 pw.print(mTmpRect.left);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002086 pw.print(" mNextAppTransitionStartY=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002087 pw.println(mTmpRect.top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002088 pw.print(prefix); pw.print("mNextAppTransitionStartWidth=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002089 pw.print(mTmpRect.width());
Craig Mautner164d4bb2012-11-26 13:51:23 -08002090 pw.print(" mNextAppTransitionStartHeight=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002091 pw.println(mTmpRect.height());
Craig Mautner164d4bb2012-11-26 13:51:23 -08002092 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002093 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002094 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
2095 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
Winson Chunga4ccb862014-08-22 15:26:27 -07002096 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002097 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN: {
2098 pw.print(prefix); pw.print("mDefaultNextAppTransitionAnimationSpec=");
2099 pw.println(mDefaultNextAppTransitionAnimationSpec);
2100 pw.print(prefix); pw.print("mNextAppTransitionAnimationsSpecs=");
2101 pw.println(mNextAppTransitionAnimationsSpecs);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002102 pw.print(prefix); pw.print("mNextAppTransitionScaleUp=");
2103 pw.println(mNextAppTransitionScaleUp);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002104 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002105 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002106 }
2107 if (mNextAppTransitionCallback != null) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002108 pw.print(prefix); pw.print("mNextAppTransitionCallback=");
2109 pw.println(mNextAppTransitionCallback);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002110 }
Chong Zhang60091a92016-07-27 17:52:45 -07002111 if (mLastUsedAppTransition != TRANSIT_NONE) {
2112 pw.print(prefix); pw.print("mLastUsedAppTransition=");
2113 pw.println(appTransitionToString(mLastUsedAppTransition));
2114 pw.print(prefix); pw.print("mLastOpeningApp=");
2115 pw.println(mLastOpeningApp);
2116 pw.print(prefix); pw.print("mLastClosingApp=");
2117 pw.println(mLastClosingApp);
2118 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002119 }
Amith Yamasani4befbec2013-07-10 16:18:01 -07002120
2121 public void setCurrentUser(int newUserId) {
2122 mCurrentUserId = newUserId;
2123 }
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002124
2125 /**
2126 * @return true if transition is not running and should not be skipped, false if transition is
2127 * already running
2128 */
Jorim Jaggif84e2f62018-01-16 14:17:59 +01002129 boolean prepareAppTransitionLocked(@TransitionType int transit, boolean alwaysKeepCurrent,
2130 @TransitionFlags int flags, boolean forceOverride) {
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002131 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Prepare app transition:"
2132 + " transit=" + appTransitionToString(transit)
2133 + " " + this
2134 + " alwaysKeepCurrent=" + alwaysKeepCurrent
2135 + " Callers=" + Debug.getCallers(3));
Jorim Jaggife762342016-10-13 14:33:27 +02002136 if (forceOverride || isKeyguardTransit(transit) || !isTransitionSet()
2137 || mNextAppTransition == TRANSIT_NONE) {
2138 setAppTransition(transit, flags);
Jorim Jaggia69243a2017-06-15 15:10:38 -04002139 }
2140 // We never want to change from a Keyguard transit to a non-Keyguard transit, as our logic
Adrian Roos93577212018-04-10 14:12:10 -07002141 // relies on the fact that we always execute a Keyguard transition after preparing one. We
2142 // also don't want to change away from a crashing transition.
2143 else if (!alwaysKeepCurrent && !isKeyguardTransit(transit)
2144 && transit != TRANSIT_CRASHING_ACTIVITY_CLOSE) {
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002145 if (transit == TRANSIT_TASK_OPEN && isTransitionEqual(TRANSIT_TASK_CLOSE)) {
2146 // Opening a new task always supersedes a close for the anim.
Jorim Jaggife762342016-10-13 14:33:27 +02002147 setAppTransition(transit, flags);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002148 } else if (transit == TRANSIT_ACTIVITY_OPEN
2149 && isTransitionEqual(TRANSIT_ACTIVITY_CLOSE)) {
2150 // Opening a new activity always supersedes a close for the anim.
Jorim Jaggife762342016-10-13 14:33:27 +02002151 setAppTransition(transit, flags);
Jorim Jaggicecf4242018-02-21 18:46:53 +01002152 } else if (isTaskTransit(transit) && isActivityTransit(mNextAppTransition)) {
2153 // Task animations always supersede activity animations, because if we have both, it
2154 // usually means that activity transition were just trampoline activities.
2155 setAppTransition(transit, flags);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002156 }
2157 }
2158 boolean prepared = prepare();
2159 if (isTransitionSet()) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08002160 mService.mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
2161 mService.mH.sendEmptyMessageDelayed(H.APP_TRANSITION_TIMEOUT, APP_TRANSITION_TIMEOUT_MS);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002162 }
2163 return prepared;
2164 }
Winsonb2024762016-04-05 17:32:30 -07002165
2166 /**
Jorim Jaggife762342016-10-13 14:33:27 +02002167 * @return true if {@param transit} is representing a transition in which Keyguard is going
2168 * away, false otherwise
2169 */
2170 public static boolean isKeyguardGoingAwayTransit(int transit) {
2171 return transit == TRANSIT_KEYGUARD_GOING_AWAY
2172 || transit == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER;
2173 }
2174
2175 private static boolean isKeyguardTransit(int transit) {
2176 return isKeyguardGoingAwayTransit(transit) || transit == TRANSIT_KEYGUARD_OCCLUDE
2177 || transit == TRANSIT_KEYGUARD_UNOCCLUDE;
2178 }
2179
Jorim Jaggi98a9d202018-03-26 16:17:07 +02002180 static boolean isTaskTransit(int transit) {
2181 return isTaskOpenTransit(transit)
Jorim Jaggicecf4242018-02-21 18:46:53 +01002182 || transit == TRANSIT_TASK_CLOSE
Jorim Jaggicecf4242018-02-21 18:46:53 +01002183 || transit == TRANSIT_TASK_TO_BACK
Jorim Jaggicecf4242018-02-21 18:46:53 +01002184 || transit == TRANSIT_TASK_IN_PLACE;
2185 }
2186
Jorim Jaggi98a9d202018-03-26 16:17:07 +02002187 private static boolean isTaskOpenTransit(int transit) {
2188 return transit == TRANSIT_TASK_OPEN
2189 || transit == TRANSIT_TASK_OPEN_BEHIND
2190 || transit == TRANSIT_TASK_TO_FRONT;
2191 }
2192
2193 static boolean isActivityTransit(int transit) {
Jorim Jaggicecf4242018-02-21 18:46:53 +01002194 return transit == TRANSIT_ACTIVITY_OPEN
2195 || transit == TRANSIT_ACTIVITY_CLOSE
2196 || transit == TRANSIT_ACTIVITY_RELAUNCH;
2197 }
2198
Jorim Jaggife762342016-10-13 14:33:27 +02002199 /**
Manu Cornetd7376802017-01-13 13:44:07 -08002200 * @return whether the transition should show the thumbnail being scaled down.
2201 */
2202 private boolean shouldScaleDownThumbnailTransition(int uiMode, int orientation) {
Sid Soundararajan0e88d322017-03-07 15:37:30 -08002203 return mGridLayoutRecentsEnabled
Manu Cornetd7376802017-01-13 13:44:07 -08002204 || orientation == Configuration.ORIENTATION_PORTRAIT;
2205 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002206}