blob: c20ee973bac5e387907f343afcea36142f92a681 [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
Wale Ogunwale72919d22016-12-08 18:58:50 -0800169 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
170 DisplayContent dc, long inputDispatchingTimeoutNanos, boolean fullscreen,
171 boolean showForAllUsers, int targetSdk, int orientation, int rotationAnimationHint,
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800172 int configChanges, boolean launchTaskBehind, boolean alwaysFocusable,
173 AppWindowContainerController controller) {
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800174 this(service, token, voiceInteraction, dc, fullscreen);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800175 setController(controller);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800176 mInputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800177 mShowForAllUsers = showForAllUsers;
178 mTargetSdk = targetSdk;
179 mOrientation = orientation;
180 layoutConfigChanges = (configChanges & (CONFIG_SCREEN_SIZE | CONFIG_ORIENTATION)) != 0;
181 mLaunchTaskBehind = launchTaskBehind;
182 mAlwaysFocusable = alwaysFocusable;
183 mRotationAnimationHint = rotationAnimationHint;
184
185 // Application tokens start out hidden.
186 hidden = true;
187 hiddenRequested = true;
188 }
189
190 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800191 DisplayContent dc, boolean fillsParent) {
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800192 super(service, token != null ? token.asBinder() : null, TYPE_APPLICATION, true, dc,
193 false /* ownerCanManageAppTokens */);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700194 appToken = token;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800195 mVoiceInteraction = voiceInteraction;
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800196 mFillsParent = fillsParent;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800197 mInputApplicationHandle = new InputApplicationHandle(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700198 mAppAnimator = new AppWindowAnimator(this, service);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800199 }
200
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800201 void onFirstWindowDrawn(WindowState win, WindowStateAnimator winAnimator) {
202 firstWindowDrawn = true;
203
204 // We now have a good window to show, remove dead placeholders
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700205 removeDeadWindows();
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800206
Jorim Jaggi02886a82016-12-06 09:10:06 -0800207 if (startingWindow != null) {
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800208 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, "Finish starting "
209 + win.mToken + ": first real window is shown, no animation");
210 // If this initial window is animating, stop it -- we will do an animation to reveal
211 // it from behind the starting window, so there is no need for it to also be doing its
212 // own stuff.
213 winAnimator.clearAnimation();
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800214 if (getController() != null) {
215 getController().removeStartingWindow();
216 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800217 }
218 updateReportedVisibilityLocked();
219 }
220
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800221 void updateReportedVisibilityLocked() {
222 if (appToken == null) {
223 return;
224 }
225
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700226 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700227 final int count = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800228
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700229 mReportedVisibilityResults.reset();
230
231 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700232 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700233 win.updateReportedVisibility(mReportedVisibilityResults);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800234 }
235
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700236 int numInteresting = mReportedVisibilityResults.numInteresting;
237 int numVisible = mReportedVisibilityResults.numVisible;
238 int numDrawn = mReportedVisibilityResults.numDrawn;
239 boolean nowGone = mReportedVisibilityResults.nowGone;
240
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700241 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800242 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700243 if (!nowGone) {
244 // If the app is not yet gone, then it can only become visible/drawn.
245 if (!nowDrawn) {
246 nowDrawn = reportedDrawn;
247 }
248 if (!nowVisible) {
249 nowVisible = reportedVisible;
250 }
251 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800252 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800253 + numInteresting + " visible=" + numVisible);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800254 final AppWindowContainerController controller = getController();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700255 if (nowDrawn != reportedDrawn) {
256 if (nowDrawn) {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800257 if (controller != null) {
258 controller.reportWindowsDrawn();
259 }
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700260 }
261 reportedDrawn = nowDrawn;
262 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800263 if (nowVisible != reportedVisible) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700264 if (DEBUG_VISIBILITY) Slog.v(TAG,
265 "Visibility changed in " + this + ": vis=" + nowVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800266 reportedVisible = nowVisible;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800267 if (controller != null) {
268 if (nowVisible) {
269 controller.reportWindowsVisible();
270 } else {
271 controller.reportWindowsGone();
272 }
273 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800274 }
275 }
276
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700277 boolean setVisibility(WindowManager.LayoutParams lp,
278 boolean visible, int transit, boolean performLayout, boolean isVoiceInteraction) {
279
280 boolean delayed = false;
281 inPendingTransaction = false;
282
283 if (clientHidden == visible) {
284 clientHidden = !visible;
285 sendAppVisibilityToClients();
286 }
287
288 // Allow for state changes and animation to be applied if:
289 // * token is transitioning visibility state
290 // * or the token was marked as hidden and is exiting before we had a chance to play the
291 // transition animation
292 // * or this is an opening app and windows are being replaced.
293 boolean visibilityChanged = false;
294 if (hidden == visible || (hidden && mIsExiting) || (visible && waitingForReplacement())) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700295 final AccessibilityController accessibilityController = mService.mAccessibilityController;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700296 boolean changed = false;
297 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
298 "Changing app " + this + " hidden=" + hidden + " performLayout=" + performLayout);
299
300 boolean runningAppAnimation = false;
301
302 if (transit != AppTransition.TRANSIT_UNSET) {
303 if (mAppAnimator.animation == AppWindowAnimator.sDummyAnimation) {
304 mAppAnimator.setNullAnimation();
305 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700306 if (mService.applyAnimationLocked(this, lp, transit, visible, isVoiceInteraction)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700307 delayed = runningAppAnimation = true;
308 }
309 final WindowState window = findMainWindow();
310 //TODO (multidisplay): Magnification is supported only for the default display.
311 if (window != null && accessibilityController != null
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700312 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700313 accessibilityController.onAppWindowTransitionLocked(window, transit);
314 }
315 changed = true;
316 }
317
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700318 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700319 for (int i = 0; i < windowsCount; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700320 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700321 changed |= win.onAppVisibilityChanged(visible, runningAppAnimation);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700322 }
323
324 hidden = hiddenRequested = !visible;
325 visibilityChanged = true;
326 if (!visible) {
327 stopFreezingScreen(true, true);
328 } else {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700329 // If we are being set visible, and the starting window is not yet displayed,
330 // then make sure it doesn't get displayed.
331 if (startingWindow != null && !startingWindow.isDrawnLw()) {
332 startingWindow.mPolicyVisibility = false;
333 startingWindow.mPolicyVisibilityAfterAnim = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700334 }
335 }
336
337 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setVisibility: " + this
338 + ": hidden=" + hidden + " hiddenRequested=" + hiddenRequested);
339
340 if (changed) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700341 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700342 if (performLayout) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700343 mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700344 false /*updateInputWindows*/);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700345 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700346 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700347 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700348 }
349 }
350
351 if (mAppAnimator.animation != null) {
352 delayed = true;
353 }
354
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700355 for (int i = mChildren.size() - 1; i >= 0 && !delayed; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700356 if ((mChildren.get(i)).isWindowAnimationSet()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700357 delayed = true;
358 }
359 }
360
361 if (visibilityChanged) {
362 if (visible && !delayed) {
363 // The token was made immediately visible, there will be no entrance animation.
364 // We need to inform the client the enter animation was finished.
365 mEnteringAnimation = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700366 mService.mActivityManagerAppTransitionNotifier.onAppTransitionFinishedLocked(token);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700367 }
368
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700369 if (!mService.mClosingApps.contains(this) && !mService.mOpeningApps.contains(this)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700370 // The token is not closing nor opening, so even if there is an animation set, that
371 // doesn't mean that it goes through the normal app transition cycle so we have
372 // to inform the docked controller about visibility change.
Andrii Kulian1e32e022016-09-16 15:29:34 -0700373 // TODO(multi-display): notify docked divider on all displays where visibility was
374 // affected.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700375 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700376 .notifyAppVisibilityChanged();
Jorim Jaggi8b702ed2017-01-20 16:59:03 +0100377 mService.mTaskSnapshotController.notifyAppVisibilityChanged(this, visible);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700378 }
379 }
380
381 return delayed;
382 }
383
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800384 WindowState findMainWindow() {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700385 WindowState candidate = null;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700386 int j = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800387 while (j > 0) {
388 j--;
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700389 final WindowState win = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700390 final int type = win.mAttrs.type;
391 // No need to loop through child window as base application and starting types can't be
392 // child windows.
393 if (type == TYPE_BASE_APPLICATION || type == TYPE_APPLICATION_STARTING) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700394 // In cases where there are multiple windows, we prefer the non-exiting window. This
Sungsoo Lim0d3d1f82015-12-02 14:47:59 +0900395 // happens for example when replacing windows during an activity relaunch. When
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700396 // constructing the animation, we want the new window, not the exiting one.
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800397 if (win.mAnimatingExit) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700398 candidate = win;
399 } else {
400 return win;
401 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800402 }
403 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700404 return candidate;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800405 }
406
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800407 boolean windowsAreFocusable() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800408 return StackId.canReceiveKeys(getTask().mStack.mStackId) || mAlwaysFocusable;
Wale Ogunwaled045c822015-12-02 09:14:28 -0800409 }
410
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800411 AppWindowContainerController getController() {
412 final WindowContainerController controller = super.getController();
413 return controller != null ? (AppWindowContainerController) controller : null;
414 }
415
Wale Ogunwale571771c2016-08-26 13:18:50 -0700416 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -0700417 boolean isVisible() {
Wale Ogunwalee471be62016-10-03 07:53:55 -0700418 // If the app token isn't hidden then it is considered visible and there is no need to check
419 // its children windows to see if they are visible.
420 return !hidden;
Wale Ogunwale44f21802016-09-02 12:49:48 -0700421 }
422
423 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -0700424 void removeIfPossible() {
Craig Mautnere3119b72015-01-20 15:02:36 -0800425 mIsExiting = false;
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800426 removeAllWindowsIfPossible();
Bryce Lee6d410262017-02-28 15:30:17 -0800427 removeImmediately();
Craig Mautnere3119b72015-01-20 15:02:36 -0800428 }
429
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700430 @Override
431 boolean checkCompleteDeferredRemoval() {
432 if (mIsExiting) {
433 removeIfPossible();
434 }
435 return super.checkCompleteDeferredRemoval();
436 }
437
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700438 void onRemovedFromDisplay() {
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700439 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app token: " + this);
440
Wale Ogunwale72919d22016-12-08 18:58:50 -0800441 boolean delayed = setVisibility(null, false, TRANSIT_UNSET, true, mVoiceInteraction);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700442
443 mService.mOpeningApps.remove(this);
Jorim Jaggi1b4b23e2016-11-15 16:30:12 -0800444 mService.mUnknownAppVisibilityController.appRemoved(this);
Jorim Jaggi10abe2f2017-01-03 16:44:46 +0100445 mService.mTaskSnapshotController.onAppRemoved(this);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700446 waitingToShow = false;
447 if (mService.mClosingApps.contains(this)) {
448 delayed = true;
449 } else if (mService.mAppTransition.isTransitionSet()) {
450 mService.mClosingApps.add(this);
451 delayed = true;
452 }
453
454 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app " + this + " delayed=" + delayed
455 + " animation=" + mAppAnimator.animation + " animating=" + mAppAnimator.animating);
456
457 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM, "removeAppToken: "
458 + this + " delayed=" + delayed + " Callers=" + Debug.getCallers(4));
459
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800460 if (startingData != null && getController() != null) {
461 getController().removeStartingWindow();
462 }
463
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800464 final TaskStack stack = getTask().mStack;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700465 if (delayed && !isEmpty()) {
466 // set the token aside because it has an active animation to be finished
467 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM,
468 "removeAppToken make exiting: " + this);
469 stack.mExitingAppTokens.add(this);
470 mIsExiting = true;
471 } else {
472 // Make sure there is no animation running on this token, so any windows associated
473 // with it will be removed as soon as their animations are complete
474 mAppAnimator.clearAnimation();
475 mAppAnimator.animating = false;
476 removeIfPossible();
477 }
478
479 removed = true;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700480 stopFreezingScreen(true, true);
Bryce Lee6d410262017-02-28 15:30:17 -0800481
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700482 if (mService.mFocusedApp == this) {
483 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "Removing focused app token:" + this);
484 mService.mFocusedApp = null;
485 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
486 mService.mInputMonitor.setFocusedAppLw(null);
487 }
488
489 if (!delayed) {
490 updateReportedVisibilityLocked();
491 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700492 }
493
Chong Zhange05bcb12016-07-26 17:47:29 -0700494 void clearAnimatingFlags() {
Chong Zhangb0d26702016-08-12 16:03:29 -0700495 boolean wallpaperMightChange = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700496 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700497 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700498 wallpaperMightChange |= win.clearAnimatingFlags();
Chong Zhange05bcb12016-07-26 17:47:29 -0700499 }
Chong Zhangb0d26702016-08-12 16:03:29 -0700500 if (wallpaperMightChange) {
501 requestUpdateWallpaperIfNeeded();
502 }
Chong Zhange05bcb12016-07-26 17:47:29 -0700503 }
504
Robert Carre12aece2016-02-02 22:43:27 -0800505 void destroySurfaces() {
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700506 destroySurfaces(false /*cleanupOnResume*/);
507 }
508
509 /**
510 * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure
511 * the client has finished with them.
512 *
513 * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If
514 * set to true, destroy only surfaces of removed windows, and clear relevant flags of the
515 * others so that they are ready to be reused. If set to false (common case), destroy all
516 * surfaces that's eligible, if the app is already stopped.
517 */
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700518 private void destroySurfaces(boolean cleanupOnResume) {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700519 boolean destroyedSomething = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700520 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700521 final WindowState win = mChildren.get(i);
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700522 destroyedSomething |= win.destroySurface(cleanupOnResume, mAppStopped);
Robert Carre12aece2016-02-02 22:43:27 -0800523 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700524 if (destroyedSomething) {
525 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700526 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Robert Carre12aece2016-02-02 22:43:27 -0800527 }
528 }
529
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800530 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700531 * Notify that the app is now resumed, and it was not stopped before, perform a clean
532 * up of the surfaces
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800533 */
Chong Zhangad24f962016-08-25 12:12:33 -0700534 void notifyAppResumed(boolean wasStopped, boolean allowSavedSurface) {
535 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped
536 + " allowSavedSurface=" + allowSavedSurface + " " + this);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700537 mAppStopped = false;
538 if (!wasStopped) {
539 destroySurfaces(true /*cleanupOnResume*/);
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800540 }
Chong Zhangad24f962016-08-25 12:12:33 -0700541 if (!allowSavedSurface) {
542 destroySavedSurfaces();
543 }
Robert Carre12aece2016-02-02 22:43:27 -0800544 }
545
Chong Zhangbef461f2015-10-27 11:38:24 -0700546 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700547 * Notify that the app has stopped, and it is okay to destroy any surfaces which were
548 * keeping alive in case they were still being used.
549 */
550 void notifyAppStopped() {
551 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this);
552 mAppStopped = true;
553 destroySurfaces();
554 // Remove any starting window that was added for this app if they are still around.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800555 if (getController() != null) {
556 getController().removeStartingWindow();
557 }
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700558 }
559
560 /**
Chong Zhangbef461f2015-10-27 11:38:24 -0700561 * Checks whether we should save surfaces for this app.
562 *
563 * @return true if the surfaces should be saved, false otherwise.
564 */
565 boolean shouldSaveSurface() {
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800566 // We want to save surface if the app's windows are "allDrawn".
567 // (If we started entering animation early with saved surfaces, allDrawn
568 // should have been restored to true. So we'll save again in that case
569 // even if app didn't actually finish drawing.)
570 return allDrawn;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800571 }
572
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700573 private boolean canRestoreSurfaces() {
574 for (int i = mChildren.size() -1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700575 final WindowState w = mChildren.get(i);
Chong Zhang92147042016-05-09 12:47:11 -0700576 if (w.canRestoreSurface()) {
Robert Carr13f7be9e2015-12-02 18:39:45 -0800577 return true;
578 }
Chong Zhangbef461f2015-10-27 11:38:24 -0700579 }
580 return false;
581 }
582
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700583 private void clearWasVisibleBeforeClientHidden() {
584 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700585 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700586 w.clearWasVisibleBeforeClientHidden();
Chong Zhang92147042016-05-09 12:47:11 -0700587 }
588 }
589
Chong Zhang8e4bda92016-05-04 15:08:18 -0700590 /**
591 * Whether the app has some window that is invisible in layout, but
592 * animating with saved surface.
593 */
594 boolean isAnimatingInvisibleWithSavedSurface() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700595 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700596 final WindowState w = mChildren.get(i);
Chong Zhang8e4bda92016-05-04 15:08:18 -0700597 if (w.isAnimatingInvisibleWithSavedSurface()) {
598 return true;
599 }
600 }
601 return false;
602 }
603
604 /**
605 * Hide all window surfaces that's still invisible in layout but animating
606 * with a saved surface, and mark them destroying.
607 */
608 void stopUsingSavedSurfaceLocked() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700609 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700610 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700611 w.stopUsingSavedSurface();
Chong Zhang8e4bda92016-05-04 15:08:18 -0700612 }
613 destroySurfaces();
614 }
615
Chong Zhangf58631a2016-05-24 16:02:10 -0700616 void markSavedSurfaceExiting() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700617 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700618 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700619 w.markSavedSurfaceExiting();
Chong Zhangf58631a2016-05-24 16:02:10 -0700620 }
621 }
622
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700623 void restoreSavedSurfaceForInterestingWindows() {
Chong Zhang92147042016-05-09 12:47:11 -0700624 if (!canRestoreSurfaces()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700625 clearWasVisibleBeforeClientHidden();
Chong Zhangbef461f2015-10-27 11:38:24 -0700626 return;
627 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700628
629 // Check if all interesting windows are drawn and we can mark allDrawn=true.
630 int interestingNotDrawn = -1;
631
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700632 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700633 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700634 interestingNotDrawn = w.restoreSavedSurfaceForInterestingWindow();
Chong Zhangbef461f2015-10-27 11:38:24 -0700635 }
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800636
Chong Zhang92147042016-05-09 12:47:11 -0700637 if (!allDrawn) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700638 allDrawn = (interestingNotDrawn == 0);
Chong Zhang92147042016-05-09 12:47:11 -0700639 if (allDrawn) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700640 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Chong Zhang92147042016-05-09 12:47:11 -0700641 }
642 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700643 clearWasVisibleBeforeClientHidden();
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800644
645 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700646 "restoreSavedSurfaceForInterestingWindows: " + this + " allDrawn=" + allDrawn
647 + " interestingNotDrawn=" + interestingNotDrawn);
Chong Zhangbef461f2015-10-27 11:38:24 -0700648 }
649
650 void destroySavedSurfaces() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700651 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700652 final WindowState win = mChildren.get(i);
Robert Carr13f7be9e2015-12-02 18:39:45 -0800653 win.destroySavedSurface();
Chong Zhangbef461f2015-10-27 11:38:24 -0700654 }
Chong Zhang92147042016-05-09 12:47:11 -0700655 }
656
657 void clearAllDrawn() {
658 allDrawn = false;
659 deferClearAllDrawn = false;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700660 allDrawnExcludingSaved = false;
Chong Zhangbef461f2015-10-27 11:38:24 -0700661 }
662
Bryce Lee6d410262017-02-28 15:30:17 -0800663 Task getTask() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800664 return (Task) getParent();
Bryce Lee6d410262017-02-28 15:30:17 -0800665 }
666
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800667 TaskStack getStack() {
668 final Task task = getTask();
669 if (task != null) {
670 return task.mStack;
671 } else {
672 return null;
673 }
674 }
675
Bryce Lee6d410262017-02-28 15:30:17 -0800676 @Override
677 void onParentSet() {
678 super.onParentSet();
679
680 // When the associated task is {@code null}, the {@link AppWindowToken} can no longer
681 // access visual elements like the {@link DisplayContent}. We must remove any associations
682 // such as animations.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800683 if (!mReparenting) {
684 final Task task = getTask();
685 if (task == null) {
686 // It is possible we have been marked as a closing app earlier. We must remove ourselves
687 // from this list so we do not participate in any future animations.
688 mService.mClosingApps.remove(this);
689 } else if (task.mStack != null) {
690 task.mStack.mExitingAppTokens.remove(this);
691 }
Bryce Lee6d410262017-02-28 15:30:17 -0800692 }
693 }
694
Wale Ogunwalefa854eb2016-09-20 13:43:52 -0700695 void postWindowRemoveStartingWindowCleanup(WindowState win) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700696 // TODO: Something smells about the code below...Is there a better way?
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700697 if (startingWindow == win) {
698 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800699 if (getController() != null) {
700 getController().removeStartingWindow();
701 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700702 } else if (mChildren.size() == 0 && startingData != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700703 // If this is the last window and we had requested a starting transition window,
704 // well there is no point now.
Jorim Jaggi02886a82016-12-06 09:10:06 -0800705 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingData");
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700706 startingData = null;
Jorim Jaggi829b9cd2017-01-23 16:20:53 +0100707 } else if (mChildren.size() == 1 && startingSurface != null && !isRelaunching()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700708 // If this is the last window except for a starting transition window,
709 // we need to get rid of the starting transition.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800710 if (getController() != null) {
711 getController().removeStartingWindow();
712 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700713 }
714 }
715
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700716 void removeDeadWindows() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700717 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700718 WindowState win = mChildren.get(winNdx);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800719 if (win.mAppDied) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700720 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700721 "removeDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800722 // Set mDestroying, we don't want any animation or delayed removal here.
723 win.mDestroying = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700724 // Also removes child windows.
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700725 win.removeIfPossible();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800726 }
727 }
728 }
729
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700730 boolean hasWindowsAlive() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700731 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700732 // No need to loop through child windows as the answer should be the same as that of the
733 // parent window.
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700734 if (!(mChildren.get(i)).mAppDied) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700735 return true;
736 }
737 }
738 return false;
739 }
740
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700741 void setWillReplaceWindows(boolean animate) {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700742 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
743 "Marking app token " + this + " with replacing windows.");
Robert Carra1eb4392015-12-10 12:43:51 -0800744
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700745 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700746 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700747 w.setWillReplaceWindow(animate);
Robert Carra1eb4392015-12-10 12:43:51 -0800748 }
749 if (animate) {
750 // Set-up dummy animation so we can start treating windows associated with this
751 // token like they are in transition before the new app window is ready for us to
752 // run the real transition animation.
753 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700754 "setWillReplaceWindow() Setting dummy animation on: " + this);
Robert Carra1eb4392015-12-10 12:43:51 -0800755 mAppAnimator.setDummyAnimation();
756 }
757 }
758
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700759 void setWillReplaceChildWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700760 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this
Robert Carr23fa16b2016-01-13 13:19:58 -0800761 + " with replacing child windows.");
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700762 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700763 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700764 w.setWillReplaceChildWindows();
Robert Carr23fa16b2016-01-13 13:19:58 -0800765 }
766 }
767
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700768 void clearWillReplaceWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700769 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
770 "Resetting app token " + this + " of replacing window marks.");
Chong Zhangf596cd52016-01-05 13:42:44 -0800771
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700772 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700773 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700774 w.clearWillReplaceWindow();
Chong Zhangf596cd52016-01-05 13:42:44 -0800775 }
776 }
777
Chong Zhang4d7369a2016-04-25 16:09:14 -0700778 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700779 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700780 final WindowState w = mChildren.get(i);
Chong Zhang4d7369a2016-04-25 16:09:14 -0700781 w.requestUpdateWallpaperIfNeeded();
782 }
783 }
784
Chong Zhangd78ddb42016-03-02 17:01:14 -0800785 boolean isRelaunching() {
786 return mPendingRelaunchCount > 0;
787 }
788
789 void startRelaunching() {
790 if (canFreezeBounds()) {
791 freezeBounds();
792 }
Robert Carrd5c7dd62017-03-08 10:39:30 -0800793
794 // In the process of tearing down before relaunching, the app will
795 // try and clean up it's child surfaces. We need to prevent this from
796 // happening, so we sever the children, transfering their ownership
797 // from the client it-self to the parent surface (owned by us).
798 for (int i = mChildren.size() - 1; i >= 0; i--) {
799 final WindowState w = mChildren.get(i);
800 w.mWinAnimator.detachChildren();
801 }
802
Chong Zhangd78ddb42016-03-02 17:01:14 -0800803 mPendingRelaunchCount++;
804 }
805
806 void finishRelaunching() {
807 if (canFreezeBounds()) {
808 unfreezeBounds();
809 }
810 if (mPendingRelaunchCount > 0) {
811 mPendingRelaunchCount--;
812 }
813 }
814
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700815 void clearRelaunching() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700816 if (mPendingRelaunchCount == 0) {
817 return;
818 }
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700819 if (canFreezeBounds()) {
820 unfreezeBounds();
821 }
822 mPendingRelaunchCount = 0;
823 }
824
Wale Ogunwale07bcab72016-10-14 15:30:09 -0700825 /**
826 * Returns true if the new child window we are adding to this token is considered greater than
827 * the existing child window in this token in terms of z-order.
828 */
829 @Override
830 protected boolean isFirstChildWindowGreaterThanSecond(WindowState newWindow,
831 WindowState existingWindow) {
832 final int type1 = newWindow.mAttrs.type;
833 final int type2 = existingWindow.mAttrs.type;
834
835 // Base application windows should be z-ordered BELOW all other windows in the app token.
836 if (type1 == TYPE_BASE_APPLICATION && type2 != TYPE_BASE_APPLICATION) {
837 return false;
838 } else if (type1 != TYPE_BASE_APPLICATION && type2 == TYPE_BASE_APPLICATION) {
839 return true;
840 }
841
842 // Starting windows should be z-ordered ABOVE all other windows in the app token.
843 if (type1 == TYPE_APPLICATION_STARTING && type2 != TYPE_APPLICATION_STARTING) {
844 return true;
845 } else if (type1 != TYPE_APPLICATION_STARTING && type2 == TYPE_APPLICATION_STARTING) {
846 return false;
847 }
848
849 // Otherwise the new window is greater than the existing window.
850 return true;
851 }
852
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700853 @Override
Robert Carra1eb4392015-12-10 12:43:51 -0800854 void addWindow(WindowState w) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700855 super.addWindow(w);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700856
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700857 boolean gotReplacementWindow = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700858 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700859 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700860 gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w);
861 }
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700862
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700863 // if we got a replacement window, reset the timeout to give drawing more time
864 if (gotReplacementWindow) {
865 mService.scheduleWindowReplacementTimeouts(this);
Robert Carra1eb4392015-12-10 12:43:51 -0800866 }
Jorim Jaggife762342016-10-13 14:33:27 +0200867 checkKeyguardFlagsChanged();
868 }
869
870 @Override
871 void removeChild(WindowState child) {
872 super.removeChild(child);
873 checkKeyguardFlagsChanged();
Robert Carra1eb4392015-12-10 12:43:51 -0800874 }
875
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700876 private boolean waitingForReplacement() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700877 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700878 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700879 if (candidate.waitingForReplacement()) {
Robert Carra1eb4392015-12-10 12:43:51 -0800880 return true;
881 }
882 }
883 return false;
884 }
885
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700886 void onWindowReplacementTimeout() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700887 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700888 (mChildren.get(i)).onWindowReplacementTimeout();
Robert Carra1eb4392015-12-10 12:43:51 -0800889 }
890 }
891
Winson Chung30480042017-01-26 10:55:34 -0800892 void reparent(Task task, int position) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800893 final Task currentTask = getTask();
894 if (task == currentTask) {
Winson Chung30480042017-01-26 10:55:34 -0800895 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800896 "window token=" + this + " already child of task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -0800897 }
Bryce Lee6d410262017-02-28 15:30:17 -0800898
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800899 if (currentTask.mStack != task.mStack) {
Bryce Lee6d410262017-02-28 15:30:17 -0800900 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800901 "window token=" + this + " current task=" + currentTask
Bryce Lee6d410262017-02-28 15:30:17 -0800902 + " belongs to a different stack than " + task);
903 }
904
Winson Chung30480042017-01-26 10:55:34 -0800905 if (DEBUG_ADD_REMOVE) Slog.i(TAG, "reParentWindowToken: removing window token=" + this
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800906 + " from task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -0800907 final DisplayContent prevDisplayContent = getDisplayContent();
908
Bryce Lee6d410262017-02-28 15:30:17 -0800909 mReparenting = true;
910
Winson Chung30480042017-01-26 10:55:34 -0800911 getParent().removeChild(this);
912 task.addChild(this, position);
913
Bryce Lee6d410262017-02-28 15:30:17 -0800914 mReparenting = false;
915
Winson Chung30480042017-01-26 10:55:34 -0800916 // Relayout display(s).
917 final DisplayContent displayContent = task.getDisplayContent();
918 displayContent.setLayoutNeeded();
919 if (prevDisplayContent != displayContent) {
920 onDisplayChanged(displayContent);
921 prevDisplayContent.setLayoutNeeded();
922 }
923 }
924
Chong Zhangd78ddb42016-03-02 17:01:14 -0800925 private boolean canFreezeBounds() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800926 final Task task = getTask();
927
Chong Zhangd78ddb42016-03-02 17:01:14 -0800928 // For freeform windows, we can't freeze the bounds at the moment because this would make
929 // the resizing unresponsive.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800930 return task != null && !task.inFreeformWorkspace();
Chong Zhangd78ddb42016-03-02 17:01:14 -0800931 }
932
Jorim Jaggi0429f352015-12-22 16:29:16 +0100933 /**
934 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
935 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
936 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
937 * with a queue.
938 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800939 private void freezeBounds() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800940 final Task task = getTask();
941 mFrozenBounds.offer(new Rect(task.mPreparedFrozenBounds));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700942
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800943 if (task.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) {
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700944 // We didn't call prepareFreezingBounds on the task, so use the current value.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800945 mFrozenMergedConfig.offer(new Configuration(task.getConfiguration()));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700946 } else {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800947 mFrozenMergedConfig.offer(new Configuration(task.mPreparedFrozenMergedConfig));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700948 }
Andrii Kulianb10330d2016-09-16 13:51:46 -0700949 // Calling unset() to make it equal to Configuration.EMPTY.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800950 task.mPreparedFrozenMergedConfig.unset();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100951 }
952
953 /**
954 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
955 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800956 private void unfreezeBounds() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700957 if (!mFrozenBounds.isEmpty()) {
958 mFrozenBounds.remove();
959 }
960 if (!mFrozenMergedConfig.isEmpty()) {
961 mFrozenMergedConfig.remove();
962 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700963 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700964 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700965 win.onUnfreezeBounds();
Jorim Jaggi4846ee32016-01-07 17:39:12 +0100966 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700967 mService.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100968 }
969
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700970 void resetJustMovedInStack() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700971 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700972 (mChildren.get(i)).resetJustMovedInStack();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700973 }
974 }
975
976 void notifyMovedInStack() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700977 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700978 final WindowState win = mChildren.get(winNdx);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700979 win.notifyMovedInStack();
980 }
981 }
982
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700983 void setAppLayoutChanges(int changes, String reason) {
984 if (!mChildren.isEmpty()) {
985 final DisplayContent dc = getDisplayContent();
986 dc.pendingLayoutChanges |= changes;
987 if (DEBUG_LAYOUT_REPEATS) {
988 mService.mWindowPlacerLocked.debugLayoutRepeats(reason, dc.pendingLayoutChanges);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700989 }
990 }
991 }
992
993 void removeReplacedWindowIfNeeded(WindowState replacement) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700994 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700995 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700996 if (win.removeReplacedWindowIfNeeded(replacement)) {
997 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700998 }
999 }
1000 }
1001
1002 void startFreezingScreen() {
1003 if (DEBUG_ORIENTATION) logWithStack(TAG, "Set freezing of " + appToken + ": hidden="
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001004 + hidden + " freezing=" + mAppAnimator.freezingScreen + " hiddenRequested="
1005 + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001006 if (!hiddenRequested) {
1007 if (!mAppAnimator.freezingScreen) {
1008 mAppAnimator.freezingScreen = true;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001009 mService.registerAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001010 mAppAnimator.lastFreezeDuration = 0;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001011 mService.mAppsFreezingScreen++;
1012 if (mService.mAppsFreezingScreen == 1) {
1013 mService.startFreezingDisplayLocked(false, 0, 0);
1014 mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT);
1015 mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001016 }
1017 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001018 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001019 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001020 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001021 w.onStartFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001022 }
1023 }
1024 }
1025
1026 void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) {
1027 if (!mAppAnimator.freezingScreen) {
1028 return;
1029 }
1030 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + this + " force=" + force);
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001031 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001032 boolean unfrozeWindows = false;
1033 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001034 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001035 unfrozeWindows |= w.onStopFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001036 }
1037 if (force || unfrozeWindows) {
1038 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this);
1039 mAppAnimator.freezingScreen = false;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001040 mService.unregisterAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001041 mAppAnimator.lastFreezeDuration =
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001042 (int)(SystemClock.elapsedRealtime() - mService.mDisplayFreezeTime);
1043 mService.mAppsFreezingScreen--;
1044 mService.mLastFinishedFreezeSource = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001045 }
1046 if (unfreezeSurfaceNow) {
1047 if (unfrozeWindows) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001048 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001049 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001050 mService.stopFreezingDisplayLocked();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001051 }
1052 }
1053
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001054 @Override
1055 public void onAppFreezeTimeout() {
1056 Slog.w(TAG_WM, "Force clearing freeze: " + this);
1057 stopFreezingScreen(true, true);
1058 }
1059
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001060 boolean transferStartingWindow(IBinder transferFrom) {
Wale Ogunwale02319a62016-09-26 15:21:22 -07001061 final AppWindowToken fromToken = getDisplayContent().getAppWindowToken(transferFrom);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001062 if (fromToken == null) {
1063 return false;
1064 }
1065
1066 final WindowState tStartingWindow = fromToken.startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001067 if (tStartingWindow != null && fromToken.startingSurface != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001068 // In this case, the starting icon has already been displayed, so start
1069 // letting windows get shown immediately without any more transitions.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001070 mService.mSkipAppTransitionAnimation = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001071
1072 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow
1073 + " from " + fromToken + " to " + this);
1074
1075 final long origId = Binder.clearCallingIdentity();
1076
1077 // Transfer the starting window over to the new token.
1078 startingData = fromToken.startingData;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001079 startingSurface = fromToken.startingSurface;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001080 startingDisplayed = fromToken.startingDisplayed;
1081 fromToken.startingDisplayed = false;
1082 startingWindow = tStartingWindow;
1083 reportedVisible = fromToken.reportedVisible;
1084 fromToken.startingData = null;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001085 fromToken.startingSurface = null;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001086 fromToken.startingWindow = null;
1087 fromToken.startingMoved = true;
1088 tStartingWindow.mToken = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001089 tStartingWindow.mAppToken = this;
1090
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001091 if (DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001092 "Removing starting " + tStartingWindow + " from " + fromToken);
Wale Ogunwalefa854eb2016-09-20 13:43:52 -07001093 fromToken.removeChild(tStartingWindow);
1094 fromToken.postWindowRemoveStartingWindowCleanup(tStartingWindow);
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001095 addWindow(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001096
1097 // Propagate other interesting state between the tokens. If the old token is displayed,
1098 // we should immediately force the new one to be displayed. If it is animating, we need
1099 // to move that animation to the new one.
1100 if (fromToken.allDrawn) {
1101 allDrawn = true;
1102 deferClearAllDrawn = fromToken.deferClearAllDrawn;
1103 }
1104 if (fromToken.firstWindowDrawn) {
1105 firstWindowDrawn = true;
1106 }
1107 if (!fromToken.hidden) {
1108 hidden = false;
1109 hiddenRequested = false;
1110 }
1111 if (clientHidden != fromToken.clientHidden) {
1112 clientHidden = fromToken.clientHidden;
1113 sendAppVisibilityToClients();
1114 }
1115 fromToken.mAppAnimator.transferCurrentAnimation(
1116 mAppAnimator, tStartingWindow.mWinAnimator);
1117
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001118 mService.updateFocusedWindowLocked(
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001119 UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/);
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001120 getDisplayContent().setLayoutNeeded();
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001121 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001122 Binder.restoreCallingIdentity(origId);
1123 return true;
1124 } else if (fromToken.startingData != null) {
1125 // The previous app was getting ready to show a
1126 // starting window, but hasn't yet done so. Steal it!
1127 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1128 "Moving pending starting from " + fromToken + " to " + this);
1129 startingData = fromToken.startingData;
1130 fromToken.startingData = null;
1131 fromToken.startingMoved = true;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001132 if (getController() != null) {
1133 getController().scheduleAddStartingWindow();
1134 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001135 return true;
1136 }
1137
1138 final AppWindowAnimator tAppAnimator = fromToken.mAppAnimator;
1139 final AppWindowAnimator wAppAnimator = mAppAnimator;
1140 if (tAppAnimator.thumbnail != null) {
1141 // The old token is animating with a thumbnail, transfer that to the new token.
1142 if (wAppAnimator.thumbnail != null) {
1143 wAppAnimator.thumbnail.destroy();
1144 }
1145 wAppAnimator.thumbnail = tAppAnimator.thumbnail;
1146 wAppAnimator.thumbnailLayer = tAppAnimator.thumbnailLayer;
1147 wAppAnimator.thumbnailAnimation = tAppAnimator.thumbnailAnimation;
1148 tAppAnimator.thumbnail = null;
1149 }
1150 return false;
1151 }
1152
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001153 boolean isLastWindow(WindowState win) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001154 return mChildren.size() == 1 && mChildren.get(0) == win;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001155 }
1156
1157 void setAllAppWinAnimators() {
1158 final ArrayList<WindowStateAnimator> allAppWinAnimators = mAppAnimator.mAllAppWinAnimators;
1159 allAppWinAnimators.clear();
1160
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001161 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001162 for (int j = 0; j < windowsCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001163 (mChildren.get(j)).addWinAnimatorToList(allAppWinAnimators);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001164 }
1165 }
1166
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001167 @Override
1168 void onAppTransitionDone() {
1169 sendingToBottom = false;
1170 }
1171
Wale Ogunwale51362492016-09-08 17:49:17 -07001172 /**
1173 * We override because this class doesn't want its children affecting its reported orientation
1174 * in anyway.
1175 */
1176 @Override
1177 int getOrientation() {
Bryce Leea163b762017-01-24 11:05:01 -08001178 if (fillsParent() && (isVisible() || mService.mOpeningApps.contains(this))) {
1179 return mOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001180 }
Bryce Leea163b762017-01-24 11:05:01 -08001181
1182 return SCREEN_ORIENTATION_UNSET;
Wale Ogunwale51362492016-09-08 17:49:17 -07001183 }
1184
Wale Ogunwaleb198b742016-12-01 08:44:09 -08001185 /** Returns the app's preferred orientation regardless of its currently visibility state. */
1186 int getOrientationIgnoreVisibility() {
1187 return mOrientation;
1188 }
1189
Craig Mautnerdbb79912012-03-01 18:59:14 -08001190 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001191 void checkAppWindowsReadyToShow() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001192 if (allDrawn == mAppAnimator.allDrawn) {
1193 return;
1194 }
1195
1196 mAppAnimator.allDrawn = allDrawn;
1197 if (!allDrawn) {
1198 return;
1199 }
1200
1201 // The token has now changed state to having all windows shown... what to do, what to do?
1202 if (mAppAnimator.freezingScreen) {
1203 mAppAnimator.showAllWindowsLocked();
1204 stopFreezingScreen(false, true);
1205 if (DEBUG_ORIENTATION) Slog.i(TAG,
1206 "Setting mOrientationChangeComplete=true because wtoken " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001207 + " numInteresting=" + mNumInterestingWindows + " numDrawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001208 // This will set mOrientationChangeComplete and cause a pass through layout.
1209 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001210 "checkAppWindowsReadyToShow: freezingScreen");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001211 } else {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001212 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001213
1214 // We can now show all of the drawn windows!
1215 if (!mService.mOpeningApps.contains(this)) {
1216 mService.mAnimator.orAnimating(mAppAnimator.showAllWindowsLocked());
1217 }
1218 }
1219 }
1220
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001221 void updateAllDrawn(DisplayContent dc) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001222 if (!allDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001223 final int numInteresting = mNumInterestingWindows;
1224 if (numInteresting > 0 && mNumDrawnWindows >= numInteresting) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001225 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawn: " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001226 + " interesting=" + numInteresting + " drawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001227 allDrawn = true;
1228 // Force an additional layout pass where
1229 // WindowStateAnimator#commitFinishDrawingLocked() will call performShowLocked().
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001230 dc.setLayoutNeeded();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001231 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
1232 }
1233 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001234
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001235 if (!allDrawnExcludingSaved) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001236 int numInteresting = mNumInterestingWindowsExcludingSaved;
1237 if (numInteresting > 0 && mNumDrawnWindowsExcludingSaved >= numInteresting) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001238 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawnExcludingSaved: " + this
1239 + " interesting=" + numInteresting
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001240 + " drawn=" + mNumDrawnWindowsExcludingSaved);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001241 allDrawnExcludingSaved = true;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001242 dc.setLayoutNeeded();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001243 if (isAnimatingInvisibleWithSavedSurface()
1244 && !mService.mFinishedEarlyAnim.contains(this)) {
1245 mService.mFinishedEarlyAnim.add(this);
1246 }
1247 }
1248 }
1249 }
1250
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001251 /**
1252 * Updated this app token tracking states for interesting and drawn windows based on the window.
1253 *
1254 * @return Returns true if the input window is considered interesting and drawn while all the
1255 * windows in this app token where not considered drawn as of the last pass.
1256 */
1257 boolean updateDrawnWindowStates(WindowState w) {
1258 if (DEBUG_STARTING_WINDOW && w == startingWindow) {
1259 Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" + w.isOnScreen()
1260 + " allDrawn=" + allDrawn + " freezingScreen=" + mAppAnimator.freezingScreen);
1261 }
1262
1263 if (allDrawn && allDrawnExcludingSaved && !mAppAnimator.freezingScreen) {
1264 return false;
1265 }
1266
1267 if (mLastTransactionSequence != mService.mTransactionSequence) {
1268 mLastTransactionSequence = mService.mTransactionSequence;
1269 mNumInterestingWindows = mNumDrawnWindows = 0;
1270 mNumInterestingWindowsExcludingSaved = 0;
1271 mNumDrawnWindowsExcludingSaved = 0;
1272 startingDisplayed = false;
1273 }
1274
1275 final WindowStateAnimator winAnimator = w.mWinAnimator;
1276
1277 boolean isInterestingAndDrawn = false;
1278
1279 if (!allDrawn && w.mightAffectAllDrawn(false /* visibleOnly */)) {
1280 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
1281 Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw()
1282 + ", isAnimationSet=" + winAnimator.isAnimationSet());
1283 if (!w.isDrawnLw()) {
1284 Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController
1285 + " pv=" + w.mPolicyVisibility
1286 + " mDrawState=" + winAnimator.drawStateToString()
1287 + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested
1288 + " a=" + winAnimator.mAnimating);
1289 }
1290 }
1291
1292 if (w != startingWindow) {
1293 if (w.isInteresting()) {
1294 mNumInterestingWindows++;
1295 if (w.isDrawnLw()) {
1296 mNumDrawnWindows++;
1297
1298 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, "tokenMayBeDrawn: "
1299 + this + " w=" + w + " numInteresting=" + mNumInterestingWindows
1300 + " freezingScreen=" + mAppAnimator.freezingScreen
1301 + " mAppFreezing=" + w.mAppFreezing);
1302
1303 isInterestingAndDrawn = true;
1304 }
1305 }
1306 } else if (w.isDrawnLw()) {
Jorim Jaggi3878ca32017-02-02 17:13:05 -08001307 if (getController() != null) {
1308 getController().reportStartingWindowDrawn();
1309 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001310 startingDisplayed = true;
1311 }
1312 }
1313
1314 if (!allDrawnExcludingSaved && w.mightAffectAllDrawn(true /* visibleOnly */)) {
1315 if (w != startingWindow && w.isInteresting()) {
1316 mNumInterestingWindowsExcludingSaved++;
1317 if (w.isDrawnLw() && !w.isAnimatingWithSavedSurface()) {
1318 mNumDrawnWindowsExcludingSaved++;
1319
1320 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
1321 "tokenMayBeDrawnExcludingSaved: " + this + " w=" + w
1322 + " numInteresting=" + mNumInterestingWindowsExcludingSaved
1323 + " freezingScreen=" + mAppAnimator.freezingScreen
1324 + " mAppFreezing=" + w.mAppFreezing);
1325
1326 isInterestingAndDrawn = true;
1327 }
1328 }
1329 }
1330
1331 return isInterestingAndDrawn;
1332 }
1333
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001334 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001335 void stepAppWindowsAnimation(long currentTime) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001336 mAppAnimator.wasAnimating = mAppAnimator.animating;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001337 if (mAppAnimator.stepAnimationLocked(currentTime)) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001338 mAppAnimator.animating = true;
1339 mService.mAnimator.setAnimating(true);
1340 mService.mAnimator.mAppWindowAnimating = true;
1341 } else if (mAppAnimator.wasAnimating) {
1342 // stopped animating, do one more pass through the layout
Wale Ogunwale1e129a42016-11-21 13:03:47 -08001343 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
1344 DEBUG_LAYOUT_REPEATS ? "appToken " + this + " done" : null);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001345 if (DEBUG_ANIM) Slog.v(TAG, "updateWindowsApps...: done animating " + this);
1346 }
1347 }
1348
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001349 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001350 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001351 // For legacy reasons we process the TaskStack.mExitingAppTokens first in DisplayContent
1352 // before the non-exiting app tokens. So, we skip the exiting app tokens here.
1353 // TODO: Investigate if we need to continue to do this or if we can just process them
1354 // in-order.
1355 if (mIsExiting && !waitingForReplacement()) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001356 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001357 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001358 return forAllWindowsUnchecked(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001359 }
1360
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001361 boolean forAllWindowsUnchecked(ToBooleanFunction<WindowState> callback,
1362 boolean traverseTopToBottom) {
1363 return super.forAllWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001364 }
1365
1366 @Override
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001367 AppWindowToken asAppWindowToken() {
1368 // I am an app window token!
1369 return this;
1370 }
1371
1372 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -07001373 boolean fillsParent() {
1374 return mFillsParent;
1375 }
1376
1377 void setFillsParent(boolean fillsParent) {
1378 mFillsParent = fillsParent;
1379 }
1380
Jorim Jaggife762342016-10-13 14:33:27 +02001381 boolean containsDismissKeyguardWindow() {
1382 for (int i = mChildren.size() - 1; i >= 0; i--) {
1383 if ((mChildren.get(i).mAttrs.flags & FLAG_DISMISS_KEYGUARD) != 0) {
1384 return true;
1385 }
1386 }
1387 return false;
1388 }
1389
1390 boolean containsShowWhenLockedWindow() {
1391 for (int i = mChildren.size() - 1; i >= 0; i--) {
1392 if ((mChildren.get(i).mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
1393 return true;
1394 }
1395 }
1396 return false;
1397 }
1398
1399 void checkKeyguardFlagsChanged() {
1400 final boolean containsDismissKeyguard = containsDismissKeyguardWindow();
1401 final boolean containsShowWhenLocked = containsShowWhenLockedWindow();
1402 if (containsDismissKeyguard != mLastContainsDismissKeyguardWindow
1403 || containsShowWhenLocked != mLastContainsShowWhenLockedWindow) {
1404 mService.notifyKeyguardFlagsChanged(null /* callback */);
1405 }
1406 mLastContainsDismissKeyguardWindow = containsDismissKeyguard;
1407 mLastContainsShowWhenLockedWindow = containsShowWhenLocked;
1408 }
1409
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001410 WindowState getImeTargetBelowWindow(WindowState w) {
1411 final int index = mChildren.indexOf(w);
1412 if (index > 0) {
1413 final WindowState target = mChildren.get(index - 1);
1414 if (target.canBeImeTarget()) {
1415 return target;
1416 }
1417 }
1418 return null;
1419 }
1420
1421 WindowState getHighestAnimLayerWindow(WindowState currentTarget) {
1422 WindowState candidate = null;
1423 for (int i = mChildren.indexOf(currentTarget); i >= 0; i--) {
1424 final WindowState w = mChildren.get(i);
1425 if (w.mRemoved) {
1426 continue;
1427 }
1428 if (candidate == null || w.mWinAnimator.mAnimLayer >
1429 candidate.mWinAnimator.mAnimLayer) {
1430 candidate = w;
1431 }
1432 }
1433 return candidate;
1434 }
1435
Wale Ogunwale51362492016-09-08 17:49:17 -07001436 @Override
Robert Carrdee1b3f2017-02-27 11:33:33 -08001437 int getAnimLayerAdjustment() {
1438 return mAppAnimator.animLayerAdjustment;
1439 }
1440
1441 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001442 void dump(PrintWriter pw, String prefix) {
1443 super.dump(pw, prefix);
1444 if (appToken != null) {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001445 pw.println(prefix + "app=true mVoiceInteraction=" + mVoiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001446 }
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001447 pw.print(prefix); pw.print("task="); pw.println(getTask());
Wale Ogunwale51362492016-09-08 17:49:17 -07001448 pw.print(prefix); pw.print(" mFillsParent="); pw.print(mFillsParent);
1449 pw.print(" mOrientation="); pw.println(mOrientation);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001450 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
1451 pw.print(" clientHidden="); pw.print(clientHidden);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -07001452 pw.print(" reportedDrawn="); pw.print(reportedDrawn);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001453 pw.print(" reportedVisible="); pw.println(reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -07001454 if (paused) {
1455 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001456 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001457 if (mAppStopped) {
1458 pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped);
1459 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001460 if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0
Craig Mautner6fbda632012-07-03 09:26:39 -07001461 || allDrawn || mAppAnimator.allDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001462 pw.print(prefix); pw.print("mNumInterestingWindows=");
1463 pw.print(mNumInterestingWindows);
1464 pw.print(" mNumDrawnWindows="); pw.print(mNumDrawnWindows);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001465 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -07001466 pw.print(" allDrawn="); pw.print(allDrawn);
1467 pw.print(" (animator="); pw.print(mAppAnimator.allDrawn);
1468 pw.println(")");
1469 }
1470 if (inPendingTransaction) {
1471 pw.print(prefix); pw.print("inPendingTransaction=");
1472 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001473 }
Craig Mautner799bc1d2015-01-14 10:33:48 -08001474 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001475 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
1476 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -08001477 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -08001478 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001479 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001480 if (startingWindow != null || startingSurface != null
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001481 || startingDisplayed || startingMoved) {
1482 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001483 pw.print(" startingSurface="); pw.print(startingSurface);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001484 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001485 pw.print(" startingMoved="); pw.println(startingMoved);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001486 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01001487 if (!mFrozenBounds.isEmpty()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -08001488 pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds);
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001489 pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig);
Chong Zhangd78ddb42016-03-02 17:01:14 -08001490 }
1491 if (mPendingRelaunchCount != 0) {
1492 pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount);
Jorim Jaggi0429f352015-12-22 16:29:16 +01001493 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001494 }
1495
1496 @Override
1497 public String toString() {
1498 if (stringName == null) {
1499 StringBuilder sb = new StringBuilder();
1500 sb.append("AppWindowToken{");
1501 sb.append(Integer.toHexString(System.identityHashCode(this)));
1502 sb.append(" token="); sb.append(token); sb.append('}');
1503 stringName = sb.toString();
1504 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001505 return stringName + ((mIsExiting) ? " mIsExiting=" : "");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001506 }
Jeff Browne9bdb312012-04-05 15:30:10 -07001507}