blob: 2f221df182c05a93b8454ede160252c89f4d2827 [file] [log] [blame]
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server.wm;
18
Wale Ogunwale6cae7652015-12-26 07:36:26 -080019import static android.app.ActivityManager.StackId;
Wale Ogunwale72919d22016-12-08 18:58:50 -080020import static android.content.pm.ActivityInfo.CONFIG_ORIENTATION;
21import static android.content.pm.ActivityInfo.CONFIG_SCREEN_SIZE;
Wale Ogunwale51362492016-09-08 17:49:17 -070022import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070023import static android.view.Display.DEFAULT_DISPLAY;
Jorim Jaggife762342016-10-13 14:33:27 +020024import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
25import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
Wale Ogunwaled1c37912016-08-16 03:19:39 -070026import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080027import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070028import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -070029import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
30import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070031import static com.android.server.wm.AppTransition.TRANSIT_UNSET;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080032import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080033import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
34import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070035import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070036import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
37import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
Wale Ogunwale9017ec02016-02-25 08:55:25 -080038import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070039import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TOKEN_MOVEMENT;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080040import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
41import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_MOVEMENT;
42import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
43import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Chong Zhang92147042016-05-09 12:47:11 -070044import static com.android.server.wm.WindowManagerService.H.NOTIFY_ACTIVITY_DRAWN;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070045import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070046import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070047import static com.android.server.wm.WindowManagerService.logWithStack;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080048
Filip Gruszczynskia590c992015-11-25 16:45:26 -080049import android.annotation.NonNull;
Jorim Jaggi26c8c422016-05-09 19:57:25 -070050import android.content.res.Configuration;
Jorim Jaggi0429f352015-12-22 16:29:16 +010051import android.graphics.Rect;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070052import android.os.Binder;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080053import android.os.Debug;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070054import android.os.IBinder;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070055import android.os.SystemClock;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080056import android.util.Slog;
57import android.view.IApplicationToken;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080058import android.view.WindowManager;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080059import android.view.WindowManagerPolicy.StartingSurface;
60
61import com.android.internal.util.ToBooleanFunction;
62import com.android.server.input.InputApplicationHandle;
63import com.android.server.wm.WindowManagerService.H;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080064
65import java.io.PrintWriter;
Jorim Jaggi0429f352015-12-22 16:29:16 +010066import java.util.ArrayDeque;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080067import java.util.ArrayList;
68
69class AppTokenList extends ArrayList<AppWindowToken> {
70}
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080071
72/**
73 * Version of WindowToken that is specifically for a particular application (or
74 * really activity) that is displaying windows.
75 */
Wale Ogunwale3f4433d2016-08-18 20:42:42 -070076class AppWindowToken extends WindowToken implements WindowManagerService.AppFreezeListener {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080077 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppWindowToken" : TAG_WM;
78
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080079 // Non-null only for application tokens.
80 final IApplicationToken appToken;
81
Filip Gruszczynskia590c992015-11-25 16:45:26 -080082 @NonNull final AppWindowAnimator mAppAnimator;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -070083
Wale Ogunwale72919d22016-12-08 18:58:50 -080084 final boolean mVoiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -070085
Wale Ogunwale51362492016-09-08 17:49:17 -070086 /** @see WindowContainer#fillsParent() */
87 private boolean mFillsParent;
Craig Mautner4c5eb222013-11-18 12:59:05 -080088 boolean layoutConfigChanges;
Wale Ogunwale72919d22016-12-08 18:58:50 -080089 boolean mShowForAllUsers;
90 int mTargetSdk;
Craig Mautnera2c77052012-03-26 12:14:43 -070091
Bryce Lee6d410262017-02-28 15:30:17 -080092 // Flag set while reparenting to prevent actions normally triggered by an individual parent
93 // change.
94 private boolean mReparenting;
95
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080096 // The input dispatching timeout for this application token in nanoseconds.
Wale Ogunwale72919d22016-12-08 18:58:50 -080097 long mInputDispatchingTimeoutNanos;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080098
99 // These are used for determining when all windows associated with
100 // an activity have been drawn, so they can be made visible together
101 // at the same time.
Craig Mautner764983d2012-03-22 11:37:36 -0700102 // initialize so that it doesn't match mTransactionSequence which is an int.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700103 private long mLastTransactionSequence = Long.MIN_VALUE;
104 private int mNumInterestingWindows;
105 private int mNumDrawnWindows;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800106 boolean inPendingTransaction;
107 boolean allDrawn;
Craig Mautner7636dfb2012-11-16 15:24:11 -0800108 // Set to true when this app creates a surface while in the middle of an animation. In that
109 // case do not clear allDrawn until the animation completes.
110 boolean deferClearAllDrawn;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800111
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700112 /**
113 * These are to track the app's real drawing status if there were no saved surfaces.
114 * @see #updateDrawnWindowStates
115 */
Chong Zhang8e4bda92016-05-04 15:08:18 -0700116 boolean allDrawnExcludingSaved;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700117 private int mNumInterestingWindowsExcludingSaved;
118 private int mNumDrawnWindowsExcludingSaved;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700119
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800120 // Is this window's surface needed? This is almost like hidden, except
121 // it will sometimes be true a little earlier: when the token has
122 // been shown, but is still waiting for its app transition to execute
123 // before making its windows shown.
124 boolean hiddenRequested;
125
126 // Have we told the window clients to hide themselves?
127 boolean clientHidden;
128
129 // Last visibility state we reported to the app token.
130 boolean reportedVisible;
131
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700132 // Last drawn state we reported to the app token.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700133 private boolean reportedDrawn;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700134
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800135 // Set to true when the token has been removed from the window mgr.
136 boolean removed;
137
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800138 // Information about an application starting window if displayed.
139 StartingData startingData;
140 WindowState startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800141 StartingSurface startingSurface;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800142 boolean startingDisplayed;
143 boolean startingMoved;
144 boolean firstWindowDrawn;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700145 private final WindowState.UpdateReportedVisibilityResults mReportedVisibilityResults =
146 new WindowState.UpdateReportedVisibilityResults();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800147
148 // Input application handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700149 final InputApplicationHandle mInputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800150
Wale Ogunwale571771c2016-08-26 13:18:50 -0700151 // TODO: Have a WindowContainer state for tracking exiting/deferred removal.
Craig Mautner799bc1d2015-01-14 10:33:48 -0800152 boolean mIsExiting;
Craig Mautner9ef471f2014-02-07 13:11:47 -0800153
Craig Mautnerbb742462014-07-07 15:28:55 -0700154 boolean mLaunchTaskBehind;
Craig Mautner8746a472014-07-24 15:12:54 -0700155 boolean mEnteringAnimation;
Craig Mautnerbb742462014-07-07 15:28:55 -0700156
Wale Ogunwale72919d22016-12-08 18:58:50 -0800157 private boolean mAlwaysFocusable;
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800158
Robert Carre12aece2016-02-02 22:43:27 -0800159 boolean mAppStopped;
Robert Carrfd10cd12016-06-29 16:41:50 -0700160 int mRotationAnimationHint;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700161 private int mPendingRelaunchCount;
Robert Carre12aece2016-02-02 22:43:27 -0800162
Jorim Jaggife762342016-10-13 14:33:27 +0200163 private boolean mLastContainsShowWhenLockedWindow;
164 private boolean mLastContainsDismissKeyguardWindow;
165
Robert Carr91b228092016-06-28 17:32:37 -0700166 private ArrayList<WindowSurfaceController.SurfaceControlWithBackground> mSurfaceViewBackgrounds =
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700167 new ArrayList<>();
Robert Carr91b228092016-06-28 17:32:37 -0700168
Jorim Jaggi0429f352015-12-22 16:29:16 +0100169 ArrayDeque<Rect> mFrozenBounds = new ArrayDeque<>();
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700170 ArrayDeque<Configuration> mFrozenMergedConfig = new ArrayDeque<>();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100171
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 }
371
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700372 if (!mService.mClosingApps.contains(this) && !mService.mOpeningApps.contains(this)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700373 // The token is not closing nor opening, so even if there is an animation set, that
374 // doesn't mean that it goes through the normal app transition cycle so we have
375 // to inform the docked controller about visibility change.
Andrii Kulian1e32e022016-09-16 15:29:34 -0700376 // TODO(multi-display): notify docked divider on all displays where visibility was
377 // affected.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700378 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700379 .notifyAppVisibilityChanged();
Jorim Jaggi8b702ed2017-01-20 16:59:03 +0100380 mService.mTaskSnapshotController.notifyAppVisibilityChanged(this, visible);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700381 }
382 }
383
384 return delayed;
385 }
386
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800387 WindowState findMainWindow() {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700388 WindowState candidate = null;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700389 int j = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800390 while (j > 0) {
391 j--;
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700392 final WindowState win = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700393 final int type = win.mAttrs.type;
394 // No need to loop through child window as base application and starting types can't be
395 // child windows.
396 if (type == TYPE_BASE_APPLICATION || type == TYPE_APPLICATION_STARTING) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700397 // In cases where there are multiple windows, we prefer the non-exiting window. This
Sungsoo Lim0d3d1f82015-12-02 14:47:59 +0900398 // happens for example when replacing windows during an activity relaunch. When
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700399 // constructing the animation, we want the new window, not the exiting one.
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800400 if (win.mAnimatingExit) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700401 candidate = win;
402 } else {
403 return win;
404 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800405 }
406 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700407 return candidate;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800408 }
409
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800410 boolean windowsAreFocusable() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800411 return StackId.canReceiveKeys(getTask().mStack.mStackId) || mAlwaysFocusable;
Wale Ogunwaled045c822015-12-02 09:14:28 -0800412 }
413
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800414 AppWindowContainerController getController() {
415 final WindowContainerController controller = super.getController();
416 return controller != null ? (AppWindowContainerController) controller : null;
417 }
418
Wale Ogunwale571771c2016-08-26 13:18:50 -0700419 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -0700420 boolean isVisible() {
Wale Ogunwalee471be62016-10-03 07:53:55 -0700421 // If the app token isn't hidden then it is considered visible and there is no need to check
422 // its children windows to see if they are visible.
423 return !hidden;
Wale Ogunwale44f21802016-09-02 12:49:48 -0700424 }
425
426 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -0700427 void removeIfPossible() {
Craig Mautnere3119b72015-01-20 15:02:36 -0800428 mIsExiting = false;
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800429 removeAllWindowsIfPossible();
Bryce Lee6d410262017-02-28 15:30:17 -0800430 removeImmediately();
Craig Mautnere3119b72015-01-20 15:02:36 -0800431 }
432
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700433 @Override
434 boolean checkCompleteDeferredRemoval() {
435 if (mIsExiting) {
436 removeIfPossible();
437 }
438 return super.checkCompleteDeferredRemoval();
439 }
440
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700441 void onRemovedFromDisplay() {
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700442 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app token: " + this);
443
Wale Ogunwale72919d22016-12-08 18:58:50 -0800444 boolean delayed = setVisibility(null, false, TRANSIT_UNSET, true, mVoiceInteraction);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700445
446 mService.mOpeningApps.remove(this);
Jorim Jaggi1b4b23e2016-11-15 16:30:12 -0800447 mService.mUnknownAppVisibilityController.appRemoved(this);
Jorim Jaggi10abe2f2017-01-03 16:44:46 +0100448 mService.mTaskSnapshotController.onAppRemoved(this);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700449 waitingToShow = false;
450 if (mService.mClosingApps.contains(this)) {
451 delayed = true;
452 } else if (mService.mAppTransition.isTransitionSet()) {
453 mService.mClosingApps.add(this);
454 delayed = true;
455 }
456
457 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app " + this + " delayed=" + delayed
458 + " animation=" + mAppAnimator.animation + " animating=" + mAppAnimator.animating);
459
460 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM, "removeAppToken: "
461 + this + " delayed=" + delayed + " Callers=" + Debug.getCallers(4));
462
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800463 if (startingData != null && getController() != null) {
464 getController().removeStartingWindow();
465 }
466
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800467 final TaskStack stack = getTask().mStack;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700468 if (delayed && !isEmpty()) {
469 // set the token aside because it has an active animation to be finished
470 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM,
471 "removeAppToken make exiting: " + this);
472 stack.mExitingAppTokens.add(this);
473 mIsExiting = true;
474 } else {
475 // Make sure there is no animation running on this token, so any windows associated
476 // with it will be removed as soon as their animations are complete
477 mAppAnimator.clearAnimation();
478 mAppAnimator.animating = false;
479 removeIfPossible();
480 }
481
482 removed = true;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700483 stopFreezingScreen(true, true);
Bryce Lee6d410262017-02-28 15:30:17 -0800484
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700485 if (mService.mFocusedApp == this) {
486 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "Removing focused app token:" + this);
487 mService.mFocusedApp = null;
488 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
489 mService.mInputMonitor.setFocusedAppLw(null);
490 }
491
492 if (!delayed) {
493 updateReportedVisibilityLocked();
494 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700495 }
496
Chong Zhange05bcb12016-07-26 17:47:29 -0700497 void clearAnimatingFlags() {
Chong Zhangb0d26702016-08-12 16:03:29 -0700498 boolean wallpaperMightChange = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700499 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700500 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700501 wallpaperMightChange |= win.clearAnimatingFlags();
Chong Zhange05bcb12016-07-26 17:47:29 -0700502 }
Chong Zhangb0d26702016-08-12 16:03:29 -0700503 if (wallpaperMightChange) {
504 requestUpdateWallpaperIfNeeded();
505 }
Chong Zhange05bcb12016-07-26 17:47:29 -0700506 }
507
Robert Carre12aece2016-02-02 22:43:27 -0800508 void destroySurfaces() {
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700509 destroySurfaces(false /*cleanupOnResume*/);
510 }
511
512 /**
513 * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure
514 * the client has finished with them.
515 *
516 * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If
517 * set to true, destroy only surfaces of removed windows, and clear relevant flags of the
518 * others so that they are ready to be reused. If set to false (common case), destroy all
519 * surfaces that's eligible, if the app is already stopped.
520 */
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700521 private void destroySurfaces(boolean cleanupOnResume) {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700522 boolean destroyedSomething = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700523 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700524 final WindowState win = mChildren.get(i);
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700525 destroyedSomething |= win.destroySurface(cleanupOnResume, mAppStopped);
Robert Carre12aece2016-02-02 22:43:27 -0800526 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700527 if (destroyedSomething) {
528 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700529 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Robert Carre12aece2016-02-02 22:43:27 -0800530 }
531 }
532
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800533 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700534 * Notify that the app is now resumed, and it was not stopped before, perform a clean
535 * up of the surfaces
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800536 */
Chong Zhangad24f962016-08-25 12:12:33 -0700537 void notifyAppResumed(boolean wasStopped, boolean allowSavedSurface) {
538 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped
539 + " allowSavedSurface=" + allowSavedSurface + " " + this);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700540 mAppStopped = false;
541 if (!wasStopped) {
542 destroySurfaces(true /*cleanupOnResume*/);
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800543 }
Chong Zhangad24f962016-08-25 12:12:33 -0700544 if (!allowSavedSurface) {
545 destroySavedSurfaces();
546 }
Robert Carre12aece2016-02-02 22:43:27 -0800547 }
548
Chong Zhangbef461f2015-10-27 11:38:24 -0700549 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700550 * Notify that the app has stopped, and it is okay to destroy any surfaces which were
551 * keeping alive in case they were still being used.
552 */
553 void notifyAppStopped() {
554 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this);
555 mAppStopped = true;
556 destroySurfaces();
557 // Remove any starting window that was added for this app if they are still around.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800558 if (getController() != null) {
559 getController().removeStartingWindow();
560 }
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700561 }
562
563 /**
Chong Zhangbef461f2015-10-27 11:38:24 -0700564 * Checks whether we should save surfaces for this app.
565 *
566 * @return true if the surfaces should be saved, false otherwise.
567 */
568 boolean shouldSaveSurface() {
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800569 // We want to save surface if the app's windows are "allDrawn".
570 // (If we started entering animation early with saved surfaces, allDrawn
571 // should have been restored to true. So we'll save again in that case
572 // even if app didn't actually finish drawing.)
573 return allDrawn;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800574 }
575
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700576 private boolean canRestoreSurfaces() {
577 for (int i = mChildren.size() -1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700578 final WindowState w = mChildren.get(i);
Chong Zhang92147042016-05-09 12:47:11 -0700579 if (w.canRestoreSurface()) {
Robert Carr13f7be9e2015-12-02 18:39:45 -0800580 return true;
581 }
Chong Zhangbef461f2015-10-27 11:38:24 -0700582 }
583 return false;
584 }
585
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700586 private void clearWasVisibleBeforeClientHidden() {
587 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700588 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700589 w.clearWasVisibleBeforeClientHidden();
Chong Zhang92147042016-05-09 12:47:11 -0700590 }
591 }
592
Chong Zhang8e4bda92016-05-04 15:08:18 -0700593 /**
594 * Whether the app has some window that is invisible in layout, but
595 * animating with saved surface.
596 */
597 boolean isAnimatingInvisibleWithSavedSurface() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700598 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700599 final WindowState w = mChildren.get(i);
Chong Zhang8e4bda92016-05-04 15:08:18 -0700600 if (w.isAnimatingInvisibleWithSavedSurface()) {
601 return true;
602 }
603 }
604 return false;
605 }
606
607 /**
608 * Hide all window surfaces that's still invisible in layout but animating
609 * with a saved surface, and mark them destroying.
610 */
611 void stopUsingSavedSurfaceLocked() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700612 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700613 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700614 w.stopUsingSavedSurface();
Chong Zhang8e4bda92016-05-04 15:08:18 -0700615 }
616 destroySurfaces();
617 }
618
Chong Zhangf58631a2016-05-24 16:02:10 -0700619 void markSavedSurfaceExiting() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700620 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700621 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700622 w.markSavedSurfaceExiting();
Chong Zhangf58631a2016-05-24 16:02:10 -0700623 }
624 }
625
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700626 void restoreSavedSurfaceForInterestingWindows() {
Chong Zhang92147042016-05-09 12:47:11 -0700627 if (!canRestoreSurfaces()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700628 clearWasVisibleBeforeClientHidden();
Chong Zhangbef461f2015-10-27 11:38:24 -0700629 return;
630 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700631
632 // Check if all interesting windows are drawn and we can mark allDrawn=true.
633 int interestingNotDrawn = -1;
634
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700635 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700636 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700637 interestingNotDrawn = w.restoreSavedSurfaceForInterestingWindow();
Chong Zhangbef461f2015-10-27 11:38:24 -0700638 }
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800639
Chong Zhang92147042016-05-09 12:47:11 -0700640 if (!allDrawn) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700641 allDrawn = (interestingNotDrawn == 0);
Chong Zhang92147042016-05-09 12:47:11 -0700642 if (allDrawn) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700643 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Chong Zhang92147042016-05-09 12:47:11 -0700644 }
645 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700646 clearWasVisibleBeforeClientHidden();
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800647
648 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700649 "restoreSavedSurfaceForInterestingWindows: " + this + " allDrawn=" + allDrawn
650 + " interestingNotDrawn=" + interestingNotDrawn);
Chong Zhangbef461f2015-10-27 11:38:24 -0700651 }
652
653 void destroySavedSurfaces() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700654 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700655 final WindowState win = mChildren.get(i);
Robert Carr13f7be9e2015-12-02 18:39:45 -0800656 win.destroySavedSurface();
Chong Zhangbef461f2015-10-27 11:38:24 -0700657 }
Chong Zhang92147042016-05-09 12:47:11 -0700658 }
659
660 void clearAllDrawn() {
661 allDrawn = false;
662 deferClearAllDrawn = false;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700663 allDrawnExcludingSaved = false;
Chong Zhangbef461f2015-10-27 11:38:24 -0700664 }
665
Bryce Lee6d410262017-02-28 15:30:17 -0800666 Task getTask() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800667 return (Task) getParent();
Bryce Lee6d410262017-02-28 15:30:17 -0800668 }
669
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800670 TaskStack getStack() {
671 final Task task = getTask();
672 if (task != null) {
673 return task.mStack;
674 } else {
675 return null;
676 }
677 }
678
Bryce Lee6d410262017-02-28 15:30:17 -0800679 @Override
680 void onParentSet() {
681 super.onParentSet();
682
683 // When the associated task is {@code null}, the {@link AppWindowToken} can no longer
684 // access visual elements like the {@link DisplayContent}. We must remove any associations
685 // such as animations.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800686 if (!mReparenting) {
687 final Task task = getTask();
688 if (task == null) {
689 // It is possible we have been marked as a closing app earlier. We must remove ourselves
690 // from this list so we do not participate in any future animations.
691 mService.mClosingApps.remove(this);
692 } else if (task.mStack != null) {
693 task.mStack.mExitingAppTokens.remove(this);
694 }
Bryce Lee6d410262017-02-28 15:30:17 -0800695 }
696 }
697
Wale Ogunwalefa854eb2016-09-20 13:43:52 -0700698 void postWindowRemoveStartingWindowCleanup(WindowState win) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700699 // TODO: Something smells about the code below...Is there a better way?
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700700 if (startingWindow == win) {
701 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800702 if (getController() != null) {
703 getController().removeStartingWindow();
704 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700705 } else if (mChildren.size() == 0 && startingData != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700706 // If this is the last window and we had requested a starting transition window,
707 // well there is no point now.
Jorim Jaggi02886a82016-12-06 09:10:06 -0800708 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingData");
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700709 startingData = null;
Jorim Jaggi829b9cd2017-01-23 16:20:53 +0100710 } else if (mChildren.size() == 1 && startingSurface != null && !isRelaunching()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700711 // If this is the last window except for a starting transition window,
712 // we need to get rid of the starting transition.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800713 if (getController() != null) {
714 getController().removeStartingWindow();
715 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700716 }
717 }
718
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700719 void removeDeadWindows() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700720 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700721 WindowState win = mChildren.get(winNdx);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800722 if (win.mAppDied) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700723 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700724 "removeDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800725 // Set mDestroying, we don't want any animation or delayed removal here.
726 win.mDestroying = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700727 // Also removes child windows.
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700728 win.removeIfPossible();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800729 }
730 }
731 }
732
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700733 boolean hasWindowsAlive() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700734 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700735 // No need to loop through child windows as the answer should be the same as that of the
736 // parent window.
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700737 if (!(mChildren.get(i)).mAppDied) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700738 return true;
739 }
740 }
741 return false;
742 }
743
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700744 void setWillReplaceWindows(boolean animate) {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700745 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
746 "Marking app token " + this + " with replacing windows.");
Robert Carra1eb4392015-12-10 12:43:51 -0800747
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700748 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700749 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700750 w.setWillReplaceWindow(animate);
Robert Carra1eb4392015-12-10 12:43:51 -0800751 }
752 if (animate) {
753 // Set-up dummy animation so we can start treating windows associated with this
754 // token like they are in transition before the new app window is ready for us to
755 // run the real transition animation.
756 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700757 "setWillReplaceWindow() Setting dummy animation on: " + this);
Robert Carra1eb4392015-12-10 12:43:51 -0800758 mAppAnimator.setDummyAnimation();
759 }
760 }
761
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700762 void setWillReplaceChildWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700763 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this
Robert Carr23fa16b2016-01-13 13:19:58 -0800764 + " with replacing child windows.");
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700765 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700766 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700767 w.setWillReplaceChildWindows();
Robert Carr23fa16b2016-01-13 13:19:58 -0800768 }
769 }
770
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700771 void clearWillReplaceWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700772 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
773 "Resetting app token " + this + " of replacing window marks.");
Chong Zhangf596cd52016-01-05 13:42:44 -0800774
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700775 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700776 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700777 w.clearWillReplaceWindow();
Chong Zhangf596cd52016-01-05 13:42:44 -0800778 }
779 }
780
Chong Zhang4d7369a2016-04-25 16:09:14 -0700781 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700782 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700783 final WindowState w = mChildren.get(i);
Chong Zhang4d7369a2016-04-25 16:09:14 -0700784 w.requestUpdateWallpaperIfNeeded();
785 }
786 }
787
Chong Zhangd78ddb42016-03-02 17:01:14 -0800788 boolean isRelaunching() {
789 return mPendingRelaunchCount > 0;
790 }
791
792 void startRelaunching() {
793 if (canFreezeBounds()) {
794 freezeBounds();
795 }
Robert Carrd5c7dd62017-03-08 10:39:30 -0800796
797 // In the process of tearing down before relaunching, the app will
798 // try and clean up it's child surfaces. We need to prevent this from
799 // happening, so we sever the children, transfering their ownership
800 // from the client it-self to the parent surface (owned by us).
801 for (int i = mChildren.size() - 1; i >= 0; i--) {
802 final WindowState w = mChildren.get(i);
803 w.mWinAnimator.detachChildren();
804 }
805
Chong Zhangd78ddb42016-03-02 17:01:14 -0800806 mPendingRelaunchCount++;
807 }
808
809 void finishRelaunching() {
810 if (canFreezeBounds()) {
811 unfreezeBounds();
812 }
813 if (mPendingRelaunchCount > 0) {
814 mPendingRelaunchCount--;
815 }
816 }
817
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700818 void clearRelaunching() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700819 if (mPendingRelaunchCount == 0) {
820 return;
821 }
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700822 if (canFreezeBounds()) {
823 unfreezeBounds();
824 }
825 mPendingRelaunchCount = 0;
826 }
827
Wale Ogunwale07bcab72016-10-14 15:30:09 -0700828 /**
829 * Returns true if the new child window we are adding to this token is considered greater than
830 * the existing child window in this token in terms of z-order.
831 */
832 @Override
833 protected boolean isFirstChildWindowGreaterThanSecond(WindowState newWindow,
834 WindowState existingWindow) {
835 final int type1 = newWindow.mAttrs.type;
836 final int type2 = existingWindow.mAttrs.type;
837
838 // Base application windows should be z-ordered BELOW all other windows in the app token.
839 if (type1 == TYPE_BASE_APPLICATION && type2 != TYPE_BASE_APPLICATION) {
840 return false;
841 } else if (type1 != TYPE_BASE_APPLICATION && type2 == TYPE_BASE_APPLICATION) {
842 return true;
843 }
844
845 // Starting windows should be z-ordered ABOVE all other windows in the app token.
846 if (type1 == TYPE_APPLICATION_STARTING && type2 != TYPE_APPLICATION_STARTING) {
847 return true;
848 } else if (type1 != TYPE_APPLICATION_STARTING && type2 == TYPE_APPLICATION_STARTING) {
849 return false;
850 }
851
852 // Otherwise the new window is greater than the existing window.
853 return true;
854 }
855
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700856 @Override
Robert Carra1eb4392015-12-10 12:43:51 -0800857 void addWindow(WindowState w) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700858 super.addWindow(w);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700859
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700860 boolean gotReplacementWindow = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700861 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700862 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700863 gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w);
864 }
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700865
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700866 // if we got a replacement window, reset the timeout to give drawing more time
867 if (gotReplacementWindow) {
868 mService.scheduleWindowReplacementTimeouts(this);
Robert Carra1eb4392015-12-10 12:43:51 -0800869 }
Jorim Jaggife762342016-10-13 14:33:27 +0200870 checkKeyguardFlagsChanged();
871 }
872
873 @Override
874 void removeChild(WindowState child) {
875 super.removeChild(child);
876 checkKeyguardFlagsChanged();
Robert Carra1eb4392015-12-10 12:43:51 -0800877 }
878
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700879 private boolean waitingForReplacement() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700880 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700881 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700882 if (candidate.waitingForReplacement()) {
Robert Carra1eb4392015-12-10 12:43:51 -0800883 return true;
884 }
885 }
886 return false;
887 }
888
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700889 void onWindowReplacementTimeout() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700890 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700891 (mChildren.get(i)).onWindowReplacementTimeout();
Robert Carra1eb4392015-12-10 12:43:51 -0800892 }
893 }
894
Winson Chung30480042017-01-26 10:55:34 -0800895 void reparent(Task task, int position) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800896 final Task currentTask = getTask();
897 if (task == currentTask) {
Winson Chung30480042017-01-26 10:55:34 -0800898 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800899 "window token=" + this + " already child of task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -0800900 }
Bryce Lee6d410262017-02-28 15:30:17 -0800901
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800902 if (currentTask.mStack != task.mStack) {
Bryce Lee6d410262017-02-28 15:30:17 -0800903 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800904 "window token=" + this + " current task=" + currentTask
Bryce Lee6d410262017-02-28 15:30:17 -0800905 + " belongs to a different stack than " + task);
906 }
907
Winson Chung30480042017-01-26 10:55:34 -0800908 if (DEBUG_ADD_REMOVE) Slog.i(TAG, "reParentWindowToken: removing window token=" + this
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800909 + " from task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -0800910 final DisplayContent prevDisplayContent = getDisplayContent();
911
Bryce Lee6d410262017-02-28 15:30:17 -0800912 mReparenting = true;
913
Winson Chung30480042017-01-26 10:55:34 -0800914 getParent().removeChild(this);
915 task.addChild(this, position);
916
Bryce Lee6d410262017-02-28 15:30:17 -0800917 mReparenting = false;
918
Winson Chung30480042017-01-26 10:55:34 -0800919 // Relayout display(s).
920 final DisplayContent displayContent = task.getDisplayContent();
921 displayContent.setLayoutNeeded();
922 if (prevDisplayContent != displayContent) {
923 onDisplayChanged(displayContent);
924 prevDisplayContent.setLayoutNeeded();
925 }
926 }
927
Chong Zhangd78ddb42016-03-02 17:01:14 -0800928 private boolean canFreezeBounds() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800929 final Task task = getTask();
930
Chong Zhangd78ddb42016-03-02 17:01:14 -0800931 // For freeform windows, we can't freeze the bounds at the moment because this would make
932 // the resizing unresponsive.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800933 return task != null && !task.inFreeformWorkspace();
Chong Zhangd78ddb42016-03-02 17:01:14 -0800934 }
935
Jorim Jaggi0429f352015-12-22 16:29:16 +0100936 /**
937 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
938 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
939 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
940 * with a queue.
941 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800942 private void freezeBounds() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800943 final Task task = getTask();
944 mFrozenBounds.offer(new Rect(task.mPreparedFrozenBounds));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700945
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800946 if (task.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) {
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700947 // We didn't call prepareFreezingBounds on the task, so use the current value.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800948 mFrozenMergedConfig.offer(new Configuration(task.getConfiguration()));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700949 } else {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800950 mFrozenMergedConfig.offer(new Configuration(task.mPreparedFrozenMergedConfig));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700951 }
Andrii Kulianb10330d2016-09-16 13:51:46 -0700952 // Calling unset() to make it equal to Configuration.EMPTY.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800953 task.mPreparedFrozenMergedConfig.unset();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100954 }
955
956 /**
957 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
958 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800959 private void unfreezeBounds() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700960 if (!mFrozenBounds.isEmpty()) {
961 mFrozenBounds.remove();
962 }
963 if (!mFrozenMergedConfig.isEmpty()) {
964 mFrozenMergedConfig.remove();
965 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700966 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700967 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700968 win.onUnfreezeBounds();
Jorim Jaggi4846ee32016-01-07 17:39:12 +0100969 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700970 mService.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100971 }
972
Robert Carr91b228092016-06-28 17:32:37 -0700973 void addSurfaceViewBackground(WindowSurfaceController.SurfaceControlWithBackground background) {
974 mSurfaceViewBackgrounds.add(background);
975 }
976
977 void removeSurfaceViewBackground(WindowSurfaceController.SurfaceControlWithBackground background) {
978 mSurfaceViewBackgrounds.remove(background);
979 updateSurfaceViewBackgroundVisibilities();
980 }
981
982 // We use DimLayers behind SurfaceViews to prevent holes while resizing and creating.
983 // However, we need to ensure one SurfaceView doesn't cover another when they are both placed
984 // below the main app window (as traditionally a SurfaceView which is never drawn
985 // to is totally translucent). So we look at all our SurfaceView backgrounds and only enable
986 // the background for the SurfaceView with lowest Z order
987 void updateSurfaceViewBackgroundVisibilities() {
988 WindowSurfaceController.SurfaceControlWithBackground bottom = null;
989 int bottomLayer = Integer.MAX_VALUE;
990 for (int i = 0; i < mSurfaceViewBackgrounds.size(); i++) {
991 WindowSurfaceController.SurfaceControlWithBackground sc = mSurfaceViewBackgrounds.get(i);
992 if (sc.mVisible && sc.mLayer < bottomLayer) {
993 bottomLayer = sc.mLayer;
994 bottom = sc;
995 }
996 }
997 for (int i = 0; i < mSurfaceViewBackgrounds.size(); i++) {
998 WindowSurfaceController.SurfaceControlWithBackground sc = mSurfaceViewBackgrounds.get(i);
999 sc.updateBackgroundVisibility(sc != bottom);
1000 }
1001 }
1002
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001003 void resetJustMovedInStack() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001004 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001005 (mChildren.get(i)).resetJustMovedInStack();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001006 }
1007 }
1008
1009 void notifyMovedInStack() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001010 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001011 final WindowState win = mChildren.get(winNdx);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001012 win.notifyMovedInStack();
1013 }
1014 }
1015
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001016 void setAppLayoutChanges(int changes, String reason) {
1017 if (!mChildren.isEmpty()) {
1018 final DisplayContent dc = getDisplayContent();
1019 dc.pendingLayoutChanges |= changes;
1020 if (DEBUG_LAYOUT_REPEATS) {
1021 mService.mWindowPlacerLocked.debugLayoutRepeats(reason, dc.pendingLayoutChanges);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001022 }
1023 }
1024 }
1025
1026 void removeReplacedWindowIfNeeded(WindowState replacement) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001027 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001028 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001029 if (win.removeReplacedWindowIfNeeded(replacement)) {
1030 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001031 }
1032 }
1033 }
1034
1035 void startFreezingScreen() {
1036 if (DEBUG_ORIENTATION) logWithStack(TAG, "Set freezing of " + appToken + ": hidden="
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001037 + hidden + " freezing=" + mAppAnimator.freezingScreen + " hiddenRequested="
1038 + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001039 if (!hiddenRequested) {
1040 if (!mAppAnimator.freezingScreen) {
1041 mAppAnimator.freezingScreen = true;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001042 mService.registerAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001043 mAppAnimator.lastFreezeDuration = 0;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001044 mService.mAppsFreezingScreen++;
1045 if (mService.mAppsFreezingScreen == 1) {
1046 mService.startFreezingDisplayLocked(false, 0, 0);
1047 mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT);
1048 mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001049 }
1050 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001051 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001052 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001053 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001054 w.onStartFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001055 }
1056 }
1057 }
1058
1059 void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) {
1060 if (!mAppAnimator.freezingScreen) {
1061 return;
1062 }
1063 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + this + " force=" + force);
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001064 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001065 boolean unfrozeWindows = false;
1066 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001067 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001068 unfrozeWindows |= w.onStopFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001069 }
1070 if (force || unfrozeWindows) {
1071 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this);
1072 mAppAnimator.freezingScreen = false;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001073 mService.unregisterAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001074 mAppAnimator.lastFreezeDuration =
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001075 (int)(SystemClock.elapsedRealtime() - mService.mDisplayFreezeTime);
1076 mService.mAppsFreezingScreen--;
1077 mService.mLastFinishedFreezeSource = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001078 }
1079 if (unfreezeSurfaceNow) {
1080 if (unfrozeWindows) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001081 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001082 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001083 mService.stopFreezingDisplayLocked();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001084 }
1085 }
1086
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001087 @Override
1088 public void onAppFreezeTimeout() {
1089 Slog.w(TAG_WM, "Force clearing freeze: " + this);
1090 stopFreezingScreen(true, true);
1091 }
1092
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001093 boolean transferStartingWindow(IBinder transferFrom) {
Wale Ogunwale02319a62016-09-26 15:21:22 -07001094 final AppWindowToken fromToken = getDisplayContent().getAppWindowToken(transferFrom);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001095 if (fromToken == null) {
1096 return false;
1097 }
1098
1099 final WindowState tStartingWindow = fromToken.startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001100 if (tStartingWindow != null && fromToken.startingSurface != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001101 // In this case, the starting icon has already been displayed, so start
1102 // letting windows get shown immediately without any more transitions.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001103 mService.mSkipAppTransitionAnimation = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001104
1105 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow
1106 + " from " + fromToken + " to " + this);
1107
1108 final long origId = Binder.clearCallingIdentity();
1109
1110 // Transfer the starting window over to the new token.
1111 startingData = fromToken.startingData;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001112 startingSurface = fromToken.startingSurface;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001113 startingDisplayed = fromToken.startingDisplayed;
1114 fromToken.startingDisplayed = false;
1115 startingWindow = tStartingWindow;
1116 reportedVisible = fromToken.reportedVisible;
1117 fromToken.startingData = null;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001118 fromToken.startingSurface = null;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001119 fromToken.startingWindow = null;
1120 fromToken.startingMoved = true;
1121 tStartingWindow.mToken = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001122 tStartingWindow.mAppToken = this;
1123
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001124 if (DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001125 "Removing starting " + tStartingWindow + " from " + fromToken);
Wale Ogunwalefa854eb2016-09-20 13:43:52 -07001126 fromToken.removeChild(tStartingWindow);
1127 fromToken.postWindowRemoveStartingWindowCleanup(tStartingWindow);
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001128 addWindow(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001129
1130 // Propagate other interesting state between the tokens. If the old token is displayed,
1131 // we should immediately force the new one to be displayed. If it is animating, we need
1132 // to move that animation to the new one.
1133 if (fromToken.allDrawn) {
1134 allDrawn = true;
1135 deferClearAllDrawn = fromToken.deferClearAllDrawn;
1136 }
1137 if (fromToken.firstWindowDrawn) {
1138 firstWindowDrawn = true;
1139 }
1140 if (!fromToken.hidden) {
1141 hidden = false;
1142 hiddenRequested = false;
1143 }
1144 if (clientHidden != fromToken.clientHidden) {
1145 clientHidden = fromToken.clientHidden;
1146 sendAppVisibilityToClients();
1147 }
1148 fromToken.mAppAnimator.transferCurrentAnimation(
1149 mAppAnimator, tStartingWindow.mWinAnimator);
1150
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001151 mService.updateFocusedWindowLocked(
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001152 UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/);
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001153 getDisplayContent().setLayoutNeeded();
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001154 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001155 Binder.restoreCallingIdentity(origId);
1156 return true;
1157 } else if (fromToken.startingData != null) {
1158 // The previous app was getting ready to show a
1159 // starting window, but hasn't yet done so. Steal it!
1160 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1161 "Moving pending starting from " + fromToken + " to " + this);
1162 startingData = fromToken.startingData;
1163 fromToken.startingData = null;
1164 fromToken.startingMoved = true;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001165 if (getController() != null) {
1166 getController().scheduleAddStartingWindow();
1167 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001168 return true;
1169 }
1170
1171 final AppWindowAnimator tAppAnimator = fromToken.mAppAnimator;
1172 final AppWindowAnimator wAppAnimator = mAppAnimator;
1173 if (tAppAnimator.thumbnail != null) {
1174 // The old token is animating with a thumbnail, transfer that to the new token.
1175 if (wAppAnimator.thumbnail != null) {
1176 wAppAnimator.thumbnail.destroy();
1177 }
1178 wAppAnimator.thumbnail = tAppAnimator.thumbnail;
1179 wAppAnimator.thumbnailLayer = tAppAnimator.thumbnailLayer;
1180 wAppAnimator.thumbnailAnimation = tAppAnimator.thumbnailAnimation;
1181 tAppAnimator.thumbnail = null;
1182 }
1183 return false;
1184 }
1185
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001186 boolean isLastWindow(WindowState win) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001187 return mChildren.size() == 1 && mChildren.get(0) == win;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001188 }
1189
1190 void setAllAppWinAnimators() {
1191 final ArrayList<WindowStateAnimator> allAppWinAnimators = mAppAnimator.mAllAppWinAnimators;
1192 allAppWinAnimators.clear();
1193
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001194 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001195 for (int j = 0; j < windowsCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001196 (mChildren.get(j)).addWinAnimatorToList(allAppWinAnimators);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001197 }
1198 }
1199
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001200 @Override
1201 void onAppTransitionDone() {
1202 sendingToBottom = false;
1203 }
1204
Wale Ogunwale51362492016-09-08 17:49:17 -07001205 /**
1206 * We override because this class doesn't want its children affecting its reported orientation
1207 * in anyway.
1208 */
1209 @Override
1210 int getOrientation() {
Bryce Leea163b762017-01-24 11:05:01 -08001211 if (fillsParent() && (isVisible() || mService.mOpeningApps.contains(this))) {
1212 return mOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001213 }
Bryce Leea163b762017-01-24 11:05:01 -08001214
1215 return SCREEN_ORIENTATION_UNSET;
Wale Ogunwale51362492016-09-08 17:49:17 -07001216 }
1217
Wale Ogunwaleb198b742016-12-01 08:44:09 -08001218 /** Returns the app's preferred orientation regardless of its currently visibility state. */
1219 int getOrientationIgnoreVisibility() {
1220 return mOrientation;
1221 }
1222
Craig Mautnerdbb79912012-03-01 18:59:14 -08001223 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001224 void checkAppWindowsReadyToShow() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001225 if (allDrawn == mAppAnimator.allDrawn) {
1226 return;
1227 }
1228
1229 mAppAnimator.allDrawn = allDrawn;
1230 if (!allDrawn) {
1231 return;
1232 }
1233
1234 // The token has now changed state to having all windows shown... what to do, what to do?
1235 if (mAppAnimator.freezingScreen) {
1236 mAppAnimator.showAllWindowsLocked();
1237 stopFreezingScreen(false, true);
1238 if (DEBUG_ORIENTATION) Slog.i(TAG,
1239 "Setting mOrientationChangeComplete=true because wtoken " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001240 + " numInteresting=" + mNumInterestingWindows + " numDrawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001241 // This will set mOrientationChangeComplete and cause a pass through layout.
1242 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001243 "checkAppWindowsReadyToShow: freezingScreen");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001244 } else {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001245 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001246
1247 // We can now show all of the drawn windows!
1248 if (!mService.mOpeningApps.contains(this)) {
1249 mService.mAnimator.orAnimating(mAppAnimator.showAllWindowsLocked());
1250 }
1251 }
1252 }
1253
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001254 void updateAllDrawn(DisplayContent dc) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001255 if (!allDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001256 final int numInteresting = mNumInterestingWindows;
1257 if (numInteresting > 0 && mNumDrawnWindows >= numInteresting) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001258 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawn: " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001259 + " interesting=" + numInteresting + " drawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001260 allDrawn = true;
1261 // Force an additional layout pass where
1262 // WindowStateAnimator#commitFinishDrawingLocked() will call performShowLocked().
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001263 dc.setLayoutNeeded();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001264 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
1265 }
1266 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001267
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001268 if (!allDrawnExcludingSaved) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001269 int numInteresting = mNumInterestingWindowsExcludingSaved;
1270 if (numInteresting > 0 && mNumDrawnWindowsExcludingSaved >= numInteresting) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001271 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawnExcludingSaved: " + this
1272 + " interesting=" + numInteresting
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001273 + " drawn=" + mNumDrawnWindowsExcludingSaved);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001274 allDrawnExcludingSaved = true;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001275 dc.setLayoutNeeded();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001276 if (isAnimatingInvisibleWithSavedSurface()
1277 && !mService.mFinishedEarlyAnim.contains(this)) {
1278 mService.mFinishedEarlyAnim.add(this);
1279 }
1280 }
1281 }
1282 }
1283
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001284 /**
1285 * Updated this app token tracking states for interesting and drawn windows based on the window.
1286 *
1287 * @return Returns true if the input window is considered interesting and drawn while all the
1288 * windows in this app token where not considered drawn as of the last pass.
1289 */
1290 boolean updateDrawnWindowStates(WindowState w) {
1291 if (DEBUG_STARTING_WINDOW && w == startingWindow) {
1292 Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" + w.isOnScreen()
1293 + " allDrawn=" + allDrawn + " freezingScreen=" + mAppAnimator.freezingScreen);
1294 }
1295
1296 if (allDrawn && allDrawnExcludingSaved && !mAppAnimator.freezingScreen) {
1297 return false;
1298 }
1299
1300 if (mLastTransactionSequence != mService.mTransactionSequence) {
1301 mLastTransactionSequence = mService.mTransactionSequence;
1302 mNumInterestingWindows = mNumDrawnWindows = 0;
1303 mNumInterestingWindowsExcludingSaved = 0;
1304 mNumDrawnWindowsExcludingSaved = 0;
1305 startingDisplayed = false;
1306 }
1307
1308 final WindowStateAnimator winAnimator = w.mWinAnimator;
1309
1310 boolean isInterestingAndDrawn = false;
1311
1312 if (!allDrawn && w.mightAffectAllDrawn(false /* visibleOnly */)) {
1313 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
1314 Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw()
1315 + ", isAnimationSet=" + winAnimator.isAnimationSet());
1316 if (!w.isDrawnLw()) {
1317 Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController
1318 + " pv=" + w.mPolicyVisibility
1319 + " mDrawState=" + winAnimator.drawStateToString()
1320 + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested
1321 + " a=" + winAnimator.mAnimating);
1322 }
1323 }
1324
1325 if (w != startingWindow) {
1326 if (w.isInteresting()) {
1327 mNumInterestingWindows++;
1328 if (w.isDrawnLw()) {
1329 mNumDrawnWindows++;
1330
1331 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, "tokenMayBeDrawn: "
1332 + this + " w=" + w + " numInteresting=" + mNumInterestingWindows
1333 + " freezingScreen=" + mAppAnimator.freezingScreen
1334 + " mAppFreezing=" + w.mAppFreezing);
1335
1336 isInterestingAndDrawn = true;
1337 }
1338 }
1339 } else if (w.isDrawnLw()) {
Jorim Jaggi3878ca32017-02-02 17:13:05 -08001340 if (getController() != null) {
1341 getController().reportStartingWindowDrawn();
1342 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001343 startingDisplayed = true;
1344 }
1345 }
1346
1347 if (!allDrawnExcludingSaved && w.mightAffectAllDrawn(true /* visibleOnly */)) {
1348 if (w != startingWindow && w.isInteresting()) {
1349 mNumInterestingWindowsExcludingSaved++;
1350 if (w.isDrawnLw() && !w.isAnimatingWithSavedSurface()) {
1351 mNumDrawnWindowsExcludingSaved++;
1352
1353 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
1354 "tokenMayBeDrawnExcludingSaved: " + this + " w=" + w
1355 + " numInteresting=" + mNumInterestingWindowsExcludingSaved
1356 + " freezingScreen=" + mAppAnimator.freezingScreen
1357 + " mAppFreezing=" + w.mAppFreezing);
1358
1359 isInterestingAndDrawn = true;
1360 }
1361 }
1362 }
1363
1364 return isInterestingAndDrawn;
1365 }
1366
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001367 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001368 void stepAppWindowsAnimation(long currentTime) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001369 mAppAnimator.wasAnimating = mAppAnimator.animating;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001370 if (mAppAnimator.stepAnimationLocked(currentTime)) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001371 mAppAnimator.animating = true;
1372 mService.mAnimator.setAnimating(true);
1373 mService.mAnimator.mAppWindowAnimating = true;
1374 } else if (mAppAnimator.wasAnimating) {
1375 // stopped animating, do one more pass through the layout
Wale Ogunwale1e129a42016-11-21 13:03:47 -08001376 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
1377 DEBUG_LAYOUT_REPEATS ? "appToken " + this + " done" : null);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001378 if (DEBUG_ANIM) Slog.v(TAG, "updateWindowsApps...: done animating " + this);
1379 }
1380 }
1381
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001382 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001383 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001384 // For legacy reasons we process the TaskStack.mExitingAppTokens first in DisplayContent
1385 // before the non-exiting app tokens. So, we skip the exiting app tokens here.
1386 // TODO: Investigate if we need to continue to do this or if we can just process them
1387 // in-order.
1388 if (mIsExiting && !waitingForReplacement()) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001389 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001390 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001391 return forAllWindowsUnchecked(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001392 }
1393
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001394 boolean forAllWindowsUnchecked(ToBooleanFunction<WindowState> callback,
1395 boolean traverseTopToBottom) {
1396 return super.forAllWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001397 }
1398
1399 @Override
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001400 AppWindowToken asAppWindowToken() {
1401 // I am an app window token!
1402 return this;
1403 }
1404
1405 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -07001406 boolean fillsParent() {
1407 return mFillsParent;
1408 }
1409
1410 void setFillsParent(boolean fillsParent) {
1411 mFillsParent = fillsParent;
1412 }
1413
Jorim Jaggife762342016-10-13 14:33:27 +02001414 boolean containsDismissKeyguardWindow() {
1415 for (int i = mChildren.size() - 1; i >= 0; i--) {
1416 if ((mChildren.get(i).mAttrs.flags & FLAG_DISMISS_KEYGUARD) != 0) {
1417 return true;
1418 }
1419 }
1420 return false;
1421 }
1422
1423 boolean containsShowWhenLockedWindow() {
1424 for (int i = mChildren.size() - 1; i >= 0; i--) {
1425 if ((mChildren.get(i).mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
1426 return true;
1427 }
1428 }
1429 return false;
1430 }
1431
1432 void checkKeyguardFlagsChanged() {
1433 final boolean containsDismissKeyguard = containsDismissKeyguardWindow();
1434 final boolean containsShowWhenLocked = containsShowWhenLockedWindow();
1435 if (containsDismissKeyguard != mLastContainsDismissKeyguardWindow
1436 || containsShowWhenLocked != mLastContainsShowWhenLockedWindow) {
1437 mService.notifyKeyguardFlagsChanged(null /* callback */);
1438 }
1439 mLastContainsDismissKeyguardWindow = containsDismissKeyguard;
1440 mLastContainsShowWhenLockedWindow = containsShowWhenLocked;
1441 }
1442
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001443 WindowState getImeTargetBelowWindow(WindowState w) {
1444 final int index = mChildren.indexOf(w);
1445 if (index > 0) {
1446 final WindowState target = mChildren.get(index - 1);
1447 if (target.canBeImeTarget()) {
1448 return target;
1449 }
1450 }
1451 return null;
1452 }
1453
1454 WindowState getHighestAnimLayerWindow(WindowState currentTarget) {
1455 WindowState candidate = null;
1456 for (int i = mChildren.indexOf(currentTarget); i >= 0; i--) {
1457 final WindowState w = mChildren.get(i);
1458 if (w.mRemoved) {
1459 continue;
1460 }
1461 if (candidate == null || w.mWinAnimator.mAnimLayer >
1462 candidate.mWinAnimator.mAnimLayer) {
1463 candidate = w;
1464 }
1465 }
1466 return candidate;
1467 }
1468
Wale Ogunwale51362492016-09-08 17:49:17 -07001469 @Override
Robert Carrdee1b3f2017-02-27 11:33:33 -08001470 int getAnimLayerAdjustment() {
1471 return mAppAnimator.animLayerAdjustment;
1472 }
1473
1474 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001475 void dump(PrintWriter pw, String prefix) {
1476 super.dump(pw, prefix);
1477 if (appToken != null) {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001478 pw.println(prefix + "app=true mVoiceInteraction=" + mVoiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001479 }
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001480 pw.print(prefix); pw.print("task="); pw.println(getTask());
Wale Ogunwale51362492016-09-08 17:49:17 -07001481 pw.print(prefix); pw.print(" mFillsParent="); pw.print(mFillsParent);
1482 pw.print(" mOrientation="); pw.println(mOrientation);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001483 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
1484 pw.print(" clientHidden="); pw.print(clientHidden);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -07001485 pw.print(" reportedDrawn="); pw.print(reportedDrawn);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001486 pw.print(" reportedVisible="); pw.println(reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -07001487 if (paused) {
1488 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001489 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001490 if (mAppStopped) {
1491 pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped);
1492 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001493 if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0
Craig Mautner6fbda632012-07-03 09:26:39 -07001494 || allDrawn || mAppAnimator.allDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001495 pw.print(prefix); pw.print("mNumInterestingWindows=");
1496 pw.print(mNumInterestingWindows);
1497 pw.print(" mNumDrawnWindows="); pw.print(mNumDrawnWindows);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001498 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -07001499 pw.print(" allDrawn="); pw.print(allDrawn);
1500 pw.print(" (animator="); pw.print(mAppAnimator.allDrawn);
1501 pw.println(")");
1502 }
1503 if (inPendingTransaction) {
1504 pw.print(prefix); pw.print("inPendingTransaction=");
1505 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001506 }
Craig Mautner799bc1d2015-01-14 10:33:48 -08001507 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001508 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
1509 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -08001510 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -08001511 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001512 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001513 if (startingWindow != null || startingSurface != null
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001514 || startingDisplayed || startingMoved) {
1515 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001516 pw.print(" startingSurface="); pw.print(startingSurface);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001517 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001518 pw.print(" startingMoved="); pw.println(startingMoved);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001519 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01001520 if (!mFrozenBounds.isEmpty()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -08001521 pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds);
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001522 pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig);
Chong Zhangd78ddb42016-03-02 17:01:14 -08001523 }
1524 if (mPendingRelaunchCount != 0) {
1525 pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount);
Jorim Jaggi0429f352015-12-22 16:29:16 +01001526 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001527 }
1528
1529 @Override
1530 public String toString() {
1531 if (stringName == null) {
1532 StringBuilder sb = new StringBuilder();
1533 sb.append("AppWindowToken{");
1534 sb.append(Integer.toHexString(System.identityHashCode(this)));
1535 sb.append(" token="); sb.append(token); sb.append('}');
1536 stringName = sb.toString();
1537 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001538 return stringName + ((mIsExiting) ? " mIsExiting=" : "");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001539 }
Jeff Browne9bdb312012-04-05 15:30:10 -07001540}