blob: 994f38d5a94aef85fed78b219348c7b38bf47276 [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 Ogunwalef6192862016-09-10 13:42:30 -070087 // TODO: Use getParent instead?
Bryce Lee6d410262017-02-28 15:30:17 -080088 private Task mTask;
Wale Ogunwale51362492016-09-08 17:49:17 -070089 /** @see WindowContainer#fillsParent() */
90 private boolean mFillsParent;
Craig Mautner4c5eb222013-11-18 12:59:05 -080091 boolean layoutConfigChanges;
Wale Ogunwale72919d22016-12-08 18:58:50 -080092 boolean mShowForAllUsers;
93 int mTargetSdk;
Craig Mautnera2c77052012-03-26 12:14:43 -070094
Bryce Lee6d410262017-02-28 15:30:17 -080095 // Flag set while reparenting to prevent actions normally triggered by an individual parent
96 // change.
97 private boolean mReparenting;
98
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080099 // The input dispatching timeout for this application token in nanoseconds.
Wale Ogunwale72919d22016-12-08 18:58:50 -0800100 long mInputDispatchingTimeoutNanos;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800101
102 // These are used for determining when all windows associated with
103 // an activity have been drawn, so they can be made visible together
104 // at the same time.
Craig Mautner764983d2012-03-22 11:37:36 -0700105 // initialize so that it doesn't match mTransactionSequence which is an int.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700106 private long mLastTransactionSequence = Long.MIN_VALUE;
107 private int mNumInterestingWindows;
108 private int mNumDrawnWindows;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800109 boolean inPendingTransaction;
110 boolean allDrawn;
Craig Mautner7636dfb2012-11-16 15:24:11 -0800111 // Set to true when this app creates a surface while in the middle of an animation. In that
112 // case do not clear allDrawn until the animation completes.
113 boolean deferClearAllDrawn;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800114
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700115 /**
116 * These are to track the app's real drawing status if there were no saved surfaces.
117 * @see #updateDrawnWindowStates
118 */
Chong Zhang8e4bda92016-05-04 15:08:18 -0700119 boolean allDrawnExcludingSaved;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700120 private int mNumInterestingWindowsExcludingSaved;
121 private int mNumDrawnWindowsExcludingSaved;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700122
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800123 // Is this window's surface needed? This is almost like hidden, except
124 // it will sometimes be true a little earlier: when the token has
125 // been shown, but is still waiting for its app transition to execute
126 // before making its windows shown.
127 boolean hiddenRequested;
128
129 // Have we told the window clients to hide themselves?
130 boolean clientHidden;
131
132 // Last visibility state we reported to the app token.
133 boolean reportedVisible;
134
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700135 // Last drawn state we reported to the app token.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700136 private boolean reportedDrawn;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700137
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800138 // Set to true when the token has been removed from the window mgr.
139 boolean removed;
140
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800141 // Information about an application starting window if displayed.
142 StartingData startingData;
143 WindowState startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800144 StartingSurface startingSurface;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800145 boolean startingDisplayed;
146 boolean startingMoved;
147 boolean firstWindowDrawn;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700148 private final WindowState.UpdateReportedVisibilityResults mReportedVisibilityResults =
149 new WindowState.UpdateReportedVisibilityResults();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800150
151 // Input application handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700152 final InputApplicationHandle mInputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800153
Wale Ogunwale571771c2016-08-26 13:18:50 -0700154 // TODO: Have a WindowContainer state for tracking exiting/deferred removal.
Craig Mautner799bc1d2015-01-14 10:33:48 -0800155 boolean mIsExiting;
Craig Mautner9ef471f2014-02-07 13:11:47 -0800156
Craig Mautnerbb742462014-07-07 15:28:55 -0700157 boolean mLaunchTaskBehind;
Craig Mautner8746a472014-07-24 15:12:54 -0700158 boolean mEnteringAnimation;
Craig Mautnerbb742462014-07-07 15:28:55 -0700159
Wale Ogunwale72919d22016-12-08 18:58:50 -0800160 private boolean mAlwaysFocusable;
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800161
Robert Carre12aece2016-02-02 22:43:27 -0800162 boolean mAppStopped;
Robert Carrfd10cd12016-06-29 16:41:50 -0700163 int mRotationAnimationHint;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700164 private int mPendingRelaunchCount;
Robert Carre12aece2016-02-02 22:43:27 -0800165
Jorim Jaggife762342016-10-13 14:33:27 +0200166 private boolean mLastContainsShowWhenLockedWindow;
167 private boolean mLastContainsDismissKeyguardWindow;
168
Robert Carr91b228092016-06-28 17:32:37 -0700169 private ArrayList<WindowSurfaceController.SurfaceControlWithBackground> mSurfaceViewBackgrounds =
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700170 new ArrayList<>();
Robert Carr91b228092016-06-28 17:32:37 -0700171
Jorim Jaggi0429f352015-12-22 16:29:16 +0100172 ArrayDeque<Rect> mFrozenBounds = new ArrayDeque<>();
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700173 ArrayDeque<Configuration> mFrozenMergedConfig = new ArrayDeque<>();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100174
Wale Ogunwale72919d22016-12-08 18:58:50 -0800175 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
176 DisplayContent dc, long inputDispatchingTimeoutNanos, boolean fullscreen,
177 boolean showForAllUsers, int targetSdk, int orientation, int rotationAnimationHint,
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800178 int configChanges, boolean launchTaskBehind, boolean alwaysFocusable,
179 AppWindowContainerController controller) {
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800180 this(service, token, voiceInteraction, dc, fullscreen);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800181 setController(controller);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800182 mInputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800183 mShowForAllUsers = showForAllUsers;
184 mTargetSdk = targetSdk;
185 mOrientation = orientation;
186 layoutConfigChanges = (configChanges & (CONFIG_SCREEN_SIZE | CONFIG_ORIENTATION)) != 0;
187 mLaunchTaskBehind = launchTaskBehind;
188 mAlwaysFocusable = alwaysFocusable;
189 mRotationAnimationHint = rotationAnimationHint;
190
191 // Application tokens start out hidden.
192 hidden = true;
193 hiddenRequested = true;
194 }
195
196 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800197 DisplayContent dc, boolean fillsParent) {
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800198 super(service, token != null ? token.asBinder() : null, TYPE_APPLICATION, true, dc,
199 false /* ownerCanManageAppTokens */);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700200 appToken = token;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800201 mVoiceInteraction = voiceInteraction;
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800202 mFillsParent = fillsParent;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800203 mInputApplicationHandle = new InputApplicationHandle(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700204 mAppAnimator = new AppWindowAnimator(this, service);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800205 }
206
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800207 void onFirstWindowDrawn(WindowState win, WindowStateAnimator winAnimator) {
208 firstWindowDrawn = true;
209
210 // We now have a good window to show, remove dead placeholders
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700211 removeDeadWindows();
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800212
Jorim Jaggi02886a82016-12-06 09:10:06 -0800213 if (startingWindow != null) {
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800214 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, "Finish starting "
215 + win.mToken + ": first real window is shown, no animation");
216 // If this initial window is animating, stop it -- we will do an animation to reveal
217 // it from behind the starting window, so there is no need for it to also be doing its
218 // own stuff.
219 winAnimator.clearAnimation();
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800220 if (getController() != null) {
221 getController().removeStartingWindow();
222 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800223 }
224 updateReportedVisibilityLocked();
225 }
226
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800227 void updateReportedVisibilityLocked() {
228 if (appToken == null) {
229 return;
230 }
231
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700232 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700233 final int count = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800234
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700235 mReportedVisibilityResults.reset();
236
237 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700238 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700239 win.updateReportedVisibility(mReportedVisibilityResults);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800240 }
241
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700242 int numInteresting = mReportedVisibilityResults.numInteresting;
243 int numVisible = mReportedVisibilityResults.numVisible;
244 int numDrawn = mReportedVisibilityResults.numDrawn;
245 boolean nowGone = mReportedVisibilityResults.nowGone;
246
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700247 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800248 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700249 if (!nowGone) {
250 // If the app is not yet gone, then it can only become visible/drawn.
251 if (!nowDrawn) {
252 nowDrawn = reportedDrawn;
253 }
254 if (!nowVisible) {
255 nowVisible = reportedVisible;
256 }
257 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800258 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800259 + numInteresting + " visible=" + numVisible);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800260 final AppWindowContainerController controller = getController();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700261 if (nowDrawn != reportedDrawn) {
262 if (nowDrawn) {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800263 if (controller != null) {
264 controller.reportWindowsDrawn();
265 }
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700266 }
267 reportedDrawn = nowDrawn;
268 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800269 if (nowVisible != reportedVisible) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700270 if (DEBUG_VISIBILITY) Slog.v(TAG,
271 "Visibility changed in " + this + ": vis=" + nowVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800272 reportedVisible = nowVisible;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800273 if (controller != null) {
274 if (nowVisible) {
275 controller.reportWindowsVisible();
276 } else {
277 controller.reportWindowsGone();
278 }
279 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800280 }
281 }
282
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700283 boolean setVisibility(WindowManager.LayoutParams lp,
284 boolean visible, int transit, boolean performLayout, boolean isVoiceInteraction) {
285
286 boolean delayed = false;
287 inPendingTransaction = false;
288
289 if (clientHidden == visible) {
290 clientHidden = !visible;
291 sendAppVisibilityToClients();
292 }
293
294 // Allow for state changes and animation to be applied if:
295 // * token is transitioning visibility state
296 // * or the token was marked as hidden and is exiting before we had a chance to play the
297 // transition animation
298 // * or this is an opening app and windows are being replaced.
299 boolean visibilityChanged = false;
300 if (hidden == visible || (hidden && mIsExiting) || (visible && waitingForReplacement())) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700301 final AccessibilityController accessibilityController = mService.mAccessibilityController;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700302 boolean changed = false;
303 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
304 "Changing app " + this + " hidden=" + hidden + " performLayout=" + performLayout);
305
306 boolean runningAppAnimation = false;
307
308 if (transit != AppTransition.TRANSIT_UNSET) {
309 if (mAppAnimator.animation == AppWindowAnimator.sDummyAnimation) {
310 mAppAnimator.setNullAnimation();
311 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700312 if (mService.applyAnimationLocked(this, lp, transit, visible, isVoiceInteraction)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700313 delayed = runningAppAnimation = true;
314 }
315 final WindowState window = findMainWindow();
316 //TODO (multidisplay): Magnification is supported only for the default display.
317 if (window != null && accessibilityController != null
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700318 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700319 accessibilityController.onAppWindowTransitionLocked(window, transit);
320 }
321 changed = true;
322 }
323
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700324 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700325 for (int i = 0; i < windowsCount; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700326 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700327 changed |= win.onAppVisibilityChanged(visible, runningAppAnimation);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700328 }
329
330 hidden = hiddenRequested = !visible;
331 visibilityChanged = true;
332 if (!visible) {
333 stopFreezingScreen(true, true);
334 } else {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700335 // If we are being set visible, and the starting window is not yet displayed,
336 // then make sure it doesn't get displayed.
337 if (startingWindow != null && !startingWindow.isDrawnLw()) {
338 startingWindow.mPolicyVisibility = false;
339 startingWindow.mPolicyVisibilityAfterAnim = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700340 }
341 }
342
343 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setVisibility: " + this
344 + ": hidden=" + hidden + " hiddenRequested=" + hiddenRequested);
345
346 if (changed) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700347 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700348 if (performLayout) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700349 mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700350 false /*updateInputWindows*/);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700351 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700352 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700353 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700354 }
355 }
356
357 if (mAppAnimator.animation != null) {
358 delayed = true;
359 }
360
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700361 for (int i = mChildren.size() - 1; i >= 0 && !delayed; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700362 if ((mChildren.get(i)).isWindowAnimationSet()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700363 delayed = true;
364 }
365 }
366
367 if (visibilityChanged) {
368 if (visible && !delayed) {
369 // The token was made immediately visible, there will be no entrance animation.
370 // We need to inform the client the enter animation was finished.
371 mEnteringAnimation = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700372 mService.mActivityManagerAppTransitionNotifier.onAppTransitionFinishedLocked(token);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700373 }
374
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700375 if (!mService.mClosingApps.contains(this) && !mService.mOpeningApps.contains(this)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700376 // The token is not closing nor opening, so even if there is an animation set, that
377 // doesn't mean that it goes through the normal app transition cycle so we have
378 // to inform the docked controller about visibility change.
Andrii Kulian1e32e022016-09-16 15:29:34 -0700379 // TODO(multi-display): notify docked divider on all displays where visibility was
380 // affected.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700381 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700382 .notifyAppVisibilityChanged();
Jorim Jaggi8b702ed2017-01-20 16:59:03 +0100383 mService.mTaskSnapshotController.notifyAppVisibilityChanged(this, visible);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700384 }
385 }
386
387 return delayed;
388 }
389
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800390 WindowState findMainWindow() {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700391 WindowState candidate = null;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700392 int j = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800393 while (j > 0) {
394 j--;
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700395 final WindowState win = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700396 final int type = win.mAttrs.type;
397 // No need to loop through child window as base application and starting types can't be
398 // child windows.
399 if (type == TYPE_BASE_APPLICATION || type == TYPE_APPLICATION_STARTING) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700400 // In cases where there are multiple windows, we prefer the non-exiting window. This
Sungsoo Lim0d3d1f82015-12-02 14:47:59 +0900401 // happens for example when replacing windows during an activity relaunch. When
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700402 // constructing the animation, we want the new window, not the exiting one.
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800403 if (win.mAnimatingExit) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700404 candidate = win;
405 } else {
406 return win;
407 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800408 }
409 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700410 return candidate;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800411 }
412
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800413 boolean windowsAreFocusable() {
414 return StackId.canReceiveKeys(mTask.mStack.mStackId) || mAlwaysFocusable;
Wale Ogunwaled045c822015-12-02 09:14:28 -0800415 }
416
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800417 AppWindowContainerController getController() {
418 final WindowContainerController controller = super.getController();
419 return controller != null ? (AppWindowContainerController) controller : null;
420 }
421
Wale Ogunwale571771c2016-08-26 13:18:50 -0700422 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -0700423 boolean isVisible() {
Wale Ogunwalee471be62016-10-03 07:53:55 -0700424 // If the app token isn't hidden then it is considered visible and there is no need to check
425 // its children windows to see if they are visible.
426 return !hidden;
Wale Ogunwale44f21802016-09-02 12:49:48 -0700427 }
428
429 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -0700430 void removeIfPossible() {
Craig Mautnere3119b72015-01-20 15:02:36 -0800431 mIsExiting = false;
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800432 removeAllWindowsIfPossible();
Bryce Lee6d410262017-02-28 15:30:17 -0800433 removeImmediately();
Craig Mautnere3119b72015-01-20 15:02:36 -0800434 }
435
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700436 @Override
437 boolean checkCompleteDeferredRemoval() {
438 if (mIsExiting) {
439 removeIfPossible();
440 }
441 return super.checkCompleteDeferredRemoval();
442 }
443
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700444 void onRemovedFromDisplay() {
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700445 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app token: " + this);
446
Wale Ogunwale72919d22016-12-08 18:58:50 -0800447 boolean delayed = setVisibility(null, false, TRANSIT_UNSET, true, mVoiceInteraction);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700448
449 mService.mOpeningApps.remove(this);
Jorim Jaggi1b4b23e2016-11-15 16:30:12 -0800450 mService.mUnknownAppVisibilityController.appRemoved(this);
Jorim Jaggi10abe2f2017-01-03 16:44:46 +0100451 mService.mTaskSnapshotController.onAppRemoved(this);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700452 waitingToShow = false;
453 if (mService.mClosingApps.contains(this)) {
454 delayed = true;
455 } else if (mService.mAppTransition.isTransitionSet()) {
456 mService.mClosingApps.add(this);
457 delayed = true;
458 }
459
460 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app " + this + " delayed=" + delayed
461 + " animation=" + mAppAnimator.animation + " animating=" + mAppAnimator.animating);
462
463 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM, "removeAppToken: "
464 + this + " delayed=" + delayed + " Callers=" + Debug.getCallers(4));
465
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800466 if (startingData != null && getController() != null) {
467 getController().removeStartingWindow();
468 }
469
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700470 final TaskStack stack = mTask.mStack;
471 if (delayed && !isEmpty()) {
472 // set the token aside because it has an active animation to be finished
473 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM,
474 "removeAppToken make exiting: " + this);
475 stack.mExitingAppTokens.add(this);
476 mIsExiting = true;
477 } else {
478 // Make sure there is no animation running on this token, so any windows associated
479 // with it will be removed as soon as their animations are complete
480 mAppAnimator.clearAnimation();
481 mAppAnimator.animating = false;
482 removeIfPossible();
483 }
484
485 removed = true;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700486 stopFreezingScreen(true, true);
Bryce Lee6d410262017-02-28 15:30:17 -0800487
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700488 if (mService.mFocusedApp == this) {
489 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "Removing focused app token:" + this);
490 mService.mFocusedApp = null;
491 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
492 mService.mInputMonitor.setFocusedAppLw(null);
493 }
494
495 if (!delayed) {
496 updateReportedVisibilityLocked();
497 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700498 }
499
Chong Zhange05bcb12016-07-26 17:47:29 -0700500 void clearAnimatingFlags() {
Chong Zhangb0d26702016-08-12 16:03:29 -0700501 boolean wallpaperMightChange = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700502 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700503 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700504 wallpaperMightChange |= win.clearAnimatingFlags();
Chong Zhange05bcb12016-07-26 17:47:29 -0700505 }
Chong Zhangb0d26702016-08-12 16:03:29 -0700506 if (wallpaperMightChange) {
507 requestUpdateWallpaperIfNeeded();
508 }
Chong Zhange05bcb12016-07-26 17:47:29 -0700509 }
510
Robert Carre12aece2016-02-02 22:43:27 -0800511 void destroySurfaces() {
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700512 destroySurfaces(false /*cleanupOnResume*/);
513 }
514
515 /**
516 * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure
517 * the client has finished with them.
518 *
519 * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If
520 * set to true, destroy only surfaces of removed windows, and clear relevant flags of the
521 * others so that they are ready to be reused. If set to false (common case), destroy all
522 * surfaces that's eligible, if the app is already stopped.
523 */
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700524 private void destroySurfaces(boolean cleanupOnResume) {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700525 boolean destroyedSomething = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700526 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700527 final WindowState win = mChildren.get(i);
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700528 destroyedSomething |= win.destroySurface(cleanupOnResume, mAppStopped);
Robert Carre12aece2016-02-02 22:43:27 -0800529 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700530 if (destroyedSomething) {
531 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700532 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Robert Carre12aece2016-02-02 22:43:27 -0800533 }
534 }
535
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800536 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700537 * Notify that the app is now resumed, and it was not stopped before, perform a clean
538 * up of the surfaces
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800539 */
Chong Zhangad24f962016-08-25 12:12:33 -0700540 void notifyAppResumed(boolean wasStopped, boolean allowSavedSurface) {
541 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped
542 + " allowSavedSurface=" + allowSavedSurface + " " + this);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700543 mAppStopped = false;
544 if (!wasStopped) {
545 destroySurfaces(true /*cleanupOnResume*/);
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800546 }
Chong Zhangad24f962016-08-25 12:12:33 -0700547 if (!allowSavedSurface) {
548 destroySavedSurfaces();
549 }
Robert Carre12aece2016-02-02 22:43:27 -0800550 }
551
Chong Zhangbef461f2015-10-27 11:38:24 -0700552 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700553 * Notify that the app has stopped, and it is okay to destroy any surfaces which were
554 * keeping alive in case they were still being used.
555 */
556 void notifyAppStopped() {
557 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this);
558 mAppStopped = true;
559 destroySurfaces();
560 // Remove any starting window that was added for this app if they are still around.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800561 if (getController() != null) {
562 getController().removeStartingWindow();
563 }
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700564 }
565
566 /**
Chong Zhangbef461f2015-10-27 11:38:24 -0700567 * Checks whether we should save surfaces for this app.
568 *
569 * @return true if the surfaces should be saved, false otherwise.
570 */
571 boolean shouldSaveSurface() {
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800572 // We want to save surface if the app's windows are "allDrawn".
573 // (If we started entering animation early with saved surfaces, allDrawn
574 // should have been restored to true. So we'll save again in that case
575 // even if app didn't actually finish drawing.)
576 return allDrawn;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800577 }
578
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700579 private boolean canRestoreSurfaces() {
580 for (int i = mChildren.size() -1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700581 final WindowState w = mChildren.get(i);
Chong Zhang92147042016-05-09 12:47:11 -0700582 if (w.canRestoreSurface()) {
Robert Carr13f7be9e2015-12-02 18:39:45 -0800583 return true;
584 }
Chong Zhangbef461f2015-10-27 11:38:24 -0700585 }
586 return false;
587 }
588
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700589 private void clearWasVisibleBeforeClientHidden() {
590 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700591 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700592 w.clearWasVisibleBeforeClientHidden();
Chong Zhang92147042016-05-09 12:47:11 -0700593 }
594 }
595
Chong Zhang8e4bda92016-05-04 15:08:18 -0700596 /**
597 * Whether the app has some window that is invisible in layout, but
598 * animating with saved surface.
599 */
600 boolean isAnimatingInvisibleWithSavedSurface() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700601 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700602 final WindowState w = mChildren.get(i);
Chong Zhang8e4bda92016-05-04 15:08:18 -0700603 if (w.isAnimatingInvisibleWithSavedSurface()) {
604 return true;
605 }
606 }
607 return false;
608 }
609
610 /**
611 * Hide all window surfaces that's still invisible in layout but animating
612 * with a saved surface, and mark them destroying.
613 */
614 void stopUsingSavedSurfaceLocked() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700615 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700616 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700617 w.stopUsingSavedSurface();
Chong Zhang8e4bda92016-05-04 15:08:18 -0700618 }
619 destroySurfaces();
620 }
621
Chong Zhangf58631a2016-05-24 16:02:10 -0700622 void markSavedSurfaceExiting() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700623 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700624 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700625 w.markSavedSurfaceExiting();
Chong Zhangf58631a2016-05-24 16:02:10 -0700626 }
627 }
628
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700629 void restoreSavedSurfaceForInterestingWindows() {
Chong Zhang92147042016-05-09 12:47:11 -0700630 if (!canRestoreSurfaces()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700631 clearWasVisibleBeforeClientHidden();
Chong Zhangbef461f2015-10-27 11:38:24 -0700632 return;
633 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700634
635 // Check if all interesting windows are drawn and we can mark allDrawn=true.
636 int interestingNotDrawn = -1;
637
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700638 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700639 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700640 interestingNotDrawn = w.restoreSavedSurfaceForInterestingWindow();
Chong Zhangbef461f2015-10-27 11:38:24 -0700641 }
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800642
Chong Zhang92147042016-05-09 12:47:11 -0700643 if (!allDrawn) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700644 allDrawn = (interestingNotDrawn == 0);
Chong Zhang92147042016-05-09 12:47:11 -0700645 if (allDrawn) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700646 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Chong Zhang92147042016-05-09 12:47:11 -0700647 }
648 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700649 clearWasVisibleBeforeClientHidden();
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800650
651 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700652 "restoreSavedSurfaceForInterestingWindows: " + this + " allDrawn=" + allDrawn
653 + " interestingNotDrawn=" + interestingNotDrawn);
Chong Zhangbef461f2015-10-27 11:38:24 -0700654 }
655
656 void destroySavedSurfaces() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700657 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700658 final WindowState win = mChildren.get(i);
Robert Carr13f7be9e2015-12-02 18:39:45 -0800659 win.destroySavedSurface();
Chong Zhangbef461f2015-10-27 11:38:24 -0700660 }
Chong Zhang92147042016-05-09 12:47:11 -0700661 }
662
663 void clearAllDrawn() {
664 allDrawn = false;
665 deferClearAllDrawn = false;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700666 allDrawnExcludingSaved = false;
Chong Zhangbef461f2015-10-27 11:38:24 -0700667 }
668
Bryce Lee6d410262017-02-28 15:30:17 -0800669 Task getTask() {
670 return mTask;
671 }
672
673 /**
674 * Sets the associated task, cleaning up dependencies when unset.
675 */
676 void setTask(Task task) {
677 // Note: the following code assumes that the previous task's stack is the same as the
678 // new task's stack.
679 if (!mReparenting && mTask != null && mTask.mStack != null) {
680 mTask.mStack.mExitingAppTokens.remove(this);
681 }
682
683 mTask = task;
684 }
685
686 @Override
687 void onParentSet() {
688 super.onParentSet();
689
690 // When the associated task is {@code null}, the {@link AppWindowToken} can no longer
691 // access visual elements like the {@link DisplayContent}. We must remove any associations
692 // such as animations.
693 if (!mReparenting && mTask == null) {
694 // It is possible we have been marked as a closing app earlier. We must remove ourselves
695 // from this list so we do not participate in any future animations.
696 mService.mClosingApps.remove(this);
697 }
698 }
699
Wale Ogunwalefa854eb2016-09-20 13:43:52 -0700700 void postWindowRemoveStartingWindowCleanup(WindowState win) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700701 // TODO: Something smells about the code below...Is there a better way?
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700702 if (startingWindow == win) {
703 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800704 if (getController() != null) {
705 getController().removeStartingWindow();
706 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700707 } else if (mChildren.size() == 0 && startingData != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700708 // If this is the last window and we had requested a starting transition window,
709 // well there is no point now.
Jorim Jaggi02886a82016-12-06 09:10:06 -0800710 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingData");
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700711 startingData = null;
Jorim Jaggi829b9cd2017-01-23 16:20:53 +0100712 } else if (mChildren.size() == 1 && startingSurface != null && !isRelaunching()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700713 // If this is the last window except for a starting transition window,
714 // we need to get rid of the starting transition.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800715 if (getController() != null) {
716 getController().removeStartingWindow();
717 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700718 }
719 }
720
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700721 void removeDeadWindows() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700722 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700723 WindowState win = mChildren.get(winNdx);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800724 if (win.mAppDied) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700725 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700726 "removeDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800727 // Set mDestroying, we don't want any animation or delayed removal here.
728 win.mDestroying = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700729 // Also removes child windows.
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700730 win.removeIfPossible();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800731 }
732 }
733 }
734
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700735 boolean hasWindowsAlive() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700736 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700737 // No need to loop through child windows as the answer should be the same as that of the
738 // parent window.
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700739 if (!(mChildren.get(i)).mAppDied) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700740 return true;
741 }
742 }
743 return false;
744 }
745
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700746 void setWillReplaceWindows(boolean animate) {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700747 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
748 "Marking app token " + this + " with replacing windows.");
Robert Carra1eb4392015-12-10 12:43:51 -0800749
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700750 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700751 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700752 w.setWillReplaceWindow(animate);
Robert Carra1eb4392015-12-10 12:43:51 -0800753 }
754 if (animate) {
755 // Set-up dummy animation so we can start treating windows associated with this
756 // token like they are in transition before the new app window is ready for us to
757 // run the real transition animation.
758 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700759 "setWillReplaceWindow() Setting dummy animation on: " + this);
Robert Carra1eb4392015-12-10 12:43:51 -0800760 mAppAnimator.setDummyAnimation();
761 }
762 }
763
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700764 void setWillReplaceChildWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700765 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this
Robert Carr23fa16b2016-01-13 13:19:58 -0800766 + " with replacing child windows.");
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.setWillReplaceChildWindows();
Robert Carr23fa16b2016-01-13 13:19:58 -0800770 }
771 }
772
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700773 void clearWillReplaceWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700774 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
775 "Resetting app token " + this + " of replacing window marks.");
Chong Zhangf596cd52016-01-05 13:42:44 -0800776
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700777 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700778 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700779 w.clearWillReplaceWindow();
Chong Zhangf596cd52016-01-05 13:42:44 -0800780 }
781 }
782
Chong Zhang4d7369a2016-04-25 16:09:14 -0700783 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700784 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700785 final WindowState w = mChildren.get(i);
Chong Zhang4d7369a2016-04-25 16:09:14 -0700786 w.requestUpdateWallpaperIfNeeded();
787 }
788 }
789
Chong Zhangd78ddb42016-03-02 17:01:14 -0800790 boolean isRelaunching() {
791 return mPendingRelaunchCount > 0;
792 }
793
794 void startRelaunching() {
795 if (canFreezeBounds()) {
796 freezeBounds();
797 }
Robert Carr693f3432016-12-19 10:12:48 -0800798
799 // In the process of tearing down before relaunching, the app will
800 // try and clean up it's child surfaces. We need to prevent this from
801 // happening, so we sever the children, transfering their ownership
802 // from the client it-self to the parent surface (owned by us).
803 for (int i = mChildren.size() - 1; i >= 0; i--) {
804 final WindowState w = mChildren.get(i);
805 w.mWinAnimator.detachChildren();
806 }
807
Chong Zhangd78ddb42016-03-02 17:01:14 -0800808 mPendingRelaunchCount++;
809 }
810
811 void finishRelaunching() {
812 if (canFreezeBounds()) {
813 unfreezeBounds();
814 }
815 if (mPendingRelaunchCount > 0) {
816 mPendingRelaunchCount--;
817 }
818 }
819
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700820 void clearRelaunching() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700821 if (mPendingRelaunchCount == 0) {
822 return;
823 }
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700824 if (canFreezeBounds()) {
825 unfreezeBounds();
826 }
827 mPendingRelaunchCount = 0;
828 }
829
Wale Ogunwale07bcab72016-10-14 15:30:09 -0700830 /**
831 * Returns true if the new child window we are adding to this token is considered greater than
832 * the existing child window in this token in terms of z-order.
833 */
834 @Override
835 protected boolean isFirstChildWindowGreaterThanSecond(WindowState newWindow,
836 WindowState existingWindow) {
837 final int type1 = newWindow.mAttrs.type;
838 final int type2 = existingWindow.mAttrs.type;
839
840 // Base application windows should be z-ordered BELOW all other windows in the app token.
841 if (type1 == TYPE_BASE_APPLICATION && type2 != TYPE_BASE_APPLICATION) {
842 return false;
843 } else if (type1 != TYPE_BASE_APPLICATION && type2 == TYPE_BASE_APPLICATION) {
844 return true;
845 }
846
847 // Starting windows should be z-ordered ABOVE all other windows in the app token.
848 if (type1 == TYPE_APPLICATION_STARTING && type2 != TYPE_APPLICATION_STARTING) {
849 return true;
850 } else if (type1 != TYPE_APPLICATION_STARTING && type2 == TYPE_APPLICATION_STARTING) {
851 return false;
852 }
853
854 // Otherwise the new window is greater than the existing window.
855 return true;
856 }
857
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700858 @Override
Robert Carra1eb4392015-12-10 12:43:51 -0800859 void addWindow(WindowState w) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700860 super.addWindow(w);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700861
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700862 boolean gotReplacementWindow = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700863 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700864 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700865 gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w);
866 }
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700867
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700868 // if we got a replacement window, reset the timeout to give drawing more time
869 if (gotReplacementWindow) {
870 mService.scheduleWindowReplacementTimeouts(this);
Robert Carra1eb4392015-12-10 12:43:51 -0800871 }
Jorim Jaggife762342016-10-13 14:33:27 +0200872 checkKeyguardFlagsChanged();
873 }
874
875 @Override
876 void removeChild(WindowState child) {
877 super.removeChild(child);
878 checkKeyguardFlagsChanged();
Robert Carra1eb4392015-12-10 12:43:51 -0800879 }
880
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700881 private boolean waitingForReplacement() {
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 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700884 if (candidate.waitingForReplacement()) {
Robert Carra1eb4392015-12-10 12:43:51 -0800885 return true;
886 }
887 }
888 return false;
889 }
890
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700891 void onWindowReplacementTimeout() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700892 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700893 (mChildren.get(i)).onWindowReplacementTimeout();
Robert Carra1eb4392015-12-10 12:43:51 -0800894 }
895 }
896
Winson Chung30480042017-01-26 10:55:34 -0800897 void reparent(Task task, int position) {
898 if (task == mTask) {
899 throw new IllegalArgumentException(
900 "window token=" + this + " already child of task=" + mTask);
901 }
Bryce Lee6d410262017-02-28 15:30:17 -0800902
903 if (mTask.mStack != task.mStack) {
904 throw new IllegalArgumentException(
905 "window token=" + this + " current task=" + mTask
906 + " belongs to a different stack than " + task);
907 }
908
Winson Chung30480042017-01-26 10:55:34 -0800909 if (DEBUG_ADD_REMOVE) Slog.i(TAG, "reParentWindowToken: removing window token=" + this
910 + " from task=" + mTask);
911 final DisplayContent prevDisplayContent = getDisplayContent();
912
Bryce Lee6d410262017-02-28 15:30:17 -0800913 mReparenting = true;
914
Winson Chung30480042017-01-26 10:55:34 -0800915 getParent().removeChild(this);
916 task.addChild(this, position);
917
Bryce Lee6d410262017-02-28 15:30:17 -0800918 mReparenting = false;
919
Winson Chung30480042017-01-26 10:55:34 -0800920 // Relayout display(s).
921 final DisplayContent displayContent = task.getDisplayContent();
922 displayContent.setLayoutNeeded();
923 if (prevDisplayContent != displayContent) {
924 onDisplayChanged(displayContent);
925 prevDisplayContent.setLayoutNeeded();
926 }
927 }
928
Chong Zhangd78ddb42016-03-02 17:01:14 -0800929 private boolean canFreezeBounds() {
930 // For freeform windows, we can't freeze the bounds at the moment because this would make
931 // the resizing unresponsive.
932 return mTask != null && !mTask.inFreeformWorkspace();
933 }
934
Jorim Jaggi0429f352015-12-22 16:29:16 +0100935 /**
936 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
937 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
938 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
939 * with a queue.
940 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800941 private void freezeBounds() {
Jorim Jaggi0429f352015-12-22 16:29:16 +0100942 mFrozenBounds.offer(new Rect(mTask.mPreparedFrozenBounds));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700943
944 if (mTask.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) {
945 // We didn't call prepareFreezingBounds on the task, so use the current value.
Andrii Kulian441e4492016-09-29 15:25:00 -0700946 mFrozenMergedConfig.offer(new Configuration(mTask.getConfiguration()));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700947 } else {
948 mFrozenMergedConfig.offer(new Configuration(mTask.mPreparedFrozenMergedConfig));
949 }
Andrii Kulianb10330d2016-09-16 13:51:46 -0700950 // Calling unset() to make it equal to Configuration.EMPTY.
951 mTask.mPreparedFrozenMergedConfig.unset();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100952 }
953
954 /**
955 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
956 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800957 private void unfreezeBounds() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700958 if (!mFrozenBounds.isEmpty()) {
959 mFrozenBounds.remove();
960 }
961 if (!mFrozenMergedConfig.isEmpty()) {
962 mFrozenMergedConfig.remove();
963 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700964 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700965 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700966 win.onUnfreezeBounds();
Jorim Jaggi4846ee32016-01-07 17:39:12 +0100967 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700968 mService.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100969 }
970
Robert Carr91b228092016-06-28 17:32:37 -0700971 void addSurfaceViewBackground(WindowSurfaceController.SurfaceControlWithBackground background) {
972 mSurfaceViewBackgrounds.add(background);
973 }
974
975 void removeSurfaceViewBackground(WindowSurfaceController.SurfaceControlWithBackground background) {
976 mSurfaceViewBackgrounds.remove(background);
977 updateSurfaceViewBackgroundVisibilities();
978 }
979
980 // We use DimLayers behind SurfaceViews to prevent holes while resizing and creating.
981 // However, we need to ensure one SurfaceView doesn't cover another when they are both placed
982 // below the main app window (as traditionally a SurfaceView which is never drawn
983 // to is totally translucent). So we look at all our SurfaceView backgrounds and only enable
984 // the background for the SurfaceView with lowest Z order
985 void updateSurfaceViewBackgroundVisibilities() {
986 WindowSurfaceController.SurfaceControlWithBackground bottom = null;
987 int bottomLayer = Integer.MAX_VALUE;
988 for (int i = 0; i < mSurfaceViewBackgrounds.size(); i++) {
989 WindowSurfaceController.SurfaceControlWithBackground sc = mSurfaceViewBackgrounds.get(i);
990 if (sc.mVisible && sc.mLayer < bottomLayer) {
991 bottomLayer = sc.mLayer;
992 bottom = sc;
993 }
994 }
995 for (int i = 0; i < mSurfaceViewBackgrounds.size(); i++) {
996 WindowSurfaceController.SurfaceControlWithBackground sc = mSurfaceViewBackgrounds.get(i);
997 sc.updateBackgroundVisibility(sc != bottom);
998 }
999 }
1000
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001001 void resetJustMovedInStack() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001002 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001003 (mChildren.get(i)).resetJustMovedInStack();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001004 }
1005 }
1006
1007 void notifyMovedInStack() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001008 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001009 final WindowState win = mChildren.get(winNdx);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001010 win.notifyMovedInStack();
1011 }
1012 }
1013
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001014 void setAppLayoutChanges(int changes, String reason) {
1015 if (!mChildren.isEmpty()) {
1016 final DisplayContent dc = getDisplayContent();
1017 dc.pendingLayoutChanges |= changes;
1018 if (DEBUG_LAYOUT_REPEATS) {
1019 mService.mWindowPlacerLocked.debugLayoutRepeats(reason, dc.pendingLayoutChanges);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001020 }
1021 }
1022 }
1023
1024 void removeReplacedWindowIfNeeded(WindowState replacement) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001025 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001026 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001027 if (win.removeReplacedWindowIfNeeded(replacement)) {
1028 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001029 }
1030 }
1031 }
1032
1033 void startFreezingScreen() {
1034 if (DEBUG_ORIENTATION) logWithStack(TAG, "Set freezing of " + appToken + ": hidden="
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001035 + hidden + " freezing=" + mAppAnimator.freezingScreen + " hiddenRequested="
1036 + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001037 if (!hiddenRequested) {
1038 if (!mAppAnimator.freezingScreen) {
1039 mAppAnimator.freezingScreen = true;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001040 mService.registerAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001041 mAppAnimator.lastFreezeDuration = 0;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001042 mService.mAppsFreezingScreen++;
1043 if (mService.mAppsFreezingScreen == 1) {
1044 mService.startFreezingDisplayLocked(false, 0, 0);
1045 mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT);
1046 mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001047 }
1048 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001049 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001050 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001051 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001052 w.onStartFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001053 }
1054 }
1055 }
1056
1057 void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) {
1058 if (!mAppAnimator.freezingScreen) {
1059 return;
1060 }
1061 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + this + " force=" + force);
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001062 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001063 boolean unfrozeWindows = false;
1064 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001065 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001066 unfrozeWindows |= w.onStopFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001067 }
1068 if (force || unfrozeWindows) {
1069 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this);
1070 mAppAnimator.freezingScreen = false;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001071 mService.unregisterAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001072 mAppAnimator.lastFreezeDuration =
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001073 (int)(SystemClock.elapsedRealtime() - mService.mDisplayFreezeTime);
1074 mService.mAppsFreezingScreen--;
1075 mService.mLastFinishedFreezeSource = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001076 }
1077 if (unfreezeSurfaceNow) {
1078 if (unfrozeWindows) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001079 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001080 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001081 mService.stopFreezingDisplayLocked();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001082 }
1083 }
1084
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001085 @Override
1086 public void onAppFreezeTimeout() {
1087 Slog.w(TAG_WM, "Force clearing freeze: " + this);
1088 stopFreezingScreen(true, true);
1089 }
1090
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001091 boolean transferStartingWindow(IBinder transferFrom) {
Wale Ogunwale02319a62016-09-26 15:21:22 -07001092 final AppWindowToken fromToken = getDisplayContent().getAppWindowToken(transferFrom);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001093 if (fromToken == null) {
1094 return false;
1095 }
1096
1097 final WindowState tStartingWindow = fromToken.startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001098 if (tStartingWindow != null && fromToken.startingSurface != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001099 // In this case, the starting icon has already been displayed, so start
1100 // letting windows get shown immediately without any more transitions.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001101 mService.mSkipAppTransitionAnimation = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001102
1103 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow
1104 + " from " + fromToken + " to " + this);
1105
1106 final long origId = Binder.clearCallingIdentity();
1107
1108 // Transfer the starting window over to the new token.
1109 startingData = fromToken.startingData;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001110 startingSurface = fromToken.startingSurface;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001111 startingDisplayed = fromToken.startingDisplayed;
1112 fromToken.startingDisplayed = false;
1113 startingWindow = tStartingWindow;
1114 reportedVisible = fromToken.reportedVisible;
1115 fromToken.startingData = null;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001116 fromToken.startingSurface = null;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001117 fromToken.startingWindow = null;
1118 fromToken.startingMoved = true;
1119 tStartingWindow.mToken = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001120 tStartingWindow.mAppToken = this;
1121
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001122 if (DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001123 "Removing starting " + tStartingWindow + " from " + fromToken);
Wale Ogunwalefa854eb2016-09-20 13:43:52 -07001124 fromToken.removeChild(tStartingWindow);
1125 fromToken.postWindowRemoveStartingWindowCleanup(tStartingWindow);
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001126 addWindow(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001127
1128 // Propagate other interesting state between the tokens. If the old token is displayed,
1129 // we should immediately force the new one to be displayed. If it is animating, we need
1130 // to move that animation to the new one.
1131 if (fromToken.allDrawn) {
1132 allDrawn = true;
1133 deferClearAllDrawn = fromToken.deferClearAllDrawn;
1134 }
1135 if (fromToken.firstWindowDrawn) {
1136 firstWindowDrawn = true;
1137 }
1138 if (!fromToken.hidden) {
1139 hidden = false;
1140 hiddenRequested = false;
1141 }
1142 if (clientHidden != fromToken.clientHidden) {
1143 clientHidden = fromToken.clientHidden;
1144 sendAppVisibilityToClients();
1145 }
1146 fromToken.mAppAnimator.transferCurrentAnimation(
1147 mAppAnimator, tStartingWindow.mWinAnimator);
1148
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001149 mService.updateFocusedWindowLocked(
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001150 UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/);
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001151 getDisplayContent().setLayoutNeeded();
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001152 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001153 Binder.restoreCallingIdentity(origId);
1154 return true;
1155 } else if (fromToken.startingData != null) {
1156 // The previous app was getting ready to show a
1157 // starting window, but hasn't yet done so. Steal it!
1158 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1159 "Moving pending starting from " + fromToken + " to " + this);
1160 startingData = fromToken.startingData;
1161 fromToken.startingData = null;
1162 fromToken.startingMoved = true;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001163 if (getController() != null) {
1164 getController().scheduleAddStartingWindow();
1165 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001166 return true;
1167 }
1168
1169 final AppWindowAnimator tAppAnimator = fromToken.mAppAnimator;
1170 final AppWindowAnimator wAppAnimator = mAppAnimator;
1171 if (tAppAnimator.thumbnail != null) {
1172 // The old token is animating with a thumbnail, transfer that to the new token.
1173 if (wAppAnimator.thumbnail != null) {
1174 wAppAnimator.thumbnail.destroy();
1175 }
1176 wAppAnimator.thumbnail = tAppAnimator.thumbnail;
1177 wAppAnimator.thumbnailLayer = tAppAnimator.thumbnailLayer;
1178 wAppAnimator.thumbnailAnimation = tAppAnimator.thumbnailAnimation;
1179 tAppAnimator.thumbnail = null;
1180 }
1181 return false;
1182 }
1183
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001184 boolean isLastWindow(WindowState win) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001185 return mChildren.size() == 1 && mChildren.get(0) == win;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001186 }
1187
1188 void setAllAppWinAnimators() {
1189 final ArrayList<WindowStateAnimator> allAppWinAnimators = mAppAnimator.mAllAppWinAnimators;
1190 allAppWinAnimators.clear();
1191
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001192 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001193 for (int j = 0; j < windowsCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001194 (mChildren.get(j)).addWinAnimatorToList(allAppWinAnimators);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001195 }
1196 }
1197
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001198 @Override
1199 void onAppTransitionDone() {
1200 sendingToBottom = false;
1201 }
1202
Wale Ogunwale51362492016-09-08 17:49:17 -07001203 /**
1204 * We override because this class doesn't want its children affecting its reported orientation
1205 * in anyway.
1206 */
1207 @Override
1208 int getOrientation() {
Bryce Leea163b762017-01-24 11:05:01 -08001209 if (fillsParent() && (isVisible() || mService.mOpeningApps.contains(this))) {
1210 return mOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001211 }
Bryce Leea163b762017-01-24 11:05:01 -08001212
1213 return SCREEN_ORIENTATION_UNSET;
Wale Ogunwale51362492016-09-08 17:49:17 -07001214 }
1215
Wale Ogunwaleb198b742016-12-01 08:44:09 -08001216 /** Returns the app's preferred orientation regardless of its currently visibility state. */
1217 int getOrientationIgnoreVisibility() {
1218 return mOrientation;
1219 }
1220
Craig Mautnerdbb79912012-03-01 18:59:14 -08001221 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001222 void checkAppWindowsReadyToShow() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001223 if (allDrawn == mAppAnimator.allDrawn) {
1224 return;
1225 }
1226
1227 mAppAnimator.allDrawn = allDrawn;
1228 if (!allDrawn) {
1229 return;
1230 }
1231
1232 // The token has now changed state to having all windows shown... what to do, what to do?
1233 if (mAppAnimator.freezingScreen) {
1234 mAppAnimator.showAllWindowsLocked();
1235 stopFreezingScreen(false, true);
1236 if (DEBUG_ORIENTATION) Slog.i(TAG,
1237 "Setting mOrientationChangeComplete=true because wtoken " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001238 + " numInteresting=" + mNumInterestingWindows + " numDrawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001239 // This will set mOrientationChangeComplete and cause a pass through layout.
1240 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001241 "checkAppWindowsReadyToShow: freezingScreen");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001242 } else {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001243 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001244
1245 // We can now show all of the drawn windows!
1246 if (!mService.mOpeningApps.contains(this)) {
1247 mService.mAnimator.orAnimating(mAppAnimator.showAllWindowsLocked());
1248 }
1249 }
1250 }
1251
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001252 void updateAllDrawn(DisplayContent dc) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001253 if (!allDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001254 final int numInteresting = mNumInterestingWindows;
1255 if (numInteresting > 0 && mNumDrawnWindows >= numInteresting) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001256 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawn: " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001257 + " interesting=" + numInteresting + " drawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001258 allDrawn = true;
1259 // Force an additional layout pass where
1260 // WindowStateAnimator#commitFinishDrawingLocked() will call performShowLocked().
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001261 dc.setLayoutNeeded();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001262 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
1263 }
1264 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001265
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001266 if (!allDrawnExcludingSaved) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001267 int numInteresting = mNumInterestingWindowsExcludingSaved;
1268 if (numInteresting > 0 && mNumDrawnWindowsExcludingSaved >= numInteresting) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001269 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawnExcludingSaved: " + this
1270 + " interesting=" + numInteresting
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001271 + " drawn=" + mNumDrawnWindowsExcludingSaved);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001272 allDrawnExcludingSaved = true;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001273 dc.setLayoutNeeded();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001274 if (isAnimatingInvisibleWithSavedSurface()
1275 && !mService.mFinishedEarlyAnim.contains(this)) {
1276 mService.mFinishedEarlyAnim.add(this);
1277 }
1278 }
1279 }
1280 }
1281
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001282 /**
1283 * Updated this app token tracking states for interesting and drawn windows based on the window.
1284 *
1285 * @return Returns true if the input window is considered interesting and drawn while all the
1286 * windows in this app token where not considered drawn as of the last pass.
1287 */
1288 boolean updateDrawnWindowStates(WindowState w) {
1289 if (DEBUG_STARTING_WINDOW && w == startingWindow) {
1290 Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" + w.isOnScreen()
1291 + " allDrawn=" + allDrawn + " freezingScreen=" + mAppAnimator.freezingScreen);
1292 }
1293
1294 if (allDrawn && allDrawnExcludingSaved && !mAppAnimator.freezingScreen) {
1295 return false;
1296 }
1297
1298 if (mLastTransactionSequence != mService.mTransactionSequence) {
1299 mLastTransactionSequence = mService.mTransactionSequence;
1300 mNumInterestingWindows = mNumDrawnWindows = 0;
1301 mNumInterestingWindowsExcludingSaved = 0;
1302 mNumDrawnWindowsExcludingSaved = 0;
1303 startingDisplayed = false;
1304 }
1305
1306 final WindowStateAnimator winAnimator = w.mWinAnimator;
1307
1308 boolean isInterestingAndDrawn = false;
1309
1310 if (!allDrawn && w.mightAffectAllDrawn(false /* visibleOnly */)) {
1311 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
1312 Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw()
1313 + ", isAnimationSet=" + winAnimator.isAnimationSet());
1314 if (!w.isDrawnLw()) {
1315 Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController
1316 + " pv=" + w.mPolicyVisibility
1317 + " mDrawState=" + winAnimator.drawStateToString()
1318 + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested
1319 + " a=" + winAnimator.mAnimating);
1320 }
1321 }
1322
1323 if (w != startingWindow) {
1324 if (w.isInteresting()) {
1325 mNumInterestingWindows++;
1326 if (w.isDrawnLw()) {
1327 mNumDrawnWindows++;
1328
1329 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, "tokenMayBeDrawn: "
1330 + this + " w=" + w + " numInteresting=" + mNumInterestingWindows
1331 + " freezingScreen=" + mAppAnimator.freezingScreen
1332 + " mAppFreezing=" + w.mAppFreezing);
1333
1334 isInterestingAndDrawn = true;
1335 }
1336 }
1337 } else if (w.isDrawnLw()) {
1338 mService.mH.sendEmptyMessage(NOTIFY_STARTING_WINDOW_DRAWN);
1339 startingDisplayed = true;
1340 }
1341 }
1342
1343 if (!allDrawnExcludingSaved && w.mightAffectAllDrawn(true /* visibleOnly */)) {
1344 if (w != startingWindow && w.isInteresting()) {
1345 mNumInterestingWindowsExcludingSaved++;
1346 if (w.isDrawnLw() && !w.isAnimatingWithSavedSurface()) {
1347 mNumDrawnWindowsExcludingSaved++;
1348
1349 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
1350 "tokenMayBeDrawnExcludingSaved: " + this + " w=" + w
1351 + " numInteresting=" + mNumInterestingWindowsExcludingSaved
1352 + " freezingScreen=" + mAppAnimator.freezingScreen
1353 + " mAppFreezing=" + w.mAppFreezing);
1354
1355 isInterestingAndDrawn = true;
1356 }
1357 }
1358 }
1359
1360 return isInterestingAndDrawn;
1361 }
1362
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001363 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001364 void stepAppWindowsAnimation(long currentTime) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001365 mAppAnimator.wasAnimating = mAppAnimator.animating;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001366 if (mAppAnimator.stepAnimationLocked(currentTime)) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001367 mAppAnimator.animating = true;
1368 mService.mAnimator.setAnimating(true);
1369 mService.mAnimator.mAppWindowAnimating = true;
1370 } else if (mAppAnimator.wasAnimating) {
1371 // stopped animating, do one more pass through the layout
Wale Ogunwale1e129a42016-11-21 13:03:47 -08001372 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
1373 DEBUG_LAYOUT_REPEATS ? "appToken " + this + " done" : null);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001374 if (DEBUG_ANIM) Slog.v(TAG, "updateWindowsApps...: done animating " + this);
1375 }
1376 }
1377
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001378 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001379 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001380 // For legacy reasons we process the TaskStack.mExitingAppTokens first in DisplayContent
1381 // before the non-exiting app tokens. So, we skip the exiting app tokens here.
1382 // TODO: Investigate if we need to continue to do this or if we can just process them
1383 // in-order.
1384 if (mIsExiting && !waitingForReplacement()) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001385 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001386 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001387 return forAllWindowsUnchecked(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001388 }
1389
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001390 boolean forAllWindowsUnchecked(ToBooleanFunction<WindowState> callback,
1391 boolean traverseTopToBottom) {
1392 return super.forAllWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001393 }
1394
1395 @Override
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001396 AppWindowToken asAppWindowToken() {
1397 // I am an app window token!
1398 return this;
1399 }
1400
1401 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -07001402 boolean fillsParent() {
1403 return mFillsParent;
1404 }
1405
1406 void setFillsParent(boolean fillsParent) {
1407 mFillsParent = fillsParent;
1408 }
1409
Jorim Jaggife762342016-10-13 14:33:27 +02001410 boolean containsDismissKeyguardWindow() {
1411 for (int i = mChildren.size() - 1; i >= 0; i--) {
1412 if ((mChildren.get(i).mAttrs.flags & FLAG_DISMISS_KEYGUARD) != 0) {
1413 return true;
1414 }
1415 }
1416 return false;
1417 }
1418
1419 boolean containsShowWhenLockedWindow() {
1420 for (int i = mChildren.size() - 1; i >= 0; i--) {
1421 if ((mChildren.get(i).mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
1422 return true;
1423 }
1424 }
1425 return false;
1426 }
1427
1428 void checkKeyguardFlagsChanged() {
1429 final boolean containsDismissKeyguard = containsDismissKeyguardWindow();
1430 final boolean containsShowWhenLocked = containsShowWhenLockedWindow();
1431 if (containsDismissKeyguard != mLastContainsDismissKeyguardWindow
1432 || containsShowWhenLocked != mLastContainsShowWhenLockedWindow) {
1433 mService.notifyKeyguardFlagsChanged(null /* callback */);
1434 }
1435 mLastContainsDismissKeyguardWindow = containsDismissKeyguard;
1436 mLastContainsShowWhenLockedWindow = containsShowWhenLocked;
1437 }
1438
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001439 WindowState getImeTargetBelowWindow(WindowState w) {
1440 final int index = mChildren.indexOf(w);
1441 if (index > 0) {
1442 final WindowState target = mChildren.get(index - 1);
1443 if (target.canBeImeTarget()) {
1444 return target;
1445 }
1446 }
1447 return null;
1448 }
1449
1450 WindowState getHighestAnimLayerWindow(WindowState currentTarget) {
1451 WindowState candidate = null;
1452 for (int i = mChildren.indexOf(currentTarget); i >= 0; i--) {
1453 final WindowState w = mChildren.get(i);
1454 if (w.mRemoved) {
1455 continue;
1456 }
1457 if (candidate == null || w.mWinAnimator.mAnimLayer >
1458 candidate.mWinAnimator.mAnimLayer) {
1459 candidate = w;
1460 }
1461 }
1462 return candidate;
1463 }
1464
Wale Ogunwale51362492016-09-08 17:49:17 -07001465 @Override
Robert Carrdee1b3f2017-02-27 11:33:33 -08001466 int getAnimLayerAdjustment() {
1467 return mAppAnimator.animLayerAdjustment;
1468 }
1469
1470 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001471 void dump(PrintWriter pw, String prefix) {
1472 super.dump(pw, prefix);
1473 if (appToken != null) {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001474 pw.println(prefix + "app=true mVoiceInteraction=" + mVoiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001475 }
Craig Mautner83162a92015-01-26 14:43:30 -08001476 pw.print(prefix); pw.print("task="); pw.println(mTask);
Wale Ogunwale51362492016-09-08 17:49:17 -07001477 pw.print(prefix); pw.print(" mFillsParent="); pw.print(mFillsParent);
1478 pw.print(" mOrientation="); pw.println(mOrientation);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001479 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
1480 pw.print(" clientHidden="); pw.print(clientHidden);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -07001481 pw.print(" reportedDrawn="); pw.print(reportedDrawn);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001482 pw.print(" reportedVisible="); pw.println(reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -07001483 if (paused) {
1484 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001485 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001486 if (mAppStopped) {
1487 pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped);
1488 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001489 if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0
Craig Mautner6fbda632012-07-03 09:26:39 -07001490 || allDrawn || mAppAnimator.allDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001491 pw.print(prefix); pw.print("mNumInterestingWindows=");
1492 pw.print(mNumInterestingWindows);
1493 pw.print(" mNumDrawnWindows="); pw.print(mNumDrawnWindows);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001494 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -07001495 pw.print(" allDrawn="); pw.print(allDrawn);
1496 pw.print(" (animator="); pw.print(mAppAnimator.allDrawn);
1497 pw.println(")");
1498 }
1499 if (inPendingTransaction) {
1500 pw.print(prefix); pw.print("inPendingTransaction=");
1501 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001502 }
Craig Mautner799bc1d2015-01-14 10:33:48 -08001503 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001504 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
1505 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -08001506 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -08001507 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001508 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001509 if (startingWindow != null || startingSurface != null
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001510 || startingDisplayed || startingMoved) {
1511 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001512 pw.print(" startingSurface="); pw.print(startingSurface);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001513 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001514 pw.print(" startingMoved="); pw.println(startingMoved);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001515 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01001516 if (!mFrozenBounds.isEmpty()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -08001517 pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds);
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001518 pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig);
Chong Zhangd78ddb42016-03-02 17:01:14 -08001519 }
1520 if (mPendingRelaunchCount != 0) {
1521 pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount);
Jorim Jaggi0429f352015-12-22 16:29:16 +01001522 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001523 }
1524
1525 @Override
1526 public String toString() {
1527 if (stringName == null) {
1528 StringBuilder sb = new StringBuilder();
1529 sb.append("AppWindowToken{");
1530 sb.append(Integer.toHexString(System.identityHashCode(this)));
1531 sb.append(" token="); sb.append(token); sb.append('}');
1532 stringName = sb.toString();
1533 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001534 return stringName + ((mIsExiting) ? " mIsExiting=" : "");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001535 }
Jeff Browne9bdb312012-04-05 15:30:10 -07001536}