blob: e38e229099578f10126d09a6fb795ea71d1037ee [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;
Riddle Hsua118b3a2018-10-11 22:05:06 +0800105import com.android.internal.annotations.VisibleForTesting;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800106import com.android.internal.util.ToBooleanFunction;
107import com.android.server.input.InputApplicationHandle;
Adrian Roose99bc052017-11-20 17:55:31 +0100108import com.android.server.policy.WindowManagerPolicy.StartingSurface;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800109import com.android.server.wm.WindowManagerService.H;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800110
111import java.io.PrintWriter;
Jorim Jaggi0429f352015-12-22 16:29:16 +0100112import java.util.ArrayDeque;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800113import java.util.ArrayList;
114
115class AppTokenList extends ArrayList<AppWindowToken> {
116}
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800117
118/**
119 * Version of WindowToken that is specifically for a particular application (or
120 * really activity) that is displaying windows.
121 */
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700122class AppWindowToken extends WindowToken implements WindowManagerService.AppFreezeListener {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800123 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppWindowToken" : TAG_WM;
124
Jorim Jaggi619c9f72017-12-19 18:04:29 +0100125 /**
126 * Value to increment the z-layer when boosting a layer during animations. BOOST in l33tsp34k.
127 */
128 private static final int Z_BOOST_BASE = 800570000;
129
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800130 // Non-null only for application tokens.
131 final IApplicationToken appToken;
132
Wale Ogunwale72919d22016-12-08 18:58:50 -0800133 final boolean mVoiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700134
Wale Ogunwale51362492016-09-08 17:49:17 -0700135 /** @see WindowContainer#fillsParent() */
136 private boolean mFillsParent;
Craig Mautner4c5eb222013-11-18 12:59:05 -0800137 boolean layoutConfigChanges;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800138 boolean mShowForAllUsers;
139 int mTargetSdk;
Craig Mautnera2c77052012-03-26 12:14:43 -0700140
Bryce Lee6d410262017-02-28 15:30:17 -0800141 // Flag set while reparenting to prevent actions normally triggered by an individual parent
142 // change.
143 private boolean mReparenting;
144
Wale Ogunwalee287e192017-04-21 09:30:12 -0700145 // True if we are current in the process of removing this app token from the display
146 private boolean mRemovingFromDisplay = false;
147
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800148 // The input dispatching timeout for this application token in nanoseconds.
Wale Ogunwale72919d22016-12-08 18:58:50 -0800149 long mInputDispatchingTimeoutNanos;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800150
151 // These are used for determining when all windows associated with
152 // an activity have been drawn, so they can be made visible together
153 // at the same time.
Craig Mautner764983d2012-03-22 11:37:36 -0700154 // initialize so that it doesn't match mTransactionSequence which is an int.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700155 private long mLastTransactionSequence = Long.MIN_VALUE;
156 private int mNumInterestingWindows;
157 private int mNumDrawnWindows;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800158 boolean inPendingTransaction;
159 boolean allDrawn;
Jorim Jaggib0fc8172017-11-23 17:04:08 +0000160 private boolean mLastAllDrawn;
161
Craig Mautner7636dfb2012-11-16 15:24:11 -0800162 // Set to true when this app creates a surface while in the middle of an animation. In that
163 // case do not clear allDrawn until the animation completes.
164 boolean deferClearAllDrawn;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800165
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800166 // Is this window's surface needed? This is almost like hidden, except
167 // it will sometimes be true a little earlier: when the token has
168 // been shown, but is still waiting for its app transition to execute
169 // before making its windows shown.
170 boolean hiddenRequested;
171
172 // Have we told the window clients to hide themselves?
Wale Ogunwale89973222017-04-23 18:39:45 -0700173 private boolean mClientHidden;
174
175 // If true we will defer setting mClientHidden to true and reporting to the client that it is
176 // hidden.
177 boolean mDeferHidingClient;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800178
179 // Last visibility state we reported to the app token.
180 boolean reportedVisible;
181
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700182 // Last drawn state we reported to the app token.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700183 private boolean reportedDrawn;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700184
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800185 // Set to true when the token has been removed from the window mgr.
186 boolean removed;
187
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800188 // Information about an application starting window if displayed.
189 StartingData startingData;
190 WindowState startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800191 StartingSurface startingSurface;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800192 boolean startingDisplayed;
193 boolean startingMoved;
Jorim Jaggi60f9c972018-02-01 19:21:07 +0100194
Wale Ogunwale6c459212017-05-17 08:56:03 -0700195 // True if the hidden state of this token was forced to false due to a transferred starting
196 // window.
197 private boolean mHiddenSetFromTransferredStartingWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800198 boolean firstWindowDrawn;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700199 private final WindowState.UpdateReportedVisibilityResults mReportedVisibilityResults =
200 new WindowState.UpdateReportedVisibilityResults();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800201
202 // Input application handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700203 final InputApplicationHandle mInputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800204
Wale Ogunwale571771c2016-08-26 13:18:50 -0700205 // TODO: Have a WindowContainer state for tracking exiting/deferred removal.
Craig Mautner799bc1d2015-01-14 10:33:48 -0800206 boolean mIsExiting;
Craig Mautner9ef471f2014-02-07 13:11:47 -0800207
Craig Mautnerbb742462014-07-07 15:28:55 -0700208 boolean mLaunchTaskBehind;
Craig Mautner8746a472014-07-24 15:12:54 -0700209 boolean mEnteringAnimation;
Craig Mautnerbb742462014-07-07 15:28:55 -0700210
Wale Ogunwale72919d22016-12-08 18:58:50 -0800211 private boolean mAlwaysFocusable;
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800212
Robert Carre12aece2016-02-02 22:43:27 -0800213 boolean mAppStopped;
Robert Carrfd10cd12016-06-29 16:41:50 -0700214 int mRotationAnimationHint;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700215 private int mPendingRelaunchCount;
Robert Carre12aece2016-02-02 22:43:27 -0800216
Jorim Jaggife762342016-10-13 14:33:27 +0200217 private boolean mLastContainsShowWhenLockedWindow;
218 private boolean mLastContainsDismissKeyguardWindow;
219
Jorim Jaggi0429f352015-12-22 16:29:16 +0100220 ArrayDeque<Rect> mFrozenBounds = new ArrayDeque<>();
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700221 ArrayDeque<Configuration> mFrozenMergedConfig = new ArrayDeque<>();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100222
Wale Ogunwale6c459212017-05-17 08:56:03 -0700223 private boolean mDisablePreviewScreenshots;
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +0100224
Wale Ogunwale034a8ec2017-09-02 17:14:40 -0700225 private Task mLastParent;
Robert Carred3e83b2017-04-21 13:26:55 -0700226
chaviwd3bf08d2017-08-01 17:24:59 -0700227 /**
228 * See {@link #canTurnScreenOn()}
229 */
230 private boolean mCanTurnScreenOn = true;
231
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200232 /**
233 * If we are running an animation, this determines the transition type. Must be one of
234 * AppTransition.TRANSIT_* constants.
235 */
236 private int mTransit;
237
238 /**
239 * If we are running an animation, this determines the flags during this animation. Must be a
240 * bitwise combination of AppTransition.TRANSIT_FLAG_* constants.
241 */
242 private int mTransitFlags;
243
244 /** Whether our surface was set to be showing in the last call to {@link #prepareSurfaces} */
Jorim Jaggifd1891462017-12-29 15:41:36 +0100245 private boolean mLastSurfaceShowing = true;
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200246
Jorim Jaggi988f6682017-11-17 17:46:43 +0100247 private AppWindowThumbnail mThumbnail;
248
Jorim Jaggib0fc8172017-11-23 17:04:08 +0000249 /** Have we been asked to have this token keep the screen frozen? */
250 private boolean mFreezingScreen;
251
252 /** Whether this token should be boosted at the top of all app window tokens. */
253 private boolean mNeedsZBoost;
Adrian Roos4d18a2e2017-12-19 19:08:05 +0100254 private Letterbox mLetterbox;
Jorim Jaggib0fc8172017-11-23 17:04:08 +0000255
chaviw23ee71c2017-12-18 11:29:41 -0800256 private final Point mTmpPoint = new Point();
chaviw23012112017-12-20 15:29:04 -0800257 private final Rect mTmpRect = new Rect();
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100258 private RemoteAnimationDefinition mRemoteAnimationDefinition;
Jorim Jaggi6de61012018-03-19 14:53:23 +0100259 private AnimatingAppWindowTokenRegistry mAnimatingAppWindowTokenRegistry;
chaviw23ee71c2017-12-18 11:29:41 -0800260
chaviw4ad54912018-05-30 11:05:44 -0700261 /**
262 * A flag to determine if this AWT is in the process of closing or entering PIP. This is needed
263 * to help AWT know that the app is in the process of closing but hasn't yet started closing on
264 * the WM side.
265 */
266 private boolean mWillCloseOrEnterPip;
267
Vishnu Naira2977262018-07-26 13:31:26 -0700268 /** Layer used to constrain the animation to a token's stack bounds. */
269 SurfaceControl mAnimationBoundsLayer;
270
271 /** Whether this token needs to create mAnimationBoundsLayer for cropping animations. */
272 boolean mNeedsAnimationBoundsLayer;
273
Wale Ogunwale72919d22016-12-08 18:58:50 -0800274 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
275 DisplayContent dc, long inputDispatchingTimeoutNanos, boolean fullscreen,
276 boolean showForAllUsers, int targetSdk, int orientation, int rotationAnimationHint,
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800277 int configChanges, boolean launchTaskBehind, boolean alwaysFocusable,
Bryce Leef3c6a472017-11-14 14:53:06 -0800278 AppWindowContainerController controller) {
279 this(service, token, voiceInteraction, dc, fullscreen);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800280 setController(controller);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800281 mInputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800282 mShowForAllUsers = showForAllUsers;
283 mTargetSdk = targetSdk;
284 mOrientation = orientation;
285 layoutConfigChanges = (configChanges & (CONFIG_SCREEN_SIZE | CONFIG_ORIENTATION)) != 0;
286 mLaunchTaskBehind = launchTaskBehind;
287 mAlwaysFocusable = alwaysFocusable;
288 mRotationAnimationHint = rotationAnimationHint;
289
290 // Application tokens start out hidden.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200291 setHidden(true);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800292 hiddenRequested = true;
293 }
294
295 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
Bryce Leef3c6a472017-11-14 14:53:06 -0800296 DisplayContent dc, boolean fillsParent) {
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800297 super(service, token != null ? token.asBinder() : null, TYPE_APPLICATION, true, dc,
298 false /* ownerCanManageAppTokens */);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700299 appToken = token;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800300 mVoiceInteraction = voiceInteraction;
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800301 mFillsParent = fillsParent;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800302 mInputApplicationHandle = new InputApplicationHandle(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800303 }
304
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800305 void onFirstWindowDrawn(WindowState win, WindowStateAnimator winAnimator) {
306 firstWindowDrawn = true;
307
308 // We now have a good window to show, remove dead placeholders
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700309 removeDeadWindows();
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800310
Jorim Jaggi02886a82016-12-06 09:10:06 -0800311 if (startingWindow != null) {
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800312 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, "Finish starting "
313 + win.mToken + ": first real window is shown, no animation");
314 // If this initial window is animating, stop it -- we will do an animation to reveal
315 // it from behind the starting window, so there is no need for it to also be doing its
316 // own stuff.
Jorim Jaggia5e10572017-11-15 14:36:26 +0100317 win.cancelAnimation();
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800318 if (getController() != null) {
319 getController().removeStartingWindow();
320 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800321 }
322 updateReportedVisibilityLocked();
323 }
324
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800325 void updateReportedVisibilityLocked() {
326 if (appToken == null) {
327 return;
328 }
329
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700330 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700331 final int count = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800332
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700333 mReportedVisibilityResults.reset();
334
335 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700336 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700337 win.updateReportedVisibility(mReportedVisibilityResults);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800338 }
339
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700340 int numInteresting = mReportedVisibilityResults.numInteresting;
341 int numVisible = mReportedVisibilityResults.numVisible;
342 int numDrawn = mReportedVisibilityResults.numDrawn;
343 boolean nowGone = mReportedVisibilityResults.nowGone;
344
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700345 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200346 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting && !isHidden();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700347 if (!nowGone) {
348 // If the app is not yet gone, then it can only become visible/drawn.
349 if (!nowDrawn) {
350 nowDrawn = reportedDrawn;
351 }
352 if (!nowVisible) {
353 nowVisible = reportedVisible;
354 }
355 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800356 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800357 + numInteresting + " visible=" + numVisible);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800358 final AppWindowContainerController controller = getController();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700359 if (nowDrawn != reportedDrawn) {
360 if (nowDrawn) {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800361 if (controller != null) {
362 controller.reportWindowsDrawn();
363 }
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700364 }
365 reportedDrawn = nowDrawn;
366 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800367 if (nowVisible != reportedVisible) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700368 if (DEBUG_VISIBILITY) Slog.v(TAG,
369 "Visibility changed in " + this + ": vis=" + nowVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800370 reportedVisible = nowVisible;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800371 if (controller != null) {
372 if (nowVisible) {
373 controller.reportWindowsVisible();
374 } else {
375 controller.reportWindowsGone();
376 }
377 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800378 }
379 }
380
Wale Ogunwale89973222017-04-23 18:39:45 -0700381 boolean isClientHidden() {
382 return mClientHidden;
383 }
384
385 void setClientHidden(boolean hideClient) {
386 if (mClientHidden == hideClient || (hideClient && mDeferHidingClient)) {
387 return;
388 }
Jorim Jaggi067b5bf2018-02-23 17:42:39 +0100389 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setClientHidden: " + this
390 + " clientHidden=" + hideClient + " Callers=" + Debug.getCallers(5));
Wale Ogunwale89973222017-04-23 18:39:45 -0700391 mClientHidden = hideClient;
392 sendAppVisibilityToClients();
393 }
394
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700395 boolean setVisibility(WindowManager.LayoutParams lp,
396 boolean visible, int transit, boolean performLayout, boolean isVoiceInteraction) {
397
398 boolean delayed = false;
399 inPendingTransaction = false;
Wale Ogunwale9e4721f2017-05-23 19:37:30 -0700400 // Reset the state of mHiddenSetFromTransferredStartingWindow since visibility is actually
401 // been set by the app now.
402 mHiddenSetFromTransferredStartingWindow = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700403
404 // Allow for state changes and animation to be applied if:
405 // * token is transitioning visibility state
406 // * or the token was marked as hidden and is exiting before we had a chance to play the
407 // transition animation
408 // * or this is an opening app and windows are being replaced.
409 boolean visibilityChanged = false;
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200410 if (isHidden() == visible || (isHidden() && mIsExiting) || (visible && waitingForReplacement())) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700411 final AccessibilityController accessibilityController = mService.mAccessibilityController;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700412 boolean changed = false;
413 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200414 "Changing app " + this + " hidden=" + isHidden() + " performLayout=" + performLayout);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700415
416 boolean runningAppAnimation = false;
417
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100418 if (transit != WindowManager.TRANSIT_UNSET) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200419 if (applyAnimationLocked(lp, transit, visible, isVoiceInteraction)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700420 delayed = runningAppAnimation = true;
421 }
422 final WindowState window = findMainWindow();
423 //TODO (multidisplay): Magnification is supported only for the default display.
424 if (window != null && accessibilityController != null
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700425 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700426 accessibilityController.onAppWindowTransitionLocked(window, transit);
427 }
428 changed = true;
429 }
430
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700431 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700432 for (int i = 0; i < windowsCount; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700433 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700434 changed |= win.onAppVisibilityChanged(visible, runningAppAnimation);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700435 }
436
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200437 setHidden(!visible);
438 hiddenRequested = !visible;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700439 visibilityChanged = true;
440 if (!visible) {
441 stopFreezingScreen(true, true);
442 } else {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700443 // If we are being set visible, and the starting window is not yet displayed,
444 // then make sure it doesn't get displayed.
445 if (startingWindow != null && !startingWindow.isDrawnLw()) {
446 startingWindow.mPolicyVisibility = false;
447 startingWindow.mPolicyVisibilityAfterAnim = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700448 }
Jorim Jaggi38d44ec2017-06-14 16:04:59 -0700449
450 // We are becoming visible, so better freeze the screen with the windows that are
451 // getting visible so we also wait for them.
452 forAllWindows(mService::makeWindowFreezingScreenIfNeededLocked, true);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700453 }
454
455 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setVisibility: " + this
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200456 + ": hidden=" + isHidden() + " hiddenRequested=" + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700457
458 if (changed) {
Arthur Hung95b38a92018-07-20 18:56:12 +0800459 getDisplayContent().getInputMonitor().setUpdateInputWindowsNeededLw();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700460 if (performLayout) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700461 mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700462 false /*updateInputWindows*/);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700463 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700464 }
Arthur Hung95b38a92018-07-20 18:56:12 +0800465 getDisplayContent().getInputMonitor().updateInputWindowsLw(false /*force*/);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700466 }
467 }
468
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200469 if (isReallyAnimating()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700470 delayed = true;
Jorim Jaggiab9fcb22018-03-15 23:46:12 +0100471 } else {
472
473 // We aren't animating anything, but exiting windows rely on the animation finished
474 // callback being called in case the AppWindowToken was pretending to be animating,
475 // which we might have done because we were in closing/opening apps list.
476 onAnimationFinished();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700477 }
478
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700479 for (int i = mChildren.size() - 1; i >= 0 && !delayed; i--) {
Jorim Jaggia5e10572017-11-15 14:36:26 +0100480 if ((mChildren.get(i)).isSelfOrChildAnimating()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700481 delayed = true;
482 }
483 }
484
485 if (visibilityChanged) {
486 if (visible && !delayed) {
487 // The token was made immediately visible, there will be no entrance animation.
488 // We need to inform the client the enter animation was finished.
489 mEnteringAnimation = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700490 mService.mActivityManagerAppTransitionNotifier.onAppTransitionFinishedLocked(token);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700491 }
Robert Carr61b81112017-07-17 18:08:15 -0700492
Jorim Jaggi110839b2018-01-22 12:49:04 +0100493 // If we're becoming visible, immediately change client visibility as well although it
494 // usually gets changed in AppWindowContainerController.setVisibility already. However,
495 // there seem to be some edge cases where we change our visibility but client visibility
496 // never gets updated.
497 // If we're becoming invisible, update the client visibility if we are not running an
498 // animation. Otherwise, we'll update client visibility in onAnimationFinished.
Jorim Jaggi3cad57f2018-02-20 18:32:01 +0100499 if (visible || !isReallyAnimating()) {
Jorim Jaggi110839b2018-01-22 12:49:04 +0100500 setClientHidden(!visible);
Jorim Jaggi4876b4a2018-01-11 15:43:49 +0100501 }
502
chaviwa953fcf2018-03-01 12:00:39 -0800503 if (!mService.mClosingApps.contains(this) && !mService.mOpeningApps.contains(this)) {
504 // The token is not closing nor opening, so even if there is an animation set, that
505 // doesn't mean that it goes through the normal app transition cycle so we have
506 // to inform the docked controller about visibility change.
507 // TODO(multi-display): notify docked divider on all displays where visibility was
508 // affected.
509 mService.getDefaultDisplayContentLocked().getDockedDividerController()
510 .notifyAppVisibilityChanged();
511
512 // Take the screenshot before possibly hiding the WSA, otherwise the screenshot
513 // will not be taken.
514 mService.mTaskSnapshotController.notifyAppVisibilityChanged(this, visible);
515 }
516
Robert Carre7cc44d2017-03-20 19:04:30 -0700517 // If we are hidden but there is no delay needed we immediately
518 // apply the Surface transaction so that the ActivityManager
Robert Carr61b81112017-07-17 18:08:15 -0700519 // can have some guarantee on the Surface state following
520 // setting the visibility. This captures cases like dismissing
521 // the docked or pinned stack where there is no app transition.
522 //
523 // In the case of a "Null" animation, there will be
524 // no animation but there will still be a transition set.
525 // We still need to delay hiding the surface such that it
526 // can be synchronized with showing the next surface in the transition.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200527 if (isHidden() && !delayed && !mService.mAppTransition.isTransitionSet()) {
Robert Carr6914f082017-03-20 19:04:30 -0700528 SurfaceControl.openTransaction();
529 for (int i = mChildren.size() - 1; i >= 0; i--) {
530 mChildren.get(i).mWinAnimator.hide("immediately hidden");
531 }
532 SurfaceControl.closeTransaction();
533 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700534 }
535
536 return delayed;
537 }
538
Jorim Jaggi87fdbcb2017-08-17 13:41:11 +0200539 /**
540 * @return The to top most child window for which {@link LayoutParams#isFullscreen()} returns
541 * true.
542 */
543 WindowState getTopFullscreenWindow() {
544 for (int i = mChildren.size() - 1; i >= 0; i--) {
545 final WindowState win = mChildren.get(i);
546 if (win != null && win.mAttrs.isFullscreen()) {
547 return win;
548 }
549 }
550 return null;
551 }
552
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800553 WindowState findMainWindow() {
Matthew Ng53e66b22018-01-12 17:13:13 -0800554 return findMainWindow(true);
555 }
556
557 /**
558 * Finds the main window that either has type base application or application starting if
559 * requested.
560 *
561 * @param includeStartingApp Allow to search application-starting windows to also be returned.
562 * @return The main window of type base application or application starting if requested.
563 */
564 WindowState findMainWindow(boolean includeStartingApp) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700565 WindowState candidate = null;
Matthew Ng53e66b22018-01-12 17:13:13 -0800566 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700567 final WindowState win = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700568 final int type = win.mAttrs.type;
569 // No need to loop through child window as base application and starting types can't be
570 // child windows.
Matthew Ng53e66b22018-01-12 17:13:13 -0800571 if (type == TYPE_BASE_APPLICATION
572 || (includeStartingApp && type == TYPE_APPLICATION_STARTING)) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700573 // In cases where there are multiple windows, we prefer the non-exiting window. This
Sungsoo Lim0d3d1f82015-12-02 14:47:59 +0900574 // happens for example when replacing windows during an activity relaunch. When
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700575 // constructing the animation, we want the new window, not the exiting one.
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800576 if (win.mAnimatingExit) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700577 candidate = win;
578 } else {
579 return win;
580 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800581 }
582 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700583 return candidate;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800584 }
585
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800586 boolean windowsAreFocusable() {
Wale Ogunwale3382ab12017-07-27 08:55:03 -0700587 return getWindowConfiguration().canReceiveKeys() || mAlwaysFocusable;
Wale Ogunwaled045c822015-12-02 09:14:28 -0800588 }
589
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800590 AppWindowContainerController getController() {
591 final WindowContainerController controller = super.getController();
592 return controller != null ? (AppWindowContainerController) controller : null;
593 }
594
Wale Ogunwale571771c2016-08-26 13:18:50 -0700595 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -0700596 boolean isVisible() {
Wale Ogunwalee471be62016-10-03 07:53:55 -0700597 // If the app token isn't hidden then it is considered visible and there is no need to check
598 // its children windows to see if they are visible.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200599 return !isHidden();
Wale Ogunwale44f21802016-09-02 12:49:48 -0700600 }
601
602 @Override
Wale Ogunwalee287e192017-04-21 09:30:12 -0700603 void removeImmediately() {
604 onRemovedFromDisplay();
605 super.removeImmediately();
606 }
607
608 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -0700609 void removeIfPossible() {
Craig Mautnere3119b72015-01-20 15:02:36 -0800610 mIsExiting = false;
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800611 removeAllWindowsIfPossible();
Bryce Lee6d410262017-02-28 15:30:17 -0800612 removeImmediately();
Craig Mautnere3119b72015-01-20 15:02:36 -0800613 }
614
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700615 @Override
616 boolean checkCompleteDeferredRemoval() {
617 if (mIsExiting) {
618 removeIfPossible();
619 }
620 return super.checkCompleteDeferredRemoval();
621 }
622
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700623 void onRemovedFromDisplay() {
Wale Ogunwalee287e192017-04-21 09:30:12 -0700624 if (mRemovingFromDisplay) {
625 return;
626 }
627 mRemovingFromDisplay = true;
628
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700629 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app token: " + this);
630
Wale Ogunwale72919d22016-12-08 18:58:50 -0800631 boolean delayed = setVisibility(null, false, TRANSIT_UNSET, true, mVoiceInteraction);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700632
633 mService.mOpeningApps.remove(this);
Jorim Jaggi45ca0542017-05-30 16:16:01 -0700634 mService.mUnknownAppVisibilityController.appRemovedOrHidden(this);
Jorim Jaggi10abe2f2017-01-03 16:44:46 +0100635 mService.mTaskSnapshotController.onAppRemoved(this);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700636 waitingToShow = false;
637 if (mService.mClosingApps.contains(this)) {
638 delayed = true;
639 } else if (mService.mAppTransition.isTransitionSet()) {
640 mService.mClosingApps.add(this);
641 delayed = true;
642 }
643
644 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app " + this + " delayed=" + delayed
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200645 + " animation=" + getAnimation() + " animating=" + isSelfAnimating());
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700646
647 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM, "removeAppToken: "
648 + this + " delayed=" + delayed + " Callers=" + Debug.getCallers(4));
649
Jorim Jaggi19be6052017-08-03 18:33:43 +0200650 if (startingData != null && getController() != null) {
651 getController().removeStartingWindow();
652 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800653
Winson Chung87e5d552017-04-05 11:49:38 -0700654 // If this window was animating, then we need to ensure that the app transition notifies
655 // that animations have completed in WMS.handleAnimatingStoppedAndTransitionLocked(), so
656 // add to that list now
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200657 if (isSelfAnimating()) {
Winson Chung87e5d552017-04-05 11:49:38 -0700658 mService.mNoAnimationNotifyOnTransitionFinished.add(token);
659 }
660
Wale Ogunwalee287e192017-04-21 09:30:12 -0700661 final TaskStack stack = getStack();
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700662 if (delayed && !isEmpty()) {
663 // set the token aside because it has an active animation to be finished
664 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM,
665 "removeAppToken make exiting: " + this);
Wale Ogunwalee287e192017-04-21 09:30:12 -0700666 if (stack != null) {
667 stack.mExitingAppTokens.add(this);
668 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700669 mIsExiting = true;
670 } else {
671 // Make sure there is no animation running on this token, so any windows associated
672 // with it will be removed as soon as their animations are complete
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200673 cancelAnimation();
Wale Ogunwale3106ae012017-05-16 08:56:37 -0700674 if (stack != null) {
675 stack.mExitingAppTokens.remove(this);
676 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700677 removeIfPossible();
678 }
679
680 removed = true;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700681 stopFreezingScreen(true, true);
Bryce Lee6d410262017-02-28 15:30:17 -0800682
Tiger Huang1e5b10a2018-07-30 20:19:51 +0800683 final DisplayContent dc = getDisplayContent();
684 if (dc.mFocusedApp == this) {
685 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "Removing focused app token:" + this
686 + " displayId=" + dc.getDisplayId());
687 dc.setFocusedApp(null);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700688 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700689 }
690
691 if (!delayed) {
692 updateReportedVisibilityLocked();
693 }
Wale Ogunwalee287e192017-04-21 09:30:12 -0700694
695 mRemovingFromDisplay = false;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700696 }
697
Chong Zhange05bcb12016-07-26 17:47:29 -0700698 void clearAnimatingFlags() {
Chong Zhangb0d26702016-08-12 16:03:29 -0700699 boolean wallpaperMightChange = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700700 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700701 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700702 wallpaperMightChange |= win.clearAnimatingFlags();
Chong Zhange05bcb12016-07-26 17:47:29 -0700703 }
Chong Zhangb0d26702016-08-12 16:03:29 -0700704 if (wallpaperMightChange) {
705 requestUpdateWallpaperIfNeeded();
706 }
Chong Zhange05bcb12016-07-26 17:47:29 -0700707 }
708
Robert Carre12aece2016-02-02 22:43:27 -0800709 void destroySurfaces() {
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700710 destroySurfaces(false /*cleanupOnResume*/);
711 }
712
713 /**
714 * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure
715 * the client has finished with them.
716 *
717 * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If
718 * set to true, destroy only surfaces of removed windows, and clear relevant flags of the
719 * others so that they are ready to be reused. If set to false (common case), destroy all
720 * surfaces that's eligible, if the app is already stopped.
721 */
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700722 private void destroySurfaces(boolean cleanupOnResume) {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700723 boolean destroyedSomething = false;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100724
725 // Copying to a different list as multiple children can be removed.
Jorim Jaggi59f3e922018-01-05 15:40:32 +0100726 final ArrayList<WindowState> children = new ArrayList<>(mChildren);
Jorim Jaggia5e10572017-11-15 14:36:26 +0100727 for (int i = children.size() - 1; i >= 0; i--) {
728 final WindowState win = children.get(i);
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700729 destroyedSomething |= win.destroySurface(cleanupOnResume, mAppStopped);
Robert Carre12aece2016-02-02 22:43:27 -0800730 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700731 if (destroyedSomething) {
732 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700733 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Adrian Roos23df3a32018-03-15 15:41:13 +0100734 updateLetterboxSurface(null);
Robert Carre12aece2016-02-02 22:43:27 -0800735 }
736 }
737
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800738 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700739 * Notify that the app is now resumed, and it was not stopped before, perform a clean
740 * up of the surfaces
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800741 */
Jorim Jaggibae01b12017-04-11 16:29:10 -0700742 void notifyAppResumed(boolean wasStopped) {
Chong Zhangad24f962016-08-25 12:12:33 -0700743 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped
Jorim Jaggibae01b12017-04-11 16:29:10 -0700744 + " " + this);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700745 mAppStopped = false;
chaviwd3bf08d2017-08-01 17:24:59 -0700746 // Allow the window to turn the screen on once the app is resumed again.
747 setCanTurnScreenOn(true);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700748 if (!wasStopped) {
749 destroySurfaces(true /*cleanupOnResume*/);
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800750 }
Robert Carre12aece2016-02-02 22:43:27 -0800751 }
752
Chong Zhangbef461f2015-10-27 11:38:24 -0700753 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700754 * Notify that the app has stopped, and it is okay to destroy any surfaces which were
755 * keeping alive in case they were still being used.
756 */
757 void notifyAppStopped() {
758 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this);
759 mAppStopped = true;
760 destroySurfaces();
761 // Remove any starting window that was added for this app if they are still around.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800762 if (getController() != null) {
763 getController().removeStartingWindow();
764 }
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700765 }
766
Chong Zhang92147042016-05-09 12:47:11 -0700767 void clearAllDrawn() {
768 allDrawn = false;
769 deferClearAllDrawn = false;
Chong Zhangbef461f2015-10-27 11:38:24 -0700770 }
771
Bryce Lee6d410262017-02-28 15:30:17 -0800772 Task getTask() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800773 return (Task) getParent();
Bryce Lee6d410262017-02-28 15:30:17 -0800774 }
775
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800776 TaskStack getStack() {
777 final Task task = getTask();
778 if (task != null) {
779 return task.mStack;
780 } else {
781 return null;
782 }
783 }
784
Bryce Lee6d410262017-02-28 15:30:17 -0800785 @Override
786 void onParentSet() {
787 super.onParentSet();
788
Robert Carred3e83b2017-04-21 13:26:55 -0700789 final Task task = getTask();
790
Bryce Lee6d410262017-02-28 15:30:17 -0800791 // When the associated task is {@code null}, the {@link AppWindowToken} can no longer
792 // access visual elements like the {@link DisplayContent}. We must remove any associations
793 // such as animations.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800794 if (!mReparenting) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800795 if (task == null) {
796 // It is possible we have been marked as a closing app earlier. We must remove ourselves
797 // from this list so we do not participate in any future animations.
798 mService.mClosingApps.remove(this);
Robert Carred3e83b2017-04-21 13:26:55 -0700799 } else if (mLastParent != null && mLastParent.mStack != null) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800800 task.mStack.mExitingAppTokens.remove(this);
801 }
Bryce Lee6d410262017-02-28 15:30:17 -0800802 }
Jorim Jaggi6de61012018-03-19 14:53:23 +0100803 final TaskStack stack = getStack();
804
805 // If we reparent, make sure to remove ourselves from the old animation registry.
806 if (mAnimatingAppWindowTokenRegistry != null) {
807 mAnimatingAppWindowTokenRegistry.notifyFinished(this);
808 }
809 mAnimatingAppWindowTokenRegistry = stack != null
810 ? stack.getAnimatingAppWindowTokenRegistry()
811 : null;
812
Robert Carred3e83b2017-04-21 13:26:55 -0700813 mLastParent = task;
Bryce Lee6d410262017-02-28 15:30:17 -0800814 }
815
Wale Ogunwalefa854eb2016-09-20 13:43:52 -0700816 void postWindowRemoveStartingWindowCleanup(WindowState win) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700817 // TODO: Something smells about the code below...Is there a better way?
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700818 if (startingWindow == win) {
819 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800820 if (getController() != null) {
821 getController().removeStartingWindow();
822 }
Wale Ogunwale6c459212017-05-17 08:56:03 -0700823 } else if (mChildren.size() == 0) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700824 // If this is the last window and we had requested a starting transition window,
825 // well there is no point now.
Jorim Jaggi02886a82016-12-06 09:10:06 -0800826 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingData");
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700827 startingData = null;
Wale Ogunwale6c459212017-05-17 08:56:03 -0700828 if (mHiddenSetFromTransferredStartingWindow) {
829 // We set the hidden state to false for the token from a transferred starting window.
830 // We now reset it back to true since the starting window was the last window in the
831 // token.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200832 setHidden(true);
Wale Ogunwale6c459212017-05-17 08:56:03 -0700833 }
Jorim Jaggi829b9cd2017-01-23 16:20:53 +0100834 } else if (mChildren.size() == 1 && startingSurface != null && !isRelaunching()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700835 // If this is the last window except for a starting transition window,
836 // we need to get rid of the starting transition.
Jorim Jaggie4b0f282017-05-17 15:10:29 +0200837 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Last window, removing starting window "
838 + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800839 if (getController() != null) {
840 getController().removeStartingWindow();
841 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700842 }
843 }
844
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700845 void removeDeadWindows() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700846 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700847 WindowState win = mChildren.get(winNdx);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800848 if (win.mAppDied) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700849 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700850 "removeDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800851 // Set mDestroying, we don't want any animation or delayed removal here.
852 win.mDestroying = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700853 // Also removes child windows.
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700854 win.removeIfPossible();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800855 }
856 }
857 }
858
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700859 boolean hasWindowsAlive() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700860 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700861 // No need to loop through child windows as the answer should be the same as that of the
862 // parent window.
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700863 if (!(mChildren.get(i)).mAppDied) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700864 return true;
865 }
866 }
867 return false;
868 }
869
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700870 void setWillReplaceWindows(boolean animate) {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700871 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
872 "Marking app token " + this + " with replacing windows.");
Robert Carra1eb4392015-12-10 12:43:51 -0800873
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700874 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700875 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700876 w.setWillReplaceWindow(animate);
Robert Carra1eb4392015-12-10 12:43:51 -0800877 }
Robert Carra1eb4392015-12-10 12:43:51 -0800878 }
879
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700880 void setWillReplaceChildWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700881 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this
Robert Carr23fa16b2016-01-13 13:19:58 -0800882 + " with replacing child windows.");
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700883 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700884 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700885 w.setWillReplaceChildWindows();
Robert Carr23fa16b2016-01-13 13:19:58 -0800886 }
887 }
888
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700889 void clearWillReplaceWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700890 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
891 "Resetting app token " + this + " of replacing window marks.");
Chong Zhangf596cd52016-01-05 13:42:44 -0800892
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700893 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700894 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700895 w.clearWillReplaceWindow();
Chong Zhangf596cd52016-01-05 13:42:44 -0800896 }
897 }
898
Chong Zhang4d7369a2016-04-25 16:09:14 -0700899 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700900 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700901 final WindowState w = mChildren.get(i);
Chong Zhang4d7369a2016-04-25 16:09:14 -0700902 w.requestUpdateWallpaperIfNeeded();
903 }
904 }
905
Chong Zhangd78ddb42016-03-02 17:01:14 -0800906 boolean isRelaunching() {
907 return mPendingRelaunchCount > 0;
908 }
909
Robert Carr68375192017-06-13 12:41:53 -0700910 boolean shouldFreezeBounds() {
911 final Task task = getTask();
912
913 // For freeform windows, we can't freeze the bounds at the moment because this would make
914 // the resizing unresponsive.
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700915 if (task == null || task.inFreeformWindowingMode()) {
Robert Carr68375192017-06-13 12:41:53 -0700916 return false;
917 }
918
919 // We freeze the bounds while drag resizing to deal with the time between
920 // the divider/drag handle being released, and the handling it's new
921 // configuration. If we are relaunched outside of the drag resizing state,
922 // we need to be careful not to do this.
923 return getTask().isDragResizing();
924 }
925
Chong Zhangd78ddb42016-03-02 17:01:14 -0800926 void startRelaunching() {
Robert Carr68375192017-06-13 12:41:53 -0700927 if (shouldFreezeBounds()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -0800928 freezeBounds();
929 }
Robert Carrd5c7dd62017-03-08 10:39:30 -0800930
931 // In the process of tearing down before relaunching, the app will
932 // try and clean up it's child surfaces. We need to prevent this from
933 // happening, so we sever the children, transfering their ownership
934 // from the client it-self to the parent surface (owned by us).
Robert Carr29daa922018-04-27 11:56:48 -0700935 detachChildren();
936
937 mPendingRelaunchCount++;
938 }
939
940 void detachChildren() {
Robert Carrfd8e93b2018-05-10 13:40:25 -0700941 SurfaceControl.openTransaction();
Robert Carrd5c7dd62017-03-08 10:39:30 -0800942 for (int i = mChildren.size() - 1; i >= 0; i--) {
943 final WindowState w = mChildren.get(i);
944 w.mWinAnimator.detachChildren();
945 }
Robert Carrfd8e93b2018-05-10 13:40:25 -0700946 SurfaceControl.closeTransaction();
Chong Zhangd78ddb42016-03-02 17:01:14 -0800947 }
948
949 void finishRelaunching() {
Robert Carr68375192017-06-13 12:41:53 -0700950 unfreezeBounds();
951
Chong Zhangd78ddb42016-03-02 17:01:14 -0800952 if (mPendingRelaunchCount > 0) {
953 mPendingRelaunchCount--;
Bryce Lee081554b2017-05-25 07:52:12 -0700954 } else {
955 // Update keyguard flags upon finishing relaunch.
956 checkKeyguardFlagsChanged();
Chong Zhangd78ddb42016-03-02 17:01:14 -0800957 }
958 }
959
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700960 void clearRelaunching() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700961 if (mPendingRelaunchCount == 0) {
962 return;
963 }
Robert Carr68375192017-06-13 12:41:53 -0700964 unfreezeBounds();
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700965 mPendingRelaunchCount = 0;
966 }
967
Wale Ogunwale07bcab72016-10-14 15:30:09 -0700968 /**
969 * Returns true if the new child window we are adding to this token is considered greater than
970 * the existing child window in this token in terms of z-order.
971 */
972 @Override
973 protected boolean isFirstChildWindowGreaterThanSecond(WindowState newWindow,
974 WindowState existingWindow) {
975 final int type1 = newWindow.mAttrs.type;
976 final int type2 = existingWindow.mAttrs.type;
977
978 // Base application windows should be z-ordered BELOW all other windows in the app token.
979 if (type1 == TYPE_BASE_APPLICATION && type2 != TYPE_BASE_APPLICATION) {
980 return false;
981 } else if (type1 != TYPE_BASE_APPLICATION && type2 == TYPE_BASE_APPLICATION) {
982 return true;
983 }
984
985 // Starting windows should be z-ordered ABOVE all other windows in the app token.
986 if (type1 == TYPE_APPLICATION_STARTING && type2 != TYPE_APPLICATION_STARTING) {
987 return true;
988 } else if (type1 != TYPE_APPLICATION_STARTING && type2 == TYPE_APPLICATION_STARTING) {
989 return false;
990 }
991
992 // Otherwise the new window is greater than the existing window.
993 return true;
994 }
995
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700996 @Override
Robert Carra1eb4392015-12-10 12:43:51 -0800997 void addWindow(WindowState w) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700998 super.addWindow(w);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700999
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001000 boolean gotReplacementWindow = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001001 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001002 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001003 gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w);
1004 }
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001005
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001006 // if we got a replacement window, reset the timeout to give drawing more time
1007 if (gotReplacementWindow) {
1008 mService.scheduleWindowReplacementTimeouts(this);
Robert Carra1eb4392015-12-10 12:43:51 -08001009 }
Jorim Jaggife762342016-10-13 14:33:27 +02001010 checkKeyguardFlagsChanged();
1011 }
1012
1013 @Override
1014 void removeChild(WindowState child) {
1015 super.removeChild(child);
1016 checkKeyguardFlagsChanged();
Adrian Roos23df3a32018-03-15 15:41:13 +01001017 updateLetterboxSurface(child);
Robert Carra1eb4392015-12-10 12:43:51 -08001018 }
1019
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001020 private boolean waitingForReplacement() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001021 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001022 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001023 if (candidate.waitingForReplacement()) {
Robert Carra1eb4392015-12-10 12:43:51 -08001024 return true;
1025 }
1026 }
1027 return false;
1028 }
1029
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001030 void onWindowReplacementTimeout() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001031 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001032 (mChildren.get(i)).onWindowReplacementTimeout();
Robert Carra1eb4392015-12-10 12:43:51 -08001033 }
1034 }
1035
Winson Chung30480042017-01-26 10:55:34 -08001036 void reparent(Task task, int position) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001037 final Task currentTask = getTask();
1038 if (task == currentTask) {
Winson Chung30480042017-01-26 10:55:34 -08001039 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001040 "window token=" + this + " already child of task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -08001041 }
Bryce Lee6d410262017-02-28 15:30:17 -08001042
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001043 if (currentTask.mStack != task.mStack) {
Bryce Lee6d410262017-02-28 15:30:17 -08001044 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001045 "window token=" + this + " current task=" + currentTask
Bryce Lee6d410262017-02-28 15:30:17 -08001046 + " belongs to a different stack than " + task);
1047 }
1048
Winson Chung30480042017-01-26 10:55:34 -08001049 if (DEBUG_ADD_REMOVE) Slog.i(TAG, "reParentWindowToken: removing window token=" + this
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001050 + " from task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -08001051 final DisplayContent prevDisplayContent = getDisplayContent();
1052
Bryce Lee6d410262017-02-28 15:30:17 -08001053 mReparenting = true;
1054
Winson Chung30480042017-01-26 10:55:34 -08001055 getParent().removeChild(this);
1056 task.addChild(this, position);
1057
Bryce Lee6d410262017-02-28 15:30:17 -08001058 mReparenting = false;
1059
Winson Chung30480042017-01-26 10:55:34 -08001060 // Relayout display(s).
1061 final DisplayContent displayContent = task.getDisplayContent();
1062 displayContent.setLayoutNeeded();
1063 if (prevDisplayContent != displayContent) {
1064 onDisplayChanged(displayContent);
1065 prevDisplayContent.setLayoutNeeded();
1066 }
1067 }
1068
Tiger Huang1e5b10a2018-07-30 20:19:51 +08001069 @Override
1070 void onDisplayChanged(DisplayContent dc) {
1071 DisplayContent prevDc = mDisplayContent;
1072 super.onDisplayChanged(dc);
1073 if (prevDc != null && prevDc.mFocusedApp == this) {
1074 prevDc.setFocusedApp(null);
1075 if (dc.getTopStack().getTopChild().getTopChild() == this) {
1076 dc.setFocusedApp(this);
1077 }
1078 }
1079 }
1080
Jorim Jaggi0429f352015-12-22 16:29:16 +01001081 /**
1082 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
1083 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
1084 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
1085 * with a queue.
1086 */
Chong Zhangd78ddb42016-03-02 17:01:14 -08001087 private void freezeBounds() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001088 final Task task = getTask();
1089 mFrozenBounds.offer(new Rect(task.mPreparedFrozenBounds));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001090
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001091 if (task.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) {
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001092 // We didn't call prepareFreezingBounds on the task, so use the current value.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001093 mFrozenMergedConfig.offer(new Configuration(task.getConfiguration()));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001094 } else {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001095 mFrozenMergedConfig.offer(new Configuration(task.mPreparedFrozenMergedConfig));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001096 }
Andrii Kulianb10330d2016-09-16 13:51:46 -07001097 // Calling unset() to make it equal to Configuration.EMPTY.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001098 task.mPreparedFrozenMergedConfig.unset();
Jorim Jaggi0429f352015-12-22 16:29:16 +01001099 }
1100
1101 /**
1102 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
1103 */
Chong Zhangd78ddb42016-03-02 17:01:14 -08001104 private void unfreezeBounds() {
Robert Carr68375192017-06-13 12:41:53 -07001105 if (mFrozenBounds.isEmpty()) {
1106 return;
Wale Ogunwale37dbafc2016-06-27 10:15:20 -07001107 }
Robert Carr68375192017-06-13 12:41:53 -07001108 mFrozenBounds.remove();
Wale Ogunwale37dbafc2016-06-27 10:15:20 -07001109 if (!mFrozenMergedConfig.isEmpty()) {
1110 mFrozenMergedConfig.remove();
1111 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001112 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001113 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001114 win.onUnfreezeBounds();
Jorim Jaggi4846ee32016-01-07 17:39:12 +01001115 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001116 mService.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +01001117 }
1118
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001119 void setAppLayoutChanges(int changes, String reason) {
1120 if (!mChildren.isEmpty()) {
1121 final DisplayContent dc = getDisplayContent();
1122 dc.pendingLayoutChanges |= changes;
1123 if (DEBUG_LAYOUT_REPEATS) {
1124 mService.mWindowPlacerLocked.debugLayoutRepeats(reason, dc.pendingLayoutChanges);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001125 }
1126 }
1127 }
1128
1129 void removeReplacedWindowIfNeeded(WindowState replacement) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001130 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001131 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001132 if (win.removeReplacedWindowIfNeeded(replacement)) {
1133 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001134 }
1135 }
1136 }
1137
1138 void startFreezingScreen() {
1139 if (DEBUG_ORIENTATION) logWithStack(TAG, "Set freezing of " + appToken + ": hidden="
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001140 + isHidden() + " freezing=" + mFreezingScreen + " hiddenRequested="
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001141 + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001142 if (!hiddenRequested) {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001143 if (!mFreezingScreen) {
1144 mFreezingScreen = true;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001145 mService.registerAppFreezeListener(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001146 mService.mAppsFreezingScreen++;
1147 if (mService.mAppsFreezingScreen == 1) {
Robert Carrae606b42018-02-15 15:36:23 -08001148 mService.startFreezingDisplayLocked(0, 0, getDisplayContent());
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001149 mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT);
1150 mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001151 }
1152 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001153 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001154 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 w.onStartFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001157 }
1158 }
1159 }
1160
1161 void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001162 if (!mFreezingScreen) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001163 return;
1164 }
1165 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + this + " force=" + force);
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001166 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001167 boolean unfrozeWindows = false;
1168 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001169 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001170 unfrozeWindows |= w.onStopFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001171 }
1172 if (force || unfrozeWindows) {
1173 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this);
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001174 mFreezingScreen = false;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001175 mService.unregisterAppFreezeListener(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001176 mService.mAppsFreezingScreen--;
1177 mService.mLastFinishedFreezeSource = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001178 }
1179 if (unfreezeSurfaceNow) {
1180 if (unfrozeWindows) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001181 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001182 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001183 mService.stopFreezingDisplayLocked();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001184 }
1185 }
1186
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001187 @Override
1188 public void onAppFreezeTimeout() {
1189 Slog.w(TAG_WM, "Force clearing freeze: " + this);
1190 stopFreezingScreen(true, true);
1191 }
1192
Jorim Jaggi60f9c972018-02-01 19:21:07 +01001193 /**
1194 * Tries to transfer the starting window from a token that's above ourselves in the task but
1195 * not visible anymore. This is a common scenario apps use: Trampoline activity T start main
1196 * activity M in the same task. Now, when reopening the task, T starts on top of M but then
1197 * immediately finishes after, so we have to transfer T to M.
1198 */
1199 void transferStartingWindowFromHiddenAboveTokenIfNeeded() {
1200 final Task task = getTask();
1201 for (int i = task.mChildren.size() - 1; i >= 0; i--) {
1202 final AppWindowToken fromToken = task.mChildren.get(i);
1203 if (fromToken == this) {
1204 return;
1205 }
1206 if (fromToken.hiddenRequested && transferStartingWindow(fromToken.token)) {
1207 return;
1208 }
1209 }
1210 }
1211
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001212 boolean transferStartingWindow(IBinder transferFrom) {
Wale Ogunwale02319a62016-09-26 15:21:22 -07001213 final AppWindowToken fromToken = getDisplayContent().getAppWindowToken(transferFrom);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001214 if (fromToken == null) {
1215 return false;
1216 }
1217
1218 final WindowState tStartingWindow = fromToken.startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001219 if (tStartingWindow != null && fromToken.startingSurface != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001220 // In this case, the starting icon has already been displayed, so start
1221 // letting windows get shown immediately without any more transitions.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001222 mService.mSkipAppTransitionAnimation = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001223
1224 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow
1225 + " from " + fromToken + " to " + this);
1226
1227 final long origId = Binder.clearCallingIdentity();
Peter Visontay3556a3b2017-11-01 17:23:17 +00001228 try {
1229 // Transfer the starting window over to the new token.
1230 startingData = fromToken.startingData;
1231 startingSurface = fromToken.startingSurface;
1232 startingDisplayed = fromToken.startingDisplayed;
1233 fromToken.startingDisplayed = false;
1234 startingWindow = tStartingWindow;
1235 reportedVisible = fromToken.reportedVisible;
1236 fromToken.startingData = null;
1237 fromToken.startingSurface = null;
1238 fromToken.startingWindow = null;
1239 fromToken.startingMoved = true;
1240 tStartingWindow.mToken = this;
1241 tStartingWindow.mAppToken = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001242
Peter Visontay3556a3b2017-11-01 17:23:17 +00001243 if (DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1244 "Removing starting " + tStartingWindow + " from " + fromToken);
1245 fromToken.removeChild(tStartingWindow);
1246 fromToken.postWindowRemoveStartingWindowCleanup(tStartingWindow);
1247 fromToken.mHiddenSetFromTransferredStartingWindow = false;
1248 addWindow(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001249
Peter Visontay3556a3b2017-11-01 17:23:17 +00001250 // Propagate other interesting state between the tokens. If the old token is displayed,
1251 // we should immediately force the new one to be displayed. If it is animating, we need
1252 // to move that animation to the new one.
1253 if (fromToken.allDrawn) {
1254 allDrawn = true;
1255 deferClearAllDrawn = fromToken.deferClearAllDrawn;
1256 }
1257 if (fromToken.firstWindowDrawn) {
1258 firstWindowDrawn = true;
1259 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001260 if (!fromToken.isHidden()) {
1261 setHidden(false);
Peter Visontay3556a3b2017-11-01 17:23:17 +00001262 hiddenRequested = false;
1263 mHiddenSetFromTransferredStartingWindow = true;
1264 }
1265 setClientHidden(fromToken.mClientHidden);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001266
Jorim Jaggi980c9de2017-11-17 01:41:37 +01001267 transferAnimation(fromToken);
1268
1269 // When transferring an animation, we no longer need to apply an animation to the
1270 // the token we transfer the animation over. Thus, remove the animation from
1271 // pending opening apps.
1272 mService.mOpeningApps.remove(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001273
Peter Visontay3556a3b2017-11-01 17:23:17 +00001274 mService.updateFocusedWindowLocked(
1275 UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/);
1276 getDisplayContent().setLayoutNeeded();
1277 mService.mWindowPlacerLocked.performSurfacePlacement();
1278 } finally {
1279 Binder.restoreCallingIdentity(origId);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001280 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001281 return true;
1282 } else if (fromToken.startingData != null) {
1283 // The previous app was getting ready to show a
1284 // starting window, but hasn't yet done so. Steal it!
1285 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1286 "Moving pending starting from " + fromToken + " to " + this);
1287 startingData = fromToken.startingData;
1288 fromToken.startingData = null;
1289 fromToken.startingMoved = true;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001290 if (getController() != null) {
1291 getController().scheduleAddStartingWindow();
1292 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001293 return true;
1294 }
1295
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001296 // TODO: Transfer thumbnail
1297
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001298 return false;
1299 }
1300
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001301 boolean isLastWindow(WindowState win) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001302 return mChildren.size() == 1 && mChildren.get(0) == win;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001303 }
1304
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001305 @Override
1306 void onAppTransitionDone() {
1307 sendingToBottom = false;
1308 }
1309
Wale Ogunwale51362492016-09-08 17:49:17 -07001310 /**
1311 * We override because this class doesn't want its children affecting its reported orientation
1312 * in anyway.
1313 */
1314 @Override
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001315 int getOrientation(int candidate) {
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001316 if (candidate == SCREEN_ORIENTATION_BEHIND) {
1317 // Allow app to specify orientation regardless of its visibility state if the current
1318 // candidate want us to use orientation behind. I.e. the visible app on-top of this one
1319 // wants us to use the orientation of the app behind it.
1320 return mOrientation;
1321 }
1322
Bryce Lee61fbcbc2017-03-10 14:14:03 -08001323 // The {@link AppWindowToken} should only specify an orientation when it is not closing or
1324 // going to the bottom. Allowing closing {@link AppWindowToken} to participate can lead to
1325 // an Activity in another task being started in the wrong orientation during the transition.
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001326 if (!(sendingToBottom || mService.mClosingApps.contains(this))
Andrii Kulian0918d362018-05-23 17:01:37 -07001327 && (isVisible() || mService.mOpeningApps.contains(this))) {
Bryce Leea163b762017-01-24 11:05:01 -08001328 return mOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001329 }
Bryce Leea163b762017-01-24 11:05:01 -08001330
1331 return SCREEN_ORIENTATION_UNSET;
Wale Ogunwale51362492016-09-08 17:49:17 -07001332 }
1333
Wale Ogunwaleb198b742016-12-01 08:44:09 -08001334 /** Returns the app's preferred orientation regardless of its currently visibility state. */
1335 int getOrientationIgnoreVisibility() {
1336 return mOrientation;
1337 }
1338
Craig Mautnerdbb79912012-03-01 18:59:14 -08001339 @Override
Winson Chunge55c0192017-08-24 14:50:48 -07001340 public void onConfigurationChanged(Configuration newParentConfig) {
1341 final int prevWinMode = getWindowingMode();
1342 super.onConfigurationChanged(newParentConfig);
1343 final int winMode = getWindowingMode();
1344
1345 if (prevWinMode == winMode) {
1346 return;
1347 }
1348
1349 if (prevWinMode != WINDOWING_MODE_UNDEFINED && winMode == WINDOWING_MODE_PINNED) {
1350 // Entering PiP from fullscreen, reset the snap fraction
1351 mDisplayContent.mPinnedStackControllerLocked.resetReentrySnapFraction(this);
Winson Chung82267ce2018-04-06 16:38:26 -07001352 } else if (prevWinMode == WINDOWING_MODE_PINNED && winMode != WINDOWING_MODE_UNDEFINED
1353 && !isHidden()) {
Winson Chunge55c0192017-08-24 14:50:48 -07001354 // Leaving PiP to fullscreen, save the snap fraction based on the pre-animation bounds
1355 // for the next re-entry into PiP (assuming the activity is not hidden or destroyed)
1356 final TaskStack pinnedStack = mDisplayContent.getPinnedStack();
1357 if (pinnedStack != null) {
Winson Chung8efa1652018-06-06 09:34:23 -07001358 final Rect stackBounds;
1359 if (pinnedStack.lastAnimatingBoundsWasToFullscreen()) {
1360 // We are animating the bounds, use the pre-animation bounds to save the snap
1361 // fraction
1362 stackBounds = pinnedStack.mPreAnimationBounds;
1363 } else {
1364 // We skip the animation if the fullscreen configuration is not compatible, so
1365 // use the current bounds to calculate the saved snap fraction instead
1366 // (see PinnedActivityStack.skipResizeAnimation())
1367 stackBounds = mTmpRect;
1368 pinnedStack.getBounds(stackBounds);
1369 }
Winson Chunge55c0192017-08-24 14:50:48 -07001370 mDisplayContent.mPinnedStackControllerLocked.saveReentrySnapFraction(this,
Winson Chung8efa1652018-06-06 09:34:23 -07001371 stackBounds);
Winson Chunge55c0192017-08-24 14:50:48 -07001372 }
1373 }
1374 }
1375
1376 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001377 void checkAppWindowsReadyToShow() {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001378 if (allDrawn == mLastAllDrawn) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001379 return;
1380 }
1381
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001382 mLastAllDrawn = allDrawn;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001383 if (!allDrawn) {
1384 return;
1385 }
1386
1387 // The token has now changed state to having all windows shown... what to do, what to do?
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001388 if (mFreezingScreen) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001389 showAllWindowsLocked();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001390 stopFreezingScreen(false, true);
1391 if (DEBUG_ORIENTATION) Slog.i(TAG,
1392 "Setting mOrientationChangeComplete=true because wtoken " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001393 + " numInteresting=" + mNumInterestingWindows + " numDrawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001394 // This will set mOrientationChangeComplete and cause a pass through layout.
1395 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001396 "checkAppWindowsReadyToShow: freezingScreen");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001397 } else {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001398 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001399
1400 // We can now show all of the drawn windows!
Jorim Jaggiaf0d6d22018-06-08 15:25:35 +02001401 if (!mService.mOpeningApps.contains(this) && canShowWindows()) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001402 showAllWindowsLocked();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001403 }
1404 }
1405 }
1406
Matthew Ng5d23afa2017-06-21 16:16:24 -07001407 /**
Bryce Leed390deb2017-06-22 13:14:28 -07001408 * Returns whether the drawn window states of this {@link AppWindowToken} has considered every
1409 * child {@link WindowState}. A child is considered if it has been passed into
1410 * {@link #updateDrawnWindowStates(WindowState)} after being added. This is used to determine
1411 * whether states, such as {@code allDrawn}, can be set, which relies on state variables such as
1412 * {@code mNumInterestingWindows}, which depend on all {@link WindowState}s being considered.
1413 *
1414 * @return {@code true} If all children have been considered, {@code false}.
1415 */
1416 private boolean allDrawnStatesConsidered() {
Bryce Lee6311c4b2017-07-06 14:09:29 -07001417 for (int i = mChildren.size() - 1; i >= 0; --i) {
1418 final WindowState child = mChildren.get(i);
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001419 if (child.mightAffectAllDrawn() && !child.getDrawnStateEvaluated()) {
Bryce Leed390deb2017-06-22 13:14:28 -07001420 return false;
1421 }
1422 }
1423 return true;
1424 }
1425
1426 /**
Matthew Ng5d23afa2017-06-21 16:16:24 -07001427 * Determines if the token has finished drawing. This should only be called from
1428 * {@link DisplayContent#applySurfaceChangesTransaction}
1429 */
Matthew Ng498c71d2017-04-18 13:55:45 -07001430 void updateAllDrawn() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001431 if (!allDrawn) {
Matthew Ng498c71d2017-04-18 13:55:45 -07001432 // Number of drawn windows can be less when a window is being relaunched, wait for
Bryce Leed390deb2017-06-22 13:14:28 -07001433 // all windows to be launched and drawn for this token be considered all drawn.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001434 final int numInteresting = mNumInterestingWindows;
Bryce Leed390deb2017-06-22 13:14:28 -07001435
1436 // We must make sure that all present children have been considered (determined by
1437 // {@link #allDrawnStatesConsidered}) before evaluating whether everything has been
1438 // drawn.
1439 if (numInteresting > 0 && allDrawnStatesConsidered()
1440 && mNumDrawnWindows >= numInteresting && !isRelaunching()) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001441 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawn: " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001442 + " interesting=" + numInteresting + " drawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001443 allDrawn = true;
1444 // Force an additional layout pass where
1445 // WindowStateAnimator#commitFinishDrawingLocked() will call performShowLocked().
Matthew Ng498c71d2017-04-18 13:55:45 -07001446 if (mDisplayContent != null) {
1447 mDisplayContent.setLayoutNeeded();
1448 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001449 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Robert Carrecc06b32017-04-18 14:25:10 -07001450
Winson Chunge7ba6862017-05-24 12:13:33 -07001451 // Notify the pinned stack upon all windows drawn. If there was an animation in
1452 // progress then this signal will resume that animation.
Wale Ogunwale61911492017-10-11 08:50:50 -07001453 final TaskStack pinnedStack = mDisplayContent.getPinnedStack();
Winson Chunge7ba6862017-05-24 12:13:33 -07001454 if (pinnedStack != null) {
1455 pinnedStack.onAllWindowsDrawn();
Robert Carrecc06b32017-04-18 14:25:10 -07001456 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001457 }
1458 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001459 }
1460
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001461 /**
1462 * Updated this app token tracking states for interesting and drawn windows based on the window.
1463 *
1464 * @return Returns true if the input window is considered interesting and drawn while all the
1465 * windows in this app token where not considered drawn as of the last pass.
1466 */
1467 boolean updateDrawnWindowStates(WindowState w) {
Bryce Leed390deb2017-06-22 13:14:28 -07001468 w.setDrawnStateEvaluated(true /*evaluated*/);
1469
Jorim Jaggie4b0f282017-05-17 15:10:29 +02001470 if (DEBUG_STARTING_WINDOW_VERBOSE && w == startingWindow) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001471 Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" + w.isOnScreen()
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001472 + " allDrawn=" + allDrawn + " freezingScreen=" + mFreezingScreen);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001473 }
1474
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001475 if (allDrawn && !mFreezingScreen) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001476 return false;
1477 }
1478
1479 if (mLastTransactionSequence != mService.mTransactionSequence) {
1480 mLastTransactionSequence = mService.mTransactionSequence;
Matthew Ng53e66b22018-01-12 17:13:13 -08001481 mNumDrawnWindows = 0;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001482 startingDisplayed = false;
Matthew Ng53e66b22018-01-12 17:13:13 -08001483
1484 // There is the main base application window, even if it is exiting, wait for it
1485 mNumInterestingWindows = findMainWindow(false /* includeStartingApp */) != null ? 1 : 0;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001486 }
1487
1488 final WindowStateAnimator winAnimator = w.mWinAnimator;
1489
1490 boolean isInterestingAndDrawn = false;
1491
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001492 if (!allDrawn && w.mightAffectAllDrawn()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001493 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
1494 Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw()
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001495 + ", isAnimationSet=" + isSelfAnimating());
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001496 if (!w.isDrawnLw()) {
1497 Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController
1498 + " pv=" + w.mPolicyVisibility
1499 + " mDrawState=" + winAnimator.drawStateToString()
1500 + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001501 + " a=" + isSelfAnimating());
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001502 }
1503 }
1504
1505 if (w != startingWindow) {
1506 if (w.isInteresting()) {
Matthew Ng53e66b22018-01-12 17:13:13 -08001507 // Add non-main window as interesting since the main app has already been added
1508 if (findMainWindow(false /* includeStartingApp */) != w) {
1509 mNumInterestingWindows++;
1510 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001511 if (w.isDrawnLw()) {
1512 mNumDrawnWindows++;
1513
1514 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, "tokenMayBeDrawn: "
1515 + this + " w=" + w + " numInteresting=" + mNumInterestingWindows
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001516 + " freezingScreen=" + mFreezingScreen
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001517 + " mAppFreezing=" + w.mAppFreezing);
1518
1519 isInterestingAndDrawn = true;
1520 }
1521 }
1522 } else if (w.isDrawnLw()) {
Jorim Jaggi3878ca32017-02-02 17:13:05 -08001523 if (getController() != null) {
1524 getController().reportStartingWindowDrawn();
1525 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001526 startingDisplayed = true;
1527 }
1528 }
1529
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001530 return isInterestingAndDrawn;
1531 }
1532
Adrian Roos23df3a32018-03-15 15:41:13 +01001533 void layoutLetterbox(WindowState winHint) {
Adrian Roos4d18a2e2017-12-19 19:08:05 +01001534 final WindowState w = findMainWindow();
Adrian Roosf93b6d22018-03-21 13:48:26 +01001535 if (w == null || winHint != null && w != winHint) {
Adrian Roos4d18a2e2017-12-19 19:08:05 +01001536 return;
1537 }
Jorim Jaggia32da382018-03-28 18:01:22 +02001538 final boolean surfaceReady = w.isDrawnLw() // Regular case
Adrian Roosf93b6d22018-03-21 13:48:26 +01001539 || w.mWinAnimator.mSurfaceDestroyDeferred // The preserved surface is still ready.
1540 || w.isDragResizeChanged(); // Waiting for relayoutWindow to call preserveSurface.
1541 final boolean needsLetterbox = w.isLetterboxedAppWindow() && fillsParent() && surfaceReady;
Adrian Roos4d18a2e2017-12-19 19:08:05 +01001542 if (needsLetterbox) {
1543 if (mLetterbox == null) {
1544 mLetterbox = new Letterbox(() -> makeChildSurface(null));
1545 }
chaviw492139a2018-07-16 16:07:35 -07001546 mLetterbox.layout(getParent().getBounds(), w.getFrameLw());
Adrian Roos4d18a2e2017-12-19 19:08:05 +01001547 } else if (mLetterbox != null) {
Adrian Roos23df3a32018-03-15 15:41:13 +01001548 mLetterbox.hide();
1549 }
1550 }
1551
1552 void updateLetterboxSurface(WindowState winHint) {
1553 final WindowState w = findMainWindow();
1554 if (w != winHint && winHint != null && w != null) {
1555 return;
1556 }
1557 layoutLetterbox(winHint);
1558 if (mLetterbox != null && mLetterbox.needsApplySurfaceChanges()) {
1559 mLetterbox.applySurfaceChanges(mPendingTransaction);
Adrian Roos4d18a2e2017-12-19 19:08:05 +01001560 }
1561 }
1562
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001563 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001564 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001565 // For legacy reasons we process the TaskStack.mExitingAppTokens first in DisplayContent
1566 // before the non-exiting app tokens. So, we skip the exiting app tokens here.
1567 // TODO: Investigate if we need to continue to do this or if we can just process them
1568 // in-order.
1569 if (mIsExiting && !waitingForReplacement()) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001570 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001571 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001572 return forAllWindowsUnchecked(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001573 }
1574
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001575 boolean forAllWindowsUnchecked(ToBooleanFunction<WindowState> callback,
1576 boolean traverseTopToBottom) {
1577 return super.forAllWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001578 }
1579
1580 @Override
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001581 AppWindowToken asAppWindowToken() {
1582 // I am an app window token!
1583 return this;
1584 }
1585
1586 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -07001587 boolean fillsParent() {
1588 return mFillsParent;
1589 }
1590
1591 void setFillsParent(boolean fillsParent) {
1592 mFillsParent = fillsParent;
1593 }
1594
Jorim Jaggife762342016-10-13 14:33:27 +02001595 boolean containsDismissKeyguardWindow() {
Bryce Lee081554b2017-05-25 07:52:12 -07001596 // Window state is transient during relaunch. We are not guaranteed to be frozen during the
1597 // entirety of the relaunch.
1598 if (isRelaunching()) {
1599 return mLastContainsDismissKeyguardWindow;
1600 }
1601
Jorim Jaggife762342016-10-13 14:33:27 +02001602 for (int i = mChildren.size() - 1; i >= 0; i--) {
1603 if ((mChildren.get(i).mAttrs.flags & FLAG_DISMISS_KEYGUARD) != 0) {
1604 return true;
1605 }
1606 }
1607 return false;
1608 }
1609
1610 boolean containsShowWhenLockedWindow() {
Bryce Lee081554b2017-05-25 07:52:12 -07001611 // When we are relaunching, it is possible for us to be unfrozen before our previous
1612 // windows have been added back. Using the cached value ensures that our previous
1613 // showWhenLocked preference is honored until relaunching is complete.
1614 if (isRelaunching()) {
1615 return mLastContainsShowWhenLockedWindow;
1616 }
1617
Jorim Jaggife762342016-10-13 14:33:27 +02001618 for (int i = mChildren.size() - 1; i >= 0; i--) {
1619 if ((mChildren.get(i).mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
1620 return true;
1621 }
1622 }
Bryce Lee081554b2017-05-25 07:52:12 -07001623
Jorim Jaggife762342016-10-13 14:33:27 +02001624 return false;
1625 }
1626
1627 void checkKeyguardFlagsChanged() {
1628 final boolean containsDismissKeyguard = containsDismissKeyguardWindow();
1629 final boolean containsShowWhenLocked = containsShowWhenLockedWindow();
1630 if (containsDismissKeyguard != mLastContainsDismissKeyguardWindow
1631 || containsShowWhenLocked != mLastContainsShowWhenLockedWindow) {
1632 mService.notifyKeyguardFlagsChanged(null /* callback */);
1633 }
1634 mLastContainsDismissKeyguardWindow = containsDismissKeyguard;
1635 mLastContainsShowWhenLockedWindow = containsShowWhenLocked;
1636 }
1637
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001638 WindowState getImeTargetBelowWindow(WindowState w) {
1639 final int index = mChildren.indexOf(w);
1640 if (index > 0) {
1641 final WindowState target = mChildren.get(index - 1);
1642 if (target.canBeImeTarget()) {
1643 return target;
1644 }
1645 }
1646 return null;
1647 }
1648
1649 WindowState getHighestAnimLayerWindow(WindowState currentTarget) {
1650 WindowState candidate = null;
1651 for (int i = mChildren.indexOf(currentTarget); i >= 0; i--) {
1652 final WindowState w = mChildren.get(i);
1653 if (w.mRemoved) {
1654 continue;
1655 }
Jorim Jaggi35d328a2018-08-14 17:00:20 +02001656 if (candidate == null) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001657 candidate = w;
1658 }
1659 }
1660 return candidate;
1661 }
1662
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001663 /**
1664 * See {@link Activity#setDisablePreviewScreenshots}.
1665 */
1666 void setDisablePreviewScreenshots(boolean disable) {
Wale Ogunwale6c459212017-05-17 08:56:03 -07001667 mDisablePreviewScreenshots = disable;
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001668 }
1669
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001670 /**
chaviwd3bf08d2017-08-01 17:24:59 -07001671 * Sets whether the current launch can turn the screen on. See {@link #canTurnScreenOn()}
1672 */
1673 void setCanTurnScreenOn(boolean canTurnScreenOn) {
1674 mCanTurnScreenOn = canTurnScreenOn;
1675 }
1676
1677 /**
1678 * Indicates whether the current launch can turn the screen on. This is to prevent multiple
1679 * relayouts from turning the screen back on. The screen should only turn on at most
1680 * once per activity resume.
1681 *
1682 * @return true if the screen can be turned on.
1683 */
1684 boolean canTurnScreenOn() {
1685 return mCanTurnScreenOn;
1686 }
1687
1688 /**
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001689 * Retrieves whether we'd like to generate a snapshot that's based solely on the theme. This is
1690 * the case when preview screenshots are disabled {@link #setDisablePreviewScreenshots} or when
1691 * we can't take a snapshot for other reasons, for example, if we have a secure window.
1692 *
1693 * @return True if we need to generate an app theme snapshot, false if we'd like to take a real
1694 * screenshot.
1695 */
1696 boolean shouldUseAppThemeSnapshot() {
Wale Ogunwale6c459212017-05-17 08:56:03 -07001697 return mDisablePreviewScreenshots || forAllWindows(w -> (w.mAttrs.flags & FLAG_SECURE) != 0,
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001698 true /* topToBottom */);
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001699 }
1700
Jorim Jaggibe418292018-03-26 16:14:12 +02001701 SurfaceControl getAppAnimationLayer() {
Jorim Jaggi391790622018-04-18 15:30:44 +02001702 return getAppAnimationLayer(isActivityTypeHome() ? ANIMATION_LAYER_HOME
1703 : needsZBoost() ? ANIMATION_LAYER_BOOSTED
1704 : ANIMATION_LAYER_STANDARD);
Jorim Jaggibe418292018-03-26 16:14:12 +02001705 }
1706
chaviw23ee71c2017-12-18 11:29:41 -08001707 @Override
Jorim Jaggi596a1992017-12-29 14:48:02 +01001708 public SurfaceControl getAnimationLeashParent() {
Robert Carrb9506032018-02-13 13:54:00 -08001709 // All normal app transitions take place in an animation layer which is below the pinned
1710 // stack but may be above the parent stacks of the given animating apps.
1711 // For transitions in the pinned stack (menu activity) we just let them occur as a child
1712 // of the pinned stack.
1713 if (!inPinnedWindowingMode()) {
1714 return getAppAnimationLayer();
1715 } else {
1716 return getStack().getSurfaceControl();
1717 }
chaviw23ee71c2017-12-18 11:29:41 -08001718 }
1719
Jorim Jaggic6976f02018-04-18 16:31:07 +02001720 private boolean shouldAnimate(int transit) {
1721 final boolean isSplitScreenPrimary =
1722 getWindowingMode() == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY;
1723 final boolean allowSplitScreenPrimaryAnimation = transit != TRANSIT_WALLPAPER_OPEN;
1724
1725 // We animate always if it's not split screen primary, and only some special cases in split
1726 // screen primary because it causes issues with stack clipping when we run an un-minimize
1727 // animation at the same time.
1728 return !isSplitScreenPrimary || allowSplitScreenPrimaryAnimation;
1729 }
1730
Vishnu Naira2977262018-07-26 13:31:26 -07001731 /**
1732 * Creates a layer to apply crop to an animation.
1733 */
1734 private SurfaceControl createAnimationBoundsLayer(Transaction t) {
1735 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.i(TAG, "Creating animation bounds layer");
1736 final SurfaceControl.Builder builder = makeAnimationLeash()
1737 .setParent(getAnimationLeashParent())
1738 .setName(getSurfaceControl() + " - animation-bounds")
1739 .setSize(getSurfaceWidth(), getSurfaceHeight());
1740 final SurfaceControl boundsLayer = builder.build();
1741 t.show(boundsLayer);
1742 return boundsLayer;
1743 }
1744
Riddle Hsua118b3a2018-10-11 22:05:06 +08001745 /** Get position and crop region of animation. */
1746 @VisibleForTesting
1747 void getAnimationBounds(Point outPosition, Rect outBounds) {
1748 outPosition.set(0, 0);
1749 outBounds.setEmpty();
1750
1751 final TaskStack stack = getStack();
1752 final Task task = getTask();
1753 if (task != null && task.inFreeformWindowingMode()) {
1754 task.getRelativePosition(outPosition);
1755 } else if (stack != null) {
1756 stack.getRelativePosition(outPosition);
1757 }
1758
1759 // Always use stack bounds in order to have the ability to animate outside the task region.
1760 // It also needs to be consistent when {@link #mNeedsAnimationBoundsLayer} is set that crops
1761 // according to the bounds.
1762 if (stack != null) {
1763 stack.getBounds(outBounds);
1764 }
1765 // We have the relative position so the local position can be removed from bounds.
1766 outBounds.offsetTo(0, 0);
1767 }
1768
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001769 boolean applyAnimationLocked(WindowManager.LayoutParams lp, int transit, boolean enter,
1770 boolean isVoiceInteraction) {
1771
Jorim Jaggic6976f02018-04-18 16:31:07 +02001772 if (mService.mDisableTransitionAnimation || !shouldAnimate(transit)) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001773 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
Jorim Jaggic6976f02018-04-18 16:31:07 +02001774 Slog.v(TAG_WM, "applyAnimation: transition animation is disabled or skipped."
1775 + " atoken=" + this);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001776 }
1777 cancelAnimation();
1778 return false;
1779 }
1780
1781 // Only apply an animation if the display isn't frozen. If it is frozen, there is no reason
1782 // to animate and it can cause strange artifacts when we unfreeze the display if some
1783 // different animation is running.
1784 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "AWT#applyAnimationLocked");
1785 if (okToAnimate()) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001786 final AnimationAdapter adapter;
Riddle Hsua118b3a2018-10-11 22:05:06 +08001787 getAnimationBounds(mTmpPoint, mTmpRect);
Jorim Jaggic4d29f22018-03-22 16:30:56 +01001788
1789 // Delaying animation start isn't compatible with remote animations at all.
1790 if (mService.mAppTransition.getRemoteAnimationController() != null
1791 && !mSurfaceAnimator.isAnimationStartDelayed()) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001792 adapter = mService.mAppTransition.getRemoteAnimationController()
1793 .createAnimationAdapter(this, mTmpPoint, mTmpRect);
1794 } else {
Vishnu Naira2977262018-07-26 13:31:26 -07001795 final int appStackClipMode = mService.mAppTransition.getAppStackClipMode();
1796 mNeedsAnimationBoundsLayer = (appStackClipMode == STACK_CLIP_AFTER_ANIM);
1797
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001798 final Animation a = loadAnimation(lp, transit, enter, isVoiceInteraction);
1799 if (a != null) {
1800 adapter = new LocalAnimationAdapter(
1801 new WindowAnimationSpec(a, mTmpPoint, mTmpRect,
1802 mService.mAppTransition.canSkipFirstFrame(),
Vishnu Naira2977262018-07-26 13:31:26 -07001803 appStackClipMode,
Jorim Jaggiaa763cd2018-03-22 23:20:36 +01001804 true /* isAppAnimation */),
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001805 mService.mSurfaceAnimationRunner);
1806 if (a.getZAdjustment() == Animation.ZORDER_TOP) {
1807 mNeedsZBoost = true;
1808 }
1809 mTransit = transit;
1810 mTransitFlags = mService.mAppTransition.getTransitFlags();
1811 } else {
1812 adapter = null;
chaviw23ee71c2017-12-18 11:29:41 -08001813 }
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001814 }
1815 if (adapter != null) {
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001816 startAnimation(getPendingTransaction(), adapter, !isVisible());
Jorim Jaggi82c17862018-02-21 17:50:18 +01001817 if (adapter.getShowWallpaper()) {
1818 mDisplayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
1819 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001820 }
1821 } else {
1822 cancelAnimation();
1823 }
1824 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
1825
1826 return isReallyAnimating();
1827 }
1828
1829 private Animation loadAnimation(WindowManager.LayoutParams lp, int transit, boolean enter,
1830 boolean isVoiceInteraction) {
1831 final DisplayContent displayContent = getTask().getDisplayContent();
1832 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
1833 final int width = displayInfo.appWidth;
1834 final int height = displayInfo.appHeight;
1835 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG_WM,
1836 "applyAnimation: atoken=" + this);
1837
1838 // Determine the visible rect to calculate the thumbnail clip
1839 final WindowState win = findMainWindow();
1840 final Rect frame = new Rect(0, 0, width, height);
1841 final Rect displayFrame = new Rect(0, 0,
1842 displayInfo.logicalWidth, displayInfo.logicalHeight);
1843 final Rect insets = new Rect();
1844 final Rect stableInsets = new Rect();
1845 Rect surfaceInsets = null;
1846 final boolean freeform = win != null && win.inFreeformWindowingMode();
1847 if (win != null) {
1848 // Containing frame will usually cover the whole screen, including dialog windows.
1849 // For freeform workspace windows it will not cover the whole screen and it also
1850 // won't exactly match the final freeform window frame (e.g. when overlapping with
1851 // the status bar). In that case we need to use the final frame.
1852 if (freeform) {
chaviw492139a2018-07-16 16:07:35 -07001853 frame.set(win.getFrameLw());
Adrian Roos4d18a2e2017-12-19 19:08:05 +01001854 } else if (win.isLetterboxedAppWindow()) {
1855 frame.set(getTask().getBounds());
Winson Chungc1674272018-02-21 10:15:17 -08001856 } else if (win.isDockedResizing()) {
1857 // If we are animating while docked resizing, then use the stack bounds as the
1858 // animation target (which will be different than the task bounds)
1859 frame.set(getTask().getParent().getBounds());
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001860 } else {
chaviw553b0212018-07-12 13:37:01 -07001861 frame.set(win.getContainingFrame());
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001862 }
1863 surfaceInsets = win.getAttrs().surfaceInsets;
Adrian Roos20e07892018-02-23 19:12:01 +01001864 // XXX(b/72757033): These are insets relative to the window frame, but we're really
1865 // interested in the insets relative to the frame we chose in the if-blocks above.
chaviw9c81e632018-07-31 11:17:52 -07001866 win.getContentInsets(insets);
1867 win.getStableInsets(stableInsets);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001868 }
1869
1870 if (mLaunchTaskBehind) {
1871 // Differentiate the two animations. This one which is briefly on the screen
1872 // gets the !enter animation, and the other activity which remains on the
1873 // screen gets the enter animation. Both appear in the mOpeningApps set.
1874 enter = false;
1875 }
1876 if (DEBUG_APP_TRANSITIONS) Slog.d(TAG_WM, "Loading animation for app transition."
1877 + " transit=" + AppTransition.appTransitionToString(transit) + " enter=" + enter
1878 + " frame=" + frame + " insets=" + insets + " surfaceInsets=" + surfaceInsets);
1879 final Configuration displayConfig = displayContent.getConfiguration();
1880 final Animation a = mService.mAppTransition.loadAnimation(lp, transit, enter,
1881 displayConfig.uiMode, displayConfig.orientation, frame, displayFrame, insets,
1882 surfaceInsets, stableInsets, isVoiceInteraction, freeform, getTask().mTaskId);
1883 if (a != null) {
1884 if (DEBUG_ANIM) logWithStack(TAG, "Loaded animation " + a + " for " + this);
1885 final int containingWidth = frame.width();
1886 final int containingHeight = frame.height();
1887 a.initialize(containingWidth, containingHeight, width, height);
1888 a.scaleCurrentDuration(mService.getTransitionAnimationScaleLocked());
1889 }
1890 return a;
1891 }
1892
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001893 @Override
Jorim Jaggi6de61012018-03-19 14:53:23 +01001894 public boolean shouldDeferAnimationFinish(Runnable endDeferFinishCallback) {
1895 return mAnimatingAppWindowTokenRegistry != null
1896 && mAnimatingAppWindowTokenRegistry.notifyAboutToFinish(
1897 this, endDeferFinishCallback);
1898 }
1899
1900 @Override
1901 public void onAnimationLeashDestroyed(Transaction t) {
1902 super.onAnimationLeashDestroyed(t);
Vishnu Naira2977262018-07-26 13:31:26 -07001903 if (mAnimationBoundsLayer != null) {
1904 t.destroy(mAnimationBoundsLayer);
1905 mAnimationBoundsLayer = null;
1906 }
1907
Jorim Jaggi6de61012018-03-19 14:53:23 +01001908 if (mAnimatingAppWindowTokenRegistry != null) {
1909 mAnimatingAppWindowTokenRegistry.notifyFinished(this);
1910 }
1911 }
1912
1913 @Override
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001914 protected void setLayer(Transaction t, int layer) {
1915 if (!mSurfaceAnimator.hasLeash()) {
1916 t.setLayer(mSurfaceControl, layer);
1917 }
1918 }
1919
1920 @Override
1921 protected void setRelativeLayer(Transaction t, SurfaceControl relativeTo, int layer) {
1922 if (!mSurfaceAnimator.hasLeash()) {
1923 t.setRelativeLayer(mSurfaceControl, relativeTo, layer);
1924 }
1925 }
1926
1927 @Override
1928 protected void reparentSurfaceControl(Transaction t, SurfaceControl newParent) {
1929 if (!mSurfaceAnimator.hasLeash()) {
1930 t.reparent(mSurfaceControl, newParent.getHandle());
1931 }
1932 }
1933
1934 @Override
1935 public void onAnimationLeashCreated(Transaction t, SurfaceControl leash) {
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001936 // The leash is parented to the animation layer. We need to preserve the z-order by using
1937 // the prefix order index, but we boost if necessary.
Robert Carrb9506032018-02-13 13:54:00 -08001938 int layer = 0;
1939 if (!inPinnedWindowingMode()) {
1940 layer = getPrefixOrderIndex();
1941 } else {
1942 // Pinned stacks have animations take place within themselves rather than an animation
1943 // layer so we need to preserve the order relative to the stack (e.g. the order of our
1944 // task/parent).
1945 layer = getParent().getPrefixOrderIndex();
1946 }
1947
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001948 if (mNeedsZBoost) {
1949 layer += Z_BOOST_BASE;
1950 }
1951 leash.setLayer(layer);
Robert Carr2f8aa392018-01-31 14:46:51 -08001952
1953 final DisplayContent dc = getDisplayContent();
Jorim Jaggibe418292018-03-26 16:14:12 +02001954 dc.assignStackOrdering();
Jorim Jaggi6de61012018-03-19 14:53:23 +01001955 if (mAnimatingAppWindowTokenRegistry != null) {
1956 mAnimatingAppWindowTokenRegistry.notifyStarting(this);
1957 }
Vishnu Naira2977262018-07-26 13:31:26 -07001958
1959 // If the animation needs to be cropped then an animation bounds layer is created as a child
1960 // of the pinned stack or animation layer. The leash is then reparented to this new layer.
1961 if (mNeedsAnimationBoundsLayer) {
1962 final TaskStack stack = getStack();
1963 if (stack == null) {
1964 return;
1965 }
1966 mAnimationBoundsLayer = createAnimationBoundsLayer(t);
1967
1968 // Set clip rect to stack bounds.
1969 mTmpRect.setEmpty();
1970 stack.getBounds(mTmpRect);
1971
1972 // Crop to stack bounds.
1973 t.setWindowCrop(mAnimationBoundsLayer, mTmpRect);
1974
1975 // Reparent leash to animation bounds layer.
1976 t.reparent(leash, mAnimationBoundsLayer.getHandle());
1977 }
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001978 }
1979
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001980 /**
1981 * This must be called while inside a transaction.
1982 */
1983 void showAllWindowsLocked() {
1984 forAllWindows(windowState -> {
1985 if (DEBUG_VISIBILITY) Slog.v(TAG, "performing show on: " + windowState);
1986 windowState.performShowLocked();
1987 }, false /* traverseTopToBottom */);
Jorim Jaggia5e10572017-11-15 14:36:26 +01001988 }
1989
1990 @Override
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001991 protected void onAnimationFinished() {
1992 super.onAnimationFinished();
1993
1994 mTransit = TRANSIT_UNSET;
1995 mTransitFlags = 0;
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001996 mNeedsZBoost = false;
Vishnu Naira2977262018-07-26 13:31:26 -07001997 mNeedsAnimationBoundsLayer = false;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001998
1999 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM | FINISH_LAYOUT_REDO_WALLPAPER,
2000 "AppWindowToken");
2001
Jorim Jaggi988f6682017-11-17 17:46:43 +01002002 clearThumbnail();
Jorim Jaggi752cd822018-03-29 16:29:18 +02002003 setClientHidden(isHidden() && hiddenRequested);
Jorim Jaggi988f6682017-11-17 17:46:43 +01002004
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002005 if (mService.mInputMethodTarget != null && mService.mInputMethodTarget.mAppToken == this) {
2006 getDisplayContent().computeImeTarget(true /* updateImeTarget */);
2007 }
2008
2009 if (DEBUG_ANIM) Slog.v(TAG, "Animation done in " + this
2010 + ": reportedVisible=" + reportedVisible
2011 + " okToDisplay=" + okToDisplay()
2012 + " okToAnimate=" + okToAnimate()
2013 + " startingDisplayed=" + startingDisplayed);
2014
2015 // WindowState.onExitAnimationDone might modify the children list, so make a copy and then
2016 // traverse the copy.
2017 final ArrayList<WindowState> children = new ArrayList<>(mChildren);
2018 children.forEach(WindowState::onExitAnimationDone);
2019
2020 mService.mAppTransition.notifyAppTransitionFinishedLocked(token);
2021 scheduleAnimation();
2022 }
2023
2024 @Override
2025 boolean isAppAnimating() {
2026 return isSelfAnimating();
2027 }
2028
2029 @Override
2030 boolean isSelfAnimating() {
2031 // If we are about to start a transition, we also need to be considered animating.
2032 return isWaitingForTransitionStart() || isReallyAnimating();
2033 }
2034
2035 /**
2036 * @return True if and only if we are actually running an animation. Note that
2037 * {@link #isSelfAnimating} also returns true if we are waiting for an animation to
2038 * start.
2039 */
2040 private boolean isReallyAnimating() {
2041 return super.isSelfAnimating();
2042 }
2043
Jorim Jaggi988f6682017-11-17 17:46:43 +01002044 @Override
2045 void cancelAnimation() {
2046 super.cancelAnimation();
2047 clearThumbnail();
2048 }
2049
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002050 boolean isWaitingForTransitionStart() {
2051 return mService.mAppTransition.isTransitionSet()
2052 && (mService.mOpeningApps.contains(this) || mService.mClosingApps.contains(this));
2053 }
2054
2055 public int getTransit() {
2056 return mTransit;
2057 }
2058
2059 int getTransitFlags() {
2060 return mTransitFlags;
2061 }
2062
Jorim Jaggi988f6682017-11-17 17:46:43 +01002063 void attachThumbnailAnimation() {
2064 if (!isReallyAnimating()) {
2065 return;
2066 }
2067 final int taskId = getTask().mTaskId;
2068 final GraphicBuffer thumbnailHeader =
2069 mService.mAppTransition.getAppTransitionThumbnailHeader(taskId);
2070 if (thumbnailHeader == null) {
2071 if (DEBUG_APP_TRANSITIONS) Slog.d(TAG, "No thumbnail header bitmap for: " + taskId);
2072 return;
2073 }
2074 clearThumbnail();
2075 mThumbnail = new AppWindowThumbnail(getPendingTransaction(), this, thumbnailHeader);
2076 mThumbnail.startAnimation(getPendingTransaction(), loadThumbnailAnimation(thumbnailHeader));
2077 }
2078
Tony Mak64b8d562017-12-28 17:44:02 +00002079 /**
2080 * Attaches a surface with a thumbnail for the
2081 * {@link android.app.ActivityOptions#ANIM_OPEN_CROSS_PROFILE_APPS} animation.
2082 */
2083 void attachCrossProfileAppsThumbnailAnimation() {
2084 if (!isReallyAnimating()) {
2085 return;
2086 }
2087 clearThumbnail();
2088
2089 final WindowState win = findMainWindow();
2090 if (win == null) {
2091 return;
2092 }
chaviw492139a2018-07-16 16:07:35 -07002093 final Rect frame = win.getFrameLw();
Tony Mak64b8d562017-12-28 17:44:02 +00002094 final int thumbnailDrawableRes = getTask().mUserId == mService.mCurrentUserId
2095 ? R.drawable.ic_account_circle
Tony Makda4af232018-04-27 11:01:10 +01002096 : R.drawable.ic_corp_badge;
Tony Mak64b8d562017-12-28 17:44:02 +00002097 final GraphicBuffer thumbnail =
2098 mService.mAppTransition
2099 .createCrossProfileAppsThumbnail(thumbnailDrawableRes, frame);
2100 if (thumbnail == null) {
2101 return;
2102 }
2103 mThumbnail = new AppWindowThumbnail(getPendingTransaction(), this, thumbnail);
2104 final Animation animation =
chaviw492139a2018-07-16 16:07:35 -07002105 mService.mAppTransition.createCrossProfileAppsThumbnailAnimationLocked(
2106 win.getFrameLw());
Tony Mak64b8d562017-12-28 17:44:02 +00002107 mThumbnail.startAnimation(getPendingTransaction(), animation, new Point(frame.left,
2108 frame.top));
2109 }
2110
Jorim Jaggi988f6682017-11-17 17:46:43 +01002111 private Animation loadThumbnailAnimation(GraphicBuffer thumbnailHeader) {
2112 final DisplayInfo displayInfo = mDisplayContent.getDisplayInfo();
2113
2114 // If this is a multi-window scenario, we use the windows frame as
2115 // destination of the thumbnail header animation. If this is a full screen
2116 // window scenario, we use the whole display as the target.
2117 WindowState win = findMainWindow();
2118 Rect appRect = win != null ? win.getContentFrameLw() :
2119 new Rect(0, 0, displayInfo.appWidth, displayInfo.appHeight);
chaviw9c81e632018-07-31 11:17:52 -07002120 final Rect insets = win != null ? win.getContentInsets() : null;
Jorim Jaggi988f6682017-11-17 17:46:43 +01002121 final Configuration displayConfig = mDisplayContent.getConfiguration();
2122 return mService.mAppTransition.createThumbnailAspectScaleAnimationLocked(
2123 appRect, insets, thumbnailHeader, getTask().mTaskId, displayConfig.uiMode,
2124 displayConfig.orientation);
2125 }
2126
2127 private void clearThumbnail() {
2128 if (mThumbnail == null) {
2129 return;
2130 }
2131 mThumbnail.destroy();
2132 mThumbnail = null;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002133 }
2134
Jorim Jaggif84e2f62018-01-16 14:17:59 +01002135 void registerRemoteAnimations(RemoteAnimationDefinition definition) {
2136 mRemoteAnimationDefinition = definition;
2137 }
2138
2139 RemoteAnimationDefinition getRemoteAnimationDefinition() {
2140 return mRemoteAnimationDefinition;
2141 }
2142
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002143 @Override
2144 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
2145 super.dump(pw, prefix, dumpAll);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002146 if (appToken != null) {
Wale Ogunwale72919d22016-12-08 18:58:50 -08002147 pw.println(prefix + "app=true mVoiceInteraction=" + mVoiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002148 }
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08002149 pw.print(prefix); pw.print("task="); pw.println(getTask());
Wale Ogunwale51362492016-09-08 17:49:17 -07002150 pw.print(prefix); pw.print(" mFillsParent="); pw.print(mFillsParent);
2151 pw.print(" mOrientation="); pw.println(mOrientation);
Wale Ogunwale89973222017-04-23 18:39:45 -07002152 pw.println(prefix + "hiddenRequested=" + hiddenRequested + " mClientHidden=" + mClientHidden
2153 + ((mDeferHidingClient) ? " mDeferHidingClient=" + mDeferHidingClient : "")
2154 + " reportedDrawn=" + reportedDrawn + " reportedVisible=" + reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -07002155 if (paused) {
2156 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002157 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -08002158 if (mAppStopped) {
2159 pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped);
2160 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07002161 if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002162 || allDrawn || mLastAllDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07002163 pw.print(prefix); pw.print("mNumInterestingWindows=");
2164 pw.print(mNumInterestingWindows);
2165 pw.print(" mNumDrawnWindows="); pw.print(mNumDrawnWindows);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002166 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -07002167 pw.print(" allDrawn="); pw.print(allDrawn);
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002168 pw.print(" lastAllDrawn="); pw.print(mLastAllDrawn);
Craig Mautner6fbda632012-07-03 09:26:39 -07002169 pw.println(")");
2170 }
2171 if (inPendingTransaction) {
2172 pw.print(prefix); pw.print("inPendingTransaction=");
2173 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002174 }
Craig Mautner799bc1d2015-01-14 10:33:48 -08002175 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002176 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
2177 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -08002178 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -08002179 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002180 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08002181 if (startingWindow != null || startingSurface != null
Wale Ogunwale6c459212017-05-17 08:56:03 -07002182 || startingDisplayed || startingMoved || mHiddenSetFromTransferredStartingWindow) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002183 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08002184 pw.print(" startingSurface="); pw.print(startingSurface);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002185 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
Wale Ogunwale6c459212017-05-17 08:56:03 -07002186 pw.print(" startingMoved="); pw.print(startingMoved);
2187 pw.println(" mHiddenSetFromTransferredStartingWindow="
2188 + mHiddenSetFromTransferredStartingWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002189 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01002190 if (!mFrozenBounds.isEmpty()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -08002191 pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds);
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002192 pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig);
Chong Zhangd78ddb42016-03-02 17:01:14 -08002193 }
2194 if (mPendingRelaunchCount != 0) {
2195 pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount);
Jorim Jaggi0429f352015-12-22 16:29:16 +01002196 }
Wale Ogunwale9c64cb62017-04-12 13:39:59 -07002197 if (getController() != null) {
2198 pw.print(prefix); pw.print("controller="); pw.println(getController());
2199 }
Wale Ogunwalee287e192017-04-21 09:30:12 -07002200 if (mRemovingFromDisplay) {
2201 pw.println(prefix + "mRemovingFromDisplay=" + mRemovingFromDisplay);
2202 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002203 }
2204
2205 @Override
2206 void setHidden(boolean hidden) {
2207 super.setHidden(hidden);
Winson Chunge55c0192017-08-24 14:50:48 -07002208
2209 if (hidden) {
2210 // Once the app window is hidden, reset the last saved PiP snap fraction
2211 mDisplayContent.mPinnedStackControllerLocked.resetReentrySnapFraction(this);
2212 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002213 scheduleAnimation();
2214 }
2215
2216 @Override
2217 void prepareSurfaces() {
2218 // isSelfAnimating also returns true when we are about to start a transition, so we need
2219 // to check super here.
2220 final boolean reallyAnimating = super.isSelfAnimating();
2221 final boolean show = !isHidden() || reallyAnimating;
2222 if (show && !mLastSurfaceShowing) {
2223 mPendingTransaction.show(mSurfaceControl);
2224 } else if (!show && mLastSurfaceShowing) {
2225 mPendingTransaction.hide(mSurfaceControl);
Jorim Jaggi4d1835d2017-08-31 17:28:27 +02002226 }
Jorim Jaggi988f6682017-11-17 17:46:43 +01002227 if (mThumbnail != null) {
2228 mThumbnail.setShowing(mPendingTransaction, show);
2229 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002230 mLastSurfaceShowing = show;
2231 super.prepareSurfaces();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002232 }
2233
Jorim Jaggi77d0f36c2018-03-16 17:49:49 +01002234 /**
2235 * @return Whether our {@link #getSurfaceControl} is currently showing.
2236 */
2237 boolean isSurfaceShowing() {
2238 return mLastSurfaceShowing;
2239 }
2240
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002241 boolean isFreezingScreen() {
2242 return mFreezingScreen;
2243 }
2244
2245 @Override
2246 boolean needsZBoost() {
2247 return mNeedsZBoost || super.needsZBoost();
2248 }
2249
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07002250 @CallSuper
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002251 @Override
Adrian Roos4921ccf2017-09-28 16:54:06 +02002252 public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07002253 final long token = proto.start(fieldId);
2254 writeNameToProto(proto, NAME);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002255 super.writeToProto(proto, WINDOW_TOKEN, trim);
Vishnu Nair04ab4392018-01-10 11:00:06 -08002256 proto.write(LAST_SURFACE_SHOWING, mLastSurfaceShowing);
2257 proto.write(IS_WAITING_FOR_TRANSITION_START, isWaitingForTransitionStart());
2258 proto.write(IS_REALLY_ANIMATING, isReallyAnimating());
2259 if (mThumbnail != null){
2260 mThumbnail.writeToProto(proto, THUMBNAIL);
2261 }
2262 proto.write(FILLS_PARENT, mFillsParent);
2263 proto.write(APP_STOPPED, mAppStopped);
2264 proto.write(HIDDEN_REQUESTED, hiddenRequested);
2265 proto.write(CLIENT_HIDDEN, mClientHidden);
2266 proto.write(DEFER_HIDING_CLIENT, mDeferHidingClient);
2267 proto.write(REPORTED_DRAWN, reportedDrawn);
2268 proto.write(REPORTED_VISIBLE, reportedVisible);
2269 proto.write(NUM_INTERESTING_WINDOWS, mNumInterestingWindows);
2270 proto.write(NUM_DRAWN_WINDOWS, mNumDrawnWindows);
2271 proto.write(ALL_DRAWN, allDrawn);
2272 proto.write(LAST_ALL_DRAWN, mLastAllDrawn);
2273 proto.write(REMOVED, removed);
2274 if (startingWindow != null){
2275 startingWindow.writeIdentifierToProto(proto, STARTING_WINDOW);
2276 }
2277 proto.write(STARTING_DISPLAYED, startingDisplayed);
2278 proto.write(STARTING_MOVED, startingMoved);
2279 proto.write(HIDDEN_SET_FROM_TRANSFERRED_STARTING_WINDOW,
2280 mHiddenSetFromTransferredStartingWindow);
2281 for (Rect bounds : mFrozenBounds) {
2282 bounds.writeToProto(proto, FROZEN_BOUNDS);
2283 }
Steven Timotiusaf03df62017-07-18 16:56:43 -07002284 proto.end(token);
2285 }
2286
2287 void writeNameToProto(ProtoOutputStream proto, long fieldId) {
2288 if (appToken == null) {
2289 return;
2290 }
2291 try {
2292 proto.write(fieldId, appToken.getName());
2293 } catch (RemoteException e) {
2294 // This shouldn't happen, but in this case fall back to outputting nothing
2295 Slog.e(TAG, e.toString());
2296 }
2297 }
2298
2299 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002300 public String toString() {
2301 if (stringName == null) {
2302 StringBuilder sb = new StringBuilder();
2303 sb.append("AppWindowToken{");
2304 sb.append(Integer.toHexString(System.identityHashCode(this)));
2305 sb.append(" token="); sb.append(token); sb.append('}');
2306 stringName = sb.toString();
2307 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07002308 return stringName + ((mIsExiting) ? " mIsExiting=" : "");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002309 }
Adrian Roos20e07892018-02-23 19:12:01 +01002310
2311 Rect getLetterboxInsets() {
2312 if (mLetterbox != null) {
2313 return mLetterbox.getInsets();
2314 } else {
2315 return new Rect();
2316 }
2317 }
Adrian Roos23df3a32018-03-15 15:41:13 +01002318
2319 /**
2320 * @eturn true if there is a letterbox and any part of that letterbox overlaps with
2321 * the given {@code rect}.
2322 */
2323 boolean isLetterboxOverlappingWith(Rect rect) {
2324 return mLetterbox != null && mLetterbox.isOverlappingWith(rect);
2325 }
chaviw4ad54912018-05-30 11:05:44 -07002326
2327 /**
2328 * Sets if this AWT is in the process of closing or entering PIP.
2329 * {@link #mWillCloseOrEnterPip}}
2330 */
2331 void setWillCloseOrEnterPip(boolean willCloseOrEnterPip) {
2332 mWillCloseOrEnterPip = willCloseOrEnterPip;
2333 }
2334
2335 /**
2336 * Returns whether this AWT is considered closing. Conditions are either
2337 * 1. Is this app animating and was requested to be hidden
2338 * 2. App is delayed closing since it might enter PIP.
2339 */
2340 boolean isClosingOrEnteringPip() {
2341 return (isAnimating() && hiddenRequested) || mWillCloseOrEnterPip;
2342 }
Jorim Jaggiaf0d6d22018-06-08 15:25:35 +02002343
2344 /**
2345 * @return Whether we are allowed to show non-starting windows at the moment. We disallow
2346 * showing windows during transitions in case we have windows that have wide-color-gamut
2347 * color mode set to avoid jank in the middle of the transition.
2348 */
2349 boolean canShowWindows() {
2350 return allDrawn && !(isReallyAnimating() && hasNonDefaultColorWindow());
2351 }
2352
2353 /**
2354 * @return true if we have a window that has a non-default color mode set; false otherwise.
2355 */
2356 private boolean hasNonDefaultColorWindow() {
2357 return forAllWindows(ws -> ws.mAttrs.getColorMode() != COLOR_MODE_DEFAULT,
2358 true /* topToBottom */);
2359 }
Jeff Browne9bdb312012-04-05 15:30:10 -07002360}