blob: fc7610239fa37d60e4f7bfc6839907e5e906808a [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;
chaviw9c81e632018-07-31 11:17:52 -070035import static android.view.WindowManager.TRANSIT_UNSET;
Jorim Jaggic6976f02018-04-18 16:31:07 +020036import static android.view.WindowManager.TRANSIT_WALLPAPER_OPEN;
chaviw9c81e632018-07-31 11:17:52 -070037
Adrian Roose99bc052017-11-20 17:55:31 +010038import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
39import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Yi Jin6c6e9ca2018-03-20 16:53:35 -070040import static com.android.server.wm.AppWindowTokenProto.ALL_DRAWN;
41import static com.android.server.wm.AppWindowTokenProto.APP_STOPPED;
42import static com.android.server.wm.AppWindowTokenProto.CLIENT_HIDDEN;
43import static com.android.server.wm.AppWindowTokenProto.DEFER_HIDING_CLIENT;
44import static com.android.server.wm.AppWindowTokenProto.FILLS_PARENT;
45import static com.android.server.wm.AppWindowTokenProto.FROZEN_BOUNDS;
46import static com.android.server.wm.AppWindowTokenProto.HIDDEN_REQUESTED;
47import static com.android.server.wm.AppWindowTokenProto.HIDDEN_SET_FROM_TRANSFERRED_STARTING_WINDOW;
48import static com.android.server.wm.AppWindowTokenProto.IS_REALLY_ANIMATING;
49import static com.android.server.wm.AppWindowTokenProto.IS_WAITING_FOR_TRANSITION_START;
50import static com.android.server.wm.AppWindowTokenProto.LAST_ALL_DRAWN;
51import static com.android.server.wm.AppWindowTokenProto.LAST_SURFACE_SHOWING;
52import static com.android.server.wm.AppWindowTokenProto.NAME;
53import static com.android.server.wm.AppWindowTokenProto.NUM_DRAWN_WINDOWS;
54import static com.android.server.wm.AppWindowTokenProto.NUM_INTERESTING_WINDOWS;
55import static com.android.server.wm.AppWindowTokenProto.REMOVED;
56import static com.android.server.wm.AppWindowTokenProto.REPORTED_DRAWN;
57import static com.android.server.wm.AppWindowTokenProto.REPORTED_VISIBLE;
58import static com.android.server.wm.AppWindowTokenProto.STARTING_DISPLAYED;
59import static com.android.server.wm.AppWindowTokenProto.STARTING_MOVED;
60import static com.android.server.wm.AppWindowTokenProto.STARTING_WINDOW;
61import static com.android.server.wm.AppWindowTokenProto.THUMBNAIL;
62import static com.android.server.wm.AppWindowTokenProto.WINDOW_TOKEN;
chaviw9c81e632018-07-31 11:17:52 -070063import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
64import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
65import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
66import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
67import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
68import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
69import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
70import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW_VERBOSE;
71import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TOKEN_MOVEMENT;
72import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
73import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_MOVEMENT;
74import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
75import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
76import static com.android.server.wm.WindowManagerService.H.NOTIFY_ACTIVITY_DRAWN;
77import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
78import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
79import static com.android.server.wm.WindowManagerService.logWithStack;
Vishnu Naira2977262018-07-26 13:31:26 -070080import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_AFTER_ANIM;
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
Vishnu Naira2977262018-07-26 13:31:26 -0700267 /** Layer used to constrain the animation to a token's stack bounds. */
268 SurfaceControl mAnimationBoundsLayer;
269
270 /** Whether this token needs to create mAnimationBoundsLayer for cropping animations. */
271 boolean mNeedsAnimationBoundsLayer;
272
Wale Ogunwale72919d22016-12-08 18:58:50 -0800273 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
274 DisplayContent dc, long inputDispatchingTimeoutNanos, boolean fullscreen,
275 boolean showForAllUsers, int targetSdk, int orientation, int rotationAnimationHint,
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800276 int configChanges, boolean launchTaskBehind, boolean alwaysFocusable,
Bryce Leef3c6a472017-11-14 14:53:06 -0800277 AppWindowContainerController controller) {
278 this(service, token, voiceInteraction, dc, fullscreen);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800279 setController(controller);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800280 mInputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800281 mShowForAllUsers = showForAllUsers;
282 mTargetSdk = targetSdk;
283 mOrientation = orientation;
284 layoutConfigChanges = (configChanges & (CONFIG_SCREEN_SIZE | CONFIG_ORIENTATION)) != 0;
285 mLaunchTaskBehind = launchTaskBehind;
286 mAlwaysFocusable = alwaysFocusable;
287 mRotationAnimationHint = rotationAnimationHint;
288
289 // Application tokens start out hidden.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200290 setHidden(true);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800291 hiddenRequested = true;
292 }
293
294 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
Bryce Leef3c6a472017-11-14 14:53:06 -0800295 DisplayContent dc, boolean fillsParent) {
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800296 super(service, token != null ? token.asBinder() : null, TYPE_APPLICATION, true, dc,
297 false /* ownerCanManageAppTokens */);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700298 appToken = token;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800299 mVoiceInteraction = voiceInteraction;
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800300 mFillsParent = fillsParent;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800301 mInputApplicationHandle = new InputApplicationHandle(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800302 }
303
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800304 void onFirstWindowDrawn(WindowState win, WindowStateAnimator winAnimator) {
305 firstWindowDrawn = true;
306
307 // We now have a good window to show, remove dead placeholders
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700308 removeDeadWindows();
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800309
Jorim Jaggi02886a82016-12-06 09:10:06 -0800310 if (startingWindow != null) {
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800311 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, "Finish starting "
312 + win.mToken + ": first real window is shown, no animation");
313 // If this initial window is animating, stop it -- we will do an animation to reveal
314 // it from behind the starting window, so there is no need for it to also be doing its
315 // own stuff.
Jorim Jaggia5e10572017-11-15 14:36:26 +0100316 win.cancelAnimation();
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800317 if (getController() != null) {
318 getController().removeStartingWindow();
319 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800320 }
321 updateReportedVisibilityLocked();
322 }
323
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800324 void updateReportedVisibilityLocked() {
325 if (appToken == null) {
326 return;
327 }
328
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700329 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700330 final int count = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800331
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700332 mReportedVisibilityResults.reset();
333
334 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700335 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700336 win.updateReportedVisibility(mReportedVisibilityResults);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800337 }
338
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700339 int numInteresting = mReportedVisibilityResults.numInteresting;
340 int numVisible = mReportedVisibilityResults.numVisible;
341 int numDrawn = mReportedVisibilityResults.numDrawn;
342 boolean nowGone = mReportedVisibilityResults.nowGone;
343
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700344 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200345 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting && !isHidden();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700346 if (!nowGone) {
347 // If the app is not yet gone, then it can only become visible/drawn.
348 if (!nowDrawn) {
349 nowDrawn = reportedDrawn;
350 }
351 if (!nowVisible) {
352 nowVisible = reportedVisible;
353 }
354 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800355 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800356 + numInteresting + " visible=" + numVisible);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800357 final AppWindowContainerController controller = getController();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700358 if (nowDrawn != reportedDrawn) {
359 if (nowDrawn) {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800360 if (controller != null) {
361 controller.reportWindowsDrawn();
362 }
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700363 }
364 reportedDrawn = nowDrawn;
365 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800366 if (nowVisible != reportedVisible) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700367 if (DEBUG_VISIBILITY) Slog.v(TAG,
368 "Visibility changed in " + this + ": vis=" + nowVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800369 reportedVisible = nowVisible;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800370 if (controller != null) {
371 if (nowVisible) {
372 controller.reportWindowsVisible();
373 } else {
374 controller.reportWindowsGone();
375 }
376 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800377 }
378 }
379
Wale Ogunwale89973222017-04-23 18:39:45 -0700380 boolean isClientHidden() {
381 return mClientHidden;
382 }
383
384 void setClientHidden(boolean hideClient) {
385 if (mClientHidden == hideClient || (hideClient && mDeferHidingClient)) {
386 return;
387 }
Jorim Jaggi067b5bf2018-02-23 17:42:39 +0100388 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setClientHidden: " + this
389 + " clientHidden=" + hideClient + " Callers=" + Debug.getCallers(5));
Wale Ogunwale89973222017-04-23 18:39:45 -0700390 mClientHidden = hideClient;
391 sendAppVisibilityToClients();
392 }
393
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700394 boolean setVisibility(WindowManager.LayoutParams lp,
395 boolean visible, int transit, boolean performLayout, boolean isVoiceInteraction) {
396
397 boolean delayed = false;
398 inPendingTransaction = false;
Wale Ogunwale9e4721f2017-05-23 19:37:30 -0700399 // Reset the state of mHiddenSetFromTransferredStartingWindow since visibility is actually
400 // been set by the app now.
401 mHiddenSetFromTransferredStartingWindow = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700402
403 // Allow for state changes and animation to be applied if:
404 // * token is transitioning visibility state
405 // * or the token was marked as hidden and is exiting before we had a chance to play the
406 // transition animation
407 // * or this is an opening app and windows are being replaced.
408 boolean visibilityChanged = false;
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200409 if (isHidden() == visible || (isHidden() && mIsExiting) || (visible && waitingForReplacement())) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700410 final AccessibilityController accessibilityController = mService.mAccessibilityController;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700411 boolean changed = false;
412 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200413 "Changing app " + this + " hidden=" + isHidden() + " performLayout=" + performLayout);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700414
415 boolean runningAppAnimation = false;
416
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100417 if (transit != WindowManager.TRANSIT_UNSET) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200418 if (applyAnimationLocked(lp, transit, visible, isVoiceInteraction)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700419 delayed = runningAppAnimation = true;
420 }
421 final WindowState window = findMainWindow();
422 //TODO (multidisplay): Magnification is supported only for the default display.
423 if (window != null && accessibilityController != null
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700424 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700425 accessibilityController.onAppWindowTransitionLocked(window, transit);
426 }
427 changed = true;
428 }
429
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700430 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700431 for (int i = 0; i < windowsCount; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700432 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700433 changed |= win.onAppVisibilityChanged(visible, runningAppAnimation);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700434 }
435
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200436 setHidden(!visible);
437 hiddenRequested = !visible;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700438 visibilityChanged = true;
439 if (!visible) {
440 stopFreezingScreen(true, true);
441 } else {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700442 // If we are being set visible, and the starting window is not yet displayed,
443 // then make sure it doesn't get displayed.
444 if (startingWindow != null && !startingWindow.isDrawnLw()) {
445 startingWindow.mPolicyVisibility = false;
446 startingWindow.mPolicyVisibilityAfterAnim = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700447 }
Jorim Jaggi38d44ec2017-06-14 16:04:59 -0700448
449 // We are becoming visible, so better freeze the screen with the windows that are
450 // getting visible so we also wait for them.
451 forAllWindows(mService::makeWindowFreezingScreenIfNeededLocked, true);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700452 }
453
454 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setVisibility: " + this
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200455 + ": hidden=" + isHidden() + " hiddenRequested=" + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700456
457 if (changed) {
Arthur Hung95b38a92018-07-20 18:56:12 +0800458 getDisplayContent().getInputMonitor().setUpdateInputWindowsNeededLw();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700459 if (performLayout) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700460 mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700461 false /*updateInputWindows*/);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700462 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700463 }
Arthur Hung95b38a92018-07-20 18:56:12 +0800464 getDisplayContent().getInputMonitor().updateInputWindowsLw(false /*force*/);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700465 }
466 }
467
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200468 if (isReallyAnimating()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700469 delayed = true;
Jorim Jaggiab9fcb22018-03-15 23:46:12 +0100470 } else {
471
472 // We aren't animating anything, but exiting windows rely on the animation finished
473 // callback being called in case the AppWindowToken was pretending to be animating,
474 // which we might have done because we were in closing/opening apps list.
475 onAnimationFinished();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700476 }
477
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700478 for (int i = mChildren.size() - 1; i >= 0 && !delayed; i--) {
Jorim Jaggia5e10572017-11-15 14:36:26 +0100479 if ((mChildren.get(i)).isSelfOrChildAnimating()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700480 delayed = true;
481 }
482 }
483
484 if (visibilityChanged) {
485 if (visible && !delayed) {
486 // The token was made immediately visible, there will be no entrance animation.
487 // We need to inform the client the enter animation was finished.
488 mEnteringAnimation = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700489 mService.mActivityManagerAppTransitionNotifier.onAppTransitionFinishedLocked(token);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700490 }
Robert Carr61b81112017-07-17 18:08:15 -0700491
Jorim Jaggi110839b2018-01-22 12:49:04 +0100492 // If we're becoming visible, immediately change client visibility as well although it
493 // usually gets changed in AppWindowContainerController.setVisibility already. However,
494 // there seem to be some edge cases where we change our visibility but client visibility
495 // never gets updated.
496 // If we're becoming invisible, update the client visibility if we are not running an
497 // animation. Otherwise, we'll update client visibility in onAnimationFinished.
Jorim Jaggi3cad57f2018-02-20 18:32:01 +0100498 if (visible || !isReallyAnimating()) {
Jorim Jaggi110839b2018-01-22 12:49:04 +0100499 setClientHidden(!visible);
Jorim Jaggi4876b4a2018-01-11 15:43:49 +0100500 }
501
chaviwa953fcf2018-03-01 12:00:39 -0800502 if (!mService.mClosingApps.contains(this) && !mService.mOpeningApps.contains(this)) {
503 // The token is not closing nor opening, so even if there is an animation set, that
504 // doesn't mean that it goes through the normal app transition cycle so we have
505 // to inform the docked controller about visibility change.
506 // TODO(multi-display): notify docked divider on all displays where visibility was
507 // affected.
508 mService.getDefaultDisplayContentLocked().getDockedDividerController()
509 .notifyAppVisibilityChanged();
510
511 // Take the screenshot before possibly hiding the WSA, otherwise the screenshot
512 // will not be taken.
513 mService.mTaskSnapshotController.notifyAppVisibilityChanged(this, visible);
514 }
515
Robert Carre7cc44d2017-03-20 19:04:30 -0700516 // If we are hidden but there is no delay needed we immediately
517 // apply the Surface transaction so that the ActivityManager
Robert Carr61b81112017-07-17 18:08:15 -0700518 // can have some guarantee on the Surface state following
519 // setting the visibility. This captures cases like dismissing
520 // the docked or pinned stack where there is no app transition.
521 //
522 // In the case of a "Null" animation, there will be
523 // no animation but there will still be a transition set.
524 // We still need to delay hiding the surface such that it
525 // can be synchronized with showing the next surface in the transition.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200526 if (isHidden() && !delayed && !mService.mAppTransition.isTransitionSet()) {
Robert Carr6914f082017-03-20 19:04:30 -0700527 SurfaceControl.openTransaction();
528 for (int i = mChildren.size() - 1; i >= 0; i--) {
529 mChildren.get(i).mWinAnimator.hide("immediately hidden");
530 }
531 SurfaceControl.closeTransaction();
532 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700533 }
534
535 return delayed;
536 }
537
Jorim Jaggi87fdbcb2017-08-17 13:41:11 +0200538 /**
539 * @return The to top most child window for which {@link LayoutParams#isFullscreen()} returns
540 * true.
541 */
542 WindowState getTopFullscreenWindow() {
543 for (int i = mChildren.size() - 1; i >= 0; i--) {
544 final WindowState win = mChildren.get(i);
545 if (win != null && win.mAttrs.isFullscreen()) {
546 return win;
547 }
548 }
549 return null;
550 }
551
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800552 WindowState findMainWindow() {
Matthew Ng53e66b22018-01-12 17:13:13 -0800553 return findMainWindow(true);
554 }
555
556 /**
557 * Finds the main window that either has type base application or application starting if
558 * requested.
559 *
560 * @param includeStartingApp Allow to search application-starting windows to also be returned.
561 * @return The main window of type base application or application starting if requested.
562 */
563 WindowState findMainWindow(boolean includeStartingApp) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700564 WindowState candidate = null;
Matthew Ng53e66b22018-01-12 17:13:13 -0800565 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700566 final WindowState win = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700567 final int type = win.mAttrs.type;
568 // No need to loop through child window as base application and starting types can't be
569 // child windows.
Matthew Ng53e66b22018-01-12 17:13:13 -0800570 if (type == TYPE_BASE_APPLICATION
571 || (includeStartingApp && type == TYPE_APPLICATION_STARTING)) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700572 // In cases where there are multiple windows, we prefer the non-exiting window. This
Sungsoo Lim0d3d1f82015-12-02 14:47:59 +0900573 // happens for example when replacing windows during an activity relaunch. When
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700574 // constructing the animation, we want the new window, not the exiting one.
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800575 if (win.mAnimatingExit) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700576 candidate = win;
577 } else {
578 return win;
579 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800580 }
581 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700582 return candidate;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800583 }
584
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800585 boolean windowsAreFocusable() {
Wale Ogunwale3382ab12017-07-27 08:55:03 -0700586 return getWindowConfiguration().canReceiveKeys() || mAlwaysFocusable;
Wale Ogunwaled045c822015-12-02 09:14:28 -0800587 }
588
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800589 AppWindowContainerController getController() {
590 final WindowContainerController controller = super.getController();
591 return controller != null ? (AppWindowContainerController) controller : null;
592 }
593
Wale Ogunwale571771c2016-08-26 13:18:50 -0700594 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -0700595 boolean isVisible() {
Wale Ogunwalee471be62016-10-03 07:53:55 -0700596 // If the app token isn't hidden then it is considered visible and there is no need to check
597 // its children windows to see if they are visible.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200598 return !isHidden();
Wale Ogunwale44f21802016-09-02 12:49:48 -0700599 }
600
601 @Override
Wale Ogunwalee287e192017-04-21 09:30:12 -0700602 void removeImmediately() {
603 onRemovedFromDisplay();
604 super.removeImmediately();
605 }
606
607 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -0700608 void removeIfPossible() {
Craig Mautnere3119b72015-01-20 15:02:36 -0800609 mIsExiting = false;
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800610 removeAllWindowsIfPossible();
Bryce Lee6d410262017-02-28 15:30:17 -0800611 removeImmediately();
Craig Mautnere3119b72015-01-20 15:02:36 -0800612 }
613
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700614 @Override
615 boolean checkCompleteDeferredRemoval() {
616 if (mIsExiting) {
617 removeIfPossible();
618 }
619 return super.checkCompleteDeferredRemoval();
620 }
621
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700622 void onRemovedFromDisplay() {
Wale Ogunwalee287e192017-04-21 09:30:12 -0700623 if (mRemovingFromDisplay) {
624 return;
625 }
626 mRemovingFromDisplay = true;
627
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700628 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app token: " + this);
629
Wale Ogunwale72919d22016-12-08 18:58:50 -0800630 boolean delayed = setVisibility(null, false, TRANSIT_UNSET, true, mVoiceInteraction);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700631
632 mService.mOpeningApps.remove(this);
Jorim Jaggi45ca0542017-05-30 16:16:01 -0700633 mService.mUnknownAppVisibilityController.appRemovedOrHidden(this);
Jorim Jaggi10abe2f2017-01-03 16:44:46 +0100634 mService.mTaskSnapshotController.onAppRemoved(this);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700635 waitingToShow = false;
636 if (mService.mClosingApps.contains(this)) {
637 delayed = true;
638 } else if (mService.mAppTransition.isTransitionSet()) {
639 mService.mClosingApps.add(this);
640 delayed = true;
641 }
642
643 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app " + this + " delayed=" + delayed
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200644 + " animation=" + getAnimation() + " animating=" + isSelfAnimating());
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700645
646 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM, "removeAppToken: "
647 + this + " delayed=" + delayed + " Callers=" + Debug.getCallers(4));
648
Jorim Jaggi19be6052017-08-03 18:33:43 +0200649 if (startingData != null && getController() != null) {
650 getController().removeStartingWindow();
651 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800652
Winson Chung87e5d552017-04-05 11:49:38 -0700653 // If this window was animating, then we need to ensure that the app transition notifies
654 // that animations have completed in WMS.handleAnimatingStoppedAndTransitionLocked(), so
655 // add to that list now
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200656 if (isSelfAnimating()) {
Winson Chung87e5d552017-04-05 11:49:38 -0700657 mService.mNoAnimationNotifyOnTransitionFinished.add(token);
658 }
659
Wale Ogunwalee287e192017-04-21 09:30:12 -0700660 final TaskStack stack = getStack();
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700661 if (delayed && !isEmpty()) {
662 // set the token aside because it has an active animation to be finished
663 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM,
664 "removeAppToken make exiting: " + this);
Wale Ogunwalee287e192017-04-21 09:30:12 -0700665 if (stack != null) {
666 stack.mExitingAppTokens.add(this);
667 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700668 mIsExiting = true;
669 } else {
670 // Make sure there is no animation running on this token, so any windows associated
671 // with it will be removed as soon as their animations are complete
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200672 cancelAnimation();
Wale Ogunwale3106ae012017-05-16 08:56:37 -0700673 if (stack != null) {
674 stack.mExitingAppTokens.remove(this);
675 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700676 removeIfPossible();
677 }
678
679 removed = true;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700680 stopFreezingScreen(true, true);
Bryce Lee6d410262017-02-28 15:30:17 -0800681
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700682 if (mService.mFocusedApp == this) {
683 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "Removing focused app token:" + this);
684 mService.mFocusedApp = null;
685 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
Arthur Hung95b38a92018-07-20 18:56:12 +0800686 getDisplayContent().getInputMonitor().setFocusedAppLw(null);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700687 }
688
689 if (!delayed) {
690 updateReportedVisibilityLocked();
691 }
Wale Ogunwalee287e192017-04-21 09:30:12 -0700692
693 mRemovingFromDisplay = false;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700694 }
695
Chong Zhange05bcb12016-07-26 17:47:29 -0700696 void clearAnimatingFlags() {
Chong Zhangb0d26702016-08-12 16:03:29 -0700697 boolean wallpaperMightChange = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700698 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700699 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700700 wallpaperMightChange |= win.clearAnimatingFlags();
Chong Zhange05bcb12016-07-26 17:47:29 -0700701 }
Chong Zhangb0d26702016-08-12 16:03:29 -0700702 if (wallpaperMightChange) {
703 requestUpdateWallpaperIfNeeded();
704 }
Chong Zhange05bcb12016-07-26 17:47:29 -0700705 }
706
Robert Carre12aece2016-02-02 22:43:27 -0800707 void destroySurfaces() {
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700708 destroySurfaces(false /*cleanupOnResume*/);
709 }
710
711 /**
712 * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure
713 * the client has finished with them.
714 *
715 * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If
716 * set to true, destroy only surfaces of removed windows, and clear relevant flags of the
717 * others so that they are ready to be reused. If set to false (common case), destroy all
718 * surfaces that's eligible, if the app is already stopped.
719 */
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700720 private void destroySurfaces(boolean cleanupOnResume) {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700721 boolean destroyedSomething = false;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100722
723 // Copying to a different list as multiple children can be removed.
Jorim Jaggi59f3e922018-01-05 15:40:32 +0100724 final ArrayList<WindowState> children = new ArrayList<>(mChildren);
Jorim Jaggia5e10572017-11-15 14:36:26 +0100725 for (int i = children.size() - 1; i >= 0; i--) {
726 final WindowState win = children.get(i);
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700727 destroyedSomething |= win.destroySurface(cleanupOnResume, mAppStopped);
Robert Carre12aece2016-02-02 22:43:27 -0800728 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700729 if (destroyedSomething) {
730 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700731 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Adrian Roos23df3a32018-03-15 15:41:13 +0100732 updateLetterboxSurface(null);
Robert Carre12aece2016-02-02 22:43:27 -0800733 }
734 }
735
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800736 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700737 * Notify that the app is now resumed, and it was not stopped before, perform a clean
738 * up of the surfaces
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800739 */
Jorim Jaggibae01b12017-04-11 16:29:10 -0700740 void notifyAppResumed(boolean wasStopped) {
Chong Zhangad24f962016-08-25 12:12:33 -0700741 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped
Jorim Jaggibae01b12017-04-11 16:29:10 -0700742 + " " + this);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700743 mAppStopped = false;
chaviwd3bf08d2017-08-01 17:24:59 -0700744 // Allow the window to turn the screen on once the app is resumed again.
745 setCanTurnScreenOn(true);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700746 if (!wasStopped) {
747 destroySurfaces(true /*cleanupOnResume*/);
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800748 }
Robert Carre12aece2016-02-02 22:43:27 -0800749 }
750
Chong Zhangbef461f2015-10-27 11:38:24 -0700751 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700752 * Notify that the app has stopped, and it is okay to destroy any surfaces which were
753 * keeping alive in case they were still being used.
754 */
755 void notifyAppStopped() {
756 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this);
757 mAppStopped = true;
758 destroySurfaces();
759 // Remove any starting window that was added for this app if they are still around.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800760 if (getController() != null) {
761 getController().removeStartingWindow();
762 }
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700763 }
764
Chong Zhang92147042016-05-09 12:47:11 -0700765 void clearAllDrawn() {
766 allDrawn = false;
767 deferClearAllDrawn = false;
Chong Zhangbef461f2015-10-27 11:38:24 -0700768 }
769
Bryce Lee6d410262017-02-28 15:30:17 -0800770 Task getTask() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800771 return (Task) getParent();
Bryce Lee6d410262017-02-28 15:30:17 -0800772 }
773
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800774 TaskStack getStack() {
775 final Task task = getTask();
776 if (task != null) {
777 return task.mStack;
778 } else {
779 return null;
780 }
781 }
782
Bryce Lee6d410262017-02-28 15:30:17 -0800783 @Override
784 void onParentSet() {
785 super.onParentSet();
786
Robert Carred3e83b2017-04-21 13:26:55 -0700787 final Task task = getTask();
788
Bryce Lee6d410262017-02-28 15:30:17 -0800789 // When the associated task is {@code null}, the {@link AppWindowToken} can no longer
790 // access visual elements like the {@link DisplayContent}. We must remove any associations
791 // such as animations.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800792 if (!mReparenting) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800793 if (task == null) {
794 // It is possible we have been marked as a closing app earlier. We must remove ourselves
795 // from this list so we do not participate in any future animations.
796 mService.mClosingApps.remove(this);
Robert Carred3e83b2017-04-21 13:26:55 -0700797 } else if (mLastParent != null && mLastParent.mStack != null) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800798 task.mStack.mExitingAppTokens.remove(this);
799 }
Bryce Lee6d410262017-02-28 15:30:17 -0800800 }
Jorim Jaggi6de61012018-03-19 14:53:23 +0100801 final TaskStack stack = getStack();
802
803 // If we reparent, make sure to remove ourselves from the old animation registry.
804 if (mAnimatingAppWindowTokenRegistry != null) {
805 mAnimatingAppWindowTokenRegistry.notifyFinished(this);
806 }
807 mAnimatingAppWindowTokenRegistry = stack != null
808 ? stack.getAnimatingAppWindowTokenRegistry()
809 : null;
810
Robert Carred3e83b2017-04-21 13:26:55 -0700811 mLastParent = task;
Bryce Lee6d410262017-02-28 15:30:17 -0800812 }
813
Wale Ogunwalefa854eb2016-09-20 13:43:52 -0700814 void postWindowRemoveStartingWindowCleanup(WindowState win) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700815 // TODO: Something smells about the code below...Is there a better way?
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700816 if (startingWindow == win) {
817 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800818 if (getController() != null) {
819 getController().removeStartingWindow();
820 }
Wale Ogunwale6c459212017-05-17 08:56:03 -0700821 } else if (mChildren.size() == 0) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700822 // If this is the last window and we had requested a starting transition window,
823 // well there is no point now.
Jorim Jaggi02886a82016-12-06 09:10:06 -0800824 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingData");
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700825 startingData = null;
Wale Ogunwale6c459212017-05-17 08:56:03 -0700826 if (mHiddenSetFromTransferredStartingWindow) {
827 // We set the hidden state to false for the token from a transferred starting window.
828 // We now reset it back to true since the starting window was the last window in the
829 // token.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200830 setHidden(true);
Wale Ogunwale6c459212017-05-17 08:56:03 -0700831 }
Jorim Jaggi829b9cd2017-01-23 16:20:53 +0100832 } else if (mChildren.size() == 1 && startingSurface != null && !isRelaunching()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700833 // If this is the last window except for a starting transition window,
834 // we need to get rid of the starting transition.
Jorim Jaggie4b0f282017-05-17 15:10:29 +0200835 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Last window, removing starting window "
836 + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800837 if (getController() != null) {
838 getController().removeStartingWindow();
839 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700840 }
841 }
842
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700843 void removeDeadWindows() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700844 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700845 WindowState win = mChildren.get(winNdx);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800846 if (win.mAppDied) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700847 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700848 "removeDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800849 // Set mDestroying, we don't want any animation or delayed removal here.
850 win.mDestroying = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700851 // Also removes child windows.
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700852 win.removeIfPossible();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800853 }
854 }
855 }
856
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700857 boolean hasWindowsAlive() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700858 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700859 // No need to loop through child windows as the answer should be the same as that of the
860 // parent window.
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700861 if (!(mChildren.get(i)).mAppDied) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700862 return true;
863 }
864 }
865 return false;
866 }
867
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700868 void setWillReplaceWindows(boolean animate) {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700869 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
870 "Marking app token " + this + " with replacing windows.");
Robert Carra1eb4392015-12-10 12:43:51 -0800871
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700872 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700873 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700874 w.setWillReplaceWindow(animate);
Robert Carra1eb4392015-12-10 12:43:51 -0800875 }
Robert Carra1eb4392015-12-10 12:43:51 -0800876 }
877
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700878 void setWillReplaceChildWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700879 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this
Robert Carr23fa16b2016-01-13 13:19:58 -0800880 + " with replacing child windows.");
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700881 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700882 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700883 w.setWillReplaceChildWindows();
Robert Carr23fa16b2016-01-13 13:19:58 -0800884 }
885 }
886
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700887 void clearWillReplaceWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700888 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
889 "Resetting app token " + this + " of replacing window marks.");
Chong Zhangf596cd52016-01-05 13:42:44 -0800890
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700891 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700892 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700893 w.clearWillReplaceWindow();
Chong Zhangf596cd52016-01-05 13:42:44 -0800894 }
895 }
896
Chong Zhang4d7369a2016-04-25 16:09:14 -0700897 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700898 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700899 final WindowState w = mChildren.get(i);
Chong Zhang4d7369a2016-04-25 16:09:14 -0700900 w.requestUpdateWallpaperIfNeeded();
901 }
902 }
903
Chong Zhangd78ddb42016-03-02 17:01:14 -0800904 boolean isRelaunching() {
905 return mPendingRelaunchCount > 0;
906 }
907
Robert Carr68375192017-06-13 12:41:53 -0700908 boolean shouldFreezeBounds() {
909 final Task task = getTask();
910
911 // For freeform windows, we can't freeze the bounds at the moment because this would make
912 // the resizing unresponsive.
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700913 if (task == null || task.inFreeformWindowingMode()) {
Robert Carr68375192017-06-13 12:41:53 -0700914 return false;
915 }
916
917 // We freeze the bounds while drag resizing to deal with the time between
918 // the divider/drag handle being released, and the handling it's new
919 // configuration. If we are relaunched outside of the drag resizing state,
920 // we need to be careful not to do this.
921 return getTask().isDragResizing();
922 }
923
Chong Zhangd78ddb42016-03-02 17:01:14 -0800924 void startRelaunching() {
Robert Carr68375192017-06-13 12:41:53 -0700925 if (shouldFreezeBounds()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -0800926 freezeBounds();
927 }
Robert Carrd5c7dd62017-03-08 10:39:30 -0800928
929 // In the process of tearing down before relaunching, the app will
930 // try and clean up it's child surfaces. We need to prevent this from
931 // happening, so we sever the children, transfering their ownership
932 // from the client it-self to the parent surface (owned by us).
Robert Carr29daa922018-04-27 11:56:48 -0700933 detachChildren();
934
935 mPendingRelaunchCount++;
936 }
937
938 void detachChildren() {
Robert Carrfd8e93b2018-05-10 13:40:25 -0700939 SurfaceControl.openTransaction();
Robert Carrd5c7dd62017-03-08 10:39:30 -0800940 for (int i = mChildren.size() - 1; i >= 0; i--) {
941 final WindowState w = mChildren.get(i);
942 w.mWinAnimator.detachChildren();
943 }
Robert Carrfd8e93b2018-05-10 13:40:25 -0700944 SurfaceControl.closeTransaction();
Chong Zhangd78ddb42016-03-02 17:01:14 -0800945 }
946
947 void finishRelaunching() {
Robert Carr68375192017-06-13 12:41:53 -0700948 unfreezeBounds();
949
Chong Zhangd78ddb42016-03-02 17:01:14 -0800950 if (mPendingRelaunchCount > 0) {
951 mPendingRelaunchCount--;
Bryce Lee081554b2017-05-25 07:52:12 -0700952 } else {
953 // Update keyguard flags upon finishing relaunch.
954 checkKeyguardFlagsChanged();
Chong Zhangd78ddb42016-03-02 17:01:14 -0800955 }
956 }
957
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700958 void clearRelaunching() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700959 if (mPendingRelaunchCount == 0) {
960 return;
961 }
Robert Carr68375192017-06-13 12:41:53 -0700962 unfreezeBounds();
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700963 mPendingRelaunchCount = 0;
964 }
965
Wale Ogunwale07bcab72016-10-14 15:30:09 -0700966 /**
967 * Returns true if the new child window we are adding to this token is considered greater than
968 * the existing child window in this token in terms of z-order.
969 */
970 @Override
971 protected boolean isFirstChildWindowGreaterThanSecond(WindowState newWindow,
972 WindowState existingWindow) {
973 final int type1 = newWindow.mAttrs.type;
974 final int type2 = existingWindow.mAttrs.type;
975
976 // Base application windows should be z-ordered BELOW all other windows in the app token.
977 if (type1 == TYPE_BASE_APPLICATION && type2 != TYPE_BASE_APPLICATION) {
978 return false;
979 } else if (type1 != TYPE_BASE_APPLICATION && type2 == TYPE_BASE_APPLICATION) {
980 return true;
981 }
982
983 // Starting windows should be z-ordered ABOVE all other windows in the app token.
984 if (type1 == TYPE_APPLICATION_STARTING && type2 != TYPE_APPLICATION_STARTING) {
985 return true;
986 } else if (type1 != TYPE_APPLICATION_STARTING && type2 == TYPE_APPLICATION_STARTING) {
987 return false;
988 }
989
990 // Otherwise the new window is greater than the existing window.
991 return true;
992 }
993
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700994 @Override
Robert Carra1eb4392015-12-10 12:43:51 -0800995 void addWindow(WindowState w) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700996 super.addWindow(w);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700997
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700998 boolean gotReplacementWindow = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700999 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001000 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001001 gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w);
1002 }
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001003
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001004 // if we got a replacement window, reset the timeout to give drawing more time
1005 if (gotReplacementWindow) {
1006 mService.scheduleWindowReplacementTimeouts(this);
Robert Carra1eb4392015-12-10 12:43:51 -08001007 }
Jorim Jaggife762342016-10-13 14:33:27 +02001008 checkKeyguardFlagsChanged();
1009 }
1010
1011 @Override
1012 void removeChild(WindowState child) {
1013 super.removeChild(child);
1014 checkKeyguardFlagsChanged();
Adrian Roos23df3a32018-03-15 15:41:13 +01001015 updateLetterboxSurface(child);
Robert Carra1eb4392015-12-10 12:43:51 -08001016 }
1017
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001018 private boolean waitingForReplacement() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001019 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001020 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001021 if (candidate.waitingForReplacement()) {
Robert Carra1eb4392015-12-10 12:43:51 -08001022 return true;
1023 }
1024 }
1025 return false;
1026 }
1027
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001028 void onWindowReplacementTimeout() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001029 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001030 (mChildren.get(i)).onWindowReplacementTimeout();
Robert Carra1eb4392015-12-10 12:43:51 -08001031 }
1032 }
1033
Winson Chung30480042017-01-26 10:55:34 -08001034 void reparent(Task task, int position) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001035 final Task currentTask = getTask();
1036 if (task == currentTask) {
Winson Chung30480042017-01-26 10:55:34 -08001037 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001038 "window token=" + this + " already child of task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -08001039 }
Bryce Lee6d410262017-02-28 15:30:17 -08001040
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001041 if (currentTask.mStack != task.mStack) {
Bryce Lee6d410262017-02-28 15:30:17 -08001042 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001043 "window token=" + this + " current task=" + currentTask
Bryce Lee6d410262017-02-28 15:30:17 -08001044 + " belongs to a different stack than " + task);
1045 }
1046
Winson Chung30480042017-01-26 10:55:34 -08001047 if (DEBUG_ADD_REMOVE) Slog.i(TAG, "reParentWindowToken: removing window token=" + this
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001048 + " from task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -08001049 final DisplayContent prevDisplayContent = getDisplayContent();
1050
Bryce Lee6d410262017-02-28 15:30:17 -08001051 mReparenting = true;
1052
Winson Chung30480042017-01-26 10:55:34 -08001053 getParent().removeChild(this);
1054 task.addChild(this, position);
1055
Bryce Lee6d410262017-02-28 15:30:17 -08001056 mReparenting = false;
1057
Winson Chung30480042017-01-26 10:55:34 -08001058 // Relayout display(s).
1059 final DisplayContent displayContent = task.getDisplayContent();
1060 displayContent.setLayoutNeeded();
1061 if (prevDisplayContent != displayContent) {
1062 onDisplayChanged(displayContent);
1063 prevDisplayContent.setLayoutNeeded();
1064 }
1065 }
1066
Jorim Jaggi0429f352015-12-22 16:29:16 +01001067 /**
1068 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
1069 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
1070 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
1071 * with a queue.
1072 */
Chong Zhangd78ddb42016-03-02 17:01:14 -08001073 private void freezeBounds() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001074 final Task task = getTask();
1075 mFrozenBounds.offer(new Rect(task.mPreparedFrozenBounds));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001076
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001077 if (task.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) {
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001078 // We didn't call prepareFreezingBounds on the task, so use the current value.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001079 mFrozenMergedConfig.offer(new Configuration(task.getConfiguration()));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001080 } else {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001081 mFrozenMergedConfig.offer(new Configuration(task.mPreparedFrozenMergedConfig));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001082 }
Andrii Kulianb10330d2016-09-16 13:51:46 -07001083 // Calling unset() to make it equal to Configuration.EMPTY.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001084 task.mPreparedFrozenMergedConfig.unset();
Jorim Jaggi0429f352015-12-22 16:29:16 +01001085 }
1086
1087 /**
1088 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
1089 */
Chong Zhangd78ddb42016-03-02 17:01:14 -08001090 private void unfreezeBounds() {
Robert Carr68375192017-06-13 12:41:53 -07001091 if (mFrozenBounds.isEmpty()) {
1092 return;
Wale Ogunwale37dbafc2016-06-27 10:15:20 -07001093 }
Robert Carr68375192017-06-13 12:41:53 -07001094 mFrozenBounds.remove();
Wale Ogunwale37dbafc2016-06-27 10:15:20 -07001095 if (!mFrozenMergedConfig.isEmpty()) {
1096 mFrozenMergedConfig.remove();
1097 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001098 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001099 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001100 win.onUnfreezeBounds();
Jorim Jaggi4846ee32016-01-07 17:39:12 +01001101 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001102 mService.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +01001103 }
1104
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001105 void setAppLayoutChanges(int changes, String reason) {
1106 if (!mChildren.isEmpty()) {
1107 final DisplayContent dc = getDisplayContent();
1108 dc.pendingLayoutChanges |= changes;
1109 if (DEBUG_LAYOUT_REPEATS) {
1110 mService.mWindowPlacerLocked.debugLayoutRepeats(reason, dc.pendingLayoutChanges);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001111 }
1112 }
1113 }
1114
1115 void removeReplacedWindowIfNeeded(WindowState replacement) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001116 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001117 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001118 if (win.removeReplacedWindowIfNeeded(replacement)) {
1119 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001120 }
1121 }
1122 }
1123
1124 void startFreezingScreen() {
1125 if (DEBUG_ORIENTATION) logWithStack(TAG, "Set freezing of " + appToken + ": hidden="
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001126 + isHidden() + " freezing=" + mFreezingScreen + " hiddenRequested="
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001127 + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001128 if (!hiddenRequested) {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001129 if (!mFreezingScreen) {
1130 mFreezingScreen = true;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001131 mService.registerAppFreezeListener(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001132 mService.mAppsFreezingScreen++;
1133 if (mService.mAppsFreezingScreen == 1) {
Robert Carrae606b42018-02-15 15:36:23 -08001134 mService.startFreezingDisplayLocked(0, 0, getDisplayContent());
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001135 mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT);
1136 mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001137 }
1138 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001139 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001140 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001141 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001142 w.onStartFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001143 }
1144 }
1145 }
1146
1147 void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001148 if (!mFreezingScreen) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001149 return;
1150 }
1151 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + this + " force=" + force);
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001152 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001153 boolean unfrozeWindows = false;
1154 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001155 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001156 unfrozeWindows |= w.onStopFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001157 }
1158 if (force || unfrozeWindows) {
1159 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this);
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001160 mFreezingScreen = false;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001161 mService.unregisterAppFreezeListener(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001162 mService.mAppsFreezingScreen--;
1163 mService.mLastFinishedFreezeSource = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001164 }
1165 if (unfreezeSurfaceNow) {
1166 if (unfrozeWindows) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001167 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001168 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001169 mService.stopFreezingDisplayLocked();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001170 }
1171 }
1172
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001173 @Override
1174 public void onAppFreezeTimeout() {
1175 Slog.w(TAG_WM, "Force clearing freeze: " + this);
1176 stopFreezingScreen(true, true);
1177 }
1178
Jorim Jaggi60f9c972018-02-01 19:21:07 +01001179 /**
1180 * Tries to transfer the starting window from a token that's above ourselves in the task but
1181 * not visible anymore. This is a common scenario apps use: Trampoline activity T start main
1182 * activity M in the same task. Now, when reopening the task, T starts on top of M but then
1183 * immediately finishes after, so we have to transfer T to M.
1184 */
1185 void transferStartingWindowFromHiddenAboveTokenIfNeeded() {
1186 final Task task = getTask();
1187 for (int i = task.mChildren.size() - 1; i >= 0; i--) {
1188 final AppWindowToken fromToken = task.mChildren.get(i);
1189 if (fromToken == this) {
1190 return;
1191 }
1192 if (fromToken.hiddenRequested && transferStartingWindow(fromToken.token)) {
1193 return;
1194 }
1195 }
1196 }
1197
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001198 boolean transferStartingWindow(IBinder transferFrom) {
Wale Ogunwale02319a62016-09-26 15:21:22 -07001199 final AppWindowToken fromToken = getDisplayContent().getAppWindowToken(transferFrom);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001200 if (fromToken == null) {
1201 return false;
1202 }
1203
1204 final WindowState tStartingWindow = fromToken.startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001205 if (tStartingWindow != null && fromToken.startingSurface != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001206 // In this case, the starting icon has already been displayed, so start
1207 // letting windows get shown immediately without any more transitions.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001208 mService.mSkipAppTransitionAnimation = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001209
1210 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow
1211 + " from " + fromToken + " to " + this);
1212
1213 final long origId = Binder.clearCallingIdentity();
Peter Visontay3556a3b2017-11-01 17:23:17 +00001214 try {
1215 // Transfer the starting window over to the new token.
1216 startingData = fromToken.startingData;
1217 startingSurface = fromToken.startingSurface;
1218 startingDisplayed = fromToken.startingDisplayed;
1219 fromToken.startingDisplayed = false;
1220 startingWindow = tStartingWindow;
1221 reportedVisible = fromToken.reportedVisible;
1222 fromToken.startingData = null;
1223 fromToken.startingSurface = null;
1224 fromToken.startingWindow = null;
1225 fromToken.startingMoved = true;
1226 tStartingWindow.mToken = this;
1227 tStartingWindow.mAppToken = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001228
Peter Visontay3556a3b2017-11-01 17:23:17 +00001229 if (DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1230 "Removing starting " + tStartingWindow + " from " + fromToken);
1231 fromToken.removeChild(tStartingWindow);
1232 fromToken.postWindowRemoveStartingWindowCleanup(tStartingWindow);
1233 fromToken.mHiddenSetFromTransferredStartingWindow = false;
1234 addWindow(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001235
Peter Visontay3556a3b2017-11-01 17:23:17 +00001236 // Propagate other interesting state between the tokens. If the old token is displayed,
1237 // we should immediately force the new one to be displayed. If it is animating, we need
1238 // to move that animation to the new one.
1239 if (fromToken.allDrawn) {
1240 allDrawn = true;
1241 deferClearAllDrawn = fromToken.deferClearAllDrawn;
1242 }
1243 if (fromToken.firstWindowDrawn) {
1244 firstWindowDrawn = true;
1245 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001246 if (!fromToken.isHidden()) {
1247 setHidden(false);
Peter Visontay3556a3b2017-11-01 17:23:17 +00001248 hiddenRequested = false;
1249 mHiddenSetFromTransferredStartingWindow = true;
1250 }
1251 setClientHidden(fromToken.mClientHidden);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001252
Jorim Jaggi980c9de2017-11-17 01:41:37 +01001253 transferAnimation(fromToken);
1254
1255 // When transferring an animation, we no longer need to apply an animation to the
1256 // the token we transfer the animation over. Thus, remove the animation from
1257 // pending opening apps.
1258 mService.mOpeningApps.remove(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001259
Peter Visontay3556a3b2017-11-01 17:23:17 +00001260 mService.updateFocusedWindowLocked(
1261 UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/);
1262 getDisplayContent().setLayoutNeeded();
1263 mService.mWindowPlacerLocked.performSurfacePlacement();
1264 } finally {
1265 Binder.restoreCallingIdentity(origId);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001266 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001267 return true;
1268 } else if (fromToken.startingData != null) {
1269 // The previous app was getting ready to show a
1270 // starting window, but hasn't yet done so. Steal it!
1271 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1272 "Moving pending starting from " + fromToken + " to " + this);
1273 startingData = fromToken.startingData;
1274 fromToken.startingData = null;
1275 fromToken.startingMoved = true;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001276 if (getController() != null) {
1277 getController().scheduleAddStartingWindow();
1278 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001279 return true;
1280 }
1281
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001282 // TODO: Transfer thumbnail
1283
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001284 return false;
1285 }
1286
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001287 boolean isLastWindow(WindowState win) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001288 return mChildren.size() == 1 && mChildren.get(0) == win;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001289 }
1290
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001291 @Override
1292 void onAppTransitionDone() {
1293 sendingToBottom = false;
1294 }
1295
Wale Ogunwale51362492016-09-08 17:49:17 -07001296 /**
1297 * We override because this class doesn't want its children affecting its reported orientation
1298 * in anyway.
1299 */
1300 @Override
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001301 int getOrientation(int candidate) {
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001302 if (candidate == SCREEN_ORIENTATION_BEHIND) {
1303 // Allow app to specify orientation regardless of its visibility state if the current
1304 // candidate want us to use orientation behind. I.e. the visible app on-top of this one
1305 // wants us to use the orientation of the app behind it.
1306 return mOrientation;
1307 }
1308
Bryce Lee61fbcbc2017-03-10 14:14:03 -08001309 // The {@link AppWindowToken} should only specify an orientation when it is not closing or
1310 // going to the bottom. Allowing closing {@link AppWindowToken} to participate can lead to
1311 // an Activity in another task being started in the wrong orientation during the transition.
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001312 if (!(sendingToBottom || mService.mClosingApps.contains(this))
Andrii Kulian0918d362018-05-23 17:01:37 -07001313 && (isVisible() || mService.mOpeningApps.contains(this))) {
Bryce Leea163b762017-01-24 11:05:01 -08001314 return mOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001315 }
Bryce Leea163b762017-01-24 11:05:01 -08001316
1317 return SCREEN_ORIENTATION_UNSET;
Wale Ogunwale51362492016-09-08 17:49:17 -07001318 }
1319
Wale Ogunwaleb198b742016-12-01 08:44:09 -08001320 /** Returns the app's preferred orientation regardless of its currently visibility state. */
1321 int getOrientationIgnoreVisibility() {
1322 return mOrientation;
1323 }
1324
Craig Mautnerdbb79912012-03-01 18:59:14 -08001325 @Override
Winson Chunge55c0192017-08-24 14:50:48 -07001326 public void onConfigurationChanged(Configuration newParentConfig) {
1327 final int prevWinMode = getWindowingMode();
1328 super.onConfigurationChanged(newParentConfig);
1329 final int winMode = getWindowingMode();
1330
1331 if (prevWinMode == winMode) {
1332 return;
1333 }
1334
1335 if (prevWinMode != WINDOWING_MODE_UNDEFINED && winMode == WINDOWING_MODE_PINNED) {
1336 // Entering PiP from fullscreen, reset the snap fraction
1337 mDisplayContent.mPinnedStackControllerLocked.resetReentrySnapFraction(this);
Winson Chung82267ce2018-04-06 16:38:26 -07001338 } else if (prevWinMode == WINDOWING_MODE_PINNED && winMode != WINDOWING_MODE_UNDEFINED
1339 && !isHidden()) {
Winson Chunge55c0192017-08-24 14:50:48 -07001340 // Leaving PiP to fullscreen, save the snap fraction based on the pre-animation bounds
1341 // for the next re-entry into PiP (assuming the activity is not hidden or destroyed)
1342 final TaskStack pinnedStack = mDisplayContent.getPinnedStack();
1343 if (pinnedStack != null) {
Winson Chung8efa1652018-06-06 09:34:23 -07001344 final Rect stackBounds;
1345 if (pinnedStack.lastAnimatingBoundsWasToFullscreen()) {
1346 // We are animating the bounds, use the pre-animation bounds to save the snap
1347 // fraction
1348 stackBounds = pinnedStack.mPreAnimationBounds;
1349 } else {
1350 // We skip the animation if the fullscreen configuration is not compatible, so
1351 // use the current bounds to calculate the saved snap fraction instead
1352 // (see PinnedActivityStack.skipResizeAnimation())
1353 stackBounds = mTmpRect;
1354 pinnedStack.getBounds(stackBounds);
1355 }
Winson Chunge55c0192017-08-24 14:50:48 -07001356 mDisplayContent.mPinnedStackControllerLocked.saveReentrySnapFraction(this,
Winson Chung8efa1652018-06-06 09:34:23 -07001357 stackBounds);
Winson Chunge55c0192017-08-24 14:50:48 -07001358 }
1359 }
1360 }
1361
1362 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001363 void checkAppWindowsReadyToShow() {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001364 if (allDrawn == mLastAllDrawn) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001365 return;
1366 }
1367
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001368 mLastAllDrawn = allDrawn;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001369 if (!allDrawn) {
1370 return;
1371 }
1372
1373 // The token has now changed state to having all windows shown... what to do, what to do?
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001374 if (mFreezingScreen) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001375 showAllWindowsLocked();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001376 stopFreezingScreen(false, true);
1377 if (DEBUG_ORIENTATION) Slog.i(TAG,
1378 "Setting mOrientationChangeComplete=true because wtoken " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001379 + " numInteresting=" + mNumInterestingWindows + " numDrawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001380 // This will set mOrientationChangeComplete and cause a pass through layout.
1381 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001382 "checkAppWindowsReadyToShow: freezingScreen");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001383 } else {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001384 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001385
1386 // We can now show all of the drawn windows!
Jorim Jaggiaf0d6d22018-06-08 15:25:35 +02001387 if (!mService.mOpeningApps.contains(this) && canShowWindows()) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001388 showAllWindowsLocked();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001389 }
1390 }
1391 }
1392
Matthew Ng5d23afa2017-06-21 16:16:24 -07001393 /**
Bryce Leed390deb2017-06-22 13:14:28 -07001394 * Returns whether the drawn window states of this {@link AppWindowToken} has considered every
1395 * child {@link WindowState}. A child is considered if it has been passed into
1396 * {@link #updateDrawnWindowStates(WindowState)} after being added. This is used to determine
1397 * whether states, such as {@code allDrawn}, can be set, which relies on state variables such as
1398 * {@code mNumInterestingWindows}, which depend on all {@link WindowState}s being considered.
1399 *
1400 * @return {@code true} If all children have been considered, {@code false}.
1401 */
1402 private boolean allDrawnStatesConsidered() {
Bryce Lee6311c4b2017-07-06 14:09:29 -07001403 for (int i = mChildren.size() - 1; i >= 0; --i) {
1404 final WindowState child = mChildren.get(i);
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001405 if (child.mightAffectAllDrawn() && !child.getDrawnStateEvaluated()) {
Bryce Leed390deb2017-06-22 13:14:28 -07001406 return false;
1407 }
1408 }
1409 return true;
1410 }
1411
1412 /**
Matthew Ng5d23afa2017-06-21 16:16:24 -07001413 * Determines if the token has finished drawing. This should only be called from
1414 * {@link DisplayContent#applySurfaceChangesTransaction}
1415 */
Matthew Ng498c71d2017-04-18 13:55:45 -07001416 void updateAllDrawn() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001417 if (!allDrawn) {
Matthew Ng498c71d2017-04-18 13:55:45 -07001418 // Number of drawn windows can be less when a window is being relaunched, wait for
Bryce Leed390deb2017-06-22 13:14:28 -07001419 // all windows to be launched and drawn for this token be considered all drawn.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001420 final int numInteresting = mNumInterestingWindows;
Bryce Leed390deb2017-06-22 13:14:28 -07001421
1422 // We must make sure that all present children have been considered (determined by
1423 // {@link #allDrawnStatesConsidered}) before evaluating whether everything has been
1424 // drawn.
1425 if (numInteresting > 0 && allDrawnStatesConsidered()
1426 && mNumDrawnWindows >= numInteresting && !isRelaunching()) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001427 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawn: " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001428 + " interesting=" + numInteresting + " drawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001429 allDrawn = true;
1430 // Force an additional layout pass where
1431 // WindowStateAnimator#commitFinishDrawingLocked() will call performShowLocked().
Matthew Ng498c71d2017-04-18 13:55:45 -07001432 if (mDisplayContent != null) {
1433 mDisplayContent.setLayoutNeeded();
1434 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001435 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Robert Carrecc06b32017-04-18 14:25:10 -07001436
Winson Chunge7ba6862017-05-24 12:13:33 -07001437 // Notify the pinned stack upon all windows drawn. If there was an animation in
1438 // progress then this signal will resume that animation.
Wale Ogunwale61911492017-10-11 08:50:50 -07001439 final TaskStack pinnedStack = mDisplayContent.getPinnedStack();
Winson Chunge7ba6862017-05-24 12:13:33 -07001440 if (pinnedStack != null) {
1441 pinnedStack.onAllWindowsDrawn();
Robert Carrecc06b32017-04-18 14:25:10 -07001442 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001443 }
1444 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001445 }
1446
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001447 /**
1448 * Updated this app token tracking states for interesting and drawn windows based on the window.
1449 *
1450 * @return Returns true if the input window is considered interesting and drawn while all the
1451 * windows in this app token where not considered drawn as of the last pass.
1452 */
1453 boolean updateDrawnWindowStates(WindowState w) {
Bryce Leed390deb2017-06-22 13:14:28 -07001454 w.setDrawnStateEvaluated(true /*evaluated*/);
1455
Jorim Jaggie4b0f282017-05-17 15:10:29 +02001456 if (DEBUG_STARTING_WINDOW_VERBOSE && w == startingWindow) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001457 Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" + w.isOnScreen()
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001458 + " allDrawn=" + allDrawn + " freezingScreen=" + mFreezingScreen);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001459 }
1460
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001461 if (allDrawn && !mFreezingScreen) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001462 return false;
1463 }
1464
1465 if (mLastTransactionSequence != mService.mTransactionSequence) {
1466 mLastTransactionSequence = mService.mTransactionSequence;
Matthew Ng53e66b22018-01-12 17:13:13 -08001467 mNumDrawnWindows = 0;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001468 startingDisplayed = false;
Matthew Ng53e66b22018-01-12 17:13:13 -08001469
1470 // There is the main base application window, even if it is exiting, wait for it
1471 mNumInterestingWindows = findMainWindow(false /* includeStartingApp */) != null ? 1 : 0;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001472 }
1473
1474 final WindowStateAnimator winAnimator = w.mWinAnimator;
1475
1476 boolean isInterestingAndDrawn = false;
1477
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001478 if (!allDrawn && w.mightAffectAllDrawn()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001479 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
1480 Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw()
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001481 + ", isAnimationSet=" + isSelfAnimating());
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001482 if (!w.isDrawnLw()) {
1483 Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController
1484 + " pv=" + w.mPolicyVisibility
1485 + " mDrawState=" + winAnimator.drawStateToString()
1486 + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001487 + " a=" + isSelfAnimating());
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001488 }
1489 }
1490
1491 if (w != startingWindow) {
1492 if (w.isInteresting()) {
Matthew Ng53e66b22018-01-12 17:13:13 -08001493 // Add non-main window as interesting since the main app has already been added
1494 if (findMainWindow(false /* includeStartingApp */) != w) {
1495 mNumInterestingWindows++;
1496 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001497 if (w.isDrawnLw()) {
1498 mNumDrawnWindows++;
1499
1500 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, "tokenMayBeDrawn: "
1501 + this + " w=" + w + " numInteresting=" + mNumInterestingWindows
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001502 + " freezingScreen=" + mFreezingScreen
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001503 + " mAppFreezing=" + w.mAppFreezing);
1504
1505 isInterestingAndDrawn = true;
1506 }
1507 }
1508 } else if (w.isDrawnLw()) {
Jorim Jaggi3878ca32017-02-02 17:13:05 -08001509 if (getController() != null) {
1510 getController().reportStartingWindowDrawn();
1511 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001512 startingDisplayed = true;
1513 }
1514 }
1515
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001516 return isInterestingAndDrawn;
1517 }
1518
Adrian Roos23df3a32018-03-15 15:41:13 +01001519 void layoutLetterbox(WindowState winHint) {
Adrian Roos4d18a2e2017-12-19 19:08:05 +01001520 final WindowState w = findMainWindow();
Adrian Roosf93b6d22018-03-21 13:48:26 +01001521 if (w == null || winHint != null && w != winHint) {
Adrian Roos4d18a2e2017-12-19 19:08:05 +01001522 return;
1523 }
Jorim Jaggia32da382018-03-28 18:01:22 +02001524 final boolean surfaceReady = w.isDrawnLw() // Regular case
Adrian Roosf93b6d22018-03-21 13:48:26 +01001525 || w.mWinAnimator.mSurfaceDestroyDeferred // The preserved surface is still ready.
1526 || w.isDragResizeChanged(); // Waiting for relayoutWindow to call preserveSurface.
1527 final boolean needsLetterbox = w.isLetterboxedAppWindow() && fillsParent() && surfaceReady;
Adrian Roos4d18a2e2017-12-19 19:08:05 +01001528 if (needsLetterbox) {
1529 if (mLetterbox == null) {
1530 mLetterbox = new Letterbox(() -> makeChildSurface(null));
1531 }
chaviw492139a2018-07-16 16:07:35 -07001532 mLetterbox.layout(getParent().getBounds(), w.getFrameLw());
Adrian Roos4d18a2e2017-12-19 19:08:05 +01001533 } else if (mLetterbox != null) {
Adrian Roos23df3a32018-03-15 15:41:13 +01001534 mLetterbox.hide();
1535 }
1536 }
1537
1538 void updateLetterboxSurface(WindowState winHint) {
1539 final WindowState w = findMainWindow();
1540 if (w != winHint && winHint != null && w != null) {
1541 return;
1542 }
1543 layoutLetterbox(winHint);
1544 if (mLetterbox != null && mLetterbox.needsApplySurfaceChanges()) {
1545 mLetterbox.applySurfaceChanges(mPendingTransaction);
Adrian Roos4d18a2e2017-12-19 19:08:05 +01001546 }
1547 }
1548
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001549 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001550 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001551 // For legacy reasons we process the TaskStack.mExitingAppTokens first in DisplayContent
1552 // before the non-exiting app tokens. So, we skip the exiting app tokens here.
1553 // TODO: Investigate if we need to continue to do this or if we can just process them
1554 // in-order.
1555 if (mIsExiting && !waitingForReplacement()) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001556 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001557 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001558 return forAllWindowsUnchecked(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001559 }
1560
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001561 boolean forAllWindowsUnchecked(ToBooleanFunction<WindowState> callback,
1562 boolean traverseTopToBottom) {
1563 return super.forAllWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001564 }
1565
1566 @Override
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001567 AppWindowToken asAppWindowToken() {
1568 // I am an app window token!
1569 return this;
1570 }
1571
1572 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -07001573 boolean fillsParent() {
1574 return mFillsParent;
1575 }
1576
1577 void setFillsParent(boolean fillsParent) {
1578 mFillsParent = fillsParent;
1579 }
1580
Jorim Jaggife762342016-10-13 14:33:27 +02001581 boolean containsDismissKeyguardWindow() {
Bryce Lee081554b2017-05-25 07:52:12 -07001582 // Window state is transient during relaunch. We are not guaranteed to be frozen during the
1583 // entirety of the relaunch.
1584 if (isRelaunching()) {
1585 return mLastContainsDismissKeyguardWindow;
1586 }
1587
Jorim Jaggife762342016-10-13 14:33:27 +02001588 for (int i = mChildren.size() - 1; i >= 0; i--) {
1589 if ((mChildren.get(i).mAttrs.flags & FLAG_DISMISS_KEYGUARD) != 0) {
1590 return true;
1591 }
1592 }
1593 return false;
1594 }
1595
1596 boolean containsShowWhenLockedWindow() {
Bryce Lee081554b2017-05-25 07:52:12 -07001597 // When we are relaunching, it is possible for us to be unfrozen before our previous
1598 // windows have been added back. Using the cached value ensures that our previous
1599 // showWhenLocked preference is honored until relaunching is complete.
1600 if (isRelaunching()) {
1601 return mLastContainsShowWhenLockedWindow;
1602 }
1603
Jorim Jaggife762342016-10-13 14:33:27 +02001604 for (int i = mChildren.size() - 1; i >= 0; i--) {
1605 if ((mChildren.get(i).mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
1606 return true;
1607 }
1608 }
Bryce Lee081554b2017-05-25 07:52:12 -07001609
Jorim Jaggife762342016-10-13 14:33:27 +02001610 return false;
1611 }
1612
1613 void checkKeyguardFlagsChanged() {
1614 final boolean containsDismissKeyguard = containsDismissKeyguardWindow();
1615 final boolean containsShowWhenLocked = containsShowWhenLockedWindow();
1616 if (containsDismissKeyguard != mLastContainsDismissKeyguardWindow
1617 || containsShowWhenLocked != mLastContainsShowWhenLockedWindow) {
1618 mService.notifyKeyguardFlagsChanged(null /* callback */);
1619 }
1620 mLastContainsDismissKeyguardWindow = containsDismissKeyguard;
1621 mLastContainsShowWhenLockedWindow = containsShowWhenLocked;
1622 }
1623
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001624 WindowState getImeTargetBelowWindow(WindowState w) {
1625 final int index = mChildren.indexOf(w);
1626 if (index > 0) {
1627 final WindowState target = mChildren.get(index - 1);
1628 if (target.canBeImeTarget()) {
1629 return target;
1630 }
1631 }
1632 return null;
1633 }
1634
1635 WindowState getHighestAnimLayerWindow(WindowState currentTarget) {
1636 WindowState candidate = null;
1637 for (int i = mChildren.indexOf(currentTarget); i >= 0; i--) {
1638 final WindowState w = mChildren.get(i);
1639 if (w.mRemoved) {
1640 continue;
1641 }
Jorim Jaggi35d328a2018-08-14 17:00:20 +02001642 if (candidate == null) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001643 candidate = w;
1644 }
1645 }
1646 return candidate;
1647 }
1648
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001649 /**
1650 * See {@link Activity#setDisablePreviewScreenshots}.
1651 */
1652 void setDisablePreviewScreenshots(boolean disable) {
Wale Ogunwale6c459212017-05-17 08:56:03 -07001653 mDisablePreviewScreenshots = disable;
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001654 }
1655
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001656 /**
chaviwd3bf08d2017-08-01 17:24:59 -07001657 * Sets whether the current launch can turn the screen on. See {@link #canTurnScreenOn()}
1658 */
1659 void setCanTurnScreenOn(boolean canTurnScreenOn) {
1660 mCanTurnScreenOn = canTurnScreenOn;
1661 }
1662
1663 /**
1664 * Indicates whether the current launch can turn the screen on. This is to prevent multiple
1665 * relayouts from turning the screen back on. The screen should only turn on at most
1666 * once per activity resume.
1667 *
1668 * @return true if the screen can be turned on.
1669 */
1670 boolean canTurnScreenOn() {
1671 return mCanTurnScreenOn;
1672 }
1673
1674 /**
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001675 * Retrieves whether we'd like to generate a snapshot that's based solely on the theme. This is
1676 * the case when preview screenshots are disabled {@link #setDisablePreviewScreenshots} or when
1677 * we can't take a snapshot for other reasons, for example, if we have a secure window.
1678 *
1679 * @return True if we need to generate an app theme snapshot, false if we'd like to take a real
1680 * screenshot.
1681 */
1682 boolean shouldUseAppThemeSnapshot() {
Wale Ogunwale6c459212017-05-17 08:56:03 -07001683 return mDisablePreviewScreenshots || forAllWindows(w -> (w.mAttrs.flags & FLAG_SECURE) != 0,
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001684 true /* topToBottom */);
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001685 }
1686
Jorim Jaggibe418292018-03-26 16:14:12 +02001687 SurfaceControl getAppAnimationLayer() {
Jorim Jaggi391790622018-04-18 15:30:44 +02001688 return getAppAnimationLayer(isActivityTypeHome() ? ANIMATION_LAYER_HOME
1689 : needsZBoost() ? ANIMATION_LAYER_BOOSTED
1690 : ANIMATION_LAYER_STANDARD);
Jorim Jaggibe418292018-03-26 16:14:12 +02001691 }
1692
chaviw23ee71c2017-12-18 11:29:41 -08001693 @Override
Jorim Jaggi596a1992017-12-29 14:48:02 +01001694 public SurfaceControl getAnimationLeashParent() {
Robert Carrb9506032018-02-13 13:54:00 -08001695 // All normal app transitions take place in an animation layer which is below the pinned
1696 // stack but may be above the parent stacks of the given animating apps.
1697 // For transitions in the pinned stack (menu activity) we just let them occur as a child
1698 // of the pinned stack.
1699 if (!inPinnedWindowingMode()) {
1700 return getAppAnimationLayer();
1701 } else {
1702 return getStack().getSurfaceControl();
1703 }
chaviw23ee71c2017-12-18 11:29:41 -08001704 }
1705
Jorim Jaggic6976f02018-04-18 16:31:07 +02001706 private boolean shouldAnimate(int transit) {
1707 final boolean isSplitScreenPrimary =
1708 getWindowingMode() == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY;
1709 final boolean allowSplitScreenPrimaryAnimation = transit != TRANSIT_WALLPAPER_OPEN;
1710
1711 // We animate always if it's not split screen primary, and only some special cases in split
1712 // screen primary because it causes issues with stack clipping when we run an un-minimize
1713 // animation at the same time.
1714 return !isSplitScreenPrimary || allowSplitScreenPrimaryAnimation;
1715 }
1716
Vishnu Naira2977262018-07-26 13:31:26 -07001717 /**
1718 * Creates a layer to apply crop to an animation.
1719 */
1720 private SurfaceControl createAnimationBoundsLayer(Transaction t) {
1721 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.i(TAG, "Creating animation bounds layer");
1722 final SurfaceControl.Builder builder = makeAnimationLeash()
1723 .setParent(getAnimationLeashParent())
1724 .setName(getSurfaceControl() + " - animation-bounds")
1725 .setSize(getSurfaceWidth(), getSurfaceHeight());
1726 final SurfaceControl boundsLayer = builder.build();
1727 t.show(boundsLayer);
1728 return boundsLayer;
1729 }
1730
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001731 boolean applyAnimationLocked(WindowManager.LayoutParams lp, int transit, boolean enter,
1732 boolean isVoiceInteraction) {
1733
Jorim Jaggic6976f02018-04-18 16:31:07 +02001734 if (mService.mDisableTransitionAnimation || !shouldAnimate(transit)) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001735 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
Jorim Jaggic6976f02018-04-18 16:31:07 +02001736 Slog.v(TAG_WM, "applyAnimation: transition animation is disabled or skipped."
1737 + " atoken=" + this);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001738 }
1739 cancelAnimation();
1740 return false;
1741 }
1742
1743 // Only apply an animation if the display isn't frozen. If it is frozen, there is no reason
1744 // to animate and it can cause strange artifacts when we unfreeze the display if some
1745 // different animation is running.
1746 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "AWT#applyAnimationLocked");
1747 if (okToAnimate()) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001748 final AnimationAdapter adapter;
1749 final TaskStack stack = getStack();
1750 mTmpPoint.set(0, 0);
1751 mTmpRect.setEmpty();
1752 if (stack != null) {
1753 stack.getRelativePosition(mTmpPoint);
1754 stack.getBounds(mTmpRect);
1755 mTmpRect.offsetTo(0, 0);
1756 }
Jorim Jaggic4d29f22018-03-22 16:30:56 +01001757
1758 // Delaying animation start isn't compatible with remote animations at all.
1759 if (mService.mAppTransition.getRemoteAnimationController() != null
1760 && !mSurfaceAnimator.isAnimationStartDelayed()) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001761 adapter = mService.mAppTransition.getRemoteAnimationController()
1762 .createAnimationAdapter(this, mTmpPoint, mTmpRect);
1763 } else {
Vishnu Naira2977262018-07-26 13:31:26 -07001764 final int appStackClipMode = mService.mAppTransition.getAppStackClipMode();
1765 mNeedsAnimationBoundsLayer = (appStackClipMode == STACK_CLIP_AFTER_ANIM);
1766
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001767 final Animation a = loadAnimation(lp, transit, enter, isVoiceInteraction);
1768 if (a != null) {
1769 adapter = new LocalAnimationAdapter(
1770 new WindowAnimationSpec(a, mTmpPoint, mTmpRect,
1771 mService.mAppTransition.canSkipFirstFrame(),
Vishnu Naira2977262018-07-26 13:31:26 -07001772 appStackClipMode,
Jorim Jaggiaa763cd2018-03-22 23:20:36 +01001773 true /* isAppAnimation */),
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001774 mService.mSurfaceAnimationRunner);
1775 if (a.getZAdjustment() == Animation.ZORDER_TOP) {
1776 mNeedsZBoost = true;
1777 }
1778 mTransit = transit;
1779 mTransitFlags = mService.mAppTransition.getTransitFlags();
1780 } else {
1781 adapter = null;
chaviw23ee71c2017-12-18 11:29:41 -08001782 }
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001783 }
1784 if (adapter != null) {
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001785 startAnimation(getPendingTransaction(), adapter, !isVisible());
Jorim Jaggi82c17862018-02-21 17:50:18 +01001786 if (adapter.getShowWallpaper()) {
1787 mDisplayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
1788 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001789 }
1790 } else {
1791 cancelAnimation();
1792 }
1793 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
1794
1795 return isReallyAnimating();
1796 }
1797
1798 private Animation loadAnimation(WindowManager.LayoutParams lp, int transit, boolean enter,
1799 boolean isVoiceInteraction) {
1800 final DisplayContent displayContent = getTask().getDisplayContent();
1801 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
1802 final int width = displayInfo.appWidth;
1803 final int height = displayInfo.appHeight;
1804 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG_WM,
1805 "applyAnimation: atoken=" + this);
1806
1807 // Determine the visible rect to calculate the thumbnail clip
1808 final WindowState win = findMainWindow();
1809 final Rect frame = new Rect(0, 0, width, height);
1810 final Rect displayFrame = new Rect(0, 0,
1811 displayInfo.logicalWidth, displayInfo.logicalHeight);
1812 final Rect insets = new Rect();
1813 final Rect stableInsets = new Rect();
1814 Rect surfaceInsets = null;
1815 final boolean freeform = win != null && win.inFreeformWindowingMode();
1816 if (win != null) {
1817 // Containing frame will usually cover the whole screen, including dialog windows.
1818 // For freeform workspace windows it will not cover the whole screen and it also
1819 // won't exactly match the final freeform window frame (e.g. when overlapping with
1820 // the status bar). In that case we need to use the final frame.
1821 if (freeform) {
chaviw492139a2018-07-16 16:07:35 -07001822 frame.set(win.getFrameLw());
Adrian Roos4d18a2e2017-12-19 19:08:05 +01001823 } else if (win.isLetterboxedAppWindow()) {
1824 frame.set(getTask().getBounds());
Winson Chungc1674272018-02-21 10:15:17 -08001825 } else if (win.isDockedResizing()) {
1826 // If we are animating while docked resizing, then use the stack bounds as the
1827 // animation target (which will be different than the task bounds)
1828 frame.set(getTask().getParent().getBounds());
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001829 } else {
chaviw553b0212018-07-12 13:37:01 -07001830 frame.set(win.getContainingFrame());
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001831 }
1832 surfaceInsets = win.getAttrs().surfaceInsets;
Adrian Roos20e07892018-02-23 19:12:01 +01001833 // XXX(b/72757033): These are insets relative to the window frame, but we're really
1834 // interested in the insets relative to the frame we chose in the if-blocks above.
chaviw9c81e632018-07-31 11:17:52 -07001835 win.getContentInsets(insets);
1836 win.getStableInsets(stableInsets);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001837 }
1838
1839 if (mLaunchTaskBehind) {
1840 // Differentiate the two animations. This one which is briefly on the screen
1841 // gets the !enter animation, and the other activity which remains on the
1842 // screen gets the enter animation. Both appear in the mOpeningApps set.
1843 enter = false;
1844 }
1845 if (DEBUG_APP_TRANSITIONS) Slog.d(TAG_WM, "Loading animation for app transition."
1846 + " transit=" + AppTransition.appTransitionToString(transit) + " enter=" + enter
1847 + " frame=" + frame + " insets=" + insets + " surfaceInsets=" + surfaceInsets);
1848 final Configuration displayConfig = displayContent.getConfiguration();
1849 final Animation a = mService.mAppTransition.loadAnimation(lp, transit, enter,
1850 displayConfig.uiMode, displayConfig.orientation, frame, displayFrame, insets,
1851 surfaceInsets, stableInsets, isVoiceInteraction, freeform, getTask().mTaskId);
1852 if (a != null) {
1853 if (DEBUG_ANIM) logWithStack(TAG, "Loaded animation " + a + " for " + this);
1854 final int containingWidth = frame.width();
1855 final int containingHeight = frame.height();
1856 a.initialize(containingWidth, containingHeight, width, height);
1857 a.scaleCurrentDuration(mService.getTransitionAnimationScaleLocked());
1858 }
1859 return a;
1860 }
1861
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001862 @Override
Jorim Jaggi6de61012018-03-19 14:53:23 +01001863 public boolean shouldDeferAnimationFinish(Runnable endDeferFinishCallback) {
1864 return mAnimatingAppWindowTokenRegistry != null
1865 && mAnimatingAppWindowTokenRegistry.notifyAboutToFinish(
1866 this, endDeferFinishCallback);
1867 }
1868
1869 @Override
1870 public void onAnimationLeashDestroyed(Transaction t) {
1871 super.onAnimationLeashDestroyed(t);
Vishnu Naira2977262018-07-26 13:31:26 -07001872 if (mAnimationBoundsLayer != null) {
1873 t.destroy(mAnimationBoundsLayer);
1874 mAnimationBoundsLayer = null;
1875 }
1876
Jorim Jaggi6de61012018-03-19 14:53:23 +01001877 if (mAnimatingAppWindowTokenRegistry != null) {
1878 mAnimatingAppWindowTokenRegistry.notifyFinished(this);
1879 }
1880 }
1881
1882 @Override
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001883 protected void setLayer(Transaction t, int layer) {
1884 if (!mSurfaceAnimator.hasLeash()) {
1885 t.setLayer(mSurfaceControl, layer);
1886 }
1887 }
1888
1889 @Override
1890 protected void setRelativeLayer(Transaction t, SurfaceControl relativeTo, int layer) {
1891 if (!mSurfaceAnimator.hasLeash()) {
1892 t.setRelativeLayer(mSurfaceControl, relativeTo, layer);
1893 }
1894 }
1895
1896 @Override
1897 protected void reparentSurfaceControl(Transaction t, SurfaceControl newParent) {
1898 if (!mSurfaceAnimator.hasLeash()) {
1899 t.reparent(mSurfaceControl, newParent.getHandle());
1900 }
1901 }
1902
1903 @Override
1904 public void onAnimationLeashCreated(Transaction t, SurfaceControl leash) {
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001905 // The leash is parented to the animation layer. We need to preserve the z-order by using
1906 // the prefix order index, but we boost if necessary.
Robert Carrb9506032018-02-13 13:54:00 -08001907 int layer = 0;
1908 if (!inPinnedWindowingMode()) {
1909 layer = getPrefixOrderIndex();
1910 } else {
1911 // Pinned stacks have animations take place within themselves rather than an animation
1912 // layer so we need to preserve the order relative to the stack (e.g. the order of our
1913 // task/parent).
1914 layer = getParent().getPrefixOrderIndex();
1915 }
1916
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001917 if (mNeedsZBoost) {
1918 layer += Z_BOOST_BASE;
1919 }
1920 leash.setLayer(layer);
Robert Carr2f8aa392018-01-31 14:46:51 -08001921
1922 final DisplayContent dc = getDisplayContent();
Jorim Jaggibe418292018-03-26 16:14:12 +02001923 dc.assignStackOrdering();
Jorim Jaggi6de61012018-03-19 14:53:23 +01001924 if (mAnimatingAppWindowTokenRegistry != null) {
1925 mAnimatingAppWindowTokenRegistry.notifyStarting(this);
1926 }
Vishnu Naira2977262018-07-26 13:31:26 -07001927
1928 // If the animation needs to be cropped then an animation bounds layer is created as a child
1929 // of the pinned stack or animation layer. The leash is then reparented to this new layer.
1930 if (mNeedsAnimationBoundsLayer) {
1931 final TaskStack stack = getStack();
1932 if (stack == null) {
1933 return;
1934 }
1935 mAnimationBoundsLayer = createAnimationBoundsLayer(t);
1936
1937 // Set clip rect to stack bounds.
1938 mTmpRect.setEmpty();
1939 stack.getBounds(mTmpRect);
1940
1941 // Crop to stack bounds.
1942 t.setWindowCrop(mAnimationBoundsLayer, mTmpRect);
1943
1944 // Reparent leash to animation bounds layer.
1945 t.reparent(leash, mAnimationBoundsLayer.getHandle());
1946 }
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001947 }
1948
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001949 /**
1950 * This must be called while inside a transaction.
1951 */
1952 void showAllWindowsLocked() {
1953 forAllWindows(windowState -> {
1954 if (DEBUG_VISIBILITY) Slog.v(TAG, "performing show on: " + windowState);
1955 windowState.performShowLocked();
1956 }, false /* traverseTopToBottom */);
Jorim Jaggia5e10572017-11-15 14:36:26 +01001957 }
1958
1959 @Override
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001960 protected void onAnimationFinished() {
1961 super.onAnimationFinished();
1962
1963 mTransit = TRANSIT_UNSET;
1964 mTransitFlags = 0;
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001965 mNeedsZBoost = false;
Vishnu Naira2977262018-07-26 13:31:26 -07001966 mNeedsAnimationBoundsLayer = false;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001967
1968 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM | FINISH_LAYOUT_REDO_WALLPAPER,
1969 "AppWindowToken");
1970
Jorim Jaggi988f6682017-11-17 17:46:43 +01001971 clearThumbnail();
Jorim Jaggi752cd822018-03-29 16:29:18 +02001972 setClientHidden(isHidden() && hiddenRequested);
Jorim Jaggi988f6682017-11-17 17:46:43 +01001973
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001974 if (mService.mInputMethodTarget != null && mService.mInputMethodTarget.mAppToken == this) {
1975 getDisplayContent().computeImeTarget(true /* updateImeTarget */);
1976 }
1977
1978 if (DEBUG_ANIM) Slog.v(TAG, "Animation done in " + this
1979 + ": reportedVisible=" + reportedVisible
1980 + " okToDisplay=" + okToDisplay()
1981 + " okToAnimate=" + okToAnimate()
1982 + " startingDisplayed=" + startingDisplayed);
1983
1984 // WindowState.onExitAnimationDone might modify the children list, so make a copy and then
1985 // traverse the copy.
1986 final ArrayList<WindowState> children = new ArrayList<>(mChildren);
1987 children.forEach(WindowState::onExitAnimationDone);
1988
1989 mService.mAppTransition.notifyAppTransitionFinishedLocked(token);
1990 scheduleAnimation();
1991 }
1992
1993 @Override
1994 boolean isAppAnimating() {
1995 return isSelfAnimating();
1996 }
1997
1998 @Override
1999 boolean isSelfAnimating() {
2000 // If we are about to start a transition, we also need to be considered animating.
2001 return isWaitingForTransitionStart() || isReallyAnimating();
2002 }
2003
2004 /**
2005 * @return True if and only if we are actually running an animation. Note that
2006 * {@link #isSelfAnimating} also returns true if we are waiting for an animation to
2007 * start.
2008 */
2009 private boolean isReallyAnimating() {
2010 return super.isSelfAnimating();
2011 }
2012
Jorim Jaggi988f6682017-11-17 17:46:43 +01002013 @Override
2014 void cancelAnimation() {
2015 super.cancelAnimation();
2016 clearThumbnail();
2017 }
2018
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002019 boolean isWaitingForTransitionStart() {
2020 return mService.mAppTransition.isTransitionSet()
2021 && (mService.mOpeningApps.contains(this) || mService.mClosingApps.contains(this));
2022 }
2023
2024 public int getTransit() {
2025 return mTransit;
2026 }
2027
2028 int getTransitFlags() {
2029 return mTransitFlags;
2030 }
2031
Jorim Jaggi988f6682017-11-17 17:46:43 +01002032 void attachThumbnailAnimation() {
2033 if (!isReallyAnimating()) {
2034 return;
2035 }
2036 final int taskId = getTask().mTaskId;
2037 final GraphicBuffer thumbnailHeader =
2038 mService.mAppTransition.getAppTransitionThumbnailHeader(taskId);
2039 if (thumbnailHeader == null) {
2040 if (DEBUG_APP_TRANSITIONS) Slog.d(TAG, "No thumbnail header bitmap for: " + taskId);
2041 return;
2042 }
2043 clearThumbnail();
2044 mThumbnail = new AppWindowThumbnail(getPendingTransaction(), this, thumbnailHeader);
2045 mThumbnail.startAnimation(getPendingTransaction(), loadThumbnailAnimation(thumbnailHeader));
2046 }
2047
Tony Mak64b8d562017-12-28 17:44:02 +00002048 /**
2049 * Attaches a surface with a thumbnail for the
2050 * {@link android.app.ActivityOptions#ANIM_OPEN_CROSS_PROFILE_APPS} animation.
2051 */
2052 void attachCrossProfileAppsThumbnailAnimation() {
2053 if (!isReallyAnimating()) {
2054 return;
2055 }
2056 clearThumbnail();
2057
2058 final WindowState win = findMainWindow();
2059 if (win == null) {
2060 return;
2061 }
chaviw492139a2018-07-16 16:07:35 -07002062 final Rect frame = win.getFrameLw();
Tony Mak64b8d562017-12-28 17:44:02 +00002063 final int thumbnailDrawableRes = getTask().mUserId == mService.mCurrentUserId
2064 ? R.drawable.ic_account_circle
Tony Makda4af232018-04-27 11:01:10 +01002065 : R.drawable.ic_corp_badge;
Tony Mak64b8d562017-12-28 17:44:02 +00002066 final GraphicBuffer thumbnail =
2067 mService.mAppTransition
2068 .createCrossProfileAppsThumbnail(thumbnailDrawableRes, frame);
2069 if (thumbnail == null) {
2070 return;
2071 }
2072 mThumbnail = new AppWindowThumbnail(getPendingTransaction(), this, thumbnail);
2073 final Animation animation =
chaviw492139a2018-07-16 16:07:35 -07002074 mService.mAppTransition.createCrossProfileAppsThumbnailAnimationLocked(
2075 win.getFrameLw());
Tony Mak64b8d562017-12-28 17:44:02 +00002076 mThumbnail.startAnimation(getPendingTransaction(), animation, new Point(frame.left,
2077 frame.top));
2078 }
2079
Jorim Jaggi988f6682017-11-17 17:46:43 +01002080 private Animation loadThumbnailAnimation(GraphicBuffer thumbnailHeader) {
2081 final DisplayInfo displayInfo = mDisplayContent.getDisplayInfo();
2082
2083 // If this is a multi-window scenario, we use the windows frame as
2084 // destination of the thumbnail header animation. If this is a full screen
2085 // window scenario, we use the whole display as the target.
2086 WindowState win = findMainWindow();
2087 Rect appRect = win != null ? win.getContentFrameLw() :
2088 new Rect(0, 0, displayInfo.appWidth, displayInfo.appHeight);
chaviw9c81e632018-07-31 11:17:52 -07002089 final Rect insets = win != null ? win.getContentInsets() : null;
Jorim Jaggi988f6682017-11-17 17:46:43 +01002090 final Configuration displayConfig = mDisplayContent.getConfiguration();
2091 return mService.mAppTransition.createThumbnailAspectScaleAnimationLocked(
2092 appRect, insets, thumbnailHeader, getTask().mTaskId, displayConfig.uiMode,
2093 displayConfig.orientation);
2094 }
2095
2096 private void clearThumbnail() {
2097 if (mThumbnail == null) {
2098 return;
2099 }
2100 mThumbnail.destroy();
2101 mThumbnail = null;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002102 }
2103
Jorim Jaggif84e2f62018-01-16 14:17:59 +01002104 void registerRemoteAnimations(RemoteAnimationDefinition definition) {
2105 mRemoteAnimationDefinition = definition;
2106 }
2107
2108 RemoteAnimationDefinition getRemoteAnimationDefinition() {
2109 return mRemoteAnimationDefinition;
2110 }
2111
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002112 @Override
2113 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
2114 super.dump(pw, prefix, dumpAll);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002115 if (appToken != null) {
Wale Ogunwale72919d22016-12-08 18:58:50 -08002116 pw.println(prefix + "app=true mVoiceInteraction=" + mVoiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002117 }
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08002118 pw.print(prefix); pw.print("task="); pw.println(getTask());
Wale Ogunwale51362492016-09-08 17:49:17 -07002119 pw.print(prefix); pw.print(" mFillsParent="); pw.print(mFillsParent);
2120 pw.print(" mOrientation="); pw.println(mOrientation);
Wale Ogunwale89973222017-04-23 18:39:45 -07002121 pw.println(prefix + "hiddenRequested=" + hiddenRequested + " mClientHidden=" + mClientHidden
2122 + ((mDeferHidingClient) ? " mDeferHidingClient=" + mDeferHidingClient : "")
2123 + " reportedDrawn=" + reportedDrawn + " reportedVisible=" + reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -07002124 if (paused) {
2125 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002126 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -08002127 if (mAppStopped) {
2128 pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped);
2129 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07002130 if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002131 || allDrawn || mLastAllDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07002132 pw.print(prefix); pw.print("mNumInterestingWindows=");
2133 pw.print(mNumInterestingWindows);
2134 pw.print(" mNumDrawnWindows="); pw.print(mNumDrawnWindows);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002135 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -07002136 pw.print(" allDrawn="); pw.print(allDrawn);
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002137 pw.print(" lastAllDrawn="); pw.print(mLastAllDrawn);
Craig Mautner6fbda632012-07-03 09:26:39 -07002138 pw.println(")");
2139 }
2140 if (inPendingTransaction) {
2141 pw.print(prefix); pw.print("inPendingTransaction=");
2142 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002143 }
Craig Mautner799bc1d2015-01-14 10:33:48 -08002144 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002145 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
2146 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -08002147 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -08002148 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002149 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08002150 if (startingWindow != null || startingSurface != null
Wale Ogunwale6c459212017-05-17 08:56:03 -07002151 || startingDisplayed || startingMoved || mHiddenSetFromTransferredStartingWindow) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002152 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08002153 pw.print(" startingSurface="); pw.print(startingSurface);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002154 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
Wale Ogunwale6c459212017-05-17 08:56:03 -07002155 pw.print(" startingMoved="); pw.print(startingMoved);
2156 pw.println(" mHiddenSetFromTransferredStartingWindow="
2157 + mHiddenSetFromTransferredStartingWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002158 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01002159 if (!mFrozenBounds.isEmpty()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -08002160 pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds);
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002161 pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig);
Chong Zhangd78ddb42016-03-02 17:01:14 -08002162 }
2163 if (mPendingRelaunchCount != 0) {
2164 pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount);
Jorim Jaggi0429f352015-12-22 16:29:16 +01002165 }
Wale Ogunwale9c64cb62017-04-12 13:39:59 -07002166 if (getController() != null) {
2167 pw.print(prefix); pw.print("controller="); pw.println(getController());
2168 }
Wale Ogunwalee287e192017-04-21 09:30:12 -07002169 if (mRemovingFromDisplay) {
2170 pw.println(prefix + "mRemovingFromDisplay=" + mRemovingFromDisplay);
2171 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002172 }
2173
2174 @Override
2175 void setHidden(boolean hidden) {
2176 super.setHidden(hidden);
Winson Chunge55c0192017-08-24 14:50:48 -07002177
2178 if (hidden) {
2179 // Once the app window is hidden, reset the last saved PiP snap fraction
2180 mDisplayContent.mPinnedStackControllerLocked.resetReentrySnapFraction(this);
2181 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002182 scheduleAnimation();
2183 }
2184
2185 @Override
2186 void prepareSurfaces() {
2187 // isSelfAnimating also returns true when we are about to start a transition, so we need
2188 // to check super here.
2189 final boolean reallyAnimating = super.isSelfAnimating();
2190 final boolean show = !isHidden() || reallyAnimating;
2191 if (show && !mLastSurfaceShowing) {
2192 mPendingTransaction.show(mSurfaceControl);
2193 } else if (!show && mLastSurfaceShowing) {
2194 mPendingTransaction.hide(mSurfaceControl);
Jorim Jaggi4d1835d2017-08-31 17:28:27 +02002195 }
Jorim Jaggi988f6682017-11-17 17:46:43 +01002196 if (mThumbnail != null) {
2197 mThumbnail.setShowing(mPendingTransaction, show);
2198 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002199 mLastSurfaceShowing = show;
2200 super.prepareSurfaces();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002201 }
2202
Jorim Jaggi77d0f36c2018-03-16 17:49:49 +01002203 /**
2204 * @return Whether our {@link #getSurfaceControl} is currently showing.
2205 */
2206 boolean isSurfaceShowing() {
2207 return mLastSurfaceShowing;
2208 }
2209
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002210 boolean isFreezingScreen() {
2211 return mFreezingScreen;
2212 }
2213
2214 @Override
2215 boolean needsZBoost() {
2216 return mNeedsZBoost || super.needsZBoost();
2217 }
2218
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07002219 @CallSuper
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002220 @Override
Adrian Roos4921ccf2017-09-28 16:54:06 +02002221 public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07002222 final long token = proto.start(fieldId);
2223 writeNameToProto(proto, NAME);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002224 super.writeToProto(proto, WINDOW_TOKEN, trim);
Vishnu Nair04ab4392018-01-10 11:00:06 -08002225 proto.write(LAST_SURFACE_SHOWING, mLastSurfaceShowing);
2226 proto.write(IS_WAITING_FOR_TRANSITION_START, isWaitingForTransitionStart());
2227 proto.write(IS_REALLY_ANIMATING, isReallyAnimating());
2228 if (mThumbnail != null){
2229 mThumbnail.writeToProto(proto, THUMBNAIL);
2230 }
2231 proto.write(FILLS_PARENT, mFillsParent);
2232 proto.write(APP_STOPPED, mAppStopped);
2233 proto.write(HIDDEN_REQUESTED, hiddenRequested);
2234 proto.write(CLIENT_HIDDEN, mClientHidden);
2235 proto.write(DEFER_HIDING_CLIENT, mDeferHidingClient);
2236 proto.write(REPORTED_DRAWN, reportedDrawn);
2237 proto.write(REPORTED_VISIBLE, reportedVisible);
2238 proto.write(NUM_INTERESTING_WINDOWS, mNumInterestingWindows);
2239 proto.write(NUM_DRAWN_WINDOWS, mNumDrawnWindows);
2240 proto.write(ALL_DRAWN, allDrawn);
2241 proto.write(LAST_ALL_DRAWN, mLastAllDrawn);
2242 proto.write(REMOVED, removed);
2243 if (startingWindow != null){
2244 startingWindow.writeIdentifierToProto(proto, STARTING_WINDOW);
2245 }
2246 proto.write(STARTING_DISPLAYED, startingDisplayed);
2247 proto.write(STARTING_MOVED, startingMoved);
2248 proto.write(HIDDEN_SET_FROM_TRANSFERRED_STARTING_WINDOW,
2249 mHiddenSetFromTransferredStartingWindow);
2250 for (Rect bounds : mFrozenBounds) {
2251 bounds.writeToProto(proto, FROZEN_BOUNDS);
2252 }
Steven Timotiusaf03df62017-07-18 16:56:43 -07002253 proto.end(token);
2254 }
2255
2256 void writeNameToProto(ProtoOutputStream proto, long fieldId) {
2257 if (appToken == null) {
2258 return;
2259 }
2260 try {
2261 proto.write(fieldId, appToken.getName());
2262 } catch (RemoteException e) {
2263 // This shouldn't happen, but in this case fall back to outputting nothing
2264 Slog.e(TAG, e.toString());
2265 }
2266 }
2267
2268 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002269 public String toString() {
2270 if (stringName == null) {
2271 StringBuilder sb = new StringBuilder();
2272 sb.append("AppWindowToken{");
2273 sb.append(Integer.toHexString(System.identityHashCode(this)));
2274 sb.append(" token="); sb.append(token); sb.append('}');
2275 stringName = sb.toString();
2276 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07002277 return stringName + ((mIsExiting) ? " mIsExiting=" : "");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002278 }
Adrian Roos20e07892018-02-23 19:12:01 +01002279
2280 Rect getLetterboxInsets() {
2281 if (mLetterbox != null) {
2282 return mLetterbox.getInsets();
2283 } else {
2284 return new Rect();
2285 }
2286 }
Adrian Roos23df3a32018-03-15 15:41:13 +01002287
2288 /**
2289 * @eturn true if there is a letterbox and any part of that letterbox overlaps with
2290 * the given {@code rect}.
2291 */
2292 boolean isLetterboxOverlappingWith(Rect rect) {
2293 return mLetterbox != null && mLetterbox.isOverlappingWith(rect);
2294 }
chaviw4ad54912018-05-30 11:05:44 -07002295
2296 /**
2297 * Sets if this AWT is in the process of closing or entering PIP.
2298 * {@link #mWillCloseOrEnterPip}}
2299 */
2300 void setWillCloseOrEnterPip(boolean willCloseOrEnterPip) {
2301 mWillCloseOrEnterPip = willCloseOrEnterPip;
2302 }
2303
2304 /**
2305 * Returns whether this AWT is considered closing. Conditions are either
2306 * 1. Is this app animating and was requested to be hidden
2307 * 2. App is delayed closing since it might enter PIP.
2308 */
2309 boolean isClosingOrEnteringPip() {
2310 return (isAnimating() && hiddenRequested) || mWillCloseOrEnterPip;
2311 }
Jorim Jaggiaf0d6d22018-06-08 15:25:35 +02002312
2313 /**
2314 * @return Whether we are allowed to show non-starting windows at the moment. We disallow
2315 * showing windows during transitions in case we have windows that have wide-color-gamut
2316 * color mode set to avoid jank in the middle of the transition.
2317 */
2318 boolean canShowWindows() {
2319 return allDrawn && !(isReallyAnimating() && hasNonDefaultColorWindow());
2320 }
2321
2322 /**
2323 * @return true if we have a window that has a non-default color mode set; false otherwise.
2324 */
2325 private boolean hasNonDefaultColorWindow() {
2326 return forAllWindows(ws -> ws.mAttrs.getColorMode() != COLOR_MODE_DEFAULT,
2327 true /* topToBottom */);
2328 }
Jeff Browne9bdb312012-04-05 15:30:10 -07002329}