blob: 936739bf143eaf9a2bc1b877def8a3e8b066f2eb [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 Ogunwale5e5a68d2017-03-24 17:36:38 -070022import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND;
Wale Ogunwale51362492016-09-08 17:49:17 -070023import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070024import static android.view.Display.DEFAULT_DISPLAY;
Jorim Jaggife762342016-10-13 14:33:27 +020025import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
26import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
Wale Ogunwaled1c37912016-08-16 03:19:39 -070027import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080028import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070029import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -070030import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
31import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070032import static com.android.server.wm.AppTransition.TRANSIT_UNSET;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080033import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080034import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
35import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070036import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070037import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
38import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
Wale Ogunwale9017ec02016-02-25 08:55:25 -080039import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070040import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TOKEN_MOVEMENT;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080041import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
42import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_MOVEMENT;
43import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
44import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Chong Zhang92147042016-05-09 12:47:11 -070045import static com.android.server.wm.WindowManagerService.H.NOTIFY_ACTIVITY_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;
Robert Carr6914f082017-03-20 19:04:30 -070059import android.view.SurfaceControl;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080060import android.view.WindowManager;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080061import android.view.WindowManagerPolicy.StartingSurface;
62
63import com.android.internal.util.ToBooleanFunction;
64import com.android.server.input.InputApplicationHandle;
65import com.android.server.wm.WindowManagerService.H;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080066
67import java.io.PrintWriter;
Jorim Jaggi0429f352015-12-22 16:29:16 +010068import java.util.ArrayDeque;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080069import java.util.ArrayList;
70
71class AppTokenList extends ArrayList<AppWindowToken> {
72}
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080073
74/**
75 * Version of WindowToken that is specifically for a particular application (or
76 * really activity) that is displaying windows.
77 */
Wale Ogunwale3f4433d2016-08-18 20:42:42 -070078class AppWindowToken extends WindowToken implements WindowManagerService.AppFreezeListener {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080079 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppWindowToken" : TAG_WM;
80
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080081 // Non-null only for application tokens.
82 final IApplicationToken appToken;
83
Filip Gruszczynskia590c992015-11-25 16:45:26 -080084 @NonNull final AppWindowAnimator mAppAnimator;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -070085
Wale Ogunwale72919d22016-12-08 18:58:50 -080086 final boolean mVoiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -070087
Wale Ogunwale51362492016-09-08 17:49:17 -070088 /** @see WindowContainer#fillsParent() */
89 private boolean mFillsParent;
Craig Mautner4c5eb222013-11-18 12:59:05 -080090 boolean layoutConfigChanges;
Wale Ogunwale72919d22016-12-08 18:58:50 -080091 boolean mShowForAllUsers;
92 int mTargetSdk;
Craig Mautnera2c77052012-03-26 12:14:43 -070093
Bryce Lee6d410262017-02-28 15:30:17 -080094 // Flag set while reparenting to prevent actions normally triggered by an individual parent
95 // change.
96 private boolean mReparenting;
97
Wale Ogunwalee287e192017-04-21 09:30:12 -070098 // True if we are current in the process of removing this app token from the display
99 private boolean mRemovingFromDisplay = false;
100
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800101 // The input dispatching timeout for this application token in nanoseconds.
Wale Ogunwale72919d22016-12-08 18:58:50 -0800102 long mInputDispatchingTimeoutNanos;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800103
104 // These are used for determining when all windows associated with
105 // an activity have been drawn, so they can be made visible together
106 // at the same time.
Craig Mautner764983d2012-03-22 11:37:36 -0700107 // initialize so that it doesn't match mTransactionSequence which is an int.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700108 private long mLastTransactionSequence = Long.MIN_VALUE;
109 private int mNumInterestingWindows;
110 private int mNumDrawnWindows;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800111 boolean inPendingTransaction;
112 boolean allDrawn;
Craig Mautner7636dfb2012-11-16 15:24:11 -0800113 // Set to true when this app creates a surface while in the middle of an animation. In that
114 // case do not clear allDrawn until the animation completes.
115 boolean deferClearAllDrawn;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800116
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700117 /**
118 * These are to track the app's real drawing status if there were no saved surfaces.
119 * @see #updateDrawnWindowStates
120 */
Chong Zhang8e4bda92016-05-04 15:08:18 -0700121 boolean allDrawnExcludingSaved;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700122 private int mNumInterestingWindowsExcludingSaved;
123 private int mNumDrawnWindowsExcludingSaved;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700124
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800125 // Is this window's surface needed? This is almost like hidden, except
126 // it will sometimes be true a little earlier: when the token has
127 // been shown, but is still waiting for its app transition to execute
128 // before making its windows shown.
129 boolean hiddenRequested;
130
131 // Have we told the window clients to hide themselves?
132 boolean clientHidden;
133
134 // Last visibility state we reported to the app token.
135 boolean reportedVisible;
136
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700137 // Last drawn state we reported to the app token.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700138 private boolean reportedDrawn;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700139
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800140 // Set to true when the token has been removed from the window mgr.
141 boolean removed;
142
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800143 // Information about an application starting window if displayed.
144 StartingData startingData;
145 WindowState startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800146 StartingSurface startingSurface;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800147 boolean startingDisplayed;
148 boolean startingMoved;
149 boolean firstWindowDrawn;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700150 private final WindowState.UpdateReportedVisibilityResults mReportedVisibilityResults =
151 new WindowState.UpdateReportedVisibilityResults();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800152
153 // Input application handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700154 final InputApplicationHandle mInputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800155
Wale Ogunwale571771c2016-08-26 13:18:50 -0700156 // TODO: Have a WindowContainer state for tracking exiting/deferred removal.
Craig Mautner799bc1d2015-01-14 10:33:48 -0800157 boolean mIsExiting;
Craig Mautner9ef471f2014-02-07 13:11:47 -0800158
Craig Mautnerbb742462014-07-07 15:28:55 -0700159 boolean mLaunchTaskBehind;
Craig Mautner8746a472014-07-24 15:12:54 -0700160 boolean mEnteringAnimation;
Craig Mautnerbb742462014-07-07 15:28:55 -0700161
Wale Ogunwale72919d22016-12-08 18:58:50 -0800162 private boolean mAlwaysFocusable;
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800163
Robert Carre12aece2016-02-02 22:43:27 -0800164 boolean mAppStopped;
Robert Carrfd10cd12016-06-29 16:41:50 -0700165 int mRotationAnimationHint;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700166 private int mPendingRelaunchCount;
Robert Carre12aece2016-02-02 22:43:27 -0800167
Jorim Jaggife762342016-10-13 14:33:27 +0200168 private boolean mLastContainsShowWhenLockedWindow;
169 private boolean mLastContainsDismissKeyguardWindow;
170
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700171 // The bounds of this activity. Mainly used for aspect-ratio compatibility.
172 // TODO(b/36505427): Every level on WindowContainer now has bounds information, which directly
173 // affects the configuration. We should probably move this into that class.
174 private final Rect mBounds = new Rect();
175
Jorim Jaggi0429f352015-12-22 16:29:16 +0100176 ArrayDeque<Rect> mFrozenBounds = new ArrayDeque<>();
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700177 ArrayDeque<Configuration> mFrozenMergedConfig = new ArrayDeque<>();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100178
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +0100179 private boolean mDisbalePreviewScreenshots;
180
Wale Ogunwale72919d22016-12-08 18:58:50 -0800181 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
182 DisplayContent dc, long inputDispatchingTimeoutNanos, boolean fullscreen,
183 boolean showForAllUsers, int targetSdk, int orientation, int rotationAnimationHint,
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800184 int configChanges, boolean launchTaskBehind, boolean alwaysFocusable,
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700185 AppWindowContainerController controller, Configuration overrideConfig, Rect bounds) {
186 this(service, token, voiceInteraction, dc, fullscreen, overrideConfig, bounds);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800187 setController(controller);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800188 mInputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800189 mShowForAllUsers = showForAllUsers;
190 mTargetSdk = targetSdk;
191 mOrientation = orientation;
192 layoutConfigChanges = (configChanges & (CONFIG_SCREEN_SIZE | CONFIG_ORIENTATION)) != 0;
193 mLaunchTaskBehind = launchTaskBehind;
194 mAlwaysFocusable = alwaysFocusable;
195 mRotationAnimationHint = rotationAnimationHint;
196
197 // Application tokens start out hidden.
198 hidden = true;
199 hiddenRequested = true;
200 }
201
202 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700203 DisplayContent dc, boolean fillsParent, Configuration overrideConfig, Rect bounds) {
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800204 super(service, token != null ? token.asBinder() : null, TYPE_APPLICATION, true, dc,
205 false /* ownerCanManageAppTokens */);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700206 appToken = token;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800207 mVoiceInteraction = voiceInteraction;
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800208 mFillsParent = fillsParent;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800209 mInputApplicationHandle = new InputApplicationHandle(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700210 mAppAnimator = new AppWindowAnimator(this, service);
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700211 if (overrideConfig != null) {
212 onOverrideConfigurationChanged(overrideConfig);
213 }
214 if (bounds != null) {
215 mBounds.set(bounds);
216 }
217 }
218
219 void onOverrideConfigurationChanged(Configuration overrideConfiguration, Rect bounds) {
220 onOverrideConfigurationChanged(overrideConfiguration);
221 if (mBounds.equals(bounds)) {
222 return;
223 }
224 // TODO(b/36505427): If bounds is in WC, then we can automatically call onResize() when set.
225 mBounds.set(bounds);
226 onResize();
227 }
228
229 void getBounds(Rect outBounds) {
230 outBounds.set(mBounds);
231 }
232
233 boolean hasBounds() {
234 return !mBounds.isEmpty();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800235 }
236
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800237 void onFirstWindowDrawn(WindowState win, WindowStateAnimator winAnimator) {
238 firstWindowDrawn = true;
239
240 // We now have a good window to show, remove dead placeholders
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700241 removeDeadWindows();
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800242
Jorim Jaggi02886a82016-12-06 09:10:06 -0800243 if (startingWindow != null) {
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800244 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, "Finish starting "
245 + win.mToken + ": first real window is shown, no animation");
246 // If this initial window is animating, stop it -- we will do an animation to reveal
247 // it from behind the starting window, so there is no need for it to also be doing its
248 // own stuff.
249 winAnimator.clearAnimation();
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800250 if (getController() != null) {
251 getController().removeStartingWindow();
252 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800253 }
254 updateReportedVisibilityLocked();
255 }
256
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800257 void updateReportedVisibilityLocked() {
258 if (appToken == null) {
259 return;
260 }
261
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700262 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700263 final int count = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800264
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700265 mReportedVisibilityResults.reset();
266
267 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700268 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700269 win.updateReportedVisibility(mReportedVisibilityResults);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800270 }
271
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700272 int numInteresting = mReportedVisibilityResults.numInteresting;
273 int numVisible = mReportedVisibilityResults.numVisible;
274 int numDrawn = mReportedVisibilityResults.numDrawn;
275 boolean nowGone = mReportedVisibilityResults.nowGone;
276
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700277 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800278 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700279 if (!nowGone) {
280 // If the app is not yet gone, then it can only become visible/drawn.
281 if (!nowDrawn) {
282 nowDrawn = reportedDrawn;
283 }
284 if (!nowVisible) {
285 nowVisible = reportedVisible;
286 }
287 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800288 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800289 + numInteresting + " visible=" + numVisible);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800290 final AppWindowContainerController controller = getController();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700291 if (nowDrawn != reportedDrawn) {
292 if (nowDrawn) {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800293 if (controller != null) {
294 controller.reportWindowsDrawn();
295 }
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700296 }
297 reportedDrawn = nowDrawn;
298 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800299 if (nowVisible != reportedVisible) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700300 if (DEBUG_VISIBILITY) Slog.v(TAG,
301 "Visibility changed in " + this + ": vis=" + nowVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800302 reportedVisible = nowVisible;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800303 if (controller != null) {
304 if (nowVisible) {
305 controller.reportWindowsVisible();
306 } else {
307 controller.reportWindowsGone();
308 }
309 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800310 }
311 }
312
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700313 boolean setVisibility(WindowManager.LayoutParams lp,
314 boolean visible, int transit, boolean performLayout, boolean isVoiceInteraction) {
315
316 boolean delayed = false;
317 inPendingTransaction = false;
318
319 if (clientHidden == visible) {
320 clientHidden = !visible;
321 sendAppVisibilityToClients();
322 }
323
324 // Allow for state changes and animation to be applied if:
325 // * token is transitioning visibility state
326 // * or the token was marked as hidden and is exiting before we had a chance to play the
327 // transition animation
328 // * or this is an opening app and windows are being replaced.
329 boolean visibilityChanged = false;
330 if (hidden == visible || (hidden && mIsExiting) || (visible && waitingForReplacement())) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700331 final AccessibilityController accessibilityController = mService.mAccessibilityController;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700332 boolean changed = false;
333 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
334 "Changing app " + this + " hidden=" + hidden + " performLayout=" + performLayout);
335
336 boolean runningAppAnimation = false;
337
338 if (transit != AppTransition.TRANSIT_UNSET) {
339 if (mAppAnimator.animation == AppWindowAnimator.sDummyAnimation) {
340 mAppAnimator.setNullAnimation();
341 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700342 if (mService.applyAnimationLocked(this, lp, transit, visible, isVoiceInteraction)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700343 delayed = runningAppAnimation = true;
344 }
345 final WindowState window = findMainWindow();
346 //TODO (multidisplay): Magnification is supported only for the default display.
347 if (window != null && accessibilityController != null
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700348 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700349 accessibilityController.onAppWindowTransitionLocked(window, transit);
350 }
351 changed = true;
352 }
353
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700354 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700355 for (int i = 0; i < windowsCount; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700356 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700357 changed |= win.onAppVisibilityChanged(visible, runningAppAnimation);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700358 }
359
360 hidden = hiddenRequested = !visible;
361 visibilityChanged = true;
362 if (!visible) {
363 stopFreezingScreen(true, true);
364 } else {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700365 // If we are being set visible, and the starting window is not yet displayed,
366 // then make sure it doesn't get displayed.
367 if (startingWindow != null && !startingWindow.isDrawnLw()) {
368 startingWindow.mPolicyVisibility = false;
369 startingWindow.mPolicyVisibilityAfterAnim = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700370 }
371 }
372
373 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setVisibility: " + this
374 + ": hidden=" + hidden + " hiddenRequested=" + hiddenRequested);
375
376 if (changed) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700377 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700378 if (performLayout) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700379 mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700380 false /*updateInputWindows*/);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700381 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700382 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700383 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700384 }
385 }
386
387 if (mAppAnimator.animation != null) {
388 delayed = true;
389 }
390
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700391 for (int i = mChildren.size() - 1; i >= 0 && !delayed; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700392 if ((mChildren.get(i)).isWindowAnimationSet()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700393 delayed = true;
394 }
395 }
396
397 if (visibilityChanged) {
398 if (visible && !delayed) {
399 // The token was made immediately visible, there will be no entrance animation.
400 // We need to inform the client the enter animation was finished.
401 mEnteringAnimation = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700402 mService.mActivityManagerAppTransitionNotifier.onAppTransitionFinishedLocked(token);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700403 }
Robert Carre7cc44d2017-03-20 19:04:30 -0700404 // If we are hidden but there is no delay needed we immediately
405 // apply the Surface transaction so that the ActivityManager
406 // can have some guarantee on the Surface state
407 // following setting the visibility.
Robert Carr6914f082017-03-20 19:04:30 -0700408 if (hidden && !delayed) {
409 SurfaceControl.openTransaction();
410 for (int i = mChildren.size() - 1; i >= 0; i--) {
411 mChildren.get(i).mWinAnimator.hide("immediately hidden");
412 }
413 SurfaceControl.closeTransaction();
414 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700415
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700416 if (!mService.mClosingApps.contains(this) && !mService.mOpeningApps.contains(this)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700417 // The token is not closing nor opening, so even if there is an animation set, that
418 // doesn't mean that it goes through the normal app transition cycle so we have
419 // to inform the docked controller about visibility change.
Andrii Kulian1e32e022016-09-16 15:29:34 -0700420 // TODO(multi-display): notify docked divider on all displays where visibility was
421 // affected.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700422 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700423 .notifyAppVisibilityChanged();
Jorim Jaggi8b702ed2017-01-20 16:59:03 +0100424 mService.mTaskSnapshotController.notifyAppVisibilityChanged(this, visible);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700425 }
426 }
427
428 return delayed;
429 }
430
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800431 WindowState findMainWindow() {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700432 WindowState candidate = null;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700433 int j = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800434 while (j > 0) {
435 j--;
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700436 final WindowState win = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700437 final int type = win.mAttrs.type;
438 // No need to loop through child window as base application and starting types can't be
439 // child windows.
440 if (type == TYPE_BASE_APPLICATION || type == TYPE_APPLICATION_STARTING) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700441 // In cases where there are multiple windows, we prefer the non-exiting window. This
Sungsoo Lim0d3d1f82015-12-02 14:47:59 +0900442 // happens for example when replacing windows during an activity relaunch. When
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700443 // constructing the animation, we want the new window, not the exiting one.
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800444 if (win.mAnimatingExit) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700445 candidate = win;
446 } else {
447 return win;
448 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800449 }
450 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700451 return candidate;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800452 }
453
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800454 boolean windowsAreFocusable() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800455 return StackId.canReceiveKeys(getTask().mStack.mStackId) || mAlwaysFocusable;
Wale Ogunwaled045c822015-12-02 09:14:28 -0800456 }
457
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800458 AppWindowContainerController getController() {
459 final WindowContainerController controller = super.getController();
460 return controller != null ? (AppWindowContainerController) controller : null;
461 }
462
Wale Ogunwale571771c2016-08-26 13:18:50 -0700463 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -0700464 boolean isVisible() {
Wale Ogunwalee471be62016-10-03 07:53:55 -0700465 // If the app token isn't hidden then it is considered visible and there is no need to check
466 // its children windows to see if they are visible.
467 return !hidden;
Wale Ogunwale44f21802016-09-02 12:49:48 -0700468 }
469
470 @Override
Wale Ogunwalee287e192017-04-21 09:30:12 -0700471 void removeImmediately() {
472 onRemovedFromDisplay();
473 super.removeImmediately();
474 }
475
476 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -0700477 void removeIfPossible() {
Craig Mautnere3119b72015-01-20 15:02:36 -0800478 mIsExiting = false;
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800479 removeAllWindowsIfPossible();
Bryce Lee6d410262017-02-28 15:30:17 -0800480 removeImmediately();
Craig Mautnere3119b72015-01-20 15:02:36 -0800481 }
482
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700483 @Override
484 boolean checkCompleteDeferredRemoval() {
485 if (mIsExiting) {
486 removeIfPossible();
487 }
488 return super.checkCompleteDeferredRemoval();
489 }
490
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700491 void onRemovedFromDisplay() {
Wale Ogunwalee287e192017-04-21 09:30:12 -0700492 if (mRemovingFromDisplay) {
493 return;
494 }
495 mRemovingFromDisplay = true;
496
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700497 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app token: " + this);
498
Wale Ogunwale72919d22016-12-08 18:58:50 -0800499 boolean delayed = setVisibility(null, false, TRANSIT_UNSET, true, mVoiceInteraction);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700500
501 mService.mOpeningApps.remove(this);
Jorim Jaggi1b4b23e2016-11-15 16:30:12 -0800502 mService.mUnknownAppVisibilityController.appRemoved(this);
Jorim Jaggi10abe2f2017-01-03 16:44:46 +0100503 mService.mTaskSnapshotController.onAppRemoved(this);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700504 waitingToShow = false;
505 if (mService.mClosingApps.contains(this)) {
506 delayed = true;
507 } else if (mService.mAppTransition.isTransitionSet()) {
508 mService.mClosingApps.add(this);
509 delayed = true;
510 }
511
512 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app " + this + " delayed=" + delayed
513 + " animation=" + mAppAnimator.animation + " animating=" + mAppAnimator.animating);
514
515 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM, "removeAppToken: "
516 + this + " delayed=" + delayed + " Callers=" + Debug.getCallers(4));
517
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800518 if (startingData != null && getController() != null) {
519 getController().removeStartingWindow();
520 }
521
Winson Chung87e5d552017-04-05 11:49:38 -0700522 // If this window was animating, then we need to ensure that the app transition notifies
523 // that animations have completed in WMS.handleAnimatingStoppedAndTransitionLocked(), so
524 // add to that list now
525 if (mAppAnimator.animating) {
526 mService.mNoAnimationNotifyOnTransitionFinished.add(token);
527 }
528
Wale Ogunwalee287e192017-04-21 09:30:12 -0700529 final TaskStack stack = getStack();
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700530 if (delayed && !isEmpty()) {
531 // set the token aside because it has an active animation to be finished
532 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM,
533 "removeAppToken make exiting: " + this);
Wale Ogunwalee287e192017-04-21 09:30:12 -0700534 if (stack != null) {
535 stack.mExitingAppTokens.add(this);
536 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700537 mIsExiting = true;
538 } else {
539 // Make sure there is no animation running on this token, so any windows associated
540 // with it will be removed as soon as their animations are complete
541 mAppAnimator.clearAnimation();
542 mAppAnimator.animating = false;
543 removeIfPossible();
544 }
545
546 removed = true;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700547 stopFreezingScreen(true, true);
Bryce Lee6d410262017-02-28 15:30:17 -0800548
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700549 if (mService.mFocusedApp == this) {
550 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "Removing focused app token:" + this);
551 mService.mFocusedApp = null;
552 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
553 mService.mInputMonitor.setFocusedAppLw(null);
554 }
555
556 if (!delayed) {
557 updateReportedVisibilityLocked();
558 }
Wale Ogunwalee287e192017-04-21 09:30:12 -0700559
560 mRemovingFromDisplay = false;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700561 }
562
Chong Zhange05bcb12016-07-26 17:47:29 -0700563 void clearAnimatingFlags() {
Chong Zhangb0d26702016-08-12 16:03:29 -0700564 boolean wallpaperMightChange = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700565 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700566 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700567 wallpaperMightChange |= win.clearAnimatingFlags();
Chong Zhange05bcb12016-07-26 17:47:29 -0700568 }
Chong Zhangb0d26702016-08-12 16:03:29 -0700569 if (wallpaperMightChange) {
570 requestUpdateWallpaperIfNeeded();
571 }
Chong Zhange05bcb12016-07-26 17:47:29 -0700572 }
573
Robert Carre12aece2016-02-02 22:43:27 -0800574 void destroySurfaces() {
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700575 destroySurfaces(false /*cleanupOnResume*/);
576 }
577
578 /**
579 * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure
580 * the client has finished with them.
581 *
582 * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If
583 * set to true, destroy only surfaces of removed windows, and clear relevant flags of the
584 * others so that they are ready to be reused. If set to false (common case), destroy all
585 * surfaces that's eligible, if the app is already stopped.
586 */
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700587 private void destroySurfaces(boolean cleanupOnResume) {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700588 boolean destroyedSomething = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700589 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700590 final WindowState win = mChildren.get(i);
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700591 destroyedSomething |= win.destroySurface(cleanupOnResume, mAppStopped);
Robert Carre12aece2016-02-02 22:43:27 -0800592 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700593 if (destroyedSomething) {
594 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700595 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Robert Carre12aece2016-02-02 22:43:27 -0800596 }
597 }
598
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800599 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700600 * Notify that the app is now resumed, and it was not stopped before, perform a clean
601 * up of the surfaces
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800602 */
Jorim Jaggibae01b12017-04-11 16:29:10 -0700603 void notifyAppResumed(boolean wasStopped) {
Chong Zhangad24f962016-08-25 12:12:33 -0700604 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped
Jorim Jaggibae01b12017-04-11 16:29:10 -0700605 + " " + this);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700606 mAppStopped = false;
607 if (!wasStopped) {
608 destroySurfaces(true /*cleanupOnResume*/);
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800609 }
Robert Carre12aece2016-02-02 22:43:27 -0800610 }
611
Chong Zhangbef461f2015-10-27 11:38:24 -0700612 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700613 * Notify that the app has stopped, and it is okay to destroy any surfaces which were
614 * keeping alive in case they were still being used.
615 */
616 void notifyAppStopped() {
617 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this);
618 mAppStopped = true;
619 destroySurfaces();
620 // Remove any starting window that was added for this app if they are still around.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800621 if (getController() != null) {
622 getController().removeStartingWindow();
623 }
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700624 }
625
626 /**
Chong Zhangbef461f2015-10-27 11:38:24 -0700627 * Checks whether we should save surfaces for this app.
628 *
629 * @return true if the surfaces should be saved, false otherwise.
630 */
631 boolean shouldSaveSurface() {
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800632 // We want to save surface if the app's windows are "allDrawn".
633 // (If we started entering animation early with saved surfaces, allDrawn
634 // should have been restored to true. So we'll save again in that case
635 // even if app didn't actually finish drawing.)
636 return allDrawn;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800637 }
638
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700639 private boolean canRestoreSurfaces() {
640 for (int i = mChildren.size() -1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700641 final WindowState w = mChildren.get(i);
Chong Zhang92147042016-05-09 12:47:11 -0700642 if (w.canRestoreSurface()) {
Robert Carr13f7be9e2015-12-02 18:39:45 -0800643 return true;
644 }
Chong Zhangbef461f2015-10-27 11:38:24 -0700645 }
646 return false;
647 }
648
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700649 private void clearWasVisibleBeforeClientHidden() {
650 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700651 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700652 w.clearWasVisibleBeforeClientHidden();
Chong Zhang92147042016-05-09 12:47:11 -0700653 }
654 }
655
Chong Zhang8e4bda92016-05-04 15:08:18 -0700656 /**
657 * Whether the app has some window that is invisible in layout, but
658 * animating with saved surface.
659 */
660 boolean isAnimatingInvisibleWithSavedSurface() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700661 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700662 final WindowState w = mChildren.get(i);
Chong Zhang8e4bda92016-05-04 15:08:18 -0700663 if (w.isAnimatingInvisibleWithSavedSurface()) {
664 return true;
665 }
666 }
667 return false;
668 }
669
670 /**
671 * Hide all window surfaces that's still invisible in layout but animating
672 * with a saved surface, and mark them destroying.
673 */
674 void stopUsingSavedSurfaceLocked() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700675 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700676 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700677 w.stopUsingSavedSurface();
Chong Zhang8e4bda92016-05-04 15:08:18 -0700678 }
679 destroySurfaces();
680 }
681
Chong Zhangf58631a2016-05-24 16:02:10 -0700682 void markSavedSurfaceExiting() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700683 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700684 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700685 w.markSavedSurfaceExiting();
Chong Zhangf58631a2016-05-24 16:02:10 -0700686 }
687 }
688
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700689 void restoreSavedSurfaceForInterestingWindows() {
Chong Zhang92147042016-05-09 12:47:11 -0700690 if (!canRestoreSurfaces()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700691 clearWasVisibleBeforeClientHidden();
Chong Zhangbef461f2015-10-27 11:38:24 -0700692 return;
693 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700694
695 // Check if all interesting windows are drawn and we can mark allDrawn=true.
696 int interestingNotDrawn = -1;
697
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700698 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700699 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700700 interestingNotDrawn = w.restoreSavedSurfaceForInterestingWindow();
Chong Zhangbef461f2015-10-27 11:38:24 -0700701 }
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800702
Chong Zhang92147042016-05-09 12:47:11 -0700703 if (!allDrawn) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700704 allDrawn = (interestingNotDrawn == 0);
Chong Zhang92147042016-05-09 12:47:11 -0700705 if (allDrawn) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700706 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Chong Zhang92147042016-05-09 12:47:11 -0700707 }
708 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700709 clearWasVisibleBeforeClientHidden();
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800710
711 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700712 "restoreSavedSurfaceForInterestingWindows: " + this + " allDrawn=" + allDrawn
713 + " interestingNotDrawn=" + interestingNotDrawn);
Chong Zhangbef461f2015-10-27 11:38:24 -0700714 }
715
716 void destroySavedSurfaces() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700717 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700718 final WindowState win = mChildren.get(i);
Robert Carr13f7be9e2015-12-02 18:39:45 -0800719 win.destroySavedSurface();
Chong Zhangbef461f2015-10-27 11:38:24 -0700720 }
Chong Zhang92147042016-05-09 12:47:11 -0700721 }
722
723 void clearAllDrawn() {
724 allDrawn = false;
725 deferClearAllDrawn = false;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700726 allDrawnExcludingSaved = false;
Chong Zhangbef461f2015-10-27 11:38:24 -0700727 }
728
Bryce Lee6d410262017-02-28 15:30:17 -0800729 Task getTask() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800730 return (Task) getParent();
Bryce Lee6d410262017-02-28 15:30:17 -0800731 }
732
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800733 TaskStack getStack() {
734 final Task task = getTask();
735 if (task != null) {
736 return task.mStack;
737 } else {
738 return null;
739 }
740 }
741
Bryce Lee6d410262017-02-28 15:30:17 -0800742 @Override
743 void onParentSet() {
744 super.onParentSet();
745
746 // When the associated task is {@code null}, the {@link AppWindowToken} can no longer
747 // access visual elements like the {@link DisplayContent}. We must remove any associations
748 // such as animations.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800749 if (!mReparenting) {
750 final Task task = getTask();
751 if (task == null) {
752 // It is possible we have been marked as a closing app earlier. We must remove ourselves
753 // from this list so we do not participate in any future animations.
754 mService.mClosingApps.remove(this);
755 } else if (task.mStack != null) {
756 task.mStack.mExitingAppTokens.remove(this);
757 }
Bryce Lee6d410262017-02-28 15:30:17 -0800758 }
759 }
760
Wale Ogunwalefa854eb2016-09-20 13:43:52 -0700761 void postWindowRemoveStartingWindowCleanup(WindowState win) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700762 // TODO: Something smells about the code below...Is there a better way?
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700763 if (startingWindow == win) {
764 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800765 if (getController() != null) {
766 getController().removeStartingWindow();
767 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700768 } else if (mChildren.size() == 0 && startingData != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700769 // If this is the last window and we had requested a starting transition window,
770 // well there is no point now.
Jorim Jaggi02886a82016-12-06 09:10:06 -0800771 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingData");
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700772 startingData = null;
Jorim Jaggi829b9cd2017-01-23 16:20:53 +0100773 } else if (mChildren.size() == 1 && startingSurface != null && !isRelaunching()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700774 // If this is the last window except for a starting transition window,
775 // we need to get rid of the starting transition.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800776 if (getController() != null) {
777 getController().removeStartingWindow();
778 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700779 }
780 }
781
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700782 void removeDeadWindows() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700783 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700784 WindowState win = mChildren.get(winNdx);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800785 if (win.mAppDied) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700786 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700787 "removeDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800788 // Set mDestroying, we don't want any animation or delayed removal here.
789 win.mDestroying = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700790 // Also removes child windows.
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700791 win.removeIfPossible();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800792 }
793 }
794 }
795
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700796 boolean hasWindowsAlive() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700797 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700798 // No need to loop through child windows as the answer should be the same as that of the
799 // parent window.
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700800 if (!(mChildren.get(i)).mAppDied) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700801 return true;
802 }
803 }
804 return false;
805 }
806
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700807 void setWillReplaceWindows(boolean animate) {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700808 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
809 "Marking app token " + this + " with replacing windows.");
Robert Carra1eb4392015-12-10 12:43:51 -0800810
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700811 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700812 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700813 w.setWillReplaceWindow(animate);
Robert Carra1eb4392015-12-10 12:43:51 -0800814 }
815 if (animate) {
816 // Set-up dummy animation so we can start treating windows associated with this
817 // token like they are in transition before the new app window is ready for us to
818 // run the real transition animation.
819 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700820 "setWillReplaceWindow() Setting dummy animation on: " + this);
Robert Carra1eb4392015-12-10 12:43:51 -0800821 mAppAnimator.setDummyAnimation();
822 }
823 }
824
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700825 void setWillReplaceChildWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700826 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this
Robert Carr23fa16b2016-01-13 13:19:58 -0800827 + " with replacing child windows.");
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700828 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700829 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700830 w.setWillReplaceChildWindows();
Robert Carr23fa16b2016-01-13 13:19:58 -0800831 }
832 }
833
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700834 void clearWillReplaceWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700835 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
836 "Resetting app token " + this + " of replacing window marks.");
Chong Zhangf596cd52016-01-05 13:42:44 -0800837
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700838 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700839 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700840 w.clearWillReplaceWindow();
Chong Zhangf596cd52016-01-05 13:42:44 -0800841 }
842 }
843
Chong Zhang4d7369a2016-04-25 16:09:14 -0700844 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700845 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700846 final WindowState w = mChildren.get(i);
Chong Zhang4d7369a2016-04-25 16:09:14 -0700847 w.requestUpdateWallpaperIfNeeded();
848 }
849 }
850
Chong Zhangd78ddb42016-03-02 17:01:14 -0800851 boolean isRelaunching() {
852 return mPendingRelaunchCount > 0;
853 }
854
855 void startRelaunching() {
856 if (canFreezeBounds()) {
857 freezeBounds();
858 }
Robert Carrd5c7dd62017-03-08 10:39:30 -0800859
860 // In the process of tearing down before relaunching, the app will
861 // try and clean up it's child surfaces. We need to prevent this from
862 // happening, so we sever the children, transfering their ownership
863 // from the client it-self to the parent surface (owned by us).
864 for (int i = mChildren.size() - 1; i >= 0; i--) {
865 final WindowState w = mChildren.get(i);
866 w.mWinAnimator.detachChildren();
867 }
868
Chong Zhangd78ddb42016-03-02 17:01:14 -0800869 mPendingRelaunchCount++;
870 }
871
872 void finishRelaunching() {
873 if (canFreezeBounds()) {
874 unfreezeBounds();
875 }
876 if (mPendingRelaunchCount > 0) {
877 mPendingRelaunchCount--;
878 }
879 }
880
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700881 void clearRelaunching() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700882 if (mPendingRelaunchCount == 0) {
883 return;
884 }
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700885 if (canFreezeBounds()) {
886 unfreezeBounds();
887 }
888 mPendingRelaunchCount = 0;
889 }
890
Wale Ogunwale07bcab72016-10-14 15:30:09 -0700891 /**
892 * Returns true if the new child window we are adding to this token is considered greater than
893 * the existing child window in this token in terms of z-order.
894 */
895 @Override
896 protected boolean isFirstChildWindowGreaterThanSecond(WindowState newWindow,
897 WindowState existingWindow) {
898 final int type1 = newWindow.mAttrs.type;
899 final int type2 = existingWindow.mAttrs.type;
900
901 // Base application windows should be z-ordered BELOW all other windows in the app token.
902 if (type1 == TYPE_BASE_APPLICATION && type2 != TYPE_BASE_APPLICATION) {
903 return false;
904 } else if (type1 != TYPE_BASE_APPLICATION && type2 == TYPE_BASE_APPLICATION) {
905 return true;
906 }
907
908 // Starting windows should be z-ordered ABOVE all other windows in the app token.
909 if (type1 == TYPE_APPLICATION_STARTING && type2 != TYPE_APPLICATION_STARTING) {
910 return true;
911 } else if (type1 != TYPE_APPLICATION_STARTING && type2 == TYPE_APPLICATION_STARTING) {
912 return false;
913 }
914
915 // Otherwise the new window is greater than the existing window.
916 return true;
917 }
918
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700919 @Override
Robert Carra1eb4392015-12-10 12:43:51 -0800920 void addWindow(WindowState w) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700921 super.addWindow(w);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700922
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700923 boolean gotReplacementWindow = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700924 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700925 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700926 gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w);
927 }
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700928
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700929 // if we got a replacement window, reset the timeout to give drawing more time
930 if (gotReplacementWindow) {
931 mService.scheduleWindowReplacementTimeouts(this);
Robert Carra1eb4392015-12-10 12:43:51 -0800932 }
Jorim Jaggife762342016-10-13 14:33:27 +0200933 checkKeyguardFlagsChanged();
934 }
935
936 @Override
937 void removeChild(WindowState child) {
938 super.removeChild(child);
939 checkKeyguardFlagsChanged();
Robert Carra1eb4392015-12-10 12:43:51 -0800940 }
941
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700942 private boolean waitingForReplacement() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700943 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700944 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700945 if (candidate.waitingForReplacement()) {
Robert Carra1eb4392015-12-10 12:43:51 -0800946 return true;
947 }
948 }
949 return false;
950 }
951
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700952 void onWindowReplacementTimeout() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700953 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700954 (mChildren.get(i)).onWindowReplacementTimeout();
Robert Carra1eb4392015-12-10 12:43:51 -0800955 }
956 }
957
Winson Chung30480042017-01-26 10:55:34 -0800958 void reparent(Task task, int position) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800959 final Task currentTask = getTask();
960 if (task == currentTask) {
Winson Chung30480042017-01-26 10:55:34 -0800961 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800962 "window token=" + this + " already child of task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -0800963 }
Bryce Lee6d410262017-02-28 15:30:17 -0800964
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800965 if (currentTask.mStack != task.mStack) {
Bryce Lee6d410262017-02-28 15:30:17 -0800966 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800967 "window token=" + this + " current task=" + currentTask
Bryce Lee6d410262017-02-28 15:30:17 -0800968 + " belongs to a different stack than " + task);
969 }
970
Winson Chung30480042017-01-26 10:55:34 -0800971 if (DEBUG_ADD_REMOVE) Slog.i(TAG, "reParentWindowToken: removing window token=" + this
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800972 + " from task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -0800973 final DisplayContent prevDisplayContent = getDisplayContent();
974
Bryce Lee6d410262017-02-28 15:30:17 -0800975 mReparenting = true;
976
Winson Chung30480042017-01-26 10:55:34 -0800977 getParent().removeChild(this);
978 task.addChild(this, position);
979
Bryce Lee6d410262017-02-28 15:30:17 -0800980 mReparenting = false;
981
Winson Chung30480042017-01-26 10:55:34 -0800982 // Relayout display(s).
983 final DisplayContent displayContent = task.getDisplayContent();
984 displayContent.setLayoutNeeded();
985 if (prevDisplayContent != displayContent) {
986 onDisplayChanged(displayContent);
987 prevDisplayContent.setLayoutNeeded();
988 }
989 }
990
Chong Zhangd78ddb42016-03-02 17:01:14 -0800991 private boolean canFreezeBounds() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800992 final Task task = getTask();
993
Chong Zhangd78ddb42016-03-02 17:01:14 -0800994 // For freeform windows, we can't freeze the bounds at the moment because this would make
995 // the resizing unresponsive.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800996 return task != null && !task.inFreeformWorkspace();
Chong Zhangd78ddb42016-03-02 17:01:14 -0800997 }
998
Jorim Jaggi0429f352015-12-22 16:29:16 +0100999 /**
1000 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
1001 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
1002 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
1003 * with a queue.
1004 */
Chong Zhangd78ddb42016-03-02 17:01:14 -08001005 private void freezeBounds() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001006 final Task task = getTask();
1007 mFrozenBounds.offer(new Rect(task.mPreparedFrozenBounds));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001008
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001009 if (task.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) {
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001010 // We didn't call prepareFreezingBounds on the task, so use the current value.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001011 mFrozenMergedConfig.offer(new Configuration(task.getConfiguration()));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001012 } else {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001013 mFrozenMergedConfig.offer(new Configuration(task.mPreparedFrozenMergedConfig));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001014 }
Andrii Kulianb10330d2016-09-16 13:51:46 -07001015 // Calling unset() to make it equal to Configuration.EMPTY.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001016 task.mPreparedFrozenMergedConfig.unset();
Jorim Jaggi0429f352015-12-22 16:29:16 +01001017 }
1018
1019 /**
1020 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
1021 */
Chong Zhangd78ddb42016-03-02 17:01:14 -08001022 private void unfreezeBounds() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -07001023 if (!mFrozenBounds.isEmpty()) {
1024 mFrozenBounds.remove();
1025 }
1026 if (!mFrozenMergedConfig.isEmpty()) {
1027 mFrozenMergedConfig.remove();
1028 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001029 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001030 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001031 win.onUnfreezeBounds();
Jorim Jaggi4846ee32016-01-07 17:39:12 +01001032 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001033 mService.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +01001034 }
1035
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001036 void setAppLayoutChanges(int changes, String reason) {
1037 if (!mChildren.isEmpty()) {
1038 final DisplayContent dc = getDisplayContent();
1039 dc.pendingLayoutChanges |= changes;
1040 if (DEBUG_LAYOUT_REPEATS) {
1041 mService.mWindowPlacerLocked.debugLayoutRepeats(reason, dc.pendingLayoutChanges);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001042 }
1043 }
1044 }
1045
1046 void removeReplacedWindowIfNeeded(WindowState replacement) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001047 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001048 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001049 if (win.removeReplacedWindowIfNeeded(replacement)) {
1050 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001051 }
1052 }
1053 }
1054
1055 void startFreezingScreen() {
1056 if (DEBUG_ORIENTATION) logWithStack(TAG, "Set freezing of " + appToken + ": hidden="
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001057 + hidden + " freezing=" + mAppAnimator.freezingScreen + " hiddenRequested="
1058 + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001059 if (!hiddenRequested) {
1060 if (!mAppAnimator.freezingScreen) {
1061 mAppAnimator.freezingScreen = true;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001062 mService.registerAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001063 mAppAnimator.lastFreezeDuration = 0;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001064 mService.mAppsFreezingScreen++;
1065 if (mService.mAppsFreezingScreen == 1) {
1066 mService.startFreezingDisplayLocked(false, 0, 0);
1067 mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT);
1068 mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001069 }
1070 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001071 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001072 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001073 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001074 w.onStartFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001075 }
1076 }
1077 }
1078
1079 void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) {
1080 if (!mAppAnimator.freezingScreen) {
1081 return;
1082 }
1083 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + this + " force=" + force);
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001084 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001085 boolean unfrozeWindows = false;
1086 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001087 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001088 unfrozeWindows |= w.onStopFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001089 }
1090 if (force || unfrozeWindows) {
1091 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this);
1092 mAppAnimator.freezingScreen = false;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001093 mService.unregisterAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001094 mAppAnimator.lastFreezeDuration =
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001095 (int)(SystemClock.elapsedRealtime() - mService.mDisplayFreezeTime);
1096 mService.mAppsFreezingScreen--;
1097 mService.mLastFinishedFreezeSource = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001098 }
1099 if (unfreezeSurfaceNow) {
1100 if (unfrozeWindows) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001101 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001102 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001103 mService.stopFreezingDisplayLocked();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001104 }
1105 }
1106
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001107 @Override
1108 public void onAppFreezeTimeout() {
1109 Slog.w(TAG_WM, "Force clearing freeze: " + this);
1110 stopFreezingScreen(true, true);
1111 }
1112
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001113 boolean transferStartingWindow(IBinder transferFrom) {
Wale Ogunwale02319a62016-09-26 15:21:22 -07001114 final AppWindowToken fromToken = getDisplayContent().getAppWindowToken(transferFrom);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001115 if (fromToken == null) {
1116 return false;
1117 }
1118
1119 final WindowState tStartingWindow = fromToken.startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001120 if (tStartingWindow != null && fromToken.startingSurface != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001121 // In this case, the starting icon has already been displayed, so start
1122 // letting windows get shown immediately without any more transitions.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001123 mService.mSkipAppTransitionAnimation = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001124
1125 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow
1126 + " from " + fromToken + " to " + this);
1127
1128 final long origId = Binder.clearCallingIdentity();
1129
1130 // Transfer the starting window over to the new token.
1131 startingData = fromToken.startingData;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001132 startingSurface = fromToken.startingSurface;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001133 startingDisplayed = fromToken.startingDisplayed;
1134 fromToken.startingDisplayed = false;
1135 startingWindow = tStartingWindow;
1136 reportedVisible = fromToken.reportedVisible;
1137 fromToken.startingData = null;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001138 fromToken.startingSurface = null;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001139 fromToken.startingWindow = null;
1140 fromToken.startingMoved = true;
1141 tStartingWindow.mToken = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001142 tStartingWindow.mAppToken = this;
1143
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001144 if (DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001145 "Removing starting " + tStartingWindow + " from " + fromToken);
Wale Ogunwalefa854eb2016-09-20 13:43:52 -07001146 fromToken.removeChild(tStartingWindow);
1147 fromToken.postWindowRemoveStartingWindowCleanup(tStartingWindow);
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001148 addWindow(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001149
1150 // Propagate other interesting state between the tokens. If the old token is displayed,
1151 // we should immediately force the new one to be displayed. If it is animating, we need
1152 // to move that animation to the new one.
1153 if (fromToken.allDrawn) {
1154 allDrawn = true;
1155 deferClearAllDrawn = fromToken.deferClearAllDrawn;
1156 }
1157 if (fromToken.firstWindowDrawn) {
1158 firstWindowDrawn = true;
1159 }
1160 if (!fromToken.hidden) {
1161 hidden = false;
1162 hiddenRequested = false;
1163 }
1164 if (clientHidden != fromToken.clientHidden) {
1165 clientHidden = fromToken.clientHidden;
1166 sendAppVisibilityToClients();
1167 }
1168 fromToken.mAppAnimator.transferCurrentAnimation(
1169 mAppAnimator, tStartingWindow.mWinAnimator);
1170
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001171 mService.updateFocusedWindowLocked(
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001172 UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/);
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001173 getDisplayContent().setLayoutNeeded();
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001174 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001175 Binder.restoreCallingIdentity(origId);
1176 return true;
1177 } else if (fromToken.startingData != null) {
1178 // The previous app was getting ready to show a
1179 // starting window, but hasn't yet done so. Steal it!
1180 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1181 "Moving pending starting from " + fromToken + " to " + this);
1182 startingData = fromToken.startingData;
1183 fromToken.startingData = null;
1184 fromToken.startingMoved = true;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001185 if (getController() != null) {
1186 getController().scheduleAddStartingWindow();
1187 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001188 return true;
1189 }
1190
1191 final AppWindowAnimator tAppAnimator = fromToken.mAppAnimator;
1192 final AppWindowAnimator wAppAnimator = mAppAnimator;
1193 if (tAppAnimator.thumbnail != null) {
1194 // The old token is animating with a thumbnail, transfer that to the new token.
1195 if (wAppAnimator.thumbnail != null) {
1196 wAppAnimator.thumbnail.destroy();
1197 }
1198 wAppAnimator.thumbnail = tAppAnimator.thumbnail;
1199 wAppAnimator.thumbnailLayer = tAppAnimator.thumbnailLayer;
1200 wAppAnimator.thumbnailAnimation = tAppAnimator.thumbnailAnimation;
1201 tAppAnimator.thumbnail = null;
1202 }
1203 return false;
1204 }
1205
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001206 boolean isLastWindow(WindowState win) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001207 return mChildren.size() == 1 && mChildren.get(0) == win;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001208 }
1209
1210 void setAllAppWinAnimators() {
1211 final ArrayList<WindowStateAnimator> allAppWinAnimators = mAppAnimator.mAllAppWinAnimators;
1212 allAppWinAnimators.clear();
1213
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001214 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001215 for (int j = 0; j < windowsCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001216 (mChildren.get(j)).addWinAnimatorToList(allAppWinAnimators);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001217 }
1218 }
1219
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001220 @Override
1221 void onAppTransitionDone() {
1222 sendingToBottom = false;
1223 }
1224
Wale Ogunwale51362492016-09-08 17:49:17 -07001225 /**
1226 * We override because this class doesn't want its children affecting its reported orientation
1227 * in anyway.
1228 */
1229 @Override
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001230 int getOrientation(int candidate) {
1231 if (!fillsParent()) {
1232 // Can't specify orientation if app doesn't fill parent.
1233 return SCREEN_ORIENTATION_UNSET;
1234 }
1235
1236 if (candidate == SCREEN_ORIENTATION_BEHIND) {
1237 // Allow app to specify orientation regardless of its visibility state if the current
1238 // candidate want us to use orientation behind. I.e. the visible app on-top of this one
1239 // wants us to use the orientation of the app behind it.
1240 return mOrientation;
1241 }
1242
Bryce Lee61fbcbc2017-03-10 14:14:03 -08001243 // The {@link AppWindowToken} should only specify an orientation when it is not closing or
1244 // going to the bottom. Allowing closing {@link AppWindowToken} to participate can lead to
1245 // an Activity in another task being started in the wrong orientation during the transition.
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001246 if (!(sendingToBottom || mService.mClosingApps.contains(this))
Bryce Lee61fbcbc2017-03-10 14:14:03 -08001247 && (isVisible() || mService.mOpeningApps.contains(this))) {
Bryce Leea163b762017-01-24 11:05:01 -08001248 return mOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001249 }
Bryce Leea163b762017-01-24 11:05:01 -08001250
1251 return SCREEN_ORIENTATION_UNSET;
Wale Ogunwale51362492016-09-08 17:49:17 -07001252 }
1253
Wale Ogunwaleb198b742016-12-01 08:44:09 -08001254 /** Returns the app's preferred orientation regardless of its currently visibility state. */
1255 int getOrientationIgnoreVisibility() {
1256 return mOrientation;
1257 }
1258
Craig Mautnerdbb79912012-03-01 18:59:14 -08001259 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001260 void checkAppWindowsReadyToShow() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001261 if (allDrawn == mAppAnimator.allDrawn) {
1262 return;
1263 }
1264
1265 mAppAnimator.allDrawn = allDrawn;
1266 if (!allDrawn) {
1267 return;
1268 }
1269
1270 // The token has now changed state to having all windows shown... what to do, what to do?
1271 if (mAppAnimator.freezingScreen) {
1272 mAppAnimator.showAllWindowsLocked();
1273 stopFreezingScreen(false, true);
1274 if (DEBUG_ORIENTATION) Slog.i(TAG,
1275 "Setting mOrientationChangeComplete=true because wtoken " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001276 + " numInteresting=" + mNumInterestingWindows + " numDrawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001277 // This will set mOrientationChangeComplete and cause a pass through layout.
1278 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001279 "checkAppWindowsReadyToShow: freezingScreen");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001280 } else {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001281 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001282
1283 // We can now show all of the drawn windows!
1284 if (!mService.mOpeningApps.contains(this)) {
1285 mService.mAnimator.orAnimating(mAppAnimator.showAllWindowsLocked());
1286 }
1287 }
1288 }
1289
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001290 void updateAllDrawn(DisplayContent dc) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001291 if (!allDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001292 final int numInteresting = mNumInterestingWindows;
1293 if (numInteresting > 0 && mNumDrawnWindows >= numInteresting) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001294 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawn: " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001295 + " interesting=" + numInteresting + " drawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001296 allDrawn = true;
1297 // Force an additional layout pass where
1298 // WindowStateAnimator#commitFinishDrawingLocked() will call performShowLocked().
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001299 dc.setLayoutNeeded();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001300 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Robert Carrecc06b32017-04-18 14:25:10 -07001301
1302 final TaskStack s = getStack();
1303 if (s != null) {
1304 s.onAllWindowsDrawn();
1305 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001306 }
1307 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001308
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001309 if (!allDrawnExcludingSaved) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001310 int numInteresting = mNumInterestingWindowsExcludingSaved;
1311 if (numInteresting > 0 && mNumDrawnWindowsExcludingSaved >= numInteresting) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001312 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawnExcludingSaved: " + this
1313 + " interesting=" + numInteresting
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001314 + " drawn=" + mNumDrawnWindowsExcludingSaved);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001315 allDrawnExcludingSaved = true;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001316 dc.setLayoutNeeded();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001317 if (isAnimatingInvisibleWithSavedSurface()
1318 && !mService.mFinishedEarlyAnim.contains(this)) {
1319 mService.mFinishedEarlyAnim.add(this);
1320 }
1321 }
1322 }
1323 }
1324
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001325 /**
1326 * Updated this app token tracking states for interesting and drawn windows based on the window.
1327 *
1328 * @return Returns true if the input window is considered interesting and drawn while all the
1329 * windows in this app token where not considered drawn as of the last pass.
1330 */
1331 boolean updateDrawnWindowStates(WindowState w) {
1332 if (DEBUG_STARTING_WINDOW && w == startingWindow) {
1333 Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" + w.isOnScreen()
1334 + " allDrawn=" + allDrawn + " freezingScreen=" + mAppAnimator.freezingScreen);
1335 }
1336
1337 if (allDrawn && allDrawnExcludingSaved && !mAppAnimator.freezingScreen) {
1338 return false;
1339 }
1340
1341 if (mLastTransactionSequence != mService.mTransactionSequence) {
1342 mLastTransactionSequence = mService.mTransactionSequence;
1343 mNumInterestingWindows = mNumDrawnWindows = 0;
1344 mNumInterestingWindowsExcludingSaved = 0;
1345 mNumDrawnWindowsExcludingSaved = 0;
1346 startingDisplayed = false;
1347 }
1348
1349 final WindowStateAnimator winAnimator = w.mWinAnimator;
1350
1351 boolean isInterestingAndDrawn = false;
1352
1353 if (!allDrawn && w.mightAffectAllDrawn(false /* visibleOnly */)) {
1354 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
1355 Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw()
1356 + ", isAnimationSet=" + winAnimator.isAnimationSet());
1357 if (!w.isDrawnLw()) {
1358 Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController
1359 + " pv=" + w.mPolicyVisibility
1360 + " mDrawState=" + winAnimator.drawStateToString()
1361 + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested
1362 + " a=" + winAnimator.mAnimating);
1363 }
1364 }
1365
1366 if (w != startingWindow) {
1367 if (w.isInteresting()) {
1368 mNumInterestingWindows++;
1369 if (w.isDrawnLw()) {
1370 mNumDrawnWindows++;
1371
1372 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, "tokenMayBeDrawn: "
1373 + this + " w=" + w + " numInteresting=" + mNumInterestingWindows
1374 + " freezingScreen=" + mAppAnimator.freezingScreen
1375 + " mAppFreezing=" + w.mAppFreezing);
1376
1377 isInterestingAndDrawn = true;
1378 }
1379 }
1380 } else if (w.isDrawnLw()) {
Jorim Jaggi3878ca32017-02-02 17:13:05 -08001381 if (getController() != null) {
1382 getController().reportStartingWindowDrawn();
1383 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001384 startingDisplayed = true;
1385 }
1386 }
1387
1388 if (!allDrawnExcludingSaved && w.mightAffectAllDrawn(true /* visibleOnly */)) {
1389 if (w != startingWindow && w.isInteresting()) {
1390 mNumInterestingWindowsExcludingSaved++;
1391 if (w.isDrawnLw() && !w.isAnimatingWithSavedSurface()) {
1392 mNumDrawnWindowsExcludingSaved++;
1393
1394 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
1395 "tokenMayBeDrawnExcludingSaved: " + this + " w=" + w
1396 + " numInteresting=" + mNumInterestingWindowsExcludingSaved
1397 + " freezingScreen=" + mAppAnimator.freezingScreen
1398 + " mAppFreezing=" + w.mAppFreezing);
1399
1400 isInterestingAndDrawn = true;
1401 }
1402 }
1403 }
1404
1405 return isInterestingAndDrawn;
1406 }
1407
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001408 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001409 void stepAppWindowsAnimation(long currentTime) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001410 mAppAnimator.wasAnimating = mAppAnimator.animating;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001411 if (mAppAnimator.stepAnimationLocked(currentTime)) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001412 mAppAnimator.animating = true;
1413 mService.mAnimator.setAnimating(true);
1414 mService.mAnimator.mAppWindowAnimating = true;
1415 } else if (mAppAnimator.wasAnimating) {
1416 // stopped animating, do one more pass through the layout
Wale Ogunwale1e129a42016-11-21 13:03:47 -08001417 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
1418 DEBUG_LAYOUT_REPEATS ? "appToken " + this + " done" : null);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001419 if (DEBUG_ANIM) Slog.v(TAG, "updateWindowsApps...: done animating " + this);
1420 }
1421 }
1422
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001423 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001424 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001425 // For legacy reasons we process the TaskStack.mExitingAppTokens first in DisplayContent
1426 // before the non-exiting app tokens. So, we skip the exiting app tokens here.
1427 // TODO: Investigate if we need to continue to do this or if we can just process them
1428 // in-order.
1429 if (mIsExiting && !waitingForReplacement()) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001430 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001431 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001432 return forAllWindowsUnchecked(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001433 }
1434
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001435 boolean forAllWindowsUnchecked(ToBooleanFunction<WindowState> callback,
1436 boolean traverseTopToBottom) {
1437 return super.forAllWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001438 }
1439
1440 @Override
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001441 AppWindowToken asAppWindowToken() {
1442 // I am an app window token!
1443 return this;
1444 }
1445
1446 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -07001447 boolean fillsParent() {
1448 return mFillsParent;
1449 }
1450
1451 void setFillsParent(boolean fillsParent) {
1452 mFillsParent = fillsParent;
1453 }
1454
Jorim Jaggife762342016-10-13 14:33:27 +02001455 boolean containsDismissKeyguardWindow() {
1456 for (int i = mChildren.size() - 1; i >= 0; i--) {
1457 if ((mChildren.get(i).mAttrs.flags & FLAG_DISMISS_KEYGUARD) != 0) {
1458 return true;
1459 }
1460 }
1461 return false;
1462 }
1463
1464 boolean containsShowWhenLockedWindow() {
1465 for (int i = mChildren.size() - 1; i >= 0; i--) {
1466 if ((mChildren.get(i).mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
1467 return true;
1468 }
1469 }
1470 return false;
1471 }
1472
1473 void checkKeyguardFlagsChanged() {
1474 final boolean containsDismissKeyguard = containsDismissKeyguardWindow();
1475 final boolean containsShowWhenLocked = containsShowWhenLockedWindow();
1476 if (containsDismissKeyguard != mLastContainsDismissKeyguardWindow
1477 || containsShowWhenLocked != mLastContainsShowWhenLockedWindow) {
1478 mService.notifyKeyguardFlagsChanged(null /* callback */);
1479 }
1480 mLastContainsDismissKeyguardWindow = containsDismissKeyguard;
1481 mLastContainsShowWhenLockedWindow = containsShowWhenLocked;
1482 }
1483
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001484 WindowState getImeTargetBelowWindow(WindowState w) {
1485 final int index = mChildren.indexOf(w);
1486 if (index > 0) {
1487 final WindowState target = mChildren.get(index - 1);
1488 if (target.canBeImeTarget()) {
1489 return target;
1490 }
1491 }
1492 return null;
1493 }
1494
1495 WindowState getHighestAnimLayerWindow(WindowState currentTarget) {
1496 WindowState candidate = null;
1497 for (int i = mChildren.indexOf(currentTarget); i >= 0; i--) {
1498 final WindowState w = mChildren.get(i);
1499 if (w.mRemoved) {
1500 continue;
1501 }
1502 if (candidate == null || w.mWinAnimator.mAnimLayer >
1503 candidate.mWinAnimator.mAnimLayer) {
1504 candidate = w;
1505 }
1506 }
1507 return candidate;
1508 }
1509
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001510 void setDisablePreviewSnapshots(boolean disable) {
1511 mDisbalePreviewScreenshots = disable;
1512 }
1513
1514 boolean shouldDisablePreviewScreenshots() {
1515 return mDisbalePreviewScreenshots;
1516 }
1517
Wale Ogunwale51362492016-09-08 17:49:17 -07001518 @Override
Robert Carrdee1b3f2017-02-27 11:33:33 -08001519 int getAnimLayerAdjustment() {
1520 return mAppAnimator.animLayerAdjustment;
1521 }
1522
1523 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001524 void dump(PrintWriter pw, String prefix) {
1525 super.dump(pw, prefix);
1526 if (appToken != null) {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001527 pw.println(prefix + "app=true mVoiceInteraction=" + mVoiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001528 }
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001529 pw.print(prefix); pw.print("task="); pw.println(getTask());
Wale Ogunwale51362492016-09-08 17:49:17 -07001530 pw.print(prefix); pw.print(" mFillsParent="); pw.print(mFillsParent);
1531 pw.print(" mOrientation="); pw.println(mOrientation);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001532 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
1533 pw.print(" clientHidden="); pw.print(clientHidden);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -07001534 pw.print(" reportedDrawn="); pw.print(reportedDrawn);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001535 pw.print(" reportedVisible="); pw.println(reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -07001536 if (paused) {
1537 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001538 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001539 if (mAppStopped) {
1540 pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped);
1541 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001542 if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0
Craig Mautner6fbda632012-07-03 09:26:39 -07001543 || allDrawn || mAppAnimator.allDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001544 pw.print(prefix); pw.print("mNumInterestingWindows=");
1545 pw.print(mNumInterestingWindows);
1546 pw.print(" mNumDrawnWindows="); pw.print(mNumDrawnWindows);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001547 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -07001548 pw.print(" allDrawn="); pw.print(allDrawn);
1549 pw.print(" (animator="); pw.print(mAppAnimator.allDrawn);
1550 pw.println(")");
1551 }
1552 if (inPendingTransaction) {
1553 pw.print(prefix); pw.print("inPendingTransaction=");
1554 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001555 }
Craig Mautner799bc1d2015-01-14 10:33:48 -08001556 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001557 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
1558 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -08001559 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -08001560 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001561 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001562 if (startingWindow != null || startingSurface != null
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001563 || startingDisplayed || startingMoved) {
1564 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001565 pw.print(" startingSurface="); pw.print(startingSurface);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001566 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001567 pw.print(" startingMoved="); pw.println(startingMoved);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001568 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01001569 if (!mFrozenBounds.isEmpty()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -08001570 pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds);
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001571 pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig);
Chong Zhangd78ddb42016-03-02 17:01:14 -08001572 }
1573 if (mPendingRelaunchCount != 0) {
1574 pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount);
Jorim Jaggi0429f352015-12-22 16:29:16 +01001575 }
Wale Ogunwale9c64cb62017-04-12 13:39:59 -07001576 if (getController() != null) {
1577 pw.print(prefix); pw.print("controller="); pw.println(getController());
1578 }
Wale Ogunwalee287e192017-04-21 09:30:12 -07001579 if (mRemovingFromDisplay) {
1580 pw.println(prefix + "mRemovingFromDisplay=" + mRemovingFromDisplay);
1581 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001582 }
1583
1584 @Override
1585 public String toString() {
1586 if (stringName == null) {
1587 StringBuilder sb = new StringBuilder();
1588 sb.append("AppWindowToken{");
1589 sb.append(Integer.toHexString(System.identityHashCode(this)));
1590 sb.append(" token="); sb.append(token); sb.append('}');
1591 stringName = sb.toString();
1592 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001593 return stringName + ((mIsExiting) ? " mIsExiting=" : "");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001594 }
Jeff Browne9bdb312012-04-05 15:30:10 -07001595}