blob: 2ac758344f52ecfde65c871d9c69663edb2a512b [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
Filip Gruszczynski82861362015-10-16 14:21:09 -070019import static com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation;
20import static com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
21import static com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation;
22import static com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
23import static com.android.internal.R.styleable.WindowAnimation_launchTaskBehindSourceAnimation;
24import static com.android.internal.R.styleable.WindowAnimation_launchTaskBehindTargetAnimation;
25import static com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation;
26import static com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
27import static com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation;
28import static com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
29import static com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation;
30import static com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
31import static com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation;
32import static com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
33import static com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation;
34import static com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
35import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation;
36import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
37import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation;
38import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
39import static com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation;
40import static com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Filip Gruszczynski198dcbf2016-01-18 10:02:00 -080041import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
42import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080043import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
44import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Adrian Roose99bc052017-11-20 17:55:31 +010045import static com.android.server.wm.WindowManagerInternal.AppTransitionListener;
Tony Mak089c35e2017-12-18 20:34:14 +000046import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_AFTER_ANIM;
Matthew Ngbf1d9852017-03-14 12:23:09 -070047import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_BEFORE_ANIM;
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +010048import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_NONE;
Steven Timotiusaf03df62017-07-18 16:56:43 -070049import static com.android.server.wm.proto.AppTransitionProto.APP_TRANSITION_STATE;
50import static com.android.server.wm.proto.AppTransitionProto.LAST_USED_APP_TRANSITION;
Filip Gruszczynski82861362015-10-16 14:21:09 -070051
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -070052import android.annotation.Nullable;
Matthew Ng43db6d22017-06-27 15:29:39 -070053import android.app.ActivityManager;
Tony Mak089c35e2017-12-18 20:34:14 +000054import android.content.ComponentName;
Craig Mautner164d4bb2012-11-26 13:51:23 -080055import android.content.Context;
Winson21700932016-03-24 17:26:23 -070056import android.content.res.Configuration;
Winson Chungaa7fa012017-05-24 15:50:06 -070057import android.graphics.GraphicBuffer;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +010058import android.graphics.Path;
Winson Chung399f6202014-03-19 10:47:20 -070059import android.graphics.Rect;
Jorim Jaggied410b62017-05-05 15:16:14 +020060import android.os.Binder;
Craig Mautner164d4bb2012-11-26 13:51:23 -080061import android.os.Debug;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010062import android.os.IBinder;
Craig Mautner164d4bb2012-11-26 13:51:23 -080063import android.os.IRemoteCallback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010064import android.os.RemoteException;
Jorim Jaggif5f9e122017-10-24 18:21:09 +020065import android.os.SystemClock;
Manu Cornetd7376802017-01-13 13:44:07 -080066import android.os.SystemProperties;
Tony Mak089c35e2017-12-18 20:34:14 +000067import android.os.UserHandle;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -080068import android.util.ArraySet;
Craig Mautner164d4bb2012-11-26 13:51:23 -080069import android.util.Slog;
Filip Gruszczynski170192a2015-08-16 17:46:34 -070070import android.util.SparseArray;
Steven Timotiusaf03df62017-07-18 16:56:43 -070071import android.util.proto.ProtoOutputStream;
Filip Gruszczynski170192a2015-08-16 17:46:34 -070072import android.view.AppTransitionAnimationSpec;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010073import android.view.IAppTransitionAnimationSpecsFuture;
Craig Mautner164d4bb2012-11-26 13:51:23 -080074import android.view.WindowManager;
Craig Mautner164d4bb2012-11-26 13:51:23 -080075import android.view.animation.AlphaAnimation;
76import android.view.animation.Animation;
77import android.view.animation.AnimationSet;
78import android.view.animation.AnimationUtils;
Winson Chung399f6202014-03-19 10:47:20 -070079import android.view.animation.ClipRectAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -080080import android.view.animation.Interpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070081import android.view.animation.PathInterpolator;
Craig Mautner164d4bb2012-11-26 13:51:23 -080082import android.view.animation.ScaleAnimation;
Winson Chung399f6202014-03-19 10:47:20 -070083import android.view.animation.TranslateAnimation;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070084
Craig Mautner164d4bb2012-11-26 13:51:23 -080085import com.android.internal.util.DumpUtils.Dump;
86import com.android.server.AttributeCache;
87import com.android.server.wm.WindowManagerService.H;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -080088import com.android.server.wm.animation.ClipRectLRAnimation;
89import com.android.server.wm.animation.ClipRectTBAnimation;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +010090import com.android.server.wm.animation.CurvedTranslateAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -080091
92import java.io.PrintWriter;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010093import java.util.ArrayList;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010094import java.util.concurrent.ExecutorService;
95import java.util.concurrent.Executors;
Craig Mautner164d4bb2012-11-26 13:51:23 -080096
Craig Mautner164d4bb2012-11-26 13:51:23 -080097// State management of app transitions. When we are preparing for a
98// transition, mNextAppTransition will be the kind of transition to
99// perform or TRANSIT_NONE if we are not waiting. If we are waiting,
100// mOpeningApps and mClosingApps are the lists of tokens that will be
101// made visible or hidden at the next transition.
102public class AppTransition implements Dump {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800103 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppTransition" : TAG_WM;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700104 private static final int CLIP_REVEAL_TRANSLATION_Y_DP = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800105
Craig Mautner4b71aa12012-12-27 17:20:01 -0800106 /** Not set up for a transition. */
107 public static final int TRANSIT_UNSET = -1;
108 /** No animation for transition. */
109 public static final int TRANSIT_NONE = 0;
110 /** A window in a new activity is being opened on top of an existing one in the same task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700111 public static final int TRANSIT_ACTIVITY_OPEN = 6;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800112 /** The window in the top-most activity is being closed to reveal the
113 * previous activity in the same task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700114 public static final int TRANSIT_ACTIVITY_CLOSE = 7;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800115 /** A window in a new task is being opened on top of an existing one
116 * in another activity's task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700117 public static final int TRANSIT_TASK_OPEN = 8;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800118 /** A window in the top-most activity is being closed to reveal the
119 * previous activity in a different task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700120 public static final int TRANSIT_TASK_CLOSE = 9;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800121 /** A window in an existing task is being displayed on top of an existing one
122 * in another activity's task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700123 public static final int TRANSIT_TASK_TO_FRONT = 10;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800124 /** A window in an existing task is being put below all other tasks. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700125 public static final int TRANSIT_TASK_TO_BACK = 11;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800126 /** A window in a new activity that doesn't have a wallpaper is being opened on top of one that
127 * does, effectively closing the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700128 public static final int TRANSIT_WALLPAPER_CLOSE = 12;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800129 /** A window in a new activity that does have a wallpaper is being opened on one that didn't,
130 * effectively opening the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700131 public static final int TRANSIT_WALLPAPER_OPEN = 13;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800132 /** A window in a new activity is being opened on top of an existing one, and both are on top
133 * of the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700134 public static final int TRANSIT_WALLPAPER_INTRA_OPEN = 14;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800135 /** The window in the top-most activity is being closed to reveal the previous activity, and
136 * both are on top of the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700137 public static final int TRANSIT_WALLPAPER_INTRA_CLOSE = 15;
138 /** A window in a new task is being opened behind an existing one in another activity's task.
139 * The new window will show briefly and then be gone. */
140 public static final int TRANSIT_TASK_OPEN_BEHIND = 16;
Winson Chung044d5292014-11-06 11:05:19 -0800141 /** A window in a task is being animated in-place. */
142 public static final int TRANSIT_TASK_IN_PLACE = 17;
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700143 /** An activity is being relaunched (e.g. due to configuration change). */
144 public static final int TRANSIT_ACTIVITY_RELAUNCH = 18;
Jorim Jaggi192086e2016-03-11 17:17:03 +0100145 /** A task is being docked from recents. */
146 public static final int TRANSIT_DOCK_TASK_FROM_RECENTS = 19;
Jorim Jaggife762342016-10-13 14:33:27 +0200147 /** Keyguard is going away */
148 public static final int TRANSIT_KEYGUARD_GOING_AWAY = 20;
149 /** Keyguard is going away with showing an activity behind that requests wallpaper */
150 public static final int TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER = 21;
151 /** Keyguard is being occluded */
152 public static final int TRANSIT_KEYGUARD_OCCLUDE = 22;
153 /** Keyguard is being unoccluded */
154 public static final int TRANSIT_KEYGUARD_UNOCCLUDE = 23;
155
156 /** Transition flag: Keyguard is going away, but keeping the notification shade open */
157 public static final int TRANSIT_FLAG_KEYGUARD_GOING_AWAY_TO_SHADE = 0x1;
158 /** Transition flag: Keyguard is going away, but doesn't want an animation for it */
159 public static final int TRANSIT_FLAG_KEYGUARD_GOING_AWAY_NO_ANIMATION = 0x2;
160 /** Transition flag: Keyguard is going away while it was showing the system wallpaper. */
161 public static final int TRANSIT_FLAG_KEYGUARD_GOING_AWAY_WITH_WALLPAPER = 0x4;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800162
Winson Chunga4ccb862014-08-22 15:26:27 -0700163 /** Fraction of animation at which the recents thumbnail stays completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700164 private static final float RECENTS_THUMBNAIL_FADEIN_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800165 /** Fraction of animation at which the recents thumbnail becomes completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700166 private static final float RECENTS_THUMBNAIL_FADEOUT_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800167
Filip Gruszczynski84fa3352016-01-25 16:28:49 -0800168 static final int DEFAULT_APP_TRANSITION_DURATION = 336;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800169
170 /** Interpolator to be used for animations that respond directly to a touch */
171 static final Interpolator TOUCH_RESPONSE_INTERPOLATOR =
172 new PathInterpolator(0.3f, 0f, 0.1f, 1f);
173
Jorim Jaggic69bd222016-03-15 14:38:37 +0100174 private static final Interpolator THUMBNAIL_DOCK_INTERPOLATOR =
175 new PathInterpolator(0.85f, 0f, 1f, 1f);
176
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800177 /**
178 * Maximum duration for the clip reveal animation. This is used when there is a lot of movement
179 * involved, to make it more understandable.
180 */
181 private static final int MAX_CLIP_REVEAL_TRANSITION_DURATION = 420;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700182 private static final int THUMBNAIL_APP_TRANSITION_DURATION = 336;
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700183 private static final long APP_TRANSITION_TIMEOUT_MS = 5000;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800184
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800185 private final Context mContext;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800186 private final WindowManagerService mService;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800187
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800188 private int mNextAppTransition = TRANSIT_UNSET;
Jorim Jaggife762342016-10-13 14:33:27 +0200189 private int mNextAppTransitionFlags = 0;
Chong Zhang60091a92016-07-27 17:52:45 -0700190 private int mLastUsedAppTransition = TRANSIT_UNSET;
191 private String mLastOpeningApp;
192 private String mLastClosingApp;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800193
194 private static final int NEXT_TRANSIT_TYPE_NONE = 0;
195 private static final int NEXT_TRANSIT_TYPE_CUSTOM = 1;
196 private static final int NEXT_TRANSIT_TYPE_SCALE_UP = 2;
197 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP = 3;
198 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN = 4;
Winson Chunga4ccb862014-08-22 15:26:27 -0700199 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP = 5;
200 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN = 6;
Winson Chung044d5292014-11-06 11:05:19 -0800201 private static final int NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE = 7;
Chet Haase10e23ab2015-02-11 15:08:38 -0800202 private static final int NEXT_TRANSIT_TYPE_CLIP_REVEAL = 8;
Tony Mak089c35e2017-12-18 20:34:14 +0000203
204 /**
205 * Refers to the transition to activity started by using {@link
206 * android.content.pm.crossprofile.CrossProfileApps#startMainActivity(ComponentName, UserHandle)
207 * }.
208 */
209 private static final int NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS = 9;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800210 private int mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
211
Winson Chung399f6202014-03-19 10:47:20 -0700212 // These are the possible states for the enter/exit activities during a thumbnail transition
213 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_UP = 0;
214 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_UP = 1;
215 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN = 2;
216 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN = 3;
217
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800218 private String mNextAppTransitionPackage;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800219 // Used for thumbnail transitions. True if we're scaling up, false if scaling down
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800220 private boolean mNextAppTransitionScaleUp;
221 private IRemoteCallback mNextAppTransitionCallback;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +0100222 private IRemoteCallback mNextAppTransitionFutureCallback;
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -0700223 private IRemoteCallback mAnimationFinishedCallback;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800224 private int mNextAppTransitionEnter;
225 private int mNextAppTransitionExit;
Winson Chung044d5292014-11-06 11:05:19 -0800226 private int mNextAppTransitionInPlace;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700227
228 // Keyed by task id.
229 private final SparseArray<AppTransitionAnimationSpec> mNextAppTransitionAnimationsSpecs
230 = new SparseArray<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100231 private IAppTransitionAnimationSpecsFuture mNextAppTransitionAnimationsSpecsFuture;
232 private boolean mNextAppTransitionAnimationsSpecsPending;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700233 private AppTransitionAnimationSpec mDefaultNextAppTransitionAnimationSpec;
234
Winson Chunga4ccb862014-08-22 15:26:27 -0700235 private Rect mNextAppTransitionInsets = new Rect();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800236
Winson Chung2820c452014-04-15 15:34:44 -0700237 private Rect mTmpFromClipRect = new Rect();
238 private Rect mTmpToClipRect = new Rect();
239
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700240 private final Rect mTmpRect = new Rect();
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700241
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800242 private final static int APP_STATE_IDLE = 0;
243 private final static int APP_STATE_READY = 1;
244 private final static int APP_STATE_RUNNING = 2;
245 private final static int APP_STATE_TIMEOUT = 3;
246 private int mAppTransitionState = APP_STATE_IDLE;
247
248 private final int mConfigShortAnimTime;
Craig Mautner321bdf52012-12-18 09:53:24 -0800249 private final Interpolator mDecelerateInterpolator;
Winson Chunga4ccb862014-08-22 15:26:27 -0700250 private final Interpolator mThumbnailFadeInInterpolator;
251 private final Interpolator mThumbnailFadeOutInterpolator;
Chet Haase10e23ab2015-02-11 15:08:38 -0800252 private final Interpolator mLinearOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700253 private final Interpolator mFastOutLinearInInterpolator;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100254 private final Interpolator mFastOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700255 private final Interpolator mClipHorizontalInterpolator = new PathInterpolator(0, 0, 0.4f, 1f);
256
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700257 private final int mClipRevealTranslationY;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800258
Amith Yamasani4befbec2013-07-10 16:18:01 -0700259 private int mCurrentUserId = 0;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800260 private long mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Amith Yamasani4befbec2013-07-10 16:18:01 -0700261
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100262 private final ArrayList<AppTransitionListener> mListeners = new ArrayList<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100263 private final ExecutorService mDefaultExecutor = Executors.newSingleThreadExecutor();
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100264
Jorim Jaggif97ed922016-02-18 18:57:07 -0800265 private int mLastClipRevealMaxTranslation;
266 private boolean mLastHadClipReveal;
Jorim Jaggi363ab982016-04-26 19:51:20 -0700267 private boolean mProlongedAnimationsEnded;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800268
Manu Cornetd7376802017-01-13 13:44:07 -0800269 private final boolean mGridLayoutRecentsEnabled;
Matthew Ng43db6d22017-06-27 15:29:39 -0700270 private final boolean mLowRamRecentsEnabled;
Manu Cornetd7376802017-01-13 13:44:07 -0800271
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800272 AppTransition(Context context, WindowManagerService service) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800273 mContext = context;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800274 mService = service;
Chet Haase10e23ab2015-02-11 15:08:38 -0800275 mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
276 com.android.internal.R.interpolator.linear_out_slow_in);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700277 mFastOutLinearInInterpolator = AnimationUtils.loadInterpolator(context,
278 com.android.internal.R.interpolator.fast_out_linear_in);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100279 mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
280 com.android.internal.R.interpolator.fast_out_slow_in);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800281 mConfigShortAnimTime = context.getResources().getInteger(
282 com.android.internal.R.integer.config_shortAnimTime);
Craig Mautner321bdf52012-12-18 09:53:24 -0800283 mDecelerateInterpolator = AnimationUtils.loadInterpolator(context,
284 com.android.internal.R.interpolator.decelerate_cubic);
Winson Chunga4ccb862014-08-22 15:26:27 -0700285 mThumbnailFadeInInterpolator = new Interpolator() {
286 @Override
287 public float getInterpolation(float input) {
288 // Linear response for first fraction, then complete after that.
289 if (input < RECENTS_THUMBNAIL_FADEIN_FRACTION) {
290 return 0f;
291 }
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700292 float t = (input - RECENTS_THUMBNAIL_FADEIN_FRACTION) /
Winson Chunga4ccb862014-08-22 15:26:27 -0700293 (1f - RECENTS_THUMBNAIL_FADEIN_FRACTION);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700294 return mFastOutLinearInInterpolator.getInterpolation(t);
Winson Chunga4ccb862014-08-22 15:26:27 -0700295 }
296 };
297 mThumbnailFadeOutInterpolator = new Interpolator() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800298 @Override
299 public float getInterpolation(float input) {
300 // Linear response for first fraction, then complete after that.
301 if (input < RECENTS_THUMBNAIL_FADEOUT_FRACTION) {
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700302 float t = input / RECENTS_THUMBNAIL_FADEOUT_FRACTION;
303 return mLinearOutSlowInInterpolator.getInterpolation(t);
Craig Mautner321bdf52012-12-18 09:53:24 -0800304 }
Winson Chunga4ccb862014-08-22 15:26:27 -0700305 return 1f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800306 }
307 };
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700308 mClipRevealTranslationY = (int) (CLIP_REVEAL_TRANSLATION_Y_DP
309 * mContext.getResources().getDisplayMetrics().density);
Manu Cornetd7376802017-01-13 13:44:07 -0800310 mGridLayoutRecentsEnabled = SystemProperties.getBoolean("ro.recents.grid", false);
Matthew Ng43db6d22017-06-27 15:29:39 -0700311 mLowRamRecentsEnabled = ActivityManager.isLowRamDeviceStatic();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800312 }
313
314 boolean isTransitionSet() {
315 return mNextAppTransition != TRANSIT_UNSET;
316 }
317
Craig Mautner164d4bb2012-11-26 13:51:23 -0800318 boolean isTransitionEqual(int transit) {
319 return mNextAppTransition == transit;
320 }
321
322 int getAppTransition() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800323 return mNextAppTransition;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800324 }
325
Jorim Jaggife762342016-10-13 14:33:27 +0200326 private void setAppTransition(int transit, int flags) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800327 mNextAppTransition = transit;
Jorim Jaggife762342016-10-13 14:33:27 +0200328 mNextAppTransitionFlags |= flags;
Chong Zhang60091a92016-07-27 17:52:45 -0700329 setLastAppTransition(TRANSIT_UNSET, null, null);
Jorim Jaggi245281c2017-06-07 14:33:04 -0700330 updateBooster();
Chong Zhang60091a92016-07-27 17:52:45 -0700331 }
332
333 void setLastAppTransition(int transit, AppWindowToken openingApp, AppWindowToken closingApp) {
334 mLastUsedAppTransition = transit;
335 mLastOpeningApp = "" + openingApp;
336 mLastClosingApp = "" + closingApp;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800337 }
338
339 boolean isReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800340 return mAppTransitionState == APP_STATE_READY
341 || mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800342 }
343
Craig Mautnerae446592012-12-06 19:05:05 -0800344 void setReady() {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700345 setAppTransitionState(APP_STATE_READY);
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100346 fetchAppTransitionSpecsFromFuture();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800347 }
348
349 boolean isRunning() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800350 return mAppTransitionState == APP_STATE_RUNNING;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800351 }
352
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800353 void setIdle() {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700354 setAppTransitionState(APP_STATE_IDLE);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800355 }
356
357 boolean isTimeout() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800358 return mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800359 }
360
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800361 void setTimeout() {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700362 setAppTransitionState(APP_STATE_TIMEOUT);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800363 }
364
Winson Chungaa7fa012017-05-24 15:50:06 -0700365 GraphicBuffer getAppTransitionThumbnailHeader(int taskId) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700366 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800367 if (spec == null) {
368 spec = mDefaultNextAppTransitionAnimationSpec;
369 }
Winson Chungaa7fa012017-05-24 15:50:06 -0700370 return spec != null ? spec.buffer : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800371 }
372
Winson Chunga4ccb862014-08-22 15:26:27 -0700373 /** Returns whether the next thumbnail transition is aspect scaled up. */
374 boolean isNextThumbnailTransitionAspectScaled() {
375 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
376 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
377 }
378
379 /** Returns whether the next thumbnail transition is scaling up. */
380 boolean isNextThumbnailTransitionScaleUp() {
381 return mNextAppTransitionScaleUp;
382 }
383
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -0800384 boolean isNextAppTransitionThumbnailUp() {
385 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
386 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP;
387 }
388
389 boolean isNextAppTransitionThumbnailDown() {
390 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN ||
391 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
392 }
393
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100394 /**
395 * @return true if and only if we are currently fetching app transition specs from the future
396 * passed into {@link #overridePendingAppTransitionMultiThumbFuture}
397 */
398 boolean isFetchingAppTransitionsSpecs() {
399 return mNextAppTransitionAnimationsSpecsPending;
400 }
401
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700402 private boolean prepare() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800403 if (!isRunning()) {
Jorim Jaggi245281c2017-06-07 14:33:04 -0700404 setAppTransitionState(APP_STATE_IDLE);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100405 notifyAppTransitionPendingLocked();
Jorim Jaggif97ed922016-02-18 18:57:07 -0800406 mLastHadClipReveal = false;
407 mLastClipRevealMaxTranslation = 0;
408 mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700409 return true;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800410 }
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700411 return false;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800412 }
413
Jorim Jaggife762342016-10-13 14:33:27 +0200414 /**
415 * @return bit-map of WindowManagerPolicy#FINISH_LAYOUT_REDO_* to indicate whether another
416 * layout pass needs to be done
417 */
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200418 int goodToGo(int transit, AppWindowToken topOpeningApp,
419 AppWindowToken topClosingApp, ArraySet<AppWindowToken> openingApps,
Jorim Jaggife762342016-10-13 14:33:27 +0200420 ArraySet<AppWindowToken> closingApps) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800421 mNextAppTransition = TRANSIT_UNSET;
Jorim Jaggife762342016-10-13 14:33:27 +0200422 mNextAppTransitionFlags = 0;
Jorim Jaggi245281c2017-06-07 14:33:04 -0700423 setAppTransitionState(APP_STATE_RUNNING);
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200424 final AnimationAdapter topOpeningAnim = topOpeningApp != null
425 ? topOpeningApp.getAnimation()
426 : null;
Jorim Jaggife762342016-10-13 14:33:27 +0200427 int redoLayout = notifyAppTransitionStartingLocked(transit,
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200428 topOpeningApp != null ? topOpeningApp.token : null,
429 topClosingApp != null ? topClosingApp.token : null,
430 topOpeningAnim != null ? topOpeningAnim.getDurationHint() : 0,
431 topOpeningAnim != null
432 ? topOpeningAnim.getStatusBarTransitionsStartTime()
433 : SystemClock.uptimeMillis(),
434 AnimationAdapter.STATUS_BAR_TRANSITION_DURATION);
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800435 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Jorim Jaggife762342016-10-13 14:33:27 +0200436 .notifyAppTransitionStarting(openingApps, transit);
Jorim Jaggi363ab982016-04-26 19:51:20 -0700437
438 // Prolong the start for the transition when docking a task from recents, unless recents
439 // ended it already then we don't need to wait.
Jorim Jaggife762342016-10-13 14:33:27 +0200440 if (transit == TRANSIT_DOCK_TASK_FROM_RECENTS && !mProlongedAnimationsEnded) {
Jorim Jaggi363ab982016-04-26 19:51:20 -0700441 for (int i = openingApps.size() - 1; i >= 0; i--) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200442 final AppWindowToken app = openingApps.valueAt(i);
443 app.startDelayingAnimationStart();
Jorim Jaggi363ab982016-04-26 19:51:20 -0700444 }
445 }
Jorim Jaggife762342016-10-13 14:33:27 +0200446 return redoLayout;
Jorim Jaggi363ab982016-04-26 19:51:20 -0700447 }
448
449 /**
450 * Let the transitions manager know that the somebody wanted to end the prolonged animations.
451 */
452 void notifyProlongedAnimationsEnded() {
453 mProlongedAnimationsEnded = true;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800454 }
455
456 void clear() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800457 mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800458 mNextAppTransitionPackage = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700459 mNextAppTransitionAnimationsSpecs.clear();
Jorim Jaggi65193992015-11-23 16:49:59 -0800460 mNextAppTransitionAnimationsSpecsFuture = null;
461 mDefaultNextAppTransitionAnimationSpec = null;
462 mAnimationFinishedCallback = null;
Jorim Jaggi363ab982016-04-26 19:51:20 -0700463 mProlongedAnimationsEnded = false;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800464 }
465
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800466 void freeze() {
Jorim Jaggife762342016-10-13 14:33:27 +0200467 final int transit = mNextAppTransition;
468 setAppTransition(AppTransition.TRANSIT_UNSET, 0 /* flags */);
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800469 clear();
470 setReady();
Jorim Jaggife762342016-10-13 14:33:27 +0200471 notifyAppTransitionCancelledLocked(transit);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100472 }
473
Jorim Jaggi245281c2017-06-07 14:33:04 -0700474 private void setAppTransitionState(int state) {
475 mAppTransitionState = state;
476 updateBooster();
477 }
478
479 /**
480 * Updates whether we currently boost wm locked sections and the animation thread. We want to
481 * boost the priorities to a more important value whenever an app transition is going to happen
482 * soon or an app transition is running.
483 */
484 private void updateBooster() {
485 WindowManagerService.sThreadPriorityBooster.setAppTransitionRunning(
486 mNextAppTransition != TRANSIT_UNSET || mAppTransitionState == APP_STATE_READY
487 || mAppTransitionState == APP_STATE_RUNNING);
488 }
489
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100490 void registerListenerLocked(AppTransitionListener listener) {
491 mListeners.add(listener);
492 }
493
Wale Ogunwalea48eadb2015-05-14 17:43:12 -0700494 public void notifyAppTransitionFinishedLocked(IBinder token) {
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100495 for (int i = 0; i < mListeners.size(); i++) {
496 mListeners.get(i).onAppTransitionFinishedLocked(token);
497 }
498 }
499
500 private void notifyAppTransitionPendingLocked() {
501 for (int i = 0; i < mListeners.size(); i++) {
502 mListeners.get(i).onAppTransitionPendingLocked();
503 }
504 }
505
Jorim Jaggife762342016-10-13 14:33:27 +0200506 private void notifyAppTransitionCancelledLocked(int transit) {
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100507 for (int i = 0; i < mListeners.size(); i++) {
Jorim Jaggife762342016-10-13 14:33:27 +0200508 mListeners.get(i).onAppTransitionCancelledLocked(transit);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100509 }
510 }
511
Jorim Jaggife762342016-10-13 14:33:27 +0200512 private int notifyAppTransitionStartingLocked(int transit, IBinder openToken,
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200513 IBinder closeToken, long duration, long statusBarAnimationStartTime,
514 long statusBarAnimationDuration) {
Jorim Jaggife762342016-10-13 14:33:27 +0200515 int redoLayout = 0;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100516 for (int i = 0; i < mListeners.size(); i++) {
Jorim Jaggife762342016-10-13 14:33:27 +0200517 redoLayout |= mListeners.get(i).onAppTransitionStartingLocked(transit, openToken,
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200518 closeToken, duration, statusBarAnimationStartTime, statusBarAnimationDuration);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100519 }
Jorim Jaggife762342016-10-13 14:33:27 +0200520 return redoLayout;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800521 }
522
Craig Mautner164d4bb2012-11-26 13:51:23 -0800523 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
524 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg="
525 + (lp != null ? lp.packageName : null)
526 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
527 if (lp != null && lp.windowAnimations != 0) {
528 // If this is a system resource, don't try to load it from the
529 // application resources. It is nice to avoid loading application
530 // resources if we can.
531 String packageName = lp.packageName != null ? lp.packageName : "android";
532 int resId = lp.windowAnimations;
533 if ((resId&0xFF000000) == 0x01000000) {
534 packageName = "android";
535 }
536 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
537 + packageName);
538 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700539 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800540 }
541 return null;
542 }
543
544 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
545 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package="
546 + packageName + " resId=0x" + Integer.toHexString(resId));
547 if (packageName != null) {
548 if ((resId&0xFF000000) == 0x01000000) {
549 packageName = "android";
550 }
551 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
552 + packageName);
553 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700554 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800555 }
556 return null;
557 }
558
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700559 Animation loadAnimationAttr(WindowManager.LayoutParams lp, int animAttr) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800560 int anim = 0;
561 Context context = mContext;
562 if (animAttr >= 0) {
563 AttributeCache.Entry ent = getCachedAnimations(lp);
564 if (ent != null) {
565 context = ent.context;
566 anim = ent.array.getResourceId(animAttr, 0);
567 }
568 }
569 if (anim != 0) {
570 return AnimationUtils.loadAnimation(context, anim);
571 }
572 return null;
573 }
574
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700575 Animation loadAnimationRes(WindowManager.LayoutParams lp, int resId) {
576 Context context = mContext;
577 if (resId >= 0) {
578 AttributeCache.Entry ent = getCachedAnimations(lp);
579 if (ent != null) {
580 context = ent.context;
581 }
582 return AnimationUtils.loadAnimation(context, resId);
583 }
584 return null;
585 }
586
587 private Animation loadAnimationRes(String packageName, int resId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800588 int anim = 0;
589 Context context = mContext;
590 if (resId >= 0) {
591 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
592 if (ent != null) {
593 context = ent.context;
594 anim = resId;
595 }
596 }
597 if (anim != 0) {
598 return AnimationUtils.loadAnimation(context, anim);
599 }
600 return null;
601 }
602
Craig Mautner164d4bb2012-11-26 13:51:23 -0800603 /**
604 * Compute the pivot point for an animation that is scaling from a small
605 * rect on screen to a larger rect. The pivot point varies depending on
606 * the distance between the inner and outer edges on both sides. This
607 * function computes the pivot point for one dimension.
608 * @param startPos Offset from left/top edge of outer rectangle to
609 * left/top edge of inner rectangle.
610 * @param finalScale The scaling factor between the size of the outer
611 * and inner rectangles.
612 */
613 private static float computePivot(int startPos, float finalScale) {
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800614
615 /*
616 Theorem of intercepting lines:
617
618 + + +-----------------------------------------------+
619 | | | |
620 | | | |
621 | | | |
622 | | | |
623 x | y | | |
624 | | | |
625 | | | |
626 | | | |
627 | | | |
628 | + | +--------------------+ |
629 | | | | |
630 | | | | |
631 | | | | |
632 | | | | |
633 | | | | |
634 | | | | |
635 | | | | |
636 | | | | |
637 | | | | |
638 | | | | |
639 | | | | |
640 | | | | |
641 | | | | |
642 | | | | |
643 | | | | |
644 | | | | |
645 | | | | |
646 | | +--------------------+ |
647 | | |
648 | | |
649 | | |
650 | | |
651 | | |
652 | | |
653 | | |
654 | +-----------------------------------------------+
655 |
656 |
657 |
658 |
659 |
660 |
661 |
662 |
663 |
664 + ++
665 p ++
666
667 scale = (x - y) / x
668 <=> x = -y / (scale - 1)
669 */
Craig Mautner164d4bb2012-11-26 13:51:23 -0800670 final float denom = finalScale-1;
671 if (Math.abs(denom) < .0001f) {
672 return startPos;
673 }
674 return -startPos / denom;
675 }
676
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700677 private Animation createScaleUpAnimationLocked(int transit, boolean enter,
678 Rect containingFrame) {
679 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700680 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700681 final int appWidth = containingFrame.width();
682 final int appHeight = containingFrame.height();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800683 if (enter) {
684 // Entering app zooms out from the center of the initial rect.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700685 float scaleW = mTmpRect.width() / (float) appWidth;
686 float scaleH = mTmpRect.height() / (float) appHeight;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800687 Animation scale = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700688 computePivot(mTmpRect.left, scaleW),
Winson4c3fecd2016-07-13 12:29:48 -0700689 computePivot(mTmpRect.top, scaleH));
Craig Mautner321bdf52012-12-18 09:53:24 -0800690 scale.setInterpolator(mDecelerateInterpolator);
691
Craig Mautner164d4bb2012-11-26 13:51:23 -0800692 Animation alpha = new AlphaAnimation(0, 1);
Winson Chunga4ccb862014-08-22 15:26:27 -0700693 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
Craig Mautner321bdf52012-12-18 09:53:24 -0800694
695 AnimationSet set = new AnimationSet(false);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800696 set.addAnimation(scale);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800697 set.addAnimation(alpha);
698 set.setDetachWallpaper(true);
699 a = set;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800700 } else if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
701 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800702 // If we are on top of the wallpaper, we need an animation that
703 // correctly handles the wallpaper staying static behind all of
704 // the animated elements. To do this, will just have the existing
705 // element fade out.
706 a = new AlphaAnimation(1, 0);
707 a.setDetachWallpaper(true);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800708 } else {
Craig Mautner321bdf52012-12-18 09:53:24 -0800709 // For normal animations, the exiting element just holds in place.
710 a = new AlphaAnimation(1, 1);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800711 }
Craig Mautner321bdf52012-12-18 09:53:24 -0800712
713 // Pick the desired duration. If this is an inter-activity transition,
714 // it is the standard duration for that. Otherwise we use the longer
715 // task transition duration.
716 final long duration;
717 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800718 case TRANSIT_ACTIVITY_OPEN:
719 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800720 duration = mConfigShortAnimTime;
721 break;
722 default:
723 duration = DEFAULT_APP_TRANSITION_DURATION;
724 break;
725 }
726 a.setDuration(duration);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800727 a.setFillAfter(true);
Craig Mautner321bdf52012-12-18 09:53:24 -0800728 a.setInterpolator(mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800729 a.initialize(appWidth, appHeight, appWidth, appHeight);
730 return a;
731 }
732
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700733 private void getDefaultNextAppTransitionStartRect(Rect rect) {
734 if (mDefaultNextAppTransitionAnimationSpec == null ||
735 mDefaultNextAppTransitionAnimationSpec.rect == null) {
Jorim Jaggi2550f3f2017-03-14 20:15:59 +0100736 Slog.e(TAG, "Starting rect for app requested, but none available", new Throwable());
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700737 rect.setEmpty();
738 } else {
739 rect.set(mDefaultNextAppTransitionAnimationSpec.rect);
740 }
741 }
742
743 void getNextAppTransitionStartRect(int taskId, Rect rect) {
744 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800745 if (spec == null) {
746 spec = mDefaultNextAppTransitionAnimationSpec;
747 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700748 if (spec == null || spec.rect == null) {
Jorim Jaggi2550f3f2017-03-14 20:15:59 +0100749 Slog.e(TAG, "Starting rect for task: " + taskId + " requested, but not available",
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700750 new Throwable());
751 rect.setEmpty();
752 } else {
753 rect.set(spec.rect);
754 }
755 }
756
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800757 private void putDefaultNextAppTransitionCoordinates(int left, int top, int width, int height,
Winson Chungaa7fa012017-05-24 15:50:06 -0700758 GraphicBuffer buffer) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700759 mDefaultNextAppTransitionAnimationSpec = new AppTransitionAnimationSpec(-1 /* taskId */,
Winson Chungaa7fa012017-05-24 15:50:06 -0700760 buffer, new Rect(left, top, left + width, top + height));
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700761 }
762
Jorim Jaggif97ed922016-02-18 18:57:07 -0800763 /**
764 * @return the duration of the last clip reveal animation
765 */
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800766 long getLastClipRevealTransitionDuration() {
767 return mLastClipRevealTransitionDuration;
768 }
769
770 /**
Jorim Jaggif97ed922016-02-18 18:57:07 -0800771 * @return the maximum distance the app surface is traveling of the last clip reveal animation
772 */
773 int getLastClipRevealMaxTranslation() {
774 return mLastClipRevealMaxTranslation;
775 }
776
777 /**
778 * @return true if in the last app transition had a clip reveal animation, false otherwise
779 */
780 boolean hadClipRevealAnimation() {
781 return mLastHadClipReveal;
782 }
783
784 /**
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800785 * Calculates the duration for the clip reveal animation. If the clip is "cut off", meaning that
786 * the start rect is outside of the target rect, and there is a lot of movement going on.
787 *
788 * @param cutOff whether the start rect was not fully contained by the end rect
789 * @param translationX the total translation the surface moves in x direction
790 * @param translationY the total translation the surfaces moves in y direction
791 * @param displayFrame our display frame
792 *
793 * @return the duration of the clip reveal animation, in milliseconds
794 */
795 private long calculateClipRevealTransitionDuration(boolean cutOff, float translationX,
796 float translationY, Rect displayFrame) {
797 if (!cutOff) {
798 return DEFAULT_APP_TRANSITION_DURATION;
799 }
800 final float fraction = Math.max(Math.abs(translationX) / displayFrame.width(),
801 Math.abs(translationY) / displayFrame.height());
802 return (long) (DEFAULT_APP_TRANSITION_DURATION + fraction *
803 (MAX_CLIP_REVEAL_TRANSITION_DURATION - DEFAULT_APP_TRANSITION_DURATION));
804 }
805
806 private Animation createClipRevealAnimationLocked(int transit, boolean enter, Rect appFrame,
807 Rect displayFrame) {
Chet Haase10e23ab2015-02-11 15:08:38 -0800808 final Animation anim;
809 if (enter) {
Craig Mautner80b1f642015-04-22 10:59:09 -0700810 final int appWidth = appFrame.width();
811 final int appHeight = appFrame.height();
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800812
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700813 // mTmpRect will contain an area around the launcher icon that was pressed. We will
Filip Gruszczynski82861362015-10-16 14:21:09 -0700814 // clip reveal from that area in the final area of the app.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700815 getDefaultNextAppTransitionStartRect(mTmpRect);
Craig Mautner80b1f642015-04-22 10:59:09 -0700816
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700817 float t = 0f;
818 if (appHeight > 0) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800819 t = (float) mTmpRect.top / displayFrame.height();
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700820 }
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800821 int translationY = mClipRevealTranslationY + (int)(displayFrame.height() / 7f * t);
822 int translationX = 0;
823 int translationYCorrection = translationY;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700824 int centerX = mTmpRect.centerX();
825 int centerY = mTmpRect.centerY();
826 int halfWidth = mTmpRect.width() / 2;
827 int halfHeight = mTmpRect.height() / 2;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800828 int clipStartX = centerX - halfWidth - appFrame.left;
829 int clipStartY = centerY - halfHeight - appFrame.top;
830 boolean cutOff = false;
831
832 // If the starting rectangle is fully or partially outside of the target rectangle, we
833 // need to start the clipping at the edge and then achieve the rest with translation
834 // and extending the clip rect from that edge.
835 if (appFrame.top > centerY - halfHeight) {
836 translationY = (centerY - halfHeight) - appFrame.top;
837 translationYCorrection = 0;
838 clipStartY = 0;
839 cutOff = true;
840 }
841 if (appFrame.left > centerX - halfWidth) {
842 translationX = (centerX - halfWidth) - appFrame.left;
843 clipStartX = 0;
844 cutOff = true;
845 }
846 if (appFrame.right < centerX + halfWidth) {
847 translationX = (centerX + halfWidth) - appFrame.right;
848 clipStartX = appWidth - mTmpRect.width();
849 cutOff = true;
850 }
851 final long duration = calculateClipRevealTransitionDuration(cutOff, translationX,
852 translationY, displayFrame);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700853
854 // Clip third of the from size of launch icon, expand to full width/height
Chet Haase10e23ab2015-02-11 15:08:38 -0800855 Animation clipAnimLR = new ClipRectLRAnimation(
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800856 clipStartX, clipStartX + mTmpRect.width(), 0, appWidth);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700857 clipAnimLR.setInterpolator(mClipHorizontalInterpolator);
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800858 clipAnimLR.setDuration((long) (duration / 2.5f));
Filip Gruszczynski82861362015-10-16 14:21:09 -0700859
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800860 TranslateAnimation translate = new TranslateAnimation(translationX, 0, translationY, 0);
861 translate.setInterpolator(cutOff ? TOUCH_RESPONSE_INTERPOLATOR
862 : mLinearOutSlowInInterpolator);
863 translate.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800864
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800865 Animation clipAnimTB = new ClipRectTBAnimation(
866 clipStartY, clipStartY + mTmpRect.height(),
867 0, appHeight,
868 translationYCorrection, 0,
869 mLinearOutSlowInInterpolator);
870 clipAnimTB.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
871 clipAnimTB.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800872
873 // Quick fade-in from icon to app window
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800874 final long alphaDuration = duration / 4;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700875 AlphaAnimation alpha = new AlphaAnimation(0.5f, 1);
Chet Haase10e23ab2015-02-11 15:08:38 -0800876 alpha.setDuration(alphaDuration);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700877 alpha.setInterpolator(mLinearOutSlowInInterpolator);
Chet Haase10e23ab2015-02-11 15:08:38 -0800878
879 AnimationSet set = new AnimationSet(false);
880 set.addAnimation(clipAnimLR);
881 set.addAnimation(clipAnimTB);
Filip Gruszczynski82861362015-10-16 14:21:09 -0700882 set.addAnimation(translate);
Chet Haase10e23ab2015-02-11 15:08:38 -0800883 set.addAnimation(alpha);
Filip Gruszczynski9e2cf5b2015-07-31 12:20:40 -0700884 set.setZAdjustment(Animation.ZORDER_TOP);
Chet Haase10e23ab2015-02-11 15:08:38 -0800885 set.initialize(appWidth, appHeight, appWidth, appHeight);
886 anim = set;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800887 mLastHadClipReveal = true;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800888 mLastClipRevealTransitionDuration = duration;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800889
890 // If the start rect was full inside the target rect (cutOff == false), we don't need
891 // to store the translation, because it's only used if cutOff == true.
892 mLastClipRevealMaxTranslation = cutOff
893 ? Math.max(Math.abs(translationY), Math.abs(translationX)) : 0;
Chet Haase10e23ab2015-02-11 15:08:38 -0800894 } else {
895 final long duration;
896 switch (transit) {
897 case TRANSIT_ACTIVITY_OPEN:
898 case TRANSIT_ACTIVITY_CLOSE:
899 duration = mConfigShortAnimTime;
900 break;
901 default:
902 duration = DEFAULT_APP_TRANSITION_DURATION;
903 break;
904 }
905 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
906 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
907 // If we are on top of the wallpaper, we need an animation that
908 // correctly handles the wallpaper staying static behind all of
909 // the animated elements. To do this, will just have the existing
910 // element fade out.
911 anim = new AlphaAnimation(1, 0);
912 anim.setDetachWallpaper(true);
913 } else {
914 // For normal animations, the exiting element just holds in place.
915 anim = new AlphaAnimation(1, 1);
916 }
917 anim.setInterpolator(mDecelerateInterpolator);
918 anim.setDuration(duration);
919 anim.setFillAfter(true);
920 }
921 return anim;
922 }
923
Winson Chung399f6202014-03-19 10:47:20 -0700924 /**
925 * Prepares the specified animation with a standard duration, interpolator, etc.
926 */
Winson Chung5393dff2014-05-08 14:25:43 -0700927 Animation prepareThumbnailAnimationWithDuration(Animation a, int appWidth, int appHeight,
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100928 long duration, Interpolator interpolator) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700929 if (duration > 0) {
930 a.setDuration(duration);
931 }
Winson Chung5393dff2014-05-08 14:25:43 -0700932 a.setFillAfter(true);
Jorim Jaggic69bd222016-03-15 14:38:37 +0100933 if (interpolator != null) {
934 a.setInterpolator(interpolator);
935 }
Winson Chung5393dff2014-05-08 14:25:43 -0700936 a.initialize(appWidth, appHeight, appWidth, appHeight);
937 return a;
938 }
939
940 /**
941 * Prepares the specified animation with a standard duration, interpolator, etc.
942 */
Winson Chung399f6202014-03-19 10:47:20 -0700943 Animation prepareThumbnailAnimation(Animation a, int appWidth, int appHeight, int transit) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800944 // Pick the desired duration. If this is an inter-activity transition,
945 // it is the standard duration for that. Otherwise we use the longer
946 // task transition duration.
Winson Chung5393dff2014-05-08 14:25:43 -0700947 final int duration;
Craig Mautner321bdf52012-12-18 09:53:24 -0800948 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800949 case TRANSIT_ACTIVITY_OPEN:
950 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800951 duration = mConfigShortAnimTime;
952 break;
953 default:
954 duration = DEFAULT_APP_TRANSITION_DURATION;
955 break;
956 }
Winson Chung5393dff2014-05-08 14:25:43 -0700957 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, duration,
958 mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800959 }
960
Winson Chung399f6202014-03-19 10:47:20 -0700961 /**
962 * Return the current thumbnail transition state.
963 */
964 int getThumbnailTransitionState(boolean enter) {
965 if (enter) {
966 if (mNextAppTransitionScaleUp) {
967 return THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
968 } else {
969 return THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN;
970 }
971 } else {
972 if (mNextAppTransitionScaleUp) {
973 return THUMBNAIL_TRANSITION_EXIT_SCALE_UP;
974 } else {
975 return THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN;
976 }
977 }
978 }
979
980 /**
981 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700982 * when a thumbnail is specified with the pending animation override.
Winson Chung399f6202014-03-19 10:47:20 -0700983 */
Jorim Jaggide63d442016-03-14 14:56:56 +0100984 Animation createThumbnailAspectScaleAnimationLocked(Rect appRect, @Nullable Rect contentInsets,
Winson Chungaa7fa012017-05-24 15:50:06 -0700985 GraphicBuffer thumbnailHeader, final int taskId, int uiMode, int orientation) {
Winson Chung399f6202014-03-19 10:47:20 -0700986 Animation a;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700987 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chung399f6202014-03-19 10:47:20 -0700988 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700989 final int thumbHeightI = thumbnailHeader.getHeight();
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700990 final int appWidth = appRect.width();
Winson Chung399f6202014-03-19 10:47:20 -0700991
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700992 float scaleW = appWidth / thumbWidth;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700993 getNextAppTransitionStartRect(taskId, mTmpRect);
Jorim Jaggi09072002016-03-25 16:48:42 -0700994 final float fromX;
Manu Cornet57b61492017-01-24 18:19:05 +0900995 float fromY;
Jorim Jaggi09072002016-03-25 16:48:42 -0700996 final float toX;
Manu Cornet57b61492017-01-24 18:19:05 +0900997 float toY;
Jorim Jaggi09072002016-03-25 16:48:42 -0700998 final float pivotX;
999 final float pivotY;
Manu Cornetd7376802017-01-13 13:44:07 -08001000 if (shouldScaleDownThumbnailTransition(uiMode, orientation)) {
Jorim Jaggi09072002016-03-25 16:48:42 -07001001 fromX = mTmpRect.left;
1002 fromY = mTmpRect.top;
1003
1004 // For the curved translate animation to work, the pivot points needs to be at the
1005 // same absolute position as the one from the real surface.
1006 toX = mTmpRect.width() / 2 * (scaleW - 1f) + appRect.left;
1007 toY = appRect.height() / 2 * (1 - 1 / scaleW) + appRect.top;
1008 pivotX = mTmpRect.width() / 2;
1009 pivotY = appRect.height() / 2 / scaleW;
Manu Cornet57b61492017-01-24 18:19:05 +09001010 if (mGridLayoutRecentsEnabled) {
1011 // In the grid layout, the header is displayed above the thumbnail instead of
1012 // overlapping it.
1013 fromY -= thumbHeightI;
1014 toY -= thumbHeightI * scaleW;
1015 }
Jorim Jaggi09072002016-03-25 16:48:42 -07001016 } else {
1017 pivotX = 0;
1018 pivotY = 0;
1019 fromX = mTmpRect.left;
1020 fromY = mTmpRect.top;
1021 toX = appRect.left;
1022 toY = appRect.top;
1023 }
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001024 final long duration = getAspectScaleDuration();
1025 final Interpolator interpolator = getAspectScaleInterpolator();
Winson Chung399f6202014-03-19 10:47:20 -07001026 if (mNextAppTransitionScaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001027 // Animation up from the thumbnail to the full screen
Jorim Jaggi8448f332016-03-14 17:50:37 +01001028 Animation scale = new ScaleAnimation(1f, scaleW, 1f, scaleW, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001029 scale.setInterpolator(interpolator);
1030 scale.setDuration(duration);
Jorim Jaggic6c89a82016-01-28 17:48:21 -08001031 Animation alpha = new AlphaAnimation(1f, 0f);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001032 alpha.setInterpolator(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
1033 ? THUMBNAIL_DOCK_INTERPOLATOR : mThumbnailFadeOutInterpolator);
1034 alpha.setDuration(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
1035 ? duration / 2
1036 : duration);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001037 Animation translate = createCurvedMotion(fromX, toX, fromY, toY);
1038 translate.setInterpolator(interpolator);
1039 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -07001040
Jorim Jaggide63d442016-03-14 14:56:56 +01001041 mTmpFromClipRect.set(0, 0, thumbWidthI, thumbHeightI);
1042 mTmpToClipRect.set(appRect);
1043
1044 // Containing frame is in screen space, but we need the clip rect in the
1045 // app space.
1046 mTmpToClipRect.offsetTo(0, 0);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001047 mTmpToClipRect.right = (int) (mTmpToClipRect.right / scaleW);
1048 mTmpToClipRect.bottom = (int) (mTmpToClipRect.bottom / scaleW);
Jorim Jaggide63d442016-03-14 14:56:56 +01001049
1050 if (contentInsets != null) {
Jorim Jaggi8448f332016-03-14 17:50:37 +01001051 mTmpToClipRect.inset((int) (-contentInsets.left * scaleW),
1052 (int) (-contentInsets.top * scaleW),
1053 (int) (-contentInsets.right * scaleW),
1054 (int) (-contentInsets.bottom * scaleW));
Jorim Jaggide63d442016-03-14 14:56:56 +01001055 }
1056
1057 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001058 clipAnim.setInterpolator(interpolator);
1059 clipAnim.setDuration(duration);
Jorim Jaggide63d442016-03-14 14:56:56 +01001060
Winson Chung399f6202014-03-19 10:47:20 -07001061 // This AnimationSet uses the Interpolators assigned above.
1062 AnimationSet set = new AnimationSet(false);
1063 set.addAnimation(scale);
Manu Cornet57b61492017-01-24 18:19:05 +09001064 if (!mGridLayoutRecentsEnabled) {
1065 // In the grid layout, the header should be shown for the whole animation.
1066 set.addAnimation(alpha);
1067 }
Winson Chunga4ccb862014-08-22 15:26:27 -07001068 set.addAnimation(translate);
Jorim Jaggide63d442016-03-14 14:56:56 +01001069 set.addAnimation(clipAnim);
Winson Chung399f6202014-03-19 10:47:20 -07001070 a = set;
1071 } else {
Winson Chunga4ccb862014-08-22 15:26:27 -07001072 // Animation down from the full screen to the thumbnail
Jorim Jaggi8448f332016-03-14 17:50:37 +01001073 Animation scale = new ScaleAnimation(scaleW, 1f, scaleW, 1f, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001074 scale.setInterpolator(interpolator);
1075 scale.setDuration(duration);
Winson Chunga4ccb862014-08-22 15:26:27 -07001076 Animation alpha = new AlphaAnimation(0f, 1f);
1077 alpha.setInterpolator(mThumbnailFadeInInterpolator);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001078 alpha.setDuration(duration);
1079 Animation translate = createCurvedMotion(toX, fromX, toY, fromY);
1080 translate.setInterpolator(interpolator);
1081 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -07001082
Winson Chunga4ccb862014-08-22 15:26:27 -07001083 // This AnimationSet uses the Interpolators assigned above.
1084 AnimationSet set = new AnimationSet(false);
1085 set.addAnimation(scale);
Manu Cornet57b61492017-01-24 18:19:05 +09001086 if (!mGridLayoutRecentsEnabled) {
1087 // In the grid layout, the header should be shown for the whole animation.
1088 set.addAnimation(alpha);
1089 }
Winson Chunga4ccb862014-08-22 15:26:27 -07001090 set.addAnimation(translate);
1091 a = set;
1092
1093 }
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -07001094 return prepareThumbnailAnimationWithDuration(a, appWidth, appRect.height(), 0,
Jorim Jaggic69bd222016-03-15 14:38:37 +01001095 null);
Winson Chung399f6202014-03-19 10:47:20 -07001096 }
1097
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001098 private Animation createCurvedMotion(float fromX, float toX, float fromY, float toY) {
1099
1100 // Almost no x-change - use linear animation
Jorim Jaggic69bd222016-03-15 14:38:37 +01001101 if (Math.abs(toX - fromX) < 1f || mNextAppTransition != TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001102 return new TranslateAnimation(fromX, toX, fromY, toY);
1103 } else {
1104 final Path path = createCurvedPath(fromX, toX, fromY, toY);
1105 return new CurvedTranslateAnimation(path);
1106 }
1107 }
1108
1109 private Path createCurvedPath(float fromX, float toX, float fromY, float toY) {
1110 final Path path = new Path();
1111 path.moveTo(fromX, fromY);
Jorim Jaggi1f458fb2016-03-25 17:36:37 -07001112
1113 if (fromY > toY) {
1114 // If the object needs to go up, move it in horizontal direction first, then vertical.
1115 path.cubicTo(fromX, fromY, toX, 0.9f * fromY + 0.1f * toY, toX, toY);
1116 } else {
1117 // If the object needs to go down, move it in vertical direction first, then horizontal.
1118 path.cubicTo(fromX, fromY, fromX, 0.1f * fromY + 0.9f * toY, toX, toY);
1119 }
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001120 return path;
1121 }
1122
1123 private long getAspectScaleDuration() {
1124 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggic69bd222016-03-15 14:38:37 +01001125 return (long) (THUMBNAIL_APP_TRANSITION_DURATION * 1.35f);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001126 } else {
1127 return THUMBNAIL_APP_TRANSITION_DURATION;
1128 }
1129 }
1130
1131 private Interpolator getAspectScaleInterpolator() {
1132 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
1133 return mFastOutSlowInInterpolator;
1134 } else {
1135 return TOUCH_RESPONSE_INTERPOLATOR;
1136 }
1137 }
1138
Winson Chung399f6202014-03-19 10:47:20 -07001139 /**
1140 * This alternate animation is created when we are doing a thumbnail transition, for the
1141 * activity that is leaving, and the activity that is entering.
1142 */
Winson Chunga4ccb862014-08-22 15:26:27 -07001143 Animation createAspectScaledThumbnailEnterExitAnimationLocked(int thumbTransitState,
Winsonb2024762016-04-05 17:32:30 -07001144 int uiMode, int orientation, int transit, Rect containingFrame, Rect contentInsets,
Matthew Ng43db6d22017-06-27 15:29:39 -07001145 @Nullable Rect surfaceInsets, @Nullable Rect stableInsets, boolean freeform,
1146 int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -07001147 Animation a;
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001148 final int appWidth = containingFrame.width();
1149 final int appHeight = containingFrame.height();
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001150 getDefaultNextAppTransitionStartRect(mTmpRect);
1151 final int thumbWidthI = mTmpRect.width();
Winson Chung399f6202014-03-19 10:47:20 -07001152 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001153 final int thumbHeightI = mTmpRect.height();
Winson Chung399f6202014-03-19 10:47:20 -07001154 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
Winsoncbb625b2016-07-06 15:24:15 -07001155 final int thumbStartX = mTmpRect.left - containingFrame.left - contentInsets.left;
Winson21700932016-03-24 17:26:23 -07001156 final int thumbStartY = mTmpRect.top - containingFrame.top;
Winson Chung399f6202014-03-19 10:47:20 -07001157
1158 switch (thumbTransitState) {
Jorim Jaggi8448f332016-03-14 17:50:37 +01001159 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP:
1160 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1161 final boolean scaleUp = thumbTransitState == THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
1162 if (freeform && scaleUp) {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001163 a = createAspectScaledThumbnailEnterFreeformAnimationLocked(
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001164 containingFrame, surfaceInsets, taskId);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001165 } else if (freeform) {
1166 a = createAspectScaledThumbnailExitFreeformAnimationLocked(
1167 containingFrame, surfaceInsets, taskId);
Winson Chung2820c452014-04-15 15:34:44 -07001168 } else {
Winson21700932016-03-24 17:26:23 -07001169 AnimationSet set = new AnimationSet(true);
1170
1171 // In portrait, we scale to fit the width
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001172 mTmpFromClipRect.set(containingFrame);
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001173 mTmpToClipRect.set(containingFrame);
Jorim Jaggic6c89a82016-01-28 17:48:21 -08001174
1175 // Containing frame is in screen space, but we need the clip rect in the
1176 // app space.
1177 mTmpFromClipRect.offsetTo(0, 0);
1178 mTmpToClipRect.offsetTo(0, 0);
1179
1180 // Exclude insets region from the source clip.
1181 mTmpFromClipRect.inset(contentInsets);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001182 mNextAppTransitionInsets.set(contentInsets);
1183
Manu Cornetd7376802017-01-13 13:44:07 -08001184 if (shouldScaleDownThumbnailTransition(uiMode, orientation)) {
Jorim Jaggic69bd222016-03-15 14:38:37 +01001185 // We scale the width and clip to the top/left square
1186 float scale = thumbWidth /
1187 (appWidth - contentInsets.left - contentInsets.right);
Manu Cornetb68b7652017-01-23 19:37:53 +09001188 if (!mGridLayoutRecentsEnabled) {
1189 int unscaledThumbHeight = (int) (thumbHeight / scale);
1190 mTmpFromClipRect.bottom = mTmpFromClipRect.top + unscaledThumbHeight;
1191 }
Jorim Jaggic69bd222016-03-15 14:38:37 +01001192
1193 mNextAppTransitionInsets.set(contentInsets);
1194
Jorim Jaggi8448f332016-03-14 17:50:37 +01001195 Animation scaleAnim = new ScaleAnimation(
1196 scaleUp ? scale : 1, scaleUp ? 1 : scale,
1197 scaleUp ? scale : 1, scaleUp ? 1 : scale,
Jorim Jaggic69bd222016-03-15 14:38:37 +01001198 containingFrame.width() / 2f,
1199 containingFrame.height() / 2f + contentInsets.top);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001200 final float targetX = (mTmpRect.left - containingFrame.left);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001201 final float x = containingFrame.width() / 2f
1202 - containingFrame.width() / 2f * scale;
Jorim Jaggi8448f332016-03-14 17:50:37 +01001203 final float targetY = (mTmpRect.top - containingFrame.top);
Matthew Ng43db6d22017-06-27 15:29:39 -07001204 float y = containingFrame.height() / 2f
Jorim Jaggic69bd222016-03-15 14:38:37 +01001205 - containingFrame.height() / 2f * scale;
Matthew Ng43db6d22017-06-27 15:29:39 -07001206
1207 // During transition may require clipping offset from any top stable insets
1208 // such as the statusbar height when statusbar is hidden
1209 if (mLowRamRecentsEnabled && contentInsets.top == 0 && scaleUp) {
1210 mTmpFromClipRect.top += stableInsets.top;
1211 y += stableInsets.top;
1212 }
Jorim Jaggi8448f332016-03-14 17:50:37 +01001213 final float startX = targetX - x;
1214 final float startY = targetY - y;
1215 Animation clipAnim = scaleUp
1216 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1217 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1218 Animation translateAnim = scaleUp
Jorim Jaggic69bd222016-03-15 14:38:37 +01001219 ? createCurvedMotion(startX, 0, startY - contentInsets.top, 0)
1220 : createCurvedMotion(0, startX, 0, startY - contentInsets.top);
1221
Winson21700932016-03-24 17:26:23 -07001222 set.addAnimation(clipAnim);
1223 set.addAnimation(scaleAnim);
1224 set.addAnimation(translateAnim);
1225
1226 } else {
1227 // In landscape, we don't scale at all and only crop
1228 mTmpFromClipRect.bottom = mTmpFromClipRect.top + thumbHeightI;
1229 mTmpFromClipRect.right = mTmpFromClipRect.left + thumbWidthI;
1230
Jorim Jaggi8448f332016-03-14 17:50:37 +01001231 Animation clipAnim = scaleUp
1232 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1233 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1234 Animation translateAnim = scaleUp
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001235 ? createCurvedMotion(thumbStartX, 0,
1236 thumbStartY - contentInsets.top, 0)
1237 : createCurvedMotion(0, thumbStartX, 0,
1238 thumbStartY - contentInsets.top);
Winson21700932016-03-24 17:26:23 -07001239
1240 set.addAnimation(clipAnim);
1241 set.addAnimation(translateAnim);
1242 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001243 a = set;
Winson21700932016-03-24 17:26:23 -07001244 a.setZAdjustment(Animation.ZORDER_TOP);
Winson Chung2820c452014-04-15 15:34:44 -07001245 }
Winson Chung399f6202014-03-19 10:47:20 -07001246 break;
1247 }
1248 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001249 // Previous app window during the scale up
Winson Chung399f6202014-03-19 10:47:20 -07001250 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001251 // Fade out the source activity if we are animating to a wallpaper
Winson Chung399f6202014-03-19 10:47:20 -07001252 // activity.
1253 a = new AlphaAnimation(1, 0);
1254 } else {
Winson Chung399f6202014-03-19 10:47:20 -07001255 a = new AlphaAnimation(1, 1);
1256 }
1257 break;
1258 }
1259 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001260 // Target app window during the scale down
1261 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1262 // Fade in the destination activity if we are animating from a wallpaper
1263 // activity.
1264 a = new AlphaAnimation(0, 1);
1265 } else {
1266 a = new AlphaAnimation(1, 1);
1267 }
Winson Chung399f6202014-03-19 10:47:20 -07001268 break;
1269 }
Winson Chung399f6202014-03-19 10:47:20 -07001270 default:
1271 throw new RuntimeException("Invalid thumbnail transition state");
1272 }
1273
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001274 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight,
1275 getAspectScaleDuration(), getAspectScaleInterpolator());
Winson Chung399f6202014-03-19 10:47:20 -07001276 }
1277
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001278 private Animation createAspectScaledThumbnailEnterFreeformAnimationLocked(Rect frame,
1279 @Nullable Rect surfaceInsets, int taskId) {
1280 getNextAppTransitionStartRect(taskId, mTmpRect);
1281 return createAspectScaledThumbnailFreeformAnimationLocked(mTmpRect, frame, surfaceInsets,
1282 true);
1283 }
1284
1285 private Animation createAspectScaledThumbnailExitFreeformAnimationLocked(Rect frame,
1286 @Nullable Rect surfaceInsets, int taskId) {
1287 getNextAppTransitionStartRect(taskId, mTmpRect);
1288 return createAspectScaledThumbnailFreeformAnimationLocked(frame, mTmpRect, surfaceInsets,
1289 false);
1290 }
1291
1292 private AnimationSet createAspectScaledThumbnailFreeformAnimationLocked(Rect sourceFrame,
1293 Rect destFrame, @Nullable Rect surfaceInsets, boolean enter) {
1294 final float sourceWidth = sourceFrame.width();
1295 final float sourceHeight = sourceFrame.height();
1296 final float destWidth = destFrame.width();
1297 final float destHeight = destFrame.height();
1298 final float scaleH = enter ? sourceWidth / destWidth : destWidth / sourceWidth;
1299 final float scaleV = enter ? sourceHeight / destHeight : destHeight / sourceHeight;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001300 AnimationSet set = new AnimationSet(true);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001301 final int surfaceInsetsH = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001302 ? 0 : surfaceInsets.left + surfaceInsets.right;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001303 final int surfaceInsetsV = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001304 ? 0 : surfaceInsets.top + surfaceInsets.bottom;
1305 // We want the scaling to happen from the center of the surface. In order to achieve that,
1306 // we need to account for surface insets that will be used to enlarge the surface.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001307 final float scaleHCenter = ((enter ? destWidth : sourceWidth) + surfaceInsetsH) / 2;
1308 final float scaleVCenter = ((enter ? destHeight : sourceHeight) + surfaceInsetsV) / 2;
1309 final ScaleAnimation scale = enter ?
1310 new ScaleAnimation(scaleH, 1, scaleV, 1, scaleHCenter, scaleVCenter)
1311 : new ScaleAnimation(1, scaleH, 1, scaleV, scaleHCenter, scaleVCenter);
1312 final int sourceHCenter = sourceFrame.left + sourceFrame.width() / 2;
1313 final int sourceVCenter = sourceFrame.top + sourceFrame.height() / 2;
1314 final int destHCenter = destFrame.left + destFrame.width() / 2;
1315 final int destVCenter = destFrame.top + destFrame.height() / 2;
1316 final int fromX = enter ? sourceHCenter - destHCenter : destHCenter - sourceHCenter;
1317 final int fromY = enter ? sourceVCenter - destVCenter : destVCenter - sourceVCenter;
1318 final TranslateAnimation translation = enter ? new TranslateAnimation(fromX, 0, fromY, 0)
1319 : new TranslateAnimation(0, fromX, 0, fromY);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001320 set.addAnimation(scale);
1321 set.addAnimation(translation);
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001322
1323 final IRemoteCallback callback = mAnimationFinishedCallback;
1324 if (callback != null) {
1325 set.setAnimationListener(new Animation.AnimationListener() {
1326 @Override
1327 public void onAnimationStart(Animation animation) { }
1328
1329 @Override
1330 public void onAnimationEnd(Animation animation) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001331 mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK, callback).sendToTarget();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001332 }
1333
1334 @Override
1335 public void onAnimationRepeat(Animation animation) { }
1336 });
1337 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001338 return set;
1339 }
1340
Winson Chung399f6202014-03-19 10:47:20 -07001341 /**
Winson Chunga4ccb862014-08-22 15:26:27 -07001342 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001343 * when a thumbnail is specified with the pending animation override.
Winson Chunga4ccb862014-08-22 15:26:27 -07001344 */
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001345 Animation createThumbnailScaleAnimationLocked(int appWidth, int appHeight, int transit,
Winson Chungaa7fa012017-05-24 15:50:06 -07001346 GraphicBuffer thumbnailHeader) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001347 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001348 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001349 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chunga4ccb862014-08-22 15:26:27 -07001350 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001351 final int thumbHeightI = thumbnailHeader.getHeight();
Winson Chunga4ccb862014-08-22 15:26:27 -07001352 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1353
1354 if (mNextAppTransitionScaleUp) {
1355 // Animation for the thumbnail zooming from its initial size to the full screen
1356 float scaleW = appWidth / thumbWidth;
1357 float scaleH = appHeight / thumbHeight;
1358 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001359 computePivot(mTmpRect.left, 1 / scaleW),
1360 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001361 scale.setInterpolator(mDecelerateInterpolator);
1362
1363 Animation alpha = new AlphaAnimation(1, 0);
1364 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
1365
1366 // This AnimationSet uses the Interpolators assigned above.
1367 AnimationSet set = new AnimationSet(false);
1368 set.addAnimation(scale);
1369 set.addAnimation(alpha);
1370 a = set;
1371 } else {
1372 // Animation for the thumbnail zooming down from the full screen to its final size
1373 float scaleW = appWidth / thumbWidth;
1374 float scaleH = appHeight / thumbHeight;
1375 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001376 computePivot(mTmpRect.left, 1 / scaleW),
1377 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001378 }
1379
1380 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1381 }
1382
1383 /**
Winson Chung399f6202014-03-19 10:47:20 -07001384 * This animation is created when we are doing a thumbnail transition, for the activity that is
1385 * leaving, and the activity that is entering.
1386 */
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001387 Animation createThumbnailEnterExitAnimationLocked(int thumbTransitState, Rect containingFrame,
1388 int transit, int taskId) {
1389 final int appWidth = containingFrame.width();
1390 final int appHeight = containingFrame.height();
Winson Chungaa7fa012017-05-24 15:50:06 -07001391 final GraphicBuffer thumbnailHeader = getAppTransitionThumbnailHeader(taskId);
Winson Chung399f6202014-03-19 10:47:20 -07001392 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001393 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001394 final int thumbWidthI = thumbnailHeader != null ? thumbnailHeader.getWidth() : appWidth;
Winson Chung399f6202014-03-19 10:47:20 -07001395 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001396 final int thumbHeightI = thumbnailHeader != null ? thumbnailHeader.getHeight() : appHeight;
Winson Chung399f6202014-03-19 10:47:20 -07001397 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1398
1399 switch (thumbTransitState) {
1400 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
1401 // Entering app scales up with the thumbnail
1402 float scaleW = thumbWidth / appWidth;
1403 float scaleH = thumbHeight / appHeight;
1404 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001405 computePivot(mTmpRect.left, scaleW),
1406 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001407 break;
1408 }
1409 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
1410 // Exiting app while the thumbnail is scaling up should fade or stay in place
1411 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1412 // Fade out while bringing up selected activity. This keeps the
1413 // current activity from showing through a launching wallpaper
1414 // activity.
1415 a = new AlphaAnimation(1, 0);
1416 } else {
1417 // noop animation
1418 a = new AlphaAnimation(1, 1);
1419 }
1420 break;
1421 }
1422 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
1423 // Entering the other app, it should just be visible while we scale the thumbnail
1424 // down above it
1425 a = new AlphaAnimation(1, 1);
1426 break;
1427 }
1428 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1429 // Exiting the current app, the app should scale down with the thumbnail
1430 float scaleW = thumbWidth / appWidth;
1431 float scaleH = thumbHeight / appHeight;
1432 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001433 computePivot(mTmpRect.left, scaleW),
1434 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001435
1436 Animation alpha = new AlphaAnimation(1, 0);
1437
1438 AnimationSet set = new AnimationSet(true);
1439 set.addAnimation(scale);
1440 set.addAnimation(alpha);
1441 set.setZAdjustment(Animation.ZORDER_TOP);
1442 a = set;
1443 break;
1444 }
1445 default:
1446 throw new RuntimeException("Invalid thumbnail transition state");
1447 }
1448
1449 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1450 }
1451
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001452 private Animation createRelaunchAnimation(Rect containingFrame, Rect contentInsets) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001453 getDefaultNextAppTransitionStartRect(mTmpFromClipRect);
1454 final int left = mTmpFromClipRect.left;
1455 final int top = mTmpFromClipRect.top;
1456 mTmpFromClipRect.offset(-left, -top);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001457 // TODO: Isn't that strange that we ignore exact position of the containingFrame?
1458 mTmpToClipRect.set(0, 0, containingFrame.width(), containingFrame.height());
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001459 AnimationSet set = new AnimationSet(true);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001460 float fromWidth = mTmpFromClipRect.width();
1461 float toWidth = mTmpToClipRect.width();
1462 float fromHeight = mTmpFromClipRect.height();
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001463 // While the window might span the whole display, the actual content will be cropped to the
1464 // system decoration frame, for example when the window is docked. We need to take into
1465 // account the visible height when constructing the animation.
1466 float toHeight = mTmpToClipRect.height() - contentInsets.top - contentInsets.bottom;
1467 int translateAdjustment = 0;
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001468 if (fromWidth <= toWidth && fromHeight <= toHeight) {
1469 // The final window is larger in both dimensions than current window (e.g. we are
1470 // maximizing), so we can simply unclip the new window and there will be no disappearing
1471 // frame.
1472 set.addAnimation(new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect));
1473 } else {
1474 // The disappearing window has one larger dimension. We need to apply scaling, so the
1475 // first frame of the entry animation matches the old window.
1476 set.addAnimation(new ScaleAnimation(fromWidth / toWidth, 1, fromHeight / toHeight, 1));
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001477 // We might not be going exactly full screen, but instead be aligned under the status
1478 // bar using cropping. We still need to account for the cropped part, which will also
1479 // be scaled.
1480 translateAdjustment = (int) (contentInsets.top * fromHeight / toHeight);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001481 }
1482
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001483 // We animate the translation from the old position of the removed window, to the new
1484 // position of the added window. The latter might not be full screen, for example docked for
1485 // docked windows.
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001486 TranslateAnimation translate = new TranslateAnimation(left - containingFrame.left,
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001487 0, top - containingFrame.top - translateAdjustment, 0);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001488 set.addAnimation(translate);
1489 set.setDuration(DEFAULT_APP_TRANSITION_DURATION);
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07001490 set.setZAdjustment(Animation.ZORDER_TOP);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001491 return set;
1492 }
1493
Jorim Jaggic554b772015-06-04 16:07:57 -07001494 /**
1495 * @return true if and only if the first frame of the transition can be skipped, i.e. the first
1496 * frame of the transition doesn't change the visuals on screen, so we can start
1497 * directly with the second one
1498 */
1499 boolean canSkipFirstFrame() {
1500 return mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM
1501 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE
Jorim Jaggife762342016-10-13 14:33:27 +02001502 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CLIP_REVEAL
1503 && mNextAppTransition != TRANSIT_KEYGUARD_GOING_AWAY;
Jorim Jaggic554b772015-06-04 16:07:57 -07001504 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001505
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001506 /**
1507 *
1508 * @param frame These are the bounds of the window when it finishes the animation. This is where
1509 * the animation must usually finish in entrance animation, as the next frame will
1510 * display the window at these coordinates. In case of exit animation, this is
1511 * where the animation must start, as the frame before the animation is displaying
1512 * the window at these bounds.
1513 * @param insets Knowing where the window will be positioned is not enough. Some parts of the
1514 * window might be obscured, usually by the system windows (status bar and
1515 * navigation bar) and we use content insets to convey that information. This
1516 * usually affects the animation aspects vertically, as the system decoration is
1517 * at the top and the bottom. For example when we animate from full screen to
1518 * recents, we want to exclude the covered parts, because they won't match the
1519 * thumbnail after the last frame is executed.
1520 * @param surfaceInsets In rare situation the surface is larger than the content and we need to
1521 * know about this to make the animation frames match. We currently use
1522 * this for freeform windows, which have larger surfaces to display
1523 * shadows. When we animate them from recents, we want to match the content
1524 * to the recents thumbnail and hence need to account for the surface being
1525 * bigger.
1526 */
Winsonb2024762016-04-05 17:32:30 -07001527 Animation loadAnimation(WindowManager.LayoutParams lp, int transit, boolean enter, int uiMode,
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001528 int orientation, Rect frame, Rect displayFrame, Rect insets,
Matthew Ng43db6d22017-06-27 15:29:39 -07001529 @Nullable Rect surfaceInsets, @Nullable Rect stableInsets, boolean isVoiceInteraction,
1530 boolean freeform, int taskId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001531 Animation a;
Jorim Jaggife762342016-10-13 14:33:27 +02001532 if (isKeyguardGoingAwayTransit(transit) && enter) {
1533 a = loadKeyguardExitAnimation(transit);
1534 } else if (transit == TRANSIT_KEYGUARD_OCCLUDE) {
1535 a = null;
1536 } else if (transit == TRANSIT_KEYGUARD_UNOCCLUDE && !enter) {
1537 a = loadAnimationRes(lp, com.android.internal.R.anim.wallpaper_open_exit);
1538 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_OPEN
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001539 || transit == TRANSIT_TASK_OPEN
1540 || transit == TRANSIT_TASK_TO_FRONT)) {
1541 a = loadAnimationRes(lp, enter
1542 ? com.android.internal.R.anim.voice_activity_open_enter
1543 : com.android.internal.R.anim.voice_activity_open_exit);
1544 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1545 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001546 + " anim=" + a + " transit=" + appTransitionToString(transit)
1547 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001548 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_CLOSE
1549 || transit == TRANSIT_TASK_CLOSE
1550 || transit == TRANSIT_TASK_TO_BACK)) {
1551 a = loadAnimationRes(lp, enter
1552 ? com.android.internal.R.anim.voice_activity_close_enter
1553 : com.android.internal.R.anim.voice_activity_close_exit);
1554 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1555 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001556 + " anim=" + a + " transit=" + appTransitionToString(transit)
1557 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001558 } else if (transit == TRANSIT_ACTIVITY_RELAUNCH) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001559 a = createRelaunchAnimation(frame, insets);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001560 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1561 "applyAnimation:"
1562 + " anim=" + a + " nextAppTransition=" + mNextAppTransition
1563 + " transit=" + appTransitionToString(transit)
1564 + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001565 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM) {
1566 a = loadAnimationRes(mNextAppTransitionPackage, enter ?
Craig Mautner164d4bb2012-11-26 13:51:23 -08001567 mNextAppTransitionEnter : mNextAppTransitionExit);
1568 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1569 "applyAnimation:"
1570 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001571 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001572 + " Callers=" + Debug.getCallers(3));
Winson Chung044d5292014-11-06 11:05:19 -08001573 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE) {
1574 a = loadAnimationRes(mNextAppTransitionPackage, mNextAppTransitionInPlace);
1575 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1576 "applyAnimation:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001577 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM_IN_PLACE"
1578 + " transit=" + appTransitionToString(transit)
1579 + " Callers=" + Debug.getCallers(3));
Chet Haase10e23ab2015-02-11 15:08:38 -08001580 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001581 a = createClipRevealAnimationLocked(transit, enter, frame, displayFrame);
Chet Haase10e23ab2015-02-11 15:08:38 -08001582 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1583 "applyAnimation:"
1584 + " anim=" + a + " nextAppTransition=ANIM_CLIP_REVEAL"
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001585 + " transit=" + appTransitionToString(transit)
Chet Haase10e23ab2015-02-11 15:08:38 -08001586 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001587 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_SCALE_UP) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001588 a = createScaleUpAnimationLocked(transit, enter, frame);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001589 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1590 "applyAnimation:"
1591 + " anim=" + a + " nextAppTransition=ANIM_SCALE_UP"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001592 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001593 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001594 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
1595 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001596 mNextAppTransitionScaleUp =
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001597 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP);
Winson Chunga4ccb862014-08-22 15:26:27 -07001598 a = createThumbnailEnterExitAnimationLocked(getThumbnailTransitionState(enter),
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001599 frame, transit, taskId);
Winson Chunga4ccb862014-08-22 15:26:27 -07001600 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1601 String animName = mNextAppTransitionScaleUp ?
1602 "ANIM_THUMBNAIL_SCALE_UP" : "ANIM_THUMBNAIL_SCALE_DOWN";
1603 Slog.v(TAG, "applyAnimation:"
1604 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001605 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Winson Chunga4ccb862014-08-22 15:26:27 -07001606 + " Callers=" + Debug.getCallers(3));
1607 }
1608 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
1609 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN) {
1610 mNextAppTransitionScaleUp =
1611 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP);
1612 a = createAspectScaledThumbnailEnterExitAnimationLocked(
Winsonb2024762016-04-05 17:32:30 -07001613 getThumbnailTransitionState(enter), uiMode, orientation, transit, frame,
Matthew Ng43db6d22017-06-27 15:29:39 -07001614 insets, surfaceInsets, stableInsets, freeform, taskId);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001615 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1616 String animName = mNextAppTransitionScaleUp ?
Winson Chunga4ccb862014-08-22 15:26:27 -07001617 "ANIM_THUMBNAIL_ASPECT_SCALE_UP" : "ANIM_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner164d4bb2012-11-26 13:51:23 -08001618 Slog.v(TAG, "applyAnimation:"
1619 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001620 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001621 + " Callers=" + Debug.getCallers(3));
1622 }
Tony Mak089c35e2017-12-18 20:34:14 +00001623 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS
1624 && (transit == TRANSIT_ACTIVITY_OPEN
1625 || transit == TRANSIT_TASK_OPEN
1626 || transit == TRANSIT_TASK_TO_FRONT)) {
1627 a = loadAnimationRes("android", enter
1628 ? com.android.internal.R.anim.activity_open_enter
1629 : com.android.internal.R.anim.activity_open_exit);
1630 Slog.v(TAG,
1631 "applyAnimation NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS:"
1632 + " anim=" + a + " transit=" + appTransitionToString(transit)
1633 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Craig Mautner164d4bb2012-11-26 13:51:23 -08001634 } else {
1635 int animAttr = 0;
1636 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001637 case TRANSIT_ACTIVITY_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001638 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001639 ? WindowAnimation_activityOpenEnterAnimation
1640 : WindowAnimation_activityOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001641 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001642 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001643 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001644 ? WindowAnimation_activityCloseEnterAnimation
1645 : WindowAnimation_activityCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001646 break;
Jorim Jaggi192086e2016-03-11 17:17:03 +01001647 case TRANSIT_DOCK_TASK_FROM_RECENTS:
Craig Mautner4b71aa12012-12-27 17:20:01 -08001648 case TRANSIT_TASK_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001649 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001650 ? WindowAnimation_taskOpenEnterAnimation
1651 : WindowAnimation_taskOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001652 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001653 case TRANSIT_TASK_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001654 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001655 ? WindowAnimation_taskCloseEnterAnimation
1656 : WindowAnimation_taskCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001657 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001658 case TRANSIT_TASK_TO_FRONT:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001659 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001660 ? WindowAnimation_taskToFrontEnterAnimation
1661 : WindowAnimation_taskToFrontExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001662 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001663 case TRANSIT_TASK_TO_BACK:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001664 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001665 ? WindowAnimation_taskToBackEnterAnimation
1666 : WindowAnimation_taskToBackExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001667 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001668 case TRANSIT_WALLPAPER_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001669 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001670 ? WindowAnimation_wallpaperOpenEnterAnimation
1671 : WindowAnimation_wallpaperOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001672 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001673 case TRANSIT_WALLPAPER_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001674 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001675 ? WindowAnimation_wallpaperCloseEnterAnimation
1676 : WindowAnimation_wallpaperCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001677 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001678 case TRANSIT_WALLPAPER_INTRA_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001679 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001680 ? WindowAnimation_wallpaperIntraOpenEnterAnimation
1681 : WindowAnimation_wallpaperIntraOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001682 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001683 case TRANSIT_WALLPAPER_INTRA_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001684 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001685 ? WindowAnimation_wallpaperIntraCloseEnterAnimation
1686 : WindowAnimation_wallpaperIntraCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001687 break;
Craig Mautnerbb742462014-07-07 15:28:55 -07001688 case TRANSIT_TASK_OPEN_BEHIND:
1689 animAttr = enter
1690 ? WindowAnimation_launchTaskBehindSourceAnimation
Craig Mautner3b2cd1d2014-08-25 14:25:54 -07001691 : WindowAnimation_launchTaskBehindTargetAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001692 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001693 a = animAttr != 0 ? loadAnimationAttr(lp, animAttr) : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001694 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1695 "applyAnimation:"
1696 + " anim=" + a
1697 + " animAttr=0x" + Integer.toHexString(animAttr)
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001698 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001699 + " Callers=" + Debug.getCallers(3));
1700 }
1701 return a;
1702 }
1703
Jorim Jaggife762342016-10-13 14:33:27 +02001704 private Animation loadKeyguardExitAnimation(int transit) {
1705 if ((mNextAppTransitionFlags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_NO_ANIMATION) != 0) {
1706 return null;
1707 }
1708 final boolean toShade =
1709 (mNextAppTransitionFlags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_TO_SHADE) != 0;
1710 return mService.mPolicy.createHiddenByKeyguardExit(
1711 transit == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER, toShade);
1712 }
1713
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001714 int getAppStackClipMode() {
Matthew Ngbf1d9852017-03-14 12:23:09 -07001715 // When dismiss keyguard animation occurs, clip before the animation to prevent docked
1716 // app from showing beyond the divider
1717 if (mNextAppTransition == TRANSIT_KEYGUARD_GOING_AWAY
1718 || mNextAppTransition == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER) {
1719 return STACK_CLIP_BEFORE_ANIM;
1720 }
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001721 return mNextAppTransition == TRANSIT_ACTIVITY_RELAUNCH
Jorim Jaggic69bd222016-03-15 14:38:37 +01001722 || mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
Jorim Jaggi1f458fb2016-03-25 17:36:37 -07001723 || mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001724 ? STACK_CLIP_NONE
1725 : STACK_CLIP_AFTER_ANIM;
1726 }
1727
Jorim Jaggife762342016-10-13 14:33:27 +02001728 public int getTransitFlags() {
1729 return mNextAppTransitionFlags;
1730 }
1731
Craig Mautner164d4bb2012-11-26 13:51:23 -08001732 void postAnimationCallback() {
1733 if (mNextAppTransitionCallback != null) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001734 mService.mH.sendMessage(mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK,
1735 mNextAppTransitionCallback));
Craig Mautner164d4bb2012-11-26 13:51:23 -08001736 mNextAppTransitionCallback = null;
1737 }
1738 }
1739
1740 void overridePendingAppTransition(String packageName, int enterAnim, int exitAnim,
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001741 IRemoteCallback startedCallback) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001742 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001743 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001744 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001745 mNextAppTransitionPackage = packageName;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001746 mNextAppTransitionEnter = enterAnim;
1747 mNextAppTransitionExit = exitAnim;
1748 postAnimationCallback();
1749 mNextAppTransitionCallback = startedCallback;
1750 } else {
1751 postAnimationCallback();
1752 }
1753 }
1754
1755 void overridePendingAppTransitionScaleUp(int startX, int startY, int startWidth,
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001756 int startHeight) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001757 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001758 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001759 mNextAppTransitionType = NEXT_TRANSIT_TYPE_SCALE_UP;
Winson4c3fecd2016-07-13 12:29:48 -07001760 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001761 postAnimationCallback();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001762 }
1763 }
1764
Chet Haase10e23ab2015-02-11 15:08:38 -08001765 void overridePendingAppTransitionClipReveal(int startX, int startY,
1766 int startWidth, int startHeight) {
1767 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001768 clear();
Chet Haase10e23ab2015-02-11 15:08:38 -08001769 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CLIP_REVEAL;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001770 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Chet Haase10e23ab2015-02-11 15:08:38 -08001771 postAnimationCallback();
Chet Haase10e23ab2015-02-11 15:08:38 -08001772 }
1773 }
1774
Winson Chungaa7fa012017-05-24 15:50:06 -07001775 void overridePendingAppTransitionThumb(GraphicBuffer srcThumb, int startX, int startY,
Craig Mautner164d4bb2012-11-26 13:51:23 -08001776 IRemoteCallback startedCallback, boolean scaleUp) {
1777 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001778 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001779 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP
1780 : NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001781 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001782 putDefaultNextAppTransitionCoordinates(startX, startY, 0, 0, srcThumb);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001783 postAnimationCallback();
1784 mNextAppTransitionCallback = startedCallback;
1785 } else {
1786 postAnimationCallback();
1787 }
1788 }
1789
Winson Chungaa7fa012017-05-24 15:50:06 -07001790 void overridePendingAppTransitionAspectScaledThumb(GraphicBuffer srcThumb, int startX, int startY,
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001791 int targetWidth, int targetHeight, IRemoteCallback startedCallback, boolean scaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001792 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001793 clear();
Winson Chunga4ccb862014-08-22 15:26:27 -07001794 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1795 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Winson Chunga4ccb862014-08-22 15:26:27 -07001796 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001797 putDefaultNextAppTransitionCoordinates(startX, startY, targetWidth, targetHeight,
1798 srcThumb);
Winson Chunga4ccb862014-08-22 15:26:27 -07001799 postAnimationCallback();
1800 mNextAppTransitionCallback = startedCallback;
1801 } else {
1802 postAnimationCallback();
1803 }
1804 }
1805
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001806 public void overridePendingAppTransitionMultiThumb(AppTransitionAnimationSpec[] specs,
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001807 IRemoteCallback onAnimationStartedCallback, IRemoteCallback onAnimationFinishedCallback,
1808 boolean scaleUp) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001809 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001810 clear();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001811 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1812 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001813 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi43102412015-11-11 16:28:37 +01001814 if (specs != null) {
1815 for (int i = 0; i < specs.length; i++) {
1816 AppTransitionAnimationSpec spec = specs[i];
1817 if (spec != null) {
1818 mNextAppTransitionAnimationsSpecs.put(spec.taskId, spec);
1819 if (i == 0) {
1820 // In full screen mode, the transition code depends on the default spec
1821 // to be set.
1822 Rect rect = spec.rect;
1823 putDefaultNextAppTransitionCoordinates(rect.left, rect.top,
Winson Chungaa7fa012017-05-24 15:50:06 -07001824 rect.width(), rect.height(), spec.buffer);
Jorim Jaggi43102412015-11-11 16:28:37 +01001825 }
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001826 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001827 }
1828 }
1829 postAnimationCallback();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001830 mNextAppTransitionCallback = onAnimationStartedCallback;
1831 mAnimationFinishedCallback = onAnimationFinishedCallback;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001832 } else {
1833 postAnimationCallback();
1834 }
1835 }
1836
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001837 void overridePendingAppTransitionMultiThumbFuture(
1838 IAppTransitionAnimationSpecsFuture specsFuture, IRemoteCallback callback,
1839 boolean scaleUp) {
1840 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001841 clear();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001842 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1843 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001844 mNextAppTransitionAnimationsSpecsFuture = specsFuture;
1845 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001846 mNextAppTransitionFutureCallback = callback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001847 }
1848 }
1849
Winson Chung044d5292014-11-06 11:05:19 -08001850 void overrideInPlaceAppTransition(String packageName, int anim) {
1851 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001852 clear();
Winson Chung044d5292014-11-06 11:05:19 -08001853 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE;
1854 mNextAppTransitionPackage = packageName;
1855 mNextAppTransitionInPlace = anim;
1856 } else {
1857 postAnimationCallback();
1858 }
1859 }
1860
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001861 /**
Tony Mak089c35e2017-12-18 20:34:14 +00001862 * @see {@link #NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS}
1863 */
1864 void overridePendingAppTransitionStartCrossProfileApps() {
1865 if (isTransitionSet()) {
1866 clear();
1867 mNextAppTransitionType = NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS;
1868 postAnimationCallback();
1869 }
1870 }
1871
1872 /**
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001873 * If a future is set for the app transition specs, fetch it in another thread.
1874 */
1875 private void fetchAppTransitionSpecsFromFuture() {
1876 if (mNextAppTransitionAnimationsSpecsFuture != null) {
1877 mNextAppTransitionAnimationsSpecsPending = true;
1878 final IAppTransitionAnimationSpecsFuture future
1879 = mNextAppTransitionAnimationsSpecsFuture;
1880 mNextAppTransitionAnimationsSpecsFuture = null;
Jorim Jaggied410b62017-05-05 15:16:14 +02001881 mDefaultExecutor.execute(() -> {
1882 AppTransitionAnimationSpec[] specs = null;
1883 try {
1884 Binder.allowBlocking(future.asBinder());
1885 specs = future.get();
1886 } catch (RemoteException e) {
1887 Slog.w(TAG, "Failed to fetch app transition specs: " + e);
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001888 }
Jorim Jaggied410b62017-05-05 15:16:14 +02001889 synchronized (mService.mWindowMap) {
1890 mNextAppTransitionAnimationsSpecsPending = false;
1891 overridePendingAppTransitionMultiThumb(specs,
1892 mNextAppTransitionFutureCallback, null /* finishedCallback */,
1893 mNextAppTransitionScaleUp);
1894 mNextAppTransitionFutureCallback = null;
Jorim Jaggied410b62017-05-05 15:16:14 +02001895 }
1896 mService.requestTraversal();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001897 });
1898 }
1899 }
1900
Craig Mautner164d4bb2012-11-26 13:51:23 -08001901 @Override
1902 public String toString() {
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001903 return "mNextAppTransition=" + appTransitionToString(mNextAppTransition);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001904 }
1905
Craig Mautner4b71aa12012-12-27 17:20:01 -08001906 /**
1907 * Returns the human readable name of a window transition.
1908 *
1909 * @param transition The window transition.
1910 * @return The transition symbolic name.
1911 */
1912 public static String appTransitionToString(int transition) {
1913 switch (transition) {
1914 case TRANSIT_UNSET: {
1915 return "TRANSIT_UNSET";
1916 }
1917 case TRANSIT_NONE: {
1918 return "TRANSIT_NONE";
1919 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001920 case TRANSIT_ACTIVITY_OPEN: {
1921 return "TRANSIT_ACTIVITY_OPEN";
1922 }
1923 case TRANSIT_ACTIVITY_CLOSE: {
1924 return "TRANSIT_ACTIVITY_CLOSE";
1925 }
1926 case TRANSIT_TASK_OPEN: {
1927 return "TRANSIT_TASK_OPEN";
1928 }
1929 case TRANSIT_TASK_CLOSE: {
1930 return "TRANSIT_TASK_CLOSE";
1931 }
1932 case TRANSIT_TASK_TO_FRONT: {
1933 return "TRANSIT_TASK_TO_FRONT";
1934 }
1935 case TRANSIT_TASK_TO_BACK: {
1936 return "TRANSIT_TASK_TO_BACK";
1937 }
1938 case TRANSIT_WALLPAPER_CLOSE: {
1939 return "TRANSIT_WALLPAPER_CLOSE";
1940 }
1941 case TRANSIT_WALLPAPER_OPEN: {
1942 return "TRANSIT_WALLPAPER_OPEN";
1943 }
1944 case TRANSIT_WALLPAPER_INTRA_OPEN: {
1945 return "TRANSIT_WALLPAPER_INTRA_OPEN";
1946 }
1947 case TRANSIT_WALLPAPER_INTRA_CLOSE: {
1948 return "TRANSIT_WALLPAPER_INTRA_CLOSE";
1949 }
Craig Mautnerbb742462014-07-07 15:28:55 -07001950 case TRANSIT_TASK_OPEN_BEHIND: {
1951 return "TRANSIT_TASK_OPEN_BEHIND";
1952 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001953 case TRANSIT_ACTIVITY_RELAUNCH: {
1954 return "TRANSIT_ACTIVITY_RELAUNCH";
1955 }
Jorim Jaggi192086e2016-03-11 17:17:03 +01001956 case TRANSIT_DOCK_TASK_FROM_RECENTS: {
1957 return "TRANSIT_DOCK_TASK_FROM_RECENTS";
1958 }
Jorim Jaggife762342016-10-13 14:33:27 +02001959 case TRANSIT_KEYGUARD_GOING_AWAY: {
1960 return "TRANSIT_KEYGUARD_GOING_AWAY";
1961 }
1962 case TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER: {
1963 return "TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER";
1964 }
1965 case TRANSIT_KEYGUARD_OCCLUDE: {
1966 return "TRANSIT_KEYGUARD_OCCLUDE";
1967 }
1968 case TRANSIT_KEYGUARD_UNOCCLUDE: {
1969 return "TRANSIT_KEYGUARD_UNOCCLUDE";
1970 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001971 default: {
1972 return "<UNKNOWN>";
1973 }
1974 }
1975 }
1976
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001977 private String appStateToString() {
1978 switch (mAppTransitionState) {
1979 case APP_STATE_IDLE:
1980 return "APP_STATE_IDLE";
1981 case APP_STATE_READY:
1982 return "APP_STATE_READY";
1983 case APP_STATE_RUNNING:
1984 return "APP_STATE_RUNNING";
1985 case APP_STATE_TIMEOUT:
1986 return "APP_STATE_TIMEOUT";
1987 default:
1988 return "unknown state=" + mAppTransitionState;
1989 }
1990 }
1991
1992 private String transitTypeToString() {
1993 switch (mNextAppTransitionType) {
1994 case NEXT_TRANSIT_TYPE_NONE:
1995 return "NEXT_TRANSIT_TYPE_NONE";
1996 case NEXT_TRANSIT_TYPE_CUSTOM:
1997 return "NEXT_TRANSIT_TYPE_CUSTOM";
Winson Chung044d5292014-11-06 11:05:19 -08001998 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
1999 return "NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002000 case NEXT_TRANSIT_TYPE_SCALE_UP:
2001 return "NEXT_TRANSIT_TYPE_SCALE_UP";
2002 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
2003 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP";
2004 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
2005 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN";
Winson Chunga4ccb862014-08-22 15:26:27 -07002006 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
2007 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP";
2008 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN:
2009 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002010 default:
2011 return "unknown type=" + mNextAppTransitionType;
2012 }
2013 }
2014
Steven Timotiusaf03df62017-07-18 16:56:43 -07002015 void writeToProto(ProtoOutputStream proto, long fieldId) {
2016 final long token = proto.start(fieldId);
2017 proto.write(APP_TRANSITION_STATE, mAppTransitionState);
2018 proto.write(LAST_USED_APP_TRANSITION, mLastUsedAppTransition);
2019 proto.end(token);
2020 }
2021
Craig Mautner164d4bb2012-11-26 13:51:23 -08002022 @Override
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002023 public void dump(PrintWriter pw, String prefix) {
2024 pw.print(prefix); pw.println(this);
2025 pw.print(prefix); pw.print("mAppTransitionState="); pw.println(appStateToString());
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002026 if (mNextAppTransitionType != NEXT_TRANSIT_TYPE_NONE) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002027 pw.print(prefix); pw.print("mNextAppTransitionType=");
2028 pw.println(transitTypeToString());
Craig Mautner164d4bb2012-11-26 13:51:23 -08002029 }
2030 switch (mNextAppTransitionType) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002031 case NEXT_TRANSIT_TYPE_CUSTOM:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002032 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Craig Mautner164d4bb2012-11-26 13:51:23 -08002033 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002034 pw.print(prefix); pw.print("mNextAppTransitionEnter=0x");
Craig Mautner164d4bb2012-11-26 13:51:23 -08002035 pw.print(Integer.toHexString(mNextAppTransitionEnter));
2036 pw.print(" mNextAppTransitionExit=0x");
2037 pw.println(Integer.toHexString(mNextAppTransitionExit));
2038 break;
Winson Chung044d5292014-11-06 11:05:19 -08002039 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002040 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Winson Chung044d5292014-11-06 11:05:19 -08002041 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002042 pw.print(prefix); pw.print("mNextAppTransitionInPlace=0x");
Winson Chung044d5292014-11-06 11:05:19 -08002043 pw.print(Integer.toHexString(mNextAppTransitionInPlace));
2044 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002045 case NEXT_TRANSIT_TYPE_SCALE_UP: {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002046 getDefaultNextAppTransitionStartRect(mTmpRect);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002047 pw.print(prefix); pw.print("mNextAppTransitionStartX=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002048 pw.print(mTmpRect.left);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002049 pw.print(" mNextAppTransitionStartY=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002050 pw.println(mTmpRect.top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002051 pw.print(prefix); pw.print("mNextAppTransitionStartWidth=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002052 pw.print(mTmpRect.width());
Craig Mautner164d4bb2012-11-26 13:51:23 -08002053 pw.print(" mNextAppTransitionStartHeight=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07002054 pw.println(mTmpRect.height());
Craig Mautner164d4bb2012-11-26 13:51:23 -08002055 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002056 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -08002057 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
2058 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
Winson Chunga4ccb862014-08-22 15:26:27 -07002059 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002060 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN: {
2061 pw.print(prefix); pw.print("mDefaultNextAppTransitionAnimationSpec=");
2062 pw.println(mDefaultNextAppTransitionAnimationSpec);
2063 pw.print(prefix); pw.print("mNextAppTransitionAnimationsSpecs=");
2064 pw.println(mNextAppTransitionAnimationsSpecs);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002065 pw.print(prefix); pw.print("mNextAppTransitionScaleUp=");
2066 pw.println(mNextAppTransitionScaleUp);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002067 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07002068 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002069 }
2070 if (mNextAppTransitionCallback != null) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08002071 pw.print(prefix); pw.print("mNextAppTransitionCallback=");
2072 pw.println(mNextAppTransitionCallback);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002073 }
Chong Zhang60091a92016-07-27 17:52:45 -07002074 if (mLastUsedAppTransition != TRANSIT_NONE) {
2075 pw.print(prefix); pw.print("mLastUsedAppTransition=");
2076 pw.println(appTransitionToString(mLastUsedAppTransition));
2077 pw.print(prefix); pw.print("mLastOpeningApp=");
2078 pw.println(mLastOpeningApp);
2079 pw.print(prefix); pw.print("mLastClosingApp=");
2080 pw.println(mLastClosingApp);
2081 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002082 }
Amith Yamasani4befbec2013-07-10 16:18:01 -07002083
2084 public void setCurrentUser(int newUserId) {
2085 mCurrentUserId = newUserId;
2086 }
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002087
2088 /**
2089 * @return true if transition is not running and should not be skipped, false if transition is
2090 * already running
2091 */
Jorim Jaggife762342016-10-13 14:33:27 +02002092 boolean prepareAppTransitionLocked(int transit, boolean alwaysKeepCurrent, int flags,
2093 boolean forceOverride) {
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002094 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Prepare app transition:"
2095 + " transit=" + appTransitionToString(transit)
2096 + " " + this
2097 + " alwaysKeepCurrent=" + alwaysKeepCurrent
2098 + " Callers=" + Debug.getCallers(3));
Jorim Jaggife762342016-10-13 14:33:27 +02002099 if (forceOverride || isKeyguardTransit(transit) || !isTransitionSet()
2100 || mNextAppTransition == TRANSIT_NONE) {
2101 setAppTransition(transit, flags);
Jorim Jaggia69243a2017-06-15 15:10:38 -04002102 }
2103 // We never want to change from a Keyguard transit to a non-Keyguard transit, as our logic
2104 // relies on the fact that we always execute a Keyguard transition after preparing one.
2105 else if (!alwaysKeepCurrent && !isKeyguardTransit(transit)) {
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002106 if (transit == TRANSIT_TASK_OPEN && isTransitionEqual(TRANSIT_TASK_CLOSE)) {
2107 // Opening a new task always supersedes a close for the anim.
Jorim Jaggife762342016-10-13 14:33:27 +02002108 setAppTransition(transit, flags);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002109 } else if (transit == TRANSIT_ACTIVITY_OPEN
2110 && isTransitionEqual(TRANSIT_ACTIVITY_CLOSE)) {
2111 // Opening a new activity always supersedes a close for the anim.
Jorim Jaggife762342016-10-13 14:33:27 +02002112 setAppTransition(transit, flags);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002113 }
2114 }
2115 boolean prepared = prepare();
2116 if (isTransitionSet()) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08002117 mService.mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
2118 mService.mH.sendEmptyMessageDelayed(H.APP_TRANSITION_TIMEOUT, APP_TRANSITION_TIMEOUT_MS);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002119 }
2120 return prepared;
2121 }
Winsonb2024762016-04-05 17:32:30 -07002122
2123 /**
Jorim Jaggife762342016-10-13 14:33:27 +02002124 * @return true if {@param transit} is representing a transition in which Keyguard is going
2125 * away, false otherwise
2126 */
2127 public static boolean isKeyguardGoingAwayTransit(int transit) {
2128 return transit == TRANSIT_KEYGUARD_GOING_AWAY
2129 || transit == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER;
2130 }
2131
2132 private static boolean isKeyguardTransit(int transit) {
2133 return isKeyguardGoingAwayTransit(transit) || transit == TRANSIT_KEYGUARD_OCCLUDE
2134 || transit == TRANSIT_KEYGUARD_UNOCCLUDE;
2135 }
2136
2137 /**
Manu Cornetd7376802017-01-13 13:44:07 -08002138 * @return whether the transition should show the thumbnail being scaled down.
2139 */
2140 private boolean shouldScaleDownThumbnailTransition(int uiMode, int orientation) {
Sid Soundararajan0e88d322017-03-07 15:37:30 -08002141 return mGridLayoutRecentsEnabled
Manu Cornetd7376802017-01-13 13:44:07 -08002142 || orientation == Configuration.ORIENTATION_PORTRAIT;
2143 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002144}