blob: 4aa013ae90c1eb2afe323c9ece20df4c9298373e [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 Ogunwale9d9d8f12016-09-28 15:29:59 -070045import static com.android.server.wm.WindowManagerService.H.NOTIFY_STARTING_WINDOW_DRAWN;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070046import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070047import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070048import static com.android.server.wm.WindowManagerService.logWithStack;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080049
Filip Gruszczynskia590c992015-11-25 16:45:26 -080050import android.annotation.NonNull;
Jorim Jaggi26c8c422016-05-09 19:57:25 -070051import android.content.res.Configuration;
Jorim Jaggi0429f352015-12-22 16:29:16 +010052import android.graphics.Rect;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070053import android.os.Binder;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080054import android.os.Debug;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070055import android.os.IBinder;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070056import android.os.SystemClock;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080057import android.util.Slog;
58import android.view.IApplicationToken;
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
Robert Carr91b228092016-06-28 17:32:37 -0700167 private ArrayList<WindowSurfaceController.SurfaceControlWithBackground> mSurfaceViewBackgrounds =
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700168 new ArrayList<>();
Robert Carr91b228092016-06-28 17:32:37 -0700169
Jorim Jaggi0429f352015-12-22 16:29:16 +0100170 ArrayDeque<Rect> mFrozenBounds = new ArrayDeque<>();
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700171 ArrayDeque<Configuration> mFrozenMergedConfig = new ArrayDeque<>();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100172
Wale Ogunwale72919d22016-12-08 18:58:50 -0800173 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
174 DisplayContent dc, long inputDispatchingTimeoutNanos, boolean fullscreen,
175 boolean showForAllUsers, int targetSdk, int orientation, int rotationAnimationHint,
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800176 int configChanges, boolean launchTaskBehind, boolean alwaysFocusable,
177 AppWindowContainerController controller) {
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800178 this(service, token, voiceInteraction, dc, fullscreen);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800179 setController(controller);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800180 mInputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800181 mShowForAllUsers = showForAllUsers;
182 mTargetSdk = targetSdk;
183 mOrientation = orientation;
184 layoutConfigChanges = (configChanges & (CONFIG_SCREEN_SIZE | CONFIG_ORIENTATION)) != 0;
185 mLaunchTaskBehind = launchTaskBehind;
186 mAlwaysFocusable = alwaysFocusable;
187 mRotationAnimationHint = rotationAnimationHint;
188
189 // Application tokens start out hidden.
190 hidden = true;
191 hiddenRequested = true;
192 }
193
194 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800195 DisplayContent dc, boolean fillsParent) {
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800196 super(service, token != null ? token.asBinder() : null, TYPE_APPLICATION, true, dc,
197 false /* ownerCanManageAppTokens */);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700198 appToken = token;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800199 mVoiceInteraction = voiceInteraction;
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800200 mFillsParent = fillsParent;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800201 mInputApplicationHandle = new InputApplicationHandle(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700202 mAppAnimator = new AppWindowAnimator(this, service);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800203 }
204
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800205 void onFirstWindowDrawn(WindowState win, WindowStateAnimator winAnimator) {
206 firstWindowDrawn = true;
207
208 // We now have a good window to show, remove dead placeholders
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700209 removeDeadWindows();
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800210
Jorim Jaggi02886a82016-12-06 09:10:06 -0800211 if (startingWindow != null) {
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800212 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, "Finish starting "
213 + win.mToken + ": first real window is shown, no animation");
214 // If this initial window is animating, stop it -- we will do an animation to reveal
215 // it from behind the starting window, so there is no need for it to also be doing its
216 // own stuff.
217 winAnimator.clearAnimation();
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800218 if (getController() != null) {
219 getController().removeStartingWindow();
220 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800221 }
222 updateReportedVisibilityLocked();
223 }
224
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800225 void updateReportedVisibilityLocked() {
226 if (appToken == null) {
227 return;
228 }
229
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700230 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700231 final int count = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800232
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700233 mReportedVisibilityResults.reset();
234
235 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700236 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700237 win.updateReportedVisibility(mReportedVisibilityResults);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800238 }
239
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700240 int numInteresting = mReportedVisibilityResults.numInteresting;
241 int numVisible = mReportedVisibilityResults.numVisible;
242 int numDrawn = mReportedVisibilityResults.numDrawn;
243 boolean nowGone = mReportedVisibilityResults.nowGone;
244
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700245 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800246 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700247 if (!nowGone) {
248 // If the app is not yet gone, then it can only become visible/drawn.
249 if (!nowDrawn) {
250 nowDrawn = reportedDrawn;
251 }
252 if (!nowVisible) {
253 nowVisible = reportedVisible;
254 }
255 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800256 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800257 + numInteresting + " visible=" + numVisible);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800258 final AppWindowContainerController controller = getController();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700259 if (nowDrawn != reportedDrawn) {
260 if (nowDrawn) {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800261 if (controller != null) {
262 controller.reportWindowsDrawn();
263 }
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700264 }
265 reportedDrawn = nowDrawn;
266 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800267 if (nowVisible != reportedVisible) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700268 if (DEBUG_VISIBILITY) Slog.v(TAG,
269 "Visibility changed in " + this + ": vis=" + nowVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800270 reportedVisible = nowVisible;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800271 if (controller != null) {
272 if (nowVisible) {
273 controller.reportWindowsVisible();
274 } else {
275 controller.reportWindowsGone();
276 }
277 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800278 }
279 }
280
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700281 boolean setVisibility(WindowManager.LayoutParams lp,
282 boolean visible, int transit, boolean performLayout, boolean isVoiceInteraction) {
283
284 boolean delayed = false;
285 inPendingTransaction = false;
286
287 if (clientHidden == visible) {
288 clientHidden = !visible;
289 sendAppVisibilityToClients();
290 }
291
292 // Allow for state changes and animation to be applied if:
293 // * token is transitioning visibility state
294 // * or the token was marked as hidden and is exiting before we had a chance to play the
295 // transition animation
296 // * or this is an opening app and windows are being replaced.
297 boolean visibilityChanged = false;
298 if (hidden == visible || (hidden && mIsExiting) || (visible && waitingForReplacement())) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700299 final AccessibilityController accessibilityController = mService.mAccessibilityController;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700300 boolean changed = false;
301 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
302 "Changing app " + this + " hidden=" + hidden + " performLayout=" + performLayout);
303
304 boolean runningAppAnimation = false;
305
306 if (transit != AppTransition.TRANSIT_UNSET) {
307 if (mAppAnimator.animation == AppWindowAnimator.sDummyAnimation) {
308 mAppAnimator.setNullAnimation();
309 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700310 if (mService.applyAnimationLocked(this, lp, transit, visible, isVoiceInteraction)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700311 delayed = runningAppAnimation = true;
312 }
313 final WindowState window = findMainWindow();
314 //TODO (multidisplay): Magnification is supported only for the default display.
315 if (window != null && accessibilityController != null
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700316 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700317 accessibilityController.onAppWindowTransitionLocked(window, transit);
318 }
319 changed = true;
320 }
321
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700322 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700323 for (int i = 0; i < windowsCount; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700324 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700325 changed |= win.onAppVisibilityChanged(visible, runningAppAnimation);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700326 }
327
328 hidden = hiddenRequested = !visible;
329 visibilityChanged = true;
330 if (!visible) {
331 stopFreezingScreen(true, true);
332 } else {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700333 // If we are being set visible, and the starting window is not yet displayed,
334 // then make sure it doesn't get displayed.
335 if (startingWindow != null && !startingWindow.isDrawnLw()) {
336 startingWindow.mPolicyVisibility = false;
337 startingWindow.mPolicyVisibilityAfterAnim = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700338 }
339 }
340
341 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setVisibility: " + this
342 + ": hidden=" + hidden + " hiddenRequested=" + hiddenRequested);
343
344 if (changed) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700345 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700346 if (performLayout) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700347 mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700348 false /*updateInputWindows*/);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700349 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700350 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700351 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700352 }
353 }
354
355 if (mAppAnimator.animation != null) {
356 delayed = true;
357 }
358
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700359 for (int i = mChildren.size() - 1; i >= 0 && !delayed; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700360 if ((mChildren.get(i)).isWindowAnimationSet()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700361 delayed = true;
362 }
363 }
364
365 if (visibilityChanged) {
366 if (visible && !delayed) {
367 // The token was made immediately visible, there will be no entrance animation.
368 // We need to inform the client the enter animation was finished.
369 mEnteringAnimation = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700370 mService.mActivityManagerAppTransitionNotifier.onAppTransitionFinishedLocked(token);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700371 }
372
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700373 if (!mService.mClosingApps.contains(this) && !mService.mOpeningApps.contains(this)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700374 // The token is not closing nor opening, so even if there is an animation set, that
375 // doesn't mean that it goes through the normal app transition cycle so we have
376 // to inform the docked controller about visibility change.
Andrii Kulian1e32e022016-09-16 15:29:34 -0700377 // TODO(multi-display): notify docked divider on all displays where visibility was
378 // affected.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700379 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700380 .notifyAppVisibilityChanged();
Jorim Jaggi8b702ed2017-01-20 16:59:03 +0100381 mService.mTaskSnapshotController.notifyAppVisibilityChanged(this, visible);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700382 }
383 }
384
385 return delayed;
386 }
387
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800388 WindowState findMainWindow() {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700389 WindowState candidate = null;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700390 int j = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800391 while (j > 0) {
392 j--;
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700393 final WindowState win = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700394 final int type = win.mAttrs.type;
395 // No need to loop through child window as base application and starting types can't be
396 // child windows.
397 if (type == TYPE_BASE_APPLICATION || type == TYPE_APPLICATION_STARTING) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700398 // In cases where there are multiple windows, we prefer the non-exiting window. This
Sungsoo Lim0d3d1f82015-12-02 14:47:59 +0900399 // happens for example when replacing windows during an activity relaunch. When
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700400 // constructing the animation, we want the new window, not the exiting one.
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800401 if (win.mAnimatingExit) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700402 candidate = win;
403 } else {
404 return win;
405 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800406 }
407 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700408 return candidate;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800409 }
410
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800411 boolean windowsAreFocusable() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800412 return StackId.canReceiveKeys(getTask().mStack.mStackId) || mAlwaysFocusable;
Wale Ogunwaled045c822015-12-02 09:14:28 -0800413 }
414
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800415 AppWindowContainerController getController() {
416 final WindowContainerController controller = super.getController();
417 return controller != null ? (AppWindowContainerController) controller : null;
418 }
419
Wale Ogunwale571771c2016-08-26 13:18:50 -0700420 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -0700421 boolean isVisible() {
Wale Ogunwalee471be62016-10-03 07:53:55 -0700422 // If the app token isn't hidden then it is considered visible and there is no need to check
423 // its children windows to see if they are visible.
424 return !hidden;
Wale Ogunwale44f21802016-09-02 12:49:48 -0700425 }
426
427 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -0700428 void removeIfPossible() {
Craig Mautnere3119b72015-01-20 15:02:36 -0800429 mIsExiting = false;
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800430 removeAllWindowsIfPossible();
Bryce Lee6d410262017-02-28 15:30:17 -0800431 removeImmediately();
Craig Mautnere3119b72015-01-20 15:02:36 -0800432 }
433
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700434 @Override
435 boolean checkCompleteDeferredRemoval() {
436 if (mIsExiting) {
437 removeIfPossible();
438 }
439 return super.checkCompleteDeferredRemoval();
440 }
441
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700442 void onRemovedFromDisplay() {
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700443 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app token: " + this);
444
Wale Ogunwale72919d22016-12-08 18:58:50 -0800445 boolean delayed = setVisibility(null, false, TRANSIT_UNSET, true, mVoiceInteraction);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700446
447 mService.mOpeningApps.remove(this);
Jorim Jaggi1b4b23e2016-11-15 16:30:12 -0800448 mService.mUnknownAppVisibilityController.appRemoved(this);
Jorim Jaggi10abe2f2017-01-03 16:44:46 +0100449 mService.mTaskSnapshotController.onAppRemoved(this);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700450 waitingToShow = false;
451 if (mService.mClosingApps.contains(this)) {
452 delayed = true;
453 } else if (mService.mAppTransition.isTransitionSet()) {
454 mService.mClosingApps.add(this);
455 delayed = true;
456 }
457
458 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app " + this + " delayed=" + delayed
459 + " animation=" + mAppAnimator.animation + " animating=" + mAppAnimator.animating);
460
461 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM, "removeAppToken: "
462 + this + " delayed=" + delayed + " Callers=" + Debug.getCallers(4));
463
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800464 if (startingData != null && getController() != null) {
465 getController().removeStartingWindow();
466 }
467
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800468 final TaskStack stack = getTask().mStack;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700469 if (delayed && !isEmpty()) {
470 // set the token aside because it has an active animation to be finished
471 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM,
472 "removeAppToken make exiting: " + this);
473 stack.mExitingAppTokens.add(this);
474 mIsExiting = true;
475 } else {
476 // Make sure there is no animation running on this token, so any windows associated
477 // with it will be removed as soon as their animations are complete
478 mAppAnimator.clearAnimation();
479 mAppAnimator.animating = false;
480 removeIfPossible();
481 }
482
483 removed = true;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700484 stopFreezingScreen(true, true);
Bryce Lee6d410262017-02-28 15:30:17 -0800485
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700486 if (mService.mFocusedApp == this) {
487 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "Removing focused app token:" + this);
488 mService.mFocusedApp = null;
489 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
490 mService.mInputMonitor.setFocusedAppLw(null);
491 }
492
493 if (!delayed) {
494 updateReportedVisibilityLocked();
495 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700496 }
497
Chong Zhange05bcb12016-07-26 17:47:29 -0700498 void clearAnimatingFlags() {
Chong Zhangb0d26702016-08-12 16:03:29 -0700499 boolean wallpaperMightChange = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700500 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700501 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700502 wallpaperMightChange |= win.clearAnimatingFlags();
Chong Zhange05bcb12016-07-26 17:47:29 -0700503 }
Chong Zhangb0d26702016-08-12 16:03:29 -0700504 if (wallpaperMightChange) {
505 requestUpdateWallpaperIfNeeded();
506 }
Chong Zhange05bcb12016-07-26 17:47:29 -0700507 }
508
Robert Carre12aece2016-02-02 22:43:27 -0800509 void destroySurfaces() {
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700510 destroySurfaces(false /*cleanupOnResume*/);
511 }
512
513 /**
514 * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure
515 * the client has finished with them.
516 *
517 * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If
518 * set to true, destroy only surfaces of removed windows, and clear relevant flags of the
519 * others so that they are ready to be reused. If set to false (common case), destroy all
520 * surfaces that's eligible, if the app is already stopped.
521 */
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700522 private void destroySurfaces(boolean cleanupOnResume) {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700523 boolean destroyedSomething = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700524 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700525 final WindowState win = mChildren.get(i);
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700526 destroyedSomething |= win.destroySurface(cleanupOnResume, mAppStopped);
Robert Carre12aece2016-02-02 22:43:27 -0800527 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700528 if (destroyedSomething) {
529 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700530 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Robert Carre12aece2016-02-02 22:43:27 -0800531 }
532 }
533
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800534 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700535 * Notify that the app is now resumed, and it was not stopped before, perform a clean
536 * up of the surfaces
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800537 */
Chong Zhangad24f962016-08-25 12:12:33 -0700538 void notifyAppResumed(boolean wasStopped, boolean allowSavedSurface) {
539 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped
540 + " allowSavedSurface=" + allowSavedSurface + " " + this);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700541 mAppStopped = false;
542 if (!wasStopped) {
543 destroySurfaces(true /*cleanupOnResume*/);
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800544 }
Chong Zhangad24f962016-08-25 12:12:33 -0700545 if (!allowSavedSurface) {
546 destroySavedSurfaces();
547 }
Robert Carre12aece2016-02-02 22:43:27 -0800548 }
549
Chong Zhangbef461f2015-10-27 11:38:24 -0700550 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700551 * Notify that the app has stopped, and it is okay to destroy any surfaces which were
552 * keeping alive in case they were still being used.
553 */
554 void notifyAppStopped() {
555 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this);
556 mAppStopped = true;
557 destroySurfaces();
558 // Remove any starting window that was added for this app if they are still around.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800559 if (getController() != null) {
560 getController().removeStartingWindow();
561 }
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700562 }
563
564 /**
Chong Zhangbef461f2015-10-27 11:38:24 -0700565 * Checks whether we should save surfaces for this app.
566 *
567 * @return true if the surfaces should be saved, false otherwise.
568 */
569 boolean shouldSaveSurface() {
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800570 // We want to save surface if the app's windows are "allDrawn".
571 // (If we started entering animation early with saved surfaces, allDrawn
572 // should have been restored to true. So we'll save again in that case
573 // even if app didn't actually finish drawing.)
574 return allDrawn;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800575 }
576
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700577 private boolean canRestoreSurfaces() {
578 for (int i = mChildren.size() -1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700579 final WindowState w = mChildren.get(i);
Chong Zhang92147042016-05-09 12:47:11 -0700580 if (w.canRestoreSurface()) {
Robert Carr13f7be9e2015-12-02 18:39:45 -0800581 return true;
582 }
Chong Zhangbef461f2015-10-27 11:38:24 -0700583 }
584 return false;
585 }
586
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700587 private void clearWasVisibleBeforeClientHidden() {
588 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700589 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700590 w.clearWasVisibleBeforeClientHidden();
Chong Zhang92147042016-05-09 12:47:11 -0700591 }
592 }
593
Chong Zhang8e4bda92016-05-04 15:08:18 -0700594 /**
595 * Whether the app has some window that is invisible in layout, but
596 * animating with saved surface.
597 */
598 boolean isAnimatingInvisibleWithSavedSurface() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700599 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700600 final WindowState w = mChildren.get(i);
Chong Zhang8e4bda92016-05-04 15:08:18 -0700601 if (w.isAnimatingInvisibleWithSavedSurface()) {
602 return true;
603 }
604 }
605 return false;
606 }
607
608 /**
609 * Hide all window surfaces that's still invisible in layout but animating
610 * with a saved surface, and mark them destroying.
611 */
612 void stopUsingSavedSurfaceLocked() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700613 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700614 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700615 w.stopUsingSavedSurface();
Chong Zhang8e4bda92016-05-04 15:08:18 -0700616 }
617 destroySurfaces();
618 }
619
Chong Zhangf58631a2016-05-24 16:02:10 -0700620 void markSavedSurfaceExiting() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700621 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700622 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700623 w.markSavedSurfaceExiting();
Chong Zhangf58631a2016-05-24 16:02:10 -0700624 }
625 }
626
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700627 void restoreSavedSurfaceForInterestingWindows() {
Chong Zhang92147042016-05-09 12:47:11 -0700628 if (!canRestoreSurfaces()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700629 clearWasVisibleBeforeClientHidden();
Chong Zhangbef461f2015-10-27 11:38:24 -0700630 return;
631 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700632
633 // Check if all interesting windows are drawn and we can mark allDrawn=true.
634 int interestingNotDrawn = -1;
635
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700636 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700637 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700638 interestingNotDrawn = w.restoreSavedSurfaceForInterestingWindow();
Chong Zhangbef461f2015-10-27 11:38:24 -0700639 }
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800640
Chong Zhang92147042016-05-09 12:47:11 -0700641 if (!allDrawn) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700642 allDrawn = (interestingNotDrawn == 0);
Chong Zhang92147042016-05-09 12:47:11 -0700643 if (allDrawn) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700644 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Chong Zhang92147042016-05-09 12:47:11 -0700645 }
646 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700647 clearWasVisibleBeforeClientHidden();
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800648
649 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700650 "restoreSavedSurfaceForInterestingWindows: " + this + " allDrawn=" + allDrawn
651 + " interestingNotDrawn=" + interestingNotDrawn);
Chong Zhangbef461f2015-10-27 11:38:24 -0700652 }
653
654 void destroySavedSurfaces() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700655 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700656 final WindowState win = mChildren.get(i);
Robert Carr13f7be9e2015-12-02 18:39:45 -0800657 win.destroySavedSurface();
Chong Zhangbef461f2015-10-27 11:38:24 -0700658 }
Chong Zhang92147042016-05-09 12:47:11 -0700659 }
660
661 void clearAllDrawn() {
662 allDrawn = false;
663 deferClearAllDrawn = false;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700664 allDrawnExcludingSaved = false;
Chong Zhangbef461f2015-10-27 11:38:24 -0700665 }
666
Bryce Lee6d410262017-02-28 15:30:17 -0800667 Task getTask() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800668 return (Task) getParent();
Bryce Lee6d410262017-02-28 15:30:17 -0800669 }
670
671 @Override
672 void onParentSet() {
673 super.onParentSet();
674
675 // When the associated task is {@code null}, the {@link AppWindowToken} can no longer
676 // access visual elements like the {@link DisplayContent}. We must remove any associations
677 // such as animations.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800678 if (!mReparenting) {
679 final Task task = getTask();
680 if (task == null) {
681 // It is possible we have been marked as a closing app earlier. We must remove ourselves
682 // from this list so we do not participate in any future animations.
683 mService.mClosingApps.remove(this);
684 } else if (task.mStack != null) {
685 task.mStack.mExitingAppTokens.remove(this);
686 }
Bryce Lee6d410262017-02-28 15:30:17 -0800687 }
688 }
689
Wale Ogunwalefa854eb2016-09-20 13:43:52 -0700690 void postWindowRemoveStartingWindowCleanup(WindowState win) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700691 // TODO: Something smells about the code below...Is there a better way?
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700692 if (startingWindow == win) {
693 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800694 if (getController() != null) {
695 getController().removeStartingWindow();
696 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700697 } else if (mChildren.size() == 0 && startingData != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700698 // If this is the last window and we had requested a starting transition window,
699 // well there is no point now.
Jorim Jaggi02886a82016-12-06 09:10:06 -0800700 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingData");
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700701 startingData = null;
Jorim Jaggi829b9cd2017-01-23 16:20:53 +0100702 } else if (mChildren.size() == 1 && startingSurface != null && !isRelaunching()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700703 // If this is the last window except for a starting transition window,
704 // we need to get rid of the starting transition.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800705 if (getController() != null) {
706 getController().removeStartingWindow();
707 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700708 }
709 }
710
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700711 void removeDeadWindows() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700712 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700713 WindowState win = mChildren.get(winNdx);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800714 if (win.mAppDied) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700715 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700716 "removeDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800717 // Set mDestroying, we don't want any animation or delayed removal here.
718 win.mDestroying = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700719 // Also removes child windows.
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700720 win.removeIfPossible();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800721 }
722 }
723 }
724
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700725 boolean hasWindowsAlive() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700726 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700727 // No need to loop through child windows as the answer should be the same as that of the
728 // parent window.
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700729 if (!(mChildren.get(i)).mAppDied) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700730 return true;
731 }
732 }
733 return false;
734 }
735
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700736 void setWillReplaceWindows(boolean animate) {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700737 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
738 "Marking app token " + this + " with replacing windows.");
Robert Carra1eb4392015-12-10 12:43:51 -0800739
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700740 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700741 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700742 w.setWillReplaceWindow(animate);
Robert Carra1eb4392015-12-10 12:43:51 -0800743 }
744 if (animate) {
745 // Set-up dummy animation so we can start treating windows associated with this
746 // token like they are in transition before the new app window is ready for us to
747 // run the real transition animation.
748 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700749 "setWillReplaceWindow() Setting dummy animation on: " + this);
Robert Carra1eb4392015-12-10 12:43:51 -0800750 mAppAnimator.setDummyAnimation();
751 }
752 }
753
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700754 void setWillReplaceChildWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700755 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this
Robert Carr23fa16b2016-01-13 13:19:58 -0800756 + " with replacing child windows.");
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700757 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700758 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700759 w.setWillReplaceChildWindows();
Robert Carr23fa16b2016-01-13 13:19:58 -0800760 }
761 }
762
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700763 void clearWillReplaceWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700764 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
765 "Resetting app token " + this + " of replacing window marks.");
Chong Zhangf596cd52016-01-05 13:42:44 -0800766
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700767 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700768 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700769 w.clearWillReplaceWindow();
Chong Zhangf596cd52016-01-05 13:42:44 -0800770 }
771 }
772
Chong Zhang4d7369a2016-04-25 16:09:14 -0700773 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700774 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700775 final WindowState w = mChildren.get(i);
Chong Zhang4d7369a2016-04-25 16:09:14 -0700776 w.requestUpdateWallpaperIfNeeded();
777 }
778 }
779
Chong Zhangd78ddb42016-03-02 17:01:14 -0800780 boolean isRelaunching() {
781 return mPendingRelaunchCount > 0;
782 }
783
784 void startRelaunching() {
785 if (canFreezeBounds()) {
786 freezeBounds();
787 }
Robert Carr693f3432016-12-19 10:12:48 -0800788
789 // In the process of tearing down before relaunching, the app will
790 // try and clean up it's child surfaces. We need to prevent this from
791 // happening, so we sever the children, transfering their ownership
792 // from the client it-self to the parent surface (owned by us).
793 for (int i = mChildren.size() - 1; i >= 0; i--) {
794 final WindowState w = mChildren.get(i);
795 w.mWinAnimator.detachChildren();
796 }
797
Chong Zhangd78ddb42016-03-02 17:01:14 -0800798 mPendingRelaunchCount++;
799 }
800
801 void finishRelaunching() {
802 if (canFreezeBounds()) {
803 unfreezeBounds();
804 }
805 if (mPendingRelaunchCount > 0) {
806 mPendingRelaunchCount--;
807 }
808 }
809
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700810 void clearRelaunching() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700811 if (mPendingRelaunchCount == 0) {
812 return;
813 }
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700814 if (canFreezeBounds()) {
815 unfreezeBounds();
816 }
817 mPendingRelaunchCount = 0;
818 }
819
Wale Ogunwale07bcab72016-10-14 15:30:09 -0700820 /**
821 * Returns true if the new child window we are adding to this token is considered greater than
822 * the existing child window in this token in terms of z-order.
823 */
824 @Override
825 protected boolean isFirstChildWindowGreaterThanSecond(WindowState newWindow,
826 WindowState existingWindow) {
827 final int type1 = newWindow.mAttrs.type;
828 final int type2 = existingWindow.mAttrs.type;
829
830 // Base application windows should be z-ordered BELOW all other windows in the app token.
831 if (type1 == TYPE_BASE_APPLICATION && type2 != TYPE_BASE_APPLICATION) {
832 return false;
833 } else if (type1 != TYPE_BASE_APPLICATION && type2 == TYPE_BASE_APPLICATION) {
834 return true;
835 }
836
837 // Starting windows should be z-ordered ABOVE all other windows in the app token.
838 if (type1 == TYPE_APPLICATION_STARTING && type2 != TYPE_APPLICATION_STARTING) {
839 return true;
840 } else if (type1 != TYPE_APPLICATION_STARTING && type2 == TYPE_APPLICATION_STARTING) {
841 return false;
842 }
843
844 // Otherwise the new window is greater than the existing window.
845 return true;
846 }
847
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700848 @Override
Robert Carra1eb4392015-12-10 12:43:51 -0800849 void addWindow(WindowState w) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700850 super.addWindow(w);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700851
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700852 boolean gotReplacementWindow = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700853 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700854 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700855 gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w);
856 }
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700857
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700858 // if we got a replacement window, reset the timeout to give drawing more time
859 if (gotReplacementWindow) {
860 mService.scheduleWindowReplacementTimeouts(this);
Robert Carra1eb4392015-12-10 12:43:51 -0800861 }
Jorim Jaggife762342016-10-13 14:33:27 +0200862 checkKeyguardFlagsChanged();
863 }
864
865 @Override
866 void removeChild(WindowState child) {
867 super.removeChild(child);
868 checkKeyguardFlagsChanged();
Robert Carra1eb4392015-12-10 12:43:51 -0800869 }
870
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700871 private boolean waitingForReplacement() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700872 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700873 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700874 if (candidate.waitingForReplacement()) {
Robert Carra1eb4392015-12-10 12:43:51 -0800875 return true;
876 }
877 }
878 return false;
879 }
880
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700881 void onWindowReplacementTimeout() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700882 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700883 (mChildren.get(i)).onWindowReplacementTimeout();
Robert Carra1eb4392015-12-10 12:43:51 -0800884 }
885 }
886
Winson Chung30480042017-01-26 10:55:34 -0800887 void reparent(Task task, int position) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800888 final Task currentTask = getTask();
889 if (task == currentTask) {
Winson Chung30480042017-01-26 10:55:34 -0800890 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800891 "window token=" + this + " already child of task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -0800892 }
Bryce Lee6d410262017-02-28 15:30:17 -0800893
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800894 if (currentTask.mStack != task.mStack) {
Bryce Lee6d410262017-02-28 15:30:17 -0800895 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800896 "window token=" + this + " current task=" + currentTask
Bryce Lee6d410262017-02-28 15:30:17 -0800897 + " belongs to a different stack than " + task);
898 }
899
Winson Chung30480042017-01-26 10:55:34 -0800900 if (DEBUG_ADD_REMOVE) Slog.i(TAG, "reParentWindowToken: removing window token=" + this
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800901 + " from task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -0800902 final DisplayContent prevDisplayContent = getDisplayContent();
903
Bryce Lee6d410262017-02-28 15:30:17 -0800904 mReparenting = true;
905
Winson Chung30480042017-01-26 10:55:34 -0800906 getParent().removeChild(this);
907 task.addChild(this, position);
908
Bryce Lee6d410262017-02-28 15:30:17 -0800909 mReparenting = false;
910
Winson Chung30480042017-01-26 10:55:34 -0800911 // Relayout display(s).
912 final DisplayContent displayContent = task.getDisplayContent();
913 displayContent.setLayoutNeeded();
914 if (prevDisplayContent != displayContent) {
915 onDisplayChanged(displayContent);
916 prevDisplayContent.setLayoutNeeded();
917 }
918 }
919
Chong Zhangd78ddb42016-03-02 17:01:14 -0800920 private boolean canFreezeBounds() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800921 final Task task = getTask();
922
Chong Zhangd78ddb42016-03-02 17:01:14 -0800923 // For freeform windows, we can't freeze the bounds at the moment because this would make
924 // the resizing unresponsive.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800925 return task != null && !task.inFreeformWorkspace();
Chong Zhangd78ddb42016-03-02 17:01:14 -0800926 }
927
Jorim Jaggi0429f352015-12-22 16:29:16 +0100928 /**
929 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
930 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
931 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
932 * with a queue.
933 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800934 private void freezeBounds() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800935 final Task task = getTask();
936 mFrozenBounds.offer(new Rect(task.mPreparedFrozenBounds));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700937
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800938 if (task.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) {
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700939 // We didn't call prepareFreezingBounds on the task, so use the current value.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800940 mFrozenMergedConfig.offer(new Configuration(task.getConfiguration()));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700941 } else {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800942 mFrozenMergedConfig.offer(new Configuration(task.mPreparedFrozenMergedConfig));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700943 }
Andrii Kulianb10330d2016-09-16 13:51:46 -0700944 // Calling unset() to make it equal to Configuration.EMPTY.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800945 task.mPreparedFrozenMergedConfig.unset();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100946 }
947
948 /**
949 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
950 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800951 private void unfreezeBounds() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700952 if (!mFrozenBounds.isEmpty()) {
953 mFrozenBounds.remove();
954 }
955 if (!mFrozenMergedConfig.isEmpty()) {
956 mFrozenMergedConfig.remove();
957 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700958 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700959 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700960 win.onUnfreezeBounds();
Jorim Jaggi4846ee32016-01-07 17:39:12 +0100961 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700962 mService.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100963 }
964
Robert Carr91b228092016-06-28 17:32:37 -0700965 void addSurfaceViewBackground(WindowSurfaceController.SurfaceControlWithBackground background) {
966 mSurfaceViewBackgrounds.add(background);
967 }
968
969 void removeSurfaceViewBackground(WindowSurfaceController.SurfaceControlWithBackground background) {
970 mSurfaceViewBackgrounds.remove(background);
971 updateSurfaceViewBackgroundVisibilities();
972 }
973
974 // We use DimLayers behind SurfaceViews to prevent holes while resizing and creating.
975 // However, we need to ensure one SurfaceView doesn't cover another when they are both placed
976 // below the main app window (as traditionally a SurfaceView which is never drawn
977 // to is totally translucent). So we look at all our SurfaceView backgrounds and only enable
978 // the background for the SurfaceView with lowest Z order
979 void updateSurfaceViewBackgroundVisibilities() {
980 WindowSurfaceController.SurfaceControlWithBackground bottom = null;
981 int bottomLayer = Integer.MAX_VALUE;
982 for (int i = 0; i < mSurfaceViewBackgrounds.size(); i++) {
983 WindowSurfaceController.SurfaceControlWithBackground sc = mSurfaceViewBackgrounds.get(i);
984 if (sc.mVisible && sc.mLayer < bottomLayer) {
985 bottomLayer = sc.mLayer;
986 bottom = sc;
987 }
988 }
989 for (int i = 0; i < mSurfaceViewBackgrounds.size(); i++) {
990 WindowSurfaceController.SurfaceControlWithBackground sc = mSurfaceViewBackgrounds.get(i);
991 sc.updateBackgroundVisibility(sc != bottom);
992 }
993 }
994
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700995 void resetJustMovedInStack() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700996 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700997 (mChildren.get(i)).resetJustMovedInStack();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700998 }
999 }
1000
1001 void notifyMovedInStack() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001002 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001003 final WindowState win = mChildren.get(winNdx);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001004 win.notifyMovedInStack();
1005 }
1006 }
1007
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001008 void setAppLayoutChanges(int changes, String reason) {
1009 if (!mChildren.isEmpty()) {
1010 final DisplayContent dc = getDisplayContent();
1011 dc.pendingLayoutChanges |= changes;
1012 if (DEBUG_LAYOUT_REPEATS) {
1013 mService.mWindowPlacerLocked.debugLayoutRepeats(reason, dc.pendingLayoutChanges);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001014 }
1015 }
1016 }
1017
1018 void removeReplacedWindowIfNeeded(WindowState replacement) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001019 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001020 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001021 if (win.removeReplacedWindowIfNeeded(replacement)) {
1022 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001023 }
1024 }
1025 }
1026
1027 void startFreezingScreen() {
1028 if (DEBUG_ORIENTATION) logWithStack(TAG, "Set freezing of " + appToken + ": hidden="
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001029 + hidden + " freezing=" + mAppAnimator.freezingScreen + " hiddenRequested="
1030 + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001031 if (!hiddenRequested) {
1032 if (!mAppAnimator.freezingScreen) {
1033 mAppAnimator.freezingScreen = true;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001034 mService.registerAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001035 mAppAnimator.lastFreezeDuration = 0;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001036 mService.mAppsFreezingScreen++;
1037 if (mService.mAppsFreezingScreen == 1) {
1038 mService.startFreezingDisplayLocked(false, 0, 0);
1039 mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT);
1040 mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001041 }
1042 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001043 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001044 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001045 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001046 w.onStartFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001047 }
1048 }
1049 }
1050
1051 void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) {
1052 if (!mAppAnimator.freezingScreen) {
1053 return;
1054 }
1055 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + this + " force=" + force);
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001056 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001057 boolean unfrozeWindows = false;
1058 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001059 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001060 unfrozeWindows |= w.onStopFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001061 }
1062 if (force || unfrozeWindows) {
1063 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this);
1064 mAppAnimator.freezingScreen = false;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001065 mService.unregisterAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001066 mAppAnimator.lastFreezeDuration =
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001067 (int)(SystemClock.elapsedRealtime() - mService.mDisplayFreezeTime);
1068 mService.mAppsFreezingScreen--;
1069 mService.mLastFinishedFreezeSource = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001070 }
1071 if (unfreezeSurfaceNow) {
1072 if (unfrozeWindows) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001073 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001074 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001075 mService.stopFreezingDisplayLocked();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001076 }
1077 }
1078
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001079 @Override
1080 public void onAppFreezeTimeout() {
1081 Slog.w(TAG_WM, "Force clearing freeze: " + this);
1082 stopFreezingScreen(true, true);
1083 }
1084
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001085 boolean transferStartingWindow(IBinder transferFrom) {
Wale Ogunwale02319a62016-09-26 15:21:22 -07001086 final AppWindowToken fromToken = getDisplayContent().getAppWindowToken(transferFrom);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001087 if (fromToken == null) {
1088 return false;
1089 }
1090
1091 final WindowState tStartingWindow = fromToken.startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001092 if (tStartingWindow != null && fromToken.startingSurface != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001093 // In this case, the starting icon has already been displayed, so start
1094 // letting windows get shown immediately without any more transitions.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001095 mService.mSkipAppTransitionAnimation = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001096
1097 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow
1098 + " from " + fromToken + " to " + this);
1099
1100 final long origId = Binder.clearCallingIdentity();
1101
1102 // Transfer the starting window over to the new token.
1103 startingData = fromToken.startingData;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001104 startingSurface = fromToken.startingSurface;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001105 startingDisplayed = fromToken.startingDisplayed;
1106 fromToken.startingDisplayed = false;
1107 startingWindow = tStartingWindow;
1108 reportedVisible = fromToken.reportedVisible;
1109 fromToken.startingData = null;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001110 fromToken.startingSurface = null;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001111 fromToken.startingWindow = null;
1112 fromToken.startingMoved = true;
1113 tStartingWindow.mToken = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001114 tStartingWindow.mAppToken = this;
1115
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001116 if (DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001117 "Removing starting " + tStartingWindow + " from " + fromToken);
Wale Ogunwalefa854eb2016-09-20 13:43:52 -07001118 fromToken.removeChild(tStartingWindow);
1119 fromToken.postWindowRemoveStartingWindowCleanup(tStartingWindow);
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001120 addWindow(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001121
1122 // Propagate other interesting state between the tokens. If the old token is displayed,
1123 // we should immediately force the new one to be displayed. If it is animating, we need
1124 // to move that animation to the new one.
1125 if (fromToken.allDrawn) {
1126 allDrawn = true;
1127 deferClearAllDrawn = fromToken.deferClearAllDrawn;
1128 }
1129 if (fromToken.firstWindowDrawn) {
1130 firstWindowDrawn = true;
1131 }
1132 if (!fromToken.hidden) {
1133 hidden = false;
1134 hiddenRequested = false;
1135 }
1136 if (clientHidden != fromToken.clientHidden) {
1137 clientHidden = fromToken.clientHidden;
1138 sendAppVisibilityToClients();
1139 }
1140 fromToken.mAppAnimator.transferCurrentAnimation(
1141 mAppAnimator, tStartingWindow.mWinAnimator);
1142
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001143 mService.updateFocusedWindowLocked(
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001144 UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/);
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001145 getDisplayContent().setLayoutNeeded();
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001146 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001147 Binder.restoreCallingIdentity(origId);
1148 return true;
1149 } else if (fromToken.startingData != null) {
1150 // The previous app was getting ready to show a
1151 // starting window, but hasn't yet done so. Steal it!
1152 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1153 "Moving pending starting from " + fromToken + " to " + this);
1154 startingData = fromToken.startingData;
1155 fromToken.startingData = null;
1156 fromToken.startingMoved = true;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001157 if (getController() != null) {
1158 getController().scheduleAddStartingWindow();
1159 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001160 return true;
1161 }
1162
1163 final AppWindowAnimator tAppAnimator = fromToken.mAppAnimator;
1164 final AppWindowAnimator wAppAnimator = mAppAnimator;
1165 if (tAppAnimator.thumbnail != null) {
1166 // The old token is animating with a thumbnail, transfer that to the new token.
1167 if (wAppAnimator.thumbnail != null) {
1168 wAppAnimator.thumbnail.destroy();
1169 }
1170 wAppAnimator.thumbnail = tAppAnimator.thumbnail;
1171 wAppAnimator.thumbnailLayer = tAppAnimator.thumbnailLayer;
1172 wAppAnimator.thumbnailAnimation = tAppAnimator.thumbnailAnimation;
1173 tAppAnimator.thumbnail = null;
1174 }
1175 return false;
1176 }
1177
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001178 boolean isLastWindow(WindowState win) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001179 return mChildren.size() == 1 && mChildren.get(0) == win;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001180 }
1181
1182 void setAllAppWinAnimators() {
1183 final ArrayList<WindowStateAnimator> allAppWinAnimators = mAppAnimator.mAllAppWinAnimators;
1184 allAppWinAnimators.clear();
1185
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001186 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001187 for (int j = 0; j < windowsCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001188 (mChildren.get(j)).addWinAnimatorToList(allAppWinAnimators);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001189 }
1190 }
1191
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001192 @Override
1193 void onAppTransitionDone() {
1194 sendingToBottom = false;
1195 }
1196
Wale Ogunwale51362492016-09-08 17:49:17 -07001197 /**
1198 * We override because this class doesn't want its children affecting its reported orientation
1199 * in anyway.
1200 */
1201 @Override
1202 int getOrientation() {
Bryce Leea163b762017-01-24 11:05:01 -08001203 if (fillsParent() && (isVisible() || mService.mOpeningApps.contains(this))) {
1204 return mOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001205 }
Bryce Leea163b762017-01-24 11:05:01 -08001206
1207 return SCREEN_ORIENTATION_UNSET;
Wale Ogunwale51362492016-09-08 17:49:17 -07001208 }
1209
Wale Ogunwaleb198b742016-12-01 08:44:09 -08001210 /** Returns the app's preferred orientation regardless of its currently visibility state. */
1211 int getOrientationIgnoreVisibility() {
1212 return mOrientation;
1213 }
1214
Craig Mautnerdbb79912012-03-01 18:59:14 -08001215 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001216 void checkAppWindowsReadyToShow() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001217 if (allDrawn == mAppAnimator.allDrawn) {
1218 return;
1219 }
1220
1221 mAppAnimator.allDrawn = allDrawn;
1222 if (!allDrawn) {
1223 return;
1224 }
1225
1226 // The token has now changed state to having all windows shown... what to do, what to do?
1227 if (mAppAnimator.freezingScreen) {
1228 mAppAnimator.showAllWindowsLocked();
1229 stopFreezingScreen(false, true);
1230 if (DEBUG_ORIENTATION) Slog.i(TAG,
1231 "Setting mOrientationChangeComplete=true because wtoken " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001232 + " numInteresting=" + mNumInterestingWindows + " numDrawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001233 // This will set mOrientationChangeComplete and cause a pass through layout.
1234 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001235 "checkAppWindowsReadyToShow: freezingScreen");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001236 } else {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001237 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001238
1239 // We can now show all of the drawn windows!
1240 if (!mService.mOpeningApps.contains(this)) {
1241 mService.mAnimator.orAnimating(mAppAnimator.showAllWindowsLocked());
1242 }
1243 }
1244 }
1245
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001246 void updateAllDrawn(DisplayContent dc) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001247 if (!allDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001248 final int numInteresting = mNumInterestingWindows;
1249 if (numInteresting > 0 && mNumDrawnWindows >= numInteresting) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001250 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawn: " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001251 + " interesting=" + numInteresting + " drawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001252 allDrawn = true;
1253 // Force an additional layout pass where
1254 // WindowStateAnimator#commitFinishDrawingLocked() will call performShowLocked().
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001255 dc.setLayoutNeeded();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001256 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
1257 }
1258 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001259
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001260 if (!allDrawnExcludingSaved) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001261 int numInteresting = mNumInterestingWindowsExcludingSaved;
1262 if (numInteresting > 0 && mNumDrawnWindowsExcludingSaved >= numInteresting) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001263 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawnExcludingSaved: " + this
1264 + " interesting=" + numInteresting
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001265 + " drawn=" + mNumDrawnWindowsExcludingSaved);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001266 allDrawnExcludingSaved = true;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001267 dc.setLayoutNeeded();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001268 if (isAnimatingInvisibleWithSavedSurface()
1269 && !mService.mFinishedEarlyAnim.contains(this)) {
1270 mService.mFinishedEarlyAnim.add(this);
1271 }
1272 }
1273 }
1274 }
1275
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001276 /**
1277 * Updated this app token tracking states for interesting and drawn windows based on the window.
1278 *
1279 * @return Returns true if the input window is considered interesting and drawn while all the
1280 * windows in this app token where not considered drawn as of the last pass.
1281 */
1282 boolean updateDrawnWindowStates(WindowState w) {
1283 if (DEBUG_STARTING_WINDOW && w == startingWindow) {
1284 Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" + w.isOnScreen()
1285 + " allDrawn=" + allDrawn + " freezingScreen=" + mAppAnimator.freezingScreen);
1286 }
1287
1288 if (allDrawn && allDrawnExcludingSaved && !mAppAnimator.freezingScreen) {
1289 return false;
1290 }
1291
1292 if (mLastTransactionSequence != mService.mTransactionSequence) {
1293 mLastTransactionSequence = mService.mTransactionSequence;
1294 mNumInterestingWindows = mNumDrawnWindows = 0;
1295 mNumInterestingWindowsExcludingSaved = 0;
1296 mNumDrawnWindowsExcludingSaved = 0;
1297 startingDisplayed = false;
1298 }
1299
1300 final WindowStateAnimator winAnimator = w.mWinAnimator;
1301
1302 boolean isInterestingAndDrawn = false;
1303
1304 if (!allDrawn && w.mightAffectAllDrawn(false /* visibleOnly */)) {
1305 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
1306 Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw()
1307 + ", isAnimationSet=" + winAnimator.isAnimationSet());
1308 if (!w.isDrawnLw()) {
1309 Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController
1310 + " pv=" + w.mPolicyVisibility
1311 + " mDrawState=" + winAnimator.drawStateToString()
1312 + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested
1313 + " a=" + winAnimator.mAnimating);
1314 }
1315 }
1316
1317 if (w != startingWindow) {
1318 if (w.isInteresting()) {
1319 mNumInterestingWindows++;
1320 if (w.isDrawnLw()) {
1321 mNumDrawnWindows++;
1322
1323 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, "tokenMayBeDrawn: "
1324 + this + " w=" + w + " numInteresting=" + mNumInterestingWindows
1325 + " freezingScreen=" + mAppAnimator.freezingScreen
1326 + " mAppFreezing=" + w.mAppFreezing);
1327
1328 isInterestingAndDrawn = true;
1329 }
1330 }
1331 } else if (w.isDrawnLw()) {
1332 mService.mH.sendEmptyMessage(NOTIFY_STARTING_WINDOW_DRAWN);
1333 startingDisplayed = true;
1334 }
1335 }
1336
1337 if (!allDrawnExcludingSaved && w.mightAffectAllDrawn(true /* visibleOnly */)) {
1338 if (w != startingWindow && w.isInteresting()) {
1339 mNumInterestingWindowsExcludingSaved++;
1340 if (w.isDrawnLw() && !w.isAnimatingWithSavedSurface()) {
1341 mNumDrawnWindowsExcludingSaved++;
1342
1343 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
1344 "tokenMayBeDrawnExcludingSaved: " + this + " w=" + w
1345 + " numInteresting=" + mNumInterestingWindowsExcludingSaved
1346 + " freezingScreen=" + mAppAnimator.freezingScreen
1347 + " mAppFreezing=" + w.mAppFreezing);
1348
1349 isInterestingAndDrawn = true;
1350 }
1351 }
1352 }
1353
1354 return isInterestingAndDrawn;
1355 }
1356
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001357 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001358 void stepAppWindowsAnimation(long currentTime) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001359 mAppAnimator.wasAnimating = mAppAnimator.animating;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001360 if (mAppAnimator.stepAnimationLocked(currentTime)) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001361 mAppAnimator.animating = true;
1362 mService.mAnimator.setAnimating(true);
1363 mService.mAnimator.mAppWindowAnimating = true;
1364 } else if (mAppAnimator.wasAnimating) {
1365 // stopped animating, do one more pass through the layout
Wale Ogunwale1e129a42016-11-21 13:03:47 -08001366 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
1367 DEBUG_LAYOUT_REPEATS ? "appToken " + this + " done" : null);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001368 if (DEBUG_ANIM) Slog.v(TAG, "updateWindowsApps...: done animating " + this);
1369 }
1370 }
1371
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001372 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001373 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001374 // For legacy reasons we process the TaskStack.mExitingAppTokens first in DisplayContent
1375 // before the non-exiting app tokens. So, we skip the exiting app tokens here.
1376 // TODO: Investigate if we need to continue to do this or if we can just process them
1377 // in-order.
1378 if (mIsExiting && !waitingForReplacement()) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001379 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001380 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001381 return forAllWindowsUnchecked(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001382 }
1383
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001384 boolean forAllWindowsUnchecked(ToBooleanFunction<WindowState> callback,
1385 boolean traverseTopToBottom) {
1386 return super.forAllWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001387 }
1388
1389 @Override
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001390 AppWindowToken asAppWindowToken() {
1391 // I am an app window token!
1392 return this;
1393 }
1394
1395 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -07001396 boolean fillsParent() {
1397 return mFillsParent;
1398 }
1399
1400 void setFillsParent(boolean fillsParent) {
1401 mFillsParent = fillsParent;
1402 }
1403
Jorim Jaggife762342016-10-13 14:33:27 +02001404 boolean containsDismissKeyguardWindow() {
1405 for (int i = mChildren.size() - 1; i >= 0; i--) {
1406 if ((mChildren.get(i).mAttrs.flags & FLAG_DISMISS_KEYGUARD) != 0) {
1407 return true;
1408 }
1409 }
1410 return false;
1411 }
1412
1413 boolean containsShowWhenLockedWindow() {
1414 for (int i = mChildren.size() - 1; i >= 0; i--) {
1415 if ((mChildren.get(i).mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
1416 return true;
1417 }
1418 }
1419 return false;
1420 }
1421
1422 void checkKeyguardFlagsChanged() {
1423 final boolean containsDismissKeyguard = containsDismissKeyguardWindow();
1424 final boolean containsShowWhenLocked = containsShowWhenLockedWindow();
1425 if (containsDismissKeyguard != mLastContainsDismissKeyguardWindow
1426 || containsShowWhenLocked != mLastContainsShowWhenLockedWindow) {
1427 mService.notifyKeyguardFlagsChanged(null /* callback */);
1428 }
1429 mLastContainsDismissKeyguardWindow = containsDismissKeyguard;
1430 mLastContainsShowWhenLockedWindow = containsShowWhenLocked;
1431 }
1432
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001433 WindowState getImeTargetBelowWindow(WindowState w) {
1434 final int index = mChildren.indexOf(w);
1435 if (index > 0) {
1436 final WindowState target = mChildren.get(index - 1);
1437 if (target.canBeImeTarget()) {
1438 return target;
1439 }
1440 }
1441 return null;
1442 }
1443
1444 WindowState getHighestAnimLayerWindow(WindowState currentTarget) {
1445 WindowState candidate = null;
1446 for (int i = mChildren.indexOf(currentTarget); i >= 0; i--) {
1447 final WindowState w = mChildren.get(i);
1448 if (w.mRemoved) {
1449 continue;
1450 }
1451 if (candidate == null || w.mWinAnimator.mAnimLayer >
1452 candidate.mWinAnimator.mAnimLayer) {
1453 candidate = w;
1454 }
1455 }
1456 return candidate;
1457 }
1458
Wale Ogunwale51362492016-09-08 17:49:17 -07001459 @Override
Robert Carrdee1b3f2017-02-27 11:33:33 -08001460 int getAnimLayerAdjustment() {
1461 return mAppAnimator.animLayerAdjustment;
1462 }
1463
1464 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001465 void dump(PrintWriter pw, String prefix) {
1466 super.dump(pw, prefix);
1467 if (appToken != null) {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001468 pw.println(prefix + "app=true mVoiceInteraction=" + mVoiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001469 }
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001470 pw.print(prefix); pw.print("task="); pw.println(getTask());
Wale Ogunwale51362492016-09-08 17:49:17 -07001471 pw.print(prefix); pw.print(" mFillsParent="); pw.print(mFillsParent);
1472 pw.print(" mOrientation="); pw.println(mOrientation);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001473 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
1474 pw.print(" clientHidden="); pw.print(clientHidden);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -07001475 pw.print(" reportedDrawn="); pw.print(reportedDrawn);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001476 pw.print(" reportedVisible="); pw.println(reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -07001477 if (paused) {
1478 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001479 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001480 if (mAppStopped) {
1481 pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped);
1482 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001483 if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0
Craig Mautner6fbda632012-07-03 09:26:39 -07001484 || allDrawn || mAppAnimator.allDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001485 pw.print(prefix); pw.print("mNumInterestingWindows=");
1486 pw.print(mNumInterestingWindows);
1487 pw.print(" mNumDrawnWindows="); pw.print(mNumDrawnWindows);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001488 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -07001489 pw.print(" allDrawn="); pw.print(allDrawn);
1490 pw.print(" (animator="); pw.print(mAppAnimator.allDrawn);
1491 pw.println(")");
1492 }
1493 if (inPendingTransaction) {
1494 pw.print(prefix); pw.print("inPendingTransaction=");
1495 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001496 }
Craig Mautner799bc1d2015-01-14 10:33:48 -08001497 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001498 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
1499 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -08001500 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -08001501 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001502 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001503 if (startingWindow != null || startingSurface != null
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001504 || startingDisplayed || startingMoved) {
1505 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001506 pw.print(" startingSurface="); pw.print(startingSurface);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001507 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001508 pw.print(" startingMoved="); pw.println(startingMoved);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001509 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01001510 if (!mFrozenBounds.isEmpty()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -08001511 pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds);
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001512 pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig);
Chong Zhangd78ddb42016-03-02 17:01:14 -08001513 }
1514 if (mPendingRelaunchCount != 0) {
1515 pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount);
Jorim Jaggi0429f352015-12-22 16:29:16 +01001516 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001517 }
1518
1519 @Override
1520 public String toString() {
1521 if (stringName == null) {
1522 StringBuilder sb = new StringBuilder();
1523 sb.append("AppWindowToken{");
1524 sb.append(Integer.toHexString(System.identityHashCode(this)));
1525 sb.append(" token="); sb.append(token); sb.append('}');
1526 stringName = sb.toString();
1527 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001528 return stringName + ((mIsExiting) ? " mIsExiting=" : "");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001529 }
Jeff Browne9bdb312012-04-05 15:30:10 -07001530}