blob: a24ac219bce19933d8e61c82ca3eb1b7c48a169e [file] [log] [blame]
Craig Mautner164d4bb2012-11-26 13:51:23 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server.wm;
18
Jorim Jaggif84e2f62018-01-16 14:17:59 +010019import static android.view.WindowManager.LayoutParams;
20import static android.view.WindowManager.TRANSIT_ACTIVITY_CLOSE;
21import static android.view.WindowManager.TRANSIT_ACTIVITY_OPEN;
22import static android.view.WindowManager.TRANSIT_ACTIVITY_RELAUNCH;
Adrian Roos93577212018-04-10 14:12:10 -070023import static android.view.WindowManager.TRANSIT_CRASHING_ACTIVITY_CLOSE;
Jorim Jaggif84e2f62018-01-16 14:17:59 +010024import static android.view.WindowManager.TRANSIT_DOCK_TASK_FROM_RECENTS;
25import static android.view.WindowManager.TRANSIT_FLAG_KEYGUARD_GOING_AWAY_NO_ANIMATION;
26import static android.view.WindowManager.TRANSIT_FLAG_KEYGUARD_GOING_AWAY_TO_SHADE;
27import static android.view.WindowManager.TRANSIT_KEYGUARD_GOING_AWAY;
28import static android.view.WindowManager.TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER;
29import static android.view.WindowManager.TRANSIT_KEYGUARD_OCCLUDE;
30import static android.view.WindowManager.TRANSIT_KEYGUARD_UNOCCLUDE;
31import static android.view.WindowManager.TRANSIT_NONE;
32import static android.view.WindowManager.TRANSIT_TASK_CLOSE;
Jorim Jaggicecf4242018-02-21 18:46:53 +010033import static android.view.WindowManager.TRANSIT_TASK_IN_PLACE;
Jorim Jaggif84e2f62018-01-16 14:17:59 +010034import static android.view.WindowManager.TRANSIT_TASK_OPEN;
35import static android.view.WindowManager.TRANSIT_TASK_OPEN_BEHIND;
36import static android.view.WindowManager.TRANSIT_TASK_TO_BACK;
37import static android.view.WindowManager.TRANSIT_TASK_TO_FRONT;
Jorim Jaggi98a9d202018-03-26 16:17:07 +020038import static android.view.WindowManager.TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE;
39import static android.view.WindowManager.TRANSIT_TRANSLUCENT_ACTIVITY_OPEN;
Jorim Jaggif84e2f62018-01-16 14:17:59 +010040import static android.view.WindowManager.TRANSIT_UNSET;
41import static android.view.WindowManager.TRANSIT_WALLPAPER_CLOSE;
42import static android.view.WindowManager.TRANSIT_WALLPAPER_INTRA_CLOSE;
43import static android.view.WindowManager.TRANSIT_WALLPAPER_INTRA_OPEN;
44import static android.view.WindowManager.TRANSIT_WALLPAPER_OPEN;
Tony Mak83546a82018-01-22 13:56:20 +000045
Filip Gruszczynski82861362015-10-16 14:21:09 -070046import static com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation;
47import static com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
48import static com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation;
49import static com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
50import static com.android.internal.R.styleable.WindowAnimation_launchTaskBehindSourceAnimation;
51import static com.android.internal.R.styleable.WindowAnimation_launchTaskBehindTargetAnimation;
52import static com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation;
53import static com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
54import static com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation;
55import static com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
56import static com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation;
57import static com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
58import static com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation;
59import static com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
60import static com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation;
61import static com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
62import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation;
63import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
64import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation;
65import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
66import static com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation;
67import static com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Filip Gruszczynski198dcbf2016-01-18 10:02:00 -080068import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
69import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080070import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
71import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Adrian Roose99bc052017-11-20 17:55:31 +010072import static com.android.server.wm.WindowManagerInternal.AppTransitionListener;
Tony Mak089c35e2017-12-18 20:34:14 +000073import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_AFTER_ANIM;
Matthew Ngbf1d9852017-03-14 12:23:09 -070074import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_BEFORE_ANIM;
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +010075import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_NONE;
Yi Jin6c6e9ca2018-03-20 16:53:35 -070076import static com.android.server.wm.AppTransitionProto.APP_TRANSITION_STATE;
77import static com.android.server.wm.AppTransitionProto.LAST_USED_APP_TRANSITION;
Filip Gruszczynski82861362015-10-16 14:21:09 -070078
Tony Mak64b8d562017-12-28 17:44:02 +000079import android.annotation.DrawableRes;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -070080import android.annotation.Nullable;
Matthew Ng43db6d22017-06-27 15:29:39 -070081import android.app.ActivityManager;
Tony Mak089c35e2017-12-18 20:34:14 +000082import android.content.ComponentName;
Craig Mautner164d4bb2012-11-26 13:51:23 -080083import android.content.Context;
Winson21700932016-03-24 17:26:23 -070084import android.content.res.Configuration;
John Reck519ad482018-02-12 17:08:48 -080085import android.graphics.Bitmap;
86import android.graphics.Canvas;
Tony Mak64b8d562017-12-28 17:44:02 +000087import android.graphics.Color;
Winson Chungaa7fa012017-05-24 15:50:06 -070088import android.graphics.GraphicBuffer;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +010089import android.graphics.Path;
John Reck519ad482018-02-12 17:08:48 -080090import android.graphics.Picture;
Winson Chung399f6202014-03-19 10:47:20 -070091import android.graphics.Rect;
Tony Mak64b8d562017-12-28 17:44:02 +000092import android.graphics.drawable.Drawable;
Jorim Jaggied410b62017-05-05 15:16:14 +020093import android.os.Binder;
Craig Mautner164d4bb2012-11-26 13:51:23 -080094import android.os.Debug;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010095import android.os.IBinder;
Craig Mautner164d4bb2012-11-26 13:51:23 -080096import android.os.IRemoteCallback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010097import android.os.RemoteException;
Jorim Jaggif5f9e122017-10-24 18:21:09 +020098import android.os.SystemClock;
Manu Cornetd7376802017-01-13 13:44:07 -080099import android.os.SystemProperties;
Tony Mak089c35e2017-12-18 20:34:14 +0000100import android.os.UserHandle;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800101import android.util.ArraySet;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800102import android.util.Slog;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700103import android.util.SparseArray;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700104import android.util.proto.ProtoOutputStream;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700105import android.view.AppTransitionAnimationSpec;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100106import android.view.IAppTransitionAnimationSpecsFuture;
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100107import android.view.RemoteAnimationAdapter;
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100108import android.view.WindowManager.TransitionFlags;
109import android.view.WindowManager.TransitionType;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800110import android.view.animation.AlphaAnimation;
111import android.view.animation.Animation;
112import android.view.animation.AnimationSet;
113import android.view.animation.AnimationUtils;
Winson Chung399f6202014-03-19 10:47:20 -0700114import android.view.animation.ClipRectAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800115import android.view.animation.Interpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700116import android.view.animation.PathInterpolator;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800117import android.view.animation.ScaleAnimation;
Winson Chung399f6202014-03-19 10:47:20 -0700118import android.view.animation.TranslateAnimation;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700119
Jorim Jaggi98a9d202018-03-26 16:17:07 +0200120import com.android.internal.R;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800121import com.android.internal.util.DumpUtils.Dump;
122import com.android.server.AttributeCache;
123import com.android.server.wm.WindowManagerService.H;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800124import com.android.server.wm.animation.ClipRectLRAnimation;
125import com.android.server.wm.animation.ClipRectTBAnimation;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100126import com.android.server.wm.animation.CurvedTranslateAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800127
128import java.io.PrintWriter;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100129import java.util.ArrayList;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100130import java.util.concurrent.ExecutorService;
131import java.util.concurrent.Executors;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800132
Craig Mautner164d4bb2012-11-26 13:51:23 -0800133// State management of app transitions. When we are preparing for a
134// transition, mNextAppTransition will be the kind of transition to
135// perform or TRANSIT_NONE if we are not waiting. If we are waiting,
136// mOpeningApps and mClosingApps are the lists of tokens that will be
137// made visible or hidden at the next transition.
138public class AppTransition implements Dump {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800139 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppTransition" : TAG_WM;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700140 private static final int CLIP_REVEAL_TRANSLATION_Y_DP = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800141
Winson Chunga4ccb862014-08-22 15:26:27 -0700142 /** Fraction of animation at which the recents thumbnail stays completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700143 private static final float RECENTS_THUMBNAIL_FADEIN_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800144 /** Fraction of animation at which the recents thumbnail becomes completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700145 private static final float RECENTS_THUMBNAIL_FADEOUT_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800146
Filip Gruszczynski84fa3352016-01-25 16:28:49 -0800147 static final int DEFAULT_APP_TRANSITION_DURATION = 336;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800148
149 /** Interpolator to be used for animations that respond directly to a touch */
150 static final Interpolator TOUCH_RESPONSE_INTERPOLATOR =
151 new PathInterpolator(0.3f, 0f, 0.1f, 1f);
152
Jorim Jaggic69bd222016-03-15 14:38:37 +0100153 private static final Interpolator THUMBNAIL_DOCK_INTERPOLATOR =
154 new PathInterpolator(0.85f, 0f, 1f, 1f);
155
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800156 /**
157 * Maximum duration for the clip reveal animation. This is used when there is a lot of movement
158 * involved, to make it more understandable.
159 */
160 private static final int MAX_CLIP_REVEAL_TRANSITION_DURATION = 420;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700161 private static final int THUMBNAIL_APP_TRANSITION_DURATION = 336;
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700162 private static final long APP_TRANSITION_TIMEOUT_MS = 5000;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800163
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800164 private final Context mContext;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800165 private final WindowManagerService mService;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800166
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100167 private @TransitionType int mNextAppTransition = TRANSIT_UNSET;
168 private @TransitionFlags int mNextAppTransitionFlags = 0;
Chong Zhang60091a92016-07-27 17:52:45 -0700169 private int mLastUsedAppTransition = TRANSIT_UNSET;
170 private String mLastOpeningApp;
171 private String mLastClosingApp;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800172
173 private static final int NEXT_TRANSIT_TYPE_NONE = 0;
174 private static final int NEXT_TRANSIT_TYPE_CUSTOM = 1;
175 private static final int NEXT_TRANSIT_TYPE_SCALE_UP = 2;
176 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP = 3;
177 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN = 4;
Winson Chunga4ccb862014-08-22 15:26:27 -0700178 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP = 5;
179 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN = 6;
Winson Chung044d5292014-11-06 11:05:19 -0800180 private static final int NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE = 7;
Chet Haase10e23ab2015-02-11 15:08:38 -0800181 private static final int NEXT_TRANSIT_TYPE_CLIP_REVEAL = 8;
Tony Mak089c35e2017-12-18 20:34:14 +0000182
183 /**
184 * Refers to the transition to activity started by using {@link
185 * android.content.pm.crossprofile.CrossProfileApps#startMainActivity(ComponentName, UserHandle)
186 * }.
187 */
188 private static final int NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS = 9;
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100189 private static final int NEXT_TRANSIT_TYPE_REMOTE = 10;
190
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800191 private int mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
192
Winson Chung399f6202014-03-19 10:47:20 -0700193 // These are the possible states for the enter/exit activities during a thumbnail transition
194 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_UP = 0;
195 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_UP = 1;
196 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN = 2;
197 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN = 3;
198
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800199 private String mNextAppTransitionPackage;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800200 // Used for thumbnail transitions. True if we're scaling up, false if scaling down
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800201 private boolean mNextAppTransitionScaleUp;
202 private IRemoteCallback mNextAppTransitionCallback;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +0100203 private IRemoteCallback mNextAppTransitionFutureCallback;
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -0700204 private IRemoteCallback mAnimationFinishedCallback;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800205 private int mNextAppTransitionEnter;
206 private int mNextAppTransitionExit;
Winson Chung044d5292014-11-06 11:05:19 -0800207 private int mNextAppTransitionInPlace;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700208
209 // Keyed by task id.
210 private final SparseArray<AppTransitionAnimationSpec> mNextAppTransitionAnimationsSpecs
211 = new SparseArray<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100212 private IAppTransitionAnimationSpecsFuture mNextAppTransitionAnimationsSpecsFuture;
213 private boolean mNextAppTransitionAnimationsSpecsPending;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700214 private AppTransitionAnimationSpec mDefaultNextAppTransitionAnimationSpec;
215
Winson Chunga4ccb862014-08-22 15:26:27 -0700216 private Rect mNextAppTransitionInsets = new Rect();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800217
Winson Chung2820c452014-04-15 15:34:44 -0700218 private Rect mTmpFromClipRect = new Rect();
219 private Rect mTmpToClipRect = new Rect();
220
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700221 private final Rect mTmpRect = new Rect();
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700222
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800223 private final static int APP_STATE_IDLE = 0;
224 private final static int APP_STATE_READY = 1;
225 private final static int APP_STATE_RUNNING = 2;
226 private final static int APP_STATE_TIMEOUT = 3;
227 private int mAppTransitionState = APP_STATE_IDLE;
228
229 private final int mConfigShortAnimTime;
Craig Mautner321bdf52012-12-18 09:53:24 -0800230 private final Interpolator mDecelerateInterpolator;
Winson Chunga4ccb862014-08-22 15:26:27 -0700231 private final Interpolator mThumbnailFadeInInterpolator;
232 private final Interpolator mThumbnailFadeOutInterpolator;
Chet Haase10e23ab2015-02-11 15:08:38 -0800233 private final Interpolator mLinearOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700234 private final Interpolator mFastOutLinearInInterpolator;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100235 private final Interpolator mFastOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700236 private final Interpolator mClipHorizontalInterpolator = new PathInterpolator(0, 0, 0.4f, 1f);
237
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700238 private final int mClipRevealTranslationY;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800239
Amith Yamasani4befbec2013-07-10 16:18:01 -0700240 private int mCurrentUserId = 0;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800241 private long mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Amith Yamasani4befbec2013-07-10 16:18:01 -0700242
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100243 private final ArrayList<AppTransitionListener> mListeners = new ArrayList<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100244 private final ExecutorService mDefaultExecutor = Executors.newSingleThreadExecutor();
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100245
Jorim Jaggif97ed922016-02-18 18:57:07 -0800246 private int mLastClipRevealMaxTranslation;
247 private boolean mLastHadClipReveal;
Jorim Jaggi363ab982016-04-26 19:51:20 -0700248 private boolean mProlongedAnimationsEnded;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800249
Manu Cornetd7376802017-01-13 13:44:07 -0800250 private final boolean mGridLayoutRecentsEnabled;
Matthew Ng43db6d22017-06-27 15:29:39 -0700251 private final boolean mLowRamRecentsEnabled;
Manu Cornetd7376802017-01-13 13:44:07 -0800252
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100253 private RemoteAnimationController mRemoteAnimationController;
254
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800255 AppTransition(Context context, WindowManagerService service) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800256 mContext = context;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800257 mService = service;
Chet Haase10e23ab2015-02-11 15:08:38 -0800258 mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
259 com.android.internal.R.interpolator.linear_out_slow_in);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700260 mFastOutLinearInInterpolator = AnimationUtils.loadInterpolator(context,
261 com.android.internal.R.interpolator.fast_out_linear_in);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100262 mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
263 com.android.internal.R.interpolator.fast_out_slow_in);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800264 mConfigShortAnimTime = context.getResources().getInteger(
265 com.android.internal.R.integer.config_shortAnimTime);
Craig Mautner321bdf52012-12-18 09:53:24 -0800266 mDecelerateInterpolator = AnimationUtils.loadInterpolator(context,
267 com.android.internal.R.interpolator.decelerate_cubic);
Winson Chunga4ccb862014-08-22 15:26:27 -0700268 mThumbnailFadeInInterpolator = new Interpolator() {
269 @Override
270 public float getInterpolation(float input) {
271 // Linear response for first fraction, then complete after that.
272 if (input < RECENTS_THUMBNAIL_FADEIN_FRACTION) {
273 return 0f;
274 }
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700275 float t = (input - RECENTS_THUMBNAIL_FADEIN_FRACTION) /
Winson Chunga4ccb862014-08-22 15:26:27 -0700276 (1f - RECENTS_THUMBNAIL_FADEIN_FRACTION);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700277 return mFastOutLinearInInterpolator.getInterpolation(t);
Winson Chunga4ccb862014-08-22 15:26:27 -0700278 }
279 };
280 mThumbnailFadeOutInterpolator = new Interpolator() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800281 @Override
282 public float getInterpolation(float input) {
283 // Linear response for first fraction, then complete after that.
284 if (input < RECENTS_THUMBNAIL_FADEOUT_FRACTION) {
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700285 float t = input / RECENTS_THUMBNAIL_FADEOUT_FRACTION;
286 return mLinearOutSlowInInterpolator.getInterpolation(t);
Craig Mautner321bdf52012-12-18 09:53:24 -0800287 }
Winson Chunga4ccb862014-08-22 15:26:27 -0700288 return 1f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800289 }
290 };
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700291 mClipRevealTranslationY = (int) (CLIP_REVEAL_TRANSLATION_Y_DP
292 * mContext.getResources().getDisplayMetrics().density);
Manu Cornetd7376802017-01-13 13:44:07 -0800293 mGridLayoutRecentsEnabled = SystemProperties.getBoolean("ro.recents.grid", false);
Matthew Ng43db6d22017-06-27 15:29:39 -0700294 mLowRamRecentsEnabled = ActivityManager.isLowRamDeviceStatic();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800295 }
296
297 boolean isTransitionSet() {
298 return mNextAppTransition != TRANSIT_UNSET;
299 }
300
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100301 boolean isTransitionEqual(@TransitionType int transit) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800302 return mNextAppTransition == transit;
303 }
304
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100305 @TransitionType int getAppTransition() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800306 return mNextAppTransition;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800307 }
308
Jorim Jaggife762342016-10-13 14:33:27 +0200309 private void setAppTransition(int transit, int flags) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800310 mNextAppTransition = transit;
Jorim Jaggife762342016-10-13 14:33:27 +0200311 mNextAppTransitionFlags |= flags;
Chong Zhang60091a92016-07-27 17:52:45 -0700312 setLastAppTransition(TRANSIT_UNSET, null, null);
Jorim Jaggi245281c2017-06-07 14:33:04 -0700313 updateBooster();
Chong Zhang60091a92016-07-27 17:52:45 -0700314 }
315
316 void setLastAppTransition(int transit, AppWindowToken openingApp, AppWindowToken closingApp) {
317 mLastUsedAppTransition = transit;
318 mLastOpeningApp = "" + openingApp;
319 mLastClosingApp = "" + closingApp;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800320 }
321
322 boolean isReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800323 return mAppTransitionState == APP_STATE_READY
324 || mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800325 }
326
Craig Mautnerae446592012-12-06 19:05:05 -0800327 void setReady() {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700328 setAppTransitionState(APP_STATE_READY);
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100329 fetchAppTransitionSpecsFromFuture();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800330 }
331
332 boolean isRunning() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800333 return mAppTransitionState == APP_STATE_RUNNING;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800334 }
335
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800336 void setIdle() {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700337 setAppTransitionState(APP_STATE_IDLE);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800338 }
339
340 boolean isTimeout() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800341 return mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800342 }
343
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800344 void setTimeout() {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700345 setAppTransitionState(APP_STATE_TIMEOUT);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800346 }
347
Winson Chungaa7fa012017-05-24 15:50:06 -0700348 GraphicBuffer getAppTransitionThumbnailHeader(int taskId) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700349 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800350 if (spec == null) {
351 spec = mDefaultNextAppTransitionAnimationSpec;
352 }
Winson Chungaa7fa012017-05-24 15:50:06 -0700353 return spec != null ? spec.buffer : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800354 }
355
Winson Chunga4ccb862014-08-22 15:26:27 -0700356 /** Returns whether the next thumbnail transition is aspect scaled up. */
357 boolean isNextThumbnailTransitionAspectScaled() {
358 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
359 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
360 }
361
362 /** Returns whether the next thumbnail transition is scaling up. */
363 boolean isNextThumbnailTransitionScaleUp() {
364 return mNextAppTransitionScaleUp;
365 }
366
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -0800367 boolean isNextAppTransitionThumbnailUp() {
368 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
369 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP;
370 }
371
372 boolean isNextAppTransitionThumbnailDown() {
373 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN ||
374 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
375 }
376
Tony Mak64b8d562017-12-28 17:44:02 +0000377
378 boolean isNextAppTransitionOpenCrossProfileApps() {
379 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS;
380 }
381
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100382 /**
383 * @return true if and only if we are currently fetching app transition specs from the future
384 * passed into {@link #overridePendingAppTransitionMultiThumbFuture}
385 */
386 boolean isFetchingAppTransitionsSpecs() {
387 return mNextAppTransitionAnimationsSpecsPending;
388 }
389
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700390 private boolean prepare() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800391 if (!isRunning()) {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700392 setAppTransitionState(APP_STATE_IDLE);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100393 notifyAppTransitionPendingLocked();
Jorim Jaggif97ed922016-02-18 18:57:07 -0800394 mLastHadClipReveal = false;
395 mLastClipRevealMaxTranslation = 0;
396 mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700397 return true;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800398 }
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700399 return false;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800400 }
401
Jorim Jaggife762342016-10-13 14:33:27 +0200402 /**
403 * @return bit-map of WindowManagerPolicy#FINISH_LAYOUT_REDO_* to indicate whether another
404 * layout pass needs to be done
405 */
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200406 int goodToGo(int transit, AppWindowToken topOpeningApp,
407 AppWindowToken topClosingApp, ArraySet<AppWindowToken> openingApps,
Jorim Jaggife762342016-10-13 14:33:27 +0200408 ArraySet<AppWindowToken> closingApps) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800409 mNextAppTransition = TRANSIT_UNSET;
Jorim Jaggife762342016-10-13 14:33:27 +0200410 mNextAppTransitionFlags = 0;
Jorim Jaggi245281c2017-06-07 14:33:04 -0700411 setAppTransitionState(APP_STATE_RUNNING);
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200412 final AnimationAdapter topOpeningAnim = topOpeningApp != null
413 ? topOpeningApp.getAnimation()
414 : null;
Jorim Jaggife762342016-10-13 14:33:27 +0200415 int redoLayout = notifyAppTransitionStartingLocked(transit,
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200416 topOpeningApp != null ? topOpeningApp.token : null,
417 topClosingApp != null ? topClosingApp.token : null,
418 topOpeningAnim != null ? topOpeningAnim.getDurationHint() : 0,
419 topOpeningAnim != null
420 ? topOpeningAnim.getStatusBarTransitionsStartTime()
421 : SystemClock.uptimeMillis(),
422 AnimationAdapter.STATUS_BAR_TRANSITION_DURATION);
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800423 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Jorim Jaggife762342016-10-13 14:33:27 +0200424 .notifyAppTransitionStarting(openingApps, transit);
Jorim Jaggi363ab982016-04-26 19:51:20 -0700425
426 // Prolong the start for the transition when docking a task from recents, unless recents
427 // ended it already then we don't need to wait.
Jorim Jaggife762342016-10-13 14:33:27 +0200428 if (transit == TRANSIT_DOCK_TASK_FROM_RECENTS && !mProlongedAnimationsEnded) {
Jorim Jaggi363ab982016-04-26 19:51:20 -0700429 for (int i = openingApps.size() - 1; i >= 0; i--) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200430 final AppWindowToken app = openingApps.valueAt(i);
431 app.startDelayingAnimationStart();
Jorim Jaggi363ab982016-04-26 19:51:20 -0700432 }
433 }
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100434 if (mRemoteAnimationController != null) {
435 mRemoteAnimationController.goodToGo();
436 }
Jorim Jaggife762342016-10-13 14:33:27 +0200437 return redoLayout;
Jorim Jaggi363ab982016-04-26 19:51:20 -0700438 }
439
440 /**
441 * Let the transitions manager know that the somebody wanted to end the prolonged animations.
442 */
443 void notifyProlongedAnimationsEnded() {
444 mProlongedAnimationsEnded = true;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800445 }
446
447 void clear() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800448 mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800449 mNextAppTransitionPackage = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700450 mNextAppTransitionAnimationsSpecs.clear();
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100451 mRemoteAnimationController = null;
Jorim Jaggi65193992015-11-23 16:49:59 -0800452 mNextAppTransitionAnimationsSpecsFuture = null;
453 mDefaultNextAppTransitionAnimationSpec = null;
454 mAnimationFinishedCallback = null;
Jorim Jaggi363ab982016-04-26 19:51:20 -0700455 mProlongedAnimationsEnded = false;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800456 }
457
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800458 void freeze() {
Jorim Jaggife762342016-10-13 14:33:27 +0200459 final int transit = mNextAppTransition;
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100460 setAppTransition(TRANSIT_UNSET, 0 /* flags */);
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800461 clear();
462 setReady();
Jorim Jaggife762342016-10-13 14:33:27 +0200463 notifyAppTransitionCancelledLocked(transit);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100464 }
465
Jorim Jaggi245281c2017-06-07 14:33:04 -0700466 private void setAppTransitionState(int state) {
467 mAppTransitionState = state;
468 updateBooster();
469 }
470
471 /**
472 * Updates whether we currently boost wm locked sections and the animation thread. We want to
473 * boost the priorities to a more important value whenever an app transition is going to happen
474 * soon or an app transition is running.
475 */
Jorim Jaggic8cc2292018-03-15 20:16:15 +0100476 void updateBooster() {
477 WindowManagerService.sThreadPriorityBooster.setAppTransitionRunning(needsBoosting());
478 }
479
480 private boolean needsBoosting() {
481 final boolean recentsAnimRunning = mService.getRecentsAnimationController() != null;
482 return mNextAppTransition != TRANSIT_UNSET
483 || mAppTransitionState == APP_STATE_READY
484 || mAppTransitionState == APP_STATE_RUNNING
485 || recentsAnimRunning;
Jorim Jaggi245281c2017-06-07 14:33:04 -0700486 }
487
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100488 void registerListenerLocked(AppTransitionListener listener) {
489 mListeners.add(listener);
490 }
491
Wale Ogunwalea48eadb2015-05-14 17:43:12 -0700492 public void notifyAppTransitionFinishedLocked(IBinder token) {
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100493 for (int i = 0; i < mListeners.size(); i++) {
494 mListeners.get(i).onAppTransitionFinishedLocked(token);
495 }
496 }
497
498 private void notifyAppTransitionPendingLocked() {
499 for (int i = 0; i < mListeners.size(); i++) {
500 mListeners.get(i).onAppTransitionPendingLocked();
501 }
502 }
503
Jorim Jaggife762342016-10-13 14:33:27 +0200504 private void notifyAppTransitionCancelledLocked(int transit) {
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100505 for (int i = 0; i < mListeners.size(); i++) {
Jorim Jaggife762342016-10-13 14:33:27 +0200506 mListeners.get(i).onAppTransitionCancelledLocked(transit);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100507 }
508 }
509
Jorim Jaggife762342016-10-13 14:33:27 +0200510 private int notifyAppTransitionStartingLocked(int transit, IBinder openToken,
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200511 IBinder closeToken, long duration, long statusBarAnimationStartTime,
512 long statusBarAnimationDuration) {
Jorim Jaggife762342016-10-13 14:33:27 +0200513 int redoLayout = 0;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100514 for (int i = 0; i < mListeners.size(); i++) {
Jorim Jaggife762342016-10-13 14:33:27 +0200515 redoLayout |= mListeners.get(i).onAppTransitionStartingLocked(transit, openToken,
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200516 closeToken, duration, statusBarAnimationStartTime, statusBarAnimationDuration);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100517 }
Jorim Jaggife762342016-10-13 14:33:27 +0200518 return redoLayout;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800519 }
520
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100521 private AttributeCache.Entry getCachedAnimations(LayoutParams lp) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800522 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg="
523 + (lp != null ? lp.packageName : null)
524 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
525 if (lp != null && lp.windowAnimations != 0) {
526 // If this is a system resource, don't try to load it from the
527 // application resources. It is nice to avoid loading application
528 // resources if we can.
529 String packageName = lp.packageName != null ? lp.packageName : "android";
530 int resId = lp.windowAnimations;
531 if ((resId&0xFF000000) == 0x01000000) {
532 packageName = "android";
533 }
534 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
535 + packageName);
536 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700537 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800538 }
539 return null;
540 }
541
542 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
543 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package="
544 + packageName + " resId=0x" + Integer.toHexString(resId));
545 if (packageName != null) {
546 if ((resId&0xFF000000) == 0x01000000) {
547 packageName = "android";
548 }
549 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
550 + packageName);
551 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700552 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800553 }
554 return null;
555 }
556
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100557 Animation loadAnimationAttr(LayoutParams lp, int animAttr) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800558 int anim = 0;
559 Context context = mContext;
560 if (animAttr >= 0) {
561 AttributeCache.Entry ent = getCachedAnimations(lp);
562 if (ent != null) {
563 context = ent.context;
564 anim = ent.array.getResourceId(animAttr, 0);
565 }
566 }
567 if (anim != 0) {
568 return AnimationUtils.loadAnimation(context, anim);
569 }
570 return null;
571 }
572
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100573 Animation loadAnimationRes(LayoutParams lp, int resId) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700574 Context context = mContext;
575 if (resId >= 0) {
576 AttributeCache.Entry ent = getCachedAnimations(lp);
577 if (ent != null) {
578 context = ent.context;
579 }
580 return AnimationUtils.loadAnimation(context, resId);
581 }
582 return null;
583 }
584
585 private Animation loadAnimationRes(String packageName, int resId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800586 int anim = 0;
587 Context context = mContext;
588 if (resId >= 0) {
589 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
590 if (ent != null) {
591 context = ent.context;
592 anim = resId;
593 }
594 }
595 if (anim != 0) {
596 return AnimationUtils.loadAnimation(context, anim);
597 }
598 return null;
599 }
600
Craig Mautner164d4bb2012-11-26 13:51:23 -0800601 /**
602 * Compute the pivot point for an animation that is scaling from a small
603 * rect on screen to a larger rect. The pivot point varies depending on
604 * the distance between the inner and outer edges on both sides. This
605 * function computes the pivot point for one dimension.
606 * @param startPos Offset from left/top edge of outer rectangle to
607 * left/top edge of inner rectangle.
608 * @param finalScale The scaling factor between the size of the outer
609 * and inner rectangles.
610 */
611 private static float computePivot(int startPos, float finalScale) {
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800612
613 /*
614 Theorem of intercepting lines:
615
616 + + +-----------------------------------------------+
617 | | | |
618 | | | |
619 | | | |
620 | | | |
621 x | y | | |
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 | +-----------------------------------------------+
653 |
654 |
655 |
656 |
657 |
658 |
659 |
660 |
661 |
662 + ++
663 p ++
664
665 scale = (x - y) / x
666 <=> x = -y / (scale - 1)
667 */
Craig Mautner164d4bb2012-11-26 13:51:23 -0800668 final float denom = finalScale-1;
669 if (Math.abs(denom) < .0001f) {
670 return startPos;
671 }
672 return -startPos / denom;
673 }
674
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700675 private Animation createScaleUpAnimationLocked(int transit, boolean enter,
676 Rect containingFrame) {
677 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700678 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700679 final int appWidth = containingFrame.width();
680 final int appHeight = containingFrame.height();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800681 if (enter) {
682 // Entering app zooms out from the center of the initial rect.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700683 float scaleW = mTmpRect.width() / (float) appWidth;
684 float scaleH = mTmpRect.height() / (float) appHeight;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800685 Animation scale = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700686 computePivot(mTmpRect.left, scaleW),
Winson4c3fecd2016-07-13 12:29:48 -0700687 computePivot(mTmpRect.top, scaleH));
Craig Mautner321bdf52012-12-18 09:53:24 -0800688 scale.setInterpolator(mDecelerateInterpolator);
689
Craig Mautner164d4bb2012-11-26 13:51:23 -0800690 Animation alpha = new AlphaAnimation(0, 1);
Winson Chunga4ccb862014-08-22 15:26:27 -0700691 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
Craig Mautner321bdf52012-12-18 09:53:24 -0800692
693 AnimationSet set = new AnimationSet(false);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800694 set.addAnimation(scale);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800695 set.addAnimation(alpha);
696 set.setDetachWallpaper(true);
697 a = set;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800698 } else if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
699 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800700 // If we are on top of the wallpaper, we need an animation that
701 // correctly handles the wallpaper staying static behind all of
702 // the animated elements. To do this, will just have the existing
703 // element fade out.
704 a = new AlphaAnimation(1, 0);
705 a.setDetachWallpaper(true);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800706 } else {
Craig Mautner321bdf52012-12-18 09:53:24 -0800707 // For normal animations, the exiting element just holds in place.
708 a = new AlphaAnimation(1, 1);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800709 }
Craig Mautner321bdf52012-12-18 09:53:24 -0800710
711 // Pick the desired duration. If this is an inter-activity transition,
712 // it is the standard duration for that. Otherwise we use the longer
713 // task transition duration.
714 final long duration;
715 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800716 case TRANSIT_ACTIVITY_OPEN:
717 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800718 duration = mConfigShortAnimTime;
719 break;
720 default:
721 duration = DEFAULT_APP_TRANSITION_DURATION;
722 break;
723 }
724 a.setDuration(duration);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800725 a.setFillAfter(true);
Craig Mautner321bdf52012-12-18 09:53:24 -0800726 a.setInterpolator(mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800727 a.initialize(appWidth, appHeight, appWidth, appHeight);
728 return a;
729 }
730
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700731 private void getDefaultNextAppTransitionStartRect(Rect rect) {
732 if (mDefaultNextAppTransitionAnimationSpec == null ||
733 mDefaultNextAppTransitionAnimationSpec.rect == null) {
Jorim Jaggi2550f3f2017-03-14 20:15:59 +0100734 Slog.e(TAG, "Starting rect for app requested, but none available", new Throwable());
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700735 rect.setEmpty();
736 } else {
737 rect.set(mDefaultNextAppTransitionAnimationSpec.rect);
738 }
739 }
740
741 void getNextAppTransitionStartRect(int taskId, Rect rect) {
742 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800743 if (spec == null) {
744 spec = mDefaultNextAppTransitionAnimationSpec;
745 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700746 if (spec == null || spec.rect == null) {
Jorim Jaggi2550f3f2017-03-14 20:15:59 +0100747 Slog.e(TAG, "Starting rect for task: " + taskId + " requested, but not available",
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700748 new Throwable());
749 rect.setEmpty();
750 } else {
751 rect.set(spec.rect);
752 }
753 }
754
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800755 private void putDefaultNextAppTransitionCoordinates(int left, int top, int width, int height,
Winson Chungaa7fa012017-05-24 15:50:06 -0700756 GraphicBuffer buffer) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700757 mDefaultNextAppTransitionAnimationSpec = new AppTransitionAnimationSpec(-1 /* taskId */,
Winson Chungaa7fa012017-05-24 15:50:06 -0700758 buffer, new Rect(left, top, left + width, top + height));
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700759 }
760
Jorim Jaggif97ed922016-02-18 18:57:07 -0800761 /**
762 * @return the duration of the last clip reveal animation
763 */
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800764 long getLastClipRevealTransitionDuration() {
765 return mLastClipRevealTransitionDuration;
766 }
767
768 /**
Jorim Jaggif97ed922016-02-18 18:57:07 -0800769 * @return the maximum distance the app surface is traveling of the last clip reveal animation
770 */
771 int getLastClipRevealMaxTranslation() {
772 return mLastClipRevealMaxTranslation;
773 }
774
775 /**
776 * @return true if in the last app transition had a clip reveal animation, false otherwise
777 */
778 boolean hadClipRevealAnimation() {
779 return mLastHadClipReveal;
780 }
781
782 /**
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800783 * Calculates the duration for the clip reveal animation. If the clip is "cut off", meaning that
784 * the start rect is outside of the target rect, and there is a lot of movement going on.
785 *
786 * @param cutOff whether the start rect was not fully contained by the end rect
787 * @param translationX the total translation the surface moves in x direction
788 * @param translationY the total translation the surfaces moves in y direction
789 * @param displayFrame our display frame
790 *
791 * @return the duration of the clip reveal animation, in milliseconds
792 */
793 private long calculateClipRevealTransitionDuration(boolean cutOff, float translationX,
794 float translationY, Rect displayFrame) {
795 if (!cutOff) {
796 return DEFAULT_APP_TRANSITION_DURATION;
797 }
798 final float fraction = Math.max(Math.abs(translationX) / displayFrame.width(),
799 Math.abs(translationY) / displayFrame.height());
800 return (long) (DEFAULT_APP_TRANSITION_DURATION + fraction *
801 (MAX_CLIP_REVEAL_TRANSITION_DURATION - DEFAULT_APP_TRANSITION_DURATION));
802 }
803
804 private Animation createClipRevealAnimationLocked(int transit, boolean enter, Rect appFrame,
805 Rect displayFrame) {
Chet Haase10e23ab2015-02-11 15:08:38 -0800806 final Animation anim;
807 if (enter) {
Craig Mautner80b1f642015-04-22 10:59:09 -0700808 final int appWidth = appFrame.width();
809 final int appHeight = appFrame.height();
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800810
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700811 // mTmpRect will contain an area around the launcher icon that was pressed. We will
Filip Gruszczynski82861362015-10-16 14:21:09 -0700812 // clip reveal from that area in the final area of the app.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700813 getDefaultNextAppTransitionStartRect(mTmpRect);
Craig Mautner80b1f642015-04-22 10:59:09 -0700814
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700815 float t = 0f;
816 if (appHeight > 0) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800817 t = (float) mTmpRect.top / displayFrame.height();
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700818 }
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800819 int translationY = mClipRevealTranslationY + (int)(displayFrame.height() / 7f * t);
820 int translationX = 0;
821 int translationYCorrection = translationY;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700822 int centerX = mTmpRect.centerX();
823 int centerY = mTmpRect.centerY();
824 int halfWidth = mTmpRect.width() / 2;
825 int halfHeight = mTmpRect.height() / 2;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800826 int clipStartX = centerX - halfWidth - appFrame.left;
827 int clipStartY = centerY - halfHeight - appFrame.top;
828 boolean cutOff = false;
829
830 // If the starting rectangle is fully or partially outside of the target rectangle, we
831 // need to start the clipping at the edge and then achieve the rest with translation
832 // and extending the clip rect from that edge.
833 if (appFrame.top > centerY - halfHeight) {
834 translationY = (centerY - halfHeight) - appFrame.top;
835 translationYCorrection = 0;
836 clipStartY = 0;
837 cutOff = true;
838 }
839 if (appFrame.left > centerX - halfWidth) {
840 translationX = (centerX - halfWidth) - appFrame.left;
841 clipStartX = 0;
842 cutOff = true;
843 }
844 if (appFrame.right < centerX + halfWidth) {
845 translationX = (centerX + halfWidth) - appFrame.right;
846 clipStartX = appWidth - mTmpRect.width();
847 cutOff = true;
848 }
849 final long duration = calculateClipRevealTransitionDuration(cutOff, translationX,
850 translationY, displayFrame);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700851
852 // Clip third of the from size of launch icon, expand to full width/height
Chet Haase10e23ab2015-02-11 15:08:38 -0800853 Animation clipAnimLR = new ClipRectLRAnimation(
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800854 clipStartX, clipStartX + mTmpRect.width(), 0, appWidth);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700855 clipAnimLR.setInterpolator(mClipHorizontalInterpolator);
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800856 clipAnimLR.setDuration((long) (duration / 2.5f));
Filip Gruszczynski82861362015-10-16 14:21:09 -0700857
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800858 TranslateAnimation translate = new TranslateAnimation(translationX, 0, translationY, 0);
859 translate.setInterpolator(cutOff ? TOUCH_RESPONSE_INTERPOLATOR
860 : mLinearOutSlowInInterpolator);
861 translate.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800862
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800863 Animation clipAnimTB = new ClipRectTBAnimation(
864 clipStartY, clipStartY + mTmpRect.height(),
865 0, appHeight,
866 translationYCorrection, 0,
867 mLinearOutSlowInInterpolator);
868 clipAnimTB.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
869 clipAnimTB.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800870
871 // Quick fade-in from icon to app window
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800872 final long alphaDuration = duration / 4;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700873 AlphaAnimation alpha = new AlphaAnimation(0.5f, 1);
Chet Haase10e23ab2015-02-11 15:08:38 -0800874 alpha.setDuration(alphaDuration);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700875 alpha.setInterpolator(mLinearOutSlowInInterpolator);
Chet Haase10e23ab2015-02-11 15:08:38 -0800876
877 AnimationSet set = new AnimationSet(false);
878 set.addAnimation(clipAnimLR);
879 set.addAnimation(clipAnimTB);
Filip Gruszczynski82861362015-10-16 14:21:09 -0700880 set.addAnimation(translate);
Chet Haase10e23ab2015-02-11 15:08:38 -0800881 set.addAnimation(alpha);
Filip Gruszczynski9e2cf5b2015-07-31 12:20:40 -0700882 set.setZAdjustment(Animation.ZORDER_TOP);
Chet Haase10e23ab2015-02-11 15:08:38 -0800883 set.initialize(appWidth, appHeight, appWidth, appHeight);
884 anim = set;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800885 mLastHadClipReveal = true;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800886 mLastClipRevealTransitionDuration = duration;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800887
888 // If the start rect was full inside the target rect (cutOff == false), we don't need
889 // to store the translation, because it's only used if cutOff == true.
890 mLastClipRevealMaxTranslation = cutOff
891 ? Math.max(Math.abs(translationY), Math.abs(translationX)) : 0;
Chet Haase10e23ab2015-02-11 15:08:38 -0800892 } else {
893 final long duration;
894 switch (transit) {
895 case TRANSIT_ACTIVITY_OPEN:
896 case TRANSIT_ACTIVITY_CLOSE:
897 duration = mConfigShortAnimTime;
898 break;
899 default:
900 duration = DEFAULT_APP_TRANSITION_DURATION;
901 break;
902 }
903 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
904 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
905 // If we are on top of the wallpaper, we need an animation that
906 // correctly handles the wallpaper staying static behind all of
907 // the animated elements. To do this, will just have the existing
908 // element fade out.
909 anim = new AlphaAnimation(1, 0);
910 anim.setDetachWallpaper(true);
911 } else {
912 // For normal animations, the exiting element just holds in place.
913 anim = new AlphaAnimation(1, 1);
914 }
915 anim.setInterpolator(mDecelerateInterpolator);
916 anim.setDuration(duration);
917 anim.setFillAfter(true);
918 }
919 return anim;
920 }
921
Winson Chung399f6202014-03-19 10:47:20 -0700922 /**
923 * Prepares the specified animation with a standard duration, interpolator, etc.
924 */
Winson Chung5393dff2014-05-08 14:25:43 -0700925 Animation prepareThumbnailAnimationWithDuration(Animation a, int appWidth, int appHeight,
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100926 long duration, Interpolator interpolator) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700927 if (duration > 0) {
928 a.setDuration(duration);
929 }
Winson Chung5393dff2014-05-08 14:25:43 -0700930 a.setFillAfter(true);
Jorim Jaggic69bd222016-03-15 14:38:37 +0100931 if (interpolator != null) {
932 a.setInterpolator(interpolator);
933 }
Winson Chung5393dff2014-05-08 14:25:43 -0700934 a.initialize(appWidth, appHeight, appWidth, appHeight);
935 return a;
936 }
937
938 /**
939 * Prepares the specified animation with a standard duration, interpolator, etc.
940 */
Winson Chung399f6202014-03-19 10:47:20 -0700941 Animation prepareThumbnailAnimation(Animation a, int appWidth, int appHeight, int transit) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800942 // Pick the desired duration. If this is an inter-activity transition,
943 // it is the standard duration for that. Otherwise we use the longer
944 // task transition duration.
Winson Chung5393dff2014-05-08 14:25:43 -0700945 final int duration;
Craig Mautner321bdf52012-12-18 09:53:24 -0800946 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800947 case TRANSIT_ACTIVITY_OPEN:
948 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800949 duration = mConfigShortAnimTime;
950 break;
951 default:
952 duration = DEFAULT_APP_TRANSITION_DURATION;
953 break;
954 }
Winson Chung5393dff2014-05-08 14:25:43 -0700955 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, duration,
956 mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800957 }
958
Winson Chung399f6202014-03-19 10:47:20 -0700959 /**
960 * Return the current thumbnail transition state.
961 */
962 int getThumbnailTransitionState(boolean enter) {
963 if (enter) {
964 if (mNextAppTransitionScaleUp) {
965 return THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
966 } else {
967 return THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN;
968 }
969 } else {
970 if (mNextAppTransitionScaleUp) {
971 return THUMBNAIL_TRANSITION_EXIT_SCALE_UP;
972 } else {
973 return THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN;
974 }
975 }
976 }
977
978 /**
Tony Mak64b8d562017-12-28 17:44:02 +0000979 * Creates an overlay with a background color and a thumbnail for the cross profile apps
980 * animation.
981 */
982 GraphicBuffer createCrossProfileAppsThumbnail(
983 @DrawableRes int thumbnailDrawableRes, Rect frame) {
984 final int width = frame.width();
985 final int height = frame.height();
986
John Reck519ad482018-02-12 17:08:48 -0800987 final Picture picture = new Picture();
988 final Canvas canvas = picture.beginRecording(width, height);
Tony Mak64b8d562017-12-28 17:44:02 +0000989 canvas.drawColor(Color.argb(0.6f, 0, 0, 0));
990 final int thumbnailSize = mService.mContext.getResources().getDimensionPixelSize(
991 com.android.internal.R.dimen.cross_profile_apps_thumbnail_size);
992 final Drawable drawable = mService.mContext.getDrawable(thumbnailDrawableRes);
993 drawable.setBounds(
994 (width - thumbnailSize) / 2,
995 (height - thumbnailSize) / 2,
996 (width + thumbnailSize) / 2,
997 (height + thumbnailSize) / 2);
998 drawable.draw(canvas);
John Reck519ad482018-02-12 17:08:48 -0800999 picture.endRecording();
Tony Mak64b8d562017-12-28 17:44:02 +00001000
John Reck519ad482018-02-12 17:08:48 -08001001 return Bitmap.createBitmap(picture).createGraphicBufferHandle();
Tony Mak64b8d562017-12-28 17:44:02 +00001002 }
1003
1004 Animation createCrossProfileAppsThumbnailAnimationLocked(Rect appRect) {
1005 final Animation animation = loadAnimationRes(
1006 "android", com.android.internal.R.anim.cross_profile_apps_thumbnail_enter);
1007 return prepareThumbnailAnimationWithDuration(animation, appRect.width(),
1008 appRect.height(), 0, null);
1009 }
1010
1011 /**
Winson Chung399f6202014-03-19 10:47:20 -07001012 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001013 * when a thumbnail is specified with the pending animation override.
Winson Chung399f6202014-03-19 10:47:20 -07001014 */
Jorim Jaggide63d442016-03-14 14:56:56 +01001015 Animation createThumbnailAspectScaleAnimationLocked(Rect appRect, @Nullable Rect contentInsets,
Winson Chungaa7fa012017-05-24 15:50:06 -07001016 GraphicBuffer thumbnailHeader, final int taskId, int uiMode, int orientation) {
Winson Chung399f6202014-03-19 10:47:20 -07001017 Animation a;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001018 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chung399f6202014-03-19 10:47:20 -07001019 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001020 final int thumbHeightI = thumbnailHeader.getHeight();
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -07001021 final int appWidth = appRect.width();
Winson Chung399f6202014-03-19 10:47:20 -07001022
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -07001023 float scaleW = appWidth / thumbWidth;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001024 getNextAppTransitionStartRect(taskId, mTmpRect);
Jorim Jaggi09072002016-03-25 16:48:42 -07001025 final float fromX;
Manu Cornet57b61492017-01-24 18:19:05 +09001026 float fromY;
Jorim Jaggi09072002016-03-25 16:48:42 -07001027 final float toX;
Manu Cornet57b61492017-01-24 18:19:05 +09001028 float toY;
Jorim Jaggi09072002016-03-25 16:48:42 -07001029 final float pivotX;
1030 final float pivotY;
Manu Cornetd7376802017-01-13 13:44:07 -08001031 if (shouldScaleDownThumbnailTransition(uiMode, orientation)) {
Jorim Jaggi09072002016-03-25 16:48:42 -07001032 fromX = mTmpRect.left;
1033 fromY = mTmpRect.top;
1034
1035 // For the curved translate animation to work, the pivot points needs to be at the
1036 // same absolute position as the one from the real surface.
1037 toX = mTmpRect.width() / 2 * (scaleW - 1f) + appRect.left;
1038 toY = appRect.height() / 2 * (1 - 1 / scaleW) + appRect.top;
1039 pivotX = mTmpRect.width() / 2;
1040 pivotY = appRect.height() / 2 / scaleW;
Manu Cornet57b61492017-01-24 18:19:05 +09001041 if (mGridLayoutRecentsEnabled) {
1042 // In the grid layout, the header is displayed above the thumbnail instead of
1043 // overlapping it.
1044 fromY -= thumbHeightI;
1045 toY -= thumbHeightI * scaleW;
1046 }
Jorim Jaggi09072002016-03-25 16:48:42 -07001047 } else {
1048 pivotX = 0;
1049 pivotY = 0;
1050 fromX = mTmpRect.left;
1051 fromY = mTmpRect.top;
1052 toX = appRect.left;
1053 toY = appRect.top;
1054 }
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001055 final long duration = getAspectScaleDuration();
1056 final Interpolator interpolator = getAspectScaleInterpolator();
Winson Chung399f6202014-03-19 10:47:20 -07001057 if (mNextAppTransitionScaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001058 // Animation up from the thumbnail to the full screen
Jorim Jaggi8448f332016-03-14 17:50:37 +01001059 Animation scale = new ScaleAnimation(1f, scaleW, 1f, scaleW, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001060 scale.setInterpolator(interpolator);
1061 scale.setDuration(duration);
Jorim Jaggic6c89a82016-01-28 17:48:21 -08001062 Animation alpha = new AlphaAnimation(1f, 0f);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001063 alpha.setInterpolator(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
1064 ? THUMBNAIL_DOCK_INTERPOLATOR : mThumbnailFadeOutInterpolator);
1065 alpha.setDuration(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
1066 ? duration / 2
1067 : duration);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001068 Animation translate = createCurvedMotion(fromX, toX, fromY, toY);
1069 translate.setInterpolator(interpolator);
1070 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -07001071
Jorim Jaggide63d442016-03-14 14:56:56 +01001072 mTmpFromClipRect.set(0, 0, thumbWidthI, thumbHeightI);
1073 mTmpToClipRect.set(appRect);
1074
1075 // Containing frame is in screen space, but we need the clip rect in the
1076 // app space.
1077 mTmpToClipRect.offsetTo(0, 0);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001078 mTmpToClipRect.right = (int) (mTmpToClipRect.right / scaleW);
1079 mTmpToClipRect.bottom = (int) (mTmpToClipRect.bottom / scaleW);
Jorim Jaggide63d442016-03-14 14:56:56 +01001080
1081 if (contentInsets != null) {
Jorim Jaggi8448f332016-03-14 17:50:37 +01001082 mTmpToClipRect.inset((int) (-contentInsets.left * scaleW),
1083 (int) (-contentInsets.top * scaleW),
1084 (int) (-contentInsets.right * scaleW),
1085 (int) (-contentInsets.bottom * scaleW));
Jorim Jaggide63d442016-03-14 14:56:56 +01001086 }
1087
1088 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001089 clipAnim.setInterpolator(interpolator);
1090 clipAnim.setDuration(duration);
Jorim Jaggide63d442016-03-14 14:56:56 +01001091
Winson Chung399f6202014-03-19 10:47:20 -07001092 // This AnimationSet uses the Interpolators assigned above.
1093 AnimationSet set = new AnimationSet(false);
1094 set.addAnimation(scale);
Manu Cornet57b61492017-01-24 18:19:05 +09001095 if (!mGridLayoutRecentsEnabled) {
1096 // In the grid layout, the header should be shown for the whole animation.
1097 set.addAnimation(alpha);
1098 }
Winson Chunga4ccb862014-08-22 15:26:27 -07001099 set.addAnimation(translate);
Jorim Jaggide63d442016-03-14 14:56:56 +01001100 set.addAnimation(clipAnim);
Winson Chung399f6202014-03-19 10:47:20 -07001101 a = set;
1102 } else {
Winson Chunga4ccb862014-08-22 15:26:27 -07001103 // Animation down from the full screen to the thumbnail
Jorim Jaggi8448f332016-03-14 17:50:37 +01001104 Animation scale = new ScaleAnimation(scaleW, 1f, scaleW, 1f, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001105 scale.setInterpolator(interpolator);
1106 scale.setDuration(duration);
Winson Chunga4ccb862014-08-22 15:26:27 -07001107 Animation alpha = new AlphaAnimation(0f, 1f);
1108 alpha.setInterpolator(mThumbnailFadeInInterpolator);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001109 alpha.setDuration(duration);
1110 Animation translate = createCurvedMotion(toX, fromX, toY, fromY);
1111 translate.setInterpolator(interpolator);
1112 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -07001113
Winson Chunga4ccb862014-08-22 15:26:27 -07001114 // This AnimationSet uses the Interpolators assigned above.
1115 AnimationSet set = new AnimationSet(false);
1116 set.addAnimation(scale);
Manu Cornet57b61492017-01-24 18:19:05 +09001117 if (!mGridLayoutRecentsEnabled) {
1118 // In the grid layout, the header should be shown for the whole animation.
1119 set.addAnimation(alpha);
1120 }
Winson Chunga4ccb862014-08-22 15:26:27 -07001121 set.addAnimation(translate);
1122 a = set;
1123
1124 }
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -07001125 return prepareThumbnailAnimationWithDuration(a, appWidth, appRect.height(), 0,
Jorim Jaggic69bd222016-03-15 14:38:37 +01001126 null);
Winson Chung399f6202014-03-19 10:47:20 -07001127 }
1128
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001129 private Animation createCurvedMotion(float fromX, float toX, float fromY, float toY) {
1130
1131 // Almost no x-change - use linear animation
Jorim Jaggic69bd222016-03-15 14:38:37 +01001132 if (Math.abs(toX - fromX) < 1f || mNextAppTransition != TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001133 return new TranslateAnimation(fromX, toX, fromY, toY);
1134 } else {
1135 final Path path = createCurvedPath(fromX, toX, fromY, toY);
1136 return new CurvedTranslateAnimation(path);
1137 }
1138 }
1139
1140 private Path createCurvedPath(float fromX, float toX, float fromY, float toY) {
1141 final Path path = new Path();
1142 path.moveTo(fromX, fromY);
Jorim Jaggi1f458fb2016-03-25 17:36:37 -07001143
1144 if (fromY > toY) {
1145 // If the object needs to go up, move it in horizontal direction first, then vertical.
1146 path.cubicTo(fromX, fromY, toX, 0.9f * fromY + 0.1f * toY, toX, toY);
1147 } else {
1148 // If the object needs to go down, move it in vertical direction first, then horizontal.
1149 path.cubicTo(fromX, fromY, fromX, 0.1f * fromY + 0.9f * toY, toX, toY);
1150 }
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001151 return path;
1152 }
1153
1154 private long getAspectScaleDuration() {
1155 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggic69bd222016-03-15 14:38:37 +01001156 return (long) (THUMBNAIL_APP_TRANSITION_DURATION * 1.35f);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001157 } else {
1158 return THUMBNAIL_APP_TRANSITION_DURATION;
1159 }
1160 }
1161
1162 private Interpolator getAspectScaleInterpolator() {
1163 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
1164 return mFastOutSlowInInterpolator;
1165 } else {
1166 return TOUCH_RESPONSE_INTERPOLATOR;
1167 }
1168 }
1169
Winson Chung399f6202014-03-19 10:47:20 -07001170 /**
1171 * This alternate animation is created when we are doing a thumbnail transition, for the
1172 * activity that is leaving, and the activity that is entering.
1173 */
Winson Chunga4ccb862014-08-22 15:26:27 -07001174 Animation createAspectScaledThumbnailEnterExitAnimationLocked(int thumbTransitState,
Winsonb2024762016-04-05 17:32:30 -07001175 int uiMode, int orientation, int transit, Rect containingFrame, Rect contentInsets,
Matthew Ng43db6d22017-06-27 15:29:39 -07001176 @Nullable Rect surfaceInsets, @Nullable Rect stableInsets, boolean freeform,
1177 int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -07001178 Animation a;
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001179 final int appWidth = containingFrame.width();
1180 final int appHeight = containingFrame.height();
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001181 getDefaultNextAppTransitionStartRect(mTmpRect);
1182 final int thumbWidthI = mTmpRect.width();
Winson Chung399f6202014-03-19 10:47:20 -07001183 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001184 final int thumbHeightI = mTmpRect.height();
Winson Chung399f6202014-03-19 10:47:20 -07001185 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
Winsoncbb625b2016-07-06 15:24:15 -07001186 final int thumbStartX = mTmpRect.left - containingFrame.left - contentInsets.left;
Winson21700932016-03-24 17:26:23 -07001187 final int thumbStartY = mTmpRect.top - containingFrame.top;
Winson Chung399f6202014-03-19 10:47:20 -07001188
1189 switch (thumbTransitState) {
Jorim Jaggi8448f332016-03-14 17:50:37 +01001190 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP:
1191 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1192 final boolean scaleUp = thumbTransitState == THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
1193 if (freeform && scaleUp) {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001194 a = createAspectScaledThumbnailEnterFreeformAnimationLocked(
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001195 containingFrame, surfaceInsets, taskId);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001196 } else if (freeform) {
1197 a = createAspectScaledThumbnailExitFreeformAnimationLocked(
1198 containingFrame, surfaceInsets, taskId);
Winson Chung2820c452014-04-15 15:34:44 -07001199 } else {
Winson21700932016-03-24 17:26:23 -07001200 AnimationSet set = new AnimationSet(true);
1201
1202 // In portrait, we scale to fit the width
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001203 mTmpFromClipRect.set(containingFrame);
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001204 mTmpToClipRect.set(containingFrame);
Jorim Jaggic6c89a82016-01-28 17:48:21 -08001205
1206 // Containing frame is in screen space, but we need the clip rect in the
1207 // app space.
1208 mTmpFromClipRect.offsetTo(0, 0);
1209 mTmpToClipRect.offsetTo(0, 0);
1210
1211 // Exclude insets region from the source clip.
1212 mTmpFromClipRect.inset(contentInsets);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001213 mNextAppTransitionInsets.set(contentInsets);
1214
Manu Cornetd7376802017-01-13 13:44:07 -08001215 if (shouldScaleDownThumbnailTransition(uiMode, orientation)) {
Jorim Jaggic69bd222016-03-15 14:38:37 +01001216 // We scale the width and clip to the top/left square
1217 float scale = thumbWidth /
1218 (appWidth - contentInsets.left - contentInsets.right);
Manu Cornetb68b7652017-01-23 19:37:53 +09001219 if (!mGridLayoutRecentsEnabled) {
1220 int unscaledThumbHeight = (int) (thumbHeight / scale);
1221 mTmpFromClipRect.bottom = mTmpFromClipRect.top + unscaledThumbHeight;
1222 }
Jorim Jaggic69bd222016-03-15 14:38:37 +01001223
1224 mNextAppTransitionInsets.set(contentInsets);
1225
Jorim Jaggi8448f332016-03-14 17:50:37 +01001226 Animation scaleAnim = new ScaleAnimation(
1227 scaleUp ? scale : 1, scaleUp ? 1 : scale,
1228 scaleUp ? scale : 1, scaleUp ? 1 : scale,
Jorim Jaggic69bd222016-03-15 14:38:37 +01001229 containingFrame.width() / 2f,
1230 containingFrame.height() / 2f + contentInsets.top);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001231 final float targetX = (mTmpRect.left - containingFrame.left);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001232 final float x = containingFrame.width() / 2f
1233 - containingFrame.width() / 2f * scale;
Jorim Jaggi8448f332016-03-14 17:50:37 +01001234 final float targetY = (mTmpRect.top - containingFrame.top);
Matthew Ng43db6d22017-06-27 15:29:39 -07001235 float y = containingFrame.height() / 2f
Jorim Jaggic69bd222016-03-15 14:38:37 +01001236 - containingFrame.height() / 2f * scale;
Matthew Ng43db6d22017-06-27 15:29:39 -07001237
1238 // During transition may require clipping offset from any top stable insets
1239 // such as the statusbar height when statusbar is hidden
1240 if (mLowRamRecentsEnabled && contentInsets.top == 0 && scaleUp) {
1241 mTmpFromClipRect.top += stableInsets.top;
1242 y += stableInsets.top;
1243 }
Jorim Jaggi8448f332016-03-14 17:50:37 +01001244 final float startX = targetX - x;
1245 final float startY = targetY - y;
1246 Animation clipAnim = scaleUp
1247 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1248 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1249 Animation translateAnim = scaleUp
Jorim Jaggic69bd222016-03-15 14:38:37 +01001250 ? createCurvedMotion(startX, 0, startY - contentInsets.top, 0)
1251 : createCurvedMotion(0, startX, 0, startY - contentInsets.top);
1252
Winson21700932016-03-24 17:26:23 -07001253 set.addAnimation(clipAnim);
1254 set.addAnimation(scaleAnim);
1255 set.addAnimation(translateAnim);
1256
1257 } else {
1258 // In landscape, we don't scale at all and only crop
1259 mTmpFromClipRect.bottom = mTmpFromClipRect.top + thumbHeightI;
1260 mTmpFromClipRect.right = mTmpFromClipRect.left + thumbWidthI;
1261
Jorim Jaggi8448f332016-03-14 17:50:37 +01001262 Animation clipAnim = scaleUp
1263 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1264 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1265 Animation translateAnim = scaleUp
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001266 ? createCurvedMotion(thumbStartX, 0,
1267 thumbStartY - contentInsets.top, 0)
1268 : createCurvedMotion(0, thumbStartX, 0,
1269 thumbStartY - contentInsets.top);
Winson21700932016-03-24 17:26:23 -07001270
1271 set.addAnimation(clipAnim);
1272 set.addAnimation(translateAnim);
1273 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001274 a = set;
Winson21700932016-03-24 17:26:23 -07001275 a.setZAdjustment(Animation.ZORDER_TOP);
Winson Chung2820c452014-04-15 15:34:44 -07001276 }
Winson Chung399f6202014-03-19 10:47:20 -07001277 break;
1278 }
1279 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001280 // Previous app window during the scale up
Winson Chung399f6202014-03-19 10:47:20 -07001281 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001282 // Fade out the source activity if we are animating to a wallpaper
Winson Chung399f6202014-03-19 10:47:20 -07001283 // activity.
1284 a = new AlphaAnimation(1, 0);
1285 } else {
Winson Chung399f6202014-03-19 10:47:20 -07001286 a = new AlphaAnimation(1, 1);
1287 }
1288 break;
1289 }
1290 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001291 // Target app window during the scale down
1292 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1293 // Fade in the destination activity if we are animating from a wallpaper
1294 // activity.
1295 a = new AlphaAnimation(0, 1);
1296 } else {
1297 a = new AlphaAnimation(1, 1);
1298 }
Winson Chung399f6202014-03-19 10:47:20 -07001299 break;
1300 }
Winson Chung399f6202014-03-19 10:47:20 -07001301 default:
1302 throw new RuntimeException("Invalid thumbnail transition state");
1303 }
1304
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001305 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight,
1306 getAspectScaleDuration(), getAspectScaleInterpolator());
Winson Chung399f6202014-03-19 10:47:20 -07001307 }
1308
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001309 private Animation createAspectScaledThumbnailEnterFreeformAnimationLocked(Rect frame,
1310 @Nullable Rect surfaceInsets, int taskId) {
1311 getNextAppTransitionStartRect(taskId, mTmpRect);
1312 return createAspectScaledThumbnailFreeformAnimationLocked(mTmpRect, frame, surfaceInsets,
1313 true);
1314 }
1315
1316 private Animation createAspectScaledThumbnailExitFreeformAnimationLocked(Rect frame,
1317 @Nullable Rect surfaceInsets, int taskId) {
1318 getNextAppTransitionStartRect(taskId, mTmpRect);
1319 return createAspectScaledThumbnailFreeformAnimationLocked(frame, mTmpRect, surfaceInsets,
1320 false);
1321 }
1322
1323 private AnimationSet createAspectScaledThumbnailFreeformAnimationLocked(Rect sourceFrame,
1324 Rect destFrame, @Nullable Rect surfaceInsets, boolean enter) {
1325 final float sourceWidth = sourceFrame.width();
1326 final float sourceHeight = sourceFrame.height();
1327 final float destWidth = destFrame.width();
1328 final float destHeight = destFrame.height();
1329 final float scaleH = enter ? sourceWidth / destWidth : destWidth / sourceWidth;
1330 final float scaleV = enter ? sourceHeight / destHeight : destHeight / sourceHeight;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001331 AnimationSet set = new AnimationSet(true);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001332 final int surfaceInsetsH = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001333 ? 0 : surfaceInsets.left + surfaceInsets.right;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001334 final int surfaceInsetsV = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001335 ? 0 : surfaceInsets.top + surfaceInsets.bottom;
1336 // We want the scaling to happen from the center of the surface. In order to achieve that,
1337 // we need to account for surface insets that will be used to enlarge the surface.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001338 final float scaleHCenter = ((enter ? destWidth : sourceWidth) + surfaceInsetsH) / 2;
1339 final float scaleVCenter = ((enter ? destHeight : sourceHeight) + surfaceInsetsV) / 2;
1340 final ScaleAnimation scale = enter ?
1341 new ScaleAnimation(scaleH, 1, scaleV, 1, scaleHCenter, scaleVCenter)
1342 : new ScaleAnimation(1, scaleH, 1, scaleV, scaleHCenter, scaleVCenter);
1343 final int sourceHCenter = sourceFrame.left + sourceFrame.width() / 2;
1344 final int sourceVCenter = sourceFrame.top + sourceFrame.height() / 2;
1345 final int destHCenter = destFrame.left + destFrame.width() / 2;
1346 final int destVCenter = destFrame.top + destFrame.height() / 2;
1347 final int fromX = enter ? sourceHCenter - destHCenter : destHCenter - sourceHCenter;
1348 final int fromY = enter ? sourceVCenter - destVCenter : destVCenter - sourceVCenter;
1349 final TranslateAnimation translation = enter ? new TranslateAnimation(fromX, 0, fromY, 0)
1350 : new TranslateAnimation(0, fromX, 0, fromY);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001351 set.addAnimation(scale);
1352 set.addAnimation(translation);
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001353
1354 final IRemoteCallback callback = mAnimationFinishedCallback;
1355 if (callback != null) {
1356 set.setAnimationListener(new Animation.AnimationListener() {
1357 @Override
1358 public void onAnimationStart(Animation animation) { }
1359
1360 @Override
1361 public void onAnimationEnd(Animation animation) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001362 mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK, callback).sendToTarget();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001363 }
1364
1365 @Override
1366 public void onAnimationRepeat(Animation animation) { }
1367 });
1368 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001369 return set;
1370 }
1371
Winson Chung399f6202014-03-19 10:47:20 -07001372 /**
Winson Chunga4ccb862014-08-22 15:26:27 -07001373 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001374 * when a thumbnail is specified with the pending animation override.
Winson Chunga4ccb862014-08-22 15:26:27 -07001375 */
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001376 Animation createThumbnailScaleAnimationLocked(int appWidth, int appHeight, int transit,
Winson Chungaa7fa012017-05-24 15:50:06 -07001377 GraphicBuffer thumbnailHeader) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001378 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001379 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001380 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chunga4ccb862014-08-22 15:26:27 -07001381 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001382 final int thumbHeightI = thumbnailHeader.getHeight();
Winson Chunga4ccb862014-08-22 15:26:27 -07001383 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1384
1385 if (mNextAppTransitionScaleUp) {
1386 // Animation for the thumbnail zooming from its initial size to the full screen
1387 float scaleW = appWidth / thumbWidth;
1388 float scaleH = appHeight / thumbHeight;
1389 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001390 computePivot(mTmpRect.left, 1 / scaleW),
1391 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001392 scale.setInterpolator(mDecelerateInterpolator);
1393
1394 Animation alpha = new AlphaAnimation(1, 0);
1395 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
1396
1397 // This AnimationSet uses the Interpolators assigned above.
1398 AnimationSet set = new AnimationSet(false);
1399 set.addAnimation(scale);
1400 set.addAnimation(alpha);
1401 a = set;
1402 } else {
1403 // Animation for the thumbnail zooming down from the full screen to its final size
1404 float scaleW = appWidth / thumbWidth;
1405 float scaleH = appHeight / thumbHeight;
1406 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001407 computePivot(mTmpRect.left, 1 / scaleW),
1408 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001409 }
1410
1411 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1412 }
1413
1414 /**
Winson Chung399f6202014-03-19 10:47:20 -07001415 * This animation is created when we are doing a thumbnail transition, for the activity that is
1416 * leaving, and the activity that is entering.
1417 */
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001418 Animation createThumbnailEnterExitAnimationLocked(int thumbTransitState, Rect containingFrame,
1419 int transit, int taskId) {
1420 final int appWidth = containingFrame.width();
1421 final int appHeight = containingFrame.height();
Winson Chungaa7fa012017-05-24 15:50:06 -07001422 final GraphicBuffer thumbnailHeader = getAppTransitionThumbnailHeader(taskId);
Winson Chung399f6202014-03-19 10:47:20 -07001423 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001424 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001425 final int thumbWidthI = thumbnailHeader != null ? thumbnailHeader.getWidth() : appWidth;
Winson Chung399f6202014-03-19 10:47:20 -07001426 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001427 final int thumbHeightI = thumbnailHeader != null ? thumbnailHeader.getHeight() : appHeight;
Winson Chung399f6202014-03-19 10:47:20 -07001428 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1429
1430 switch (thumbTransitState) {
1431 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
1432 // Entering app scales up with the thumbnail
1433 float scaleW = thumbWidth / appWidth;
1434 float scaleH = thumbHeight / appHeight;
1435 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001436 computePivot(mTmpRect.left, scaleW),
1437 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001438 break;
1439 }
1440 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
1441 // Exiting app while the thumbnail is scaling up should fade or stay in place
1442 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1443 // Fade out while bringing up selected activity. This keeps the
1444 // current activity from showing through a launching wallpaper
1445 // activity.
1446 a = new AlphaAnimation(1, 0);
1447 } else {
1448 // noop animation
1449 a = new AlphaAnimation(1, 1);
1450 }
1451 break;
1452 }
1453 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
1454 // Entering the other app, it should just be visible while we scale the thumbnail
1455 // down above it
1456 a = new AlphaAnimation(1, 1);
1457 break;
1458 }
1459 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1460 // Exiting the current app, the app should scale down with the thumbnail
1461 float scaleW = thumbWidth / appWidth;
1462 float scaleH = thumbHeight / appHeight;
1463 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001464 computePivot(mTmpRect.left, scaleW),
1465 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001466
1467 Animation alpha = new AlphaAnimation(1, 0);
1468
1469 AnimationSet set = new AnimationSet(true);
1470 set.addAnimation(scale);
1471 set.addAnimation(alpha);
1472 set.setZAdjustment(Animation.ZORDER_TOP);
1473 a = set;
1474 break;
1475 }
1476 default:
1477 throw new RuntimeException("Invalid thumbnail transition state");
1478 }
1479
1480 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1481 }
1482
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001483 private Animation createRelaunchAnimation(Rect containingFrame, Rect contentInsets) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001484 getDefaultNextAppTransitionStartRect(mTmpFromClipRect);
1485 final int left = mTmpFromClipRect.left;
1486 final int top = mTmpFromClipRect.top;
1487 mTmpFromClipRect.offset(-left, -top);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001488 // TODO: Isn't that strange that we ignore exact position of the containingFrame?
1489 mTmpToClipRect.set(0, 0, containingFrame.width(), containingFrame.height());
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001490 AnimationSet set = new AnimationSet(true);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001491 float fromWidth = mTmpFromClipRect.width();
1492 float toWidth = mTmpToClipRect.width();
1493 float fromHeight = mTmpFromClipRect.height();
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001494 // While the window might span the whole display, the actual content will be cropped to the
1495 // system decoration frame, for example when the window is docked. We need to take into
1496 // account the visible height when constructing the animation.
1497 float toHeight = mTmpToClipRect.height() - contentInsets.top - contentInsets.bottom;
1498 int translateAdjustment = 0;
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001499 if (fromWidth <= toWidth && fromHeight <= toHeight) {
1500 // The final window is larger in both dimensions than current window (e.g. we are
1501 // maximizing), so we can simply unclip the new window and there will be no disappearing
1502 // frame.
1503 set.addAnimation(new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect));
1504 } else {
1505 // The disappearing window has one larger dimension. We need to apply scaling, so the
1506 // first frame of the entry animation matches the old window.
1507 set.addAnimation(new ScaleAnimation(fromWidth / toWidth, 1, fromHeight / toHeight, 1));
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001508 // We might not be going exactly full screen, but instead be aligned under the status
1509 // bar using cropping. We still need to account for the cropped part, which will also
1510 // be scaled.
1511 translateAdjustment = (int) (contentInsets.top * fromHeight / toHeight);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001512 }
1513
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001514 // We animate the translation from the old position of the removed window, to the new
1515 // position of the added window. The latter might not be full screen, for example docked for
1516 // docked windows.
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001517 TranslateAnimation translate = new TranslateAnimation(left - containingFrame.left,
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001518 0, top - containingFrame.top - translateAdjustment, 0);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001519 set.addAnimation(translate);
1520 set.setDuration(DEFAULT_APP_TRANSITION_DURATION);
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07001521 set.setZAdjustment(Animation.ZORDER_TOP);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001522 return set;
1523 }
1524
Jorim Jaggic554b772015-06-04 16:07:57 -07001525 /**
1526 * @return true if and only if the first frame of the transition can be skipped, i.e. the first
1527 * frame of the transition doesn't change the visuals on screen, so we can start
1528 * directly with the second one
1529 */
1530 boolean canSkipFirstFrame() {
1531 return mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM
1532 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE
Jorim Jaggife762342016-10-13 14:33:27 +02001533 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CLIP_REVEAL
1534 && mNextAppTransition != TRANSIT_KEYGUARD_GOING_AWAY;
Jorim Jaggic554b772015-06-04 16:07:57 -07001535 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001536
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001537 RemoteAnimationController getRemoteAnimationController() {
1538 return mRemoteAnimationController;
1539 }
1540
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001541 /**
1542 *
1543 * @param frame These are the bounds of the window when it finishes the animation. This is where
1544 * the animation must usually finish in entrance animation, as the next frame will
1545 * display the window at these coordinates. In case of exit animation, this is
1546 * where the animation must start, as the frame before the animation is displaying
1547 * the window at these bounds.
1548 * @param insets Knowing where the window will be positioned is not enough. Some parts of the
1549 * window might be obscured, usually by the system windows (status bar and
1550 * navigation bar) and we use content insets to convey that information. This
1551 * usually affects the animation aspects vertically, as the system decoration is
1552 * at the top and the bottom. For example when we animate from full screen to
1553 * recents, we want to exclude the covered parts, because they won't match the
1554 * thumbnail after the last frame is executed.
1555 * @param surfaceInsets In rare situation the surface is larger than the content and we need to
1556 * know about this to make the animation frames match. We currently use
1557 * this for freeform windows, which have larger surfaces to display
1558 * shadows. When we animate them from recents, we want to match the content
1559 * to the recents thumbnail and hence need to account for the surface being
1560 * bigger.
1561 */
Jorim Jaggif84e2f62018-01-16 14:17:59 +01001562 Animation loadAnimation(LayoutParams lp, int transit, boolean enter, int uiMode,
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001563 int orientation, Rect frame, Rect displayFrame, Rect insets,
Matthew Ng43db6d22017-06-27 15:29:39 -07001564 @Nullable Rect surfaceInsets, @Nullable Rect stableInsets, boolean isVoiceInteraction,
1565 boolean freeform, int taskId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001566 Animation a;
Jorim Jaggife762342016-10-13 14:33:27 +02001567 if (isKeyguardGoingAwayTransit(transit) && enter) {
1568 a = loadKeyguardExitAnimation(transit);
1569 } else if (transit == TRANSIT_KEYGUARD_OCCLUDE) {
1570 a = null;
1571 } else if (transit == TRANSIT_KEYGUARD_UNOCCLUDE && !enter) {
1572 a = loadAnimationRes(lp, com.android.internal.R.anim.wallpaper_open_exit);
Adrian Roos93577212018-04-10 14:12:10 -07001573 } else if (transit == TRANSIT_CRASHING_ACTIVITY_CLOSE) {
1574 a = null;
Jorim Jaggife762342016-10-13 14:33:27 +02001575 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_OPEN
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001576 || transit == TRANSIT_TASK_OPEN
1577 || transit == TRANSIT_TASK_TO_FRONT)) {
1578 a = loadAnimationRes(lp, enter
1579 ? com.android.internal.R.anim.voice_activity_open_enter
1580 : com.android.internal.R.anim.voice_activity_open_exit);
1581 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1582 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001583 + " anim=" + a + " transit=" + appTransitionToString(transit)
1584 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001585 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_CLOSE
1586 || transit == TRANSIT_TASK_CLOSE
1587 || transit == TRANSIT_TASK_TO_BACK)) {
1588 a = loadAnimationRes(lp, enter
1589 ? com.android.internal.R.anim.voice_activity_close_enter
1590 : com.android.internal.R.anim.voice_activity_close_exit);
1591 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1592 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001593 + " anim=" + a + " transit=" + appTransitionToString(transit)
1594 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001595 } else if (transit == TRANSIT_ACTIVITY_RELAUNCH) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001596 a = createRelaunchAnimation(frame, insets);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001597 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1598 "applyAnimation:"
1599 + " anim=" + a + " nextAppTransition=" + mNextAppTransition
1600 + " transit=" + appTransitionToString(transit)
1601 + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001602 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM) {
1603 a = loadAnimationRes(mNextAppTransitionPackage, enter ?
Craig Mautner164d4bb2012-11-26 13:51:23 -08001604 mNextAppTransitionEnter : mNextAppTransitionExit);
1605 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1606 "applyAnimation:"
1607 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001608 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001609 + " Callers=" + Debug.getCallers(3));
Winson Chung044d5292014-11-06 11:05:19 -08001610 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE) {
1611 a = loadAnimationRes(mNextAppTransitionPackage, mNextAppTransitionInPlace);
1612 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1613 "applyAnimation:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001614 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM_IN_PLACE"
1615 + " transit=" + appTransitionToString(transit)
1616 + " Callers=" + Debug.getCallers(3));
Chet Haase10e23ab2015-02-11 15:08:38 -08001617 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001618 a = createClipRevealAnimationLocked(transit, enter, frame, displayFrame);
Chet Haase10e23ab2015-02-11 15:08:38 -08001619 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1620 "applyAnimation:"
1621 + " anim=" + a + " nextAppTransition=ANIM_CLIP_REVEAL"
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001622 + " transit=" + appTransitionToString(transit)
Chet Haase10e23ab2015-02-11 15:08:38 -08001623 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001624 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_SCALE_UP) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001625 a = createScaleUpAnimationLocked(transit, enter, frame);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001626 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1627 "applyAnimation:"
1628 + " anim=" + a + " nextAppTransition=ANIM_SCALE_UP"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001629 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001630 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001631 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
1632 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001633 mNextAppTransitionScaleUp =
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001634 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP);
Winson Chunga4ccb862014-08-22 15:26:27 -07001635 a = createThumbnailEnterExitAnimationLocked(getThumbnailTransitionState(enter),
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001636 frame, transit, taskId);
Winson Chunga4ccb862014-08-22 15:26:27 -07001637 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1638 String animName = mNextAppTransitionScaleUp ?
1639 "ANIM_THUMBNAIL_SCALE_UP" : "ANIM_THUMBNAIL_SCALE_DOWN";
1640 Slog.v(TAG, "applyAnimation:"
1641 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001642 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Winson Chunga4ccb862014-08-22 15:26:27 -07001643 + " Callers=" + Debug.getCallers(3));
1644 }
1645 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
1646 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN) {
1647 mNextAppTransitionScaleUp =
1648 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP);
1649 a = createAspectScaledThumbnailEnterExitAnimationLocked(
Winsonb2024762016-04-05 17:32:30 -07001650 getThumbnailTransitionState(enter), uiMode, orientation, transit, frame,
Matthew Ng43db6d22017-06-27 15:29:39 -07001651 insets, surfaceInsets, stableInsets, freeform, taskId);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001652 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1653 String animName = mNextAppTransitionScaleUp ?
Winson Chunga4ccb862014-08-22 15:26:27 -07001654 "ANIM_THUMBNAIL_ASPECT_SCALE_UP" : "ANIM_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner164d4bb2012-11-26 13:51:23 -08001655 Slog.v(TAG, "applyAnimation:"
1656 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001657 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001658 + " Callers=" + Debug.getCallers(3));
1659 }
Tony Mak83546a82018-01-22 13:56:20 +00001660 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS && enter) {
Jorim Jaggi98a9d202018-03-26 16:17:07 +02001661 a = loadAnimationRes("android",
1662 com.android.internal.R.anim.task_open_enter_cross_profile_apps);
Tony Mak089c35e2017-12-18 20:34:14 +00001663 Slog.v(TAG,
1664 "applyAnimation NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS:"
1665 + " anim=" + a + " transit=" + appTransitionToString(transit)
Jorim Jaggi98a9d202018-03-26 16:17:07 +02001666 + " isEntrance=true" + " Callers=" + Debug.getCallers(3));
1667 } else if (transit == TRANSIT_TRANSLUCENT_ACTIVITY_OPEN && enter) {
1668 a = loadAnimationRes("android",
1669 com.android.internal.R.anim.activity_translucent_open_enter);
1670 Slog.v(TAG,
1671 "applyAnimation TRANSIT_TRANSLUCENT_ACTIVITY_OPEN:"
1672 + " anim=" + a + " transit=" + appTransitionToString(transit)
1673 + " isEntrance=true" + " Callers=" + Debug.getCallers(3));
1674 } else if (transit == TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE && !enter) {
1675 a = loadAnimationRes("android",
1676 com.android.internal.R.anim.activity_translucent_close_exit);
1677 Slog.v(TAG,
1678 "applyAnimation TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE:"
1679 + " anim=" + a + " transit=" + appTransitionToString(transit)
1680 + " isEntrance=false" + " Callers=" + Debug.getCallers(3));
Craig Mautner164d4bb2012-11-26 13:51:23 -08001681 } else {
1682 int animAttr = 0;
1683 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001684 case TRANSIT_ACTIVITY_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001685 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001686 ? WindowAnimation_activityOpenEnterAnimation
1687 : WindowAnimation_activityOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001688 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001689 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001690 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001691 ? WindowAnimation_activityCloseEnterAnimation
1692 : WindowAnimation_activityCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001693 break;
Jorim Jaggi192086e2016-03-11 17:17:03 +01001694 case TRANSIT_DOCK_TASK_FROM_RECENTS:
Craig Mautner4b71aa12012-12-27 17:20:01 -08001695 case TRANSIT_TASK_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001696 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001697 ? WindowAnimation_taskOpenEnterAnimation
1698 : WindowAnimation_taskOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001699 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001700 case TRANSIT_TASK_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001701 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001702 ? WindowAnimation_taskCloseEnterAnimation
1703 : WindowAnimation_taskCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001704 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001705 case TRANSIT_TASK_TO_FRONT:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001706 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001707 ? WindowAnimation_taskToFrontEnterAnimation
1708 : WindowAnimation_taskToFrontExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001709 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001710 case TRANSIT_TASK_TO_BACK:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001711 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001712 ? WindowAnimation_taskToBackEnterAnimation
1713 : WindowAnimation_taskToBackExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001714 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001715 case TRANSIT_WALLPAPER_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001716 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001717 ? WindowAnimation_wallpaperOpenEnterAnimation
1718 : WindowAnimation_wallpaperOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001719 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001720 case TRANSIT_WALLPAPER_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001721 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001722 ? WindowAnimation_wallpaperCloseEnterAnimation
1723 : WindowAnimation_wallpaperCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001724 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001725 case TRANSIT_WALLPAPER_INTRA_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001726 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001727 ? WindowAnimation_wallpaperIntraOpenEnterAnimation
1728 : WindowAnimation_wallpaperIntraOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001729 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001730 case TRANSIT_WALLPAPER_INTRA_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001731 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001732 ? WindowAnimation_wallpaperIntraCloseEnterAnimation
1733 : WindowAnimation_wallpaperIntraCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001734 break;
Craig Mautnerbb742462014-07-07 15:28:55 -07001735 case TRANSIT_TASK_OPEN_BEHIND:
1736 animAttr = enter
1737 ? WindowAnimation_launchTaskBehindSourceAnimation
Craig Mautner3b2cd1d2014-08-25 14:25:54 -07001738 : WindowAnimation_launchTaskBehindTargetAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001739 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001740 a = animAttr != 0 ? loadAnimationAttr(lp, animAttr) : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001741 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1742 "applyAnimation:"
1743 + " anim=" + a
1744 + " animAttr=0x" + Integer.toHexString(animAttr)
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001745 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001746 + " Callers=" + Debug.getCallers(3));
1747 }
1748 return a;
1749 }
1750
Jorim Jaggife762342016-10-13 14:33:27 +02001751 private Animation loadKeyguardExitAnimation(int transit) {
1752 if ((mNextAppTransitionFlags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_NO_ANIMATION) != 0) {
1753 return null;
1754 }
1755 final boolean toShade =
1756 (mNextAppTransitionFlags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_TO_SHADE) != 0;
1757 return mService.mPolicy.createHiddenByKeyguardExit(
1758 transit == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER, toShade);
1759 }
1760
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001761 int getAppStackClipMode() {
Matthew Ngbf1d9852017-03-14 12:23:09 -07001762 // When dismiss keyguard animation occurs, clip before the animation to prevent docked
1763 // app from showing beyond the divider
1764 if (mNextAppTransition == TRANSIT_KEYGUARD_GOING_AWAY
1765 || mNextAppTransition == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER) {
1766 return STACK_CLIP_BEFORE_ANIM;
1767 }
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001768 return mNextAppTransition == TRANSIT_ACTIVITY_RELAUNCH
Jorim Jaggic69bd222016-03-15 14:38:37 +01001769 || mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
Jorim Jaggi1f458fb2016-03-25 17:36:37 -07001770 || mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001771 ? STACK_CLIP_NONE
1772 : STACK_CLIP_AFTER_ANIM;
1773 }
1774
Jorim Jaggife762342016-10-13 14:33:27 +02001775 public int getTransitFlags() {
1776 return mNextAppTransitionFlags;
1777 }
1778
Craig Mautner164d4bb2012-11-26 13:51:23 -08001779 void postAnimationCallback() {
1780 if (mNextAppTransitionCallback != null) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001781 mService.mH.sendMessage(mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK,
1782 mNextAppTransitionCallback));
Craig Mautner164d4bb2012-11-26 13:51:23 -08001783 mNextAppTransitionCallback = null;
1784 }
1785 }
1786
1787 void overridePendingAppTransition(String packageName, int enterAnim, int exitAnim,
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001788 IRemoteCallback startedCallback) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001789 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001790 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001791 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001792 mNextAppTransitionPackage = packageName;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001793 mNextAppTransitionEnter = enterAnim;
1794 mNextAppTransitionExit = exitAnim;
1795 postAnimationCallback();
1796 mNextAppTransitionCallback = startedCallback;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001797 }
1798 }
1799
1800 void overridePendingAppTransitionScaleUp(int startX, int startY, int startWidth,
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001801 int startHeight) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001802 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001803 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001804 mNextAppTransitionType = NEXT_TRANSIT_TYPE_SCALE_UP;
Winson4c3fecd2016-07-13 12:29:48 -07001805 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001806 postAnimationCallback();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001807 }
1808 }
1809
Chet Haase10e23ab2015-02-11 15:08:38 -08001810 void overridePendingAppTransitionClipReveal(int startX, int startY,
1811 int startWidth, int startHeight) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001812 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001813 clear();
Chet Haase10e23ab2015-02-11 15:08:38 -08001814 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CLIP_REVEAL;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001815 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Chet Haase10e23ab2015-02-11 15:08:38 -08001816 postAnimationCallback();
Chet Haase10e23ab2015-02-11 15:08:38 -08001817 }
1818 }
1819
Winson Chungaa7fa012017-05-24 15:50:06 -07001820 void overridePendingAppTransitionThumb(GraphicBuffer srcThumb, int startX, int startY,
Craig Mautner164d4bb2012-11-26 13:51:23 -08001821 IRemoteCallback startedCallback, boolean scaleUp) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001822 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001823 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001824 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP
1825 : NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001826 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001827 putDefaultNextAppTransitionCoordinates(startX, startY, 0, 0, srcThumb);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001828 postAnimationCallback();
1829 mNextAppTransitionCallback = startedCallback;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001830 }
1831 }
1832
Winson Chungaa7fa012017-05-24 15:50:06 -07001833 void overridePendingAppTransitionAspectScaledThumb(GraphicBuffer srcThumb, int startX, int startY,
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001834 int targetWidth, int targetHeight, IRemoteCallback startedCallback, boolean scaleUp) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001835 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001836 clear();
Winson Chunga4ccb862014-08-22 15:26:27 -07001837 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1838 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Winson Chunga4ccb862014-08-22 15:26:27 -07001839 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001840 putDefaultNextAppTransitionCoordinates(startX, startY, targetWidth, targetHeight,
1841 srcThumb);
Winson Chunga4ccb862014-08-22 15:26:27 -07001842 postAnimationCallback();
1843 mNextAppTransitionCallback = startedCallback;
Winson Chunga4ccb862014-08-22 15:26:27 -07001844 }
1845 }
1846
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001847 void overridePendingAppTransitionMultiThumb(AppTransitionAnimationSpec[] specs,
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001848 IRemoteCallback onAnimationStartedCallback, IRemoteCallback onAnimationFinishedCallback,
1849 boolean scaleUp) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001850 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001851 clear();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001852 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1853 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001854 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi43102412015-11-11 16:28:37 +01001855 if (specs != null) {
1856 for (int i = 0; i < specs.length; i++) {
1857 AppTransitionAnimationSpec spec = specs[i];
1858 if (spec != null) {
1859 mNextAppTransitionAnimationsSpecs.put(spec.taskId, spec);
1860 if (i == 0) {
1861 // In full screen mode, the transition code depends on the default spec
1862 // to be set.
1863 Rect rect = spec.rect;
1864 putDefaultNextAppTransitionCoordinates(rect.left, rect.top,
Winson Chungaa7fa012017-05-24 15:50:06 -07001865 rect.width(), rect.height(), spec.buffer);
Jorim Jaggi43102412015-11-11 16:28:37 +01001866 }
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001867 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001868 }
1869 }
1870 postAnimationCallback();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001871 mNextAppTransitionCallback = onAnimationStartedCallback;
1872 mAnimationFinishedCallback = onAnimationFinishedCallback;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001873 }
1874 }
1875
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001876 void overridePendingAppTransitionMultiThumbFuture(
1877 IAppTransitionAnimationSpecsFuture specsFuture, IRemoteCallback callback,
1878 boolean scaleUp) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001879 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001880 clear();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001881 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1882 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001883 mNextAppTransitionAnimationsSpecsFuture = specsFuture;
1884 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001885 mNextAppTransitionFutureCallback = callback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001886 }
1887 }
1888
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001889 void overridePendingAppTransitionRemote(RemoteAnimationAdapter remoteAnimationAdapter) {
Winson Chung044d5292014-11-06 11:05:19 -08001890 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001891 clear();
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001892 mNextAppTransitionType = NEXT_TRANSIT_TYPE_REMOTE;
1893 mRemoteAnimationController = new RemoteAnimationController(mService,
1894 remoteAnimationAdapter, mService.mH);
1895 }
1896 }
1897
1898 void overrideInPlaceAppTransition(String packageName, int anim) {
1899 if (canOverridePendingAppTransition()) {
1900 clear();
Winson Chung044d5292014-11-06 11:05:19 -08001901 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE;
1902 mNextAppTransitionPackage = packageName;
1903 mNextAppTransitionInPlace = anim;
Winson Chung044d5292014-11-06 11:05:19 -08001904 }
1905 }
1906
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001907 /**
Tony Mak089c35e2017-12-18 20:34:14 +00001908 * @see {@link #NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS}
1909 */
1910 void overridePendingAppTransitionStartCrossProfileApps() {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001911 if (canOverridePendingAppTransition()) {
Tony Mak089c35e2017-12-18 20:34:14 +00001912 clear();
1913 mNextAppTransitionType = NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS;
1914 postAnimationCallback();
1915 }
1916 }
1917
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001918 private boolean canOverridePendingAppTransition() {
1919 // Remote animations always take precedence
1920 return isTransitionSet() && mNextAppTransitionType != NEXT_TRANSIT_TYPE_REMOTE;
1921 }
1922
Tony Mak089c35e2017-12-18 20:34:14 +00001923 /**
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001924 * If a future is set for the app transition specs, fetch it in another thread.
1925 */
1926 private void fetchAppTransitionSpecsFromFuture() {
1927 if (mNextAppTransitionAnimationsSpecsFuture != null) {
1928 mNextAppTransitionAnimationsSpecsPending = true;
1929 final IAppTransitionAnimationSpecsFuture future
1930 = mNextAppTransitionAnimationsSpecsFuture;
1931 mNextAppTransitionAnimationsSpecsFuture = null;
Jorim Jaggied410b62017-05-05 15:16:14 +02001932 mDefaultExecutor.execute(() -> {
1933 AppTransitionAnimationSpec[] specs = null;
1934 try {
1935 Binder.allowBlocking(future.asBinder());
1936 specs = future.get();
1937 } catch (RemoteException e) {
1938 Slog.w(TAG, "Failed to fetch app transition specs: " + e);
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001939 }
Jorim Jaggied410b62017-05-05 15:16:14 +02001940 synchronized (mService.mWindowMap) {
1941 mNextAppTransitionAnimationsSpecsPending = false;
1942 overridePendingAppTransitionMultiThumb(specs,
1943 mNextAppTransitionFutureCallback, null /* finishedCallback */,
1944 mNextAppTransitionScaleUp);
1945 mNextAppTransitionFutureCallback = null;
Jorim Jaggied410b62017-05-05 15:16:14 +02001946 }
1947 mService.requestTraversal();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001948 });
1949 }
1950 }
1951
Craig Mautner164d4bb2012-11-26 13:51:23 -08001952 @Override
1953 public String toString() {
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001954 return "mNextAppTransition=" + appTransitionToString(mNextAppTransition);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001955 }
1956
Craig Mautner4b71aa12012-12-27 17:20:01 -08001957 /**
1958 * Returns the human readable name of a window transition.
1959 *
1960 * @param transition The window transition.
1961 * @return The transition symbolic name.
1962 */
1963 public static String appTransitionToString(int transition) {
1964 switch (transition) {
1965 case TRANSIT_UNSET: {
1966 return "TRANSIT_UNSET";
1967 }
1968 case TRANSIT_NONE: {
1969 return "TRANSIT_NONE";
1970 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001971 case TRANSIT_ACTIVITY_OPEN: {
1972 return "TRANSIT_ACTIVITY_OPEN";
1973 }
1974 case TRANSIT_ACTIVITY_CLOSE: {
1975 return "TRANSIT_ACTIVITY_CLOSE";
1976 }
1977 case TRANSIT_TASK_OPEN: {
1978 return "TRANSIT_TASK_OPEN";
1979 }
1980 case TRANSIT_TASK_CLOSE: {
1981 return "TRANSIT_TASK_CLOSE";
1982 }
1983 case TRANSIT_TASK_TO_FRONT: {
1984 return "TRANSIT_TASK_TO_FRONT";
1985 }
1986 case TRANSIT_TASK_TO_BACK: {
1987 return "TRANSIT_TASK_TO_BACK";
1988 }
1989 case TRANSIT_WALLPAPER_CLOSE: {
1990 return "TRANSIT_WALLPAPER_CLOSE";
1991 }
1992 case TRANSIT_WALLPAPER_OPEN: {
1993 return "TRANSIT_WALLPAPER_OPEN";
1994 }
1995 case TRANSIT_WALLPAPER_INTRA_OPEN: {
1996 return "TRANSIT_WALLPAPER_INTRA_OPEN";
1997 }
1998 case TRANSIT_WALLPAPER_INTRA_CLOSE: {
1999 return "TRANSIT_WALLPAPER_INTRA_CLOSE";
2000 }
Craig Mautnerbb742462014-07-07 15:28:55 -07002001 case TRANSIT_TASK_OPEN_BEHIND: {
2002 return "TRANSIT_TASK_OPEN_BEHIND";
2003 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07002004 case TRANSIT_ACTIVITY_RELAUNCH: {
2005 return "TRANSIT_ACTIVITY_RELAUNCH";
2006 }
Jorim Jaggi192086e2016-03-11 17:17:03 +01002007 case TRANSIT_DOCK_TASK_FROM_RECENTS: {
2008 return "TRANSIT_DOCK_TASK_FROM_RECENTS";
2009 }
Jorim Jaggife762342016-10-13 14:33:27 +02002010 case TRANSIT_KEYGUARD_GOING_AWAY: {
2011 return "TRANSIT_KEYGUARD_GOING_AWAY";
2012 }
2013 case TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER: {
2014 return "TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER";
2015 }
2016 case TRANSIT_KEYGUARD_OCCLUDE: {
2017 return "TRANSIT_KEYGUARD_OCCLUDE";
2018 }
2019 case TRANSIT_KEYGUARD_UNOCCLUDE: {
2020 return "TRANSIT_KEYGUARD_UNOCCLUDE";
2021 }
Jorim Jaggi98a9d202018-03-26 16:17:07 +02002022 case TRANSIT_TRANSLUCENT_ACTIVITY_OPEN: {
2023 return "TRANSIT_TRANSLUCENT_ACTIVITY_OPEN";
2024 }
2025 case TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE: {
2026 return "TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE";
2027 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002028 default: {
2029 return "<UNKNOWN>";
2030 }
2031 }
2032 }
2033
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002034 private String appStateToString() {
2035 switch (mAppTransitionState) {
2036 case APP_STATE_IDLE:
2037 return "APP_STATE_IDLE";
2038 case APP_STATE_READY:
2039 return "APP_STATE_READY";
2040 case APP_STATE_RUNNING:
2041 return "APP_STATE_RUNNING";
2042 case APP_STATE_TIMEOUT:
2043 return "APP_STATE_TIMEOUT";
2044 default:
2045 return "unknown state=" + mAppTransitionState;
2046 }
2047 }
2048
2049 private String transitTypeToString() {
2050 switch (mNextAppTransitionType) {
2051 case NEXT_TRANSIT_TYPE_NONE:
2052 return "NEXT_TRANSIT_TYPE_NONE";
2053 case NEXT_TRANSIT_TYPE_CUSTOM:
2054 return "NEXT_TRANSIT_TYPE_CUSTOM";
Winson Chung044d5292014-11-06 11:05:19 -08002055 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
2056 return "NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002057 case NEXT_TRANSIT_TYPE_SCALE_UP:
2058 return "NEXT_TRANSIT_TYPE_SCALE_UP";
2059 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
2060 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP";
2061 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
2062 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN";
Winson Chunga4ccb862014-08-22 15:26:27 -07002063 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
2064 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP";
2065 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN:
2066 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN";
Tony Mak64b8d562017-12-28 17:44:02 +00002067 case NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS:
2068 return "NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002069 default:
2070 return "unknown type=" + mNextAppTransitionType;
2071 }
2072 }
2073
Steven Timotiusaf03df62017-07-18 16:56:43 -07002074 void writeToProto(ProtoOutputStream proto, long fieldId) {
2075 final long token = proto.start(fieldId);
2076 proto.write(APP_TRANSITION_STATE, mAppTransitionState);
2077 proto.write(LAST_USED_APP_TRANSITION, mLastUsedAppTransition);
2078 proto.end(token);
2079 }
2080
Craig Mautner164d4bb2012-11-26 13:51:23 -08002081 @Override
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002082 public void dump(PrintWriter pw, String prefix) {
2083 pw.print(prefix); pw.println(this);
2084 pw.print(prefix); pw.print("mAppTransitionState="); pw.println(appStateToString());
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002085 if (mNextAppTransitionType != NEXT_TRANSIT_TYPE_NONE) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002086 pw.print(prefix); pw.print("mNextAppTransitionType=");
2087 pw.println(transitTypeToString());
Craig Mautner164d4bb2012-11-26 13:51:23 -08002088 }
2089 switch (mNextAppTransitionType) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002090 case NEXT_TRANSIT_TYPE_CUSTOM:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002091 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Craig Mautner164d4bb2012-11-26 13:51:23 -08002092 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002093 pw.print(prefix); pw.print("mNextAppTransitionEnter=0x");
Craig Mautner164d4bb2012-11-26 13:51:23 -08002094 pw.print(Integer.toHexString(mNextAppTransitionEnter));
2095 pw.print(" mNextAppTransitionExit=0x");
2096 pw.println(Integer.toHexString(mNextAppTransitionExit));
2097 break;
Winson Chung044d5292014-11-06 11:05:19 -08002098 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002099 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Winson Chung044d5292014-11-06 11:05:19 -08002100 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002101 pw.print(prefix); pw.print("mNextAppTransitionInPlace=0x");
Winson Chung044d5292014-11-06 11:05:19 -08002102 pw.print(Integer.toHexString(mNextAppTransitionInPlace));
2103 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002104 case NEXT_TRANSIT_TYPE_SCALE_UP: {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002105 getDefaultNextAppTransitionStartRect(mTmpRect);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002106 pw.print(prefix); pw.print("mNextAppTransitionStartX=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002107 pw.print(mTmpRect.left);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002108 pw.print(" mNextAppTransitionStartY=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002109 pw.println(mTmpRect.top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002110 pw.print(prefix); pw.print("mNextAppTransitionStartWidth=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002111 pw.print(mTmpRect.width());
Craig Mautner164d4bb2012-11-26 13:51:23 -08002112 pw.print(" mNextAppTransitionStartHeight=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002113 pw.println(mTmpRect.height());
Craig Mautner164d4bb2012-11-26 13:51:23 -08002114 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002115 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002116 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
2117 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
Winson Chunga4ccb862014-08-22 15:26:27 -07002118 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002119 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN: {
2120 pw.print(prefix); pw.print("mDefaultNextAppTransitionAnimationSpec=");
2121 pw.println(mDefaultNextAppTransitionAnimationSpec);
2122 pw.print(prefix); pw.print("mNextAppTransitionAnimationsSpecs=");
2123 pw.println(mNextAppTransitionAnimationsSpecs);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002124 pw.print(prefix); pw.print("mNextAppTransitionScaleUp=");
2125 pw.println(mNextAppTransitionScaleUp);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002126 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002127 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002128 }
2129 if (mNextAppTransitionCallback != null) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002130 pw.print(prefix); pw.print("mNextAppTransitionCallback=");
2131 pw.println(mNextAppTransitionCallback);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002132 }
Chong Zhang60091a92016-07-27 17:52:45 -07002133 if (mLastUsedAppTransition != TRANSIT_NONE) {
2134 pw.print(prefix); pw.print("mLastUsedAppTransition=");
2135 pw.println(appTransitionToString(mLastUsedAppTransition));
2136 pw.print(prefix); pw.print("mLastOpeningApp=");
2137 pw.println(mLastOpeningApp);
2138 pw.print(prefix); pw.print("mLastClosingApp=");
2139 pw.println(mLastClosingApp);
2140 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002141 }
Amith Yamasani4befbec2013-07-10 16:18:01 -07002142
2143 public void setCurrentUser(int newUserId) {
2144 mCurrentUserId = newUserId;
2145 }
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002146
2147 /**
2148 * @return true if transition is not running and should not be skipped, false if transition is
2149 * already running
2150 */
Jorim Jaggif84e2f62018-01-16 14:17:59 +01002151 boolean prepareAppTransitionLocked(@TransitionType int transit, boolean alwaysKeepCurrent,
2152 @TransitionFlags int flags, boolean forceOverride) {
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002153 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Prepare app transition:"
2154 + " transit=" + appTransitionToString(transit)
2155 + " " + this
2156 + " alwaysKeepCurrent=" + alwaysKeepCurrent
2157 + " Callers=" + Debug.getCallers(3));
Jorim Jaggife762342016-10-13 14:33:27 +02002158 if (forceOverride || isKeyguardTransit(transit) || !isTransitionSet()
2159 || mNextAppTransition == TRANSIT_NONE) {
2160 setAppTransition(transit, flags);
Jorim Jaggia69243a2017-06-15 15:10:38 -04002161 }
2162 // We never want to change from a Keyguard transit to a non-Keyguard transit, as our logic
Adrian Roos93577212018-04-10 14:12:10 -07002163 // relies on the fact that we always execute a Keyguard transition after preparing one. We
2164 // also don't want to change away from a crashing transition.
2165 else if (!alwaysKeepCurrent && !isKeyguardTransit(transit)
2166 && transit != TRANSIT_CRASHING_ACTIVITY_CLOSE) {
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002167 if (transit == TRANSIT_TASK_OPEN && isTransitionEqual(TRANSIT_TASK_CLOSE)) {
2168 // Opening a new task always supersedes a close for the anim.
Jorim Jaggife762342016-10-13 14:33:27 +02002169 setAppTransition(transit, flags);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002170 } else if (transit == TRANSIT_ACTIVITY_OPEN
2171 && isTransitionEqual(TRANSIT_ACTIVITY_CLOSE)) {
2172 // Opening a new activity always supersedes a close for the anim.
Jorim Jaggife762342016-10-13 14:33:27 +02002173 setAppTransition(transit, flags);
Jorim Jaggicecf4242018-02-21 18:46:53 +01002174 } else if (isTaskTransit(transit) && isActivityTransit(mNextAppTransition)) {
2175 // Task animations always supersede activity animations, because if we have both, it
2176 // usually means that activity transition were just trampoline activities.
2177 setAppTransition(transit, flags);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002178 }
2179 }
2180 boolean prepared = prepare();
2181 if (isTransitionSet()) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08002182 mService.mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
2183 mService.mH.sendEmptyMessageDelayed(H.APP_TRANSITION_TIMEOUT, APP_TRANSITION_TIMEOUT_MS);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002184 }
2185 return prepared;
2186 }
Winsonb2024762016-04-05 17:32:30 -07002187
2188 /**
Jorim Jaggife762342016-10-13 14:33:27 +02002189 * @return true if {@param transit} is representing a transition in which Keyguard is going
2190 * away, false otherwise
2191 */
2192 public static boolean isKeyguardGoingAwayTransit(int transit) {
2193 return transit == TRANSIT_KEYGUARD_GOING_AWAY
2194 || transit == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER;
2195 }
2196
2197 private static boolean isKeyguardTransit(int transit) {
2198 return isKeyguardGoingAwayTransit(transit) || transit == TRANSIT_KEYGUARD_OCCLUDE
2199 || transit == TRANSIT_KEYGUARD_UNOCCLUDE;
2200 }
2201
Jorim Jaggi98a9d202018-03-26 16:17:07 +02002202 static boolean isTaskTransit(int transit) {
2203 return isTaskOpenTransit(transit)
Jorim Jaggicecf4242018-02-21 18:46:53 +01002204 || transit == TRANSIT_TASK_CLOSE
Jorim Jaggicecf4242018-02-21 18:46:53 +01002205 || transit == TRANSIT_TASK_TO_BACK
Jorim Jaggicecf4242018-02-21 18:46:53 +01002206 || transit == TRANSIT_TASK_IN_PLACE;
2207 }
2208
Jorim Jaggi98a9d202018-03-26 16:17:07 +02002209 private static boolean isTaskOpenTransit(int transit) {
2210 return transit == TRANSIT_TASK_OPEN
2211 || transit == TRANSIT_TASK_OPEN_BEHIND
2212 || transit == TRANSIT_TASK_TO_FRONT;
2213 }
2214
2215 static boolean isActivityTransit(int transit) {
Jorim Jaggicecf4242018-02-21 18:46:53 +01002216 return transit == TRANSIT_ACTIVITY_OPEN
2217 || transit == TRANSIT_ACTIVITY_CLOSE
2218 || transit == TRANSIT_ACTIVITY_RELAUNCH;
2219 }
2220
Jorim Jaggife762342016-10-13 14:33:27 +02002221 /**
Manu Cornetd7376802017-01-13 13:44:07 -08002222 * @return whether the transition should show the thumbnail being scaled down.
2223 */
2224 private boolean shouldScaleDownThumbnailTransition(int uiMode, int orientation) {
Sid Soundararajan0e88d322017-03-07 15:37:30 -08002225 return mGridLayoutRecentsEnabled
Manu Cornetd7376802017-01-13 13:44:07 -08002226 || orientation == Configuration.ORIENTATION_PORTRAIT;
2227 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002228}