blob: 0dc06b27a6050d04e316d07b2079a8541e0d107d [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 Jaggi0a1523d2018-04-19 17:48:38 +0200557 Animation loadAnimationAttr(LayoutParams lp, int animAttr, int transit) {
Jorim Jaggi5f95b002018-04-19 13:27:52 +0000558 int anim = 0;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800559 Context context = mContext;
Jorim Jaggi5f95b002018-04-19 13:27:52 +0000560 if (animAttr >= 0) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800561 AttributeCache.Entry ent = getCachedAnimations(lp);
562 if (ent != null) {
563 context = ent.context;
564 anim = ent.array.getResourceId(animAttr, 0);
565 }
566 }
Jorim Jaggi0a1523d2018-04-19 17:48:38 +0200567 anim = updateToTranslucentAnimIfNeeded(anim, transit);
Jorim Jaggi5f95b002018-04-19 13:27:52 +0000568 if (anim != 0) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800569 return AnimationUtils.loadAnimation(context, anim);
570 }
571 return null;
572 }
573
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100574 Animation loadAnimationRes(LayoutParams lp, int resId) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700575 Context context = mContext;
Jorim Jaggi5f95b002018-04-19 13:27:52 +0000576 if (resId >= 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700577 AttributeCache.Entry ent = getCachedAnimations(lp);
578 if (ent != null) {
579 context = ent.context;
580 }
581 return AnimationUtils.loadAnimation(context, resId);
582 }
583 return null;
584 }
585
586 private Animation loadAnimationRes(String packageName, int resId) {
Jorim Jaggi5f95b002018-04-19 13:27:52 +0000587 int anim = 0;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800588 Context context = mContext;
Jorim Jaggi5f95b002018-04-19 13:27:52 +0000589 if (resId >= 0) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800590 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
591 if (ent != null) {
592 context = ent.context;
593 anim = resId;
594 }
595 }
Jorim Jaggi5f95b002018-04-19 13:27:52 +0000596 if (anim != 0) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800597 return AnimationUtils.loadAnimation(context, anim);
598 }
599 return null;
600 }
601
Jorim Jaggi0a1523d2018-04-19 17:48:38 +0200602 private int updateToTranslucentAnimIfNeeded(int anim, int transit) {
603 if (transit == TRANSIT_TRANSLUCENT_ACTIVITY_OPEN && anim == R.anim.activity_open_enter) {
604 return R.anim.activity_translucent_open_enter;
605 }
606 if (transit == TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE && anim == R.anim.activity_close_exit) {
607 return R.anim.activity_translucent_close_exit;
608 }
609 return anim;
610 }
611
Craig Mautner164d4bb2012-11-26 13:51:23 -0800612 /**
613 * Compute the pivot point for an animation that is scaling from a small
614 * rect on screen to a larger rect. The pivot point varies depending on
615 * the distance between the inner and outer edges on both sides. This
616 * function computes the pivot point for one dimension.
617 * @param startPos Offset from left/top edge of outer rectangle to
618 * left/top edge of inner rectangle.
619 * @param finalScale The scaling factor between the size of the outer
620 * and inner rectangles.
621 */
622 private static float computePivot(int startPos, float finalScale) {
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800623
624 /*
625 Theorem of intercepting lines:
626
627 + + +-----------------------------------------------+
628 | | | |
629 | | | |
630 | | | |
631 | | | |
632 x | y | | |
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 | +-----------------------------------------------+
664 |
665 |
666 |
667 |
668 |
669 |
670 |
671 |
672 |
673 + ++
674 p ++
675
676 scale = (x - y) / x
677 <=> x = -y / (scale - 1)
678 */
Craig Mautner164d4bb2012-11-26 13:51:23 -0800679 final float denom = finalScale-1;
680 if (Math.abs(denom) < .0001f) {
681 return startPos;
682 }
683 return -startPos / denom;
684 }
685
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700686 private Animation createScaleUpAnimationLocked(int transit, boolean enter,
687 Rect containingFrame) {
688 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700689 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700690 final int appWidth = containingFrame.width();
691 final int appHeight = containingFrame.height();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800692 if (enter) {
693 // Entering app zooms out from the center of the initial rect.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700694 float scaleW = mTmpRect.width() / (float) appWidth;
695 float scaleH = mTmpRect.height() / (float) appHeight;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800696 Animation scale = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700697 computePivot(mTmpRect.left, scaleW),
Winson4c3fecd2016-07-13 12:29:48 -0700698 computePivot(mTmpRect.top, scaleH));
Craig Mautner321bdf52012-12-18 09:53:24 -0800699 scale.setInterpolator(mDecelerateInterpolator);
700
Craig Mautner164d4bb2012-11-26 13:51:23 -0800701 Animation alpha = new AlphaAnimation(0, 1);
Winson Chunga4ccb862014-08-22 15:26:27 -0700702 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
Craig Mautner321bdf52012-12-18 09:53:24 -0800703
704 AnimationSet set = new AnimationSet(false);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800705 set.addAnimation(scale);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800706 set.addAnimation(alpha);
707 set.setDetachWallpaper(true);
708 a = set;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800709 } else if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
710 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800711 // If we are on top of the wallpaper, we need an animation that
712 // correctly handles the wallpaper staying static behind all of
713 // the animated elements. To do this, will just have the existing
714 // element fade out.
715 a = new AlphaAnimation(1, 0);
716 a.setDetachWallpaper(true);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800717 } else {
Craig Mautner321bdf52012-12-18 09:53:24 -0800718 // For normal animations, the exiting element just holds in place.
719 a = new AlphaAnimation(1, 1);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800720 }
Craig Mautner321bdf52012-12-18 09:53:24 -0800721
722 // Pick the desired duration. If this is an inter-activity transition,
723 // it is the standard duration for that. Otherwise we use the longer
724 // task transition duration.
725 final long duration;
726 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800727 case TRANSIT_ACTIVITY_OPEN:
728 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800729 duration = mConfigShortAnimTime;
730 break;
731 default:
732 duration = DEFAULT_APP_TRANSITION_DURATION;
733 break;
734 }
735 a.setDuration(duration);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800736 a.setFillAfter(true);
Craig Mautner321bdf52012-12-18 09:53:24 -0800737 a.setInterpolator(mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800738 a.initialize(appWidth, appHeight, appWidth, appHeight);
739 return a;
740 }
741
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700742 private void getDefaultNextAppTransitionStartRect(Rect rect) {
743 if (mDefaultNextAppTransitionAnimationSpec == null ||
744 mDefaultNextAppTransitionAnimationSpec.rect == null) {
Jorim Jaggi2550f3f2017-03-14 20:15:59 +0100745 Slog.e(TAG, "Starting rect for app requested, but none available", new Throwable());
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700746 rect.setEmpty();
747 } else {
748 rect.set(mDefaultNextAppTransitionAnimationSpec.rect);
749 }
750 }
751
752 void getNextAppTransitionStartRect(int taskId, Rect rect) {
753 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800754 if (spec == null) {
755 spec = mDefaultNextAppTransitionAnimationSpec;
756 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700757 if (spec == null || spec.rect == null) {
Jorim Jaggi2550f3f2017-03-14 20:15:59 +0100758 Slog.e(TAG, "Starting rect for task: " + taskId + " requested, but not available",
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700759 new Throwable());
760 rect.setEmpty();
761 } else {
762 rect.set(spec.rect);
763 }
764 }
765
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800766 private void putDefaultNextAppTransitionCoordinates(int left, int top, int width, int height,
Winson Chungaa7fa012017-05-24 15:50:06 -0700767 GraphicBuffer buffer) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700768 mDefaultNextAppTransitionAnimationSpec = new AppTransitionAnimationSpec(-1 /* taskId */,
Winson Chungaa7fa012017-05-24 15:50:06 -0700769 buffer, new Rect(left, top, left + width, top + height));
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700770 }
771
Jorim Jaggif97ed922016-02-18 18:57:07 -0800772 /**
773 * @return the duration of the last clip reveal animation
774 */
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800775 long getLastClipRevealTransitionDuration() {
776 return mLastClipRevealTransitionDuration;
777 }
778
779 /**
Jorim Jaggif97ed922016-02-18 18:57:07 -0800780 * @return the maximum distance the app surface is traveling of the last clip reveal animation
781 */
782 int getLastClipRevealMaxTranslation() {
783 return mLastClipRevealMaxTranslation;
784 }
785
786 /**
787 * @return true if in the last app transition had a clip reveal animation, false otherwise
788 */
789 boolean hadClipRevealAnimation() {
790 return mLastHadClipReveal;
791 }
792
793 /**
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800794 * Calculates the duration for the clip reveal animation. If the clip is "cut off", meaning that
795 * the start rect is outside of the target rect, and there is a lot of movement going on.
796 *
797 * @param cutOff whether the start rect was not fully contained by the end rect
798 * @param translationX the total translation the surface moves in x direction
799 * @param translationY the total translation the surfaces moves in y direction
800 * @param displayFrame our display frame
801 *
802 * @return the duration of the clip reveal animation, in milliseconds
803 */
804 private long calculateClipRevealTransitionDuration(boolean cutOff, float translationX,
805 float translationY, Rect displayFrame) {
806 if (!cutOff) {
807 return DEFAULT_APP_TRANSITION_DURATION;
808 }
809 final float fraction = Math.max(Math.abs(translationX) / displayFrame.width(),
810 Math.abs(translationY) / displayFrame.height());
811 return (long) (DEFAULT_APP_TRANSITION_DURATION + fraction *
812 (MAX_CLIP_REVEAL_TRANSITION_DURATION - DEFAULT_APP_TRANSITION_DURATION));
813 }
814
815 private Animation createClipRevealAnimationLocked(int transit, boolean enter, Rect appFrame,
816 Rect displayFrame) {
Chet Haase10e23ab2015-02-11 15:08:38 -0800817 final Animation anim;
818 if (enter) {
Craig Mautner80b1f642015-04-22 10:59:09 -0700819 final int appWidth = appFrame.width();
820 final int appHeight = appFrame.height();
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800821
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700822 // mTmpRect will contain an area around the launcher icon that was pressed. We will
Filip Gruszczynski82861362015-10-16 14:21:09 -0700823 // clip reveal from that area in the final area of the app.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700824 getDefaultNextAppTransitionStartRect(mTmpRect);
Craig Mautner80b1f642015-04-22 10:59:09 -0700825
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700826 float t = 0f;
827 if (appHeight > 0) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800828 t = (float) mTmpRect.top / displayFrame.height();
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700829 }
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800830 int translationY = mClipRevealTranslationY + (int)(displayFrame.height() / 7f * t);
831 int translationX = 0;
832 int translationYCorrection = translationY;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700833 int centerX = mTmpRect.centerX();
834 int centerY = mTmpRect.centerY();
835 int halfWidth = mTmpRect.width() / 2;
836 int halfHeight = mTmpRect.height() / 2;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800837 int clipStartX = centerX - halfWidth - appFrame.left;
838 int clipStartY = centerY - halfHeight - appFrame.top;
839 boolean cutOff = false;
840
841 // If the starting rectangle is fully or partially outside of the target rectangle, we
842 // need to start the clipping at the edge and then achieve the rest with translation
843 // and extending the clip rect from that edge.
844 if (appFrame.top > centerY - halfHeight) {
845 translationY = (centerY - halfHeight) - appFrame.top;
846 translationYCorrection = 0;
847 clipStartY = 0;
848 cutOff = true;
849 }
850 if (appFrame.left > centerX - halfWidth) {
851 translationX = (centerX - halfWidth) - appFrame.left;
852 clipStartX = 0;
853 cutOff = true;
854 }
855 if (appFrame.right < centerX + halfWidth) {
856 translationX = (centerX + halfWidth) - appFrame.right;
857 clipStartX = appWidth - mTmpRect.width();
858 cutOff = true;
859 }
860 final long duration = calculateClipRevealTransitionDuration(cutOff, translationX,
861 translationY, displayFrame);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700862
863 // Clip third of the from size of launch icon, expand to full width/height
Chet Haase10e23ab2015-02-11 15:08:38 -0800864 Animation clipAnimLR = new ClipRectLRAnimation(
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800865 clipStartX, clipStartX + mTmpRect.width(), 0, appWidth);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700866 clipAnimLR.setInterpolator(mClipHorizontalInterpolator);
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800867 clipAnimLR.setDuration((long) (duration / 2.5f));
Filip Gruszczynski82861362015-10-16 14:21:09 -0700868
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800869 TranslateAnimation translate = new TranslateAnimation(translationX, 0, translationY, 0);
870 translate.setInterpolator(cutOff ? TOUCH_RESPONSE_INTERPOLATOR
871 : mLinearOutSlowInInterpolator);
872 translate.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800873
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800874 Animation clipAnimTB = new ClipRectTBAnimation(
875 clipStartY, clipStartY + mTmpRect.height(),
876 0, appHeight,
877 translationYCorrection, 0,
878 mLinearOutSlowInInterpolator);
879 clipAnimTB.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
880 clipAnimTB.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800881
882 // Quick fade-in from icon to app window
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800883 final long alphaDuration = duration / 4;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700884 AlphaAnimation alpha = new AlphaAnimation(0.5f, 1);
Chet Haase10e23ab2015-02-11 15:08:38 -0800885 alpha.setDuration(alphaDuration);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700886 alpha.setInterpolator(mLinearOutSlowInInterpolator);
Chet Haase10e23ab2015-02-11 15:08:38 -0800887
888 AnimationSet set = new AnimationSet(false);
889 set.addAnimation(clipAnimLR);
890 set.addAnimation(clipAnimTB);
Filip Gruszczynski82861362015-10-16 14:21:09 -0700891 set.addAnimation(translate);
Chet Haase10e23ab2015-02-11 15:08:38 -0800892 set.addAnimation(alpha);
Filip Gruszczynski9e2cf5b2015-07-31 12:20:40 -0700893 set.setZAdjustment(Animation.ZORDER_TOP);
Chet Haase10e23ab2015-02-11 15:08:38 -0800894 set.initialize(appWidth, appHeight, appWidth, appHeight);
895 anim = set;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800896 mLastHadClipReveal = true;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800897 mLastClipRevealTransitionDuration = duration;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800898
899 // If the start rect was full inside the target rect (cutOff == false), we don't need
900 // to store the translation, because it's only used if cutOff == true.
901 mLastClipRevealMaxTranslation = cutOff
902 ? Math.max(Math.abs(translationY), Math.abs(translationX)) : 0;
Chet Haase10e23ab2015-02-11 15:08:38 -0800903 } else {
904 final long duration;
905 switch (transit) {
906 case TRANSIT_ACTIVITY_OPEN:
907 case TRANSIT_ACTIVITY_CLOSE:
908 duration = mConfigShortAnimTime;
909 break;
910 default:
911 duration = DEFAULT_APP_TRANSITION_DURATION;
912 break;
913 }
914 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
915 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
916 // If we are on top of the wallpaper, we need an animation that
917 // correctly handles the wallpaper staying static behind all of
918 // the animated elements. To do this, will just have the existing
919 // element fade out.
920 anim = new AlphaAnimation(1, 0);
921 anim.setDetachWallpaper(true);
922 } else {
923 // For normal animations, the exiting element just holds in place.
924 anim = new AlphaAnimation(1, 1);
925 }
926 anim.setInterpolator(mDecelerateInterpolator);
927 anim.setDuration(duration);
928 anim.setFillAfter(true);
929 }
930 return anim;
931 }
932
Winson Chung399f6202014-03-19 10:47:20 -0700933 /**
934 * Prepares the specified animation with a standard duration, interpolator, etc.
935 */
Winson Chung5393dff2014-05-08 14:25:43 -0700936 Animation prepareThumbnailAnimationWithDuration(Animation a, int appWidth, int appHeight,
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100937 long duration, Interpolator interpolator) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700938 if (duration > 0) {
939 a.setDuration(duration);
940 }
Winson Chung5393dff2014-05-08 14:25:43 -0700941 a.setFillAfter(true);
Jorim Jaggic69bd222016-03-15 14:38:37 +0100942 if (interpolator != null) {
943 a.setInterpolator(interpolator);
944 }
Winson Chung5393dff2014-05-08 14:25:43 -0700945 a.initialize(appWidth, appHeight, appWidth, appHeight);
946 return a;
947 }
948
949 /**
950 * Prepares the specified animation with a standard duration, interpolator, etc.
951 */
Winson Chung399f6202014-03-19 10:47:20 -0700952 Animation prepareThumbnailAnimation(Animation a, int appWidth, int appHeight, int transit) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800953 // Pick the desired duration. If this is an inter-activity transition,
954 // it is the standard duration for that. Otherwise we use the longer
955 // task transition duration.
Winson Chung5393dff2014-05-08 14:25:43 -0700956 final int duration;
Craig Mautner321bdf52012-12-18 09:53:24 -0800957 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800958 case TRANSIT_ACTIVITY_OPEN:
959 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800960 duration = mConfigShortAnimTime;
961 break;
962 default:
963 duration = DEFAULT_APP_TRANSITION_DURATION;
964 break;
965 }
Winson Chung5393dff2014-05-08 14:25:43 -0700966 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, duration,
967 mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800968 }
969
Winson Chung399f6202014-03-19 10:47:20 -0700970 /**
971 * Return the current thumbnail transition state.
972 */
973 int getThumbnailTransitionState(boolean enter) {
974 if (enter) {
975 if (mNextAppTransitionScaleUp) {
976 return THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
977 } else {
978 return THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN;
979 }
980 } else {
981 if (mNextAppTransitionScaleUp) {
982 return THUMBNAIL_TRANSITION_EXIT_SCALE_UP;
983 } else {
984 return THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN;
985 }
986 }
987 }
988
989 /**
Tony Mak64b8d562017-12-28 17:44:02 +0000990 * Creates an overlay with a background color and a thumbnail for the cross profile apps
991 * animation.
992 */
993 GraphicBuffer createCrossProfileAppsThumbnail(
994 @DrawableRes int thumbnailDrawableRes, Rect frame) {
995 final int width = frame.width();
996 final int height = frame.height();
997
John Reck519ad482018-02-12 17:08:48 -0800998 final Picture picture = new Picture();
999 final Canvas canvas = picture.beginRecording(width, height);
Tony Mak64b8d562017-12-28 17:44:02 +00001000 canvas.drawColor(Color.argb(0.6f, 0, 0, 0));
1001 final int thumbnailSize = mService.mContext.getResources().getDimensionPixelSize(
1002 com.android.internal.R.dimen.cross_profile_apps_thumbnail_size);
1003 final Drawable drawable = mService.mContext.getDrawable(thumbnailDrawableRes);
1004 drawable.setBounds(
1005 (width - thumbnailSize) / 2,
1006 (height - thumbnailSize) / 2,
1007 (width + thumbnailSize) / 2,
1008 (height + thumbnailSize) / 2);
1009 drawable.draw(canvas);
John Reck519ad482018-02-12 17:08:48 -08001010 picture.endRecording();
Tony Mak64b8d562017-12-28 17:44:02 +00001011
John Reck519ad482018-02-12 17:08:48 -08001012 return Bitmap.createBitmap(picture).createGraphicBufferHandle();
Tony Mak64b8d562017-12-28 17:44:02 +00001013 }
1014
1015 Animation createCrossProfileAppsThumbnailAnimationLocked(Rect appRect) {
1016 final Animation animation = loadAnimationRes(
1017 "android", com.android.internal.R.anim.cross_profile_apps_thumbnail_enter);
1018 return prepareThumbnailAnimationWithDuration(animation, appRect.width(),
1019 appRect.height(), 0, null);
1020 }
1021
1022 /**
Winson Chung399f6202014-03-19 10:47:20 -07001023 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001024 * when a thumbnail is specified with the pending animation override.
Winson Chung399f6202014-03-19 10:47:20 -07001025 */
Jorim Jaggide63d442016-03-14 14:56:56 +01001026 Animation createThumbnailAspectScaleAnimationLocked(Rect appRect, @Nullable Rect contentInsets,
Winson Chungaa7fa012017-05-24 15:50:06 -07001027 GraphicBuffer thumbnailHeader, final int taskId, int uiMode, int orientation) {
Winson Chung399f6202014-03-19 10:47:20 -07001028 Animation a;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001029 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chung399f6202014-03-19 10:47:20 -07001030 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001031 final int thumbHeightI = thumbnailHeader.getHeight();
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -07001032 final int appWidth = appRect.width();
Winson Chung399f6202014-03-19 10:47:20 -07001033
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -07001034 float scaleW = appWidth / thumbWidth;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001035 getNextAppTransitionStartRect(taskId, mTmpRect);
Jorim Jaggi09072002016-03-25 16:48:42 -07001036 final float fromX;
Manu Cornet57b61492017-01-24 18:19:05 +09001037 float fromY;
Jorim Jaggi09072002016-03-25 16:48:42 -07001038 final float toX;
Manu Cornet57b61492017-01-24 18:19:05 +09001039 float toY;
Jorim Jaggi09072002016-03-25 16:48:42 -07001040 final float pivotX;
1041 final float pivotY;
Manu Cornetd7376802017-01-13 13:44:07 -08001042 if (shouldScaleDownThumbnailTransition(uiMode, orientation)) {
Jorim Jaggi09072002016-03-25 16:48:42 -07001043 fromX = mTmpRect.left;
1044 fromY = mTmpRect.top;
1045
1046 // For the curved translate animation to work, the pivot points needs to be at the
1047 // same absolute position as the one from the real surface.
1048 toX = mTmpRect.width() / 2 * (scaleW - 1f) + appRect.left;
1049 toY = appRect.height() / 2 * (1 - 1 / scaleW) + appRect.top;
1050 pivotX = mTmpRect.width() / 2;
1051 pivotY = appRect.height() / 2 / scaleW;
Manu Cornet57b61492017-01-24 18:19:05 +09001052 if (mGridLayoutRecentsEnabled) {
1053 // In the grid layout, the header is displayed above the thumbnail instead of
1054 // overlapping it.
1055 fromY -= thumbHeightI;
1056 toY -= thumbHeightI * scaleW;
1057 }
Jorim Jaggi09072002016-03-25 16:48:42 -07001058 } else {
1059 pivotX = 0;
1060 pivotY = 0;
1061 fromX = mTmpRect.left;
1062 fromY = mTmpRect.top;
1063 toX = appRect.left;
1064 toY = appRect.top;
1065 }
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001066 final long duration = getAspectScaleDuration();
1067 final Interpolator interpolator = getAspectScaleInterpolator();
Winson Chung399f6202014-03-19 10:47:20 -07001068 if (mNextAppTransitionScaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001069 // Animation up from the thumbnail to the full screen
Jorim Jaggi8448f332016-03-14 17:50:37 +01001070 Animation scale = new ScaleAnimation(1f, scaleW, 1f, scaleW, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001071 scale.setInterpolator(interpolator);
1072 scale.setDuration(duration);
Jorim Jaggic6c89a82016-01-28 17:48:21 -08001073 Animation alpha = new AlphaAnimation(1f, 0f);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001074 alpha.setInterpolator(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
1075 ? THUMBNAIL_DOCK_INTERPOLATOR : mThumbnailFadeOutInterpolator);
1076 alpha.setDuration(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
1077 ? duration / 2
1078 : duration);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001079 Animation translate = createCurvedMotion(fromX, toX, fromY, toY);
1080 translate.setInterpolator(interpolator);
1081 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -07001082
Jorim Jaggide63d442016-03-14 14:56:56 +01001083 mTmpFromClipRect.set(0, 0, thumbWidthI, thumbHeightI);
1084 mTmpToClipRect.set(appRect);
1085
1086 // Containing frame is in screen space, but we need the clip rect in the
1087 // app space.
1088 mTmpToClipRect.offsetTo(0, 0);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001089 mTmpToClipRect.right = (int) (mTmpToClipRect.right / scaleW);
1090 mTmpToClipRect.bottom = (int) (mTmpToClipRect.bottom / scaleW);
Jorim Jaggide63d442016-03-14 14:56:56 +01001091
1092 if (contentInsets != null) {
Jorim Jaggi8448f332016-03-14 17:50:37 +01001093 mTmpToClipRect.inset((int) (-contentInsets.left * scaleW),
1094 (int) (-contentInsets.top * scaleW),
1095 (int) (-contentInsets.right * scaleW),
1096 (int) (-contentInsets.bottom * scaleW));
Jorim Jaggide63d442016-03-14 14:56:56 +01001097 }
1098
1099 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001100 clipAnim.setInterpolator(interpolator);
1101 clipAnim.setDuration(duration);
Jorim Jaggide63d442016-03-14 14:56:56 +01001102
Winson Chung399f6202014-03-19 10:47:20 -07001103 // This AnimationSet uses the Interpolators assigned above.
1104 AnimationSet set = new AnimationSet(false);
1105 set.addAnimation(scale);
Manu Cornet57b61492017-01-24 18:19:05 +09001106 if (!mGridLayoutRecentsEnabled) {
1107 // In the grid layout, the header should be shown for the whole animation.
1108 set.addAnimation(alpha);
1109 }
Winson Chunga4ccb862014-08-22 15:26:27 -07001110 set.addAnimation(translate);
Jorim Jaggide63d442016-03-14 14:56:56 +01001111 set.addAnimation(clipAnim);
Winson Chung399f6202014-03-19 10:47:20 -07001112 a = set;
1113 } else {
Winson Chunga4ccb862014-08-22 15:26:27 -07001114 // Animation down from the full screen to the thumbnail
Jorim Jaggi8448f332016-03-14 17:50:37 +01001115 Animation scale = new ScaleAnimation(scaleW, 1f, scaleW, 1f, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001116 scale.setInterpolator(interpolator);
1117 scale.setDuration(duration);
Winson Chunga4ccb862014-08-22 15:26:27 -07001118 Animation alpha = new AlphaAnimation(0f, 1f);
1119 alpha.setInterpolator(mThumbnailFadeInInterpolator);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001120 alpha.setDuration(duration);
1121 Animation translate = createCurvedMotion(toX, fromX, toY, fromY);
1122 translate.setInterpolator(interpolator);
1123 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -07001124
Winson Chunga4ccb862014-08-22 15:26:27 -07001125 // This AnimationSet uses the Interpolators assigned above.
1126 AnimationSet set = new AnimationSet(false);
1127 set.addAnimation(scale);
Manu Cornet57b61492017-01-24 18:19:05 +09001128 if (!mGridLayoutRecentsEnabled) {
1129 // In the grid layout, the header should be shown for the whole animation.
1130 set.addAnimation(alpha);
1131 }
Winson Chunga4ccb862014-08-22 15:26:27 -07001132 set.addAnimation(translate);
1133 a = set;
1134
1135 }
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -07001136 return prepareThumbnailAnimationWithDuration(a, appWidth, appRect.height(), 0,
Jorim Jaggic69bd222016-03-15 14:38:37 +01001137 null);
Winson Chung399f6202014-03-19 10:47:20 -07001138 }
1139
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001140 private Animation createCurvedMotion(float fromX, float toX, float fromY, float toY) {
1141
1142 // Almost no x-change - use linear animation
Jorim Jaggic69bd222016-03-15 14:38:37 +01001143 if (Math.abs(toX - fromX) < 1f || mNextAppTransition != TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001144 return new TranslateAnimation(fromX, toX, fromY, toY);
1145 } else {
1146 final Path path = createCurvedPath(fromX, toX, fromY, toY);
1147 return new CurvedTranslateAnimation(path);
1148 }
1149 }
1150
1151 private Path createCurvedPath(float fromX, float toX, float fromY, float toY) {
1152 final Path path = new Path();
1153 path.moveTo(fromX, fromY);
Jorim Jaggi1f458fb2016-03-25 17:36:37 -07001154
1155 if (fromY > toY) {
1156 // If the object needs to go up, move it in horizontal direction first, then vertical.
1157 path.cubicTo(fromX, fromY, toX, 0.9f * fromY + 0.1f * toY, toX, toY);
1158 } else {
1159 // If the object needs to go down, move it in vertical direction first, then horizontal.
1160 path.cubicTo(fromX, fromY, fromX, 0.1f * fromY + 0.9f * toY, toX, toY);
1161 }
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001162 return path;
1163 }
1164
1165 private long getAspectScaleDuration() {
1166 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggic69bd222016-03-15 14:38:37 +01001167 return (long) (THUMBNAIL_APP_TRANSITION_DURATION * 1.35f);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001168 } else {
1169 return THUMBNAIL_APP_TRANSITION_DURATION;
1170 }
1171 }
1172
1173 private Interpolator getAspectScaleInterpolator() {
1174 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
1175 return mFastOutSlowInInterpolator;
1176 } else {
1177 return TOUCH_RESPONSE_INTERPOLATOR;
1178 }
1179 }
1180
Winson Chung399f6202014-03-19 10:47:20 -07001181 /**
1182 * This alternate animation is created when we are doing a thumbnail transition, for the
1183 * activity that is leaving, and the activity that is entering.
1184 */
Winson Chunga4ccb862014-08-22 15:26:27 -07001185 Animation createAspectScaledThumbnailEnterExitAnimationLocked(int thumbTransitState,
Winsonb2024762016-04-05 17:32:30 -07001186 int uiMode, int orientation, int transit, Rect containingFrame, Rect contentInsets,
Matthew Ng43db6d22017-06-27 15:29:39 -07001187 @Nullable Rect surfaceInsets, @Nullable Rect stableInsets, boolean freeform,
1188 int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -07001189 Animation a;
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001190 final int appWidth = containingFrame.width();
1191 final int appHeight = containingFrame.height();
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001192 getDefaultNextAppTransitionStartRect(mTmpRect);
1193 final int thumbWidthI = mTmpRect.width();
Winson Chung399f6202014-03-19 10:47:20 -07001194 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001195 final int thumbHeightI = mTmpRect.height();
Winson Chung399f6202014-03-19 10:47:20 -07001196 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
Winsoncbb625b2016-07-06 15:24:15 -07001197 final int thumbStartX = mTmpRect.left - containingFrame.left - contentInsets.left;
Winson21700932016-03-24 17:26:23 -07001198 final int thumbStartY = mTmpRect.top - containingFrame.top;
Winson Chung399f6202014-03-19 10:47:20 -07001199
1200 switch (thumbTransitState) {
Jorim Jaggi8448f332016-03-14 17:50:37 +01001201 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP:
1202 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1203 final boolean scaleUp = thumbTransitState == THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
1204 if (freeform && scaleUp) {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001205 a = createAspectScaledThumbnailEnterFreeformAnimationLocked(
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001206 containingFrame, surfaceInsets, taskId);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001207 } else if (freeform) {
1208 a = createAspectScaledThumbnailExitFreeformAnimationLocked(
1209 containingFrame, surfaceInsets, taskId);
Winson Chung2820c452014-04-15 15:34:44 -07001210 } else {
Winson21700932016-03-24 17:26:23 -07001211 AnimationSet set = new AnimationSet(true);
1212
1213 // In portrait, we scale to fit the width
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001214 mTmpFromClipRect.set(containingFrame);
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001215 mTmpToClipRect.set(containingFrame);
Jorim Jaggic6c89a82016-01-28 17:48:21 -08001216
1217 // Containing frame is in screen space, but we need the clip rect in the
1218 // app space.
1219 mTmpFromClipRect.offsetTo(0, 0);
1220 mTmpToClipRect.offsetTo(0, 0);
1221
1222 // Exclude insets region from the source clip.
1223 mTmpFromClipRect.inset(contentInsets);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001224 mNextAppTransitionInsets.set(contentInsets);
1225
Manu Cornetd7376802017-01-13 13:44:07 -08001226 if (shouldScaleDownThumbnailTransition(uiMode, orientation)) {
Jorim Jaggic69bd222016-03-15 14:38:37 +01001227 // We scale the width and clip to the top/left square
1228 float scale = thumbWidth /
1229 (appWidth - contentInsets.left - contentInsets.right);
Manu Cornetb68b7652017-01-23 19:37:53 +09001230 if (!mGridLayoutRecentsEnabled) {
1231 int unscaledThumbHeight = (int) (thumbHeight / scale);
1232 mTmpFromClipRect.bottom = mTmpFromClipRect.top + unscaledThumbHeight;
1233 }
Jorim Jaggic69bd222016-03-15 14:38:37 +01001234
1235 mNextAppTransitionInsets.set(contentInsets);
1236
Jorim Jaggi8448f332016-03-14 17:50:37 +01001237 Animation scaleAnim = new ScaleAnimation(
1238 scaleUp ? scale : 1, scaleUp ? 1 : scale,
1239 scaleUp ? scale : 1, scaleUp ? 1 : scale,
Jorim Jaggic69bd222016-03-15 14:38:37 +01001240 containingFrame.width() / 2f,
1241 containingFrame.height() / 2f + contentInsets.top);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001242 final float targetX = (mTmpRect.left - containingFrame.left);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001243 final float x = containingFrame.width() / 2f
1244 - containingFrame.width() / 2f * scale;
Jorim Jaggi8448f332016-03-14 17:50:37 +01001245 final float targetY = (mTmpRect.top - containingFrame.top);
Matthew Ng43db6d22017-06-27 15:29:39 -07001246 float y = containingFrame.height() / 2f
Jorim Jaggic69bd222016-03-15 14:38:37 +01001247 - containingFrame.height() / 2f * scale;
Matthew Ng43db6d22017-06-27 15:29:39 -07001248
1249 // During transition may require clipping offset from any top stable insets
1250 // such as the statusbar height when statusbar is hidden
1251 if (mLowRamRecentsEnabled && contentInsets.top == 0 && scaleUp) {
1252 mTmpFromClipRect.top += stableInsets.top;
1253 y += stableInsets.top;
1254 }
Jorim Jaggi8448f332016-03-14 17:50:37 +01001255 final float startX = targetX - x;
1256 final float startY = targetY - y;
1257 Animation clipAnim = scaleUp
1258 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1259 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1260 Animation translateAnim = scaleUp
Jorim Jaggic69bd222016-03-15 14:38:37 +01001261 ? createCurvedMotion(startX, 0, startY - contentInsets.top, 0)
1262 : createCurvedMotion(0, startX, 0, startY - contentInsets.top);
1263
Winson21700932016-03-24 17:26:23 -07001264 set.addAnimation(clipAnim);
1265 set.addAnimation(scaleAnim);
1266 set.addAnimation(translateAnim);
1267
1268 } else {
1269 // In landscape, we don't scale at all and only crop
1270 mTmpFromClipRect.bottom = mTmpFromClipRect.top + thumbHeightI;
1271 mTmpFromClipRect.right = mTmpFromClipRect.left + thumbWidthI;
1272
Jorim Jaggi8448f332016-03-14 17:50:37 +01001273 Animation clipAnim = scaleUp
1274 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1275 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1276 Animation translateAnim = scaleUp
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001277 ? createCurvedMotion(thumbStartX, 0,
1278 thumbStartY - contentInsets.top, 0)
1279 : createCurvedMotion(0, thumbStartX, 0,
1280 thumbStartY - contentInsets.top);
Winson21700932016-03-24 17:26:23 -07001281
1282 set.addAnimation(clipAnim);
1283 set.addAnimation(translateAnim);
1284 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001285 a = set;
Winson21700932016-03-24 17:26:23 -07001286 a.setZAdjustment(Animation.ZORDER_TOP);
Winson Chung2820c452014-04-15 15:34:44 -07001287 }
Winson Chung399f6202014-03-19 10:47:20 -07001288 break;
1289 }
1290 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001291 // Previous app window during the scale up
Winson Chung399f6202014-03-19 10:47:20 -07001292 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001293 // Fade out the source activity if we are animating to a wallpaper
Winson Chung399f6202014-03-19 10:47:20 -07001294 // activity.
1295 a = new AlphaAnimation(1, 0);
1296 } else {
Winson Chung399f6202014-03-19 10:47:20 -07001297 a = new AlphaAnimation(1, 1);
1298 }
1299 break;
1300 }
1301 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001302 // Target app window during the scale down
1303 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1304 // Fade in the destination activity if we are animating from a wallpaper
1305 // activity.
1306 a = new AlphaAnimation(0, 1);
1307 } else {
1308 a = new AlphaAnimation(1, 1);
1309 }
Winson Chung399f6202014-03-19 10:47:20 -07001310 break;
1311 }
Winson Chung399f6202014-03-19 10:47:20 -07001312 default:
1313 throw new RuntimeException("Invalid thumbnail transition state");
1314 }
1315
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001316 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight,
1317 getAspectScaleDuration(), getAspectScaleInterpolator());
Winson Chung399f6202014-03-19 10:47:20 -07001318 }
1319
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001320 private Animation createAspectScaledThumbnailEnterFreeformAnimationLocked(Rect frame,
1321 @Nullable Rect surfaceInsets, int taskId) {
1322 getNextAppTransitionStartRect(taskId, mTmpRect);
1323 return createAspectScaledThumbnailFreeformAnimationLocked(mTmpRect, frame, surfaceInsets,
1324 true);
1325 }
1326
1327 private Animation createAspectScaledThumbnailExitFreeformAnimationLocked(Rect frame,
1328 @Nullable Rect surfaceInsets, int taskId) {
1329 getNextAppTransitionStartRect(taskId, mTmpRect);
1330 return createAspectScaledThumbnailFreeformAnimationLocked(frame, mTmpRect, surfaceInsets,
1331 false);
1332 }
1333
1334 private AnimationSet createAspectScaledThumbnailFreeformAnimationLocked(Rect sourceFrame,
1335 Rect destFrame, @Nullable Rect surfaceInsets, boolean enter) {
1336 final float sourceWidth = sourceFrame.width();
1337 final float sourceHeight = sourceFrame.height();
1338 final float destWidth = destFrame.width();
1339 final float destHeight = destFrame.height();
1340 final float scaleH = enter ? sourceWidth / destWidth : destWidth / sourceWidth;
1341 final float scaleV = enter ? sourceHeight / destHeight : destHeight / sourceHeight;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001342 AnimationSet set = new AnimationSet(true);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001343 final int surfaceInsetsH = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001344 ? 0 : surfaceInsets.left + surfaceInsets.right;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001345 final int surfaceInsetsV = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001346 ? 0 : surfaceInsets.top + surfaceInsets.bottom;
1347 // We want the scaling to happen from the center of the surface. In order to achieve that,
1348 // we need to account for surface insets that will be used to enlarge the surface.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001349 final float scaleHCenter = ((enter ? destWidth : sourceWidth) + surfaceInsetsH) / 2;
1350 final float scaleVCenter = ((enter ? destHeight : sourceHeight) + surfaceInsetsV) / 2;
1351 final ScaleAnimation scale = enter ?
1352 new ScaleAnimation(scaleH, 1, scaleV, 1, scaleHCenter, scaleVCenter)
1353 : new ScaleAnimation(1, scaleH, 1, scaleV, scaleHCenter, scaleVCenter);
1354 final int sourceHCenter = sourceFrame.left + sourceFrame.width() / 2;
1355 final int sourceVCenter = sourceFrame.top + sourceFrame.height() / 2;
1356 final int destHCenter = destFrame.left + destFrame.width() / 2;
1357 final int destVCenter = destFrame.top + destFrame.height() / 2;
1358 final int fromX = enter ? sourceHCenter - destHCenter : destHCenter - sourceHCenter;
1359 final int fromY = enter ? sourceVCenter - destVCenter : destVCenter - sourceVCenter;
1360 final TranslateAnimation translation = enter ? new TranslateAnimation(fromX, 0, fromY, 0)
1361 : new TranslateAnimation(0, fromX, 0, fromY);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001362 set.addAnimation(scale);
1363 set.addAnimation(translation);
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001364
1365 final IRemoteCallback callback = mAnimationFinishedCallback;
1366 if (callback != null) {
1367 set.setAnimationListener(new Animation.AnimationListener() {
1368 @Override
1369 public void onAnimationStart(Animation animation) { }
1370
1371 @Override
1372 public void onAnimationEnd(Animation animation) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001373 mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK, callback).sendToTarget();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001374 }
1375
1376 @Override
1377 public void onAnimationRepeat(Animation animation) { }
1378 });
1379 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001380 return set;
1381 }
1382
Winson Chung399f6202014-03-19 10:47:20 -07001383 /**
Winson Chunga4ccb862014-08-22 15:26:27 -07001384 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001385 * when a thumbnail is specified with the pending animation override.
Winson Chunga4ccb862014-08-22 15:26:27 -07001386 */
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001387 Animation createThumbnailScaleAnimationLocked(int appWidth, int appHeight, int transit,
Winson Chungaa7fa012017-05-24 15:50:06 -07001388 GraphicBuffer thumbnailHeader) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001389 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001390 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001391 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chunga4ccb862014-08-22 15:26:27 -07001392 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001393 final int thumbHeightI = thumbnailHeader.getHeight();
Winson Chunga4ccb862014-08-22 15:26:27 -07001394 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1395
1396 if (mNextAppTransitionScaleUp) {
1397 // Animation for the thumbnail zooming from its initial size to the full screen
1398 float scaleW = appWidth / thumbWidth;
1399 float scaleH = appHeight / thumbHeight;
1400 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001401 computePivot(mTmpRect.left, 1 / scaleW),
1402 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001403 scale.setInterpolator(mDecelerateInterpolator);
1404
1405 Animation alpha = new AlphaAnimation(1, 0);
1406 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
1407
1408 // This AnimationSet uses the Interpolators assigned above.
1409 AnimationSet set = new AnimationSet(false);
1410 set.addAnimation(scale);
1411 set.addAnimation(alpha);
1412 a = set;
1413 } else {
1414 // Animation for the thumbnail zooming down from the full screen to its final size
1415 float scaleW = appWidth / thumbWidth;
1416 float scaleH = appHeight / thumbHeight;
1417 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001418 computePivot(mTmpRect.left, 1 / scaleW),
1419 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001420 }
1421
1422 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1423 }
1424
1425 /**
Winson Chung399f6202014-03-19 10:47:20 -07001426 * This animation is created when we are doing a thumbnail transition, for the activity that is
1427 * leaving, and the activity that is entering.
1428 */
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001429 Animation createThumbnailEnterExitAnimationLocked(int thumbTransitState, Rect containingFrame,
1430 int transit, int taskId) {
1431 final int appWidth = containingFrame.width();
1432 final int appHeight = containingFrame.height();
Winson Chungaa7fa012017-05-24 15:50:06 -07001433 final GraphicBuffer thumbnailHeader = getAppTransitionThumbnailHeader(taskId);
Winson Chung399f6202014-03-19 10:47:20 -07001434 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001435 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001436 final int thumbWidthI = thumbnailHeader != null ? thumbnailHeader.getWidth() : appWidth;
Winson Chung399f6202014-03-19 10:47:20 -07001437 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001438 final int thumbHeightI = thumbnailHeader != null ? thumbnailHeader.getHeight() : appHeight;
Winson Chung399f6202014-03-19 10:47:20 -07001439 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1440
1441 switch (thumbTransitState) {
1442 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
1443 // Entering app scales up with the thumbnail
1444 float scaleW = thumbWidth / appWidth;
1445 float scaleH = thumbHeight / appHeight;
1446 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001447 computePivot(mTmpRect.left, scaleW),
1448 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001449 break;
1450 }
1451 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
1452 // Exiting app while the thumbnail is scaling up should fade or stay in place
1453 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1454 // Fade out while bringing up selected activity. This keeps the
1455 // current activity from showing through a launching wallpaper
1456 // activity.
1457 a = new AlphaAnimation(1, 0);
1458 } else {
1459 // noop animation
1460 a = new AlphaAnimation(1, 1);
1461 }
1462 break;
1463 }
1464 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
1465 // Entering the other app, it should just be visible while we scale the thumbnail
1466 // down above it
1467 a = new AlphaAnimation(1, 1);
1468 break;
1469 }
1470 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1471 // Exiting the current app, the app should scale down with the thumbnail
1472 float scaleW = thumbWidth / appWidth;
1473 float scaleH = thumbHeight / appHeight;
1474 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001475 computePivot(mTmpRect.left, scaleW),
1476 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001477
1478 Animation alpha = new AlphaAnimation(1, 0);
1479
1480 AnimationSet set = new AnimationSet(true);
1481 set.addAnimation(scale);
1482 set.addAnimation(alpha);
1483 set.setZAdjustment(Animation.ZORDER_TOP);
1484 a = set;
1485 break;
1486 }
1487 default:
1488 throw new RuntimeException("Invalid thumbnail transition state");
1489 }
1490
1491 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1492 }
1493
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001494 private Animation createRelaunchAnimation(Rect containingFrame, Rect contentInsets) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001495 getDefaultNextAppTransitionStartRect(mTmpFromClipRect);
1496 final int left = mTmpFromClipRect.left;
1497 final int top = mTmpFromClipRect.top;
1498 mTmpFromClipRect.offset(-left, -top);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001499 // TODO: Isn't that strange that we ignore exact position of the containingFrame?
1500 mTmpToClipRect.set(0, 0, containingFrame.width(), containingFrame.height());
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001501 AnimationSet set = new AnimationSet(true);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001502 float fromWidth = mTmpFromClipRect.width();
1503 float toWidth = mTmpToClipRect.width();
1504 float fromHeight = mTmpFromClipRect.height();
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001505 // While the window might span the whole display, the actual content will be cropped to the
1506 // system decoration frame, for example when the window is docked. We need to take into
1507 // account the visible height when constructing the animation.
1508 float toHeight = mTmpToClipRect.height() - contentInsets.top - contentInsets.bottom;
1509 int translateAdjustment = 0;
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001510 if (fromWidth <= toWidth && fromHeight <= toHeight) {
1511 // The final window is larger in both dimensions than current window (e.g. we are
1512 // maximizing), so we can simply unclip the new window and there will be no disappearing
1513 // frame.
1514 set.addAnimation(new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect));
1515 } else {
1516 // The disappearing window has one larger dimension. We need to apply scaling, so the
1517 // first frame of the entry animation matches the old window.
1518 set.addAnimation(new ScaleAnimation(fromWidth / toWidth, 1, fromHeight / toHeight, 1));
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001519 // We might not be going exactly full screen, but instead be aligned under the status
1520 // bar using cropping. We still need to account for the cropped part, which will also
1521 // be scaled.
1522 translateAdjustment = (int) (contentInsets.top * fromHeight / toHeight);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001523 }
1524
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001525 // We animate the translation from the old position of the removed window, to the new
1526 // position of the added window. The latter might not be full screen, for example docked for
1527 // docked windows.
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001528 TranslateAnimation translate = new TranslateAnimation(left - containingFrame.left,
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001529 0, top - containingFrame.top - translateAdjustment, 0);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001530 set.addAnimation(translate);
1531 set.setDuration(DEFAULT_APP_TRANSITION_DURATION);
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07001532 set.setZAdjustment(Animation.ZORDER_TOP);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001533 return set;
1534 }
1535
Jorim Jaggic554b772015-06-04 16:07:57 -07001536 /**
1537 * @return true if and only if the first frame of the transition can be skipped, i.e. the first
1538 * frame of the transition doesn't change the visuals on screen, so we can start
1539 * directly with the second one
1540 */
1541 boolean canSkipFirstFrame() {
1542 return mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM
1543 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE
Jorim Jaggife762342016-10-13 14:33:27 +02001544 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CLIP_REVEAL
1545 && mNextAppTransition != TRANSIT_KEYGUARD_GOING_AWAY;
Jorim Jaggic554b772015-06-04 16:07:57 -07001546 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001547
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001548 RemoteAnimationController getRemoteAnimationController() {
1549 return mRemoteAnimationController;
1550 }
1551
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001552 /**
1553 *
1554 * @param frame These are the bounds of the window when it finishes the animation. This is where
1555 * the animation must usually finish in entrance animation, as the next frame will
1556 * display the window at these coordinates. In case of exit animation, this is
1557 * where the animation must start, as the frame before the animation is displaying
1558 * the window at these bounds.
1559 * @param insets Knowing where the window will be positioned is not enough. Some parts of the
1560 * window might be obscured, usually by the system windows (status bar and
1561 * navigation bar) and we use content insets to convey that information. This
1562 * usually affects the animation aspects vertically, as the system decoration is
1563 * at the top and the bottom. For example when we animate from full screen to
1564 * recents, we want to exclude the covered parts, because they won't match the
1565 * thumbnail after the last frame is executed.
1566 * @param surfaceInsets In rare situation the surface is larger than the content and we need to
1567 * know about this to make the animation frames match. We currently use
1568 * this for freeform windows, which have larger surfaces to display
1569 * shadows. When we animate them from recents, we want to match the content
1570 * to the recents thumbnail and hence need to account for the surface being
1571 * bigger.
1572 */
Jorim Jaggif84e2f62018-01-16 14:17:59 +01001573 Animation loadAnimation(LayoutParams lp, int transit, boolean enter, int uiMode,
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001574 int orientation, Rect frame, Rect displayFrame, Rect insets,
Matthew Ng43db6d22017-06-27 15:29:39 -07001575 @Nullable Rect surfaceInsets, @Nullable Rect stableInsets, boolean isVoiceInteraction,
1576 boolean freeform, int taskId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001577 Animation a;
Jorim Jaggife762342016-10-13 14:33:27 +02001578 if (isKeyguardGoingAwayTransit(transit) && enter) {
1579 a = loadKeyguardExitAnimation(transit);
1580 } else if (transit == TRANSIT_KEYGUARD_OCCLUDE) {
1581 a = null;
1582 } else if (transit == TRANSIT_KEYGUARD_UNOCCLUDE && !enter) {
1583 a = loadAnimationRes(lp, com.android.internal.R.anim.wallpaper_open_exit);
Adrian Roos93577212018-04-10 14:12:10 -07001584 } else if (transit == TRANSIT_CRASHING_ACTIVITY_CLOSE) {
1585 a = null;
Jorim Jaggife762342016-10-13 14:33:27 +02001586 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_OPEN
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001587 || transit == TRANSIT_TASK_OPEN
1588 || transit == TRANSIT_TASK_TO_FRONT)) {
1589 a = loadAnimationRes(lp, enter
1590 ? com.android.internal.R.anim.voice_activity_open_enter
1591 : com.android.internal.R.anim.voice_activity_open_exit);
1592 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1593 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001594 + " anim=" + a + " transit=" + appTransitionToString(transit)
1595 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001596 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_CLOSE
1597 || transit == TRANSIT_TASK_CLOSE
1598 || transit == TRANSIT_TASK_TO_BACK)) {
1599 a = loadAnimationRes(lp, enter
1600 ? com.android.internal.R.anim.voice_activity_close_enter
1601 : com.android.internal.R.anim.voice_activity_close_exit);
1602 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1603 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001604 + " anim=" + a + " transit=" + appTransitionToString(transit)
1605 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001606 } else if (transit == TRANSIT_ACTIVITY_RELAUNCH) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001607 a = createRelaunchAnimation(frame, insets);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001608 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1609 "applyAnimation:"
1610 + " anim=" + a + " nextAppTransition=" + mNextAppTransition
1611 + " transit=" + appTransitionToString(transit)
1612 + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001613 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM) {
1614 a = loadAnimationRes(mNextAppTransitionPackage, enter ?
Craig Mautner164d4bb2012-11-26 13:51:23 -08001615 mNextAppTransitionEnter : mNextAppTransitionExit);
1616 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1617 "applyAnimation:"
1618 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001619 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001620 + " Callers=" + Debug.getCallers(3));
Winson Chung044d5292014-11-06 11:05:19 -08001621 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE) {
1622 a = loadAnimationRes(mNextAppTransitionPackage, mNextAppTransitionInPlace);
1623 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1624 "applyAnimation:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001625 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM_IN_PLACE"
1626 + " transit=" + appTransitionToString(transit)
1627 + " Callers=" + Debug.getCallers(3));
Chet Haase10e23ab2015-02-11 15:08:38 -08001628 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001629 a = createClipRevealAnimationLocked(transit, enter, frame, displayFrame);
Chet Haase10e23ab2015-02-11 15:08:38 -08001630 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1631 "applyAnimation:"
1632 + " anim=" + a + " nextAppTransition=ANIM_CLIP_REVEAL"
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001633 + " transit=" + appTransitionToString(transit)
Chet Haase10e23ab2015-02-11 15:08:38 -08001634 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001635 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_SCALE_UP) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001636 a = createScaleUpAnimationLocked(transit, enter, frame);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001637 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1638 "applyAnimation:"
1639 + " anim=" + a + " nextAppTransition=ANIM_SCALE_UP"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001640 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001641 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001642 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
1643 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001644 mNextAppTransitionScaleUp =
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001645 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP);
Winson Chunga4ccb862014-08-22 15:26:27 -07001646 a = createThumbnailEnterExitAnimationLocked(getThumbnailTransitionState(enter),
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001647 frame, transit, taskId);
Winson Chunga4ccb862014-08-22 15:26:27 -07001648 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1649 String animName = mNextAppTransitionScaleUp ?
1650 "ANIM_THUMBNAIL_SCALE_UP" : "ANIM_THUMBNAIL_SCALE_DOWN";
1651 Slog.v(TAG, "applyAnimation:"
1652 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001653 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Winson Chunga4ccb862014-08-22 15:26:27 -07001654 + " Callers=" + Debug.getCallers(3));
1655 }
1656 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
1657 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN) {
1658 mNextAppTransitionScaleUp =
1659 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP);
1660 a = createAspectScaledThumbnailEnterExitAnimationLocked(
Winsonb2024762016-04-05 17:32:30 -07001661 getThumbnailTransitionState(enter), uiMode, orientation, transit, frame,
Matthew Ng43db6d22017-06-27 15:29:39 -07001662 insets, surfaceInsets, stableInsets, freeform, taskId);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001663 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1664 String animName = mNextAppTransitionScaleUp ?
Winson Chunga4ccb862014-08-22 15:26:27 -07001665 "ANIM_THUMBNAIL_ASPECT_SCALE_UP" : "ANIM_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner164d4bb2012-11-26 13:51:23 -08001666 Slog.v(TAG, "applyAnimation:"
1667 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001668 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001669 + " Callers=" + Debug.getCallers(3));
1670 }
Tony Mak83546a82018-01-22 13:56:20 +00001671 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS && enter) {
Jorim Jaggi98a9d202018-03-26 16:17:07 +02001672 a = loadAnimationRes("android",
1673 com.android.internal.R.anim.task_open_enter_cross_profile_apps);
Tony Mak089c35e2017-12-18 20:34:14 +00001674 Slog.v(TAG,
1675 "applyAnimation NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS:"
1676 + " anim=" + a + " transit=" + appTransitionToString(transit)
Jorim Jaggi98a9d202018-03-26 16:17:07 +02001677 + " isEntrance=true" + " Callers=" + Debug.getCallers(3));
Craig Mautner164d4bb2012-11-26 13:51:23 -08001678 } else {
1679 int animAttr = 0;
1680 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001681 case TRANSIT_ACTIVITY_OPEN:
Jorim Jaggi0a1523d2018-04-19 17:48:38 +02001682 case TRANSIT_TRANSLUCENT_ACTIVITY_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001683 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001684 ? WindowAnimation_activityOpenEnterAnimation
1685 : WindowAnimation_activityOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001686 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001687 case TRANSIT_ACTIVITY_CLOSE:
Jorim Jaggi0a1523d2018-04-19 17:48:38 +02001688 case TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001689 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001690 ? WindowAnimation_activityCloseEnterAnimation
1691 : WindowAnimation_activityCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001692 break;
Jorim Jaggi192086e2016-03-11 17:17:03 +01001693 case TRANSIT_DOCK_TASK_FROM_RECENTS:
Craig Mautner4b71aa12012-12-27 17:20:01 -08001694 case TRANSIT_TASK_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001695 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001696 ? WindowAnimation_taskOpenEnterAnimation
1697 : WindowAnimation_taskOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001698 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001699 case TRANSIT_TASK_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001700 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001701 ? WindowAnimation_taskCloseEnterAnimation
1702 : WindowAnimation_taskCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001703 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001704 case TRANSIT_TASK_TO_FRONT:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001705 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001706 ? WindowAnimation_taskToFrontEnterAnimation
1707 : WindowAnimation_taskToFrontExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001708 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001709 case TRANSIT_TASK_TO_BACK:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001710 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001711 ? WindowAnimation_taskToBackEnterAnimation
1712 : WindowAnimation_taskToBackExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001713 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001714 case TRANSIT_WALLPAPER_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001715 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001716 ? WindowAnimation_wallpaperOpenEnterAnimation
1717 : WindowAnimation_wallpaperOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001718 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001719 case TRANSIT_WALLPAPER_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001720 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001721 ? WindowAnimation_wallpaperCloseEnterAnimation
1722 : WindowAnimation_wallpaperCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001723 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001724 case TRANSIT_WALLPAPER_INTRA_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001725 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001726 ? WindowAnimation_wallpaperIntraOpenEnterAnimation
1727 : WindowAnimation_wallpaperIntraOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001728 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001729 case TRANSIT_WALLPAPER_INTRA_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001730 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001731 ? WindowAnimation_wallpaperIntraCloseEnterAnimation
1732 : WindowAnimation_wallpaperIntraCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001733 break;
Craig Mautnerbb742462014-07-07 15:28:55 -07001734 case TRANSIT_TASK_OPEN_BEHIND:
1735 animAttr = enter
1736 ? WindowAnimation_launchTaskBehindSourceAnimation
Craig Mautner3b2cd1d2014-08-25 14:25:54 -07001737 : WindowAnimation_launchTaskBehindTargetAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001738 }
Jorim Jaggi0a1523d2018-04-19 17:48:38 +02001739 a = animAttr != 0 ? loadAnimationAttr(lp, animAttr, transit) : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001740 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1741 "applyAnimation:"
1742 + " anim=" + a
1743 + " animAttr=0x" + Integer.toHexString(animAttr)
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001744 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001745 + " Callers=" + Debug.getCallers(3));
1746 }
1747 return a;
1748 }
1749
Jorim Jaggife762342016-10-13 14:33:27 +02001750 private Animation loadKeyguardExitAnimation(int transit) {
1751 if ((mNextAppTransitionFlags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_NO_ANIMATION) != 0) {
1752 return null;
1753 }
1754 final boolean toShade =
1755 (mNextAppTransitionFlags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_TO_SHADE) != 0;
1756 return mService.mPolicy.createHiddenByKeyguardExit(
1757 transit == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER, toShade);
1758 }
1759
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001760 int getAppStackClipMode() {
Matthew Ngbf1d9852017-03-14 12:23:09 -07001761 // When dismiss keyguard animation occurs, clip before the animation to prevent docked
1762 // app from showing beyond the divider
1763 if (mNextAppTransition == TRANSIT_KEYGUARD_GOING_AWAY
1764 || mNextAppTransition == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER) {
1765 return STACK_CLIP_BEFORE_ANIM;
1766 }
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001767 return mNextAppTransition == TRANSIT_ACTIVITY_RELAUNCH
Jorim Jaggic69bd222016-03-15 14:38:37 +01001768 || mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
Jorim Jaggi1f458fb2016-03-25 17:36:37 -07001769 || mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001770 ? STACK_CLIP_NONE
1771 : STACK_CLIP_AFTER_ANIM;
1772 }
1773
Jorim Jaggife762342016-10-13 14:33:27 +02001774 public int getTransitFlags() {
1775 return mNextAppTransitionFlags;
1776 }
1777
Craig Mautner164d4bb2012-11-26 13:51:23 -08001778 void postAnimationCallback() {
1779 if (mNextAppTransitionCallback != null) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001780 mService.mH.sendMessage(mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK,
1781 mNextAppTransitionCallback));
Craig Mautner164d4bb2012-11-26 13:51:23 -08001782 mNextAppTransitionCallback = null;
1783 }
1784 }
1785
1786 void overridePendingAppTransition(String packageName, int enterAnim, int exitAnim,
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001787 IRemoteCallback startedCallback) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001788 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001789 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001790 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001791 mNextAppTransitionPackage = packageName;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001792 mNextAppTransitionEnter = enterAnim;
1793 mNextAppTransitionExit = exitAnim;
1794 postAnimationCallback();
1795 mNextAppTransitionCallback = startedCallback;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001796 }
1797 }
1798
1799 void overridePendingAppTransitionScaleUp(int startX, int startY, int startWidth,
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001800 int startHeight) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001801 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001802 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001803 mNextAppTransitionType = NEXT_TRANSIT_TYPE_SCALE_UP;
Winson4c3fecd2016-07-13 12:29:48 -07001804 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001805 postAnimationCallback();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001806 }
1807 }
1808
Chet Haase10e23ab2015-02-11 15:08:38 -08001809 void overridePendingAppTransitionClipReveal(int startX, int startY,
1810 int startWidth, int startHeight) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001811 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001812 clear();
Chet Haase10e23ab2015-02-11 15:08:38 -08001813 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CLIP_REVEAL;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001814 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Chet Haase10e23ab2015-02-11 15:08:38 -08001815 postAnimationCallback();
Chet Haase10e23ab2015-02-11 15:08:38 -08001816 }
1817 }
1818
Winson Chungaa7fa012017-05-24 15:50:06 -07001819 void overridePendingAppTransitionThumb(GraphicBuffer srcThumb, int startX, int startY,
Craig Mautner164d4bb2012-11-26 13:51:23 -08001820 IRemoteCallback startedCallback, boolean scaleUp) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001821 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001822 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001823 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP
1824 : NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001825 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001826 putDefaultNextAppTransitionCoordinates(startX, startY, 0, 0, srcThumb);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001827 postAnimationCallback();
1828 mNextAppTransitionCallback = startedCallback;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001829 }
1830 }
1831
Winson Chungaa7fa012017-05-24 15:50:06 -07001832 void overridePendingAppTransitionAspectScaledThumb(GraphicBuffer srcThumb, int startX, int startY,
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001833 int targetWidth, int targetHeight, IRemoteCallback startedCallback, boolean scaleUp) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001834 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001835 clear();
Winson Chunga4ccb862014-08-22 15:26:27 -07001836 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1837 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Winson Chunga4ccb862014-08-22 15:26:27 -07001838 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001839 putDefaultNextAppTransitionCoordinates(startX, startY, targetWidth, targetHeight,
1840 srcThumb);
Winson Chunga4ccb862014-08-22 15:26:27 -07001841 postAnimationCallback();
1842 mNextAppTransitionCallback = startedCallback;
Winson Chunga4ccb862014-08-22 15:26:27 -07001843 }
1844 }
1845
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001846 void overridePendingAppTransitionMultiThumb(AppTransitionAnimationSpec[] specs,
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001847 IRemoteCallback onAnimationStartedCallback, IRemoteCallback onAnimationFinishedCallback,
1848 boolean scaleUp) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001849 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001850 clear();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001851 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1852 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001853 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi43102412015-11-11 16:28:37 +01001854 if (specs != null) {
1855 for (int i = 0; i < specs.length; i++) {
1856 AppTransitionAnimationSpec spec = specs[i];
1857 if (spec != null) {
1858 mNextAppTransitionAnimationsSpecs.put(spec.taskId, spec);
1859 if (i == 0) {
1860 // In full screen mode, the transition code depends on the default spec
1861 // to be set.
1862 Rect rect = spec.rect;
1863 putDefaultNextAppTransitionCoordinates(rect.left, rect.top,
Winson Chungaa7fa012017-05-24 15:50:06 -07001864 rect.width(), rect.height(), spec.buffer);
Jorim Jaggi43102412015-11-11 16:28:37 +01001865 }
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001866 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001867 }
1868 }
1869 postAnimationCallback();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001870 mNextAppTransitionCallback = onAnimationStartedCallback;
1871 mAnimationFinishedCallback = onAnimationFinishedCallback;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001872 }
1873 }
1874
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001875 void overridePendingAppTransitionMultiThumbFuture(
1876 IAppTransitionAnimationSpecsFuture specsFuture, IRemoteCallback callback,
1877 boolean scaleUp) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001878 if (canOverridePendingAppTransition()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001879 clear();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001880 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1881 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001882 mNextAppTransitionAnimationsSpecsFuture = specsFuture;
1883 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001884 mNextAppTransitionFutureCallback = callback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001885 }
1886 }
1887
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001888 void overridePendingAppTransitionRemote(RemoteAnimationAdapter remoteAnimationAdapter) {
Winson Chung044d5292014-11-06 11:05:19 -08001889 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001890 clear();
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001891 mNextAppTransitionType = NEXT_TRANSIT_TYPE_REMOTE;
1892 mRemoteAnimationController = new RemoteAnimationController(mService,
1893 remoteAnimationAdapter, mService.mH);
1894 }
1895 }
1896
1897 void overrideInPlaceAppTransition(String packageName, int anim) {
1898 if (canOverridePendingAppTransition()) {
1899 clear();
Winson Chung044d5292014-11-06 11:05:19 -08001900 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE;
1901 mNextAppTransitionPackage = packageName;
1902 mNextAppTransitionInPlace = anim;
Winson Chung044d5292014-11-06 11:05:19 -08001903 }
1904 }
1905
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001906 /**
Tony Mak089c35e2017-12-18 20:34:14 +00001907 * @see {@link #NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS}
1908 */
1909 void overridePendingAppTransitionStartCrossProfileApps() {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001910 if (canOverridePendingAppTransition()) {
Tony Mak089c35e2017-12-18 20:34:14 +00001911 clear();
1912 mNextAppTransitionType = NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS;
1913 postAnimationCallback();
1914 }
1915 }
1916
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001917 private boolean canOverridePendingAppTransition() {
1918 // Remote animations always take precedence
1919 return isTransitionSet() && mNextAppTransitionType != NEXT_TRANSIT_TYPE_REMOTE;
1920 }
1921
Tony Mak089c35e2017-12-18 20:34:14 +00001922 /**
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001923 * If a future is set for the app transition specs, fetch it in another thread.
1924 */
1925 private void fetchAppTransitionSpecsFromFuture() {
1926 if (mNextAppTransitionAnimationsSpecsFuture != null) {
1927 mNextAppTransitionAnimationsSpecsPending = true;
1928 final IAppTransitionAnimationSpecsFuture future
1929 = mNextAppTransitionAnimationsSpecsFuture;
1930 mNextAppTransitionAnimationsSpecsFuture = null;
Jorim Jaggied410b62017-05-05 15:16:14 +02001931 mDefaultExecutor.execute(() -> {
1932 AppTransitionAnimationSpec[] specs = null;
1933 try {
1934 Binder.allowBlocking(future.asBinder());
1935 specs = future.get();
1936 } catch (RemoteException e) {
1937 Slog.w(TAG, "Failed to fetch app transition specs: " + e);
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001938 }
Jorim Jaggied410b62017-05-05 15:16:14 +02001939 synchronized (mService.mWindowMap) {
1940 mNextAppTransitionAnimationsSpecsPending = false;
1941 overridePendingAppTransitionMultiThumb(specs,
1942 mNextAppTransitionFutureCallback, null /* finishedCallback */,
1943 mNextAppTransitionScaleUp);
1944 mNextAppTransitionFutureCallback = null;
Jorim Jaggied410b62017-05-05 15:16:14 +02001945 }
1946 mService.requestTraversal();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001947 });
1948 }
1949 }
1950
Craig Mautner164d4bb2012-11-26 13:51:23 -08001951 @Override
1952 public String toString() {
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001953 return "mNextAppTransition=" + appTransitionToString(mNextAppTransition);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001954 }
1955
Craig Mautner4b71aa12012-12-27 17:20:01 -08001956 /**
1957 * Returns the human readable name of a window transition.
1958 *
1959 * @param transition The window transition.
1960 * @return The transition symbolic name.
1961 */
1962 public static String appTransitionToString(int transition) {
1963 switch (transition) {
1964 case TRANSIT_UNSET: {
1965 return "TRANSIT_UNSET";
1966 }
1967 case TRANSIT_NONE: {
1968 return "TRANSIT_NONE";
1969 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001970 case TRANSIT_ACTIVITY_OPEN: {
1971 return "TRANSIT_ACTIVITY_OPEN";
1972 }
1973 case TRANSIT_ACTIVITY_CLOSE: {
1974 return "TRANSIT_ACTIVITY_CLOSE";
1975 }
1976 case TRANSIT_TASK_OPEN: {
1977 return "TRANSIT_TASK_OPEN";
1978 }
1979 case TRANSIT_TASK_CLOSE: {
1980 return "TRANSIT_TASK_CLOSE";
1981 }
1982 case TRANSIT_TASK_TO_FRONT: {
1983 return "TRANSIT_TASK_TO_FRONT";
1984 }
1985 case TRANSIT_TASK_TO_BACK: {
1986 return "TRANSIT_TASK_TO_BACK";
1987 }
1988 case TRANSIT_WALLPAPER_CLOSE: {
1989 return "TRANSIT_WALLPAPER_CLOSE";
1990 }
1991 case TRANSIT_WALLPAPER_OPEN: {
1992 return "TRANSIT_WALLPAPER_OPEN";
1993 }
1994 case TRANSIT_WALLPAPER_INTRA_OPEN: {
1995 return "TRANSIT_WALLPAPER_INTRA_OPEN";
1996 }
1997 case TRANSIT_WALLPAPER_INTRA_CLOSE: {
1998 return "TRANSIT_WALLPAPER_INTRA_CLOSE";
1999 }
Craig Mautnerbb742462014-07-07 15:28:55 -07002000 case TRANSIT_TASK_OPEN_BEHIND: {
2001 return "TRANSIT_TASK_OPEN_BEHIND";
2002 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07002003 case TRANSIT_ACTIVITY_RELAUNCH: {
2004 return "TRANSIT_ACTIVITY_RELAUNCH";
2005 }
Jorim Jaggi192086e2016-03-11 17:17:03 +01002006 case TRANSIT_DOCK_TASK_FROM_RECENTS: {
2007 return "TRANSIT_DOCK_TASK_FROM_RECENTS";
2008 }
Jorim Jaggife762342016-10-13 14:33:27 +02002009 case TRANSIT_KEYGUARD_GOING_AWAY: {
2010 return "TRANSIT_KEYGUARD_GOING_AWAY";
2011 }
2012 case TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER: {
2013 return "TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER";
2014 }
2015 case TRANSIT_KEYGUARD_OCCLUDE: {
2016 return "TRANSIT_KEYGUARD_OCCLUDE";
2017 }
2018 case TRANSIT_KEYGUARD_UNOCCLUDE: {
2019 return "TRANSIT_KEYGUARD_UNOCCLUDE";
2020 }
Jorim Jaggi98a9d202018-03-26 16:17:07 +02002021 case TRANSIT_TRANSLUCENT_ACTIVITY_OPEN: {
2022 return "TRANSIT_TRANSLUCENT_ACTIVITY_OPEN";
2023 }
2024 case TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE: {
2025 return "TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE";
2026 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002027 default: {
2028 return "<UNKNOWN>";
2029 }
2030 }
2031 }
2032
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002033 private String appStateToString() {
2034 switch (mAppTransitionState) {
2035 case APP_STATE_IDLE:
2036 return "APP_STATE_IDLE";
2037 case APP_STATE_READY:
2038 return "APP_STATE_READY";
2039 case APP_STATE_RUNNING:
2040 return "APP_STATE_RUNNING";
2041 case APP_STATE_TIMEOUT:
2042 return "APP_STATE_TIMEOUT";
2043 default:
2044 return "unknown state=" + mAppTransitionState;
2045 }
2046 }
2047
2048 private String transitTypeToString() {
2049 switch (mNextAppTransitionType) {
2050 case NEXT_TRANSIT_TYPE_NONE:
2051 return "NEXT_TRANSIT_TYPE_NONE";
2052 case NEXT_TRANSIT_TYPE_CUSTOM:
2053 return "NEXT_TRANSIT_TYPE_CUSTOM";
Winson Chung044d5292014-11-06 11:05:19 -08002054 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
2055 return "NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002056 case NEXT_TRANSIT_TYPE_SCALE_UP:
2057 return "NEXT_TRANSIT_TYPE_SCALE_UP";
2058 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
2059 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP";
2060 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
2061 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN";
Winson Chunga4ccb862014-08-22 15:26:27 -07002062 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
2063 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP";
2064 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN:
2065 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN";
Tony Mak64b8d562017-12-28 17:44:02 +00002066 case NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS:
2067 return "NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002068 default:
2069 return "unknown type=" + mNextAppTransitionType;
2070 }
2071 }
2072
Steven Timotiusaf03df62017-07-18 16:56:43 -07002073 void writeToProto(ProtoOutputStream proto, long fieldId) {
2074 final long token = proto.start(fieldId);
2075 proto.write(APP_TRANSITION_STATE, mAppTransitionState);
2076 proto.write(LAST_USED_APP_TRANSITION, mLastUsedAppTransition);
2077 proto.end(token);
2078 }
2079
Craig Mautner164d4bb2012-11-26 13:51:23 -08002080 @Override
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002081 public void dump(PrintWriter pw, String prefix) {
2082 pw.print(prefix); pw.println(this);
2083 pw.print(prefix); pw.print("mAppTransitionState="); pw.println(appStateToString());
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002084 if (mNextAppTransitionType != NEXT_TRANSIT_TYPE_NONE) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002085 pw.print(prefix); pw.print("mNextAppTransitionType=");
2086 pw.println(transitTypeToString());
Craig Mautner164d4bb2012-11-26 13:51:23 -08002087 }
2088 switch (mNextAppTransitionType) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002089 case NEXT_TRANSIT_TYPE_CUSTOM:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002090 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Craig Mautner164d4bb2012-11-26 13:51:23 -08002091 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002092 pw.print(prefix); pw.print("mNextAppTransitionEnter=0x");
Craig Mautner164d4bb2012-11-26 13:51:23 -08002093 pw.print(Integer.toHexString(mNextAppTransitionEnter));
2094 pw.print(" mNextAppTransitionExit=0x");
2095 pw.println(Integer.toHexString(mNextAppTransitionExit));
2096 break;
Winson Chung044d5292014-11-06 11:05:19 -08002097 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002098 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Winson Chung044d5292014-11-06 11:05:19 -08002099 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002100 pw.print(prefix); pw.print("mNextAppTransitionInPlace=0x");
Winson Chung044d5292014-11-06 11:05:19 -08002101 pw.print(Integer.toHexString(mNextAppTransitionInPlace));
2102 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002103 case NEXT_TRANSIT_TYPE_SCALE_UP: {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002104 getDefaultNextAppTransitionStartRect(mTmpRect);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002105 pw.print(prefix); pw.print("mNextAppTransitionStartX=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002106 pw.print(mTmpRect.left);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002107 pw.print(" mNextAppTransitionStartY=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002108 pw.println(mTmpRect.top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002109 pw.print(prefix); pw.print("mNextAppTransitionStartWidth=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002110 pw.print(mTmpRect.width());
Craig Mautner164d4bb2012-11-26 13:51:23 -08002111 pw.print(" mNextAppTransitionStartHeight=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002112 pw.println(mTmpRect.height());
Craig Mautner164d4bb2012-11-26 13:51:23 -08002113 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002114 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002115 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
2116 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
Winson Chunga4ccb862014-08-22 15:26:27 -07002117 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002118 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN: {
2119 pw.print(prefix); pw.print("mDefaultNextAppTransitionAnimationSpec=");
2120 pw.println(mDefaultNextAppTransitionAnimationSpec);
2121 pw.print(prefix); pw.print("mNextAppTransitionAnimationsSpecs=");
2122 pw.println(mNextAppTransitionAnimationsSpecs);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002123 pw.print(prefix); pw.print("mNextAppTransitionScaleUp=");
2124 pw.println(mNextAppTransitionScaleUp);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002125 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002126 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002127 }
2128 if (mNextAppTransitionCallback != null) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002129 pw.print(prefix); pw.print("mNextAppTransitionCallback=");
2130 pw.println(mNextAppTransitionCallback);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002131 }
Chong Zhang60091a92016-07-27 17:52:45 -07002132 if (mLastUsedAppTransition != TRANSIT_NONE) {
2133 pw.print(prefix); pw.print("mLastUsedAppTransition=");
2134 pw.println(appTransitionToString(mLastUsedAppTransition));
2135 pw.print(prefix); pw.print("mLastOpeningApp=");
2136 pw.println(mLastOpeningApp);
2137 pw.print(prefix); pw.print("mLastClosingApp=");
2138 pw.println(mLastClosingApp);
2139 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002140 }
Amith Yamasani4befbec2013-07-10 16:18:01 -07002141
2142 public void setCurrentUser(int newUserId) {
2143 mCurrentUserId = newUserId;
2144 }
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002145
2146 /**
2147 * @return true if transition is not running and should not be skipped, false if transition is
2148 * already running
2149 */
Jorim Jaggif84e2f62018-01-16 14:17:59 +01002150 boolean prepareAppTransitionLocked(@TransitionType int transit, boolean alwaysKeepCurrent,
2151 @TransitionFlags int flags, boolean forceOverride) {
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002152 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Prepare app transition:"
2153 + " transit=" + appTransitionToString(transit)
2154 + " " + this
2155 + " alwaysKeepCurrent=" + alwaysKeepCurrent
2156 + " Callers=" + Debug.getCallers(3));
Jorim Jaggife762342016-10-13 14:33:27 +02002157 if (forceOverride || isKeyguardTransit(transit) || !isTransitionSet()
2158 || mNextAppTransition == TRANSIT_NONE) {
2159 setAppTransition(transit, flags);
Jorim Jaggia69243a2017-06-15 15:10:38 -04002160 }
2161 // We never want to change from a Keyguard transit to a non-Keyguard transit, as our logic
Adrian Roos93577212018-04-10 14:12:10 -07002162 // relies on the fact that we always execute a Keyguard transition after preparing one. We
2163 // also don't want to change away from a crashing transition.
2164 else if (!alwaysKeepCurrent && !isKeyguardTransit(transit)
2165 && transit != TRANSIT_CRASHING_ACTIVITY_CLOSE) {
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002166 if (transit == TRANSIT_TASK_OPEN && isTransitionEqual(TRANSIT_TASK_CLOSE)) {
2167 // Opening a new task always supersedes a close for the anim.
Jorim Jaggife762342016-10-13 14:33:27 +02002168 setAppTransition(transit, flags);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002169 } else if (transit == TRANSIT_ACTIVITY_OPEN
2170 && isTransitionEqual(TRANSIT_ACTIVITY_CLOSE)) {
2171 // Opening a new activity always supersedes a close for the anim.
Jorim Jaggife762342016-10-13 14:33:27 +02002172 setAppTransition(transit, flags);
Jorim Jaggicecf4242018-02-21 18:46:53 +01002173 } else if (isTaskTransit(transit) && isActivityTransit(mNextAppTransition)) {
2174 // Task animations always supersede activity animations, because if we have both, it
2175 // usually means that activity transition were just trampoline activities.
2176 setAppTransition(transit, flags);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002177 }
2178 }
2179 boolean prepared = prepare();
2180 if (isTransitionSet()) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08002181 mService.mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
2182 mService.mH.sendEmptyMessageDelayed(H.APP_TRANSITION_TIMEOUT, APP_TRANSITION_TIMEOUT_MS);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002183 }
2184 return prepared;
2185 }
Winsonb2024762016-04-05 17:32:30 -07002186
2187 /**
Jorim Jaggife762342016-10-13 14:33:27 +02002188 * @return true if {@param transit} is representing a transition in which Keyguard is going
2189 * away, false otherwise
2190 */
2191 public static boolean isKeyguardGoingAwayTransit(int transit) {
2192 return transit == TRANSIT_KEYGUARD_GOING_AWAY
2193 || transit == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER;
2194 }
2195
2196 private static boolean isKeyguardTransit(int transit) {
2197 return isKeyguardGoingAwayTransit(transit) || transit == TRANSIT_KEYGUARD_OCCLUDE
2198 || transit == TRANSIT_KEYGUARD_UNOCCLUDE;
2199 }
2200
Jorim Jaggi98a9d202018-03-26 16:17:07 +02002201 static boolean isTaskTransit(int transit) {
2202 return isTaskOpenTransit(transit)
Jorim Jaggicecf4242018-02-21 18:46:53 +01002203 || transit == TRANSIT_TASK_CLOSE
Jorim Jaggicecf4242018-02-21 18:46:53 +01002204 || transit == TRANSIT_TASK_TO_BACK
Jorim Jaggicecf4242018-02-21 18:46:53 +01002205 || transit == TRANSIT_TASK_IN_PLACE;
2206 }
2207
Jorim Jaggi98a9d202018-03-26 16:17:07 +02002208 private static boolean isTaskOpenTransit(int transit) {
2209 return transit == TRANSIT_TASK_OPEN
2210 || transit == TRANSIT_TASK_OPEN_BEHIND
2211 || transit == TRANSIT_TASK_TO_FRONT;
2212 }
2213
2214 static boolean isActivityTransit(int transit) {
Jorim Jaggicecf4242018-02-21 18:46:53 +01002215 return transit == TRANSIT_ACTIVITY_OPEN
2216 || transit == TRANSIT_ACTIVITY_CLOSE
2217 || transit == TRANSIT_ACTIVITY_RELAUNCH;
2218 }
2219
Jorim Jaggife762342016-10-13 14:33:27 +02002220 /**
Manu Cornetd7376802017-01-13 13:44:07 -08002221 * @return whether the transition should show the thumbnail being scaled down.
2222 */
2223 private boolean shouldScaleDownThumbnailTransition(int uiMode, int orientation) {
Sid Soundararajan0e88d322017-03-07 15:37:30 -08002224 return mGridLayoutRecentsEnabled
Manu Cornetd7376802017-01-13 13:44:07 -08002225 || orientation == Configuration.ORIENTATION_PORTRAIT;
2226 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002227}