blob: 2bdaa1a66b7eb42cdd342bce4db6539b9aafe54c [file] [log] [blame]
Craig Mautner164d4bb2012-11-26 13:51:23 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server.wm;
18
Jorim Jaggif84e2f62018-01-16 14:17:59 +010019import static android.view.WindowManager.LayoutParams;
20import static android.view.WindowManager.TRANSIT_ACTIVITY_CLOSE;
21import static android.view.WindowManager.TRANSIT_ACTIVITY_OPEN;
22import static android.view.WindowManager.TRANSIT_ACTIVITY_RELAUNCH;
23import static android.view.WindowManager.TRANSIT_DOCK_TASK_FROM_RECENTS;
24import static android.view.WindowManager.TRANSIT_FLAG_KEYGUARD_GOING_AWAY_NO_ANIMATION;
25import static android.view.WindowManager.TRANSIT_FLAG_KEYGUARD_GOING_AWAY_TO_SHADE;
26import static android.view.WindowManager.TRANSIT_KEYGUARD_GOING_AWAY;
27import static android.view.WindowManager.TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER;
28import static android.view.WindowManager.TRANSIT_KEYGUARD_OCCLUDE;
29import static android.view.WindowManager.TRANSIT_KEYGUARD_UNOCCLUDE;
30import static android.view.WindowManager.TRANSIT_NONE;
31import static android.view.WindowManager.TRANSIT_TASK_CLOSE;
32import static android.view.WindowManager.TRANSIT_TASK_OPEN;
33import static android.view.WindowManager.TRANSIT_TASK_OPEN_BEHIND;
34import static android.view.WindowManager.TRANSIT_TASK_TO_BACK;
35import static android.view.WindowManager.TRANSIT_TASK_TO_FRONT;
36import static android.view.WindowManager.TRANSIT_UNSET;
37import static android.view.WindowManager.TRANSIT_WALLPAPER_CLOSE;
38import static android.view.WindowManager.TRANSIT_WALLPAPER_INTRA_CLOSE;
39import static android.view.WindowManager.TRANSIT_WALLPAPER_INTRA_OPEN;
40import static android.view.WindowManager.TRANSIT_WALLPAPER_OPEN;
Tony Mak83546a82018-01-22 13:56:20 +000041
Filip Gruszczynski82861362015-10-16 14:21:09 -070042import static com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation;
43import static com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
44import static com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation;
45import static com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
46import static com.android.internal.R.styleable.WindowAnimation_launchTaskBehindSourceAnimation;
47import static com.android.internal.R.styleable.WindowAnimation_launchTaskBehindTargetAnimation;
48import static com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation;
49import static com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
50import static com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation;
51import static com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
52import static com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation;
53import static com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
54import static com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation;
55import static com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
56import static com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation;
57import static com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
58import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation;
59import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
60import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation;
61import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
62import static com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation;
63import static com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Filip Gruszczynski198dcbf2016-01-18 10:02:00 -080064import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
65import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080066import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
67import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Adrian Roose99bc052017-11-20 17:55:31 +010068import static com.android.server.wm.WindowManagerInternal.AppTransitionListener;
Tony Mak089c35e2017-12-18 20:34:14 +000069import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_AFTER_ANIM;
Matthew Ngbf1d9852017-03-14 12:23:09 -070070import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_BEFORE_ANIM;
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +010071import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_NONE;
Steven Timotiusaf03df62017-07-18 16:56:43 -070072import static com.android.server.wm.proto.AppTransitionProto.APP_TRANSITION_STATE;
73import static com.android.server.wm.proto.AppTransitionProto.LAST_USED_APP_TRANSITION;
Filip Gruszczynski82861362015-10-16 14:21:09 -070074
Tony Mak64b8d562017-12-28 17:44:02 +000075import android.annotation.DrawableRes;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -070076import android.annotation.Nullable;
Matthew Ng43db6d22017-06-27 15:29:39 -070077import android.app.ActivityManager;
Tony Mak089c35e2017-12-18 20:34:14 +000078import android.content.ComponentName;
Craig Mautner164d4bb2012-11-26 13:51:23 -080079import android.content.Context;
Winson21700932016-03-24 17:26:23 -070080import android.content.res.Configuration;
Tony Mak64b8d562017-12-28 17:44:02 +000081import android.graphics.Color;
Winson Chungaa7fa012017-05-24 15:50:06 -070082import android.graphics.GraphicBuffer;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +010083import android.graphics.Path;
Winson Chung399f6202014-03-19 10:47:20 -070084import android.graphics.Rect;
Tony Mak64b8d562017-12-28 17:44:02 +000085import android.graphics.drawable.Drawable;
Jorim Jaggied410b62017-05-05 15:16:14 +020086import android.os.Binder;
Craig Mautner164d4bb2012-11-26 13:51:23 -080087import android.os.Debug;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010088import android.os.IBinder;
Craig Mautner164d4bb2012-11-26 13:51:23 -080089import android.os.IRemoteCallback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010090import android.os.RemoteException;
Jorim Jaggif5f9e122017-10-24 18:21:09 +020091import android.os.SystemClock;
Manu Cornetd7376802017-01-13 13:44:07 -080092import android.os.SystemProperties;
Tony Mak089c35e2017-12-18 20:34:14 +000093import android.os.UserHandle;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -080094import android.util.ArraySet;
Craig Mautner164d4bb2012-11-26 13:51:23 -080095import android.util.Slog;
Filip Gruszczynski170192a2015-08-16 17:46:34 -070096import android.util.SparseArray;
Steven Timotiusaf03df62017-07-18 16:56:43 -070097import android.util.proto.ProtoOutputStream;
Filip Gruszczynski170192a2015-08-16 17:46:34 -070098import android.view.AppTransitionAnimationSpec;
Tony Mak64b8d562017-12-28 17:44:02 +000099import android.view.DisplayListCanvas;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100100import android.view.IAppTransitionAnimationSpecsFuture;
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100101import android.view.RemoteAnimationAdapter;
Tony Mak64b8d562017-12-28 17:44:02 +0000102import android.view.RenderNode;
103import android.view.ThreadedRenderer;
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100104import android.view.WindowManager.TransitionFlags;
105import android.view.WindowManager.TransitionType;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800106import android.view.animation.AlphaAnimation;
107import android.view.animation.Animation;
108import android.view.animation.AnimationSet;
109import android.view.animation.AnimationUtils;
Winson Chung399f6202014-03-19 10:47:20 -0700110import android.view.animation.ClipRectAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800111import android.view.animation.Interpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700112import android.view.animation.PathInterpolator;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800113import android.view.animation.ScaleAnimation;
Winson Chung399f6202014-03-19 10:47:20 -0700114import android.view.animation.TranslateAnimation;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700115
Craig Mautner164d4bb2012-11-26 13:51:23 -0800116import com.android.internal.util.DumpUtils.Dump;
117import com.android.server.AttributeCache;
118import com.android.server.wm.WindowManagerService.H;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800119import com.android.server.wm.animation.ClipRectLRAnimation;
120import com.android.server.wm.animation.ClipRectTBAnimation;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100121import com.android.server.wm.animation.CurvedTranslateAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800122
123import java.io.PrintWriter;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100124import java.util.ArrayList;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100125import java.util.concurrent.ExecutorService;
126import java.util.concurrent.Executors;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800127
Craig Mautner164d4bb2012-11-26 13:51:23 -0800128// State management of app transitions. When we are preparing for a
129// transition, mNextAppTransition will be the kind of transition to
130// perform or TRANSIT_NONE if we are not waiting. If we are waiting,
131// mOpeningApps and mClosingApps are the lists of tokens that will be
132// made visible or hidden at the next transition.
133public class AppTransition implements Dump {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800134 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppTransition" : TAG_WM;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700135 private static final int CLIP_REVEAL_TRANSLATION_Y_DP = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800136
Winson Chunga4ccb862014-08-22 15:26:27 -0700137 /** Fraction of animation at which the recents thumbnail stays completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700138 private static final float RECENTS_THUMBNAIL_FADEIN_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800139 /** Fraction of animation at which the recents thumbnail becomes completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700140 private static final float RECENTS_THUMBNAIL_FADEOUT_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800141
Filip Gruszczynski84fa3352016-01-25 16:28:49 -0800142 static final int DEFAULT_APP_TRANSITION_DURATION = 336;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800143
144 /** Interpolator to be used for animations that respond directly to a touch */
145 static final Interpolator TOUCH_RESPONSE_INTERPOLATOR =
146 new PathInterpolator(0.3f, 0f, 0.1f, 1f);
147
Jorim Jaggic69bd222016-03-15 14:38:37 +0100148 private static final Interpolator THUMBNAIL_DOCK_INTERPOLATOR =
149 new PathInterpolator(0.85f, 0f, 1f, 1f);
150
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800151 /**
152 * Maximum duration for the clip reveal animation. This is used when there is a lot of movement
153 * involved, to make it more understandable.
154 */
155 private static final int MAX_CLIP_REVEAL_TRANSITION_DURATION = 420;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700156 private static final int THUMBNAIL_APP_TRANSITION_DURATION = 336;
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700157 private static final long APP_TRANSITION_TIMEOUT_MS = 5000;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800158
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800159 private final Context mContext;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800160 private final WindowManagerService mService;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800161
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100162 private @TransitionType int mNextAppTransition = TRANSIT_UNSET;
163 private @TransitionFlags int mNextAppTransitionFlags = 0;
Chong Zhang60091a92016-07-27 17:52:45 -0700164 private int mLastUsedAppTransition = TRANSIT_UNSET;
165 private String mLastOpeningApp;
166 private String mLastClosingApp;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800167
168 private static final int NEXT_TRANSIT_TYPE_NONE = 0;
169 private static final int NEXT_TRANSIT_TYPE_CUSTOM = 1;
170 private static final int NEXT_TRANSIT_TYPE_SCALE_UP = 2;
171 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP = 3;
172 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN = 4;
Winson Chunga4ccb862014-08-22 15:26:27 -0700173 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP = 5;
174 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN = 6;
Winson Chung044d5292014-11-06 11:05:19 -0800175 private static final int NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE = 7;
Chet Haase10e23ab2015-02-11 15:08:38 -0800176 private static final int NEXT_TRANSIT_TYPE_CLIP_REVEAL = 8;
Tony Mak089c35e2017-12-18 20:34:14 +0000177
178 /**
179 * Refers to the transition to activity started by using {@link
180 * android.content.pm.crossprofile.CrossProfileApps#startMainActivity(ComponentName, UserHandle)
181 * }.
182 */
183 private static final int NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS = 9;
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100184 private static final int NEXT_TRANSIT_TYPE_REMOTE = 10;
185
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800186 private int mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
187
Winson Chung399f6202014-03-19 10:47:20 -0700188 // These are the possible states for the enter/exit activities during a thumbnail transition
189 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_UP = 0;
190 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_UP = 1;
191 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN = 2;
192 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN = 3;
193
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800194 private String mNextAppTransitionPackage;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800195 // Used for thumbnail transitions. True if we're scaling up, false if scaling down
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800196 private boolean mNextAppTransitionScaleUp;
197 private IRemoteCallback mNextAppTransitionCallback;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +0100198 private IRemoteCallback mNextAppTransitionFutureCallback;
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -0700199 private IRemoteCallback mAnimationFinishedCallback;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800200 private int mNextAppTransitionEnter;
201 private int mNextAppTransitionExit;
Winson Chung044d5292014-11-06 11:05:19 -0800202 private int mNextAppTransitionInPlace;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700203
204 // Keyed by task id.
205 private final SparseArray<AppTransitionAnimationSpec> mNextAppTransitionAnimationsSpecs
206 = new SparseArray<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100207 private IAppTransitionAnimationSpecsFuture mNextAppTransitionAnimationsSpecsFuture;
208 private boolean mNextAppTransitionAnimationsSpecsPending;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700209 private AppTransitionAnimationSpec mDefaultNextAppTransitionAnimationSpec;
210
Winson Chunga4ccb862014-08-22 15:26:27 -0700211 private Rect mNextAppTransitionInsets = new Rect();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800212
Winson Chung2820c452014-04-15 15:34:44 -0700213 private Rect mTmpFromClipRect = new Rect();
214 private Rect mTmpToClipRect = new Rect();
215
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700216 private final Rect mTmpRect = new Rect();
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700217
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800218 private final static int APP_STATE_IDLE = 0;
219 private final static int APP_STATE_READY = 1;
220 private final static int APP_STATE_RUNNING = 2;
221 private final static int APP_STATE_TIMEOUT = 3;
222 private int mAppTransitionState = APP_STATE_IDLE;
223
224 private final int mConfigShortAnimTime;
Craig Mautner321bdf52012-12-18 09:53:24 -0800225 private final Interpolator mDecelerateInterpolator;
Winson Chunga4ccb862014-08-22 15:26:27 -0700226 private final Interpolator mThumbnailFadeInInterpolator;
227 private final Interpolator mThumbnailFadeOutInterpolator;
Chet Haase10e23ab2015-02-11 15:08:38 -0800228 private final Interpolator mLinearOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700229 private final Interpolator mFastOutLinearInInterpolator;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100230 private final Interpolator mFastOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700231 private final Interpolator mClipHorizontalInterpolator = new PathInterpolator(0, 0, 0.4f, 1f);
232
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700233 private final int mClipRevealTranslationY;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800234
Amith Yamasani4befbec2013-07-10 16:18:01 -0700235 private int mCurrentUserId = 0;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800236 private long mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Amith Yamasani4befbec2013-07-10 16:18:01 -0700237
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100238 private final ArrayList<AppTransitionListener> mListeners = new ArrayList<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100239 private final ExecutorService mDefaultExecutor = Executors.newSingleThreadExecutor();
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100240
Jorim Jaggif97ed922016-02-18 18:57:07 -0800241 private int mLastClipRevealMaxTranslation;
242 private boolean mLastHadClipReveal;
Jorim Jaggi363ab982016-04-26 19:51:20 -0700243 private boolean mProlongedAnimationsEnded;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800244
Manu Cornetd7376802017-01-13 13:44:07 -0800245 private final boolean mGridLayoutRecentsEnabled;
Matthew Ng43db6d22017-06-27 15:29:39 -0700246 private final boolean mLowRamRecentsEnabled;
Manu Cornetd7376802017-01-13 13:44:07 -0800247
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100248 private RemoteAnimationController mRemoteAnimationController;
249
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800250 AppTransition(Context context, WindowManagerService service) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800251 mContext = context;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800252 mService = service;
Chet Haase10e23ab2015-02-11 15:08:38 -0800253 mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
254 com.android.internal.R.interpolator.linear_out_slow_in);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700255 mFastOutLinearInInterpolator = AnimationUtils.loadInterpolator(context,
256 com.android.internal.R.interpolator.fast_out_linear_in);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100257 mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
258 com.android.internal.R.interpolator.fast_out_slow_in);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800259 mConfigShortAnimTime = context.getResources().getInteger(
260 com.android.internal.R.integer.config_shortAnimTime);
Craig Mautner321bdf52012-12-18 09:53:24 -0800261 mDecelerateInterpolator = AnimationUtils.loadInterpolator(context,
262 com.android.internal.R.interpolator.decelerate_cubic);
Winson Chunga4ccb862014-08-22 15:26:27 -0700263 mThumbnailFadeInInterpolator = new Interpolator() {
264 @Override
265 public float getInterpolation(float input) {
266 // Linear response for first fraction, then complete after that.
267 if (input < RECENTS_THUMBNAIL_FADEIN_FRACTION) {
268 return 0f;
269 }
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700270 float t = (input - RECENTS_THUMBNAIL_FADEIN_FRACTION) /
Winson Chunga4ccb862014-08-22 15:26:27 -0700271 (1f - RECENTS_THUMBNAIL_FADEIN_FRACTION);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700272 return mFastOutLinearInInterpolator.getInterpolation(t);
Winson Chunga4ccb862014-08-22 15:26:27 -0700273 }
274 };
275 mThumbnailFadeOutInterpolator = new Interpolator() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800276 @Override
277 public float getInterpolation(float input) {
278 // Linear response for first fraction, then complete after that.
279 if (input < RECENTS_THUMBNAIL_FADEOUT_FRACTION) {
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700280 float t = input / RECENTS_THUMBNAIL_FADEOUT_FRACTION;
281 return mLinearOutSlowInInterpolator.getInterpolation(t);
Craig Mautner321bdf52012-12-18 09:53:24 -0800282 }
Winson Chunga4ccb862014-08-22 15:26:27 -0700283 return 1f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800284 }
285 };
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700286 mClipRevealTranslationY = (int) (CLIP_REVEAL_TRANSLATION_Y_DP
287 * mContext.getResources().getDisplayMetrics().density);
Manu Cornetd7376802017-01-13 13:44:07 -0800288 mGridLayoutRecentsEnabled = SystemProperties.getBoolean("ro.recents.grid", false);
Matthew Ng43db6d22017-06-27 15:29:39 -0700289 mLowRamRecentsEnabled = ActivityManager.isLowRamDeviceStatic();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800290 }
291
292 boolean isTransitionSet() {
293 return mNextAppTransition != TRANSIT_UNSET;
294 }
295
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100296 boolean isTransitionEqual(@TransitionType int transit) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800297 return mNextAppTransition == transit;
298 }
299
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100300 @TransitionType int getAppTransition() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800301 return mNextAppTransition;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800302 }
303
Jorim Jaggife762342016-10-13 14:33:27 +0200304 private void setAppTransition(int transit, int flags) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800305 mNextAppTransition = transit;
Jorim Jaggife762342016-10-13 14:33:27 +0200306 mNextAppTransitionFlags |= flags;
Chong Zhang60091a92016-07-27 17:52:45 -0700307 setLastAppTransition(TRANSIT_UNSET, null, null);
Jorim Jaggi245281c2017-06-07 14:33:04 -0700308 updateBooster();
Chong Zhang60091a92016-07-27 17:52:45 -0700309 }
310
311 void setLastAppTransition(int transit, AppWindowToken openingApp, AppWindowToken closingApp) {
312 mLastUsedAppTransition = transit;
313 mLastOpeningApp = "" + openingApp;
314 mLastClosingApp = "" + closingApp;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800315 }
316
317 boolean isReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800318 return mAppTransitionState == APP_STATE_READY
319 || mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800320 }
321
Craig Mautnerae446592012-12-06 19:05:05 -0800322 void setReady() {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700323 setAppTransitionState(APP_STATE_READY);
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100324 fetchAppTransitionSpecsFromFuture();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800325 }
326
327 boolean isRunning() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800328 return mAppTransitionState == APP_STATE_RUNNING;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800329 }
330
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800331 void setIdle() {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700332 setAppTransitionState(APP_STATE_IDLE);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800333 }
334
335 boolean isTimeout() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800336 return mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800337 }
338
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800339 void setTimeout() {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700340 setAppTransitionState(APP_STATE_TIMEOUT);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800341 }
342
Winson Chungaa7fa012017-05-24 15:50:06 -0700343 GraphicBuffer getAppTransitionThumbnailHeader(int taskId) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700344 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800345 if (spec == null) {
346 spec = mDefaultNextAppTransitionAnimationSpec;
347 }
Winson Chungaa7fa012017-05-24 15:50:06 -0700348 return spec != null ? spec.buffer : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800349 }
350
Winson Chunga4ccb862014-08-22 15:26:27 -0700351 /** Returns whether the next thumbnail transition is aspect scaled up. */
352 boolean isNextThumbnailTransitionAspectScaled() {
353 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
354 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
355 }
356
357 /** Returns whether the next thumbnail transition is scaling up. */
358 boolean isNextThumbnailTransitionScaleUp() {
359 return mNextAppTransitionScaleUp;
360 }
361
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -0800362 boolean isNextAppTransitionThumbnailUp() {
363 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
364 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP;
365 }
366
367 boolean isNextAppTransitionThumbnailDown() {
368 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN ||
369 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
370 }
371
Tony Mak64b8d562017-12-28 17:44:02 +0000372
373 boolean isNextAppTransitionOpenCrossProfileApps() {
374 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS;
375 }
376
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100377 /**
378 * @return true if and only if we are currently fetching app transition specs from the future
379 * passed into {@link #overridePendingAppTransitionMultiThumbFuture}
380 */
381 boolean isFetchingAppTransitionsSpecs() {
382 return mNextAppTransitionAnimationsSpecsPending;
383 }
384
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700385 private boolean prepare() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800386 if (!isRunning()) {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700387 setAppTransitionState(APP_STATE_IDLE);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100388 notifyAppTransitionPendingLocked();
Jorim Jaggif97ed922016-02-18 18:57:07 -0800389 mLastHadClipReveal = false;
390 mLastClipRevealMaxTranslation = 0;
391 mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700392 return true;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800393 }
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700394 return false;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800395 }
396
Jorim Jaggife762342016-10-13 14:33:27 +0200397 /**
398 * @return bit-map of WindowManagerPolicy#FINISH_LAYOUT_REDO_* to indicate whether another
399 * layout pass needs to be done
400 */
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200401 int goodToGo(int transit, AppWindowToken topOpeningApp,
402 AppWindowToken topClosingApp, ArraySet<AppWindowToken> openingApps,
Jorim Jaggife762342016-10-13 14:33:27 +0200403 ArraySet<AppWindowToken> closingApps) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800404 mNextAppTransition = TRANSIT_UNSET;
Jorim Jaggife762342016-10-13 14:33:27 +0200405 mNextAppTransitionFlags = 0;
Jorim Jaggi245281c2017-06-07 14:33:04 -0700406 setAppTransitionState(APP_STATE_RUNNING);
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200407 final AnimationAdapter topOpeningAnim = topOpeningApp != null
408 ? topOpeningApp.getAnimation()
409 : null;
Jorim Jaggife762342016-10-13 14:33:27 +0200410 int redoLayout = notifyAppTransitionStartingLocked(transit,
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200411 topOpeningApp != null ? topOpeningApp.token : null,
412 topClosingApp != null ? topClosingApp.token : null,
413 topOpeningAnim != null ? topOpeningAnim.getDurationHint() : 0,
414 topOpeningAnim != null
415 ? topOpeningAnim.getStatusBarTransitionsStartTime()
416 : SystemClock.uptimeMillis(),
417 AnimationAdapter.STATUS_BAR_TRANSITION_DURATION);
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800418 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Jorim Jaggife762342016-10-13 14:33:27 +0200419 .notifyAppTransitionStarting(openingApps, transit);
Jorim Jaggi363ab982016-04-26 19:51:20 -0700420
421 // Prolong the start for the transition when docking a task from recents, unless recents
422 // ended it already then we don't need to wait.
Jorim Jaggife762342016-10-13 14:33:27 +0200423 if (transit == TRANSIT_DOCK_TASK_FROM_RECENTS && !mProlongedAnimationsEnded) {
Jorim Jaggi363ab982016-04-26 19:51:20 -0700424 for (int i = openingApps.size() - 1; i >= 0; i--) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200425 final AppWindowToken app = openingApps.valueAt(i);
426 app.startDelayingAnimationStart();
Jorim Jaggi363ab982016-04-26 19:51:20 -0700427 }
428 }
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100429 if (mRemoteAnimationController != null) {
430 mRemoteAnimationController.goodToGo();
431 }
Jorim Jaggife762342016-10-13 14:33:27 +0200432 return redoLayout;
Jorim Jaggi363ab982016-04-26 19:51:20 -0700433 }
434
435 /**
436 * Let the transitions manager know that the somebody wanted to end the prolonged animations.
437 */
438 void notifyProlongedAnimationsEnded() {
439 mProlongedAnimationsEnded = true;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800440 }
441
442 void clear() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800443 mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800444 mNextAppTransitionPackage = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700445 mNextAppTransitionAnimationsSpecs.clear();
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100446 mRemoteAnimationController = null;
Jorim Jaggi65193992015-11-23 16:49:59 -0800447 mNextAppTransitionAnimationsSpecsFuture = null;
448 mDefaultNextAppTransitionAnimationSpec = null;
449 mAnimationFinishedCallback = null;
Jorim Jaggi363ab982016-04-26 19:51:20 -0700450 mProlongedAnimationsEnded = false;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800451 }
452
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800453 void freeze() {
Jorim Jaggife762342016-10-13 14:33:27 +0200454 final int transit = mNextAppTransition;
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100455 setAppTransition(TRANSIT_UNSET, 0 /* flags */);
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800456 clear();
457 setReady();
Jorim Jaggife762342016-10-13 14:33:27 +0200458 notifyAppTransitionCancelledLocked(transit);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100459 }
460
Jorim Jaggi245281c2017-06-07 14:33:04 -0700461 private void setAppTransitionState(int state) {
462 mAppTransitionState = state;
463 updateBooster();
464 }
465
466 /**
467 * Updates whether we currently boost wm locked sections and the animation thread. We want to
468 * boost the priorities to a more important value whenever an app transition is going to happen
469 * soon or an app transition is running.
470 */
471 private void updateBooster() {
472 WindowManagerService.sThreadPriorityBooster.setAppTransitionRunning(
473 mNextAppTransition != TRANSIT_UNSET || mAppTransitionState == APP_STATE_READY
474 || mAppTransitionState == APP_STATE_RUNNING);
475 }
476
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100477 void registerListenerLocked(AppTransitionListener listener) {
478 mListeners.add(listener);
479 }
480
Wale Ogunwalea48eadb2015-05-14 17:43:12 -0700481 public void notifyAppTransitionFinishedLocked(IBinder token) {
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100482 for (int i = 0; i < mListeners.size(); i++) {
483 mListeners.get(i).onAppTransitionFinishedLocked(token);
484 }
485 }
486
487 private void notifyAppTransitionPendingLocked() {
488 for (int i = 0; i < mListeners.size(); i++) {
489 mListeners.get(i).onAppTransitionPendingLocked();
490 }
491 }
492
Jorim Jaggife762342016-10-13 14:33:27 +0200493 private void notifyAppTransitionCancelledLocked(int transit) {
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100494 for (int i = 0; i < mListeners.size(); i++) {
Jorim Jaggife762342016-10-13 14:33:27 +0200495 mListeners.get(i).onAppTransitionCancelledLocked(transit);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100496 }
497 }
498
Jorim Jaggife762342016-10-13 14:33:27 +0200499 private int notifyAppTransitionStartingLocked(int transit, IBinder openToken,
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200500 IBinder closeToken, long duration, long statusBarAnimationStartTime,
501 long statusBarAnimationDuration) {
Jorim Jaggife762342016-10-13 14:33:27 +0200502 int redoLayout = 0;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100503 for (int i = 0; i < mListeners.size(); i++) {
Jorim Jaggife762342016-10-13 14:33:27 +0200504 redoLayout |= mListeners.get(i).onAppTransitionStartingLocked(transit, openToken,
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200505 closeToken, duration, statusBarAnimationStartTime, statusBarAnimationDuration);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100506 }
Jorim Jaggife762342016-10-13 14:33:27 +0200507 return redoLayout;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800508 }
509
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100510 private AttributeCache.Entry getCachedAnimations(LayoutParams lp) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800511 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg="
512 + (lp != null ? lp.packageName : null)
513 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
514 if (lp != null && lp.windowAnimations != 0) {
515 // If this is a system resource, don't try to load it from the
516 // application resources. It is nice to avoid loading application
517 // resources if we can.
518 String packageName = lp.packageName != null ? lp.packageName : "android";
519 int resId = lp.windowAnimations;
520 if ((resId&0xFF000000) == 0x01000000) {
521 packageName = "android";
522 }
523 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
524 + packageName);
525 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700526 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800527 }
528 return null;
529 }
530
531 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
532 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package="
533 + packageName + " resId=0x" + Integer.toHexString(resId));
534 if (packageName != null) {
535 if ((resId&0xFF000000) == 0x01000000) {
536 packageName = "android";
537 }
538 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
539 + packageName);
540 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700541 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800542 }
543 return null;
544 }
545
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100546 Animation loadAnimationAttr(LayoutParams lp, int animAttr) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800547 int anim = 0;
548 Context context = mContext;
549 if (animAttr >= 0) {
550 AttributeCache.Entry ent = getCachedAnimations(lp);
551 if (ent != null) {
552 context = ent.context;
553 anim = ent.array.getResourceId(animAttr, 0);
554 }
555 }
556 if (anim != 0) {
557 return AnimationUtils.loadAnimation(context, anim);
558 }
559 return null;
560 }
561
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100562 Animation loadAnimationRes(LayoutParams lp, int resId) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700563 Context context = mContext;
564 if (resId >= 0) {
565 AttributeCache.Entry ent = getCachedAnimations(lp);
566 if (ent != null) {
567 context = ent.context;
568 }
569 return AnimationUtils.loadAnimation(context, resId);
570 }
571 return null;
572 }
573
574 private Animation loadAnimationRes(String packageName, int resId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800575 int anim = 0;
576 Context context = mContext;
577 if (resId >= 0) {
578 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
579 if (ent != null) {
580 context = ent.context;
581 anim = resId;
582 }
583 }
584 if (anim != 0) {
585 return AnimationUtils.loadAnimation(context, anim);
586 }
587 return null;
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
976 final RenderNode node = RenderNode.create("CrossProfileAppsThumbnail", null);
977 node.setLeftTopRightBottom(0, 0, width, height);
978 node.setClipToBounds(false);
979
980 final DisplayListCanvas canvas = node.start(width, height);
981 canvas.drawColor(Color.argb(0.6f, 0, 0, 0));
982 final int thumbnailSize = mService.mContext.getResources().getDimensionPixelSize(
983 com.android.internal.R.dimen.cross_profile_apps_thumbnail_size);
984 final Drawable drawable = mService.mContext.getDrawable(thumbnailDrawableRes);
985 drawable.setBounds(
986 (width - thumbnailSize) / 2,
987 (height - thumbnailSize) / 2,
988 (width + thumbnailSize) / 2,
989 (height + thumbnailSize) / 2);
990 drawable.draw(canvas);
991 node.end(canvas);
992
993 return ThreadedRenderer.createHardwareBitmap(node, width, height)
994 .createGraphicBufferHandle();
995 }
996
997 Animation createCrossProfileAppsThumbnailAnimationLocked(Rect appRect) {
998 final Animation animation = loadAnimationRes(
999 "android", com.android.internal.R.anim.cross_profile_apps_thumbnail_enter);
1000 return prepareThumbnailAnimationWithDuration(animation, appRect.width(),
1001 appRect.height(), 0, null);
1002 }
1003
1004 /**
Winson Chung399f6202014-03-19 10:47:20 -07001005 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001006 * when a thumbnail is specified with the pending animation override.
Winson Chung399f6202014-03-19 10:47:20 -07001007 */
Jorim Jaggide63d442016-03-14 14:56:56 +01001008 Animation createThumbnailAspectScaleAnimationLocked(Rect appRect, @Nullable Rect contentInsets,
Winson Chungaa7fa012017-05-24 15:50:06 -07001009 GraphicBuffer thumbnailHeader, final int taskId, int uiMode, int orientation) {
Winson Chung399f6202014-03-19 10:47:20 -07001010 Animation a;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001011 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chung399f6202014-03-19 10:47:20 -07001012 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001013 final int thumbHeightI = thumbnailHeader.getHeight();
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -07001014 final int appWidth = appRect.width();
Winson Chung399f6202014-03-19 10:47:20 -07001015
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -07001016 float scaleW = appWidth / thumbWidth;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001017 getNextAppTransitionStartRect(taskId, mTmpRect);
Jorim Jaggi09072002016-03-25 16:48:42 -07001018 final float fromX;
Manu Cornet57b61492017-01-24 18:19:05 +09001019 float fromY;
Jorim Jaggi09072002016-03-25 16:48:42 -07001020 final float toX;
Manu Cornet57b61492017-01-24 18:19:05 +09001021 float toY;
Jorim Jaggi09072002016-03-25 16:48:42 -07001022 final float pivotX;
1023 final float pivotY;
Manu Cornetd7376802017-01-13 13:44:07 -08001024 if (shouldScaleDownThumbnailTransition(uiMode, orientation)) {
Jorim Jaggi09072002016-03-25 16:48:42 -07001025 fromX = mTmpRect.left;
1026 fromY = mTmpRect.top;
1027
1028 // For the curved translate animation to work, the pivot points needs to be at the
1029 // same absolute position as the one from the real surface.
1030 toX = mTmpRect.width() / 2 * (scaleW - 1f) + appRect.left;
1031 toY = appRect.height() / 2 * (1 - 1 / scaleW) + appRect.top;
1032 pivotX = mTmpRect.width() / 2;
1033 pivotY = appRect.height() / 2 / scaleW;
Manu Cornet57b61492017-01-24 18:19:05 +09001034 if (mGridLayoutRecentsEnabled) {
1035 // In the grid layout, the header is displayed above the thumbnail instead of
1036 // overlapping it.
1037 fromY -= thumbHeightI;
1038 toY -= thumbHeightI * scaleW;
1039 }
Jorim Jaggi09072002016-03-25 16:48:42 -07001040 } else {
1041 pivotX = 0;
1042 pivotY = 0;
1043 fromX = mTmpRect.left;
1044 fromY = mTmpRect.top;
1045 toX = appRect.left;
1046 toY = appRect.top;
1047 }
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001048 final long duration = getAspectScaleDuration();
1049 final Interpolator interpolator = getAspectScaleInterpolator();
Winson Chung399f6202014-03-19 10:47:20 -07001050 if (mNextAppTransitionScaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001051 // Animation up from the thumbnail to the full screen
Jorim Jaggi8448f332016-03-14 17:50:37 +01001052 Animation scale = new ScaleAnimation(1f, scaleW, 1f, scaleW, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001053 scale.setInterpolator(interpolator);
1054 scale.setDuration(duration);
Jorim Jaggic6c89a82016-01-28 17:48:21 -08001055 Animation alpha = new AlphaAnimation(1f, 0f);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001056 alpha.setInterpolator(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
1057 ? THUMBNAIL_DOCK_INTERPOLATOR : mThumbnailFadeOutInterpolator);
1058 alpha.setDuration(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
1059 ? duration / 2
1060 : duration);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001061 Animation translate = createCurvedMotion(fromX, toX, fromY, toY);
1062 translate.setInterpolator(interpolator);
1063 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -07001064
Jorim Jaggide63d442016-03-14 14:56:56 +01001065 mTmpFromClipRect.set(0, 0, thumbWidthI, thumbHeightI);
1066 mTmpToClipRect.set(appRect);
1067
1068 // Containing frame is in screen space, but we need the clip rect in the
1069 // app space.
1070 mTmpToClipRect.offsetTo(0, 0);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001071 mTmpToClipRect.right = (int) (mTmpToClipRect.right / scaleW);
1072 mTmpToClipRect.bottom = (int) (mTmpToClipRect.bottom / scaleW);
Jorim Jaggide63d442016-03-14 14:56:56 +01001073
1074 if (contentInsets != null) {
Jorim Jaggi8448f332016-03-14 17:50:37 +01001075 mTmpToClipRect.inset((int) (-contentInsets.left * scaleW),
1076 (int) (-contentInsets.top * scaleW),
1077 (int) (-contentInsets.right * scaleW),
1078 (int) (-contentInsets.bottom * scaleW));
Jorim Jaggide63d442016-03-14 14:56:56 +01001079 }
1080
1081 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001082 clipAnim.setInterpolator(interpolator);
1083 clipAnim.setDuration(duration);
Jorim Jaggide63d442016-03-14 14:56:56 +01001084
Winson Chung399f6202014-03-19 10:47:20 -07001085 // This AnimationSet uses the Interpolators assigned above.
1086 AnimationSet set = new AnimationSet(false);
1087 set.addAnimation(scale);
Manu Cornet57b61492017-01-24 18:19:05 +09001088 if (!mGridLayoutRecentsEnabled) {
1089 // In the grid layout, the header should be shown for the whole animation.
1090 set.addAnimation(alpha);
1091 }
Winson Chunga4ccb862014-08-22 15:26:27 -07001092 set.addAnimation(translate);
Jorim Jaggide63d442016-03-14 14:56:56 +01001093 set.addAnimation(clipAnim);
Winson Chung399f6202014-03-19 10:47:20 -07001094 a = set;
1095 } else {
Winson Chunga4ccb862014-08-22 15:26:27 -07001096 // Animation down from the full screen to the thumbnail
Jorim Jaggi8448f332016-03-14 17:50:37 +01001097 Animation scale = new ScaleAnimation(scaleW, 1f, scaleW, 1f, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001098 scale.setInterpolator(interpolator);
1099 scale.setDuration(duration);
Winson Chunga4ccb862014-08-22 15:26:27 -07001100 Animation alpha = new AlphaAnimation(0f, 1f);
1101 alpha.setInterpolator(mThumbnailFadeInInterpolator);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001102 alpha.setDuration(duration);
1103 Animation translate = createCurvedMotion(toX, fromX, toY, fromY);
1104 translate.setInterpolator(interpolator);
1105 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -07001106
Winson Chunga4ccb862014-08-22 15:26:27 -07001107 // This AnimationSet uses the Interpolators assigned above.
1108 AnimationSet set = new AnimationSet(false);
1109 set.addAnimation(scale);
Manu Cornet57b61492017-01-24 18:19:05 +09001110 if (!mGridLayoutRecentsEnabled) {
1111 // In the grid layout, the header should be shown for the whole animation.
1112 set.addAnimation(alpha);
1113 }
Winson Chunga4ccb862014-08-22 15:26:27 -07001114 set.addAnimation(translate);
1115 a = set;
1116
1117 }
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -07001118 return prepareThumbnailAnimationWithDuration(a, appWidth, appRect.height(), 0,
Jorim Jaggic69bd222016-03-15 14:38:37 +01001119 null);
Winson Chung399f6202014-03-19 10:47:20 -07001120 }
1121
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001122 private Animation createCurvedMotion(float fromX, float toX, float fromY, float toY) {
1123
1124 // Almost no x-change - use linear animation
Jorim Jaggic69bd222016-03-15 14:38:37 +01001125 if (Math.abs(toX - fromX) < 1f || mNextAppTransition != TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001126 return new TranslateAnimation(fromX, toX, fromY, toY);
1127 } else {
1128 final Path path = createCurvedPath(fromX, toX, fromY, toY);
1129 return new CurvedTranslateAnimation(path);
1130 }
1131 }
1132
1133 private Path createCurvedPath(float fromX, float toX, float fromY, float toY) {
1134 final Path path = new Path();
1135 path.moveTo(fromX, fromY);
Jorim Jaggi1f458fb2016-03-25 17:36:37 -07001136
1137 if (fromY > toY) {
1138 // If the object needs to go up, move it in horizontal direction first, then vertical.
1139 path.cubicTo(fromX, fromY, toX, 0.9f * fromY + 0.1f * toY, toX, toY);
1140 } else {
1141 // If the object needs to go down, move it in vertical direction first, then horizontal.
1142 path.cubicTo(fromX, fromY, fromX, 0.1f * fromY + 0.9f * toY, toX, toY);
1143 }
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001144 return path;
1145 }
1146
1147 private long getAspectScaleDuration() {
1148 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggic69bd222016-03-15 14:38:37 +01001149 return (long) (THUMBNAIL_APP_TRANSITION_DURATION * 1.35f);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001150 } else {
1151 return THUMBNAIL_APP_TRANSITION_DURATION;
1152 }
1153 }
1154
1155 private Interpolator getAspectScaleInterpolator() {
1156 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
1157 return mFastOutSlowInInterpolator;
1158 } else {
1159 return TOUCH_RESPONSE_INTERPOLATOR;
1160 }
1161 }
1162
Winson Chung399f6202014-03-19 10:47:20 -07001163 /**
1164 * This alternate animation is created when we are doing a thumbnail transition, for the
1165 * activity that is leaving, and the activity that is entering.
1166 */
Winson Chunga4ccb862014-08-22 15:26:27 -07001167 Animation createAspectScaledThumbnailEnterExitAnimationLocked(int thumbTransitState,
Winsonb2024762016-04-05 17:32:30 -07001168 int uiMode, int orientation, int transit, Rect containingFrame, Rect contentInsets,
Matthew Ng43db6d22017-06-27 15:29:39 -07001169 @Nullable Rect surfaceInsets, @Nullable Rect stableInsets, boolean freeform,
1170 int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -07001171 Animation a;
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001172 final int appWidth = containingFrame.width();
1173 final int appHeight = containingFrame.height();
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001174 getDefaultNextAppTransitionStartRect(mTmpRect);
1175 final int thumbWidthI = mTmpRect.width();
Winson Chung399f6202014-03-19 10:47:20 -07001176 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001177 final int thumbHeightI = mTmpRect.height();
Winson Chung399f6202014-03-19 10:47:20 -07001178 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
Winsoncbb625b2016-07-06 15:24:15 -07001179 final int thumbStartX = mTmpRect.left - containingFrame.left - contentInsets.left;
Winson21700932016-03-24 17:26:23 -07001180 final int thumbStartY = mTmpRect.top - containingFrame.top;
Winson Chung399f6202014-03-19 10:47:20 -07001181
1182 switch (thumbTransitState) {
Jorim Jaggi8448f332016-03-14 17:50:37 +01001183 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP:
1184 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1185 final boolean scaleUp = thumbTransitState == THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
1186 if (freeform && scaleUp) {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001187 a = createAspectScaledThumbnailEnterFreeformAnimationLocked(
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001188 containingFrame, surfaceInsets, taskId);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001189 } else if (freeform) {
1190 a = createAspectScaledThumbnailExitFreeformAnimationLocked(
1191 containingFrame, surfaceInsets, taskId);
Winson Chung2820c452014-04-15 15:34:44 -07001192 } else {
Winson21700932016-03-24 17:26:23 -07001193 AnimationSet set = new AnimationSet(true);
1194
1195 // In portrait, we scale to fit the width
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001196 mTmpFromClipRect.set(containingFrame);
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001197 mTmpToClipRect.set(containingFrame);
Jorim Jaggic6c89a82016-01-28 17:48:21 -08001198
1199 // Containing frame is in screen space, but we need the clip rect in the
1200 // app space.
1201 mTmpFromClipRect.offsetTo(0, 0);
1202 mTmpToClipRect.offsetTo(0, 0);
1203
1204 // Exclude insets region from the source clip.
1205 mTmpFromClipRect.inset(contentInsets);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001206 mNextAppTransitionInsets.set(contentInsets);
1207
Manu Cornetd7376802017-01-13 13:44:07 -08001208 if (shouldScaleDownThumbnailTransition(uiMode, orientation)) {
Jorim Jaggic69bd222016-03-15 14:38:37 +01001209 // We scale the width and clip to the top/left square
1210 float scale = thumbWidth /
1211 (appWidth - contentInsets.left - contentInsets.right);
Manu Cornetb68b7652017-01-23 19:37:53 +09001212 if (!mGridLayoutRecentsEnabled) {
1213 int unscaledThumbHeight = (int) (thumbHeight / scale);
1214 mTmpFromClipRect.bottom = mTmpFromClipRect.top + unscaledThumbHeight;
1215 }
Jorim Jaggic69bd222016-03-15 14:38:37 +01001216
1217 mNextAppTransitionInsets.set(contentInsets);
1218
Jorim Jaggi8448f332016-03-14 17:50:37 +01001219 Animation scaleAnim = new ScaleAnimation(
1220 scaleUp ? scale : 1, scaleUp ? 1 : scale,
1221 scaleUp ? scale : 1, scaleUp ? 1 : scale,
Jorim Jaggic69bd222016-03-15 14:38:37 +01001222 containingFrame.width() / 2f,
1223 containingFrame.height() / 2f + contentInsets.top);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001224 final float targetX = (mTmpRect.left - containingFrame.left);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001225 final float x = containingFrame.width() / 2f
1226 - containingFrame.width() / 2f * scale;
Jorim Jaggi8448f332016-03-14 17:50:37 +01001227 final float targetY = (mTmpRect.top - containingFrame.top);
Matthew Ng43db6d22017-06-27 15:29:39 -07001228 float y = containingFrame.height() / 2f
Jorim Jaggic69bd222016-03-15 14:38:37 +01001229 - containingFrame.height() / 2f * scale;
Matthew Ng43db6d22017-06-27 15:29:39 -07001230
1231 // During transition may require clipping offset from any top stable insets
1232 // such as the statusbar height when statusbar is hidden
1233 if (mLowRamRecentsEnabled && contentInsets.top == 0 && scaleUp) {
1234 mTmpFromClipRect.top += stableInsets.top;
1235 y += stableInsets.top;
1236 }
Jorim Jaggi8448f332016-03-14 17:50:37 +01001237 final float startX = targetX - x;
1238 final float startY = targetY - y;
1239 Animation clipAnim = scaleUp
1240 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1241 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1242 Animation translateAnim = scaleUp
Jorim Jaggic69bd222016-03-15 14:38:37 +01001243 ? createCurvedMotion(startX, 0, startY - contentInsets.top, 0)
1244 : createCurvedMotion(0, startX, 0, startY - contentInsets.top);
1245
Winson21700932016-03-24 17:26:23 -07001246 set.addAnimation(clipAnim);
1247 set.addAnimation(scaleAnim);
1248 set.addAnimation(translateAnim);
1249
1250 } else {
1251 // In landscape, we don't scale at all and only crop
1252 mTmpFromClipRect.bottom = mTmpFromClipRect.top + thumbHeightI;
1253 mTmpFromClipRect.right = mTmpFromClipRect.left + thumbWidthI;
1254
Jorim Jaggi8448f332016-03-14 17:50:37 +01001255 Animation clipAnim = scaleUp
1256 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1257 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1258 Animation translateAnim = scaleUp
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001259 ? createCurvedMotion(thumbStartX, 0,
1260 thumbStartY - contentInsets.top, 0)
1261 : createCurvedMotion(0, thumbStartX, 0,
1262 thumbStartY - contentInsets.top);
Winson21700932016-03-24 17:26:23 -07001263
1264 set.addAnimation(clipAnim);
1265 set.addAnimation(translateAnim);
1266 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001267 a = set;
Winson21700932016-03-24 17:26:23 -07001268 a.setZAdjustment(Animation.ZORDER_TOP);
Winson Chung2820c452014-04-15 15:34:44 -07001269 }
Winson Chung399f6202014-03-19 10:47:20 -07001270 break;
1271 }
1272 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001273 // Previous app window during the scale up
Winson Chung399f6202014-03-19 10:47:20 -07001274 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001275 // Fade out the source activity if we are animating to a wallpaper
Winson Chung399f6202014-03-19 10:47:20 -07001276 // activity.
1277 a = new AlphaAnimation(1, 0);
1278 } else {
Winson Chung399f6202014-03-19 10:47:20 -07001279 a = new AlphaAnimation(1, 1);
1280 }
1281 break;
1282 }
1283 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001284 // Target app window during the scale down
1285 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1286 // Fade in the destination activity if we are animating from a wallpaper
1287 // activity.
1288 a = new AlphaAnimation(0, 1);
1289 } else {
1290 a = new AlphaAnimation(1, 1);
1291 }
Winson Chung399f6202014-03-19 10:47:20 -07001292 break;
1293 }
Winson Chung399f6202014-03-19 10:47:20 -07001294 default:
1295 throw new RuntimeException("Invalid thumbnail transition state");
1296 }
1297
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001298 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight,
1299 getAspectScaleDuration(), getAspectScaleInterpolator());
Winson Chung399f6202014-03-19 10:47:20 -07001300 }
1301
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001302 private Animation createAspectScaledThumbnailEnterFreeformAnimationLocked(Rect frame,
1303 @Nullable Rect surfaceInsets, int taskId) {
1304 getNextAppTransitionStartRect(taskId, mTmpRect);
1305 return createAspectScaledThumbnailFreeformAnimationLocked(mTmpRect, frame, surfaceInsets,
1306 true);
1307 }
1308
1309 private Animation createAspectScaledThumbnailExitFreeformAnimationLocked(Rect frame,
1310 @Nullable Rect surfaceInsets, int taskId) {
1311 getNextAppTransitionStartRect(taskId, mTmpRect);
1312 return createAspectScaledThumbnailFreeformAnimationLocked(frame, mTmpRect, surfaceInsets,
1313 false);
1314 }
1315
1316 private AnimationSet createAspectScaledThumbnailFreeformAnimationLocked(Rect sourceFrame,
1317 Rect destFrame, @Nullable Rect surfaceInsets, boolean enter) {
1318 final float sourceWidth = sourceFrame.width();
1319 final float sourceHeight = sourceFrame.height();
1320 final float destWidth = destFrame.width();
1321 final float destHeight = destFrame.height();
1322 final float scaleH = enter ? sourceWidth / destWidth : destWidth / sourceWidth;
1323 final float scaleV = enter ? sourceHeight / destHeight : destHeight / sourceHeight;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001324 AnimationSet set = new AnimationSet(true);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001325 final int surfaceInsetsH = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001326 ? 0 : surfaceInsets.left + surfaceInsets.right;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001327 final int surfaceInsetsV = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001328 ? 0 : surfaceInsets.top + surfaceInsets.bottom;
1329 // We want the scaling to happen from the center of the surface. In order to achieve that,
1330 // we need to account for surface insets that will be used to enlarge the surface.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001331 final float scaleHCenter = ((enter ? destWidth : sourceWidth) + surfaceInsetsH) / 2;
1332 final float scaleVCenter = ((enter ? destHeight : sourceHeight) + surfaceInsetsV) / 2;
1333 final ScaleAnimation scale = enter ?
1334 new ScaleAnimation(scaleH, 1, scaleV, 1, scaleHCenter, scaleVCenter)
1335 : new ScaleAnimation(1, scaleH, 1, scaleV, scaleHCenter, scaleVCenter);
1336 final int sourceHCenter = sourceFrame.left + sourceFrame.width() / 2;
1337 final int sourceVCenter = sourceFrame.top + sourceFrame.height() / 2;
1338 final int destHCenter = destFrame.left + destFrame.width() / 2;
1339 final int destVCenter = destFrame.top + destFrame.height() / 2;
1340 final int fromX = enter ? sourceHCenter - destHCenter : destHCenter - sourceHCenter;
1341 final int fromY = enter ? sourceVCenter - destVCenter : destVCenter - sourceVCenter;
1342 final TranslateAnimation translation = enter ? new TranslateAnimation(fromX, 0, fromY, 0)
1343 : new TranslateAnimation(0, fromX, 0, fromY);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001344 set.addAnimation(scale);
1345 set.addAnimation(translation);
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001346
1347 final IRemoteCallback callback = mAnimationFinishedCallback;
1348 if (callback != null) {
1349 set.setAnimationListener(new Animation.AnimationListener() {
1350 @Override
1351 public void onAnimationStart(Animation animation) { }
1352
1353 @Override
1354 public void onAnimationEnd(Animation animation) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001355 mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK, callback).sendToTarget();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001356 }
1357
1358 @Override
1359 public void onAnimationRepeat(Animation animation) { }
1360 });
1361 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001362 return set;
1363 }
1364
Winson Chung399f6202014-03-19 10:47:20 -07001365 /**
Winson Chunga4ccb862014-08-22 15:26:27 -07001366 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001367 * when a thumbnail is specified with the pending animation override.
Winson Chunga4ccb862014-08-22 15:26:27 -07001368 */
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001369 Animation createThumbnailScaleAnimationLocked(int appWidth, int appHeight, int transit,
Winson Chungaa7fa012017-05-24 15:50:06 -07001370 GraphicBuffer thumbnailHeader) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001371 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001372 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001373 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chunga4ccb862014-08-22 15:26:27 -07001374 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001375 final int thumbHeightI = thumbnailHeader.getHeight();
Winson Chunga4ccb862014-08-22 15:26:27 -07001376 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1377
1378 if (mNextAppTransitionScaleUp) {
1379 // Animation for the thumbnail zooming from its initial size to the full screen
1380 float scaleW = appWidth / thumbWidth;
1381 float scaleH = appHeight / thumbHeight;
1382 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001383 computePivot(mTmpRect.left, 1 / scaleW),
1384 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001385 scale.setInterpolator(mDecelerateInterpolator);
1386
1387 Animation alpha = new AlphaAnimation(1, 0);
1388 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
1389
1390 // This AnimationSet uses the Interpolators assigned above.
1391 AnimationSet set = new AnimationSet(false);
1392 set.addAnimation(scale);
1393 set.addAnimation(alpha);
1394 a = set;
1395 } else {
1396 // Animation for the thumbnail zooming down from the full screen to its final size
1397 float scaleW = appWidth / thumbWidth;
1398 float scaleH = appHeight / thumbHeight;
1399 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001400 computePivot(mTmpRect.left, 1 / scaleW),
1401 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001402 }
1403
1404 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1405 }
1406
1407 /**
Winson Chung399f6202014-03-19 10:47:20 -07001408 * This animation is created when we are doing a thumbnail transition, for the activity that is
1409 * leaving, and the activity that is entering.
1410 */
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001411 Animation createThumbnailEnterExitAnimationLocked(int thumbTransitState, Rect containingFrame,
1412 int transit, int taskId) {
1413 final int appWidth = containingFrame.width();
1414 final int appHeight = containingFrame.height();
Winson Chungaa7fa012017-05-24 15:50:06 -07001415 final GraphicBuffer thumbnailHeader = getAppTransitionThumbnailHeader(taskId);
Winson Chung399f6202014-03-19 10:47:20 -07001416 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001417 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001418 final int thumbWidthI = thumbnailHeader != null ? thumbnailHeader.getWidth() : appWidth;
Winson Chung399f6202014-03-19 10:47:20 -07001419 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001420 final int thumbHeightI = thumbnailHeader != null ? thumbnailHeader.getHeight() : appHeight;
Winson Chung399f6202014-03-19 10:47:20 -07001421 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1422
1423 switch (thumbTransitState) {
1424 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
1425 // Entering app scales up with the thumbnail
1426 float scaleW = thumbWidth / appWidth;
1427 float scaleH = thumbHeight / appHeight;
1428 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001429 computePivot(mTmpRect.left, scaleW),
1430 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001431 break;
1432 }
1433 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
1434 // Exiting app while the thumbnail is scaling up should fade or stay in place
1435 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1436 // Fade out while bringing up selected activity. This keeps the
1437 // current activity from showing through a launching wallpaper
1438 // activity.
1439 a = new AlphaAnimation(1, 0);
1440 } else {
1441 // noop animation
1442 a = new AlphaAnimation(1, 1);
1443 }
1444 break;
1445 }
1446 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
1447 // Entering the other app, it should just be visible while we scale the thumbnail
1448 // down above it
1449 a = new AlphaAnimation(1, 1);
1450 break;
1451 }
1452 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1453 // Exiting the current app, the app should scale down with the thumbnail
1454 float scaleW = thumbWidth / appWidth;
1455 float scaleH = thumbHeight / appHeight;
1456 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001457 computePivot(mTmpRect.left, scaleW),
1458 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001459
1460 Animation alpha = new AlphaAnimation(1, 0);
1461
1462 AnimationSet set = new AnimationSet(true);
1463 set.addAnimation(scale);
1464 set.addAnimation(alpha);
1465 set.setZAdjustment(Animation.ZORDER_TOP);
1466 a = set;
1467 break;
1468 }
1469 default:
1470 throw new RuntimeException("Invalid thumbnail transition state");
1471 }
1472
1473 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1474 }
1475
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001476 private Animation createRelaunchAnimation(Rect containingFrame, Rect contentInsets) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001477 getDefaultNextAppTransitionStartRect(mTmpFromClipRect);
1478 final int left = mTmpFromClipRect.left;
1479 final int top = mTmpFromClipRect.top;
1480 mTmpFromClipRect.offset(-left, -top);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001481 // TODO: Isn't that strange that we ignore exact position of the containingFrame?
1482 mTmpToClipRect.set(0, 0, containingFrame.width(), containingFrame.height());
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001483 AnimationSet set = new AnimationSet(true);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001484 float fromWidth = mTmpFromClipRect.width();
1485 float toWidth = mTmpToClipRect.width();
1486 float fromHeight = mTmpFromClipRect.height();
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001487 // While the window might span the whole display, the actual content will be cropped to the
1488 // system decoration frame, for example when the window is docked. We need to take into
1489 // account the visible height when constructing the animation.
1490 float toHeight = mTmpToClipRect.height() - contentInsets.top - contentInsets.bottom;
1491 int translateAdjustment = 0;
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001492 if (fromWidth <= toWidth && fromHeight <= toHeight) {
1493 // The final window is larger in both dimensions than current window (e.g. we are
1494 // maximizing), so we can simply unclip the new window and there will be no disappearing
1495 // frame.
1496 set.addAnimation(new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect));
1497 } else {
1498 // The disappearing window has one larger dimension. We need to apply scaling, so the
1499 // first frame of the entry animation matches the old window.
1500 set.addAnimation(new ScaleAnimation(fromWidth / toWidth, 1, fromHeight / toHeight, 1));
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001501 // We might not be going exactly full screen, but instead be aligned under the status
1502 // bar using cropping. We still need to account for the cropped part, which will also
1503 // be scaled.
1504 translateAdjustment = (int) (contentInsets.top * fromHeight / toHeight);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001505 }
1506
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001507 // We animate the translation from the old position of the removed window, to the new
1508 // position of the added window. The latter might not be full screen, for example docked for
1509 // docked windows.
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001510 TranslateAnimation translate = new TranslateAnimation(left - containingFrame.left,
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001511 0, top - containingFrame.top - translateAdjustment, 0);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001512 set.addAnimation(translate);
1513 set.setDuration(DEFAULT_APP_TRANSITION_DURATION);
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07001514 set.setZAdjustment(Animation.ZORDER_TOP);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001515 return set;
1516 }
1517
Jorim Jaggic554b772015-06-04 16:07:57 -07001518 /**
1519 * @return true if and only if the first frame of the transition can be skipped, i.e. the first
1520 * frame of the transition doesn't change the visuals on screen, so we can start
1521 * directly with the second one
1522 */
1523 boolean canSkipFirstFrame() {
1524 return mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM
1525 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE
Jorim Jaggife762342016-10-13 14:33:27 +02001526 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CLIP_REVEAL
1527 && mNextAppTransition != TRANSIT_KEYGUARD_GOING_AWAY;
Jorim Jaggic554b772015-06-04 16:07:57 -07001528 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001529
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001530 RemoteAnimationController getRemoteAnimationController() {
1531 return mRemoteAnimationController;
1532 }
1533
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001534 /**
1535 *
1536 * @param frame These are the bounds of the window when it finishes the animation. This is where
1537 * the animation must usually finish in entrance animation, as the next frame will
1538 * display the window at these coordinates. In case of exit animation, this is
1539 * where the animation must start, as the frame before the animation is displaying
1540 * the window at these bounds.
1541 * @param insets Knowing where the window will be positioned is not enough. Some parts of the
1542 * window might be obscured, usually by the system windows (status bar and
1543 * navigation bar) and we use content insets to convey that information. This
1544 * usually affects the animation aspects vertically, as the system decoration is
1545 * at the top and the bottom. For example when we animate from full screen to
1546 * recents, we want to exclude the covered parts, because they won't match the
1547 * thumbnail after the last frame is executed.
1548 * @param surfaceInsets In rare situation the surface is larger than the content and we need to
1549 * know about this to make the animation frames match. We currently use
1550 * this for freeform windows, which have larger surfaces to display
1551 * shadows. When we animate them from recents, we want to match the content
1552 * to the recents thumbnail and hence need to account for the surface being
1553 * bigger.
1554 */
Jorim Jaggif84e2f62018-01-16 14:17:59 +01001555 Animation loadAnimation(LayoutParams lp, int transit, boolean enter, int uiMode,
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001556 int orientation, Rect frame, Rect displayFrame, Rect insets,
Matthew Ng43db6d22017-06-27 15:29:39 -07001557 @Nullable Rect surfaceInsets, @Nullable Rect stableInsets, boolean isVoiceInteraction,
1558 boolean freeform, int taskId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001559 Animation a;
Jorim Jaggife762342016-10-13 14:33:27 +02001560 if (isKeyguardGoingAwayTransit(transit) && enter) {
1561 a = loadKeyguardExitAnimation(transit);
1562 } else if (transit == TRANSIT_KEYGUARD_OCCLUDE) {
1563 a = null;
1564 } else if (transit == TRANSIT_KEYGUARD_UNOCCLUDE && !enter) {
1565 a = loadAnimationRes(lp, com.android.internal.R.anim.wallpaper_open_exit);
1566 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_OPEN
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001567 || transit == TRANSIT_TASK_OPEN
1568 || transit == TRANSIT_TASK_TO_FRONT)) {
1569 a = loadAnimationRes(lp, enter
1570 ? com.android.internal.R.anim.voice_activity_open_enter
1571 : com.android.internal.R.anim.voice_activity_open_exit);
1572 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1573 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001574 + " anim=" + a + " transit=" + appTransitionToString(transit)
1575 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001576 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_CLOSE
1577 || transit == TRANSIT_TASK_CLOSE
1578 || transit == TRANSIT_TASK_TO_BACK)) {
1579 a = loadAnimationRes(lp, enter
1580 ? com.android.internal.R.anim.voice_activity_close_enter
1581 : com.android.internal.R.anim.voice_activity_close_exit);
1582 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1583 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001584 + " anim=" + a + " transit=" + appTransitionToString(transit)
1585 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001586 } else if (transit == TRANSIT_ACTIVITY_RELAUNCH) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001587 a = createRelaunchAnimation(frame, insets);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001588 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1589 "applyAnimation:"
1590 + " anim=" + a + " nextAppTransition=" + mNextAppTransition
1591 + " transit=" + appTransitionToString(transit)
1592 + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001593 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM) {
1594 a = loadAnimationRes(mNextAppTransitionPackage, enter ?
Craig Mautner164d4bb2012-11-26 13:51:23 -08001595 mNextAppTransitionEnter : mNextAppTransitionExit);
1596 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1597 "applyAnimation:"
1598 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001599 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001600 + " Callers=" + Debug.getCallers(3));
Winson Chung044d5292014-11-06 11:05:19 -08001601 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE) {
1602 a = loadAnimationRes(mNextAppTransitionPackage, mNextAppTransitionInPlace);
1603 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1604 "applyAnimation:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001605 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM_IN_PLACE"
1606 + " transit=" + appTransitionToString(transit)
1607 + " Callers=" + Debug.getCallers(3));
Chet Haase10e23ab2015-02-11 15:08:38 -08001608 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001609 a = createClipRevealAnimationLocked(transit, enter, frame, displayFrame);
Chet Haase10e23ab2015-02-11 15:08:38 -08001610 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1611 "applyAnimation:"
1612 + " anim=" + a + " nextAppTransition=ANIM_CLIP_REVEAL"
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001613 + " transit=" + appTransitionToString(transit)
Chet Haase10e23ab2015-02-11 15:08:38 -08001614 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001615 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_SCALE_UP) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001616 a = createScaleUpAnimationLocked(transit, enter, frame);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001617 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1618 "applyAnimation:"
1619 + " anim=" + a + " nextAppTransition=ANIM_SCALE_UP"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001620 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001621 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001622 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
1623 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001624 mNextAppTransitionScaleUp =
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001625 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP);
Winson Chunga4ccb862014-08-22 15:26:27 -07001626 a = createThumbnailEnterExitAnimationLocked(getThumbnailTransitionState(enter),
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001627 frame, transit, taskId);
Winson Chunga4ccb862014-08-22 15:26:27 -07001628 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1629 String animName = mNextAppTransitionScaleUp ?
1630 "ANIM_THUMBNAIL_SCALE_UP" : "ANIM_THUMBNAIL_SCALE_DOWN";
1631 Slog.v(TAG, "applyAnimation:"
1632 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001633 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Winson Chunga4ccb862014-08-22 15:26:27 -07001634 + " Callers=" + Debug.getCallers(3));
1635 }
1636 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
1637 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN) {
1638 mNextAppTransitionScaleUp =
1639 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP);
1640 a = createAspectScaledThumbnailEnterExitAnimationLocked(
Winsonb2024762016-04-05 17:32:30 -07001641 getThumbnailTransitionState(enter), uiMode, orientation, transit, frame,
Matthew Ng43db6d22017-06-27 15:29:39 -07001642 insets, surfaceInsets, stableInsets, freeform, taskId);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001643 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1644 String animName = mNextAppTransitionScaleUp ?
Winson Chunga4ccb862014-08-22 15:26:27 -07001645 "ANIM_THUMBNAIL_ASPECT_SCALE_UP" : "ANIM_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner164d4bb2012-11-26 13:51:23 -08001646 Slog.v(TAG, "applyAnimation:"
1647 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001648 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001649 + " Callers=" + Debug.getCallers(3));
1650 }
Tony Mak83546a82018-01-22 13:56:20 +00001651 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS && enter) {
Tony Mak64b8d562017-12-28 17:44:02 +00001652
Tony Mak089c35e2017-12-18 20:34:14 +00001653 a = loadAnimationRes("android", enter
Tony Mak64b8d562017-12-28 17:44:02 +00001654 ? com.android.internal.R.anim.task_open_enter_cross_profile_apps
1655 : com.android.internal.R.anim.task_open_exit);
Tony Mak089c35e2017-12-18 20:34:14 +00001656 Slog.v(TAG,
1657 "applyAnimation NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS:"
1658 + " anim=" + a + " transit=" + appTransitionToString(transit)
1659 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Craig Mautner164d4bb2012-11-26 13:51:23 -08001660 } else {
1661 int animAttr = 0;
1662 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001663 case TRANSIT_ACTIVITY_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001664 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001665 ? WindowAnimation_activityOpenEnterAnimation
1666 : WindowAnimation_activityOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001667 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001668 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001669 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001670 ? WindowAnimation_activityCloseEnterAnimation
1671 : WindowAnimation_activityCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001672 break;
Jorim Jaggi192086e2016-03-11 17:17:03 +01001673 case TRANSIT_DOCK_TASK_FROM_RECENTS:
Craig Mautner4b71aa12012-12-27 17:20:01 -08001674 case TRANSIT_TASK_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001675 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001676 ? WindowAnimation_taskOpenEnterAnimation
1677 : WindowAnimation_taskOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001678 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001679 case TRANSIT_TASK_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001680 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001681 ? WindowAnimation_taskCloseEnterAnimation
1682 : WindowAnimation_taskCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001683 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001684 case TRANSIT_TASK_TO_FRONT:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001685 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001686 ? WindowAnimation_taskToFrontEnterAnimation
1687 : WindowAnimation_taskToFrontExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001688 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001689 case TRANSIT_TASK_TO_BACK:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001690 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001691 ? WindowAnimation_taskToBackEnterAnimation
1692 : WindowAnimation_taskToBackExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001693 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001694 case TRANSIT_WALLPAPER_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001695 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001696 ? WindowAnimation_wallpaperOpenEnterAnimation
1697 : WindowAnimation_wallpaperOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001698 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001699 case TRANSIT_WALLPAPER_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001700 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001701 ? WindowAnimation_wallpaperCloseEnterAnimation
1702 : WindowAnimation_wallpaperCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001703 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001704 case TRANSIT_WALLPAPER_INTRA_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001705 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001706 ? WindowAnimation_wallpaperIntraOpenEnterAnimation
1707 : WindowAnimation_wallpaperIntraOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001708 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001709 case TRANSIT_WALLPAPER_INTRA_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001710 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001711 ? WindowAnimation_wallpaperIntraCloseEnterAnimation
1712 : WindowAnimation_wallpaperIntraCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001713 break;
Craig Mautnerbb742462014-07-07 15:28:55 -07001714 case TRANSIT_TASK_OPEN_BEHIND:
1715 animAttr = enter
1716 ? WindowAnimation_launchTaskBehindSourceAnimation
Craig Mautner3b2cd1d2014-08-25 14:25:54 -07001717 : WindowAnimation_launchTaskBehindTargetAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001718 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001719 a = animAttr != 0 ? loadAnimationAttr(lp, animAttr) : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001720 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1721 "applyAnimation:"
1722 + " anim=" + a
1723 + " animAttr=0x" + Integer.toHexString(animAttr)
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001724 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001725 + " Callers=" + Debug.getCallers(3));
1726 }
1727 return a;
1728 }
1729
Jorim Jaggife762342016-10-13 14:33:27 +02001730 private Animation loadKeyguardExitAnimation(int transit) {
1731 if ((mNextAppTransitionFlags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_NO_ANIMATION) != 0) {
1732 return null;
1733 }
1734 final boolean toShade =
1735 (mNextAppTransitionFlags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_TO_SHADE) != 0;
1736 return mService.mPolicy.createHiddenByKeyguardExit(
1737 transit == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER, toShade);
1738 }
1739
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001740 int getAppStackClipMode() {
Matthew Ngbf1d9852017-03-14 12:23:09 -07001741 // When dismiss keyguard animation occurs, clip before the animation to prevent docked
1742 // app from showing beyond the divider
1743 if (mNextAppTransition == TRANSIT_KEYGUARD_GOING_AWAY
1744 || mNextAppTransition == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER) {
1745 return STACK_CLIP_BEFORE_ANIM;
1746 }
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001747 return mNextAppTransition == TRANSIT_ACTIVITY_RELAUNCH
Jorim Jaggic69bd222016-03-15 14:38:37 +01001748 || mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
Jorim Jaggi1f458fb2016-03-25 17:36:37 -07001749 || mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001750 ? STACK_CLIP_NONE
1751 : STACK_CLIP_AFTER_ANIM;
1752 }
1753
Jorim Jaggife762342016-10-13 14:33:27 +02001754 public int getTransitFlags() {
1755 return mNextAppTransitionFlags;
1756 }
1757
Craig Mautner164d4bb2012-11-26 13:51:23 -08001758 void postAnimationCallback() {
1759 if (mNextAppTransitionCallback != null) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001760 mService.mH.sendMessage(mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK,
1761 mNextAppTransitionCallback));
Craig Mautner164d4bb2012-11-26 13:51:23 -08001762 mNextAppTransitionCallback = null;
1763 }
1764 }
1765
1766 void overridePendingAppTransition(String packageName, int enterAnim, int exitAnim,
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001767 IRemoteCallback startedCallback) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001768 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001769 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001770 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001771 mNextAppTransitionPackage = packageName;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001772 mNextAppTransitionEnter = enterAnim;
1773 mNextAppTransitionExit = exitAnim;
1774 postAnimationCallback();
1775 mNextAppTransitionCallback = startedCallback;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001776 }
1777 }
1778
1779 void overridePendingAppTransitionScaleUp(int startX, int startY, int startWidth,
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001780 int startHeight) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001781 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001782 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001783 mNextAppTransitionType = NEXT_TRANSIT_TYPE_SCALE_UP;
Winson4c3fecd2016-07-13 12:29:48 -07001784 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001785 postAnimationCallback();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001786 }
1787 }
1788
Chet Haase10e23ab2015-02-11 15:08:38 -08001789 void overridePendingAppTransitionClipReveal(int startX, int startY,
1790 int startWidth, int startHeight) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001791 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001792 clear();
Chet Haase10e23ab2015-02-11 15:08:38 -08001793 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CLIP_REVEAL;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001794 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Chet Haase10e23ab2015-02-11 15:08:38 -08001795 postAnimationCallback();
Chet Haase10e23ab2015-02-11 15:08:38 -08001796 }
1797 }
1798
Winson Chungaa7fa012017-05-24 15:50:06 -07001799 void overridePendingAppTransitionThumb(GraphicBuffer srcThumb, int startX, int startY,
Craig Mautner164d4bb2012-11-26 13:51:23 -08001800 IRemoteCallback startedCallback, boolean scaleUp) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001801 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001802 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001803 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP
1804 : NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001805 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001806 putDefaultNextAppTransitionCoordinates(startX, startY, 0, 0, srcThumb);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001807 postAnimationCallback();
1808 mNextAppTransitionCallback = startedCallback;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001809 }
1810 }
1811
Winson Chungaa7fa012017-05-24 15:50:06 -07001812 void overridePendingAppTransitionAspectScaledThumb(GraphicBuffer srcThumb, int startX, int startY,
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001813 int targetWidth, int targetHeight, IRemoteCallback startedCallback, boolean scaleUp) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001814 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001815 clear();
Winson Chunga4ccb862014-08-22 15:26:27 -07001816 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1817 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Winson Chunga4ccb862014-08-22 15:26:27 -07001818 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001819 putDefaultNextAppTransitionCoordinates(startX, startY, targetWidth, targetHeight,
1820 srcThumb);
Winson Chunga4ccb862014-08-22 15:26:27 -07001821 postAnimationCallback();
1822 mNextAppTransitionCallback = startedCallback;
Winson Chunga4ccb862014-08-22 15:26:27 -07001823 }
1824 }
1825
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001826 void overridePendingAppTransitionMultiThumb(AppTransitionAnimationSpec[] specs,
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001827 IRemoteCallback onAnimationStartedCallback, IRemoteCallback onAnimationFinishedCallback,
1828 boolean scaleUp) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001829 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001830 clear();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001831 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1832 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001833 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi43102412015-11-11 16:28:37 +01001834 if (specs != null) {
1835 for (int i = 0; i < specs.length; i++) {
1836 AppTransitionAnimationSpec spec = specs[i];
1837 if (spec != null) {
1838 mNextAppTransitionAnimationsSpecs.put(spec.taskId, spec);
1839 if (i == 0) {
1840 // In full screen mode, the transition code depends on the default spec
1841 // to be set.
1842 Rect rect = spec.rect;
1843 putDefaultNextAppTransitionCoordinates(rect.left, rect.top,
Winson Chungaa7fa012017-05-24 15:50:06 -07001844 rect.width(), rect.height(), spec.buffer);
Jorim Jaggi43102412015-11-11 16:28:37 +01001845 }
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001846 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001847 }
1848 }
1849 postAnimationCallback();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001850 mNextAppTransitionCallback = onAnimationStartedCallback;
1851 mAnimationFinishedCallback = onAnimationFinishedCallback;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001852 }
1853 }
1854
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001855 void overridePendingAppTransitionMultiThumbFuture(
1856 IAppTransitionAnimationSpecsFuture specsFuture, IRemoteCallback callback,
1857 boolean scaleUp) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001858 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001859 clear();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001860 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1861 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001862 mNextAppTransitionAnimationsSpecsFuture = specsFuture;
1863 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001864 mNextAppTransitionFutureCallback = callback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001865 }
1866 }
1867
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001868 void overridePendingAppTransitionRemote(RemoteAnimationAdapter remoteAnimationAdapter) {
Winson Chung044d5292014-11-06 11:05:19 -08001869 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001870 clear();
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001871 mNextAppTransitionType = NEXT_TRANSIT_TYPE_REMOTE;
1872 mRemoteAnimationController = new RemoteAnimationController(mService,
1873 remoteAnimationAdapter, mService.mH);
1874 }
1875 }
1876
1877 void overrideInPlaceAppTransition(String packageName, int anim) {
1878 if (canOverridePendingAppTransition()) {
1879 clear();
Winson Chung044d5292014-11-06 11:05:19 -08001880 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE;
1881 mNextAppTransitionPackage = packageName;
1882 mNextAppTransitionInPlace = anim;
Winson Chung044d5292014-11-06 11:05:19 -08001883 }
1884 }
1885
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001886 /**
Tony Mak089c35e2017-12-18 20:34:14 +00001887 * @see {@link #NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS}
1888 */
1889 void overridePendingAppTransitionStartCrossProfileApps() {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001890 if (canOverridePendingAppTransition()) {
Tony Mak089c35e2017-12-18 20:34:14 +00001891 clear();
1892 mNextAppTransitionType = NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS;
1893 postAnimationCallback();
1894 }
1895 }
1896
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001897 private boolean canOverridePendingAppTransition() {
1898 // Remote animations always take precedence
1899 return isTransitionSet() && mNextAppTransitionType != NEXT_TRANSIT_TYPE_REMOTE;
1900 }
1901
Tony Mak089c35e2017-12-18 20:34:14 +00001902 /**
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001903 * If a future is set for the app transition specs, fetch it in another thread.
1904 */
1905 private void fetchAppTransitionSpecsFromFuture() {
1906 if (mNextAppTransitionAnimationsSpecsFuture != null) {
1907 mNextAppTransitionAnimationsSpecsPending = true;
1908 final IAppTransitionAnimationSpecsFuture future
1909 = mNextAppTransitionAnimationsSpecsFuture;
1910 mNextAppTransitionAnimationsSpecsFuture = null;
Jorim Jaggied410b62017-05-05 15:16:14 +02001911 mDefaultExecutor.execute(() -> {
1912 AppTransitionAnimationSpec[] specs = null;
1913 try {
1914 Binder.allowBlocking(future.asBinder());
1915 specs = future.get();
1916 } catch (RemoteException e) {
1917 Slog.w(TAG, "Failed to fetch app transition specs: " + e);
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001918 }
Jorim Jaggied410b62017-05-05 15:16:14 +02001919 synchronized (mService.mWindowMap) {
1920 mNextAppTransitionAnimationsSpecsPending = false;
1921 overridePendingAppTransitionMultiThumb(specs,
1922 mNextAppTransitionFutureCallback, null /* finishedCallback */,
1923 mNextAppTransitionScaleUp);
1924 mNextAppTransitionFutureCallback = null;
Jorim Jaggied410b62017-05-05 15:16:14 +02001925 }
1926 mService.requestTraversal();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001927 });
1928 }
1929 }
1930
Craig Mautner164d4bb2012-11-26 13:51:23 -08001931 @Override
1932 public String toString() {
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001933 return "mNextAppTransition=" + appTransitionToString(mNextAppTransition);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001934 }
1935
Craig Mautner4b71aa12012-12-27 17:20:01 -08001936 /**
1937 * Returns the human readable name of a window transition.
1938 *
1939 * @param transition The window transition.
1940 * @return The transition symbolic name.
1941 */
1942 public static String appTransitionToString(int transition) {
1943 switch (transition) {
1944 case TRANSIT_UNSET: {
1945 return "TRANSIT_UNSET";
1946 }
1947 case TRANSIT_NONE: {
1948 return "TRANSIT_NONE";
1949 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001950 case TRANSIT_ACTIVITY_OPEN: {
1951 return "TRANSIT_ACTIVITY_OPEN";
1952 }
1953 case TRANSIT_ACTIVITY_CLOSE: {
1954 return "TRANSIT_ACTIVITY_CLOSE";
1955 }
1956 case TRANSIT_TASK_OPEN: {
1957 return "TRANSIT_TASK_OPEN";
1958 }
1959 case TRANSIT_TASK_CLOSE: {
1960 return "TRANSIT_TASK_CLOSE";
1961 }
1962 case TRANSIT_TASK_TO_FRONT: {
1963 return "TRANSIT_TASK_TO_FRONT";
1964 }
1965 case TRANSIT_TASK_TO_BACK: {
1966 return "TRANSIT_TASK_TO_BACK";
1967 }
1968 case TRANSIT_WALLPAPER_CLOSE: {
1969 return "TRANSIT_WALLPAPER_CLOSE";
1970 }
1971 case TRANSIT_WALLPAPER_OPEN: {
1972 return "TRANSIT_WALLPAPER_OPEN";
1973 }
1974 case TRANSIT_WALLPAPER_INTRA_OPEN: {
1975 return "TRANSIT_WALLPAPER_INTRA_OPEN";
1976 }
1977 case TRANSIT_WALLPAPER_INTRA_CLOSE: {
1978 return "TRANSIT_WALLPAPER_INTRA_CLOSE";
1979 }
Craig Mautnerbb742462014-07-07 15:28:55 -07001980 case TRANSIT_TASK_OPEN_BEHIND: {
1981 return "TRANSIT_TASK_OPEN_BEHIND";
1982 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001983 case TRANSIT_ACTIVITY_RELAUNCH: {
1984 return "TRANSIT_ACTIVITY_RELAUNCH";
1985 }
Jorim Jaggi192086e2016-03-11 17:17:03 +01001986 case TRANSIT_DOCK_TASK_FROM_RECENTS: {
1987 return "TRANSIT_DOCK_TASK_FROM_RECENTS";
1988 }
Jorim Jaggife762342016-10-13 14:33:27 +02001989 case TRANSIT_KEYGUARD_GOING_AWAY: {
1990 return "TRANSIT_KEYGUARD_GOING_AWAY";
1991 }
1992 case TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER: {
1993 return "TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER";
1994 }
1995 case TRANSIT_KEYGUARD_OCCLUDE: {
1996 return "TRANSIT_KEYGUARD_OCCLUDE";
1997 }
1998 case TRANSIT_KEYGUARD_UNOCCLUDE: {
1999 return "TRANSIT_KEYGUARD_UNOCCLUDE";
2000 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002001 default: {
2002 return "<UNKNOWN>";
2003 }
2004 }
2005 }
2006
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002007 private String appStateToString() {
2008 switch (mAppTransitionState) {
2009 case APP_STATE_IDLE:
2010 return "APP_STATE_IDLE";
2011 case APP_STATE_READY:
2012 return "APP_STATE_READY";
2013 case APP_STATE_RUNNING:
2014 return "APP_STATE_RUNNING";
2015 case APP_STATE_TIMEOUT:
2016 return "APP_STATE_TIMEOUT";
2017 default:
2018 return "unknown state=" + mAppTransitionState;
2019 }
2020 }
2021
2022 private String transitTypeToString() {
2023 switch (mNextAppTransitionType) {
2024 case NEXT_TRANSIT_TYPE_NONE:
2025 return "NEXT_TRANSIT_TYPE_NONE";
2026 case NEXT_TRANSIT_TYPE_CUSTOM:
2027 return "NEXT_TRANSIT_TYPE_CUSTOM";
Winson Chung044d5292014-11-06 11:05:19 -08002028 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
2029 return "NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002030 case NEXT_TRANSIT_TYPE_SCALE_UP:
2031 return "NEXT_TRANSIT_TYPE_SCALE_UP";
2032 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
2033 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP";
2034 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
2035 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN";
Winson Chunga4ccb862014-08-22 15:26:27 -07002036 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
2037 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP";
2038 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN:
2039 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN";
Tony Mak64b8d562017-12-28 17:44:02 +00002040 case NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS:
2041 return "NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002042 default:
2043 return "unknown type=" + mNextAppTransitionType;
2044 }
2045 }
2046
Steven Timotiusaf03df62017-07-18 16:56:43 -07002047 void writeToProto(ProtoOutputStream proto, long fieldId) {
2048 final long token = proto.start(fieldId);
2049 proto.write(APP_TRANSITION_STATE, mAppTransitionState);
2050 proto.write(LAST_USED_APP_TRANSITION, mLastUsedAppTransition);
2051 proto.end(token);
2052 }
2053
Craig Mautner164d4bb2012-11-26 13:51:23 -08002054 @Override
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002055 public void dump(PrintWriter pw, String prefix) {
2056 pw.print(prefix); pw.println(this);
2057 pw.print(prefix); pw.print("mAppTransitionState="); pw.println(appStateToString());
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002058 if (mNextAppTransitionType != NEXT_TRANSIT_TYPE_NONE) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002059 pw.print(prefix); pw.print("mNextAppTransitionType=");
2060 pw.println(transitTypeToString());
Craig Mautner164d4bb2012-11-26 13:51:23 -08002061 }
2062 switch (mNextAppTransitionType) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002063 case NEXT_TRANSIT_TYPE_CUSTOM:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002064 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Craig Mautner164d4bb2012-11-26 13:51:23 -08002065 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002066 pw.print(prefix); pw.print("mNextAppTransitionEnter=0x");
Craig Mautner164d4bb2012-11-26 13:51:23 -08002067 pw.print(Integer.toHexString(mNextAppTransitionEnter));
2068 pw.print(" mNextAppTransitionExit=0x");
2069 pw.println(Integer.toHexString(mNextAppTransitionExit));
2070 break;
Winson Chung044d5292014-11-06 11:05:19 -08002071 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002072 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Winson Chung044d5292014-11-06 11:05:19 -08002073 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002074 pw.print(prefix); pw.print("mNextAppTransitionInPlace=0x");
Winson Chung044d5292014-11-06 11:05:19 -08002075 pw.print(Integer.toHexString(mNextAppTransitionInPlace));
2076 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002077 case NEXT_TRANSIT_TYPE_SCALE_UP: {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002078 getDefaultNextAppTransitionStartRect(mTmpRect);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002079 pw.print(prefix); pw.print("mNextAppTransitionStartX=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002080 pw.print(mTmpRect.left);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002081 pw.print(" mNextAppTransitionStartY=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002082 pw.println(mTmpRect.top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002083 pw.print(prefix); pw.print("mNextAppTransitionStartWidth=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002084 pw.print(mTmpRect.width());
Craig Mautner164d4bb2012-11-26 13:51:23 -08002085 pw.print(" mNextAppTransitionStartHeight=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002086 pw.println(mTmpRect.height());
Craig Mautner164d4bb2012-11-26 13:51:23 -08002087 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002088 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002089 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
2090 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
Winson Chunga4ccb862014-08-22 15:26:27 -07002091 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002092 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN: {
2093 pw.print(prefix); pw.print("mDefaultNextAppTransitionAnimationSpec=");
2094 pw.println(mDefaultNextAppTransitionAnimationSpec);
2095 pw.print(prefix); pw.print("mNextAppTransitionAnimationsSpecs=");
2096 pw.println(mNextAppTransitionAnimationsSpecs);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002097 pw.print(prefix); pw.print("mNextAppTransitionScaleUp=");
2098 pw.println(mNextAppTransitionScaleUp);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002099 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002100 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002101 }
2102 if (mNextAppTransitionCallback != null) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002103 pw.print(prefix); pw.print("mNextAppTransitionCallback=");
2104 pw.println(mNextAppTransitionCallback);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002105 }
Chong Zhang60091a92016-07-27 17:52:45 -07002106 if (mLastUsedAppTransition != TRANSIT_NONE) {
2107 pw.print(prefix); pw.print("mLastUsedAppTransition=");
2108 pw.println(appTransitionToString(mLastUsedAppTransition));
2109 pw.print(prefix); pw.print("mLastOpeningApp=");
2110 pw.println(mLastOpeningApp);
2111 pw.print(prefix); pw.print("mLastClosingApp=");
2112 pw.println(mLastClosingApp);
2113 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002114 }
Amith Yamasani4befbec2013-07-10 16:18:01 -07002115
2116 public void setCurrentUser(int newUserId) {
2117 mCurrentUserId = newUserId;
2118 }
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002119
2120 /**
2121 * @return true if transition is not running and should not be skipped, false if transition is
2122 * already running
2123 */
Jorim Jaggif84e2f62018-01-16 14:17:59 +01002124 boolean prepareAppTransitionLocked(@TransitionType int transit, boolean alwaysKeepCurrent,
2125 @TransitionFlags int flags, boolean forceOverride) {
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002126 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Prepare app transition:"
2127 + " transit=" + appTransitionToString(transit)
2128 + " " + this
2129 + " alwaysKeepCurrent=" + alwaysKeepCurrent
2130 + " Callers=" + Debug.getCallers(3));
Jorim Jaggife762342016-10-13 14:33:27 +02002131 if (forceOverride || isKeyguardTransit(transit) || !isTransitionSet()
2132 || mNextAppTransition == TRANSIT_NONE) {
2133 setAppTransition(transit, flags);
Jorim Jaggia69243a2017-06-15 15:10:38 -04002134 }
2135 // We never want to change from a Keyguard transit to a non-Keyguard transit, as our logic
2136 // relies on the fact that we always execute a Keyguard transition after preparing one.
2137 else if (!alwaysKeepCurrent && !isKeyguardTransit(transit)) {
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002138 if (transit == TRANSIT_TASK_OPEN && isTransitionEqual(TRANSIT_TASK_CLOSE)) {
2139 // Opening a new task always supersedes a close for the anim.
Jorim Jaggife762342016-10-13 14:33:27 +02002140 setAppTransition(transit, flags);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002141 } else if (transit == TRANSIT_ACTIVITY_OPEN
2142 && isTransitionEqual(TRANSIT_ACTIVITY_CLOSE)) {
2143 // Opening a new activity always supersedes a close for the anim.
Jorim Jaggife762342016-10-13 14:33:27 +02002144 setAppTransition(transit, flags);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002145 }
2146 }
2147 boolean prepared = prepare();
2148 if (isTransitionSet()) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08002149 mService.mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
2150 mService.mH.sendEmptyMessageDelayed(H.APP_TRANSITION_TIMEOUT, APP_TRANSITION_TIMEOUT_MS);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002151 }
2152 return prepared;
2153 }
Winsonb2024762016-04-05 17:32:30 -07002154
2155 /**
Jorim Jaggife762342016-10-13 14:33:27 +02002156 * @return true if {@param transit} is representing a transition in which Keyguard is going
2157 * away, false otherwise
2158 */
2159 public static boolean isKeyguardGoingAwayTransit(int transit) {
2160 return transit == TRANSIT_KEYGUARD_GOING_AWAY
2161 || transit == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER;
2162 }
2163
2164 private static boolean isKeyguardTransit(int transit) {
2165 return isKeyguardGoingAwayTransit(transit) || transit == TRANSIT_KEYGUARD_OCCLUDE
2166 || transit == TRANSIT_KEYGUARD_UNOCCLUDE;
2167 }
2168
2169 /**
Manu Cornetd7376802017-01-13 13:44:07 -08002170 * @return whether the transition should show the thumbnail being scaled down.
2171 */
2172 private boolean shouldScaleDownThumbnailTransition(int uiMode, int orientation) {
Sid Soundararajan0e88d322017-03-07 15:37:30 -08002173 return mGridLayoutRecentsEnabled
Manu Cornetd7376802017-01-13 13:44:07 -08002174 || orientation == Configuration.ORIENTATION_PORTRAIT;
2175 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002176}