blob: 5e19a459bf17264e864715a8b072ae21b1bcda0b [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;
Robert Carr6914f082017-03-20 19:04:30 -070058import android.view.SurfaceControl;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080059import android.view.WindowManager;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080060import android.view.WindowManagerPolicy.StartingSurface;
61
62import com.android.internal.util.ToBooleanFunction;
63import com.android.server.input.InputApplicationHandle;
64import com.android.server.wm.WindowManagerService.H;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080065
66import java.io.PrintWriter;
Jorim Jaggi0429f352015-12-22 16:29:16 +010067import java.util.ArrayDeque;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080068import java.util.ArrayList;
69
70class AppTokenList extends ArrayList<AppWindowToken> {
71}
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080072
73/**
74 * Version of WindowToken that is specifically for a particular application (or
75 * really activity) that is displaying windows.
76 */
Wale Ogunwale3f4433d2016-08-18 20:42:42 -070077class AppWindowToken extends WindowToken implements WindowManagerService.AppFreezeListener {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080078 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppWindowToken" : TAG_WM;
79
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080080 // Non-null only for application tokens.
81 final IApplicationToken appToken;
82
Filip Gruszczynskia590c992015-11-25 16:45:26 -080083 @NonNull final AppWindowAnimator mAppAnimator;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -070084
Wale Ogunwale72919d22016-12-08 18:58:50 -080085 final boolean mVoiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -070086
Wale Ogunwale51362492016-09-08 17:49:17 -070087 /** @see WindowContainer#fillsParent() */
88 private boolean mFillsParent;
Craig Mautner4c5eb222013-11-18 12:59:05 -080089 boolean layoutConfigChanges;
Wale Ogunwale72919d22016-12-08 18:58:50 -080090 boolean mShowForAllUsers;
91 int mTargetSdk;
Craig Mautnera2c77052012-03-26 12:14:43 -070092
Bryce Lee6d410262017-02-28 15:30:17 -080093 // Flag set while reparenting to prevent actions normally triggered by an individual parent
94 // change.
95 private boolean mReparenting;
96
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080097 // The input dispatching timeout for this application token in nanoseconds.
Wale Ogunwale72919d22016-12-08 18:58:50 -080098 long mInputDispatchingTimeoutNanos;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080099
100 // These are used for determining when all windows associated with
101 // an activity have been drawn, so they can be made visible together
102 // at the same time.
Craig Mautner764983d2012-03-22 11:37:36 -0700103 // initialize so that it doesn't match mTransactionSequence which is an int.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700104 private long mLastTransactionSequence = Long.MIN_VALUE;
105 private int mNumInterestingWindows;
106 private int mNumDrawnWindows;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800107 boolean inPendingTransaction;
108 boolean allDrawn;
Craig Mautner7636dfb2012-11-16 15:24:11 -0800109 // Set to true when this app creates a surface while in the middle of an animation. In that
110 // case do not clear allDrawn until the animation completes.
111 boolean deferClearAllDrawn;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800112
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700113 /**
114 * These are to track the app's real drawing status if there were no saved surfaces.
115 * @see #updateDrawnWindowStates
116 */
Chong Zhang8e4bda92016-05-04 15:08:18 -0700117 boolean allDrawnExcludingSaved;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700118 private int mNumInterestingWindowsExcludingSaved;
119 private int mNumDrawnWindowsExcludingSaved;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700120
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800121 // Is this window's surface needed? This is almost like hidden, except
122 // it will sometimes be true a little earlier: when the token has
123 // been shown, but is still waiting for its app transition to execute
124 // before making its windows shown.
125 boolean hiddenRequested;
126
127 // Have we told the window clients to hide themselves?
128 boolean clientHidden;
129
130 // Last visibility state we reported to the app token.
131 boolean reportedVisible;
132
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700133 // Last drawn state we reported to the app token.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700134 private boolean reportedDrawn;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700135
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800136 // Set to true when the token has been removed from the window mgr.
137 boolean removed;
138
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800139 // Information about an application starting window if displayed.
140 StartingData startingData;
141 WindowState startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800142 StartingSurface startingSurface;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800143 boolean startingDisplayed;
144 boolean startingMoved;
145 boolean firstWindowDrawn;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700146 private final WindowState.UpdateReportedVisibilityResults mReportedVisibilityResults =
147 new WindowState.UpdateReportedVisibilityResults();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800148
149 // Input application handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700150 final InputApplicationHandle mInputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800151
Wale Ogunwale571771c2016-08-26 13:18:50 -0700152 // TODO: Have a WindowContainer state for tracking exiting/deferred removal.
Craig Mautner799bc1d2015-01-14 10:33:48 -0800153 boolean mIsExiting;
Craig Mautner9ef471f2014-02-07 13:11:47 -0800154
Craig Mautnerbb742462014-07-07 15:28:55 -0700155 boolean mLaunchTaskBehind;
Craig Mautner8746a472014-07-24 15:12:54 -0700156 boolean mEnteringAnimation;
Craig Mautnerbb742462014-07-07 15:28:55 -0700157
Wale Ogunwale72919d22016-12-08 18:58:50 -0800158 private boolean mAlwaysFocusable;
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800159
Robert Carre12aece2016-02-02 22:43:27 -0800160 boolean mAppStopped;
Robert Carrfd10cd12016-06-29 16:41:50 -0700161 int mRotationAnimationHint;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700162 private int mPendingRelaunchCount;
Robert Carre12aece2016-02-02 22:43:27 -0800163
Jorim Jaggife762342016-10-13 14:33:27 +0200164 private boolean mLastContainsShowWhenLockedWindow;
165 private boolean mLastContainsDismissKeyguardWindow;
166
Jorim Jaggi0429f352015-12-22 16:29:16 +0100167 ArrayDeque<Rect> mFrozenBounds = new ArrayDeque<>();
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700168 ArrayDeque<Configuration> mFrozenMergedConfig = new ArrayDeque<>();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100169
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +0100170 private boolean mDisbalePreviewScreenshots;
171
Wale Ogunwale72919d22016-12-08 18:58:50 -0800172 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
173 DisplayContent dc, long inputDispatchingTimeoutNanos, boolean fullscreen,
174 boolean showForAllUsers, int targetSdk, int orientation, int rotationAnimationHint,
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800175 int configChanges, boolean launchTaskBehind, boolean alwaysFocusable,
176 AppWindowContainerController controller) {
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800177 this(service, token, voiceInteraction, dc, fullscreen);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800178 setController(controller);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800179 mInputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800180 mShowForAllUsers = showForAllUsers;
181 mTargetSdk = targetSdk;
182 mOrientation = orientation;
183 layoutConfigChanges = (configChanges & (CONFIG_SCREEN_SIZE | CONFIG_ORIENTATION)) != 0;
184 mLaunchTaskBehind = launchTaskBehind;
185 mAlwaysFocusable = alwaysFocusable;
186 mRotationAnimationHint = rotationAnimationHint;
187
188 // Application tokens start out hidden.
189 hidden = true;
190 hiddenRequested = true;
191 }
192
193 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800194 DisplayContent dc, boolean fillsParent) {
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800195 super(service, token != null ? token.asBinder() : null, TYPE_APPLICATION, true, dc,
196 false /* ownerCanManageAppTokens */);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700197 appToken = token;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800198 mVoiceInteraction = voiceInteraction;
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800199 mFillsParent = fillsParent;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800200 mInputApplicationHandle = new InputApplicationHandle(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700201 mAppAnimator = new AppWindowAnimator(this, service);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800202 }
203
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800204 void onFirstWindowDrawn(WindowState win, WindowStateAnimator winAnimator) {
205 firstWindowDrawn = true;
206
207 // We now have a good window to show, remove dead placeholders
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700208 removeDeadWindows();
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800209
Jorim Jaggi02886a82016-12-06 09:10:06 -0800210 if (startingWindow != null) {
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800211 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, "Finish starting "
212 + win.mToken + ": first real window is shown, no animation");
213 // If this initial window is animating, stop it -- we will do an animation to reveal
214 // it from behind the starting window, so there is no need for it to also be doing its
215 // own stuff.
216 winAnimator.clearAnimation();
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800217 if (getController() != null) {
218 getController().removeStartingWindow();
219 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800220 }
221 updateReportedVisibilityLocked();
222 }
223
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800224 void updateReportedVisibilityLocked() {
225 if (appToken == null) {
226 return;
227 }
228
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700229 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700230 final int count = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800231
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700232 mReportedVisibilityResults.reset();
233
234 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700235 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700236 win.updateReportedVisibility(mReportedVisibilityResults);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800237 }
238
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700239 int numInteresting = mReportedVisibilityResults.numInteresting;
240 int numVisible = mReportedVisibilityResults.numVisible;
241 int numDrawn = mReportedVisibilityResults.numDrawn;
242 boolean nowGone = mReportedVisibilityResults.nowGone;
243
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700244 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800245 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700246 if (!nowGone) {
247 // If the app is not yet gone, then it can only become visible/drawn.
248 if (!nowDrawn) {
249 nowDrawn = reportedDrawn;
250 }
251 if (!nowVisible) {
252 nowVisible = reportedVisible;
253 }
254 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800255 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800256 + numInteresting + " visible=" + numVisible);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800257 final AppWindowContainerController controller = getController();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700258 if (nowDrawn != reportedDrawn) {
259 if (nowDrawn) {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800260 if (controller != null) {
261 controller.reportWindowsDrawn();
262 }
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700263 }
264 reportedDrawn = nowDrawn;
265 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800266 if (nowVisible != reportedVisible) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700267 if (DEBUG_VISIBILITY) Slog.v(TAG,
268 "Visibility changed in " + this + ": vis=" + nowVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800269 reportedVisible = nowVisible;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800270 if (controller != null) {
271 if (nowVisible) {
272 controller.reportWindowsVisible();
273 } else {
274 controller.reportWindowsGone();
275 }
276 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800277 }
278 }
279
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700280 boolean setVisibility(WindowManager.LayoutParams lp,
281 boolean visible, int transit, boolean performLayout, boolean isVoiceInteraction) {
282
283 boolean delayed = false;
284 inPendingTransaction = false;
285
286 if (clientHidden == visible) {
287 clientHidden = !visible;
288 sendAppVisibilityToClients();
289 }
290
291 // Allow for state changes and animation to be applied if:
292 // * token is transitioning visibility state
293 // * or the token was marked as hidden and is exiting before we had a chance to play the
294 // transition animation
295 // * or this is an opening app and windows are being replaced.
296 boolean visibilityChanged = false;
297 if (hidden == visible || (hidden && mIsExiting) || (visible && waitingForReplacement())) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700298 final AccessibilityController accessibilityController = mService.mAccessibilityController;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700299 boolean changed = false;
300 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
301 "Changing app " + this + " hidden=" + hidden + " performLayout=" + performLayout);
302
303 boolean runningAppAnimation = false;
304
305 if (transit != AppTransition.TRANSIT_UNSET) {
306 if (mAppAnimator.animation == AppWindowAnimator.sDummyAnimation) {
307 mAppAnimator.setNullAnimation();
308 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700309 if (mService.applyAnimationLocked(this, lp, transit, visible, isVoiceInteraction)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700310 delayed = runningAppAnimation = true;
311 }
312 final WindowState window = findMainWindow();
313 //TODO (multidisplay): Magnification is supported only for the default display.
314 if (window != null && accessibilityController != null
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700315 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700316 accessibilityController.onAppWindowTransitionLocked(window, transit);
317 }
318 changed = true;
319 }
320
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700321 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700322 for (int i = 0; i < windowsCount; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700323 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700324 changed |= win.onAppVisibilityChanged(visible, runningAppAnimation);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700325 }
326
327 hidden = hiddenRequested = !visible;
328 visibilityChanged = true;
329 if (!visible) {
330 stopFreezingScreen(true, true);
331 } else {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700332 // If we are being set visible, and the starting window is not yet displayed,
333 // then make sure it doesn't get displayed.
334 if (startingWindow != null && !startingWindow.isDrawnLw()) {
335 startingWindow.mPolicyVisibility = false;
336 startingWindow.mPolicyVisibilityAfterAnim = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700337 }
338 }
339
340 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setVisibility: " + this
341 + ": hidden=" + hidden + " hiddenRequested=" + hiddenRequested);
342
343 if (changed) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700344 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700345 if (performLayout) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700346 mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700347 false /*updateInputWindows*/);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700348 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700349 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700350 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700351 }
352 }
353
354 if (mAppAnimator.animation != null) {
355 delayed = true;
356 }
357
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700358 for (int i = mChildren.size() - 1; i >= 0 && !delayed; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700359 if ((mChildren.get(i)).isWindowAnimationSet()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700360 delayed = true;
361 }
362 }
363
364 if (visibilityChanged) {
365 if (visible && !delayed) {
366 // The token was made immediately visible, there will be no entrance animation.
367 // We need to inform the client the enter animation was finished.
368 mEnteringAnimation = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700369 mService.mActivityManagerAppTransitionNotifier.onAppTransitionFinishedLocked(token);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700370 }
Robert Carre7cc44d2017-03-20 19:04:30 -0700371 // If we are hidden but there is no delay needed we immediately
372 // apply the Surface transaction so that the ActivityManager
373 // can have some guarantee on the Surface state
374 // following setting the visibility.
Robert Carr6914f082017-03-20 19:04:30 -0700375 if (hidden && !delayed) {
376 SurfaceControl.openTransaction();
377 for (int i = mChildren.size() - 1; i >= 0; i--) {
378 mChildren.get(i).mWinAnimator.hide("immediately hidden");
379 }
380 SurfaceControl.closeTransaction();
381 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700382
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700383 if (!mService.mClosingApps.contains(this) && !mService.mOpeningApps.contains(this)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700384 // The token is not closing nor opening, so even if there is an animation set, that
385 // doesn't mean that it goes through the normal app transition cycle so we have
386 // to inform the docked controller about visibility change.
Andrii Kulian1e32e022016-09-16 15:29:34 -0700387 // TODO(multi-display): notify docked divider on all displays where visibility was
388 // affected.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700389 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700390 .notifyAppVisibilityChanged();
Jorim Jaggi8b702ed2017-01-20 16:59:03 +0100391 mService.mTaskSnapshotController.notifyAppVisibilityChanged(this, visible);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700392 }
393 }
394
395 return delayed;
396 }
397
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800398 WindowState findMainWindow() {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700399 WindowState candidate = null;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700400 int j = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800401 while (j > 0) {
402 j--;
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700403 final WindowState win = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700404 final int type = win.mAttrs.type;
405 // No need to loop through child window as base application and starting types can't be
406 // child windows.
407 if (type == TYPE_BASE_APPLICATION || type == TYPE_APPLICATION_STARTING) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700408 // In cases where there are multiple windows, we prefer the non-exiting window. This
Sungsoo Lim0d3d1f82015-12-02 14:47:59 +0900409 // happens for example when replacing windows during an activity relaunch. When
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700410 // constructing the animation, we want the new window, not the exiting one.
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800411 if (win.mAnimatingExit) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700412 candidate = win;
413 } else {
414 return win;
415 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800416 }
417 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700418 return candidate;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800419 }
420
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800421 boolean windowsAreFocusable() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800422 return StackId.canReceiveKeys(getTask().mStack.mStackId) || mAlwaysFocusable;
Wale Ogunwaled045c822015-12-02 09:14:28 -0800423 }
424
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800425 AppWindowContainerController getController() {
426 final WindowContainerController controller = super.getController();
427 return controller != null ? (AppWindowContainerController) controller : null;
428 }
429
Wale Ogunwale571771c2016-08-26 13:18:50 -0700430 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -0700431 boolean isVisible() {
Wale Ogunwalee471be62016-10-03 07:53:55 -0700432 // If the app token isn't hidden then it is considered visible and there is no need to check
433 // its children windows to see if they are visible.
434 return !hidden;
Wale Ogunwale44f21802016-09-02 12:49:48 -0700435 }
436
437 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -0700438 void removeIfPossible() {
Craig Mautnere3119b72015-01-20 15:02:36 -0800439 mIsExiting = false;
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800440 removeAllWindowsIfPossible();
Bryce Lee6d410262017-02-28 15:30:17 -0800441 removeImmediately();
Craig Mautnere3119b72015-01-20 15:02:36 -0800442 }
443
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700444 @Override
445 boolean checkCompleteDeferredRemoval() {
446 if (mIsExiting) {
447 removeIfPossible();
448 }
449 return super.checkCompleteDeferredRemoval();
450 }
451
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700452 void onRemovedFromDisplay() {
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700453 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app token: " + this);
454
Wale Ogunwale72919d22016-12-08 18:58:50 -0800455 boolean delayed = setVisibility(null, false, TRANSIT_UNSET, true, mVoiceInteraction);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700456
457 mService.mOpeningApps.remove(this);
Jorim Jaggi1b4b23e2016-11-15 16:30:12 -0800458 mService.mUnknownAppVisibilityController.appRemoved(this);
Jorim Jaggi10abe2f2017-01-03 16:44:46 +0100459 mService.mTaskSnapshotController.onAppRemoved(this);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700460 waitingToShow = false;
461 if (mService.mClosingApps.contains(this)) {
462 delayed = true;
463 } else if (mService.mAppTransition.isTransitionSet()) {
464 mService.mClosingApps.add(this);
465 delayed = true;
466 }
467
468 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app " + this + " delayed=" + delayed
469 + " animation=" + mAppAnimator.animation + " animating=" + mAppAnimator.animating);
470
471 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM, "removeAppToken: "
472 + this + " delayed=" + delayed + " Callers=" + Debug.getCallers(4));
473
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800474 if (startingData != null && getController() != null) {
475 getController().removeStartingWindow();
476 }
477
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800478 final TaskStack stack = getTask().mStack;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700479 if (delayed && !isEmpty()) {
480 // set the token aside because it has an active animation to be finished
481 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM,
482 "removeAppToken make exiting: " + this);
483 stack.mExitingAppTokens.add(this);
484 mIsExiting = true;
485 } else {
486 // Make sure there is no animation running on this token, so any windows associated
487 // with it will be removed as soon as their animations are complete
488 mAppAnimator.clearAnimation();
489 mAppAnimator.animating = false;
490 removeIfPossible();
491 }
492
493 removed = true;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700494 stopFreezingScreen(true, true);
Bryce Lee6d410262017-02-28 15:30:17 -0800495
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700496 if (mService.mFocusedApp == this) {
497 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "Removing focused app token:" + this);
498 mService.mFocusedApp = null;
499 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
500 mService.mInputMonitor.setFocusedAppLw(null);
501 }
502
503 if (!delayed) {
504 updateReportedVisibilityLocked();
505 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700506 }
507
Chong Zhange05bcb12016-07-26 17:47:29 -0700508 void clearAnimatingFlags() {
Chong Zhangb0d26702016-08-12 16:03:29 -0700509 boolean wallpaperMightChange = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700510 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700511 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700512 wallpaperMightChange |= win.clearAnimatingFlags();
Chong Zhange05bcb12016-07-26 17:47:29 -0700513 }
Chong Zhangb0d26702016-08-12 16:03:29 -0700514 if (wallpaperMightChange) {
515 requestUpdateWallpaperIfNeeded();
516 }
Chong Zhange05bcb12016-07-26 17:47:29 -0700517 }
518
Robert Carre12aece2016-02-02 22:43:27 -0800519 void destroySurfaces() {
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700520 destroySurfaces(false /*cleanupOnResume*/);
521 }
522
523 /**
524 * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure
525 * the client has finished with them.
526 *
527 * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If
528 * set to true, destroy only surfaces of removed windows, and clear relevant flags of the
529 * others so that they are ready to be reused. If set to false (common case), destroy all
530 * surfaces that's eligible, if the app is already stopped.
531 */
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700532 private void destroySurfaces(boolean cleanupOnResume) {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700533 boolean destroyedSomething = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700534 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700535 final WindowState win = mChildren.get(i);
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700536 destroyedSomething |= win.destroySurface(cleanupOnResume, mAppStopped);
Robert Carre12aece2016-02-02 22:43:27 -0800537 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700538 if (destroyedSomething) {
539 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700540 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Robert Carre12aece2016-02-02 22:43:27 -0800541 }
542 }
543
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800544 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700545 * Notify that the app is now resumed, and it was not stopped before, perform a clean
546 * up of the surfaces
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800547 */
Chong Zhangad24f962016-08-25 12:12:33 -0700548 void notifyAppResumed(boolean wasStopped, boolean allowSavedSurface) {
549 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped
550 + " allowSavedSurface=" + allowSavedSurface + " " + this);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700551 mAppStopped = false;
552 if (!wasStopped) {
553 destroySurfaces(true /*cleanupOnResume*/);
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800554 }
Chong Zhangad24f962016-08-25 12:12:33 -0700555 if (!allowSavedSurface) {
556 destroySavedSurfaces();
557 }
Robert Carre12aece2016-02-02 22:43:27 -0800558 }
559
Chong Zhangbef461f2015-10-27 11:38:24 -0700560 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700561 * Notify that the app has stopped, and it is okay to destroy any surfaces which were
562 * keeping alive in case they were still being used.
563 */
564 void notifyAppStopped() {
565 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this);
566 mAppStopped = true;
567 destroySurfaces();
568 // Remove any starting window that was added for this app if they are still around.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800569 if (getController() != null) {
570 getController().removeStartingWindow();
571 }
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700572 }
573
574 /**
Chong Zhangbef461f2015-10-27 11:38:24 -0700575 * Checks whether we should save surfaces for this app.
576 *
577 * @return true if the surfaces should be saved, false otherwise.
578 */
579 boolean shouldSaveSurface() {
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800580 // We want to save surface if the app's windows are "allDrawn".
581 // (If we started entering animation early with saved surfaces, allDrawn
582 // should have been restored to true. So we'll save again in that case
583 // even if app didn't actually finish drawing.)
584 return allDrawn;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800585 }
586
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700587 private boolean canRestoreSurfaces() {
588 for (int i = mChildren.size() -1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700589 final WindowState w = mChildren.get(i);
Chong Zhang92147042016-05-09 12:47:11 -0700590 if (w.canRestoreSurface()) {
Robert Carr13f7be9e2015-12-02 18:39:45 -0800591 return true;
592 }
Chong Zhangbef461f2015-10-27 11:38:24 -0700593 }
594 return false;
595 }
596
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700597 private void clearWasVisibleBeforeClientHidden() {
598 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700599 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700600 w.clearWasVisibleBeforeClientHidden();
Chong Zhang92147042016-05-09 12:47:11 -0700601 }
602 }
603
Chong Zhang8e4bda92016-05-04 15:08:18 -0700604 /**
605 * Whether the app has some window that is invisible in layout, but
606 * animating with saved surface.
607 */
608 boolean isAnimatingInvisibleWithSavedSurface() {
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);
Chong Zhang8e4bda92016-05-04 15:08:18 -0700611 if (w.isAnimatingInvisibleWithSavedSurface()) {
612 return true;
613 }
614 }
615 return false;
616 }
617
618 /**
619 * Hide all window surfaces that's still invisible in layout but animating
620 * with a saved surface, and mark them destroying.
621 */
622 void stopUsingSavedSurfaceLocked() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700623 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700624 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700625 w.stopUsingSavedSurface();
Chong Zhang8e4bda92016-05-04 15:08:18 -0700626 }
627 destroySurfaces();
628 }
629
Chong Zhangf58631a2016-05-24 16:02:10 -0700630 void markSavedSurfaceExiting() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700631 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700632 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700633 w.markSavedSurfaceExiting();
Chong Zhangf58631a2016-05-24 16:02:10 -0700634 }
635 }
636
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700637 void restoreSavedSurfaceForInterestingWindows() {
Chong Zhang92147042016-05-09 12:47:11 -0700638 if (!canRestoreSurfaces()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700639 clearWasVisibleBeforeClientHidden();
Chong Zhangbef461f2015-10-27 11:38:24 -0700640 return;
641 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700642
643 // Check if all interesting windows are drawn and we can mark allDrawn=true.
644 int interestingNotDrawn = -1;
645
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700646 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700647 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700648 interestingNotDrawn = w.restoreSavedSurfaceForInterestingWindow();
Chong Zhangbef461f2015-10-27 11:38:24 -0700649 }
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800650
Chong Zhang92147042016-05-09 12:47:11 -0700651 if (!allDrawn) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700652 allDrawn = (interestingNotDrawn == 0);
Chong Zhang92147042016-05-09 12:47:11 -0700653 if (allDrawn) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700654 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Chong Zhang92147042016-05-09 12:47:11 -0700655 }
656 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700657 clearWasVisibleBeforeClientHidden();
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800658
659 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700660 "restoreSavedSurfaceForInterestingWindows: " + this + " allDrawn=" + allDrawn
661 + " interestingNotDrawn=" + interestingNotDrawn);
Chong Zhangbef461f2015-10-27 11:38:24 -0700662 }
663
664 void destroySavedSurfaces() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700665 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700666 final WindowState win = mChildren.get(i);
Robert Carr13f7be9e2015-12-02 18:39:45 -0800667 win.destroySavedSurface();
Chong Zhangbef461f2015-10-27 11:38:24 -0700668 }
Chong Zhang92147042016-05-09 12:47:11 -0700669 }
670
671 void clearAllDrawn() {
672 allDrawn = false;
673 deferClearAllDrawn = false;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700674 allDrawnExcludingSaved = false;
Chong Zhangbef461f2015-10-27 11:38:24 -0700675 }
676
Bryce Lee6d410262017-02-28 15:30:17 -0800677 Task getTask() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800678 return (Task) getParent();
Bryce Lee6d410262017-02-28 15:30:17 -0800679 }
680
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800681 TaskStack getStack() {
682 final Task task = getTask();
683 if (task != null) {
684 return task.mStack;
685 } else {
686 return null;
687 }
688 }
689
Bryce Lee6d410262017-02-28 15:30:17 -0800690 @Override
691 void onParentSet() {
692 super.onParentSet();
693
694 // When the associated task is {@code null}, the {@link AppWindowToken} can no longer
695 // access visual elements like the {@link DisplayContent}. We must remove any associations
696 // such as animations.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800697 if (!mReparenting) {
698 final Task task = getTask();
699 if (task == null) {
700 // It is possible we have been marked as a closing app earlier. We must remove ourselves
701 // from this list so we do not participate in any future animations.
702 mService.mClosingApps.remove(this);
703 } else if (task.mStack != null) {
704 task.mStack.mExitingAppTokens.remove(this);
705 }
Bryce Lee6d410262017-02-28 15:30:17 -0800706 }
707 }
708
Wale Ogunwalefa854eb2016-09-20 13:43:52 -0700709 void postWindowRemoveStartingWindowCleanup(WindowState win) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700710 // TODO: Something smells about the code below...Is there a better way?
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700711 if (startingWindow == win) {
712 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800713 if (getController() != null) {
714 getController().removeStartingWindow();
715 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700716 } else if (mChildren.size() == 0 && startingData != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700717 // If this is the last window and we had requested a starting transition window,
718 // well there is no point now.
Jorim Jaggi02886a82016-12-06 09:10:06 -0800719 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingData");
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700720 startingData = null;
Jorim Jaggi829b9cd2017-01-23 16:20:53 +0100721 } else if (mChildren.size() == 1 && startingSurface != null && !isRelaunching()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700722 // If this is the last window except for a starting transition window,
723 // we need to get rid of the starting transition.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800724 if (getController() != null) {
725 getController().removeStartingWindow();
726 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700727 }
728 }
729
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700730 void removeDeadWindows() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700731 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700732 WindowState win = mChildren.get(winNdx);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800733 if (win.mAppDied) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700734 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700735 "removeDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800736 // Set mDestroying, we don't want any animation or delayed removal here.
737 win.mDestroying = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700738 // Also removes child windows.
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700739 win.removeIfPossible();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800740 }
741 }
742 }
743
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700744 boolean hasWindowsAlive() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700745 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700746 // No need to loop through child windows as the answer should be the same as that of the
747 // parent window.
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700748 if (!(mChildren.get(i)).mAppDied) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700749 return true;
750 }
751 }
752 return false;
753 }
754
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700755 void setWillReplaceWindows(boolean animate) {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700756 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
757 "Marking app token " + this + " with replacing windows.");
Robert Carra1eb4392015-12-10 12:43:51 -0800758
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700759 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700760 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700761 w.setWillReplaceWindow(animate);
Robert Carra1eb4392015-12-10 12:43:51 -0800762 }
763 if (animate) {
764 // Set-up dummy animation so we can start treating windows associated with this
765 // token like they are in transition before the new app window is ready for us to
766 // run the real transition animation.
767 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700768 "setWillReplaceWindow() Setting dummy animation on: " + this);
Robert Carra1eb4392015-12-10 12:43:51 -0800769 mAppAnimator.setDummyAnimation();
770 }
771 }
772
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700773 void setWillReplaceChildWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700774 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this
Robert Carr23fa16b2016-01-13 13:19:58 -0800775 + " with replacing child windows.");
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700776 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700777 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700778 w.setWillReplaceChildWindows();
Robert Carr23fa16b2016-01-13 13:19:58 -0800779 }
780 }
781
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700782 void clearWillReplaceWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700783 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
784 "Resetting app token " + this + " of replacing window marks.");
Chong Zhangf596cd52016-01-05 13:42:44 -0800785
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700786 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700787 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700788 w.clearWillReplaceWindow();
Chong Zhangf596cd52016-01-05 13:42:44 -0800789 }
790 }
791
Chong Zhang4d7369a2016-04-25 16:09:14 -0700792 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700793 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700794 final WindowState w = mChildren.get(i);
Chong Zhang4d7369a2016-04-25 16:09:14 -0700795 w.requestUpdateWallpaperIfNeeded();
796 }
797 }
798
Chong Zhangd78ddb42016-03-02 17:01:14 -0800799 boolean isRelaunching() {
800 return mPendingRelaunchCount > 0;
801 }
802
803 void startRelaunching() {
804 if (canFreezeBounds()) {
805 freezeBounds();
806 }
Robert Carrd5c7dd62017-03-08 10:39:30 -0800807
808 // In the process of tearing down before relaunching, the app will
809 // try and clean up it's child surfaces. We need to prevent this from
810 // happening, so we sever the children, transfering their ownership
811 // from the client it-self to the parent surface (owned by us).
812 for (int i = mChildren.size() - 1; i >= 0; i--) {
813 final WindowState w = mChildren.get(i);
814 w.mWinAnimator.detachChildren();
815 }
816
Chong Zhangd78ddb42016-03-02 17:01:14 -0800817 mPendingRelaunchCount++;
818 }
819
820 void finishRelaunching() {
821 if (canFreezeBounds()) {
822 unfreezeBounds();
823 }
824 if (mPendingRelaunchCount > 0) {
825 mPendingRelaunchCount--;
826 }
827 }
828
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700829 void clearRelaunching() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700830 if (mPendingRelaunchCount == 0) {
831 return;
832 }
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700833 if (canFreezeBounds()) {
834 unfreezeBounds();
835 }
836 mPendingRelaunchCount = 0;
837 }
838
Wale Ogunwale07bcab72016-10-14 15:30:09 -0700839 /**
840 * Returns true if the new child window we are adding to this token is considered greater than
841 * the existing child window in this token in terms of z-order.
842 */
843 @Override
844 protected boolean isFirstChildWindowGreaterThanSecond(WindowState newWindow,
845 WindowState existingWindow) {
846 final int type1 = newWindow.mAttrs.type;
847 final int type2 = existingWindow.mAttrs.type;
848
849 // Base application windows should be z-ordered BELOW all other windows in the app token.
850 if (type1 == TYPE_BASE_APPLICATION && type2 != TYPE_BASE_APPLICATION) {
851 return false;
852 } else if (type1 != TYPE_BASE_APPLICATION && type2 == TYPE_BASE_APPLICATION) {
853 return true;
854 }
855
856 // Starting windows should be z-ordered ABOVE all other windows in the app token.
857 if (type1 == TYPE_APPLICATION_STARTING && type2 != TYPE_APPLICATION_STARTING) {
858 return true;
859 } else if (type1 != TYPE_APPLICATION_STARTING && type2 == TYPE_APPLICATION_STARTING) {
860 return false;
861 }
862
863 // Otherwise the new window is greater than the existing window.
864 return true;
865 }
866
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700867 @Override
Robert Carra1eb4392015-12-10 12:43:51 -0800868 void addWindow(WindowState w) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700869 super.addWindow(w);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700870
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700871 boolean gotReplacementWindow = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700872 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700873 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700874 gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w);
875 }
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700876
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700877 // if we got a replacement window, reset the timeout to give drawing more time
878 if (gotReplacementWindow) {
879 mService.scheduleWindowReplacementTimeouts(this);
Robert Carra1eb4392015-12-10 12:43:51 -0800880 }
Jorim Jaggife762342016-10-13 14:33:27 +0200881 checkKeyguardFlagsChanged();
882 }
883
884 @Override
885 void removeChild(WindowState child) {
886 super.removeChild(child);
887 checkKeyguardFlagsChanged();
Robert Carra1eb4392015-12-10 12:43:51 -0800888 }
889
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700890 private boolean waitingForReplacement() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700891 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700892 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700893 if (candidate.waitingForReplacement()) {
Robert Carra1eb4392015-12-10 12:43:51 -0800894 return true;
895 }
896 }
897 return false;
898 }
899
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700900 void onWindowReplacementTimeout() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700901 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700902 (mChildren.get(i)).onWindowReplacementTimeout();
Robert Carra1eb4392015-12-10 12:43:51 -0800903 }
904 }
905
Winson Chung30480042017-01-26 10:55:34 -0800906 void reparent(Task task, int position) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800907 final Task currentTask = getTask();
908 if (task == currentTask) {
Winson Chung30480042017-01-26 10:55:34 -0800909 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800910 "window token=" + this + " already child of task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -0800911 }
Bryce Lee6d410262017-02-28 15:30:17 -0800912
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800913 if (currentTask.mStack != task.mStack) {
Bryce Lee6d410262017-02-28 15:30:17 -0800914 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800915 "window token=" + this + " current task=" + currentTask
Bryce Lee6d410262017-02-28 15:30:17 -0800916 + " belongs to a different stack than " + task);
917 }
918
Winson Chung30480042017-01-26 10:55:34 -0800919 if (DEBUG_ADD_REMOVE) Slog.i(TAG, "reParentWindowToken: removing window token=" + this
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800920 + " from task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -0800921 final DisplayContent prevDisplayContent = getDisplayContent();
922
Bryce Lee6d410262017-02-28 15:30:17 -0800923 mReparenting = true;
924
Winson Chung30480042017-01-26 10:55:34 -0800925 getParent().removeChild(this);
926 task.addChild(this, position);
927
Bryce Lee6d410262017-02-28 15:30:17 -0800928 mReparenting = false;
929
Winson Chung30480042017-01-26 10:55:34 -0800930 // Relayout display(s).
931 final DisplayContent displayContent = task.getDisplayContent();
932 displayContent.setLayoutNeeded();
933 if (prevDisplayContent != displayContent) {
934 onDisplayChanged(displayContent);
935 prevDisplayContent.setLayoutNeeded();
936 }
937 }
938
Chong Zhangd78ddb42016-03-02 17:01:14 -0800939 private boolean canFreezeBounds() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800940 final Task task = getTask();
941
Chong Zhangd78ddb42016-03-02 17:01:14 -0800942 // For freeform windows, we can't freeze the bounds at the moment because this would make
943 // the resizing unresponsive.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800944 return task != null && !task.inFreeformWorkspace();
Chong Zhangd78ddb42016-03-02 17:01:14 -0800945 }
946
Jorim Jaggi0429f352015-12-22 16:29:16 +0100947 /**
948 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
949 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
950 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
951 * with a queue.
952 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800953 private void freezeBounds() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800954 final Task task = getTask();
955 mFrozenBounds.offer(new Rect(task.mPreparedFrozenBounds));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700956
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800957 if (task.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) {
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700958 // We didn't call prepareFreezingBounds on the task, so use the current value.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800959 mFrozenMergedConfig.offer(new Configuration(task.getConfiguration()));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700960 } else {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800961 mFrozenMergedConfig.offer(new Configuration(task.mPreparedFrozenMergedConfig));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700962 }
Andrii Kulianb10330d2016-09-16 13:51:46 -0700963 // Calling unset() to make it equal to Configuration.EMPTY.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800964 task.mPreparedFrozenMergedConfig.unset();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100965 }
966
967 /**
968 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
969 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800970 private void unfreezeBounds() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700971 if (!mFrozenBounds.isEmpty()) {
972 mFrozenBounds.remove();
973 }
974 if (!mFrozenMergedConfig.isEmpty()) {
975 mFrozenMergedConfig.remove();
976 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700977 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700978 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700979 win.onUnfreezeBounds();
Jorim Jaggi4846ee32016-01-07 17:39:12 +0100980 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700981 mService.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100982 }
983
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700984 void setAppLayoutChanges(int changes, String reason) {
985 if (!mChildren.isEmpty()) {
986 final DisplayContent dc = getDisplayContent();
987 dc.pendingLayoutChanges |= changes;
988 if (DEBUG_LAYOUT_REPEATS) {
989 mService.mWindowPlacerLocked.debugLayoutRepeats(reason, dc.pendingLayoutChanges);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700990 }
991 }
992 }
993
994 void removeReplacedWindowIfNeeded(WindowState replacement) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700995 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700996 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700997 if (win.removeReplacedWindowIfNeeded(replacement)) {
998 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700999 }
1000 }
1001 }
1002
1003 void startFreezingScreen() {
1004 if (DEBUG_ORIENTATION) logWithStack(TAG, "Set freezing of " + appToken + ": hidden="
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001005 + hidden + " freezing=" + mAppAnimator.freezingScreen + " hiddenRequested="
1006 + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001007 if (!hiddenRequested) {
1008 if (!mAppAnimator.freezingScreen) {
1009 mAppAnimator.freezingScreen = true;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001010 mService.registerAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001011 mAppAnimator.lastFreezeDuration = 0;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001012 mService.mAppsFreezingScreen++;
1013 if (mService.mAppsFreezingScreen == 1) {
1014 mService.startFreezingDisplayLocked(false, 0, 0);
1015 mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT);
1016 mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001017 }
1018 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001019 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001020 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001021 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001022 w.onStartFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001023 }
1024 }
1025 }
1026
1027 void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) {
1028 if (!mAppAnimator.freezingScreen) {
1029 return;
1030 }
1031 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + this + " force=" + force);
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001032 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001033 boolean unfrozeWindows = false;
1034 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001035 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001036 unfrozeWindows |= w.onStopFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001037 }
1038 if (force || unfrozeWindows) {
1039 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this);
1040 mAppAnimator.freezingScreen = false;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001041 mService.unregisterAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001042 mAppAnimator.lastFreezeDuration =
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001043 (int)(SystemClock.elapsedRealtime() - mService.mDisplayFreezeTime);
1044 mService.mAppsFreezingScreen--;
1045 mService.mLastFinishedFreezeSource = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001046 }
1047 if (unfreezeSurfaceNow) {
1048 if (unfrozeWindows) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001049 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001050 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001051 mService.stopFreezingDisplayLocked();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001052 }
1053 }
1054
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001055 @Override
1056 public void onAppFreezeTimeout() {
1057 Slog.w(TAG_WM, "Force clearing freeze: " + this);
1058 stopFreezingScreen(true, true);
1059 }
1060
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001061 boolean transferStartingWindow(IBinder transferFrom) {
Wale Ogunwale02319a62016-09-26 15:21:22 -07001062 final AppWindowToken fromToken = getDisplayContent().getAppWindowToken(transferFrom);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001063 if (fromToken == null) {
1064 return false;
1065 }
1066
1067 final WindowState tStartingWindow = fromToken.startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001068 if (tStartingWindow != null && fromToken.startingSurface != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001069 // In this case, the starting icon has already been displayed, so start
1070 // letting windows get shown immediately without any more transitions.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001071 mService.mSkipAppTransitionAnimation = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001072
1073 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow
1074 + " from " + fromToken + " to " + this);
1075
1076 final long origId = Binder.clearCallingIdentity();
1077
1078 // Transfer the starting window over to the new token.
1079 startingData = fromToken.startingData;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001080 startingSurface = fromToken.startingSurface;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001081 startingDisplayed = fromToken.startingDisplayed;
1082 fromToken.startingDisplayed = false;
1083 startingWindow = tStartingWindow;
1084 reportedVisible = fromToken.reportedVisible;
1085 fromToken.startingData = null;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001086 fromToken.startingSurface = null;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001087 fromToken.startingWindow = null;
1088 fromToken.startingMoved = true;
1089 tStartingWindow.mToken = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001090 tStartingWindow.mAppToken = this;
1091
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001092 if (DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001093 "Removing starting " + tStartingWindow + " from " + fromToken);
Wale Ogunwalefa854eb2016-09-20 13:43:52 -07001094 fromToken.removeChild(tStartingWindow);
1095 fromToken.postWindowRemoveStartingWindowCleanup(tStartingWindow);
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001096 addWindow(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001097
1098 // Propagate other interesting state between the tokens. If the old token is displayed,
1099 // we should immediately force the new one to be displayed. If it is animating, we need
1100 // to move that animation to the new one.
1101 if (fromToken.allDrawn) {
1102 allDrawn = true;
1103 deferClearAllDrawn = fromToken.deferClearAllDrawn;
1104 }
1105 if (fromToken.firstWindowDrawn) {
1106 firstWindowDrawn = true;
1107 }
1108 if (!fromToken.hidden) {
1109 hidden = false;
1110 hiddenRequested = false;
1111 }
1112 if (clientHidden != fromToken.clientHidden) {
1113 clientHidden = fromToken.clientHidden;
1114 sendAppVisibilityToClients();
1115 }
1116 fromToken.mAppAnimator.transferCurrentAnimation(
1117 mAppAnimator, tStartingWindow.mWinAnimator);
1118
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001119 mService.updateFocusedWindowLocked(
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001120 UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/);
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001121 getDisplayContent().setLayoutNeeded();
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001122 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001123 Binder.restoreCallingIdentity(origId);
1124 return true;
1125 } else if (fromToken.startingData != null) {
1126 // The previous app was getting ready to show a
1127 // starting window, but hasn't yet done so. Steal it!
1128 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1129 "Moving pending starting from " + fromToken + " to " + this);
1130 startingData = fromToken.startingData;
1131 fromToken.startingData = null;
1132 fromToken.startingMoved = true;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001133 if (getController() != null) {
1134 getController().scheduleAddStartingWindow();
1135 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001136 return true;
1137 }
1138
1139 final AppWindowAnimator tAppAnimator = fromToken.mAppAnimator;
1140 final AppWindowAnimator wAppAnimator = mAppAnimator;
1141 if (tAppAnimator.thumbnail != null) {
1142 // The old token is animating with a thumbnail, transfer that to the new token.
1143 if (wAppAnimator.thumbnail != null) {
1144 wAppAnimator.thumbnail.destroy();
1145 }
1146 wAppAnimator.thumbnail = tAppAnimator.thumbnail;
1147 wAppAnimator.thumbnailLayer = tAppAnimator.thumbnailLayer;
1148 wAppAnimator.thumbnailAnimation = tAppAnimator.thumbnailAnimation;
1149 tAppAnimator.thumbnail = null;
1150 }
1151 return false;
1152 }
1153
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001154 boolean isLastWindow(WindowState win) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001155 return mChildren.size() == 1 && mChildren.get(0) == win;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001156 }
1157
1158 void setAllAppWinAnimators() {
1159 final ArrayList<WindowStateAnimator> allAppWinAnimators = mAppAnimator.mAllAppWinAnimators;
1160 allAppWinAnimators.clear();
1161
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001162 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001163 for (int j = 0; j < windowsCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001164 (mChildren.get(j)).addWinAnimatorToList(allAppWinAnimators);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001165 }
1166 }
1167
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001168 @Override
1169 void onAppTransitionDone() {
1170 sendingToBottom = false;
1171 }
1172
Wale Ogunwale51362492016-09-08 17:49:17 -07001173 /**
1174 * We override because this class doesn't want its children affecting its reported orientation
1175 * in anyway.
1176 */
1177 @Override
1178 int getOrientation() {
Bryce Leea163b762017-01-24 11:05:01 -08001179 if (fillsParent() && (isVisible() || mService.mOpeningApps.contains(this))) {
1180 return mOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001181 }
Bryce Leea163b762017-01-24 11:05:01 -08001182
1183 return SCREEN_ORIENTATION_UNSET;
Wale Ogunwale51362492016-09-08 17:49:17 -07001184 }
1185
Wale Ogunwaleb198b742016-12-01 08:44:09 -08001186 /** Returns the app's preferred orientation regardless of its currently visibility state. */
1187 int getOrientationIgnoreVisibility() {
1188 return mOrientation;
1189 }
1190
Craig Mautnerdbb79912012-03-01 18:59:14 -08001191 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001192 void checkAppWindowsReadyToShow() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001193 if (allDrawn == mAppAnimator.allDrawn) {
1194 return;
1195 }
1196
1197 mAppAnimator.allDrawn = allDrawn;
1198 if (!allDrawn) {
1199 return;
1200 }
1201
1202 // The token has now changed state to having all windows shown... what to do, what to do?
1203 if (mAppAnimator.freezingScreen) {
1204 mAppAnimator.showAllWindowsLocked();
1205 stopFreezingScreen(false, true);
1206 if (DEBUG_ORIENTATION) Slog.i(TAG,
1207 "Setting mOrientationChangeComplete=true because wtoken " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001208 + " numInteresting=" + mNumInterestingWindows + " numDrawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001209 // This will set mOrientationChangeComplete and cause a pass through layout.
1210 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001211 "checkAppWindowsReadyToShow: freezingScreen");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001212 } else {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001213 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001214
1215 // We can now show all of the drawn windows!
1216 if (!mService.mOpeningApps.contains(this)) {
1217 mService.mAnimator.orAnimating(mAppAnimator.showAllWindowsLocked());
1218 }
1219 }
1220 }
1221
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001222 void updateAllDrawn(DisplayContent dc) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001223 if (!allDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001224 final int numInteresting = mNumInterestingWindows;
1225 if (numInteresting > 0 && mNumDrawnWindows >= numInteresting) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001226 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawn: " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001227 + " interesting=" + numInteresting + " drawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001228 allDrawn = true;
1229 // Force an additional layout pass where
1230 // WindowStateAnimator#commitFinishDrawingLocked() will call performShowLocked().
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001231 dc.setLayoutNeeded();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001232 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
1233 }
1234 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001235
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001236 if (!allDrawnExcludingSaved) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001237 int numInteresting = mNumInterestingWindowsExcludingSaved;
1238 if (numInteresting > 0 && mNumDrawnWindowsExcludingSaved >= numInteresting) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001239 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawnExcludingSaved: " + this
1240 + " interesting=" + numInteresting
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001241 + " drawn=" + mNumDrawnWindowsExcludingSaved);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001242 allDrawnExcludingSaved = true;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001243 dc.setLayoutNeeded();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001244 if (isAnimatingInvisibleWithSavedSurface()
1245 && !mService.mFinishedEarlyAnim.contains(this)) {
1246 mService.mFinishedEarlyAnim.add(this);
1247 }
1248 }
1249 }
1250 }
1251
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001252 /**
1253 * Updated this app token tracking states for interesting and drawn windows based on the window.
1254 *
1255 * @return Returns true if the input window is considered interesting and drawn while all the
1256 * windows in this app token where not considered drawn as of the last pass.
1257 */
1258 boolean updateDrawnWindowStates(WindowState w) {
1259 if (DEBUG_STARTING_WINDOW && w == startingWindow) {
1260 Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" + w.isOnScreen()
1261 + " allDrawn=" + allDrawn + " freezingScreen=" + mAppAnimator.freezingScreen);
1262 }
1263
1264 if (allDrawn && allDrawnExcludingSaved && !mAppAnimator.freezingScreen) {
1265 return false;
1266 }
1267
1268 if (mLastTransactionSequence != mService.mTransactionSequence) {
1269 mLastTransactionSequence = mService.mTransactionSequence;
1270 mNumInterestingWindows = mNumDrawnWindows = 0;
1271 mNumInterestingWindowsExcludingSaved = 0;
1272 mNumDrawnWindowsExcludingSaved = 0;
1273 startingDisplayed = false;
1274 }
1275
1276 final WindowStateAnimator winAnimator = w.mWinAnimator;
1277
1278 boolean isInterestingAndDrawn = false;
1279
1280 if (!allDrawn && w.mightAffectAllDrawn(false /* visibleOnly */)) {
1281 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
1282 Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw()
1283 + ", isAnimationSet=" + winAnimator.isAnimationSet());
1284 if (!w.isDrawnLw()) {
1285 Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController
1286 + " pv=" + w.mPolicyVisibility
1287 + " mDrawState=" + winAnimator.drawStateToString()
1288 + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested
1289 + " a=" + winAnimator.mAnimating);
1290 }
1291 }
1292
1293 if (w != startingWindow) {
1294 if (w.isInteresting()) {
1295 mNumInterestingWindows++;
1296 if (w.isDrawnLw()) {
1297 mNumDrawnWindows++;
1298
1299 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, "tokenMayBeDrawn: "
1300 + this + " w=" + w + " numInteresting=" + mNumInterestingWindows
1301 + " freezingScreen=" + mAppAnimator.freezingScreen
1302 + " mAppFreezing=" + w.mAppFreezing);
1303
1304 isInterestingAndDrawn = true;
1305 }
1306 }
1307 } else if (w.isDrawnLw()) {
Jorim Jaggi3878ca32017-02-02 17:13:05 -08001308 if (getController() != null) {
1309 getController().reportStartingWindowDrawn();
1310 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001311 startingDisplayed = true;
1312 }
1313 }
1314
1315 if (!allDrawnExcludingSaved && w.mightAffectAllDrawn(true /* visibleOnly */)) {
1316 if (w != startingWindow && w.isInteresting()) {
1317 mNumInterestingWindowsExcludingSaved++;
1318 if (w.isDrawnLw() && !w.isAnimatingWithSavedSurface()) {
1319 mNumDrawnWindowsExcludingSaved++;
1320
1321 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
1322 "tokenMayBeDrawnExcludingSaved: " + this + " w=" + w
1323 + " numInteresting=" + mNumInterestingWindowsExcludingSaved
1324 + " freezingScreen=" + mAppAnimator.freezingScreen
1325 + " mAppFreezing=" + w.mAppFreezing);
1326
1327 isInterestingAndDrawn = true;
1328 }
1329 }
1330 }
1331
1332 return isInterestingAndDrawn;
1333 }
1334
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001335 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001336 void stepAppWindowsAnimation(long currentTime) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001337 mAppAnimator.wasAnimating = mAppAnimator.animating;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001338 if (mAppAnimator.stepAnimationLocked(currentTime)) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001339 mAppAnimator.animating = true;
1340 mService.mAnimator.setAnimating(true);
1341 mService.mAnimator.mAppWindowAnimating = true;
1342 } else if (mAppAnimator.wasAnimating) {
1343 // stopped animating, do one more pass through the layout
Wale Ogunwale1e129a42016-11-21 13:03:47 -08001344 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
1345 DEBUG_LAYOUT_REPEATS ? "appToken " + this + " done" : null);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001346 if (DEBUG_ANIM) Slog.v(TAG, "updateWindowsApps...: done animating " + this);
1347 }
1348 }
1349
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001350 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001351 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001352 // For legacy reasons we process the TaskStack.mExitingAppTokens first in DisplayContent
1353 // before the non-exiting app tokens. So, we skip the exiting app tokens here.
1354 // TODO: Investigate if we need to continue to do this or if we can just process them
1355 // in-order.
1356 if (mIsExiting && !waitingForReplacement()) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001357 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001358 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001359 return forAllWindowsUnchecked(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001360 }
1361
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001362 boolean forAllWindowsUnchecked(ToBooleanFunction<WindowState> callback,
1363 boolean traverseTopToBottom) {
1364 return super.forAllWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001365 }
1366
1367 @Override
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001368 AppWindowToken asAppWindowToken() {
1369 // I am an app window token!
1370 return this;
1371 }
1372
1373 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -07001374 boolean fillsParent() {
1375 return mFillsParent;
1376 }
1377
1378 void setFillsParent(boolean fillsParent) {
1379 mFillsParent = fillsParent;
1380 }
1381
Jorim Jaggife762342016-10-13 14:33:27 +02001382 boolean containsDismissKeyguardWindow() {
1383 for (int i = mChildren.size() - 1; i >= 0; i--) {
1384 if ((mChildren.get(i).mAttrs.flags & FLAG_DISMISS_KEYGUARD) != 0) {
1385 return true;
1386 }
1387 }
1388 return false;
1389 }
1390
1391 boolean containsShowWhenLockedWindow() {
1392 for (int i = mChildren.size() - 1; i >= 0; i--) {
1393 if ((mChildren.get(i).mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
1394 return true;
1395 }
1396 }
1397 return false;
1398 }
1399
1400 void checkKeyguardFlagsChanged() {
1401 final boolean containsDismissKeyguard = containsDismissKeyguardWindow();
1402 final boolean containsShowWhenLocked = containsShowWhenLockedWindow();
1403 if (containsDismissKeyguard != mLastContainsDismissKeyguardWindow
1404 || containsShowWhenLocked != mLastContainsShowWhenLockedWindow) {
1405 mService.notifyKeyguardFlagsChanged(null /* callback */);
1406 }
1407 mLastContainsDismissKeyguardWindow = containsDismissKeyguard;
1408 mLastContainsShowWhenLockedWindow = containsShowWhenLocked;
1409 }
1410
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001411 WindowState getImeTargetBelowWindow(WindowState w) {
1412 final int index = mChildren.indexOf(w);
1413 if (index > 0) {
1414 final WindowState target = mChildren.get(index - 1);
1415 if (target.canBeImeTarget()) {
1416 return target;
1417 }
1418 }
1419 return null;
1420 }
1421
1422 WindowState getHighestAnimLayerWindow(WindowState currentTarget) {
1423 WindowState candidate = null;
1424 for (int i = mChildren.indexOf(currentTarget); i >= 0; i--) {
1425 final WindowState w = mChildren.get(i);
1426 if (w.mRemoved) {
1427 continue;
1428 }
1429 if (candidate == null || w.mWinAnimator.mAnimLayer >
1430 candidate.mWinAnimator.mAnimLayer) {
1431 candidate = w;
1432 }
1433 }
1434 return candidate;
1435 }
1436
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001437 void setDisablePreviewSnapshots(boolean disable) {
1438 mDisbalePreviewScreenshots = disable;
1439 }
1440
1441 boolean shouldDisablePreviewScreenshots() {
1442 return mDisbalePreviewScreenshots;
1443 }
1444
Wale Ogunwale51362492016-09-08 17:49:17 -07001445 @Override
Robert Carrdee1b3f2017-02-27 11:33:33 -08001446 int getAnimLayerAdjustment() {
1447 return mAppAnimator.animLayerAdjustment;
1448 }
1449
1450 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001451 void dump(PrintWriter pw, String prefix) {
1452 super.dump(pw, prefix);
1453 if (appToken != null) {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001454 pw.println(prefix + "app=true mVoiceInteraction=" + mVoiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001455 }
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001456 pw.print(prefix); pw.print("task="); pw.println(getTask());
Wale Ogunwale51362492016-09-08 17:49:17 -07001457 pw.print(prefix); pw.print(" mFillsParent="); pw.print(mFillsParent);
1458 pw.print(" mOrientation="); pw.println(mOrientation);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001459 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
1460 pw.print(" clientHidden="); pw.print(clientHidden);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -07001461 pw.print(" reportedDrawn="); pw.print(reportedDrawn);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001462 pw.print(" reportedVisible="); pw.println(reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -07001463 if (paused) {
1464 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001465 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001466 if (mAppStopped) {
1467 pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped);
1468 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001469 if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0
Craig Mautner6fbda632012-07-03 09:26:39 -07001470 || allDrawn || mAppAnimator.allDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001471 pw.print(prefix); pw.print("mNumInterestingWindows=");
1472 pw.print(mNumInterestingWindows);
1473 pw.print(" mNumDrawnWindows="); pw.print(mNumDrawnWindows);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001474 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -07001475 pw.print(" allDrawn="); pw.print(allDrawn);
1476 pw.print(" (animator="); pw.print(mAppAnimator.allDrawn);
1477 pw.println(")");
1478 }
1479 if (inPendingTransaction) {
1480 pw.print(prefix); pw.print("inPendingTransaction=");
1481 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001482 }
Craig Mautner799bc1d2015-01-14 10:33:48 -08001483 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001484 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
1485 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -08001486 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -08001487 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001488 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001489 if (startingWindow != null || startingSurface != null
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001490 || startingDisplayed || startingMoved) {
1491 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001492 pw.print(" startingSurface="); pw.print(startingSurface);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001493 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001494 pw.print(" startingMoved="); pw.println(startingMoved);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001495 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01001496 if (!mFrozenBounds.isEmpty()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -08001497 pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds);
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001498 pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig);
Chong Zhangd78ddb42016-03-02 17:01:14 -08001499 }
1500 if (mPendingRelaunchCount != 0) {
1501 pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount);
Jorim Jaggi0429f352015-12-22 16:29:16 +01001502 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001503 }
1504
1505 @Override
1506 public String toString() {
1507 if (stringName == null) {
1508 StringBuilder sb = new StringBuilder();
1509 sb.append("AppWindowToken{");
1510 sb.append(Integer.toHexString(System.identityHashCode(this)));
1511 sb.append(" token="); sb.append(token); sb.append('}');
1512 stringName = sb.toString();
1513 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001514 return stringName + ((mIsExiting) ? " mIsExiting=" : "");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001515 }
Jeff Browne9bdb312012-04-05 15:30:10 -07001516}