blob: 9baafcb73279d474543ae52a1e78c27a28eac100 [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;
lumark588a3e82018-07-20 18:53:54 +0800114import java.util.function.Consumer;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800115
116class AppTokenList extends ArrayList<AppWindowToken> {
117}
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800118
119/**
120 * Version of WindowToken that is specifically for a particular application (or
121 * really activity) that is displaying windows.
122 */
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700123class AppWindowToken extends WindowToken implements WindowManagerService.AppFreezeListener {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800124 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppWindowToken" : TAG_WM;
125
Jorim Jaggi619c9f72017-12-19 18:04:29 +0100126 /**
127 * Value to increment the z-layer when boosting a layer during animations. BOOST in l33tsp34k.
128 */
129 private static final int Z_BOOST_BASE = 800570000;
130
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800131 // Non-null only for application tokens.
132 final IApplicationToken appToken;
133
Wale Ogunwale72919d22016-12-08 18:58:50 -0800134 final boolean mVoiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700135
Wale Ogunwale51362492016-09-08 17:49:17 -0700136 /** @see WindowContainer#fillsParent() */
137 private boolean mFillsParent;
Craig Mautner4c5eb222013-11-18 12:59:05 -0800138 boolean layoutConfigChanges;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800139 boolean mShowForAllUsers;
140 int mTargetSdk;
Craig Mautnera2c77052012-03-26 12:14:43 -0700141
Bryce Lee6d410262017-02-28 15:30:17 -0800142 // Flag set while reparenting to prevent actions normally triggered by an individual parent
143 // change.
144 private boolean mReparenting;
145
Wale Ogunwalee287e192017-04-21 09:30:12 -0700146 // True if we are current in the process of removing this app token from the display
147 private boolean mRemovingFromDisplay = false;
148
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800149 // The input dispatching timeout for this application token in nanoseconds.
Wale Ogunwale72919d22016-12-08 18:58:50 -0800150 long mInputDispatchingTimeoutNanos;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800151
152 // These are used for determining when all windows associated with
153 // an activity have been drawn, so they can be made visible together
154 // at the same time.
Craig Mautner764983d2012-03-22 11:37:36 -0700155 // initialize so that it doesn't match mTransactionSequence which is an int.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700156 private long mLastTransactionSequence = Long.MIN_VALUE;
157 private int mNumInterestingWindows;
158 private int mNumDrawnWindows;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800159 boolean inPendingTransaction;
160 boolean allDrawn;
Jorim Jaggib0fc8172017-11-23 17:04:08 +0000161 private boolean mLastAllDrawn;
162
Craig Mautner7636dfb2012-11-16 15:24:11 -0800163 // Set to true when this app creates a surface while in the middle of an animation. In that
164 // case do not clear allDrawn until the animation completes.
165 boolean deferClearAllDrawn;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800166
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800167 // Is this window's surface needed? This is almost like hidden, except
168 // it will sometimes be true a little earlier: when the token has
169 // been shown, but is still waiting for its app transition to execute
170 // before making its windows shown.
171 boolean hiddenRequested;
172
173 // Have we told the window clients to hide themselves?
Wale Ogunwale89973222017-04-23 18:39:45 -0700174 private boolean mClientHidden;
175
176 // If true we will defer setting mClientHidden to true and reporting to the client that it is
177 // hidden.
178 boolean mDeferHidingClient;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800179
180 // Last visibility state we reported to the app token.
181 boolean reportedVisible;
182
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700183 // Last drawn state we reported to the app token.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700184 private boolean reportedDrawn;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700185
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800186 // Set to true when the token has been removed from the window mgr.
187 boolean removed;
188
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800189 // Information about an application starting window if displayed.
190 StartingData startingData;
191 WindowState startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800192 StartingSurface startingSurface;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800193 boolean startingDisplayed;
194 boolean startingMoved;
Jorim Jaggi60f9c972018-02-01 19:21:07 +0100195
Wale Ogunwale6c459212017-05-17 08:56:03 -0700196 // True if the hidden state of this token was forced to false due to a transferred starting
197 // window.
198 private boolean mHiddenSetFromTransferredStartingWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800199 boolean firstWindowDrawn;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700200 private final WindowState.UpdateReportedVisibilityResults mReportedVisibilityResults =
201 new WindowState.UpdateReportedVisibilityResults();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800202
203 // Input application handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700204 final InputApplicationHandle mInputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800205
Wale Ogunwale571771c2016-08-26 13:18:50 -0700206 // TODO: Have a WindowContainer state for tracking exiting/deferred removal.
Craig Mautner799bc1d2015-01-14 10:33:48 -0800207 boolean mIsExiting;
Craig Mautner9ef471f2014-02-07 13:11:47 -0800208
Craig Mautnerbb742462014-07-07 15:28:55 -0700209 boolean mLaunchTaskBehind;
Craig Mautner8746a472014-07-24 15:12:54 -0700210 boolean mEnteringAnimation;
Craig Mautnerbb742462014-07-07 15:28:55 -0700211
Wale Ogunwale72919d22016-12-08 18:58:50 -0800212 private boolean mAlwaysFocusable;
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800213
Robert Carre12aece2016-02-02 22:43:27 -0800214 boolean mAppStopped;
Robert Carrfd10cd12016-06-29 16:41:50 -0700215 int mRotationAnimationHint;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700216 private int mPendingRelaunchCount;
Robert Carre12aece2016-02-02 22:43:27 -0800217
Jorim Jaggife762342016-10-13 14:33:27 +0200218 private boolean mLastContainsShowWhenLockedWindow;
219 private boolean mLastContainsDismissKeyguardWindow;
220
Jorim Jaggi0429f352015-12-22 16:29:16 +0100221 ArrayDeque<Rect> mFrozenBounds = new ArrayDeque<>();
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700222 ArrayDeque<Configuration> mFrozenMergedConfig = new ArrayDeque<>();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100223
Wale Ogunwale6c459212017-05-17 08:56:03 -0700224 private boolean mDisablePreviewScreenshots;
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +0100225
Wale Ogunwale034a8ec2017-09-02 17:14:40 -0700226 private Task mLastParent;
Robert Carred3e83b2017-04-21 13:26:55 -0700227
chaviwd3bf08d2017-08-01 17:24:59 -0700228 /**
229 * See {@link #canTurnScreenOn()}
230 */
231 private boolean mCanTurnScreenOn = true;
232
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200233 /**
234 * If we are running an animation, this determines the transition type. Must be one of
235 * AppTransition.TRANSIT_* constants.
236 */
237 private int mTransit;
238
239 /**
240 * If we are running an animation, this determines the flags during this animation. Must be a
241 * bitwise combination of AppTransition.TRANSIT_FLAG_* constants.
242 */
243 private int mTransitFlags;
244
245 /** Whether our surface was set to be showing in the last call to {@link #prepareSurfaces} */
Jorim Jaggifd1891462017-12-29 15:41:36 +0100246 private boolean mLastSurfaceShowing = true;
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200247
Jorim Jaggi988f6682017-11-17 17:46:43 +0100248 private AppWindowThumbnail mThumbnail;
249
Jorim Jaggib0fc8172017-11-23 17:04:08 +0000250 /** Have we been asked to have this token keep the screen frozen? */
251 private boolean mFreezingScreen;
252
253 /** Whether this token should be boosted at the top of all app window tokens. */
254 private boolean mNeedsZBoost;
Adrian Roos4d18a2e2017-12-19 19:08:05 +0100255 private Letterbox mLetterbox;
Jorim Jaggib0fc8172017-11-23 17:04:08 +0000256
chaviw23ee71c2017-12-18 11:29:41 -0800257 private final Point mTmpPoint = new Point();
chaviw23012112017-12-20 15:29:04 -0800258 private final Rect mTmpRect = new Rect();
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100259 private RemoteAnimationDefinition mRemoteAnimationDefinition;
Jorim Jaggi6de61012018-03-19 14:53:23 +0100260 private AnimatingAppWindowTokenRegistry mAnimatingAppWindowTokenRegistry;
chaviw23ee71c2017-12-18 11:29:41 -0800261
chaviw4ad54912018-05-30 11:05:44 -0700262 /**
263 * A flag to determine if this AWT is in the process of closing or entering PIP. This is needed
264 * to help AWT know that the app is in the process of closing but hasn't yet started closing on
265 * the WM side.
266 */
267 private boolean mWillCloseOrEnterPip;
268
Vishnu Naira2977262018-07-26 13:31:26 -0700269 /** Layer used to constrain the animation to a token's stack bounds. */
270 SurfaceControl mAnimationBoundsLayer;
271
272 /** Whether this token needs to create mAnimationBoundsLayer for cropping animations. */
273 boolean mNeedsAnimationBoundsLayer;
274
Wale Ogunwale72919d22016-12-08 18:58:50 -0800275 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
276 DisplayContent dc, long inputDispatchingTimeoutNanos, boolean fullscreen,
277 boolean showForAllUsers, int targetSdk, int orientation, int rotationAnimationHint,
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800278 int configChanges, boolean launchTaskBehind, boolean alwaysFocusable,
Bryce Leef3c6a472017-11-14 14:53:06 -0800279 AppWindowContainerController controller) {
280 this(service, token, voiceInteraction, dc, fullscreen);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800281 setController(controller);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800282 mInputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800283 mShowForAllUsers = showForAllUsers;
284 mTargetSdk = targetSdk;
285 mOrientation = orientation;
286 layoutConfigChanges = (configChanges & (CONFIG_SCREEN_SIZE | CONFIG_ORIENTATION)) != 0;
287 mLaunchTaskBehind = launchTaskBehind;
288 mAlwaysFocusable = alwaysFocusable;
289 mRotationAnimationHint = rotationAnimationHint;
290
291 // Application tokens start out hidden.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200292 setHidden(true);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800293 hiddenRequested = true;
294 }
295
296 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
Bryce Leef3c6a472017-11-14 14:53:06 -0800297 DisplayContent dc, boolean fillsParent) {
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800298 super(service, token != null ? token.asBinder() : null, TYPE_APPLICATION, true, dc,
299 false /* ownerCanManageAppTokens */);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700300 appToken = token;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800301 mVoiceInteraction = voiceInteraction;
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800302 mFillsParent = fillsParent;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800303 mInputApplicationHandle = new InputApplicationHandle(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800304 }
305
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800306 void onFirstWindowDrawn(WindowState win, WindowStateAnimator winAnimator) {
307 firstWindowDrawn = true;
308
309 // We now have a good window to show, remove dead placeholders
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700310 removeDeadWindows();
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800311
Jorim Jaggi02886a82016-12-06 09:10:06 -0800312 if (startingWindow != null) {
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800313 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, "Finish starting "
314 + win.mToken + ": first real window is shown, no animation");
315 // If this initial window is animating, stop it -- we will do an animation to reveal
316 // it from behind the starting window, so there is no need for it to also be doing its
317 // own stuff.
Jorim Jaggia5e10572017-11-15 14:36:26 +0100318 win.cancelAnimation();
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800319 if (getController() != null) {
320 getController().removeStartingWindow();
321 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800322 }
323 updateReportedVisibilityLocked();
324 }
325
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800326 void updateReportedVisibilityLocked() {
327 if (appToken == null) {
328 return;
329 }
330
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700331 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700332 final int count = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800333
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700334 mReportedVisibilityResults.reset();
335
336 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700337 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700338 win.updateReportedVisibility(mReportedVisibilityResults);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800339 }
340
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700341 int numInteresting = mReportedVisibilityResults.numInteresting;
342 int numVisible = mReportedVisibilityResults.numVisible;
343 int numDrawn = mReportedVisibilityResults.numDrawn;
344 boolean nowGone = mReportedVisibilityResults.nowGone;
345
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700346 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200347 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting && !isHidden();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700348 if (!nowGone) {
349 // If the app is not yet gone, then it can only become visible/drawn.
350 if (!nowDrawn) {
351 nowDrawn = reportedDrawn;
352 }
353 if (!nowVisible) {
354 nowVisible = reportedVisible;
355 }
356 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800357 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800358 + numInteresting + " visible=" + numVisible);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800359 final AppWindowContainerController controller = getController();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700360 if (nowDrawn != reportedDrawn) {
361 if (nowDrawn) {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800362 if (controller != null) {
363 controller.reportWindowsDrawn();
364 }
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700365 }
366 reportedDrawn = nowDrawn;
367 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800368 if (nowVisible != reportedVisible) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700369 if (DEBUG_VISIBILITY) Slog.v(TAG,
370 "Visibility changed in " + this + ": vis=" + nowVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800371 reportedVisible = nowVisible;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800372 if (controller != null) {
373 if (nowVisible) {
374 controller.reportWindowsVisible();
375 } else {
376 controller.reportWindowsGone();
377 }
378 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800379 }
380 }
381
Wale Ogunwale89973222017-04-23 18:39:45 -0700382 boolean isClientHidden() {
383 return mClientHidden;
384 }
385
386 void setClientHidden(boolean hideClient) {
387 if (mClientHidden == hideClient || (hideClient && mDeferHidingClient)) {
388 return;
389 }
Jorim Jaggi067b5bf2018-02-23 17:42:39 +0100390 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setClientHidden: " + this
391 + " clientHidden=" + hideClient + " Callers=" + Debug.getCallers(5));
Wale Ogunwale89973222017-04-23 18:39:45 -0700392 mClientHidden = hideClient;
393 sendAppVisibilityToClients();
394 }
395
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700396 boolean setVisibility(WindowManager.LayoutParams lp,
397 boolean visible, int transit, boolean performLayout, boolean isVoiceInteraction) {
398
399 boolean delayed = false;
400 inPendingTransaction = false;
Wale Ogunwale9e4721f2017-05-23 19:37:30 -0700401 // Reset the state of mHiddenSetFromTransferredStartingWindow since visibility is actually
402 // been set by the app now.
403 mHiddenSetFromTransferredStartingWindow = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700404
405 // Allow for state changes and animation to be applied if:
406 // * token is transitioning visibility state
407 // * or the token was marked as hidden and is exiting before we had a chance to play the
408 // transition animation
409 // * or this is an opening app and windows are being replaced.
410 boolean visibilityChanged = false;
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200411 if (isHidden() == visible || (isHidden() && mIsExiting) || (visible && waitingForReplacement())) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700412 final AccessibilityController accessibilityController = mService.mAccessibilityController;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700413 boolean changed = false;
414 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200415 "Changing app " + this + " hidden=" + isHidden() + " performLayout=" + performLayout);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700416
417 boolean runningAppAnimation = false;
418
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100419 if (transit != WindowManager.TRANSIT_UNSET) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200420 if (applyAnimationLocked(lp, transit, visible, isVoiceInteraction)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700421 delayed = runningAppAnimation = true;
422 }
423 final WindowState window = findMainWindow();
424 //TODO (multidisplay): Magnification is supported only for the default display.
425 if (window != null && accessibilityController != null
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700426 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700427 accessibilityController.onAppWindowTransitionLocked(window, transit);
428 }
429 changed = true;
430 }
431
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700432 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700433 for (int i = 0; i < windowsCount; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700434 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700435 changed |= win.onAppVisibilityChanged(visible, runningAppAnimation);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700436 }
437
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200438 setHidden(!visible);
439 hiddenRequested = !visible;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700440 visibilityChanged = true;
441 if (!visible) {
442 stopFreezingScreen(true, true);
443 } else {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700444 // If we are being set visible, and the starting window is not yet displayed,
445 // then make sure it doesn't get displayed.
446 if (startingWindow != null && !startingWindow.isDrawnLw()) {
447 startingWindow.mPolicyVisibility = false;
448 startingWindow.mPolicyVisibilityAfterAnim = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700449 }
Jorim Jaggi38d44ec2017-06-14 16:04:59 -0700450
451 // We are becoming visible, so better freeze the screen with the windows that are
452 // getting visible so we also wait for them.
453 forAllWindows(mService::makeWindowFreezingScreenIfNeededLocked, true);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700454 }
455
456 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setVisibility: " + this
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200457 + ": hidden=" + isHidden() + " hiddenRequested=" + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700458
459 if (changed) {
Arthur Hung95b38a92018-07-20 18:56:12 +0800460 getDisplayContent().getInputMonitor().setUpdateInputWindowsNeededLw();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700461 if (performLayout) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700462 mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700463 false /*updateInputWindows*/);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700464 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700465 }
Arthur Hung95b38a92018-07-20 18:56:12 +0800466 getDisplayContent().getInputMonitor().updateInputWindowsLw(false /*force*/);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700467 }
468 }
469
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200470 if (isReallyAnimating()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700471 delayed = true;
Jorim Jaggiab9fcb22018-03-15 23:46:12 +0100472 } else {
473
474 // We aren't animating anything, but exiting windows rely on the animation finished
475 // callback being called in case the AppWindowToken was pretending to be animating,
476 // which we might have done because we were in closing/opening apps list.
477 onAnimationFinished();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700478 }
479
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700480 for (int i = mChildren.size() - 1; i >= 0 && !delayed; i--) {
Jorim Jaggia5e10572017-11-15 14:36:26 +0100481 if ((mChildren.get(i)).isSelfOrChildAnimating()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700482 delayed = true;
483 }
484 }
485
486 if (visibilityChanged) {
487 if (visible && !delayed) {
488 // The token was made immediately visible, there will be no entrance animation.
489 // We need to inform the client the enter animation was finished.
490 mEnteringAnimation = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700491 mService.mActivityManagerAppTransitionNotifier.onAppTransitionFinishedLocked(token);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700492 }
Robert Carr61b81112017-07-17 18:08:15 -0700493
Jorim Jaggi110839b2018-01-22 12:49:04 +0100494 // If we're becoming visible, immediately change client visibility as well although it
495 // usually gets changed in AppWindowContainerController.setVisibility already. However,
496 // there seem to be some edge cases where we change our visibility but client visibility
497 // never gets updated.
498 // If we're becoming invisible, update the client visibility if we are not running an
499 // animation. Otherwise, we'll update client visibility in onAnimationFinished.
Jorim Jaggi3cad57f2018-02-20 18:32:01 +0100500 if (visible || !isReallyAnimating()) {
Jorim Jaggi110839b2018-01-22 12:49:04 +0100501 setClientHidden(!visible);
Jorim Jaggi4876b4a2018-01-11 15:43:49 +0100502 }
503
lumark588a3e82018-07-20 18:53:54 +0800504 if (!getDisplayContent().mClosingApps.contains(this)
505 && !getDisplayContent().mOpeningApps.contains(this)) {
chaviwa953fcf2018-03-01 12:00:39 -0800506 // The token is not closing nor opening, so even if there is an animation set, that
507 // doesn't mean that it goes through the normal app transition cycle so we have
508 // to inform the docked controller about visibility change.
509 // TODO(multi-display): notify docked divider on all displays where visibility was
510 // affected.
lumark588a3e82018-07-20 18:53:54 +0800511 getDisplayContent().getDockedDividerController().notifyAppVisibilityChanged();
chaviwa953fcf2018-03-01 12:00:39 -0800512
513 // Take the screenshot before possibly hiding the WSA, otherwise the screenshot
514 // will not be taken.
515 mService.mTaskSnapshotController.notifyAppVisibilityChanged(this, visible);
516 }
517
Robert Carre7cc44d2017-03-20 19:04:30 -0700518 // If we are hidden but there is no delay needed we immediately
519 // apply the Surface transaction so that the ActivityManager
Robert Carr61b81112017-07-17 18:08:15 -0700520 // can have some guarantee on the Surface state following
521 // setting the visibility. This captures cases like dismissing
522 // the docked or pinned stack where there is no app transition.
523 //
524 // In the case of a "Null" animation, there will be
525 // no animation but there will still be a transition set.
526 // We still need to delay hiding the surface such that it
527 // can be synchronized with showing the next surface in the transition.
lumark588a3e82018-07-20 18:53:54 +0800528 if (isHidden() && !delayed && !getDisplayContent().mAppTransition.isTransitionSet()) {
Robert Carr6914f082017-03-20 19:04:30 -0700529 SurfaceControl.openTransaction();
530 for (int i = mChildren.size() - 1; i >= 0; i--) {
531 mChildren.get(i).mWinAnimator.hide("immediately hidden");
532 }
533 SurfaceControl.closeTransaction();
534 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700535 }
536
537 return delayed;
538 }
539
Jorim Jaggi87fdbcb2017-08-17 13:41:11 +0200540 /**
541 * @return The to top most child window for which {@link LayoutParams#isFullscreen()} returns
542 * true.
543 */
544 WindowState getTopFullscreenWindow() {
545 for (int i = mChildren.size() - 1; i >= 0; i--) {
546 final WindowState win = mChildren.get(i);
547 if (win != null && win.mAttrs.isFullscreen()) {
548 return win;
549 }
550 }
551 return null;
552 }
553
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800554 WindowState findMainWindow() {
Matthew Ng53e66b22018-01-12 17:13:13 -0800555 return findMainWindow(true);
556 }
557
558 /**
559 * Finds the main window that either has type base application or application starting if
560 * requested.
561 *
562 * @param includeStartingApp Allow to search application-starting windows to also be returned.
563 * @return The main window of type base application or application starting if requested.
564 */
565 WindowState findMainWindow(boolean includeStartingApp) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700566 WindowState candidate = null;
Matthew Ng53e66b22018-01-12 17:13:13 -0800567 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700568 final WindowState win = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700569 final int type = win.mAttrs.type;
570 // No need to loop through child window as base application and starting types can't be
571 // child windows.
Matthew Ng53e66b22018-01-12 17:13:13 -0800572 if (type == TYPE_BASE_APPLICATION
573 || (includeStartingApp && type == TYPE_APPLICATION_STARTING)) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700574 // In cases where there are multiple windows, we prefer the non-exiting window. This
Sungsoo Lim0d3d1f82015-12-02 14:47:59 +0900575 // happens for example when replacing windows during an activity relaunch. When
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700576 // constructing the animation, we want the new window, not the exiting one.
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800577 if (win.mAnimatingExit) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700578 candidate = win;
579 } else {
580 return win;
581 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800582 }
583 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700584 return candidate;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800585 }
586
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800587 boolean windowsAreFocusable() {
Wale Ogunwale3382ab12017-07-27 08:55:03 -0700588 return getWindowConfiguration().canReceiveKeys() || mAlwaysFocusable;
Wale Ogunwaled045c822015-12-02 09:14:28 -0800589 }
590
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800591 AppWindowContainerController getController() {
592 final WindowContainerController controller = super.getController();
593 return controller != null ? (AppWindowContainerController) controller : null;
594 }
595
Wale Ogunwale571771c2016-08-26 13:18:50 -0700596 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -0700597 boolean isVisible() {
Wale Ogunwalee471be62016-10-03 07:53:55 -0700598 // If the app token isn't hidden then it is considered visible and there is no need to check
599 // its children windows to see if they are visible.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200600 return !isHidden();
Wale Ogunwale44f21802016-09-02 12:49:48 -0700601 }
602
603 @Override
Wale Ogunwalee287e192017-04-21 09:30:12 -0700604 void removeImmediately() {
605 onRemovedFromDisplay();
606 super.removeImmediately();
607 }
608
609 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -0700610 void removeIfPossible() {
Craig Mautnere3119b72015-01-20 15:02:36 -0800611 mIsExiting = false;
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800612 removeAllWindowsIfPossible();
Bryce Lee6d410262017-02-28 15:30:17 -0800613 removeImmediately();
Craig Mautnere3119b72015-01-20 15:02:36 -0800614 }
615
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700616 @Override
617 boolean checkCompleteDeferredRemoval() {
618 if (mIsExiting) {
619 removeIfPossible();
620 }
621 return super.checkCompleteDeferredRemoval();
622 }
623
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700624 void onRemovedFromDisplay() {
Wale Ogunwalee287e192017-04-21 09:30:12 -0700625 if (mRemovingFromDisplay) {
626 return;
627 }
628 mRemovingFromDisplay = true;
629
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700630 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app token: " + this);
631
Wale Ogunwale72919d22016-12-08 18:58:50 -0800632 boolean delayed = setVisibility(null, false, TRANSIT_UNSET, true, mVoiceInteraction);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700633
lumark588a3e82018-07-20 18:53:54 +0800634 getDisplayContent().mOpeningApps.remove(this);
635 getDisplayContent().mUnknownAppVisibilityController.appRemovedOrHidden(this);
Jorim Jaggi10abe2f2017-01-03 16:44:46 +0100636 mService.mTaskSnapshotController.onAppRemoved(this);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700637 waitingToShow = false;
lumark588a3e82018-07-20 18:53:54 +0800638 if (getDisplayContent().mClosingApps.contains(this)) {
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700639 delayed = true;
lumark588a3e82018-07-20 18:53:54 +0800640 } else if (getDisplayContent().mAppTransition.isTransitionSet()) {
641 getDisplayContent().mClosingApps.add(this);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700642 delayed = true;
643 }
644
645 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app " + this + " delayed=" + delayed
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200646 + " animation=" + getAnimation() + " animating=" + isSelfAnimating());
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700647
648 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM, "removeAppToken: "
649 + this + " delayed=" + delayed + " Callers=" + Debug.getCallers(4));
650
Jorim Jaggi19be6052017-08-03 18:33:43 +0200651 if (startingData != null && getController() != null) {
652 getController().removeStartingWindow();
653 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800654
Winson Chung87e5d552017-04-05 11:49:38 -0700655 // If this window was animating, then we need to ensure that the app transition notifies
lumark588a3e82018-07-20 18:53:54 +0800656 // that animations have completed in DisplayContent.handleAnimatingStoppedAndTransition(),
657 // so add to that list now
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200658 if (isSelfAnimating()) {
lumark588a3e82018-07-20 18:53:54 +0800659 getDisplayContent().mNoAnimationNotifyOnTransitionFinished.add(token);
Winson Chung87e5d552017-04-05 11:49:38 -0700660 }
661
Wale Ogunwalee287e192017-04-21 09:30:12 -0700662 final TaskStack stack = getStack();
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700663 if (delayed && !isEmpty()) {
664 // set the token aside because it has an active animation to be finished
665 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM,
666 "removeAppToken make exiting: " + this);
Wale Ogunwalee287e192017-04-21 09:30:12 -0700667 if (stack != null) {
668 stack.mExitingAppTokens.add(this);
669 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700670 mIsExiting = true;
671 } else {
672 // Make sure there is no animation running on this token, so any windows associated
673 // with it will be removed as soon as their animations are complete
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200674 cancelAnimation();
Wale Ogunwale3106ae012017-05-16 08:56:37 -0700675 if (stack != null) {
676 stack.mExitingAppTokens.remove(this);
677 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700678 removeIfPossible();
679 }
680
681 removed = true;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700682 stopFreezingScreen(true, true);
Bryce Lee6d410262017-02-28 15:30:17 -0800683
Tiger Huang1e5b10a2018-07-30 20:19:51 +0800684 final DisplayContent dc = getDisplayContent();
685 if (dc.mFocusedApp == this) {
686 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "Removing focused app token:" + this
687 + " displayId=" + dc.getDisplayId());
688 dc.setFocusedApp(null);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700689 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700690 }
691
692 if (!delayed) {
693 updateReportedVisibilityLocked();
694 }
Wale Ogunwalee287e192017-04-21 09:30:12 -0700695
696 mRemovingFromDisplay = false;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700697 }
698
Chong Zhange05bcb12016-07-26 17:47:29 -0700699 void clearAnimatingFlags() {
Chong Zhangb0d26702016-08-12 16:03:29 -0700700 boolean wallpaperMightChange = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700701 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700702 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700703 wallpaperMightChange |= win.clearAnimatingFlags();
Chong Zhange05bcb12016-07-26 17:47:29 -0700704 }
Chong Zhangb0d26702016-08-12 16:03:29 -0700705 if (wallpaperMightChange) {
706 requestUpdateWallpaperIfNeeded();
707 }
Chong Zhange05bcb12016-07-26 17:47:29 -0700708 }
709
Robert Carre12aece2016-02-02 22:43:27 -0800710 void destroySurfaces() {
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700711 destroySurfaces(false /*cleanupOnResume*/);
712 }
713
714 /**
715 * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure
716 * the client has finished with them.
717 *
718 * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If
719 * set to true, destroy only surfaces of removed windows, and clear relevant flags of the
720 * others so that they are ready to be reused. If set to false (common case), destroy all
721 * surfaces that's eligible, if the app is already stopped.
722 */
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700723 private void destroySurfaces(boolean cleanupOnResume) {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700724 boolean destroyedSomething = false;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100725
726 // Copying to a different list as multiple children can be removed.
Jorim Jaggi59f3e922018-01-05 15:40:32 +0100727 final ArrayList<WindowState> children = new ArrayList<>(mChildren);
Jorim Jaggia5e10572017-11-15 14:36:26 +0100728 for (int i = children.size() - 1; i >= 0; i--) {
729 final WindowState win = children.get(i);
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700730 destroyedSomething |= win.destroySurface(cleanupOnResume, mAppStopped);
Robert Carre12aece2016-02-02 22:43:27 -0800731 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700732 if (destroyedSomething) {
733 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700734 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Adrian Roos23df3a32018-03-15 15:41:13 +0100735 updateLetterboxSurface(null);
Robert Carre12aece2016-02-02 22:43:27 -0800736 }
737 }
738
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800739 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700740 * Notify that the app is now resumed, and it was not stopped before, perform a clean
741 * up of the surfaces
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800742 */
Jorim Jaggibae01b12017-04-11 16:29:10 -0700743 void notifyAppResumed(boolean wasStopped) {
Chong Zhangad24f962016-08-25 12:12:33 -0700744 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped
Jorim Jaggibae01b12017-04-11 16:29:10 -0700745 + " " + this);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700746 mAppStopped = false;
chaviwd3bf08d2017-08-01 17:24:59 -0700747 // Allow the window to turn the screen on once the app is resumed again.
748 setCanTurnScreenOn(true);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700749 if (!wasStopped) {
750 destroySurfaces(true /*cleanupOnResume*/);
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800751 }
Robert Carre12aece2016-02-02 22:43:27 -0800752 }
753
Chong Zhangbef461f2015-10-27 11:38:24 -0700754 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700755 * Notify that the app has stopped, and it is okay to destroy any surfaces which were
756 * keeping alive in case they were still being used.
757 */
758 void notifyAppStopped() {
759 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this);
760 mAppStopped = true;
761 destroySurfaces();
762 // Remove any starting window that was added for this app if they are still around.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800763 if (getController() != null) {
764 getController().removeStartingWindow();
765 }
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700766 }
767
Chong Zhang92147042016-05-09 12:47:11 -0700768 void clearAllDrawn() {
769 allDrawn = false;
770 deferClearAllDrawn = false;
Chong Zhangbef461f2015-10-27 11:38:24 -0700771 }
772
Bryce Lee6d410262017-02-28 15:30:17 -0800773 Task getTask() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800774 return (Task) getParent();
Bryce Lee6d410262017-02-28 15:30:17 -0800775 }
776
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800777 TaskStack getStack() {
778 final Task task = getTask();
779 if (task != null) {
780 return task.mStack;
781 } else {
782 return null;
783 }
784 }
785
Bryce Lee6d410262017-02-28 15:30:17 -0800786 @Override
787 void onParentSet() {
788 super.onParentSet();
789
Robert Carred3e83b2017-04-21 13:26:55 -0700790 final Task task = getTask();
791
Bryce Lee6d410262017-02-28 15:30:17 -0800792 // When the associated task is {@code null}, the {@link AppWindowToken} can no longer
793 // access visual elements like the {@link DisplayContent}. We must remove any associations
794 // such as animations.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800795 if (!mReparenting) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800796 if (task == null) {
797 // It is possible we have been marked as a closing app earlier. We must remove ourselves
798 // from this list so we do not participate in any future animations.
lumark588a3e82018-07-20 18:53:54 +0800799 getDisplayContent().mClosingApps.remove(this);
Robert Carred3e83b2017-04-21 13:26:55 -0700800 } else if (mLastParent != null && mLastParent.mStack != null) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800801 task.mStack.mExitingAppTokens.remove(this);
802 }
Bryce Lee6d410262017-02-28 15:30:17 -0800803 }
Jorim Jaggi6de61012018-03-19 14:53:23 +0100804 final TaskStack stack = getStack();
805
806 // If we reparent, make sure to remove ourselves from the old animation registry.
807 if (mAnimatingAppWindowTokenRegistry != null) {
808 mAnimatingAppWindowTokenRegistry.notifyFinished(this);
809 }
810 mAnimatingAppWindowTokenRegistry = stack != null
811 ? stack.getAnimatingAppWindowTokenRegistry()
812 : null;
813
Robert Carred3e83b2017-04-21 13:26:55 -0700814 mLastParent = task;
Bryce Lee6d410262017-02-28 15:30:17 -0800815 }
816
Wale Ogunwalefa854eb2016-09-20 13:43:52 -0700817 void postWindowRemoveStartingWindowCleanup(WindowState win) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700818 // TODO: Something smells about the code below...Is there a better way?
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700819 if (startingWindow == win) {
820 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800821 if (getController() != null) {
822 getController().removeStartingWindow();
823 }
Wale Ogunwale6c459212017-05-17 08:56:03 -0700824 } else if (mChildren.size() == 0) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700825 // If this is the last window and we had requested a starting transition window,
826 // well there is no point now.
Jorim Jaggi02886a82016-12-06 09:10:06 -0800827 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingData");
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700828 startingData = null;
Wale Ogunwale6c459212017-05-17 08:56:03 -0700829 if (mHiddenSetFromTransferredStartingWindow) {
830 // We set the hidden state to false for the token from a transferred starting window.
831 // We now reset it back to true since the starting window was the last window in the
832 // token.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200833 setHidden(true);
Wale Ogunwale6c459212017-05-17 08:56:03 -0700834 }
Jorim Jaggi829b9cd2017-01-23 16:20:53 +0100835 } else if (mChildren.size() == 1 && startingSurface != null && !isRelaunching()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700836 // If this is the last window except for a starting transition window,
837 // we need to get rid of the starting transition.
Jorim Jaggie4b0f282017-05-17 15:10:29 +0200838 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Last window, removing starting window "
839 + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800840 if (getController() != null) {
841 getController().removeStartingWindow();
842 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700843 }
844 }
845
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700846 void removeDeadWindows() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700847 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700848 WindowState win = mChildren.get(winNdx);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800849 if (win.mAppDied) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700850 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700851 "removeDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800852 // Set mDestroying, we don't want any animation or delayed removal here.
853 win.mDestroying = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700854 // Also removes child windows.
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700855 win.removeIfPossible();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800856 }
857 }
858 }
859
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700860 boolean hasWindowsAlive() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700861 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700862 // No need to loop through child windows as the answer should be the same as that of the
863 // parent window.
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700864 if (!(mChildren.get(i)).mAppDied) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700865 return true;
866 }
867 }
868 return false;
869 }
870
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700871 void setWillReplaceWindows(boolean animate) {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700872 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
873 "Marking app token " + this + " with replacing windows.");
Robert Carra1eb4392015-12-10 12:43:51 -0800874
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700875 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700876 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700877 w.setWillReplaceWindow(animate);
Robert Carra1eb4392015-12-10 12:43:51 -0800878 }
Robert Carra1eb4392015-12-10 12:43:51 -0800879 }
880
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700881 void setWillReplaceChildWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700882 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this
Robert Carr23fa16b2016-01-13 13:19:58 -0800883 + " with replacing child windows.");
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700884 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700885 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700886 w.setWillReplaceChildWindows();
Robert Carr23fa16b2016-01-13 13:19:58 -0800887 }
888 }
889
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700890 void clearWillReplaceWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700891 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
892 "Resetting app token " + this + " of replacing window marks.");
Chong Zhangf596cd52016-01-05 13:42:44 -0800893
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700894 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700895 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700896 w.clearWillReplaceWindow();
Chong Zhangf596cd52016-01-05 13:42:44 -0800897 }
898 }
899
Chong Zhang4d7369a2016-04-25 16:09:14 -0700900 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700901 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700902 final WindowState w = mChildren.get(i);
Chong Zhang4d7369a2016-04-25 16:09:14 -0700903 w.requestUpdateWallpaperIfNeeded();
904 }
905 }
906
Chong Zhangd78ddb42016-03-02 17:01:14 -0800907 boolean isRelaunching() {
908 return mPendingRelaunchCount > 0;
909 }
910
Robert Carr68375192017-06-13 12:41:53 -0700911 boolean shouldFreezeBounds() {
912 final Task task = getTask();
913
914 // For freeform windows, we can't freeze the bounds at the moment because this would make
915 // the resizing unresponsive.
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700916 if (task == null || task.inFreeformWindowingMode()) {
Robert Carr68375192017-06-13 12:41:53 -0700917 return false;
918 }
919
920 // We freeze the bounds while drag resizing to deal with the time between
921 // the divider/drag handle being released, and the handling it's new
922 // configuration. If we are relaunched outside of the drag resizing state,
923 // we need to be careful not to do this.
924 return getTask().isDragResizing();
925 }
926
Chong Zhangd78ddb42016-03-02 17:01:14 -0800927 void startRelaunching() {
Robert Carr68375192017-06-13 12:41:53 -0700928 if (shouldFreezeBounds()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -0800929 freezeBounds();
930 }
Robert Carrd5c7dd62017-03-08 10:39:30 -0800931
932 // In the process of tearing down before relaunching, the app will
933 // try and clean up it's child surfaces. We need to prevent this from
934 // happening, so we sever the children, transfering their ownership
935 // from the client it-self to the parent surface (owned by us).
Robert Carr29daa922018-04-27 11:56:48 -0700936 detachChildren();
937
938 mPendingRelaunchCount++;
939 }
940
941 void detachChildren() {
Robert Carrfd8e93b2018-05-10 13:40:25 -0700942 SurfaceControl.openTransaction();
Robert Carrd5c7dd62017-03-08 10:39:30 -0800943 for (int i = mChildren.size() - 1; i >= 0; i--) {
944 final WindowState w = mChildren.get(i);
945 w.mWinAnimator.detachChildren();
946 }
Robert Carrfd8e93b2018-05-10 13:40:25 -0700947 SurfaceControl.closeTransaction();
Chong Zhangd78ddb42016-03-02 17:01:14 -0800948 }
949
950 void finishRelaunching() {
Robert Carr68375192017-06-13 12:41:53 -0700951 unfreezeBounds();
952
Chong Zhangd78ddb42016-03-02 17:01:14 -0800953 if (mPendingRelaunchCount > 0) {
954 mPendingRelaunchCount--;
Bryce Lee081554b2017-05-25 07:52:12 -0700955 } else {
956 // Update keyguard flags upon finishing relaunch.
957 checkKeyguardFlagsChanged();
Chong Zhangd78ddb42016-03-02 17:01:14 -0800958 }
959 }
960
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700961 void clearRelaunching() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700962 if (mPendingRelaunchCount == 0) {
963 return;
964 }
Robert Carr68375192017-06-13 12:41:53 -0700965 unfreezeBounds();
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700966 mPendingRelaunchCount = 0;
967 }
968
Wale Ogunwale07bcab72016-10-14 15:30:09 -0700969 /**
970 * Returns true if the new child window we are adding to this token is considered greater than
971 * the existing child window in this token in terms of z-order.
972 */
973 @Override
974 protected boolean isFirstChildWindowGreaterThanSecond(WindowState newWindow,
975 WindowState existingWindow) {
976 final int type1 = newWindow.mAttrs.type;
977 final int type2 = existingWindow.mAttrs.type;
978
979 // Base application windows should be z-ordered BELOW all other windows in the app token.
980 if (type1 == TYPE_BASE_APPLICATION && type2 != TYPE_BASE_APPLICATION) {
981 return false;
982 } else if (type1 != TYPE_BASE_APPLICATION && type2 == TYPE_BASE_APPLICATION) {
983 return true;
984 }
985
986 // Starting windows should be z-ordered ABOVE all other windows in the app token.
987 if (type1 == TYPE_APPLICATION_STARTING && type2 != TYPE_APPLICATION_STARTING) {
988 return true;
989 } else if (type1 != TYPE_APPLICATION_STARTING && type2 == TYPE_APPLICATION_STARTING) {
990 return false;
991 }
992
993 // Otherwise the new window is greater than the existing window.
994 return true;
995 }
996
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700997 @Override
Robert Carra1eb4392015-12-10 12:43:51 -0800998 void addWindow(WindowState w) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700999 super.addWindow(w);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001000
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001001 boolean gotReplacementWindow = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001002 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001003 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001004 gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w);
1005 }
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001006
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001007 // if we got a replacement window, reset the timeout to give drawing more time
1008 if (gotReplacementWindow) {
1009 mService.scheduleWindowReplacementTimeouts(this);
Robert Carra1eb4392015-12-10 12:43:51 -08001010 }
Jorim Jaggife762342016-10-13 14:33:27 +02001011 checkKeyguardFlagsChanged();
1012 }
1013
1014 @Override
1015 void removeChild(WindowState child) {
1016 super.removeChild(child);
1017 checkKeyguardFlagsChanged();
Adrian Roos23df3a32018-03-15 15:41:13 +01001018 updateLetterboxSurface(child);
Robert Carra1eb4392015-12-10 12:43:51 -08001019 }
1020
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001021 private boolean waitingForReplacement() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001022 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001023 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001024 if (candidate.waitingForReplacement()) {
Robert Carra1eb4392015-12-10 12:43:51 -08001025 return true;
1026 }
1027 }
1028 return false;
1029 }
1030
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001031 void onWindowReplacementTimeout() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001032 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001033 (mChildren.get(i)).onWindowReplacementTimeout();
Robert Carra1eb4392015-12-10 12:43:51 -08001034 }
1035 }
1036
Winson Chung30480042017-01-26 10:55:34 -08001037 void reparent(Task task, int position) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001038 final Task currentTask = getTask();
1039 if (task == currentTask) {
Winson Chung30480042017-01-26 10:55:34 -08001040 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001041 "window token=" + this + " already child of task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -08001042 }
Bryce Lee6d410262017-02-28 15:30:17 -08001043
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001044 if (currentTask.mStack != task.mStack) {
Bryce Lee6d410262017-02-28 15:30:17 -08001045 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001046 "window token=" + this + " current task=" + currentTask
Bryce Lee6d410262017-02-28 15:30:17 -08001047 + " belongs to a different stack than " + task);
1048 }
1049
Winson Chung30480042017-01-26 10:55:34 -08001050 if (DEBUG_ADD_REMOVE) Slog.i(TAG, "reParentWindowToken: removing window token=" + this
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001051 + " from task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -08001052 final DisplayContent prevDisplayContent = getDisplayContent();
1053
Bryce Lee6d410262017-02-28 15:30:17 -08001054 mReparenting = true;
1055
Winson Chung30480042017-01-26 10:55:34 -08001056 getParent().removeChild(this);
1057 task.addChild(this, position);
1058
Bryce Lee6d410262017-02-28 15:30:17 -08001059 mReparenting = false;
1060
Winson Chung30480042017-01-26 10:55:34 -08001061 // Relayout display(s).
1062 final DisplayContent displayContent = task.getDisplayContent();
1063 displayContent.setLayoutNeeded();
1064 if (prevDisplayContent != displayContent) {
1065 onDisplayChanged(displayContent);
1066 prevDisplayContent.setLayoutNeeded();
1067 }
1068 }
1069
Tiger Huang1e5b10a2018-07-30 20:19:51 +08001070 @Override
1071 void onDisplayChanged(DisplayContent dc) {
1072 DisplayContent prevDc = mDisplayContent;
1073 super.onDisplayChanged(dc);
1074 if (prevDc != null && prevDc.mFocusedApp == this) {
1075 prevDc.setFocusedApp(null);
1076 if (dc.getTopStack().getTopChild().getTopChild() == this) {
1077 dc.setFocusedApp(this);
1078 }
1079 }
1080 }
1081
Jorim Jaggi0429f352015-12-22 16:29:16 +01001082 /**
1083 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
1084 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
1085 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
1086 * with a queue.
1087 */
Chong Zhangd78ddb42016-03-02 17:01:14 -08001088 private void freezeBounds() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001089 final Task task = getTask();
1090 mFrozenBounds.offer(new Rect(task.mPreparedFrozenBounds));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001091
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001092 if (task.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) {
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001093 // We didn't call prepareFreezingBounds on the task, so use the current value.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001094 mFrozenMergedConfig.offer(new Configuration(task.getConfiguration()));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001095 } else {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001096 mFrozenMergedConfig.offer(new Configuration(task.mPreparedFrozenMergedConfig));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001097 }
Andrii Kulianb10330d2016-09-16 13:51:46 -07001098 // Calling unset() to make it equal to Configuration.EMPTY.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001099 task.mPreparedFrozenMergedConfig.unset();
Jorim Jaggi0429f352015-12-22 16:29:16 +01001100 }
1101
1102 /**
1103 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
1104 */
Chong Zhangd78ddb42016-03-02 17:01:14 -08001105 private void unfreezeBounds() {
Robert Carr68375192017-06-13 12:41:53 -07001106 if (mFrozenBounds.isEmpty()) {
1107 return;
Wale Ogunwale37dbafc2016-06-27 10:15:20 -07001108 }
Robert Carr68375192017-06-13 12:41:53 -07001109 mFrozenBounds.remove();
Wale Ogunwale37dbafc2016-06-27 10:15:20 -07001110 if (!mFrozenMergedConfig.isEmpty()) {
1111 mFrozenMergedConfig.remove();
1112 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001113 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001114 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001115 win.onUnfreezeBounds();
Jorim Jaggi4846ee32016-01-07 17:39:12 +01001116 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001117 mService.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +01001118 }
1119
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001120 void setAppLayoutChanges(int changes, String reason) {
1121 if (!mChildren.isEmpty()) {
1122 final DisplayContent dc = getDisplayContent();
1123 dc.pendingLayoutChanges |= changes;
1124 if (DEBUG_LAYOUT_REPEATS) {
1125 mService.mWindowPlacerLocked.debugLayoutRepeats(reason, dc.pendingLayoutChanges);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001126 }
1127 }
1128 }
1129
1130 void removeReplacedWindowIfNeeded(WindowState replacement) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001131 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001132 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001133 if (win.removeReplacedWindowIfNeeded(replacement)) {
1134 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001135 }
1136 }
1137 }
1138
1139 void startFreezingScreen() {
1140 if (DEBUG_ORIENTATION) logWithStack(TAG, "Set freezing of " + appToken + ": hidden="
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001141 + isHidden() + " freezing=" + mFreezingScreen + " hiddenRequested="
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001142 + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001143 if (!hiddenRequested) {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001144 if (!mFreezingScreen) {
1145 mFreezingScreen = true;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001146 mService.registerAppFreezeListener(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001147 mService.mAppsFreezingScreen++;
1148 if (mService.mAppsFreezingScreen == 1) {
Robert Carrae606b42018-02-15 15:36:23 -08001149 mService.startFreezingDisplayLocked(0, 0, getDisplayContent());
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001150 mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT);
1151 mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001152 }
1153 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001154 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001155 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001156 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001157 w.onStartFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001158 }
1159 }
1160 }
1161
1162 void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001163 if (!mFreezingScreen) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001164 return;
1165 }
1166 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + this + " force=" + force);
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001167 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001168 boolean unfrozeWindows = false;
1169 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001170 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001171 unfrozeWindows |= w.onStopFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001172 }
1173 if (force || unfrozeWindows) {
1174 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this);
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001175 mFreezingScreen = false;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001176 mService.unregisterAppFreezeListener(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001177 mService.mAppsFreezingScreen--;
1178 mService.mLastFinishedFreezeSource = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001179 }
1180 if (unfreezeSurfaceNow) {
1181 if (unfrozeWindows) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001182 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001183 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001184 mService.stopFreezingDisplayLocked();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001185 }
1186 }
1187
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001188 @Override
1189 public void onAppFreezeTimeout() {
1190 Slog.w(TAG_WM, "Force clearing freeze: " + this);
1191 stopFreezingScreen(true, true);
1192 }
1193
Jorim Jaggi60f9c972018-02-01 19:21:07 +01001194 /**
1195 * Tries to transfer the starting window from a token that's above ourselves in the task but
1196 * not visible anymore. This is a common scenario apps use: Trampoline activity T start main
1197 * activity M in the same task. Now, when reopening the task, T starts on top of M but then
1198 * immediately finishes after, so we have to transfer T to M.
1199 */
1200 void transferStartingWindowFromHiddenAboveTokenIfNeeded() {
1201 final Task task = getTask();
1202 for (int i = task.mChildren.size() - 1; i >= 0; i--) {
1203 final AppWindowToken fromToken = task.mChildren.get(i);
1204 if (fromToken == this) {
1205 return;
1206 }
1207 if (fromToken.hiddenRequested && transferStartingWindow(fromToken.token)) {
1208 return;
1209 }
1210 }
1211 }
1212
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001213 boolean transferStartingWindow(IBinder transferFrom) {
Wale Ogunwale02319a62016-09-26 15:21:22 -07001214 final AppWindowToken fromToken = getDisplayContent().getAppWindowToken(transferFrom);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001215 if (fromToken == null) {
1216 return false;
1217 }
1218
1219 final WindowState tStartingWindow = fromToken.startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001220 if (tStartingWindow != null && fromToken.startingSurface != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001221 // In this case, the starting icon has already been displayed, so start
1222 // letting windows get shown immediately without any more transitions.
lumark588a3e82018-07-20 18:53:54 +08001223 getDisplayContent().mSkipAppTransitionAnimation = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001224
1225 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow
1226 + " from " + fromToken + " to " + this);
1227
1228 final long origId = Binder.clearCallingIdentity();
Peter Visontay3556a3b2017-11-01 17:23:17 +00001229 try {
1230 // Transfer the starting window over to the new token.
1231 startingData = fromToken.startingData;
1232 startingSurface = fromToken.startingSurface;
1233 startingDisplayed = fromToken.startingDisplayed;
1234 fromToken.startingDisplayed = false;
1235 startingWindow = tStartingWindow;
1236 reportedVisible = fromToken.reportedVisible;
1237 fromToken.startingData = null;
1238 fromToken.startingSurface = null;
1239 fromToken.startingWindow = null;
1240 fromToken.startingMoved = true;
1241 tStartingWindow.mToken = this;
1242 tStartingWindow.mAppToken = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001243
Peter Visontay3556a3b2017-11-01 17:23:17 +00001244 if (DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1245 "Removing starting " + tStartingWindow + " from " + fromToken);
1246 fromToken.removeChild(tStartingWindow);
1247 fromToken.postWindowRemoveStartingWindowCleanup(tStartingWindow);
1248 fromToken.mHiddenSetFromTransferredStartingWindow = false;
1249 addWindow(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001250
Peter Visontay3556a3b2017-11-01 17:23:17 +00001251 // Propagate other interesting state between the tokens. If the old token is displayed,
1252 // we should immediately force the new one to be displayed. If it is animating, we need
1253 // to move that animation to the new one.
1254 if (fromToken.allDrawn) {
1255 allDrawn = true;
1256 deferClearAllDrawn = fromToken.deferClearAllDrawn;
1257 }
1258 if (fromToken.firstWindowDrawn) {
1259 firstWindowDrawn = true;
1260 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001261 if (!fromToken.isHidden()) {
1262 setHidden(false);
Peter Visontay3556a3b2017-11-01 17:23:17 +00001263 hiddenRequested = false;
1264 mHiddenSetFromTransferredStartingWindow = true;
1265 }
1266 setClientHidden(fromToken.mClientHidden);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001267
Jorim Jaggi980c9de2017-11-17 01:41:37 +01001268 transferAnimation(fromToken);
1269
1270 // When transferring an animation, we no longer need to apply an animation to the
1271 // the token we transfer the animation over. Thus, remove the animation from
1272 // pending opening apps.
lumark588a3e82018-07-20 18:53:54 +08001273 getDisplayContent().mOpeningApps.remove(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001274
Peter Visontay3556a3b2017-11-01 17:23:17 +00001275 mService.updateFocusedWindowLocked(
1276 UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/);
1277 getDisplayContent().setLayoutNeeded();
1278 mService.mWindowPlacerLocked.performSurfacePlacement();
1279 } finally {
1280 Binder.restoreCallingIdentity(origId);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001281 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001282 return true;
1283 } else if (fromToken.startingData != null) {
1284 // The previous app was getting ready to show a
1285 // starting window, but hasn't yet done so. Steal it!
1286 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1287 "Moving pending starting from " + fromToken + " to " + this);
1288 startingData = fromToken.startingData;
1289 fromToken.startingData = null;
1290 fromToken.startingMoved = true;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001291 if (getController() != null) {
1292 getController().scheduleAddStartingWindow();
1293 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001294 return true;
1295 }
1296
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001297 // TODO: Transfer thumbnail
1298
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001299 return false;
1300 }
1301
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001302 boolean isLastWindow(WindowState win) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001303 return mChildren.size() == 1 && mChildren.get(0) == win;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001304 }
1305
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001306 @Override
1307 void onAppTransitionDone() {
1308 sendingToBottom = false;
1309 }
1310
Wale Ogunwale51362492016-09-08 17:49:17 -07001311 /**
1312 * We override because this class doesn't want its children affecting its reported orientation
1313 * in anyway.
1314 */
1315 @Override
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001316 int getOrientation(int candidate) {
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001317 if (candidate == SCREEN_ORIENTATION_BEHIND) {
1318 // Allow app to specify orientation regardless of its visibility state if the current
1319 // candidate want us to use orientation behind. I.e. the visible app on-top of this one
1320 // wants us to use the orientation of the app behind it.
1321 return mOrientation;
1322 }
1323
Bryce Lee61fbcbc2017-03-10 14:14:03 -08001324 // The {@link AppWindowToken} should only specify an orientation when it is not closing or
1325 // going to the bottom. Allowing closing {@link AppWindowToken} to participate can lead to
1326 // an Activity in another task being started in the wrong orientation during the transition.
lumark588a3e82018-07-20 18:53:54 +08001327 if (!(sendingToBottom || getDisplayContent().mClosingApps.contains(this))
1328 && (isVisible() || getDisplayContent().mOpeningApps.contains(this))) {
Bryce Leea163b762017-01-24 11:05:01 -08001329 return mOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001330 }
Bryce Leea163b762017-01-24 11:05:01 -08001331
1332 return SCREEN_ORIENTATION_UNSET;
Wale Ogunwale51362492016-09-08 17:49:17 -07001333 }
1334
Wale Ogunwaleb198b742016-12-01 08:44:09 -08001335 /** Returns the app's preferred orientation regardless of its currently visibility state. */
1336 int getOrientationIgnoreVisibility() {
1337 return mOrientation;
1338 }
1339
Craig Mautnerdbb79912012-03-01 18:59:14 -08001340 @Override
Winson Chunge55c0192017-08-24 14:50:48 -07001341 public void onConfigurationChanged(Configuration newParentConfig) {
1342 final int prevWinMode = getWindowingMode();
1343 super.onConfigurationChanged(newParentConfig);
1344 final int winMode = getWindowingMode();
1345
1346 if (prevWinMode == winMode) {
1347 return;
1348 }
1349
1350 if (prevWinMode != WINDOWING_MODE_UNDEFINED && winMode == WINDOWING_MODE_PINNED) {
1351 // Entering PiP from fullscreen, reset the snap fraction
1352 mDisplayContent.mPinnedStackControllerLocked.resetReentrySnapFraction(this);
Winson Chung82267ce2018-04-06 16:38:26 -07001353 } else if (prevWinMode == WINDOWING_MODE_PINNED && winMode != WINDOWING_MODE_UNDEFINED
1354 && !isHidden()) {
Winson Chunge55c0192017-08-24 14:50:48 -07001355 // Leaving PiP to fullscreen, save the snap fraction based on the pre-animation bounds
1356 // for the next re-entry into PiP (assuming the activity is not hidden or destroyed)
1357 final TaskStack pinnedStack = mDisplayContent.getPinnedStack();
1358 if (pinnedStack != null) {
Winson Chung8efa1652018-06-06 09:34:23 -07001359 final Rect stackBounds;
1360 if (pinnedStack.lastAnimatingBoundsWasToFullscreen()) {
1361 // We are animating the bounds, use the pre-animation bounds to save the snap
1362 // fraction
1363 stackBounds = pinnedStack.mPreAnimationBounds;
1364 } else {
1365 // We skip the animation if the fullscreen configuration is not compatible, so
1366 // use the current bounds to calculate the saved snap fraction instead
1367 // (see PinnedActivityStack.skipResizeAnimation())
1368 stackBounds = mTmpRect;
1369 pinnedStack.getBounds(stackBounds);
1370 }
Winson Chunge55c0192017-08-24 14:50:48 -07001371 mDisplayContent.mPinnedStackControllerLocked.saveReentrySnapFraction(this,
Winson Chung8efa1652018-06-06 09:34:23 -07001372 stackBounds);
Winson Chunge55c0192017-08-24 14:50:48 -07001373 }
1374 }
1375 }
1376
1377 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001378 void checkAppWindowsReadyToShow() {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001379 if (allDrawn == mLastAllDrawn) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001380 return;
1381 }
1382
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001383 mLastAllDrawn = allDrawn;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001384 if (!allDrawn) {
1385 return;
1386 }
1387
1388 // The token has now changed state to having all windows shown... what to do, what to do?
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001389 if (mFreezingScreen) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001390 showAllWindowsLocked();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001391 stopFreezingScreen(false, true);
1392 if (DEBUG_ORIENTATION) Slog.i(TAG,
1393 "Setting mOrientationChangeComplete=true because wtoken " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001394 + " numInteresting=" + mNumInterestingWindows + " numDrawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001395 // This will set mOrientationChangeComplete and cause a pass through layout.
1396 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001397 "checkAppWindowsReadyToShow: freezingScreen");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001398 } else {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001399 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001400
1401 // We can now show all of the drawn windows!
lumark588a3e82018-07-20 18:53:54 +08001402 if (!getDisplayContent().mOpeningApps.contains(this) && canShowWindows()) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001403 showAllWindowsLocked();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001404 }
1405 }
1406 }
1407
Matthew Ng5d23afa2017-06-21 16:16:24 -07001408 /**
Bryce Leed390deb2017-06-22 13:14:28 -07001409 * Returns whether the drawn window states of this {@link AppWindowToken} has considered every
1410 * child {@link WindowState}. A child is considered if it has been passed into
1411 * {@link #updateDrawnWindowStates(WindowState)} after being added. This is used to determine
1412 * whether states, such as {@code allDrawn}, can be set, which relies on state variables such as
1413 * {@code mNumInterestingWindows}, which depend on all {@link WindowState}s being considered.
1414 *
1415 * @return {@code true} If all children have been considered, {@code false}.
1416 */
1417 private boolean allDrawnStatesConsidered() {
Bryce Lee6311c4b2017-07-06 14:09:29 -07001418 for (int i = mChildren.size() - 1; i >= 0; --i) {
1419 final WindowState child = mChildren.get(i);
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001420 if (child.mightAffectAllDrawn() && !child.getDrawnStateEvaluated()) {
Bryce Leed390deb2017-06-22 13:14:28 -07001421 return false;
1422 }
1423 }
1424 return true;
1425 }
1426
1427 /**
Matthew Ng5d23afa2017-06-21 16:16:24 -07001428 * Determines if the token has finished drawing. This should only be called from
1429 * {@link DisplayContent#applySurfaceChangesTransaction}
1430 */
Matthew Ng498c71d2017-04-18 13:55:45 -07001431 void updateAllDrawn() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001432 if (!allDrawn) {
Matthew Ng498c71d2017-04-18 13:55:45 -07001433 // Number of drawn windows can be less when a window is being relaunched, wait for
Bryce Leed390deb2017-06-22 13:14:28 -07001434 // all windows to be launched and drawn for this token be considered all drawn.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001435 final int numInteresting = mNumInterestingWindows;
Bryce Leed390deb2017-06-22 13:14:28 -07001436
1437 // We must make sure that all present children have been considered (determined by
1438 // {@link #allDrawnStatesConsidered}) before evaluating whether everything has been
1439 // drawn.
1440 if (numInteresting > 0 && allDrawnStatesConsidered()
1441 && mNumDrawnWindows >= numInteresting && !isRelaunching()) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001442 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawn: " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001443 + " interesting=" + numInteresting + " drawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001444 allDrawn = true;
1445 // Force an additional layout pass where
1446 // WindowStateAnimator#commitFinishDrawingLocked() will call performShowLocked().
Matthew Ng498c71d2017-04-18 13:55:45 -07001447 if (mDisplayContent != null) {
1448 mDisplayContent.setLayoutNeeded();
1449 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001450 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Robert Carrecc06b32017-04-18 14:25:10 -07001451
Winson Chunge7ba6862017-05-24 12:13:33 -07001452 // Notify the pinned stack upon all windows drawn. If there was an animation in
1453 // progress then this signal will resume that animation.
Wale Ogunwale61911492017-10-11 08:50:50 -07001454 final TaskStack pinnedStack = mDisplayContent.getPinnedStack();
Winson Chunge7ba6862017-05-24 12:13:33 -07001455 if (pinnedStack != null) {
1456 pinnedStack.onAllWindowsDrawn();
Robert Carrecc06b32017-04-18 14:25:10 -07001457 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001458 }
1459 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001460 }
1461
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001462 /**
1463 * Updated this app token tracking states for interesting and drawn windows based on the window.
1464 *
1465 * @return Returns true if the input window is considered interesting and drawn while all the
1466 * windows in this app token where not considered drawn as of the last pass.
1467 */
1468 boolean updateDrawnWindowStates(WindowState w) {
Bryce Leed390deb2017-06-22 13:14:28 -07001469 w.setDrawnStateEvaluated(true /*evaluated*/);
1470
Jorim Jaggie4b0f282017-05-17 15:10:29 +02001471 if (DEBUG_STARTING_WINDOW_VERBOSE && w == startingWindow) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001472 Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" + w.isOnScreen()
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001473 + " allDrawn=" + allDrawn + " freezingScreen=" + mFreezingScreen);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001474 }
1475
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001476 if (allDrawn && !mFreezingScreen) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001477 return false;
1478 }
1479
1480 if (mLastTransactionSequence != mService.mTransactionSequence) {
1481 mLastTransactionSequence = mService.mTransactionSequence;
Matthew Ng53e66b22018-01-12 17:13:13 -08001482 mNumDrawnWindows = 0;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001483 startingDisplayed = false;
Matthew Ng53e66b22018-01-12 17:13:13 -08001484
1485 // There is the main base application window, even if it is exiting, wait for it
1486 mNumInterestingWindows = findMainWindow(false /* includeStartingApp */) != null ? 1 : 0;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001487 }
1488
1489 final WindowStateAnimator winAnimator = w.mWinAnimator;
1490
1491 boolean isInterestingAndDrawn = false;
1492
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001493 if (!allDrawn && w.mightAffectAllDrawn()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001494 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
1495 Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw()
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001496 + ", isAnimationSet=" + isSelfAnimating());
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001497 if (!w.isDrawnLw()) {
1498 Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController
1499 + " pv=" + w.mPolicyVisibility
1500 + " mDrawState=" + winAnimator.drawStateToString()
1501 + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001502 + " a=" + isSelfAnimating());
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001503 }
1504 }
1505
1506 if (w != startingWindow) {
1507 if (w.isInteresting()) {
Matthew Ng53e66b22018-01-12 17:13:13 -08001508 // Add non-main window as interesting since the main app has already been added
1509 if (findMainWindow(false /* includeStartingApp */) != w) {
1510 mNumInterestingWindows++;
1511 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001512 if (w.isDrawnLw()) {
1513 mNumDrawnWindows++;
1514
1515 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, "tokenMayBeDrawn: "
1516 + this + " w=" + w + " numInteresting=" + mNumInterestingWindows
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001517 + " freezingScreen=" + mFreezingScreen
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001518 + " mAppFreezing=" + w.mAppFreezing);
1519
1520 isInterestingAndDrawn = true;
1521 }
1522 }
1523 } else if (w.isDrawnLw()) {
Jorim Jaggi3878ca32017-02-02 17:13:05 -08001524 if (getController() != null) {
1525 getController().reportStartingWindowDrawn();
1526 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001527 startingDisplayed = true;
1528 }
1529 }
1530
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001531 return isInterestingAndDrawn;
1532 }
1533
Adrian Roos23df3a32018-03-15 15:41:13 +01001534 void layoutLetterbox(WindowState winHint) {
Adrian Roos4d18a2e2017-12-19 19:08:05 +01001535 final WindowState w = findMainWindow();
Adrian Roosf93b6d22018-03-21 13:48:26 +01001536 if (w == null || winHint != null && w != winHint) {
Adrian Roos4d18a2e2017-12-19 19:08:05 +01001537 return;
1538 }
Jorim Jaggia32da382018-03-28 18:01:22 +02001539 final boolean surfaceReady = w.isDrawnLw() // Regular case
Adrian Roosf93b6d22018-03-21 13:48:26 +01001540 || w.mWinAnimator.mSurfaceDestroyDeferred // The preserved surface is still ready.
1541 || w.isDragResizeChanged(); // Waiting for relayoutWindow to call preserveSurface.
1542 final boolean needsLetterbox = w.isLetterboxedAppWindow() && fillsParent() && surfaceReady;
Adrian Roos4d18a2e2017-12-19 19:08:05 +01001543 if (needsLetterbox) {
1544 if (mLetterbox == null) {
1545 mLetterbox = new Letterbox(() -> makeChildSurface(null));
1546 }
chaviw492139a2018-07-16 16:07:35 -07001547 mLetterbox.layout(getParent().getBounds(), w.getFrameLw());
Adrian Roos4d18a2e2017-12-19 19:08:05 +01001548 } else if (mLetterbox != null) {
Adrian Roos23df3a32018-03-15 15:41:13 +01001549 mLetterbox.hide();
1550 }
1551 }
1552
1553 void updateLetterboxSurface(WindowState winHint) {
1554 final WindowState w = findMainWindow();
1555 if (w != winHint && winHint != null && w != null) {
1556 return;
1557 }
1558 layoutLetterbox(winHint);
1559 if (mLetterbox != null && mLetterbox.needsApplySurfaceChanges()) {
1560 mLetterbox.applySurfaceChanges(mPendingTransaction);
Adrian Roos4d18a2e2017-12-19 19:08:05 +01001561 }
1562 }
1563
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001564 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001565 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001566 // For legacy reasons we process the TaskStack.mExitingAppTokens first in DisplayContent
1567 // before the non-exiting app tokens. So, we skip the exiting app tokens here.
1568 // TODO: Investigate if we need to continue to do this or if we can just process them
1569 // in-order.
1570 if (mIsExiting && !waitingForReplacement()) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001571 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001572 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001573 return forAllWindowsUnchecked(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001574 }
1575
lumark588a3e82018-07-20 18:53:54 +08001576 @Override
1577 void forAllAppWindows(Consumer<AppWindowToken> callback) {
1578 callback.accept(this);
1579 }
1580
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001581 boolean forAllWindowsUnchecked(ToBooleanFunction<WindowState> callback,
1582 boolean traverseTopToBottom) {
1583 return super.forAllWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001584 }
1585
1586 @Override
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001587 AppWindowToken asAppWindowToken() {
1588 // I am an app window token!
1589 return this;
1590 }
1591
1592 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -07001593 boolean fillsParent() {
1594 return mFillsParent;
1595 }
1596
1597 void setFillsParent(boolean fillsParent) {
1598 mFillsParent = fillsParent;
1599 }
1600
Jorim Jaggife762342016-10-13 14:33:27 +02001601 boolean containsDismissKeyguardWindow() {
Bryce Lee081554b2017-05-25 07:52:12 -07001602 // Window state is transient during relaunch. We are not guaranteed to be frozen during the
1603 // entirety of the relaunch.
1604 if (isRelaunching()) {
1605 return mLastContainsDismissKeyguardWindow;
1606 }
1607
Jorim Jaggife762342016-10-13 14:33:27 +02001608 for (int i = mChildren.size() - 1; i >= 0; i--) {
1609 if ((mChildren.get(i).mAttrs.flags & FLAG_DISMISS_KEYGUARD) != 0) {
1610 return true;
1611 }
1612 }
1613 return false;
1614 }
1615
1616 boolean containsShowWhenLockedWindow() {
Bryce Lee081554b2017-05-25 07:52:12 -07001617 // When we are relaunching, it is possible for us to be unfrozen before our previous
1618 // windows have been added back. Using the cached value ensures that our previous
1619 // showWhenLocked preference is honored until relaunching is complete.
1620 if (isRelaunching()) {
1621 return mLastContainsShowWhenLockedWindow;
1622 }
1623
Jorim Jaggife762342016-10-13 14:33:27 +02001624 for (int i = mChildren.size() - 1; i >= 0; i--) {
1625 if ((mChildren.get(i).mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
1626 return true;
1627 }
1628 }
Bryce Lee081554b2017-05-25 07:52:12 -07001629
Jorim Jaggife762342016-10-13 14:33:27 +02001630 return false;
1631 }
1632
1633 void checkKeyguardFlagsChanged() {
1634 final boolean containsDismissKeyguard = containsDismissKeyguardWindow();
1635 final boolean containsShowWhenLocked = containsShowWhenLockedWindow();
1636 if (containsDismissKeyguard != mLastContainsDismissKeyguardWindow
1637 || containsShowWhenLocked != mLastContainsShowWhenLockedWindow) {
lumark588a3e82018-07-20 18:53:54 +08001638 mService.notifyKeyguardFlagsChanged(null /* callback */,
1639 getDisplayContent().getDisplayId());
Jorim Jaggife762342016-10-13 14:33:27 +02001640 }
1641 mLastContainsDismissKeyguardWindow = containsDismissKeyguard;
1642 mLastContainsShowWhenLockedWindow = containsShowWhenLocked;
1643 }
1644
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001645 WindowState getImeTargetBelowWindow(WindowState w) {
1646 final int index = mChildren.indexOf(w);
1647 if (index > 0) {
1648 final WindowState target = mChildren.get(index - 1);
1649 if (target.canBeImeTarget()) {
1650 return target;
1651 }
1652 }
1653 return null;
1654 }
1655
1656 WindowState getHighestAnimLayerWindow(WindowState currentTarget) {
1657 WindowState candidate = null;
1658 for (int i = mChildren.indexOf(currentTarget); i >= 0; i--) {
1659 final WindowState w = mChildren.get(i);
1660 if (w.mRemoved) {
1661 continue;
1662 }
Jorim Jaggi35d328a2018-08-14 17:00:20 +02001663 if (candidate == null) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001664 candidate = w;
1665 }
1666 }
1667 return candidate;
1668 }
1669
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001670 /**
1671 * See {@link Activity#setDisablePreviewScreenshots}.
1672 */
1673 void setDisablePreviewScreenshots(boolean disable) {
Wale Ogunwale6c459212017-05-17 08:56:03 -07001674 mDisablePreviewScreenshots = disable;
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001675 }
1676
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001677 /**
chaviwd3bf08d2017-08-01 17:24:59 -07001678 * Sets whether the current launch can turn the screen on. See {@link #canTurnScreenOn()}
1679 */
1680 void setCanTurnScreenOn(boolean canTurnScreenOn) {
1681 mCanTurnScreenOn = canTurnScreenOn;
1682 }
1683
1684 /**
1685 * Indicates whether the current launch can turn the screen on. This is to prevent multiple
1686 * relayouts from turning the screen back on. The screen should only turn on at most
1687 * once per activity resume.
1688 *
1689 * @return true if the screen can be turned on.
1690 */
1691 boolean canTurnScreenOn() {
1692 return mCanTurnScreenOn;
1693 }
1694
1695 /**
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001696 * Retrieves whether we'd like to generate a snapshot that's based solely on the theme. This is
1697 * the case when preview screenshots are disabled {@link #setDisablePreviewScreenshots} or when
1698 * we can't take a snapshot for other reasons, for example, if we have a secure window.
1699 *
1700 * @return True if we need to generate an app theme snapshot, false if we'd like to take a real
1701 * screenshot.
1702 */
1703 boolean shouldUseAppThemeSnapshot() {
Wale Ogunwale6c459212017-05-17 08:56:03 -07001704 return mDisablePreviewScreenshots || forAllWindows(w -> (w.mAttrs.flags & FLAG_SECURE) != 0,
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001705 true /* topToBottom */);
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001706 }
1707
Jorim Jaggibe418292018-03-26 16:14:12 +02001708 SurfaceControl getAppAnimationLayer() {
Jorim Jaggi391790622018-04-18 15:30:44 +02001709 return getAppAnimationLayer(isActivityTypeHome() ? ANIMATION_LAYER_HOME
1710 : needsZBoost() ? ANIMATION_LAYER_BOOSTED
1711 : ANIMATION_LAYER_STANDARD);
Jorim Jaggibe418292018-03-26 16:14:12 +02001712 }
1713
chaviw23ee71c2017-12-18 11:29:41 -08001714 @Override
Jorim Jaggi596a1992017-12-29 14:48:02 +01001715 public SurfaceControl getAnimationLeashParent() {
Robert Carrb9506032018-02-13 13:54:00 -08001716 // All normal app transitions take place in an animation layer which is below the pinned
1717 // stack but may be above the parent stacks of the given animating apps.
1718 // For transitions in the pinned stack (menu activity) we just let them occur as a child
1719 // of the pinned stack.
1720 if (!inPinnedWindowingMode()) {
1721 return getAppAnimationLayer();
1722 } else {
1723 return getStack().getSurfaceControl();
1724 }
chaviw23ee71c2017-12-18 11:29:41 -08001725 }
1726
Jorim Jaggic6976f02018-04-18 16:31:07 +02001727 private boolean shouldAnimate(int transit) {
1728 final boolean isSplitScreenPrimary =
1729 getWindowingMode() == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY;
1730 final boolean allowSplitScreenPrimaryAnimation = transit != TRANSIT_WALLPAPER_OPEN;
1731
1732 // We animate always if it's not split screen primary, and only some special cases in split
1733 // screen primary because it causes issues with stack clipping when we run an un-minimize
1734 // animation at the same time.
1735 return !isSplitScreenPrimary || allowSplitScreenPrimaryAnimation;
1736 }
1737
Vishnu Naira2977262018-07-26 13:31:26 -07001738 /**
1739 * Creates a layer to apply crop to an animation.
1740 */
1741 private SurfaceControl createAnimationBoundsLayer(Transaction t) {
1742 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.i(TAG, "Creating animation bounds layer");
1743 final SurfaceControl.Builder builder = makeAnimationLeash()
1744 .setParent(getAnimationLeashParent())
1745 .setName(getSurfaceControl() + " - animation-bounds")
1746 .setSize(getSurfaceWidth(), getSurfaceHeight());
1747 final SurfaceControl boundsLayer = builder.build();
1748 t.show(boundsLayer);
1749 return boundsLayer;
1750 }
1751
Riddle Hsua118b3a2018-10-11 22:05:06 +08001752 /** Get position and crop region of animation. */
1753 @VisibleForTesting
1754 void getAnimationBounds(Point outPosition, Rect outBounds) {
1755 outPosition.set(0, 0);
1756 outBounds.setEmpty();
1757
1758 final TaskStack stack = getStack();
1759 final Task task = getTask();
1760 if (task != null && task.inFreeformWindowingMode()) {
1761 task.getRelativePosition(outPosition);
1762 } else if (stack != null) {
1763 stack.getRelativePosition(outPosition);
1764 }
1765
1766 // Always use stack bounds in order to have the ability to animate outside the task region.
1767 // It also needs to be consistent when {@link #mNeedsAnimationBoundsLayer} is set that crops
1768 // according to the bounds.
1769 if (stack != null) {
1770 stack.getBounds(outBounds);
1771 }
1772 // We have the relative position so the local position can be removed from bounds.
1773 outBounds.offsetTo(0, 0);
1774 }
1775
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001776 boolean applyAnimationLocked(WindowManager.LayoutParams lp, int transit, boolean enter,
1777 boolean isVoiceInteraction) {
1778
Jorim Jaggic6976f02018-04-18 16:31:07 +02001779 if (mService.mDisableTransitionAnimation || !shouldAnimate(transit)) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001780 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
Jorim Jaggic6976f02018-04-18 16:31:07 +02001781 Slog.v(TAG_WM, "applyAnimation: transition animation is disabled or skipped."
1782 + " atoken=" + this);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001783 }
1784 cancelAnimation();
1785 return false;
1786 }
1787
1788 // Only apply an animation if the display isn't frozen. If it is frozen, there is no reason
1789 // to animate and it can cause strange artifacts when we unfreeze the display if some
1790 // different animation is running.
1791 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "AWT#applyAnimationLocked");
1792 if (okToAnimate()) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001793 final AnimationAdapter adapter;
Riddle Hsua118b3a2018-10-11 22:05:06 +08001794 getAnimationBounds(mTmpPoint, mTmpRect);
Jorim Jaggic4d29f22018-03-22 16:30:56 +01001795
1796 // Delaying animation start isn't compatible with remote animations at all.
lumark588a3e82018-07-20 18:53:54 +08001797 if (getDisplayContent().mAppTransition.getRemoteAnimationController() != null
Jorim Jaggic4d29f22018-03-22 16:30:56 +01001798 && !mSurfaceAnimator.isAnimationStartDelayed()) {
lumark588a3e82018-07-20 18:53:54 +08001799 adapter = getDisplayContent().mAppTransition.getRemoteAnimationController()
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001800 .createAnimationAdapter(this, mTmpPoint, mTmpRect);
1801 } else {
lumark588a3e82018-07-20 18:53:54 +08001802 final int appStackClipMode =
1803 getDisplayContent().mAppTransition.getAppStackClipMode();
Vishnu Naira2977262018-07-26 13:31:26 -07001804 mNeedsAnimationBoundsLayer = (appStackClipMode == STACK_CLIP_AFTER_ANIM);
1805
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001806 final Animation a = loadAnimation(lp, transit, enter, isVoiceInteraction);
1807 if (a != null) {
1808 adapter = new LocalAnimationAdapter(
1809 new WindowAnimationSpec(a, mTmpPoint, mTmpRect,
lumark588a3e82018-07-20 18:53:54 +08001810 getDisplayContent().mAppTransition.canSkipFirstFrame(),
Vishnu Naira2977262018-07-26 13:31:26 -07001811 appStackClipMode,
Jorim Jaggiaa763cd2018-03-22 23:20:36 +01001812 true /* isAppAnimation */),
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001813 mService.mSurfaceAnimationRunner);
1814 if (a.getZAdjustment() == Animation.ZORDER_TOP) {
1815 mNeedsZBoost = true;
1816 }
1817 mTransit = transit;
lumark588a3e82018-07-20 18:53:54 +08001818 mTransitFlags = getDisplayContent().mAppTransition.getTransitFlags();
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001819 } else {
1820 adapter = null;
chaviw23ee71c2017-12-18 11:29:41 -08001821 }
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001822 }
1823 if (adapter != null) {
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001824 startAnimation(getPendingTransaction(), adapter, !isVisible());
Jorim Jaggi82c17862018-02-21 17:50:18 +01001825 if (adapter.getShowWallpaper()) {
1826 mDisplayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
1827 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001828 }
1829 } else {
1830 cancelAnimation();
1831 }
1832 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
1833
1834 return isReallyAnimating();
1835 }
1836
1837 private Animation loadAnimation(WindowManager.LayoutParams lp, int transit, boolean enter,
1838 boolean isVoiceInteraction) {
1839 final DisplayContent displayContent = getTask().getDisplayContent();
1840 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
1841 final int width = displayInfo.appWidth;
1842 final int height = displayInfo.appHeight;
1843 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG_WM,
1844 "applyAnimation: atoken=" + this);
1845
1846 // Determine the visible rect to calculate the thumbnail clip
1847 final WindowState win = findMainWindow();
1848 final Rect frame = new Rect(0, 0, width, height);
1849 final Rect displayFrame = new Rect(0, 0,
1850 displayInfo.logicalWidth, displayInfo.logicalHeight);
1851 final Rect insets = new Rect();
1852 final Rect stableInsets = new Rect();
1853 Rect surfaceInsets = null;
1854 final boolean freeform = win != null && win.inFreeformWindowingMode();
1855 if (win != null) {
1856 // Containing frame will usually cover the whole screen, including dialog windows.
1857 // For freeform workspace windows it will not cover the whole screen and it also
1858 // won't exactly match the final freeform window frame (e.g. when overlapping with
1859 // the status bar). In that case we need to use the final frame.
1860 if (freeform) {
chaviw492139a2018-07-16 16:07:35 -07001861 frame.set(win.getFrameLw());
Adrian Roos4d18a2e2017-12-19 19:08:05 +01001862 } else if (win.isLetterboxedAppWindow()) {
1863 frame.set(getTask().getBounds());
Winson Chungc1674272018-02-21 10:15:17 -08001864 } else if (win.isDockedResizing()) {
1865 // If we are animating while docked resizing, then use the stack bounds as the
1866 // animation target (which will be different than the task bounds)
1867 frame.set(getTask().getParent().getBounds());
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001868 } else {
chaviw553b0212018-07-12 13:37:01 -07001869 frame.set(win.getContainingFrame());
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001870 }
1871 surfaceInsets = win.getAttrs().surfaceInsets;
Adrian Roos20e07892018-02-23 19:12:01 +01001872 // XXX(b/72757033): These are insets relative to the window frame, but we're really
1873 // interested in the insets relative to the frame we chose in the if-blocks above.
chaviw9c81e632018-07-31 11:17:52 -07001874 win.getContentInsets(insets);
1875 win.getStableInsets(stableInsets);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001876 }
1877
1878 if (mLaunchTaskBehind) {
1879 // Differentiate the two animations. This one which is briefly on the screen
1880 // gets the !enter animation, and the other activity which remains on the
1881 // screen gets the enter animation. Both appear in the mOpeningApps set.
1882 enter = false;
1883 }
1884 if (DEBUG_APP_TRANSITIONS) Slog.d(TAG_WM, "Loading animation for app transition."
1885 + " transit=" + AppTransition.appTransitionToString(transit) + " enter=" + enter
1886 + " frame=" + frame + " insets=" + insets + " surfaceInsets=" + surfaceInsets);
1887 final Configuration displayConfig = displayContent.getConfiguration();
lumark588a3e82018-07-20 18:53:54 +08001888 final Animation a = getDisplayContent().mAppTransition.loadAnimation(lp, transit, enter,
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001889 displayConfig.uiMode, displayConfig.orientation, frame, displayFrame, insets,
1890 surfaceInsets, stableInsets, isVoiceInteraction, freeform, getTask().mTaskId);
1891 if (a != null) {
1892 if (DEBUG_ANIM) logWithStack(TAG, "Loaded animation " + a + " for " + this);
1893 final int containingWidth = frame.width();
1894 final int containingHeight = frame.height();
1895 a.initialize(containingWidth, containingHeight, width, height);
1896 a.scaleCurrentDuration(mService.getTransitionAnimationScaleLocked());
1897 }
1898 return a;
1899 }
1900
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001901 @Override
Jorim Jaggi6de61012018-03-19 14:53:23 +01001902 public boolean shouldDeferAnimationFinish(Runnable endDeferFinishCallback) {
1903 return mAnimatingAppWindowTokenRegistry != null
1904 && mAnimatingAppWindowTokenRegistry.notifyAboutToFinish(
1905 this, endDeferFinishCallback);
1906 }
1907
1908 @Override
1909 public void onAnimationLeashDestroyed(Transaction t) {
1910 super.onAnimationLeashDestroyed(t);
Vishnu Naira2977262018-07-26 13:31:26 -07001911 if (mAnimationBoundsLayer != null) {
1912 t.destroy(mAnimationBoundsLayer);
1913 mAnimationBoundsLayer = null;
1914 }
1915
Jorim Jaggi6de61012018-03-19 14:53:23 +01001916 if (mAnimatingAppWindowTokenRegistry != null) {
1917 mAnimatingAppWindowTokenRegistry.notifyFinished(this);
1918 }
1919 }
1920
1921 @Override
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001922 protected void setLayer(Transaction t, int layer) {
1923 if (!mSurfaceAnimator.hasLeash()) {
1924 t.setLayer(mSurfaceControl, layer);
1925 }
1926 }
1927
1928 @Override
1929 protected void setRelativeLayer(Transaction t, SurfaceControl relativeTo, int layer) {
1930 if (!mSurfaceAnimator.hasLeash()) {
1931 t.setRelativeLayer(mSurfaceControl, relativeTo, layer);
1932 }
1933 }
1934
1935 @Override
1936 protected void reparentSurfaceControl(Transaction t, SurfaceControl newParent) {
1937 if (!mSurfaceAnimator.hasLeash()) {
1938 t.reparent(mSurfaceControl, newParent.getHandle());
1939 }
1940 }
1941
1942 @Override
1943 public void onAnimationLeashCreated(Transaction t, SurfaceControl leash) {
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001944 // The leash is parented to the animation layer. We need to preserve the z-order by using
1945 // the prefix order index, but we boost if necessary.
Robert Carrb9506032018-02-13 13:54:00 -08001946 int layer = 0;
1947 if (!inPinnedWindowingMode()) {
1948 layer = getPrefixOrderIndex();
1949 } else {
1950 // Pinned stacks have animations take place within themselves rather than an animation
1951 // layer so we need to preserve the order relative to the stack (e.g. the order of our
1952 // task/parent).
1953 layer = getParent().getPrefixOrderIndex();
1954 }
1955
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001956 if (mNeedsZBoost) {
1957 layer += Z_BOOST_BASE;
1958 }
1959 leash.setLayer(layer);
Robert Carr2f8aa392018-01-31 14:46:51 -08001960
1961 final DisplayContent dc = getDisplayContent();
Jorim Jaggibe418292018-03-26 16:14:12 +02001962 dc.assignStackOrdering();
Jorim Jaggi6de61012018-03-19 14:53:23 +01001963 if (mAnimatingAppWindowTokenRegistry != null) {
1964 mAnimatingAppWindowTokenRegistry.notifyStarting(this);
1965 }
Vishnu Naira2977262018-07-26 13:31:26 -07001966
1967 // If the animation needs to be cropped then an animation bounds layer is created as a child
1968 // of the pinned stack or animation layer. The leash is then reparented to this new layer.
1969 if (mNeedsAnimationBoundsLayer) {
1970 final TaskStack stack = getStack();
1971 if (stack == null) {
1972 return;
1973 }
1974 mAnimationBoundsLayer = createAnimationBoundsLayer(t);
1975
1976 // Set clip rect to stack bounds.
1977 mTmpRect.setEmpty();
1978 stack.getBounds(mTmpRect);
1979
1980 // Crop to stack bounds.
1981 t.setWindowCrop(mAnimationBoundsLayer, mTmpRect);
1982
1983 // Reparent leash to animation bounds layer.
1984 t.reparent(leash, mAnimationBoundsLayer.getHandle());
1985 }
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001986 }
1987
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001988 /**
1989 * This must be called while inside a transaction.
1990 */
1991 void showAllWindowsLocked() {
1992 forAllWindows(windowState -> {
1993 if (DEBUG_VISIBILITY) Slog.v(TAG, "performing show on: " + windowState);
1994 windowState.performShowLocked();
1995 }, false /* traverseTopToBottom */);
Jorim Jaggia5e10572017-11-15 14:36:26 +01001996 }
1997
1998 @Override
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001999 protected void onAnimationFinished() {
2000 super.onAnimationFinished();
2001
2002 mTransit = TRANSIT_UNSET;
2003 mTransitFlags = 0;
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002004 mNeedsZBoost = false;
Vishnu Naira2977262018-07-26 13:31:26 -07002005 mNeedsAnimationBoundsLayer = false;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002006
2007 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM | FINISH_LAYOUT_REDO_WALLPAPER,
2008 "AppWindowToken");
2009
Jorim Jaggi988f6682017-11-17 17:46:43 +01002010 clearThumbnail();
Jorim Jaggi752cd822018-03-29 16:29:18 +02002011 setClientHidden(isHidden() && hiddenRequested);
Jorim Jaggi988f6682017-11-17 17:46:43 +01002012
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002013 if (mService.mInputMethodTarget != null && mService.mInputMethodTarget.mAppToken == this) {
2014 getDisplayContent().computeImeTarget(true /* updateImeTarget */);
2015 }
2016
2017 if (DEBUG_ANIM) Slog.v(TAG, "Animation done in " + this
2018 + ": reportedVisible=" + reportedVisible
2019 + " okToDisplay=" + okToDisplay()
2020 + " okToAnimate=" + okToAnimate()
2021 + " startingDisplayed=" + startingDisplayed);
2022
2023 // WindowState.onExitAnimationDone might modify the children list, so make a copy and then
2024 // traverse the copy.
2025 final ArrayList<WindowState> children = new ArrayList<>(mChildren);
2026 children.forEach(WindowState::onExitAnimationDone);
2027
lumark588a3e82018-07-20 18:53:54 +08002028 getDisplayContent().mAppTransition.notifyAppTransitionFinishedLocked(token);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002029 scheduleAnimation();
2030 }
2031
2032 @Override
2033 boolean isAppAnimating() {
2034 return isSelfAnimating();
2035 }
2036
2037 @Override
2038 boolean isSelfAnimating() {
2039 // If we are about to start a transition, we also need to be considered animating.
2040 return isWaitingForTransitionStart() || isReallyAnimating();
2041 }
2042
2043 /**
2044 * @return True if and only if we are actually running an animation. Note that
2045 * {@link #isSelfAnimating} also returns true if we are waiting for an animation to
2046 * start.
2047 */
2048 private boolean isReallyAnimating() {
2049 return super.isSelfAnimating();
2050 }
2051
Jorim Jaggi988f6682017-11-17 17:46:43 +01002052 @Override
2053 void cancelAnimation() {
2054 super.cancelAnimation();
2055 clearThumbnail();
2056 }
2057
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002058 boolean isWaitingForTransitionStart() {
lumark588a3e82018-07-20 18:53:54 +08002059 return getDisplayContent().mAppTransition.isTransitionSet()
2060 && (getDisplayContent().mOpeningApps.contains(this)
2061 || getDisplayContent().mClosingApps.contains(this));
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002062 }
2063
2064 public int getTransit() {
2065 return mTransit;
2066 }
2067
2068 int getTransitFlags() {
2069 return mTransitFlags;
2070 }
2071
Jorim Jaggi988f6682017-11-17 17:46:43 +01002072 void attachThumbnailAnimation() {
2073 if (!isReallyAnimating()) {
2074 return;
2075 }
2076 final int taskId = getTask().mTaskId;
2077 final GraphicBuffer thumbnailHeader =
lumark588a3e82018-07-20 18:53:54 +08002078 getDisplayContent().mAppTransition.getAppTransitionThumbnailHeader(taskId);
Jorim Jaggi988f6682017-11-17 17:46:43 +01002079 if (thumbnailHeader == null) {
2080 if (DEBUG_APP_TRANSITIONS) Slog.d(TAG, "No thumbnail header bitmap for: " + taskId);
2081 return;
2082 }
2083 clearThumbnail();
2084 mThumbnail = new AppWindowThumbnail(getPendingTransaction(), this, thumbnailHeader);
2085 mThumbnail.startAnimation(getPendingTransaction(), loadThumbnailAnimation(thumbnailHeader));
2086 }
2087
Tony Mak64b8d562017-12-28 17:44:02 +00002088 /**
2089 * Attaches a surface with a thumbnail for the
2090 * {@link android.app.ActivityOptions#ANIM_OPEN_CROSS_PROFILE_APPS} animation.
2091 */
2092 void attachCrossProfileAppsThumbnailAnimation() {
2093 if (!isReallyAnimating()) {
2094 return;
2095 }
2096 clearThumbnail();
2097
2098 final WindowState win = findMainWindow();
2099 if (win == null) {
2100 return;
2101 }
chaviw492139a2018-07-16 16:07:35 -07002102 final Rect frame = win.getFrameLw();
Tony Mak64b8d562017-12-28 17:44:02 +00002103 final int thumbnailDrawableRes = getTask().mUserId == mService.mCurrentUserId
2104 ? R.drawable.ic_account_circle
Tony Makda4af232018-04-27 11:01:10 +01002105 : R.drawable.ic_corp_badge;
Tony Mak64b8d562017-12-28 17:44:02 +00002106 final GraphicBuffer thumbnail =
lumark588a3e82018-07-20 18:53:54 +08002107 getDisplayContent().mAppTransition
Tony Mak64b8d562017-12-28 17:44:02 +00002108 .createCrossProfileAppsThumbnail(thumbnailDrawableRes, frame);
2109 if (thumbnail == null) {
2110 return;
2111 }
2112 mThumbnail = new AppWindowThumbnail(getPendingTransaction(), this, thumbnail);
2113 final Animation animation =
lumark588a3e82018-07-20 18:53:54 +08002114 getDisplayContent().mAppTransition.createCrossProfileAppsThumbnailAnimationLocked(
chaviw492139a2018-07-16 16:07:35 -07002115 win.getFrameLw());
Tony Mak64b8d562017-12-28 17:44:02 +00002116 mThumbnail.startAnimation(getPendingTransaction(), animation, new Point(frame.left,
2117 frame.top));
2118 }
2119
Jorim Jaggi988f6682017-11-17 17:46:43 +01002120 private Animation loadThumbnailAnimation(GraphicBuffer thumbnailHeader) {
2121 final DisplayInfo displayInfo = mDisplayContent.getDisplayInfo();
2122
2123 // If this is a multi-window scenario, we use the windows frame as
2124 // destination of the thumbnail header animation. If this is a full screen
2125 // window scenario, we use the whole display as the target.
2126 WindowState win = findMainWindow();
2127 Rect appRect = win != null ? win.getContentFrameLw() :
2128 new Rect(0, 0, displayInfo.appWidth, displayInfo.appHeight);
chaviw9c81e632018-07-31 11:17:52 -07002129 final Rect insets = win != null ? win.getContentInsets() : null;
Jorim Jaggi988f6682017-11-17 17:46:43 +01002130 final Configuration displayConfig = mDisplayContent.getConfiguration();
lumark588a3e82018-07-20 18:53:54 +08002131 return getDisplayContent().mAppTransition.createThumbnailAspectScaleAnimationLocked(
Jorim Jaggi988f6682017-11-17 17:46:43 +01002132 appRect, insets, thumbnailHeader, getTask().mTaskId, displayConfig.uiMode,
2133 displayConfig.orientation);
2134 }
2135
2136 private void clearThumbnail() {
2137 if (mThumbnail == null) {
2138 return;
2139 }
2140 mThumbnail.destroy();
2141 mThumbnail = null;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002142 }
2143
Jorim Jaggif84e2f62018-01-16 14:17:59 +01002144 void registerRemoteAnimations(RemoteAnimationDefinition definition) {
2145 mRemoteAnimationDefinition = definition;
2146 }
2147
2148 RemoteAnimationDefinition getRemoteAnimationDefinition() {
2149 return mRemoteAnimationDefinition;
2150 }
2151
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002152 @Override
2153 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
2154 super.dump(pw, prefix, dumpAll);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002155 if (appToken != null) {
Wale Ogunwale72919d22016-12-08 18:58:50 -08002156 pw.println(prefix + "app=true mVoiceInteraction=" + mVoiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002157 }
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08002158 pw.print(prefix); pw.print("task="); pw.println(getTask());
Wale Ogunwale51362492016-09-08 17:49:17 -07002159 pw.print(prefix); pw.print(" mFillsParent="); pw.print(mFillsParent);
2160 pw.print(" mOrientation="); pw.println(mOrientation);
Wale Ogunwale89973222017-04-23 18:39:45 -07002161 pw.println(prefix + "hiddenRequested=" + hiddenRequested + " mClientHidden=" + mClientHidden
2162 + ((mDeferHidingClient) ? " mDeferHidingClient=" + mDeferHidingClient : "")
2163 + " reportedDrawn=" + reportedDrawn + " reportedVisible=" + reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -07002164 if (paused) {
2165 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002166 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -08002167 if (mAppStopped) {
2168 pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped);
2169 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07002170 if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002171 || allDrawn || mLastAllDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07002172 pw.print(prefix); pw.print("mNumInterestingWindows=");
2173 pw.print(mNumInterestingWindows);
2174 pw.print(" mNumDrawnWindows="); pw.print(mNumDrawnWindows);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002175 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -07002176 pw.print(" allDrawn="); pw.print(allDrawn);
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002177 pw.print(" lastAllDrawn="); pw.print(mLastAllDrawn);
Craig Mautner6fbda632012-07-03 09:26:39 -07002178 pw.println(")");
2179 }
2180 if (inPendingTransaction) {
2181 pw.print(prefix); pw.print("inPendingTransaction=");
2182 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002183 }
Craig Mautner799bc1d2015-01-14 10:33:48 -08002184 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002185 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
2186 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -08002187 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -08002188 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002189 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08002190 if (startingWindow != null || startingSurface != null
Wale Ogunwale6c459212017-05-17 08:56:03 -07002191 || startingDisplayed || startingMoved || mHiddenSetFromTransferredStartingWindow) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002192 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08002193 pw.print(" startingSurface="); pw.print(startingSurface);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002194 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
Wale Ogunwale6c459212017-05-17 08:56:03 -07002195 pw.print(" startingMoved="); pw.print(startingMoved);
2196 pw.println(" mHiddenSetFromTransferredStartingWindow="
2197 + mHiddenSetFromTransferredStartingWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002198 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01002199 if (!mFrozenBounds.isEmpty()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -08002200 pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds);
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002201 pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig);
Chong Zhangd78ddb42016-03-02 17:01:14 -08002202 }
2203 if (mPendingRelaunchCount != 0) {
2204 pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount);
Jorim Jaggi0429f352015-12-22 16:29:16 +01002205 }
Wale Ogunwale9c64cb62017-04-12 13:39:59 -07002206 if (getController() != null) {
2207 pw.print(prefix); pw.print("controller="); pw.println(getController());
2208 }
Wale Ogunwalee287e192017-04-21 09:30:12 -07002209 if (mRemovingFromDisplay) {
2210 pw.println(prefix + "mRemovingFromDisplay=" + mRemovingFromDisplay);
2211 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002212 }
2213
2214 @Override
2215 void setHidden(boolean hidden) {
2216 super.setHidden(hidden);
Winson Chunge55c0192017-08-24 14:50:48 -07002217
2218 if (hidden) {
2219 // Once the app window is hidden, reset the last saved PiP snap fraction
2220 mDisplayContent.mPinnedStackControllerLocked.resetReentrySnapFraction(this);
2221 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002222 scheduleAnimation();
2223 }
2224
2225 @Override
2226 void prepareSurfaces() {
2227 // isSelfAnimating also returns true when we are about to start a transition, so we need
2228 // to check super here.
2229 final boolean reallyAnimating = super.isSelfAnimating();
2230 final boolean show = !isHidden() || reallyAnimating;
2231 if (show && !mLastSurfaceShowing) {
2232 mPendingTransaction.show(mSurfaceControl);
2233 } else if (!show && mLastSurfaceShowing) {
2234 mPendingTransaction.hide(mSurfaceControl);
Jorim Jaggi4d1835d2017-08-31 17:28:27 +02002235 }
Jorim Jaggi988f6682017-11-17 17:46:43 +01002236 if (mThumbnail != null) {
2237 mThumbnail.setShowing(mPendingTransaction, show);
2238 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002239 mLastSurfaceShowing = show;
2240 super.prepareSurfaces();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002241 }
2242
Jorim Jaggi77d0f36c2018-03-16 17:49:49 +01002243 /**
2244 * @return Whether our {@link #getSurfaceControl} is currently showing.
2245 */
2246 boolean isSurfaceShowing() {
2247 return mLastSurfaceShowing;
2248 }
2249
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002250 boolean isFreezingScreen() {
2251 return mFreezingScreen;
2252 }
2253
2254 @Override
2255 boolean needsZBoost() {
2256 return mNeedsZBoost || super.needsZBoost();
2257 }
2258
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07002259 @CallSuper
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002260 @Override
Adrian Roos4921ccf2017-09-28 16:54:06 +02002261 public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07002262 final long token = proto.start(fieldId);
2263 writeNameToProto(proto, NAME);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002264 super.writeToProto(proto, WINDOW_TOKEN, trim);
Vishnu Nair04ab4392018-01-10 11:00:06 -08002265 proto.write(LAST_SURFACE_SHOWING, mLastSurfaceShowing);
2266 proto.write(IS_WAITING_FOR_TRANSITION_START, isWaitingForTransitionStart());
2267 proto.write(IS_REALLY_ANIMATING, isReallyAnimating());
2268 if (mThumbnail != null){
2269 mThumbnail.writeToProto(proto, THUMBNAIL);
2270 }
2271 proto.write(FILLS_PARENT, mFillsParent);
2272 proto.write(APP_STOPPED, mAppStopped);
2273 proto.write(HIDDEN_REQUESTED, hiddenRequested);
2274 proto.write(CLIENT_HIDDEN, mClientHidden);
2275 proto.write(DEFER_HIDING_CLIENT, mDeferHidingClient);
2276 proto.write(REPORTED_DRAWN, reportedDrawn);
2277 proto.write(REPORTED_VISIBLE, reportedVisible);
2278 proto.write(NUM_INTERESTING_WINDOWS, mNumInterestingWindows);
2279 proto.write(NUM_DRAWN_WINDOWS, mNumDrawnWindows);
2280 proto.write(ALL_DRAWN, allDrawn);
2281 proto.write(LAST_ALL_DRAWN, mLastAllDrawn);
2282 proto.write(REMOVED, removed);
2283 if (startingWindow != null){
2284 startingWindow.writeIdentifierToProto(proto, STARTING_WINDOW);
2285 }
2286 proto.write(STARTING_DISPLAYED, startingDisplayed);
2287 proto.write(STARTING_MOVED, startingMoved);
2288 proto.write(HIDDEN_SET_FROM_TRANSFERRED_STARTING_WINDOW,
2289 mHiddenSetFromTransferredStartingWindow);
2290 for (Rect bounds : mFrozenBounds) {
2291 bounds.writeToProto(proto, FROZEN_BOUNDS);
2292 }
Steven Timotiusaf03df62017-07-18 16:56:43 -07002293 proto.end(token);
2294 }
2295
2296 void writeNameToProto(ProtoOutputStream proto, long fieldId) {
2297 if (appToken == null) {
2298 return;
2299 }
2300 try {
2301 proto.write(fieldId, appToken.getName());
2302 } catch (RemoteException e) {
2303 // This shouldn't happen, but in this case fall back to outputting nothing
2304 Slog.e(TAG, e.toString());
2305 }
2306 }
2307
2308 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002309 public String toString() {
2310 if (stringName == null) {
2311 StringBuilder sb = new StringBuilder();
2312 sb.append("AppWindowToken{");
2313 sb.append(Integer.toHexString(System.identityHashCode(this)));
2314 sb.append(" token="); sb.append(token); sb.append('}');
2315 stringName = sb.toString();
2316 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07002317 return stringName + ((mIsExiting) ? " mIsExiting=" : "");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002318 }
Adrian Roos20e07892018-02-23 19:12:01 +01002319
2320 Rect getLetterboxInsets() {
2321 if (mLetterbox != null) {
2322 return mLetterbox.getInsets();
2323 } else {
2324 return new Rect();
2325 }
2326 }
Adrian Roos23df3a32018-03-15 15:41:13 +01002327
2328 /**
2329 * @eturn true if there is a letterbox and any part of that letterbox overlaps with
2330 * the given {@code rect}.
2331 */
2332 boolean isLetterboxOverlappingWith(Rect rect) {
2333 return mLetterbox != null && mLetterbox.isOverlappingWith(rect);
2334 }
chaviw4ad54912018-05-30 11:05:44 -07002335
2336 /**
2337 * Sets if this AWT is in the process of closing or entering PIP.
2338 * {@link #mWillCloseOrEnterPip}}
2339 */
2340 void setWillCloseOrEnterPip(boolean willCloseOrEnterPip) {
2341 mWillCloseOrEnterPip = willCloseOrEnterPip;
2342 }
2343
2344 /**
2345 * Returns whether this AWT is considered closing. Conditions are either
2346 * 1. Is this app animating and was requested to be hidden
2347 * 2. App is delayed closing since it might enter PIP.
2348 */
2349 boolean isClosingOrEnteringPip() {
2350 return (isAnimating() && hiddenRequested) || mWillCloseOrEnterPip;
2351 }
Jorim Jaggiaf0d6d22018-06-08 15:25:35 +02002352
2353 /**
2354 * @return Whether we are allowed to show non-starting windows at the moment. We disallow
2355 * showing windows during transitions in case we have windows that have wide-color-gamut
2356 * color mode set to avoid jank in the middle of the transition.
2357 */
2358 boolean canShowWindows() {
2359 return allDrawn && !(isReallyAnimating() && hasNonDefaultColorWindow());
2360 }
2361
2362 /**
2363 * @return true if we have a window that has a non-default color mode set; false otherwise.
2364 */
2365 private boolean hasNonDefaultColorWindow() {
2366 return forAllWindows(ws -> ws.mAttrs.getColorMode() != COLOR_MODE_DEFAULT,
2367 true /* topToBottom */);
2368 }
lumark588a3e82018-07-20 18:53:54 +08002369
2370 void removeFromPendingTransition() {
2371 if (isWaitingForTransitionStart() && mDisplayContent != null) {
2372 mDisplayContent.mOpeningApps.remove(this);
2373 mDisplayContent.mClosingApps.remove(this);
2374 }
2375 }
Jeff Browne9bdb312012-04-05 15:30:10 -07002376}