blob: 08d0ae9dcdd8813415d32a74b1cc170fb1d02480 [file] [log] [blame]
Dianne Hackborn6e1eb762011-02-17 16:07:28 -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
Winson Chunge55c0192017-08-24 14:50:48 -070019import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
Jorim Jaggic6976f02018-04-18 16:31:07 +020020import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY;
Winson Chunge55c0192017-08-24 14:50:48 -070021import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;
Wale Ogunwale72919d22016-12-08 18:58:50 -080022import static android.content.pm.ActivityInfo.CONFIG_ORIENTATION;
23import static android.content.pm.ActivityInfo.CONFIG_SCREEN_SIZE;
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -070024import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND;
Wale Ogunwale51362492016-09-08 17:49:17 -070025import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET;
Jorim Jaggif5f9e122017-10-24 18:21:09 +020026import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070027import static android.view.Display.DEFAULT_DISPLAY;
Jorim Jaggife762342016-10-13 14:33:27 +020028import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
Jorim Jaggid635a4a2017-05-03 15:21:26 +020029import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
Jorim Jaggife762342016-10-13 14:33:27 +020030import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
Wale Ogunwaled1c37912016-08-16 03:19:39 -070031import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080032import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070033import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
Tony Mak64b8d562017-12-28 17:44:02 +000034
Jorim Jaggic6976f02018-04-18 16:31:07 +020035import static android.view.WindowManager.TRANSIT_WALLPAPER_OPEN;
Adrian Roose99bc052017-11-20 17:55:31 +010036import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
37import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Jorim Jaggif84e2f62018-01-16 14:17:59 +010038import static android.view.WindowManager.TRANSIT_UNSET;
chaviw4ad54912018-05-30 11:05:44 -070039
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080040import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080041import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
42import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070043import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070044import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
45import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
Wale Ogunwale9017ec02016-02-25 08:55:25 -080046import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
Jorim Jaggie4b0f282017-05-17 15:10:29 +020047import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW_VERBOSE;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070048import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TOKEN_MOVEMENT;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080049import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
50import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_MOVEMENT;
51import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
52import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Chong Zhang92147042016-05-09 12:47:11 -070053import static com.android.server.wm.WindowManagerService.H.NOTIFY_ACTIVITY_DRAWN;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070054import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070055import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070056import static com.android.server.wm.WindowManagerService.logWithStack;
Yi Jin6c6e9ca2018-03-20 16:53:35 -070057import static com.android.server.wm.AppWindowTokenProto.ALL_DRAWN;
58import static com.android.server.wm.AppWindowTokenProto.APP_STOPPED;
59import static com.android.server.wm.AppWindowTokenProto.CLIENT_HIDDEN;
60import static com.android.server.wm.AppWindowTokenProto.DEFER_HIDING_CLIENT;
61import static com.android.server.wm.AppWindowTokenProto.FILLS_PARENT;
62import static com.android.server.wm.AppWindowTokenProto.FROZEN_BOUNDS;
63import static com.android.server.wm.AppWindowTokenProto.HIDDEN_REQUESTED;
64import static com.android.server.wm.AppWindowTokenProto.HIDDEN_SET_FROM_TRANSFERRED_STARTING_WINDOW;
65import static com.android.server.wm.AppWindowTokenProto.IS_REALLY_ANIMATING;
66import static com.android.server.wm.AppWindowTokenProto.IS_WAITING_FOR_TRANSITION_START;
67import static com.android.server.wm.AppWindowTokenProto.LAST_ALL_DRAWN;
68import static com.android.server.wm.AppWindowTokenProto.LAST_SURFACE_SHOWING;
69import static com.android.server.wm.AppWindowTokenProto.NAME;
70import static com.android.server.wm.AppWindowTokenProto.NUM_DRAWN_WINDOWS;
71import static com.android.server.wm.AppWindowTokenProto.NUM_INTERESTING_WINDOWS;
72import static com.android.server.wm.AppWindowTokenProto.REMOVED;
73import static com.android.server.wm.AppWindowTokenProto.REPORTED_DRAWN;
74import static com.android.server.wm.AppWindowTokenProto.REPORTED_VISIBLE;
75import static com.android.server.wm.AppWindowTokenProto.STARTING_DISPLAYED;
76import static com.android.server.wm.AppWindowTokenProto.STARTING_MOVED;
77import static com.android.server.wm.AppWindowTokenProto.STARTING_WINDOW;
78import static com.android.server.wm.AppWindowTokenProto.THUMBNAIL;
79import static com.android.server.wm.AppWindowTokenProto.WINDOW_TOKEN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080080
Wale Ogunwale0d5609b2017-09-13 05:55:07 -070081import android.annotation.CallSuper;
Jorim Jaggid635a4a2017-05-03 15:21:26 +020082import android.app.Activity;
Jorim Jaggi26c8c422016-05-09 19:57:25 -070083import android.content.res.Configuration;
Jorim Jaggi988f6682017-11-17 17:46:43 +010084import android.graphics.GraphicBuffer;
Jorim Jaggif5f9e122017-10-24 18:21:09 +020085import android.graphics.Point;
Jorim Jaggi0429f352015-12-22 16:29:16 +010086import android.graphics.Rect;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070087import android.os.Binder;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080088import android.os.Debug;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070089import android.os.IBinder;
Steven Timotiusaf03df62017-07-18 16:56:43 -070090import android.os.RemoteException;
Jorim Jaggif5f9e122017-10-24 18:21:09 +020091import android.os.Trace;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080092import android.util.Slog;
Steven Timotiusaf03df62017-07-18 16:56:43 -070093import android.util.proto.ProtoOutputStream;
Jorim Jaggif5f9e122017-10-24 18:21:09 +020094import android.view.DisplayInfo;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080095import android.view.IApplicationToken;
Jorim Jaggif84e2f62018-01-16 14:17:59 +010096import android.view.RemoteAnimationDefinition;
Robert Carr6914f082017-03-20 19:04:30 -070097import android.view.SurfaceControl;
Tony Mak64b8d562017-12-28 17:44:02 +000098import android.view.SurfaceControl.Transaction;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080099import android.view.WindowManager;
Jorim Jaggi87fdbcb2017-08-17 13:41:11 +0200100import android.view.WindowManager.LayoutParams;
Tony Mak64b8d562017-12-28 17:44:02 +0000101import android.view.animation.Animation;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800102
Tony Mak64b8d562017-12-28 17:44:02 +0000103import com.android.internal.R;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800104import com.android.internal.util.ToBooleanFunction;
105import com.android.server.input.InputApplicationHandle;
Adrian Roose99bc052017-11-20 17:55:31 +0100106import com.android.server.policy.WindowManagerPolicy.StartingSurface;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800107import com.android.server.wm.WindowManagerService.H;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800108
109import java.io.PrintWriter;
Jorim Jaggi0429f352015-12-22 16:29:16 +0100110import java.util.ArrayDeque;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800111import java.util.ArrayList;
112
113class AppTokenList extends ArrayList<AppWindowToken> {
114}
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800115
116/**
117 * Version of WindowToken that is specifically for a particular application (or
118 * really activity) that is displaying windows.
119 */
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700120class AppWindowToken extends WindowToken implements WindowManagerService.AppFreezeListener {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800121 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppWindowToken" : TAG_WM;
122
Jorim Jaggi619c9f72017-12-19 18:04:29 +0100123 /**
124 * Value to increment the z-layer when boosting a layer during animations. BOOST in l33tsp34k.
125 */
126 private static final int Z_BOOST_BASE = 800570000;
127
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800128 // Non-null only for application tokens.
129 final IApplicationToken appToken;
130
Wale Ogunwale72919d22016-12-08 18:58:50 -0800131 final boolean mVoiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700132
Wale Ogunwale51362492016-09-08 17:49:17 -0700133 /** @see WindowContainer#fillsParent() */
134 private boolean mFillsParent;
Craig Mautner4c5eb222013-11-18 12:59:05 -0800135 boolean layoutConfigChanges;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800136 boolean mShowForAllUsers;
137 int mTargetSdk;
Craig Mautnera2c77052012-03-26 12:14:43 -0700138
Bryce Lee6d410262017-02-28 15:30:17 -0800139 // Flag set while reparenting to prevent actions normally triggered by an individual parent
140 // change.
141 private boolean mReparenting;
142
Wale Ogunwalee287e192017-04-21 09:30:12 -0700143 // True if we are current in the process of removing this app token from the display
144 private boolean mRemovingFromDisplay = false;
145
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800146 // The input dispatching timeout for this application token in nanoseconds.
Wale Ogunwale72919d22016-12-08 18:58:50 -0800147 long mInputDispatchingTimeoutNanos;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800148
149 // These are used for determining when all windows associated with
150 // an activity have been drawn, so they can be made visible together
151 // at the same time.
Craig Mautner764983d2012-03-22 11:37:36 -0700152 // initialize so that it doesn't match mTransactionSequence which is an int.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700153 private long mLastTransactionSequence = Long.MIN_VALUE;
154 private int mNumInterestingWindows;
155 private int mNumDrawnWindows;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800156 boolean inPendingTransaction;
157 boolean allDrawn;
Jorim Jaggib0fc8172017-11-23 17:04:08 +0000158 private boolean mLastAllDrawn;
159
Craig Mautner7636dfb2012-11-16 15:24:11 -0800160 // Set to true when this app creates a surface while in the middle of an animation. In that
161 // case do not clear allDrawn until the animation completes.
162 boolean deferClearAllDrawn;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800163
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800164 // Is this window's surface needed? This is almost like hidden, except
165 // it will sometimes be true a little earlier: when the token has
166 // been shown, but is still waiting for its app transition to execute
167 // before making its windows shown.
168 boolean hiddenRequested;
169
170 // Have we told the window clients to hide themselves?
Wale Ogunwale89973222017-04-23 18:39:45 -0700171 private boolean mClientHidden;
172
173 // If true we will defer setting mClientHidden to true and reporting to the client that it is
174 // hidden.
175 boolean mDeferHidingClient;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800176
177 // Last visibility state we reported to the app token.
178 boolean reportedVisible;
179
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700180 // Last drawn state we reported to the app token.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700181 private boolean reportedDrawn;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700182
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800183 // Set to true when the token has been removed from the window mgr.
184 boolean removed;
185
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800186 // Information about an application starting window if displayed.
187 StartingData startingData;
188 WindowState startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800189 StartingSurface startingSurface;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800190 boolean startingDisplayed;
191 boolean startingMoved;
Jorim Jaggi60f9c972018-02-01 19:21:07 +0100192
Wale Ogunwale6c459212017-05-17 08:56:03 -0700193 // True if the hidden state of this token was forced to false due to a transferred starting
194 // window.
195 private boolean mHiddenSetFromTransferredStartingWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800196 boolean firstWindowDrawn;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700197 private final WindowState.UpdateReportedVisibilityResults mReportedVisibilityResults =
198 new WindowState.UpdateReportedVisibilityResults();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800199
200 // Input application handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700201 final InputApplicationHandle mInputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800202
Wale Ogunwale571771c2016-08-26 13:18:50 -0700203 // TODO: Have a WindowContainer state for tracking exiting/deferred removal.
Craig Mautner799bc1d2015-01-14 10:33:48 -0800204 boolean mIsExiting;
Craig Mautner9ef471f2014-02-07 13:11:47 -0800205
Craig Mautnerbb742462014-07-07 15:28:55 -0700206 boolean mLaunchTaskBehind;
Craig Mautner8746a472014-07-24 15:12:54 -0700207 boolean mEnteringAnimation;
Craig Mautnerbb742462014-07-07 15:28:55 -0700208
Wale Ogunwale72919d22016-12-08 18:58:50 -0800209 private boolean mAlwaysFocusable;
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800210
Robert Carre12aece2016-02-02 22:43:27 -0800211 boolean mAppStopped;
Robert Carrfd10cd12016-06-29 16:41:50 -0700212 int mRotationAnimationHint;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700213 private int mPendingRelaunchCount;
Robert Carre12aece2016-02-02 22:43:27 -0800214
Jorim Jaggife762342016-10-13 14:33:27 +0200215 private boolean mLastContainsShowWhenLockedWindow;
216 private boolean mLastContainsDismissKeyguardWindow;
217
Jorim Jaggi0429f352015-12-22 16:29:16 +0100218 ArrayDeque<Rect> mFrozenBounds = new ArrayDeque<>();
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700219 ArrayDeque<Configuration> mFrozenMergedConfig = new ArrayDeque<>();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100220
Wale Ogunwale6c459212017-05-17 08:56:03 -0700221 private boolean mDisablePreviewScreenshots;
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +0100222
Wale Ogunwale034a8ec2017-09-02 17:14:40 -0700223 private Task mLastParent;
Robert Carred3e83b2017-04-21 13:26:55 -0700224
chaviwd3bf08d2017-08-01 17:24:59 -0700225 /**
226 * See {@link #canTurnScreenOn()}
227 */
228 private boolean mCanTurnScreenOn = true;
229
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200230 /**
231 * If we are running an animation, this determines the transition type. Must be one of
232 * AppTransition.TRANSIT_* constants.
233 */
234 private int mTransit;
235
236 /**
237 * If we are running an animation, this determines the flags during this animation. Must be a
238 * bitwise combination of AppTransition.TRANSIT_FLAG_* constants.
239 */
240 private int mTransitFlags;
241
242 /** Whether our surface was set to be showing in the last call to {@link #prepareSurfaces} */
Jorim Jaggifd1891462017-12-29 15:41:36 +0100243 private boolean mLastSurfaceShowing = true;
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200244
Jorim Jaggi988f6682017-11-17 17:46:43 +0100245 private AppWindowThumbnail mThumbnail;
246
Jorim Jaggib0fc8172017-11-23 17:04:08 +0000247 /** Have we been asked to have this token keep the screen frozen? */
248 private boolean mFreezingScreen;
249
250 /** Whether this token should be boosted at the top of all app window tokens. */
251 private boolean mNeedsZBoost;
Adrian Roos4d18a2e2017-12-19 19:08:05 +0100252 private Letterbox mLetterbox;
Jorim Jaggib0fc8172017-11-23 17:04:08 +0000253
chaviw23ee71c2017-12-18 11:29:41 -0800254 private final Point mTmpPoint = new Point();
chaviw23012112017-12-20 15:29:04 -0800255 private final Rect mTmpRect = new Rect();
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100256 private RemoteAnimationDefinition mRemoteAnimationDefinition;
Jorim Jaggi6de61012018-03-19 14:53:23 +0100257 private AnimatingAppWindowTokenRegistry mAnimatingAppWindowTokenRegistry;
chaviw23ee71c2017-12-18 11:29:41 -0800258
chaviw4ad54912018-05-30 11:05:44 -0700259 /**
260 * A flag to determine if this AWT is in the process of closing or entering PIP. This is needed
261 * to help AWT know that the app is in the process of closing but hasn't yet started closing on
262 * the WM side.
263 */
264 private boolean mWillCloseOrEnterPip;
265
Wale Ogunwale72919d22016-12-08 18:58:50 -0800266 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
267 DisplayContent dc, long inputDispatchingTimeoutNanos, boolean fullscreen,
268 boolean showForAllUsers, int targetSdk, int orientation, int rotationAnimationHint,
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800269 int configChanges, boolean launchTaskBehind, boolean alwaysFocusable,
Bryce Leef3c6a472017-11-14 14:53:06 -0800270 AppWindowContainerController controller) {
271 this(service, token, voiceInteraction, dc, fullscreen);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800272 setController(controller);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800273 mInputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800274 mShowForAllUsers = showForAllUsers;
275 mTargetSdk = targetSdk;
276 mOrientation = orientation;
277 layoutConfigChanges = (configChanges & (CONFIG_SCREEN_SIZE | CONFIG_ORIENTATION)) != 0;
278 mLaunchTaskBehind = launchTaskBehind;
279 mAlwaysFocusable = alwaysFocusable;
280 mRotationAnimationHint = rotationAnimationHint;
281
282 // Application tokens start out hidden.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200283 setHidden(true);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800284 hiddenRequested = true;
285 }
286
287 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
Bryce Leef3c6a472017-11-14 14:53:06 -0800288 DisplayContent dc, boolean fillsParent) {
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800289 super(service, token != null ? token.asBinder() : null, TYPE_APPLICATION, true, dc,
290 false /* ownerCanManageAppTokens */);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700291 appToken = token;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800292 mVoiceInteraction = voiceInteraction;
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800293 mFillsParent = fillsParent;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800294 mInputApplicationHandle = new InputApplicationHandle(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800295 }
296
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800297 void onFirstWindowDrawn(WindowState win, WindowStateAnimator winAnimator) {
298 firstWindowDrawn = true;
299
300 // We now have a good window to show, remove dead placeholders
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700301 removeDeadWindows();
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800302
Jorim Jaggi02886a82016-12-06 09:10:06 -0800303 if (startingWindow != null) {
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800304 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, "Finish starting "
305 + win.mToken + ": first real window is shown, no animation");
306 // If this initial window is animating, stop it -- we will do an animation to reveal
307 // it from behind the starting window, so there is no need for it to also be doing its
308 // own stuff.
Jorim Jaggia5e10572017-11-15 14:36:26 +0100309 win.cancelAnimation();
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800310 if (getController() != null) {
311 getController().removeStartingWindow();
312 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800313 }
314 updateReportedVisibilityLocked();
315 }
316
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800317 void updateReportedVisibilityLocked() {
318 if (appToken == null) {
319 return;
320 }
321
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700322 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700323 final int count = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800324
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700325 mReportedVisibilityResults.reset();
326
327 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700328 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700329 win.updateReportedVisibility(mReportedVisibilityResults);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800330 }
331
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700332 int numInteresting = mReportedVisibilityResults.numInteresting;
333 int numVisible = mReportedVisibilityResults.numVisible;
334 int numDrawn = mReportedVisibilityResults.numDrawn;
335 boolean nowGone = mReportedVisibilityResults.nowGone;
336
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700337 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200338 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting && !isHidden();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700339 if (!nowGone) {
340 // If the app is not yet gone, then it can only become visible/drawn.
341 if (!nowDrawn) {
342 nowDrawn = reportedDrawn;
343 }
344 if (!nowVisible) {
345 nowVisible = reportedVisible;
346 }
347 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800348 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800349 + numInteresting + " visible=" + numVisible);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800350 final AppWindowContainerController controller = getController();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700351 if (nowDrawn != reportedDrawn) {
352 if (nowDrawn) {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800353 if (controller != null) {
354 controller.reportWindowsDrawn();
355 }
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700356 }
357 reportedDrawn = nowDrawn;
358 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800359 if (nowVisible != reportedVisible) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700360 if (DEBUG_VISIBILITY) Slog.v(TAG,
361 "Visibility changed in " + this + ": vis=" + nowVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800362 reportedVisible = nowVisible;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800363 if (controller != null) {
364 if (nowVisible) {
365 controller.reportWindowsVisible();
366 } else {
367 controller.reportWindowsGone();
368 }
369 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800370 }
371 }
372
Wale Ogunwale89973222017-04-23 18:39:45 -0700373 boolean isClientHidden() {
374 return mClientHidden;
375 }
376
377 void setClientHidden(boolean hideClient) {
378 if (mClientHidden == hideClient || (hideClient && mDeferHidingClient)) {
379 return;
380 }
Jorim Jaggi067b5bf2018-02-23 17:42:39 +0100381 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setClientHidden: " + this
382 + " clientHidden=" + hideClient + " Callers=" + Debug.getCallers(5));
Wale Ogunwale89973222017-04-23 18:39:45 -0700383 mClientHidden = hideClient;
384 sendAppVisibilityToClients();
385 }
386
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700387 boolean setVisibility(WindowManager.LayoutParams lp,
388 boolean visible, int transit, boolean performLayout, boolean isVoiceInteraction) {
389
390 boolean delayed = false;
391 inPendingTransaction = false;
Wale Ogunwale9e4721f2017-05-23 19:37:30 -0700392 // Reset the state of mHiddenSetFromTransferredStartingWindow since visibility is actually
393 // been set by the app now.
394 mHiddenSetFromTransferredStartingWindow = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700395
396 // Allow for state changes and animation to be applied if:
397 // * token is transitioning visibility state
398 // * or the token was marked as hidden and is exiting before we had a chance to play the
399 // transition animation
400 // * or this is an opening app and windows are being replaced.
401 boolean visibilityChanged = false;
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200402 if (isHidden() == visible || (isHidden() && mIsExiting) || (visible && waitingForReplacement())) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700403 final AccessibilityController accessibilityController = mService.mAccessibilityController;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700404 boolean changed = false;
405 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200406 "Changing app " + this + " hidden=" + isHidden() + " performLayout=" + performLayout);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700407
408 boolean runningAppAnimation = false;
409
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100410 if (transit != WindowManager.TRANSIT_UNSET) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200411 if (applyAnimationLocked(lp, transit, visible, isVoiceInteraction)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700412 delayed = runningAppAnimation = true;
413 }
414 final WindowState window = findMainWindow();
415 //TODO (multidisplay): Magnification is supported only for the default display.
416 if (window != null && accessibilityController != null
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700417 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700418 accessibilityController.onAppWindowTransitionLocked(window, transit);
419 }
420 changed = true;
421 }
422
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700423 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700424 for (int i = 0; i < windowsCount; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700425 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700426 changed |= win.onAppVisibilityChanged(visible, runningAppAnimation);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700427 }
428
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200429 setHidden(!visible);
430 hiddenRequested = !visible;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700431 visibilityChanged = true;
432 if (!visible) {
433 stopFreezingScreen(true, true);
434 } else {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700435 // If we are being set visible, and the starting window is not yet displayed,
436 // then make sure it doesn't get displayed.
437 if (startingWindow != null && !startingWindow.isDrawnLw()) {
438 startingWindow.mPolicyVisibility = false;
439 startingWindow.mPolicyVisibilityAfterAnim = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700440 }
Jorim Jaggi38d44ec2017-06-14 16:04:59 -0700441
442 // We are becoming visible, so better freeze the screen with the windows that are
443 // getting visible so we also wait for them.
444 forAllWindows(mService::makeWindowFreezingScreenIfNeededLocked, true);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700445 }
446
447 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setVisibility: " + this
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200448 + ": hidden=" + isHidden() + " hiddenRequested=" + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700449
450 if (changed) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700451 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700452 if (performLayout) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700453 mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700454 false /*updateInputWindows*/);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700455 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700456 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700457 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700458 }
459 }
460
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200461 if (isReallyAnimating()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700462 delayed = true;
Jorim Jaggiab9fcb22018-03-15 23:46:12 +0100463 } else {
464
465 // We aren't animating anything, but exiting windows rely on the animation finished
466 // callback being called in case the AppWindowToken was pretending to be animating,
467 // which we might have done because we were in closing/opening apps list.
468 onAnimationFinished();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700469 }
470
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700471 for (int i = mChildren.size() - 1; i >= 0 && !delayed; i--) {
Jorim Jaggia5e10572017-11-15 14:36:26 +0100472 if ((mChildren.get(i)).isSelfOrChildAnimating()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700473 delayed = true;
474 }
475 }
476
477 if (visibilityChanged) {
478 if (visible && !delayed) {
479 // The token was made immediately visible, there will be no entrance animation.
480 // We need to inform the client the enter animation was finished.
481 mEnteringAnimation = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700482 mService.mActivityManagerAppTransitionNotifier.onAppTransitionFinishedLocked(token);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700483 }
Robert Carr61b81112017-07-17 18:08:15 -0700484
Jorim Jaggi110839b2018-01-22 12:49:04 +0100485 // If we're becoming visible, immediately change client visibility as well although it
486 // usually gets changed in AppWindowContainerController.setVisibility already. However,
487 // there seem to be some edge cases where we change our visibility but client visibility
488 // never gets updated.
489 // If we're becoming invisible, update the client visibility if we are not running an
490 // animation. Otherwise, we'll update client visibility in onAnimationFinished.
Jorim Jaggi3cad57f2018-02-20 18:32:01 +0100491 if (visible || !isReallyAnimating()) {
Jorim Jaggi110839b2018-01-22 12:49:04 +0100492 setClientHidden(!visible);
Jorim Jaggi4876b4a2018-01-11 15:43:49 +0100493 }
494
chaviwa953fcf2018-03-01 12:00:39 -0800495 if (!mService.mClosingApps.contains(this) && !mService.mOpeningApps.contains(this)) {
496 // The token is not closing nor opening, so even if there is an animation set, that
497 // doesn't mean that it goes through the normal app transition cycle so we have
498 // to inform the docked controller about visibility change.
499 // TODO(multi-display): notify docked divider on all displays where visibility was
500 // affected.
501 mService.getDefaultDisplayContentLocked().getDockedDividerController()
502 .notifyAppVisibilityChanged();
503
504 // Take the screenshot before possibly hiding the WSA, otherwise the screenshot
505 // will not be taken.
506 mService.mTaskSnapshotController.notifyAppVisibilityChanged(this, visible);
507 }
508
Robert Carre7cc44d2017-03-20 19:04:30 -0700509 // If we are hidden but there is no delay needed we immediately
510 // apply the Surface transaction so that the ActivityManager
Robert Carr61b81112017-07-17 18:08:15 -0700511 // can have some guarantee on the Surface state following
512 // setting the visibility. This captures cases like dismissing
513 // the docked or pinned stack where there is no app transition.
514 //
515 // In the case of a "Null" animation, there will be
516 // no animation but there will still be a transition set.
517 // We still need to delay hiding the surface such that it
518 // can be synchronized with showing the next surface in the transition.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200519 if (isHidden() && !delayed && !mService.mAppTransition.isTransitionSet()) {
Robert Carr6914f082017-03-20 19:04:30 -0700520 SurfaceControl.openTransaction();
521 for (int i = mChildren.size() - 1; i >= 0; i--) {
522 mChildren.get(i).mWinAnimator.hide("immediately hidden");
523 }
524 SurfaceControl.closeTransaction();
525 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700526 }
527
528 return delayed;
529 }
530
Jorim Jaggi87fdbcb2017-08-17 13:41:11 +0200531 /**
532 * @return The to top most child window for which {@link LayoutParams#isFullscreen()} returns
533 * true.
534 */
535 WindowState getTopFullscreenWindow() {
536 for (int i = mChildren.size() - 1; i >= 0; i--) {
537 final WindowState win = mChildren.get(i);
538 if (win != null && win.mAttrs.isFullscreen()) {
539 return win;
540 }
541 }
542 return null;
543 }
544
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800545 WindowState findMainWindow() {
Matthew Ng53e66b22018-01-12 17:13:13 -0800546 return findMainWindow(true);
547 }
548
549 /**
550 * Finds the main window that either has type base application or application starting if
551 * requested.
552 *
553 * @param includeStartingApp Allow to search application-starting windows to also be returned.
554 * @return The main window of type base application or application starting if requested.
555 */
556 WindowState findMainWindow(boolean includeStartingApp) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700557 WindowState candidate = null;
Matthew Ng53e66b22018-01-12 17:13:13 -0800558 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700559 final WindowState win = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700560 final int type = win.mAttrs.type;
561 // No need to loop through child window as base application and starting types can't be
562 // child windows.
Matthew Ng53e66b22018-01-12 17:13:13 -0800563 if (type == TYPE_BASE_APPLICATION
564 || (includeStartingApp && type == TYPE_APPLICATION_STARTING)) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700565 // In cases where there are multiple windows, we prefer the non-exiting window. This
Sungsoo Lim0d3d1f82015-12-02 14:47:59 +0900566 // happens for example when replacing windows during an activity relaunch. When
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700567 // constructing the animation, we want the new window, not the exiting one.
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800568 if (win.mAnimatingExit) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700569 candidate = win;
570 } else {
571 return win;
572 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800573 }
574 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700575 return candidate;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800576 }
577
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800578 boolean windowsAreFocusable() {
Wale Ogunwale3382ab12017-07-27 08:55:03 -0700579 return getWindowConfiguration().canReceiveKeys() || mAlwaysFocusable;
Wale Ogunwaled045c822015-12-02 09:14:28 -0800580 }
581
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800582 AppWindowContainerController getController() {
583 final WindowContainerController controller = super.getController();
584 return controller != null ? (AppWindowContainerController) controller : null;
585 }
586
Wale Ogunwale571771c2016-08-26 13:18:50 -0700587 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -0700588 boolean isVisible() {
Wale Ogunwalee471be62016-10-03 07:53:55 -0700589 // If the app token isn't hidden then it is considered visible and there is no need to check
590 // its children windows to see if they are visible.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200591 return !isHidden();
Wale Ogunwale44f21802016-09-02 12:49:48 -0700592 }
593
594 @Override
Wale Ogunwalee287e192017-04-21 09:30:12 -0700595 void removeImmediately() {
596 onRemovedFromDisplay();
597 super.removeImmediately();
598 }
599
600 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -0700601 void removeIfPossible() {
Craig Mautnere3119b72015-01-20 15:02:36 -0800602 mIsExiting = false;
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800603 removeAllWindowsIfPossible();
Bryce Lee6d410262017-02-28 15:30:17 -0800604 removeImmediately();
Craig Mautnere3119b72015-01-20 15:02:36 -0800605 }
606
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700607 @Override
608 boolean checkCompleteDeferredRemoval() {
609 if (mIsExiting) {
610 removeIfPossible();
611 }
612 return super.checkCompleteDeferredRemoval();
613 }
614
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700615 void onRemovedFromDisplay() {
Wale Ogunwalee287e192017-04-21 09:30:12 -0700616 if (mRemovingFromDisplay) {
617 return;
618 }
619 mRemovingFromDisplay = true;
620
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700621 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app token: " + this);
622
Wale Ogunwale72919d22016-12-08 18:58:50 -0800623 boolean delayed = setVisibility(null, false, TRANSIT_UNSET, true, mVoiceInteraction);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700624
625 mService.mOpeningApps.remove(this);
Jorim Jaggi45ca0542017-05-30 16:16:01 -0700626 mService.mUnknownAppVisibilityController.appRemovedOrHidden(this);
Jorim Jaggi10abe2f2017-01-03 16:44:46 +0100627 mService.mTaskSnapshotController.onAppRemoved(this);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700628 waitingToShow = false;
629 if (mService.mClosingApps.contains(this)) {
630 delayed = true;
631 } else if (mService.mAppTransition.isTransitionSet()) {
632 mService.mClosingApps.add(this);
633 delayed = true;
634 }
635
636 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app " + this + " delayed=" + delayed
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200637 + " animation=" + getAnimation() + " animating=" + isSelfAnimating());
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700638
639 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM, "removeAppToken: "
640 + this + " delayed=" + delayed + " Callers=" + Debug.getCallers(4));
641
Jorim Jaggi19be6052017-08-03 18:33:43 +0200642 if (startingData != null && getController() != null) {
643 getController().removeStartingWindow();
644 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800645
Winson Chung87e5d552017-04-05 11:49:38 -0700646 // If this window was animating, then we need to ensure that the app transition notifies
647 // that animations have completed in WMS.handleAnimatingStoppedAndTransitionLocked(), so
648 // add to that list now
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200649 if (isSelfAnimating()) {
Winson Chung87e5d552017-04-05 11:49:38 -0700650 mService.mNoAnimationNotifyOnTransitionFinished.add(token);
651 }
652
Wale Ogunwalee287e192017-04-21 09:30:12 -0700653 final TaskStack stack = getStack();
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700654 if (delayed && !isEmpty()) {
655 // set the token aside because it has an active animation to be finished
656 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM,
657 "removeAppToken make exiting: " + this);
Wale Ogunwalee287e192017-04-21 09:30:12 -0700658 if (stack != null) {
659 stack.mExitingAppTokens.add(this);
660 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700661 mIsExiting = true;
662 } else {
663 // Make sure there is no animation running on this token, so any windows associated
664 // with it will be removed as soon as their animations are complete
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200665 cancelAnimation();
Wale Ogunwale3106ae012017-05-16 08:56:37 -0700666 if (stack != null) {
667 stack.mExitingAppTokens.remove(this);
668 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700669 removeIfPossible();
670 }
671
672 removed = true;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700673 stopFreezingScreen(true, true);
Bryce Lee6d410262017-02-28 15:30:17 -0800674
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700675 if (mService.mFocusedApp == this) {
676 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "Removing focused app token:" + this);
677 mService.mFocusedApp = null;
678 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
679 mService.mInputMonitor.setFocusedAppLw(null);
680 }
681
682 if (!delayed) {
683 updateReportedVisibilityLocked();
684 }
Wale Ogunwalee287e192017-04-21 09:30:12 -0700685
686 mRemovingFromDisplay = false;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700687 }
688
Chong Zhange05bcb12016-07-26 17:47:29 -0700689 void clearAnimatingFlags() {
Chong Zhangb0d26702016-08-12 16:03:29 -0700690 boolean wallpaperMightChange = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700691 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700692 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700693 wallpaperMightChange |= win.clearAnimatingFlags();
Chong Zhange05bcb12016-07-26 17:47:29 -0700694 }
Chong Zhangb0d26702016-08-12 16:03:29 -0700695 if (wallpaperMightChange) {
696 requestUpdateWallpaperIfNeeded();
697 }
Chong Zhange05bcb12016-07-26 17:47:29 -0700698 }
699
Robert Carre12aece2016-02-02 22:43:27 -0800700 void destroySurfaces() {
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700701 destroySurfaces(false /*cleanupOnResume*/);
702 }
703
704 /**
705 * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure
706 * the client has finished with them.
707 *
708 * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If
709 * set to true, destroy only surfaces of removed windows, and clear relevant flags of the
710 * others so that they are ready to be reused. If set to false (common case), destroy all
711 * surfaces that's eligible, if the app is already stopped.
712 */
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700713 private void destroySurfaces(boolean cleanupOnResume) {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700714 boolean destroyedSomething = false;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100715
716 // Copying to a different list as multiple children can be removed.
Jorim Jaggi59f3e922018-01-05 15:40:32 +0100717 final ArrayList<WindowState> children = new ArrayList<>(mChildren);
Jorim Jaggia5e10572017-11-15 14:36:26 +0100718 for (int i = children.size() - 1; i >= 0; i--) {
719 final WindowState win = children.get(i);
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700720 destroyedSomething |= win.destroySurface(cleanupOnResume, mAppStopped);
Robert Carre12aece2016-02-02 22:43:27 -0800721 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700722 if (destroyedSomething) {
723 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700724 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Adrian Roos23df3a32018-03-15 15:41:13 +0100725 updateLetterboxSurface(null);
Robert Carre12aece2016-02-02 22:43:27 -0800726 }
727 }
728
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800729 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700730 * Notify that the app is now resumed, and it was not stopped before, perform a clean
731 * up of the surfaces
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800732 */
Jorim Jaggibae01b12017-04-11 16:29:10 -0700733 void notifyAppResumed(boolean wasStopped) {
Chong Zhangad24f962016-08-25 12:12:33 -0700734 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped
Jorim Jaggibae01b12017-04-11 16:29:10 -0700735 + " " + this);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700736 mAppStopped = false;
chaviwd3bf08d2017-08-01 17:24:59 -0700737 // Allow the window to turn the screen on once the app is resumed again.
738 setCanTurnScreenOn(true);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700739 if (!wasStopped) {
740 destroySurfaces(true /*cleanupOnResume*/);
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800741 }
Robert Carre12aece2016-02-02 22:43:27 -0800742 }
743
Chong Zhangbef461f2015-10-27 11:38:24 -0700744 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700745 * Notify that the app has stopped, and it is okay to destroy any surfaces which were
746 * keeping alive in case they were still being used.
747 */
748 void notifyAppStopped() {
749 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this);
750 mAppStopped = true;
751 destroySurfaces();
752 // Remove any starting window that was added for this app if they are still around.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800753 if (getController() != null) {
754 getController().removeStartingWindow();
755 }
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700756 }
757
Chong Zhang92147042016-05-09 12:47:11 -0700758 void clearAllDrawn() {
759 allDrawn = false;
760 deferClearAllDrawn = false;
Chong Zhangbef461f2015-10-27 11:38:24 -0700761 }
762
Bryce Lee6d410262017-02-28 15:30:17 -0800763 Task getTask() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800764 return (Task) getParent();
Bryce Lee6d410262017-02-28 15:30:17 -0800765 }
766
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800767 TaskStack getStack() {
768 final Task task = getTask();
769 if (task != null) {
770 return task.mStack;
771 } else {
772 return null;
773 }
774 }
775
Bryce Lee6d410262017-02-28 15:30:17 -0800776 @Override
777 void onParentSet() {
778 super.onParentSet();
779
Robert Carred3e83b2017-04-21 13:26:55 -0700780 final Task task = getTask();
781
Bryce Lee6d410262017-02-28 15:30:17 -0800782 // When the associated task is {@code null}, the {@link AppWindowToken} can no longer
783 // access visual elements like the {@link DisplayContent}. We must remove any associations
784 // such as animations.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800785 if (!mReparenting) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800786 if (task == null) {
787 // It is possible we have been marked as a closing app earlier. We must remove ourselves
788 // from this list so we do not participate in any future animations.
789 mService.mClosingApps.remove(this);
Robert Carred3e83b2017-04-21 13:26:55 -0700790 } else if (mLastParent != null && mLastParent.mStack != null) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800791 task.mStack.mExitingAppTokens.remove(this);
792 }
Bryce Lee6d410262017-02-28 15:30:17 -0800793 }
Jorim Jaggi6de61012018-03-19 14:53:23 +0100794 final TaskStack stack = getStack();
795
796 // If we reparent, make sure to remove ourselves from the old animation registry.
797 if (mAnimatingAppWindowTokenRegistry != null) {
798 mAnimatingAppWindowTokenRegistry.notifyFinished(this);
799 }
800 mAnimatingAppWindowTokenRegistry = stack != null
801 ? stack.getAnimatingAppWindowTokenRegistry()
802 : null;
803
Robert Carred3e83b2017-04-21 13:26:55 -0700804 mLastParent = task;
Bryce Lee6d410262017-02-28 15:30:17 -0800805 }
806
Wale Ogunwalefa854eb2016-09-20 13:43:52 -0700807 void postWindowRemoveStartingWindowCleanup(WindowState win) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700808 // TODO: Something smells about the code below...Is there a better way?
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700809 if (startingWindow == win) {
810 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800811 if (getController() != null) {
812 getController().removeStartingWindow();
813 }
Wale Ogunwale6c459212017-05-17 08:56:03 -0700814 } else if (mChildren.size() == 0) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700815 // If this is the last window and we had requested a starting transition window,
816 // well there is no point now.
Jorim Jaggi02886a82016-12-06 09:10:06 -0800817 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingData");
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700818 startingData = null;
Wale Ogunwale6c459212017-05-17 08:56:03 -0700819 if (mHiddenSetFromTransferredStartingWindow) {
820 // We set the hidden state to false for the token from a transferred starting window.
821 // We now reset it back to true since the starting window was the last window in the
822 // token.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200823 setHidden(true);
Wale Ogunwale6c459212017-05-17 08:56:03 -0700824 }
Jorim Jaggi829b9cd2017-01-23 16:20:53 +0100825 } else if (mChildren.size() == 1 && startingSurface != null && !isRelaunching()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700826 // If this is the last window except for a starting transition window,
827 // we need to get rid of the starting transition.
Jorim Jaggie4b0f282017-05-17 15:10:29 +0200828 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Last window, removing starting window "
829 + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800830 if (getController() != null) {
831 getController().removeStartingWindow();
832 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700833 }
834 }
835
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700836 void removeDeadWindows() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700837 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700838 WindowState win = mChildren.get(winNdx);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800839 if (win.mAppDied) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700840 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700841 "removeDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800842 // Set mDestroying, we don't want any animation or delayed removal here.
843 win.mDestroying = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700844 // Also removes child windows.
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700845 win.removeIfPossible();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800846 }
847 }
848 }
849
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700850 boolean hasWindowsAlive() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700851 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700852 // No need to loop through child windows as the answer should be the same as that of the
853 // parent window.
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700854 if (!(mChildren.get(i)).mAppDied) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700855 return true;
856 }
857 }
858 return false;
859 }
860
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700861 void setWillReplaceWindows(boolean animate) {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700862 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
863 "Marking app token " + this + " with replacing windows.");
Robert Carra1eb4392015-12-10 12:43:51 -0800864
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700865 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700866 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700867 w.setWillReplaceWindow(animate);
Robert Carra1eb4392015-12-10 12:43:51 -0800868 }
Robert Carra1eb4392015-12-10 12:43:51 -0800869 }
870
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700871 void setWillReplaceChildWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700872 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this
Robert Carr23fa16b2016-01-13 13:19:58 -0800873 + " with replacing child windows.");
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700874 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700875 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700876 w.setWillReplaceChildWindows();
Robert Carr23fa16b2016-01-13 13:19:58 -0800877 }
878 }
879
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700880 void clearWillReplaceWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700881 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
882 "Resetting app token " + this + " of replacing window marks.");
Chong Zhangf596cd52016-01-05 13:42:44 -0800883
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700884 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700885 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700886 w.clearWillReplaceWindow();
Chong Zhangf596cd52016-01-05 13:42:44 -0800887 }
888 }
889
Chong Zhang4d7369a2016-04-25 16:09:14 -0700890 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700891 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700892 final WindowState w = mChildren.get(i);
Chong Zhang4d7369a2016-04-25 16:09:14 -0700893 w.requestUpdateWallpaperIfNeeded();
894 }
895 }
896
Chong Zhangd78ddb42016-03-02 17:01:14 -0800897 boolean isRelaunching() {
898 return mPendingRelaunchCount > 0;
899 }
900
Robert Carr68375192017-06-13 12:41:53 -0700901 boolean shouldFreezeBounds() {
902 final Task task = getTask();
903
904 // For freeform windows, we can't freeze the bounds at the moment because this would make
905 // the resizing unresponsive.
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700906 if (task == null || task.inFreeformWindowingMode()) {
Robert Carr68375192017-06-13 12:41:53 -0700907 return false;
908 }
909
910 // We freeze the bounds while drag resizing to deal with the time between
911 // the divider/drag handle being released, and the handling it's new
912 // configuration. If we are relaunched outside of the drag resizing state,
913 // we need to be careful not to do this.
914 return getTask().isDragResizing();
915 }
916
Chong Zhangd78ddb42016-03-02 17:01:14 -0800917 void startRelaunching() {
Robert Carr68375192017-06-13 12:41:53 -0700918 if (shouldFreezeBounds()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -0800919 freezeBounds();
920 }
Robert Carrd5c7dd62017-03-08 10:39:30 -0800921
922 // In the process of tearing down before relaunching, the app will
923 // try and clean up it's child surfaces. We need to prevent this from
924 // happening, so we sever the children, transfering their ownership
925 // from the client it-self to the parent surface (owned by us).
Robert Carr29daa922018-04-27 11:56:48 -0700926 detachChildren();
927
928 mPendingRelaunchCount++;
929 }
930
931 void detachChildren() {
Robert Carrfd8e93b2018-05-10 13:40:25 -0700932 SurfaceControl.openTransaction();
Robert Carrd5c7dd62017-03-08 10:39:30 -0800933 for (int i = mChildren.size() - 1; i >= 0; i--) {
934 final WindowState w = mChildren.get(i);
935 w.mWinAnimator.detachChildren();
936 }
Robert Carrfd8e93b2018-05-10 13:40:25 -0700937 SurfaceControl.closeTransaction();
Chong Zhangd78ddb42016-03-02 17:01:14 -0800938 }
939
940 void finishRelaunching() {
Robert Carr68375192017-06-13 12:41:53 -0700941 unfreezeBounds();
942
Chong Zhangd78ddb42016-03-02 17:01:14 -0800943 if (mPendingRelaunchCount > 0) {
944 mPendingRelaunchCount--;
Bryce Lee081554b2017-05-25 07:52:12 -0700945 } else {
946 // Update keyguard flags upon finishing relaunch.
947 checkKeyguardFlagsChanged();
Chong Zhangd78ddb42016-03-02 17:01:14 -0800948 }
949 }
950
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700951 void clearRelaunching() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700952 if (mPendingRelaunchCount == 0) {
953 return;
954 }
Robert Carr68375192017-06-13 12:41:53 -0700955 unfreezeBounds();
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700956 mPendingRelaunchCount = 0;
957 }
958
Wale Ogunwale07bcab72016-10-14 15:30:09 -0700959 /**
960 * Returns true if the new child window we are adding to this token is considered greater than
961 * the existing child window in this token in terms of z-order.
962 */
963 @Override
964 protected boolean isFirstChildWindowGreaterThanSecond(WindowState newWindow,
965 WindowState existingWindow) {
966 final int type1 = newWindow.mAttrs.type;
967 final int type2 = existingWindow.mAttrs.type;
968
969 // Base application windows should be z-ordered BELOW all other windows in the app token.
970 if (type1 == TYPE_BASE_APPLICATION && type2 != TYPE_BASE_APPLICATION) {
971 return false;
972 } else if (type1 != TYPE_BASE_APPLICATION && type2 == TYPE_BASE_APPLICATION) {
973 return true;
974 }
975
976 // Starting windows should be z-ordered ABOVE all other windows in the app token.
977 if (type1 == TYPE_APPLICATION_STARTING && type2 != TYPE_APPLICATION_STARTING) {
978 return true;
979 } else if (type1 != TYPE_APPLICATION_STARTING && type2 == TYPE_APPLICATION_STARTING) {
980 return false;
981 }
982
983 // Otherwise the new window is greater than the existing window.
984 return true;
985 }
986
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700987 @Override
Robert Carra1eb4392015-12-10 12:43:51 -0800988 void addWindow(WindowState w) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700989 super.addWindow(w);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700990
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700991 boolean gotReplacementWindow = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700992 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700993 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700994 gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w);
995 }
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700996
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700997 // if we got a replacement window, reset the timeout to give drawing more time
998 if (gotReplacementWindow) {
999 mService.scheduleWindowReplacementTimeouts(this);
Robert Carra1eb4392015-12-10 12:43:51 -08001000 }
Jorim Jaggife762342016-10-13 14:33:27 +02001001 checkKeyguardFlagsChanged();
1002 }
1003
1004 @Override
1005 void removeChild(WindowState child) {
1006 super.removeChild(child);
1007 checkKeyguardFlagsChanged();
Adrian Roos23df3a32018-03-15 15:41:13 +01001008 updateLetterboxSurface(child);
Robert Carra1eb4392015-12-10 12:43:51 -08001009 }
1010
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001011 private boolean waitingForReplacement() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001012 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001013 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001014 if (candidate.waitingForReplacement()) {
Robert Carra1eb4392015-12-10 12:43:51 -08001015 return true;
1016 }
1017 }
1018 return false;
1019 }
1020
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001021 void onWindowReplacementTimeout() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001022 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001023 (mChildren.get(i)).onWindowReplacementTimeout();
Robert Carra1eb4392015-12-10 12:43:51 -08001024 }
1025 }
1026
Winson Chung30480042017-01-26 10:55:34 -08001027 void reparent(Task task, int position) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001028 final Task currentTask = getTask();
1029 if (task == currentTask) {
Winson Chung30480042017-01-26 10:55:34 -08001030 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001031 "window token=" + this + " already child of task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -08001032 }
Bryce Lee6d410262017-02-28 15:30:17 -08001033
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001034 if (currentTask.mStack != task.mStack) {
Bryce Lee6d410262017-02-28 15:30:17 -08001035 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001036 "window token=" + this + " current task=" + currentTask
Bryce Lee6d410262017-02-28 15:30:17 -08001037 + " belongs to a different stack than " + task);
1038 }
1039
Winson Chung30480042017-01-26 10:55:34 -08001040 if (DEBUG_ADD_REMOVE) Slog.i(TAG, "reParentWindowToken: removing window token=" + this
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001041 + " from task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -08001042 final DisplayContent prevDisplayContent = getDisplayContent();
1043
Bryce Lee6d410262017-02-28 15:30:17 -08001044 mReparenting = true;
1045
Winson Chung30480042017-01-26 10:55:34 -08001046 getParent().removeChild(this);
1047 task.addChild(this, position);
1048
Bryce Lee6d410262017-02-28 15:30:17 -08001049 mReparenting = false;
1050
Winson Chung30480042017-01-26 10:55:34 -08001051 // Relayout display(s).
1052 final DisplayContent displayContent = task.getDisplayContent();
1053 displayContent.setLayoutNeeded();
1054 if (prevDisplayContent != displayContent) {
1055 onDisplayChanged(displayContent);
1056 prevDisplayContent.setLayoutNeeded();
1057 }
1058 }
1059
Jorim Jaggi0429f352015-12-22 16:29:16 +01001060 /**
1061 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
1062 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
1063 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
1064 * with a queue.
1065 */
Chong Zhangd78ddb42016-03-02 17:01:14 -08001066 private void freezeBounds() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001067 final Task task = getTask();
1068 mFrozenBounds.offer(new Rect(task.mPreparedFrozenBounds));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001069
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001070 if (task.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) {
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001071 // We didn't call prepareFreezingBounds on the task, so use the current value.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001072 mFrozenMergedConfig.offer(new Configuration(task.getConfiguration()));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001073 } else {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001074 mFrozenMergedConfig.offer(new Configuration(task.mPreparedFrozenMergedConfig));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001075 }
Andrii Kulianb10330d2016-09-16 13:51:46 -07001076 // Calling unset() to make it equal to Configuration.EMPTY.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001077 task.mPreparedFrozenMergedConfig.unset();
Jorim Jaggi0429f352015-12-22 16:29:16 +01001078 }
1079
1080 /**
1081 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
1082 */
Chong Zhangd78ddb42016-03-02 17:01:14 -08001083 private void unfreezeBounds() {
Robert Carr68375192017-06-13 12:41:53 -07001084 if (mFrozenBounds.isEmpty()) {
1085 return;
Wale Ogunwale37dbafc2016-06-27 10:15:20 -07001086 }
Robert Carr68375192017-06-13 12:41:53 -07001087 mFrozenBounds.remove();
Wale Ogunwale37dbafc2016-06-27 10:15:20 -07001088 if (!mFrozenMergedConfig.isEmpty()) {
1089 mFrozenMergedConfig.remove();
1090 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001091 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001092 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001093 win.onUnfreezeBounds();
Jorim Jaggi4846ee32016-01-07 17:39:12 +01001094 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001095 mService.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +01001096 }
1097
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001098 void setAppLayoutChanges(int changes, String reason) {
1099 if (!mChildren.isEmpty()) {
1100 final DisplayContent dc = getDisplayContent();
1101 dc.pendingLayoutChanges |= changes;
1102 if (DEBUG_LAYOUT_REPEATS) {
1103 mService.mWindowPlacerLocked.debugLayoutRepeats(reason, dc.pendingLayoutChanges);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001104 }
1105 }
1106 }
1107
1108 void removeReplacedWindowIfNeeded(WindowState replacement) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001109 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001110 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001111 if (win.removeReplacedWindowIfNeeded(replacement)) {
1112 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001113 }
1114 }
1115 }
1116
1117 void startFreezingScreen() {
1118 if (DEBUG_ORIENTATION) logWithStack(TAG, "Set freezing of " + appToken + ": hidden="
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001119 + isHidden() + " freezing=" + mFreezingScreen + " hiddenRequested="
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001120 + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001121 if (!hiddenRequested) {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001122 if (!mFreezingScreen) {
1123 mFreezingScreen = true;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001124 mService.registerAppFreezeListener(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001125 mService.mAppsFreezingScreen++;
1126 if (mService.mAppsFreezingScreen == 1) {
Robert Carrae606b42018-02-15 15:36:23 -08001127 mService.startFreezingDisplayLocked(0, 0, getDisplayContent());
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001128 mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT);
1129 mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001130 }
1131 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001132 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001133 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001134 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001135 w.onStartFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001136 }
1137 }
1138 }
1139
1140 void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001141 if (!mFreezingScreen) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001142 return;
1143 }
1144 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + this + " force=" + force);
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001145 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001146 boolean unfrozeWindows = false;
1147 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001148 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001149 unfrozeWindows |= w.onStopFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001150 }
1151 if (force || unfrozeWindows) {
1152 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this);
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001153 mFreezingScreen = false;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001154 mService.unregisterAppFreezeListener(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001155 mService.mAppsFreezingScreen--;
1156 mService.mLastFinishedFreezeSource = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001157 }
1158 if (unfreezeSurfaceNow) {
1159 if (unfrozeWindows) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001160 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001161 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001162 mService.stopFreezingDisplayLocked();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001163 }
1164 }
1165
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001166 @Override
1167 public void onAppFreezeTimeout() {
1168 Slog.w(TAG_WM, "Force clearing freeze: " + this);
1169 stopFreezingScreen(true, true);
1170 }
1171
Jorim Jaggi60f9c972018-02-01 19:21:07 +01001172 /**
1173 * Tries to transfer the starting window from a token that's above ourselves in the task but
1174 * not visible anymore. This is a common scenario apps use: Trampoline activity T start main
1175 * activity M in the same task. Now, when reopening the task, T starts on top of M but then
1176 * immediately finishes after, so we have to transfer T to M.
1177 */
1178 void transferStartingWindowFromHiddenAboveTokenIfNeeded() {
1179 final Task task = getTask();
1180 for (int i = task.mChildren.size() - 1; i >= 0; i--) {
1181 final AppWindowToken fromToken = task.mChildren.get(i);
1182 if (fromToken == this) {
1183 return;
1184 }
1185 if (fromToken.hiddenRequested && transferStartingWindow(fromToken.token)) {
1186 return;
1187 }
1188 }
1189 }
1190
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001191 boolean transferStartingWindow(IBinder transferFrom) {
Wale Ogunwale02319a62016-09-26 15:21:22 -07001192 final AppWindowToken fromToken = getDisplayContent().getAppWindowToken(transferFrom);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001193 if (fromToken == null) {
1194 return false;
1195 }
1196
1197 final WindowState tStartingWindow = fromToken.startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001198 if (tStartingWindow != null && fromToken.startingSurface != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001199 // In this case, the starting icon has already been displayed, so start
1200 // letting windows get shown immediately without any more transitions.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001201 mService.mSkipAppTransitionAnimation = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001202
1203 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow
1204 + " from " + fromToken + " to " + this);
1205
1206 final long origId = Binder.clearCallingIdentity();
Peter Visontay3556a3b2017-11-01 17:23:17 +00001207 try {
1208 // Transfer the starting window over to the new token.
1209 startingData = fromToken.startingData;
1210 startingSurface = fromToken.startingSurface;
1211 startingDisplayed = fromToken.startingDisplayed;
1212 fromToken.startingDisplayed = false;
1213 startingWindow = tStartingWindow;
1214 reportedVisible = fromToken.reportedVisible;
1215 fromToken.startingData = null;
1216 fromToken.startingSurface = null;
1217 fromToken.startingWindow = null;
1218 fromToken.startingMoved = true;
1219 tStartingWindow.mToken = this;
1220 tStartingWindow.mAppToken = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001221
Peter Visontay3556a3b2017-11-01 17:23:17 +00001222 if (DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1223 "Removing starting " + tStartingWindow + " from " + fromToken);
1224 fromToken.removeChild(tStartingWindow);
1225 fromToken.postWindowRemoveStartingWindowCleanup(tStartingWindow);
1226 fromToken.mHiddenSetFromTransferredStartingWindow = false;
1227 addWindow(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001228
Peter Visontay3556a3b2017-11-01 17:23:17 +00001229 // Propagate other interesting state between the tokens. If the old token is displayed,
1230 // we should immediately force the new one to be displayed. If it is animating, we need
1231 // to move that animation to the new one.
1232 if (fromToken.allDrawn) {
1233 allDrawn = true;
1234 deferClearAllDrawn = fromToken.deferClearAllDrawn;
1235 }
1236 if (fromToken.firstWindowDrawn) {
1237 firstWindowDrawn = true;
1238 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001239 if (!fromToken.isHidden()) {
1240 setHidden(false);
Peter Visontay3556a3b2017-11-01 17:23:17 +00001241 hiddenRequested = false;
1242 mHiddenSetFromTransferredStartingWindow = true;
1243 }
1244 setClientHidden(fromToken.mClientHidden);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001245
Jorim Jaggi980c9de2017-11-17 01:41:37 +01001246 transferAnimation(fromToken);
1247
1248 // When transferring an animation, we no longer need to apply an animation to the
1249 // the token we transfer the animation over. Thus, remove the animation from
1250 // pending opening apps.
1251 mService.mOpeningApps.remove(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001252
Peter Visontay3556a3b2017-11-01 17:23:17 +00001253 mService.updateFocusedWindowLocked(
1254 UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/);
1255 getDisplayContent().setLayoutNeeded();
1256 mService.mWindowPlacerLocked.performSurfacePlacement();
1257 } finally {
1258 Binder.restoreCallingIdentity(origId);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001259 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001260 return true;
1261 } else if (fromToken.startingData != null) {
1262 // The previous app was getting ready to show a
1263 // starting window, but hasn't yet done so. Steal it!
1264 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1265 "Moving pending starting from " + fromToken + " to " + this);
1266 startingData = fromToken.startingData;
1267 fromToken.startingData = null;
1268 fromToken.startingMoved = true;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001269 if (getController() != null) {
1270 getController().scheduleAddStartingWindow();
1271 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001272 return true;
1273 }
1274
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001275 // TODO: Transfer thumbnail
1276
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001277 return false;
1278 }
1279
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001280 boolean isLastWindow(WindowState win) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001281 return mChildren.size() == 1 && mChildren.get(0) == win;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001282 }
1283
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001284 @Override
1285 void onAppTransitionDone() {
1286 sendingToBottom = false;
1287 }
1288
Wale Ogunwale51362492016-09-08 17:49:17 -07001289 /**
1290 * We override because this class doesn't want its children affecting its reported orientation
1291 * in anyway.
1292 */
1293 @Override
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001294 int getOrientation(int candidate) {
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001295 if (candidate == SCREEN_ORIENTATION_BEHIND) {
1296 // Allow app to specify orientation regardless of its visibility state if the current
1297 // candidate want us to use orientation behind. I.e. the visible app on-top of this one
1298 // wants us to use the orientation of the app behind it.
1299 return mOrientation;
1300 }
1301
Bryce Lee61fbcbc2017-03-10 14:14:03 -08001302 // The {@link AppWindowToken} should only specify an orientation when it is not closing or
1303 // going to the bottom. Allowing closing {@link AppWindowToken} to participate can lead to
1304 // an Activity in another task being started in the wrong orientation during the transition.
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001305 if (!(sendingToBottom || mService.mClosingApps.contains(this))
Andrii Kulian0918d362018-05-23 17:01:37 -07001306 && (isVisible() || mService.mOpeningApps.contains(this))) {
Bryce Leea163b762017-01-24 11:05:01 -08001307 return mOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001308 }
Bryce Leea163b762017-01-24 11:05:01 -08001309
1310 return SCREEN_ORIENTATION_UNSET;
Wale Ogunwale51362492016-09-08 17:49:17 -07001311 }
1312
Wale Ogunwaleb198b742016-12-01 08:44:09 -08001313 /** Returns the app's preferred orientation regardless of its currently visibility state. */
1314 int getOrientationIgnoreVisibility() {
1315 return mOrientation;
1316 }
1317
Craig Mautnerdbb79912012-03-01 18:59:14 -08001318 @Override
Winson Chunge55c0192017-08-24 14:50:48 -07001319 public void onConfigurationChanged(Configuration newParentConfig) {
1320 final int prevWinMode = getWindowingMode();
1321 super.onConfigurationChanged(newParentConfig);
1322 final int winMode = getWindowingMode();
1323
1324 if (prevWinMode == winMode) {
1325 return;
1326 }
1327
1328 if (prevWinMode != WINDOWING_MODE_UNDEFINED && winMode == WINDOWING_MODE_PINNED) {
1329 // Entering PiP from fullscreen, reset the snap fraction
1330 mDisplayContent.mPinnedStackControllerLocked.resetReentrySnapFraction(this);
Winson Chung82267ce2018-04-06 16:38:26 -07001331 } else if (prevWinMode == WINDOWING_MODE_PINNED && winMode != WINDOWING_MODE_UNDEFINED
1332 && !isHidden()) {
Winson Chunge55c0192017-08-24 14:50:48 -07001333 // Leaving PiP to fullscreen, save the snap fraction based on the pre-animation bounds
1334 // for the next re-entry into PiP (assuming the activity is not hidden or destroyed)
1335 final TaskStack pinnedStack = mDisplayContent.getPinnedStack();
1336 if (pinnedStack != null) {
Winson Chung8efa1652018-06-06 09:34:23 -07001337 final Rect stackBounds;
1338 if (pinnedStack.lastAnimatingBoundsWasToFullscreen()) {
1339 // We are animating the bounds, use the pre-animation bounds to save the snap
1340 // fraction
1341 stackBounds = pinnedStack.mPreAnimationBounds;
1342 } else {
1343 // We skip the animation if the fullscreen configuration is not compatible, so
1344 // use the current bounds to calculate the saved snap fraction instead
1345 // (see PinnedActivityStack.skipResizeAnimation())
1346 stackBounds = mTmpRect;
1347 pinnedStack.getBounds(stackBounds);
1348 }
Winson Chunge55c0192017-08-24 14:50:48 -07001349 mDisplayContent.mPinnedStackControllerLocked.saveReentrySnapFraction(this,
Winson Chung8efa1652018-06-06 09:34:23 -07001350 stackBounds);
Winson Chunge55c0192017-08-24 14:50:48 -07001351 }
1352 }
1353 }
1354
1355 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001356 void checkAppWindowsReadyToShow() {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001357 if (allDrawn == mLastAllDrawn) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001358 return;
1359 }
1360
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001361 mLastAllDrawn = allDrawn;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001362 if (!allDrawn) {
1363 return;
1364 }
1365
1366 // The token has now changed state to having all windows shown... what to do, what to do?
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001367 if (mFreezingScreen) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001368 showAllWindowsLocked();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001369 stopFreezingScreen(false, true);
1370 if (DEBUG_ORIENTATION) Slog.i(TAG,
1371 "Setting mOrientationChangeComplete=true because wtoken " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001372 + " numInteresting=" + mNumInterestingWindows + " numDrawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001373 // This will set mOrientationChangeComplete and cause a pass through layout.
1374 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001375 "checkAppWindowsReadyToShow: freezingScreen");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001376 } else {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001377 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001378
1379 // We can now show all of the drawn windows!
1380 if (!mService.mOpeningApps.contains(this)) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001381 showAllWindowsLocked();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001382 }
1383 }
1384 }
1385
Matthew Ng5d23afa2017-06-21 16:16:24 -07001386 /**
Bryce Leed390deb2017-06-22 13:14:28 -07001387 * Returns whether the drawn window states of this {@link AppWindowToken} has considered every
1388 * child {@link WindowState}. A child is considered if it has been passed into
1389 * {@link #updateDrawnWindowStates(WindowState)} after being added. This is used to determine
1390 * whether states, such as {@code allDrawn}, can be set, which relies on state variables such as
1391 * {@code mNumInterestingWindows}, which depend on all {@link WindowState}s being considered.
1392 *
1393 * @return {@code true} If all children have been considered, {@code false}.
1394 */
1395 private boolean allDrawnStatesConsidered() {
Bryce Lee6311c4b2017-07-06 14:09:29 -07001396 for (int i = mChildren.size() - 1; i >= 0; --i) {
1397 final WindowState child = mChildren.get(i);
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001398 if (child.mightAffectAllDrawn() && !child.getDrawnStateEvaluated()) {
Bryce Leed390deb2017-06-22 13:14:28 -07001399 return false;
1400 }
1401 }
1402 return true;
1403 }
1404
1405 /**
Matthew Ng5d23afa2017-06-21 16:16:24 -07001406 * Determines if the token has finished drawing. This should only be called from
1407 * {@link DisplayContent#applySurfaceChangesTransaction}
1408 */
Matthew Ng498c71d2017-04-18 13:55:45 -07001409 void updateAllDrawn() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001410 if (!allDrawn) {
Matthew Ng498c71d2017-04-18 13:55:45 -07001411 // Number of drawn windows can be less when a window is being relaunched, wait for
Bryce Leed390deb2017-06-22 13:14:28 -07001412 // all windows to be launched and drawn for this token be considered all drawn.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001413 final int numInteresting = mNumInterestingWindows;
Bryce Leed390deb2017-06-22 13:14:28 -07001414
1415 // We must make sure that all present children have been considered (determined by
1416 // {@link #allDrawnStatesConsidered}) before evaluating whether everything has been
1417 // drawn.
1418 if (numInteresting > 0 && allDrawnStatesConsidered()
1419 && mNumDrawnWindows >= numInteresting && !isRelaunching()) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001420 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawn: " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001421 + " interesting=" + numInteresting + " drawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001422 allDrawn = true;
1423 // Force an additional layout pass where
1424 // WindowStateAnimator#commitFinishDrawingLocked() will call performShowLocked().
Matthew Ng498c71d2017-04-18 13:55:45 -07001425 if (mDisplayContent != null) {
1426 mDisplayContent.setLayoutNeeded();
1427 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001428 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Robert Carrecc06b32017-04-18 14:25:10 -07001429
Winson Chunge7ba6862017-05-24 12:13:33 -07001430 // Notify the pinned stack upon all windows drawn. If there was an animation in
1431 // progress then this signal will resume that animation.
Wale Ogunwale61911492017-10-11 08:50:50 -07001432 final TaskStack pinnedStack = mDisplayContent.getPinnedStack();
Winson Chunge7ba6862017-05-24 12:13:33 -07001433 if (pinnedStack != null) {
1434 pinnedStack.onAllWindowsDrawn();
Robert Carrecc06b32017-04-18 14:25:10 -07001435 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001436 }
1437 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001438 }
1439
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001440 /**
1441 * Updated this app token tracking states for interesting and drawn windows based on the window.
1442 *
1443 * @return Returns true if the input window is considered interesting and drawn while all the
1444 * windows in this app token where not considered drawn as of the last pass.
1445 */
1446 boolean updateDrawnWindowStates(WindowState w) {
Bryce Leed390deb2017-06-22 13:14:28 -07001447 w.setDrawnStateEvaluated(true /*evaluated*/);
1448
Jorim Jaggie4b0f282017-05-17 15:10:29 +02001449 if (DEBUG_STARTING_WINDOW_VERBOSE && w == startingWindow) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001450 Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" + w.isOnScreen()
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001451 + " allDrawn=" + allDrawn + " freezingScreen=" + mFreezingScreen);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001452 }
1453
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001454 if (allDrawn && !mFreezingScreen) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001455 return false;
1456 }
1457
1458 if (mLastTransactionSequence != mService.mTransactionSequence) {
1459 mLastTransactionSequence = mService.mTransactionSequence;
Matthew Ng53e66b22018-01-12 17:13:13 -08001460 mNumDrawnWindows = 0;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001461 startingDisplayed = false;
Matthew Ng53e66b22018-01-12 17:13:13 -08001462
1463 // There is the main base application window, even if it is exiting, wait for it
1464 mNumInterestingWindows = findMainWindow(false /* includeStartingApp */) != null ? 1 : 0;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001465 }
1466
1467 final WindowStateAnimator winAnimator = w.mWinAnimator;
1468
1469 boolean isInterestingAndDrawn = false;
1470
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001471 if (!allDrawn && w.mightAffectAllDrawn()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001472 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
1473 Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw()
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001474 + ", isAnimationSet=" + isSelfAnimating());
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001475 if (!w.isDrawnLw()) {
1476 Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController
1477 + " pv=" + w.mPolicyVisibility
1478 + " mDrawState=" + winAnimator.drawStateToString()
1479 + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001480 + " a=" + isSelfAnimating());
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001481 }
1482 }
1483
1484 if (w != startingWindow) {
1485 if (w.isInteresting()) {
Matthew Ng53e66b22018-01-12 17:13:13 -08001486 // Add non-main window as interesting since the main app has already been added
1487 if (findMainWindow(false /* includeStartingApp */) != w) {
1488 mNumInterestingWindows++;
1489 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001490 if (w.isDrawnLw()) {
1491 mNumDrawnWindows++;
1492
1493 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, "tokenMayBeDrawn: "
1494 + this + " w=" + w + " numInteresting=" + mNumInterestingWindows
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001495 + " freezingScreen=" + mFreezingScreen
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001496 + " mAppFreezing=" + w.mAppFreezing);
1497
1498 isInterestingAndDrawn = true;
1499 }
1500 }
1501 } else if (w.isDrawnLw()) {
Jorim Jaggi3878ca32017-02-02 17:13:05 -08001502 if (getController() != null) {
1503 getController().reportStartingWindowDrawn();
1504 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001505 startingDisplayed = true;
1506 }
1507 }
1508
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001509 return isInterestingAndDrawn;
1510 }
1511
Adrian Roos23df3a32018-03-15 15:41:13 +01001512 void layoutLetterbox(WindowState winHint) {
Adrian Roos4d18a2e2017-12-19 19:08:05 +01001513 final WindowState w = findMainWindow();
Adrian Roosf93b6d22018-03-21 13:48:26 +01001514 if (w == null || winHint != null && w != winHint) {
Adrian Roos4d18a2e2017-12-19 19:08:05 +01001515 return;
1516 }
Jorim Jaggia32da382018-03-28 18:01:22 +02001517 final boolean surfaceReady = w.isDrawnLw() // Regular case
Adrian Roosf93b6d22018-03-21 13:48:26 +01001518 || w.mWinAnimator.mSurfaceDestroyDeferred // The preserved surface is still ready.
1519 || w.isDragResizeChanged(); // Waiting for relayoutWindow to call preserveSurface.
1520 final boolean needsLetterbox = w.isLetterboxedAppWindow() && fillsParent() && surfaceReady;
Adrian Roos4d18a2e2017-12-19 19:08:05 +01001521 if (needsLetterbox) {
1522 if (mLetterbox == null) {
1523 mLetterbox = new Letterbox(() -> makeChildSurface(null));
1524 }
Adrian Roos23df3a32018-03-15 15:41:13 +01001525 mLetterbox.layout(getParent().getBounds(), w.mFrame);
Adrian Roos4d18a2e2017-12-19 19:08:05 +01001526 } else if (mLetterbox != null) {
Adrian Roos23df3a32018-03-15 15:41:13 +01001527 mLetterbox.hide();
1528 }
1529 }
1530
1531 void updateLetterboxSurface(WindowState winHint) {
1532 final WindowState w = findMainWindow();
1533 if (w != winHint && winHint != null && w != null) {
1534 return;
1535 }
1536 layoutLetterbox(winHint);
1537 if (mLetterbox != null && mLetterbox.needsApplySurfaceChanges()) {
1538 mLetterbox.applySurfaceChanges(mPendingTransaction);
Adrian Roos4d18a2e2017-12-19 19:08:05 +01001539 }
1540 }
1541
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001542 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001543 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001544 // For legacy reasons we process the TaskStack.mExitingAppTokens first in DisplayContent
1545 // before the non-exiting app tokens. So, we skip the exiting app tokens here.
1546 // TODO: Investigate if we need to continue to do this or if we can just process them
1547 // in-order.
1548 if (mIsExiting && !waitingForReplacement()) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001549 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001550 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001551 return forAllWindowsUnchecked(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001552 }
1553
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001554 boolean forAllWindowsUnchecked(ToBooleanFunction<WindowState> callback,
1555 boolean traverseTopToBottom) {
1556 return super.forAllWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001557 }
1558
1559 @Override
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001560 AppWindowToken asAppWindowToken() {
1561 // I am an app window token!
1562 return this;
1563 }
1564
1565 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -07001566 boolean fillsParent() {
1567 return mFillsParent;
1568 }
1569
1570 void setFillsParent(boolean fillsParent) {
1571 mFillsParent = fillsParent;
1572 }
1573
Jorim Jaggife762342016-10-13 14:33:27 +02001574 boolean containsDismissKeyguardWindow() {
Bryce Lee081554b2017-05-25 07:52:12 -07001575 // Window state is transient during relaunch. We are not guaranteed to be frozen during the
1576 // entirety of the relaunch.
1577 if (isRelaunching()) {
1578 return mLastContainsDismissKeyguardWindow;
1579 }
1580
Jorim Jaggife762342016-10-13 14:33:27 +02001581 for (int i = mChildren.size() - 1; i >= 0; i--) {
1582 if ((mChildren.get(i).mAttrs.flags & FLAG_DISMISS_KEYGUARD) != 0) {
1583 return true;
1584 }
1585 }
1586 return false;
1587 }
1588
1589 boolean containsShowWhenLockedWindow() {
Bryce Lee081554b2017-05-25 07:52:12 -07001590 // When we are relaunching, it is possible for us to be unfrozen before our previous
1591 // windows have been added back. Using the cached value ensures that our previous
1592 // showWhenLocked preference is honored until relaunching is complete.
1593 if (isRelaunching()) {
1594 return mLastContainsShowWhenLockedWindow;
1595 }
1596
Jorim Jaggife762342016-10-13 14:33:27 +02001597 for (int i = mChildren.size() - 1; i >= 0; i--) {
1598 if ((mChildren.get(i).mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
1599 return true;
1600 }
1601 }
Bryce Lee081554b2017-05-25 07:52:12 -07001602
Jorim Jaggife762342016-10-13 14:33:27 +02001603 return false;
1604 }
1605
1606 void checkKeyguardFlagsChanged() {
1607 final boolean containsDismissKeyguard = containsDismissKeyguardWindow();
1608 final boolean containsShowWhenLocked = containsShowWhenLockedWindow();
1609 if (containsDismissKeyguard != mLastContainsDismissKeyguardWindow
1610 || containsShowWhenLocked != mLastContainsShowWhenLockedWindow) {
1611 mService.notifyKeyguardFlagsChanged(null /* callback */);
1612 }
1613 mLastContainsDismissKeyguardWindow = containsDismissKeyguard;
1614 mLastContainsShowWhenLockedWindow = containsShowWhenLocked;
1615 }
1616
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001617 WindowState getImeTargetBelowWindow(WindowState w) {
1618 final int index = mChildren.indexOf(w);
1619 if (index > 0) {
1620 final WindowState target = mChildren.get(index - 1);
1621 if (target.canBeImeTarget()) {
1622 return target;
1623 }
1624 }
1625 return null;
1626 }
1627
Winson Chungbe9be7f2017-06-28 10:55:22 -07001628 int getLowestAnimLayer() {
1629 for (int i = 0; i < mChildren.size(); i++) {
1630 final WindowState w = mChildren.get(i);
1631 if (w.mRemoved) {
1632 continue;
1633 }
1634 return w.mWinAnimator.mAnimLayer;
1635 }
1636 return Integer.MAX_VALUE;
1637 }
1638
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001639 WindowState getHighestAnimLayerWindow(WindowState currentTarget) {
1640 WindowState candidate = null;
1641 for (int i = mChildren.indexOf(currentTarget); i >= 0; i--) {
1642 final WindowState w = mChildren.get(i);
1643 if (w.mRemoved) {
1644 continue;
1645 }
1646 if (candidate == null || w.mWinAnimator.mAnimLayer >
1647 candidate.mWinAnimator.mAnimLayer) {
1648 candidate = w;
1649 }
1650 }
1651 return candidate;
1652 }
1653
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001654 /**
1655 * See {@link Activity#setDisablePreviewScreenshots}.
1656 */
1657 void setDisablePreviewScreenshots(boolean disable) {
Wale Ogunwale6c459212017-05-17 08:56:03 -07001658 mDisablePreviewScreenshots = disable;
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001659 }
1660
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001661 /**
chaviwd3bf08d2017-08-01 17:24:59 -07001662 * Sets whether the current launch can turn the screen on. See {@link #canTurnScreenOn()}
1663 */
1664 void setCanTurnScreenOn(boolean canTurnScreenOn) {
1665 mCanTurnScreenOn = canTurnScreenOn;
1666 }
1667
1668 /**
1669 * Indicates whether the current launch can turn the screen on. This is to prevent multiple
1670 * relayouts from turning the screen back on. The screen should only turn on at most
1671 * once per activity resume.
1672 *
1673 * @return true if the screen can be turned on.
1674 */
1675 boolean canTurnScreenOn() {
1676 return mCanTurnScreenOn;
1677 }
1678
1679 /**
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001680 * Retrieves whether we'd like to generate a snapshot that's based solely on the theme. This is
1681 * the case when preview screenshots are disabled {@link #setDisablePreviewScreenshots} or when
1682 * we can't take a snapshot for other reasons, for example, if we have a secure window.
1683 *
1684 * @return True if we need to generate an app theme snapshot, false if we'd like to take a real
1685 * screenshot.
1686 */
1687 boolean shouldUseAppThemeSnapshot() {
Wale Ogunwale6c459212017-05-17 08:56:03 -07001688 return mDisablePreviewScreenshots || forAllWindows(w -> (w.mAttrs.flags & FLAG_SECURE) != 0,
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001689 true /* topToBottom */);
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001690 }
1691
Jorim Jaggibe418292018-03-26 16:14:12 +02001692 SurfaceControl getAppAnimationLayer() {
Jorim Jaggi391790622018-04-18 15:30:44 +02001693 return getAppAnimationLayer(isActivityTypeHome() ? ANIMATION_LAYER_HOME
1694 : needsZBoost() ? ANIMATION_LAYER_BOOSTED
1695 : ANIMATION_LAYER_STANDARD);
Jorim Jaggibe418292018-03-26 16:14:12 +02001696 }
1697
chaviw23ee71c2017-12-18 11:29:41 -08001698 @Override
Jorim Jaggi596a1992017-12-29 14:48:02 +01001699 public SurfaceControl getAnimationLeashParent() {
Robert Carrb9506032018-02-13 13:54:00 -08001700 // All normal app transitions take place in an animation layer which is below the pinned
1701 // stack but may be above the parent stacks of the given animating apps.
1702 // For transitions in the pinned stack (menu activity) we just let them occur as a child
1703 // of the pinned stack.
1704 if (!inPinnedWindowingMode()) {
1705 return getAppAnimationLayer();
1706 } else {
1707 return getStack().getSurfaceControl();
1708 }
chaviw23ee71c2017-12-18 11:29:41 -08001709 }
1710
Jorim Jaggic6976f02018-04-18 16:31:07 +02001711 private boolean shouldAnimate(int transit) {
1712 final boolean isSplitScreenPrimary =
1713 getWindowingMode() == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY;
1714 final boolean allowSplitScreenPrimaryAnimation = transit != TRANSIT_WALLPAPER_OPEN;
1715
1716 // We animate always if it's not split screen primary, and only some special cases in split
1717 // screen primary because it causes issues with stack clipping when we run an un-minimize
1718 // animation at the same time.
1719 return !isSplitScreenPrimary || allowSplitScreenPrimaryAnimation;
1720 }
1721
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001722 boolean applyAnimationLocked(WindowManager.LayoutParams lp, int transit, boolean enter,
1723 boolean isVoiceInteraction) {
1724
Jorim Jaggic6976f02018-04-18 16:31:07 +02001725 if (mService.mDisableTransitionAnimation || !shouldAnimate(transit)) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001726 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
Jorim Jaggic6976f02018-04-18 16:31:07 +02001727 Slog.v(TAG_WM, "applyAnimation: transition animation is disabled or skipped."
1728 + " atoken=" + this);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001729 }
1730 cancelAnimation();
1731 return false;
1732 }
1733
1734 // Only apply an animation if the display isn't frozen. If it is frozen, there is no reason
1735 // to animate and it can cause strange artifacts when we unfreeze the display if some
1736 // different animation is running.
1737 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "AWT#applyAnimationLocked");
1738 if (okToAnimate()) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001739 final AnimationAdapter adapter;
1740 final TaskStack stack = getStack();
1741 mTmpPoint.set(0, 0);
1742 mTmpRect.setEmpty();
1743 if (stack != null) {
1744 stack.getRelativePosition(mTmpPoint);
1745 stack.getBounds(mTmpRect);
1746 mTmpRect.offsetTo(0, 0);
1747 }
Jorim Jaggic4d29f22018-03-22 16:30:56 +01001748
1749 // Delaying animation start isn't compatible with remote animations at all.
1750 if (mService.mAppTransition.getRemoteAnimationController() != null
1751 && !mSurfaceAnimator.isAnimationStartDelayed()) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001752 adapter = mService.mAppTransition.getRemoteAnimationController()
1753 .createAnimationAdapter(this, mTmpPoint, mTmpRect);
1754 } else {
1755 final Animation a = loadAnimation(lp, transit, enter, isVoiceInteraction);
1756 if (a != null) {
1757 adapter = new LocalAnimationAdapter(
1758 new WindowAnimationSpec(a, mTmpPoint, mTmpRect,
1759 mService.mAppTransition.canSkipFirstFrame(),
Jorim Jaggiaa763cd2018-03-22 23:20:36 +01001760 mService.mAppTransition.getAppStackClipMode(),
1761 true /* isAppAnimation */),
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001762 mService.mSurfaceAnimationRunner);
1763 if (a.getZAdjustment() == Animation.ZORDER_TOP) {
1764 mNeedsZBoost = true;
1765 }
1766 mTransit = transit;
1767 mTransitFlags = mService.mAppTransition.getTransitFlags();
1768 } else {
1769 adapter = null;
chaviw23ee71c2017-12-18 11:29:41 -08001770 }
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001771 }
1772 if (adapter != null) {
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001773 startAnimation(getPendingTransaction(), adapter, !isVisible());
Jorim Jaggi82c17862018-02-21 17:50:18 +01001774 if (adapter.getShowWallpaper()) {
1775 mDisplayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
1776 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001777 }
1778 } else {
1779 cancelAnimation();
1780 }
1781 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
1782
1783 return isReallyAnimating();
1784 }
1785
1786 private Animation loadAnimation(WindowManager.LayoutParams lp, int transit, boolean enter,
1787 boolean isVoiceInteraction) {
1788 final DisplayContent displayContent = getTask().getDisplayContent();
1789 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
1790 final int width = displayInfo.appWidth;
1791 final int height = displayInfo.appHeight;
1792 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG_WM,
1793 "applyAnimation: atoken=" + this);
1794
1795 // Determine the visible rect to calculate the thumbnail clip
1796 final WindowState win = findMainWindow();
1797 final Rect frame = new Rect(0, 0, width, height);
1798 final Rect displayFrame = new Rect(0, 0,
1799 displayInfo.logicalWidth, displayInfo.logicalHeight);
1800 final Rect insets = new Rect();
1801 final Rect stableInsets = new Rect();
1802 Rect surfaceInsets = null;
1803 final boolean freeform = win != null && win.inFreeformWindowingMode();
1804 if (win != null) {
1805 // Containing frame will usually cover the whole screen, including dialog windows.
1806 // For freeform workspace windows it will not cover the whole screen and it also
1807 // won't exactly match the final freeform window frame (e.g. when overlapping with
1808 // the status bar). In that case we need to use the final frame.
1809 if (freeform) {
1810 frame.set(win.mFrame);
Adrian Roos4d18a2e2017-12-19 19:08:05 +01001811 } else if (win.isLetterboxedAppWindow()) {
1812 frame.set(getTask().getBounds());
Winson Chungc1674272018-02-21 10:15:17 -08001813 } else if (win.isDockedResizing()) {
1814 // If we are animating while docked resizing, then use the stack bounds as the
1815 // animation target (which will be different than the task bounds)
1816 frame.set(getTask().getParent().getBounds());
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001817 } else {
1818 frame.set(win.mContainingFrame);
1819 }
1820 surfaceInsets = win.getAttrs().surfaceInsets;
Adrian Roos20e07892018-02-23 19:12:01 +01001821 // XXX(b/72757033): These are insets relative to the window frame, but we're really
1822 // interested in the insets relative to the frame we chose in the if-blocks above.
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001823 insets.set(win.mContentInsets);
1824 stableInsets.set(win.mStableInsets);
1825 }
1826
1827 if (mLaunchTaskBehind) {
1828 // Differentiate the two animations. This one which is briefly on the screen
1829 // gets the !enter animation, and the other activity which remains on the
1830 // screen gets the enter animation. Both appear in the mOpeningApps set.
1831 enter = false;
1832 }
1833 if (DEBUG_APP_TRANSITIONS) Slog.d(TAG_WM, "Loading animation for app transition."
1834 + " transit=" + AppTransition.appTransitionToString(transit) + " enter=" + enter
1835 + " frame=" + frame + " insets=" + insets + " surfaceInsets=" + surfaceInsets);
1836 final Configuration displayConfig = displayContent.getConfiguration();
1837 final Animation a = mService.mAppTransition.loadAnimation(lp, transit, enter,
1838 displayConfig.uiMode, displayConfig.orientation, frame, displayFrame, insets,
1839 surfaceInsets, stableInsets, isVoiceInteraction, freeform, getTask().mTaskId);
1840 if (a != null) {
1841 if (DEBUG_ANIM) logWithStack(TAG, "Loaded animation " + a + " for " + this);
1842 final int containingWidth = frame.width();
1843 final int containingHeight = frame.height();
1844 a.initialize(containingWidth, containingHeight, width, height);
1845 a.scaleCurrentDuration(mService.getTransitionAnimationScaleLocked());
1846 }
1847 return a;
1848 }
1849
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001850 @Override
Jorim Jaggi6de61012018-03-19 14:53:23 +01001851 public boolean shouldDeferAnimationFinish(Runnable endDeferFinishCallback) {
1852 return mAnimatingAppWindowTokenRegistry != null
1853 && mAnimatingAppWindowTokenRegistry.notifyAboutToFinish(
1854 this, endDeferFinishCallback);
1855 }
1856
1857 @Override
1858 public void onAnimationLeashDestroyed(Transaction t) {
1859 super.onAnimationLeashDestroyed(t);
1860 if (mAnimatingAppWindowTokenRegistry != null) {
1861 mAnimatingAppWindowTokenRegistry.notifyFinished(this);
1862 }
1863 }
1864
1865 @Override
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001866 protected void setLayer(Transaction t, int layer) {
1867 if (!mSurfaceAnimator.hasLeash()) {
1868 t.setLayer(mSurfaceControl, layer);
1869 }
1870 }
1871
1872 @Override
1873 protected void setRelativeLayer(Transaction t, SurfaceControl relativeTo, int layer) {
1874 if (!mSurfaceAnimator.hasLeash()) {
1875 t.setRelativeLayer(mSurfaceControl, relativeTo, layer);
1876 }
1877 }
1878
1879 @Override
1880 protected void reparentSurfaceControl(Transaction t, SurfaceControl newParent) {
1881 if (!mSurfaceAnimator.hasLeash()) {
1882 t.reparent(mSurfaceControl, newParent.getHandle());
1883 }
1884 }
1885
1886 @Override
1887 public void onAnimationLeashCreated(Transaction t, SurfaceControl leash) {
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001888 // The leash is parented to the animation layer. We need to preserve the z-order by using
1889 // the prefix order index, but we boost if necessary.
Robert Carrb9506032018-02-13 13:54:00 -08001890 int layer = 0;
1891 if (!inPinnedWindowingMode()) {
1892 layer = getPrefixOrderIndex();
1893 } else {
1894 // Pinned stacks have animations take place within themselves rather than an animation
1895 // layer so we need to preserve the order relative to the stack (e.g. the order of our
1896 // task/parent).
1897 layer = getParent().getPrefixOrderIndex();
1898 }
1899
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001900 if (mNeedsZBoost) {
1901 layer += Z_BOOST_BASE;
1902 }
1903 leash.setLayer(layer);
Robert Carr2f8aa392018-01-31 14:46:51 -08001904
1905 final DisplayContent dc = getDisplayContent();
Jorim Jaggibe418292018-03-26 16:14:12 +02001906 dc.assignStackOrdering();
Jorim Jaggi6de61012018-03-19 14:53:23 +01001907 if (mAnimatingAppWindowTokenRegistry != null) {
1908 mAnimatingAppWindowTokenRegistry.notifyStarting(this);
1909 }
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001910 }
1911
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001912 /**
1913 * This must be called while inside a transaction.
1914 */
1915 void showAllWindowsLocked() {
1916 forAllWindows(windowState -> {
1917 if (DEBUG_VISIBILITY) Slog.v(TAG, "performing show on: " + windowState);
1918 windowState.performShowLocked();
1919 }, false /* traverseTopToBottom */);
Jorim Jaggia5e10572017-11-15 14:36:26 +01001920 }
1921
1922 @Override
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001923 protected void onAnimationFinished() {
1924 super.onAnimationFinished();
1925
1926 mTransit = TRANSIT_UNSET;
1927 mTransitFlags = 0;
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001928 mNeedsZBoost = false;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001929
1930 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM | FINISH_LAYOUT_REDO_WALLPAPER,
1931 "AppWindowToken");
1932
Jorim Jaggi988f6682017-11-17 17:46:43 +01001933 clearThumbnail();
Jorim Jaggi752cd822018-03-29 16:29:18 +02001934 setClientHidden(isHidden() && hiddenRequested);
Jorim Jaggi988f6682017-11-17 17:46:43 +01001935
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001936 if (mService.mInputMethodTarget != null && mService.mInputMethodTarget.mAppToken == this) {
1937 getDisplayContent().computeImeTarget(true /* updateImeTarget */);
1938 }
1939
1940 if (DEBUG_ANIM) Slog.v(TAG, "Animation done in " + this
1941 + ": reportedVisible=" + reportedVisible
1942 + " okToDisplay=" + okToDisplay()
1943 + " okToAnimate=" + okToAnimate()
1944 + " startingDisplayed=" + startingDisplayed);
1945
1946 // WindowState.onExitAnimationDone might modify the children list, so make a copy and then
1947 // traverse the copy.
1948 final ArrayList<WindowState> children = new ArrayList<>(mChildren);
1949 children.forEach(WindowState::onExitAnimationDone);
1950
1951 mService.mAppTransition.notifyAppTransitionFinishedLocked(token);
1952 scheduleAnimation();
1953 }
1954
1955 @Override
1956 boolean isAppAnimating() {
1957 return isSelfAnimating();
1958 }
1959
1960 @Override
1961 boolean isSelfAnimating() {
1962 // If we are about to start a transition, we also need to be considered animating.
1963 return isWaitingForTransitionStart() || isReallyAnimating();
1964 }
1965
1966 /**
1967 * @return True if and only if we are actually running an animation. Note that
1968 * {@link #isSelfAnimating} also returns true if we are waiting for an animation to
1969 * start.
1970 */
1971 private boolean isReallyAnimating() {
1972 return super.isSelfAnimating();
1973 }
1974
Jorim Jaggi988f6682017-11-17 17:46:43 +01001975 @Override
1976 void cancelAnimation() {
1977 super.cancelAnimation();
1978 clearThumbnail();
1979 }
1980
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001981 boolean isWaitingForTransitionStart() {
1982 return mService.mAppTransition.isTransitionSet()
1983 && (mService.mOpeningApps.contains(this) || mService.mClosingApps.contains(this));
1984 }
1985
1986 public int getTransit() {
1987 return mTransit;
1988 }
1989
1990 int getTransitFlags() {
1991 return mTransitFlags;
1992 }
1993
Jorim Jaggi988f6682017-11-17 17:46:43 +01001994 void attachThumbnailAnimation() {
1995 if (!isReallyAnimating()) {
1996 return;
1997 }
1998 final int taskId = getTask().mTaskId;
1999 final GraphicBuffer thumbnailHeader =
2000 mService.mAppTransition.getAppTransitionThumbnailHeader(taskId);
2001 if (thumbnailHeader == null) {
2002 if (DEBUG_APP_TRANSITIONS) Slog.d(TAG, "No thumbnail header bitmap for: " + taskId);
2003 return;
2004 }
2005 clearThumbnail();
2006 mThumbnail = new AppWindowThumbnail(getPendingTransaction(), this, thumbnailHeader);
2007 mThumbnail.startAnimation(getPendingTransaction(), loadThumbnailAnimation(thumbnailHeader));
2008 }
2009
Tony Mak64b8d562017-12-28 17:44:02 +00002010 /**
2011 * Attaches a surface with a thumbnail for the
2012 * {@link android.app.ActivityOptions#ANIM_OPEN_CROSS_PROFILE_APPS} animation.
2013 */
2014 void attachCrossProfileAppsThumbnailAnimation() {
2015 if (!isReallyAnimating()) {
2016 return;
2017 }
2018 clearThumbnail();
2019
2020 final WindowState win = findMainWindow();
2021 if (win == null) {
2022 return;
2023 }
2024 final Rect frame = win.mFrame;
2025 final int thumbnailDrawableRes = getTask().mUserId == mService.mCurrentUserId
2026 ? R.drawable.ic_account_circle
Tony Makda4af232018-04-27 11:01:10 +01002027 : R.drawable.ic_corp_badge;
Tony Mak64b8d562017-12-28 17:44:02 +00002028 final GraphicBuffer thumbnail =
2029 mService.mAppTransition
2030 .createCrossProfileAppsThumbnail(thumbnailDrawableRes, frame);
2031 if (thumbnail == null) {
2032 return;
2033 }
2034 mThumbnail = new AppWindowThumbnail(getPendingTransaction(), this, thumbnail);
2035 final Animation animation =
2036 mService.mAppTransition.createCrossProfileAppsThumbnailAnimationLocked(win.mFrame);
2037 mThumbnail.startAnimation(getPendingTransaction(), animation, new Point(frame.left,
2038 frame.top));
2039 }
2040
Jorim Jaggi988f6682017-11-17 17:46:43 +01002041 private Animation loadThumbnailAnimation(GraphicBuffer thumbnailHeader) {
2042 final DisplayInfo displayInfo = mDisplayContent.getDisplayInfo();
2043
2044 // If this is a multi-window scenario, we use the windows frame as
2045 // destination of the thumbnail header animation. If this is a full screen
2046 // window scenario, we use the whole display as the target.
2047 WindowState win = findMainWindow();
2048 Rect appRect = win != null ? win.getContentFrameLw() :
2049 new Rect(0, 0, displayInfo.appWidth, displayInfo.appHeight);
2050 Rect insets = win != null ? win.mContentInsets : null;
2051 final Configuration displayConfig = mDisplayContent.getConfiguration();
2052 return mService.mAppTransition.createThumbnailAspectScaleAnimationLocked(
2053 appRect, insets, thumbnailHeader, getTask().mTaskId, displayConfig.uiMode,
2054 displayConfig.orientation);
2055 }
2056
2057 private void clearThumbnail() {
2058 if (mThumbnail == null) {
2059 return;
2060 }
2061 mThumbnail.destroy();
2062 mThumbnail = null;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002063 }
2064
Jorim Jaggif84e2f62018-01-16 14:17:59 +01002065 void registerRemoteAnimations(RemoteAnimationDefinition definition) {
2066 mRemoteAnimationDefinition = definition;
2067 }
2068
2069 RemoteAnimationDefinition getRemoteAnimationDefinition() {
2070 return mRemoteAnimationDefinition;
2071 }
2072
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002073 @Override
2074 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
2075 super.dump(pw, prefix, dumpAll);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002076 if (appToken != null) {
Wale Ogunwale72919d22016-12-08 18:58:50 -08002077 pw.println(prefix + "app=true mVoiceInteraction=" + mVoiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002078 }
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08002079 pw.print(prefix); pw.print("task="); pw.println(getTask());
Wale Ogunwale51362492016-09-08 17:49:17 -07002080 pw.print(prefix); pw.print(" mFillsParent="); pw.print(mFillsParent);
2081 pw.print(" mOrientation="); pw.println(mOrientation);
Wale Ogunwale89973222017-04-23 18:39:45 -07002082 pw.println(prefix + "hiddenRequested=" + hiddenRequested + " mClientHidden=" + mClientHidden
2083 + ((mDeferHidingClient) ? " mDeferHidingClient=" + mDeferHidingClient : "")
2084 + " reportedDrawn=" + reportedDrawn + " reportedVisible=" + reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -07002085 if (paused) {
2086 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002087 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -08002088 if (mAppStopped) {
2089 pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped);
2090 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07002091 if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002092 || allDrawn || mLastAllDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07002093 pw.print(prefix); pw.print("mNumInterestingWindows=");
2094 pw.print(mNumInterestingWindows);
2095 pw.print(" mNumDrawnWindows="); pw.print(mNumDrawnWindows);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002096 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -07002097 pw.print(" allDrawn="); pw.print(allDrawn);
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002098 pw.print(" lastAllDrawn="); pw.print(mLastAllDrawn);
Craig Mautner6fbda632012-07-03 09:26:39 -07002099 pw.println(")");
2100 }
2101 if (inPendingTransaction) {
2102 pw.print(prefix); pw.print("inPendingTransaction=");
2103 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002104 }
Craig Mautner799bc1d2015-01-14 10:33:48 -08002105 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002106 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
2107 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -08002108 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -08002109 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002110 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08002111 if (startingWindow != null || startingSurface != null
Wale Ogunwale6c459212017-05-17 08:56:03 -07002112 || startingDisplayed || startingMoved || mHiddenSetFromTransferredStartingWindow) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002113 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08002114 pw.print(" startingSurface="); pw.print(startingSurface);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002115 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
Wale Ogunwale6c459212017-05-17 08:56:03 -07002116 pw.print(" startingMoved="); pw.print(startingMoved);
2117 pw.println(" mHiddenSetFromTransferredStartingWindow="
2118 + mHiddenSetFromTransferredStartingWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002119 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01002120 if (!mFrozenBounds.isEmpty()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -08002121 pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds);
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002122 pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig);
Chong Zhangd78ddb42016-03-02 17:01:14 -08002123 }
2124 if (mPendingRelaunchCount != 0) {
2125 pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount);
Jorim Jaggi0429f352015-12-22 16:29:16 +01002126 }
Wale Ogunwale9c64cb62017-04-12 13:39:59 -07002127 if (getController() != null) {
2128 pw.print(prefix); pw.print("controller="); pw.println(getController());
2129 }
Wale Ogunwalee287e192017-04-21 09:30:12 -07002130 if (mRemovingFromDisplay) {
2131 pw.println(prefix + "mRemovingFromDisplay=" + mRemovingFromDisplay);
2132 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002133 }
2134
2135 @Override
2136 void setHidden(boolean hidden) {
2137 super.setHidden(hidden);
Winson Chunge55c0192017-08-24 14:50:48 -07002138
2139 if (hidden) {
2140 // Once the app window is hidden, reset the last saved PiP snap fraction
2141 mDisplayContent.mPinnedStackControllerLocked.resetReentrySnapFraction(this);
2142 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002143 scheduleAnimation();
2144 }
2145
2146 @Override
2147 void prepareSurfaces() {
2148 // isSelfAnimating also returns true when we are about to start a transition, so we need
2149 // to check super here.
2150 final boolean reallyAnimating = super.isSelfAnimating();
2151 final boolean show = !isHidden() || reallyAnimating;
2152 if (show && !mLastSurfaceShowing) {
2153 mPendingTransaction.show(mSurfaceControl);
2154 } else if (!show && mLastSurfaceShowing) {
2155 mPendingTransaction.hide(mSurfaceControl);
Jorim Jaggi4d1835d2017-08-31 17:28:27 +02002156 }
Jorim Jaggi988f6682017-11-17 17:46:43 +01002157 if (mThumbnail != null) {
2158 mThumbnail.setShowing(mPendingTransaction, show);
2159 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002160 mLastSurfaceShowing = show;
2161 super.prepareSurfaces();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002162 }
2163
Jorim Jaggi77d0f36c2018-03-16 17:49:49 +01002164 /**
2165 * @return Whether our {@link #getSurfaceControl} is currently showing.
2166 */
2167 boolean isSurfaceShowing() {
2168 return mLastSurfaceShowing;
2169 }
2170
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002171 boolean isFreezingScreen() {
2172 return mFreezingScreen;
2173 }
2174
2175 @Override
2176 boolean needsZBoost() {
2177 return mNeedsZBoost || super.needsZBoost();
2178 }
2179
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07002180 @CallSuper
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002181 @Override
Adrian Roos4921ccf2017-09-28 16:54:06 +02002182 public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07002183 final long token = proto.start(fieldId);
2184 writeNameToProto(proto, NAME);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002185 super.writeToProto(proto, WINDOW_TOKEN, trim);
Vishnu Nair04ab4392018-01-10 11:00:06 -08002186 proto.write(LAST_SURFACE_SHOWING, mLastSurfaceShowing);
2187 proto.write(IS_WAITING_FOR_TRANSITION_START, isWaitingForTransitionStart());
2188 proto.write(IS_REALLY_ANIMATING, isReallyAnimating());
2189 if (mThumbnail != null){
2190 mThumbnail.writeToProto(proto, THUMBNAIL);
2191 }
2192 proto.write(FILLS_PARENT, mFillsParent);
2193 proto.write(APP_STOPPED, mAppStopped);
2194 proto.write(HIDDEN_REQUESTED, hiddenRequested);
2195 proto.write(CLIENT_HIDDEN, mClientHidden);
2196 proto.write(DEFER_HIDING_CLIENT, mDeferHidingClient);
2197 proto.write(REPORTED_DRAWN, reportedDrawn);
2198 proto.write(REPORTED_VISIBLE, reportedVisible);
2199 proto.write(NUM_INTERESTING_WINDOWS, mNumInterestingWindows);
2200 proto.write(NUM_DRAWN_WINDOWS, mNumDrawnWindows);
2201 proto.write(ALL_DRAWN, allDrawn);
2202 proto.write(LAST_ALL_DRAWN, mLastAllDrawn);
2203 proto.write(REMOVED, removed);
2204 if (startingWindow != null){
2205 startingWindow.writeIdentifierToProto(proto, STARTING_WINDOW);
2206 }
2207 proto.write(STARTING_DISPLAYED, startingDisplayed);
2208 proto.write(STARTING_MOVED, startingMoved);
2209 proto.write(HIDDEN_SET_FROM_TRANSFERRED_STARTING_WINDOW,
2210 mHiddenSetFromTransferredStartingWindow);
2211 for (Rect bounds : mFrozenBounds) {
2212 bounds.writeToProto(proto, FROZEN_BOUNDS);
2213 }
Steven Timotiusaf03df62017-07-18 16:56:43 -07002214 proto.end(token);
2215 }
2216
2217 void writeNameToProto(ProtoOutputStream proto, long fieldId) {
2218 if (appToken == null) {
2219 return;
2220 }
2221 try {
2222 proto.write(fieldId, appToken.getName());
2223 } catch (RemoteException e) {
2224 // This shouldn't happen, but in this case fall back to outputting nothing
2225 Slog.e(TAG, e.toString());
2226 }
2227 }
2228
2229 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002230 public String toString() {
2231 if (stringName == null) {
2232 StringBuilder sb = new StringBuilder();
2233 sb.append("AppWindowToken{");
2234 sb.append(Integer.toHexString(System.identityHashCode(this)));
2235 sb.append(" token="); sb.append(token); sb.append('}');
2236 stringName = sb.toString();
2237 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07002238 return stringName + ((mIsExiting) ? " mIsExiting=" : "");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002239 }
Adrian Roos20e07892018-02-23 19:12:01 +01002240
2241 Rect getLetterboxInsets() {
2242 if (mLetterbox != null) {
2243 return mLetterbox.getInsets();
2244 } else {
2245 return new Rect();
2246 }
2247 }
Adrian Roos23df3a32018-03-15 15:41:13 +01002248
2249 /**
2250 * @eturn true if there is a letterbox and any part of that letterbox overlaps with
2251 * the given {@code rect}.
2252 */
2253 boolean isLetterboxOverlappingWith(Rect rect) {
2254 return mLetterbox != null && mLetterbox.isOverlappingWith(rect);
2255 }
chaviw4ad54912018-05-30 11:05:44 -07002256
2257 /**
2258 * Sets if this AWT is in the process of closing or entering PIP.
2259 * {@link #mWillCloseOrEnterPip}}
2260 */
2261 void setWillCloseOrEnterPip(boolean willCloseOrEnterPip) {
2262 mWillCloseOrEnterPip = willCloseOrEnterPip;
2263 }
2264
2265 /**
2266 * Returns whether this AWT is considered closing. Conditions are either
2267 * 1. Is this app animating and was requested to be hidden
2268 * 2. App is delayed closing since it might enter PIP.
2269 */
2270 boolean isClosingOrEnteringPip() {
2271 return (isAnimating() && hiddenRequested) || mWillCloseOrEnterPip;
2272 }
Jeff Browne9bdb312012-04-05 15:30:10 -07002273}