blob: c15893bc6ae83b036960c6ea6315eb7cc54a72e6 [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;
20import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;
Wale Ogunwale72919d22016-12-08 18:58:50 -080021import static android.content.pm.ActivityInfo.CONFIG_ORIENTATION;
22import static android.content.pm.ActivityInfo.CONFIG_SCREEN_SIZE;
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -070023import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND;
Wale Ogunwale51362492016-09-08 17:49:17 -070024import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET;
Jorim Jaggif5f9e122017-10-24 18:21:09 +020025import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070026import static android.view.Display.DEFAULT_DISPLAY;
Jorim Jaggife762342016-10-13 14:33:27 +020027import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
Jorim Jaggid635a4a2017-05-03 15:21:26 +020028import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
Jorim Jaggife762342016-10-13 14:33:27 +020029import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
Wale Ogunwaled1c37912016-08-16 03:19:39 -070030import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080031import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070032import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
Tony Mak64b8d562017-12-28 17:44:02 +000033
Adrian Roose99bc052017-11-20 17:55:31 +010034import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
35import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Jorim Jaggif84e2f62018-01-16 14:17:59 +010036import static android.view.WindowManager.TRANSIT_UNSET;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080037import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080038import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
39import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070040import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070041import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
42import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
Wale Ogunwale9017ec02016-02-25 08:55:25 -080043import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
Jorim Jaggie4b0f282017-05-17 15:10:29 +020044import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW_VERBOSE;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070045import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TOKEN_MOVEMENT;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080046import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
47import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_MOVEMENT;
48import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
49import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Chong Zhang92147042016-05-09 12:47:11 -070050import static com.android.server.wm.WindowManagerService.H.NOTIFY_ACTIVITY_DRAWN;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070051import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070052import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070053import static com.android.server.wm.WindowManagerService.logWithStack;
Vishnu Nair04ab4392018-01-10 11:00:06 -080054import static com.android.server.wm.proto.AppWindowTokenProto.ALL_DRAWN;
55import static com.android.server.wm.proto.AppWindowTokenProto.APP_STOPPED;
56import static com.android.server.wm.proto.AppWindowTokenProto.CLIENT_HIDDEN;
57import static com.android.server.wm.proto.AppWindowTokenProto.DEFER_HIDING_CLIENT;
58import static com.android.server.wm.proto.AppWindowTokenProto.FILLS_PARENT;
59import static com.android.server.wm.proto.AppWindowTokenProto.FROZEN_BOUNDS;
60import static com.android.server.wm.proto.AppWindowTokenProto.HIDDEN_REQUESTED;
61import static com.android.server.wm.proto.AppWindowTokenProto.HIDDEN_SET_FROM_TRANSFERRED_STARTING_WINDOW;
62import static com.android.server.wm.proto.AppWindowTokenProto.IS_REALLY_ANIMATING;
63import static com.android.server.wm.proto.AppWindowTokenProto.IS_WAITING_FOR_TRANSITION_START;
64import static com.android.server.wm.proto.AppWindowTokenProto.LAST_ALL_DRAWN;
65import static com.android.server.wm.proto.AppWindowTokenProto.LAST_SURFACE_SHOWING;
Steven Timotiusaf03df62017-07-18 16:56:43 -070066import static com.android.server.wm.proto.AppWindowTokenProto.NAME;
Vishnu Nair04ab4392018-01-10 11:00:06 -080067import static com.android.server.wm.proto.AppWindowTokenProto.NUM_DRAWN_WINDOWS;
68import static com.android.server.wm.proto.AppWindowTokenProto.NUM_INTERESTING_WINDOWS;
69import static com.android.server.wm.proto.AppWindowTokenProto.REMOVED;
70import static com.android.server.wm.proto.AppWindowTokenProto.REPORTED_DRAWN;
71import static com.android.server.wm.proto.AppWindowTokenProto.REPORTED_VISIBLE;
72import static com.android.server.wm.proto.AppWindowTokenProto.STARTING_DISPLAYED;
73import static com.android.server.wm.proto.AppWindowTokenProto.STARTING_MOVED;
74import static com.android.server.wm.proto.AppWindowTokenProto.STARTING_WINDOW;
75import static com.android.server.wm.proto.AppWindowTokenProto.THUMBNAIL;
Steven Timotiusaf03df62017-07-18 16:56:43 -070076import static com.android.server.wm.proto.AppWindowTokenProto.WINDOW_TOKEN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080077
Wale Ogunwale0d5609b2017-09-13 05:55:07 -070078import android.annotation.CallSuper;
Jorim Jaggid635a4a2017-05-03 15:21:26 +020079import android.app.Activity;
Jorim Jaggi26c8c422016-05-09 19:57:25 -070080import android.content.res.Configuration;
Jorim Jaggi988f6682017-11-17 17:46:43 +010081import android.graphics.GraphicBuffer;
Jorim Jaggif5f9e122017-10-24 18:21:09 +020082import android.graphics.Point;
Jorim Jaggi0429f352015-12-22 16:29:16 +010083import android.graphics.Rect;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070084import android.os.Binder;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080085import android.os.Debug;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070086import android.os.IBinder;
Steven Timotiusaf03df62017-07-18 16:56:43 -070087import android.os.RemoteException;
Jorim Jaggif5f9e122017-10-24 18:21:09 +020088import android.os.Trace;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080089import android.util.Slog;
Steven Timotiusaf03df62017-07-18 16:56:43 -070090import android.util.proto.ProtoOutputStream;
Jorim Jaggif5f9e122017-10-24 18:21:09 +020091import android.view.DisplayInfo;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080092import android.view.IApplicationToken;
Jorim Jaggif84e2f62018-01-16 14:17:59 +010093import android.view.RemoteAnimationDefinition;
Robert Carr6914f082017-03-20 19:04:30 -070094import android.view.SurfaceControl;
Tony Mak64b8d562017-12-28 17:44:02 +000095import android.view.SurfaceControl.Transaction;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080096import android.view.WindowManager;
Jorim Jaggi87fdbcb2017-08-17 13:41:11 +020097import android.view.WindowManager.LayoutParams;
Tony Mak64b8d562017-12-28 17:44:02 +000098import android.view.animation.Animation;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080099
Tony Mak64b8d562017-12-28 17:44:02 +0000100import com.android.internal.R;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800101import com.android.internal.util.ToBooleanFunction;
102import com.android.server.input.InputApplicationHandle;
Adrian Roose99bc052017-11-20 17:55:31 +0100103import com.android.server.policy.WindowManagerPolicy.StartingSurface;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800104import com.android.server.wm.WindowManagerService.H;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800105
106import java.io.PrintWriter;
Jorim Jaggi0429f352015-12-22 16:29:16 +0100107import java.util.ArrayDeque;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800108import java.util.ArrayList;
109
110class AppTokenList extends ArrayList<AppWindowToken> {
111}
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800112
113/**
114 * Version of WindowToken that is specifically for a particular application (or
115 * really activity) that is displaying windows.
116 */
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700117class AppWindowToken extends WindowToken implements WindowManagerService.AppFreezeListener {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800118 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppWindowToken" : TAG_WM;
119
Jorim Jaggi619c9f72017-12-19 18:04:29 +0100120 /**
121 * Value to increment the z-layer when boosting a layer during animations. BOOST in l33tsp34k.
122 */
123 private static final int Z_BOOST_BASE = 800570000;
124
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800125 // Non-null only for application tokens.
126 final IApplicationToken appToken;
127
Wale Ogunwale72919d22016-12-08 18:58:50 -0800128 final boolean mVoiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700129
Wale Ogunwale51362492016-09-08 17:49:17 -0700130 /** @see WindowContainer#fillsParent() */
131 private boolean mFillsParent;
Craig Mautner4c5eb222013-11-18 12:59:05 -0800132 boolean layoutConfigChanges;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800133 boolean mShowForAllUsers;
134 int mTargetSdk;
Craig Mautnera2c77052012-03-26 12:14:43 -0700135
Bryce Lee6d410262017-02-28 15:30:17 -0800136 // Flag set while reparenting to prevent actions normally triggered by an individual parent
137 // change.
138 private boolean mReparenting;
139
Wale Ogunwalee287e192017-04-21 09:30:12 -0700140 // True if we are current in the process of removing this app token from the display
141 private boolean mRemovingFromDisplay = false;
142
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800143 // The input dispatching timeout for this application token in nanoseconds.
Wale Ogunwale72919d22016-12-08 18:58:50 -0800144 long mInputDispatchingTimeoutNanos;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800145
146 // These are used for determining when all windows associated with
147 // an activity have been drawn, so they can be made visible together
148 // at the same time.
Craig Mautner764983d2012-03-22 11:37:36 -0700149 // initialize so that it doesn't match mTransactionSequence which is an int.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700150 private long mLastTransactionSequence = Long.MIN_VALUE;
151 private int mNumInterestingWindows;
152 private int mNumDrawnWindows;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800153 boolean inPendingTransaction;
154 boolean allDrawn;
Jorim Jaggib0fc8172017-11-23 17:04:08 +0000155 private boolean mLastAllDrawn;
156
Craig Mautner7636dfb2012-11-16 15:24:11 -0800157 // Set to true when this app creates a surface while in the middle of an animation. In that
158 // case do not clear allDrawn until the animation completes.
159 boolean deferClearAllDrawn;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800160
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800161 // Is this window's surface needed? This is almost like hidden, except
162 // it will sometimes be true a little earlier: when the token has
163 // been shown, but is still waiting for its app transition to execute
164 // before making its windows shown.
165 boolean hiddenRequested;
166
167 // Have we told the window clients to hide themselves?
Wale Ogunwale89973222017-04-23 18:39:45 -0700168 private boolean mClientHidden;
169
170 // If true we will defer setting mClientHidden to true and reporting to the client that it is
171 // hidden.
172 boolean mDeferHidingClient;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800173
174 // Last visibility state we reported to the app token.
175 boolean reportedVisible;
176
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700177 // Last drawn state we reported to the app token.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700178 private boolean reportedDrawn;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700179
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800180 // Set to true when the token has been removed from the window mgr.
181 boolean removed;
182
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800183 // Information about an application starting window if displayed.
184 StartingData startingData;
185 WindowState startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800186 StartingSurface startingSurface;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800187 boolean startingDisplayed;
188 boolean startingMoved;
Jorim Jaggi60f9c972018-02-01 19:21:07 +0100189
Wale Ogunwale6c459212017-05-17 08:56:03 -0700190 // True if the hidden state of this token was forced to false due to a transferred starting
191 // window.
192 private boolean mHiddenSetFromTransferredStartingWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800193 boolean firstWindowDrawn;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700194 private final WindowState.UpdateReportedVisibilityResults mReportedVisibilityResults =
195 new WindowState.UpdateReportedVisibilityResults();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800196
197 // Input application handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700198 final InputApplicationHandle mInputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800199
Wale Ogunwale571771c2016-08-26 13:18:50 -0700200 // TODO: Have a WindowContainer state for tracking exiting/deferred removal.
Craig Mautner799bc1d2015-01-14 10:33:48 -0800201 boolean mIsExiting;
Craig Mautner9ef471f2014-02-07 13:11:47 -0800202
Craig Mautnerbb742462014-07-07 15:28:55 -0700203 boolean mLaunchTaskBehind;
Craig Mautner8746a472014-07-24 15:12:54 -0700204 boolean mEnteringAnimation;
Craig Mautnerbb742462014-07-07 15:28:55 -0700205
Wale Ogunwale72919d22016-12-08 18:58:50 -0800206 private boolean mAlwaysFocusable;
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800207
Robert Carre12aece2016-02-02 22:43:27 -0800208 boolean mAppStopped;
Robert Carrfd10cd12016-06-29 16:41:50 -0700209 int mRotationAnimationHint;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700210 private int mPendingRelaunchCount;
Robert Carre12aece2016-02-02 22:43:27 -0800211
Jorim Jaggife762342016-10-13 14:33:27 +0200212 private boolean mLastContainsShowWhenLockedWindow;
213 private boolean mLastContainsDismissKeyguardWindow;
214
Jorim Jaggi0429f352015-12-22 16:29:16 +0100215 ArrayDeque<Rect> mFrozenBounds = new ArrayDeque<>();
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700216 ArrayDeque<Configuration> mFrozenMergedConfig = new ArrayDeque<>();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100217
Wale Ogunwale6c459212017-05-17 08:56:03 -0700218 private boolean mDisablePreviewScreenshots;
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +0100219
Wale Ogunwale034a8ec2017-09-02 17:14:40 -0700220 private Task mLastParent;
Robert Carred3e83b2017-04-21 13:26:55 -0700221
chaviwd3bf08d2017-08-01 17:24:59 -0700222 /**
223 * See {@link #canTurnScreenOn()}
224 */
225 private boolean mCanTurnScreenOn = true;
226
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200227 /**
228 * If we are running an animation, this determines the transition type. Must be one of
229 * AppTransition.TRANSIT_* constants.
230 */
231 private int mTransit;
232
233 /**
234 * If we are running an animation, this determines the flags during this animation. Must be a
235 * bitwise combination of AppTransition.TRANSIT_FLAG_* constants.
236 */
237 private int mTransitFlags;
238
239 /** Whether our surface was set to be showing in the last call to {@link #prepareSurfaces} */
Jorim Jaggifd1891462017-12-29 15:41:36 +0100240 private boolean mLastSurfaceShowing = true;
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200241
Jorim Jaggi988f6682017-11-17 17:46:43 +0100242 private AppWindowThumbnail mThumbnail;
243
Jorim Jaggib0fc8172017-11-23 17:04:08 +0000244 /** Have we been asked to have this token keep the screen frozen? */
245 private boolean mFreezingScreen;
246
247 /** Whether this token should be boosted at the top of all app window tokens. */
248 private boolean mNeedsZBoost;
Adrian Roos4d18a2e2017-12-19 19:08:05 +0100249 private Letterbox mLetterbox;
Jorim Jaggib0fc8172017-11-23 17:04:08 +0000250
chaviw23ee71c2017-12-18 11:29:41 -0800251 private final Point mTmpPoint = new Point();
chaviw23012112017-12-20 15:29:04 -0800252 private final Rect mTmpRect = new Rect();
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100253 private RemoteAnimationDefinition mRemoteAnimationDefinition;
chaviw23ee71c2017-12-18 11:29:41 -0800254
Wale Ogunwale72919d22016-12-08 18:58:50 -0800255 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
256 DisplayContent dc, long inputDispatchingTimeoutNanos, boolean fullscreen,
257 boolean showForAllUsers, int targetSdk, int orientation, int rotationAnimationHint,
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800258 int configChanges, boolean launchTaskBehind, boolean alwaysFocusable,
Bryce Leef3c6a472017-11-14 14:53:06 -0800259 AppWindowContainerController controller) {
260 this(service, token, voiceInteraction, dc, fullscreen);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800261 setController(controller);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800262 mInputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800263 mShowForAllUsers = showForAllUsers;
264 mTargetSdk = targetSdk;
265 mOrientation = orientation;
266 layoutConfigChanges = (configChanges & (CONFIG_SCREEN_SIZE | CONFIG_ORIENTATION)) != 0;
267 mLaunchTaskBehind = launchTaskBehind;
268 mAlwaysFocusable = alwaysFocusable;
269 mRotationAnimationHint = rotationAnimationHint;
270
271 // Application tokens start out hidden.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200272 setHidden(true);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800273 hiddenRequested = true;
274 }
275
276 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
Bryce Leef3c6a472017-11-14 14:53:06 -0800277 DisplayContent dc, boolean fillsParent) {
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800278 super(service, token != null ? token.asBinder() : null, TYPE_APPLICATION, true, dc,
279 false /* ownerCanManageAppTokens */);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700280 appToken = token;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800281 mVoiceInteraction = voiceInteraction;
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800282 mFillsParent = fillsParent;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800283 mInputApplicationHandle = new InputApplicationHandle(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800284 }
285
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800286 void onFirstWindowDrawn(WindowState win, WindowStateAnimator winAnimator) {
287 firstWindowDrawn = true;
288
289 // We now have a good window to show, remove dead placeholders
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700290 removeDeadWindows();
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800291
Jorim Jaggi02886a82016-12-06 09:10:06 -0800292 if (startingWindow != null) {
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800293 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, "Finish starting "
294 + win.mToken + ": first real window is shown, no animation");
295 // If this initial window is animating, stop it -- we will do an animation to reveal
296 // it from behind the starting window, so there is no need for it to also be doing its
297 // own stuff.
Jorim Jaggia5e10572017-11-15 14:36:26 +0100298 win.cancelAnimation();
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800299 if (getController() != null) {
300 getController().removeStartingWindow();
301 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800302 }
303 updateReportedVisibilityLocked();
304 }
305
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800306 void updateReportedVisibilityLocked() {
307 if (appToken == null) {
308 return;
309 }
310
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700311 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700312 final int count = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800313
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700314 mReportedVisibilityResults.reset();
315
316 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700317 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700318 win.updateReportedVisibility(mReportedVisibilityResults);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800319 }
320
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700321 int numInteresting = mReportedVisibilityResults.numInteresting;
322 int numVisible = mReportedVisibilityResults.numVisible;
323 int numDrawn = mReportedVisibilityResults.numDrawn;
324 boolean nowGone = mReportedVisibilityResults.nowGone;
325
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700326 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200327 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting && !isHidden();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700328 if (!nowGone) {
329 // If the app is not yet gone, then it can only become visible/drawn.
330 if (!nowDrawn) {
331 nowDrawn = reportedDrawn;
332 }
333 if (!nowVisible) {
334 nowVisible = reportedVisible;
335 }
336 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800337 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800338 + numInteresting + " visible=" + numVisible);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800339 final AppWindowContainerController controller = getController();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700340 if (nowDrawn != reportedDrawn) {
341 if (nowDrawn) {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800342 if (controller != null) {
343 controller.reportWindowsDrawn();
344 }
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700345 }
346 reportedDrawn = nowDrawn;
347 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800348 if (nowVisible != reportedVisible) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700349 if (DEBUG_VISIBILITY) Slog.v(TAG,
350 "Visibility changed in " + this + ": vis=" + nowVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800351 reportedVisible = nowVisible;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800352 if (controller != null) {
353 if (nowVisible) {
354 controller.reportWindowsVisible();
355 } else {
356 controller.reportWindowsGone();
357 }
358 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800359 }
360 }
361
Wale Ogunwale89973222017-04-23 18:39:45 -0700362 boolean isClientHidden() {
363 return mClientHidden;
364 }
365
366 void setClientHidden(boolean hideClient) {
367 if (mClientHidden == hideClient || (hideClient && mDeferHidingClient)) {
368 return;
369 }
Jorim Jaggi067b5bf2018-02-23 17:42:39 +0100370 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setClientHidden: " + this
371 + " clientHidden=" + hideClient + " Callers=" + Debug.getCallers(5));
Wale Ogunwale89973222017-04-23 18:39:45 -0700372 mClientHidden = hideClient;
373 sendAppVisibilityToClients();
374 }
375
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700376 boolean setVisibility(WindowManager.LayoutParams lp,
377 boolean visible, int transit, boolean performLayout, boolean isVoiceInteraction) {
378
379 boolean delayed = false;
380 inPendingTransaction = false;
Wale Ogunwale9e4721f2017-05-23 19:37:30 -0700381 // Reset the state of mHiddenSetFromTransferredStartingWindow since visibility is actually
382 // been set by the app now.
383 mHiddenSetFromTransferredStartingWindow = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700384
385 // Allow for state changes and animation to be applied if:
386 // * token is transitioning visibility state
387 // * or the token was marked as hidden and is exiting before we had a chance to play the
388 // transition animation
389 // * or this is an opening app and windows are being replaced.
390 boolean visibilityChanged = false;
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200391 if (isHidden() == visible || (isHidden() && mIsExiting) || (visible && waitingForReplacement())) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700392 final AccessibilityController accessibilityController = mService.mAccessibilityController;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700393 boolean changed = false;
394 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200395 "Changing app " + this + " hidden=" + isHidden() + " performLayout=" + performLayout);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700396
397 boolean runningAppAnimation = false;
398
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100399 if (transit != WindowManager.TRANSIT_UNSET) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200400 if (applyAnimationLocked(lp, transit, visible, isVoiceInteraction)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700401 delayed = runningAppAnimation = true;
402 }
403 final WindowState window = findMainWindow();
404 //TODO (multidisplay): Magnification is supported only for the default display.
405 if (window != null && accessibilityController != null
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700406 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700407 accessibilityController.onAppWindowTransitionLocked(window, transit);
408 }
409 changed = true;
410 }
411
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700412 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700413 for (int i = 0; i < windowsCount; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700414 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700415 changed |= win.onAppVisibilityChanged(visible, runningAppAnimation);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700416 }
417
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200418 setHidden(!visible);
419 hiddenRequested = !visible;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700420 visibilityChanged = true;
421 if (!visible) {
422 stopFreezingScreen(true, true);
423 } else {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700424 // If we are being set visible, and the starting window is not yet displayed,
425 // then make sure it doesn't get displayed.
426 if (startingWindow != null && !startingWindow.isDrawnLw()) {
427 startingWindow.mPolicyVisibility = false;
428 startingWindow.mPolicyVisibilityAfterAnim = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700429 }
Jorim Jaggi38d44ec2017-06-14 16:04:59 -0700430
431 // We are becoming visible, so better freeze the screen with the windows that are
432 // getting visible so we also wait for them.
433 forAllWindows(mService::makeWindowFreezingScreenIfNeededLocked, true);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700434 }
435
436 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setVisibility: " + this
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200437 + ": hidden=" + isHidden() + " hiddenRequested=" + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700438
439 if (changed) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700440 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700441 if (performLayout) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700442 mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700443 false /*updateInputWindows*/);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700444 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700445 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700446 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700447 }
448 }
449
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200450 if (isReallyAnimating()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700451 delayed = true;
Jorim Jaggiab9fcb22018-03-15 23:46:12 +0100452 } else {
453
454 // We aren't animating anything, but exiting windows rely on the animation finished
455 // callback being called in case the AppWindowToken was pretending to be animating,
456 // which we might have done because we were in closing/opening apps list.
457 onAnimationFinished();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700458 }
459
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700460 for (int i = mChildren.size() - 1; i >= 0 && !delayed; i--) {
Jorim Jaggia5e10572017-11-15 14:36:26 +0100461 if ((mChildren.get(i)).isSelfOrChildAnimating()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700462 delayed = true;
463 }
464 }
465
466 if (visibilityChanged) {
467 if (visible && !delayed) {
468 // The token was made immediately visible, there will be no entrance animation.
469 // We need to inform the client the enter animation was finished.
470 mEnteringAnimation = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700471 mService.mActivityManagerAppTransitionNotifier.onAppTransitionFinishedLocked(token);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700472 }
Robert Carr61b81112017-07-17 18:08:15 -0700473
Jorim Jaggi110839b2018-01-22 12:49:04 +0100474 // If we're becoming visible, immediately change client visibility as well although it
475 // usually gets changed in AppWindowContainerController.setVisibility already. However,
476 // there seem to be some edge cases where we change our visibility but client visibility
477 // never gets updated.
478 // If we're becoming invisible, update the client visibility if we are not running an
479 // animation. Otherwise, we'll update client visibility in onAnimationFinished.
Jorim Jaggi3cad57f2018-02-20 18:32:01 +0100480 if (visible || !isReallyAnimating()) {
Jorim Jaggi110839b2018-01-22 12:49:04 +0100481 setClientHidden(!visible);
Jorim Jaggi4876b4a2018-01-11 15:43:49 +0100482 }
483
chaviwa953fcf2018-03-01 12:00:39 -0800484 if (!mService.mClosingApps.contains(this) && !mService.mOpeningApps.contains(this)) {
485 // The token is not closing nor opening, so even if there is an animation set, that
486 // doesn't mean that it goes through the normal app transition cycle so we have
487 // to inform the docked controller about visibility change.
488 // TODO(multi-display): notify docked divider on all displays where visibility was
489 // affected.
490 mService.getDefaultDisplayContentLocked().getDockedDividerController()
491 .notifyAppVisibilityChanged();
492
493 // Take the screenshot before possibly hiding the WSA, otherwise the screenshot
494 // will not be taken.
495 mService.mTaskSnapshotController.notifyAppVisibilityChanged(this, visible);
496 }
497
Robert Carre7cc44d2017-03-20 19:04:30 -0700498 // If we are hidden but there is no delay needed we immediately
499 // apply the Surface transaction so that the ActivityManager
Robert Carr61b81112017-07-17 18:08:15 -0700500 // can have some guarantee on the Surface state following
501 // setting the visibility. This captures cases like dismissing
502 // the docked or pinned stack where there is no app transition.
503 //
504 // In the case of a "Null" animation, there will be
505 // no animation but there will still be a transition set.
506 // We still need to delay hiding the surface such that it
507 // can be synchronized with showing the next surface in the transition.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200508 if (isHidden() && !delayed && !mService.mAppTransition.isTransitionSet()) {
Robert Carr6914f082017-03-20 19:04:30 -0700509 SurfaceControl.openTransaction();
510 for (int i = mChildren.size() - 1; i >= 0; i--) {
511 mChildren.get(i).mWinAnimator.hide("immediately hidden");
512 }
513 SurfaceControl.closeTransaction();
514 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700515 }
516
517 return delayed;
518 }
519
Jorim Jaggi87fdbcb2017-08-17 13:41:11 +0200520 /**
521 * @return The to top most child window for which {@link LayoutParams#isFullscreen()} returns
522 * true.
523 */
524 WindowState getTopFullscreenWindow() {
525 for (int i = mChildren.size() - 1; i >= 0; i--) {
526 final WindowState win = mChildren.get(i);
527 if (win != null && win.mAttrs.isFullscreen()) {
528 return win;
529 }
530 }
531 return null;
532 }
533
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800534 WindowState findMainWindow() {
Matthew Ng53e66b22018-01-12 17:13:13 -0800535 return findMainWindow(true);
536 }
537
538 /**
539 * Finds the main window that either has type base application or application starting if
540 * requested.
541 *
542 * @param includeStartingApp Allow to search application-starting windows to also be returned.
543 * @return The main window of type base application or application starting if requested.
544 */
545 WindowState findMainWindow(boolean includeStartingApp) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700546 WindowState candidate = null;
Matthew Ng53e66b22018-01-12 17:13:13 -0800547 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700548 final WindowState win = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700549 final int type = win.mAttrs.type;
550 // No need to loop through child window as base application and starting types can't be
551 // child windows.
Matthew Ng53e66b22018-01-12 17:13:13 -0800552 if (type == TYPE_BASE_APPLICATION
553 || (includeStartingApp && type == TYPE_APPLICATION_STARTING)) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700554 // In cases where there are multiple windows, we prefer the non-exiting window. This
Sungsoo Lim0d3d1f82015-12-02 14:47:59 +0900555 // happens for example when replacing windows during an activity relaunch. When
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700556 // constructing the animation, we want the new window, not the exiting one.
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800557 if (win.mAnimatingExit) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700558 candidate = win;
559 } else {
560 return win;
561 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800562 }
563 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700564 return candidate;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800565 }
566
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800567 boolean windowsAreFocusable() {
Wale Ogunwale3382ab12017-07-27 08:55:03 -0700568 return getWindowConfiguration().canReceiveKeys() || mAlwaysFocusable;
Wale Ogunwaled045c822015-12-02 09:14:28 -0800569 }
570
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800571 AppWindowContainerController getController() {
572 final WindowContainerController controller = super.getController();
573 return controller != null ? (AppWindowContainerController) controller : null;
574 }
575
Wale Ogunwale571771c2016-08-26 13:18:50 -0700576 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -0700577 boolean isVisible() {
Wale Ogunwalee471be62016-10-03 07:53:55 -0700578 // If the app token isn't hidden then it is considered visible and there is no need to check
579 // its children windows to see if they are visible.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200580 return !isHidden();
Wale Ogunwale44f21802016-09-02 12:49:48 -0700581 }
582
583 @Override
Wale Ogunwalee287e192017-04-21 09:30:12 -0700584 void removeImmediately() {
585 onRemovedFromDisplay();
586 super.removeImmediately();
587 }
588
589 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -0700590 void removeIfPossible() {
Craig Mautnere3119b72015-01-20 15:02:36 -0800591 mIsExiting = false;
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800592 removeAllWindowsIfPossible();
Bryce Lee6d410262017-02-28 15:30:17 -0800593 removeImmediately();
Craig Mautnere3119b72015-01-20 15:02:36 -0800594 }
595
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700596 @Override
597 boolean checkCompleteDeferredRemoval() {
598 if (mIsExiting) {
599 removeIfPossible();
600 }
601 return super.checkCompleteDeferredRemoval();
602 }
603
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700604 void onRemovedFromDisplay() {
Wale Ogunwalee287e192017-04-21 09:30:12 -0700605 if (mRemovingFromDisplay) {
606 return;
607 }
608 mRemovingFromDisplay = true;
609
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700610 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app token: " + this);
611
Wale Ogunwale72919d22016-12-08 18:58:50 -0800612 boolean delayed = setVisibility(null, false, TRANSIT_UNSET, true, mVoiceInteraction);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700613
614 mService.mOpeningApps.remove(this);
Jorim Jaggi45ca0542017-05-30 16:16:01 -0700615 mService.mUnknownAppVisibilityController.appRemovedOrHidden(this);
Jorim Jaggi10abe2f2017-01-03 16:44:46 +0100616 mService.mTaskSnapshotController.onAppRemoved(this);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700617 waitingToShow = false;
618 if (mService.mClosingApps.contains(this)) {
619 delayed = true;
620 } else if (mService.mAppTransition.isTransitionSet()) {
621 mService.mClosingApps.add(this);
622 delayed = true;
623 }
624
625 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app " + this + " delayed=" + delayed
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200626 + " animation=" + getAnimation() + " animating=" + isSelfAnimating());
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700627
628 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM, "removeAppToken: "
629 + this + " delayed=" + delayed + " Callers=" + Debug.getCallers(4));
630
Jorim Jaggi19be6052017-08-03 18:33:43 +0200631 if (startingData != null && getController() != null) {
632 getController().removeStartingWindow();
633 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800634
Winson Chung87e5d552017-04-05 11:49:38 -0700635 // If this window was animating, then we need to ensure that the app transition notifies
636 // that animations have completed in WMS.handleAnimatingStoppedAndTransitionLocked(), so
637 // add to that list now
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200638 if (isSelfAnimating()) {
Winson Chung87e5d552017-04-05 11:49:38 -0700639 mService.mNoAnimationNotifyOnTransitionFinished.add(token);
640 }
641
Wale Ogunwalee287e192017-04-21 09:30:12 -0700642 final TaskStack stack = getStack();
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700643 if (delayed && !isEmpty()) {
644 // set the token aside because it has an active animation to be finished
645 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM,
646 "removeAppToken make exiting: " + this);
Wale Ogunwalee287e192017-04-21 09:30:12 -0700647 if (stack != null) {
648 stack.mExitingAppTokens.add(this);
649 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700650 mIsExiting = true;
651 } else {
652 // Make sure there is no animation running on this token, so any windows associated
653 // with it will be removed as soon as their animations are complete
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200654 cancelAnimation();
Wale Ogunwale3106ae012017-05-16 08:56:37 -0700655 if (stack != null) {
656 stack.mExitingAppTokens.remove(this);
657 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700658 removeIfPossible();
659 }
660
661 removed = true;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700662 stopFreezingScreen(true, true);
Bryce Lee6d410262017-02-28 15:30:17 -0800663
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700664 if (mService.mFocusedApp == this) {
665 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "Removing focused app token:" + this);
666 mService.mFocusedApp = null;
667 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
668 mService.mInputMonitor.setFocusedAppLw(null);
669 }
670
671 if (!delayed) {
672 updateReportedVisibilityLocked();
673 }
Wale Ogunwalee287e192017-04-21 09:30:12 -0700674
675 mRemovingFromDisplay = false;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700676 }
677
Chong Zhange05bcb12016-07-26 17:47:29 -0700678 void clearAnimatingFlags() {
Chong Zhangb0d26702016-08-12 16:03:29 -0700679 boolean wallpaperMightChange = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700680 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700681 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700682 wallpaperMightChange |= win.clearAnimatingFlags();
Chong Zhange05bcb12016-07-26 17:47:29 -0700683 }
Chong Zhangb0d26702016-08-12 16:03:29 -0700684 if (wallpaperMightChange) {
685 requestUpdateWallpaperIfNeeded();
686 }
Chong Zhange05bcb12016-07-26 17:47:29 -0700687 }
688
Robert Carre12aece2016-02-02 22:43:27 -0800689 void destroySurfaces() {
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700690 destroySurfaces(false /*cleanupOnResume*/);
691 }
692
693 /**
694 * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure
695 * the client has finished with them.
696 *
697 * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If
698 * set to true, destroy only surfaces of removed windows, and clear relevant flags of the
699 * others so that they are ready to be reused. If set to false (common case), destroy all
700 * surfaces that's eligible, if the app is already stopped.
701 */
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700702 private void destroySurfaces(boolean cleanupOnResume) {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700703 boolean destroyedSomething = false;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100704
705 // Copying to a different list as multiple children can be removed.
Jorim Jaggi59f3e922018-01-05 15:40:32 +0100706 final ArrayList<WindowState> children = new ArrayList<>(mChildren);
Jorim Jaggia5e10572017-11-15 14:36:26 +0100707 for (int i = children.size() - 1; i >= 0; i--) {
708 final WindowState win = children.get(i);
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700709 destroyedSomething |= win.destroySurface(cleanupOnResume, mAppStopped);
Robert Carre12aece2016-02-02 22:43:27 -0800710 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700711 if (destroyedSomething) {
712 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700713 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Adrian Roos23df3a32018-03-15 15:41:13 +0100714 updateLetterboxSurface(null);
Robert Carre12aece2016-02-02 22:43:27 -0800715 }
716 }
717
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800718 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700719 * Notify that the app is now resumed, and it was not stopped before, perform a clean
720 * up of the surfaces
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800721 */
Jorim Jaggibae01b12017-04-11 16:29:10 -0700722 void notifyAppResumed(boolean wasStopped) {
Chong Zhangad24f962016-08-25 12:12:33 -0700723 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped
Jorim Jaggibae01b12017-04-11 16:29:10 -0700724 + " " + this);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700725 mAppStopped = false;
chaviwd3bf08d2017-08-01 17:24:59 -0700726 // Allow the window to turn the screen on once the app is resumed again.
727 setCanTurnScreenOn(true);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700728 if (!wasStopped) {
729 destroySurfaces(true /*cleanupOnResume*/);
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800730 }
Robert Carre12aece2016-02-02 22:43:27 -0800731 }
732
Chong Zhangbef461f2015-10-27 11:38:24 -0700733 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700734 * Notify that the app has stopped, and it is okay to destroy any surfaces which were
735 * keeping alive in case they were still being used.
736 */
737 void notifyAppStopped() {
738 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this);
739 mAppStopped = true;
740 destroySurfaces();
741 // Remove any starting window that was added for this app if they are still around.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800742 if (getController() != null) {
743 getController().removeStartingWindow();
744 }
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700745 }
746
Chong Zhang92147042016-05-09 12:47:11 -0700747 void clearAllDrawn() {
748 allDrawn = false;
749 deferClearAllDrawn = false;
Chong Zhangbef461f2015-10-27 11:38:24 -0700750 }
751
Bryce Lee6d410262017-02-28 15:30:17 -0800752 Task getTask() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800753 return (Task) getParent();
Bryce Lee6d410262017-02-28 15:30:17 -0800754 }
755
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800756 TaskStack getStack() {
757 final Task task = getTask();
758 if (task != null) {
759 return task.mStack;
760 } else {
761 return null;
762 }
763 }
764
Bryce Lee6d410262017-02-28 15:30:17 -0800765 @Override
766 void onParentSet() {
767 super.onParentSet();
768
Robert Carred3e83b2017-04-21 13:26:55 -0700769 final Task task = getTask();
770
Bryce Lee6d410262017-02-28 15:30:17 -0800771 // When the associated task is {@code null}, the {@link AppWindowToken} can no longer
772 // access visual elements like the {@link DisplayContent}. We must remove any associations
773 // such as animations.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800774 if (!mReparenting) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800775 if (task == null) {
776 // It is possible we have been marked as a closing app earlier. We must remove ourselves
777 // from this list so we do not participate in any future animations.
778 mService.mClosingApps.remove(this);
Robert Carred3e83b2017-04-21 13:26:55 -0700779 } else if (mLastParent != null && mLastParent.mStack != null) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800780 task.mStack.mExitingAppTokens.remove(this);
781 }
Bryce Lee6d410262017-02-28 15:30:17 -0800782 }
Robert Carred3e83b2017-04-21 13:26:55 -0700783 mLastParent = task;
Bryce Lee6d410262017-02-28 15:30:17 -0800784 }
785
Wale Ogunwalefa854eb2016-09-20 13:43:52 -0700786 void postWindowRemoveStartingWindowCleanup(WindowState win) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700787 // TODO: Something smells about the code below...Is there a better way?
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700788 if (startingWindow == win) {
789 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800790 if (getController() != null) {
791 getController().removeStartingWindow();
792 }
Wale Ogunwale6c459212017-05-17 08:56:03 -0700793 } else if (mChildren.size() == 0) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700794 // If this is the last window and we had requested a starting transition window,
795 // well there is no point now.
Jorim Jaggi02886a82016-12-06 09:10:06 -0800796 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingData");
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700797 startingData = null;
Wale Ogunwale6c459212017-05-17 08:56:03 -0700798 if (mHiddenSetFromTransferredStartingWindow) {
799 // We set the hidden state to false for the token from a transferred starting window.
800 // We now reset it back to true since the starting window was the last window in the
801 // token.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200802 setHidden(true);
Wale Ogunwale6c459212017-05-17 08:56:03 -0700803 }
Jorim Jaggi829b9cd2017-01-23 16:20:53 +0100804 } else if (mChildren.size() == 1 && startingSurface != null && !isRelaunching()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700805 // If this is the last window except for a starting transition window,
806 // we need to get rid of the starting transition.
Jorim Jaggie4b0f282017-05-17 15:10:29 +0200807 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Last window, removing starting window "
808 + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800809 if (getController() != null) {
810 getController().removeStartingWindow();
811 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700812 }
813 }
814
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700815 void removeDeadWindows() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700816 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700817 WindowState win = mChildren.get(winNdx);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800818 if (win.mAppDied) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700819 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700820 "removeDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800821 // Set mDestroying, we don't want any animation or delayed removal here.
822 win.mDestroying = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700823 // Also removes child windows.
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700824 win.removeIfPossible();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800825 }
826 }
827 }
828
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700829 boolean hasWindowsAlive() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700830 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700831 // No need to loop through child windows as the answer should be the same as that of the
832 // parent window.
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700833 if (!(mChildren.get(i)).mAppDied) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700834 return true;
835 }
836 }
837 return false;
838 }
839
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700840 void setWillReplaceWindows(boolean animate) {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700841 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
842 "Marking app token " + this + " with replacing windows.");
Robert Carra1eb4392015-12-10 12:43:51 -0800843
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700844 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700845 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700846 w.setWillReplaceWindow(animate);
Robert Carra1eb4392015-12-10 12:43:51 -0800847 }
Robert Carra1eb4392015-12-10 12:43:51 -0800848 }
849
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700850 void setWillReplaceChildWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700851 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this
Robert Carr23fa16b2016-01-13 13:19:58 -0800852 + " with replacing child windows.");
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700853 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700854 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700855 w.setWillReplaceChildWindows();
Robert Carr23fa16b2016-01-13 13:19:58 -0800856 }
857 }
858
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700859 void clearWillReplaceWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700860 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
861 "Resetting app token " + this + " of replacing window marks.");
Chong Zhangf596cd52016-01-05 13:42:44 -0800862
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700863 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700864 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700865 w.clearWillReplaceWindow();
Chong Zhangf596cd52016-01-05 13:42:44 -0800866 }
867 }
868
Chong Zhang4d7369a2016-04-25 16:09:14 -0700869 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700870 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700871 final WindowState w = mChildren.get(i);
Chong Zhang4d7369a2016-04-25 16:09:14 -0700872 w.requestUpdateWallpaperIfNeeded();
873 }
874 }
875
Chong Zhangd78ddb42016-03-02 17:01:14 -0800876 boolean isRelaunching() {
877 return mPendingRelaunchCount > 0;
878 }
879
Robert Carr68375192017-06-13 12:41:53 -0700880 boolean shouldFreezeBounds() {
881 final Task task = getTask();
882
883 // For freeform windows, we can't freeze the bounds at the moment because this would make
884 // the resizing unresponsive.
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700885 if (task == null || task.inFreeformWindowingMode()) {
Robert Carr68375192017-06-13 12:41:53 -0700886 return false;
887 }
888
889 // We freeze the bounds while drag resizing to deal with the time between
890 // the divider/drag handle being released, and the handling it's new
891 // configuration. If we are relaunched outside of the drag resizing state,
892 // we need to be careful not to do this.
893 return getTask().isDragResizing();
894 }
895
Chong Zhangd78ddb42016-03-02 17:01:14 -0800896 void startRelaunching() {
Robert Carr68375192017-06-13 12:41:53 -0700897 if (shouldFreezeBounds()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -0800898 freezeBounds();
899 }
Robert Carrd5c7dd62017-03-08 10:39:30 -0800900
901 // In the process of tearing down before relaunching, the app will
902 // try and clean up it's child surfaces. We need to prevent this from
903 // happening, so we sever the children, transfering their ownership
904 // from the client it-self to the parent surface (owned by us).
905 for (int i = mChildren.size() - 1; i >= 0; i--) {
906 final WindowState w = mChildren.get(i);
907 w.mWinAnimator.detachChildren();
908 }
909
Chong Zhangd78ddb42016-03-02 17:01:14 -0800910 mPendingRelaunchCount++;
911 }
912
913 void finishRelaunching() {
Robert Carr68375192017-06-13 12:41:53 -0700914 unfreezeBounds();
915
Chong Zhangd78ddb42016-03-02 17:01:14 -0800916 if (mPendingRelaunchCount > 0) {
917 mPendingRelaunchCount--;
Bryce Lee081554b2017-05-25 07:52:12 -0700918 } else {
919 // Update keyguard flags upon finishing relaunch.
920 checkKeyguardFlagsChanged();
Chong Zhangd78ddb42016-03-02 17:01:14 -0800921 }
922 }
923
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700924 void clearRelaunching() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700925 if (mPendingRelaunchCount == 0) {
926 return;
927 }
Robert Carr68375192017-06-13 12:41:53 -0700928 unfreezeBounds();
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700929 mPendingRelaunchCount = 0;
930 }
931
Wale Ogunwale07bcab72016-10-14 15:30:09 -0700932 /**
933 * Returns true if the new child window we are adding to this token is considered greater than
934 * the existing child window in this token in terms of z-order.
935 */
936 @Override
937 protected boolean isFirstChildWindowGreaterThanSecond(WindowState newWindow,
938 WindowState existingWindow) {
939 final int type1 = newWindow.mAttrs.type;
940 final int type2 = existingWindow.mAttrs.type;
941
942 // Base application windows should be z-ordered BELOW all other windows in the app token.
943 if (type1 == TYPE_BASE_APPLICATION && type2 != TYPE_BASE_APPLICATION) {
944 return false;
945 } else if (type1 != TYPE_BASE_APPLICATION && type2 == TYPE_BASE_APPLICATION) {
946 return true;
947 }
948
949 // Starting windows should be z-ordered ABOVE all other windows in the app token.
950 if (type1 == TYPE_APPLICATION_STARTING && type2 != TYPE_APPLICATION_STARTING) {
951 return true;
952 } else if (type1 != TYPE_APPLICATION_STARTING && type2 == TYPE_APPLICATION_STARTING) {
953 return false;
954 }
955
956 // Otherwise the new window is greater than the existing window.
957 return true;
958 }
959
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700960 @Override
Robert Carra1eb4392015-12-10 12:43:51 -0800961 void addWindow(WindowState w) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700962 super.addWindow(w);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700963
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700964 boolean gotReplacementWindow = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700965 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700966 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700967 gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w);
968 }
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700969
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700970 // if we got a replacement window, reset the timeout to give drawing more time
971 if (gotReplacementWindow) {
972 mService.scheduleWindowReplacementTimeouts(this);
Robert Carra1eb4392015-12-10 12:43:51 -0800973 }
Jorim Jaggife762342016-10-13 14:33:27 +0200974 checkKeyguardFlagsChanged();
975 }
976
977 @Override
978 void removeChild(WindowState child) {
979 super.removeChild(child);
980 checkKeyguardFlagsChanged();
Adrian Roos23df3a32018-03-15 15:41:13 +0100981 updateLetterboxSurface(child);
Robert Carra1eb4392015-12-10 12:43:51 -0800982 }
983
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700984 private boolean waitingForReplacement() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700985 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700986 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700987 if (candidate.waitingForReplacement()) {
Robert Carra1eb4392015-12-10 12:43:51 -0800988 return true;
989 }
990 }
991 return false;
992 }
993
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700994 void onWindowReplacementTimeout() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700995 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700996 (mChildren.get(i)).onWindowReplacementTimeout();
Robert Carra1eb4392015-12-10 12:43:51 -0800997 }
998 }
999
Winson Chung30480042017-01-26 10:55:34 -08001000 void reparent(Task task, int position) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001001 final Task currentTask = getTask();
1002 if (task == currentTask) {
Winson Chung30480042017-01-26 10:55:34 -08001003 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001004 "window token=" + this + " already child of task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -08001005 }
Bryce Lee6d410262017-02-28 15:30:17 -08001006
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001007 if (currentTask.mStack != task.mStack) {
Bryce Lee6d410262017-02-28 15:30:17 -08001008 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001009 "window token=" + this + " current task=" + currentTask
Bryce Lee6d410262017-02-28 15:30:17 -08001010 + " belongs to a different stack than " + task);
1011 }
1012
Winson Chung30480042017-01-26 10:55:34 -08001013 if (DEBUG_ADD_REMOVE) Slog.i(TAG, "reParentWindowToken: removing window token=" + this
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001014 + " from task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -08001015 final DisplayContent prevDisplayContent = getDisplayContent();
1016
Bryce Lee6d410262017-02-28 15:30:17 -08001017 mReparenting = true;
1018
Winson Chung30480042017-01-26 10:55:34 -08001019 getParent().removeChild(this);
1020 task.addChild(this, position);
1021
Bryce Lee6d410262017-02-28 15:30:17 -08001022 mReparenting = false;
1023
Winson Chung30480042017-01-26 10:55:34 -08001024 // Relayout display(s).
1025 final DisplayContent displayContent = task.getDisplayContent();
1026 displayContent.setLayoutNeeded();
1027 if (prevDisplayContent != displayContent) {
1028 onDisplayChanged(displayContent);
1029 prevDisplayContent.setLayoutNeeded();
1030 }
1031 }
1032
Jorim Jaggi0429f352015-12-22 16:29:16 +01001033 /**
1034 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
1035 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
1036 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
1037 * with a queue.
1038 */
Chong Zhangd78ddb42016-03-02 17:01:14 -08001039 private void freezeBounds() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001040 final Task task = getTask();
1041 mFrozenBounds.offer(new Rect(task.mPreparedFrozenBounds));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001042
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001043 if (task.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) {
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001044 // We didn't call prepareFreezingBounds on the task, so use the current value.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001045 mFrozenMergedConfig.offer(new Configuration(task.getConfiguration()));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001046 } else {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001047 mFrozenMergedConfig.offer(new Configuration(task.mPreparedFrozenMergedConfig));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001048 }
Andrii Kulianb10330d2016-09-16 13:51:46 -07001049 // Calling unset() to make it equal to Configuration.EMPTY.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001050 task.mPreparedFrozenMergedConfig.unset();
Jorim Jaggi0429f352015-12-22 16:29:16 +01001051 }
1052
1053 /**
1054 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
1055 */
Chong Zhangd78ddb42016-03-02 17:01:14 -08001056 private void unfreezeBounds() {
Robert Carr68375192017-06-13 12:41:53 -07001057 if (mFrozenBounds.isEmpty()) {
1058 return;
Wale Ogunwale37dbafc2016-06-27 10:15:20 -07001059 }
Robert Carr68375192017-06-13 12:41:53 -07001060 mFrozenBounds.remove();
Wale Ogunwale37dbafc2016-06-27 10:15:20 -07001061 if (!mFrozenMergedConfig.isEmpty()) {
1062 mFrozenMergedConfig.remove();
1063 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001064 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001065 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001066 win.onUnfreezeBounds();
Jorim Jaggi4846ee32016-01-07 17:39:12 +01001067 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001068 mService.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +01001069 }
1070
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001071 void setAppLayoutChanges(int changes, String reason) {
1072 if (!mChildren.isEmpty()) {
1073 final DisplayContent dc = getDisplayContent();
1074 dc.pendingLayoutChanges |= changes;
1075 if (DEBUG_LAYOUT_REPEATS) {
1076 mService.mWindowPlacerLocked.debugLayoutRepeats(reason, dc.pendingLayoutChanges);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001077 }
1078 }
1079 }
1080
1081 void removeReplacedWindowIfNeeded(WindowState replacement) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001082 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001083 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001084 if (win.removeReplacedWindowIfNeeded(replacement)) {
1085 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001086 }
1087 }
1088 }
1089
1090 void startFreezingScreen() {
1091 if (DEBUG_ORIENTATION) logWithStack(TAG, "Set freezing of " + appToken + ": hidden="
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001092 + isHidden() + " freezing=" + mFreezingScreen + " hiddenRequested="
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001093 + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001094 if (!hiddenRequested) {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001095 if (!mFreezingScreen) {
1096 mFreezingScreen = true;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001097 mService.registerAppFreezeListener(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001098 mService.mAppsFreezingScreen++;
1099 if (mService.mAppsFreezingScreen == 1) {
Robert Carrae606b42018-02-15 15:36:23 -08001100 mService.startFreezingDisplayLocked(0, 0, getDisplayContent());
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001101 mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT);
1102 mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001103 }
1104 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001105 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001106 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001107 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001108 w.onStartFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001109 }
1110 }
1111 }
1112
1113 void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001114 if (!mFreezingScreen) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001115 return;
1116 }
1117 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + this + " force=" + force);
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001118 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001119 boolean unfrozeWindows = false;
1120 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001121 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001122 unfrozeWindows |= w.onStopFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001123 }
1124 if (force || unfrozeWindows) {
1125 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this);
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001126 mFreezingScreen = false;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001127 mService.unregisterAppFreezeListener(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001128 mService.mAppsFreezingScreen--;
1129 mService.mLastFinishedFreezeSource = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001130 }
1131 if (unfreezeSurfaceNow) {
1132 if (unfrozeWindows) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001133 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001134 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001135 mService.stopFreezingDisplayLocked();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001136 }
1137 }
1138
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001139 @Override
1140 public void onAppFreezeTimeout() {
1141 Slog.w(TAG_WM, "Force clearing freeze: " + this);
1142 stopFreezingScreen(true, true);
1143 }
1144
Jorim Jaggi60f9c972018-02-01 19:21:07 +01001145 /**
1146 * Tries to transfer the starting window from a token that's above ourselves in the task but
1147 * not visible anymore. This is a common scenario apps use: Trampoline activity T start main
1148 * activity M in the same task. Now, when reopening the task, T starts on top of M but then
1149 * immediately finishes after, so we have to transfer T to M.
1150 */
1151 void transferStartingWindowFromHiddenAboveTokenIfNeeded() {
1152 final Task task = getTask();
1153 for (int i = task.mChildren.size() - 1; i >= 0; i--) {
1154 final AppWindowToken fromToken = task.mChildren.get(i);
1155 if (fromToken == this) {
1156 return;
1157 }
1158 if (fromToken.hiddenRequested && transferStartingWindow(fromToken.token)) {
1159 return;
1160 }
1161 }
1162 }
1163
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001164 boolean transferStartingWindow(IBinder transferFrom) {
Wale Ogunwale02319a62016-09-26 15:21:22 -07001165 final AppWindowToken fromToken = getDisplayContent().getAppWindowToken(transferFrom);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001166 if (fromToken == null) {
1167 return false;
1168 }
1169
1170 final WindowState tStartingWindow = fromToken.startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001171 if (tStartingWindow != null && fromToken.startingSurface != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001172 // In this case, the starting icon has already been displayed, so start
1173 // letting windows get shown immediately without any more transitions.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001174 mService.mSkipAppTransitionAnimation = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001175
1176 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow
1177 + " from " + fromToken + " to " + this);
1178
1179 final long origId = Binder.clearCallingIdentity();
Peter Visontay3556a3b2017-11-01 17:23:17 +00001180 try {
1181 // Transfer the starting window over to the new token.
1182 startingData = fromToken.startingData;
1183 startingSurface = fromToken.startingSurface;
1184 startingDisplayed = fromToken.startingDisplayed;
1185 fromToken.startingDisplayed = false;
1186 startingWindow = tStartingWindow;
1187 reportedVisible = fromToken.reportedVisible;
1188 fromToken.startingData = null;
1189 fromToken.startingSurface = null;
1190 fromToken.startingWindow = null;
1191 fromToken.startingMoved = true;
1192 tStartingWindow.mToken = this;
1193 tStartingWindow.mAppToken = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001194
Peter Visontay3556a3b2017-11-01 17:23:17 +00001195 if (DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1196 "Removing starting " + tStartingWindow + " from " + fromToken);
1197 fromToken.removeChild(tStartingWindow);
1198 fromToken.postWindowRemoveStartingWindowCleanup(tStartingWindow);
1199 fromToken.mHiddenSetFromTransferredStartingWindow = false;
1200 addWindow(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001201
Peter Visontay3556a3b2017-11-01 17:23:17 +00001202 // Propagate other interesting state between the tokens. If the old token is displayed,
1203 // we should immediately force the new one to be displayed. If it is animating, we need
1204 // to move that animation to the new one.
1205 if (fromToken.allDrawn) {
1206 allDrawn = true;
1207 deferClearAllDrawn = fromToken.deferClearAllDrawn;
1208 }
1209 if (fromToken.firstWindowDrawn) {
1210 firstWindowDrawn = true;
1211 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001212 if (!fromToken.isHidden()) {
1213 setHidden(false);
Peter Visontay3556a3b2017-11-01 17:23:17 +00001214 hiddenRequested = false;
1215 mHiddenSetFromTransferredStartingWindow = true;
1216 }
1217 setClientHidden(fromToken.mClientHidden);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001218
Jorim Jaggi980c9de2017-11-17 01:41:37 +01001219 transferAnimation(fromToken);
1220
1221 // When transferring an animation, we no longer need to apply an animation to the
1222 // the token we transfer the animation over. Thus, remove the animation from
1223 // pending opening apps.
1224 mService.mOpeningApps.remove(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001225
Peter Visontay3556a3b2017-11-01 17:23:17 +00001226 mService.updateFocusedWindowLocked(
1227 UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/);
1228 getDisplayContent().setLayoutNeeded();
1229 mService.mWindowPlacerLocked.performSurfacePlacement();
1230 } finally {
1231 Binder.restoreCallingIdentity(origId);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001232 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001233 return true;
1234 } else if (fromToken.startingData != null) {
1235 // The previous app was getting ready to show a
1236 // starting window, but hasn't yet done so. Steal it!
1237 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1238 "Moving pending starting from " + fromToken + " to " + this);
1239 startingData = fromToken.startingData;
1240 fromToken.startingData = null;
1241 fromToken.startingMoved = true;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001242 if (getController() != null) {
1243 getController().scheduleAddStartingWindow();
1244 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001245 return true;
1246 }
1247
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001248 // TODO: Transfer thumbnail
1249
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001250 return false;
1251 }
1252
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001253 boolean isLastWindow(WindowState win) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001254 return mChildren.size() == 1 && mChildren.get(0) == win;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001255 }
1256
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001257 @Override
1258 void onAppTransitionDone() {
1259 sendingToBottom = false;
1260 }
1261
Wale Ogunwale51362492016-09-08 17:49:17 -07001262 /**
1263 * We override because this class doesn't want its children affecting its reported orientation
1264 * in anyway.
1265 */
1266 @Override
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001267 int getOrientation(int candidate) {
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001268 if (candidate == SCREEN_ORIENTATION_BEHIND) {
1269 // Allow app to specify orientation regardless of its visibility state if the current
1270 // candidate want us to use orientation behind. I.e. the visible app on-top of this one
1271 // wants us to use the orientation of the app behind it.
1272 return mOrientation;
1273 }
1274
Bryce Lee61fbcbc2017-03-10 14:14:03 -08001275 // The {@link AppWindowToken} should only specify an orientation when it is not closing or
1276 // going to the bottom. Allowing closing {@link AppWindowToken} to participate can lead to
1277 // an Activity in another task being started in the wrong orientation during the transition.
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001278 if (!(sendingToBottom || mService.mClosingApps.contains(this))
Bryce Lee00d586d2017-07-28 20:48:43 -07001279 && (isVisible() || mService.mOpeningApps.contains(this) || isOnTop())) {
Bryce Leea163b762017-01-24 11:05:01 -08001280 return mOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001281 }
Bryce Leea163b762017-01-24 11:05:01 -08001282
1283 return SCREEN_ORIENTATION_UNSET;
Wale Ogunwale51362492016-09-08 17:49:17 -07001284 }
1285
Wale Ogunwaleb198b742016-12-01 08:44:09 -08001286 /** Returns the app's preferred orientation regardless of its currently visibility state. */
1287 int getOrientationIgnoreVisibility() {
1288 return mOrientation;
1289 }
1290
Craig Mautnerdbb79912012-03-01 18:59:14 -08001291 @Override
Winson Chunge55c0192017-08-24 14:50:48 -07001292 public void onConfigurationChanged(Configuration newParentConfig) {
1293 final int prevWinMode = getWindowingMode();
1294 super.onConfigurationChanged(newParentConfig);
1295 final int winMode = getWindowingMode();
1296
1297 if (prevWinMode == winMode) {
1298 return;
1299 }
1300
1301 if (prevWinMode != WINDOWING_MODE_UNDEFINED && winMode == WINDOWING_MODE_PINNED) {
1302 // Entering PiP from fullscreen, reset the snap fraction
1303 mDisplayContent.mPinnedStackControllerLocked.resetReentrySnapFraction(this);
1304 } else if (prevWinMode == WINDOWING_MODE_PINNED && winMode != WINDOWING_MODE_UNDEFINED) {
1305 // Leaving PiP to fullscreen, save the snap fraction based on the pre-animation bounds
1306 // for the next re-entry into PiP (assuming the activity is not hidden or destroyed)
1307 final TaskStack pinnedStack = mDisplayContent.getPinnedStack();
1308 if (pinnedStack != null) {
1309 mDisplayContent.mPinnedStackControllerLocked.saveReentrySnapFraction(this,
1310 pinnedStack.mPreAnimationBounds);
1311 }
1312 }
1313 }
1314
1315 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001316 void checkAppWindowsReadyToShow() {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001317 if (allDrawn == mLastAllDrawn) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001318 return;
1319 }
1320
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001321 mLastAllDrawn = allDrawn;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001322 if (!allDrawn) {
1323 return;
1324 }
1325
1326 // The token has now changed state to having all windows shown... what to do, what to do?
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001327 if (mFreezingScreen) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001328 showAllWindowsLocked();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001329 stopFreezingScreen(false, true);
1330 if (DEBUG_ORIENTATION) Slog.i(TAG,
1331 "Setting mOrientationChangeComplete=true because wtoken " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001332 + " numInteresting=" + mNumInterestingWindows + " numDrawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001333 // This will set mOrientationChangeComplete and cause a pass through layout.
1334 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001335 "checkAppWindowsReadyToShow: freezingScreen");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001336 } else {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001337 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001338
1339 // We can now show all of the drawn windows!
1340 if (!mService.mOpeningApps.contains(this)) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001341 showAllWindowsLocked();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001342 }
1343 }
1344 }
1345
Matthew Ng5d23afa2017-06-21 16:16:24 -07001346 /**
Bryce Leed390deb2017-06-22 13:14:28 -07001347 * Returns whether the drawn window states of this {@link AppWindowToken} has considered every
1348 * child {@link WindowState}. A child is considered if it has been passed into
1349 * {@link #updateDrawnWindowStates(WindowState)} after being added. This is used to determine
1350 * whether states, such as {@code allDrawn}, can be set, which relies on state variables such as
1351 * {@code mNumInterestingWindows}, which depend on all {@link WindowState}s being considered.
1352 *
1353 * @return {@code true} If all children have been considered, {@code false}.
1354 */
1355 private boolean allDrawnStatesConsidered() {
Bryce Lee6311c4b2017-07-06 14:09:29 -07001356 for (int i = mChildren.size() - 1; i >= 0; --i) {
1357 final WindowState child = mChildren.get(i);
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001358 if (child.mightAffectAllDrawn() && !child.getDrawnStateEvaluated()) {
Bryce Leed390deb2017-06-22 13:14:28 -07001359 return false;
1360 }
1361 }
1362 return true;
1363 }
1364
1365 /**
Matthew Ng5d23afa2017-06-21 16:16:24 -07001366 * Determines if the token has finished drawing. This should only be called from
1367 * {@link DisplayContent#applySurfaceChangesTransaction}
1368 */
Matthew Ng498c71d2017-04-18 13:55:45 -07001369 void updateAllDrawn() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001370 if (!allDrawn) {
Matthew Ng498c71d2017-04-18 13:55:45 -07001371 // Number of drawn windows can be less when a window is being relaunched, wait for
Bryce Leed390deb2017-06-22 13:14:28 -07001372 // all windows to be launched and drawn for this token be considered all drawn.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001373 final int numInteresting = mNumInterestingWindows;
Bryce Leed390deb2017-06-22 13:14:28 -07001374
1375 // We must make sure that all present children have been considered (determined by
1376 // {@link #allDrawnStatesConsidered}) before evaluating whether everything has been
1377 // drawn.
1378 if (numInteresting > 0 && allDrawnStatesConsidered()
1379 && mNumDrawnWindows >= numInteresting && !isRelaunching()) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001380 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawn: " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001381 + " interesting=" + numInteresting + " drawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001382 allDrawn = true;
1383 // Force an additional layout pass where
1384 // WindowStateAnimator#commitFinishDrawingLocked() will call performShowLocked().
Matthew Ng498c71d2017-04-18 13:55:45 -07001385 if (mDisplayContent != null) {
1386 mDisplayContent.setLayoutNeeded();
1387 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001388 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Robert Carrecc06b32017-04-18 14:25:10 -07001389
Winson Chunge7ba6862017-05-24 12:13:33 -07001390 // Notify the pinned stack upon all windows drawn. If there was an animation in
1391 // progress then this signal will resume that animation.
Wale Ogunwale61911492017-10-11 08:50:50 -07001392 final TaskStack pinnedStack = mDisplayContent.getPinnedStack();
Winson Chunge7ba6862017-05-24 12:13:33 -07001393 if (pinnedStack != null) {
1394 pinnedStack.onAllWindowsDrawn();
Robert Carrecc06b32017-04-18 14:25:10 -07001395 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001396 }
1397 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001398 }
1399
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001400 /**
1401 * Updated this app token tracking states for interesting and drawn windows based on the window.
1402 *
1403 * @return Returns true if the input window is considered interesting and drawn while all the
1404 * windows in this app token where not considered drawn as of the last pass.
1405 */
1406 boolean updateDrawnWindowStates(WindowState w) {
Bryce Leed390deb2017-06-22 13:14:28 -07001407 w.setDrawnStateEvaluated(true /*evaluated*/);
1408
Jorim Jaggie4b0f282017-05-17 15:10:29 +02001409 if (DEBUG_STARTING_WINDOW_VERBOSE && w == startingWindow) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001410 Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" + w.isOnScreen()
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001411 + " allDrawn=" + allDrawn + " freezingScreen=" + mFreezingScreen);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001412 }
1413
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001414 if (allDrawn && !mFreezingScreen) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001415 return false;
1416 }
1417
1418 if (mLastTransactionSequence != mService.mTransactionSequence) {
1419 mLastTransactionSequence = mService.mTransactionSequence;
Matthew Ng53e66b22018-01-12 17:13:13 -08001420 mNumDrawnWindows = 0;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001421 startingDisplayed = false;
Matthew Ng53e66b22018-01-12 17:13:13 -08001422
1423 // There is the main base application window, even if it is exiting, wait for it
1424 mNumInterestingWindows = findMainWindow(false /* includeStartingApp */) != null ? 1 : 0;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001425 }
1426
1427 final WindowStateAnimator winAnimator = w.mWinAnimator;
1428
1429 boolean isInterestingAndDrawn = false;
1430
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001431 if (!allDrawn && w.mightAffectAllDrawn()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001432 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
1433 Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw()
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001434 + ", isAnimationSet=" + isSelfAnimating());
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001435 if (!w.isDrawnLw()) {
1436 Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController
1437 + " pv=" + w.mPolicyVisibility
1438 + " mDrawState=" + winAnimator.drawStateToString()
1439 + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001440 + " a=" + isSelfAnimating());
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001441 }
1442 }
1443
1444 if (w != startingWindow) {
1445 if (w.isInteresting()) {
Matthew Ng53e66b22018-01-12 17:13:13 -08001446 // Add non-main window as interesting since the main app has already been added
1447 if (findMainWindow(false /* includeStartingApp */) != w) {
1448 mNumInterestingWindows++;
1449 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001450 if (w.isDrawnLw()) {
1451 mNumDrawnWindows++;
1452
1453 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, "tokenMayBeDrawn: "
1454 + this + " w=" + w + " numInteresting=" + mNumInterestingWindows
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001455 + " freezingScreen=" + mFreezingScreen
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001456 + " mAppFreezing=" + w.mAppFreezing);
1457
1458 isInterestingAndDrawn = true;
1459 }
1460 }
1461 } else if (w.isDrawnLw()) {
Jorim Jaggi3878ca32017-02-02 17:13:05 -08001462 if (getController() != null) {
1463 getController().reportStartingWindowDrawn();
1464 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001465 startingDisplayed = true;
1466 }
1467 }
1468
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001469 return isInterestingAndDrawn;
1470 }
1471
Adrian Roos23df3a32018-03-15 15:41:13 +01001472 void layoutLetterbox(WindowState winHint) {
Adrian Roos4d18a2e2017-12-19 19:08:05 +01001473 final WindowState w = findMainWindow();
1474 if (w != winHint && winHint != null && w != null) {
1475 return;
1476 }
1477 final boolean needsLetterbox = w != null && w.isLetterboxedAppWindow()
1478 && fillsParent() && w.hasDrawnLw();
1479 if (needsLetterbox) {
1480 if (mLetterbox == null) {
1481 mLetterbox = new Letterbox(() -> makeChildSurface(null));
1482 }
Adrian Roos23df3a32018-03-15 15:41:13 +01001483 mLetterbox.layout(getParent().getBounds(), w.mFrame);
Adrian Roos4d18a2e2017-12-19 19:08:05 +01001484 } else if (mLetterbox != null) {
Adrian Roos23df3a32018-03-15 15:41:13 +01001485 mLetterbox.hide();
1486 }
1487 }
1488
1489 void updateLetterboxSurface(WindowState winHint) {
1490 final WindowState w = findMainWindow();
1491 if (w != winHint && winHint != null && w != null) {
1492 return;
1493 }
1494 layoutLetterbox(winHint);
1495 if (mLetterbox != null && mLetterbox.needsApplySurfaceChanges()) {
1496 mLetterbox.applySurfaceChanges(mPendingTransaction);
Adrian Roos4d18a2e2017-12-19 19:08:05 +01001497 }
1498 }
1499
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001500 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001501 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001502 // For legacy reasons we process the TaskStack.mExitingAppTokens first in DisplayContent
1503 // before the non-exiting app tokens. So, we skip the exiting app tokens here.
1504 // TODO: Investigate if we need to continue to do this or if we can just process them
1505 // in-order.
1506 if (mIsExiting && !waitingForReplacement()) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001507 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001508 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001509 return forAllWindowsUnchecked(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001510 }
1511
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001512 boolean forAllWindowsUnchecked(ToBooleanFunction<WindowState> callback,
1513 boolean traverseTopToBottom) {
1514 return super.forAllWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001515 }
1516
1517 @Override
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001518 AppWindowToken asAppWindowToken() {
1519 // I am an app window token!
1520 return this;
1521 }
1522
1523 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -07001524 boolean fillsParent() {
1525 return mFillsParent;
1526 }
1527
1528 void setFillsParent(boolean fillsParent) {
1529 mFillsParent = fillsParent;
1530 }
1531
Jorim Jaggife762342016-10-13 14:33:27 +02001532 boolean containsDismissKeyguardWindow() {
Bryce Lee081554b2017-05-25 07:52:12 -07001533 // Window state is transient during relaunch. We are not guaranteed to be frozen during the
1534 // entirety of the relaunch.
1535 if (isRelaunching()) {
1536 return mLastContainsDismissKeyguardWindow;
1537 }
1538
Jorim Jaggife762342016-10-13 14:33:27 +02001539 for (int i = mChildren.size() - 1; i >= 0; i--) {
1540 if ((mChildren.get(i).mAttrs.flags & FLAG_DISMISS_KEYGUARD) != 0) {
1541 return true;
1542 }
1543 }
1544 return false;
1545 }
1546
1547 boolean containsShowWhenLockedWindow() {
Bryce Lee081554b2017-05-25 07:52:12 -07001548 // When we are relaunching, it is possible for us to be unfrozen before our previous
1549 // windows have been added back. Using the cached value ensures that our previous
1550 // showWhenLocked preference is honored until relaunching is complete.
1551 if (isRelaunching()) {
1552 return mLastContainsShowWhenLockedWindow;
1553 }
1554
Jorim Jaggife762342016-10-13 14:33:27 +02001555 for (int i = mChildren.size() - 1; i >= 0; i--) {
1556 if ((mChildren.get(i).mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
1557 return true;
1558 }
1559 }
Bryce Lee081554b2017-05-25 07:52:12 -07001560
Jorim Jaggife762342016-10-13 14:33:27 +02001561 return false;
1562 }
1563
1564 void checkKeyguardFlagsChanged() {
1565 final boolean containsDismissKeyguard = containsDismissKeyguardWindow();
1566 final boolean containsShowWhenLocked = containsShowWhenLockedWindow();
1567 if (containsDismissKeyguard != mLastContainsDismissKeyguardWindow
1568 || containsShowWhenLocked != mLastContainsShowWhenLockedWindow) {
1569 mService.notifyKeyguardFlagsChanged(null /* callback */);
1570 }
1571 mLastContainsDismissKeyguardWindow = containsDismissKeyguard;
1572 mLastContainsShowWhenLockedWindow = containsShowWhenLocked;
1573 }
1574
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001575 WindowState getImeTargetBelowWindow(WindowState w) {
1576 final int index = mChildren.indexOf(w);
1577 if (index > 0) {
1578 final WindowState target = mChildren.get(index - 1);
1579 if (target.canBeImeTarget()) {
1580 return target;
1581 }
1582 }
1583 return null;
1584 }
1585
Winson Chungbe9be7f2017-06-28 10:55:22 -07001586 int getLowestAnimLayer() {
1587 for (int i = 0; i < mChildren.size(); i++) {
1588 final WindowState w = mChildren.get(i);
1589 if (w.mRemoved) {
1590 continue;
1591 }
1592 return w.mWinAnimator.mAnimLayer;
1593 }
1594 return Integer.MAX_VALUE;
1595 }
1596
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001597 WindowState getHighestAnimLayerWindow(WindowState currentTarget) {
1598 WindowState candidate = null;
1599 for (int i = mChildren.indexOf(currentTarget); i >= 0; i--) {
1600 final WindowState w = mChildren.get(i);
1601 if (w.mRemoved) {
1602 continue;
1603 }
1604 if (candidate == null || w.mWinAnimator.mAnimLayer >
1605 candidate.mWinAnimator.mAnimLayer) {
1606 candidate = w;
1607 }
1608 }
1609 return candidate;
1610 }
1611
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001612 /**
1613 * See {@link Activity#setDisablePreviewScreenshots}.
1614 */
1615 void setDisablePreviewScreenshots(boolean disable) {
Wale Ogunwale6c459212017-05-17 08:56:03 -07001616 mDisablePreviewScreenshots = disable;
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001617 }
1618
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001619 /**
chaviwd3bf08d2017-08-01 17:24:59 -07001620 * Sets whether the current launch can turn the screen on. See {@link #canTurnScreenOn()}
1621 */
1622 void setCanTurnScreenOn(boolean canTurnScreenOn) {
1623 mCanTurnScreenOn = canTurnScreenOn;
1624 }
1625
1626 /**
1627 * Indicates whether the current launch can turn the screen on. This is to prevent multiple
1628 * relayouts from turning the screen back on. The screen should only turn on at most
1629 * once per activity resume.
1630 *
1631 * @return true if the screen can be turned on.
1632 */
1633 boolean canTurnScreenOn() {
1634 return mCanTurnScreenOn;
1635 }
1636
1637 /**
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001638 * Retrieves whether we'd like to generate a snapshot that's based solely on the theme. This is
1639 * the case when preview screenshots are disabled {@link #setDisablePreviewScreenshots} or when
1640 * we can't take a snapshot for other reasons, for example, if we have a secure window.
1641 *
1642 * @return True if we need to generate an app theme snapshot, false if we'd like to take a real
1643 * screenshot.
1644 */
1645 boolean shouldUseAppThemeSnapshot() {
Wale Ogunwale6c459212017-05-17 08:56:03 -07001646 return mDisablePreviewScreenshots || forAllWindows(w -> (w.mAttrs.flags & FLAG_SECURE) != 0,
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001647 true /* topToBottom */);
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001648 }
1649
chaviw23ee71c2017-12-18 11:29:41 -08001650 @Override
Jorim Jaggi596a1992017-12-29 14:48:02 +01001651 public SurfaceControl getAnimationLeashParent() {
Robert Carrb9506032018-02-13 13:54:00 -08001652 // All normal app transitions take place in an animation layer which is below the pinned
1653 // stack but may be above the parent stacks of the given animating apps.
1654 // For transitions in the pinned stack (menu activity) we just let them occur as a child
1655 // of the pinned stack.
1656 if (!inPinnedWindowingMode()) {
1657 return getAppAnimationLayer();
1658 } else {
1659 return getStack().getSurfaceControl();
1660 }
chaviw23ee71c2017-12-18 11:29:41 -08001661 }
1662
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001663 boolean applyAnimationLocked(WindowManager.LayoutParams lp, int transit, boolean enter,
1664 boolean isVoiceInteraction) {
1665
1666 if (mService.mDisableTransitionAnimation) {
1667 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1668 Slog.v(TAG_WM, "applyAnimation: transition animation is disabled. atoken=" + this);
1669 }
1670 cancelAnimation();
1671 return false;
1672 }
1673
1674 // Only apply an animation if the display isn't frozen. If it is frozen, there is no reason
1675 // to animate and it can cause strange artifacts when we unfreeze the display if some
1676 // different animation is running.
1677 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "AWT#applyAnimationLocked");
1678 if (okToAnimate()) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001679 final AnimationAdapter adapter;
1680 final TaskStack stack = getStack();
1681 mTmpPoint.set(0, 0);
1682 mTmpRect.setEmpty();
1683 if (stack != null) {
1684 stack.getRelativePosition(mTmpPoint);
1685 stack.getBounds(mTmpRect);
1686 mTmpRect.offsetTo(0, 0);
1687 }
1688 if (mService.mAppTransition.getRemoteAnimationController() != null) {
1689 adapter = mService.mAppTransition.getRemoteAnimationController()
1690 .createAnimationAdapter(this, mTmpPoint, mTmpRect);
1691 } else {
1692 final Animation a = loadAnimation(lp, transit, enter, isVoiceInteraction);
1693 if (a != null) {
1694 adapter = new LocalAnimationAdapter(
1695 new WindowAnimationSpec(a, mTmpPoint, mTmpRect,
1696 mService.mAppTransition.canSkipFirstFrame(),
1697 mService.mAppTransition.getAppStackClipMode()),
1698 mService.mSurfaceAnimationRunner);
1699 if (a.getZAdjustment() == Animation.ZORDER_TOP) {
1700 mNeedsZBoost = true;
1701 }
1702 mTransit = transit;
1703 mTransitFlags = mService.mAppTransition.getTransitFlags();
1704 } else {
1705 adapter = null;
chaviw23ee71c2017-12-18 11:29:41 -08001706 }
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001707 }
1708 if (adapter != null) {
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001709 startAnimation(getPendingTransaction(), adapter, !isVisible());
Jorim Jaggi82c17862018-02-21 17:50:18 +01001710 if (adapter.getShowWallpaper()) {
1711 mDisplayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
1712 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001713 }
1714 } else {
1715 cancelAnimation();
1716 }
1717 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
1718
1719 return isReallyAnimating();
1720 }
1721
1722 private Animation loadAnimation(WindowManager.LayoutParams lp, int transit, boolean enter,
1723 boolean isVoiceInteraction) {
1724 final DisplayContent displayContent = getTask().getDisplayContent();
1725 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
1726 final int width = displayInfo.appWidth;
1727 final int height = displayInfo.appHeight;
1728 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG_WM,
1729 "applyAnimation: atoken=" + this);
1730
1731 // Determine the visible rect to calculate the thumbnail clip
1732 final WindowState win = findMainWindow();
1733 final Rect frame = new Rect(0, 0, width, height);
1734 final Rect displayFrame = new Rect(0, 0,
1735 displayInfo.logicalWidth, displayInfo.logicalHeight);
1736 final Rect insets = new Rect();
1737 final Rect stableInsets = new Rect();
1738 Rect surfaceInsets = null;
1739 final boolean freeform = win != null && win.inFreeformWindowingMode();
1740 if (win != null) {
1741 // Containing frame will usually cover the whole screen, including dialog windows.
1742 // For freeform workspace windows it will not cover the whole screen and it also
1743 // won't exactly match the final freeform window frame (e.g. when overlapping with
1744 // the status bar). In that case we need to use the final frame.
1745 if (freeform) {
1746 frame.set(win.mFrame);
Adrian Roos4d18a2e2017-12-19 19:08:05 +01001747 } else if (win.isLetterboxedAppWindow()) {
1748 frame.set(getTask().getBounds());
Winson Chungc1674272018-02-21 10:15:17 -08001749 } else if (win.isDockedResizing()) {
1750 // If we are animating while docked resizing, then use the stack bounds as the
1751 // animation target (which will be different than the task bounds)
1752 frame.set(getTask().getParent().getBounds());
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001753 } else {
1754 frame.set(win.mContainingFrame);
1755 }
1756 surfaceInsets = win.getAttrs().surfaceInsets;
Adrian Roos20e07892018-02-23 19:12:01 +01001757 // XXX(b/72757033): These are insets relative to the window frame, but we're really
1758 // interested in the insets relative to the frame we chose in the if-blocks above.
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001759 insets.set(win.mContentInsets);
1760 stableInsets.set(win.mStableInsets);
1761 }
1762
1763 if (mLaunchTaskBehind) {
1764 // Differentiate the two animations. This one which is briefly on the screen
1765 // gets the !enter animation, and the other activity which remains on the
1766 // screen gets the enter animation. Both appear in the mOpeningApps set.
1767 enter = false;
1768 }
1769 if (DEBUG_APP_TRANSITIONS) Slog.d(TAG_WM, "Loading animation for app transition."
1770 + " transit=" + AppTransition.appTransitionToString(transit) + " enter=" + enter
1771 + " frame=" + frame + " insets=" + insets + " surfaceInsets=" + surfaceInsets);
1772 final Configuration displayConfig = displayContent.getConfiguration();
1773 final Animation a = mService.mAppTransition.loadAnimation(lp, transit, enter,
1774 displayConfig.uiMode, displayConfig.orientation, frame, displayFrame, insets,
1775 surfaceInsets, stableInsets, isVoiceInteraction, freeform, getTask().mTaskId);
1776 if (a != null) {
1777 if (DEBUG_ANIM) logWithStack(TAG, "Loaded animation " + a + " for " + this);
1778 final int containingWidth = frame.width();
1779 final int containingHeight = frame.height();
1780 a.initialize(containingWidth, containingHeight, width, height);
1781 a.scaleCurrentDuration(mService.getTransitionAnimationScaleLocked());
1782 }
1783 return a;
1784 }
1785
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001786 @Override
1787 protected void setLayer(Transaction t, int layer) {
1788 if (!mSurfaceAnimator.hasLeash()) {
1789 t.setLayer(mSurfaceControl, layer);
1790 }
1791 }
1792
1793 @Override
1794 protected void setRelativeLayer(Transaction t, SurfaceControl relativeTo, int layer) {
1795 if (!mSurfaceAnimator.hasLeash()) {
1796 t.setRelativeLayer(mSurfaceControl, relativeTo, layer);
1797 }
1798 }
1799
1800 @Override
1801 protected void reparentSurfaceControl(Transaction t, SurfaceControl newParent) {
1802 if (!mSurfaceAnimator.hasLeash()) {
1803 t.reparent(mSurfaceControl, newParent.getHandle());
1804 }
1805 }
1806
1807 @Override
1808 public void onAnimationLeashCreated(Transaction t, SurfaceControl leash) {
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001809 // The leash is parented to the animation layer. We need to preserve the z-order by using
1810 // the prefix order index, but we boost if necessary.
Robert Carrb9506032018-02-13 13:54:00 -08001811 int layer = 0;
1812 if (!inPinnedWindowingMode()) {
1813 layer = getPrefixOrderIndex();
1814 } else {
1815 // Pinned stacks have animations take place within themselves rather than an animation
1816 // layer so we need to preserve the order relative to the stack (e.g. the order of our
1817 // task/parent).
1818 layer = getParent().getPrefixOrderIndex();
1819 }
1820
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001821 if (mNeedsZBoost) {
1822 layer += Z_BOOST_BASE;
1823 }
1824 leash.setLayer(layer);
Robert Carr2f8aa392018-01-31 14:46:51 -08001825
1826 final DisplayContent dc = getDisplayContent();
1827 dc.assignStackOrdering(t);
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001828 }
1829
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001830 /**
1831 * This must be called while inside a transaction.
1832 */
1833 void showAllWindowsLocked() {
1834 forAllWindows(windowState -> {
1835 if (DEBUG_VISIBILITY) Slog.v(TAG, "performing show on: " + windowState);
1836 windowState.performShowLocked();
1837 }, false /* traverseTopToBottom */);
Jorim Jaggia5e10572017-11-15 14:36:26 +01001838 }
1839
1840 @Override
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001841 protected void onAnimationFinished() {
1842 super.onAnimationFinished();
1843
1844 mTransit = TRANSIT_UNSET;
1845 mTransitFlags = 0;
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001846 mNeedsZBoost = false;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001847
1848 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM | FINISH_LAYOUT_REDO_WALLPAPER,
1849 "AppWindowToken");
1850
Jorim Jaggi988f6682017-11-17 17:46:43 +01001851 clearThumbnail();
Jorim Jaggi3cad57f2018-02-20 18:32:01 +01001852 setClientHidden(hiddenRequested);
Jorim Jaggi988f6682017-11-17 17:46:43 +01001853
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001854 if (mService.mInputMethodTarget != null && mService.mInputMethodTarget.mAppToken == this) {
1855 getDisplayContent().computeImeTarget(true /* updateImeTarget */);
1856 }
1857
1858 if (DEBUG_ANIM) Slog.v(TAG, "Animation done in " + this
1859 + ": reportedVisible=" + reportedVisible
1860 + " okToDisplay=" + okToDisplay()
1861 + " okToAnimate=" + okToAnimate()
1862 + " startingDisplayed=" + startingDisplayed);
1863
1864 // WindowState.onExitAnimationDone might modify the children list, so make a copy and then
1865 // traverse the copy.
1866 final ArrayList<WindowState> children = new ArrayList<>(mChildren);
1867 children.forEach(WindowState::onExitAnimationDone);
1868
1869 mService.mAppTransition.notifyAppTransitionFinishedLocked(token);
1870 scheduleAnimation();
1871 }
1872
1873 @Override
1874 boolean isAppAnimating() {
1875 return isSelfAnimating();
1876 }
1877
1878 @Override
1879 boolean isSelfAnimating() {
1880 // If we are about to start a transition, we also need to be considered animating.
1881 return isWaitingForTransitionStart() || isReallyAnimating();
1882 }
1883
1884 /**
1885 * @return True if and only if we are actually running an animation. Note that
1886 * {@link #isSelfAnimating} also returns true if we are waiting for an animation to
1887 * start.
1888 */
1889 private boolean isReallyAnimating() {
1890 return super.isSelfAnimating();
1891 }
1892
Jorim Jaggi988f6682017-11-17 17:46:43 +01001893 @Override
1894 void cancelAnimation() {
1895 super.cancelAnimation();
1896 clearThumbnail();
1897 }
1898
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001899 boolean isWaitingForTransitionStart() {
1900 return mService.mAppTransition.isTransitionSet()
1901 && (mService.mOpeningApps.contains(this) || mService.mClosingApps.contains(this));
1902 }
1903
1904 public int getTransit() {
1905 return mTransit;
1906 }
1907
1908 int getTransitFlags() {
1909 return mTransitFlags;
1910 }
1911
Jorim Jaggi988f6682017-11-17 17:46:43 +01001912 void attachThumbnailAnimation() {
1913 if (!isReallyAnimating()) {
1914 return;
1915 }
1916 final int taskId = getTask().mTaskId;
1917 final GraphicBuffer thumbnailHeader =
1918 mService.mAppTransition.getAppTransitionThumbnailHeader(taskId);
1919 if (thumbnailHeader == null) {
1920 if (DEBUG_APP_TRANSITIONS) Slog.d(TAG, "No thumbnail header bitmap for: " + taskId);
1921 return;
1922 }
1923 clearThumbnail();
1924 mThumbnail = new AppWindowThumbnail(getPendingTransaction(), this, thumbnailHeader);
1925 mThumbnail.startAnimation(getPendingTransaction(), loadThumbnailAnimation(thumbnailHeader));
1926 }
1927
Tony Mak64b8d562017-12-28 17:44:02 +00001928 /**
1929 * Attaches a surface with a thumbnail for the
1930 * {@link android.app.ActivityOptions#ANIM_OPEN_CROSS_PROFILE_APPS} animation.
1931 */
1932 void attachCrossProfileAppsThumbnailAnimation() {
1933 if (!isReallyAnimating()) {
1934 return;
1935 }
1936 clearThumbnail();
1937
1938 final WindowState win = findMainWindow();
1939 if (win == null) {
1940 return;
1941 }
1942 final Rect frame = win.mFrame;
1943 final int thumbnailDrawableRes = getTask().mUserId == mService.mCurrentUserId
1944 ? R.drawable.ic_account_circle
1945 : R.drawable.ic_corp_badge_no_background;
1946 final GraphicBuffer thumbnail =
1947 mService.mAppTransition
1948 .createCrossProfileAppsThumbnail(thumbnailDrawableRes, frame);
1949 if (thumbnail == null) {
1950 return;
1951 }
1952 mThumbnail = new AppWindowThumbnail(getPendingTransaction(), this, thumbnail);
1953 final Animation animation =
1954 mService.mAppTransition.createCrossProfileAppsThumbnailAnimationLocked(win.mFrame);
1955 mThumbnail.startAnimation(getPendingTransaction(), animation, new Point(frame.left,
1956 frame.top));
1957 }
1958
Jorim Jaggi988f6682017-11-17 17:46:43 +01001959 private Animation loadThumbnailAnimation(GraphicBuffer thumbnailHeader) {
1960 final DisplayInfo displayInfo = mDisplayContent.getDisplayInfo();
1961
1962 // If this is a multi-window scenario, we use the windows frame as
1963 // destination of the thumbnail header animation. If this is a full screen
1964 // window scenario, we use the whole display as the target.
1965 WindowState win = findMainWindow();
1966 Rect appRect = win != null ? win.getContentFrameLw() :
1967 new Rect(0, 0, displayInfo.appWidth, displayInfo.appHeight);
1968 Rect insets = win != null ? win.mContentInsets : null;
1969 final Configuration displayConfig = mDisplayContent.getConfiguration();
1970 return mService.mAppTransition.createThumbnailAspectScaleAnimationLocked(
1971 appRect, insets, thumbnailHeader, getTask().mTaskId, displayConfig.uiMode,
1972 displayConfig.orientation);
1973 }
1974
1975 private void clearThumbnail() {
1976 if (mThumbnail == null) {
1977 return;
1978 }
1979 mThumbnail.destroy();
1980 mThumbnail = null;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001981 }
1982
Jorim Jaggif84e2f62018-01-16 14:17:59 +01001983 void registerRemoteAnimations(RemoteAnimationDefinition definition) {
1984 mRemoteAnimationDefinition = definition;
1985 }
1986
1987 RemoteAnimationDefinition getRemoteAnimationDefinition() {
1988 return mRemoteAnimationDefinition;
1989 }
1990
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001991 @Override
1992 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
1993 super.dump(pw, prefix, dumpAll);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001994 if (appToken != null) {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001995 pw.println(prefix + "app=true mVoiceInteraction=" + mVoiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001996 }
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001997 pw.print(prefix); pw.print("task="); pw.println(getTask());
Wale Ogunwale51362492016-09-08 17:49:17 -07001998 pw.print(prefix); pw.print(" mFillsParent="); pw.print(mFillsParent);
1999 pw.print(" mOrientation="); pw.println(mOrientation);
Wale Ogunwale89973222017-04-23 18:39:45 -07002000 pw.println(prefix + "hiddenRequested=" + hiddenRequested + " mClientHidden=" + mClientHidden
2001 + ((mDeferHidingClient) ? " mDeferHidingClient=" + mDeferHidingClient : "")
2002 + " reportedDrawn=" + reportedDrawn + " reportedVisible=" + reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -07002003 if (paused) {
2004 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002005 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -08002006 if (mAppStopped) {
2007 pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped);
2008 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07002009 if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002010 || allDrawn || mLastAllDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07002011 pw.print(prefix); pw.print("mNumInterestingWindows=");
2012 pw.print(mNumInterestingWindows);
2013 pw.print(" mNumDrawnWindows="); pw.print(mNumDrawnWindows);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002014 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -07002015 pw.print(" allDrawn="); pw.print(allDrawn);
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002016 pw.print(" lastAllDrawn="); pw.print(mLastAllDrawn);
Craig Mautner6fbda632012-07-03 09:26:39 -07002017 pw.println(")");
2018 }
2019 if (inPendingTransaction) {
2020 pw.print(prefix); pw.print("inPendingTransaction=");
2021 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002022 }
Craig Mautner799bc1d2015-01-14 10:33:48 -08002023 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002024 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
2025 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -08002026 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -08002027 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002028 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08002029 if (startingWindow != null || startingSurface != null
Wale Ogunwale6c459212017-05-17 08:56:03 -07002030 || startingDisplayed || startingMoved || mHiddenSetFromTransferredStartingWindow) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002031 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08002032 pw.print(" startingSurface="); pw.print(startingSurface);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002033 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
Wale Ogunwale6c459212017-05-17 08:56:03 -07002034 pw.print(" startingMoved="); pw.print(startingMoved);
2035 pw.println(" mHiddenSetFromTransferredStartingWindow="
2036 + mHiddenSetFromTransferredStartingWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002037 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01002038 if (!mFrozenBounds.isEmpty()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -08002039 pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds);
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002040 pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig);
Chong Zhangd78ddb42016-03-02 17:01:14 -08002041 }
2042 if (mPendingRelaunchCount != 0) {
2043 pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount);
Jorim Jaggi0429f352015-12-22 16:29:16 +01002044 }
Wale Ogunwale9c64cb62017-04-12 13:39:59 -07002045 if (getController() != null) {
2046 pw.print(prefix); pw.print("controller="); pw.println(getController());
2047 }
Wale Ogunwalee287e192017-04-21 09:30:12 -07002048 if (mRemovingFromDisplay) {
2049 pw.println(prefix + "mRemovingFromDisplay=" + mRemovingFromDisplay);
2050 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002051 }
2052
2053 @Override
2054 void setHidden(boolean hidden) {
2055 super.setHidden(hidden);
Winson Chunge55c0192017-08-24 14:50:48 -07002056
2057 if (hidden) {
2058 // Once the app window is hidden, reset the last saved PiP snap fraction
2059 mDisplayContent.mPinnedStackControllerLocked.resetReentrySnapFraction(this);
2060 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002061 scheduleAnimation();
2062 }
2063
2064 @Override
2065 void prepareSurfaces() {
2066 // isSelfAnimating also returns true when we are about to start a transition, so we need
2067 // to check super here.
2068 final boolean reallyAnimating = super.isSelfAnimating();
2069 final boolean show = !isHidden() || reallyAnimating;
2070 if (show && !mLastSurfaceShowing) {
2071 mPendingTransaction.show(mSurfaceControl);
2072 } else if (!show && mLastSurfaceShowing) {
2073 mPendingTransaction.hide(mSurfaceControl);
Jorim Jaggi4d1835d2017-08-31 17:28:27 +02002074 }
Jorim Jaggi988f6682017-11-17 17:46:43 +01002075 if (mThumbnail != null) {
2076 mThumbnail.setShowing(mPendingTransaction, show);
2077 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002078 mLastSurfaceShowing = show;
2079 super.prepareSurfaces();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002080 }
2081
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002082 boolean isFreezingScreen() {
2083 return mFreezingScreen;
2084 }
2085
2086 @Override
2087 boolean needsZBoost() {
2088 return mNeedsZBoost || super.needsZBoost();
2089 }
2090
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07002091 @CallSuper
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002092 @Override
Adrian Roos4921ccf2017-09-28 16:54:06 +02002093 public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07002094 final long token = proto.start(fieldId);
2095 writeNameToProto(proto, NAME);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002096 super.writeToProto(proto, WINDOW_TOKEN, trim);
Vishnu Nair04ab4392018-01-10 11:00:06 -08002097 proto.write(LAST_SURFACE_SHOWING, mLastSurfaceShowing);
2098 proto.write(IS_WAITING_FOR_TRANSITION_START, isWaitingForTransitionStart());
2099 proto.write(IS_REALLY_ANIMATING, isReallyAnimating());
2100 if (mThumbnail != null){
2101 mThumbnail.writeToProto(proto, THUMBNAIL);
2102 }
2103 proto.write(FILLS_PARENT, mFillsParent);
2104 proto.write(APP_STOPPED, mAppStopped);
2105 proto.write(HIDDEN_REQUESTED, hiddenRequested);
2106 proto.write(CLIENT_HIDDEN, mClientHidden);
2107 proto.write(DEFER_HIDING_CLIENT, mDeferHidingClient);
2108 proto.write(REPORTED_DRAWN, reportedDrawn);
2109 proto.write(REPORTED_VISIBLE, reportedVisible);
2110 proto.write(NUM_INTERESTING_WINDOWS, mNumInterestingWindows);
2111 proto.write(NUM_DRAWN_WINDOWS, mNumDrawnWindows);
2112 proto.write(ALL_DRAWN, allDrawn);
2113 proto.write(LAST_ALL_DRAWN, mLastAllDrawn);
2114 proto.write(REMOVED, removed);
2115 if (startingWindow != null){
2116 startingWindow.writeIdentifierToProto(proto, STARTING_WINDOW);
2117 }
2118 proto.write(STARTING_DISPLAYED, startingDisplayed);
2119 proto.write(STARTING_MOVED, startingMoved);
2120 proto.write(HIDDEN_SET_FROM_TRANSFERRED_STARTING_WINDOW,
2121 mHiddenSetFromTransferredStartingWindow);
2122 for (Rect bounds : mFrozenBounds) {
2123 bounds.writeToProto(proto, FROZEN_BOUNDS);
2124 }
Steven Timotiusaf03df62017-07-18 16:56:43 -07002125 proto.end(token);
2126 }
2127
2128 void writeNameToProto(ProtoOutputStream proto, long fieldId) {
2129 if (appToken == null) {
2130 return;
2131 }
2132 try {
2133 proto.write(fieldId, appToken.getName());
2134 } catch (RemoteException e) {
2135 // This shouldn't happen, but in this case fall back to outputting nothing
2136 Slog.e(TAG, e.toString());
2137 }
2138 }
2139
2140 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002141 public String toString() {
2142 if (stringName == null) {
2143 StringBuilder sb = new StringBuilder();
2144 sb.append("AppWindowToken{");
2145 sb.append(Integer.toHexString(System.identityHashCode(this)));
2146 sb.append(" token="); sb.append(token); sb.append('}');
2147 stringName = sb.toString();
2148 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07002149 return stringName + ((mIsExiting) ? " mIsExiting=" : "");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002150 }
Adrian Roos20e07892018-02-23 19:12:01 +01002151
2152 Rect getLetterboxInsets() {
2153 if (mLetterbox != null) {
2154 return mLetterbox.getInsets();
2155 } else {
2156 return new Rect();
2157 }
2158 }
Adrian Roos23df3a32018-03-15 15:41:13 +01002159
2160 /**
2161 * @eturn true if there is a letterbox and any part of that letterbox overlaps with
2162 * the given {@code rect}.
2163 */
2164 boolean isLetterboxOverlappingWith(Rect rect) {
2165 return mLetterbox != null && mLetterbox.isOverlappingWith(rect);
2166 }
Jeff Browne9bdb312012-04-05 15:30:10 -07002167}