blob: f2098dc3ce4f2ecffc74184d5d338f5e627081a2 [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 Ogunwale89973222017-04-23 18:39:45 -0700379 setClientHidden(!visible);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700380
381 // Allow for state changes and animation to be applied if:
382 // * token is transitioning visibility state
383 // * or the token was marked as hidden and is exiting before we had a chance to play the
384 // transition animation
385 // * or this is an opening app and windows are being replaced.
386 boolean visibilityChanged = false;
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200387 if (isHidden() == visible || (isHidden() && mIsExiting) || (visible && waitingForReplacement())) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700388 final AccessibilityController accessibilityController = mService.mAccessibilityController;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700389 boolean changed = false;
390 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200391 "Changing app " + this + " hidden=" + isHidden() + " performLayout=" + performLayout);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700392
393 boolean runningAppAnimation = false;
394
395 if (transit != AppTransition.TRANSIT_UNSET) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200396 if (applyAnimationLocked(lp, transit, visible, isVoiceInteraction)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700397 delayed = runningAppAnimation = true;
398 }
399 final WindowState window = findMainWindow();
400 //TODO (multidisplay): Magnification is supported only for the default display.
401 if (window != null && accessibilityController != null
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700402 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700403 accessibilityController.onAppWindowTransitionLocked(window, transit);
404 }
405 changed = true;
406 }
407
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700408 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700409 for (int i = 0; i < windowsCount; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700410 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700411 changed |= win.onAppVisibilityChanged(visible, runningAppAnimation);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700412 }
413
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200414 setHidden(!visible);
415 hiddenRequested = !visible;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700416 visibilityChanged = true;
417 if (!visible) {
418 stopFreezingScreen(true, true);
419 } else {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700420 // If we are being set visible, and the starting window is not yet displayed,
421 // then make sure it doesn't get displayed.
422 if (startingWindow != null && !startingWindow.isDrawnLw()) {
423 startingWindow.mPolicyVisibility = false;
424 startingWindow.mPolicyVisibilityAfterAnim = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700425 }
Jorim Jaggi38d44ec2017-06-14 16:04:59 -0700426
427 // We are becoming visible, so better freeze the screen with the windows that are
428 // getting visible so we also wait for them.
429 forAllWindows(mService::makeWindowFreezingScreenIfNeededLocked, true);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700430 }
431
432 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setVisibility: " + this
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200433 + ": hidden=" + isHidden() + " hiddenRequested=" + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700434
435 if (changed) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700436 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700437 if (performLayout) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700438 mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700439 false /*updateInputWindows*/);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700440 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700441 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700442 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700443 }
444 }
445
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200446 if (isReallyAnimating()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700447 delayed = true;
448 }
449
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700450 for (int i = mChildren.size() - 1; i >= 0 && !delayed; i--) {
Jorim Jaggia5e10572017-11-15 14:36:26 +0100451 if ((mChildren.get(i)).isSelfOrChildAnimating()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700452 delayed = true;
453 }
454 }
455
456 if (visibilityChanged) {
457 if (visible && !delayed) {
458 // The token was made immediately visible, there will be no entrance animation.
459 // We need to inform the client the enter animation was finished.
460 mEnteringAnimation = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700461 mService.mActivityManagerAppTransitionNotifier.onAppTransitionFinishedLocked(token);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700462 }
Robert Carr61b81112017-07-17 18:08:15 -0700463
Robert Carre7cc44d2017-03-20 19:04:30 -0700464 // If we are hidden but there is no delay needed we immediately
465 // apply the Surface transaction so that the ActivityManager
Robert Carr61b81112017-07-17 18:08:15 -0700466 // can have some guarantee on the Surface state following
467 // setting the visibility. This captures cases like dismissing
468 // the docked or pinned stack where there is no app transition.
469 //
470 // In the case of a "Null" animation, there will be
471 // no animation but there will still be a transition set.
472 // We still need to delay hiding the surface such that it
473 // can be synchronized with showing the next surface in the transition.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200474 if (isHidden() && !delayed && !mService.mAppTransition.isTransitionSet()) {
Robert Carr6914f082017-03-20 19:04:30 -0700475 SurfaceControl.openTransaction();
476 for (int i = mChildren.size() - 1; i >= 0; i--) {
477 mChildren.get(i).mWinAnimator.hide("immediately hidden");
478 }
479 SurfaceControl.closeTransaction();
480 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700481
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700482 if (!mService.mClosingApps.contains(this) && !mService.mOpeningApps.contains(this)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700483 // The token is not closing nor opening, so even if there is an animation set, that
484 // doesn't mean that it goes through the normal app transition cycle so we have
485 // to inform the docked controller about visibility change.
Andrii Kulian1e32e022016-09-16 15:29:34 -0700486 // TODO(multi-display): notify docked divider on all displays where visibility was
487 // affected.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700488 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700489 .notifyAppVisibilityChanged();
Jorim Jaggi8b702ed2017-01-20 16:59:03 +0100490 mService.mTaskSnapshotController.notifyAppVisibilityChanged(this, visible);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700491 }
492 }
493
494 return delayed;
495 }
496
Jorim Jaggi87fdbcb2017-08-17 13:41:11 +0200497 /**
498 * @return The to top most child window for which {@link LayoutParams#isFullscreen()} returns
499 * true.
500 */
501 WindowState getTopFullscreenWindow() {
502 for (int i = mChildren.size() - 1; i >= 0; i--) {
503 final WindowState win = mChildren.get(i);
504 if (win != null && win.mAttrs.isFullscreen()) {
505 return win;
506 }
507 }
508 return null;
509 }
510
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800511 WindowState findMainWindow() {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700512 WindowState candidate = null;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700513 int j = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800514 while (j > 0) {
515 j--;
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700516 final WindowState win = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700517 final int type = win.mAttrs.type;
518 // No need to loop through child window as base application and starting types can't be
519 // child windows.
520 if (type == TYPE_BASE_APPLICATION || type == TYPE_APPLICATION_STARTING) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700521 // In cases where there are multiple windows, we prefer the non-exiting window. This
Sungsoo Lim0d3d1f82015-12-02 14:47:59 +0900522 // happens for example when replacing windows during an activity relaunch. When
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700523 // constructing the animation, we want the new window, not the exiting one.
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800524 if (win.mAnimatingExit) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700525 candidate = win;
526 } else {
527 return win;
528 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800529 }
530 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700531 return candidate;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800532 }
533
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800534 boolean windowsAreFocusable() {
Wale Ogunwale3382ab12017-07-27 08:55:03 -0700535 return getWindowConfiguration().canReceiveKeys() || mAlwaysFocusable;
Wale Ogunwaled045c822015-12-02 09:14:28 -0800536 }
537
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800538 AppWindowContainerController getController() {
539 final WindowContainerController controller = super.getController();
540 return controller != null ? (AppWindowContainerController) controller : null;
541 }
542
Wale Ogunwale571771c2016-08-26 13:18:50 -0700543 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -0700544 boolean isVisible() {
Wale Ogunwalee471be62016-10-03 07:53:55 -0700545 // If the app token isn't hidden then it is considered visible and there is no need to check
546 // its children windows to see if they are visible.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200547 return !isHidden();
Wale Ogunwale44f21802016-09-02 12:49:48 -0700548 }
549
550 @Override
Wale Ogunwalee287e192017-04-21 09:30:12 -0700551 void removeImmediately() {
552 onRemovedFromDisplay();
553 super.removeImmediately();
554 }
555
556 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -0700557 void removeIfPossible() {
Craig Mautnere3119b72015-01-20 15:02:36 -0800558 mIsExiting = false;
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800559 removeAllWindowsIfPossible();
Bryce Lee6d410262017-02-28 15:30:17 -0800560 removeImmediately();
Craig Mautnere3119b72015-01-20 15:02:36 -0800561 }
562
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700563 @Override
564 boolean checkCompleteDeferredRemoval() {
565 if (mIsExiting) {
566 removeIfPossible();
567 }
568 return super.checkCompleteDeferredRemoval();
569 }
570
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700571 void onRemovedFromDisplay() {
Wale Ogunwalee287e192017-04-21 09:30:12 -0700572 if (mRemovingFromDisplay) {
573 return;
574 }
575 mRemovingFromDisplay = true;
576
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700577 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app token: " + this);
578
Wale Ogunwale72919d22016-12-08 18:58:50 -0800579 boolean delayed = setVisibility(null, false, TRANSIT_UNSET, true, mVoiceInteraction);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700580
581 mService.mOpeningApps.remove(this);
Jorim Jaggi45ca0542017-05-30 16:16:01 -0700582 mService.mUnknownAppVisibilityController.appRemovedOrHidden(this);
Jorim Jaggi10abe2f2017-01-03 16:44:46 +0100583 mService.mTaskSnapshotController.onAppRemoved(this);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700584 waitingToShow = false;
585 if (mService.mClosingApps.contains(this)) {
586 delayed = true;
587 } else if (mService.mAppTransition.isTransitionSet()) {
588 mService.mClosingApps.add(this);
589 delayed = true;
590 }
591
592 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app " + this + " delayed=" + delayed
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200593 + " animation=" + getAnimation() + " animating=" + isSelfAnimating());
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700594
595 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM, "removeAppToken: "
596 + this + " delayed=" + delayed + " Callers=" + Debug.getCallers(4));
597
Jorim Jaggi19be6052017-08-03 18:33:43 +0200598 if (startingData != null && getController() != null) {
599 getController().removeStartingWindow();
600 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800601
Winson Chung87e5d552017-04-05 11:49:38 -0700602 // If this window was animating, then we need to ensure that the app transition notifies
603 // that animations have completed in WMS.handleAnimatingStoppedAndTransitionLocked(), so
604 // add to that list now
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200605 if (isSelfAnimating()) {
Winson Chung87e5d552017-04-05 11:49:38 -0700606 mService.mNoAnimationNotifyOnTransitionFinished.add(token);
607 }
608
Wale Ogunwalee287e192017-04-21 09:30:12 -0700609 final TaskStack stack = getStack();
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700610 if (delayed && !isEmpty()) {
611 // set the token aside because it has an active animation to be finished
612 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM,
613 "removeAppToken make exiting: " + this);
Wale Ogunwalee287e192017-04-21 09:30:12 -0700614 if (stack != null) {
615 stack.mExitingAppTokens.add(this);
616 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700617 mIsExiting = true;
618 } else {
619 // Make sure there is no animation running on this token, so any windows associated
620 // with it will be removed as soon as their animations are complete
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200621 cancelAnimation();
Wale Ogunwale3106ae012017-05-16 08:56:37 -0700622 if (stack != null) {
623 stack.mExitingAppTokens.remove(this);
624 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700625 removeIfPossible();
626 }
627
628 removed = true;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700629 stopFreezingScreen(true, true);
Bryce Lee6d410262017-02-28 15:30:17 -0800630
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700631 if (mService.mFocusedApp == this) {
632 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "Removing focused app token:" + this);
633 mService.mFocusedApp = null;
634 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
635 mService.mInputMonitor.setFocusedAppLw(null);
636 }
637
638 if (!delayed) {
639 updateReportedVisibilityLocked();
640 }
Wale Ogunwalee287e192017-04-21 09:30:12 -0700641
642 mRemovingFromDisplay = false;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700643 }
644
Chong Zhange05bcb12016-07-26 17:47:29 -0700645 void clearAnimatingFlags() {
Chong Zhangb0d26702016-08-12 16:03:29 -0700646 boolean wallpaperMightChange = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700647 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700648 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700649 wallpaperMightChange |= win.clearAnimatingFlags();
Chong Zhange05bcb12016-07-26 17:47:29 -0700650 }
Chong Zhangb0d26702016-08-12 16:03:29 -0700651 if (wallpaperMightChange) {
652 requestUpdateWallpaperIfNeeded();
653 }
Chong Zhange05bcb12016-07-26 17:47:29 -0700654 }
655
Robert Carre12aece2016-02-02 22:43:27 -0800656 void destroySurfaces() {
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700657 destroySurfaces(false /*cleanupOnResume*/);
658 }
659
660 /**
661 * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure
662 * the client has finished with them.
663 *
664 * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If
665 * set to true, destroy only surfaces of removed windows, and clear relevant flags of the
666 * others so that they are ready to be reused. If set to false (common case), destroy all
667 * surfaces that's eligible, if the app is already stopped.
668 */
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700669 private void destroySurfaces(boolean cleanupOnResume) {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700670 boolean destroyedSomething = false;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100671
672 // Copying to a different list as multiple children can be removed.
Jorim Jaggi59f3e922018-01-05 15:40:32 +0100673 final ArrayList<WindowState> children = new ArrayList<>(mChildren);
Jorim Jaggia5e10572017-11-15 14:36:26 +0100674 for (int i = children.size() - 1; i >= 0; i--) {
675 final WindowState win = children.get(i);
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700676 destroyedSomething |= win.destroySurface(cleanupOnResume, mAppStopped);
Robert Carre12aece2016-02-02 22:43:27 -0800677 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700678 if (destroyedSomething) {
679 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700680 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Robert Carre12aece2016-02-02 22:43:27 -0800681 }
682 }
683
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800684 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700685 * Notify that the app is now resumed, and it was not stopped before, perform a clean
686 * up of the surfaces
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800687 */
Jorim Jaggibae01b12017-04-11 16:29:10 -0700688 void notifyAppResumed(boolean wasStopped) {
Chong Zhangad24f962016-08-25 12:12:33 -0700689 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped
Jorim Jaggibae01b12017-04-11 16:29:10 -0700690 + " " + this);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700691 mAppStopped = false;
chaviwd3bf08d2017-08-01 17:24:59 -0700692 // Allow the window to turn the screen on once the app is resumed again.
693 setCanTurnScreenOn(true);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700694 if (!wasStopped) {
695 destroySurfaces(true /*cleanupOnResume*/);
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800696 }
Robert Carre12aece2016-02-02 22:43:27 -0800697 }
698
Chong Zhangbef461f2015-10-27 11:38:24 -0700699 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700700 * Notify that the app has stopped, and it is okay to destroy any surfaces which were
701 * keeping alive in case they were still being used.
702 */
703 void notifyAppStopped() {
704 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this);
705 mAppStopped = true;
706 destroySurfaces();
707 // Remove any starting window that was added for this app if they are still around.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800708 if (getController() != null) {
709 getController().removeStartingWindow();
710 }
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700711 }
712
Chong Zhang92147042016-05-09 12:47:11 -0700713 void clearAllDrawn() {
714 allDrawn = false;
715 deferClearAllDrawn = false;
Chong Zhangbef461f2015-10-27 11:38:24 -0700716 }
717
Bryce Lee6d410262017-02-28 15:30:17 -0800718 Task getTask() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800719 return (Task) getParent();
Bryce Lee6d410262017-02-28 15:30:17 -0800720 }
721
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800722 TaskStack getStack() {
723 final Task task = getTask();
724 if (task != null) {
725 return task.mStack;
726 } else {
727 return null;
728 }
729 }
730
Bryce Lee6d410262017-02-28 15:30:17 -0800731 @Override
732 void onParentSet() {
733 super.onParentSet();
734
Robert Carred3e83b2017-04-21 13:26:55 -0700735 final Task task = getTask();
736
Bryce Lee6d410262017-02-28 15:30:17 -0800737 // When the associated task is {@code null}, the {@link AppWindowToken} can no longer
738 // access visual elements like the {@link DisplayContent}. We must remove any associations
739 // such as animations.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800740 if (!mReparenting) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800741 if (task == null) {
742 // It is possible we have been marked as a closing app earlier. We must remove ourselves
743 // from this list so we do not participate in any future animations.
744 mService.mClosingApps.remove(this);
Robert Carred3e83b2017-04-21 13:26:55 -0700745 } else if (mLastParent != null && mLastParent.mStack != null) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800746 task.mStack.mExitingAppTokens.remove(this);
747 }
Bryce Lee6d410262017-02-28 15:30:17 -0800748 }
Robert Carred3e83b2017-04-21 13:26:55 -0700749 mLastParent = task;
Bryce Lee6d410262017-02-28 15:30:17 -0800750 }
751
Wale Ogunwalefa854eb2016-09-20 13:43:52 -0700752 void postWindowRemoveStartingWindowCleanup(WindowState win) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700753 // TODO: Something smells about the code below...Is there a better way?
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700754 if (startingWindow == win) {
755 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800756 if (getController() != null) {
757 getController().removeStartingWindow();
758 }
Wale Ogunwale6c459212017-05-17 08:56:03 -0700759 } else if (mChildren.size() == 0) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700760 // If this is the last window and we had requested a starting transition window,
761 // well there is no point now.
Jorim Jaggi02886a82016-12-06 09:10:06 -0800762 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingData");
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700763 startingData = null;
Wale Ogunwale6c459212017-05-17 08:56:03 -0700764 if (mHiddenSetFromTransferredStartingWindow) {
765 // We set the hidden state to false for the token from a transferred starting window.
766 // We now reset it back to true since the starting window was the last window in the
767 // token.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200768 setHidden(true);
Wale Ogunwale6c459212017-05-17 08:56:03 -0700769 }
Jorim Jaggi829b9cd2017-01-23 16:20:53 +0100770 } else if (mChildren.size() == 1 && startingSurface != null && !isRelaunching()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700771 // If this is the last window except for a starting transition window,
772 // we need to get rid of the starting transition.
Jorim Jaggie4b0f282017-05-17 15:10:29 +0200773 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Last window, removing starting window "
774 + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800775 if (getController() != null) {
776 getController().removeStartingWindow();
777 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700778 }
779 }
780
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700781 void removeDeadWindows() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700782 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700783 WindowState win = mChildren.get(winNdx);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800784 if (win.mAppDied) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700785 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700786 "removeDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800787 // Set mDestroying, we don't want any animation or delayed removal here.
788 win.mDestroying = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700789 // Also removes child windows.
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700790 win.removeIfPossible();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800791 }
792 }
793 }
794
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700795 boolean hasWindowsAlive() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700796 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700797 // No need to loop through child windows as the answer should be the same as that of the
798 // parent window.
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700799 if (!(mChildren.get(i)).mAppDied) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700800 return true;
801 }
802 }
803 return false;
804 }
805
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700806 void setWillReplaceWindows(boolean animate) {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700807 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
808 "Marking app token " + this + " with replacing windows.");
Robert Carra1eb4392015-12-10 12:43:51 -0800809
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700810 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700811 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700812 w.setWillReplaceWindow(animate);
Robert Carra1eb4392015-12-10 12:43:51 -0800813 }
Robert Carra1eb4392015-12-10 12:43:51 -0800814 }
815
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700816 void setWillReplaceChildWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700817 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this
Robert Carr23fa16b2016-01-13 13:19:58 -0800818 + " with replacing child windows.");
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700819 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700820 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700821 w.setWillReplaceChildWindows();
Robert Carr23fa16b2016-01-13 13:19:58 -0800822 }
823 }
824
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700825 void clearWillReplaceWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700826 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
827 "Resetting app token " + this + " of replacing window marks.");
Chong Zhangf596cd52016-01-05 13:42:44 -0800828
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700829 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700830 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700831 w.clearWillReplaceWindow();
Chong Zhangf596cd52016-01-05 13:42:44 -0800832 }
833 }
834
Chong Zhang4d7369a2016-04-25 16:09:14 -0700835 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700836 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700837 final WindowState w = mChildren.get(i);
Chong Zhang4d7369a2016-04-25 16:09:14 -0700838 w.requestUpdateWallpaperIfNeeded();
839 }
840 }
841
Chong Zhangd78ddb42016-03-02 17:01:14 -0800842 boolean isRelaunching() {
843 return mPendingRelaunchCount > 0;
844 }
845
Robert Carr68375192017-06-13 12:41:53 -0700846 boolean shouldFreezeBounds() {
847 final Task task = getTask();
848
849 // For freeform windows, we can't freeze the bounds at the moment because this would make
850 // the resizing unresponsive.
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700851 if (task == null || task.inFreeformWindowingMode()) {
Robert Carr68375192017-06-13 12:41:53 -0700852 return false;
853 }
854
855 // We freeze the bounds while drag resizing to deal with the time between
856 // the divider/drag handle being released, and the handling it's new
857 // configuration. If we are relaunched outside of the drag resizing state,
858 // we need to be careful not to do this.
859 return getTask().isDragResizing();
860 }
861
Chong Zhangd78ddb42016-03-02 17:01:14 -0800862 void startRelaunching() {
Robert Carr68375192017-06-13 12:41:53 -0700863 if (shouldFreezeBounds()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -0800864 freezeBounds();
865 }
Robert Carrd5c7dd62017-03-08 10:39:30 -0800866
867 // In the process of tearing down before relaunching, the app will
868 // try and clean up it's child surfaces. We need to prevent this from
869 // happening, so we sever the children, transfering their ownership
870 // from the client it-self to the parent surface (owned by us).
871 for (int i = mChildren.size() - 1; i >= 0; i--) {
872 final WindowState w = mChildren.get(i);
873 w.mWinAnimator.detachChildren();
874 }
875
Chong Zhangd78ddb42016-03-02 17:01:14 -0800876 mPendingRelaunchCount++;
877 }
878
879 void finishRelaunching() {
Robert Carr68375192017-06-13 12:41:53 -0700880 unfreezeBounds();
881
Chong Zhangd78ddb42016-03-02 17:01:14 -0800882 if (mPendingRelaunchCount > 0) {
883 mPendingRelaunchCount--;
Bryce Lee081554b2017-05-25 07:52:12 -0700884 } else {
885 // Update keyguard flags upon finishing relaunch.
886 checkKeyguardFlagsChanged();
Chong Zhangd78ddb42016-03-02 17:01:14 -0800887 }
888 }
889
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700890 void clearRelaunching() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700891 if (mPendingRelaunchCount == 0) {
892 return;
893 }
Robert Carr68375192017-06-13 12:41:53 -0700894 unfreezeBounds();
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700895 mPendingRelaunchCount = 0;
896 }
897
Wale Ogunwale07bcab72016-10-14 15:30:09 -0700898 /**
899 * Returns true if the new child window we are adding to this token is considered greater than
900 * the existing child window in this token in terms of z-order.
901 */
902 @Override
903 protected boolean isFirstChildWindowGreaterThanSecond(WindowState newWindow,
904 WindowState existingWindow) {
905 final int type1 = newWindow.mAttrs.type;
906 final int type2 = existingWindow.mAttrs.type;
907
908 // Base application windows should be z-ordered BELOW all other windows in the app token.
909 if (type1 == TYPE_BASE_APPLICATION && type2 != TYPE_BASE_APPLICATION) {
910 return false;
911 } else if (type1 != TYPE_BASE_APPLICATION && type2 == TYPE_BASE_APPLICATION) {
912 return true;
913 }
914
915 // Starting windows should be z-ordered ABOVE all other windows in the app token.
916 if (type1 == TYPE_APPLICATION_STARTING && type2 != TYPE_APPLICATION_STARTING) {
917 return true;
918 } else if (type1 != TYPE_APPLICATION_STARTING && type2 == TYPE_APPLICATION_STARTING) {
919 return false;
920 }
921
922 // Otherwise the new window is greater than the existing window.
923 return true;
924 }
925
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700926 @Override
Robert Carra1eb4392015-12-10 12:43:51 -0800927 void addWindow(WindowState w) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700928 super.addWindow(w);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700929
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700930 boolean gotReplacementWindow = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700931 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700932 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700933 gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w);
934 }
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700935
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700936 // if we got a replacement window, reset the timeout to give drawing more time
937 if (gotReplacementWindow) {
938 mService.scheduleWindowReplacementTimeouts(this);
Robert Carra1eb4392015-12-10 12:43:51 -0800939 }
Jorim Jaggife762342016-10-13 14:33:27 +0200940 checkKeyguardFlagsChanged();
941 }
942
943 @Override
944 void removeChild(WindowState child) {
945 super.removeChild(child);
946 checkKeyguardFlagsChanged();
Robert Carra1eb4392015-12-10 12:43:51 -0800947 }
948
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700949 private boolean waitingForReplacement() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700950 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700951 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700952 if (candidate.waitingForReplacement()) {
Robert Carra1eb4392015-12-10 12:43:51 -0800953 return true;
954 }
955 }
956 return false;
957 }
958
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700959 void onWindowReplacementTimeout() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700960 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700961 (mChildren.get(i)).onWindowReplacementTimeout();
Robert Carra1eb4392015-12-10 12:43:51 -0800962 }
963 }
964
Winson Chung30480042017-01-26 10:55:34 -0800965 void reparent(Task task, int position) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800966 final Task currentTask = getTask();
967 if (task == currentTask) {
Winson Chung30480042017-01-26 10:55:34 -0800968 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800969 "window token=" + this + " already child of task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -0800970 }
Bryce Lee6d410262017-02-28 15:30:17 -0800971
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800972 if (currentTask.mStack != task.mStack) {
Bryce Lee6d410262017-02-28 15:30:17 -0800973 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800974 "window token=" + this + " current task=" + currentTask
Bryce Lee6d410262017-02-28 15:30:17 -0800975 + " belongs to a different stack than " + task);
976 }
977
Winson Chung30480042017-01-26 10:55:34 -0800978 if (DEBUG_ADD_REMOVE) Slog.i(TAG, "reParentWindowToken: removing window token=" + this
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800979 + " from task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -0800980 final DisplayContent prevDisplayContent = getDisplayContent();
981
Bryce Lee6d410262017-02-28 15:30:17 -0800982 mReparenting = true;
983
Winson Chung30480042017-01-26 10:55:34 -0800984 getParent().removeChild(this);
985 task.addChild(this, position);
986
Bryce Lee6d410262017-02-28 15:30:17 -0800987 mReparenting = false;
988
Winson Chung30480042017-01-26 10:55:34 -0800989 // Relayout display(s).
990 final DisplayContent displayContent = task.getDisplayContent();
991 displayContent.setLayoutNeeded();
992 if (prevDisplayContent != displayContent) {
993 onDisplayChanged(displayContent);
994 prevDisplayContent.setLayoutNeeded();
995 }
996 }
997
Jorim Jaggi0429f352015-12-22 16:29:16 +0100998 /**
999 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
1000 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
1001 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
1002 * with a queue.
1003 */
Chong Zhangd78ddb42016-03-02 17:01:14 -08001004 private void freezeBounds() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001005 final Task task = getTask();
1006 mFrozenBounds.offer(new Rect(task.mPreparedFrozenBounds));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001007
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001008 if (task.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) {
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001009 // We didn't call prepareFreezingBounds on the task, so use the current value.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001010 mFrozenMergedConfig.offer(new Configuration(task.getConfiguration()));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001011 } else {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001012 mFrozenMergedConfig.offer(new Configuration(task.mPreparedFrozenMergedConfig));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001013 }
Andrii Kulianb10330d2016-09-16 13:51:46 -07001014 // Calling unset() to make it equal to Configuration.EMPTY.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001015 task.mPreparedFrozenMergedConfig.unset();
Jorim Jaggi0429f352015-12-22 16:29:16 +01001016 }
1017
1018 /**
1019 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
1020 */
Chong Zhangd78ddb42016-03-02 17:01:14 -08001021 private void unfreezeBounds() {
Robert Carr68375192017-06-13 12:41:53 -07001022 if (mFrozenBounds.isEmpty()) {
1023 return;
Wale Ogunwale37dbafc2016-06-27 10:15:20 -07001024 }
Robert Carr68375192017-06-13 12:41:53 -07001025 mFrozenBounds.remove();
Wale Ogunwale37dbafc2016-06-27 10:15:20 -07001026 if (!mFrozenMergedConfig.isEmpty()) {
1027 mFrozenMergedConfig.remove();
1028 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001029 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001030 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001031 win.onUnfreezeBounds();
Jorim Jaggi4846ee32016-01-07 17:39:12 +01001032 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001033 mService.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +01001034 }
1035
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001036 void setAppLayoutChanges(int changes, String reason) {
1037 if (!mChildren.isEmpty()) {
1038 final DisplayContent dc = getDisplayContent();
1039 dc.pendingLayoutChanges |= changes;
1040 if (DEBUG_LAYOUT_REPEATS) {
1041 mService.mWindowPlacerLocked.debugLayoutRepeats(reason, dc.pendingLayoutChanges);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001042 }
1043 }
1044 }
1045
1046 void removeReplacedWindowIfNeeded(WindowState replacement) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001047 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001048 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001049 if (win.removeReplacedWindowIfNeeded(replacement)) {
1050 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001051 }
1052 }
1053 }
1054
1055 void startFreezingScreen() {
1056 if (DEBUG_ORIENTATION) logWithStack(TAG, "Set freezing of " + appToken + ": hidden="
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001057 + isHidden() + " freezing=" + mFreezingScreen + " hiddenRequested="
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001058 + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001059 if (!hiddenRequested) {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001060 if (!mFreezingScreen) {
1061 mFreezingScreen = true;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001062 mService.registerAppFreezeListener(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001063 mService.mAppsFreezingScreen++;
1064 if (mService.mAppsFreezingScreen == 1) {
Bryce Lee8f853582017-06-05 17:25:59 -07001065 mService.startFreezingDisplayLocked(false, 0, 0, getDisplayContent());
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001066 mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT);
1067 mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001068 }
1069 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001070 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001071 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001072 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001073 w.onStartFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001074 }
1075 }
1076 }
1077
1078 void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001079 if (!mFreezingScreen) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001080 return;
1081 }
1082 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + this + " force=" + force);
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001083 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001084 boolean unfrozeWindows = false;
1085 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001086 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001087 unfrozeWindows |= w.onStopFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001088 }
1089 if (force || unfrozeWindows) {
1090 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this);
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001091 mFreezingScreen = false;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001092 mService.unregisterAppFreezeListener(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001093 mService.mAppsFreezingScreen--;
1094 mService.mLastFinishedFreezeSource = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001095 }
1096 if (unfreezeSurfaceNow) {
1097 if (unfrozeWindows) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001098 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001099 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001100 mService.stopFreezingDisplayLocked();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001101 }
1102 }
1103
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001104 @Override
1105 public void onAppFreezeTimeout() {
1106 Slog.w(TAG_WM, "Force clearing freeze: " + this);
1107 stopFreezingScreen(true, true);
1108 }
1109
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001110 boolean transferStartingWindow(IBinder transferFrom) {
Wale Ogunwale02319a62016-09-26 15:21:22 -07001111 final AppWindowToken fromToken = getDisplayContent().getAppWindowToken(transferFrom);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001112 if (fromToken == null) {
1113 return false;
1114 }
1115
1116 final WindowState tStartingWindow = fromToken.startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001117 if (tStartingWindow != null && fromToken.startingSurface != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001118 // In this case, the starting icon has already been displayed, so start
1119 // letting windows get shown immediately without any more transitions.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001120 mService.mSkipAppTransitionAnimation = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001121
1122 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow
1123 + " from " + fromToken + " to " + this);
1124
1125 final long origId = Binder.clearCallingIdentity();
Peter Visontay3556a3b2017-11-01 17:23:17 +00001126 try {
1127 // Transfer the starting window over to the new token.
1128 startingData = fromToken.startingData;
1129 startingSurface = fromToken.startingSurface;
1130 startingDisplayed = fromToken.startingDisplayed;
1131 fromToken.startingDisplayed = false;
1132 startingWindow = tStartingWindow;
1133 reportedVisible = fromToken.reportedVisible;
1134 fromToken.startingData = null;
1135 fromToken.startingSurface = null;
1136 fromToken.startingWindow = null;
1137 fromToken.startingMoved = true;
1138 tStartingWindow.mToken = this;
1139 tStartingWindow.mAppToken = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001140
Peter Visontay3556a3b2017-11-01 17:23:17 +00001141 if (DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1142 "Removing starting " + tStartingWindow + " from " + fromToken);
1143 fromToken.removeChild(tStartingWindow);
1144 fromToken.postWindowRemoveStartingWindowCleanup(tStartingWindow);
1145 fromToken.mHiddenSetFromTransferredStartingWindow = false;
1146 addWindow(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001147
Peter Visontay3556a3b2017-11-01 17:23:17 +00001148 // Propagate other interesting state between the tokens. If the old token is displayed,
1149 // we should immediately force the new one to be displayed. If it is animating, we need
1150 // to move that animation to the new one.
1151 if (fromToken.allDrawn) {
1152 allDrawn = true;
1153 deferClearAllDrawn = fromToken.deferClearAllDrawn;
1154 }
1155 if (fromToken.firstWindowDrawn) {
1156 firstWindowDrawn = true;
1157 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001158 if (!fromToken.isHidden()) {
1159 setHidden(false);
Peter Visontay3556a3b2017-11-01 17:23:17 +00001160 hiddenRequested = false;
1161 mHiddenSetFromTransferredStartingWindow = true;
1162 }
1163 setClientHidden(fromToken.mClientHidden);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001164
Jorim Jaggi980c9de2017-11-17 01:41:37 +01001165 transferAnimation(fromToken);
1166
1167 // When transferring an animation, we no longer need to apply an animation to the
1168 // the token we transfer the animation over. Thus, remove the animation from
1169 // pending opening apps.
1170 mService.mOpeningApps.remove(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001171
Peter Visontay3556a3b2017-11-01 17:23:17 +00001172 mService.updateFocusedWindowLocked(
1173 UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/);
1174 getDisplayContent().setLayoutNeeded();
1175 mService.mWindowPlacerLocked.performSurfacePlacement();
1176 } finally {
1177 Binder.restoreCallingIdentity(origId);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001178 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001179 return true;
1180 } else if (fromToken.startingData != null) {
1181 // The previous app was getting ready to show a
1182 // starting window, but hasn't yet done so. Steal it!
1183 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1184 "Moving pending starting from " + fromToken + " to " + this);
1185 startingData = fromToken.startingData;
1186 fromToken.startingData = null;
1187 fromToken.startingMoved = true;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001188 if (getController() != null) {
1189 getController().scheduleAddStartingWindow();
1190 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001191 return true;
1192 }
1193
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001194 // TODO: Transfer thumbnail
1195
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001196 return false;
1197 }
1198
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001199 boolean isLastWindow(WindowState win) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001200 return mChildren.size() == 1 && mChildren.get(0) == win;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001201 }
1202
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001203 @Override
1204 void onAppTransitionDone() {
1205 sendingToBottom = false;
1206 }
1207
Wale Ogunwale51362492016-09-08 17:49:17 -07001208 /**
1209 * We override because this class doesn't want its children affecting its reported orientation
1210 * in anyway.
1211 */
1212 @Override
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001213 int getOrientation(int candidate) {
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001214 if (candidate == SCREEN_ORIENTATION_BEHIND) {
1215 // Allow app to specify orientation regardless of its visibility state if the current
1216 // candidate want us to use orientation behind. I.e. the visible app on-top of this one
1217 // wants us to use the orientation of the app behind it.
1218 return mOrientation;
1219 }
1220
Bryce Lee61fbcbc2017-03-10 14:14:03 -08001221 // The {@link AppWindowToken} should only specify an orientation when it is not closing or
1222 // going to the bottom. Allowing closing {@link AppWindowToken} to participate can lead to
1223 // an Activity in another task being started in the wrong orientation during the transition.
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001224 if (!(sendingToBottom || mService.mClosingApps.contains(this))
Bryce Lee00d586d2017-07-28 20:48:43 -07001225 && (isVisible() || mService.mOpeningApps.contains(this) || isOnTop())) {
Bryce Leea163b762017-01-24 11:05:01 -08001226 return mOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001227 }
Bryce Leea163b762017-01-24 11:05:01 -08001228
1229 return SCREEN_ORIENTATION_UNSET;
Wale Ogunwale51362492016-09-08 17:49:17 -07001230 }
1231
Wale Ogunwaleb198b742016-12-01 08:44:09 -08001232 /** Returns the app's preferred orientation regardless of its currently visibility state. */
1233 int getOrientationIgnoreVisibility() {
1234 return mOrientation;
1235 }
1236
Craig Mautnerdbb79912012-03-01 18:59:14 -08001237 @Override
Winson Chunge55c0192017-08-24 14:50:48 -07001238 public void onConfigurationChanged(Configuration newParentConfig) {
1239 final int prevWinMode = getWindowingMode();
1240 super.onConfigurationChanged(newParentConfig);
1241 final int winMode = getWindowingMode();
1242
1243 if (prevWinMode == winMode) {
1244 return;
1245 }
1246
1247 if (prevWinMode != WINDOWING_MODE_UNDEFINED && winMode == WINDOWING_MODE_PINNED) {
1248 // Entering PiP from fullscreen, reset the snap fraction
1249 mDisplayContent.mPinnedStackControllerLocked.resetReentrySnapFraction(this);
1250 } else if (prevWinMode == WINDOWING_MODE_PINNED && winMode != WINDOWING_MODE_UNDEFINED) {
1251 // Leaving PiP to fullscreen, save the snap fraction based on the pre-animation bounds
1252 // for the next re-entry into PiP (assuming the activity is not hidden or destroyed)
1253 final TaskStack pinnedStack = mDisplayContent.getPinnedStack();
1254 if (pinnedStack != null) {
1255 mDisplayContent.mPinnedStackControllerLocked.saveReentrySnapFraction(this,
1256 pinnedStack.mPreAnimationBounds);
1257 }
1258 }
1259 }
1260
1261 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001262 void checkAppWindowsReadyToShow() {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001263 if (allDrawn == mLastAllDrawn) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001264 return;
1265 }
1266
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001267 mLastAllDrawn = allDrawn;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001268 if (!allDrawn) {
1269 return;
1270 }
1271
1272 // The token has now changed state to having all windows shown... what to do, what to do?
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001273 if (mFreezingScreen) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001274 showAllWindowsLocked();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001275 stopFreezingScreen(false, true);
1276 if (DEBUG_ORIENTATION) Slog.i(TAG,
1277 "Setting mOrientationChangeComplete=true because wtoken " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001278 + " numInteresting=" + mNumInterestingWindows + " numDrawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001279 // This will set mOrientationChangeComplete and cause a pass through layout.
1280 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001281 "checkAppWindowsReadyToShow: freezingScreen");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001282 } else {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001283 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001284
1285 // We can now show all of the drawn windows!
1286 if (!mService.mOpeningApps.contains(this)) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001287 showAllWindowsLocked();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001288 }
1289 }
1290 }
1291
Matthew Ng5d23afa2017-06-21 16:16:24 -07001292 /**
Bryce Leed390deb2017-06-22 13:14:28 -07001293 * Returns whether the drawn window states of this {@link AppWindowToken} has considered every
1294 * child {@link WindowState}. A child is considered if it has been passed into
1295 * {@link #updateDrawnWindowStates(WindowState)} after being added. This is used to determine
1296 * whether states, such as {@code allDrawn}, can be set, which relies on state variables such as
1297 * {@code mNumInterestingWindows}, which depend on all {@link WindowState}s being considered.
1298 *
1299 * @return {@code true} If all children have been considered, {@code false}.
1300 */
1301 private boolean allDrawnStatesConsidered() {
Bryce Lee6311c4b2017-07-06 14:09:29 -07001302 for (int i = mChildren.size() - 1; i >= 0; --i) {
1303 final WindowState child = mChildren.get(i);
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001304 if (child.mightAffectAllDrawn() && !child.getDrawnStateEvaluated()) {
Bryce Leed390deb2017-06-22 13:14:28 -07001305 return false;
1306 }
1307 }
1308 return true;
1309 }
1310
1311 /**
Matthew Ng5d23afa2017-06-21 16:16:24 -07001312 * Determines if the token has finished drawing. This should only be called from
1313 * {@link DisplayContent#applySurfaceChangesTransaction}
1314 */
Matthew Ng498c71d2017-04-18 13:55:45 -07001315 void updateAllDrawn() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001316 if (!allDrawn) {
Matthew Ng498c71d2017-04-18 13:55:45 -07001317 // Number of drawn windows can be less when a window is being relaunched, wait for
Bryce Leed390deb2017-06-22 13:14:28 -07001318 // all windows to be launched and drawn for this token be considered all drawn.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001319 final int numInteresting = mNumInterestingWindows;
Bryce Leed390deb2017-06-22 13:14:28 -07001320
1321 // We must make sure that all present children have been considered (determined by
1322 // {@link #allDrawnStatesConsidered}) before evaluating whether everything has been
1323 // drawn.
1324 if (numInteresting > 0 && allDrawnStatesConsidered()
1325 && mNumDrawnWindows >= numInteresting && !isRelaunching()) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001326 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawn: " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001327 + " interesting=" + numInteresting + " drawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001328 allDrawn = true;
1329 // Force an additional layout pass where
1330 // WindowStateAnimator#commitFinishDrawingLocked() will call performShowLocked().
Matthew Ng498c71d2017-04-18 13:55:45 -07001331 if (mDisplayContent != null) {
1332 mDisplayContent.setLayoutNeeded();
1333 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001334 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Robert Carrecc06b32017-04-18 14:25:10 -07001335
Winson Chunge7ba6862017-05-24 12:13:33 -07001336 // Notify the pinned stack upon all windows drawn. If there was an animation in
1337 // progress then this signal will resume that animation.
Wale Ogunwale61911492017-10-11 08:50:50 -07001338 final TaskStack pinnedStack = mDisplayContent.getPinnedStack();
Winson Chunge7ba6862017-05-24 12:13:33 -07001339 if (pinnedStack != null) {
1340 pinnedStack.onAllWindowsDrawn();
Robert Carrecc06b32017-04-18 14:25:10 -07001341 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001342 }
1343 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001344 }
1345
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001346 /**
1347 * Updated this app token tracking states for interesting and drawn windows based on the window.
1348 *
1349 * @return Returns true if the input window is considered interesting and drawn while all the
1350 * windows in this app token where not considered drawn as of the last pass.
1351 */
1352 boolean updateDrawnWindowStates(WindowState w) {
Bryce Leed390deb2017-06-22 13:14:28 -07001353 w.setDrawnStateEvaluated(true /*evaluated*/);
1354
Jorim Jaggie4b0f282017-05-17 15:10:29 +02001355 if (DEBUG_STARTING_WINDOW_VERBOSE && w == startingWindow) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001356 Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" + w.isOnScreen()
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001357 + " allDrawn=" + allDrawn + " freezingScreen=" + mFreezingScreen);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001358 }
1359
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001360 if (allDrawn && !mFreezingScreen) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001361 return false;
1362 }
1363
1364 if (mLastTransactionSequence != mService.mTransactionSequence) {
1365 mLastTransactionSequence = mService.mTransactionSequence;
1366 mNumInterestingWindows = mNumDrawnWindows = 0;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001367 startingDisplayed = false;
1368 }
1369
1370 final WindowStateAnimator winAnimator = w.mWinAnimator;
1371
1372 boolean isInterestingAndDrawn = false;
1373
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001374 if (!allDrawn && w.mightAffectAllDrawn()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001375 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
1376 Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw()
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001377 + ", isAnimationSet=" + isSelfAnimating());
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001378 if (!w.isDrawnLw()) {
1379 Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController
1380 + " pv=" + w.mPolicyVisibility
1381 + " mDrawState=" + winAnimator.drawStateToString()
1382 + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001383 + " a=" + isSelfAnimating());
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001384 }
1385 }
1386
1387 if (w != startingWindow) {
1388 if (w.isInteresting()) {
1389 mNumInterestingWindows++;
1390 if (w.isDrawnLw()) {
1391 mNumDrawnWindows++;
1392
1393 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, "tokenMayBeDrawn: "
1394 + this + " w=" + w + " numInteresting=" + mNumInterestingWindows
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001395 + " freezingScreen=" + mFreezingScreen
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001396 + " mAppFreezing=" + w.mAppFreezing);
1397
1398 isInterestingAndDrawn = true;
1399 }
1400 }
1401 } else if (w.isDrawnLw()) {
Jorim Jaggi3878ca32017-02-02 17:13:05 -08001402 if (getController() != null) {
1403 getController().reportStartingWindowDrawn();
1404 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001405 startingDisplayed = true;
1406 }
1407 }
1408
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001409 return isInterestingAndDrawn;
1410 }
1411
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001412 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001413 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001414 // For legacy reasons we process the TaskStack.mExitingAppTokens first in DisplayContent
1415 // before the non-exiting app tokens. So, we skip the exiting app tokens here.
1416 // TODO: Investigate if we need to continue to do this or if we can just process them
1417 // in-order.
1418 if (mIsExiting && !waitingForReplacement()) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001419 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001420 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001421 return forAllWindowsUnchecked(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001422 }
1423
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001424 boolean forAllWindowsUnchecked(ToBooleanFunction<WindowState> callback,
1425 boolean traverseTopToBottom) {
1426 return super.forAllWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001427 }
1428
1429 @Override
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001430 AppWindowToken asAppWindowToken() {
1431 // I am an app window token!
1432 return this;
1433 }
1434
1435 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -07001436 boolean fillsParent() {
1437 return mFillsParent;
1438 }
1439
1440 void setFillsParent(boolean fillsParent) {
1441 mFillsParent = fillsParent;
1442 }
1443
Jorim Jaggife762342016-10-13 14:33:27 +02001444 boolean containsDismissKeyguardWindow() {
Bryce Lee081554b2017-05-25 07:52:12 -07001445 // Window state is transient during relaunch. We are not guaranteed to be frozen during the
1446 // entirety of the relaunch.
1447 if (isRelaunching()) {
1448 return mLastContainsDismissKeyguardWindow;
1449 }
1450
Jorim Jaggife762342016-10-13 14:33:27 +02001451 for (int i = mChildren.size() - 1; i >= 0; i--) {
1452 if ((mChildren.get(i).mAttrs.flags & FLAG_DISMISS_KEYGUARD) != 0) {
1453 return true;
1454 }
1455 }
1456 return false;
1457 }
1458
1459 boolean containsShowWhenLockedWindow() {
Bryce Lee081554b2017-05-25 07:52:12 -07001460 // When we are relaunching, it is possible for us to be unfrozen before our previous
1461 // windows have been added back. Using the cached value ensures that our previous
1462 // showWhenLocked preference is honored until relaunching is complete.
1463 if (isRelaunching()) {
1464 return mLastContainsShowWhenLockedWindow;
1465 }
1466
Jorim Jaggife762342016-10-13 14:33:27 +02001467 for (int i = mChildren.size() - 1; i >= 0; i--) {
1468 if ((mChildren.get(i).mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
1469 return true;
1470 }
1471 }
Bryce Lee081554b2017-05-25 07:52:12 -07001472
Jorim Jaggife762342016-10-13 14:33:27 +02001473 return false;
1474 }
1475
1476 void checkKeyguardFlagsChanged() {
1477 final boolean containsDismissKeyguard = containsDismissKeyguardWindow();
1478 final boolean containsShowWhenLocked = containsShowWhenLockedWindow();
1479 if (containsDismissKeyguard != mLastContainsDismissKeyguardWindow
1480 || containsShowWhenLocked != mLastContainsShowWhenLockedWindow) {
1481 mService.notifyKeyguardFlagsChanged(null /* callback */);
1482 }
1483 mLastContainsDismissKeyguardWindow = containsDismissKeyguard;
1484 mLastContainsShowWhenLockedWindow = containsShowWhenLocked;
1485 }
1486
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001487 WindowState getImeTargetBelowWindow(WindowState w) {
1488 final int index = mChildren.indexOf(w);
1489 if (index > 0) {
1490 final WindowState target = mChildren.get(index - 1);
1491 if (target.canBeImeTarget()) {
1492 return target;
1493 }
1494 }
1495 return null;
1496 }
1497
Winson Chungbe9be7f2017-06-28 10:55:22 -07001498 int getLowestAnimLayer() {
1499 for (int i = 0; i < mChildren.size(); i++) {
1500 final WindowState w = mChildren.get(i);
1501 if (w.mRemoved) {
1502 continue;
1503 }
1504 return w.mWinAnimator.mAnimLayer;
1505 }
1506 return Integer.MAX_VALUE;
1507 }
1508
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001509 WindowState getHighestAnimLayerWindow(WindowState currentTarget) {
1510 WindowState candidate = null;
1511 for (int i = mChildren.indexOf(currentTarget); i >= 0; i--) {
1512 final WindowState w = mChildren.get(i);
1513 if (w.mRemoved) {
1514 continue;
1515 }
1516 if (candidate == null || w.mWinAnimator.mAnimLayer >
1517 candidate.mWinAnimator.mAnimLayer) {
1518 candidate = w;
1519 }
1520 }
1521 return candidate;
1522 }
1523
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001524 /**
1525 * See {@link Activity#setDisablePreviewScreenshots}.
1526 */
1527 void setDisablePreviewScreenshots(boolean disable) {
Wale Ogunwale6c459212017-05-17 08:56:03 -07001528 mDisablePreviewScreenshots = disable;
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001529 }
1530
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001531 /**
chaviwd3bf08d2017-08-01 17:24:59 -07001532 * Sets whether the current launch can turn the screen on. See {@link #canTurnScreenOn()}
1533 */
1534 void setCanTurnScreenOn(boolean canTurnScreenOn) {
1535 mCanTurnScreenOn = canTurnScreenOn;
1536 }
1537
1538 /**
1539 * Indicates whether the current launch can turn the screen on. This is to prevent multiple
1540 * relayouts from turning the screen back on. The screen should only turn on at most
1541 * once per activity resume.
1542 *
1543 * @return true if the screen can be turned on.
1544 */
1545 boolean canTurnScreenOn() {
1546 return mCanTurnScreenOn;
1547 }
1548
1549 /**
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001550 * Retrieves whether we'd like to generate a snapshot that's based solely on the theme. This is
1551 * the case when preview screenshots are disabled {@link #setDisablePreviewScreenshots} or when
1552 * we can't take a snapshot for other reasons, for example, if we have a secure window.
1553 *
1554 * @return True if we need to generate an app theme snapshot, false if we'd like to take a real
1555 * screenshot.
1556 */
1557 boolean shouldUseAppThemeSnapshot() {
Wale Ogunwale6c459212017-05-17 08:56:03 -07001558 return mDisablePreviewScreenshots || forAllWindows(w -> (w.mAttrs.flags & FLAG_SECURE) != 0,
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001559 true /* topToBottom */);
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001560 }
1561
chaviw23ee71c2017-12-18 11:29:41 -08001562 @Override
Jorim Jaggi596a1992017-12-29 14:48:02 +01001563 public SurfaceControl getAnimationLeashParent() {
1564 return getAppAnimationLayer();
chaviw23ee71c2017-12-18 11:29:41 -08001565 }
1566
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001567 boolean applyAnimationLocked(WindowManager.LayoutParams lp, int transit, boolean enter,
1568 boolean isVoiceInteraction) {
1569
1570 if (mService.mDisableTransitionAnimation) {
1571 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1572 Slog.v(TAG_WM, "applyAnimation: transition animation is disabled. atoken=" + this);
1573 }
1574 cancelAnimation();
1575 return false;
1576 }
1577
1578 // Only apply an animation if the display isn't frozen. If it is frozen, there is no reason
1579 // to animate and it can cause strange artifacts when we unfreeze the display if some
1580 // different animation is running.
1581 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "AWT#applyAnimationLocked");
1582 if (okToAnimate()) {
1583 final Animation a = loadAnimation(lp, transit, enter, isVoiceInteraction);
1584 if (a != null) {
chaviw23ee71c2017-12-18 11:29:41 -08001585 final TaskStack stack = getStack();
1586 mTmpPoint.set(0, 0);
chaviw23012112017-12-20 15:29:04 -08001587 mTmpRect.setEmpty();
chaviw23ee71c2017-12-18 11:29:41 -08001588 if (stack != null) {
1589 stack.getRelativePosition(mTmpPoint);
chaviw23012112017-12-20 15:29:04 -08001590 stack.getBounds(mTmpRect);
chaviw977482a2017-12-28 11:35:53 -08001591 mTmpRect.offsetTo(0, 0);
chaviw23ee71c2017-12-18 11:29:41 -08001592 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001593 final AnimationAdapter adapter = new LocalAnimationAdapter(
chaviw23012112017-12-20 15:29:04 -08001594 new WindowAnimationSpec(a, mTmpPoint, mTmpRect,
1595 mService.mAppTransition.canSkipFirstFrame(),
1596 mService.mAppTransition.getAppStackClipMode()),
Jorim Jaggi2e3c31d2017-11-20 19:49:00 +01001597 mService.mSurfaceAnimationRunner);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001598 if (a.getZAdjustment() == Animation.ZORDER_TOP) {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001599 mNeedsZBoost = true;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001600 }
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001601 startAnimation(getPendingTransaction(), adapter, !isVisible());
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001602 mTransit = transit;
1603 mTransitFlags = mService.mAppTransition.getTransitFlags();
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001604 }
1605 } else {
1606 cancelAnimation();
1607 }
1608 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
1609
1610 return isReallyAnimating();
1611 }
1612
1613 private Animation loadAnimation(WindowManager.LayoutParams lp, int transit, boolean enter,
1614 boolean isVoiceInteraction) {
1615 final DisplayContent displayContent = getTask().getDisplayContent();
1616 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
1617 final int width = displayInfo.appWidth;
1618 final int height = displayInfo.appHeight;
1619 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG_WM,
1620 "applyAnimation: atoken=" + this);
1621
1622 // Determine the visible rect to calculate the thumbnail clip
1623 final WindowState win = findMainWindow();
1624 final Rect frame = new Rect(0, 0, width, height);
1625 final Rect displayFrame = new Rect(0, 0,
1626 displayInfo.logicalWidth, displayInfo.logicalHeight);
1627 final Rect insets = new Rect();
1628 final Rect stableInsets = new Rect();
1629 Rect surfaceInsets = null;
1630 final boolean freeform = win != null && win.inFreeformWindowingMode();
1631 if (win != null) {
1632 // Containing frame will usually cover the whole screen, including dialog windows.
1633 // For freeform workspace windows it will not cover the whole screen and it also
1634 // won't exactly match the final freeform window frame (e.g. when overlapping with
1635 // the status bar). In that case we need to use the final frame.
1636 if (freeform) {
1637 frame.set(win.mFrame);
1638 } else {
1639 frame.set(win.mContainingFrame);
1640 }
1641 surfaceInsets = win.getAttrs().surfaceInsets;
1642 insets.set(win.mContentInsets);
1643 stableInsets.set(win.mStableInsets);
1644 }
1645
1646 if (mLaunchTaskBehind) {
1647 // Differentiate the two animations. This one which is briefly on the screen
1648 // gets the !enter animation, and the other activity which remains on the
1649 // screen gets the enter animation. Both appear in the mOpeningApps set.
1650 enter = false;
1651 }
1652 if (DEBUG_APP_TRANSITIONS) Slog.d(TAG_WM, "Loading animation for app transition."
1653 + " transit=" + AppTransition.appTransitionToString(transit) + " enter=" + enter
1654 + " frame=" + frame + " insets=" + insets + " surfaceInsets=" + surfaceInsets);
1655 final Configuration displayConfig = displayContent.getConfiguration();
1656 final Animation a = mService.mAppTransition.loadAnimation(lp, transit, enter,
1657 displayConfig.uiMode, displayConfig.orientation, frame, displayFrame, insets,
1658 surfaceInsets, stableInsets, isVoiceInteraction, freeform, getTask().mTaskId);
1659 if (a != null) {
1660 if (DEBUG_ANIM) logWithStack(TAG, "Loaded animation " + a + " for " + this);
1661 final int containingWidth = frame.width();
1662 final int containingHeight = frame.height();
1663 a.initialize(containingWidth, containingHeight, width, height);
1664 a.scaleCurrentDuration(mService.getTransitionAnimationScaleLocked());
1665 }
1666 return a;
1667 }
1668
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001669 @Override
1670 protected void setLayer(Transaction t, int layer) {
1671 if (!mSurfaceAnimator.hasLeash()) {
1672 t.setLayer(mSurfaceControl, layer);
1673 }
1674 }
1675
1676 @Override
1677 protected void setRelativeLayer(Transaction t, SurfaceControl relativeTo, int layer) {
1678 if (!mSurfaceAnimator.hasLeash()) {
1679 t.setRelativeLayer(mSurfaceControl, relativeTo, layer);
1680 }
1681 }
1682
1683 @Override
1684 protected void reparentSurfaceControl(Transaction t, SurfaceControl newParent) {
1685 if (!mSurfaceAnimator.hasLeash()) {
1686 t.reparent(mSurfaceControl, newParent.getHandle());
1687 }
1688 }
1689
1690 @Override
1691 public void onAnimationLeashCreated(Transaction t, SurfaceControl leash) {
1692
1693 // The leash is parented to the animation layer. We need to preserve the z-order by using
1694 // the prefix order index, but we boost if necessary.
1695 int layer = getPrefixOrderIndex();
1696 if (mNeedsZBoost) {
1697 layer += Z_BOOST_BASE;
1698 }
1699 leash.setLayer(layer);
1700 }
1701
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001702 /**
1703 * This must be called while inside a transaction.
1704 */
1705 void showAllWindowsLocked() {
1706 forAllWindows(windowState -> {
1707 if (DEBUG_VISIBILITY) Slog.v(TAG, "performing show on: " + windowState);
1708 windowState.performShowLocked();
1709 }, false /* traverseTopToBottom */);
Jorim Jaggia5e10572017-11-15 14:36:26 +01001710 }
1711
1712 @Override
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001713 protected void onAnimationFinished() {
1714 super.onAnimationFinished();
1715
1716 mTransit = TRANSIT_UNSET;
1717 mTransitFlags = 0;
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001718 mNeedsZBoost = false;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001719
1720 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM | FINISH_LAYOUT_REDO_WALLPAPER,
1721 "AppWindowToken");
1722
Jorim Jaggi988f6682017-11-17 17:46:43 +01001723 clearThumbnail();
1724
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001725 if (mService.mInputMethodTarget != null && mService.mInputMethodTarget.mAppToken == this) {
1726 getDisplayContent().computeImeTarget(true /* updateImeTarget */);
1727 }
1728
1729 if (DEBUG_ANIM) Slog.v(TAG, "Animation done in " + this
1730 + ": reportedVisible=" + reportedVisible
1731 + " okToDisplay=" + okToDisplay()
1732 + " okToAnimate=" + okToAnimate()
1733 + " startingDisplayed=" + startingDisplayed);
1734
1735 // WindowState.onExitAnimationDone might modify the children list, so make a copy and then
1736 // traverse the copy.
1737 final ArrayList<WindowState> children = new ArrayList<>(mChildren);
1738 children.forEach(WindowState::onExitAnimationDone);
1739
1740 mService.mAppTransition.notifyAppTransitionFinishedLocked(token);
1741 scheduleAnimation();
1742 }
1743
1744 @Override
1745 boolean isAppAnimating() {
1746 return isSelfAnimating();
1747 }
1748
1749 @Override
1750 boolean isSelfAnimating() {
1751 // If we are about to start a transition, we also need to be considered animating.
1752 return isWaitingForTransitionStart() || isReallyAnimating();
1753 }
1754
1755 /**
1756 * @return True if and only if we are actually running an animation. Note that
1757 * {@link #isSelfAnimating} also returns true if we are waiting for an animation to
1758 * start.
1759 */
1760 private boolean isReallyAnimating() {
1761 return super.isSelfAnimating();
1762 }
1763
Jorim Jaggi988f6682017-11-17 17:46:43 +01001764 @Override
1765 void cancelAnimation() {
1766 super.cancelAnimation();
1767 clearThumbnail();
1768 }
1769
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001770 boolean isWaitingForTransitionStart() {
1771 return mService.mAppTransition.isTransitionSet()
1772 && (mService.mOpeningApps.contains(this) || mService.mClosingApps.contains(this));
1773 }
1774
1775 public int getTransit() {
1776 return mTransit;
1777 }
1778
1779 int getTransitFlags() {
1780 return mTransitFlags;
1781 }
1782
Jorim Jaggi988f6682017-11-17 17:46:43 +01001783 void attachThumbnailAnimation() {
1784 if (!isReallyAnimating()) {
1785 return;
1786 }
1787 final int taskId = getTask().mTaskId;
1788 final GraphicBuffer thumbnailHeader =
1789 mService.mAppTransition.getAppTransitionThumbnailHeader(taskId);
1790 if (thumbnailHeader == null) {
1791 if (DEBUG_APP_TRANSITIONS) Slog.d(TAG, "No thumbnail header bitmap for: " + taskId);
1792 return;
1793 }
1794 clearThumbnail();
1795 mThumbnail = new AppWindowThumbnail(getPendingTransaction(), this, thumbnailHeader);
1796 mThumbnail.startAnimation(getPendingTransaction(), loadThumbnailAnimation(thumbnailHeader));
1797 }
1798
Tony Mak64b8d562017-12-28 17:44:02 +00001799 /**
1800 * Attaches a surface with a thumbnail for the
1801 * {@link android.app.ActivityOptions#ANIM_OPEN_CROSS_PROFILE_APPS} animation.
1802 */
1803 void attachCrossProfileAppsThumbnailAnimation() {
1804 if (!isReallyAnimating()) {
1805 return;
1806 }
1807 clearThumbnail();
1808
1809 final WindowState win = findMainWindow();
1810 if (win == null) {
1811 return;
1812 }
1813 final Rect frame = win.mFrame;
1814 final int thumbnailDrawableRes = getTask().mUserId == mService.mCurrentUserId
1815 ? R.drawable.ic_account_circle
1816 : R.drawable.ic_corp_badge_no_background;
1817 final GraphicBuffer thumbnail =
1818 mService.mAppTransition
1819 .createCrossProfileAppsThumbnail(thumbnailDrawableRes, frame);
1820 if (thumbnail == null) {
1821 return;
1822 }
1823 mThumbnail = new AppWindowThumbnail(getPendingTransaction(), this, thumbnail);
1824 final Animation animation =
1825 mService.mAppTransition.createCrossProfileAppsThumbnailAnimationLocked(win.mFrame);
1826 mThumbnail.startAnimation(getPendingTransaction(), animation, new Point(frame.left,
1827 frame.top));
1828 }
1829
Jorim Jaggi988f6682017-11-17 17:46:43 +01001830 private Animation loadThumbnailAnimation(GraphicBuffer thumbnailHeader) {
1831 final DisplayInfo displayInfo = mDisplayContent.getDisplayInfo();
1832
1833 // If this is a multi-window scenario, we use the windows frame as
1834 // destination of the thumbnail header animation. If this is a full screen
1835 // window scenario, we use the whole display as the target.
1836 WindowState win = findMainWindow();
1837 Rect appRect = win != null ? win.getContentFrameLw() :
1838 new Rect(0, 0, displayInfo.appWidth, displayInfo.appHeight);
1839 Rect insets = win != null ? win.mContentInsets : null;
1840 final Configuration displayConfig = mDisplayContent.getConfiguration();
1841 return mService.mAppTransition.createThumbnailAspectScaleAnimationLocked(
1842 appRect, insets, thumbnailHeader, getTask().mTaskId, displayConfig.uiMode,
1843 displayConfig.orientation);
1844 }
1845
1846 private void clearThumbnail() {
1847 if (mThumbnail == null) {
1848 return;
1849 }
1850 mThumbnail.destroy();
1851 mThumbnail = null;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001852 }
1853
1854 @Override
1855 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
1856 super.dump(pw, prefix, dumpAll);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001857 if (appToken != null) {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001858 pw.println(prefix + "app=true mVoiceInteraction=" + mVoiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001859 }
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001860 pw.print(prefix); pw.print("task="); pw.println(getTask());
Wale Ogunwale51362492016-09-08 17:49:17 -07001861 pw.print(prefix); pw.print(" mFillsParent="); pw.print(mFillsParent);
1862 pw.print(" mOrientation="); pw.println(mOrientation);
Wale Ogunwale89973222017-04-23 18:39:45 -07001863 pw.println(prefix + "hiddenRequested=" + hiddenRequested + " mClientHidden=" + mClientHidden
1864 + ((mDeferHidingClient) ? " mDeferHidingClient=" + mDeferHidingClient : "")
1865 + " reportedDrawn=" + reportedDrawn + " reportedVisible=" + reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -07001866 if (paused) {
1867 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001868 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001869 if (mAppStopped) {
1870 pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped);
1871 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001872 if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001873 || allDrawn || mLastAllDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001874 pw.print(prefix); pw.print("mNumInterestingWindows=");
1875 pw.print(mNumInterestingWindows);
1876 pw.print(" mNumDrawnWindows="); pw.print(mNumDrawnWindows);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001877 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -07001878 pw.print(" allDrawn="); pw.print(allDrawn);
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001879 pw.print(" lastAllDrawn="); pw.print(mLastAllDrawn);
Craig Mautner6fbda632012-07-03 09:26:39 -07001880 pw.println(")");
1881 }
1882 if (inPendingTransaction) {
1883 pw.print(prefix); pw.print("inPendingTransaction=");
1884 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001885 }
Craig Mautner799bc1d2015-01-14 10:33:48 -08001886 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001887 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
1888 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -08001889 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -08001890 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001891 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001892 if (startingWindow != null || startingSurface != null
Wale Ogunwale6c459212017-05-17 08:56:03 -07001893 || startingDisplayed || startingMoved || mHiddenSetFromTransferredStartingWindow) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001894 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001895 pw.print(" startingSurface="); pw.print(startingSurface);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001896 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
Wale Ogunwale6c459212017-05-17 08:56:03 -07001897 pw.print(" startingMoved="); pw.print(startingMoved);
1898 pw.println(" mHiddenSetFromTransferredStartingWindow="
1899 + mHiddenSetFromTransferredStartingWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001900 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01001901 if (!mFrozenBounds.isEmpty()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -08001902 pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds);
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001903 pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig);
Chong Zhangd78ddb42016-03-02 17:01:14 -08001904 }
1905 if (mPendingRelaunchCount != 0) {
1906 pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount);
Jorim Jaggi0429f352015-12-22 16:29:16 +01001907 }
Wale Ogunwale9c64cb62017-04-12 13:39:59 -07001908 if (getController() != null) {
1909 pw.print(prefix); pw.print("controller="); pw.println(getController());
1910 }
Wale Ogunwalee287e192017-04-21 09:30:12 -07001911 if (mRemovingFromDisplay) {
1912 pw.println(prefix + "mRemovingFromDisplay=" + mRemovingFromDisplay);
1913 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001914 }
1915
1916 @Override
1917 void setHidden(boolean hidden) {
1918 super.setHidden(hidden);
Winson Chunge55c0192017-08-24 14:50:48 -07001919
1920 if (hidden) {
1921 // Once the app window is hidden, reset the last saved PiP snap fraction
1922 mDisplayContent.mPinnedStackControllerLocked.resetReentrySnapFraction(this);
1923 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001924 scheduleAnimation();
1925 }
1926
1927 @Override
1928 void prepareSurfaces() {
1929 // isSelfAnimating also returns true when we are about to start a transition, so we need
1930 // to check super here.
1931 final boolean reallyAnimating = super.isSelfAnimating();
1932 final boolean show = !isHidden() || reallyAnimating;
1933 if (show && !mLastSurfaceShowing) {
1934 mPendingTransaction.show(mSurfaceControl);
1935 } else if (!show && mLastSurfaceShowing) {
1936 mPendingTransaction.hide(mSurfaceControl);
Jorim Jaggi4d1835d2017-08-31 17:28:27 +02001937 }
Jorim Jaggi988f6682017-11-17 17:46:43 +01001938 if (mThumbnail != null) {
1939 mThumbnail.setShowing(mPendingTransaction, show);
1940 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001941 mLastSurfaceShowing = show;
1942 super.prepareSurfaces();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001943 }
1944
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001945 boolean isFreezingScreen() {
1946 return mFreezingScreen;
1947 }
1948
1949 @Override
1950 boolean needsZBoost() {
1951 return mNeedsZBoost || super.needsZBoost();
1952 }
1953
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07001954 @CallSuper
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001955 @Override
Adrian Roos4921ccf2017-09-28 16:54:06 +02001956 public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07001957 final long token = proto.start(fieldId);
1958 writeNameToProto(proto, NAME);
Adrian Roos4921ccf2017-09-28 16:54:06 +02001959 super.writeToProto(proto, WINDOW_TOKEN, trim);
Vishnu Nair04ab4392018-01-10 11:00:06 -08001960 proto.write(LAST_SURFACE_SHOWING, mLastSurfaceShowing);
1961 proto.write(IS_WAITING_FOR_TRANSITION_START, isWaitingForTransitionStart());
1962 proto.write(IS_REALLY_ANIMATING, isReallyAnimating());
1963 if (mThumbnail != null){
1964 mThumbnail.writeToProto(proto, THUMBNAIL);
1965 }
1966 proto.write(FILLS_PARENT, mFillsParent);
1967 proto.write(APP_STOPPED, mAppStopped);
1968 proto.write(HIDDEN_REQUESTED, hiddenRequested);
1969 proto.write(CLIENT_HIDDEN, mClientHidden);
1970 proto.write(DEFER_HIDING_CLIENT, mDeferHidingClient);
1971 proto.write(REPORTED_DRAWN, reportedDrawn);
1972 proto.write(REPORTED_VISIBLE, reportedVisible);
1973 proto.write(NUM_INTERESTING_WINDOWS, mNumInterestingWindows);
1974 proto.write(NUM_DRAWN_WINDOWS, mNumDrawnWindows);
1975 proto.write(ALL_DRAWN, allDrawn);
1976 proto.write(LAST_ALL_DRAWN, mLastAllDrawn);
1977 proto.write(REMOVED, removed);
1978 if (startingWindow != null){
1979 startingWindow.writeIdentifierToProto(proto, STARTING_WINDOW);
1980 }
1981 proto.write(STARTING_DISPLAYED, startingDisplayed);
1982 proto.write(STARTING_MOVED, startingMoved);
1983 proto.write(HIDDEN_SET_FROM_TRANSFERRED_STARTING_WINDOW,
1984 mHiddenSetFromTransferredStartingWindow);
1985 for (Rect bounds : mFrozenBounds) {
1986 bounds.writeToProto(proto, FROZEN_BOUNDS);
1987 }
Steven Timotiusaf03df62017-07-18 16:56:43 -07001988 proto.end(token);
1989 }
1990
1991 void writeNameToProto(ProtoOutputStream proto, long fieldId) {
1992 if (appToken == null) {
1993 return;
1994 }
1995 try {
1996 proto.write(fieldId, appToken.getName());
1997 } catch (RemoteException e) {
1998 // This shouldn't happen, but in this case fall back to outputting nothing
1999 Slog.e(TAG, e.toString());
2000 }
2001 }
2002
2003 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002004 public String toString() {
2005 if (stringName == null) {
2006 StringBuilder sb = new StringBuilder();
2007 sb.append("AppWindowToken{");
2008 sb.append(Integer.toHexString(System.identityHashCode(this)));
2009 sb.append(" token="); sb.append(token); sb.append('}');
2010 stringName = sb.toString();
2011 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07002012 return stringName + ((mIsExiting) ? " mIsExiting=" : "");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002013 }
Jeff Browne9bdb312012-04-05 15:30:10 -07002014}