blob: d9ddf9f9b3a451a27aa682b0b299d08a55c735b3 [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;
Jorim Jaggiaf0d6d22018-06-08 15:25:35 +020022import static android.content.pm.ActivityInfo.COLOR_MODE_DEFAULT;
Wale Ogunwale72919d22016-12-08 18:58:50 -080023import static android.content.pm.ActivityInfo.CONFIG_ORIENTATION;
24import static android.content.pm.ActivityInfo.CONFIG_SCREEN_SIZE;
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -070025import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND;
Wale Ogunwale51362492016-09-08 17:49:17 -070026import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET;
Jorim Jaggif5f9e122017-10-24 18:21:09 +020027import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070028import static android.view.Display.DEFAULT_DISPLAY;
Jorim Jaggife762342016-10-13 14:33:27 +020029import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
Jorim Jaggid635a4a2017-05-03 15:21:26 +020030import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
Jorim Jaggife762342016-10-13 14:33:27 +020031import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
Wale Ogunwaled1c37912016-08-16 03:19:39 -070032import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080033import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070034import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
Tony Mak64b8d562017-12-28 17:44:02 +000035
Jorim Jaggic6976f02018-04-18 16:31:07 +020036import static android.view.WindowManager.TRANSIT_WALLPAPER_OPEN;
Adrian Roose99bc052017-11-20 17:55:31 +010037import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
38import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Jorim Jaggif84e2f62018-01-16 14:17:59 +010039import static android.view.WindowManager.TRANSIT_UNSET;
chaviw4ad54912018-05-30 11:05:44 -070040
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080041import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080042import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
43import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070044import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070045import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
46import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
Wale Ogunwale9017ec02016-02-25 08:55:25 -080047import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
Jorim Jaggie4b0f282017-05-17 15:10:29 +020048import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW_VERBOSE;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070049import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TOKEN_MOVEMENT;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080050import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
51import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_MOVEMENT;
52import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
53import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Chong Zhang92147042016-05-09 12:47:11 -070054import static com.android.server.wm.WindowManagerService.H.NOTIFY_ACTIVITY_DRAWN;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070055import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070056import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070057import static com.android.server.wm.WindowManagerService.logWithStack;
Yi Jin6c6e9ca2018-03-20 16:53:35 -070058import static com.android.server.wm.AppWindowTokenProto.ALL_DRAWN;
59import static com.android.server.wm.AppWindowTokenProto.APP_STOPPED;
60import static com.android.server.wm.AppWindowTokenProto.CLIENT_HIDDEN;
61import static com.android.server.wm.AppWindowTokenProto.DEFER_HIDING_CLIENT;
62import static com.android.server.wm.AppWindowTokenProto.FILLS_PARENT;
63import static com.android.server.wm.AppWindowTokenProto.FROZEN_BOUNDS;
64import static com.android.server.wm.AppWindowTokenProto.HIDDEN_REQUESTED;
65import static com.android.server.wm.AppWindowTokenProto.HIDDEN_SET_FROM_TRANSFERRED_STARTING_WINDOW;
66import static com.android.server.wm.AppWindowTokenProto.IS_REALLY_ANIMATING;
67import static com.android.server.wm.AppWindowTokenProto.IS_WAITING_FOR_TRANSITION_START;
68import static com.android.server.wm.AppWindowTokenProto.LAST_ALL_DRAWN;
69import static com.android.server.wm.AppWindowTokenProto.LAST_SURFACE_SHOWING;
70import static com.android.server.wm.AppWindowTokenProto.NAME;
71import static com.android.server.wm.AppWindowTokenProto.NUM_DRAWN_WINDOWS;
72import static com.android.server.wm.AppWindowTokenProto.NUM_INTERESTING_WINDOWS;
73import static com.android.server.wm.AppWindowTokenProto.REMOVED;
74import static com.android.server.wm.AppWindowTokenProto.REPORTED_DRAWN;
75import static com.android.server.wm.AppWindowTokenProto.REPORTED_VISIBLE;
76import static com.android.server.wm.AppWindowTokenProto.STARTING_DISPLAYED;
77import static com.android.server.wm.AppWindowTokenProto.STARTING_MOVED;
78import static com.android.server.wm.AppWindowTokenProto.STARTING_WINDOW;
79import static com.android.server.wm.AppWindowTokenProto.THUMBNAIL;
80import static com.android.server.wm.AppWindowTokenProto.WINDOW_TOKEN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080081
Wale Ogunwale0d5609b2017-09-13 05:55:07 -070082import android.annotation.CallSuper;
Jorim Jaggid635a4a2017-05-03 15:21:26 +020083import android.app.Activity;
Jorim Jaggi26c8c422016-05-09 19:57:25 -070084import android.content.res.Configuration;
Jorim Jaggi988f6682017-11-17 17:46:43 +010085import android.graphics.GraphicBuffer;
Jorim Jaggif5f9e122017-10-24 18:21:09 +020086import android.graphics.Point;
Jorim Jaggi0429f352015-12-22 16:29:16 +010087import android.graphics.Rect;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070088import android.os.Binder;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080089import android.os.Debug;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070090import android.os.IBinder;
Steven Timotiusaf03df62017-07-18 16:56:43 -070091import android.os.RemoteException;
Jorim Jaggif5f9e122017-10-24 18:21:09 +020092import android.os.Trace;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080093import android.util.Slog;
Steven Timotiusaf03df62017-07-18 16:56:43 -070094import android.util.proto.ProtoOutputStream;
Jorim Jaggif5f9e122017-10-24 18:21:09 +020095import android.view.DisplayInfo;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080096import android.view.IApplicationToken;
Jorim Jaggif84e2f62018-01-16 14:17:59 +010097import android.view.RemoteAnimationDefinition;
Robert Carr6914f082017-03-20 19:04:30 -070098import android.view.SurfaceControl;
Tony Mak64b8d562017-12-28 17:44:02 +000099import android.view.SurfaceControl.Transaction;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800100import android.view.WindowManager;
Jorim Jaggi87fdbcb2017-08-17 13:41:11 +0200101import android.view.WindowManager.LayoutParams;
Tony Mak64b8d562017-12-28 17:44:02 +0000102import android.view.animation.Animation;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800103
Tony Mak64b8d562017-12-28 17:44:02 +0000104import com.android.internal.R;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800105import com.android.internal.util.ToBooleanFunction;
106import com.android.server.input.InputApplicationHandle;
Adrian Roose99bc052017-11-20 17:55:31 +0100107import com.android.server.policy.WindowManagerPolicy.StartingSurface;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800108import com.android.server.wm.WindowManagerService.H;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800109
110import java.io.PrintWriter;
Jorim Jaggi0429f352015-12-22 16:29:16 +0100111import java.util.ArrayDeque;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800112import java.util.ArrayList;
113
114class AppTokenList extends ArrayList<AppWindowToken> {
115}
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800116
117/**
118 * Version of WindowToken that is specifically for a particular application (or
119 * really activity) that is displaying windows.
120 */
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700121class AppWindowToken extends WindowToken implements WindowManagerService.AppFreezeListener {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800122 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppWindowToken" : TAG_WM;
123
Jorim Jaggi619c9f72017-12-19 18:04:29 +0100124 /**
125 * Value to increment the z-layer when boosting a layer during animations. BOOST in l33tsp34k.
126 */
127 private static final int Z_BOOST_BASE = 800570000;
128
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800129 // Non-null only for application tokens.
130 final IApplicationToken appToken;
131
Wale Ogunwale72919d22016-12-08 18:58:50 -0800132 final boolean mVoiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700133
Wale Ogunwale51362492016-09-08 17:49:17 -0700134 /** @see WindowContainer#fillsParent() */
135 private boolean mFillsParent;
Craig Mautner4c5eb222013-11-18 12:59:05 -0800136 boolean layoutConfigChanges;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800137 boolean mShowForAllUsers;
138 int mTargetSdk;
Craig Mautnera2c77052012-03-26 12:14:43 -0700139
Bryce Lee6d410262017-02-28 15:30:17 -0800140 // Flag set while reparenting to prevent actions normally triggered by an individual parent
141 // change.
142 private boolean mReparenting;
143
Wale Ogunwalee287e192017-04-21 09:30:12 -0700144 // True if we are current in the process of removing this app token from the display
145 private boolean mRemovingFromDisplay = false;
146
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800147 // The input dispatching timeout for this application token in nanoseconds.
Wale Ogunwale72919d22016-12-08 18:58:50 -0800148 long mInputDispatchingTimeoutNanos;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800149
150 // These are used for determining when all windows associated with
151 // an activity have been drawn, so they can be made visible together
152 // at the same time.
Craig Mautner764983d2012-03-22 11:37:36 -0700153 // initialize so that it doesn't match mTransactionSequence which is an int.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700154 private long mLastTransactionSequence = Long.MIN_VALUE;
155 private int mNumInterestingWindows;
156 private int mNumDrawnWindows;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800157 boolean inPendingTransaction;
158 boolean allDrawn;
Jorim Jaggib0fc8172017-11-23 17:04:08 +0000159 private boolean mLastAllDrawn;
160
Craig Mautner7636dfb2012-11-16 15:24:11 -0800161 // Set to true when this app creates a surface while in the middle of an animation. In that
162 // case do not clear allDrawn until the animation completes.
163 boolean deferClearAllDrawn;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800164
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800165 // Is this window's surface needed? This is almost like hidden, except
166 // it will sometimes be true a little earlier: when the token has
167 // been shown, but is still waiting for its app transition to execute
168 // before making its windows shown.
169 boolean hiddenRequested;
170
171 // Have we told the window clients to hide themselves?
Wale Ogunwale89973222017-04-23 18:39:45 -0700172 private boolean mClientHidden;
173
174 // If true we will defer setting mClientHidden to true and reporting to the client that it is
175 // hidden.
176 boolean mDeferHidingClient;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800177
178 // Last visibility state we reported to the app token.
179 boolean reportedVisible;
180
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700181 // Last drawn state we reported to the app token.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700182 private boolean reportedDrawn;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700183
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800184 // Set to true when the token has been removed from the window mgr.
185 boolean removed;
186
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800187 // Information about an application starting window if displayed.
188 StartingData startingData;
189 WindowState startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800190 StartingSurface startingSurface;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800191 boolean startingDisplayed;
192 boolean startingMoved;
Jorim Jaggi60f9c972018-02-01 19:21:07 +0100193
Wale Ogunwale6c459212017-05-17 08:56:03 -0700194 // True if the hidden state of this token was forced to false due to a transferred starting
195 // window.
196 private boolean mHiddenSetFromTransferredStartingWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800197 boolean firstWindowDrawn;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700198 private final WindowState.UpdateReportedVisibilityResults mReportedVisibilityResults =
199 new WindowState.UpdateReportedVisibilityResults();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800200
201 // Input application handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700202 final InputApplicationHandle mInputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800203
Wale Ogunwale571771c2016-08-26 13:18:50 -0700204 // TODO: Have a WindowContainer state for tracking exiting/deferred removal.
Craig Mautner799bc1d2015-01-14 10:33:48 -0800205 boolean mIsExiting;
Craig Mautner9ef471f2014-02-07 13:11:47 -0800206
Craig Mautnerbb742462014-07-07 15:28:55 -0700207 boolean mLaunchTaskBehind;
Craig Mautner8746a472014-07-24 15:12:54 -0700208 boolean mEnteringAnimation;
Craig Mautnerbb742462014-07-07 15:28:55 -0700209
Wale Ogunwale72919d22016-12-08 18:58:50 -0800210 private boolean mAlwaysFocusable;
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800211
Robert Carre12aece2016-02-02 22:43:27 -0800212 boolean mAppStopped;
Robert Carrfd10cd12016-06-29 16:41:50 -0700213 int mRotationAnimationHint;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700214 private int mPendingRelaunchCount;
Robert Carre12aece2016-02-02 22:43:27 -0800215
Jorim Jaggife762342016-10-13 14:33:27 +0200216 private boolean mLastContainsShowWhenLockedWindow;
217 private boolean mLastContainsDismissKeyguardWindow;
218
Jorim Jaggi0429f352015-12-22 16:29:16 +0100219 ArrayDeque<Rect> mFrozenBounds = new ArrayDeque<>();
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700220 ArrayDeque<Configuration> mFrozenMergedConfig = new ArrayDeque<>();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100221
Wale Ogunwale6c459212017-05-17 08:56:03 -0700222 private boolean mDisablePreviewScreenshots;
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +0100223
Wale Ogunwale034a8ec2017-09-02 17:14:40 -0700224 private Task mLastParent;
Robert Carred3e83b2017-04-21 13:26:55 -0700225
chaviwd3bf08d2017-08-01 17:24:59 -0700226 /**
227 * See {@link #canTurnScreenOn()}
228 */
229 private boolean mCanTurnScreenOn = true;
230
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200231 /**
232 * If we are running an animation, this determines the transition type. Must be one of
233 * AppTransition.TRANSIT_* constants.
234 */
235 private int mTransit;
236
237 /**
238 * If we are running an animation, this determines the flags during this animation. Must be a
239 * bitwise combination of AppTransition.TRANSIT_FLAG_* constants.
240 */
241 private int mTransitFlags;
242
243 /** Whether our surface was set to be showing in the last call to {@link #prepareSurfaces} */
Jorim Jaggifd1891462017-12-29 15:41:36 +0100244 private boolean mLastSurfaceShowing = true;
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200245
Jorim Jaggi988f6682017-11-17 17:46:43 +0100246 private AppWindowThumbnail mThumbnail;
247
Jorim Jaggib0fc8172017-11-23 17:04:08 +0000248 /** Have we been asked to have this token keep the screen frozen? */
249 private boolean mFreezingScreen;
250
251 /** Whether this token should be boosted at the top of all app window tokens. */
252 private boolean mNeedsZBoost;
Adrian Roos4d18a2e2017-12-19 19:08:05 +0100253 private Letterbox mLetterbox;
Jorim Jaggib0fc8172017-11-23 17:04:08 +0000254
chaviw23ee71c2017-12-18 11:29:41 -0800255 private final Point mTmpPoint = new Point();
chaviw23012112017-12-20 15:29:04 -0800256 private final Rect mTmpRect = new Rect();
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100257 private RemoteAnimationDefinition mRemoteAnimationDefinition;
Jorim Jaggi6de61012018-03-19 14:53:23 +0100258 private AnimatingAppWindowTokenRegistry mAnimatingAppWindowTokenRegistry;
chaviw23ee71c2017-12-18 11:29:41 -0800259
chaviw4ad54912018-05-30 11:05:44 -0700260 /**
261 * A flag to determine if this AWT is in the process of closing or entering PIP. This is needed
262 * to help AWT know that the app is in the process of closing but hasn't yet started closing on
263 * the WM side.
264 */
265 private boolean mWillCloseOrEnterPip;
266
Wale Ogunwale72919d22016-12-08 18:58:50 -0800267 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
268 DisplayContent dc, long inputDispatchingTimeoutNanos, boolean fullscreen,
269 boolean showForAllUsers, int targetSdk, int orientation, int rotationAnimationHint,
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800270 int configChanges, boolean launchTaskBehind, boolean alwaysFocusable,
Bryce Leef3c6a472017-11-14 14:53:06 -0800271 AppWindowContainerController controller) {
272 this(service, token, voiceInteraction, dc, fullscreen);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800273 setController(controller);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800274 mInputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800275 mShowForAllUsers = showForAllUsers;
276 mTargetSdk = targetSdk;
277 mOrientation = orientation;
278 layoutConfigChanges = (configChanges & (CONFIG_SCREEN_SIZE | CONFIG_ORIENTATION)) != 0;
279 mLaunchTaskBehind = launchTaskBehind;
280 mAlwaysFocusable = alwaysFocusable;
281 mRotationAnimationHint = rotationAnimationHint;
282
283 // Application tokens start out hidden.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200284 setHidden(true);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800285 hiddenRequested = true;
286 }
287
288 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
Bryce Leef3c6a472017-11-14 14:53:06 -0800289 DisplayContent dc, boolean fillsParent) {
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800290 super(service, token != null ? token.asBinder() : null, TYPE_APPLICATION, true, dc,
291 false /* ownerCanManageAppTokens */);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700292 appToken = token;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800293 mVoiceInteraction = voiceInteraction;
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800294 mFillsParent = fillsParent;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800295 mInputApplicationHandle = new InputApplicationHandle(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800296 }
297
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800298 void onFirstWindowDrawn(WindowState win, WindowStateAnimator winAnimator) {
299 firstWindowDrawn = true;
300
301 // We now have a good window to show, remove dead placeholders
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700302 removeDeadWindows();
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800303
Jorim Jaggi02886a82016-12-06 09:10:06 -0800304 if (startingWindow != null) {
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800305 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, "Finish starting "
306 + win.mToken + ": first real window is shown, no animation");
307 // If this initial window is animating, stop it -- we will do an animation to reveal
308 // it from behind the starting window, so there is no need for it to also be doing its
309 // own stuff.
Jorim Jaggia5e10572017-11-15 14:36:26 +0100310 win.cancelAnimation();
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800311 if (getController() != null) {
312 getController().removeStartingWindow();
313 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800314 }
315 updateReportedVisibilityLocked();
316 }
317
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800318 void updateReportedVisibilityLocked() {
319 if (appToken == null) {
320 return;
321 }
322
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700323 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700324 final int count = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800325
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700326 mReportedVisibilityResults.reset();
327
328 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700329 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700330 win.updateReportedVisibility(mReportedVisibilityResults);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800331 }
332
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700333 int numInteresting = mReportedVisibilityResults.numInteresting;
334 int numVisible = mReportedVisibilityResults.numVisible;
335 int numDrawn = mReportedVisibilityResults.numDrawn;
336 boolean nowGone = mReportedVisibilityResults.nowGone;
337
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700338 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200339 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting && !isHidden();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700340 if (!nowGone) {
341 // If the app is not yet gone, then it can only become visible/drawn.
342 if (!nowDrawn) {
343 nowDrawn = reportedDrawn;
344 }
345 if (!nowVisible) {
346 nowVisible = reportedVisible;
347 }
348 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800349 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800350 + numInteresting + " visible=" + numVisible);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800351 final AppWindowContainerController controller = getController();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700352 if (nowDrawn != reportedDrawn) {
353 if (nowDrawn) {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800354 if (controller != null) {
355 controller.reportWindowsDrawn();
356 }
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700357 }
358 reportedDrawn = nowDrawn;
359 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800360 if (nowVisible != reportedVisible) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700361 if (DEBUG_VISIBILITY) Slog.v(TAG,
362 "Visibility changed in " + this + ": vis=" + nowVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800363 reportedVisible = nowVisible;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800364 if (controller != null) {
365 if (nowVisible) {
366 controller.reportWindowsVisible();
367 } else {
368 controller.reportWindowsGone();
369 }
370 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800371 }
372 }
373
Wale Ogunwale89973222017-04-23 18:39:45 -0700374 boolean isClientHidden() {
375 return mClientHidden;
376 }
377
378 void setClientHidden(boolean hideClient) {
379 if (mClientHidden == hideClient || (hideClient && mDeferHidingClient)) {
380 return;
381 }
Jorim Jaggi067b5bf2018-02-23 17:42:39 +0100382 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setClientHidden: " + this
383 + " clientHidden=" + hideClient + " Callers=" + Debug.getCallers(5));
Wale Ogunwale89973222017-04-23 18:39:45 -0700384 mClientHidden = hideClient;
385 sendAppVisibilityToClients();
386 }
387
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700388 boolean setVisibility(WindowManager.LayoutParams lp,
389 boolean visible, int transit, boolean performLayout, boolean isVoiceInteraction) {
390
391 boolean delayed = false;
392 inPendingTransaction = false;
Wale Ogunwale9e4721f2017-05-23 19:37:30 -0700393 // Reset the state of mHiddenSetFromTransferredStartingWindow since visibility is actually
394 // been set by the app now.
395 mHiddenSetFromTransferredStartingWindow = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700396
397 // Allow for state changes and animation to be applied if:
398 // * token is transitioning visibility state
399 // * or the token was marked as hidden and is exiting before we had a chance to play the
400 // transition animation
401 // * or this is an opening app and windows are being replaced.
402 boolean visibilityChanged = false;
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200403 if (isHidden() == visible || (isHidden() && mIsExiting) || (visible && waitingForReplacement())) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700404 final AccessibilityController accessibilityController = mService.mAccessibilityController;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700405 boolean changed = false;
406 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200407 "Changing app " + this + " hidden=" + isHidden() + " performLayout=" + performLayout);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700408
409 boolean runningAppAnimation = false;
410
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100411 if (transit != WindowManager.TRANSIT_UNSET) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200412 if (applyAnimationLocked(lp, transit, visible, isVoiceInteraction)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700413 delayed = runningAppAnimation = true;
414 }
415 final WindowState window = findMainWindow();
416 //TODO (multidisplay): Magnification is supported only for the default display.
417 if (window != null && accessibilityController != null
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700418 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700419 accessibilityController.onAppWindowTransitionLocked(window, transit);
420 }
421 changed = true;
422 }
423
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700424 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700425 for (int i = 0; i < windowsCount; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700426 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700427 changed |= win.onAppVisibilityChanged(visible, runningAppAnimation);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700428 }
429
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200430 setHidden(!visible);
431 hiddenRequested = !visible;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700432 visibilityChanged = true;
433 if (!visible) {
434 stopFreezingScreen(true, true);
435 } else {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700436 // If we are being set visible, and the starting window is not yet displayed,
437 // then make sure it doesn't get displayed.
438 if (startingWindow != null && !startingWindow.isDrawnLw()) {
439 startingWindow.mPolicyVisibility = false;
440 startingWindow.mPolicyVisibilityAfterAnim = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700441 }
Jorim Jaggi38d44ec2017-06-14 16:04:59 -0700442
443 // We are becoming visible, so better freeze the screen with the windows that are
444 // getting visible so we also wait for them.
445 forAllWindows(mService::makeWindowFreezingScreenIfNeededLocked, true);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700446 }
447
448 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setVisibility: " + this
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200449 + ": hidden=" + isHidden() + " hiddenRequested=" + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700450
451 if (changed) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700452 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700453 if (performLayout) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700454 mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700455 false /*updateInputWindows*/);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700456 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700457 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700458 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700459 }
460 }
461
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200462 if (isReallyAnimating()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700463 delayed = true;
Jorim Jaggiab9fcb22018-03-15 23:46:12 +0100464 } else {
465
466 // We aren't animating anything, but exiting windows rely on the animation finished
467 // callback being called in case the AppWindowToken was pretending to be animating,
468 // which we might have done because we were in closing/opening apps list.
469 onAnimationFinished();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700470 }
471
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700472 for (int i = mChildren.size() - 1; i >= 0 && !delayed; i--) {
Jorim Jaggia5e10572017-11-15 14:36:26 +0100473 if ((mChildren.get(i)).isSelfOrChildAnimating()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700474 delayed = true;
475 }
476 }
477
478 if (visibilityChanged) {
479 if (visible && !delayed) {
480 // The token was made immediately visible, there will be no entrance animation.
481 // We need to inform the client the enter animation was finished.
482 mEnteringAnimation = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700483 mService.mActivityManagerAppTransitionNotifier.onAppTransitionFinishedLocked(token);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700484 }
Robert Carr61b81112017-07-17 18:08:15 -0700485
Jorim Jaggi110839b2018-01-22 12:49:04 +0100486 // If we're becoming visible, immediately change client visibility as well although it
487 // usually gets changed in AppWindowContainerController.setVisibility already. However,
488 // there seem to be some edge cases where we change our visibility but client visibility
489 // never gets updated.
490 // If we're becoming invisible, update the client visibility if we are not running an
491 // animation. Otherwise, we'll update client visibility in onAnimationFinished.
Jorim Jaggi3cad57f2018-02-20 18:32:01 +0100492 if (visible || !isReallyAnimating()) {
Jorim Jaggi110839b2018-01-22 12:49:04 +0100493 setClientHidden(!visible);
Jorim Jaggi4876b4a2018-01-11 15:43:49 +0100494 }
495
chaviwa953fcf2018-03-01 12:00:39 -0800496 if (!mService.mClosingApps.contains(this) && !mService.mOpeningApps.contains(this)) {
497 // The token is not closing nor opening, so even if there is an animation set, that
498 // doesn't mean that it goes through the normal app transition cycle so we have
499 // to inform the docked controller about visibility change.
500 // TODO(multi-display): notify docked divider on all displays where visibility was
501 // affected.
502 mService.getDefaultDisplayContentLocked().getDockedDividerController()
503 .notifyAppVisibilityChanged();
504
505 // Take the screenshot before possibly hiding the WSA, otherwise the screenshot
506 // will not be taken.
507 mService.mTaskSnapshotController.notifyAppVisibilityChanged(this, visible);
508 }
509
Robert Carre7cc44d2017-03-20 19:04:30 -0700510 // If we are hidden but there is no delay needed we immediately
511 // apply the Surface transaction so that the ActivityManager
Robert Carr61b81112017-07-17 18:08:15 -0700512 // can have some guarantee on the Surface state following
513 // setting the visibility. This captures cases like dismissing
514 // the docked or pinned stack where there is no app transition.
515 //
516 // In the case of a "Null" animation, there will be
517 // no animation but there will still be a transition set.
518 // We still need to delay hiding the surface such that it
519 // can be synchronized with showing the next surface in the transition.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200520 if (isHidden() && !delayed && !mService.mAppTransition.isTransitionSet()) {
Robert Carr6914f082017-03-20 19:04:30 -0700521 SurfaceControl.openTransaction();
522 for (int i = mChildren.size() - 1; i >= 0; i--) {
523 mChildren.get(i).mWinAnimator.hide("immediately hidden");
524 }
525 SurfaceControl.closeTransaction();
526 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700527 }
528
529 return delayed;
530 }
531
Jorim Jaggi87fdbcb2017-08-17 13:41:11 +0200532 /**
533 * @return The to top most child window for which {@link LayoutParams#isFullscreen()} returns
534 * true.
535 */
536 WindowState getTopFullscreenWindow() {
537 for (int i = mChildren.size() - 1; i >= 0; i--) {
538 final WindowState win = mChildren.get(i);
539 if (win != null && win.mAttrs.isFullscreen()) {
540 return win;
541 }
542 }
543 return null;
544 }
545
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800546 WindowState findMainWindow() {
Matthew Ng53e66b22018-01-12 17:13:13 -0800547 return findMainWindow(true);
548 }
549
550 /**
551 * Finds the main window that either has type base application or application starting if
552 * requested.
553 *
554 * @param includeStartingApp Allow to search application-starting windows to also be returned.
555 * @return The main window of type base application or application starting if requested.
556 */
557 WindowState findMainWindow(boolean includeStartingApp) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700558 WindowState candidate = null;
Matthew Ng53e66b22018-01-12 17:13:13 -0800559 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700560 final WindowState win = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700561 final int type = win.mAttrs.type;
562 // No need to loop through child window as base application and starting types can't be
563 // child windows.
Matthew Ng53e66b22018-01-12 17:13:13 -0800564 if (type == TYPE_BASE_APPLICATION
565 || (includeStartingApp && type == TYPE_APPLICATION_STARTING)) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700566 // In cases where there are multiple windows, we prefer the non-exiting window. This
Sungsoo Lim0d3d1f82015-12-02 14:47:59 +0900567 // happens for example when replacing windows during an activity relaunch. When
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700568 // constructing the animation, we want the new window, not the exiting one.
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800569 if (win.mAnimatingExit) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700570 candidate = win;
571 } else {
572 return win;
573 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800574 }
575 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700576 return candidate;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800577 }
578
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800579 boolean windowsAreFocusable() {
Wale Ogunwale3382ab12017-07-27 08:55:03 -0700580 return getWindowConfiguration().canReceiveKeys() || mAlwaysFocusable;
Wale Ogunwaled045c822015-12-02 09:14:28 -0800581 }
582
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800583 AppWindowContainerController getController() {
584 final WindowContainerController controller = super.getController();
585 return controller != null ? (AppWindowContainerController) controller : null;
586 }
587
Wale Ogunwale571771c2016-08-26 13:18:50 -0700588 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -0700589 boolean isVisible() {
Wale Ogunwalee471be62016-10-03 07:53:55 -0700590 // If the app token isn't hidden then it is considered visible and there is no need to check
591 // its children windows to see if they are visible.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200592 return !isHidden();
Wale Ogunwale44f21802016-09-02 12:49:48 -0700593 }
594
595 @Override
Wale Ogunwalee287e192017-04-21 09:30:12 -0700596 void removeImmediately() {
597 onRemovedFromDisplay();
598 super.removeImmediately();
599 }
600
601 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -0700602 void removeIfPossible() {
Craig Mautnere3119b72015-01-20 15:02:36 -0800603 mIsExiting = false;
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800604 removeAllWindowsIfPossible();
Bryce Lee6d410262017-02-28 15:30:17 -0800605 removeImmediately();
Craig Mautnere3119b72015-01-20 15:02:36 -0800606 }
607
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700608 @Override
609 boolean checkCompleteDeferredRemoval() {
610 if (mIsExiting) {
611 removeIfPossible();
612 }
613 return super.checkCompleteDeferredRemoval();
614 }
615
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700616 void onRemovedFromDisplay() {
Wale Ogunwalee287e192017-04-21 09:30:12 -0700617 if (mRemovingFromDisplay) {
618 return;
619 }
620 mRemovingFromDisplay = true;
621
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700622 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app token: " + this);
623
Wale Ogunwale72919d22016-12-08 18:58:50 -0800624 boolean delayed = setVisibility(null, false, TRANSIT_UNSET, true, mVoiceInteraction);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700625
626 mService.mOpeningApps.remove(this);
Jorim Jaggi45ca0542017-05-30 16:16:01 -0700627 mService.mUnknownAppVisibilityController.appRemovedOrHidden(this);
Jorim Jaggi10abe2f2017-01-03 16:44:46 +0100628 mService.mTaskSnapshotController.onAppRemoved(this);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700629 waitingToShow = false;
630 if (mService.mClosingApps.contains(this)) {
631 delayed = true;
632 } else if (mService.mAppTransition.isTransitionSet()) {
633 mService.mClosingApps.add(this);
634 delayed = true;
635 }
636
637 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app " + this + " delayed=" + delayed
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200638 + " animation=" + getAnimation() + " animating=" + isSelfAnimating());
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700639
640 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM, "removeAppToken: "
641 + this + " delayed=" + delayed + " Callers=" + Debug.getCallers(4));
642
Jorim Jaggi19be6052017-08-03 18:33:43 +0200643 if (startingData != null && getController() != null) {
644 getController().removeStartingWindow();
645 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800646
Winson Chung87e5d552017-04-05 11:49:38 -0700647 // If this window was animating, then we need to ensure that the app transition notifies
648 // that animations have completed in WMS.handleAnimatingStoppedAndTransitionLocked(), so
649 // add to that list now
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200650 if (isSelfAnimating()) {
Winson Chung87e5d552017-04-05 11:49:38 -0700651 mService.mNoAnimationNotifyOnTransitionFinished.add(token);
652 }
653
Wale Ogunwalee287e192017-04-21 09:30:12 -0700654 final TaskStack stack = getStack();
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700655 if (delayed && !isEmpty()) {
656 // set the token aside because it has an active animation to be finished
657 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM,
658 "removeAppToken make exiting: " + this);
Wale Ogunwalee287e192017-04-21 09:30:12 -0700659 if (stack != null) {
660 stack.mExitingAppTokens.add(this);
661 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700662 mIsExiting = true;
663 } else {
664 // Make sure there is no animation running on this token, so any windows associated
665 // with it will be removed as soon as their animations are complete
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200666 cancelAnimation();
Wale Ogunwale3106ae012017-05-16 08:56:37 -0700667 if (stack != null) {
668 stack.mExitingAppTokens.remove(this);
669 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700670 removeIfPossible();
671 }
672
673 removed = true;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700674 stopFreezingScreen(true, true);
Bryce Lee6d410262017-02-28 15:30:17 -0800675
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700676 if (mService.mFocusedApp == this) {
677 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "Removing focused app token:" + this);
678 mService.mFocusedApp = null;
679 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
680 mService.mInputMonitor.setFocusedAppLw(null);
681 }
682
683 if (!delayed) {
684 updateReportedVisibilityLocked();
685 }
Wale Ogunwalee287e192017-04-21 09:30:12 -0700686
687 mRemovingFromDisplay = false;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700688 }
689
Chong Zhange05bcb12016-07-26 17:47:29 -0700690 void clearAnimatingFlags() {
Chong Zhangb0d26702016-08-12 16:03:29 -0700691 boolean wallpaperMightChange = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700692 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700693 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700694 wallpaperMightChange |= win.clearAnimatingFlags();
Chong Zhange05bcb12016-07-26 17:47:29 -0700695 }
Chong Zhangb0d26702016-08-12 16:03:29 -0700696 if (wallpaperMightChange) {
697 requestUpdateWallpaperIfNeeded();
698 }
Chong Zhange05bcb12016-07-26 17:47:29 -0700699 }
700
Robert Carre12aece2016-02-02 22:43:27 -0800701 void destroySurfaces() {
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700702 destroySurfaces(false /*cleanupOnResume*/);
703 }
704
705 /**
706 * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure
707 * the client has finished with them.
708 *
709 * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If
710 * set to true, destroy only surfaces of removed windows, and clear relevant flags of the
711 * others so that they are ready to be reused. If set to false (common case), destroy all
712 * surfaces that's eligible, if the app is already stopped.
713 */
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700714 private void destroySurfaces(boolean cleanupOnResume) {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700715 boolean destroyedSomething = false;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100716
717 // Copying to a different list as multiple children can be removed.
Jorim Jaggi59f3e922018-01-05 15:40:32 +0100718 final ArrayList<WindowState> children = new ArrayList<>(mChildren);
Jorim Jaggia5e10572017-11-15 14:36:26 +0100719 for (int i = children.size() - 1; i >= 0; i--) {
720 final WindowState win = children.get(i);
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700721 destroyedSomething |= win.destroySurface(cleanupOnResume, mAppStopped);
Robert Carre12aece2016-02-02 22:43:27 -0800722 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700723 if (destroyedSomething) {
724 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700725 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Adrian Roos23df3a32018-03-15 15:41:13 +0100726 updateLetterboxSurface(null);
Robert Carre12aece2016-02-02 22:43:27 -0800727 }
728 }
729
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800730 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700731 * Notify that the app is now resumed, and it was not stopped before, perform a clean
732 * up of the surfaces
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800733 */
Jorim Jaggibae01b12017-04-11 16:29:10 -0700734 void notifyAppResumed(boolean wasStopped) {
Chong Zhangad24f962016-08-25 12:12:33 -0700735 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped
Jorim Jaggibae01b12017-04-11 16:29:10 -0700736 + " " + this);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700737 mAppStopped = false;
chaviwd3bf08d2017-08-01 17:24:59 -0700738 // Allow the window to turn the screen on once the app is resumed again.
739 setCanTurnScreenOn(true);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700740 if (!wasStopped) {
741 destroySurfaces(true /*cleanupOnResume*/);
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800742 }
Robert Carre12aece2016-02-02 22:43:27 -0800743 }
744
Chong Zhangbef461f2015-10-27 11:38:24 -0700745 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700746 * Notify that the app has stopped, and it is okay to destroy any surfaces which were
747 * keeping alive in case they were still being used.
748 */
749 void notifyAppStopped() {
750 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this);
751 mAppStopped = true;
752 destroySurfaces();
753 // Remove any starting window that was added for this app if they are still around.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800754 if (getController() != null) {
755 getController().removeStartingWindow();
756 }
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700757 }
758
Chong Zhang92147042016-05-09 12:47:11 -0700759 void clearAllDrawn() {
760 allDrawn = false;
761 deferClearAllDrawn = false;
Chong Zhangbef461f2015-10-27 11:38:24 -0700762 }
763
Bryce Lee6d410262017-02-28 15:30:17 -0800764 Task getTask() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800765 return (Task) getParent();
Bryce Lee6d410262017-02-28 15:30:17 -0800766 }
767
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800768 TaskStack getStack() {
769 final Task task = getTask();
770 if (task != null) {
771 return task.mStack;
772 } else {
773 return null;
774 }
775 }
776
Bryce Lee6d410262017-02-28 15:30:17 -0800777 @Override
778 void onParentSet() {
779 super.onParentSet();
780
Robert Carred3e83b2017-04-21 13:26:55 -0700781 final Task task = getTask();
782
Bryce Lee6d410262017-02-28 15:30:17 -0800783 // When the associated task is {@code null}, the {@link AppWindowToken} can no longer
784 // access visual elements like the {@link DisplayContent}. We must remove any associations
785 // such as animations.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800786 if (!mReparenting) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800787 if (task == null) {
788 // It is possible we have been marked as a closing app earlier. We must remove ourselves
789 // from this list so we do not participate in any future animations.
790 mService.mClosingApps.remove(this);
Robert Carred3e83b2017-04-21 13:26:55 -0700791 } else if (mLastParent != null && mLastParent.mStack != null) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800792 task.mStack.mExitingAppTokens.remove(this);
793 }
Bryce Lee6d410262017-02-28 15:30:17 -0800794 }
Jorim Jaggi6de61012018-03-19 14:53:23 +0100795 final TaskStack stack = getStack();
796
797 // If we reparent, make sure to remove ourselves from the old animation registry.
798 if (mAnimatingAppWindowTokenRegistry != null) {
799 mAnimatingAppWindowTokenRegistry.notifyFinished(this);
800 }
801 mAnimatingAppWindowTokenRegistry = stack != null
802 ? stack.getAnimatingAppWindowTokenRegistry()
803 : null;
804
Robert Carred3e83b2017-04-21 13:26:55 -0700805 mLastParent = task;
Bryce Lee6d410262017-02-28 15:30:17 -0800806 }
807
Wale Ogunwalefa854eb2016-09-20 13:43:52 -0700808 void postWindowRemoveStartingWindowCleanup(WindowState win) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700809 // TODO: Something smells about the code below...Is there a better way?
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700810 if (startingWindow == win) {
811 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800812 if (getController() != null) {
813 getController().removeStartingWindow();
814 }
Wale Ogunwale6c459212017-05-17 08:56:03 -0700815 } else if (mChildren.size() == 0) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700816 // If this is the last window and we had requested a starting transition window,
817 // well there is no point now.
Jorim Jaggi02886a82016-12-06 09:10:06 -0800818 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingData");
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700819 startingData = null;
Wale Ogunwale6c459212017-05-17 08:56:03 -0700820 if (mHiddenSetFromTransferredStartingWindow) {
821 // We set the hidden state to false for the token from a transferred starting window.
822 // We now reset it back to true since the starting window was the last window in the
823 // token.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200824 setHidden(true);
Wale Ogunwale6c459212017-05-17 08:56:03 -0700825 }
Jorim Jaggi829b9cd2017-01-23 16:20:53 +0100826 } else if (mChildren.size() == 1 && startingSurface != null && !isRelaunching()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700827 // If this is the last window except for a starting transition window,
828 // we need to get rid of the starting transition.
Jorim Jaggie4b0f282017-05-17 15:10:29 +0200829 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Last window, removing starting window "
830 + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800831 if (getController() != null) {
832 getController().removeStartingWindow();
833 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700834 }
835 }
836
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700837 void removeDeadWindows() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700838 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700839 WindowState win = mChildren.get(winNdx);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800840 if (win.mAppDied) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700841 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700842 "removeDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800843 // Set mDestroying, we don't want any animation or delayed removal here.
844 win.mDestroying = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700845 // Also removes child windows.
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700846 win.removeIfPossible();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800847 }
848 }
849 }
850
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700851 boolean hasWindowsAlive() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700852 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700853 // No need to loop through child windows as the answer should be the same as that of the
854 // parent window.
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700855 if (!(mChildren.get(i)).mAppDied) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700856 return true;
857 }
858 }
859 return false;
860 }
861
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700862 void setWillReplaceWindows(boolean animate) {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700863 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
864 "Marking app token " + this + " with replacing windows.");
Robert Carra1eb4392015-12-10 12:43:51 -0800865
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700866 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700867 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700868 w.setWillReplaceWindow(animate);
Robert Carra1eb4392015-12-10 12:43:51 -0800869 }
Robert Carra1eb4392015-12-10 12:43:51 -0800870 }
871
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700872 void setWillReplaceChildWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700873 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this
Robert Carr23fa16b2016-01-13 13:19:58 -0800874 + " with replacing child windows.");
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700875 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700876 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700877 w.setWillReplaceChildWindows();
Robert Carr23fa16b2016-01-13 13:19:58 -0800878 }
879 }
880
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700881 void clearWillReplaceWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700882 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
883 "Resetting app token " + this + " of replacing window marks.");
Chong Zhangf596cd52016-01-05 13:42:44 -0800884
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700885 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700886 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700887 w.clearWillReplaceWindow();
Chong Zhangf596cd52016-01-05 13:42:44 -0800888 }
889 }
890
Chong Zhang4d7369a2016-04-25 16:09:14 -0700891 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700892 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700893 final WindowState w = mChildren.get(i);
Chong Zhang4d7369a2016-04-25 16:09:14 -0700894 w.requestUpdateWallpaperIfNeeded();
895 }
896 }
897
Chong Zhangd78ddb42016-03-02 17:01:14 -0800898 boolean isRelaunching() {
899 return mPendingRelaunchCount > 0;
900 }
901
Robert Carr68375192017-06-13 12:41:53 -0700902 boolean shouldFreezeBounds() {
903 final Task task = getTask();
904
905 // For freeform windows, we can't freeze the bounds at the moment because this would make
906 // the resizing unresponsive.
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700907 if (task == null || task.inFreeformWindowingMode()) {
Robert Carr68375192017-06-13 12:41:53 -0700908 return false;
909 }
910
911 // We freeze the bounds while drag resizing to deal with the time between
912 // the divider/drag handle being released, and the handling it's new
913 // configuration. If we are relaunched outside of the drag resizing state,
914 // we need to be careful not to do this.
915 return getTask().isDragResizing();
916 }
917
Chong Zhangd78ddb42016-03-02 17:01:14 -0800918 void startRelaunching() {
Robert Carr68375192017-06-13 12:41:53 -0700919 if (shouldFreezeBounds()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -0800920 freezeBounds();
921 }
Robert Carrd5c7dd62017-03-08 10:39:30 -0800922
923 // In the process of tearing down before relaunching, the app will
924 // try and clean up it's child surfaces. We need to prevent this from
925 // happening, so we sever the children, transfering their ownership
926 // from the client it-self to the parent surface (owned by us).
Robert Carr29daa922018-04-27 11:56:48 -0700927 detachChildren();
928
929 mPendingRelaunchCount++;
930 }
931
932 void detachChildren() {
Robert Carrfd8e93b2018-05-10 13:40:25 -0700933 SurfaceControl.openTransaction();
Robert Carrd5c7dd62017-03-08 10:39:30 -0800934 for (int i = mChildren.size() - 1; i >= 0; i--) {
935 final WindowState w = mChildren.get(i);
936 w.mWinAnimator.detachChildren();
937 }
Robert Carrfd8e93b2018-05-10 13:40:25 -0700938 SurfaceControl.closeTransaction();
Chong Zhangd78ddb42016-03-02 17:01:14 -0800939 }
940
941 void finishRelaunching() {
Robert Carr68375192017-06-13 12:41:53 -0700942 unfreezeBounds();
943
Chong Zhangd78ddb42016-03-02 17:01:14 -0800944 if (mPendingRelaunchCount > 0) {
945 mPendingRelaunchCount--;
Bryce Lee081554b2017-05-25 07:52:12 -0700946 } else {
947 // Update keyguard flags upon finishing relaunch.
948 checkKeyguardFlagsChanged();
Chong Zhangd78ddb42016-03-02 17:01:14 -0800949 }
950 }
951
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700952 void clearRelaunching() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700953 if (mPendingRelaunchCount == 0) {
954 return;
955 }
Robert Carr68375192017-06-13 12:41:53 -0700956 unfreezeBounds();
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700957 mPendingRelaunchCount = 0;
958 }
959
Wale Ogunwale07bcab72016-10-14 15:30:09 -0700960 /**
961 * Returns true if the new child window we are adding to this token is considered greater than
962 * the existing child window in this token in terms of z-order.
963 */
964 @Override
965 protected boolean isFirstChildWindowGreaterThanSecond(WindowState newWindow,
966 WindowState existingWindow) {
967 final int type1 = newWindow.mAttrs.type;
968 final int type2 = existingWindow.mAttrs.type;
969
970 // Base application windows should be z-ordered BELOW all other windows in the app token.
971 if (type1 == TYPE_BASE_APPLICATION && type2 != TYPE_BASE_APPLICATION) {
972 return false;
973 } else if (type1 != TYPE_BASE_APPLICATION && type2 == TYPE_BASE_APPLICATION) {
974 return true;
975 }
976
977 // Starting windows should be z-ordered ABOVE all other windows in the app token.
978 if (type1 == TYPE_APPLICATION_STARTING && type2 != TYPE_APPLICATION_STARTING) {
979 return true;
980 } else if (type1 != TYPE_APPLICATION_STARTING && type2 == TYPE_APPLICATION_STARTING) {
981 return false;
982 }
983
984 // Otherwise the new window is greater than the existing window.
985 return true;
986 }
987
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700988 @Override
Robert Carra1eb4392015-12-10 12:43:51 -0800989 void addWindow(WindowState w) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700990 super.addWindow(w);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700991
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700992 boolean gotReplacementWindow = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700993 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700994 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700995 gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w);
996 }
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700997
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700998 // if we got a replacement window, reset the timeout to give drawing more time
999 if (gotReplacementWindow) {
1000 mService.scheduleWindowReplacementTimeouts(this);
Robert Carra1eb4392015-12-10 12:43:51 -08001001 }
Jorim Jaggife762342016-10-13 14:33:27 +02001002 checkKeyguardFlagsChanged();
1003 }
1004
1005 @Override
1006 void removeChild(WindowState child) {
1007 super.removeChild(child);
1008 checkKeyguardFlagsChanged();
Adrian Roos23df3a32018-03-15 15:41:13 +01001009 updateLetterboxSurface(child);
Robert Carra1eb4392015-12-10 12:43:51 -08001010 }
1011
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001012 private boolean waitingForReplacement() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001013 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001014 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001015 if (candidate.waitingForReplacement()) {
Robert Carra1eb4392015-12-10 12:43:51 -08001016 return true;
1017 }
1018 }
1019 return false;
1020 }
1021
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001022 void onWindowReplacementTimeout() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001023 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001024 (mChildren.get(i)).onWindowReplacementTimeout();
Robert Carra1eb4392015-12-10 12:43:51 -08001025 }
1026 }
1027
Winson Chung30480042017-01-26 10:55:34 -08001028 void reparent(Task task, int position) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001029 final Task currentTask = getTask();
1030 if (task == currentTask) {
Winson Chung30480042017-01-26 10:55:34 -08001031 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001032 "window token=" + this + " already child of task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -08001033 }
Bryce Lee6d410262017-02-28 15:30:17 -08001034
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001035 if (currentTask.mStack != task.mStack) {
Bryce Lee6d410262017-02-28 15:30:17 -08001036 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001037 "window token=" + this + " current task=" + currentTask
Bryce Lee6d410262017-02-28 15:30:17 -08001038 + " belongs to a different stack than " + task);
1039 }
1040
Winson Chung30480042017-01-26 10:55:34 -08001041 if (DEBUG_ADD_REMOVE) Slog.i(TAG, "reParentWindowToken: removing window token=" + this
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001042 + " from task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -08001043 final DisplayContent prevDisplayContent = getDisplayContent();
1044
Bryce Lee6d410262017-02-28 15:30:17 -08001045 mReparenting = true;
1046
Winson Chung30480042017-01-26 10:55:34 -08001047 getParent().removeChild(this);
1048 task.addChild(this, position);
1049
Bryce Lee6d410262017-02-28 15:30:17 -08001050 mReparenting = false;
1051
Winson Chung30480042017-01-26 10:55:34 -08001052 // Relayout display(s).
1053 final DisplayContent displayContent = task.getDisplayContent();
1054 displayContent.setLayoutNeeded();
1055 if (prevDisplayContent != displayContent) {
1056 onDisplayChanged(displayContent);
1057 prevDisplayContent.setLayoutNeeded();
1058 }
1059 }
1060
Jorim Jaggi0429f352015-12-22 16:29:16 +01001061 /**
1062 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
1063 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
1064 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
1065 * with a queue.
1066 */
Chong Zhangd78ddb42016-03-02 17:01:14 -08001067 private void freezeBounds() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001068 final Task task = getTask();
1069 mFrozenBounds.offer(new Rect(task.mPreparedFrozenBounds));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001070
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001071 if (task.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) {
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001072 // We didn't call prepareFreezingBounds on the task, so use the current value.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001073 mFrozenMergedConfig.offer(new Configuration(task.getConfiguration()));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001074 } else {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001075 mFrozenMergedConfig.offer(new Configuration(task.mPreparedFrozenMergedConfig));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001076 }
Andrii Kulianb10330d2016-09-16 13:51:46 -07001077 // Calling unset() to make it equal to Configuration.EMPTY.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001078 task.mPreparedFrozenMergedConfig.unset();
Jorim Jaggi0429f352015-12-22 16:29:16 +01001079 }
1080
1081 /**
1082 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
1083 */
Chong Zhangd78ddb42016-03-02 17:01:14 -08001084 private void unfreezeBounds() {
Robert Carr68375192017-06-13 12:41:53 -07001085 if (mFrozenBounds.isEmpty()) {
1086 return;
Wale Ogunwale37dbafc2016-06-27 10:15:20 -07001087 }
Robert Carr68375192017-06-13 12:41:53 -07001088 mFrozenBounds.remove();
Wale Ogunwale37dbafc2016-06-27 10:15:20 -07001089 if (!mFrozenMergedConfig.isEmpty()) {
1090 mFrozenMergedConfig.remove();
1091 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001092 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001093 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001094 win.onUnfreezeBounds();
Jorim Jaggi4846ee32016-01-07 17:39:12 +01001095 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001096 mService.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +01001097 }
1098
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001099 void setAppLayoutChanges(int changes, String reason) {
1100 if (!mChildren.isEmpty()) {
1101 final DisplayContent dc = getDisplayContent();
1102 dc.pendingLayoutChanges |= changes;
1103 if (DEBUG_LAYOUT_REPEATS) {
1104 mService.mWindowPlacerLocked.debugLayoutRepeats(reason, dc.pendingLayoutChanges);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001105 }
1106 }
1107 }
1108
1109 void removeReplacedWindowIfNeeded(WindowState replacement) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001110 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001111 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001112 if (win.removeReplacedWindowIfNeeded(replacement)) {
1113 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001114 }
1115 }
1116 }
1117
1118 void startFreezingScreen() {
1119 if (DEBUG_ORIENTATION) logWithStack(TAG, "Set freezing of " + appToken + ": hidden="
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001120 + isHidden() + " freezing=" + mFreezingScreen + " hiddenRequested="
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001121 + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001122 if (!hiddenRequested) {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001123 if (!mFreezingScreen) {
1124 mFreezingScreen = true;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001125 mService.registerAppFreezeListener(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001126 mService.mAppsFreezingScreen++;
1127 if (mService.mAppsFreezingScreen == 1) {
Robert Carrae606b42018-02-15 15:36:23 -08001128 mService.startFreezingDisplayLocked(0, 0, getDisplayContent());
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001129 mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT);
1130 mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001131 }
1132 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001133 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001134 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001135 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001136 w.onStartFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001137 }
1138 }
1139 }
1140
1141 void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001142 if (!mFreezingScreen) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001143 return;
1144 }
1145 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + this + " force=" + force);
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001146 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001147 boolean unfrozeWindows = false;
1148 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001149 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001150 unfrozeWindows |= w.onStopFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001151 }
1152 if (force || unfrozeWindows) {
1153 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this);
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001154 mFreezingScreen = false;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001155 mService.unregisterAppFreezeListener(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001156 mService.mAppsFreezingScreen--;
1157 mService.mLastFinishedFreezeSource = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001158 }
1159 if (unfreezeSurfaceNow) {
1160 if (unfrozeWindows) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001161 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001162 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001163 mService.stopFreezingDisplayLocked();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001164 }
1165 }
1166
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001167 @Override
1168 public void onAppFreezeTimeout() {
1169 Slog.w(TAG_WM, "Force clearing freeze: " + this);
1170 stopFreezingScreen(true, true);
1171 }
1172
Jorim Jaggi60f9c972018-02-01 19:21:07 +01001173 /**
1174 * Tries to transfer the starting window from a token that's above ourselves in the task but
1175 * not visible anymore. This is a common scenario apps use: Trampoline activity T start main
1176 * activity M in the same task. Now, when reopening the task, T starts on top of M but then
1177 * immediately finishes after, so we have to transfer T to M.
1178 */
1179 void transferStartingWindowFromHiddenAboveTokenIfNeeded() {
1180 final Task task = getTask();
1181 for (int i = task.mChildren.size() - 1; i >= 0; i--) {
1182 final AppWindowToken fromToken = task.mChildren.get(i);
1183 if (fromToken == this) {
1184 return;
1185 }
1186 if (fromToken.hiddenRequested && transferStartingWindow(fromToken.token)) {
1187 return;
1188 }
1189 }
1190 }
1191
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001192 boolean transferStartingWindow(IBinder transferFrom) {
Wale Ogunwale02319a62016-09-26 15:21:22 -07001193 final AppWindowToken fromToken = getDisplayContent().getAppWindowToken(transferFrom);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001194 if (fromToken == null) {
1195 return false;
1196 }
1197
1198 final WindowState tStartingWindow = fromToken.startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001199 if (tStartingWindow != null && fromToken.startingSurface != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001200 // In this case, the starting icon has already been displayed, so start
1201 // letting windows get shown immediately without any more transitions.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001202 mService.mSkipAppTransitionAnimation = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001203
1204 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow
1205 + " from " + fromToken + " to " + this);
1206
1207 final long origId = Binder.clearCallingIdentity();
Peter Visontay3556a3b2017-11-01 17:23:17 +00001208 try {
1209 // Transfer the starting window over to the new token.
1210 startingData = fromToken.startingData;
1211 startingSurface = fromToken.startingSurface;
1212 startingDisplayed = fromToken.startingDisplayed;
1213 fromToken.startingDisplayed = false;
1214 startingWindow = tStartingWindow;
1215 reportedVisible = fromToken.reportedVisible;
1216 fromToken.startingData = null;
1217 fromToken.startingSurface = null;
1218 fromToken.startingWindow = null;
1219 fromToken.startingMoved = true;
1220 tStartingWindow.mToken = this;
1221 tStartingWindow.mAppToken = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001222
Peter Visontay3556a3b2017-11-01 17:23:17 +00001223 if (DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1224 "Removing starting " + tStartingWindow + " from " + fromToken);
1225 fromToken.removeChild(tStartingWindow);
1226 fromToken.postWindowRemoveStartingWindowCleanup(tStartingWindow);
1227 fromToken.mHiddenSetFromTransferredStartingWindow = false;
1228 addWindow(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001229
Peter Visontay3556a3b2017-11-01 17:23:17 +00001230 // Propagate other interesting state between the tokens. If the old token is displayed,
1231 // we should immediately force the new one to be displayed. If it is animating, we need
1232 // to move that animation to the new one.
1233 if (fromToken.allDrawn) {
1234 allDrawn = true;
1235 deferClearAllDrawn = fromToken.deferClearAllDrawn;
1236 }
1237 if (fromToken.firstWindowDrawn) {
1238 firstWindowDrawn = true;
1239 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001240 if (!fromToken.isHidden()) {
1241 setHidden(false);
Peter Visontay3556a3b2017-11-01 17:23:17 +00001242 hiddenRequested = false;
1243 mHiddenSetFromTransferredStartingWindow = true;
1244 }
1245 setClientHidden(fromToken.mClientHidden);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001246
Jorim Jaggi980c9de2017-11-17 01:41:37 +01001247 transferAnimation(fromToken);
1248
1249 // When transferring an animation, we no longer need to apply an animation to the
1250 // the token we transfer the animation over. Thus, remove the animation from
1251 // pending opening apps.
1252 mService.mOpeningApps.remove(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001253
Peter Visontay3556a3b2017-11-01 17:23:17 +00001254 mService.updateFocusedWindowLocked(
1255 UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/);
1256 getDisplayContent().setLayoutNeeded();
1257 mService.mWindowPlacerLocked.performSurfacePlacement();
1258 } finally {
1259 Binder.restoreCallingIdentity(origId);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001260 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001261 return true;
1262 } else if (fromToken.startingData != null) {
1263 // The previous app was getting ready to show a
1264 // starting window, but hasn't yet done so. Steal it!
1265 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1266 "Moving pending starting from " + fromToken + " to " + this);
1267 startingData = fromToken.startingData;
1268 fromToken.startingData = null;
1269 fromToken.startingMoved = true;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001270 if (getController() != null) {
1271 getController().scheduleAddStartingWindow();
1272 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001273 return true;
1274 }
1275
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001276 // TODO: Transfer thumbnail
1277
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001278 return false;
1279 }
1280
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001281 boolean isLastWindow(WindowState win) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001282 return mChildren.size() == 1 && mChildren.get(0) == win;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001283 }
1284
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001285 @Override
1286 void onAppTransitionDone() {
1287 sendingToBottom = false;
1288 }
1289
Wale Ogunwale51362492016-09-08 17:49:17 -07001290 /**
1291 * We override because this class doesn't want its children affecting its reported orientation
1292 * in anyway.
1293 */
1294 @Override
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001295 int getOrientation(int candidate) {
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001296 if (candidate == SCREEN_ORIENTATION_BEHIND) {
1297 // Allow app to specify orientation regardless of its visibility state if the current
1298 // candidate want us to use orientation behind. I.e. the visible app on-top of this one
1299 // wants us to use the orientation of the app behind it.
1300 return mOrientation;
1301 }
1302
Bryce Lee61fbcbc2017-03-10 14:14:03 -08001303 // The {@link AppWindowToken} should only specify an orientation when it is not closing or
1304 // going to the bottom. Allowing closing {@link AppWindowToken} to participate can lead to
1305 // an Activity in another task being started in the wrong orientation during the transition.
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001306 if (!(sendingToBottom || mService.mClosingApps.contains(this))
Andrii Kulian0918d362018-05-23 17:01:37 -07001307 && (isVisible() || mService.mOpeningApps.contains(this))) {
Bryce Leea163b762017-01-24 11:05:01 -08001308 return mOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001309 }
Bryce Leea163b762017-01-24 11:05:01 -08001310
1311 return SCREEN_ORIENTATION_UNSET;
Wale Ogunwale51362492016-09-08 17:49:17 -07001312 }
1313
Wale Ogunwaleb198b742016-12-01 08:44:09 -08001314 /** Returns the app's preferred orientation regardless of its currently visibility state. */
1315 int getOrientationIgnoreVisibility() {
1316 return mOrientation;
1317 }
1318
Craig Mautnerdbb79912012-03-01 18:59:14 -08001319 @Override
Winson Chunge55c0192017-08-24 14:50:48 -07001320 public void onConfigurationChanged(Configuration newParentConfig) {
1321 final int prevWinMode = getWindowingMode();
1322 super.onConfigurationChanged(newParentConfig);
1323 final int winMode = getWindowingMode();
1324
1325 if (prevWinMode == winMode) {
1326 return;
1327 }
1328
1329 if (prevWinMode != WINDOWING_MODE_UNDEFINED && winMode == WINDOWING_MODE_PINNED) {
1330 // Entering PiP from fullscreen, reset the snap fraction
1331 mDisplayContent.mPinnedStackControllerLocked.resetReentrySnapFraction(this);
Winson Chung82267ce2018-04-06 16:38:26 -07001332 } else if (prevWinMode == WINDOWING_MODE_PINNED && winMode != WINDOWING_MODE_UNDEFINED
1333 && !isHidden()) {
Winson Chunge55c0192017-08-24 14:50:48 -07001334 // Leaving PiP to fullscreen, save the snap fraction based on the pre-animation bounds
1335 // for the next re-entry into PiP (assuming the activity is not hidden or destroyed)
1336 final TaskStack pinnedStack = mDisplayContent.getPinnedStack();
1337 if (pinnedStack != null) {
Winson Chung8efa1652018-06-06 09:34:23 -07001338 final Rect stackBounds;
1339 if (pinnedStack.lastAnimatingBoundsWasToFullscreen()) {
1340 // We are animating the bounds, use the pre-animation bounds to save the snap
1341 // fraction
1342 stackBounds = pinnedStack.mPreAnimationBounds;
1343 } else {
1344 // We skip the animation if the fullscreen configuration is not compatible, so
1345 // use the current bounds to calculate the saved snap fraction instead
1346 // (see PinnedActivityStack.skipResizeAnimation())
1347 stackBounds = mTmpRect;
1348 pinnedStack.getBounds(stackBounds);
1349 }
Winson Chunge55c0192017-08-24 14:50:48 -07001350 mDisplayContent.mPinnedStackControllerLocked.saveReentrySnapFraction(this,
Winson Chung8efa1652018-06-06 09:34:23 -07001351 stackBounds);
Winson Chunge55c0192017-08-24 14:50:48 -07001352 }
1353 }
1354 }
1355
1356 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001357 void checkAppWindowsReadyToShow() {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001358 if (allDrawn == mLastAllDrawn) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001359 return;
1360 }
1361
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001362 mLastAllDrawn = allDrawn;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001363 if (!allDrawn) {
1364 return;
1365 }
1366
1367 // The token has now changed state to having all windows shown... what to do, what to do?
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001368 if (mFreezingScreen) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001369 showAllWindowsLocked();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001370 stopFreezingScreen(false, true);
1371 if (DEBUG_ORIENTATION) Slog.i(TAG,
1372 "Setting mOrientationChangeComplete=true because wtoken " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001373 + " numInteresting=" + mNumInterestingWindows + " numDrawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001374 // This will set mOrientationChangeComplete and cause a pass through layout.
1375 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001376 "checkAppWindowsReadyToShow: freezingScreen");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001377 } else {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001378 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001379
1380 // We can now show all of the drawn windows!
Jorim Jaggiaf0d6d22018-06-08 15:25:35 +02001381 if (!mService.mOpeningApps.contains(this) && canShowWindows()) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001382 showAllWindowsLocked();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001383 }
1384 }
1385 }
1386
Matthew Ng5d23afa2017-06-21 16:16:24 -07001387 /**
Bryce Leed390deb2017-06-22 13:14:28 -07001388 * Returns whether the drawn window states of this {@link AppWindowToken} has considered every
1389 * child {@link WindowState}. A child is considered if it has been passed into
1390 * {@link #updateDrawnWindowStates(WindowState)} after being added. This is used to determine
1391 * whether states, such as {@code allDrawn}, can be set, which relies on state variables such as
1392 * {@code mNumInterestingWindows}, which depend on all {@link WindowState}s being considered.
1393 *
1394 * @return {@code true} If all children have been considered, {@code false}.
1395 */
1396 private boolean allDrawnStatesConsidered() {
Bryce Lee6311c4b2017-07-06 14:09:29 -07001397 for (int i = mChildren.size() - 1; i >= 0; --i) {
1398 final WindowState child = mChildren.get(i);
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001399 if (child.mightAffectAllDrawn() && !child.getDrawnStateEvaluated()) {
Bryce Leed390deb2017-06-22 13:14:28 -07001400 return false;
1401 }
1402 }
1403 return true;
1404 }
1405
1406 /**
Matthew Ng5d23afa2017-06-21 16:16:24 -07001407 * Determines if the token has finished drawing. This should only be called from
1408 * {@link DisplayContent#applySurfaceChangesTransaction}
1409 */
Matthew Ng498c71d2017-04-18 13:55:45 -07001410 void updateAllDrawn() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001411 if (!allDrawn) {
Matthew Ng498c71d2017-04-18 13:55:45 -07001412 // Number of drawn windows can be less when a window is being relaunched, wait for
Bryce Leed390deb2017-06-22 13:14:28 -07001413 // all windows to be launched and drawn for this token be considered all drawn.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001414 final int numInteresting = mNumInterestingWindows;
Bryce Leed390deb2017-06-22 13:14:28 -07001415
1416 // We must make sure that all present children have been considered (determined by
1417 // {@link #allDrawnStatesConsidered}) before evaluating whether everything has been
1418 // drawn.
1419 if (numInteresting > 0 && allDrawnStatesConsidered()
1420 && mNumDrawnWindows >= numInteresting && !isRelaunching()) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001421 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawn: " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001422 + " interesting=" + numInteresting + " drawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001423 allDrawn = true;
1424 // Force an additional layout pass where
1425 // WindowStateAnimator#commitFinishDrawingLocked() will call performShowLocked().
Matthew Ng498c71d2017-04-18 13:55:45 -07001426 if (mDisplayContent != null) {
1427 mDisplayContent.setLayoutNeeded();
1428 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001429 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Robert Carrecc06b32017-04-18 14:25:10 -07001430
Winson Chunge7ba6862017-05-24 12:13:33 -07001431 // Notify the pinned stack upon all windows drawn. If there was an animation in
1432 // progress then this signal will resume that animation.
Wale Ogunwale61911492017-10-11 08:50:50 -07001433 final TaskStack pinnedStack = mDisplayContent.getPinnedStack();
Winson Chunge7ba6862017-05-24 12:13:33 -07001434 if (pinnedStack != null) {
1435 pinnedStack.onAllWindowsDrawn();
Robert Carrecc06b32017-04-18 14:25:10 -07001436 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001437 }
1438 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001439 }
1440
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001441 /**
1442 * Updated this app token tracking states for interesting and drawn windows based on the window.
1443 *
1444 * @return Returns true if the input window is considered interesting and drawn while all the
1445 * windows in this app token where not considered drawn as of the last pass.
1446 */
1447 boolean updateDrawnWindowStates(WindowState w) {
Bryce Leed390deb2017-06-22 13:14:28 -07001448 w.setDrawnStateEvaluated(true /*evaluated*/);
1449
Jorim Jaggie4b0f282017-05-17 15:10:29 +02001450 if (DEBUG_STARTING_WINDOW_VERBOSE && w == startingWindow) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001451 Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" + w.isOnScreen()
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001452 + " allDrawn=" + allDrawn + " freezingScreen=" + mFreezingScreen);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001453 }
1454
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001455 if (allDrawn && !mFreezingScreen) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001456 return false;
1457 }
1458
1459 if (mLastTransactionSequence != mService.mTransactionSequence) {
1460 mLastTransactionSequence = mService.mTransactionSequence;
Matthew Ng53e66b22018-01-12 17:13:13 -08001461 mNumDrawnWindows = 0;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001462 startingDisplayed = false;
Matthew Ng53e66b22018-01-12 17:13:13 -08001463
1464 // There is the main base application window, even if it is exiting, wait for it
1465 mNumInterestingWindows = findMainWindow(false /* includeStartingApp */) != null ? 1 : 0;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001466 }
1467
1468 final WindowStateAnimator winAnimator = w.mWinAnimator;
1469
1470 boolean isInterestingAndDrawn = false;
1471
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001472 if (!allDrawn && w.mightAffectAllDrawn()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001473 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
1474 Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw()
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001475 + ", isAnimationSet=" + isSelfAnimating());
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001476 if (!w.isDrawnLw()) {
1477 Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController
1478 + " pv=" + w.mPolicyVisibility
1479 + " mDrawState=" + winAnimator.drawStateToString()
1480 + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001481 + " a=" + isSelfAnimating());
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001482 }
1483 }
1484
1485 if (w != startingWindow) {
1486 if (w.isInteresting()) {
Matthew Ng53e66b22018-01-12 17:13:13 -08001487 // Add non-main window as interesting since the main app has already been added
1488 if (findMainWindow(false /* includeStartingApp */) != w) {
1489 mNumInterestingWindows++;
1490 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001491 if (w.isDrawnLw()) {
1492 mNumDrawnWindows++;
1493
1494 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, "tokenMayBeDrawn: "
1495 + this + " w=" + w + " numInteresting=" + mNumInterestingWindows
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001496 + " freezingScreen=" + mFreezingScreen
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001497 + " mAppFreezing=" + w.mAppFreezing);
1498
1499 isInterestingAndDrawn = true;
1500 }
1501 }
1502 } else if (w.isDrawnLw()) {
Jorim Jaggi3878ca32017-02-02 17:13:05 -08001503 if (getController() != null) {
1504 getController().reportStartingWindowDrawn();
1505 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001506 startingDisplayed = true;
1507 }
1508 }
1509
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001510 return isInterestingAndDrawn;
1511 }
1512
Adrian Roos23df3a32018-03-15 15:41:13 +01001513 void layoutLetterbox(WindowState winHint) {
Adrian Roos4d18a2e2017-12-19 19:08:05 +01001514 final WindowState w = findMainWindow();
Adrian Roosf93b6d22018-03-21 13:48:26 +01001515 if (w == null || winHint != null && w != winHint) {
Adrian Roos4d18a2e2017-12-19 19:08:05 +01001516 return;
1517 }
Jorim Jaggia32da382018-03-28 18:01:22 +02001518 final boolean surfaceReady = w.isDrawnLw() // Regular case
Adrian Roosf93b6d22018-03-21 13:48:26 +01001519 || w.mWinAnimator.mSurfaceDestroyDeferred // The preserved surface is still ready.
1520 || w.isDragResizeChanged(); // Waiting for relayoutWindow to call preserveSurface.
1521 final boolean needsLetterbox = w.isLetterboxedAppWindow() && fillsParent() && surfaceReady;
Adrian Roos4d18a2e2017-12-19 19:08:05 +01001522 if (needsLetterbox) {
1523 if (mLetterbox == null) {
1524 mLetterbox = new Letterbox(() -> makeChildSurface(null));
1525 }
chaviw492139a2018-07-16 16:07:35 -07001526 mLetterbox.layout(getParent().getBounds(), w.getFrameLw());
Adrian Roos4d18a2e2017-12-19 19:08:05 +01001527 } else if (mLetterbox != null) {
Adrian Roos23df3a32018-03-15 15:41:13 +01001528 mLetterbox.hide();
1529 }
1530 }
1531
1532 void updateLetterboxSurface(WindowState winHint) {
1533 final WindowState w = findMainWindow();
1534 if (w != winHint && winHint != null && w != null) {
1535 return;
1536 }
1537 layoutLetterbox(winHint);
1538 if (mLetterbox != null && mLetterbox.needsApplySurfaceChanges()) {
1539 mLetterbox.applySurfaceChanges(mPendingTransaction);
Adrian Roos4d18a2e2017-12-19 19:08:05 +01001540 }
1541 }
1542
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001543 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001544 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001545 // For legacy reasons we process the TaskStack.mExitingAppTokens first in DisplayContent
1546 // before the non-exiting app tokens. So, we skip the exiting app tokens here.
1547 // TODO: Investigate if we need to continue to do this or if we can just process them
1548 // in-order.
1549 if (mIsExiting && !waitingForReplacement()) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001550 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001551 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001552 return forAllWindowsUnchecked(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001553 }
1554
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001555 boolean forAllWindowsUnchecked(ToBooleanFunction<WindowState> callback,
1556 boolean traverseTopToBottom) {
1557 return super.forAllWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001558 }
1559
1560 @Override
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001561 AppWindowToken asAppWindowToken() {
1562 // I am an app window token!
1563 return this;
1564 }
1565
1566 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -07001567 boolean fillsParent() {
1568 return mFillsParent;
1569 }
1570
1571 void setFillsParent(boolean fillsParent) {
1572 mFillsParent = fillsParent;
1573 }
1574
Jorim Jaggife762342016-10-13 14:33:27 +02001575 boolean containsDismissKeyguardWindow() {
Bryce Lee081554b2017-05-25 07:52:12 -07001576 // Window state is transient during relaunch. We are not guaranteed to be frozen during the
1577 // entirety of the relaunch.
1578 if (isRelaunching()) {
1579 return mLastContainsDismissKeyguardWindow;
1580 }
1581
Jorim Jaggife762342016-10-13 14:33:27 +02001582 for (int i = mChildren.size() - 1; i >= 0; i--) {
1583 if ((mChildren.get(i).mAttrs.flags & FLAG_DISMISS_KEYGUARD) != 0) {
1584 return true;
1585 }
1586 }
1587 return false;
1588 }
1589
1590 boolean containsShowWhenLockedWindow() {
Bryce Lee081554b2017-05-25 07:52:12 -07001591 // When we are relaunching, it is possible for us to be unfrozen before our previous
1592 // windows have been added back. Using the cached value ensures that our previous
1593 // showWhenLocked preference is honored until relaunching is complete.
1594 if (isRelaunching()) {
1595 return mLastContainsShowWhenLockedWindow;
1596 }
1597
Jorim Jaggife762342016-10-13 14:33:27 +02001598 for (int i = mChildren.size() - 1; i >= 0; i--) {
1599 if ((mChildren.get(i).mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
1600 return true;
1601 }
1602 }
Bryce Lee081554b2017-05-25 07:52:12 -07001603
Jorim Jaggife762342016-10-13 14:33:27 +02001604 return false;
1605 }
1606
1607 void checkKeyguardFlagsChanged() {
1608 final boolean containsDismissKeyguard = containsDismissKeyguardWindow();
1609 final boolean containsShowWhenLocked = containsShowWhenLockedWindow();
1610 if (containsDismissKeyguard != mLastContainsDismissKeyguardWindow
1611 || containsShowWhenLocked != mLastContainsShowWhenLockedWindow) {
1612 mService.notifyKeyguardFlagsChanged(null /* callback */);
1613 }
1614 mLastContainsDismissKeyguardWindow = containsDismissKeyguard;
1615 mLastContainsShowWhenLockedWindow = containsShowWhenLocked;
1616 }
1617
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001618 WindowState getImeTargetBelowWindow(WindowState w) {
1619 final int index = mChildren.indexOf(w);
1620 if (index > 0) {
1621 final WindowState target = mChildren.get(index - 1);
1622 if (target.canBeImeTarget()) {
1623 return target;
1624 }
1625 }
1626 return null;
1627 }
1628
Winson Chungbe9be7f2017-06-28 10:55:22 -07001629 int getLowestAnimLayer() {
1630 for (int i = 0; i < mChildren.size(); i++) {
1631 final WindowState w = mChildren.get(i);
1632 if (w.mRemoved) {
1633 continue;
1634 }
1635 return w.mWinAnimator.mAnimLayer;
1636 }
1637 return Integer.MAX_VALUE;
1638 }
1639
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001640 WindowState getHighestAnimLayerWindow(WindowState currentTarget) {
1641 WindowState candidate = null;
1642 for (int i = mChildren.indexOf(currentTarget); i >= 0; i--) {
1643 final WindowState w = mChildren.get(i);
1644 if (w.mRemoved) {
1645 continue;
1646 }
1647 if (candidate == null || w.mWinAnimator.mAnimLayer >
1648 candidate.mWinAnimator.mAnimLayer) {
1649 candidate = w;
1650 }
1651 }
1652 return candidate;
1653 }
1654
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001655 /**
1656 * See {@link Activity#setDisablePreviewScreenshots}.
1657 */
1658 void setDisablePreviewScreenshots(boolean disable) {
Wale Ogunwale6c459212017-05-17 08:56:03 -07001659 mDisablePreviewScreenshots = disable;
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001660 }
1661
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001662 /**
chaviwd3bf08d2017-08-01 17:24:59 -07001663 * Sets whether the current launch can turn the screen on. See {@link #canTurnScreenOn()}
1664 */
1665 void setCanTurnScreenOn(boolean canTurnScreenOn) {
1666 mCanTurnScreenOn = canTurnScreenOn;
1667 }
1668
1669 /**
1670 * Indicates whether the current launch can turn the screen on. This is to prevent multiple
1671 * relayouts from turning the screen back on. The screen should only turn on at most
1672 * once per activity resume.
1673 *
1674 * @return true if the screen can be turned on.
1675 */
1676 boolean canTurnScreenOn() {
1677 return mCanTurnScreenOn;
1678 }
1679
1680 /**
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001681 * Retrieves whether we'd like to generate a snapshot that's based solely on the theme. This is
1682 * the case when preview screenshots are disabled {@link #setDisablePreviewScreenshots} or when
1683 * we can't take a snapshot for other reasons, for example, if we have a secure window.
1684 *
1685 * @return True if we need to generate an app theme snapshot, false if we'd like to take a real
1686 * screenshot.
1687 */
1688 boolean shouldUseAppThemeSnapshot() {
Wale Ogunwale6c459212017-05-17 08:56:03 -07001689 return mDisablePreviewScreenshots || forAllWindows(w -> (w.mAttrs.flags & FLAG_SECURE) != 0,
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001690 true /* topToBottom */);
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001691 }
1692
Jorim Jaggibe418292018-03-26 16:14:12 +02001693 SurfaceControl getAppAnimationLayer() {
Jorim Jaggi391790622018-04-18 15:30:44 +02001694 return getAppAnimationLayer(isActivityTypeHome() ? ANIMATION_LAYER_HOME
1695 : needsZBoost() ? ANIMATION_LAYER_BOOSTED
1696 : ANIMATION_LAYER_STANDARD);
Jorim Jaggibe418292018-03-26 16:14:12 +02001697 }
1698
chaviw23ee71c2017-12-18 11:29:41 -08001699 @Override
Jorim Jaggi596a1992017-12-29 14:48:02 +01001700 public SurfaceControl getAnimationLeashParent() {
Robert Carrb9506032018-02-13 13:54:00 -08001701 // All normal app transitions take place in an animation layer which is below the pinned
1702 // stack but may be above the parent stacks of the given animating apps.
1703 // For transitions in the pinned stack (menu activity) we just let them occur as a child
1704 // of the pinned stack.
1705 if (!inPinnedWindowingMode()) {
1706 return getAppAnimationLayer();
1707 } else {
1708 return getStack().getSurfaceControl();
1709 }
chaviw23ee71c2017-12-18 11:29:41 -08001710 }
1711
Jorim Jaggic6976f02018-04-18 16:31:07 +02001712 private boolean shouldAnimate(int transit) {
1713 final boolean isSplitScreenPrimary =
1714 getWindowingMode() == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY;
1715 final boolean allowSplitScreenPrimaryAnimation = transit != TRANSIT_WALLPAPER_OPEN;
1716
1717 // We animate always if it's not split screen primary, and only some special cases in split
1718 // screen primary because it causes issues with stack clipping when we run an un-minimize
1719 // animation at the same time.
1720 return !isSplitScreenPrimary || allowSplitScreenPrimaryAnimation;
1721 }
1722
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001723 boolean applyAnimationLocked(WindowManager.LayoutParams lp, int transit, boolean enter,
1724 boolean isVoiceInteraction) {
1725
Jorim Jaggic6976f02018-04-18 16:31:07 +02001726 if (mService.mDisableTransitionAnimation || !shouldAnimate(transit)) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001727 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
Jorim Jaggic6976f02018-04-18 16:31:07 +02001728 Slog.v(TAG_WM, "applyAnimation: transition animation is disabled or skipped."
1729 + " atoken=" + this);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001730 }
1731 cancelAnimation();
1732 return false;
1733 }
1734
1735 // Only apply an animation if the display isn't frozen. If it is frozen, there is no reason
1736 // to animate and it can cause strange artifacts when we unfreeze the display if some
1737 // different animation is running.
1738 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "AWT#applyAnimationLocked");
1739 if (okToAnimate()) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001740 final AnimationAdapter adapter;
1741 final TaskStack stack = getStack();
1742 mTmpPoint.set(0, 0);
1743 mTmpRect.setEmpty();
1744 if (stack != null) {
1745 stack.getRelativePosition(mTmpPoint);
1746 stack.getBounds(mTmpRect);
1747 mTmpRect.offsetTo(0, 0);
1748 }
Jorim Jaggic4d29f22018-03-22 16:30:56 +01001749
1750 // Delaying animation start isn't compatible with remote animations at all.
1751 if (mService.mAppTransition.getRemoteAnimationController() != null
1752 && !mSurfaceAnimator.isAnimationStartDelayed()) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001753 adapter = mService.mAppTransition.getRemoteAnimationController()
1754 .createAnimationAdapter(this, mTmpPoint, mTmpRect);
1755 } else {
1756 final Animation a = loadAnimation(lp, transit, enter, isVoiceInteraction);
1757 if (a != null) {
1758 adapter = new LocalAnimationAdapter(
1759 new WindowAnimationSpec(a, mTmpPoint, mTmpRect,
1760 mService.mAppTransition.canSkipFirstFrame(),
Jorim Jaggiaa763cd2018-03-22 23:20:36 +01001761 mService.mAppTransition.getAppStackClipMode(),
1762 true /* isAppAnimation */),
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001763 mService.mSurfaceAnimationRunner);
1764 if (a.getZAdjustment() == Animation.ZORDER_TOP) {
1765 mNeedsZBoost = true;
1766 }
1767 mTransit = transit;
1768 mTransitFlags = mService.mAppTransition.getTransitFlags();
1769 } else {
1770 adapter = null;
chaviw23ee71c2017-12-18 11:29:41 -08001771 }
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001772 }
1773 if (adapter != null) {
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001774 startAnimation(getPendingTransaction(), adapter, !isVisible());
Jorim Jaggi82c17862018-02-21 17:50:18 +01001775 if (adapter.getShowWallpaper()) {
1776 mDisplayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
1777 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001778 }
1779 } else {
1780 cancelAnimation();
1781 }
1782 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
1783
1784 return isReallyAnimating();
1785 }
1786
1787 private Animation loadAnimation(WindowManager.LayoutParams lp, int transit, boolean enter,
1788 boolean isVoiceInteraction) {
1789 final DisplayContent displayContent = getTask().getDisplayContent();
1790 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
1791 final int width = displayInfo.appWidth;
1792 final int height = displayInfo.appHeight;
1793 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG_WM,
1794 "applyAnimation: atoken=" + this);
1795
1796 // Determine the visible rect to calculate the thumbnail clip
1797 final WindowState win = findMainWindow();
1798 final Rect frame = new Rect(0, 0, width, height);
1799 final Rect displayFrame = new Rect(0, 0,
1800 displayInfo.logicalWidth, displayInfo.logicalHeight);
1801 final Rect insets = new Rect();
1802 final Rect stableInsets = new Rect();
1803 Rect surfaceInsets = null;
1804 final boolean freeform = win != null && win.inFreeformWindowingMode();
1805 if (win != null) {
1806 // Containing frame will usually cover the whole screen, including dialog windows.
1807 // For freeform workspace windows it will not cover the whole screen and it also
1808 // won't exactly match the final freeform window frame (e.g. when overlapping with
1809 // the status bar). In that case we need to use the final frame.
1810 if (freeform) {
chaviw492139a2018-07-16 16:07:35 -07001811 frame.set(win.getFrameLw());
Adrian Roos4d18a2e2017-12-19 19:08:05 +01001812 } else if (win.isLetterboxedAppWindow()) {
1813 frame.set(getTask().getBounds());
Winson Chungc1674272018-02-21 10:15:17 -08001814 } else if (win.isDockedResizing()) {
1815 // If we are animating while docked resizing, then use the stack bounds as the
1816 // animation target (which will be different than the task bounds)
1817 frame.set(getTask().getParent().getBounds());
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001818 } else {
chaviw553b0212018-07-12 13:37:01 -07001819 frame.set(win.getContainingFrame());
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001820 }
1821 surfaceInsets = win.getAttrs().surfaceInsets;
Adrian Roos20e07892018-02-23 19:12:01 +01001822 // XXX(b/72757033): These are insets relative to the window frame, but we're really
1823 // interested in the insets relative to the frame we chose in the if-blocks above.
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001824 insets.set(win.mContentInsets);
1825 stableInsets.set(win.mStableInsets);
1826 }
1827
1828 if (mLaunchTaskBehind) {
1829 // Differentiate the two animations. This one which is briefly on the screen
1830 // gets the !enter animation, and the other activity which remains on the
1831 // screen gets the enter animation. Both appear in the mOpeningApps set.
1832 enter = false;
1833 }
1834 if (DEBUG_APP_TRANSITIONS) Slog.d(TAG_WM, "Loading animation for app transition."
1835 + " transit=" + AppTransition.appTransitionToString(transit) + " enter=" + enter
1836 + " frame=" + frame + " insets=" + insets + " surfaceInsets=" + surfaceInsets);
1837 final Configuration displayConfig = displayContent.getConfiguration();
1838 final Animation a = mService.mAppTransition.loadAnimation(lp, transit, enter,
1839 displayConfig.uiMode, displayConfig.orientation, frame, displayFrame, insets,
1840 surfaceInsets, stableInsets, isVoiceInteraction, freeform, getTask().mTaskId);
1841 if (a != null) {
1842 if (DEBUG_ANIM) logWithStack(TAG, "Loaded animation " + a + " for " + this);
1843 final int containingWidth = frame.width();
1844 final int containingHeight = frame.height();
1845 a.initialize(containingWidth, containingHeight, width, height);
1846 a.scaleCurrentDuration(mService.getTransitionAnimationScaleLocked());
1847 }
1848 return a;
1849 }
1850
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001851 @Override
Jorim Jaggi6de61012018-03-19 14:53:23 +01001852 public boolean shouldDeferAnimationFinish(Runnable endDeferFinishCallback) {
1853 return mAnimatingAppWindowTokenRegistry != null
1854 && mAnimatingAppWindowTokenRegistry.notifyAboutToFinish(
1855 this, endDeferFinishCallback);
1856 }
1857
1858 @Override
1859 public void onAnimationLeashDestroyed(Transaction t) {
1860 super.onAnimationLeashDestroyed(t);
1861 if (mAnimatingAppWindowTokenRegistry != null) {
1862 mAnimatingAppWindowTokenRegistry.notifyFinished(this);
1863 }
1864 }
1865
1866 @Override
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001867 protected void setLayer(Transaction t, int layer) {
1868 if (!mSurfaceAnimator.hasLeash()) {
1869 t.setLayer(mSurfaceControl, layer);
1870 }
1871 }
1872
1873 @Override
1874 protected void setRelativeLayer(Transaction t, SurfaceControl relativeTo, int layer) {
1875 if (!mSurfaceAnimator.hasLeash()) {
1876 t.setRelativeLayer(mSurfaceControl, relativeTo, layer);
1877 }
1878 }
1879
1880 @Override
1881 protected void reparentSurfaceControl(Transaction t, SurfaceControl newParent) {
1882 if (!mSurfaceAnimator.hasLeash()) {
1883 t.reparent(mSurfaceControl, newParent.getHandle());
1884 }
1885 }
1886
1887 @Override
1888 public void onAnimationLeashCreated(Transaction t, SurfaceControl leash) {
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001889 // The leash is parented to the animation layer. We need to preserve the z-order by using
1890 // the prefix order index, but we boost if necessary.
Robert Carrb9506032018-02-13 13:54:00 -08001891 int layer = 0;
1892 if (!inPinnedWindowingMode()) {
1893 layer = getPrefixOrderIndex();
1894 } else {
1895 // Pinned stacks have animations take place within themselves rather than an animation
1896 // layer so we need to preserve the order relative to the stack (e.g. the order of our
1897 // task/parent).
1898 layer = getParent().getPrefixOrderIndex();
1899 }
1900
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001901 if (mNeedsZBoost) {
1902 layer += Z_BOOST_BASE;
1903 }
1904 leash.setLayer(layer);
Robert Carr2f8aa392018-01-31 14:46:51 -08001905
1906 final DisplayContent dc = getDisplayContent();
Jorim Jaggibe418292018-03-26 16:14:12 +02001907 dc.assignStackOrdering();
Jorim Jaggi6de61012018-03-19 14:53:23 +01001908 if (mAnimatingAppWindowTokenRegistry != null) {
1909 mAnimatingAppWindowTokenRegistry.notifyStarting(this);
1910 }
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001911 }
1912
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001913 /**
1914 * This must be called while inside a transaction.
1915 */
1916 void showAllWindowsLocked() {
1917 forAllWindows(windowState -> {
1918 if (DEBUG_VISIBILITY) Slog.v(TAG, "performing show on: " + windowState);
1919 windowState.performShowLocked();
1920 }, false /* traverseTopToBottom */);
Jorim Jaggia5e10572017-11-15 14:36:26 +01001921 }
1922
1923 @Override
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001924 protected void onAnimationFinished() {
1925 super.onAnimationFinished();
1926
1927 mTransit = TRANSIT_UNSET;
1928 mTransitFlags = 0;
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001929 mNeedsZBoost = false;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001930
1931 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM | FINISH_LAYOUT_REDO_WALLPAPER,
1932 "AppWindowToken");
1933
Jorim Jaggi988f6682017-11-17 17:46:43 +01001934 clearThumbnail();
Jorim Jaggi752cd822018-03-29 16:29:18 +02001935 setClientHidden(isHidden() && hiddenRequested);
Jorim Jaggi988f6682017-11-17 17:46:43 +01001936
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001937 if (mService.mInputMethodTarget != null && mService.mInputMethodTarget.mAppToken == this) {
1938 getDisplayContent().computeImeTarget(true /* updateImeTarget */);
1939 }
1940
1941 if (DEBUG_ANIM) Slog.v(TAG, "Animation done in " + this
1942 + ": reportedVisible=" + reportedVisible
1943 + " okToDisplay=" + okToDisplay()
1944 + " okToAnimate=" + okToAnimate()
1945 + " startingDisplayed=" + startingDisplayed);
1946
1947 // WindowState.onExitAnimationDone might modify the children list, so make a copy and then
1948 // traverse the copy.
1949 final ArrayList<WindowState> children = new ArrayList<>(mChildren);
1950 children.forEach(WindowState::onExitAnimationDone);
1951
1952 mService.mAppTransition.notifyAppTransitionFinishedLocked(token);
1953 scheduleAnimation();
1954 }
1955
1956 @Override
1957 boolean isAppAnimating() {
1958 return isSelfAnimating();
1959 }
1960
1961 @Override
1962 boolean isSelfAnimating() {
1963 // If we are about to start a transition, we also need to be considered animating.
1964 return isWaitingForTransitionStart() || isReallyAnimating();
1965 }
1966
1967 /**
1968 * @return True if and only if we are actually running an animation. Note that
1969 * {@link #isSelfAnimating} also returns true if we are waiting for an animation to
1970 * start.
1971 */
1972 private boolean isReallyAnimating() {
1973 return super.isSelfAnimating();
1974 }
1975
Jorim Jaggi988f6682017-11-17 17:46:43 +01001976 @Override
1977 void cancelAnimation() {
1978 super.cancelAnimation();
1979 clearThumbnail();
1980 }
1981
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001982 boolean isWaitingForTransitionStart() {
1983 return mService.mAppTransition.isTransitionSet()
1984 && (mService.mOpeningApps.contains(this) || mService.mClosingApps.contains(this));
1985 }
1986
1987 public int getTransit() {
1988 return mTransit;
1989 }
1990
1991 int getTransitFlags() {
1992 return mTransitFlags;
1993 }
1994
Jorim Jaggi988f6682017-11-17 17:46:43 +01001995 void attachThumbnailAnimation() {
1996 if (!isReallyAnimating()) {
1997 return;
1998 }
1999 final int taskId = getTask().mTaskId;
2000 final GraphicBuffer thumbnailHeader =
2001 mService.mAppTransition.getAppTransitionThumbnailHeader(taskId);
2002 if (thumbnailHeader == null) {
2003 if (DEBUG_APP_TRANSITIONS) Slog.d(TAG, "No thumbnail header bitmap for: " + taskId);
2004 return;
2005 }
2006 clearThumbnail();
2007 mThumbnail = new AppWindowThumbnail(getPendingTransaction(), this, thumbnailHeader);
2008 mThumbnail.startAnimation(getPendingTransaction(), loadThumbnailAnimation(thumbnailHeader));
2009 }
2010
Tony Mak64b8d562017-12-28 17:44:02 +00002011 /**
2012 * Attaches a surface with a thumbnail for the
2013 * {@link android.app.ActivityOptions#ANIM_OPEN_CROSS_PROFILE_APPS} animation.
2014 */
2015 void attachCrossProfileAppsThumbnailAnimation() {
2016 if (!isReallyAnimating()) {
2017 return;
2018 }
2019 clearThumbnail();
2020
2021 final WindowState win = findMainWindow();
2022 if (win == null) {
2023 return;
2024 }
chaviw492139a2018-07-16 16:07:35 -07002025 final Rect frame = win.getFrameLw();
Tony Mak64b8d562017-12-28 17:44:02 +00002026 final int thumbnailDrawableRes = getTask().mUserId == mService.mCurrentUserId
2027 ? R.drawable.ic_account_circle
Tony Makda4af232018-04-27 11:01:10 +01002028 : R.drawable.ic_corp_badge;
Tony Mak64b8d562017-12-28 17:44:02 +00002029 final GraphicBuffer thumbnail =
2030 mService.mAppTransition
2031 .createCrossProfileAppsThumbnail(thumbnailDrawableRes, frame);
2032 if (thumbnail == null) {
2033 return;
2034 }
2035 mThumbnail = new AppWindowThumbnail(getPendingTransaction(), this, thumbnail);
2036 final Animation animation =
chaviw492139a2018-07-16 16:07:35 -07002037 mService.mAppTransition.createCrossProfileAppsThumbnailAnimationLocked(
2038 win.getFrameLw());
Tony Mak64b8d562017-12-28 17:44:02 +00002039 mThumbnail.startAnimation(getPendingTransaction(), animation, new Point(frame.left,
2040 frame.top));
2041 }
2042
Jorim Jaggi988f6682017-11-17 17:46:43 +01002043 private Animation loadThumbnailAnimation(GraphicBuffer thumbnailHeader) {
2044 final DisplayInfo displayInfo = mDisplayContent.getDisplayInfo();
2045
2046 // If this is a multi-window scenario, we use the windows frame as
2047 // destination of the thumbnail header animation. If this is a full screen
2048 // window scenario, we use the whole display as the target.
2049 WindowState win = findMainWindow();
2050 Rect appRect = win != null ? win.getContentFrameLw() :
2051 new Rect(0, 0, displayInfo.appWidth, displayInfo.appHeight);
2052 Rect insets = win != null ? win.mContentInsets : null;
2053 final Configuration displayConfig = mDisplayContent.getConfiguration();
2054 return mService.mAppTransition.createThumbnailAspectScaleAnimationLocked(
2055 appRect, insets, thumbnailHeader, getTask().mTaskId, displayConfig.uiMode,
2056 displayConfig.orientation);
2057 }
2058
2059 private void clearThumbnail() {
2060 if (mThumbnail == null) {
2061 return;
2062 }
2063 mThumbnail.destroy();
2064 mThumbnail = null;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002065 }
2066
Jorim Jaggif84e2f62018-01-16 14:17:59 +01002067 void registerRemoteAnimations(RemoteAnimationDefinition definition) {
2068 mRemoteAnimationDefinition = definition;
2069 }
2070
2071 RemoteAnimationDefinition getRemoteAnimationDefinition() {
2072 return mRemoteAnimationDefinition;
2073 }
2074
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002075 @Override
2076 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
2077 super.dump(pw, prefix, dumpAll);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002078 if (appToken != null) {
Wale Ogunwale72919d22016-12-08 18:58:50 -08002079 pw.println(prefix + "app=true mVoiceInteraction=" + mVoiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002080 }
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08002081 pw.print(prefix); pw.print("task="); pw.println(getTask());
Wale Ogunwale51362492016-09-08 17:49:17 -07002082 pw.print(prefix); pw.print(" mFillsParent="); pw.print(mFillsParent);
2083 pw.print(" mOrientation="); pw.println(mOrientation);
Wale Ogunwale89973222017-04-23 18:39:45 -07002084 pw.println(prefix + "hiddenRequested=" + hiddenRequested + " mClientHidden=" + mClientHidden
2085 + ((mDeferHidingClient) ? " mDeferHidingClient=" + mDeferHidingClient : "")
2086 + " reportedDrawn=" + reportedDrawn + " reportedVisible=" + reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -07002087 if (paused) {
2088 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002089 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -08002090 if (mAppStopped) {
2091 pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped);
2092 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07002093 if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002094 || allDrawn || mLastAllDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07002095 pw.print(prefix); pw.print("mNumInterestingWindows=");
2096 pw.print(mNumInterestingWindows);
2097 pw.print(" mNumDrawnWindows="); pw.print(mNumDrawnWindows);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002098 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -07002099 pw.print(" allDrawn="); pw.print(allDrawn);
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002100 pw.print(" lastAllDrawn="); pw.print(mLastAllDrawn);
Craig Mautner6fbda632012-07-03 09:26:39 -07002101 pw.println(")");
2102 }
2103 if (inPendingTransaction) {
2104 pw.print(prefix); pw.print("inPendingTransaction=");
2105 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002106 }
Craig Mautner799bc1d2015-01-14 10:33:48 -08002107 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002108 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
2109 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -08002110 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -08002111 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002112 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08002113 if (startingWindow != null || startingSurface != null
Wale Ogunwale6c459212017-05-17 08:56:03 -07002114 || startingDisplayed || startingMoved || mHiddenSetFromTransferredStartingWindow) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002115 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08002116 pw.print(" startingSurface="); pw.print(startingSurface);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002117 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
Wale Ogunwale6c459212017-05-17 08:56:03 -07002118 pw.print(" startingMoved="); pw.print(startingMoved);
2119 pw.println(" mHiddenSetFromTransferredStartingWindow="
2120 + mHiddenSetFromTransferredStartingWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002121 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01002122 if (!mFrozenBounds.isEmpty()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -08002123 pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds);
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002124 pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig);
Chong Zhangd78ddb42016-03-02 17:01:14 -08002125 }
2126 if (mPendingRelaunchCount != 0) {
2127 pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount);
Jorim Jaggi0429f352015-12-22 16:29:16 +01002128 }
Wale Ogunwale9c64cb62017-04-12 13:39:59 -07002129 if (getController() != null) {
2130 pw.print(prefix); pw.print("controller="); pw.println(getController());
2131 }
Wale Ogunwalee287e192017-04-21 09:30:12 -07002132 if (mRemovingFromDisplay) {
2133 pw.println(prefix + "mRemovingFromDisplay=" + mRemovingFromDisplay);
2134 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002135 }
2136
2137 @Override
2138 void setHidden(boolean hidden) {
2139 super.setHidden(hidden);
Winson Chunge55c0192017-08-24 14:50:48 -07002140
2141 if (hidden) {
2142 // Once the app window is hidden, reset the last saved PiP snap fraction
2143 mDisplayContent.mPinnedStackControllerLocked.resetReentrySnapFraction(this);
2144 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002145 scheduleAnimation();
2146 }
2147
2148 @Override
2149 void prepareSurfaces() {
2150 // isSelfAnimating also returns true when we are about to start a transition, so we need
2151 // to check super here.
2152 final boolean reallyAnimating = super.isSelfAnimating();
2153 final boolean show = !isHidden() || reallyAnimating;
2154 if (show && !mLastSurfaceShowing) {
2155 mPendingTransaction.show(mSurfaceControl);
2156 } else if (!show && mLastSurfaceShowing) {
2157 mPendingTransaction.hide(mSurfaceControl);
Jorim Jaggi4d1835d2017-08-31 17:28:27 +02002158 }
Jorim Jaggi988f6682017-11-17 17:46:43 +01002159 if (mThumbnail != null) {
2160 mThumbnail.setShowing(mPendingTransaction, show);
2161 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002162 mLastSurfaceShowing = show;
2163 super.prepareSurfaces();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002164 }
2165
Jorim Jaggi77d0f36c2018-03-16 17:49:49 +01002166 /**
2167 * @return Whether our {@link #getSurfaceControl} is currently showing.
2168 */
2169 boolean isSurfaceShowing() {
2170 return mLastSurfaceShowing;
2171 }
2172
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002173 boolean isFreezingScreen() {
2174 return mFreezingScreen;
2175 }
2176
2177 @Override
2178 boolean needsZBoost() {
2179 return mNeedsZBoost || super.needsZBoost();
2180 }
2181
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07002182 @CallSuper
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002183 @Override
Adrian Roos4921ccf2017-09-28 16:54:06 +02002184 public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07002185 final long token = proto.start(fieldId);
2186 writeNameToProto(proto, NAME);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002187 super.writeToProto(proto, WINDOW_TOKEN, trim);
Vishnu Nair04ab4392018-01-10 11:00:06 -08002188 proto.write(LAST_SURFACE_SHOWING, mLastSurfaceShowing);
2189 proto.write(IS_WAITING_FOR_TRANSITION_START, isWaitingForTransitionStart());
2190 proto.write(IS_REALLY_ANIMATING, isReallyAnimating());
2191 if (mThumbnail != null){
2192 mThumbnail.writeToProto(proto, THUMBNAIL);
2193 }
2194 proto.write(FILLS_PARENT, mFillsParent);
2195 proto.write(APP_STOPPED, mAppStopped);
2196 proto.write(HIDDEN_REQUESTED, hiddenRequested);
2197 proto.write(CLIENT_HIDDEN, mClientHidden);
2198 proto.write(DEFER_HIDING_CLIENT, mDeferHidingClient);
2199 proto.write(REPORTED_DRAWN, reportedDrawn);
2200 proto.write(REPORTED_VISIBLE, reportedVisible);
2201 proto.write(NUM_INTERESTING_WINDOWS, mNumInterestingWindows);
2202 proto.write(NUM_DRAWN_WINDOWS, mNumDrawnWindows);
2203 proto.write(ALL_DRAWN, allDrawn);
2204 proto.write(LAST_ALL_DRAWN, mLastAllDrawn);
2205 proto.write(REMOVED, removed);
2206 if (startingWindow != null){
2207 startingWindow.writeIdentifierToProto(proto, STARTING_WINDOW);
2208 }
2209 proto.write(STARTING_DISPLAYED, startingDisplayed);
2210 proto.write(STARTING_MOVED, startingMoved);
2211 proto.write(HIDDEN_SET_FROM_TRANSFERRED_STARTING_WINDOW,
2212 mHiddenSetFromTransferredStartingWindow);
2213 for (Rect bounds : mFrozenBounds) {
2214 bounds.writeToProto(proto, FROZEN_BOUNDS);
2215 }
Steven Timotiusaf03df62017-07-18 16:56:43 -07002216 proto.end(token);
2217 }
2218
2219 void writeNameToProto(ProtoOutputStream proto, long fieldId) {
2220 if (appToken == null) {
2221 return;
2222 }
2223 try {
2224 proto.write(fieldId, appToken.getName());
2225 } catch (RemoteException e) {
2226 // This shouldn't happen, but in this case fall back to outputting nothing
2227 Slog.e(TAG, e.toString());
2228 }
2229 }
2230
2231 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002232 public String toString() {
2233 if (stringName == null) {
2234 StringBuilder sb = new StringBuilder();
2235 sb.append("AppWindowToken{");
2236 sb.append(Integer.toHexString(System.identityHashCode(this)));
2237 sb.append(" token="); sb.append(token); sb.append('}');
2238 stringName = sb.toString();
2239 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07002240 return stringName + ((mIsExiting) ? " mIsExiting=" : "");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002241 }
Adrian Roos20e07892018-02-23 19:12:01 +01002242
2243 Rect getLetterboxInsets() {
2244 if (mLetterbox != null) {
2245 return mLetterbox.getInsets();
2246 } else {
2247 return new Rect();
2248 }
2249 }
Adrian Roos23df3a32018-03-15 15:41:13 +01002250
2251 /**
2252 * @eturn true if there is a letterbox and any part of that letterbox overlaps with
2253 * the given {@code rect}.
2254 */
2255 boolean isLetterboxOverlappingWith(Rect rect) {
2256 return mLetterbox != null && mLetterbox.isOverlappingWith(rect);
2257 }
chaviw4ad54912018-05-30 11:05:44 -07002258
2259 /**
2260 * Sets if this AWT is in the process of closing or entering PIP.
2261 * {@link #mWillCloseOrEnterPip}}
2262 */
2263 void setWillCloseOrEnterPip(boolean willCloseOrEnterPip) {
2264 mWillCloseOrEnterPip = willCloseOrEnterPip;
2265 }
2266
2267 /**
2268 * Returns whether this AWT is considered closing. Conditions are either
2269 * 1. Is this app animating and was requested to be hidden
2270 * 2. App is delayed closing since it might enter PIP.
2271 */
2272 boolean isClosingOrEnteringPip() {
2273 return (isAnimating() && hiddenRequested) || mWillCloseOrEnterPip;
2274 }
Jorim Jaggiaf0d6d22018-06-08 15:25:35 +02002275
2276 /**
2277 * @return Whether we are allowed to show non-starting windows at the moment. We disallow
2278 * showing windows during transitions in case we have windows that have wide-color-gamut
2279 * color mode set to avoid jank in the middle of the transition.
2280 */
2281 boolean canShowWindows() {
2282 return allDrawn && !(isReallyAnimating() && hasNonDefaultColorWindow());
2283 }
2284
2285 /**
2286 * @return true if we have a window that has a non-default color mode set; false otherwise.
2287 */
2288 private boolean hasNonDefaultColorWindow() {
2289 return forAllWindows(ws -> ws.mAttrs.getColorMode() != COLOR_MODE_DEFAULT,
2290 true /* topToBottom */);
2291 }
Jeff Browne9bdb312012-04-05 15:30:10 -07002292}