blob: 5b398f9502366f842ad081c19257b03cc5865987 [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;
Jorim Jaggid635a4a2017-05-03 15:21:26 +020026import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
Jorim Jaggife762342016-10-13 14:33:27 +020027import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
Wale Ogunwaled1c37912016-08-16 03:19:39 -070028import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080029import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070030import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -070031import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
32import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070033import static com.android.server.wm.AppTransition.TRANSIT_UNSET;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080034import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080035import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
36import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070037import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070038import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
39import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
Wale Ogunwale9017ec02016-02-25 08:55:25 -080040import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070041import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TOKEN_MOVEMENT;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080042import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
43import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_MOVEMENT;
44import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
45import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Chong Zhang92147042016-05-09 12:47:11 -070046import static com.android.server.wm.WindowManagerService.H.NOTIFY_ACTIVITY_DRAWN;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070047import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070048import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070049import static com.android.server.wm.WindowManagerService.logWithStack;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080050
Filip Gruszczynskia590c992015-11-25 16:45:26 -080051import android.annotation.NonNull;
Jorim Jaggid635a4a2017-05-03 15:21:26 +020052import android.app.Activity;
Jorim Jaggi26c8c422016-05-09 19:57:25 -070053import android.content.res.Configuration;
Jorim Jaggi0429f352015-12-22 16:29:16 +010054import android.graphics.Rect;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070055import android.os.Binder;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080056import android.os.Debug;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070057import android.os.IBinder;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070058import android.os.SystemClock;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080059import android.util.Slog;
60import android.view.IApplicationToken;
Robert Carr6914f082017-03-20 19:04:30 -070061import android.view.SurfaceControl;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080062import android.view.WindowManager;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080063import android.view.WindowManagerPolicy.StartingSurface;
64
65import com.android.internal.util.ToBooleanFunction;
66import com.android.server.input.InputApplicationHandle;
67import com.android.server.wm.WindowManagerService.H;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080068
69import java.io.PrintWriter;
Jorim Jaggi0429f352015-12-22 16:29:16 +010070import java.util.ArrayDeque;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080071import java.util.ArrayList;
72
73class AppTokenList extends ArrayList<AppWindowToken> {
74}
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080075
76/**
77 * Version of WindowToken that is specifically for a particular application (or
78 * really activity) that is displaying windows.
79 */
Wale Ogunwale3f4433d2016-08-18 20:42:42 -070080class AppWindowToken extends WindowToken implements WindowManagerService.AppFreezeListener {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080081 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppWindowToken" : TAG_WM;
82
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080083 // Non-null only for application tokens.
84 final IApplicationToken appToken;
85
Filip Gruszczynskia590c992015-11-25 16:45:26 -080086 @NonNull final AppWindowAnimator mAppAnimator;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -070087
Wale Ogunwale72919d22016-12-08 18:58:50 -080088 final boolean mVoiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -070089
Wale Ogunwale51362492016-09-08 17:49:17 -070090 /** @see WindowContainer#fillsParent() */
91 private boolean mFillsParent;
Craig Mautner4c5eb222013-11-18 12:59:05 -080092 boolean layoutConfigChanges;
Wale Ogunwale72919d22016-12-08 18:58:50 -080093 boolean mShowForAllUsers;
94 int mTargetSdk;
Craig Mautnera2c77052012-03-26 12:14:43 -070095
Bryce Lee6d410262017-02-28 15:30:17 -080096 // Flag set while reparenting to prevent actions normally triggered by an individual parent
97 // change.
98 private boolean mReparenting;
99
Wale Ogunwalee287e192017-04-21 09:30:12 -0700100 // True if we are current in the process of removing this app token from the display
101 private boolean mRemovingFromDisplay = false;
102
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800103 // The input dispatching timeout for this application token in nanoseconds.
Wale Ogunwale72919d22016-12-08 18:58:50 -0800104 long mInputDispatchingTimeoutNanos;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800105
106 // These are used for determining when all windows associated with
107 // an activity have been drawn, so they can be made visible together
108 // at the same time.
Craig Mautner764983d2012-03-22 11:37:36 -0700109 // initialize so that it doesn't match mTransactionSequence which is an int.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700110 private long mLastTransactionSequence = Long.MIN_VALUE;
111 private int mNumInterestingWindows;
112 private int mNumDrawnWindows;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800113 boolean inPendingTransaction;
114 boolean allDrawn;
Craig Mautner7636dfb2012-11-16 15:24:11 -0800115 // Set to true when this app creates a surface while in the middle of an animation. In that
116 // case do not clear allDrawn until the animation completes.
117 boolean deferClearAllDrawn;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800118
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700119 /**
120 * These are to track the app's real drawing status if there were no saved surfaces.
121 * @see #updateDrawnWindowStates
122 */
Chong Zhang8e4bda92016-05-04 15:08:18 -0700123 boolean allDrawnExcludingSaved;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700124 private int mNumInterestingWindowsExcludingSaved;
125 private int mNumDrawnWindowsExcludingSaved;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700126
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800127 // Is this window's surface needed? This is almost like hidden, except
128 // it will sometimes be true a little earlier: when the token has
129 // been shown, but is still waiting for its app transition to execute
130 // before making its windows shown.
131 boolean hiddenRequested;
132
133 // Have we told the window clients to hide themselves?
Wale Ogunwale89973222017-04-23 18:39:45 -0700134 private boolean mClientHidden;
135
136 // If true we will defer setting mClientHidden to true and reporting to the client that it is
137 // hidden.
138 boolean mDeferHidingClient;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800139
140 // Last visibility state we reported to the app token.
141 boolean reportedVisible;
142
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700143 // Last drawn state we reported to the app token.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700144 private boolean reportedDrawn;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700145
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800146 // Set to true when the token has been removed from the window mgr.
147 boolean removed;
148
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800149 // Information about an application starting window if displayed.
150 StartingData startingData;
151 WindowState startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800152 StartingSurface startingSurface;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800153 boolean startingDisplayed;
154 boolean startingMoved;
155 boolean firstWindowDrawn;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700156 private final WindowState.UpdateReportedVisibilityResults mReportedVisibilityResults =
157 new WindowState.UpdateReportedVisibilityResults();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800158
159 // Input application handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700160 final InputApplicationHandle mInputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800161
Wale Ogunwale571771c2016-08-26 13:18:50 -0700162 // TODO: Have a WindowContainer state for tracking exiting/deferred removal.
Craig Mautner799bc1d2015-01-14 10:33:48 -0800163 boolean mIsExiting;
Craig Mautner9ef471f2014-02-07 13:11:47 -0800164
Craig Mautnerbb742462014-07-07 15:28:55 -0700165 boolean mLaunchTaskBehind;
Craig Mautner8746a472014-07-24 15:12:54 -0700166 boolean mEnteringAnimation;
Craig Mautnerbb742462014-07-07 15:28:55 -0700167
Wale Ogunwale72919d22016-12-08 18:58:50 -0800168 private boolean mAlwaysFocusable;
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800169
Robert Carre12aece2016-02-02 22:43:27 -0800170 boolean mAppStopped;
Robert Carrfd10cd12016-06-29 16:41:50 -0700171 int mRotationAnimationHint;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700172 private int mPendingRelaunchCount;
Robert Carre12aece2016-02-02 22:43:27 -0800173
Jorim Jaggife762342016-10-13 14:33:27 +0200174 private boolean mLastContainsShowWhenLockedWindow;
175 private boolean mLastContainsDismissKeyguardWindow;
176
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700177 // The bounds of this activity. Mainly used for aspect-ratio compatibility.
178 // TODO(b/36505427): Every level on WindowContainer now has bounds information, which directly
179 // affects the configuration. We should probably move this into that class.
180 private final Rect mBounds = new Rect();
181
Jorim Jaggi0429f352015-12-22 16:29:16 +0100182 ArrayDeque<Rect> mFrozenBounds = new ArrayDeque<>();
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700183 ArrayDeque<Configuration> mFrozenMergedConfig = new ArrayDeque<>();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100184
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +0100185 private boolean mDisbalePreviewScreenshots;
186
Robert Carred3e83b2017-04-21 13:26:55 -0700187 Task mLastParent;
188
Wale Ogunwale72919d22016-12-08 18:58:50 -0800189 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
190 DisplayContent dc, long inputDispatchingTimeoutNanos, boolean fullscreen,
191 boolean showForAllUsers, int targetSdk, int orientation, int rotationAnimationHint,
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800192 int configChanges, boolean launchTaskBehind, boolean alwaysFocusable,
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700193 AppWindowContainerController controller, Configuration overrideConfig, Rect bounds) {
194 this(service, token, voiceInteraction, dc, fullscreen, overrideConfig, bounds);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800195 setController(controller);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800196 mInputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800197 mShowForAllUsers = showForAllUsers;
198 mTargetSdk = targetSdk;
199 mOrientation = orientation;
200 layoutConfigChanges = (configChanges & (CONFIG_SCREEN_SIZE | CONFIG_ORIENTATION)) != 0;
201 mLaunchTaskBehind = launchTaskBehind;
202 mAlwaysFocusable = alwaysFocusable;
203 mRotationAnimationHint = rotationAnimationHint;
204
205 // Application tokens start out hidden.
206 hidden = true;
207 hiddenRequested = true;
208 }
209
210 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700211 DisplayContent dc, boolean fillsParent, Configuration overrideConfig, Rect bounds) {
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800212 super(service, token != null ? token.asBinder() : null, TYPE_APPLICATION, true, dc,
213 false /* ownerCanManageAppTokens */);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700214 appToken = token;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800215 mVoiceInteraction = voiceInteraction;
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800216 mFillsParent = fillsParent;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800217 mInputApplicationHandle = new InputApplicationHandle(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700218 mAppAnimator = new AppWindowAnimator(this, service);
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700219 if (overrideConfig != null) {
220 onOverrideConfigurationChanged(overrideConfig);
221 }
222 if (bounds != null) {
223 mBounds.set(bounds);
224 }
225 }
226
227 void onOverrideConfigurationChanged(Configuration overrideConfiguration, Rect bounds) {
228 onOverrideConfigurationChanged(overrideConfiguration);
229 if (mBounds.equals(bounds)) {
230 return;
231 }
232 // TODO(b/36505427): If bounds is in WC, then we can automatically call onResize() when set.
233 mBounds.set(bounds);
234 onResize();
235 }
236
237 void getBounds(Rect outBounds) {
238 outBounds.set(mBounds);
239 }
240
241 boolean hasBounds() {
242 return !mBounds.isEmpty();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800243 }
244
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800245 void onFirstWindowDrawn(WindowState win, WindowStateAnimator winAnimator) {
246 firstWindowDrawn = true;
247
248 // We now have a good window to show, remove dead placeholders
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700249 removeDeadWindows();
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800250
Jorim Jaggi02886a82016-12-06 09:10:06 -0800251 if (startingWindow != null) {
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800252 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, "Finish starting "
253 + win.mToken + ": first real window is shown, no animation");
254 // If this initial window is animating, stop it -- we will do an animation to reveal
255 // it from behind the starting window, so there is no need for it to also be doing its
256 // own stuff.
257 winAnimator.clearAnimation();
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800258 if (getController() != null) {
259 getController().removeStartingWindow();
260 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800261 }
262 updateReportedVisibilityLocked();
263 }
264
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800265 void updateReportedVisibilityLocked() {
266 if (appToken == null) {
267 return;
268 }
269
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700270 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700271 final int count = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800272
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700273 mReportedVisibilityResults.reset();
274
275 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700276 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700277 win.updateReportedVisibility(mReportedVisibilityResults);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800278 }
279
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700280 int numInteresting = mReportedVisibilityResults.numInteresting;
281 int numVisible = mReportedVisibilityResults.numVisible;
282 int numDrawn = mReportedVisibilityResults.numDrawn;
283 boolean nowGone = mReportedVisibilityResults.nowGone;
284
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700285 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800286 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700287 if (!nowGone) {
288 // If the app is not yet gone, then it can only become visible/drawn.
289 if (!nowDrawn) {
290 nowDrawn = reportedDrawn;
291 }
292 if (!nowVisible) {
293 nowVisible = reportedVisible;
294 }
295 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800296 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800297 + numInteresting + " visible=" + numVisible);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800298 final AppWindowContainerController controller = getController();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700299 if (nowDrawn != reportedDrawn) {
300 if (nowDrawn) {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800301 if (controller != null) {
302 controller.reportWindowsDrawn();
303 }
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700304 }
305 reportedDrawn = nowDrawn;
306 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800307 if (nowVisible != reportedVisible) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700308 if (DEBUG_VISIBILITY) Slog.v(TAG,
309 "Visibility changed in " + this + ": vis=" + nowVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800310 reportedVisible = nowVisible;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800311 if (controller != null) {
312 if (nowVisible) {
313 controller.reportWindowsVisible();
314 } else {
315 controller.reportWindowsGone();
316 }
317 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800318 }
319 }
320
Wale Ogunwale89973222017-04-23 18:39:45 -0700321 boolean isClientHidden() {
322 return mClientHidden;
323 }
324
325 void setClientHidden(boolean hideClient) {
326 if (mClientHidden == hideClient || (hideClient && mDeferHidingClient)) {
327 return;
328 }
329 mClientHidden = hideClient;
330 sendAppVisibilityToClients();
331 }
332
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700333 boolean setVisibility(WindowManager.LayoutParams lp,
334 boolean visible, int transit, boolean performLayout, boolean isVoiceInteraction) {
335
336 boolean delayed = false;
337 inPendingTransaction = false;
338
Wale Ogunwale89973222017-04-23 18:39:45 -0700339 setClientHidden(!visible);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700340
341 // Allow for state changes and animation to be applied if:
342 // * token is transitioning visibility state
343 // * or the token was marked as hidden and is exiting before we had a chance to play the
344 // transition animation
345 // * or this is an opening app and windows are being replaced.
346 boolean visibilityChanged = false;
347 if (hidden == visible || (hidden && mIsExiting) || (visible && waitingForReplacement())) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700348 final AccessibilityController accessibilityController = mService.mAccessibilityController;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700349 boolean changed = false;
350 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
351 "Changing app " + this + " hidden=" + hidden + " performLayout=" + performLayout);
352
353 boolean runningAppAnimation = false;
354
355 if (transit != AppTransition.TRANSIT_UNSET) {
356 if (mAppAnimator.animation == AppWindowAnimator.sDummyAnimation) {
357 mAppAnimator.setNullAnimation();
358 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700359 if (mService.applyAnimationLocked(this, lp, transit, visible, isVoiceInteraction)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700360 delayed = runningAppAnimation = true;
361 }
362 final WindowState window = findMainWindow();
363 //TODO (multidisplay): Magnification is supported only for the default display.
364 if (window != null && accessibilityController != null
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700365 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700366 accessibilityController.onAppWindowTransitionLocked(window, transit);
367 }
368 changed = true;
369 }
370
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700371 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700372 for (int i = 0; i < windowsCount; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700373 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700374 changed |= win.onAppVisibilityChanged(visible, runningAppAnimation);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700375 }
376
377 hidden = hiddenRequested = !visible;
378 visibilityChanged = true;
379 if (!visible) {
380 stopFreezingScreen(true, true);
381 } else {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700382 // If we are being set visible, and the starting window is not yet displayed,
383 // then make sure it doesn't get displayed.
384 if (startingWindow != null && !startingWindow.isDrawnLw()) {
385 startingWindow.mPolicyVisibility = false;
386 startingWindow.mPolicyVisibilityAfterAnim = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700387 }
388 }
389
390 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setVisibility: " + this
391 + ": hidden=" + hidden + " hiddenRequested=" + hiddenRequested);
392
393 if (changed) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700394 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700395 if (performLayout) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700396 mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700397 false /*updateInputWindows*/);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700398 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700399 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700400 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700401 }
402 }
403
404 if (mAppAnimator.animation != null) {
405 delayed = true;
406 }
407
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700408 for (int i = mChildren.size() - 1; i >= 0 && !delayed; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700409 if ((mChildren.get(i)).isWindowAnimationSet()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700410 delayed = true;
411 }
412 }
413
414 if (visibilityChanged) {
415 if (visible && !delayed) {
416 // The token was made immediately visible, there will be no entrance animation.
417 // We need to inform the client the enter animation was finished.
418 mEnteringAnimation = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700419 mService.mActivityManagerAppTransitionNotifier.onAppTransitionFinishedLocked(token);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700420 }
Robert Carre7cc44d2017-03-20 19:04:30 -0700421 // If we are hidden but there is no delay needed we immediately
422 // apply the Surface transaction so that the ActivityManager
423 // can have some guarantee on the Surface state
424 // following setting the visibility.
Robert Carr6914f082017-03-20 19:04:30 -0700425 if (hidden && !delayed) {
426 SurfaceControl.openTransaction();
427 for (int i = mChildren.size() - 1; i >= 0; i--) {
428 mChildren.get(i).mWinAnimator.hide("immediately hidden");
429 }
430 SurfaceControl.closeTransaction();
431 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700432
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700433 if (!mService.mClosingApps.contains(this) && !mService.mOpeningApps.contains(this)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700434 // The token is not closing nor opening, so even if there is an animation set, that
435 // doesn't mean that it goes through the normal app transition cycle so we have
436 // to inform the docked controller about visibility change.
Andrii Kulian1e32e022016-09-16 15:29:34 -0700437 // TODO(multi-display): notify docked divider on all displays where visibility was
438 // affected.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700439 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700440 .notifyAppVisibilityChanged();
Jorim Jaggi8b702ed2017-01-20 16:59:03 +0100441 mService.mTaskSnapshotController.notifyAppVisibilityChanged(this, visible);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700442 }
443 }
444
445 return delayed;
446 }
447
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800448 WindowState findMainWindow() {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700449 WindowState candidate = null;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700450 int j = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800451 while (j > 0) {
452 j--;
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700453 final WindowState win = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700454 final int type = win.mAttrs.type;
455 // No need to loop through child window as base application and starting types can't be
456 // child windows.
457 if (type == TYPE_BASE_APPLICATION || type == TYPE_APPLICATION_STARTING) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700458 // In cases where there are multiple windows, we prefer the non-exiting window. This
Sungsoo Lim0d3d1f82015-12-02 14:47:59 +0900459 // happens for example when replacing windows during an activity relaunch. When
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700460 // constructing the animation, we want the new window, not the exiting one.
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800461 if (win.mAnimatingExit) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700462 candidate = win;
463 } else {
464 return win;
465 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800466 }
467 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700468 return candidate;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800469 }
470
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800471 boolean windowsAreFocusable() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800472 return StackId.canReceiveKeys(getTask().mStack.mStackId) || mAlwaysFocusable;
Wale Ogunwaled045c822015-12-02 09:14:28 -0800473 }
474
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800475 AppWindowContainerController getController() {
476 final WindowContainerController controller = super.getController();
477 return controller != null ? (AppWindowContainerController) controller : null;
478 }
479
Wale Ogunwale571771c2016-08-26 13:18:50 -0700480 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -0700481 boolean isVisible() {
Wale Ogunwalee471be62016-10-03 07:53:55 -0700482 // If the app token isn't hidden then it is considered visible and there is no need to check
483 // its children windows to see if they are visible.
484 return !hidden;
Wale Ogunwale44f21802016-09-02 12:49:48 -0700485 }
486
487 @Override
Wale Ogunwalee287e192017-04-21 09:30:12 -0700488 void removeImmediately() {
489 onRemovedFromDisplay();
490 super.removeImmediately();
491 }
492
493 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -0700494 void removeIfPossible() {
Craig Mautnere3119b72015-01-20 15:02:36 -0800495 mIsExiting = false;
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800496 removeAllWindowsIfPossible();
Bryce Lee6d410262017-02-28 15:30:17 -0800497 removeImmediately();
Craig Mautnere3119b72015-01-20 15:02:36 -0800498 }
499
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700500 @Override
501 boolean checkCompleteDeferredRemoval() {
502 if (mIsExiting) {
503 removeIfPossible();
504 }
505 return super.checkCompleteDeferredRemoval();
506 }
507
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700508 void onRemovedFromDisplay() {
Wale Ogunwalee287e192017-04-21 09:30:12 -0700509 if (mRemovingFromDisplay) {
510 return;
511 }
512 mRemovingFromDisplay = true;
513
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700514 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app token: " + this);
515
Wale Ogunwale72919d22016-12-08 18:58:50 -0800516 boolean delayed = setVisibility(null, false, TRANSIT_UNSET, true, mVoiceInteraction);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700517
518 mService.mOpeningApps.remove(this);
Jorim Jaggi1b4b23e2016-11-15 16:30:12 -0800519 mService.mUnknownAppVisibilityController.appRemoved(this);
Jorim Jaggi10abe2f2017-01-03 16:44:46 +0100520 mService.mTaskSnapshotController.onAppRemoved(this);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700521 waitingToShow = false;
522 if (mService.mClosingApps.contains(this)) {
523 delayed = true;
524 } else if (mService.mAppTransition.isTransitionSet()) {
525 mService.mClosingApps.add(this);
526 delayed = true;
527 }
528
529 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app " + this + " delayed=" + delayed
530 + " animation=" + mAppAnimator.animation + " animating=" + mAppAnimator.animating);
531
532 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM, "removeAppToken: "
533 + this + " delayed=" + delayed + " Callers=" + Debug.getCallers(4));
534
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800535 if (startingData != null && getController() != null) {
536 getController().removeStartingWindow();
537 }
538
Winson Chung87e5d552017-04-05 11:49:38 -0700539 // If this window was animating, then we need to ensure that the app transition notifies
540 // that animations have completed in WMS.handleAnimatingStoppedAndTransitionLocked(), so
541 // add to that list now
542 if (mAppAnimator.animating) {
543 mService.mNoAnimationNotifyOnTransitionFinished.add(token);
544 }
545
Wale Ogunwalee287e192017-04-21 09:30:12 -0700546 final TaskStack stack = getStack();
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700547 if (delayed && !isEmpty()) {
548 // set the token aside because it has an active animation to be finished
549 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM,
550 "removeAppToken make exiting: " + this);
Wale Ogunwalee287e192017-04-21 09:30:12 -0700551 if (stack != null) {
552 stack.mExitingAppTokens.add(this);
553 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700554 mIsExiting = true;
555 } else {
556 // Make sure there is no animation running on this token, so any windows associated
557 // with it will be removed as soon as their animations are complete
558 mAppAnimator.clearAnimation();
559 mAppAnimator.animating = false;
560 removeIfPossible();
561 }
562
563 removed = true;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700564 stopFreezingScreen(true, true);
Bryce Lee6d410262017-02-28 15:30:17 -0800565
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700566 if (mService.mFocusedApp == this) {
567 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "Removing focused app token:" + this);
568 mService.mFocusedApp = null;
569 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
570 mService.mInputMonitor.setFocusedAppLw(null);
571 }
572
573 if (!delayed) {
574 updateReportedVisibilityLocked();
575 }
Wale Ogunwalee287e192017-04-21 09:30:12 -0700576
577 mRemovingFromDisplay = false;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700578 }
579
Chong Zhange05bcb12016-07-26 17:47:29 -0700580 void clearAnimatingFlags() {
Chong Zhangb0d26702016-08-12 16:03:29 -0700581 boolean wallpaperMightChange = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700582 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700583 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700584 wallpaperMightChange |= win.clearAnimatingFlags();
Chong Zhange05bcb12016-07-26 17:47:29 -0700585 }
Chong Zhangb0d26702016-08-12 16:03:29 -0700586 if (wallpaperMightChange) {
587 requestUpdateWallpaperIfNeeded();
588 }
Chong Zhange05bcb12016-07-26 17:47:29 -0700589 }
590
Robert Carre12aece2016-02-02 22:43:27 -0800591 void destroySurfaces() {
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700592 destroySurfaces(false /*cleanupOnResume*/);
593 }
594
595 /**
596 * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure
597 * the client has finished with them.
598 *
599 * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If
600 * set to true, destroy only surfaces of removed windows, and clear relevant flags of the
601 * others so that they are ready to be reused. If set to false (common case), destroy all
602 * surfaces that's eligible, if the app is already stopped.
603 */
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700604 private void destroySurfaces(boolean cleanupOnResume) {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700605 boolean destroyedSomething = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700606 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700607 final WindowState win = mChildren.get(i);
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700608 destroyedSomething |= win.destroySurface(cleanupOnResume, mAppStopped);
Robert Carre12aece2016-02-02 22:43:27 -0800609 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700610 if (destroyedSomething) {
611 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700612 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Robert Carre12aece2016-02-02 22:43:27 -0800613 }
614 }
615
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800616 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700617 * Notify that the app is now resumed, and it was not stopped before, perform a clean
618 * up of the surfaces
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800619 */
Jorim Jaggibae01b12017-04-11 16:29:10 -0700620 void notifyAppResumed(boolean wasStopped) {
Chong Zhangad24f962016-08-25 12:12:33 -0700621 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped
Jorim Jaggibae01b12017-04-11 16:29:10 -0700622 + " " + this);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700623 mAppStopped = false;
624 if (!wasStopped) {
625 destroySurfaces(true /*cleanupOnResume*/);
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800626 }
Robert Carre12aece2016-02-02 22:43:27 -0800627 }
628
Chong Zhangbef461f2015-10-27 11:38:24 -0700629 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700630 * Notify that the app has stopped, and it is okay to destroy any surfaces which were
631 * keeping alive in case they were still being used.
632 */
633 void notifyAppStopped() {
634 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this);
635 mAppStopped = true;
636 destroySurfaces();
637 // Remove any starting window that was added for this app if they are still around.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800638 if (getController() != null) {
639 getController().removeStartingWindow();
640 }
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700641 }
642
643 /**
Chong Zhangbef461f2015-10-27 11:38:24 -0700644 * Checks whether we should save surfaces for this app.
645 *
646 * @return true if the surfaces should be saved, false otherwise.
647 */
648 boolean shouldSaveSurface() {
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800649 // We want to save surface if the app's windows are "allDrawn".
650 // (If we started entering animation early with saved surfaces, allDrawn
651 // should have been restored to true. So we'll save again in that case
652 // even if app didn't actually finish drawing.)
653 return allDrawn;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800654 }
655
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700656 private boolean canRestoreSurfaces() {
657 for (int i = mChildren.size() -1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700658 final WindowState w = mChildren.get(i);
Chong Zhang92147042016-05-09 12:47:11 -0700659 if (w.canRestoreSurface()) {
Robert Carr13f7be9e2015-12-02 18:39:45 -0800660 return true;
661 }
Chong Zhangbef461f2015-10-27 11:38:24 -0700662 }
663 return false;
664 }
665
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700666 private void clearWasVisibleBeforeClientHidden() {
667 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700668 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700669 w.clearWasVisibleBeforeClientHidden();
Chong Zhang92147042016-05-09 12:47:11 -0700670 }
671 }
672
Chong Zhang8e4bda92016-05-04 15:08:18 -0700673 /**
674 * Whether the app has some window that is invisible in layout, but
675 * animating with saved surface.
676 */
677 boolean isAnimatingInvisibleWithSavedSurface() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700678 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700679 final WindowState w = mChildren.get(i);
Chong Zhang8e4bda92016-05-04 15:08:18 -0700680 if (w.isAnimatingInvisibleWithSavedSurface()) {
681 return true;
682 }
683 }
684 return false;
685 }
686
687 /**
688 * Hide all window surfaces that's still invisible in layout but animating
689 * with a saved surface, and mark them destroying.
690 */
691 void stopUsingSavedSurfaceLocked() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700692 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700693 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700694 w.stopUsingSavedSurface();
Chong Zhang8e4bda92016-05-04 15:08:18 -0700695 }
696 destroySurfaces();
697 }
698
Chong Zhangf58631a2016-05-24 16:02:10 -0700699 void markSavedSurfaceExiting() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700700 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700701 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700702 w.markSavedSurfaceExiting();
Chong Zhangf58631a2016-05-24 16:02:10 -0700703 }
704 }
705
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700706 void restoreSavedSurfaceForInterestingWindows() {
Chong Zhang92147042016-05-09 12:47:11 -0700707 if (!canRestoreSurfaces()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700708 clearWasVisibleBeforeClientHidden();
Chong Zhangbef461f2015-10-27 11:38:24 -0700709 return;
710 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700711
712 // Check if all interesting windows are drawn and we can mark allDrawn=true.
713 int interestingNotDrawn = -1;
714
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700715 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700716 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700717 interestingNotDrawn = w.restoreSavedSurfaceForInterestingWindow();
Chong Zhangbef461f2015-10-27 11:38:24 -0700718 }
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800719
Chong Zhang92147042016-05-09 12:47:11 -0700720 if (!allDrawn) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700721 allDrawn = (interestingNotDrawn == 0);
Chong Zhang92147042016-05-09 12:47:11 -0700722 if (allDrawn) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700723 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Chong Zhang92147042016-05-09 12:47:11 -0700724 }
725 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700726 clearWasVisibleBeforeClientHidden();
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800727
728 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700729 "restoreSavedSurfaceForInterestingWindows: " + this + " allDrawn=" + allDrawn
730 + " interestingNotDrawn=" + interestingNotDrawn);
Chong Zhangbef461f2015-10-27 11:38:24 -0700731 }
732
733 void destroySavedSurfaces() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700734 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700735 final WindowState win = mChildren.get(i);
Robert Carr13f7be9e2015-12-02 18:39:45 -0800736 win.destroySavedSurface();
Chong Zhangbef461f2015-10-27 11:38:24 -0700737 }
Chong Zhang92147042016-05-09 12:47:11 -0700738 }
739
740 void clearAllDrawn() {
741 allDrawn = false;
742 deferClearAllDrawn = false;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700743 allDrawnExcludingSaved = false;
Chong Zhangbef461f2015-10-27 11:38:24 -0700744 }
745
Bryce Lee6d410262017-02-28 15:30:17 -0800746 Task getTask() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800747 return (Task) getParent();
Bryce Lee6d410262017-02-28 15:30:17 -0800748 }
749
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800750 TaskStack getStack() {
751 final Task task = getTask();
752 if (task != null) {
753 return task.mStack;
754 } else {
755 return null;
756 }
757 }
758
Bryce Lee6d410262017-02-28 15:30:17 -0800759 @Override
760 void onParentSet() {
761 super.onParentSet();
762
Robert Carred3e83b2017-04-21 13:26:55 -0700763 final Task task = getTask();
764
Bryce Lee6d410262017-02-28 15:30:17 -0800765 // When the associated task is {@code null}, the {@link AppWindowToken} can no longer
766 // access visual elements like the {@link DisplayContent}. We must remove any associations
767 // such as animations.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800768 if (!mReparenting) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800769 if (task == null) {
770 // It is possible we have been marked as a closing app earlier. We must remove ourselves
771 // from this list so we do not participate in any future animations.
772 mService.mClosingApps.remove(this);
Robert Carred3e83b2017-04-21 13:26:55 -0700773 } else if (mLastParent != null && mLastParent.mStack != null) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800774 task.mStack.mExitingAppTokens.remove(this);
775 }
Bryce Lee6d410262017-02-28 15:30:17 -0800776 }
Robert Carred3e83b2017-04-21 13:26:55 -0700777 mLastParent = task;
Bryce Lee6d410262017-02-28 15:30:17 -0800778 }
779
Wale Ogunwalefa854eb2016-09-20 13:43:52 -0700780 void postWindowRemoveStartingWindowCleanup(WindowState win) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700781 // TODO: Something smells about the code below...Is there a better way?
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700782 if (startingWindow == win) {
783 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800784 if (getController() != null) {
785 getController().removeStartingWindow();
786 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700787 } else if (mChildren.size() == 0 && startingData != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700788 // If this is the last window and we had requested a starting transition window,
789 // well there is no point now.
Jorim Jaggi02886a82016-12-06 09:10:06 -0800790 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingData");
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700791 startingData = null;
Jorim Jaggi829b9cd2017-01-23 16:20:53 +0100792 } else if (mChildren.size() == 1 && startingSurface != null && !isRelaunching()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700793 // If this is the last window except for a starting transition window,
794 // we need to get rid of the starting transition.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800795 if (getController() != null) {
796 getController().removeStartingWindow();
797 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700798 }
799 }
800
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700801 void removeDeadWindows() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700802 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700803 WindowState win = mChildren.get(winNdx);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800804 if (win.mAppDied) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700805 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700806 "removeDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800807 // Set mDestroying, we don't want any animation or delayed removal here.
808 win.mDestroying = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700809 // Also removes child windows.
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700810 win.removeIfPossible();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800811 }
812 }
813 }
814
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700815 boolean hasWindowsAlive() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700816 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700817 // No need to loop through child windows as the answer should be the same as that of the
818 // parent window.
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700819 if (!(mChildren.get(i)).mAppDied) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700820 return true;
821 }
822 }
823 return false;
824 }
825
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700826 void setWillReplaceWindows(boolean animate) {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700827 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
828 "Marking app token " + this + " with replacing windows.");
Robert Carra1eb4392015-12-10 12:43:51 -0800829
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700830 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700831 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700832 w.setWillReplaceWindow(animate);
Robert Carra1eb4392015-12-10 12:43:51 -0800833 }
834 if (animate) {
835 // Set-up dummy animation so we can start treating windows associated with this
836 // token like they are in transition before the new app window is ready for us to
837 // run the real transition animation.
838 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700839 "setWillReplaceWindow() Setting dummy animation on: " + this);
Robert Carra1eb4392015-12-10 12:43:51 -0800840 mAppAnimator.setDummyAnimation();
841 }
842 }
843
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700844 void setWillReplaceChildWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700845 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this
Robert Carr23fa16b2016-01-13 13:19:58 -0800846 + " with replacing child windows.");
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700847 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700848 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700849 w.setWillReplaceChildWindows();
Robert Carr23fa16b2016-01-13 13:19:58 -0800850 }
851 }
852
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700853 void clearWillReplaceWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700854 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
855 "Resetting app token " + this + " of replacing window marks.");
Chong Zhangf596cd52016-01-05 13:42:44 -0800856
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700857 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700858 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700859 w.clearWillReplaceWindow();
Chong Zhangf596cd52016-01-05 13:42:44 -0800860 }
861 }
862
Chong Zhang4d7369a2016-04-25 16:09:14 -0700863 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700864 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700865 final WindowState w = mChildren.get(i);
Chong Zhang4d7369a2016-04-25 16:09:14 -0700866 w.requestUpdateWallpaperIfNeeded();
867 }
868 }
869
Chong Zhangd78ddb42016-03-02 17:01:14 -0800870 boolean isRelaunching() {
871 return mPendingRelaunchCount > 0;
872 }
873
874 void startRelaunching() {
875 if (canFreezeBounds()) {
876 freezeBounds();
877 }
Robert Carrd5c7dd62017-03-08 10:39:30 -0800878
879 // In the process of tearing down before relaunching, the app will
880 // try and clean up it's child surfaces. We need to prevent this from
881 // happening, so we sever the children, transfering their ownership
882 // from the client it-self to the parent surface (owned by us).
883 for (int i = mChildren.size() - 1; i >= 0; i--) {
884 final WindowState w = mChildren.get(i);
885 w.mWinAnimator.detachChildren();
886 }
887
Chong Zhangd78ddb42016-03-02 17:01:14 -0800888 mPendingRelaunchCount++;
889 }
890
891 void finishRelaunching() {
892 if (canFreezeBounds()) {
893 unfreezeBounds();
894 }
895 if (mPendingRelaunchCount > 0) {
896 mPendingRelaunchCount--;
897 }
898 }
899
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700900 void clearRelaunching() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700901 if (mPendingRelaunchCount == 0) {
902 return;
903 }
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700904 if (canFreezeBounds()) {
905 unfreezeBounds();
906 }
907 mPendingRelaunchCount = 0;
908 }
909
Wale Ogunwale07bcab72016-10-14 15:30:09 -0700910 /**
911 * Returns true if the new child window we are adding to this token is considered greater than
912 * the existing child window in this token in terms of z-order.
913 */
914 @Override
915 protected boolean isFirstChildWindowGreaterThanSecond(WindowState newWindow,
916 WindowState existingWindow) {
917 final int type1 = newWindow.mAttrs.type;
918 final int type2 = existingWindow.mAttrs.type;
919
920 // Base application windows should be z-ordered BELOW all other windows in the app token.
921 if (type1 == TYPE_BASE_APPLICATION && type2 != TYPE_BASE_APPLICATION) {
922 return false;
923 } else if (type1 != TYPE_BASE_APPLICATION && type2 == TYPE_BASE_APPLICATION) {
924 return true;
925 }
926
927 // Starting windows should be z-ordered ABOVE all other windows in the app token.
928 if (type1 == TYPE_APPLICATION_STARTING && type2 != TYPE_APPLICATION_STARTING) {
929 return true;
930 } else if (type1 != TYPE_APPLICATION_STARTING && type2 == TYPE_APPLICATION_STARTING) {
931 return false;
932 }
933
934 // Otherwise the new window is greater than the existing window.
935 return true;
936 }
937
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700938 @Override
Robert Carra1eb4392015-12-10 12:43:51 -0800939 void addWindow(WindowState w) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700940 super.addWindow(w);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700941
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700942 boolean gotReplacementWindow = false;
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 gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w);
946 }
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700947
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700948 // if we got a replacement window, reset the timeout to give drawing more time
949 if (gotReplacementWindow) {
950 mService.scheduleWindowReplacementTimeouts(this);
Robert Carra1eb4392015-12-10 12:43:51 -0800951 }
Jorim Jaggife762342016-10-13 14:33:27 +0200952 checkKeyguardFlagsChanged();
953 }
954
955 @Override
956 void removeChild(WindowState child) {
957 super.removeChild(child);
958 checkKeyguardFlagsChanged();
Robert Carra1eb4392015-12-10 12:43:51 -0800959 }
960
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700961 private boolean waitingForReplacement() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700962 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700963 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700964 if (candidate.waitingForReplacement()) {
Robert Carra1eb4392015-12-10 12:43:51 -0800965 return true;
966 }
967 }
968 return false;
969 }
970
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700971 void onWindowReplacementTimeout() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700972 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700973 (mChildren.get(i)).onWindowReplacementTimeout();
Robert Carra1eb4392015-12-10 12:43:51 -0800974 }
975 }
976
Winson Chung30480042017-01-26 10:55:34 -0800977 void reparent(Task task, int position) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800978 final Task currentTask = getTask();
979 if (task == currentTask) {
Winson Chung30480042017-01-26 10:55:34 -0800980 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800981 "window token=" + this + " already child of task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -0800982 }
Bryce Lee6d410262017-02-28 15:30:17 -0800983
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800984 if (currentTask.mStack != task.mStack) {
Bryce Lee6d410262017-02-28 15:30:17 -0800985 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800986 "window token=" + this + " current task=" + currentTask
Bryce Lee6d410262017-02-28 15:30:17 -0800987 + " belongs to a different stack than " + task);
988 }
989
Winson Chung30480042017-01-26 10:55:34 -0800990 if (DEBUG_ADD_REMOVE) Slog.i(TAG, "reParentWindowToken: removing window token=" + this
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800991 + " from task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -0800992 final DisplayContent prevDisplayContent = getDisplayContent();
993
Bryce Lee6d410262017-02-28 15:30:17 -0800994 mReparenting = true;
995
Winson Chung30480042017-01-26 10:55:34 -0800996 getParent().removeChild(this);
997 task.addChild(this, position);
998
Bryce Lee6d410262017-02-28 15:30:17 -0800999 mReparenting = false;
1000
Winson Chung30480042017-01-26 10:55:34 -08001001 // Relayout display(s).
1002 final DisplayContent displayContent = task.getDisplayContent();
1003 displayContent.setLayoutNeeded();
1004 if (prevDisplayContent != displayContent) {
1005 onDisplayChanged(displayContent);
1006 prevDisplayContent.setLayoutNeeded();
1007 }
1008 }
1009
Chong Zhangd78ddb42016-03-02 17:01:14 -08001010 private boolean canFreezeBounds() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001011 final Task task = getTask();
1012
Chong Zhangd78ddb42016-03-02 17:01:14 -08001013 // For freeform windows, we can't freeze the bounds at the moment because this would make
1014 // the resizing unresponsive.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001015 return task != null && !task.inFreeformWorkspace();
Chong Zhangd78ddb42016-03-02 17:01:14 -08001016 }
1017
Jorim Jaggi0429f352015-12-22 16:29:16 +01001018 /**
1019 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
1020 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
1021 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
1022 * with a queue.
1023 */
Chong Zhangd78ddb42016-03-02 17:01:14 -08001024 private void freezeBounds() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001025 final Task task = getTask();
1026 mFrozenBounds.offer(new Rect(task.mPreparedFrozenBounds));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001027
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001028 if (task.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) {
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001029 // We didn't call prepareFreezingBounds on the task, so use the current value.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001030 mFrozenMergedConfig.offer(new Configuration(task.getConfiguration()));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001031 } else {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001032 mFrozenMergedConfig.offer(new Configuration(task.mPreparedFrozenMergedConfig));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001033 }
Andrii Kulianb10330d2016-09-16 13:51:46 -07001034 // Calling unset() to make it equal to Configuration.EMPTY.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001035 task.mPreparedFrozenMergedConfig.unset();
Jorim Jaggi0429f352015-12-22 16:29:16 +01001036 }
1037
1038 /**
1039 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
1040 */
Chong Zhangd78ddb42016-03-02 17:01:14 -08001041 private void unfreezeBounds() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -07001042 if (!mFrozenBounds.isEmpty()) {
1043 mFrozenBounds.remove();
1044 }
1045 if (!mFrozenMergedConfig.isEmpty()) {
1046 mFrozenMergedConfig.remove();
1047 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001048 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001049 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001050 win.onUnfreezeBounds();
Jorim Jaggi4846ee32016-01-07 17:39:12 +01001051 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001052 mService.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +01001053 }
1054
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001055 void setAppLayoutChanges(int changes, String reason) {
1056 if (!mChildren.isEmpty()) {
1057 final DisplayContent dc = getDisplayContent();
1058 dc.pendingLayoutChanges |= changes;
1059 if (DEBUG_LAYOUT_REPEATS) {
1060 mService.mWindowPlacerLocked.debugLayoutRepeats(reason, dc.pendingLayoutChanges);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001061 }
1062 }
1063 }
1064
1065 void removeReplacedWindowIfNeeded(WindowState replacement) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001066 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001067 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001068 if (win.removeReplacedWindowIfNeeded(replacement)) {
1069 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001070 }
1071 }
1072 }
1073
1074 void startFreezingScreen() {
1075 if (DEBUG_ORIENTATION) logWithStack(TAG, "Set freezing of " + appToken + ": hidden="
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001076 + hidden + " freezing=" + mAppAnimator.freezingScreen + " hiddenRequested="
1077 + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001078 if (!hiddenRequested) {
1079 if (!mAppAnimator.freezingScreen) {
1080 mAppAnimator.freezingScreen = true;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001081 mService.registerAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001082 mAppAnimator.lastFreezeDuration = 0;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001083 mService.mAppsFreezingScreen++;
1084 if (mService.mAppsFreezingScreen == 1) {
1085 mService.startFreezingDisplayLocked(false, 0, 0);
1086 mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT);
1087 mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001088 }
1089 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001090 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001091 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001092 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001093 w.onStartFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001094 }
1095 }
1096 }
1097
1098 void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) {
1099 if (!mAppAnimator.freezingScreen) {
1100 return;
1101 }
1102 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + this + " force=" + force);
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001103 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001104 boolean unfrozeWindows = false;
1105 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001106 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001107 unfrozeWindows |= w.onStopFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001108 }
1109 if (force || unfrozeWindows) {
1110 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this);
1111 mAppAnimator.freezingScreen = false;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001112 mService.unregisterAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001113 mAppAnimator.lastFreezeDuration =
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001114 (int)(SystemClock.elapsedRealtime() - mService.mDisplayFreezeTime);
1115 mService.mAppsFreezingScreen--;
1116 mService.mLastFinishedFreezeSource = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001117 }
1118 if (unfreezeSurfaceNow) {
1119 if (unfrozeWindows) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001120 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001121 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001122 mService.stopFreezingDisplayLocked();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001123 }
1124 }
1125
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001126 @Override
1127 public void onAppFreezeTimeout() {
1128 Slog.w(TAG_WM, "Force clearing freeze: " + this);
1129 stopFreezingScreen(true, true);
1130 }
1131
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001132 boolean transferStartingWindow(IBinder transferFrom) {
Wale Ogunwale02319a62016-09-26 15:21:22 -07001133 final AppWindowToken fromToken = getDisplayContent().getAppWindowToken(transferFrom);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001134 if (fromToken == null) {
1135 return false;
1136 }
1137
1138 final WindowState tStartingWindow = fromToken.startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001139 if (tStartingWindow != null && fromToken.startingSurface != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001140 // In this case, the starting icon has already been displayed, so start
1141 // letting windows get shown immediately without any more transitions.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001142 mService.mSkipAppTransitionAnimation = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001143
1144 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow
1145 + " from " + fromToken + " to " + this);
1146
1147 final long origId = Binder.clearCallingIdentity();
1148
1149 // Transfer the starting window over to the new token.
1150 startingData = fromToken.startingData;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001151 startingSurface = fromToken.startingSurface;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001152 startingDisplayed = fromToken.startingDisplayed;
1153 fromToken.startingDisplayed = false;
1154 startingWindow = tStartingWindow;
1155 reportedVisible = fromToken.reportedVisible;
1156 fromToken.startingData = null;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001157 fromToken.startingSurface = null;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001158 fromToken.startingWindow = null;
1159 fromToken.startingMoved = true;
1160 tStartingWindow.mToken = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001161 tStartingWindow.mAppToken = this;
1162
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001163 if (DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001164 "Removing starting " + tStartingWindow + " from " + fromToken);
Wale Ogunwalefa854eb2016-09-20 13:43:52 -07001165 fromToken.removeChild(tStartingWindow);
1166 fromToken.postWindowRemoveStartingWindowCleanup(tStartingWindow);
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001167 addWindow(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001168
1169 // Propagate other interesting state between the tokens. If the old token is displayed,
1170 // we should immediately force the new one to be displayed. If it is animating, we need
1171 // to move that animation to the new one.
1172 if (fromToken.allDrawn) {
1173 allDrawn = true;
1174 deferClearAllDrawn = fromToken.deferClearAllDrawn;
1175 }
1176 if (fromToken.firstWindowDrawn) {
1177 firstWindowDrawn = true;
1178 }
1179 if (!fromToken.hidden) {
1180 hidden = false;
1181 hiddenRequested = false;
1182 }
Wale Ogunwale89973222017-04-23 18:39:45 -07001183 setClientHidden(fromToken.mClientHidden);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001184 fromToken.mAppAnimator.transferCurrentAnimation(
1185 mAppAnimator, tStartingWindow.mWinAnimator);
1186
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001187 mService.updateFocusedWindowLocked(
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001188 UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/);
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001189 getDisplayContent().setLayoutNeeded();
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001190 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001191 Binder.restoreCallingIdentity(origId);
1192 return true;
1193 } else if (fromToken.startingData != null) {
1194 // The previous app was getting ready to show a
1195 // starting window, but hasn't yet done so. Steal it!
1196 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1197 "Moving pending starting from " + fromToken + " to " + this);
1198 startingData = fromToken.startingData;
1199 fromToken.startingData = null;
1200 fromToken.startingMoved = true;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001201 if (getController() != null) {
1202 getController().scheduleAddStartingWindow();
1203 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001204 return true;
1205 }
1206
1207 final AppWindowAnimator tAppAnimator = fromToken.mAppAnimator;
1208 final AppWindowAnimator wAppAnimator = mAppAnimator;
1209 if (tAppAnimator.thumbnail != null) {
1210 // The old token is animating with a thumbnail, transfer that to the new token.
1211 if (wAppAnimator.thumbnail != null) {
1212 wAppAnimator.thumbnail.destroy();
1213 }
1214 wAppAnimator.thumbnail = tAppAnimator.thumbnail;
1215 wAppAnimator.thumbnailLayer = tAppAnimator.thumbnailLayer;
1216 wAppAnimator.thumbnailAnimation = tAppAnimator.thumbnailAnimation;
1217 tAppAnimator.thumbnail = null;
1218 }
1219 return false;
1220 }
1221
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001222 boolean isLastWindow(WindowState win) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001223 return mChildren.size() == 1 && mChildren.get(0) == win;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001224 }
1225
1226 void setAllAppWinAnimators() {
1227 final ArrayList<WindowStateAnimator> allAppWinAnimators = mAppAnimator.mAllAppWinAnimators;
1228 allAppWinAnimators.clear();
1229
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001230 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001231 for (int j = 0; j < windowsCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001232 (mChildren.get(j)).addWinAnimatorToList(allAppWinAnimators);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001233 }
1234 }
1235
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001236 @Override
1237 void onAppTransitionDone() {
1238 sendingToBottom = false;
1239 }
1240
Wale Ogunwale51362492016-09-08 17:49:17 -07001241 /**
1242 * We override because this class doesn't want its children affecting its reported orientation
1243 * in anyway.
1244 */
1245 @Override
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001246 int getOrientation(int candidate) {
1247 if (!fillsParent()) {
1248 // Can't specify orientation if app doesn't fill parent.
1249 return SCREEN_ORIENTATION_UNSET;
1250 }
1251
1252 if (candidate == SCREEN_ORIENTATION_BEHIND) {
1253 // Allow app to specify orientation regardless of its visibility state if the current
1254 // candidate want us to use orientation behind. I.e. the visible app on-top of this one
1255 // wants us to use the orientation of the app behind it.
1256 return mOrientation;
1257 }
1258
Bryce Lee61fbcbc2017-03-10 14:14:03 -08001259 // The {@link AppWindowToken} should only specify an orientation when it is not closing or
1260 // going to the bottom. Allowing closing {@link AppWindowToken} to participate can lead to
1261 // an Activity in another task being started in the wrong orientation during the transition.
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001262 if (!(sendingToBottom || mService.mClosingApps.contains(this))
Bryce Lee61fbcbc2017-03-10 14:14:03 -08001263 && (isVisible() || mService.mOpeningApps.contains(this))) {
Bryce Leea163b762017-01-24 11:05:01 -08001264 return mOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001265 }
Bryce Leea163b762017-01-24 11:05:01 -08001266
1267 return SCREEN_ORIENTATION_UNSET;
Wale Ogunwale51362492016-09-08 17:49:17 -07001268 }
1269
Wale Ogunwaleb198b742016-12-01 08:44:09 -08001270 /** Returns the app's preferred orientation regardless of its currently visibility state. */
1271 int getOrientationIgnoreVisibility() {
1272 return mOrientation;
1273 }
1274
Craig Mautnerdbb79912012-03-01 18:59:14 -08001275 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001276 void checkAppWindowsReadyToShow() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001277 if (allDrawn == mAppAnimator.allDrawn) {
1278 return;
1279 }
1280
1281 mAppAnimator.allDrawn = allDrawn;
1282 if (!allDrawn) {
1283 return;
1284 }
1285
1286 // The token has now changed state to having all windows shown... what to do, what to do?
1287 if (mAppAnimator.freezingScreen) {
1288 mAppAnimator.showAllWindowsLocked();
1289 stopFreezingScreen(false, true);
1290 if (DEBUG_ORIENTATION) Slog.i(TAG,
1291 "Setting mOrientationChangeComplete=true because wtoken " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001292 + " numInteresting=" + mNumInterestingWindows + " numDrawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001293 // This will set mOrientationChangeComplete and cause a pass through layout.
1294 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001295 "checkAppWindowsReadyToShow: freezingScreen");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001296 } else {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001297 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001298
1299 // We can now show all of the drawn windows!
1300 if (!mService.mOpeningApps.contains(this)) {
1301 mService.mAnimator.orAnimating(mAppAnimator.showAllWindowsLocked());
1302 }
1303 }
1304 }
1305
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001306 void updateAllDrawn(DisplayContent dc) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001307 if (!allDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001308 final int numInteresting = mNumInterestingWindows;
1309 if (numInteresting > 0 && mNumDrawnWindows >= numInteresting) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001310 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawn: " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001311 + " interesting=" + numInteresting + " drawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001312 allDrawn = true;
1313 // Force an additional layout pass where
1314 // WindowStateAnimator#commitFinishDrawingLocked() will call performShowLocked().
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001315 dc.setLayoutNeeded();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001316 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Robert Carrecc06b32017-04-18 14:25:10 -07001317
1318 final TaskStack s = getStack();
1319 if (s != null) {
1320 s.onAllWindowsDrawn();
1321 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001322 }
1323 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001324
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001325 if (!allDrawnExcludingSaved) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001326 int numInteresting = mNumInterestingWindowsExcludingSaved;
1327 if (numInteresting > 0 && mNumDrawnWindowsExcludingSaved >= numInteresting) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001328 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawnExcludingSaved: " + this
1329 + " interesting=" + numInteresting
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001330 + " drawn=" + mNumDrawnWindowsExcludingSaved);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001331 allDrawnExcludingSaved = true;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001332 dc.setLayoutNeeded();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001333 if (isAnimatingInvisibleWithSavedSurface()
1334 && !mService.mFinishedEarlyAnim.contains(this)) {
1335 mService.mFinishedEarlyAnim.add(this);
1336 }
1337 }
1338 }
1339 }
1340
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001341 /**
1342 * Updated this app token tracking states for interesting and drawn windows based on the window.
1343 *
1344 * @return Returns true if the input window is considered interesting and drawn while all the
1345 * windows in this app token where not considered drawn as of the last pass.
1346 */
1347 boolean updateDrawnWindowStates(WindowState w) {
1348 if (DEBUG_STARTING_WINDOW && w == startingWindow) {
1349 Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" + w.isOnScreen()
1350 + " allDrawn=" + allDrawn + " freezingScreen=" + mAppAnimator.freezingScreen);
1351 }
1352
1353 if (allDrawn && allDrawnExcludingSaved && !mAppAnimator.freezingScreen) {
1354 return false;
1355 }
1356
1357 if (mLastTransactionSequence != mService.mTransactionSequence) {
1358 mLastTransactionSequence = mService.mTransactionSequence;
1359 mNumInterestingWindows = mNumDrawnWindows = 0;
1360 mNumInterestingWindowsExcludingSaved = 0;
1361 mNumDrawnWindowsExcludingSaved = 0;
1362 startingDisplayed = false;
1363 }
1364
1365 final WindowStateAnimator winAnimator = w.mWinAnimator;
1366
1367 boolean isInterestingAndDrawn = false;
1368
1369 if (!allDrawn && w.mightAffectAllDrawn(false /* visibleOnly */)) {
1370 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
1371 Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw()
1372 + ", isAnimationSet=" + winAnimator.isAnimationSet());
1373 if (!w.isDrawnLw()) {
1374 Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController
1375 + " pv=" + w.mPolicyVisibility
1376 + " mDrawState=" + winAnimator.drawStateToString()
1377 + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested
1378 + " a=" + winAnimator.mAnimating);
1379 }
1380 }
1381
1382 if (w != startingWindow) {
1383 if (w.isInteresting()) {
1384 mNumInterestingWindows++;
1385 if (w.isDrawnLw()) {
1386 mNumDrawnWindows++;
1387
1388 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, "tokenMayBeDrawn: "
1389 + this + " w=" + w + " numInteresting=" + mNumInterestingWindows
1390 + " freezingScreen=" + mAppAnimator.freezingScreen
1391 + " mAppFreezing=" + w.mAppFreezing);
1392
1393 isInterestingAndDrawn = true;
1394 }
1395 }
1396 } else if (w.isDrawnLw()) {
Jorim Jaggi3878ca32017-02-02 17:13:05 -08001397 if (getController() != null) {
1398 getController().reportStartingWindowDrawn();
1399 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001400 startingDisplayed = true;
1401 }
1402 }
1403
1404 if (!allDrawnExcludingSaved && w.mightAffectAllDrawn(true /* visibleOnly */)) {
1405 if (w != startingWindow && w.isInteresting()) {
1406 mNumInterestingWindowsExcludingSaved++;
1407 if (w.isDrawnLw() && !w.isAnimatingWithSavedSurface()) {
1408 mNumDrawnWindowsExcludingSaved++;
1409
1410 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
1411 "tokenMayBeDrawnExcludingSaved: " + this + " w=" + w
1412 + " numInteresting=" + mNumInterestingWindowsExcludingSaved
1413 + " freezingScreen=" + mAppAnimator.freezingScreen
1414 + " mAppFreezing=" + w.mAppFreezing);
1415
1416 isInterestingAndDrawn = true;
1417 }
1418 }
1419 }
1420
1421 return isInterestingAndDrawn;
1422 }
1423
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001424 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001425 void stepAppWindowsAnimation(long currentTime) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001426 mAppAnimator.wasAnimating = mAppAnimator.animating;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001427 if (mAppAnimator.stepAnimationLocked(currentTime)) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001428 mAppAnimator.animating = true;
1429 mService.mAnimator.setAnimating(true);
1430 mService.mAnimator.mAppWindowAnimating = true;
1431 } else if (mAppAnimator.wasAnimating) {
1432 // stopped animating, do one more pass through the layout
Wale Ogunwale1e129a42016-11-21 13:03:47 -08001433 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
1434 DEBUG_LAYOUT_REPEATS ? "appToken " + this + " done" : null);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001435 if (DEBUG_ANIM) Slog.v(TAG, "updateWindowsApps...: done animating " + this);
1436 }
1437 }
1438
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001439 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001440 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001441 // For legacy reasons we process the TaskStack.mExitingAppTokens first in DisplayContent
1442 // before the non-exiting app tokens. So, we skip the exiting app tokens here.
1443 // TODO: Investigate if we need to continue to do this or if we can just process them
1444 // in-order.
1445 if (mIsExiting && !waitingForReplacement()) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001446 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001447 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001448 return forAllWindowsUnchecked(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001449 }
1450
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001451 boolean forAllWindowsUnchecked(ToBooleanFunction<WindowState> callback,
1452 boolean traverseTopToBottom) {
1453 return super.forAllWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001454 }
1455
1456 @Override
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001457 AppWindowToken asAppWindowToken() {
1458 // I am an app window token!
1459 return this;
1460 }
1461
1462 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -07001463 boolean fillsParent() {
1464 return mFillsParent;
1465 }
1466
1467 void setFillsParent(boolean fillsParent) {
1468 mFillsParent = fillsParent;
1469 }
1470
Jorim Jaggife762342016-10-13 14:33:27 +02001471 boolean containsDismissKeyguardWindow() {
1472 for (int i = mChildren.size() - 1; i >= 0; i--) {
1473 if ((mChildren.get(i).mAttrs.flags & FLAG_DISMISS_KEYGUARD) != 0) {
1474 return true;
1475 }
1476 }
1477 return false;
1478 }
1479
1480 boolean containsShowWhenLockedWindow() {
1481 for (int i = mChildren.size() - 1; i >= 0; i--) {
1482 if ((mChildren.get(i).mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
1483 return true;
1484 }
1485 }
1486 return false;
1487 }
1488
1489 void checkKeyguardFlagsChanged() {
1490 final boolean containsDismissKeyguard = containsDismissKeyguardWindow();
1491 final boolean containsShowWhenLocked = containsShowWhenLockedWindow();
1492 if (containsDismissKeyguard != mLastContainsDismissKeyguardWindow
1493 || containsShowWhenLocked != mLastContainsShowWhenLockedWindow) {
1494 mService.notifyKeyguardFlagsChanged(null /* callback */);
1495 }
1496 mLastContainsDismissKeyguardWindow = containsDismissKeyguard;
1497 mLastContainsShowWhenLockedWindow = containsShowWhenLocked;
1498 }
1499
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001500 WindowState getImeTargetBelowWindow(WindowState w) {
1501 final int index = mChildren.indexOf(w);
1502 if (index > 0) {
1503 final WindowState target = mChildren.get(index - 1);
1504 if (target.canBeImeTarget()) {
1505 return target;
1506 }
1507 }
1508 return null;
1509 }
1510
1511 WindowState getHighestAnimLayerWindow(WindowState currentTarget) {
1512 WindowState candidate = null;
1513 for (int i = mChildren.indexOf(currentTarget); i >= 0; i--) {
1514 final WindowState w = mChildren.get(i);
1515 if (w.mRemoved) {
1516 continue;
1517 }
1518 if (candidate == null || w.mWinAnimator.mAnimLayer >
1519 candidate.mWinAnimator.mAnimLayer) {
1520 candidate = w;
1521 }
1522 }
1523 return candidate;
1524 }
1525
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001526 /**
1527 * See {@link Activity#setDisablePreviewScreenshots}.
1528 */
1529 void setDisablePreviewScreenshots(boolean disable) {
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001530 mDisbalePreviewScreenshots = disable;
1531 }
1532
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001533 /**
1534 * Retrieves whether we'd like to generate a snapshot that's based solely on the theme. This is
1535 * the case when preview screenshots are disabled {@link #setDisablePreviewScreenshots} or when
1536 * we can't take a snapshot for other reasons, for example, if we have a secure window.
1537 *
1538 * @return True if we need to generate an app theme snapshot, false if we'd like to take a real
1539 * screenshot.
1540 */
1541 boolean shouldUseAppThemeSnapshot() {
1542 return mDisbalePreviewScreenshots || forAllWindows(w -> (w.mAttrs.flags & FLAG_SECURE) != 0,
1543 true /* topToBottom */);
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001544 }
1545
Wale Ogunwale51362492016-09-08 17:49:17 -07001546 @Override
Robert Carrdee1b3f2017-02-27 11:33:33 -08001547 int getAnimLayerAdjustment() {
1548 return mAppAnimator.animLayerAdjustment;
1549 }
1550
1551 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001552 void dump(PrintWriter pw, String prefix) {
1553 super.dump(pw, prefix);
1554 if (appToken != null) {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001555 pw.println(prefix + "app=true mVoiceInteraction=" + mVoiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001556 }
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001557 pw.print(prefix); pw.print("task="); pw.println(getTask());
Wale Ogunwale51362492016-09-08 17:49:17 -07001558 pw.print(prefix); pw.print(" mFillsParent="); pw.print(mFillsParent);
1559 pw.print(" mOrientation="); pw.println(mOrientation);
Wale Ogunwale89973222017-04-23 18:39:45 -07001560 pw.println(prefix + "hiddenRequested=" + hiddenRequested + " mClientHidden=" + mClientHidden
1561 + ((mDeferHidingClient) ? " mDeferHidingClient=" + mDeferHidingClient : "")
1562 + " reportedDrawn=" + reportedDrawn + " reportedVisible=" + reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -07001563 if (paused) {
1564 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001565 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001566 if (mAppStopped) {
1567 pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped);
1568 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001569 if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0
Craig Mautner6fbda632012-07-03 09:26:39 -07001570 || allDrawn || mAppAnimator.allDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001571 pw.print(prefix); pw.print("mNumInterestingWindows=");
1572 pw.print(mNumInterestingWindows);
1573 pw.print(" mNumDrawnWindows="); pw.print(mNumDrawnWindows);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001574 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -07001575 pw.print(" allDrawn="); pw.print(allDrawn);
1576 pw.print(" (animator="); pw.print(mAppAnimator.allDrawn);
1577 pw.println(")");
1578 }
1579 if (inPendingTransaction) {
1580 pw.print(prefix); pw.print("inPendingTransaction=");
1581 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001582 }
Craig Mautner799bc1d2015-01-14 10:33:48 -08001583 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001584 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
1585 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -08001586 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -08001587 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001588 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001589 if (startingWindow != null || startingSurface != null
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001590 || startingDisplayed || startingMoved) {
1591 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001592 pw.print(" startingSurface="); pw.print(startingSurface);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001593 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001594 pw.print(" startingMoved="); pw.println(startingMoved);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001595 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01001596 if (!mFrozenBounds.isEmpty()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -08001597 pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds);
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001598 pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig);
Chong Zhangd78ddb42016-03-02 17:01:14 -08001599 }
1600 if (mPendingRelaunchCount != 0) {
1601 pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount);
Jorim Jaggi0429f352015-12-22 16:29:16 +01001602 }
Wale Ogunwale9c64cb62017-04-12 13:39:59 -07001603 if (getController() != null) {
1604 pw.print(prefix); pw.print("controller="); pw.println(getController());
1605 }
Wale Ogunwalee287e192017-04-21 09:30:12 -07001606 if (mRemovingFromDisplay) {
1607 pw.println(prefix + "mRemovingFromDisplay=" + mRemovingFromDisplay);
1608 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001609 }
1610
1611 @Override
1612 public String toString() {
1613 if (stringName == null) {
1614 StringBuilder sb = new StringBuilder();
1615 sb.append("AppWindowToken{");
1616 sb.append(Integer.toHexString(System.identityHashCode(this)));
1617 sb.append(" token="); sb.append(token); sb.append('}');
1618 stringName = sb.toString();
1619 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001620 return stringName + ((mIsExiting) ? " mIsExiting=" : "");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001621 }
Jeff Browne9bdb312012-04-05 15:30:10 -07001622}