blob: 72ae90d71a9eb7980445fc97922c5d29b2a6301e [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
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700167 // The bounds of this activity. Mainly used for aspect-ratio compatibility.
168 // TODO(b/36505427): Every level on WindowContainer now has bounds information, which directly
169 // affects the configuration. We should probably move this into that class.
170 private final Rect mBounds = new Rect();
171
Jorim Jaggi0429f352015-12-22 16:29:16 +0100172 ArrayDeque<Rect> mFrozenBounds = new ArrayDeque<>();
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700173 ArrayDeque<Configuration> mFrozenMergedConfig = new ArrayDeque<>();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100174
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +0100175 private boolean mDisbalePreviewScreenshots;
176
Wale Ogunwale72919d22016-12-08 18:58:50 -0800177 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
178 DisplayContent dc, long inputDispatchingTimeoutNanos, boolean fullscreen,
179 boolean showForAllUsers, int targetSdk, int orientation, int rotationAnimationHint,
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800180 int configChanges, boolean launchTaskBehind, boolean alwaysFocusable,
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700181 AppWindowContainerController controller, Configuration overrideConfig, Rect bounds) {
182 this(service, token, voiceInteraction, dc, fullscreen, overrideConfig, bounds);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800183 setController(controller);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800184 mInputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800185 mShowForAllUsers = showForAllUsers;
186 mTargetSdk = targetSdk;
187 mOrientation = orientation;
188 layoutConfigChanges = (configChanges & (CONFIG_SCREEN_SIZE | CONFIG_ORIENTATION)) != 0;
189 mLaunchTaskBehind = launchTaskBehind;
190 mAlwaysFocusable = alwaysFocusable;
191 mRotationAnimationHint = rotationAnimationHint;
192
193 // Application tokens start out hidden.
194 hidden = true;
195 hiddenRequested = true;
196 }
197
198 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700199 DisplayContent dc, boolean fillsParent, Configuration overrideConfig, Rect bounds) {
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800200 super(service, token != null ? token.asBinder() : null, TYPE_APPLICATION, true, dc,
201 false /* ownerCanManageAppTokens */);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700202 appToken = token;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800203 mVoiceInteraction = voiceInteraction;
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800204 mFillsParent = fillsParent;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800205 mInputApplicationHandle = new InputApplicationHandle(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700206 mAppAnimator = new AppWindowAnimator(this, service);
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700207 if (overrideConfig != null) {
208 onOverrideConfigurationChanged(overrideConfig);
209 }
210 if (bounds != null) {
211 mBounds.set(bounds);
212 }
213 }
214
215 void onOverrideConfigurationChanged(Configuration overrideConfiguration, Rect bounds) {
216 onOverrideConfigurationChanged(overrideConfiguration);
217 if (mBounds.equals(bounds)) {
218 return;
219 }
220 // TODO(b/36505427): If bounds is in WC, then we can automatically call onResize() when set.
221 mBounds.set(bounds);
222 onResize();
223 }
224
225 void getBounds(Rect outBounds) {
226 outBounds.set(mBounds);
227 }
228
229 boolean hasBounds() {
230 return !mBounds.isEmpty();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800231 }
232
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800233 void onFirstWindowDrawn(WindowState win, WindowStateAnimator winAnimator) {
234 firstWindowDrawn = true;
235
236 // We now have a good window to show, remove dead placeholders
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700237 removeDeadWindows();
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800238
Jorim Jaggi02886a82016-12-06 09:10:06 -0800239 if (startingWindow != null) {
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800240 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, "Finish starting "
241 + win.mToken + ": first real window is shown, no animation");
242 // If this initial window is animating, stop it -- we will do an animation to reveal
243 // it from behind the starting window, so there is no need for it to also be doing its
244 // own stuff.
245 winAnimator.clearAnimation();
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800246 if (getController() != null) {
247 getController().removeStartingWindow();
248 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800249 }
250 updateReportedVisibilityLocked();
251 }
252
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800253 void updateReportedVisibilityLocked() {
254 if (appToken == null) {
255 return;
256 }
257
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700258 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700259 final int count = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800260
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700261 mReportedVisibilityResults.reset();
262
263 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700264 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700265 win.updateReportedVisibility(mReportedVisibilityResults);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800266 }
267
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700268 int numInteresting = mReportedVisibilityResults.numInteresting;
269 int numVisible = mReportedVisibilityResults.numVisible;
270 int numDrawn = mReportedVisibilityResults.numDrawn;
271 boolean nowGone = mReportedVisibilityResults.nowGone;
272
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700273 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800274 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700275 if (!nowGone) {
276 // If the app is not yet gone, then it can only become visible/drawn.
277 if (!nowDrawn) {
278 nowDrawn = reportedDrawn;
279 }
280 if (!nowVisible) {
281 nowVisible = reportedVisible;
282 }
283 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800284 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800285 + numInteresting + " visible=" + numVisible);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800286 final AppWindowContainerController controller = getController();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700287 if (nowDrawn != reportedDrawn) {
288 if (nowDrawn) {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800289 if (controller != null) {
290 controller.reportWindowsDrawn();
291 }
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700292 }
293 reportedDrawn = nowDrawn;
294 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800295 if (nowVisible != reportedVisible) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700296 if (DEBUG_VISIBILITY) Slog.v(TAG,
297 "Visibility changed in " + this + ": vis=" + nowVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800298 reportedVisible = nowVisible;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800299 if (controller != null) {
300 if (nowVisible) {
301 controller.reportWindowsVisible();
302 } else {
303 controller.reportWindowsGone();
304 }
305 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800306 }
307 }
308
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700309 boolean setVisibility(WindowManager.LayoutParams lp,
310 boolean visible, int transit, boolean performLayout, boolean isVoiceInteraction) {
311
312 boolean delayed = false;
313 inPendingTransaction = false;
314
315 if (clientHidden == visible) {
316 clientHidden = !visible;
317 sendAppVisibilityToClients();
318 }
319
320 // Allow for state changes and animation to be applied if:
321 // * token is transitioning visibility state
322 // * or the token was marked as hidden and is exiting before we had a chance to play the
323 // transition animation
324 // * or this is an opening app and windows are being replaced.
325 boolean visibilityChanged = false;
326 if (hidden == visible || (hidden && mIsExiting) || (visible && waitingForReplacement())) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700327 final AccessibilityController accessibilityController = mService.mAccessibilityController;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700328 boolean changed = false;
329 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
330 "Changing app " + this + " hidden=" + hidden + " performLayout=" + performLayout);
331
332 boolean runningAppAnimation = false;
333
334 if (transit != AppTransition.TRANSIT_UNSET) {
335 if (mAppAnimator.animation == AppWindowAnimator.sDummyAnimation) {
336 mAppAnimator.setNullAnimation();
337 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700338 if (mService.applyAnimationLocked(this, lp, transit, visible, isVoiceInteraction)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700339 delayed = runningAppAnimation = true;
340 }
341 final WindowState window = findMainWindow();
342 //TODO (multidisplay): Magnification is supported only for the default display.
343 if (window != null && accessibilityController != null
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700344 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700345 accessibilityController.onAppWindowTransitionLocked(window, transit);
346 }
347 changed = true;
348 }
349
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700350 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700351 for (int i = 0; i < windowsCount; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700352 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700353 changed |= win.onAppVisibilityChanged(visible, runningAppAnimation);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700354 }
355
356 hidden = hiddenRequested = !visible;
357 visibilityChanged = true;
358 if (!visible) {
359 stopFreezingScreen(true, true);
360 } else {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700361 // If we are being set visible, and the starting window is not yet displayed,
362 // then make sure it doesn't get displayed.
363 if (startingWindow != null && !startingWindow.isDrawnLw()) {
364 startingWindow.mPolicyVisibility = false;
365 startingWindow.mPolicyVisibilityAfterAnim = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700366 }
367 }
368
369 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setVisibility: " + this
370 + ": hidden=" + hidden + " hiddenRequested=" + hiddenRequested);
371
372 if (changed) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700373 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700374 if (performLayout) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700375 mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700376 false /*updateInputWindows*/);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700377 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700378 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700379 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700380 }
381 }
382
383 if (mAppAnimator.animation != null) {
384 delayed = true;
385 }
386
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700387 for (int i = mChildren.size() - 1; i >= 0 && !delayed; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700388 if ((mChildren.get(i)).isWindowAnimationSet()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700389 delayed = true;
390 }
391 }
392
393 if (visibilityChanged) {
394 if (visible && !delayed) {
395 // The token was made immediately visible, there will be no entrance animation.
396 // We need to inform the client the enter animation was finished.
397 mEnteringAnimation = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700398 mService.mActivityManagerAppTransitionNotifier.onAppTransitionFinishedLocked(token);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700399 }
Robert Carre7cc44d2017-03-20 19:04:30 -0700400 // If we are hidden but there is no delay needed we immediately
401 // apply the Surface transaction so that the ActivityManager
402 // can have some guarantee on the Surface state
403 // following setting the visibility.
Robert Carr6914f082017-03-20 19:04:30 -0700404 if (hidden && !delayed) {
405 SurfaceControl.openTransaction();
406 for (int i = mChildren.size() - 1; i >= 0; i--) {
407 mChildren.get(i).mWinAnimator.hide("immediately hidden");
408 }
409 SurfaceControl.closeTransaction();
410 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700411
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700412 if (!mService.mClosingApps.contains(this) && !mService.mOpeningApps.contains(this)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700413 // The token is not closing nor opening, so even if there is an animation set, that
414 // doesn't mean that it goes through the normal app transition cycle so we have
415 // to inform the docked controller about visibility change.
Andrii Kulian1e32e022016-09-16 15:29:34 -0700416 // TODO(multi-display): notify docked divider on all displays where visibility was
417 // affected.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700418 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700419 .notifyAppVisibilityChanged();
Jorim Jaggi8b702ed2017-01-20 16:59:03 +0100420 mService.mTaskSnapshotController.notifyAppVisibilityChanged(this, visible);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700421 }
422 }
423
424 return delayed;
425 }
426
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800427 WindowState findMainWindow() {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700428 WindowState candidate = null;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700429 int j = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800430 while (j > 0) {
431 j--;
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700432 final WindowState win = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700433 final int type = win.mAttrs.type;
434 // No need to loop through child window as base application and starting types can't be
435 // child windows.
436 if (type == TYPE_BASE_APPLICATION || type == TYPE_APPLICATION_STARTING) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700437 // In cases where there are multiple windows, we prefer the non-exiting window. This
Sungsoo Lim0d3d1f82015-12-02 14:47:59 +0900438 // happens for example when replacing windows during an activity relaunch. When
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700439 // constructing the animation, we want the new window, not the exiting one.
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800440 if (win.mAnimatingExit) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700441 candidate = win;
442 } else {
443 return win;
444 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800445 }
446 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700447 return candidate;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800448 }
449
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800450 boolean windowsAreFocusable() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800451 return StackId.canReceiveKeys(getTask().mStack.mStackId) || mAlwaysFocusable;
Wale Ogunwaled045c822015-12-02 09:14:28 -0800452 }
453
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800454 AppWindowContainerController getController() {
455 final WindowContainerController controller = super.getController();
456 return controller != null ? (AppWindowContainerController) controller : null;
457 }
458
Wale Ogunwale571771c2016-08-26 13:18:50 -0700459 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -0700460 boolean isVisible() {
Wale Ogunwalee471be62016-10-03 07:53:55 -0700461 // If the app token isn't hidden then it is considered visible and there is no need to check
462 // its children windows to see if they are visible.
463 return !hidden;
Wale Ogunwale44f21802016-09-02 12:49:48 -0700464 }
465
466 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -0700467 void removeIfPossible() {
Craig Mautnere3119b72015-01-20 15:02:36 -0800468 mIsExiting = false;
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800469 removeAllWindowsIfPossible();
Bryce Lee6d410262017-02-28 15:30:17 -0800470 removeImmediately();
Craig Mautnere3119b72015-01-20 15:02:36 -0800471 }
472
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700473 @Override
474 boolean checkCompleteDeferredRemoval() {
475 if (mIsExiting) {
476 removeIfPossible();
477 }
478 return super.checkCompleteDeferredRemoval();
479 }
480
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700481 void onRemovedFromDisplay() {
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700482 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app token: " + this);
483
Wale Ogunwale72919d22016-12-08 18:58:50 -0800484 boolean delayed = setVisibility(null, false, TRANSIT_UNSET, true, mVoiceInteraction);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700485
486 mService.mOpeningApps.remove(this);
Jorim Jaggi1b4b23e2016-11-15 16:30:12 -0800487 mService.mUnknownAppVisibilityController.appRemoved(this);
Jorim Jaggi10abe2f2017-01-03 16:44:46 +0100488 mService.mTaskSnapshotController.onAppRemoved(this);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700489 waitingToShow = false;
490 if (mService.mClosingApps.contains(this)) {
491 delayed = true;
492 } else if (mService.mAppTransition.isTransitionSet()) {
493 mService.mClosingApps.add(this);
494 delayed = true;
495 }
496
497 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app " + this + " delayed=" + delayed
498 + " animation=" + mAppAnimator.animation + " animating=" + mAppAnimator.animating);
499
500 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM, "removeAppToken: "
501 + this + " delayed=" + delayed + " Callers=" + Debug.getCallers(4));
502
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800503 if (startingData != null && getController() != null) {
504 getController().removeStartingWindow();
505 }
506
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800507 final TaskStack stack = getTask().mStack;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700508 if (delayed && !isEmpty()) {
509 // set the token aside because it has an active animation to be finished
510 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM,
511 "removeAppToken make exiting: " + this);
512 stack.mExitingAppTokens.add(this);
513 mIsExiting = true;
514 } else {
515 // Make sure there is no animation running on this token, so any windows associated
516 // with it will be removed as soon as their animations are complete
517 mAppAnimator.clearAnimation();
518 mAppAnimator.animating = false;
519 removeIfPossible();
520 }
521
522 removed = true;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700523 stopFreezingScreen(true, true);
Bryce Lee6d410262017-02-28 15:30:17 -0800524
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700525 if (mService.mFocusedApp == this) {
526 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "Removing focused app token:" + this);
527 mService.mFocusedApp = null;
528 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
529 mService.mInputMonitor.setFocusedAppLw(null);
530 }
531
532 if (!delayed) {
533 updateReportedVisibilityLocked();
534 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700535 }
536
Chong Zhange05bcb12016-07-26 17:47:29 -0700537 void clearAnimatingFlags() {
Chong Zhangb0d26702016-08-12 16:03:29 -0700538 boolean wallpaperMightChange = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700539 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700540 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700541 wallpaperMightChange |= win.clearAnimatingFlags();
Chong Zhange05bcb12016-07-26 17:47:29 -0700542 }
Chong Zhangb0d26702016-08-12 16:03:29 -0700543 if (wallpaperMightChange) {
544 requestUpdateWallpaperIfNeeded();
545 }
Chong Zhange05bcb12016-07-26 17:47:29 -0700546 }
547
Robert Carre12aece2016-02-02 22:43:27 -0800548 void destroySurfaces() {
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700549 destroySurfaces(false /*cleanupOnResume*/);
550 }
551
552 /**
553 * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure
554 * the client has finished with them.
555 *
556 * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If
557 * set to true, destroy only surfaces of removed windows, and clear relevant flags of the
558 * others so that they are ready to be reused. If set to false (common case), destroy all
559 * surfaces that's eligible, if the app is already stopped.
560 */
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700561 private void destroySurfaces(boolean cleanupOnResume) {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700562 boolean destroyedSomething = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700563 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700564 final WindowState win = mChildren.get(i);
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700565 destroyedSomething |= win.destroySurface(cleanupOnResume, mAppStopped);
Robert Carre12aece2016-02-02 22:43:27 -0800566 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700567 if (destroyedSomething) {
568 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700569 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Robert Carre12aece2016-02-02 22:43:27 -0800570 }
571 }
572
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800573 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700574 * Notify that the app is now resumed, and it was not stopped before, perform a clean
575 * up of the surfaces
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800576 */
Chong Zhangad24f962016-08-25 12:12:33 -0700577 void notifyAppResumed(boolean wasStopped, boolean allowSavedSurface) {
578 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped
579 + " allowSavedSurface=" + allowSavedSurface + " " + this);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700580 mAppStopped = false;
581 if (!wasStopped) {
582 destroySurfaces(true /*cleanupOnResume*/);
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800583 }
Chong Zhangad24f962016-08-25 12:12:33 -0700584 if (!allowSavedSurface) {
585 destroySavedSurfaces();
586 }
Robert Carre12aece2016-02-02 22:43:27 -0800587 }
588
Chong Zhangbef461f2015-10-27 11:38:24 -0700589 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700590 * Notify that the app has stopped, and it is okay to destroy any surfaces which were
591 * keeping alive in case they were still being used.
592 */
593 void notifyAppStopped() {
594 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this);
595 mAppStopped = true;
596 destroySurfaces();
597 // Remove any starting window that was added for this app if they are still around.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800598 if (getController() != null) {
599 getController().removeStartingWindow();
600 }
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700601 }
602
603 /**
Chong Zhangbef461f2015-10-27 11:38:24 -0700604 * Checks whether we should save surfaces for this app.
605 *
606 * @return true if the surfaces should be saved, false otherwise.
607 */
608 boolean shouldSaveSurface() {
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800609 // We want to save surface if the app's windows are "allDrawn".
610 // (If we started entering animation early with saved surfaces, allDrawn
611 // should have been restored to true. So we'll save again in that case
612 // even if app didn't actually finish drawing.)
613 return allDrawn;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800614 }
615
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700616 private boolean canRestoreSurfaces() {
617 for (int i = mChildren.size() -1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700618 final WindowState w = mChildren.get(i);
Chong Zhang92147042016-05-09 12:47:11 -0700619 if (w.canRestoreSurface()) {
Robert Carr13f7be9e2015-12-02 18:39:45 -0800620 return true;
621 }
Chong Zhangbef461f2015-10-27 11:38:24 -0700622 }
623 return false;
624 }
625
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700626 private void clearWasVisibleBeforeClientHidden() {
627 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700628 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700629 w.clearWasVisibleBeforeClientHidden();
Chong Zhang92147042016-05-09 12:47:11 -0700630 }
631 }
632
Chong Zhang8e4bda92016-05-04 15:08:18 -0700633 /**
634 * Whether the app has some window that is invisible in layout, but
635 * animating with saved surface.
636 */
637 boolean isAnimatingInvisibleWithSavedSurface() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700638 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700639 final WindowState w = mChildren.get(i);
Chong Zhang8e4bda92016-05-04 15:08:18 -0700640 if (w.isAnimatingInvisibleWithSavedSurface()) {
641 return true;
642 }
643 }
644 return false;
645 }
646
647 /**
648 * Hide all window surfaces that's still invisible in layout but animating
649 * with a saved surface, and mark them destroying.
650 */
651 void stopUsingSavedSurfaceLocked() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700652 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700653 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700654 w.stopUsingSavedSurface();
Chong Zhang8e4bda92016-05-04 15:08:18 -0700655 }
656 destroySurfaces();
657 }
658
Chong Zhangf58631a2016-05-24 16:02:10 -0700659 void markSavedSurfaceExiting() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700660 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700661 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700662 w.markSavedSurfaceExiting();
Chong Zhangf58631a2016-05-24 16:02:10 -0700663 }
664 }
665
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700666 void restoreSavedSurfaceForInterestingWindows() {
Chong Zhang92147042016-05-09 12:47:11 -0700667 if (!canRestoreSurfaces()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700668 clearWasVisibleBeforeClientHidden();
Chong Zhangbef461f2015-10-27 11:38:24 -0700669 return;
670 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700671
672 // Check if all interesting windows are drawn and we can mark allDrawn=true.
673 int interestingNotDrawn = -1;
674
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700675 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700676 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700677 interestingNotDrawn = w.restoreSavedSurfaceForInterestingWindow();
Chong Zhangbef461f2015-10-27 11:38:24 -0700678 }
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800679
Chong Zhang92147042016-05-09 12:47:11 -0700680 if (!allDrawn) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700681 allDrawn = (interestingNotDrawn == 0);
Chong Zhang92147042016-05-09 12:47:11 -0700682 if (allDrawn) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700683 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Chong Zhang92147042016-05-09 12:47:11 -0700684 }
685 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700686 clearWasVisibleBeforeClientHidden();
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800687
688 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700689 "restoreSavedSurfaceForInterestingWindows: " + this + " allDrawn=" + allDrawn
690 + " interestingNotDrawn=" + interestingNotDrawn);
Chong Zhangbef461f2015-10-27 11:38:24 -0700691 }
692
693 void destroySavedSurfaces() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700694 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700695 final WindowState win = mChildren.get(i);
Robert Carr13f7be9e2015-12-02 18:39:45 -0800696 win.destroySavedSurface();
Chong Zhangbef461f2015-10-27 11:38:24 -0700697 }
Chong Zhang92147042016-05-09 12:47:11 -0700698 }
699
700 void clearAllDrawn() {
701 allDrawn = false;
702 deferClearAllDrawn = false;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700703 allDrawnExcludingSaved = false;
Chong Zhangbef461f2015-10-27 11:38:24 -0700704 }
705
Bryce Lee6d410262017-02-28 15:30:17 -0800706 Task getTask() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800707 return (Task) getParent();
Bryce Lee6d410262017-02-28 15:30:17 -0800708 }
709
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800710 TaskStack getStack() {
711 final Task task = getTask();
712 if (task != null) {
713 return task.mStack;
714 } else {
715 return null;
716 }
717 }
718
Bryce Lee6d410262017-02-28 15:30:17 -0800719 @Override
720 void onParentSet() {
721 super.onParentSet();
722
723 // When the associated task is {@code null}, the {@link AppWindowToken} can no longer
724 // access visual elements like the {@link DisplayContent}. We must remove any associations
725 // such as animations.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800726 if (!mReparenting) {
727 final Task task = getTask();
728 if (task == null) {
729 // It is possible we have been marked as a closing app earlier. We must remove ourselves
730 // from this list so we do not participate in any future animations.
731 mService.mClosingApps.remove(this);
732 } else if (task.mStack != null) {
733 task.mStack.mExitingAppTokens.remove(this);
734 }
Bryce Lee6d410262017-02-28 15:30:17 -0800735 }
736 }
737
Wale Ogunwalefa854eb2016-09-20 13:43:52 -0700738 void postWindowRemoveStartingWindowCleanup(WindowState win) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700739 // TODO: Something smells about the code below...Is there a better way?
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700740 if (startingWindow == win) {
741 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800742 if (getController() != null) {
743 getController().removeStartingWindow();
744 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700745 } else if (mChildren.size() == 0 && startingData != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700746 // If this is the last window and we had requested a starting transition window,
747 // well there is no point now.
Jorim Jaggi02886a82016-12-06 09:10:06 -0800748 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingData");
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700749 startingData = null;
Jorim Jaggi829b9cd2017-01-23 16:20:53 +0100750 } else if (mChildren.size() == 1 && startingSurface != null && !isRelaunching()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700751 // If this is the last window except for a starting transition window,
752 // we need to get rid of the starting transition.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800753 if (getController() != null) {
754 getController().removeStartingWindow();
755 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700756 }
757 }
758
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700759 void removeDeadWindows() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700760 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700761 WindowState win = mChildren.get(winNdx);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800762 if (win.mAppDied) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700763 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700764 "removeDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800765 // Set mDestroying, we don't want any animation or delayed removal here.
766 win.mDestroying = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700767 // Also removes child windows.
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700768 win.removeIfPossible();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800769 }
770 }
771 }
772
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700773 boolean hasWindowsAlive() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700774 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700775 // No need to loop through child windows as the answer should be the same as that of the
776 // parent window.
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700777 if (!(mChildren.get(i)).mAppDied) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700778 return true;
779 }
780 }
781 return false;
782 }
783
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700784 void setWillReplaceWindows(boolean animate) {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700785 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
786 "Marking app token " + this + " with replacing windows.");
Robert Carra1eb4392015-12-10 12:43:51 -0800787
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700788 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700789 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700790 w.setWillReplaceWindow(animate);
Robert Carra1eb4392015-12-10 12:43:51 -0800791 }
792 if (animate) {
793 // Set-up dummy animation so we can start treating windows associated with this
794 // token like they are in transition before the new app window is ready for us to
795 // run the real transition animation.
796 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700797 "setWillReplaceWindow() Setting dummy animation on: " + this);
Robert Carra1eb4392015-12-10 12:43:51 -0800798 mAppAnimator.setDummyAnimation();
799 }
800 }
801
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700802 void setWillReplaceChildWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700803 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this
Robert Carr23fa16b2016-01-13 13:19:58 -0800804 + " with replacing child windows.");
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700805 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700806 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700807 w.setWillReplaceChildWindows();
Robert Carr23fa16b2016-01-13 13:19:58 -0800808 }
809 }
810
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700811 void clearWillReplaceWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700812 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
813 "Resetting app token " + this + " of replacing window marks.");
Chong Zhangf596cd52016-01-05 13:42:44 -0800814
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700815 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700816 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700817 w.clearWillReplaceWindow();
Chong Zhangf596cd52016-01-05 13:42:44 -0800818 }
819 }
820
Chong Zhang4d7369a2016-04-25 16:09:14 -0700821 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700822 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700823 final WindowState w = mChildren.get(i);
Chong Zhang4d7369a2016-04-25 16:09:14 -0700824 w.requestUpdateWallpaperIfNeeded();
825 }
826 }
827
Chong Zhangd78ddb42016-03-02 17:01:14 -0800828 boolean isRelaunching() {
829 return mPendingRelaunchCount > 0;
830 }
831
832 void startRelaunching() {
833 if (canFreezeBounds()) {
834 freezeBounds();
835 }
Robert Carrd5c7dd62017-03-08 10:39:30 -0800836
837 // In the process of tearing down before relaunching, the app will
838 // try and clean up it's child surfaces. We need to prevent this from
839 // happening, so we sever the children, transfering their ownership
840 // from the client it-self to the parent surface (owned by us).
841 for (int i = mChildren.size() - 1; i >= 0; i--) {
842 final WindowState w = mChildren.get(i);
843 w.mWinAnimator.detachChildren();
844 }
845
Chong Zhangd78ddb42016-03-02 17:01:14 -0800846 mPendingRelaunchCount++;
847 }
848
849 void finishRelaunching() {
850 if (canFreezeBounds()) {
851 unfreezeBounds();
852 }
853 if (mPendingRelaunchCount > 0) {
854 mPendingRelaunchCount--;
855 }
856 }
857
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700858 void clearRelaunching() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700859 if (mPendingRelaunchCount == 0) {
860 return;
861 }
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700862 if (canFreezeBounds()) {
863 unfreezeBounds();
864 }
865 mPendingRelaunchCount = 0;
866 }
867
Wale Ogunwale07bcab72016-10-14 15:30:09 -0700868 /**
869 * Returns true if the new child window we are adding to this token is considered greater than
870 * the existing child window in this token in terms of z-order.
871 */
872 @Override
873 protected boolean isFirstChildWindowGreaterThanSecond(WindowState newWindow,
874 WindowState existingWindow) {
875 final int type1 = newWindow.mAttrs.type;
876 final int type2 = existingWindow.mAttrs.type;
877
878 // Base application windows should be z-ordered BELOW all other windows in the app token.
879 if (type1 == TYPE_BASE_APPLICATION && type2 != TYPE_BASE_APPLICATION) {
880 return false;
881 } else if (type1 != TYPE_BASE_APPLICATION && type2 == TYPE_BASE_APPLICATION) {
882 return true;
883 }
884
885 // Starting windows should be z-ordered ABOVE all other windows in the app token.
886 if (type1 == TYPE_APPLICATION_STARTING && type2 != TYPE_APPLICATION_STARTING) {
887 return true;
888 } else if (type1 != TYPE_APPLICATION_STARTING && type2 == TYPE_APPLICATION_STARTING) {
889 return false;
890 }
891
892 // Otherwise the new window is greater than the existing window.
893 return true;
894 }
895
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700896 @Override
Robert Carra1eb4392015-12-10 12:43:51 -0800897 void addWindow(WindowState w) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700898 super.addWindow(w);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700899
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700900 boolean gotReplacementWindow = false;
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 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700903 gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w);
904 }
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700905
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700906 // if we got a replacement window, reset the timeout to give drawing more time
907 if (gotReplacementWindow) {
908 mService.scheduleWindowReplacementTimeouts(this);
Robert Carra1eb4392015-12-10 12:43:51 -0800909 }
Jorim Jaggife762342016-10-13 14:33:27 +0200910 checkKeyguardFlagsChanged();
911 }
912
913 @Override
914 void removeChild(WindowState child) {
915 super.removeChild(child);
916 checkKeyguardFlagsChanged();
Robert Carra1eb4392015-12-10 12:43:51 -0800917 }
918
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700919 private boolean waitingForReplacement() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700920 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700921 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700922 if (candidate.waitingForReplacement()) {
Robert Carra1eb4392015-12-10 12:43:51 -0800923 return true;
924 }
925 }
926 return false;
927 }
928
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700929 void onWindowReplacementTimeout() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700930 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700931 (mChildren.get(i)).onWindowReplacementTimeout();
Robert Carra1eb4392015-12-10 12:43:51 -0800932 }
933 }
934
Winson Chung30480042017-01-26 10:55:34 -0800935 void reparent(Task task, int position) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800936 final Task currentTask = getTask();
937 if (task == currentTask) {
Winson Chung30480042017-01-26 10:55:34 -0800938 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800939 "window token=" + this + " already child of task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -0800940 }
Bryce Lee6d410262017-02-28 15:30:17 -0800941
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800942 if (currentTask.mStack != task.mStack) {
Bryce Lee6d410262017-02-28 15:30:17 -0800943 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800944 "window token=" + this + " current task=" + currentTask
Bryce Lee6d410262017-02-28 15:30:17 -0800945 + " belongs to a different stack than " + task);
946 }
947
Winson Chung30480042017-01-26 10:55:34 -0800948 if (DEBUG_ADD_REMOVE) Slog.i(TAG, "reParentWindowToken: removing window token=" + this
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800949 + " from task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -0800950 final DisplayContent prevDisplayContent = getDisplayContent();
951
Bryce Lee6d410262017-02-28 15:30:17 -0800952 mReparenting = true;
953
Winson Chung30480042017-01-26 10:55:34 -0800954 getParent().removeChild(this);
955 task.addChild(this, position);
956
Bryce Lee6d410262017-02-28 15:30:17 -0800957 mReparenting = false;
958
Winson Chung30480042017-01-26 10:55:34 -0800959 // Relayout display(s).
960 final DisplayContent displayContent = task.getDisplayContent();
961 displayContent.setLayoutNeeded();
962 if (prevDisplayContent != displayContent) {
963 onDisplayChanged(displayContent);
964 prevDisplayContent.setLayoutNeeded();
965 }
966 }
967
Chong Zhangd78ddb42016-03-02 17:01:14 -0800968 private boolean canFreezeBounds() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800969 final Task task = getTask();
970
Chong Zhangd78ddb42016-03-02 17:01:14 -0800971 // For freeform windows, we can't freeze the bounds at the moment because this would make
972 // the resizing unresponsive.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800973 return task != null && !task.inFreeformWorkspace();
Chong Zhangd78ddb42016-03-02 17:01:14 -0800974 }
975
Jorim Jaggi0429f352015-12-22 16:29:16 +0100976 /**
977 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
978 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
979 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
980 * with a queue.
981 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800982 private void freezeBounds() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800983 final Task task = getTask();
984 mFrozenBounds.offer(new Rect(task.mPreparedFrozenBounds));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700985
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800986 if (task.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) {
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700987 // We didn't call prepareFreezingBounds on the task, so use the current value.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800988 mFrozenMergedConfig.offer(new Configuration(task.getConfiguration()));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700989 } else {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800990 mFrozenMergedConfig.offer(new Configuration(task.mPreparedFrozenMergedConfig));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700991 }
Andrii Kulianb10330d2016-09-16 13:51:46 -0700992 // Calling unset() to make it equal to Configuration.EMPTY.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800993 task.mPreparedFrozenMergedConfig.unset();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100994 }
995
996 /**
997 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
998 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800999 private void unfreezeBounds() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -07001000 if (!mFrozenBounds.isEmpty()) {
1001 mFrozenBounds.remove();
1002 }
1003 if (!mFrozenMergedConfig.isEmpty()) {
1004 mFrozenMergedConfig.remove();
1005 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001006 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001007 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001008 win.onUnfreezeBounds();
Jorim Jaggi4846ee32016-01-07 17:39:12 +01001009 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001010 mService.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +01001011 }
1012
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001013 void setAppLayoutChanges(int changes, String reason) {
1014 if (!mChildren.isEmpty()) {
1015 final DisplayContent dc = getDisplayContent();
1016 dc.pendingLayoutChanges |= changes;
1017 if (DEBUG_LAYOUT_REPEATS) {
1018 mService.mWindowPlacerLocked.debugLayoutRepeats(reason, dc.pendingLayoutChanges);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001019 }
1020 }
1021 }
1022
1023 void removeReplacedWindowIfNeeded(WindowState replacement) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001024 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001025 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001026 if (win.removeReplacedWindowIfNeeded(replacement)) {
1027 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001028 }
1029 }
1030 }
1031
1032 void startFreezingScreen() {
1033 if (DEBUG_ORIENTATION) logWithStack(TAG, "Set freezing of " + appToken + ": hidden="
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001034 + hidden + " freezing=" + mAppAnimator.freezingScreen + " hiddenRequested="
1035 + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001036 if (!hiddenRequested) {
1037 if (!mAppAnimator.freezingScreen) {
1038 mAppAnimator.freezingScreen = true;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001039 mService.registerAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001040 mAppAnimator.lastFreezeDuration = 0;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001041 mService.mAppsFreezingScreen++;
1042 if (mService.mAppsFreezingScreen == 1) {
1043 mService.startFreezingDisplayLocked(false, 0, 0);
1044 mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT);
1045 mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001046 }
1047 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001048 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001049 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001050 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001051 w.onStartFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001052 }
1053 }
1054 }
1055
1056 void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) {
1057 if (!mAppAnimator.freezingScreen) {
1058 return;
1059 }
1060 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + this + " force=" + force);
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001061 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001062 boolean unfrozeWindows = false;
1063 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001064 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001065 unfrozeWindows |= w.onStopFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001066 }
1067 if (force || unfrozeWindows) {
1068 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this);
1069 mAppAnimator.freezingScreen = false;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001070 mService.unregisterAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001071 mAppAnimator.lastFreezeDuration =
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001072 (int)(SystemClock.elapsedRealtime() - mService.mDisplayFreezeTime);
1073 mService.mAppsFreezingScreen--;
1074 mService.mLastFinishedFreezeSource = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001075 }
1076 if (unfreezeSurfaceNow) {
1077 if (unfrozeWindows) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001078 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001079 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001080 mService.stopFreezingDisplayLocked();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001081 }
1082 }
1083
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001084 @Override
1085 public void onAppFreezeTimeout() {
1086 Slog.w(TAG_WM, "Force clearing freeze: " + this);
1087 stopFreezingScreen(true, true);
1088 }
1089
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001090 boolean transferStartingWindow(IBinder transferFrom) {
Wale Ogunwale02319a62016-09-26 15:21:22 -07001091 final AppWindowToken fromToken = getDisplayContent().getAppWindowToken(transferFrom);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001092 if (fromToken == null) {
1093 return false;
1094 }
1095
1096 final WindowState tStartingWindow = fromToken.startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001097 if (tStartingWindow != null && fromToken.startingSurface != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001098 // In this case, the starting icon has already been displayed, so start
1099 // letting windows get shown immediately without any more transitions.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001100 mService.mSkipAppTransitionAnimation = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001101
1102 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow
1103 + " from " + fromToken + " to " + this);
1104
1105 final long origId = Binder.clearCallingIdentity();
1106
1107 // Transfer the starting window over to the new token.
1108 startingData = fromToken.startingData;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001109 startingSurface = fromToken.startingSurface;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001110 startingDisplayed = fromToken.startingDisplayed;
1111 fromToken.startingDisplayed = false;
1112 startingWindow = tStartingWindow;
1113 reportedVisible = fromToken.reportedVisible;
1114 fromToken.startingData = null;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001115 fromToken.startingSurface = null;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001116 fromToken.startingWindow = null;
1117 fromToken.startingMoved = true;
1118 tStartingWindow.mToken = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001119 tStartingWindow.mAppToken = this;
1120
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001121 if (DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001122 "Removing starting " + tStartingWindow + " from " + fromToken);
Wale Ogunwalefa854eb2016-09-20 13:43:52 -07001123 fromToken.removeChild(tStartingWindow);
1124 fromToken.postWindowRemoveStartingWindowCleanup(tStartingWindow);
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001125 addWindow(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001126
1127 // Propagate other interesting state between the tokens. If the old token is displayed,
1128 // we should immediately force the new one to be displayed. If it is animating, we need
1129 // to move that animation to the new one.
1130 if (fromToken.allDrawn) {
1131 allDrawn = true;
1132 deferClearAllDrawn = fromToken.deferClearAllDrawn;
1133 }
1134 if (fromToken.firstWindowDrawn) {
1135 firstWindowDrawn = true;
1136 }
1137 if (!fromToken.hidden) {
1138 hidden = false;
1139 hiddenRequested = false;
1140 }
1141 if (clientHidden != fromToken.clientHidden) {
1142 clientHidden = fromToken.clientHidden;
1143 sendAppVisibilityToClients();
1144 }
1145 fromToken.mAppAnimator.transferCurrentAnimation(
1146 mAppAnimator, tStartingWindow.mWinAnimator);
1147
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001148 mService.updateFocusedWindowLocked(
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001149 UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/);
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001150 getDisplayContent().setLayoutNeeded();
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001151 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001152 Binder.restoreCallingIdentity(origId);
1153 return true;
1154 } else if (fromToken.startingData != null) {
1155 // The previous app was getting ready to show a
1156 // starting window, but hasn't yet done so. Steal it!
1157 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1158 "Moving pending starting from " + fromToken + " to " + this);
1159 startingData = fromToken.startingData;
1160 fromToken.startingData = null;
1161 fromToken.startingMoved = true;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001162 if (getController() != null) {
1163 getController().scheduleAddStartingWindow();
1164 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001165 return true;
1166 }
1167
1168 final AppWindowAnimator tAppAnimator = fromToken.mAppAnimator;
1169 final AppWindowAnimator wAppAnimator = mAppAnimator;
1170 if (tAppAnimator.thumbnail != null) {
1171 // The old token is animating with a thumbnail, transfer that to the new token.
1172 if (wAppAnimator.thumbnail != null) {
1173 wAppAnimator.thumbnail.destroy();
1174 }
1175 wAppAnimator.thumbnail = tAppAnimator.thumbnail;
1176 wAppAnimator.thumbnailLayer = tAppAnimator.thumbnailLayer;
1177 wAppAnimator.thumbnailAnimation = tAppAnimator.thumbnailAnimation;
1178 tAppAnimator.thumbnail = null;
1179 }
1180 return false;
1181 }
1182
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001183 boolean isLastWindow(WindowState win) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001184 return mChildren.size() == 1 && mChildren.get(0) == win;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001185 }
1186
1187 void setAllAppWinAnimators() {
1188 final ArrayList<WindowStateAnimator> allAppWinAnimators = mAppAnimator.mAllAppWinAnimators;
1189 allAppWinAnimators.clear();
1190
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001191 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001192 for (int j = 0; j < windowsCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001193 (mChildren.get(j)).addWinAnimatorToList(allAppWinAnimators);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001194 }
1195 }
1196
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001197 @Override
1198 void onAppTransitionDone() {
1199 sendingToBottom = false;
1200 }
1201
Wale Ogunwale51362492016-09-08 17:49:17 -07001202 /**
1203 * We override because this class doesn't want its children affecting its reported orientation
1204 * in anyway.
1205 */
1206 @Override
1207 int getOrientation() {
Bryce Lee61fbcbc2017-03-10 14:14:03 -08001208 // The {@link AppWindowToken} should only specify an orientation when it is not closing or
1209 // going to the bottom. Allowing closing {@link AppWindowToken} to participate can lead to
1210 // an Activity in another task being started in the wrong orientation during the transition.
1211 if (fillsParent()
1212 && !(sendingToBottom || mService.mClosingApps.contains(this))
1213 && (isVisible() || mService.mOpeningApps.contains(this))) {
Bryce Leea163b762017-01-24 11:05:01 -08001214 return mOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001215 }
Bryce Leea163b762017-01-24 11:05:01 -08001216
1217 return SCREEN_ORIENTATION_UNSET;
Wale Ogunwale51362492016-09-08 17:49:17 -07001218 }
1219
Wale Ogunwaleb198b742016-12-01 08:44:09 -08001220 /** Returns the app's preferred orientation regardless of its currently visibility state. */
1221 int getOrientationIgnoreVisibility() {
1222 return mOrientation;
1223 }
1224
Craig Mautnerdbb79912012-03-01 18:59:14 -08001225 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001226 void checkAppWindowsReadyToShow() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001227 if (allDrawn == mAppAnimator.allDrawn) {
1228 return;
1229 }
1230
1231 mAppAnimator.allDrawn = allDrawn;
1232 if (!allDrawn) {
1233 return;
1234 }
1235
1236 // The token has now changed state to having all windows shown... what to do, what to do?
1237 if (mAppAnimator.freezingScreen) {
1238 mAppAnimator.showAllWindowsLocked();
1239 stopFreezingScreen(false, true);
1240 if (DEBUG_ORIENTATION) Slog.i(TAG,
1241 "Setting mOrientationChangeComplete=true because wtoken " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001242 + " numInteresting=" + mNumInterestingWindows + " numDrawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001243 // This will set mOrientationChangeComplete and cause a pass through layout.
1244 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001245 "checkAppWindowsReadyToShow: freezingScreen");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001246 } else {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001247 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001248
1249 // We can now show all of the drawn windows!
1250 if (!mService.mOpeningApps.contains(this)) {
1251 mService.mAnimator.orAnimating(mAppAnimator.showAllWindowsLocked());
1252 }
1253 }
1254 }
1255
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001256 void updateAllDrawn(DisplayContent dc) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001257 if (!allDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001258 final int numInteresting = mNumInterestingWindows;
1259 if (numInteresting > 0 && mNumDrawnWindows >= numInteresting) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001260 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawn: " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001261 + " interesting=" + numInteresting + " drawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001262 allDrawn = true;
1263 // Force an additional layout pass where
1264 // WindowStateAnimator#commitFinishDrawingLocked() will call performShowLocked().
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001265 dc.setLayoutNeeded();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001266 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
1267 }
1268 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001269
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001270 if (!allDrawnExcludingSaved) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001271 int numInteresting = mNumInterestingWindowsExcludingSaved;
1272 if (numInteresting > 0 && mNumDrawnWindowsExcludingSaved >= numInteresting) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001273 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawnExcludingSaved: " + this
1274 + " interesting=" + numInteresting
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001275 + " drawn=" + mNumDrawnWindowsExcludingSaved);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001276 allDrawnExcludingSaved = true;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001277 dc.setLayoutNeeded();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001278 if (isAnimatingInvisibleWithSavedSurface()
1279 && !mService.mFinishedEarlyAnim.contains(this)) {
1280 mService.mFinishedEarlyAnim.add(this);
1281 }
1282 }
1283 }
1284 }
1285
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001286 /**
1287 * Updated this app token tracking states for interesting and drawn windows based on the window.
1288 *
1289 * @return Returns true if the input window is considered interesting and drawn while all the
1290 * windows in this app token where not considered drawn as of the last pass.
1291 */
1292 boolean updateDrawnWindowStates(WindowState w) {
1293 if (DEBUG_STARTING_WINDOW && w == startingWindow) {
1294 Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" + w.isOnScreen()
1295 + " allDrawn=" + allDrawn + " freezingScreen=" + mAppAnimator.freezingScreen);
1296 }
1297
1298 if (allDrawn && allDrawnExcludingSaved && !mAppAnimator.freezingScreen) {
1299 return false;
1300 }
1301
1302 if (mLastTransactionSequence != mService.mTransactionSequence) {
1303 mLastTransactionSequence = mService.mTransactionSequence;
1304 mNumInterestingWindows = mNumDrawnWindows = 0;
1305 mNumInterestingWindowsExcludingSaved = 0;
1306 mNumDrawnWindowsExcludingSaved = 0;
1307 startingDisplayed = false;
1308 }
1309
1310 final WindowStateAnimator winAnimator = w.mWinAnimator;
1311
1312 boolean isInterestingAndDrawn = false;
1313
1314 if (!allDrawn && w.mightAffectAllDrawn(false /* visibleOnly */)) {
1315 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
1316 Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw()
1317 + ", isAnimationSet=" + winAnimator.isAnimationSet());
1318 if (!w.isDrawnLw()) {
1319 Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController
1320 + " pv=" + w.mPolicyVisibility
1321 + " mDrawState=" + winAnimator.drawStateToString()
1322 + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested
1323 + " a=" + winAnimator.mAnimating);
1324 }
1325 }
1326
1327 if (w != startingWindow) {
1328 if (w.isInteresting()) {
1329 mNumInterestingWindows++;
1330 if (w.isDrawnLw()) {
1331 mNumDrawnWindows++;
1332
1333 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, "tokenMayBeDrawn: "
1334 + this + " w=" + w + " numInteresting=" + mNumInterestingWindows
1335 + " freezingScreen=" + mAppAnimator.freezingScreen
1336 + " mAppFreezing=" + w.mAppFreezing);
1337
1338 isInterestingAndDrawn = true;
1339 }
1340 }
1341 } else if (w.isDrawnLw()) {
Jorim Jaggi3878ca32017-02-02 17:13:05 -08001342 if (getController() != null) {
1343 getController().reportStartingWindowDrawn();
1344 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001345 startingDisplayed = true;
1346 }
1347 }
1348
1349 if (!allDrawnExcludingSaved && w.mightAffectAllDrawn(true /* visibleOnly */)) {
1350 if (w != startingWindow && w.isInteresting()) {
1351 mNumInterestingWindowsExcludingSaved++;
1352 if (w.isDrawnLw() && !w.isAnimatingWithSavedSurface()) {
1353 mNumDrawnWindowsExcludingSaved++;
1354
1355 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
1356 "tokenMayBeDrawnExcludingSaved: " + this + " w=" + w
1357 + " numInteresting=" + mNumInterestingWindowsExcludingSaved
1358 + " freezingScreen=" + mAppAnimator.freezingScreen
1359 + " mAppFreezing=" + w.mAppFreezing);
1360
1361 isInterestingAndDrawn = true;
1362 }
1363 }
1364 }
1365
1366 return isInterestingAndDrawn;
1367 }
1368
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001369 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001370 void stepAppWindowsAnimation(long currentTime) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001371 mAppAnimator.wasAnimating = mAppAnimator.animating;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001372 if (mAppAnimator.stepAnimationLocked(currentTime)) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001373 mAppAnimator.animating = true;
1374 mService.mAnimator.setAnimating(true);
1375 mService.mAnimator.mAppWindowAnimating = true;
1376 } else if (mAppAnimator.wasAnimating) {
1377 // stopped animating, do one more pass through the layout
Wale Ogunwale1e129a42016-11-21 13:03:47 -08001378 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
1379 DEBUG_LAYOUT_REPEATS ? "appToken " + this + " done" : null);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001380 if (DEBUG_ANIM) Slog.v(TAG, "updateWindowsApps...: done animating " + this);
1381 }
1382 }
1383
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001384 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001385 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001386 // For legacy reasons we process the TaskStack.mExitingAppTokens first in DisplayContent
1387 // before the non-exiting app tokens. So, we skip the exiting app tokens here.
1388 // TODO: Investigate if we need to continue to do this or if we can just process them
1389 // in-order.
1390 if (mIsExiting && !waitingForReplacement()) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001391 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001392 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001393 return forAllWindowsUnchecked(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001394 }
1395
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001396 boolean forAllWindowsUnchecked(ToBooleanFunction<WindowState> callback,
1397 boolean traverseTopToBottom) {
1398 return super.forAllWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001399 }
1400
1401 @Override
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001402 AppWindowToken asAppWindowToken() {
1403 // I am an app window token!
1404 return this;
1405 }
1406
1407 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -07001408 boolean fillsParent() {
1409 return mFillsParent;
1410 }
1411
1412 void setFillsParent(boolean fillsParent) {
1413 mFillsParent = fillsParent;
1414 }
1415
Jorim Jaggife762342016-10-13 14:33:27 +02001416 boolean containsDismissKeyguardWindow() {
1417 for (int i = mChildren.size() - 1; i >= 0; i--) {
1418 if ((mChildren.get(i).mAttrs.flags & FLAG_DISMISS_KEYGUARD) != 0) {
1419 return true;
1420 }
1421 }
1422 return false;
1423 }
1424
1425 boolean containsShowWhenLockedWindow() {
1426 for (int i = mChildren.size() - 1; i >= 0; i--) {
1427 if ((mChildren.get(i).mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
1428 return true;
1429 }
1430 }
1431 return false;
1432 }
1433
1434 void checkKeyguardFlagsChanged() {
1435 final boolean containsDismissKeyguard = containsDismissKeyguardWindow();
1436 final boolean containsShowWhenLocked = containsShowWhenLockedWindow();
1437 if (containsDismissKeyguard != mLastContainsDismissKeyguardWindow
1438 || containsShowWhenLocked != mLastContainsShowWhenLockedWindow) {
1439 mService.notifyKeyguardFlagsChanged(null /* callback */);
1440 }
1441 mLastContainsDismissKeyguardWindow = containsDismissKeyguard;
1442 mLastContainsShowWhenLockedWindow = containsShowWhenLocked;
1443 }
1444
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001445 WindowState getImeTargetBelowWindow(WindowState w) {
1446 final int index = mChildren.indexOf(w);
1447 if (index > 0) {
1448 final WindowState target = mChildren.get(index - 1);
1449 if (target.canBeImeTarget()) {
1450 return target;
1451 }
1452 }
1453 return null;
1454 }
1455
1456 WindowState getHighestAnimLayerWindow(WindowState currentTarget) {
1457 WindowState candidate = null;
1458 for (int i = mChildren.indexOf(currentTarget); i >= 0; i--) {
1459 final WindowState w = mChildren.get(i);
1460 if (w.mRemoved) {
1461 continue;
1462 }
1463 if (candidate == null || w.mWinAnimator.mAnimLayer >
1464 candidate.mWinAnimator.mAnimLayer) {
1465 candidate = w;
1466 }
1467 }
1468 return candidate;
1469 }
1470
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001471 void setDisablePreviewSnapshots(boolean disable) {
1472 mDisbalePreviewScreenshots = disable;
1473 }
1474
1475 boolean shouldDisablePreviewScreenshots() {
1476 return mDisbalePreviewScreenshots;
1477 }
1478
Wale Ogunwale51362492016-09-08 17:49:17 -07001479 @Override
Robert Carrdee1b3f2017-02-27 11:33:33 -08001480 int getAnimLayerAdjustment() {
1481 return mAppAnimator.animLayerAdjustment;
1482 }
1483
1484 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001485 void dump(PrintWriter pw, String prefix) {
1486 super.dump(pw, prefix);
1487 if (appToken != null) {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001488 pw.println(prefix + "app=true mVoiceInteraction=" + mVoiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001489 }
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001490 pw.print(prefix); pw.print("task="); pw.println(getTask());
Wale Ogunwale51362492016-09-08 17:49:17 -07001491 pw.print(prefix); pw.print(" mFillsParent="); pw.print(mFillsParent);
1492 pw.print(" mOrientation="); pw.println(mOrientation);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001493 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
1494 pw.print(" clientHidden="); pw.print(clientHidden);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -07001495 pw.print(" reportedDrawn="); pw.print(reportedDrawn);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001496 pw.print(" reportedVisible="); pw.println(reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -07001497 if (paused) {
1498 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001499 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001500 if (mAppStopped) {
1501 pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped);
1502 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001503 if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0
Craig Mautner6fbda632012-07-03 09:26:39 -07001504 || allDrawn || mAppAnimator.allDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001505 pw.print(prefix); pw.print("mNumInterestingWindows=");
1506 pw.print(mNumInterestingWindows);
1507 pw.print(" mNumDrawnWindows="); pw.print(mNumDrawnWindows);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001508 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -07001509 pw.print(" allDrawn="); pw.print(allDrawn);
1510 pw.print(" (animator="); pw.print(mAppAnimator.allDrawn);
1511 pw.println(")");
1512 }
1513 if (inPendingTransaction) {
1514 pw.print(prefix); pw.print("inPendingTransaction=");
1515 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001516 }
Craig Mautner799bc1d2015-01-14 10:33:48 -08001517 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001518 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
1519 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -08001520 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -08001521 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001522 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001523 if (startingWindow != null || startingSurface != null
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001524 || startingDisplayed || startingMoved) {
1525 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001526 pw.print(" startingSurface="); pw.print(startingSurface);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001527 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001528 pw.print(" startingMoved="); pw.println(startingMoved);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001529 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01001530 if (!mFrozenBounds.isEmpty()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -08001531 pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds);
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001532 pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig);
Chong Zhangd78ddb42016-03-02 17:01:14 -08001533 }
1534 if (mPendingRelaunchCount != 0) {
1535 pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount);
Jorim Jaggi0429f352015-12-22 16:29:16 +01001536 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001537 }
1538
1539 @Override
1540 public String toString() {
1541 if (stringName == null) {
1542 StringBuilder sb = new StringBuilder();
1543 sb.append("AppWindowToken{");
1544 sb.append(Integer.toHexString(System.identityHashCode(this)));
1545 sb.append(" token="); sb.append(token); sb.append('}');
1546 stringName = sb.toString();
1547 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001548 return stringName + ((mIsExiting) ? " mIsExiting=" : "");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001549 }
Jeff Browne9bdb312012-04-05 15:30:10 -07001550}