blob: 27e9deaa45ced8a92bf0ca6df8b372bad62e6564 [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
Wale Ogunwale6cae7652015-12-26 07:36:26 -080019import static android.app.ActivityManager.StackId;
Wale Ogunwale72919d22016-12-08 18:58:50 -080020import static android.content.pm.ActivityInfo.CONFIG_ORIENTATION;
21import static android.content.pm.ActivityInfo.CONFIG_SCREEN_SIZE;
Wale Ogunwale51362492016-09-08 17:49:17 -070022import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070023import static android.view.Display.DEFAULT_DISPLAY;
Jorim Jaggife762342016-10-13 14:33:27 +020024import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
25import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
Wale Ogunwaled1c37912016-08-16 03:19:39 -070026import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080027import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070028import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -070029import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
30import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070031import static com.android.server.wm.AppTransition.TRANSIT_UNSET;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080032import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080033import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
34import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070035import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070036import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
37import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
Wale Ogunwale9017ec02016-02-25 08:55:25 -080038import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070039import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TOKEN_MOVEMENT;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080040import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
41import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_MOVEMENT;
42import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
43import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Chong Zhang92147042016-05-09 12:47:11 -070044import static com.android.server.wm.WindowManagerService.H.NOTIFY_ACTIVITY_DRAWN;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070045import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070046import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070047import static com.android.server.wm.WindowManagerService.logWithStack;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080048
Filip Gruszczynskia590c992015-11-25 16:45:26 -080049import android.annotation.NonNull;
Jorim Jaggi26c8c422016-05-09 19:57:25 -070050import android.content.res.Configuration;
Jorim Jaggi0429f352015-12-22 16:29:16 +010051import android.graphics.Rect;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070052import android.os.Binder;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080053import android.os.Debug;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070054import android.os.IBinder;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070055import android.os.SystemClock;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080056import android.util.Slog;
57import android.view.IApplicationToken;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080058import android.view.WindowManager;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080059import android.view.WindowManagerPolicy.StartingSurface;
60
61import com.android.internal.util.ToBooleanFunction;
62import com.android.server.input.InputApplicationHandle;
63import com.android.server.wm.WindowManagerService.H;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080064
65import java.io.PrintWriter;
Jorim Jaggi0429f352015-12-22 16:29:16 +010066import java.util.ArrayDeque;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080067import java.util.ArrayList;
68
69class AppTokenList extends ArrayList<AppWindowToken> {
70}
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080071
72/**
73 * Version of WindowToken that is specifically for a particular application (or
74 * really activity) that is displaying windows.
75 */
Wale Ogunwale3f4433d2016-08-18 20:42:42 -070076class AppWindowToken extends WindowToken implements WindowManagerService.AppFreezeListener {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080077 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppWindowToken" : TAG_WM;
78
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080079 // Non-null only for application tokens.
80 final IApplicationToken appToken;
81
Filip Gruszczynskia590c992015-11-25 16:45:26 -080082 @NonNull final AppWindowAnimator mAppAnimator;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -070083
Wale Ogunwale72919d22016-12-08 18:58:50 -080084 final boolean mVoiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -070085
Wale Ogunwale51362492016-09-08 17:49:17 -070086 /** @see WindowContainer#fillsParent() */
87 private boolean mFillsParent;
Craig Mautner4c5eb222013-11-18 12:59:05 -080088 boolean layoutConfigChanges;
Wale Ogunwale72919d22016-12-08 18:58:50 -080089 boolean mShowForAllUsers;
90 int mTargetSdk;
Craig Mautnera2c77052012-03-26 12:14:43 -070091
Bryce Lee6d410262017-02-28 15:30:17 -080092 // Flag set while reparenting to prevent actions normally triggered by an individual parent
93 // change.
94 private boolean mReparenting;
95
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080096 // The input dispatching timeout for this application token in nanoseconds.
Wale Ogunwale72919d22016-12-08 18:58:50 -080097 long mInputDispatchingTimeoutNanos;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080098
99 // These are used for determining when all windows associated with
100 // an activity have been drawn, so they can be made visible together
101 // at the same time.
Craig Mautner764983d2012-03-22 11:37:36 -0700102 // initialize so that it doesn't match mTransactionSequence which is an int.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700103 private long mLastTransactionSequence = Long.MIN_VALUE;
104 private int mNumInterestingWindows;
105 private int mNumDrawnWindows;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800106 boolean inPendingTransaction;
107 boolean allDrawn;
Craig Mautner7636dfb2012-11-16 15:24:11 -0800108 // Set to true when this app creates a surface while in the middle of an animation. In that
109 // case do not clear allDrawn until the animation completes.
110 boolean deferClearAllDrawn;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800111
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700112 /**
113 * These are to track the app's real drawing status if there were no saved surfaces.
114 * @see #updateDrawnWindowStates
115 */
Chong Zhang8e4bda92016-05-04 15:08:18 -0700116 boolean allDrawnExcludingSaved;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700117 private int mNumInterestingWindowsExcludingSaved;
118 private int mNumDrawnWindowsExcludingSaved;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700119
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800120 // Is this window's surface needed? This is almost like hidden, except
121 // it will sometimes be true a little earlier: when the token has
122 // been shown, but is still waiting for its app transition to execute
123 // before making its windows shown.
124 boolean hiddenRequested;
125
126 // Have we told the window clients to hide themselves?
127 boolean clientHidden;
128
129 // Last visibility state we reported to the app token.
130 boolean reportedVisible;
131
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700132 // Last drawn state we reported to the app token.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700133 private boolean reportedDrawn;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700134
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800135 // Set to true when the token has been removed from the window mgr.
136 boolean removed;
137
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800138 // Information about an application starting window if displayed.
139 StartingData startingData;
140 WindowState startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800141 StartingSurface startingSurface;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800142 boolean startingDisplayed;
143 boolean startingMoved;
144 boolean firstWindowDrawn;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700145 private final WindowState.UpdateReportedVisibilityResults mReportedVisibilityResults =
146 new WindowState.UpdateReportedVisibilityResults();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800147
148 // Input application handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700149 final InputApplicationHandle mInputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800150
Wale Ogunwale571771c2016-08-26 13:18:50 -0700151 // TODO: Have a WindowContainer state for tracking exiting/deferred removal.
Craig Mautner799bc1d2015-01-14 10:33:48 -0800152 boolean mIsExiting;
Craig Mautner9ef471f2014-02-07 13:11:47 -0800153
Craig Mautnerbb742462014-07-07 15:28:55 -0700154 boolean mLaunchTaskBehind;
Craig Mautner8746a472014-07-24 15:12:54 -0700155 boolean mEnteringAnimation;
Craig Mautnerbb742462014-07-07 15:28:55 -0700156
Wale Ogunwale72919d22016-12-08 18:58:50 -0800157 private boolean mAlwaysFocusable;
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800158
Robert Carre12aece2016-02-02 22:43:27 -0800159 boolean mAppStopped;
Robert Carrfd10cd12016-06-29 16:41:50 -0700160 int mRotationAnimationHint;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700161 private int mPendingRelaunchCount;
Robert Carre12aece2016-02-02 22:43:27 -0800162
Jorim Jaggife762342016-10-13 14:33:27 +0200163 private boolean mLastContainsShowWhenLockedWindow;
164 private boolean mLastContainsDismissKeyguardWindow;
165
Jorim Jaggi0429f352015-12-22 16:29:16 +0100166 ArrayDeque<Rect> mFrozenBounds = new ArrayDeque<>();
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700167 ArrayDeque<Configuration> mFrozenMergedConfig = new ArrayDeque<>();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100168
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +0100169 private boolean mDisbalePreviewScreenshots;
170
Wale Ogunwale72919d22016-12-08 18:58:50 -0800171 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
172 DisplayContent dc, long inputDispatchingTimeoutNanos, boolean fullscreen,
173 boolean showForAllUsers, int targetSdk, int orientation, int rotationAnimationHint,
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800174 int configChanges, boolean launchTaskBehind, boolean alwaysFocusable,
175 AppWindowContainerController controller) {
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800176 this(service, token, voiceInteraction, dc, fullscreen);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800177 setController(controller);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800178 mInputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800179 mShowForAllUsers = showForAllUsers;
180 mTargetSdk = targetSdk;
181 mOrientation = orientation;
182 layoutConfigChanges = (configChanges & (CONFIG_SCREEN_SIZE | CONFIG_ORIENTATION)) != 0;
183 mLaunchTaskBehind = launchTaskBehind;
184 mAlwaysFocusable = alwaysFocusable;
185 mRotationAnimationHint = rotationAnimationHint;
186
187 // Application tokens start out hidden.
188 hidden = true;
189 hiddenRequested = true;
190 }
191
192 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800193 DisplayContent dc, boolean fillsParent) {
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800194 super(service, token != null ? token.asBinder() : null, TYPE_APPLICATION, true, dc,
195 false /* ownerCanManageAppTokens */);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700196 appToken = token;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800197 mVoiceInteraction = voiceInteraction;
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800198 mFillsParent = fillsParent;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800199 mInputApplicationHandle = new InputApplicationHandle(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700200 mAppAnimator = new AppWindowAnimator(this, service);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800201 }
202
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800203 void onFirstWindowDrawn(WindowState win, WindowStateAnimator winAnimator) {
204 firstWindowDrawn = true;
205
206 // We now have a good window to show, remove dead placeholders
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700207 removeDeadWindows();
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800208
Jorim Jaggi02886a82016-12-06 09:10:06 -0800209 if (startingWindow != null) {
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800210 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, "Finish starting "
211 + win.mToken + ": first real window is shown, no animation");
212 // If this initial window is animating, stop it -- we will do an animation to reveal
213 // it from behind the starting window, so there is no need for it to also be doing its
214 // own stuff.
215 winAnimator.clearAnimation();
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800216 if (getController() != null) {
217 getController().removeStartingWindow();
218 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800219 }
220 updateReportedVisibilityLocked();
221 }
222
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800223 void updateReportedVisibilityLocked() {
224 if (appToken == null) {
225 return;
226 }
227
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700228 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700229 final int count = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800230
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700231 mReportedVisibilityResults.reset();
232
233 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700234 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700235 win.updateReportedVisibility(mReportedVisibilityResults);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800236 }
237
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700238 int numInteresting = mReportedVisibilityResults.numInteresting;
239 int numVisible = mReportedVisibilityResults.numVisible;
240 int numDrawn = mReportedVisibilityResults.numDrawn;
241 boolean nowGone = mReportedVisibilityResults.nowGone;
242
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700243 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800244 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700245 if (!nowGone) {
246 // If the app is not yet gone, then it can only become visible/drawn.
247 if (!nowDrawn) {
248 nowDrawn = reportedDrawn;
249 }
250 if (!nowVisible) {
251 nowVisible = reportedVisible;
252 }
253 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800254 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800255 + numInteresting + " visible=" + numVisible);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800256 final AppWindowContainerController controller = getController();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700257 if (nowDrawn != reportedDrawn) {
258 if (nowDrawn) {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800259 if (controller != null) {
260 controller.reportWindowsDrawn();
261 }
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700262 }
263 reportedDrawn = nowDrawn;
264 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800265 if (nowVisible != reportedVisible) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700266 if (DEBUG_VISIBILITY) Slog.v(TAG,
267 "Visibility changed in " + this + ": vis=" + nowVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800268 reportedVisible = nowVisible;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800269 if (controller != null) {
270 if (nowVisible) {
271 controller.reportWindowsVisible();
272 } else {
273 controller.reportWindowsGone();
274 }
275 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800276 }
277 }
278
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700279 boolean setVisibility(WindowManager.LayoutParams lp,
280 boolean visible, int transit, boolean performLayout, boolean isVoiceInteraction) {
281
282 boolean delayed = false;
283 inPendingTransaction = false;
284
285 if (clientHidden == visible) {
286 clientHidden = !visible;
287 sendAppVisibilityToClients();
288 }
289
290 // Allow for state changes and animation to be applied if:
291 // * token is transitioning visibility state
292 // * or the token was marked as hidden and is exiting before we had a chance to play the
293 // transition animation
294 // * or this is an opening app and windows are being replaced.
295 boolean visibilityChanged = false;
296 if (hidden == visible || (hidden && mIsExiting) || (visible && waitingForReplacement())) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700297 final AccessibilityController accessibilityController = mService.mAccessibilityController;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700298 boolean changed = false;
299 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
300 "Changing app " + this + " hidden=" + hidden + " performLayout=" + performLayout);
301
302 boolean runningAppAnimation = false;
303
304 if (transit != AppTransition.TRANSIT_UNSET) {
305 if (mAppAnimator.animation == AppWindowAnimator.sDummyAnimation) {
306 mAppAnimator.setNullAnimation();
307 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700308 if (mService.applyAnimationLocked(this, lp, transit, visible, isVoiceInteraction)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700309 delayed = runningAppAnimation = true;
310 }
311 final WindowState window = findMainWindow();
312 //TODO (multidisplay): Magnification is supported only for the default display.
313 if (window != null && accessibilityController != null
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700314 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700315 accessibilityController.onAppWindowTransitionLocked(window, transit);
316 }
317 changed = true;
318 }
319
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700320 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700321 for (int i = 0; i < windowsCount; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700322 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700323 changed |= win.onAppVisibilityChanged(visible, runningAppAnimation);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700324 }
325
326 hidden = hiddenRequested = !visible;
327 visibilityChanged = true;
328 if (!visible) {
329 stopFreezingScreen(true, true);
330 } else {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700331 // If we are being set visible, and the starting window is not yet displayed,
332 // then make sure it doesn't get displayed.
333 if (startingWindow != null && !startingWindow.isDrawnLw()) {
334 startingWindow.mPolicyVisibility = false;
335 startingWindow.mPolicyVisibilityAfterAnim = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700336 }
337 }
338
339 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setVisibility: " + this
340 + ": hidden=" + hidden + " hiddenRequested=" + hiddenRequested);
341
342 if (changed) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700343 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700344 if (performLayout) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700345 mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700346 false /*updateInputWindows*/);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700347 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700348 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700349 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700350 }
351 }
352
353 if (mAppAnimator.animation != null) {
354 delayed = true;
355 }
356
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700357 for (int i = mChildren.size() - 1; i >= 0 && !delayed; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700358 if ((mChildren.get(i)).isWindowAnimationSet()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700359 delayed = true;
360 }
361 }
362
363 if (visibilityChanged) {
364 if (visible && !delayed) {
365 // The token was made immediately visible, there will be no entrance animation.
366 // We need to inform the client the enter animation was finished.
367 mEnteringAnimation = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700368 mService.mActivityManagerAppTransitionNotifier.onAppTransitionFinishedLocked(token);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700369 }
370
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700371 if (!mService.mClosingApps.contains(this) && !mService.mOpeningApps.contains(this)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700372 // The token is not closing nor opening, so even if there is an animation set, that
373 // doesn't mean that it goes through the normal app transition cycle so we have
374 // to inform the docked controller about visibility change.
Andrii Kulian1e32e022016-09-16 15:29:34 -0700375 // TODO(multi-display): notify docked divider on all displays where visibility was
376 // affected.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700377 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700378 .notifyAppVisibilityChanged();
Jorim Jaggi8b702ed2017-01-20 16:59:03 +0100379 mService.mTaskSnapshotController.notifyAppVisibilityChanged(this, visible);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700380 }
381 }
382
383 return delayed;
384 }
385
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800386 WindowState findMainWindow() {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700387 WindowState candidate = null;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700388 int j = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800389 while (j > 0) {
390 j--;
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700391 final WindowState win = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700392 final int type = win.mAttrs.type;
393 // No need to loop through child window as base application and starting types can't be
394 // child windows.
395 if (type == TYPE_BASE_APPLICATION || type == TYPE_APPLICATION_STARTING) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700396 // In cases where there are multiple windows, we prefer the non-exiting window. This
Sungsoo Lim0d3d1f82015-12-02 14:47:59 +0900397 // happens for example when replacing windows during an activity relaunch. When
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700398 // constructing the animation, we want the new window, not the exiting one.
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800399 if (win.mAnimatingExit) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700400 candidate = win;
401 } else {
402 return win;
403 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800404 }
405 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700406 return candidate;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800407 }
408
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800409 boolean windowsAreFocusable() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800410 return StackId.canReceiveKeys(getTask().mStack.mStackId) || mAlwaysFocusable;
Wale Ogunwaled045c822015-12-02 09:14:28 -0800411 }
412
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800413 AppWindowContainerController getController() {
414 final WindowContainerController controller = super.getController();
415 return controller != null ? (AppWindowContainerController) controller : null;
416 }
417
Wale Ogunwale571771c2016-08-26 13:18:50 -0700418 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -0700419 boolean isVisible() {
Wale Ogunwalee471be62016-10-03 07:53:55 -0700420 // If the app token isn't hidden then it is considered visible and there is no need to check
421 // its children windows to see if they are visible.
422 return !hidden;
Wale Ogunwale44f21802016-09-02 12:49:48 -0700423 }
424
425 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -0700426 void removeIfPossible() {
Craig Mautnere3119b72015-01-20 15:02:36 -0800427 mIsExiting = false;
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800428 removeAllWindowsIfPossible();
Bryce Lee6d410262017-02-28 15:30:17 -0800429 removeImmediately();
Craig Mautnere3119b72015-01-20 15:02:36 -0800430 }
431
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700432 @Override
433 boolean checkCompleteDeferredRemoval() {
434 if (mIsExiting) {
435 removeIfPossible();
436 }
437 return super.checkCompleteDeferredRemoval();
438 }
439
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700440 void onRemovedFromDisplay() {
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700441 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app token: " + this);
442
Wale Ogunwale72919d22016-12-08 18:58:50 -0800443 boolean delayed = setVisibility(null, false, TRANSIT_UNSET, true, mVoiceInteraction);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700444
445 mService.mOpeningApps.remove(this);
Jorim Jaggi1b4b23e2016-11-15 16:30:12 -0800446 mService.mUnknownAppVisibilityController.appRemoved(this);
Jorim Jaggi10abe2f2017-01-03 16:44:46 +0100447 mService.mTaskSnapshotController.onAppRemoved(this);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700448 waitingToShow = false;
449 if (mService.mClosingApps.contains(this)) {
450 delayed = true;
451 } else if (mService.mAppTransition.isTransitionSet()) {
452 mService.mClosingApps.add(this);
453 delayed = true;
454 }
455
456 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app " + this + " delayed=" + delayed
457 + " animation=" + mAppAnimator.animation + " animating=" + mAppAnimator.animating);
458
459 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM, "removeAppToken: "
460 + this + " delayed=" + delayed + " Callers=" + Debug.getCallers(4));
461
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800462 if (startingData != null && getController() != null) {
463 getController().removeStartingWindow();
464 }
465
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800466 final TaskStack stack = getTask().mStack;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700467 if (delayed && !isEmpty()) {
468 // set the token aside because it has an active animation to be finished
469 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM,
470 "removeAppToken make exiting: " + this);
471 stack.mExitingAppTokens.add(this);
472 mIsExiting = true;
473 } else {
474 // Make sure there is no animation running on this token, so any windows associated
475 // with it will be removed as soon as their animations are complete
476 mAppAnimator.clearAnimation();
477 mAppAnimator.animating = false;
478 removeIfPossible();
479 }
480
481 removed = true;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700482 stopFreezingScreen(true, true);
Bryce Lee6d410262017-02-28 15:30:17 -0800483
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700484 if (mService.mFocusedApp == this) {
485 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "Removing focused app token:" + this);
486 mService.mFocusedApp = null;
487 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
488 mService.mInputMonitor.setFocusedAppLw(null);
489 }
490
491 if (!delayed) {
492 updateReportedVisibilityLocked();
493 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700494 }
495
Chong Zhange05bcb12016-07-26 17:47:29 -0700496 void clearAnimatingFlags() {
Chong Zhangb0d26702016-08-12 16:03:29 -0700497 boolean wallpaperMightChange = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700498 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700499 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700500 wallpaperMightChange |= win.clearAnimatingFlags();
Chong Zhange05bcb12016-07-26 17:47:29 -0700501 }
Chong Zhangb0d26702016-08-12 16:03:29 -0700502 if (wallpaperMightChange) {
503 requestUpdateWallpaperIfNeeded();
504 }
Chong Zhange05bcb12016-07-26 17:47:29 -0700505 }
506
Robert Carre12aece2016-02-02 22:43:27 -0800507 void destroySurfaces() {
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700508 destroySurfaces(false /*cleanupOnResume*/);
509 }
510
511 /**
512 * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure
513 * the client has finished with them.
514 *
515 * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If
516 * set to true, destroy only surfaces of removed windows, and clear relevant flags of the
517 * others so that they are ready to be reused. If set to false (common case), destroy all
518 * surfaces that's eligible, if the app is already stopped.
519 */
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700520 private void destroySurfaces(boolean cleanupOnResume) {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700521 boolean destroyedSomething = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700522 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700523 final WindowState win = mChildren.get(i);
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700524 destroyedSomething |= win.destroySurface(cleanupOnResume, mAppStopped);
Robert Carre12aece2016-02-02 22:43:27 -0800525 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700526 if (destroyedSomething) {
527 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700528 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Robert Carre12aece2016-02-02 22:43:27 -0800529 }
530 }
531
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800532 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700533 * Notify that the app is now resumed, and it was not stopped before, perform a clean
534 * up of the surfaces
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800535 */
Chong Zhangad24f962016-08-25 12:12:33 -0700536 void notifyAppResumed(boolean wasStopped, boolean allowSavedSurface) {
537 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped
538 + " allowSavedSurface=" + allowSavedSurface + " " + this);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700539 mAppStopped = false;
540 if (!wasStopped) {
541 destroySurfaces(true /*cleanupOnResume*/);
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800542 }
Chong Zhangad24f962016-08-25 12:12:33 -0700543 if (!allowSavedSurface) {
544 destroySavedSurfaces();
545 }
Robert Carre12aece2016-02-02 22:43:27 -0800546 }
547
Chong Zhangbef461f2015-10-27 11:38:24 -0700548 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700549 * Notify that the app has stopped, and it is okay to destroy any surfaces which were
550 * keeping alive in case they were still being used.
551 */
552 void notifyAppStopped() {
553 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this);
554 mAppStopped = true;
555 destroySurfaces();
556 // Remove any starting window that was added for this app if they are still around.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800557 if (getController() != null) {
558 getController().removeStartingWindow();
559 }
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700560 }
561
562 /**
Chong Zhangbef461f2015-10-27 11:38:24 -0700563 * Checks whether we should save surfaces for this app.
564 *
565 * @return true if the surfaces should be saved, false otherwise.
566 */
567 boolean shouldSaveSurface() {
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800568 // We want to save surface if the app's windows are "allDrawn".
569 // (If we started entering animation early with saved surfaces, allDrawn
570 // should have been restored to true. So we'll save again in that case
571 // even if app didn't actually finish drawing.)
572 return allDrawn;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800573 }
574
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700575 private boolean canRestoreSurfaces() {
576 for (int i = mChildren.size() -1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700577 final WindowState w = mChildren.get(i);
Chong Zhang92147042016-05-09 12:47:11 -0700578 if (w.canRestoreSurface()) {
Robert Carr13f7be9e2015-12-02 18:39:45 -0800579 return true;
580 }
Chong Zhangbef461f2015-10-27 11:38:24 -0700581 }
582 return false;
583 }
584
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700585 private void clearWasVisibleBeforeClientHidden() {
586 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700587 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700588 w.clearWasVisibleBeforeClientHidden();
Chong Zhang92147042016-05-09 12:47:11 -0700589 }
590 }
591
Chong Zhang8e4bda92016-05-04 15:08:18 -0700592 /**
593 * Whether the app has some window that is invisible in layout, but
594 * animating with saved surface.
595 */
596 boolean isAnimatingInvisibleWithSavedSurface() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700597 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700598 final WindowState w = mChildren.get(i);
Chong Zhang8e4bda92016-05-04 15:08:18 -0700599 if (w.isAnimatingInvisibleWithSavedSurface()) {
600 return true;
601 }
602 }
603 return false;
604 }
605
606 /**
607 * Hide all window surfaces that's still invisible in layout but animating
608 * with a saved surface, and mark them destroying.
609 */
610 void stopUsingSavedSurfaceLocked() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700611 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700612 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700613 w.stopUsingSavedSurface();
Chong Zhang8e4bda92016-05-04 15:08:18 -0700614 }
615 destroySurfaces();
616 }
617
Chong Zhangf58631a2016-05-24 16:02:10 -0700618 void markSavedSurfaceExiting() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700619 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700620 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700621 w.markSavedSurfaceExiting();
Chong Zhangf58631a2016-05-24 16:02:10 -0700622 }
623 }
624
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700625 void restoreSavedSurfaceForInterestingWindows() {
Chong Zhang92147042016-05-09 12:47:11 -0700626 if (!canRestoreSurfaces()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700627 clearWasVisibleBeforeClientHidden();
Chong Zhangbef461f2015-10-27 11:38:24 -0700628 return;
629 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700630
631 // Check if all interesting windows are drawn and we can mark allDrawn=true.
632 int interestingNotDrawn = -1;
633
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700634 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700635 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700636 interestingNotDrawn = w.restoreSavedSurfaceForInterestingWindow();
Chong Zhangbef461f2015-10-27 11:38:24 -0700637 }
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800638
Chong Zhang92147042016-05-09 12:47:11 -0700639 if (!allDrawn) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700640 allDrawn = (interestingNotDrawn == 0);
Chong Zhang92147042016-05-09 12:47:11 -0700641 if (allDrawn) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700642 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Chong Zhang92147042016-05-09 12:47:11 -0700643 }
644 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700645 clearWasVisibleBeforeClientHidden();
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800646
647 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700648 "restoreSavedSurfaceForInterestingWindows: " + this + " allDrawn=" + allDrawn
649 + " interestingNotDrawn=" + interestingNotDrawn);
Chong Zhangbef461f2015-10-27 11:38:24 -0700650 }
651
652 void destroySavedSurfaces() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700653 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700654 final WindowState win = mChildren.get(i);
Robert Carr13f7be9e2015-12-02 18:39:45 -0800655 win.destroySavedSurface();
Chong Zhangbef461f2015-10-27 11:38:24 -0700656 }
Chong Zhang92147042016-05-09 12:47:11 -0700657 }
658
659 void clearAllDrawn() {
660 allDrawn = false;
661 deferClearAllDrawn = false;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700662 allDrawnExcludingSaved = false;
Chong Zhangbef461f2015-10-27 11:38:24 -0700663 }
664
Bryce Lee6d410262017-02-28 15:30:17 -0800665 Task getTask() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800666 return (Task) getParent();
Bryce Lee6d410262017-02-28 15:30:17 -0800667 }
668
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800669 TaskStack getStack() {
670 final Task task = getTask();
671 if (task != null) {
672 return task.mStack;
673 } else {
674 return null;
675 }
676 }
677
Bryce Lee6d410262017-02-28 15:30:17 -0800678 @Override
679 void onParentSet() {
680 super.onParentSet();
681
682 // When the associated task is {@code null}, the {@link AppWindowToken} can no longer
683 // access visual elements like the {@link DisplayContent}. We must remove any associations
684 // such as animations.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800685 if (!mReparenting) {
686 final Task task = getTask();
687 if (task == null) {
688 // It is possible we have been marked as a closing app earlier. We must remove ourselves
689 // from this list so we do not participate in any future animations.
690 mService.mClosingApps.remove(this);
691 } else if (task.mStack != null) {
692 task.mStack.mExitingAppTokens.remove(this);
693 }
Bryce Lee6d410262017-02-28 15:30:17 -0800694 }
695 }
696
Wale Ogunwalefa854eb2016-09-20 13:43:52 -0700697 void postWindowRemoveStartingWindowCleanup(WindowState win) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700698 // TODO: Something smells about the code below...Is there a better way?
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700699 if (startingWindow == win) {
700 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800701 if (getController() != null) {
702 getController().removeStartingWindow();
703 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700704 } else if (mChildren.size() == 0 && startingData != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700705 // If this is the last window and we had requested a starting transition window,
706 // well there is no point now.
Jorim Jaggi02886a82016-12-06 09:10:06 -0800707 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingData");
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700708 startingData = null;
Jorim Jaggi829b9cd2017-01-23 16:20:53 +0100709 } else if (mChildren.size() == 1 && startingSurface != null && !isRelaunching()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700710 // If this is the last window except for a starting transition window,
711 // we need to get rid of the starting transition.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800712 if (getController() != null) {
713 getController().removeStartingWindow();
714 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700715 }
716 }
717
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700718 void removeDeadWindows() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700719 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700720 WindowState win = mChildren.get(winNdx);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800721 if (win.mAppDied) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700722 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700723 "removeDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800724 // Set mDestroying, we don't want any animation or delayed removal here.
725 win.mDestroying = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700726 // Also removes child windows.
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700727 win.removeIfPossible();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800728 }
729 }
730 }
731
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700732 boolean hasWindowsAlive() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700733 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700734 // No need to loop through child windows as the answer should be the same as that of the
735 // parent window.
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700736 if (!(mChildren.get(i)).mAppDied) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700737 return true;
738 }
739 }
740 return false;
741 }
742
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700743 void setWillReplaceWindows(boolean animate) {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700744 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
745 "Marking app token " + this + " with replacing windows.");
Robert Carra1eb4392015-12-10 12:43:51 -0800746
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700747 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700748 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700749 w.setWillReplaceWindow(animate);
Robert Carra1eb4392015-12-10 12:43:51 -0800750 }
751 if (animate) {
752 // Set-up dummy animation so we can start treating windows associated with this
753 // token like they are in transition before the new app window is ready for us to
754 // run the real transition animation.
755 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700756 "setWillReplaceWindow() Setting dummy animation on: " + this);
Robert Carra1eb4392015-12-10 12:43:51 -0800757 mAppAnimator.setDummyAnimation();
758 }
759 }
760
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700761 void setWillReplaceChildWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700762 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this
Robert Carr23fa16b2016-01-13 13:19:58 -0800763 + " with replacing child windows.");
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700764 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700765 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700766 w.setWillReplaceChildWindows();
Robert Carr23fa16b2016-01-13 13:19:58 -0800767 }
768 }
769
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700770 void clearWillReplaceWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700771 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
772 "Resetting app token " + this + " of replacing window marks.");
Chong Zhangf596cd52016-01-05 13:42:44 -0800773
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700774 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700775 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700776 w.clearWillReplaceWindow();
Chong Zhangf596cd52016-01-05 13:42:44 -0800777 }
778 }
779
Chong Zhang4d7369a2016-04-25 16:09:14 -0700780 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700781 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700782 final WindowState w = mChildren.get(i);
Chong Zhang4d7369a2016-04-25 16:09:14 -0700783 w.requestUpdateWallpaperIfNeeded();
784 }
785 }
786
Chong Zhangd78ddb42016-03-02 17:01:14 -0800787 boolean isRelaunching() {
788 return mPendingRelaunchCount > 0;
789 }
790
791 void startRelaunching() {
792 if (canFreezeBounds()) {
793 freezeBounds();
794 }
Robert Carrd5c7dd62017-03-08 10:39:30 -0800795
796 // In the process of tearing down before relaunching, the app will
797 // try and clean up it's child surfaces. We need to prevent this from
798 // happening, so we sever the children, transfering their ownership
799 // from the client it-self to the parent surface (owned by us).
800 for (int i = mChildren.size() - 1; i >= 0; i--) {
801 final WindowState w = mChildren.get(i);
802 w.mWinAnimator.detachChildren();
803 }
804
Chong Zhangd78ddb42016-03-02 17:01:14 -0800805 mPendingRelaunchCount++;
806 }
807
808 void finishRelaunching() {
809 if (canFreezeBounds()) {
810 unfreezeBounds();
811 }
812 if (mPendingRelaunchCount > 0) {
813 mPendingRelaunchCount--;
814 }
815 }
816
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700817 void clearRelaunching() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700818 if (mPendingRelaunchCount == 0) {
819 return;
820 }
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700821 if (canFreezeBounds()) {
822 unfreezeBounds();
823 }
824 mPendingRelaunchCount = 0;
825 }
826
Wale Ogunwale07bcab72016-10-14 15:30:09 -0700827 /**
828 * Returns true if the new child window we are adding to this token is considered greater than
829 * the existing child window in this token in terms of z-order.
830 */
831 @Override
832 protected boolean isFirstChildWindowGreaterThanSecond(WindowState newWindow,
833 WindowState existingWindow) {
834 final int type1 = newWindow.mAttrs.type;
835 final int type2 = existingWindow.mAttrs.type;
836
837 // Base application windows should be z-ordered BELOW all other windows in the app token.
838 if (type1 == TYPE_BASE_APPLICATION && type2 != TYPE_BASE_APPLICATION) {
839 return false;
840 } else if (type1 != TYPE_BASE_APPLICATION && type2 == TYPE_BASE_APPLICATION) {
841 return true;
842 }
843
844 // Starting windows should be z-ordered ABOVE all other windows in the app token.
845 if (type1 == TYPE_APPLICATION_STARTING && type2 != TYPE_APPLICATION_STARTING) {
846 return true;
847 } else if (type1 != TYPE_APPLICATION_STARTING && type2 == TYPE_APPLICATION_STARTING) {
848 return false;
849 }
850
851 // Otherwise the new window is greater than the existing window.
852 return true;
853 }
854
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700855 @Override
Robert Carra1eb4392015-12-10 12:43:51 -0800856 void addWindow(WindowState w) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700857 super.addWindow(w);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700858
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700859 boolean gotReplacementWindow = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700860 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700861 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700862 gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w);
863 }
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700864
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700865 // if we got a replacement window, reset the timeout to give drawing more time
866 if (gotReplacementWindow) {
867 mService.scheduleWindowReplacementTimeouts(this);
Robert Carra1eb4392015-12-10 12:43:51 -0800868 }
Jorim Jaggife762342016-10-13 14:33:27 +0200869 checkKeyguardFlagsChanged();
870 }
871
872 @Override
873 void removeChild(WindowState child) {
874 super.removeChild(child);
875 checkKeyguardFlagsChanged();
Robert Carra1eb4392015-12-10 12:43:51 -0800876 }
877
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700878 private boolean waitingForReplacement() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700879 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700880 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700881 if (candidate.waitingForReplacement()) {
Robert Carra1eb4392015-12-10 12:43:51 -0800882 return true;
883 }
884 }
885 return false;
886 }
887
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700888 void onWindowReplacementTimeout() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700889 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700890 (mChildren.get(i)).onWindowReplacementTimeout();
Robert Carra1eb4392015-12-10 12:43:51 -0800891 }
892 }
893
Winson Chung30480042017-01-26 10:55:34 -0800894 void reparent(Task task, int position) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800895 final Task currentTask = getTask();
896 if (task == currentTask) {
Winson Chung30480042017-01-26 10:55:34 -0800897 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800898 "window token=" + this + " already child of task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -0800899 }
Bryce Lee6d410262017-02-28 15:30:17 -0800900
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800901 if (currentTask.mStack != task.mStack) {
Bryce Lee6d410262017-02-28 15:30:17 -0800902 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800903 "window token=" + this + " current task=" + currentTask
Bryce Lee6d410262017-02-28 15:30:17 -0800904 + " belongs to a different stack than " + task);
905 }
906
Winson Chung30480042017-01-26 10:55:34 -0800907 if (DEBUG_ADD_REMOVE) Slog.i(TAG, "reParentWindowToken: removing window token=" + this
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800908 + " from task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -0800909 final DisplayContent prevDisplayContent = getDisplayContent();
910
Bryce Lee6d410262017-02-28 15:30:17 -0800911 mReparenting = true;
912
Winson Chung30480042017-01-26 10:55:34 -0800913 getParent().removeChild(this);
914 task.addChild(this, position);
915
Bryce Lee6d410262017-02-28 15:30:17 -0800916 mReparenting = false;
917
Winson Chung30480042017-01-26 10:55:34 -0800918 // Relayout display(s).
919 final DisplayContent displayContent = task.getDisplayContent();
920 displayContent.setLayoutNeeded();
921 if (prevDisplayContent != displayContent) {
922 onDisplayChanged(displayContent);
923 prevDisplayContent.setLayoutNeeded();
924 }
925 }
926
Chong Zhangd78ddb42016-03-02 17:01:14 -0800927 private boolean canFreezeBounds() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800928 final Task task = getTask();
929
Chong Zhangd78ddb42016-03-02 17:01:14 -0800930 // For freeform windows, we can't freeze the bounds at the moment because this would make
931 // the resizing unresponsive.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800932 return task != null && !task.inFreeformWorkspace();
Chong Zhangd78ddb42016-03-02 17:01:14 -0800933 }
934
Jorim Jaggi0429f352015-12-22 16:29:16 +0100935 /**
936 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
937 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
938 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
939 * with a queue.
940 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800941 private void freezeBounds() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800942 final Task task = getTask();
943 mFrozenBounds.offer(new Rect(task.mPreparedFrozenBounds));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700944
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800945 if (task.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) {
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700946 // We didn't call prepareFreezingBounds on the task, so use the current value.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800947 mFrozenMergedConfig.offer(new Configuration(task.getConfiguration()));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700948 } else {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800949 mFrozenMergedConfig.offer(new Configuration(task.mPreparedFrozenMergedConfig));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700950 }
Andrii Kulianb10330d2016-09-16 13:51:46 -0700951 // Calling unset() to make it equal to Configuration.EMPTY.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800952 task.mPreparedFrozenMergedConfig.unset();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100953 }
954
955 /**
956 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
957 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800958 private void unfreezeBounds() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700959 if (!mFrozenBounds.isEmpty()) {
960 mFrozenBounds.remove();
961 }
962 if (!mFrozenMergedConfig.isEmpty()) {
963 mFrozenMergedConfig.remove();
964 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700965 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700966 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700967 win.onUnfreezeBounds();
Jorim Jaggi4846ee32016-01-07 17:39:12 +0100968 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700969 mService.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100970 }
971
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700972 void resetJustMovedInStack() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700973 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700974 (mChildren.get(i)).resetJustMovedInStack();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700975 }
976 }
977
978 void notifyMovedInStack() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700979 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700980 final WindowState win = mChildren.get(winNdx);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700981 win.notifyMovedInStack();
982 }
983 }
984
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700985 void setAppLayoutChanges(int changes, String reason) {
986 if (!mChildren.isEmpty()) {
987 final DisplayContent dc = getDisplayContent();
988 dc.pendingLayoutChanges |= changes;
989 if (DEBUG_LAYOUT_REPEATS) {
990 mService.mWindowPlacerLocked.debugLayoutRepeats(reason, dc.pendingLayoutChanges);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700991 }
992 }
993 }
994
995 void removeReplacedWindowIfNeeded(WindowState replacement) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700996 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700997 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700998 if (win.removeReplacedWindowIfNeeded(replacement)) {
999 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001000 }
1001 }
1002 }
1003
1004 void startFreezingScreen() {
1005 if (DEBUG_ORIENTATION) logWithStack(TAG, "Set freezing of " + appToken + ": hidden="
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001006 + hidden + " freezing=" + mAppAnimator.freezingScreen + " hiddenRequested="
1007 + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001008 if (!hiddenRequested) {
1009 if (!mAppAnimator.freezingScreen) {
1010 mAppAnimator.freezingScreen = true;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001011 mService.registerAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001012 mAppAnimator.lastFreezeDuration = 0;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001013 mService.mAppsFreezingScreen++;
1014 if (mService.mAppsFreezingScreen == 1) {
1015 mService.startFreezingDisplayLocked(false, 0, 0);
1016 mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT);
1017 mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001018 }
1019 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001020 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001021 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001022 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001023 w.onStartFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001024 }
1025 }
1026 }
1027
1028 void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) {
1029 if (!mAppAnimator.freezingScreen) {
1030 return;
1031 }
1032 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + this + " force=" + force);
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001033 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001034 boolean unfrozeWindows = false;
1035 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001036 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001037 unfrozeWindows |= w.onStopFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001038 }
1039 if (force || unfrozeWindows) {
1040 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this);
1041 mAppAnimator.freezingScreen = false;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001042 mService.unregisterAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001043 mAppAnimator.lastFreezeDuration =
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001044 (int)(SystemClock.elapsedRealtime() - mService.mDisplayFreezeTime);
1045 mService.mAppsFreezingScreen--;
1046 mService.mLastFinishedFreezeSource = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001047 }
1048 if (unfreezeSurfaceNow) {
1049 if (unfrozeWindows) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001050 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001051 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001052 mService.stopFreezingDisplayLocked();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001053 }
1054 }
1055
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001056 @Override
1057 public void onAppFreezeTimeout() {
1058 Slog.w(TAG_WM, "Force clearing freeze: " + this);
1059 stopFreezingScreen(true, true);
1060 }
1061
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001062 boolean transferStartingWindow(IBinder transferFrom) {
Wale Ogunwale02319a62016-09-26 15:21:22 -07001063 final AppWindowToken fromToken = getDisplayContent().getAppWindowToken(transferFrom);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001064 if (fromToken == null) {
1065 return false;
1066 }
1067
1068 final WindowState tStartingWindow = fromToken.startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001069 if (tStartingWindow != null && fromToken.startingSurface != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001070 // In this case, the starting icon has already been displayed, so start
1071 // letting windows get shown immediately without any more transitions.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001072 mService.mSkipAppTransitionAnimation = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001073
1074 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow
1075 + " from " + fromToken + " to " + this);
1076
1077 final long origId = Binder.clearCallingIdentity();
1078
1079 // Transfer the starting window over to the new token.
1080 startingData = fromToken.startingData;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001081 startingSurface = fromToken.startingSurface;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001082 startingDisplayed = fromToken.startingDisplayed;
1083 fromToken.startingDisplayed = false;
1084 startingWindow = tStartingWindow;
1085 reportedVisible = fromToken.reportedVisible;
1086 fromToken.startingData = null;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001087 fromToken.startingSurface = null;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001088 fromToken.startingWindow = null;
1089 fromToken.startingMoved = true;
1090 tStartingWindow.mToken = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001091 tStartingWindow.mAppToken = this;
1092
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001093 if (DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001094 "Removing starting " + tStartingWindow + " from " + fromToken);
Wale Ogunwalefa854eb2016-09-20 13:43:52 -07001095 fromToken.removeChild(tStartingWindow);
1096 fromToken.postWindowRemoveStartingWindowCleanup(tStartingWindow);
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001097 addWindow(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001098
1099 // Propagate other interesting state between the tokens. If the old token is displayed,
1100 // we should immediately force the new one to be displayed. If it is animating, we need
1101 // to move that animation to the new one.
1102 if (fromToken.allDrawn) {
1103 allDrawn = true;
1104 deferClearAllDrawn = fromToken.deferClearAllDrawn;
1105 }
1106 if (fromToken.firstWindowDrawn) {
1107 firstWindowDrawn = true;
1108 }
1109 if (!fromToken.hidden) {
1110 hidden = false;
1111 hiddenRequested = false;
1112 }
1113 if (clientHidden != fromToken.clientHidden) {
1114 clientHidden = fromToken.clientHidden;
1115 sendAppVisibilityToClients();
1116 }
1117 fromToken.mAppAnimator.transferCurrentAnimation(
1118 mAppAnimator, tStartingWindow.mWinAnimator);
1119
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001120 mService.updateFocusedWindowLocked(
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001121 UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/);
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001122 getDisplayContent().setLayoutNeeded();
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001123 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001124 Binder.restoreCallingIdentity(origId);
1125 return true;
1126 } else if (fromToken.startingData != null) {
1127 // The previous app was getting ready to show a
1128 // starting window, but hasn't yet done so. Steal it!
1129 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1130 "Moving pending starting from " + fromToken + " to " + this);
1131 startingData = fromToken.startingData;
1132 fromToken.startingData = null;
1133 fromToken.startingMoved = true;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001134 if (getController() != null) {
1135 getController().scheduleAddStartingWindow();
1136 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001137 return true;
1138 }
1139
1140 final AppWindowAnimator tAppAnimator = fromToken.mAppAnimator;
1141 final AppWindowAnimator wAppAnimator = mAppAnimator;
1142 if (tAppAnimator.thumbnail != null) {
1143 // The old token is animating with a thumbnail, transfer that to the new token.
1144 if (wAppAnimator.thumbnail != null) {
1145 wAppAnimator.thumbnail.destroy();
1146 }
1147 wAppAnimator.thumbnail = tAppAnimator.thumbnail;
1148 wAppAnimator.thumbnailLayer = tAppAnimator.thumbnailLayer;
1149 wAppAnimator.thumbnailAnimation = tAppAnimator.thumbnailAnimation;
1150 tAppAnimator.thumbnail = null;
1151 }
1152 return false;
1153 }
1154
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001155 boolean isLastWindow(WindowState win) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001156 return mChildren.size() == 1 && mChildren.get(0) == win;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001157 }
1158
1159 void setAllAppWinAnimators() {
1160 final ArrayList<WindowStateAnimator> allAppWinAnimators = mAppAnimator.mAllAppWinAnimators;
1161 allAppWinAnimators.clear();
1162
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001163 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001164 for (int j = 0; j < windowsCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001165 (mChildren.get(j)).addWinAnimatorToList(allAppWinAnimators);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001166 }
1167 }
1168
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001169 @Override
1170 void onAppTransitionDone() {
1171 sendingToBottom = false;
1172 }
1173
Wale Ogunwale51362492016-09-08 17:49:17 -07001174 /**
1175 * We override because this class doesn't want its children affecting its reported orientation
1176 * in anyway.
1177 */
1178 @Override
1179 int getOrientation() {
Bryce Leea163b762017-01-24 11:05:01 -08001180 if (fillsParent() && (isVisible() || mService.mOpeningApps.contains(this))) {
1181 return mOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001182 }
Bryce Leea163b762017-01-24 11:05:01 -08001183
1184 return SCREEN_ORIENTATION_UNSET;
Wale Ogunwale51362492016-09-08 17:49:17 -07001185 }
1186
Wale Ogunwaleb198b742016-12-01 08:44:09 -08001187 /** Returns the app's preferred orientation regardless of its currently visibility state. */
1188 int getOrientationIgnoreVisibility() {
1189 return mOrientation;
1190 }
1191
Craig Mautnerdbb79912012-03-01 18:59:14 -08001192 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001193 void checkAppWindowsReadyToShow() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001194 if (allDrawn == mAppAnimator.allDrawn) {
1195 return;
1196 }
1197
1198 mAppAnimator.allDrawn = allDrawn;
1199 if (!allDrawn) {
1200 return;
1201 }
1202
1203 // The token has now changed state to having all windows shown... what to do, what to do?
1204 if (mAppAnimator.freezingScreen) {
1205 mAppAnimator.showAllWindowsLocked();
1206 stopFreezingScreen(false, true);
1207 if (DEBUG_ORIENTATION) Slog.i(TAG,
1208 "Setting mOrientationChangeComplete=true because wtoken " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001209 + " numInteresting=" + mNumInterestingWindows + " numDrawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001210 // This will set mOrientationChangeComplete and cause a pass through layout.
1211 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001212 "checkAppWindowsReadyToShow: freezingScreen");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001213 } else {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001214 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001215
1216 // We can now show all of the drawn windows!
1217 if (!mService.mOpeningApps.contains(this)) {
1218 mService.mAnimator.orAnimating(mAppAnimator.showAllWindowsLocked());
1219 }
1220 }
1221 }
1222
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001223 void updateAllDrawn(DisplayContent dc) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001224 if (!allDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001225 final int numInteresting = mNumInterestingWindows;
1226 if (numInteresting > 0 && mNumDrawnWindows >= numInteresting) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001227 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawn: " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001228 + " interesting=" + numInteresting + " drawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001229 allDrawn = true;
1230 // Force an additional layout pass where
1231 // WindowStateAnimator#commitFinishDrawingLocked() will call performShowLocked().
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001232 dc.setLayoutNeeded();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001233 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
1234 }
1235 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001236
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001237 if (!allDrawnExcludingSaved) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001238 int numInteresting = mNumInterestingWindowsExcludingSaved;
1239 if (numInteresting > 0 && mNumDrawnWindowsExcludingSaved >= numInteresting) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001240 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawnExcludingSaved: " + this
1241 + " interesting=" + numInteresting
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001242 + " drawn=" + mNumDrawnWindowsExcludingSaved);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001243 allDrawnExcludingSaved = true;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001244 dc.setLayoutNeeded();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001245 if (isAnimatingInvisibleWithSavedSurface()
1246 && !mService.mFinishedEarlyAnim.contains(this)) {
1247 mService.mFinishedEarlyAnim.add(this);
1248 }
1249 }
1250 }
1251 }
1252
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001253 /**
1254 * Updated this app token tracking states for interesting and drawn windows based on the window.
1255 *
1256 * @return Returns true if the input window is considered interesting and drawn while all the
1257 * windows in this app token where not considered drawn as of the last pass.
1258 */
1259 boolean updateDrawnWindowStates(WindowState w) {
1260 if (DEBUG_STARTING_WINDOW && w == startingWindow) {
1261 Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" + w.isOnScreen()
1262 + " allDrawn=" + allDrawn + " freezingScreen=" + mAppAnimator.freezingScreen);
1263 }
1264
1265 if (allDrawn && allDrawnExcludingSaved && !mAppAnimator.freezingScreen) {
1266 return false;
1267 }
1268
1269 if (mLastTransactionSequence != mService.mTransactionSequence) {
1270 mLastTransactionSequence = mService.mTransactionSequence;
1271 mNumInterestingWindows = mNumDrawnWindows = 0;
1272 mNumInterestingWindowsExcludingSaved = 0;
1273 mNumDrawnWindowsExcludingSaved = 0;
1274 startingDisplayed = false;
1275 }
1276
1277 final WindowStateAnimator winAnimator = w.mWinAnimator;
1278
1279 boolean isInterestingAndDrawn = false;
1280
1281 if (!allDrawn && w.mightAffectAllDrawn(false /* visibleOnly */)) {
1282 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
1283 Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw()
1284 + ", isAnimationSet=" + winAnimator.isAnimationSet());
1285 if (!w.isDrawnLw()) {
1286 Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController
1287 + " pv=" + w.mPolicyVisibility
1288 + " mDrawState=" + winAnimator.drawStateToString()
1289 + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested
1290 + " a=" + winAnimator.mAnimating);
1291 }
1292 }
1293
1294 if (w != startingWindow) {
1295 if (w.isInteresting()) {
1296 mNumInterestingWindows++;
1297 if (w.isDrawnLw()) {
1298 mNumDrawnWindows++;
1299
1300 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, "tokenMayBeDrawn: "
1301 + this + " w=" + w + " numInteresting=" + mNumInterestingWindows
1302 + " freezingScreen=" + mAppAnimator.freezingScreen
1303 + " mAppFreezing=" + w.mAppFreezing);
1304
1305 isInterestingAndDrawn = true;
1306 }
1307 }
1308 } else if (w.isDrawnLw()) {
Jorim Jaggi3878ca32017-02-02 17:13:05 -08001309 if (getController() != null) {
1310 getController().reportStartingWindowDrawn();
1311 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001312 startingDisplayed = true;
1313 }
1314 }
1315
1316 if (!allDrawnExcludingSaved && w.mightAffectAllDrawn(true /* visibleOnly */)) {
1317 if (w != startingWindow && w.isInteresting()) {
1318 mNumInterestingWindowsExcludingSaved++;
1319 if (w.isDrawnLw() && !w.isAnimatingWithSavedSurface()) {
1320 mNumDrawnWindowsExcludingSaved++;
1321
1322 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
1323 "tokenMayBeDrawnExcludingSaved: " + this + " w=" + w
1324 + " numInteresting=" + mNumInterestingWindowsExcludingSaved
1325 + " freezingScreen=" + mAppAnimator.freezingScreen
1326 + " mAppFreezing=" + w.mAppFreezing);
1327
1328 isInterestingAndDrawn = true;
1329 }
1330 }
1331 }
1332
1333 return isInterestingAndDrawn;
1334 }
1335
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001336 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001337 void stepAppWindowsAnimation(long currentTime) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001338 mAppAnimator.wasAnimating = mAppAnimator.animating;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001339 if (mAppAnimator.stepAnimationLocked(currentTime)) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001340 mAppAnimator.animating = true;
1341 mService.mAnimator.setAnimating(true);
1342 mService.mAnimator.mAppWindowAnimating = true;
1343 } else if (mAppAnimator.wasAnimating) {
1344 // stopped animating, do one more pass through the layout
Wale Ogunwale1e129a42016-11-21 13:03:47 -08001345 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
1346 DEBUG_LAYOUT_REPEATS ? "appToken " + this + " done" : null);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001347 if (DEBUG_ANIM) Slog.v(TAG, "updateWindowsApps...: done animating " + this);
1348 }
1349 }
1350
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001351 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001352 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001353 // For legacy reasons we process the TaskStack.mExitingAppTokens first in DisplayContent
1354 // before the non-exiting app tokens. So, we skip the exiting app tokens here.
1355 // TODO: Investigate if we need to continue to do this or if we can just process them
1356 // in-order.
1357 if (mIsExiting && !waitingForReplacement()) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001358 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001359 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001360 return forAllWindowsUnchecked(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001361 }
1362
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001363 boolean forAllWindowsUnchecked(ToBooleanFunction<WindowState> callback,
1364 boolean traverseTopToBottom) {
1365 return super.forAllWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001366 }
1367
1368 @Override
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001369 AppWindowToken asAppWindowToken() {
1370 // I am an app window token!
1371 return this;
1372 }
1373
1374 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -07001375 boolean fillsParent() {
1376 return mFillsParent;
1377 }
1378
1379 void setFillsParent(boolean fillsParent) {
1380 mFillsParent = fillsParent;
1381 }
1382
Jorim Jaggife762342016-10-13 14:33:27 +02001383 boolean containsDismissKeyguardWindow() {
1384 for (int i = mChildren.size() - 1; i >= 0; i--) {
1385 if ((mChildren.get(i).mAttrs.flags & FLAG_DISMISS_KEYGUARD) != 0) {
1386 return true;
1387 }
1388 }
1389 return false;
1390 }
1391
1392 boolean containsShowWhenLockedWindow() {
1393 for (int i = mChildren.size() - 1; i >= 0; i--) {
1394 if ((mChildren.get(i).mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
1395 return true;
1396 }
1397 }
1398 return false;
1399 }
1400
1401 void checkKeyguardFlagsChanged() {
1402 final boolean containsDismissKeyguard = containsDismissKeyguardWindow();
1403 final boolean containsShowWhenLocked = containsShowWhenLockedWindow();
1404 if (containsDismissKeyguard != mLastContainsDismissKeyguardWindow
1405 || containsShowWhenLocked != mLastContainsShowWhenLockedWindow) {
1406 mService.notifyKeyguardFlagsChanged(null /* callback */);
1407 }
1408 mLastContainsDismissKeyguardWindow = containsDismissKeyguard;
1409 mLastContainsShowWhenLockedWindow = containsShowWhenLocked;
1410 }
1411
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001412 WindowState getImeTargetBelowWindow(WindowState w) {
1413 final int index = mChildren.indexOf(w);
1414 if (index > 0) {
1415 final WindowState target = mChildren.get(index - 1);
1416 if (target.canBeImeTarget()) {
1417 return target;
1418 }
1419 }
1420 return null;
1421 }
1422
1423 WindowState getHighestAnimLayerWindow(WindowState currentTarget) {
1424 WindowState candidate = null;
1425 for (int i = mChildren.indexOf(currentTarget); i >= 0; i--) {
1426 final WindowState w = mChildren.get(i);
1427 if (w.mRemoved) {
1428 continue;
1429 }
1430 if (candidate == null || w.mWinAnimator.mAnimLayer >
1431 candidate.mWinAnimator.mAnimLayer) {
1432 candidate = w;
1433 }
1434 }
1435 return candidate;
1436 }
1437
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001438 void setDisablePreviewSnapshots(boolean disable) {
1439 mDisbalePreviewScreenshots = disable;
1440 }
1441
1442 boolean shouldDisablePreviewScreenshots() {
1443 return mDisbalePreviewScreenshots;
1444 }
1445
Wale Ogunwale51362492016-09-08 17:49:17 -07001446 @Override
Robert Carrdee1b3f2017-02-27 11:33:33 -08001447 int getAnimLayerAdjustment() {
1448 return mAppAnimator.animLayerAdjustment;
1449 }
1450
1451 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001452 void dump(PrintWriter pw, String prefix) {
1453 super.dump(pw, prefix);
1454 if (appToken != null) {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001455 pw.println(prefix + "app=true mVoiceInteraction=" + mVoiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001456 }
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001457 pw.print(prefix); pw.print("task="); pw.println(getTask());
Wale Ogunwale51362492016-09-08 17:49:17 -07001458 pw.print(prefix); pw.print(" mFillsParent="); pw.print(mFillsParent);
1459 pw.print(" mOrientation="); pw.println(mOrientation);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001460 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
1461 pw.print(" clientHidden="); pw.print(clientHidden);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -07001462 pw.print(" reportedDrawn="); pw.print(reportedDrawn);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001463 pw.print(" reportedVisible="); pw.println(reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -07001464 if (paused) {
1465 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001466 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001467 if (mAppStopped) {
1468 pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped);
1469 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001470 if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0
Craig Mautner6fbda632012-07-03 09:26:39 -07001471 || allDrawn || mAppAnimator.allDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001472 pw.print(prefix); pw.print("mNumInterestingWindows=");
1473 pw.print(mNumInterestingWindows);
1474 pw.print(" mNumDrawnWindows="); pw.print(mNumDrawnWindows);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001475 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -07001476 pw.print(" allDrawn="); pw.print(allDrawn);
1477 pw.print(" (animator="); pw.print(mAppAnimator.allDrawn);
1478 pw.println(")");
1479 }
1480 if (inPendingTransaction) {
1481 pw.print(prefix); pw.print("inPendingTransaction=");
1482 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001483 }
Craig Mautner799bc1d2015-01-14 10:33:48 -08001484 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001485 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
1486 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -08001487 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -08001488 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001489 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001490 if (startingWindow != null || startingSurface != null
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001491 || startingDisplayed || startingMoved) {
1492 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001493 pw.print(" startingSurface="); pw.print(startingSurface);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001494 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001495 pw.print(" startingMoved="); pw.println(startingMoved);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001496 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01001497 if (!mFrozenBounds.isEmpty()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -08001498 pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds);
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001499 pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig);
Chong Zhangd78ddb42016-03-02 17:01:14 -08001500 }
1501 if (mPendingRelaunchCount != 0) {
1502 pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount);
Jorim Jaggi0429f352015-12-22 16:29:16 +01001503 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001504 }
1505
1506 @Override
1507 public String toString() {
1508 if (stringName == null) {
1509 StringBuilder sb = new StringBuilder();
1510 sb.append("AppWindowToken{");
1511 sb.append(Integer.toHexString(System.identityHashCode(this)));
1512 sb.append(" token="); sb.append(token); sb.append('}');
1513 stringName = sb.toString();
1514 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001515 return stringName + ((mIsExiting) ? " mIsExiting=" : "");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001516 }
Jeff Browne9bdb312012-04-05 15:30:10 -07001517}