blob: 0d36145c866132946ec1a05c8f2b6e920b9421b2 [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;
John Reck519ad482018-02-12 17:08:48 -080081import android.graphics.Bitmap;
82import android.graphics.Canvas;
Tony Mak64b8d562017-12-28 17:44:02 +000083import android.graphics.Color;
Winson Chungaa7fa012017-05-24 15:50:06 -070084import android.graphics.GraphicBuffer;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +010085import android.graphics.Path;
John Reck519ad482018-02-12 17:08:48 -080086import android.graphics.Picture;
Winson Chung399f6202014-03-19 10:47:20 -070087import android.graphics.Rect;
Tony Mak64b8d562017-12-28 17:44:02 +000088import android.graphics.drawable.Drawable;
Jorim Jaggied410b62017-05-05 15:16:14 +020089import android.os.Binder;
Craig Mautner164d4bb2012-11-26 13:51:23 -080090import android.os.Debug;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010091import android.os.IBinder;
Craig Mautner164d4bb2012-11-26 13:51:23 -080092import android.os.IRemoteCallback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010093import android.os.RemoteException;
Jorim Jaggif5f9e122017-10-24 18:21:09 +020094import android.os.SystemClock;
Manu Cornetd7376802017-01-13 13:44:07 -080095import android.os.SystemProperties;
Tony Mak089c35e2017-12-18 20:34:14 +000096import android.os.UserHandle;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -080097import android.util.ArraySet;
Craig Mautner164d4bb2012-11-26 13:51:23 -080098import android.util.Slog;
Filip Gruszczynski170192a2015-08-16 17:46:34 -070099import android.util.SparseArray;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700100import android.util.proto.ProtoOutputStream;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700101import android.view.AppTransitionAnimationSpec;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100102import android.view.IAppTransitionAnimationSpecsFuture;
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100103import android.view.RemoteAnimationAdapter;
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
John Reck519ad482018-02-12 17:08:48 -0800976 final Picture picture = new Picture();
977 final Canvas canvas = picture.beginRecording(width, height);
Tony Mak64b8d562017-12-28 17:44:02 +0000978 canvas.drawColor(Color.argb(0.6f, 0, 0, 0));
979 final int thumbnailSize = mService.mContext.getResources().getDimensionPixelSize(
980 com.android.internal.R.dimen.cross_profile_apps_thumbnail_size);
981 final Drawable drawable = mService.mContext.getDrawable(thumbnailDrawableRes);
982 drawable.setBounds(
983 (width - thumbnailSize) / 2,
984 (height - thumbnailSize) / 2,
985 (width + thumbnailSize) / 2,
986 (height + thumbnailSize) / 2);
987 drawable.draw(canvas);
John Reck519ad482018-02-12 17:08:48 -0800988 picture.endRecording();
Tony Mak64b8d562017-12-28 17:44:02 +0000989
John Reck519ad482018-02-12 17:08:48 -0800990 return Bitmap.createBitmap(picture).createGraphicBufferHandle();
Tony Mak64b8d562017-12-28 17:44:02 +0000991 }
992
993 Animation createCrossProfileAppsThumbnailAnimationLocked(Rect appRect) {
994 final Animation animation = loadAnimationRes(
995 "android", com.android.internal.R.anim.cross_profile_apps_thumbnail_enter);
996 return prepareThumbnailAnimationWithDuration(animation, appRect.width(),
997 appRect.height(), 0, null);
998 }
999
1000 /**
Winson Chung399f6202014-03-19 10:47:20 -07001001 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001002 * when a thumbnail is specified with the pending animation override.
Winson Chung399f6202014-03-19 10:47:20 -07001003 */
Jorim Jaggide63d442016-03-14 14:56:56 +01001004 Animation createThumbnailAspectScaleAnimationLocked(Rect appRect, @Nullable Rect contentInsets,
Winson Chungaa7fa012017-05-24 15:50:06 -07001005 GraphicBuffer thumbnailHeader, final int taskId, int uiMode, int orientation) {
Winson Chung399f6202014-03-19 10:47:20 -07001006 Animation a;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001007 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chung399f6202014-03-19 10:47:20 -07001008 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001009 final int thumbHeightI = thumbnailHeader.getHeight();
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -07001010 final int appWidth = appRect.width();
Winson Chung399f6202014-03-19 10:47:20 -07001011
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -07001012 float scaleW = appWidth / thumbWidth;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001013 getNextAppTransitionStartRect(taskId, mTmpRect);
Jorim Jaggi09072002016-03-25 16:48:42 -07001014 final float fromX;
Manu Cornet57b61492017-01-24 18:19:05 +09001015 float fromY;
Jorim Jaggi09072002016-03-25 16:48:42 -07001016 final float toX;
Manu Cornet57b61492017-01-24 18:19:05 +09001017 float toY;
Jorim Jaggi09072002016-03-25 16:48:42 -07001018 final float pivotX;
1019 final float pivotY;
Manu Cornetd7376802017-01-13 13:44:07 -08001020 if (shouldScaleDownThumbnailTransition(uiMode, orientation)) {
Jorim Jaggi09072002016-03-25 16:48:42 -07001021 fromX = mTmpRect.left;
1022 fromY = mTmpRect.top;
1023
1024 // For the curved translate animation to work, the pivot points needs to be at the
1025 // same absolute position as the one from the real surface.
1026 toX = mTmpRect.width() / 2 * (scaleW - 1f) + appRect.left;
1027 toY = appRect.height() / 2 * (1 - 1 / scaleW) + appRect.top;
1028 pivotX = mTmpRect.width() / 2;
1029 pivotY = appRect.height() / 2 / scaleW;
Manu Cornet57b61492017-01-24 18:19:05 +09001030 if (mGridLayoutRecentsEnabled) {
1031 // In the grid layout, the header is displayed above the thumbnail instead of
1032 // overlapping it.
1033 fromY -= thumbHeightI;
1034 toY -= thumbHeightI * scaleW;
1035 }
Jorim Jaggi09072002016-03-25 16:48:42 -07001036 } else {
1037 pivotX = 0;
1038 pivotY = 0;
1039 fromX = mTmpRect.left;
1040 fromY = mTmpRect.top;
1041 toX = appRect.left;
1042 toY = appRect.top;
1043 }
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001044 final long duration = getAspectScaleDuration();
1045 final Interpolator interpolator = getAspectScaleInterpolator();
Winson Chung399f6202014-03-19 10:47:20 -07001046 if (mNextAppTransitionScaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001047 // Animation up from the thumbnail to the full screen
Jorim Jaggi8448f332016-03-14 17:50:37 +01001048 Animation scale = new ScaleAnimation(1f, scaleW, 1f, scaleW, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001049 scale.setInterpolator(interpolator);
1050 scale.setDuration(duration);
Jorim Jaggic6c89a82016-01-28 17:48:21 -08001051 Animation alpha = new AlphaAnimation(1f, 0f);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001052 alpha.setInterpolator(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
1053 ? THUMBNAIL_DOCK_INTERPOLATOR : mThumbnailFadeOutInterpolator);
1054 alpha.setDuration(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
1055 ? duration / 2
1056 : duration);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001057 Animation translate = createCurvedMotion(fromX, toX, fromY, toY);
1058 translate.setInterpolator(interpolator);
1059 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -07001060
Jorim Jaggide63d442016-03-14 14:56:56 +01001061 mTmpFromClipRect.set(0, 0, thumbWidthI, thumbHeightI);
1062 mTmpToClipRect.set(appRect);
1063
1064 // Containing frame is in screen space, but we need the clip rect in the
1065 // app space.
1066 mTmpToClipRect.offsetTo(0, 0);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001067 mTmpToClipRect.right = (int) (mTmpToClipRect.right / scaleW);
1068 mTmpToClipRect.bottom = (int) (mTmpToClipRect.bottom / scaleW);
Jorim Jaggide63d442016-03-14 14:56:56 +01001069
1070 if (contentInsets != null) {
Jorim Jaggi8448f332016-03-14 17:50:37 +01001071 mTmpToClipRect.inset((int) (-contentInsets.left * scaleW),
1072 (int) (-contentInsets.top * scaleW),
1073 (int) (-contentInsets.right * scaleW),
1074 (int) (-contentInsets.bottom * scaleW));
Jorim Jaggide63d442016-03-14 14:56:56 +01001075 }
1076
1077 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001078 clipAnim.setInterpolator(interpolator);
1079 clipAnim.setDuration(duration);
Jorim Jaggide63d442016-03-14 14:56:56 +01001080
Winson Chung399f6202014-03-19 10:47:20 -07001081 // This AnimationSet uses the Interpolators assigned above.
1082 AnimationSet set = new AnimationSet(false);
1083 set.addAnimation(scale);
Manu Cornet57b61492017-01-24 18:19:05 +09001084 if (!mGridLayoutRecentsEnabled) {
1085 // In the grid layout, the header should be shown for the whole animation.
1086 set.addAnimation(alpha);
1087 }
Winson Chunga4ccb862014-08-22 15:26:27 -07001088 set.addAnimation(translate);
Jorim Jaggide63d442016-03-14 14:56:56 +01001089 set.addAnimation(clipAnim);
Winson Chung399f6202014-03-19 10:47:20 -07001090 a = set;
1091 } else {
Winson Chunga4ccb862014-08-22 15:26:27 -07001092 // Animation down from the full screen to the thumbnail
Jorim Jaggi8448f332016-03-14 17:50:37 +01001093 Animation scale = new ScaleAnimation(scaleW, 1f, scaleW, 1f, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001094 scale.setInterpolator(interpolator);
1095 scale.setDuration(duration);
Winson Chunga4ccb862014-08-22 15:26:27 -07001096 Animation alpha = new AlphaAnimation(0f, 1f);
1097 alpha.setInterpolator(mThumbnailFadeInInterpolator);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001098 alpha.setDuration(duration);
1099 Animation translate = createCurvedMotion(toX, fromX, toY, fromY);
1100 translate.setInterpolator(interpolator);
1101 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -07001102
Winson Chunga4ccb862014-08-22 15:26:27 -07001103 // This AnimationSet uses the Interpolators assigned above.
1104 AnimationSet set = new AnimationSet(false);
1105 set.addAnimation(scale);
Manu Cornet57b61492017-01-24 18:19:05 +09001106 if (!mGridLayoutRecentsEnabled) {
1107 // In the grid layout, the header should be shown for the whole animation.
1108 set.addAnimation(alpha);
1109 }
Winson Chunga4ccb862014-08-22 15:26:27 -07001110 set.addAnimation(translate);
1111 a = set;
1112
1113 }
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -07001114 return prepareThumbnailAnimationWithDuration(a, appWidth, appRect.height(), 0,
Jorim Jaggic69bd222016-03-15 14:38:37 +01001115 null);
Winson Chung399f6202014-03-19 10:47:20 -07001116 }
1117
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001118 private Animation createCurvedMotion(float fromX, float toX, float fromY, float toY) {
1119
1120 // Almost no x-change - use linear animation
Jorim Jaggic69bd222016-03-15 14:38:37 +01001121 if (Math.abs(toX - fromX) < 1f || mNextAppTransition != TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001122 return new TranslateAnimation(fromX, toX, fromY, toY);
1123 } else {
1124 final Path path = createCurvedPath(fromX, toX, fromY, toY);
1125 return new CurvedTranslateAnimation(path);
1126 }
1127 }
1128
1129 private Path createCurvedPath(float fromX, float toX, float fromY, float toY) {
1130 final Path path = new Path();
1131 path.moveTo(fromX, fromY);
Jorim Jaggi1f458fb2016-03-25 17:36:37 -07001132
1133 if (fromY > toY) {
1134 // If the object needs to go up, move it in horizontal direction first, then vertical.
1135 path.cubicTo(fromX, fromY, toX, 0.9f * fromY + 0.1f * toY, toX, toY);
1136 } else {
1137 // If the object needs to go down, move it in vertical direction first, then horizontal.
1138 path.cubicTo(fromX, fromY, fromX, 0.1f * fromY + 0.9f * toY, toX, toY);
1139 }
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001140 return path;
1141 }
1142
1143 private long getAspectScaleDuration() {
1144 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggic69bd222016-03-15 14:38:37 +01001145 return (long) (THUMBNAIL_APP_TRANSITION_DURATION * 1.35f);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001146 } else {
1147 return THUMBNAIL_APP_TRANSITION_DURATION;
1148 }
1149 }
1150
1151 private Interpolator getAspectScaleInterpolator() {
1152 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
1153 return mFastOutSlowInInterpolator;
1154 } else {
1155 return TOUCH_RESPONSE_INTERPOLATOR;
1156 }
1157 }
1158
Winson Chung399f6202014-03-19 10:47:20 -07001159 /**
1160 * This alternate animation is created when we are doing a thumbnail transition, for the
1161 * activity that is leaving, and the activity that is entering.
1162 */
Winson Chunga4ccb862014-08-22 15:26:27 -07001163 Animation createAspectScaledThumbnailEnterExitAnimationLocked(int thumbTransitState,
Winsonb2024762016-04-05 17:32:30 -07001164 int uiMode, int orientation, int transit, Rect containingFrame, Rect contentInsets,
Matthew Ng43db6d22017-06-27 15:29:39 -07001165 @Nullable Rect surfaceInsets, @Nullable Rect stableInsets, boolean freeform,
1166 int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -07001167 Animation a;
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001168 final int appWidth = containingFrame.width();
1169 final int appHeight = containingFrame.height();
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001170 getDefaultNextAppTransitionStartRect(mTmpRect);
1171 final int thumbWidthI = mTmpRect.width();
Winson Chung399f6202014-03-19 10:47:20 -07001172 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001173 final int thumbHeightI = mTmpRect.height();
Winson Chung399f6202014-03-19 10:47:20 -07001174 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
Winsoncbb625b2016-07-06 15:24:15 -07001175 final int thumbStartX = mTmpRect.left - containingFrame.left - contentInsets.left;
Winson21700932016-03-24 17:26:23 -07001176 final int thumbStartY = mTmpRect.top - containingFrame.top;
Winson Chung399f6202014-03-19 10:47:20 -07001177
1178 switch (thumbTransitState) {
Jorim Jaggi8448f332016-03-14 17:50:37 +01001179 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP:
1180 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1181 final boolean scaleUp = thumbTransitState == THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
1182 if (freeform && scaleUp) {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001183 a = createAspectScaledThumbnailEnterFreeformAnimationLocked(
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001184 containingFrame, surfaceInsets, taskId);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001185 } else if (freeform) {
1186 a = createAspectScaledThumbnailExitFreeformAnimationLocked(
1187 containingFrame, surfaceInsets, taskId);
Winson Chung2820c452014-04-15 15:34:44 -07001188 } else {
Winson21700932016-03-24 17:26:23 -07001189 AnimationSet set = new AnimationSet(true);
1190
1191 // In portrait, we scale to fit the width
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001192 mTmpFromClipRect.set(containingFrame);
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001193 mTmpToClipRect.set(containingFrame);
Jorim Jaggic6c89a82016-01-28 17:48:21 -08001194
1195 // Containing frame is in screen space, but we need the clip rect in the
1196 // app space.
1197 mTmpFromClipRect.offsetTo(0, 0);
1198 mTmpToClipRect.offsetTo(0, 0);
1199
1200 // Exclude insets region from the source clip.
1201 mTmpFromClipRect.inset(contentInsets);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001202 mNextAppTransitionInsets.set(contentInsets);
1203
Manu Cornetd7376802017-01-13 13:44:07 -08001204 if (shouldScaleDownThumbnailTransition(uiMode, orientation)) {
Jorim Jaggic69bd222016-03-15 14:38:37 +01001205 // We scale the width and clip to the top/left square
1206 float scale = thumbWidth /
1207 (appWidth - contentInsets.left - contentInsets.right);
Manu Cornetb68b7652017-01-23 19:37:53 +09001208 if (!mGridLayoutRecentsEnabled) {
1209 int unscaledThumbHeight = (int) (thumbHeight / scale);
1210 mTmpFromClipRect.bottom = mTmpFromClipRect.top + unscaledThumbHeight;
1211 }
Jorim Jaggic69bd222016-03-15 14:38:37 +01001212
1213 mNextAppTransitionInsets.set(contentInsets);
1214
Jorim Jaggi8448f332016-03-14 17:50:37 +01001215 Animation scaleAnim = new ScaleAnimation(
1216 scaleUp ? scale : 1, scaleUp ? 1 : scale,
1217 scaleUp ? scale : 1, scaleUp ? 1 : scale,
Jorim Jaggic69bd222016-03-15 14:38:37 +01001218 containingFrame.width() / 2f,
1219 containingFrame.height() / 2f + contentInsets.top);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001220 final float targetX = (mTmpRect.left - containingFrame.left);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001221 final float x = containingFrame.width() / 2f
1222 - containingFrame.width() / 2f * scale;
Jorim Jaggi8448f332016-03-14 17:50:37 +01001223 final float targetY = (mTmpRect.top - containingFrame.top);
Matthew Ng43db6d22017-06-27 15:29:39 -07001224 float y = containingFrame.height() / 2f
Jorim Jaggic69bd222016-03-15 14:38:37 +01001225 - containingFrame.height() / 2f * scale;
Matthew Ng43db6d22017-06-27 15:29:39 -07001226
1227 // During transition may require clipping offset from any top stable insets
1228 // such as the statusbar height when statusbar is hidden
1229 if (mLowRamRecentsEnabled && contentInsets.top == 0 && scaleUp) {
1230 mTmpFromClipRect.top += stableInsets.top;
1231 y += stableInsets.top;
1232 }
Jorim Jaggi8448f332016-03-14 17:50:37 +01001233 final float startX = targetX - x;
1234 final float startY = targetY - y;
1235 Animation clipAnim = scaleUp
1236 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1237 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1238 Animation translateAnim = scaleUp
Jorim Jaggic69bd222016-03-15 14:38:37 +01001239 ? createCurvedMotion(startX, 0, startY - contentInsets.top, 0)
1240 : createCurvedMotion(0, startX, 0, startY - contentInsets.top);
1241
Winson21700932016-03-24 17:26:23 -07001242 set.addAnimation(clipAnim);
1243 set.addAnimation(scaleAnim);
1244 set.addAnimation(translateAnim);
1245
1246 } else {
1247 // In landscape, we don't scale at all and only crop
1248 mTmpFromClipRect.bottom = mTmpFromClipRect.top + thumbHeightI;
1249 mTmpFromClipRect.right = mTmpFromClipRect.left + thumbWidthI;
1250
Jorim Jaggi8448f332016-03-14 17:50:37 +01001251 Animation clipAnim = scaleUp
1252 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1253 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1254 Animation translateAnim = scaleUp
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001255 ? createCurvedMotion(thumbStartX, 0,
1256 thumbStartY - contentInsets.top, 0)
1257 : createCurvedMotion(0, thumbStartX, 0,
1258 thumbStartY - contentInsets.top);
Winson21700932016-03-24 17:26:23 -07001259
1260 set.addAnimation(clipAnim);
1261 set.addAnimation(translateAnim);
1262 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001263 a = set;
Winson21700932016-03-24 17:26:23 -07001264 a.setZAdjustment(Animation.ZORDER_TOP);
Winson Chung2820c452014-04-15 15:34:44 -07001265 }
Winson Chung399f6202014-03-19 10:47:20 -07001266 break;
1267 }
1268 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001269 // Previous app window during the scale up
Winson Chung399f6202014-03-19 10:47:20 -07001270 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001271 // Fade out the source activity if we are animating to a wallpaper
Winson Chung399f6202014-03-19 10:47:20 -07001272 // activity.
1273 a = new AlphaAnimation(1, 0);
1274 } else {
Winson Chung399f6202014-03-19 10:47:20 -07001275 a = new AlphaAnimation(1, 1);
1276 }
1277 break;
1278 }
1279 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001280 // Target app window during the scale down
1281 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1282 // Fade in the destination activity if we are animating from a wallpaper
1283 // activity.
1284 a = new AlphaAnimation(0, 1);
1285 } else {
1286 a = new AlphaAnimation(1, 1);
1287 }
Winson Chung399f6202014-03-19 10:47:20 -07001288 break;
1289 }
Winson Chung399f6202014-03-19 10:47:20 -07001290 default:
1291 throw new RuntimeException("Invalid thumbnail transition state");
1292 }
1293
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001294 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight,
1295 getAspectScaleDuration(), getAspectScaleInterpolator());
Winson Chung399f6202014-03-19 10:47:20 -07001296 }
1297
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001298 private Animation createAspectScaledThumbnailEnterFreeformAnimationLocked(Rect frame,
1299 @Nullable Rect surfaceInsets, int taskId) {
1300 getNextAppTransitionStartRect(taskId, mTmpRect);
1301 return createAspectScaledThumbnailFreeformAnimationLocked(mTmpRect, frame, surfaceInsets,
1302 true);
1303 }
1304
1305 private Animation createAspectScaledThumbnailExitFreeformAnimationLocked(Rect frame,
1306 @Nullable Rect surfaceInsets, int taskId) {
1307 getNextAppTransitionStartRect(taskId, mTmpRect);
1308 return createAspectScaledThumbnailFreeformAnimationLocked(frame, mTmpRect, surfaceInsets,
1309 false);
1310 }
1311
1312 private AnimationSet createAspectScaledThumbnailFreeformAnimationLocked(Rect sourceFrame,
1313 Rect destFrame, @Nullable Rect surfaceInsets, boolean enter) {
1314 final float sourceWidth = sourceFrame.width();
1315 final float sourceHeight = sourceFrame.height();
1316 final float destWidth = destFrame.width();
1317 final float destHeight = destFrame.height();
1318 final float scaleH = enter ? sourceWidth / destWidth : destWidth / sourceWidth;
1319 final float scaleV = enter ? sourceHeight / destHeight : destHeight / sourceHeight;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001320 AnimationSet set = new AnimationSet(true);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001321 final int surfaceInsetsH = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001322 ? 0 : surfaceInsets.left + surfaceInsets.right;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001323 final int surfaceInsetsV = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001324 ? 0 : surfaceInsets.top + surfaceInsets.bottom;
1325 // We want the scaling to happen from the center of the surface. In order to achieve that,
1326 // we need to account for surface insets that will be used to enlarge the surface.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001327 final float scaleHCenter = ((enter ? destWidth : sourceWidth) + surfaceInsetsH) / 2;
1328 final float scaleVCenter = ((enter ? destHeight : sourceHeight) + surfaceInsetsV) / 2;
1329 final ScaleAnimation scale = enter ?
1330 new ScaleAnimation(scaleH, 1, scaleV, 1, scaleHCenter, scaleVCenter)
1331 : new ScaleAnimation(1, scaleH, 1, scaleV, scaleHCenter, scaleVCenter);
1332 final int sourceHCenter = sourceFrame.left + sourceFrame.width() / 2;
1333 final int sourceVCenter = sourceFrame.top + sourceFrame.height() / 2;
1334 final int destHCenter = destFrame.left + destFrame.width() / 2;
1335 final int destVCenter = destFrame.top + destFrame.height() / 2;
1336 final int fromX = enter ? sourceHCenter - destHCenter : destHCenter - sourceHCenter;
1337 final int fromY = enter ? sourceVCenter - destVCenter : destVCenter - sourceVCenter;
1338 final TranslateAnimation translation = enter ? new TranslateAnimation(fromX, 0, fromY, 0)
1339 : new TranslateAnimation(0, fromX, 0, fromY);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001340 set.addAnimation(scale);
1341 set.addAnimation(translation);
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001342
1343 final IRemoteCallback callback = mAnimationFinishedCallback;
1344 if (callback != null) {
1345 set.setAnimationListener(new Animation.AnimationListener() {
1346 @Override
1347 public void onAnimationStart(Animation animation) { }
1348
1349 @Override
1350 public void onAnimationEnd(Animation animation) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001351 mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK, callback).sendToTarget();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001352 }
1353
1354 @Override
1355 public void onAnimationRepeat(Animation animation) { }
1356 });
1357 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001358 return set;
1359 }
1360
Winson Chung399f6202014-03-19 10:47:20 -07001361 /**
Winson Chunga4ccb862014-08-22 15:26:27 -07001362 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001363 * when a thumbnail is specified with the pending animation override.
Winson Chunga4ccb862014-08-22 15:26:27 -07001364 */
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001365 Animation createThumbnailScaleAnimationLocked(int appWidth, int appHeight, int transit,
Winson Chungaa7fa012017-05-24 15:50:06 -07001366 GraphicBuffer thumbnailHeader) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001367 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001368 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001369 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chunga4ccb862014-08-22 15:26:27 -07001370 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001371 final int thumbHeightI = thumbnailHeader.getHeight();
Winson Chunga4ccb862014-08-22 15:26:27 -07001372 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1373
1374 if (mNextAppTransitionScaleUp) {
1375 // Animation for the thumbnail zooming from its initial size to the full screen
1376 float scaleW = appWidth / thumbWidth;
1377 float scaleH = appHeight / thumbHeight;
1378 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001379 computePivot(mTmpRect.left, 1 / scaleW),
1380 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001381 scale.setInterpolator(mDecelerateInterpolator);
1382
1383 Animation alpha = new AlphaAnimation(1, 0);
1384 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
1385
1386 // This AnimationSet uses the Interpolators assigned above.
1387 AnimationSet set = new AnimationSet(false);
1388 set.addAnimation(scale);
1389 set.addAnimation(alpha);
1390 a = set;
1391 } else {
1392 // Animation for the thumbnail zooming down from the full screen to its final size
1393 float scaleW = appWidth / thumbWidth;
1394 float scaleH = appHeight / thumbHeight;
1395 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001396 computePivot(mTmpRect.left, 1 / scaleW),
1397 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001398 }
1399
1400 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1401 }
1402
1403 /**
Winson Chung399f6202014-03-19 10:47:20 -07001404 * This animation is created when we are doing a thumbnail transition, for the activity that is
1405 * leaving, and the activity that is entering.
1406 */
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001407 Animation createThumbnailEnterExitAnimationLocked(int thumbTransitState, Rect containingFrame,
1408 int transit, int taskId) {
1409 final int appWidth = containingFrame.width();
1410 final int appHeight = containingFrame.height();
Winson Chungaa7fa012017-05-24 15:50:06 -07001411 final GraphicBuffer thumbnailHeader = getAppTransitionThumbnailHeader(taskId);
Winson Chung399f6202014-03-19 10:47:20 -07001412 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001413 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001414 final int thumbWidthI = thumbnailHeader != null ? thumbnailHeader.getWidth() : appWidth;
Winson Chung399f6202014-03-19 10:47:20 -07001415 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001416 final int thumbHeightI = thumbnailHeader != null ? thumbnailHeader.getHeight() : appHeight;
Winson Chung399f6202014-03-19 10:47:20 -07001417 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1418
1419 switch (thumbTransitState) {
1420 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
1421 // Entering app scales up with the thumbnail
1422 float scaleW = thumbWidth / appWidth;
1423 float scaleH = thumbHeight / appHeight;
1424 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001425 computePivot(mTmpRect.left, scaleW),
1426 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001427 break;
1428 }
1429 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
1430 // Exiting app while the thumbnail is scaling up should fade or stay in place
1431 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1432 // Fade out while bringing up selected activity. This keeps the
1433 // current activity from showing through a launching wallpaper
1434 // activity.
1435 a = new AlphaAnimation(1, 0);
1436 } else {
1437 // noop animation
1438 a = new AlphaAnimation(1, 1);
1439 }
1440 break;
1441 }
1442 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
1443 // Entering the other app, it should just be visible while we scale the thumbnail
1444 // down above it
1445 a = new AlphaAnimation(1, 1);
1446 break;
1447 }
1448 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1449 // Exiting the current app, the app should scale down with the thumbnail
1450 float scaleW = thumbWidth / appWidth;
1451 float scaleH = thumbHeight / appHeight;
1452 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001453 computePivot(mTmpRect.left, scaleW),
1454 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001455
1456 Animation alpha = new AlphaAnimation(1, 0);
1457
1458 AnimationSet set = new AnimationSet(true);
1459 set.addAnimation(scale);
1460 set.addAnimation(alpha);
1461 set.setZAdjustment(Animation.ZORDER_TOP);
1462 a = set;
1463 break;
1464 }
1465 default:
1466 throw new RuntimeException("Invalid thumbnail transition state");
1467 }
1468
1469 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1470 }
1471
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001472 private Animation createRelaunchAnimation(Rect containingFrame, Rect contentInsets) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001473 getDefaultNextAppTransitionStartRect(mTmpFromClipRect);
1474 final int left = mTmpFromClipRect.left;
1475 final int top = mTmpFromClipRect.top;
1476 mTmpFromClipRect.offset(-left, -top);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001477 // TODO: Isn't that strange that we ignore exact position of the containingFrame?
1478 mTmpToClipRect.set(0, 0, containingFrame.width(), containingFrame.height());
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001479 AnimationSet set = new AnimationSet(true);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001480 float fromWidth = mTmpFromClipRect.width();
1481 float toWidth = mTmpToClipRect.width();
1482 float fromHeight = mTmpFromClipRect.height();
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001483 // While the window might span the whole display, the actual content will be cropped to the
1484 // system decoration frame, for example when the window is docked. We need to take into
1485 // account the visible height when constructing the animation.
1486 float toHeight = mTmpToClipRect.height() - contentInsets.top - contentInsets.bottom;
1487 int translateAdjustment = 0;
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001488 if (fromWidth <= toWidth && fromHeight <= toHeight) {
1489 // The final window is larger in both dimensions than current window (e.g. we are
1490 // maximizing), so we can simply unclip the new window and there will be no disappearing
1491 // frame.
1492 set.addAnimation(new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect));
1493 } else {
1494 // The disappearing window has one larger dimension. We need to apply scaling, so the
1495 // first frame of the entry animation matches the old window.
1496 set.addAnimation(new ScaleAnimation(fromWidth / toWidth, 1, fromHeight / toHeight, 1));
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001497 // We might not be going exactly full screen, but instead be aligned under the status
1498 // bar using cropping. We still need to account for the cropped part, which will also
1499 // be scaled.
1500 translateAdjustment = (int) (contentInsets.top * fromHeight / toHeight);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001501 }
1502
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001503 // We animate the translation from the old position of the removed window, to the new
1504 // position of the added window. The latter might not be full screen, for example docked for
1505 // docked windows.
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001506 TranslateAnimation translate = new TranslateAnimation(left - containingFrame.left,
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001507 0, top - containingFrame.top - translateAdjustment, 0);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001508 set.addAnimation(translate);
1509 set.setDuration(DEFAULT_APP_TRANSITION_DURATION);
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07001510 set.setZAdjustment(Animation.ZORDER_TOP);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001511 return set;
1512 }
1513
Jorim Jaggic554b772015-06-04 16:07:57 -07001514 /**
1515 * @return true if and only if the first frame of the transition can be skipped, i.e. the first
1516 * frame of the transition doesn't change the visuals on screen, so we can start
1517 * directly with the second one
1518 */
1519 boolean canSkipFirstFrame() {
1520 return mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM
1521 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE
Jorim Jaggife762342016-10-13 14:33:27 +02001522 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CLIP_REVEAL
1523 && mNextAppTransition != TRANSIT_KEYGUARD_GOING_AWAY;
Jorim Jaggic554b772015-06-04 16:07:57 -07001524 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001525
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001526 RemoteAnimationController getRemoteAnimationController() {
1527 return mRemoteAnimationController;
1528 }
1529
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001530 /**
1531 *
1532 * @param frame These are the bounds of the window when it finishes the animation. This is where
1533 * the animation must usually finish in entrance animation, as the next frame will
1534 * display the window at these coordinates. In case of exit animation, this is
1535 * where the animation must start, as the frame before the animation is displaying
1536 * the window at these bounds.
1537 * @param insets Knowing where the window will be positioned is not enough. Some parts of the
1538 * window might be obscured, usually by the system windows (status bar and
1539 * navigation bar) and we use content insets to convey that information. This
1540 * usually affects the animation aspects vertically, as the system decoration is
1541 * at the top and the bottom. For example when we animate from full screen to
1542 * recents, we want to exclude the covered parts, because they won't match the
1543 * thumbnail after the last frame is executed.
1544 * @param surfaceInsets In rare situation the surface is larger than the content and we need to
1545 * know about this to make the animation frames match. We currently use
1546 * this for freeform windows, which have larger surfaces to display
1547 * shadows. When we animate them from recents, we want to match the content
1548 * to the recents thumbnail and hence need to account for the surface being
1549 * bigger.
1550 */
Jorim Jaggif84e2f62018-01-16 14:17:59 +01001551 Animation loadAnimation(LayoutParams lp, int transit, boolean enter, int uiMode,
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001552 int orientation, Rect frame, Rect displayFrame, Rect insets,
Matthew Ng43db6d22017-06-27 15:29:39 -07001553 @Nullable Rect surfaceInsets, @Nullable Rect stableInsets, boolean isVoiceInteraction,
1554 boolean freeform, int taskId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001555 Animation a;
Jorim Jaggife762342016-10-13 14:33:27 +02001556 if (isKeyguardGoingAwayTransit(transit) && enter) {
1557 a = loadKeyguardExitAnimation(transit);
1558 } else if (transit == TRANSIT_KEYGUARD_OCCLUDE) {
1559 a = null;
1560 } else if (transit == TRANSIT_KEYGUARD_UNOCCLUDE && !enter) {
1561 a = loadAnimationRes(lp, com.android.internal.R.anim.wallpaper_open_exit);
1562 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_OPEN
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001563 || transit == TRANSIT_TASK_OPEN
1564 || transit == TRANSIT_TASK_TO_FRONT)) {
1565 a = loadAnimationRes(lp, enter
1566 ? com.android.internal.R.anim.voice_activity_open_enter
1567 : com.android.internal.R.anim.voice_activity_open_exit);
1568 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1569 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001570 + " anim=" + a + " transit=" + appTransitionToString(transit)
1571 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001572 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_CLOSE
1573 || transit == TRANSIT_TASK_CLOSE
1574 || transit == TRANSIT_TASK_TO_BACK)) {
1575 a = loadAnimationRes(lp, enter
1576 ? com.android.internal.R.anim.voice_activity_close_enter
1577 : com.android.internal.R.anim.voice_activity_close_exit);
1578 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1579 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001580 + " anim=" + a + " transit=" + appTransitionToString(transit)
1581 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001582 } else if (transit == TRANSIT_ACTIVITY_RELAUNCH) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001583 a = createRelaunchAnimation(frame, insets);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001584 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1585 "applyAnimation:"
1586 + " anim=" + a + " nextAppTransition=" + mNextAppTransition
1587 + " transit=" + appTransitionToString(transit)
1588 + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001589 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM) {
1590 a = loadAnimationRes(mNextAppTransitionPackage, enter ?
Craig Mautner164d4bb2012-11-26 13:51:23 -08001591 mNextAppTransitionEnter : mNextAppTransitionExit);
1592 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1593 "applyAnimation:"
1594 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001595 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001596 + " Callers=" + Debug.getCallers(3));
Winson Chung044d5292014-11-06 11:05:19 -08001597 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE) {
1598 a = loadAnimationRes(mNextAppTransitionPackage, mNextAppTransitionInPlace);
1599 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1600 "applyAnimation:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001601 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM_IN_PLACE"
1602 + " transit=" + appTransitionToString(transit)
1603 + " Callers=" + Debug.getCallers(3));
Chet Haase10e23ab2015-02-11 15:08:38 -08001604 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001605 a = createClipRevealAnimationLocked(transit, enter, frame, displayFrame);
Chet Haase10e23ab2015-02-11 15:08:38 -08001606 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1607 "applyAnimation:"
1608 + " anim=" + a + " nextAppTransition=ANIM_CLIP_REVEAL"
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001609 + " transit=" + appTransitionToString(transit)
Chet Haase10e23ab2015-02-11 15:08:38 -08001610 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001611 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_SCALE_UP) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001612 a = createScaleUpAnimationLocked(transit, enter, frame);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001613 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1614 "applyAnimation:"
1615 + " anim=" + a + " nextAppTransition=ANIM_SCALE_UP"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001616 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001617 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001618 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
1619 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001620 mNextAppTransitionScaleUp =
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001621 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP);
Winson Chunga4ccb862014-08-22 15:26:27 -07001622 a = createThumbnailEnterExitAnimationLocked(getThumbnailTransitionState(enter),
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001623 frame, transit, taskId);
Winson Chunga4ccb862014-08-22 15:26:27 -07001624 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1625 String animName = mNextAppTransitionScaleUp ?
1626 "ANIM_THUMBNAIL_SCALE_UP" : "ANIM_THUMBNAIL_SCALE_DOWN";
1627 Slog.v(TAG, "applyAnimation:"
1628 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001629 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Winson Chunga4ccb862014-08-22 15:26:27 -07001630 + " Callers=" + Debug.getCallers(3));
1631 }
1632 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
1633 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN) {
1634 mNextAppTransitionScaleUp =
1635 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP);
1636 a = createAspectScaledThumbnailEnterExitAnimationLocked(
Winsonb2024762016-04-05 17:32:30 -07001637 getThumbnailTransitionState(enter), uiMode, orientation, transit, frame,
Matthew Ng43db6d22017-06-27 15:29:39 -07001638 insets, surfaceInsets, stableInsets, freeform, taskId);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001639 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1640 String animName = mNextAppTransitionScaleUp ?
Winson Chunga4ccb862014-08-22 15:26:27 -07001641 "ANIM_THUMBNAIL_ASPECT_SCALE_UP" : "ANIM_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner164d4bb2012-11-26 13:51:23 -08001642 Slog.v(TAG, "applyAnimation:"
1643 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001644 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001645 + " Callers=" + Debug.getCallers(3));
1646 }
Tony Mak83546a82018-01-22 13:56:20 +00001647 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS && enter) {
Tony Mak64b8d562017-12-28 17:44:02 +00001648
Tony Mak089c35e2017-12-18 20:34:14 +00001649 a = loadAnimationRes("android", enter
Tony Mak64b8d562017-12-28 17:44:02 +00001650 ? com.android.internal.R.anim.task_open_enter_cross_profile_apps
1651 : com.android.internal.R.anim.task_open_exit);
Tony Mak089c35e2017-12-18 20:34:14 +00001652 Slog.v(TAG,
1653 "applyAnimation NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS:"
1654 + " anim=" + a + " transit=" + appTransitionToString(transit)
1655 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Craig Mautner164d4bb2012-11-26 13:51:23 -08001656 } else {
1657 int animAttr = 0;
1658 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001659 case TRANSIT_ACTIVITY_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001660 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001661 ? WindowAnimation_activityOpenEnterAnimation
1662 : WindowAnimation_activityOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001663 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001664 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001665 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001666 ? WindowAnimation_activityCloseEnterAnimation
1667 : WindowAnimation_activityCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001668 break;
Jorim Jaggi192086e2016-03-11 17:17:03 +01001669 case TRANSIT_DOCK_TASK_FROM_RECENTS:
Craig Mautner4b71aa12012-12-27 17:20:01 -08001670 case TRANSIT_TASK_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001671 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001672 ? WindowAnimation_taskOpenEnterAnimation
1673 : WindowAnimation_taskOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001674 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001675 case TRANSIT_TASK_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001676 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001677 ? WindowAnimation_taskCloseEnterAnimation
1678 : WindowAnimation_taskCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001679 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001680 case TRANSIT_TASK_TO_FRONT:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001681 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001682 ? WindowAnimation_taskToFrontEnterAnimation
1683 : WindowAnimation_taskToFrontExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001684 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001685 case TRANSIT_TASK_TO_BACK:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001686 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001687 ? WindowAnimation_taskToBackEnterAnimation
1688 : WindowAnimation_taskToBackExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001689 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001690 case TRANSIT_WALLPAPER_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001691 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001692 ? WindowAnimation_wallpaperOpenEnterAnimation
1693 : WindowAnimation_wallpaperOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001694 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001695 case TRANSIT_WALLPAPER_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001696 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001697 ? WindowAnimation_wallpaperCloseEnterAnimation
1698 : WindowAnimation_wallpaperCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001699 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001700 case TRANSIT_WALLPAPER_INTRA_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001701 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001702 ? WindowAnimation_wallpaperIntraOpenEnterAnimation
1703 : WindowAnimation_wallpaperIntraOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001704 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001705 case TRANSIT_WALLPAPER_INTRA_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001706 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001707 ? WindowAnimation_wallpaperIntraCloseEnterAnimation
1708 : WindowAnimation_wallpaperIntraCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001709 break;
Craig Mautnerbb742462014-07-07 15:28:55 -07001710 case TRANSIT_TASK_OPEN_BEHIND:
1711 animAttr = enter
1712 ? WindowAnimation_launchTaskBehindSourceAnimation
Craig Mautner3b2cd1d2014-08-25 14:25:54 -07001713 : WindowAnimation_launchTaskBehindTargetAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001714 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001715 a = animAttr != 0 ? loadAnimationAttr(lp, animAttr) : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001716 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1717 "applyAnimation:"
1718 + " anim=" + a
1719 + " animAttr=0x" + Integer.toHexString(animAttr)
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001720 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001721 + " Callers=" + Debug.getCallers(3));
1722 }
1723 return a;
1724 }
1725
Jorim Jaggife762342016-10-13 14:33:27 +02001726 private Animation loadKeyguardExitAnimation(int transit) {
1727 if ((mNextAppTransitionFlags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_NO_ANIMATION) != 0) {
1728 return null;
1729 }
1730 final boolean toShade =
1731 (mNextAppTransitionFlags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_TO_SHADE) != 0;
1732 return mService.mPolicy.createHiddenByKeyguardExit(
1733 transit == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER, toShade);
1734 }
1735
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001736 int getAppStackClipMode() {
Matthew Ngbf1d9852017-03-14 12:23:09 -07001737 // When dismiss keyguard animation occurs, clip before the animation to prevent docked
1738 // app from showing beyond the divider
1739 if (mNextAppTransition == TRANSIT_KEYGUARD_GOING_AWAY
1740 || mNextAppTransition == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER) {
1741 return STACK_CLIP_BEFORE_ANIM;
1742 }
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001743 return mNextAppTransition == TRANSIT_ACTIVITY_RELAUNCH
Jorim Jaggic69bd222016-03-15 14:38:37 +01001744 || mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
Jorim Jaggi1f458fb2016-03-25 17:36:37 -07001745 || mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001746 ? STACK_CLIP_NONE
1747 : STACK_CLIP_AFTER_ANIM;
1748 }
1749
Jorim Jaggife762342016-10-13 14:33:27 +02001750 public int getTransitFlags() {
1751 return mNextAppTransitionFlags;
1752 }
1753
Craig Mautner164d4bb2012-11-26 13:51:23 -08001754 void postAnimationCallback() {
1755 if (mNextAppTransitionCallback != null) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001756 mService.mH.sendMessage(mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK,
1757 mNextAppTransitionCallback));
Craig Mautner164d4bb2012-11-26 13:51:23 -08001758 mNextAppTransitionCallback = null;
1759 }
1760 }
1761
1762 void overridePendingAppTransition(String packageName, int enterAnim, int exitAnim,
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001763 IRemoteCallback startedCallback) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001764 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001765 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001766 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001767 mNextAppTransitionPackage = packageName;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001768 mNextAppTransitionEnter = enterAnim;
1769 mNextAppTransitionExit = exitAnim;
1770 postAnimationCallback();
1771 mNextAppTransitionCallback = startedCallback;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001772 }
1773 }
1774
1775 void overridePendingAppTransitionScaleUp(int startX, int startY, int startWidth,
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001776 int startHeight) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001777 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001778 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001779 mNextAppTransitionType = NEXT_TRANSIT_TYPE_SCALE_UP;
Winson4c3fecd2016-07-13 12:29:48 -07001780 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001781 postAnimationCallback();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001782 }
1783 }
1784
Chet Haase10e23ab2015-02-11 15:08:38 -08001785 void overridePendingAppTransitionClipReveal(int startX, int startY,
1786 int startWidth, int startHeight) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001787 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001788 clear();
Chet Haase10e23ab2015-02-11 15:08:38 -08001789 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CLIP_REVEAL;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001790 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Chet Haase10e23ab2015-02-11 15:08:38 -08001791 postAnimationCallback();
Chet Haase10e23ab2015-02-11 15:08:38 -08001792 }
1793 }
1794
Winson Chungaa7fa012017-05-24 15:50:06 -07001795 void overridePendingAppTransitionThumb(GraphicBuffer srcThumb, int startX, int startY,
Craig Mautner164d4bb2012-11-26 13:51:23 -08001796 IRemoteCallback startedCallback, boolean scaleUp) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001797 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001798 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001799 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP
1800 : NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001801 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001802 putDefaultNextAppTransitionCoordinates(startX, startY, 0, 0, srcThumb);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001803 postAnimationCallback();
1804 mNextAppTransitionCallback = startedCallback;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001805 }
1806 }
1807
Winson Chungaa7fa012017-05-24 15:50:06 -07001808 void overridePendingAppTransitionAspectScaledThumb(GraphicBuffer srcThumb, int startX, int startY,
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001809 int targetWidth, int targetHeight, IRemoteCallback startedCallback, boolean scaleUp) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001810 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001811 clear();
Winson Chunga4ccb862014-08-22 15:26:27 -07001812 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1813 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Winson Chunga4ccb862014-08-22 15:26:27 -07001814 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001815 putDefaultNextAppTransitionCoordinates(startX, startY, targetWidth, targetHeight,
1816 srcThumb);
Winson Chunga4ccb862014-08-22 15:26:27 -07001817 postAnimationCallback();
1818 mNextAppTransitionCallback = startedCallback;
Winson Chunga4ccb862014-08-22 15:26:27 -07001819 }
1820 }
1821
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001822 void overridePendingAppTransitionMultiThumb(AppTransitionAnimationSpec[] specs,
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001823 IRemoteCallback onAnimationStartedCallback, IRemoteCallback onAnimationFinishedCallback,
1824 boolean scaleUp) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001825 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001826 clear();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001827 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1828 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001829 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi43102412015-11-11 16:28:37 +01001830 if (specs != null) {
1831 for (int i = 0; i < specs.length; i++) {
1832 AppTransitionAnimationSpec spec = specs[i];
1833 if (spec != null) {
1834 mNextAppTransitionAnimationsSpecs.put(spec.taskId, spec);
1835 if (i == 0) {
1836 // In full screen mode, the transition code depends on the default spec
1837 // to be set.
1838 Rect rect = spec.rect;
1839 putDefaultNextAppTransitionCoordinates(rect.left, rect.top,
Winson Chungaa7fa012017-05-24 15:50:06 -07001840 rect.width(), rect.height(), spec.buffer);
Jorim Jaggi43102412015-11-11 16:28:37 +01001841 }
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001842 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001843 }
1844 }
1845 postAnimationCallback();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001846 mNextAppTransitionCallback = onAnimationStartedCallback;
1847 mAnimationFinishedCallback = onAnimationFinishedCallback;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001848 }
1849 }
1850
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001851 void overridePendingAppTransitionMultiThumbFuture(
1852 IAppTransitionAnimationSpecsFuture specsFuture, IRemoteCallback callback,
1853 boolean scaleUp) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001854 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001855 clear();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001856 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1857 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001858 mNextAppTransitionAnimationsSpecsFuture = specsFuture;
1859 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001860 mNextAppTransitionFutureCallback = callback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001861 }
1862 }
1863
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001864 void overridePendingAppTransitionRemote(RemoteAnimationAdapter remoteAnimationAdapter) {
Winson Chung044d5292014-11-06 11:05:19 -08001865 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001866 clear();
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001867 mNextAppTransitionType = NEXT_TRANSIT_TYPE_REMOTE;
1868 mRemoteAnimationController = new RemoteAnimationController(mService,
1869 remoteAnimationAdapter, mService.mH);
1870 }
1871 }
1872
1873 void overrideInPlaceAppTransition(String packageName, int anim) {
1874 if (canOverridePendingAppTransition()) {
1875 clear();
Winson Chung044d5292014-11-06 11:05:19 -08001876 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE;
1877 mNextAppTransitionPackage = packageName;
1878 mNextAppTransitionInPlace = anim;
Winson Chung044d5292014-11-06 11:05:19 -08001879 }
1880 }
1881
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001882 /**
Tony Mak089c35e2017-12-18 20:34:14 +00001883 * @see {@link #NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS}
1884 */
1885 void overridePendingAppTransitionStartCrossProfileApps() {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001886 if (canOverridePendingAppTransition()) {
Tony Mak089c35e2017-12-18 20:34:14 +00001887 clear();
1888 mNextAppTransitionType = NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS;
1889 postAnimationCallback();
1890 }
1891 }
1892
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001893 private boolean canOverridePendingAppTransition() {
1894 // Remote animations always take precedence
1895 return isTransitionSet() && mNextAppTransitionType != NEXT_TRANSIT_TYPE_REMOTE;
1896 }
1897
Tony Mak089c35e2017-12-18 20:34:14 +00001898 /**
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001899 * If a future is set for the app transition specs, fetch it in another thread.
1900 */
1901 private void fetchAppTransitionSpecsFromFuture() {
1902 if (mNextAppTransitionAnimationsSpecsFuture != null) {
1903 mNextAppTransitionAnimationsSpecsPending = true;
1904 final IAppTransitionAnimationSpecsFuture future
1905 = mNextAppTransitionAnimationsSpecsFuture;
1906 mNextAppTransitionAnimationsSpecsFuture = null;
Jorim Jaggied410b62017-05-05 15:16:14 +02001907 mDefaultExecutor.execute(() -> {
1908 AppTransitionAnimationSpec[] specs = null;
1909 try {
1910 Binder.allowBlocking(future.asBinder());
1911 specs = future.get();
1912 } catch (RemoteException e) {
1913 Slog.w(TAG, "Failed to fetch app transition specs: " + e);
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001914 }
Jorim Jaggied410b62017-05-05 15:16:14 +02001915 synchronized (mService.mWindowMap) {
1916 mNextAppTransitionAnimationsSpecsPending = false;
1917 overridePendingAppTransitionMultiThumb(specs,
1918 mNextAppTransitionFutureCallback, null /* finishedCallback */,
1919 mNextAppTransitionScaleUp);
1920 mNextAppTransitionFutureCallback = null;
Jorim Jaggied410b62017-05-05 15:16:14 +02001921 }
1922 mService.requestTraversal();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001923 });
1924 }
1925 }
1926
Craig Mautner164d4bb2012-11-26 13:51:23 -08001927 @Override
1928 public String toString() {
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001929 return "mNextAppTransition=" + appTransitionToString(mNextAppTransition);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001930 }
1931
Craig Mautner4b71aa12012-12-27 17:20:01 -08001932 /**
1933 * Returns the human readable name of a window transition.
1934 *
1935 * @param transition The window transition.
1936 * @return The transition symbolic name.
1937 */
1938 public static String appTransitionToString(int transition) {
1939 switch (transition) {
1940 case TRANSIT_UNSET: {
1941 return "TRANSIT_UNSET";
1942 }
1943 case TRANSIT_NONE: {
1944 return "TRANSIT_NONE";
1945 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001946 case TRANSIT_ACTIVITY_OPEN: {
1947 return "TRANSIT_ACTIVITY_OPEN";
1948 }
1949 case TRANSIT_ACTIVITY_CLOSE: {
1950 return "TRANSIT_ACTIVITY_CLOSE";
1951 }
1952 case TRANSIT_TASK_OPEN: {
1953 return "TRANSIT_TASK_OPEN";
1954 }
1955 case TRANSIT_TASK_CLOSE: {
1956 return "TRANSIT_TASK_CLOSE";
1957 }
1958 case TRANSIT_TASK_TO_FRONT: {
1959 return "TRANSIT_TASK_TO_FRONT";
1960 }
1961 case TRANSIT_TASK_TO_BACK: {
1962 return "TRANSIT_TASK_TO_BACK";
1963 }
1964 case TRANSIT_WALLPAPER_CLOSE: {
1965 return "TRANSIT_WALLPAPER_CLOSE";
1966 }
1967 case TRANSIT_WALLPAPER_OPEN: {
1968 return "TRANSIT_WALLPAPER_OPEN";
1969 }
1970 case TRANSIT_WALLPAPER_INTRA_OPEN: {
1971 return "TRANSIT_WALLPAPER_INTRA_OPEN";
1972 }
1973 case TRANSIT_WALLPAPER_INTRA_CLOSE: {
1974 return "TRANSIT_WALLPAPER_INTRA_CLOSE";
1975 }
Craig Mautnerbb742462014-07-07 15:28:55 -07001976 case TRANSIT_TASK_OPEN_BEHIND: {
1977 return "TRANSIT_TASK_OPEN_BEHIND";
1978 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001979 case TRANSIT_ACTIVITY_RELAUNCH: {
1980 return "TRANSIT_ACTIVITY_RELAUNCH";
1981 }
Jorim Jaggi192086e2016-03-11 17:17:03 +01001982 case TRANSIT_DOCK_TASK_FROM_RECENTS: {
1983 return "TRANSIT_DOCK_TASK_FROM_RECENTS";
1984 }
Jorim Jaggife762342016-10-13 14:33:27 +02001985 case TRANSIT_KEYGUARD_GOING_AWAY: {
1986 return "TRANSIT_KEYGUARD_GOING_AWAY";
1987 }
1988 case TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER: {
1989 return "TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER";
1990 }
1991 case TRANSIT_KEYGUARD_OCCLUDE: {
1992 return "TRANSIT_KEYGUARD_OCCLUDE";
1993 }
1994 case TRANSIT_KEYGUARD_UNOCCLUDE: {
1995 return "TRANSIT_KEYGUARD_UNOCCLUDE";
1996 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001997 default: {
1998 return "<UNKNOWN>";
1999 }
2000 }
2001 }
2002
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002003 private String appStateToString() {
2004 switch (mAppTransitionState) {
2005 case APP_STATE_IDLE:
2006 return "APP_STATE_IDLE";
2007 case APP_STATE_READY:
2008 return "APP_STATE_READY";
2009 case APP_STATE_RUNNING:
2010 return "APP_STATE_RUNNING";
2011 case APP_STATE_TIMEOUT:
2012 return "APP_STATE_TIMEOUT";
2013 default:
2014 return "unknown state=" + mAppTransitionState;
2015 }
2016 }
2017
2018 private String transitTypeToString() {
2019 switch (mNextAppTransitionType) {
2020 case NEXT_TRANSIT_TYPE_NONE:
2021 return "NEXT_TRANSIT_TYPE_NONE";
2022 case NEXT_TRANSIT_TYPE_CUSTOM:
2023 return "NEXT_TRANSIT_TYPE_CUSTOM";
Winson Chung044d5292014-11-06 11:05:19 -08002024 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
2025 return "NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002026 case NEXT_TRANSIT_TYPE_SCALE_UP:
2027 return "NEXT_TRANSIT_TYPE_SCALE_UP";
2028 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
2029 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP";
2030 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
2031 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN";
Winson Chunga4ccb862014-08-22 15:26:27 -07002032 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
2033 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP";
2034 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN:
2035 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN";
Tony Mak64b8d562017-12-28 17:44:02 +00002036 case NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS:
2037 return "NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002038 default:
2039 return "unknown type=" + mNextAppTransitionType;
2040 }
2041 }
2042
Steven Timotiusaf03df62017-07-18 16:56:43 -07002043 void writeToProto(ProtoOutputStream proto, long fieldId) {
2044 final long token = proto.start(fieldId);
2045 proto.write(APP_TRANSITION_STATE, mAppTransitionState);
2046 proto.write(LAST_USED_APP_TRANSITION, mLastUsedAppTransition);
2047 proto.end(token);
2048 }
2049
Craig Mautner164d4bb2012-11-26 13:51:23 -08002050 @Override
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002051 public void dump(PrintWriter pw, String prefix) {
2052 pw.print(prefix); pw.println(this);
2053 pw.print(prefix); pw.print("mAppTransitionState="); pw.println(appStateToString());
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002054 if (mNextAppTransitionType != NEXT_TRANSIT_TYPE_NONE) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002055 pw.print(prefix); pw.print("mNextAppTransitionType=");
2056 pw.println(transitTypeToString());
Craig Mautner164d4bb2012-11-26 13:51:23 -08002057 }
2058 switch (mNextAppTransitionType) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002059 case NEXT_TRANSIT_TYPE_CUSTOM:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002060 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Craig Mautner164d4bb2012-11-26 13:51:23 -08002061 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002062 pw.print(prefix); pw.print("mNextAppTransitionEnter=0x");
Craig Mautner164d4bb2012-11-26 13:51:23 -08002063 pw.print(Integer.toHexString(mNextAppTransitionEnter));
2064 pw.print(" mNextAppTransitionExit=0x");
2065 pw.println(Integer.toHexString(mNextAppTransitionExit));
2066 break;
Winson Chung044d5292014-11-06 11:05:19 -08002067 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002068 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Winson Chung044d5292014-11-06 11:05:19 -08002069 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002070 pw.print(prefix); pw.print("mNextAppTransitionInPlace=0x");
Winson Chung044d5292014-11-06 11:05:19 -08002071 pw.print(Integer.toHexString(mNextAppTransitionInPlace));
2072 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002073 case NEXT_TRANSIT_TYPE_SCALE_UP: {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002074 getDefaultNextAppTransitionStartRect(mTmpRect);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002075 pw.print(prefix); pw.print("mNextAppTransitionStartX=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002076 pw.print(mTmpRect.left);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002077 pw.print(" mNextAppTransitionStartY=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002078 pw.println(mTmpRect.top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002079 pw.print(prefix); pw.print("mNextAppTransitionStartWidth=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002080 pw.print(mTmpRect.width());
Craig Mautner164d4bb2012-11-26 13:51:23 -08002081 pw.print(" mNextAppTransitionStartHeight=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002082 pw.println(mTmpRect.height());
Craig Mautner164d4bb2012-11-26 13:51:23 -08002083 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002084 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002085 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
2086 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
Winson Chunga4ccb862014-08-22 15:26:27 -07002087 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002088 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN: {
2089 pw.print(prefix); pw.print("mDefaultNextAppTransitionAnimationSpec=");
2090 pw.println(mDefaultNextAppTransitionAnimationSpec);
2091 pw.print(prefix); pw.print("mNextAppTransitionAnimationsSpecs=");
2092 pw.println(mNextAppTransitionAnimationsSpecs);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002093 pw.print(prefix); pw.print("mNextAppTransitionScaleUp=");
2094 pw.println(mNextAppTransitionScaleUp);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002095 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002096 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002097 }
2098 if (mNextAppTransitionCallback != null) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002099 pw.print(prefix); pw.print("mNextAppTransitionCallback=");
2100 pw.println(mNextAppTransitionCallback);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002101 }
Chong Zhang60091a92016-07-27 17:52:45 -07002102 if (mLastUsedAppTransition != TRANSIT_NONE) {
2103 pw.print(prefix); pw.print("mLastUsedAppTransition=");
2104 pw.println(appTransitionToString(mLastUsedAppTransition));
2105 pw.print(prefix); pw.print("mLastOpeningApp=");
2106 pw.println(mLastOpeningApp);
2107 pw.print(prefix); pw.print("mLastClosingApp=");
2108 pw.println(mLastClosingApp);
2109 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002110 }
Amith Yamasani4befbec2013-07-10 16:18:01 -07002111
2112 public void setCurrentUser(int newUserId) {
2113 mCurrentUserId = newUserId;
2114 }
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002115
2116 /**
2117 * @return true if transition is not running and should not be skipped, false if transition is
2118 * already running
2119 */
Jorim Jaggif84e2f62018-01-16 14:17:59 +01002120 boolean prepareAppTransitionLocked(@TransitionType int transit, boolean alwaysKeepCurrent,
2121 @TransitionFlags int flags, boolean forceOverride) {
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002122 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Prepare app transition:"
2123 + " transit=" + appTransitionToString(transit)
2124 + " " + this
2125 + " alwaysKeepCurrent=" + alwaysKeepCurrent
2126 + " Callers=" + Debug.getCallers(3));
Jorim Jaggife762342016-10-13 14:33:27 +02002127 if (forceOverride || isKeyguardTransit(transit) || !isTransitionSet()
2128 || mNextAppTransition == TRANSIT_NONE) {
2129 setAppTransition(transit, flags);
Jorim Jaggia69243a2017-06-15 15:10:38 -04002130 }
2131 // We never want to change from a Keyguard transit to a non-Keyguard transit, as our logic
2132 // relies on the fact that we always execute a Keyguard transition after preparing one.
2133 else if (!alwaysKeepCurrent && !isKeyguardTransit(transit)) {
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002134 if (transit == TRANSIT_TASK_OPEN && isTransitionEqual(TRANSIT_TASK_CLOSE)) {
2135 // Opening a new task always supersedes a close for the anim.
Jorim Jaggife762342016-10-13 14:33:27 +02002136 setAppTransition(transit, flags);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002137 } else if (transit == TRANSIT_ACTIVITY_OPEN
2138 && isTransitionEqual(TRANSIT_ACTIVITY_CLOSE)) {
2139 // Opening a new activity 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 }
2142 }
2143 boolean prepared = prepare();
2144 if (isTransitionSet()) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08002145 mService.mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
2146 mService.mH.sendEmptyMessageDelayed(H.APP_TRANSITION_TIMEOUT, APP_TRANSITION_TIMEOUT_MS);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002147 }
2148 return prepared;
2149 }
Winsonb2024762016-04-05 17:32:30 -07002150
2151 /**
Jorim Jaggife762342016-10-13 14:33:27 +02002152 * @return true if {@param transit} is representing a transition in which Keyguard is going
2153 * away, false otherwise
2154 */
2155 public static boolean isKeyguardGoingAwayTransit(int transit) {
2156 return transit == TRANSIT_KEYGUARD_GOING_AWAY
2157 || transit == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER;
2158 }
2159
2160 private static boolean isKeyguardTransit(int transit) {
2161 return isKeyguardGoingAwayTransit(transit) || transit == TRANSIT_KEYGUARD_OCCLUDE
2162 || transit == TRANSIT_KEYGUARD_UNOCCLUDE;
2163 }
2164
2165 /**
Manu Cornetd7376802017-01-13 13:44:07 -08002166 * @return whether the transition should show the thumbnail being scaled down.
2167 */
2168 private boolean shouldScaleDownThumbnailTransition(int uiMode, int orientation) {
Sid Soundararajan0e88d322017-03-07 15:37:30 -08002169 return mGridLayoutRecentsEnabled
Manu Cornetd7376802017-01-13 13:44:07 -08002170 || orientation == Configuration.ORIENTATION_PORTRAIT;
2171 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002172}