blob: 0dfef3aa63e130f6b8057621711377eeaa9c024e [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;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070036import static com.android.server.wm.AppTransition.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;
Robert Carr6914f082017-03-20 19:04:30 -070093import android.view.SurfaceControl;
Tony Mak64b8d562017-12-28 17:44:02 +000094import android.view.SurfaceControl.Transaction;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080095import android.view.WindowManager;
Jorim Jaggi87fdbcb2017-08-17 13:41:11 +020096import android.view.WindowManager.LayoutParams;
Tony Mak64b8d562017-12-28 17:44:02 +000097import android.view.animation.Animation;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080098
Tony Mak64b8d562017-12-28 17:44:02 +000099import com.android.internal.R;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800100import com.android.internal.util.ToBooleanFunction;
101import com.android.server.input.InputApplicationHandle;
Adrian Roose99bc052017-11-20 17:55:31 +0100102import com.android.server.policy.WindowManagerPolicy.StartingSurface;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800103import com.android.server.wm.WindowManagerService.H;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800104
105import java.io.PrintWriter;
Jorim Jaggi0429f352015-12-22 16:29:16 +0100106import java.util.ArrayDeque;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800107import java.util.ArrayList;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100108import java.util.LinkedList;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800109
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;
Wale Ogunwale6c459212017-05-17 08:56:03 -0700189 // True if the hidden state of this token was forced to false due to a transferred starting
190 // window.
191 private boolean mHiddenSetFromTransferredStartingWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800192 boolean firstWindowDrawn;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700193 private final WindowState.UpdateReportedVisibilityResults mReportedVisibilityResults =
194 new WindowState.UpdateReportedVisibilityResults();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800195
196 // Input application handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700197 final InputApplicationHandle mInputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800198
Wale Ogunwale571771c2016-08-26 13:18:50 -0700199 // TODO: Have a WindowContainer state for tracking exiting/deferred removal.
Craig Mautner799bc1d2015-01-14 10:33:48 -0800200 boolean mIsExiting;
Craig Mautner9ef471f2014-02-07 13:11:47 -0800201
Craig Mautnerbb742462014-07-07 15:28:55 -0700202 boolean mLaunchTaskBehind;
Craig Mautner8746a472014-07-24 15:12:54 -0700203 boolean mEnteringAnimation;
Craig Mautnerbb742462014-07-07 15:28:55 -0700204
Wale Ogunwale72919d22016-12-08 18:58:50 -0800205 private boolean mAlwaysFocusable;
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800206
Robert Carre12aece2016-02-02 22:43:27 -0800207 boolean mAppStopped;
Robert Carrfd10cd12016-06-29 16:41:50 -0700208 int mRotationAnimationHint;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700209 private int mPendingRelaunchCount;
Robert Carre12aece2016-02-02 22:43:27 -0800210
Jorim Jaggife762342016-10-13 14:33:27 +0200211 private boolean mLastContainsShowWhenLockedWindow;
212 private boolean mLastContainsDismissKeyguardWindow;
213
Jorim Jaggi0429f352015-12-22 16:29:16 +0100214 ArrayDeque<Rect> mFrozenBounds = new ArrayDeque<>();
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700215 ArrayDeque<Configuration> mFrozenMergedConfig = new ArrayDeque<>();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100216
Wale Ogunwale6c459212017-05-17 08:56:03 -0700217 private boolean mDisablePreviewScreenshots;
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +0100218
Wale Ogunwale034a8ec2017-09-02 17:14:40 -0700219 private Task mLastParent;
Robert Carred3e83b2017-04-21 13:26:55 -0700220
chaviwd3bf08d2017-08-01 17:24:59 -0700221 /**
222 * See {@link #canTurnScreenOn()}
223 */
224 private boolean mCanTurnScreenOn = true;
225
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200226 /**
227 * If we are running an animation, this determines the transition type. Must be one of
228 * AppTransition.TRANSIT_* constants.
229 */
230 private int mTransit;
231
232 /**
233 * If we are running an animation, this determines the flags during this animation. Must be a
234 * bitwise combination of AppTransition.TRANSIT_FLAG_* constants.
235 */
236 private int mTransitFlags;
237
238 /** Whether our surface was set to be showing in the last call to {@link #prepareSurfaces} */
Jorim Jaggifd1891462017-12-29 15:41:36 +0100239 private boolean mLastSurfaceShowing = true;
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200240
Jorim Jaggi988f6682017-11-17 17:46:43 +0100241 private AppWindowThumbnail mThumbnail;
242
Jorim Jaggib0fc8172017-11-23 17:04:08 +0000243 /** Have we been asked to have this token keep the screen frozen? */
244 private boolean mFreezingScreen;
245
246 /** Whether this token should be boosted at the top of all app window tokens. */
247 private boolean mNeedsZBoost;
248
chaviw23ee71c2017-12-18 11:29:41 -0800249 private final Point mTmpPoint = new Point();
chaviw23012112017-12-20 15:29:04 -0800250 private final Rect mTmpRect = new Rect();
chaviw23ee71c2017-12-18 11:29:41 -0800251
Wale Ogunwale72919d22016-12-08 18:58:50 -0800252 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
253 DisplayContent dc, long inputDispatchingTimeoutNanos, boolean fullscreen,
254 boolean showForAllUsers, int targetSdk, int orientation, int rotationAnimationHint,
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800255 int configChanges, boolean launchTaskBehind, boolean alwaysFocusable,
Bryce Leef3c6a472017-11-14 14:53:06 -0800256 AppWindowContainerController controller) {
257 this(service, token, voiceInteraction, dc, fullscreen);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800258 setController(controller);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800259 mInputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800260 mShowForAllUsers = showForAllUsers;
261 mTargetSdk = targetSdk;
262 mOrientation = orientation;
263 layoutConfigChanges = (configChanges & (CONFIG_SCREEN_SIZE | CONFIG_ORIENTATION)) != 0;
264 mLaunchTaskBehind = launchTaskBehind;
265 mAlwaysFocusable = alwaysFocusable;
266 mRotationAnimationHint = rotationAnimationHint;
267
268 // Application tokens start out hidden.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200269 setHidden(true);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800270 hiddenRequested = true;
271 }
272
273 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
Bryce Leef3c6a472017-11-14 14:53:06 -0800274 DisplayContent dc, boolean fillsParent) {
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800275 super(service, token != null ? token.asBinder() : null, TYPE_APPLICATION, true, dc,
276 false /* ownerCanManageAppTokens */);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700277 appToken = token;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800278 mVoiceInteraction = voiceInteraction;
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800279 mFillsParent = fillsParent;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800280 mInputApplicationHandle = new InputApplicationHandle(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800281 }
282
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800283 void onFirstWindowDrawn(WindowState win, WindowStateAnimator winAnimator) {
284 firstWindowDrawn = true;
285
286 // We now have a good window to show, remove dead placeholders
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700287 removeDeadWindows();
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800288
Jorim Jaggi02886a82016-12-06 09:10:06 -0800289 if (startingWindow != null) {
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800290 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, "Finish starting "
291 + win.mToken + ": first real window is shown, no animation");
292 // If this initial window is animating, stop it -- we will do an animation to reveal
293 // it from behind the starting window, so there is no need for it to also be doing its
294 // own stuff.
Jorim Jaggia5e10572017-11-15 14:36:26 +0100295 win.cancelAnimation();
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800296 if (getController() != null) {
297 getController().removeStartingWindow();
298 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800299 }
300 updateReportedVisibilityLocked();
301 }
302
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800303 void updateReportedVisibilityLocked() {
304 if (appToken == null) {
305 return;
306 }
307
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700308 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700309 final int count = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800310
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700311 mReportedVisibilityResults.reset();
312
313 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700314 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700315 win.updateReportedVisibility(mReportedVisibilityResults);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800316 }
317
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700318 int numInteresting = mReportedVisibilityResults.numInteresting;
319 int numVisible = mReportedVisibilityResults.numVisible;
320 int numDrawn = mReportedVisibilityResults.numDrawn;
321 boolean nowGone = mReportedVisibilityResults.nowGone;
322
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700323 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200324 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting && !isHidden();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700325 if (!nowGone) {
326 // If the app is not yet gone, then it can only become visible/drawn.
327 if (!nowDrawn) {
328 nowDrawn = reportedDrawn;
329 }
330 if (!nowVisible) {
331 nowVisible = reportedVisible;
332 }
333 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800334 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800335 + numInteresting + " visible=" + numVisible);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800336 final AppWindowContainerController controller = getController();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700337 if (nowDrawn != reportedDrawn) {
338 if (nowDrawn) {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800339 if (controller != null) {
340 controller.reportWindowsDrawn();
341 }
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700342 }
343 reportedDrawn = nowDrawn;
344 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800345 if (nowVisible != reportedVisible) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700346 if (DEBUG_VISIBILITY) Slog.v(TAG,
347 "Visibility changed in " + this + ": vis=" + nowVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800348 reportedVisible = nowVisible;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800349 if (controller != null) {
350 if (nowVisible) {
351 controller.reportWindowsVisible();
352 } else {
353 controller.reportWindowsGone();
354 }
355 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800356 }
357 }
358
Wale Ogunwale89973222017-04-23 18:39:45 -0700359 boolean isClientHidden() {
360 return mClientHidden;
361 }
362
363 void setClientHidden(boolean hideClient) {
364 if (mClientHidden == hideClient || (hideClient && mDeferHidingClient)) {
365 return;
366 }
367 mClientHidden = hideClient;
368 sendAppVisibilityToClients();
369 }
370
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700371 boolean setVisibility(WindowManager.LayoutParams lp,
372 boolean visible, int transit, boolean performLayout, boolean isVoiceInteraction) {
373
374 boolean delayed = false;
375 inPendingTransaction = false;
Wale Ogunwale9e4721f2017-05-23 19:37:30 -0700376 // Reset the state of mHiddenSetFromTransferredStartingWindow since visibility is actually
377 // been set by the app now.
378 mHiddenSetFromTransferredStartingWindow = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700379
380 // Allow for state changes and animation to be applied if:
381 // * token is transitioning visibility state
382 // * or the token was marked as hidden and is exiting before we had a chance to play the
383 // transition animation
384 // * or this is an opening app and windows are being replaced.
385 boolean visibilityChanged = false;
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200386 if (isHidden() == visible || (isHidden() && mIsExiting) || (visible && waitingForReplacement())) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700387 final AccessibilityController accessibilityController = mService.mAccessibilityController;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700388 boolean changed = false;
389 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200390 "Changing app " + this + " hidden=" + isHidden() + " performLayout=" + performLayout);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700391
392 boolean runningAppAnimation = false;
393
394 if (transit != AppTransition.TRANSIT_UNSET) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200395 if (applyAnimationLocked(lp, transit, visible, isVoiceInteraction)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700396 delayed = runningAppAnimation = true;
397 }
398 final WindowState window = findMainWindow();
399 //TODO (multidisplay): Magnification is supported only for the default display.
400 if (window != null && accessibilityController != null
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700401 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700402 accessibilityController.onAppWindowTransitionLocked(window, transit);
403 }
404 changed = true;
405 }
406
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700407 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700408 for (int i = 0; i < windowsCount; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700409 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700410 changed |= win.onAppVisibilityChanged(visible, runningAppAnimation);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700411 }
412
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200413 setHidden(!visible);
414 hiddenRequested = !visible;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700415 visibilityChanged = true;
416 if (!visible) {
417 stopFreezingScreen(true, true);
418 } else {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700419 // If we are being set visible, and the starting window is not yet displayed,
420 // then make sure it doesn't get displayed.
421 if (startingWindow != null && !startingWindow.isDrawnLw()) {
422 startingWindow.mPolicyVisibility = false;
423 startingWindow.mPolicyVisibilityAfterAnim = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700424 }
Jorim Jaggi38d44ec2017-06-14 16:04:59 -0700425
426 // We are becoming visible, so better freeze the screen with the windows that are
427 // getting visible so we also wait for them.
428 forAllWindows(mService::makeWindowFreezingScreenIfNeededLocked, true);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700429 }
430
431 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setVisibility: " + this
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200432 + ": hidden=" + isHidden() + " hiddenRequested=" + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700433
434 if (changed) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700435 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700436 if (performLayout) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700437 mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700438 false /*updateInputWindows*/);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700439 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700440 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700441 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700442 }
443 }
444
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200445 if (isReallyAnimating()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700446 delayed = true;
447 }
448
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700449 for (int i = mChildren.size() - 1; i >= 0 && !delayed; i--) {
Jorim Jaggia5e10572017-11-15 14:36:26 +0100450 if ((mChildren.get(i)).isSelfOrChildAnimating()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700451 delayed = true;
452 }
453 }
454
455 if (visibilityChanged) {
456 if (visible && !delayed) {
457 // The token was made immediately visible, there will be no entrance animation.
458 // We need to inform the client the enter animation was finished.
459 mEnteringAnimation = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700460 mService.mActivityManagerAppTransitionNotifier.onAppTransitionFinishedLocked(token);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700461 }
Robert Carr61b81112017-07-17 18:08:15 -0700462
Jorim Jaggi4876b4a2018-01-11 15:43:49 +0100463 // Update the client visibility if we are not running an animation. Otherwise, we'll
464 // update client visibility state in onAnimationFinished.
465 if (!visible && !delayed) {
466 setClientHidden(true);
467 }
468
Robert Carre7cc44d2017-03-20 19:04:30 -0700469 // If we are hidden but there is no delay needed we immediately
470 // apply the Surface transaction so that the ActivityManager
Robert Carr61b81112017-07-17 18:08:15 -0700471 // can have some guarantee on the Surface state following
472 // setting the visibility. This captures cases like dismissing
473 // the docked or pinned stack where there is no app transition.
474 //
475 // In the case of a "Null" animation, there will be
476 // no animation but there will still be a transition set.
477 // We still need to delay hiding the surface such that it
478 // can be synchronized with showing the next surface in the transition.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200479 if (isHidden() && !delayed && !mService.mAppTransition.isTransitionSet()) {
Robert Carr6914f082017-03-20 19:04:30 -0700480 SurfaceControl.openTransaction();
481 for (int i = mChildren.size() - 1; i >= 0; i--) {
482 mChildren.get(i).mWinAnimator.hide("immediately hidden");
483 }
484 SurfaceControl.closeTransaction();
485 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700486
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700487 if (!mService.mClosingApps.contains(this) && !mService.mOpeningApps.contains(this)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700488 // The token is not closing nor opening, so even if there is an animation set, that
489 // doesn't mean that it goes through the normal app transition cycle so we have
490 // to inform the docked controller about visibility change.
Andrii Kulian1e32e022016-09-16 15:29:34 -0700491 // TODO(multi-display): notify docked divider on all displays where visibility was
492 // affected.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700493 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700494 .notifyAppVisibilityChanged();
Jorim Jaggi8b702ed2017-01-20 16:59:03 +0100495 mService.mTaskSnapshotController.notifyAppVisibilityChanged(this, visible);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700496 }
497 }
498
499 return delayed;
500 }
501
Jorim Jaggi87fdbcb2017-08-17 13:41:11 +0200502 /**
503 * @return The to top most child window for which {@link LayoutParams#isFullscreen()} returns
504 * true.
505 */
506 WindowState getTopFullscreenWindow() {
507 for (int i = mChildren.size() - 1; i >= 0; i--) {
508 final WindowState win = mChildren.get(i);
509 if (win != null && win.mAttrs.isFullscreen()) {
510 return win;
511 }
512 }
513 return null;
514 }
515
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800516 WindowState findMainWindow() {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700517 WindowState candidate = null;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700518 int j = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800519 while (j > 0) {
520 j--;
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700521 final WindowState win = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700522 final int type = win.mAttrs.type;
523 // No need to loop through child window as base application and starting types can't be
524 // child windows.
525 if (type == TYPE_BASE_APPLICATION || type == TYPE_APPLICATION_STARTING) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700526 // In cases where there are multiple windows, we prefer the non-exiting window. This
Sungsoo Lim0d3d1f82015-12-02 14:47:59 +0900527 // happens for example when replacing windows during an activity relaunch. When
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700528 // constructing the animation, we want the new window, not the exiting one.
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800529 if (win.mAnimatingExit) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700530 candidate = win;
531 } else {
532 return win;
533 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800534 }
535 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700536 return candidate;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800537 }
538
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800539 boolean windowsAreFocusable() {
Wale Ogunwale3382ab12017-07-27 08:55:03 -0700540 return getWindowConfiguration().canReceiveKeys() || mAlwaysFocusable;
Wale Ogunwaled045c822015-12-02 09:14:28 -0800541 }
542
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800543 AppWindowContainerController getController() {
544 final WindowContainerController controller = super.getController();
545 return controller != null ? (AppWindowContainerController) controller : null;
546 }
547
Wale Ogunwale571771c2016-08-26 13:18:50 -0700548 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -0700549 boolean isVisible() {
Wale Ogunwalee471be62016-10-03 07:53:55 -0700550 // If the app token isn't hidden then it is considered visible and there is no need to check
551 // its children windows to see if they are visible.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200552 return !isHidden();
Wale Ogunwale44f21802016-09-02 12:49:48 -0700553 }
554
555 @Override
Wale Ogunwalee287e192017-04-21 09:30:12 -0700556 void removeImmediately() {
557 onRemovedFromDisplay();
558 super.removeImmediately();
559 }
560
561 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -0700562 void removeIfPossible() {
Craig Mautnere3119b72015-01-20 15:02:36 -0800563 mIsExiting = false;
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800564 removeAllWindowsIfPossible();
Bryce Lee6d410262017-02-28 15:30:17 -0800565 removeImmediately();
Craig Mautnere3119b72015-01-20 15:02:36 -0800566 }
567
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700568 @Override
569 boolean checkCompleteDeferredRemoval() {
570 if (mIsExiting) {
571 removeIfPossible();
572 }
573 return super.checkCompleteDeferredRemoval();
574 }
575
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700576 void onRemovedFromDisplay() {
Wale Ogunwalee287e192017-04-21 09:30:12 -0700577 if (mRemovingFromDisplay) {
578 return;
579 }
580 mRemovingFromDisplay = true;
581
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700582 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app token: " + this);
583
Wale Ogunwale72919d22016-12-08 18:58:50 -0800584 boolean delayed = setVisibility(null, false, TRANSIT_UNSET, true, mVoiceInteraction);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700585
586 mService.mOpeningApps.remove(this);
Jorim Jaggi45ca0542017-05-30 16:16:01 -0700587 mService.mUnknownAppVisibilityController.appRemovedOrHidden(this);
Jorim Jaggi10abe2f2017-01-03 16:44:46 +0100588 mService.mTaskSnapshotController.onAppRemoved(this);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700589 waitingToShow = false;
590 if (mService.mClosingApps.contains(this)) {
591 delayed = true;
592 } else if (mService.mAppTransition.isTransitionSet()) {
593 mService.mClosingApps.add(this);
594 delayed = true;
595 }
596
597 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app " + this + " delayed=" + delayed
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200598 + " animation=" + getAnimation() + " animating=" + isSelfAnimating());
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700599
600 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM, "removeAppToken: "
601 + this + " delayed=" + delayed + " Callers=" + Debug.getCallers(4));
602
Jorim Jaggi19be6052017-08-03 18:33:43 +0200603 if (startingData != null && getController() != null) {
604 getController().removeStartingWindow();
605 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800606
Winson Chung87e5d552017-04-05 11:49:38 -0700607 // If this window was animating, then we need to ensure that the app transition notifies
608 // that animations have completed in WMS.handleAnimatingStoppedAndTransitionLocked(), so
609 // add to that list now
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200610 if (isSelfAnimating()) {
Winson Chung87e5d552017-04-05 11:49:38 -0700611 mService.mNoAnimationNotifyOnTransitionFinished.add(token);
612 }
613
Wale Ogunwalee287e192017-04-21 09:30:12 -0700614 final TaskStack stack = getStack();
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700615 if (delayed && !isEmpty()) {
616 // set the token aside because it has an active animation to be finished
617 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM,
618 "removeAppToken make exiting: " + this);
Wale Ogunwalee287e192017-04-21 09:30:12 -0700619 if (stack != null) {
620 stack.mExitingAppTokens.add(this);
621 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700622 mIsExiting = true;
623 } else {
624 // Make sure there is no animation running on this token, so any windows associated
625 // with it will be removed as soon as their animations are complete
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200626 cancelAnimation();
Wale Ogunwale3106ae012017-05-16 08:56:37 -0700627 if (stack != null) {
628 stack.mExitingAppTokens.remove(this);
629 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700630 removeIfPossible();
631 }
632
633 removed = true;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700634 stopFreezingScreen(true, true);
Bryce Lee6d410262017-02-28 15:30:17 -0800635
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700636 if (mService.mFocusedApp == this) {
637 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "Removing focused app token:" + this);
638 mService.mFocusedApp = null;
639 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
640 mService.mInputMonitor.setFocusedAppLw(null);
641 }
642
643 if (!delayed) {
644 updateReportedVisibilityLocked();
645 }
Wale Ogunwalee287e192017-04-21 09:30:12 -0700646
647 mRemovingFromDisplay = false;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700648 }
649
Chong Zhange05bcb12016-07-26 17:47:29 -0700650 void clearAnimatingFlags() {
Chong Zhangb0d26702016-08-12 16:03:29 -0700651 boolean wallpaperMightChange = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700652 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700653 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700654 wallpaperMightChange |= win.clearAnimatingFlags();
Chong Zhange05bcb12016-07-26 17:47:29 -0700655 }
Chong Zhangb0d26702016-08-12 16:03:29 -0700656 if (wallpaperMightChange) {
657 requestUpdateWallpaperIfNeeded();
658 }
Chong Zhange05bcb12016-07-26 17:47:29 -0700659 }
660
Robert Carre12aece2016-02-02 22:43:27 -0800661 void destroySurfaces() {
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700662 destroySurfaces(false /*cleanupOnResume*/);
663 }
664
665 /**
666 * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure
667 * the client has finished with them.
668 *
669 * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If
670 * set to true, destroy only surfaces of removed windows, and clear relevant flags of the
671 * others so that they are ready to be reused. If set to false (common case), destroy all
672 * surfaces that's eligible, if the app is already stopped.
673 */
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700674 private void destroySurfaces(boolean cleanupOnResume) {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700675 boolean destroyedSomething = false;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100676
677 // Copying to a different list as multiple children can be removed.
Jorim Jaggi59f3e922018-01-05 15:40:32 +0100678 final ArrayList<WindowState> children = new ArrayList<>(mChildren);
Jorim Jaggia5e10572017-11-15 14:36:26 +0100679 for (int i = children.size() - 1; i >= 0; i--) {
680 final WindowState win = children.get(i);
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700681 destroyedSomething |= win.destroySurface(cleanupOnResume, mAppStopped);
Robert Carre12aece2016-02-02 22:43:27 -0800682 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700683 if (destroyedSomething) {
684 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700685 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Robert Carre12aece2016-02-02 22:43:27 -0800686 }
687 }
688
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800689 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700690 * Notify that the app is now resumed, and it was not stopped before, perform a clean
691 * up of the surfaces
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800692 */
Jorim Jaggibae01b12017-04-11 16:29:10 -0700693 void notifyAppResumed(boolean wasStopped) {
Chong Zhangad24f962016-08-25 12:12:33 -0700694 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped
Jorim Jaggibae01b12017-04-11 16:29:10 -0700695 + " " + this);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700696 mAppStopped = false;
chaviwd3bf08d2017-08-01 17:24:59 -0700697 // Allow the window to turn the screen on once the app is resumed again.
698 setCanTurnScreenOn(true);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700699 if (!wasStopped) {
700 destroySurfaces(true /*cleanupOnResume*/);
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800701 }
Robert Carre12aece2016-02-02 22:43:27 -0800702 }
703
Chong Zhangbef461f2015-10-27 11:38:24 -0700704 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700705 * Notify that the app has stopped, and it is okay to destroy any surfaces which were
706 * keeping alive in case they were still being used.
707 */
708 void notifyAppStopped() {
709 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this);
710 mAppStopped = true;
711 destroySurfaces();
712 // Remove any starting window that was added for this app if they are still around.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800713 if (getController() != null) {
714 getController().removeStartingWindow();
715 }
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700716 }
717
Chong Zhang92147042016-05-09 12:47:11 -0700718 void clearAllDrawn() {
719 allDrawn = false;
720 deferClearAllDrawn = false;
Chong Zhangbef461f2015-10-27 11:38:24 -0700721 }
722
Bryce Lee6d410262017-02-28 15:30:17 -0800723 Task getTask() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800724 return (Task) getParent();
Bryce Lee6d410262017-02-28 15:30:17 -0800725 }
726
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800727 TaskStack getStack() {
728 final Task task = getTask();
729 if (task != null) {
730 return task.mStack;
731 } else {
732 return null;
733 }
734 }
735
Bryce Lee6d410262017-02-28 15:30:17 -0800736 @Override
737 void onParentSet() {
738 super.onParentSet();
739
Robert Carred3e83b2017-04-21 13:26:55 -0700740 final Task task = getTask();
741
Bryce Lee6d410262017-02-28 15:30:17 -0800742 // When the associated task is {@code null}, the {@link AppWindowToken} can no longer
743 // access visual elements like the {@link DisplayContent}. We must remove any associations
744 // such as animations.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800745 if (!mReparenting) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800746 if (task == null) {
747 // It is possible we have been marked as a closing app earlier. We must remove ourselves
748 // from this list so we do not participate in any future animations.
749 mService.mClosingApps.remove(this);
Robert Carred3e83b2017-04-21 13:26:55 -0700750 } else if (mLastParent != null && mLastParent.mStack != null) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800751 task.mStack.mExitingAppTokens.remove(this);
752 }
Bryce Lee6d410262017-02-28 15:30:17 -0800753 }
Robert Carred3e83b2017-04-21 13:26:55 -0700754 mLastParent = task;
Bryce Lee6d410262017-02-28 15:30:17 -0800755 }
756
Wale Ogunwalefa854eb2016-09-20 13:43:52 -0700757 void postWindowRemoveStartingWindowCleanup(WindowState win) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700758 // TODO: Something smells about the code below...Is there a better way?
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700759 if (startingWindow == win) {
760 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800761 if (getController() != null) {
762 getController().removeStartingWindow();
763 }
Wale Ogunwale6c459212017-05-17 08:56:03 -0700764 } else if (mChildren.size() == 0) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700765 // If this is the last window and we had requested a starting transition window,
766 // well there is no point now.
Jorim Jaggi02886a82016-12-06 09:10:06 -0800767 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingData");
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700768 startingData = null;
Wale Ogunwale6c459212017-05-17 08:56:03 -0700769 if (mHiddenSetFromTransferredStartingWindow) {
770 // We set the hidden state to false for the token from a transferred starting window.
771 // We now reset it back to true since the starting window was the last window in the
772 // token.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200773 setHidden(true);
Wale Ogunwale6c459212017-05-17 08:56:03 -0700774 }
Jorim Jaggi829b9cd2017-01-23 16:20:53 +0100775 } else if (mChildren.size() == 1 && startingSurface != null && !isRelaunching()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700776 // If this is the last window except for a starting transition window,
777 // we need to get rid of the starting transition.
Jorim Jaggie4b0f282017-05-17 15:10:29 +0200778 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Last window, removing starting window "
779 + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800780 if (getController() != null) {
781 getController().removeStartingWindow();
782 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700783 }
784 }
785
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700786 void removeDeadWindows() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700787 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700788 WindowState win = mChildren.get(winNdx);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800789 if (win.mAppDied) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700790 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700791 "removeDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800792 // Set mDestroying, we don't want any animation or delayed removal here.
793 win.mDestroying = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700794 // Also removes child windows.
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700795 win.removeIfPossible();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800796 }
797 }
798 }
799
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700800 boolean hasWindowsAlive() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700801 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700802 // No need to loop through child windows as the answer should be the same as that of the
803 // parent window.
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700804 if (!(mChildren.get(i)).mAppDied) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700805 return true;
806 }
807 }
808 return false;
809 }
810
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700811 void setWillReplaceWindows(boolean animate) {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700812 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
813 "Marking app token " + this + " with replacing windows.");
Robert Carra1eb4392015-12-10 12:43:51 -0800814
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700815 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700816 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700817 w.setWillReplaceWindow(animate);
Robert Carra1eb4392015-12-10 12:43:51 -0800818 }
Robert Carra1eb4392015-12-10 12:43:51 -0800819 }
820
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700821 void setWillReplaceChildWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700822 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this
Robert Carr23fa16b2016-01-13 13:19:58 -0800823 + " with replacing child windows.");
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700824 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700825 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700826 w.setWillReplaceChildWindows();
Robert Carr23fa16b2016-01-13 13:19:58 -0800827 }
828 }
829
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700830 void clearWillReplaceWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700831 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
832 "Resetting app token " + this + " of replacing window marks.");
Chong Zhangf596cd52016-01-05 13:42:44 -0800833
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700834 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700835 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700836 w.clearWillReplaceWindow();
Chong Zhangf596cd52016-01-05 13:42:44 -0800837 }
838 }
839
Chong Zhang4d7369a2016-04-25 16:09:14 -0700840 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700841 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700842 final WindowState w = mChildren.get(i);
Chong Zhang4d7369a2016-04-25 16:09:14 -0700843 w.requestUpdateWallpaperIfNeeded();
844 }
845 }
846
Chong Zhangd78ddb42016-03-02 17:01:14 -0800847 boolean isRelaunching() {
848 return mPendingRelaunchCount > 0;
849 }
850
Robert Carr68375192017-06-13 12:41:53 -0700851 boolean shouldFreezeBounds() {
852 final Task task = getTask();
853
854 // For freeform windows, we can't freeze the bounds at the moment because this would make
855 // the resizing unresponsive.
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700856 if (task == null || task.inFreeformWindowingMode()) {
Robert Carr68375192017-06-13 12:41:53 -0700857 return false;
858 }
859
860 // We freeze the bounds while drag resizing to deal with the time between
861 // the divider/drag handle being released, and the handling it's new
862 // configuration. If we are relaunched outside of the drag resizing state,
863 // we need to be careful not to do this.
864 return getTask().isDragResizing();
865 }
866
Chong Zhangd78ddb42016-03-02 17:01:14 -0800867 void startRelaunching() {
Robert Carr68375192017-06-13 12:41:53 -0700868 if (shouldFreezeBounds()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -0800869 freezeBounds();
870 }
Robert Carrd5c7dd62017-03-08 10:39:30 -0800871
872 // In the process of tearing down before relaunching, the app will
873 // try and clean up it's child surfaces. We need to prevent this from
874 // happening, so we sever the children, transfering their ownership
875 // from the client it-self to the parent surface (owned by us).
876 for (int i = mChildren.size() - 1; i >= 0; i--) {
877 final WindowState w = mChildren.get(i);
878 w.mWinAnimator.detachChildren();
879 }
880
Chong Zhangd78ddb42016-03-02 17:01:14 -0800881 mPendingRelaunchCount++;
882 }
883
884 void finishRelaunching() {
Robert Carr68375192017-06-13 12:41:53 -0700885 unfreezeBounds();
886
Chong Zhangd78ddb42016-03-02 17:01:14 -0800887 if (mPendingRelaunchCount > 0) {
888 mPendingRelaunchCount--;
Bryce Lee081554b2017-05-25 07:52:12 -0700889 } else {
890 // Update keyguard flags upon finishing relaunch.
891 checkKeyguardFlagsChanged();
Chong Zhangd78ddb42016-03-02 17:01:14 -0800892 }
893 }
894
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700895 void clearRelaunching() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700896 if (mPendingRelaunchCount == 0) {
897 return;
898 }
Robert Carr68375192017-06-13 12:41:53 -0700899 unfreezeBounds();
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700900 mPendingRelaunchCount = 0;
901 }
902
Wale Ogunwale07bcab72016-10-14 15:30:09 -0700903 /**
904 * Returns true if the new child window we are adding to this token is considered greater than
905 * the existing child window in this token in terms of z-order.
906 */
907 @Override
908 protected boolean isFirstChildWindowGreaterThanSecond(WindowState newWindow,
909 WindowState existingWindow) {
910 final int type1 = newWindow.mAttrs.type;
911 final int type2 = existingWindow.mAttrs.type;
912
913 // Base application windows should be z-ordered BELOW all other windows in the app token.
914 if (type1 == TYPE_BASE_APPLICATION && type2 != TYPE_BASE_APPLICATION) {
915 return false;
916 } else if (type1 != TYPE_BASE_APPLICATION && type2 == TYPE_BASE_APPLICATION) {
917 return true;
918 }
919
920 // Starting windows should be z-ordered ABOVE all other windows in the app token.
921 if (type1 == TYPE_APPLICATION_STARTING && type2 != TYPE_APPLICATION_STARTING) {
922 return true;
923 } else if (type1 != TYPE_APPLICATION_STARTING && type2 == TYPE_APPLICATION_STARTING) {
924 return false;
925 }
926
927 // Otherwise the new window is greater than the existing window.
928 return true;
929 }
930
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700931 @Override
Robert Carra1eb4392015-12-10 12:43:51 -0800932 void addWindow(WindowState w) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700933 super.addWindow(w);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700934
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700935 boolean gotReplacementWindow = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700936 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700937 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700938 gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w);
939 }
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700940
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700941 // if we got a replacement window, reset the timeout to give drawing more time
942 if (gotReplacementWindow) {
943 mService.scheduleWindowReplacementTimeouts(this);
Robert Carra1eb4392015-12-10 12:43:51 -0800944 }
Jorim Jaggife762342016-10-13 14:33:27 +0200945 checkKeyguardFlagsChanged();
946 }
947
948 @Override
949 void removeChild(WindowState child) {
950 super.removeChild(child);
951 checkKeyguardFlagsChanged();
Robert Carra1eb4392015-12-10 12:43:51 -0800952 }
953
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700954 private boolean waitingForReplacement() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700955 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700956 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700957 if (candidate.waitingForReplacement()) {
Robert Carra1eb4392015-12-10 12:43:51 -0800958 return true;
959 }
960 }
961 return false;
962 }
963
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700964 void onWindowReplacementTimeout() {
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 (mChildren.get(i)).onWindowReplacementTimeout();
Robert Carra1eb4392015-12-10 12:43:51 -0800967 }
968 }
969
Winson Chung30480042017-01-26 10:55:34 -0800970 void reparent(Task task, int position) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800971 final Task currentTask = getTask();
972 if (task == currentTask) {
Winson Chung30480042017-01-26 10:55:34 -0800973 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800974 "window token=" + this + " already child of task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -0800975 }
Bryce Lee6d410262017-02-28 15:30:17 -0800976
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800977 if (currentTask.mStack != task.mStack) {
Bryce Lee6d410262017-02-28 15:30:17 -0800978 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800979 "window token=" + this + " current task=" + currentTask
Bryce Lee6d410262017-02-28 15:30:17 -0800980 + " belongs to a different stack than " + task);
981 }
982
Winson Chung30480042017-01-26 10:55:34 -0800983 if (DEBUG_ADD_REMOVE) Slog.i(TAG, "reParentWindowToken: removing window token=" + this
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800984 + " from task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -0800985 final DisplayContent prevDisplayContent = getDisplayContent();
986
Bryce Lee6d410262017-02-28 15:30:17 -0800987 mReparenting = true;
988
Winson Chung30480042017-01-26 10:55:34 -0800989 getParent().removeChild(this);
990 task.addChild(this, position);
991
Bryce Lee6d410262017-02-28 15:30:17 -0800992 mReparenting = false;
993
Winson Chung30480042017-01-26 10:55:34 -0800994 // Relayout display(s).
995 final DisplayContent displayContent = task.getDisplayContent();
996 displayContent.setLayoutNeeded();
997 if (prevDisplayContent != displayContent) {
998 onDisplayChanged(displayContent);
999 prevDisplayContent.setLayoutNeeded();
1000 }
1001 }
1002
Jorim Jaggi0429f352015-12-22 16:29:16 +01001003 /**
1004 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
1005 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
1006 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
1007 * with a queue.
1008 */
Chong Zhangd78ddb42016-03-02 17:01:14 -08001009 private void freezeBounds() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001010 final Task task = getTask();
1011 mFrozenBounds.offer(new Rect(task.mPreparedFrozenBounds));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001012
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001013 if (task.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) {
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001014 // We didn't call prepareFreezingBounds on the task, so use the current value.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001015 mFrozenMergedConfig.offer(new Configuration(task.getConfiguration()));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001016 } else {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001017 mFrozenMergedConfig.offer(new Configuration(task.mPreparedFrozenMergedConfig));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001018 }
Andrii Kulianb10330d2016-09-16 13:51:46 -07001019 // Calling unset() to make it equal to Configuration.EMPTY.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001020 task.mPreparedFrozenMergedConfig.unset();
Jorim Jaggi0429f352015-12-22 16:29:16 +01001021 }
1022
1023 /**
1024 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
1025 */
Chong Zhangd78ddb42016-03-02 17:01:14 -08001026 private void unfreezeBounds() {
Robert Carr68375192017-06-13 12:41:53 -07001027 if (mFrozenBounds.isEmpty()) {
1028 return;
Wale Ogunwale37dbafc2016-06-27 10:15:20 -07001029 }
Robert Carr68375192017-06-13 12:41:53 -07001030 mFrozenBounds.remove();
Wale Ogunwale37dbafc2016-06-27 10:15:20 -07001031 if (!mFrozenMergedConfig.isEmpty()) {
1032 mFrozenMergedConfig.remove();
1033 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001034 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001035 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001036 win.onUnfreezeBounds();
Jorim Jaggi4846ee32016-01-07 17:39:12 +01001037 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001038 mService.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +01001039 }
1040
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001041 void setAppLayoutChanges(int changes, String reason) {
1042 if (!mChildren.isEmpty()) {
1043 final DisplayContent dc = getDisplayContent();
1044 dc.pendingLayoutChanges |= changes;
1045 if (DEBUG_LAYOUT_REPEATS) {
1046 mService.mWindowPlacerLocked.debugLayoutRepeats(reason, dc.pendingLayoutChanges);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001047 }
1048 }
1049 }
1050
1051 void removeReplacedWindowIfNeeded(WindowState replacement) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001052 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001053 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001054 if (win.removeReplacedWindowIfNeeded(replacement)) {
1055 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001056 }
1057 }
1058 }
1059
1060 void startFreezingScreen() {
1061 if (DEBUG_ORIENTATION) logWithStack(TAG, "Set freezing of " + appToken + ": hidden="
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001062 + isHidden() + " freezing=" + mFreezingScreen + " hiddenRequested="
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001063 + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001064 if (!hiddenRequested) {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001065 if (!mFreezingScreen) {
1066 mFreezingScreen = true;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001067 mService.registerAppFreezeListener(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001068 mService.mAppsFreezingScreen++;
1069 if (mService.mAppsFreezingScreen == 1) {
Bryce Lee8f853582017-06-05 17:25:59 -07001070 mService.startFreezingDisplayLocked(false, 0, 0, getDisplayContent());
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001071 mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT);
1072 mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001073 }
1074 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001075 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001076 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001077 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001078 w.onStartFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001079 }
1080 }
1081 }
1082
1083 void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001084 if (!mFreezingScreen) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001085 return;
1086 }
1087 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + this + " force=" + force);
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001088 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001089 boolean unfrozeWindows = false;
1090 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001091 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001092 unfrozeWindows |= w.onStopFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001093 }
1094 if (force || unfrozeWindows) {
1095 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this);
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001096 mFreezingScreen = false;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001097 mService.unregisterAppFreezeListener(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001098 mService.mAppsFreezingScreen--;
1099 mService.mLastFinishedFreezeSource = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001100 }
1101 if (unfreezeSurfaceNow) {
1102 if (unfrozeWindows) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001103 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001104 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001105 mService.stopFreezingDisplayLocked();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001106 }
1107 }
1108
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001109 @Override
1110 public void onAppFreezeTimeout() {
1111 Slog.w(TAG_WM, "Force clearing freeze: " + this);
1112 stopFreezingScreen(true, true);
1113 }
1114
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001115 boolean transferStartingWindow(IBinder transferFrom) {
Wale Ogunwale02319a62016-09-26 15:21:22 -07001116 final AppWindowToken fromToken = getDisplayContent().getAppWindowToken(transferFrom);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001117 if (fromToken == null) {
1118 return false;
1119 }
1120
1121 final WindowState tStartingWindow = fromToken.startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001122 if (tStartingWindow != null && fromToken.startingSurface != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001123 // In this case, the starting icon has already been displayed, so start
1124 // letting windows get shown immediately without any more transitions.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001125 mService.mSkipAppTransitionAnimation = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001126
1127 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow
1128 + " from " + fromToken + " to " + this);
1129
1130 final long origId = Binder.clearCallingIdentity();
Peter Visontay3556a3b2017-11-01 17:23:17 +00001131 try {
1132 // Transfer the starting window over to the new token.
1133 startingData = fromToken.startingData;
1134 startingSurface = fromToken.startingSurface;
1135 startingDisplayed = fromToken.startingDisplayed;
1136 fromToken.startingDisplayed = false;
1137 startingWindow = tStartingWindow;
1138 reportedVisible = fromToken.reportedVisible;
1139 fromToken.startingData = null;
1140 fromToken.startingSurface = null;
1141 fromToken.startingWindow = null;
1142 fromToken.startingMoved = true;
1143 tStartingWindow.mToken = this;
1144 tStartingWindow.mAppToken = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001145
Peter Visontay3556a3b2017-11-01 17:23:17 +00001146 if (DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1147 "Removing starting " + tStartingWindow + " from " + fromToken);
1148 fromToken.removeChild(tStartingWindow);
1149 fromToken.postWindowRemoveStartingWindowCleanup(tStartingWindow);
1150 fromToken.mHiddenSetFromTransferredStartingWindow = false;
1151 addWindow(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001152
Peter Visontay3556a3b2017-11-01 17:23:17 +00001153 // Propagate other interesting state between the tokens. If the old token is displayed,
1154 // we should immediately force the new one to be displayed. If it is animating, we need
1155 // to move that animation to the new one.
1156 if (fromToken.allDrawn) {
1157 allDrawn = true;
1158 deferClearAllDrawn = fromToken.deferClearAllDrawn;
1159 }
1160 if (fromToken.firstWindowDrawn) {
1161 firstWindowDrawn = true;
1162 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001163 if (!fromToken.isHidden()) {
1164 setHidden(false);
Peter Visontay3556a3b2017-11-01 17:23:17 +00001165 hiddenRequested = false;
1166 mHiddenSetFromTransferredStartingWindow = true;
1167 }
1168 setClientHidden(fromToken.mClientHidden);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001169
Jorim Jaggi980c9de2017-11-17 01:41:37 +01001170 transferAnimation(fromToken);
1171
1172 // When transferring an animation, we no longer need to apply an animation to the
1173 // the token we transfer the animation over. Thus, remove the animation from
1174 // pending opening apps.
1175 mService.mOpeningApps.remove(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001176
Peter Visontay3556a3b2017-11-01 17:23:17 +00001177 mService.updateFocusedWindowLocked(
1178 UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/);
1179 getDisplayContent().setLayoutNeeded();
1180 mService.mWindowPlacerLocked.performSurfacePlacement();
1181 } finally {
1182 Binder.restoreCallingIdentity(origId);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001183 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001184 return true;
1185 } else if (fromToken.startingData != null) {
1186 // The previous app was getting ready to show a
1187 // starting window, but hasn't yet done so. Steal it!
1188 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1189 "Moving pending starting from " + fromToken + " to " + this);
1190 startingData = fromToken.startingData;
1191 fromToken.startingData = null;
1192 fromToken.startingMoved = true;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001193 if (getController() != null) {
1194 getController().scheduleAddStartingWindow();
1195 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001196 return true;
1197 }
1198
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001199 // TODO: Transfer thumbnail
1200
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001201 return false;
1202 }
1203
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001204 boolean isLastWindow(WindowState win) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001205 return mChildren.size() == 1 && mChildren.get(0) == win;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001206 }
1207
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001208 @Override
1209 void onAppTransitionDone() {
1210 sendingToBottom = false;
1211 }
1212
Wale Ogunwale51362492016-09-08 17:49:17 -07001213 /**
1214 * We override because this class doesn't want its children affecting its reported orientation
1215 * in anyway.
1216 */
1217 @Override
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001218 int getOrientation(int candidate) {
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001219 if (candidate == SCREEN_ORIENTATION_BEHIND) {
1220 // Allow app to specify orientation regardless of its visibility state if the current
1221 // candidate want us to use orientation behind. I.e. the visible app on-top of this one
1222 // wants us to use the orientation of the app behind it.
1223 return mOrientation;
1224 }
1225
Bryce Lee61fbcbc2017-03-10 14:14:03 -08001226 // The {@link AppWindowToken} should only specify an orientation when it is not closing or
1227 // going to the bottom. Allowing closing {@link AppWindowToken} to participate can lead to
1228 // an Activity in another task being started in the wrong orientation during the transition.
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001229 if (!(sendingToBottom || mService.mClosingApps.contains(this))
Bryce Lee00d586d2017-07-28 20:48:43 -07001230 && (isVisible() || mService.mOpeningApps.contains(this) || isOnTop())) {
Bryce Leea163b762017-01-24 11:05:01 -08001231 return mOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001232 }
Bryce Leea163b762017-01-24 11:05:01 -08001233
1234 return SCREEN_ORIENTATION_UNSET;
Wale Ogunwale51362492016-09-08 17:49:17 -07001235 }
1236
Wale Ogunwaleb198b742016-12-01 08:44:09 -08001237 /** Returns the app's preferred orientation regardless of its currently visibility state. */
1238 int getOrientationIgnoreVisibility() {
1239 return mOrientation;
1240 }
1241
Craig Mautnerdbb79912012-03-01 18:59:14 -08001242 @Override
Winson Chunge55c0192017-08-24 14:50:48 -07001243 public void onConfigurationChanged(Configuration newParentConfig) {
1244 final int prevWinMode = getWindowingMode();
1245 super.onConfigurationChanged(newParentConfig);
1246 final int winMode = getWindowingMode();
1247
1248 if (prevWinMode == winMode) {
1249 return;
1250 }
1251
1252 if (prevWinMode != WINDOWING_MODE_UNDEFINED && winMode == WINDOWING_MODE_PINNED) {
1253 // Entering PiP from fullscreen, reset the snap fraction
1254 mDisplayContent.mPinnedStackControllerLocked.resetReentrySnapFraction(this);
1255 } else if (prevWinMode == WINDOWING_MODE_PINNED && winMode != WINDOWING_MODE_UNDEFINED) {
1256 // Leaving PiP to fullscreen, save the snap fraction based on the pre-animation bounds
1257 // for the next re-entry into PiP (assuming the activity is not hidden or destroyed)
1258 final TaskStack pinnedStack = mDisplayContent.getPinnedStack();
1259 if (pinnedStack != null) {
1260 mDisplayContent.mPinnedStackControllerLocked.saveReentrySnapFraction(this,
1261 pinnedStack.mPreAnimationBounds);
1262 }
1263 }
1264 }
1265
1266 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001267 void checkAppWindowsReadyToShow() {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001268 if (allDrawn == mLastAllDrawn) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001269 return;
1270 }
1271
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001272 mLastAllDrawn = allDrawn;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001273 if (!allDrawn) {
1274 return;
1275 }
1276
1277 // The token has now changed state to having all windows shown... what to do, what to do?
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001278 if (mFreezingScreen) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001279 showAllWindowsLocked();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001280 stopFreezingScreen(false, true);
1281 if (DEBUG_ORIENTATION) Slog.i(TAG,
1282 "Setting mOrientationChangeComplete=true because wtoken " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001283 + " numInteresting=" + mNumInterestingWindows + " numDrawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001284 // This will set mOrientationChangeComplete and cause a pass through layout.
1285 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001286 "checkAppWindowsReadyToShow: freezingScreen");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001287 } else {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001288 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001289
1290 // We can now show all of the drawn windows!
1291 if (!mService.mOpeningApps.contains(this)) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001292 showAllWindowsLocked();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001293 }
1294 }
1295 }
1296
Matthew Ng5d23afa2017-06-21 16:16:24 -07001297 /**
Bryce Leed390deb2017-06-22 13:14:28 -07001298 * Returns whether the drawn window states of this {@link AppWindowToken} has considered every
1299 * child {@link WindowState}. A child is considered if it has been passed into
1300 * {@link #updateDrawnWindowStates(WindowState)} after being added. This is used to determine
1301 * whether states, such as {@code allDrawn}, can be set, which relies on state variables such as
1302 * {@code mNumInterestingWindows}, which depend on all {@link WindowState}s being considered.
1303 *
1304 * @return {@code true} If all children have been considered, {@code false}.
1305 */
1306 private boolean allDrawnStatesConsidered() {
Bryce Lee6311c4b2017-07-06 14:09:29 -07001307 for (int i = mChildren.size() - 1; i >= 0; --i) {
1308 final WindowState child = mChildren.get(i);
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001309 if (child.mightAffectAllDrawn() && !child.getDrawnStateEvaluated()) {
Bryce Leed390deb2017-06-22 13:14:28 -07001310 return false;
1311 }
1312 }
1313 return true;
1314 }
1315
1316 /**
Matthew Ng5d23afa2017-06-21 16:16:24 -07001317 * Determines if the token has finished drawing. This should only be called from
1318 * {@link DisplayContent#applySurfaceChangesTransaction}
1319 */
Matthew Ng498c71d2017-04-18 13:55:45 -07001320 void updateAllDrawn() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001321 if (!allDrawn) {
Matthew Ng498c71d2017-04-18 13:55:45 -07001322 // Number of drawn windows can be less when a window is being relaunched, wait for
Bryce Leed390deb2017-06-22 13:14:28 -07001323 // all windows to be launched and drawn for this token be considered all drawn.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001324 final int numInteresting = mNumInterestingWindows;
Bryce Leed390deb2017-06-22 13:14:28 -07001325
1326 // We must make sure that all present children have been considered (determined by
1327 // {@link #allDrawnStatesConsidered}) before evaluating whether everything has been
1328 // drawn.
1329 if (numInteresting > 0 && allDrawnStatesConsidered()
1330 && mNumDrawnWindows >= numInteresting && !isRelaunching()) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001331 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawn: " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001332 + " interesting=" + numInteresting + " drawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001333 allDrawn = true;
1334 // Force an additional layout pass where
1335 // WindowStateAnimator#commitFinishDrawingLocked() will call performShowLocked().
Matthew Ng498c71d2017-04-18 13:55:45 -07001336 if (mDisplayContent != null) {
1337 mDisplayContent.setLayoutNeeded();
1338 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001339 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Robert Carrecc06b32017-04-18 14:25:10 -07001340
Winson Chunge7ba6862017-05-24 12:13:33 -07001341 // Notify the pinned stack upon all windows drawn. If there was an animation in
1342 // progress then this signal will resume that animation.
Wale Ogunwale61911492017-10-11 08:50:50 -07001343 final TaskStack pinnedStack = mDisplayContent.getPinnedStack();
Winson Chunge7ba6862017-05-24 12:13:33 -07001344 if (pinnedStack != null) {
1345 pinnedStack.onAllWindowsDrawn();
Robert Carrecc06b32017-04-18 14:25:10 -07001346 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001347 }
1348 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001349 }
1350
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001351 /**
1352 * Updated this app token tracking states for interesting and drawn windows based on the window.
1353 *
1354 * @return Returns true if the input window is considered interesting and drawn while all the
1355 * windows in this app token where not considered drawn as of the last pass.
1356 */
1357 boolean updateDrawnWindowStates(WindowState w) {
Bryce Leed390deb2017-06-22 13:14:28 -07001358 w.setDrawnStateEvaluated(true /*evaluated*/);
1359
Jorim Jaggie4b0f282017-05-17 15:10:29 +02001360 if (DEBUG_STARTING_WINDOW_VERBOSE && w == startingWindow) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001361 Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" + w.isOnScreen()
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001362 + " allDrawn=" + allDrawn + " freezingScreen=" + mFreezingScreen);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001363 }
1364
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001365 if (allDrawn && !mFreezingScreen) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001366 return false;
1367 }
1368
1369 if (mLastTransactionSequence != mService.mTransactionSequence) {
1370 mLastTransactionSequence = mService.mTransactionSequence;
1371 mNumInterestingWindows = mNumDrawnWindows = 0;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001372 startingDisplayed = false;
1373 }
1374
1375 final WindowStateAnimator winAnimator = w.mWinAnimator;
1376
1377 boolean isInterestingAndDrawn = false;
1378
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001379 if (!allDrawn && w.mightAffectAllDrawn()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001380 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
1381 Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw()
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001382 + ", isAnimationSet=" + isSelfAnimating());
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001383 if (!w.isDrawnLw()) {
1384 Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController
1385 + " pv=" + w.mPolicyVisibility
1386 + " mDrawState=" + winAnimator.drawStateToString()
1387 + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001388 + " a=" + isSelfAnimating());
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001389 }
1390 }
1391
1392 if (w != startingWindow) {
1393 if (w.isInteresting()) {
1394 mNumInterestingWindows++;
1395 if (w.isDrawnLw()) {
1396 mNumDrawnWindows++;
1397
1398 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, "tokenMayBeDrawn: "
1399 + this + " w=" + w + " numInteresting=" + mNumInterestingWindows
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001400 + " freezingScreen=" + mFreezingScreen
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001401 + " mAppFreezing=" + w.mAppFreezing);
1402
1403 isInterestingAndDrawn = true;
1404 }
1405 }
1406 } else if (w.isDrawnLw()) {
Jorim Jaggi3878ca32017-02-02 17:13:05 -08001407 if (getController() != null) {
1408 getController().reportStartingWindowDrawn();
1409 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001410 startingDisplayed = true;
1411 }
1412 }
1413
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001414 return isInterestingAndDrawn;
1415 }
1416
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001417 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001418 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001419 // For legacy reasons we process the TaskStack.mExitingAppTokens first in DisplayContent
1420 // before the non-exiting app tokens. So, we skip the exiting app tokens here.
1421 // TODO: Investigate if we need to continue to do this or if we can just process them
1422 // in-order.
1423 if (mIsExiting && !waitingForReplacement()) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001424 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001425 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001426 return forAllWindowsUnchecked(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001427 }
1428
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001429 boolean forAllWindowsUnchecked(ToBooleanFunction<WindowState> callback,
1430 boolean traverseTopToBottom) {
1431 return super.forAllWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001432 }
1433
1434 @Override
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001435 AppWindowToken asAppWindowToken() {
1436 // I am an app window token!
1437 return this;
1438 }
1439
1440 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -07001441 boolean fillsParent() {
1442 return mFillsParent;
1443 }
1444
1445 void setFillsParent(boolean fillsParent) {
1446 mFillsParent = fillsParent;
1447 }
1448
Jorim Jaggife762342016-10-13 14:33:27 +02001449 boolean containsDismissKeyguardWindow() {
Bryce Lee081554b2017-05-25 07:52:12 -07001450 // Window state is transient during relaunch. We are not guaranteed to be frozen during the
1451 // entirety of the relaunch.
1452 if (isRelaunching()) {
1453 return mLastContainsDismissKeyguardWindow;
1454 }
1455
Jorim Jaggife762342016-10-13 14:33:27 +02001456 for (int i = mChildren.size() - 1; i >= 0; i--) {
1457 if ((mChildren.get(i).mAttrs.flags & FLAG_DISMISS_KEYGUARD) != 0) {
1458 return true;
1459 }
1460 }
1461 return false;
1462 }
1463
1464 boolean containsShowWhenLockedWindow() {
Bryce Lee081554b2017-05-25 07:52:12 -07001465 // When we are relaunching, it is possible for us to be unfrozen before our previous
1466 // windows have been added back. Using the cached value ensures that our previous
1467 // showWhenLocked preference is honored until relaunching is complete.
1468 if (isRelaunching()) {
1469 return mLastContainsShowWhenLockedWindow;
1470 }
1471
Jorim Jaggife762342016-10-13 14:33:27 +02001472 for (int i = mChildren.size() - 1; i >= 0; i--) {
1473 if ((mChildren.get(i).mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
1474 return true;
1475 }
1476 }
Bryce Lee081554b2017-05-25 07:52:12 -07001477
Jorim Jaggife762342016-10-13 14:33:27 +02001478 return false;
1479 }
1480
1481 void checkKeyguardFlagsChanged() {
1482 final boolean containsDismissKeyguard = containsDismissKeyguardWindow();
1483 final boolean containsShowWhenLocked = containsShowWhenLockedWindow();
1484 if (containsDismissKeyguard != mLastContainsDismissKeyguardWindow
1485 || containsShowWhenLocked != mLastContainsShowWhenLockedWindow) {
1486 mService.notifyKeyguardFlagsChanged(null /* callback */);
1487 }
1488 mLastContainsDismissKeyguardWindow = containsDismissKeyguard;
1489 mLastContainsShowWhenLockedWindow = containsShowWhenLocked;
1490 }
1491
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001492 WindowState getImeTargetBelowWindow(WindowState w) {
1493 final int index = mChildren.indexOf(w);
1494 if (index > 0) {
1495 final WindowState target = mChildren.get(index - 1);
1496 if (target.canBeImeTarget()) {
1497 return target;
1498 }
1499 }
1500 return null;
1501 }
1502
Winson Chungbe9be7f2017-06-28 10:55:22 -07001503 int getLowestAnimLayer() {
1504 for (int i = 0; i < mChildren.size(); i++) {
1505 final WindowState w = mChildren.get(i);
1506 if (w.mRemoved) {
1507 continue;
1508 }
1509 return w.mWinAnimator.mAnimLayer;
1510 }
1511 return Integer.MAX_VALUE;
1512 }
1513
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001514 WindowState getHighestAnimLayerWindow(WindowState currentTarget) {
1515 WindowState candidate = null;
1516 for (int i = mChildren.indexOf(currentTarget); i >= 0; i--) {
1517 final WindowState w = mChildren.get(i);
1518 if (w.mRemoved) {
1519 continue;
1520 }
1521 if (candidate == null || w.mWinAnimator.mAnimLayer >
1522 candidate.mWinAnimator.mAnimLayer) {
1523 candidate = w;
1524 }
1525 }
1526 return candidate;
1527 }
1528
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001529 /**
1530 * See {@link Activity#setDisablePreviewScreenshots}.
1531 */
1532 void setDisablePreviewScreenshots(boolean disable) {
Wale Ogunwale6c459212017-05-17 08:56:03 -07001533 mDisablePreviewScreenshots = disable;
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001534 }
1535
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001536 /**
chaviwd3bf08d2017-08-01 17:24:59 -07001537 * Sets whether the current launch can turn the screen on. See {@link #canTurnScreenOn()}
1538 */
1539 void setCanTurnScreenOn(boolean canTurnScreenOn) {
1540 mCanTurnScreenOn = canTurnScreenOn;
1541 }
1542
1543 /**
1544 * Indicates whether the current launch can turn the screen on. This is to prevent multiple
1545 * relayouts from turning the screen back on. The screen should only turn on at most
1546 * once per activity resume.
1547 *
1548 * @return true if the screen can be turned on.
1549 */
1550 boolean canTurnScreenOn() {
1551 return mCanTurnScreenOn;
1552 }
1553
1554 /**
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001555 * Retrieves whether we'd like to generate a snapshot that's based solely on the theme. This is
1556 * the case when preview screenshots are disabled {@link #setDisablePreviewScreenshots} or when
1557 * we can't take a snapshot for other reasons, for example, if we have a secure window.
1558 *
1559 * @return True if we need to generate an app theme snapshot, false if we'd like to take a real
1560 * screenshot.
1561 */
1562 boolean shouldUseAppThemeSnapshot() {
Wale Ogunwale6c459212017-05-17 08:56:03 -07001563 return mDisablePreviewScreenshots || forAllWindows(w -> (w.mAttrs.flags & FLAG_SECURE) != 0,
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001564 true /* topToBottom */);
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001565 }
1566
chaviw23ee71c2017-12-18 11:29:41 -08001567 @Override
Jorim Jaggi596a1992017-12-29 14:48:02 +01001568 public SurfaceControl getAnimationLeashParent() {
1569 return getAppAnimationLayer();
chaviw23ee71c2017-12-18 11:29:41 -08001570 }
1571
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001572 boolean applyAnimationLocked(WindowManager.LayoutParams lp, int transit, boolean enter,
1573 boolean isVoiceInteraction) {
1574
1575 if (mService.mDisableTransitionAnimation) {
1576 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1577 Slog.v(TAG_WM, "applyAnimation: transition animation is disabled. atoken=" + this);
1578 }
1579 cancelAnimation();
1580 return false;
1581 }
1582
1583 // Only apply an animation if the display isn't frozen. If it is frozen, there is no reason
1584 // to animate and it can cause strange artifacts when we unfreeze the display if some
1585 // different animation is running.
1586 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "AWT#applyAnimationLocked");
1587 if (okToAnimate()) {
1588 final Animation a = loadAnimation(lp, transit, enter, isVoiceInteraction);
1589 if (a != null) {
chaviw23ee71c2017-12-18 11:29:41 -08001590 final TaskStack stack = getStack();
1591 mTmpPoint.set(0, 0);
chaviw23012112017-12-20 15:29:04 -08001592 mTmpRect.setEmpty();
chaviw23ee71c2017-12-18 11:29:41 -08001593 if (stack != null) {
1594 stack.getRelativePosition(mTmpPoint);
chaviw23012112017-12-20 15:29:04 -08001595 stack.getBounds(mTmpRect);
chaviw977482a2017-12-28 11:35:53 -08001596 mTmpRect.offsetTo(0, 0);
chaviw23ee71c2017-12-18 11:29:41 -08001597 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001598 final AnimationAdapter adapter = new LocalAnimationAdapter(
chaviw23012112017-12-20 15:29:04 -08001599 new WindowAnimationSpec(a, mTmpPoint, mTmpRect,
1600 mService.mAppTransition.canSkipFirstFrame(),
1601 mService.mAppTransition.getAppStackClipMode()),
Jorim Jaggi2e3c31d2017-11-20 19:49:00 +01001602 mService.mSurfaceAnimationRunner);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001603 if (a.getZAdjustment() == Animation.ZORDER_TOP) {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001604 mNeedsZBoost = true;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001605 }
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001606 startAnimation(getPendingTransaction(), adapter, !isVisible());
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001607 mTransit = transit;
1608 mTransitFlags = mService.mAppTransition.getTransitFlags();
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001609 }
1610 } else {
1611 cancelAnimation();
1612 }
1613 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
1614
1615 return isReallyAnimating();
1616 }
1617
1618 private Animation loadAnimation(WindowManager.LayoutParams lp, int transit, boolean enter,
1619 boolean isVoiceInteraction) {
1620 final DisplayContent displayContent = getTask().getDisplayContent();
1621 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
1622 final int width = displayInfo.appWidth;
1623 final int height = displayInfo.appHeight;
1624 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG_WM,
1625 "applyAnimation: atoken=" + this);
1626
1627 // Determine the visible rect to calculate the thumbnail clip
1628 final WindowState win = findMainWindow();
1629 final Rect frame = new Rect(0, 0, width, height);
1630 final Rect displayFrame = new Rect(0, 0,
1631 displayInfo.logicalWidth, displayInfo.logicalHeight);
1632 final Rect insets = new Rect();
1633 final Rect stableInsets = new Rect();
1634 Rect surfaceInsets = null;
1635 final boolean freeform = win != null && win.inFreeformWindowingMode();
1636 if (win != null) {
1637 // Containing frame will usually cover the whole screen, including dialog windows.
1638 // For freeform workspace windows it will not cover the whole screen and it also
1639 // won't exactly match the final freeform window frame (e.g. when overlapping with
1640 // the status bar). In that case we need to use the final frame.
1641 if (freeform) {
1642 frame.set(win.mFrame);
1643 } else {
1644 frame.set(win.mContainingFrame);
1645 }
1646 surfaceInsets = win.getAttrs().surfaceInsets;
1647 insets.set(win.mContentInsets);
1648 stableInsets.set(win.mStableInsets);
1649 }
1650
1651 if (mLaunchTaskBehind) {
1652 // Differentiate the two animations. This one which is briefly on the screen
1653 // gets the !enter animation, and the other activity which remains on the
1654 // screen gets the enter animation. Both appear in the mOpeningApps set.
1655 enter = false;
1656 }
1657 if (DEBUG_APP_TRANSITIONS) Slog.d(TAG_WM, "Loading animation for app transition."
1658 + " transit=" + AppTransition.appTransitionToString(transit) + " enter=" + enter
1659 + " frame=" + frame + " insets=" + insets + " surfaceInsets=" + surfaceInsets);
1660 final Configuration displayConfig = displayContent.getConfiguration();
1661 final Animation a = mService.mAppTransition.loadAnimation(lp, transit, enter,
1662 displayConfig.uiMode, displayConfig.orientation, frame, displayFrame, insets,
1663 surfaceInsets, stableInsets, isVoiceInteraction, freeform, getTask().mTaskId);
1664 if (a != null) {
1665 if (DEBUG_ANIM) logWithStack(TAG, "Loaded animation " + a + " for " + this);
1666 final int containingWidth = frame.width();
1667 final int containingHeight = frame.height();
1668 a.initialize(containingWidth, containingHeight, width, height);
1669 a.scaleCurrentDuration(mService.getTransitionAnimationScaleLocked());
1670 }
1671 return a;
1672 }
1673
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001674 @Override
1675 protected void setLayer(Transaction t, int layer) {
1676 if (!mSurfaceAnimator.hasLeash()) {
1677 t.setLayer(mSurfaceControl, layer);
1678 }
1679 }
1680
1681 @Override
1682 protected void setRelativeLayer(Transaction t, SurfaceControl relativeTo, int layer) {
1683 if (!mSurfaceAnimator.hasLeash()) {
1684 t.setRelativeLayer(mSurfaceControl, relativeTo, layer);
1685 }
1686 }
1687
1688 @Override
1689 protected void reparentSurfaceControl(Transaction t, SurfaceControl newParent) {
1690 if (!mSurfaceAnimator.hasLeash()) {
1691 t.reparent(mSurfaceControl, newParent.getHandle());
1692 }
1693 }
1694
1695 @Override
1696 public void onAnimationLeashCreated(Transaction t, SurfaceControl leash) {
1697
1698 // The leash is parented to the animation layer. We need to preserve the z-order by using
1699 // the prefix order index, but we boost if necessary.
1700 int layer = getPrefixOrderIndex();
1701 if (mNeedsZBoost) {
1702 layer += Z_BOOST_BASE;
1703 }
1704 leash.setLayer(layer);
1705 }
1706
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001707 /**
1708 * This must be called while inside a transaction.
1709 */
1710 void showAllWindowsLocked() {
1711 forAllWindows(windowState -> {
1712 if (DEBUG_VISIBILITY) Slog.v(TAG, "performing show on: " + windowState);
1713 windowState.performShowLocked();
1714 }, false /* traverseTopToBottom */);
Jorim Jaggia5e10572017-11-15 14:36:26 +01001715 }
1716
1717 @Override
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001718 protected void onAnimationFinished() {
1719 super.onAnimationFinished();
1720
1721 mTransit = TRANSIT_UNSET;
1722 mTransitFlags = 0;
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001723 mNeedsZBoost = false;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001724
1725 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM | FINISH_LAYOUT_REDO_WALLPAPER,
1726 "AppWindowToken");
1727
Jorim Jaggi988f6682017-11-17 17:46:43 +01001728 clearThumbnail();
Jorim Jaggi4876b4a2018-01-11 15:43:49 +01001729 setClientHidden(isHidden());
Jorim Jaggi988f6682017-11-17 17:46:43 +01001730
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001731 if (mService.mInputMethodTarget != null && mService.mInputMethodTarget.mAppToken == this) {
1732 getDisplayContent().computeImeTarget(true /* updateImeTarget */);
1733 }
1734
1735 if (DEBUG_ANIM) Slog.v(TAG, "Animation done in " + this
1736 + ": reportedVisible=" + reportedVisible
1737 + " okToDisplay=" + okToDisplay()
1738 + " okToAnimate=" + okToAnimate()
1739 + " startingDisplayed=" + startingDisplayed);
1740
1741 // WindowState.onExitAnimationDone might modify the children list, so make a copy and then
1742 // traverse the copy.
1743 final ArrayList<WindowState> children = new ArrayList<>(mChildren);
1744 children.forEach(WindowState::onExitAnimationDone);
1745
1746 mService.mAppTransition.notifyAppTransitionFinishedLocked(token);
1747 scheduleAnimation();
1748 }
1749
1750 @Override
1751 boolean isAppAnimating() {
1752 return isSelfAnimating();
1753 }
1754
1755 @Override
1756 boolean isSelfAnimating() {
1757 // If we are about to start a transition, we also need to be considered animating.
1758 return isWaitingForTransitionStart() || isReallyAnimating();
1759 }
1760
1761 /**
1762 * @return True if and only if we are actually running an animation. Note that
1763 * {@link #isSelfAnimating} also returns true if we are waiting for an animation to
1764 * start.
1765 */
1766 private boolean isReallyAnimating() {
1767 return super.isSelfAnimating();
1768 }
1769
Jorim Jaggi988f6682017-11-17 17:46:43 +01001770 @Override
1771 void cancelAnimation() {
1772 super.cancelAnimation();
1773 clearThumbnail();
1774 }
1775
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001776 boolean isWaitingForTransitionStart() {
1777 return mService.mAppTransition.isTransitionSet()
1778 && (mService.mOpeningApps.contains(this) || mService.mClosingApps.contains(this));
1779 }
1780
1781 public int getTransit() {
1782 return mTransit;
1783 }
1784
1785 int getTransitFlags() {
1786 return mTransitFlags;
1787 }
1788
Jorim Jaggi988f6682017-11-17 17:46:43 +01001789 void attachThumbnailAnimation() {
1790 if (!isReallyAnimating()) {
1791 return;
1792 }
1793 final int taskId = getTask().mTaskId;
1794 final GraphicBuffer thumbnailHeader =
1795 mService.mAppTransition.getAppTransitionThumbnailHeader(taskId);
1796 if (thumbnailHeader == null) {
1797 if (DEBUG_APP_TRANSITIONS) Slog.d(TAG, "No thumbnail header bitmap for: " + taskId);
1798 return;
1799 }
1800 clearThumbnail();
1801 mThumbnail = new AppWindowThumbnail(getPendingTransaction(), this, thumbnailHeader);
1802 mThumbnail.startAnimation(getPendingTransaction(), loadThumbnailAnimation(thumbnailHeader));
1803 }
1804
Tony Mak64b8d562017-12-28 17:44:02 +00001805 /**
1806 * Attaches a surface with a thumbnail for the
1807 * {@link android.app.ActivityOptions#ANIM_OPEN_CROSS_PROFILE_APPS} animation.
1808 */
1809 void attachCrossProfileAppsThumbnailAnimation() {
1810 if (!isReallyAnimating()) {
1811 return;
1812 }
1813 clearThumbnail();
1814
1815 final WindowState win = findMainWindow();
1816 if (win == null) {
1817 return;
1818 }
1819 final Rect frame = win.mFrame;
1820 final int thumbnailDrawableRes = getTask().mUserId == mService.mCurrentUserId
1821 ? R.drawable.ic_account_circle
1822 : R.drawable.ic_corp_badge_no_background;
1823 final GraphicBuffer thumbnail =
1824 mService.mAppTransition
1825 .createCrossProfileAppsThumbnail(thumbnailDrawableRes, frame);
1826 if (thumbnail == null) {
1827 return;
1828 }
1829 mThumbnail = new AppWindowThumbnail(getPendingTransaction(), this, thumbnail);
1830 final Animation animation =
1831 mService.mAppTransition.createCrossProfileAppsThumbnailAnimationLocked(win.mFrame);
1832 mThumbnail.startAnimation(getPendingTransaction(), animation, new Point(frame.left,
1833 frame.top));
1834 }
1835
Jorim Jaggi988f6682017-11-17 17:46:43 +01001836 private Animation loadThumbnailAnimation(GraphicBuffer thumbnailHeader) {
1837 final DisplayInfo displayInfo = mDisplayContent.getDisplayInfo();
1838
1839 // If this is a multi-window scenario, we use the windows frame as
1840 // destination of the thumbnail header animation. If this is a full screen
1841 // window scenario, we use the whole display as the target.
1842 WindowState win = findMainWindow();
1843 Rect appRect = win != null ? win.getContentFrameLw() :
1844 new Rect(0, 0, displayInfo.appWidth, displayInfo.appHeight);
1845 Rect insets = win != null ? win.mContentInsets : null;
1846 final Configuration displayConfig = mDisplayContent.getConfiguration();
1847 return mService.mAppTransition.createThumbnailAspectScaleAnimationLocked(
1848 appRect, insets, thumbnailHeader, getTask().mTaskId, displayConfig.uiMode,
1849 displayConfig.orientation);
1850 }
1851
1852 private void clearThumbnail() {
1853 if (mThumbnail == null) {
1854 return;
1855 }
1856 mThumbnail.destroy();
1857 mThumbnail = null;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001858 }
1859
1860 @Override
1861 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
1862 super.dump(pw, prefix, dumpAll);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001863 if (appToken != null) {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001864 pw.println(prefix + "app=true mVoiceInteraction=" + mVoiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001865 }
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001866 pw.print(prefix); pw.print("task="); pw.println(getTask());
Wale Ogunwale51362492016-09-08 17:49:17 -07001867 pw.print(prefix); pw.print(" mFillsParent="); pw.print(mFillsParent);
1868 pw.print(" mOrientation="); pw.println(mOrientation);
Wale Ogunwale89973222017-04-23 18:39:45 -07001869 pw.println(prefix + "hiddenRequested=" + hiddenRequested + " mClientHidden=" + mClientHidden
1870 + ((mDeferHidingClient) ? " mDeferHidingClient=" + mDeferHidingClient : "")
1871 + " reportedDrawn=" + reportedDrawn + " reportedVisible=" + reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -07001872 if (paused) {
1873 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001874 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001875 if (mAppStopped) {
1876 pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped);
1877 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001878 if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001879 || allDrawn || mLastAllDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001880 pw.print(prefix); pw.print("mNumInterestingWindows=");
1881 pw.print(mNumInterestingWindows);
1882 pw.print(" mNumDrawnWindows="); pw.print(mNumDrawnWindows);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001883 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -07001884 pw.print(" allDrawn="); pw.print(allDrawn);
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001885 pw.print(" lastAllDrawn="); pw.print(mLastAllDrawn);
Craig Mautner6fbda632012-07-03 09:26:39 -07001886 pw.println(")");
1887 }
1888 if (inPendingTransaction) {
1889 pw.print(prefix); pw.print("inPendingTransaction=");
1890 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001891 }
Craig Mautner799bc1d2015-01-14 10:33:48 -08001892 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001893 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
1894 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -08001895 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -08001896 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001897 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001898 if (startingWindow != null || startingSurface != null
Wale Ogunwale6c459212017-05-17 08:56:03 -07001899 || startingDisplayed || startingMoved || mHiddenSetFromTransferredStartingWindow) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001900 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001901 pw.print(" startingSurface="); pw.print(startingSurface);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001902 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
Wale Ogunwale6c459212017-05-17 08:56:03 -07001903 pw.print(" startingMoved="); pw.print(startingMoved);
1904 pw.println(" mHiddenSetFromTransferredStartingWindow="
1905 + mHiddenSetFromTransferredStartingWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001906 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01001907 if (!mFrozenBounds.isEmpty()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -08001908 pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds);
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001909 pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig);
Chong Zhangd78ddb42016-03-02 17:01:14 -08001910 }
1911 if (mPendingRelaunchCount != 0) {
1912 pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount);
Jorim Jaggi0429f352015-12-22 16:29:16 +01001913 }
Wale Ogunwale9c64cb62017-04-12 13:39:59 -07001914 if (getController() != null) {
1915 pw.print(prefix); pw.print("controller="); pw.println(getController());
1916 }
Wale Ogunwalee287e192017-04-21 09:30:12 -07001917 if (mRemovingFromDisplay) {
1918 pw.println(prefix + "mRemovingFromDisplay=" + mRemovingFromDisplay);
1919 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001920 }
1921
1922 @Override
1923 void setHidden(boolean hidden) {
1924 super.setHidden(hidden);
Winson Chunge55c0192017-08-24 14:50:48 -07001925
1926 if (hidden) {
1927 // Once the app window is hidden, reset the last saved PiP snap fraction
1928 mDisplayContent.mPinnedStackControllerLocked.resetReentrySnapFraction(this);
1929 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001930 scheduleAnimation();
1931 }
1932
1933 @Override
1934 void prepareSurfaces() {
1935 // isSelfAnimating also returns true when we are about to start a transition, so we need
1936 // to check super here.
1937 final boolean reallyAnimating = super.isSelfAnimating();
1938 final boolean show = !isHidden() || reallyAnimating;
1939 if (show && !mLastSurfaceShowing) {
1940 mPendingTransaction.show(mSurfaceControl);
1941 } else if (!show && mLastSurfaceShowing) {
1942 mPendingTransaction.hide(mSurfaceControl);
Jorim Jaggi4d1835d2017-08-31 17:28:27 +02001943 }
Jorim Jaggi988f6682017-11-17 17:46:43 +01001944 if (mThumbnail != null) {
1945 mThumbnail.setShowing(mPendingTransaction, show);
1946 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001947 mLastSurfaceShowing = show;
1948 super.prepareSurfaces();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001949 }
1950
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001951 boolean isFreezingScreen() {
1952 return mFreezingScreen;
1953 }
1954
1955 @Override
1956 boolean needsZBoost() {
1957 return mNeedsZBoost || super.needsZBoost();
1958 }
1959
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07001960 @CallSuper
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001961 @Override
Adrian Roos4921ccf2017-09-28 16:54:06 +02001962 public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07001963 final long token = proto.start(fieldId);
1964 writeNameToProto(proto, NAME);
Adrian Roos4921ccf2017-09-28 16:54:06 +02001965 super.writeToProto(proto, WINDOW_TOKEN, trim);
Vishnu Nair04ab4392018-01-10 11:00:06 -08001966 proto.write(LAST_SURFACE_SHOWING, mLastSurfaceShowing);
1967 proto.write(IS_WAITING_FOR_TRANSITION_START, isWaitingForTransitionStart());
1968 proto.write(IS_REALLY_ANIMATING, isReallyAnimating());
1969 if (mThumbnail != null){
1970 mThumbnail.writeToProto(proto, THUMBNAIL);
1971 }
1972 proto.write(FILLS_PARENT, mFillsParent);
1973 proto.write(APP_STOPPED, mAppStopped);
1974 proto.write(HIDDEN_REQUESTED, hiddenRequested);
1975 proto.write(CLIENT_HIDDEN, mClientHidden);
1976 proto.write(DEFER_HIDING_CLIENT, mDeferHidingClient);
1977 proto.write(REPORTED_DRAWN, reportedDrawn);
1978 proto.write(REPORTED_VISIBLE, reportedVisible);
1979 proto.write(NUM_INTERESTING_WINDOWS, mNumInterestingWindows);
1980 proto.write(NUM_DRAWN_WINDOWS, mNumDrawnWindows);
1981 proto.write(ALL_DRAWN, allDrawn);
1982 proto.write(LAST_ALL_DRAWN, mLastAllDrawn);
1983 proto.write(REMOVED, removed);
1984 if (startingWindow != null){
1985 startingWindow.writeIdentifierToProto(proto, STARTING_WINDOW);
1986 }
1987 proto.write(STARTING_DISPLAYED, startingDisplayed);
1988 proto.write(STARTING_MOVED, startingMoved);
1989 proto.write(HIDDEN_SET_FROM_TRANSFERRED_STARTING_WINDOW,
1990 mHiddenSetFromTransferredStartingWindow);
1991 for (Rect bounds : mFrozenBounds) {
1992 bounds.writeToProto(proto, FROZEN_BOUNDS);
1993 }
Steven Timotiusaf03df62017-07-18 16:56:43 -07001994 proto.end(token);
1995 }
1996
1997 void writeNameToProto(ProtoOutputStream proto, long fieldId) {
1998 if (appToken == null) {
1999 return;
2000 }
2001 try {
2002 proto.write(fieldId, appToken.getName());
2003 } catch (RemoteException e) {
2004 // This shouldn't happen, but in this case fall back to outputting nothing
2005 Slog.e(TAG, e.toString());
2006 }
2007 }
2008
2009 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002010 public String toString() {
2011 if (stringName == null) {
2012 StringBuilder sb = new StringBuilder();
2013 sb.append("AppWindowToken{");
2014 sb.append(Integer.toHexString(System.identityHashCode(this)));
2015 sb.append(" token="); sb.append(token); sb.append('}');
2016 stringName = sb.toString();
2017 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07002018 return stringName + ((mIsExiting) ? " mIsExiting=" : "");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002019 }
Jeff Browne9bdb312012-04-05 15:30:10 -07002020}