blob: 57b0fe2c04d957504e4515d47129799f62bcb7ed [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;
Bryce Lee39791592017-04-26 09:29:12 -070056import android.os.Build;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080057import android.os.Debug;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070058import android.os.IBinder;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070059import android.os.SystemClock;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080060import android.util.Slog;
61import android.view.IApplicationToken;
Robert Carr6914f082017-03-20 19:04:30 -070062import android.view.SurfaceControl;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080063import android.view.WindowManager;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080064import android.view.WindowManagerPolicy.StartingSurface;
65
66import com.android.internal.util.ToBooleanFunction;
67import com.android.server.input.InputApplicationHandle;
68import com.android.server.wm.WindowManagerService.H;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080069
70import java.io.PrintWriter;
Jorim Jaggi0429f352015-12-22 16:29:16 +010071import java.util.ArrayDeque;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080072import java.util.ArrayList;
73
Bryce Lee39791592017-04-26 09:29:12 -070074import static android.os.Build.VERSION_CODES.O;
75
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080076class AppTokenList extends ArrayList<AppWindowToken> {
77}
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080078
79/**
80 * Version of WindowToken that is specifically for a particular application (or
81 * really activity) that is displaying windows.
82 */
Wale Ogunwale3f4433d2016-08-18 20:42:42 -070083class AppWindowToken extends WindowToken implements WindowManagerService.AppFreezeListener {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080084 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppWindowToken" : TAG_WM;
85
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080086 // Non-null only for application tokens.
87 final IApplicationToken appToken;
88
Filip Gruszczynskia590c992015-11-25 16:45:26 -080089 @NonNull final AppWindowAnimator mAppAnimator;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -070090
Wale Ogunwale72919d22016-12-08 18:58:50 -080091 final boolean mVoiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -070092
Wale Ogunwale51362492016-09-08 17:49:17 -070093 /** @see WindowContainer#fillsParent() */
94 private boolean mFillsParent;
Craig Mautner4c5eb222013-11-18 12:59:05 -080095 boolean layoutConfigChanges;
Wale Ogunwale72919d22016-12-08 18:58:50 -080096 boolean mShowForAllUsers;
97 int mTargetSdk;
Craig Mautnera2c77052012-03-26 12:14:43 -070098
Bryce Lee6d410262017-02-28 15:30:17 -080099 // Flag set while reparenting to prevent actions normally triggered by an individual parent
100 // change.
101 private boolean mReparenting;
102
Wale Ogunwalee287e192017-04-21 09:30:12 -0700103 // True if we are current in the process of removing this app token from the display
104 private boolean mRemovingFromDisplay = false;
105
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800106 // The input dispatching timeout for this application token in nanoseconds.
Wale Ogunwale72919d22016-12-08 18:58:50 -0800107 long mInputDispatchingTimeoutNanos;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800108
109 // These are used for determining when all windows associated with
110 // an activity have been drawn, so they can be made visible together
111 // at the same time.
Craig Mautner764983d2012-03-22 11:37:36 -0700112 // initialize so that it doesn't match mTransactionSequence which is an int.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700113 private long mLastTransactionSequence = Long.MIN_VALUE;
114 private int mNumInterestingWindows;
115 private int mNumDrawnWindows;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800116 boolean inPendingTransaction;
117 boolean allDrawn;
Craig Mautner7636dfb2012-11-16 15:24:11 -0800118 // Set to true when this app creates a surface while in the middle of an animation. In that
119 // case do not clear allDrawn until the animation completes.
120 boolean deferClearAllDrawn;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800121
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700122 /**
123 * These are to track the app's real drawing status if there were no saved surfaces.
124 * @see #updateDrawnWindowStates
125 */
Chong Zhang8e4bda92016-05-04 15:08:18 -0700126 boolean allDrawnExcludingSaved;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700127 private int mNumInterestingWindowsExcludingSaved;
128 private int mNumDrawnWindowsExcludingSaved;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700129
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800130 // Is this window's surface needed? This is almost like hidden, except
131 // it will sometimes be true a little earlier: when the token has
132 // been shown, but is still waiting for its app transition to execute
133 // before making its windows shown.
134 boolean hiddenRequested;
135
136 // Have we told the window clients to hide themselves?
Wale Ogunwale89973222017-04-23 18:39:45 -0700137 private boolean mClientHidden;
138
139 // If true we will defer setting mClientHidden to true and reporting to the client that it is
140 // hidden.
141 boolean mDeferHidingClient;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800142
143 // Last visibility state we reported to the app token.
144 boolean reportedVisible;
145
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700146 // Last drawn state we reported to the app token.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700147 private boolean reportedDrawn;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700148
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800149 // Set to true when the token has been removed from the window mgr.
150 boolean removed;
151
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800152 // Information about an application starting window if displayed.
153 StartingData startingData;
154 WindowState startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800155 StartingSurface startingSurface;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800156 boolean startingDisplayed;
157 boolean startingMoved;
158 boolean firstWindowDrawn;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700159 private final WindowState.UpdateReportedVisibilityResults mReportedVisibilityResults =
160 new WindowState.UpdateReportedVisibilityResults();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800161
162 // Input application handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700163 final InputApplicationHandle mInputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800164
Wale Ogunwale571771c2016-08-26 13:18:50 -0700165 // TODO: Have a WindowContainer state for tracking exiting/deferred removal.
Craig Mautner799bc1d2015-01-14 10:33:48 -0800166 boolean mIsExiting;
Craig Mautner9ef471f2014-02-07 13:11:47 -0800167
Craig Mautnerbb742462014-07-07 15:28:55 -0700168 boolean mLaunchTaskBehind;
Craig Mautner8746a472014-07-24 15:12:54 -0700169 boolean mEnteringAnimation;
Craig Mautnerbb742462014-07-07 15:28:55 -0700170
Wale Ogunwale72919d22016-12-08 18:58:50 -0800171 private boolean mAlwaysFocusable;
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800172
Robert Carre12aece2016-02-02 22:43:27 -0800173 boolean mAppStopped;
Robert Carrfd10cd12016-06-29 16:41:50 -0700174 int mRotationAnimationHint;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700175 private int mPendingRelaunchCount;
Robert Carre12aece2016-02-02 22:43:27 -0800176
Jorim Jaggife762342016-10-13 14:33:27 +0200177 private boolean mLastContainsShowWhenLockedWindow;
178 private boolean mLastContainsDismissKeyguardWindow;
179
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700180 // The bounds of this activity. Mainly used for aspect-ratio compatibility.
181 // TODO(b/36505427): Every level on WindowContainer now has bounds information, which directly
182 // affects the configuration. We should probably move this into that class.
183 private final Rect mBounds = new Rect();
184
Jorim Jaggi0429f352015-12-22 16:29:16 +0100185 ArrayDeque<Rect> mFrozenBounds = new ArrayDeque<>();
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700186 ArrayDeque<Configuration> mFrozenMergedConfig = new ArrayDeque<>();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100187
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +0100188 private boolean mDisbalePreviewScreenshots;
189
Robert Carred3e83b2017-04-21 13:26:55 -0700190 Task mLastParent;
191
Wale Ogunwale72919d22016-12-08 18:58:50 -0800192 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
193 DisplayContent dc, long inputDispatchingTimeoutNanos, boolean fullscreen,
194 boolean showForAllUsers, int targetSdk, int orientation, int rotationAnimationHint,
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800195 int configChanges, boolean launchTaskBehind, boolean alwaysFocusable,
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700196 AppWindowContainerController controller, Configuration overrideConfig, Rect bounds) {
197 this(service, token, voiceInteraction, dc, fullscreen, overrideConfig, bounds);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800198 setController(controller);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800199 mInputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800200 mShowForAllUsers = showForAllUsers;
201 mTargetSdk = targetSdk;
202 mOrientation = orientation;
203 layoutConfigChanges = (configChanges & (CONFIG_SCREEN_SIZE | CONFIG_ORIENTATION)) != 0;
204 mLaunchTaskBehind = launchTaskBehind;
205 mAlwaysFocusable = alwaysFocusable;
206 mRotationAnimationHint = rotationAnimationHint;
207
208 // Application tokens start out hidden.
209 hidden = true;
210 hiddenRequested = true;
211 }
212
213 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700214 DisplayContent dc, boolean fillsParent, Configuration overrideConfig, Rect bounds) {
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800215 super(service, token != null ? token.asBinder() : null, TYPE_APPLICATION, true, dc,
216 false /* ownerCanManageAppTokens */);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700217 appToken = token;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800218 mVoiceInteraction = voiceInteraction;
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800219 mFillsParent = fillsParent;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800220 mInputApplicationHandle = new InputApplicationHandle(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700221 mAppAnimator = new AppWindowAnimator(this, service);
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700222 if (overrideConfig != null) {
223 onOverrideConfigurationChanged(overrideConfig);
224 }
225 if (bounds != null) {
226 mBounds.set(bounds);
227 }
228 }
229
230 void onOverrideConfigurationChanged(Configuration overrideConfiguration, Rect bounds) {
231 onOverrideConfigurationChanged(overrideConfiguration);
232 if (mBounds.equals(bounds)) {
233 return;
234 }
235 // TODO(b/36505427): If bounds is in WC, then we can automatically call onResize() when set.
236 mBounds.set(bounds);
237 onResize();
238 }
239
240 void getBounds(Rect outBounds) {
241 outBounds.set(mBounds);
242 }
243
244 boolean hasBounds() {
245 return !mBounds.isEmpty();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800246 }
247
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800248 void onFirstWindowDrawn(WindowState win, WindowStateAnimator winAnimator) {
249 firstWindowDrawn = true;
250
251 // We now have a good window to show, remove dead placeholders
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700252 removeDeadWindows();
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800253
Jorim Jaggi02886a82016-12-06 09:10:06 -0800254 if (startingWindow != null) {
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800255 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, "Finish starting "
256 + win.mToken + ": first real window is shown, no animation");
257 // If this initial window is animating, stop it -- we will do an animation to reveal
258 // it from behind the starting window, so there is no need for it to also be doing its
259 // own stuff.
260 winAnimator.clearAnimation();
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800261 if (getController() != null) {
262 getController().removeStartingWindow();
263 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800264 }
265 updateReportedVisibilityLocked();
266 }
267
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800268 void updateReportedVisibilityLocked() {
269 if (appToken == null) {
270 return;
271 }
272
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700273 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700274 final int count = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800275
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700276 mReportedVisibilityResults.reset();
277
278 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700279 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700280 win.updateReportedVisibility(mReportedVisibilityResults);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800281 }
282
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700283 int numInteresting = mReportedVisibilityResults.numInteresting;
284 int numVisible = mReportedVisibilityResults.numVisible;
285 int numDrawn = mReportedVisibilityResults.numDrawn;
286 boolean nowGone = mReportedVisibilityResults.nowGone;
287
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700288 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800289 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700290 if (!nowGone) {
291 // If the app is not yet gone, then it can only become visible/drawn.
292 if (!nowDrawn) {
293 nowDrawn = reportedDrawn;
294 }
295 if (!nowVisible) {
296 nowVisible = reportedVisible;
297 }
298 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800299 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800300 + numInteresting + " visible=" + numVisible);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800301 final AppWindowContainerController controller = getController();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700302 if (nowDrawn != reportedDrawn) {
303 if (nowDrawn) {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800304 if (controller != null) {
305 controller.reportWindowsDrawn();
306 }
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700307 }
308 reportedDrawn = nowDrawn;
309 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800310 if (nowVisible != reportedVisible) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700311 if (DEBUG_VISIBILITY) Slog.v(TAG,
312 "Visibility changed in " + this + ": vis=" + nowVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800313 reportedVisible = nowVisible;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800314 if (controller != null) {
315 if (nowVisible) {
316 controller.reportWindowsVisible();
317 } else {
318 controller.reportWindowsGone();
319 }
320 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800321 }
322 }
323
Wale Ogunwale89973222017-04-23 18:39:45 -0700324 boolean isClientHidden() {
325 return mClientHidden;
326 }
327
328 void setClientHidden(boolean hideClient) {
329 if (mClientHidden == hideClient || (hideClient && mDeferHidingClient)) {
330 return;
331 }
332 mClientHidden = hideClient;
333 sendAppVisibilityToClients();
334 }
335
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700336 boolean setVisibility(WindowManager.LayoutParams lp,
337 boolean visible, int transit, boolean performLayout, boolean isVoiceInteraction) {
338
339 boolean delayed = false;
340 inPendingTransaction = false;
341
Wale Ogunwale89973222017-04-23 18:39:45 -0700342 setClientHidden(!visible);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700343
344 // Allow for state changes and animation to be applied if:
345 // * token is transitioning visibility state
346 // * or the token was marked as hidden and is exiting before we had a chance to play the
347 // transition animation
348 // * or this is an opening app and windows are being replaced.
349 boolean visibilityChanged = false;
350 if (hidden == visible || (hidden && mIsExiting) || (visible && waitingForReplacement())) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700351 final AccessibilityController accessibilityController = mService.mAccessibilityController;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700352 boolean changed = false;
353 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
354 "Changing app " + this + " hidden=" + hidden + " performLayout=" + performLayout);
355
356 boolean runningAppAnimation = false;
357
358 if (transit != AppTransition.TRANSIT_UNSET) {
359 if (mAppAnimator.animation == AppWindowAnimator.sDummyAnimation) {
360 mAppAnimator.setNullAnimation();
361 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700362 if (mService.applyAnimationLocked(this, lp, transit, visible, isVoiceInteraction)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700363 delayed = runningAppAnimation = true;
364 }
365 final WindowState window = findMainWindow();
366 //TODO (multidisplay): Magnification is supported only for the default display.
367 if (window != null && accessibilityController != null
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700368 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700369 accessibilityController.onAppWindowTransitionLocked(window, transit);
370 }
371 changed = true;
372 }
373
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700374 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700375 for (int i = 0; i < windowsCount; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700376 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700377 changed |= win.onAppVisibilityChanged(visible, runningAppAnimation);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700378 }
379
380 hidden = hiddenRequested = !visible;
381 visibilityChanged = true;
382 if (!visible) {
383 stopFreezingScreen(true, true);
384 } else {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700385 // If we are being set visible, and the starting window is not yet displayed,
386 // then make sure it doesn't get displayed.
387 if (startingWindow != null && !startingWindow.isDrawnLw()) {
388 startingWindow.mPolicyVisibility = false;
389 startingWindow.mPolicyVisibilityAfterAnim = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700390 }
391 }
392
393 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setVisibility: " + this
394 + ": hidden=" + hidden + " hiddenRequested=" + hiddenRequested);
395
396 if (changed) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700397 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700398 if (performLayout) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700399 mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700400 false /*updateInputWindows*/);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700401 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700402 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700403 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700404 }
405 }
406
407 if (mAppAnimator.animation != null) {
408 delayed = true;
409 }
410
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700411 for (int i = mChildren.size() - 1; i >= 0 && !delayed; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700412 if ((mChildren.get(i)).isWindowAnimationSet()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700413 delayed = true;
414 }
415 }
416
417 if (visibilityChanged) {
418 if (visible && !delayed) {
419 // The token was made immediately visible, there will be no entrance animation.
420 // We need to inform the client the enter animation was finished.
421 mEnteringAnimation = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700422 mService.mActivityManagerAppTransitionNotifier.onAppTransitionFinishedLocked(token);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700423 }
Robert Carre7cc44d2017-03-20 19:04:30 -0700424 // If we are hidden but there is no delay needed we immediately
425 // apply the Surface transaction so that the ActivityManager
426 // can have some guarantee on the Surface state
427 // following setting the visibility.
Robert Carr6914f082017-03-20 19:04:30 -0700428 if (hidden && !delayed) {
429 SurfaceControl.openTransaction();
430 for (int i = mChildren.size() - 1; i >= 0; i--) {
431 mChildren.get(i).mWinAnimator.hide("immediately hidden");
432 }
433 SurfaceControl.closeTransaction();
434 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700435
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700436 if (!mService.mClosingApps.contains(this) && !mService.mOpeningApps.contains(this)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700437 // The token is not closing nor opening, so even if there is an animation set, that
438 // doesn't mean that it goes through the normal app transition cycle so we have
439 // to inform the docked controller about visibility change.
Andrii Kulian1e32e022016-09-16 15:29:34 -0700440 // TODO(multi-display): notify docked divider on all displays where visibility was
441 // affected.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700442 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700443 .notifyAppVisibilityChanged();
Jorim Jaggi8b702ed2017-01-20 16:59:03 +0100444 mService.mTaskSnapshotController.notifyAppVisibilityChanged(this, visible);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700445 }
446 }
447
448 return delayed;
449 }
450
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800451 WindowState findMainWindow() {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700452 WindowState candidate = null;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700453 int j = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800454 while (j > 0) {
455 j--;
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700456 final WindowState win = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700457 final int type = win.mAttrs.type;
458 // No need to loop through child window as base application and starting types can't be
459 // child windows.
460 if (type == TYPE_BASE_APPLICATION || type == TYPE_APPLICATION_STARTING) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700461 // In cases where there are multiple windows, we prefer the non-exiting window. This
Sungsoo Lim0d3d1f82015-12-02 14:47:59 +0900462 // happens for example when replacing windows during an activity relaunch. When
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700463 // constructing the animation, we want the new window, not the exiting one.
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800464 if (win.mAnimatingExit) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700465 candidate = win;
466 } else {
467 return win;
468 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800469 }
470 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700471 return candidate;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800472 }
473
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800474 boolean windowsAreFocusable() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800475 return StackId.canReceiveKeys(getTask().mStack.mStackId) || mAlwaysFocusable;
Wale Ogunwaled045c822015-12-02 09:14:28 -0800476 }
477
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800478 AppWindowContainerController getController() {
479 final WindowContainerController controller = super.getController();
480 return controller != null ? (AppWindowContainerController) controller : null;
481 }
482
Wale Ogunwale571771c2016-08-26 13:18:50 -0700483 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -0700484 boolean isVisible() {
Wale Ogunwalee471be62016-10-03 07:53:55 -0700485 // If the app token isn't hidden then it is considered visible and there is no need to check
486 // its children windows to see if they are visible.
487 return !hidden;
Wale Ogunwale44f21802016-09-02 12:49:48 -0700488 }
489
490 @Override
Wale Ogunwalee287e192017-04-21 09:30:12 -0700491 void removeImmediately() {
492 onRemovedFromDisplay();
493 super.removeImmediately();
494 }
495
496 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -0700497 void removeIfPossible() {
Craig Mautnere3119b72015-01-20 15:02:36 -0800498 mIsExiting = false;
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800499 removeAllWindowsIfPossible();
Bryce Lee6d410262017-02-28 15:30:17 -0800500 removeImmediately();
Craig Mautnere3119b72015-01-20 15:02:36 -0800501 }
502
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700503 @Override
504 boolean checkCompleteDeferredRemoval() {
505 if (mIsExiting) {
506 removeIfPossible();
507 }
508 return super.checkCompleteDeferredRemoval();
509 }
510
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700511 void onRemovedFromDisplay() {
Wale Ogunwalee287e192017-04-21 09:30:12 -0700512 if (mRemovingFromDisplay) {
513 return;
514 }
515 mRemovingFromDisplay = true;
516
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700517 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app token: " + this);
518
Wale Ogunwale72919d22016-12-08 18:58:50 -0800519 boolean delayed = setVisibility(null, false, TRANSIT_UNSET, true, mVoiceInteraction);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700520
521 mService.mOpeningApps.remove(this);
Jorim Jaggi1b4b23e2016-11-15 16:30:12 -0800522 mService.mUnknownAppVisibilityController.appRemoved(this);
Jorim Jaggi10abe2f2017-01-03 16:44:46 +0100523 mService.mTaskSnapshotController.onAppRemoved(this);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700524 waitingToShow = false;
525 if (mService.mClosingApps.contains(this)) {
526 delayed = true;
527 } else if (mService.mAppTransition.isTransitionSet()) {
528 mService.mClosingApps.add(this);
529 delayed = true;
530 }
531
532 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app " + this + " delayed=" + delayed
533 + " animation=" + mAppAnimator.animation + " animating=" + mAppAnimator.animating);
534
535 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM, "removeAppToken: "
536 + this + " delayed=" + delayed + " Callers=" + Debug.getCallers(4));
537
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800538 if (startingData != null && getController() != null) {
539 getController().removeStartingWindow();
540 }
541
Winson Chung87e5d552017-04-05 11:49:38 -0700542 // If this window was animating, then we need to ensure that the app transition notifies
543 // that animations have completed in WMS.handleAnimatingStoppedAndTransitionLocked(), so
544 // add to that list now
545 if (mAppAnimator.animating) {
546 mService.mNoAnimationNotifyOnTransitionFinished.add(token);
547 }
548
Wale Ogunwalee287e192017-04-21 09:30:12 -0700549 final TaskStack stack = getStack();
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700550 if (delayed && !isEmpty()) {
551 // set the token aside because it has an active animation to be finished
552 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM,
553 "removeAppToken make exiting: " + this);
Wale Ogunwalee287e192017-04-21 09:30:12 -0700554 if (stack != null) {
555 stack.mExitingAppTokens.add(this);
556 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700557 mIsExiting = true;
558 } else {
559 // Make sure there is no animation running on this token, so any windows associated
560 // with it will be removed as soon as their animations are complete
561 mAppAnimator.clearAnimation();
562 mAppAnimator.animating = false;
Wale Ogunwale3106ae012017-05-16 08:56:37 -0700563 if (stack != null) {
564 stack.mExitingAppTokens.remove(this);
565 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700566 removeIfPossible();
567 }
568
569 removed = true;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700570 stopFreezingScreen(true, true);
Bryce Lee6d410262017-02-28 15:30:17 -0800571
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700572 if (mService.mFocusedApp == this) {
573 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "Removing focused app token:" + this);
574 mService.mFocusedApp = null;
575 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
576 mService.mInputMonitor.setFocusedAppLw(null);
577 }
578
579 if (!delayed) {
580 updateReportedVisibilityLocked();
581 }
Wale Ogunwalee287e192017-04-21 09:30:12 -0700582
583 mRemovingFromDisplay = false;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700584 }
585
Chong Zhange05bcb12016-07-26 17:47:29 -0700586 void clearAnimatingFlags() {
Chong Zhangb0d26702016-08-12 16:03:29 -0700587 boolean wallpaperMightChange = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700588 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700589 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700590 wallpaperMightChange |= win.clearAnimatingFlags();
Chong Zhange05bcb12016-07-26 17:47:29 -0700591 }
Chong Zhangb0d26702016-08-12 16:03:29 -0700592 if (wallpaperMightChange) {
593 requestUpdateWallpaperIfNeeded();
594 }
Chong Zhange05bcb12016-07-26 17:47:29 -0700595 }
596
Robert Carre12aece2016-02-02 22:43:27 -0800597 void destroySurfaces() {
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700598 destroySurfaces(false /*cleanupOnResume*/);
599 }
600
601 /**
602 * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure
603 * the client has finished with them.
604 *
605 * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If
606 * set to true, destroy only surfaces of removed windows, and clear relevant flags of the
607 * others so that they are ready to be reused. If set to false (common case), destroy all
608 * surfaces that's eligible, if the app is already stopped.
609 */
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700610 private void destroySurfaces(boolean cleanupOnResume) {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700611 boolean destroyedSomething = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700612 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700613 final WindowState win = mChildren.get(i);
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700614 destroyedSomething |= win.destroySurface(cleanupOnResume, mAppStopped);
Robert Carre12aece2016-02-02 22:43:27 -0800615 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700616 if (destroyedSomething) {
617 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700618 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Robert Carre12aece2016-02-02 22:43:27 -0800619 }
620 }
621
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800622 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700623 * Notify that the app is now resumed, and it was not stopped before, perform a clean
624 * up of the surfaces
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800625 */
Jorim Jaggibae01b12017-04-11 16:29:10 -0700626 void notifyAppResumed(boolean wasStopped) {
Chong Zhangad24f962016-08-25 12:12:33 -0700627 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped
Jorim Jaggibae01b12017-04-11 16:29:10 -0700628 + " " + this);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700629 mAppStopped = false;
630 if (!wasStopped) {
631 destroySurfaces(true /*cleanupOnResume*/);
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800632 }
Robert Carre12aece2016-02-02 22:43:27 -0800633 }
634
Chong Zhangbef461f2015-10-27 11:38:24 -0700635 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700636 * Notify that the app has stopped, and it is okay to destroy any surfaces which were
637 * keeping alive in case they were still being used.
638 */
639 void notifyAppStopped() {
640 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this);
641 mAppStopped = true;
642 destroySurfaces();
643 // Remove any starting window that was added for this app if they are still around.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800644 if (getController() != null) {
645 getController().removeStartingWindow();
646 }
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700647 }
648
649 /**
Chong Zhangbef461f2015-10-27 11:38:24 -0700650 * Checks whether we should save surfaces for this app.
651 *
652 * @return true if the surfaces should be saved, false otherwise.
653 */
654 boolean shouldSaveSurface() {
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800655 // We want to save surface if the app's windows are "allDrawn".
656 // (If we started entering animation early with saved surfaces, allDrawn
657 // should have been restored to true. So we'll save again in that case
658 // even if app didn't actually finish drawing.)
659 return allDrawn;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800660 }
661
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700662 private boolean canRestoreSurfaces() {
663 for (int i = mChildren.size() -1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700664 final WindowState w = mChildren.get(i);
Chong Zhang92147042016-05-09 12:47:11 -0700665 if (w.canRestoreSurface()) {
Robert Carr13f7be9e2015-12-02 18:39:45 -0800666 return true;
667 }
Chong Zhangbef461f2015-10-27 11:38:24 -0700668 }
669 return false;
670 }
671
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700672 private void clearWasVisibleBeforeClientHidden() {
673 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700674 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700675 w.clearWasVisibleBeforeClientHidden();
Chong Zhang92147042016-05-09 12:47:11 -0700676 }
677 }
678
Chong Zhang8e4bda92016-05-04 15:08:18 -0700679 /**
680 * Whether the app has some window that is invisible in layout, but
681 * animating with saved surface.
682 */
683 boolean isAnimatingInvisibleWithSavedSurface() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700684 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700685 final WindowState w = mChildren.get(i);
Chong Zhang8e4bda92016-05-04 15:08:18 -0700686 if (w.isAnimatingInvisibleWithSavedSurface()) {
687 return true;
688 }
689 }
690 return false;
691 }
692
693 /**
694 * Hide all window surfaces that's still invisible in layout but animating
695 * with a saved surface, and mark them destroying.
696 */
697 void stopUsingSavedSurfaceLocked() {
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 w.stopUsingSavedSurface();
Chong Zhang8e4bda92016-05-04 15:08:18 -0700701 }
702 destroySurfaces();
703 }
704
Chong Zhangf58631a2016-05-24 16:02:10 -0700705 void markSavedSurfaceExiting() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700706 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700707 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700708 w.markSavedSurfaceExiting();
Chong Zhangf58631a2016-05-24 16:02:10 -0700709 }
710 }
711
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700712 void restoreSavedSurfaceForInterestingWindows() {
Chong Zhang92147042016-05-09 12:47:11 -0700713 if (!canRestoreSurfaces()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700714 clearWasVisibleBeforeClientHidden();
Chong Zhangbef461f2015-10-27 11:38:24 -0700715 return;
716 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700717
718 // Check if all interesting windows are drawn and we can mark allDrawn=true.
719 int interestingNotDrawn = -1;
720
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700721 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700722 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700723 interestingNotDrawn = w.restoreSavedSurfaceForInterestingWindow();
Chong Zhangbef461f2015-10-27 11:38:24 -0700724 }
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800725
Chong Zhang92147042016-05-09 12:47:11 -0700726 if (!allDrawn) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700727 allDrawn = (interestingNotDrawn == 0);
Chong Zhang92147042016-05-09 12:47:11 -0700728 if (allDrawn) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700729 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Chong Zhang92147042016-05-09 12:47:11 -0700730 }
731 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700732 clearWasVisibleBeforeClientHidden();
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800733
734 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700735 "restoreSavedSurfaceForInterestingWindows: " + this + " allDrawn=" + allDrawn
736 + " interestingNotDrawn=" + interestingNotDrawn);
Chong Zhangbef461f2015-10-27 11:38:24 -0700737 }
738
739 void destroySavedSurfaces() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700740 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700741 final WindowState win = mChildren.get(i);
Robert Carr13f7be9e2015-12-02 18:39:45 -0800742 win.destroySavedSurface();
Chong Zhangbef461f2015-10-27 11:38:24 -0700743 }
Chong Zhang92147042016-05-09 12:47:11 -0700744 }
745
746 void clearAllDrawn() {
747 allDrawn = false;
748 deferClearAllDrawn = false;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700749 allDrawnExcludingSaved = false;
Chong Zhangbef461f2015-10-27 11:38:24 -0700750 }
751
Bryce Lee6d410262017-02-28 15:30:17 -0800752 Task getTask() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800753 return (Task) getParent();
Bryce Lee6d410262017-02-28 15:30:17 -0800754 }
755
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800756 TaskStack getStack() {
757 final Task task = getTask();
758 if (task != null) {
759 return task.mStack;
760 } else {
761 return null;
762 }
763 }
764
Bryce Lee6d410262017-02-28 15:30:17 -0800765 @Override
766 void onParentSet() {
767 super.onParentSet();
768
Robert Carred3e83b2017-04-21 13:26:55 -0700769 final Task task = getTask();
770
Bryce Lee6d410262017-02-28 15:30:17 -0800771 // When the associated task is {@code null}, the {@link AppWindowToken} can no longer
772 // access visual elements like the {@link DisplayContent}. We must remove any associations
773 // such as animations.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800774 if (!mReparenting) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800775 if (task == null) {
776 // It is possible we have been marked as a closing app earlier. We must remove ourselves
777 // from this list so we do not participate in any future animations.
778 mService.mClosingApps.remove(this);
Robert Carred3e83b2017-04-21 13:26:55 -0700779 } else if (mLastParent != null && mLastParent.mStack != null) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800780 task.mStack.mExitingAppTokens.remove(this);
781 }
Bryce Lee6d410262017-02-28 15:30:17 -0800782 }
Robert Carred3e83b2017-04-21 13:26:55 -0700783 mLastParent = task;
Bryce Lee6d410262017-02-28 15:30:17 -0800784 }
785
Wale Ogunwalefa854eb2016-09-20 13:43:52 -0700786 void postWindowRemoveStartingWindowCleanup(WindowState win) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700787 // TODO: Something smells about the code below...Is there a better way?
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700788 if (startingWindow == win) {
789 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800790 if (getController() != null) {
791 getController().removeStartingWindow();
792 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700793 } else if (mChildren.size() == 0 && startingData != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700794 // If this is the last window and we had requested a starting transition window,
795 // well there is no point now.
Jorim Jaggi02886a82016-12-06 09:10:06 -0800796 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingData");
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700797 startingData = null;
Jorim Jaggi829b9cd2017-01-23 16:20:53 +0100798 } else if (mChildren.size() == 1 && startingSurface != null && !isRelaunching()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700799 // If this is the last window except for a starting transition window,
800 // we need to get rid of the starting transition.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800801 if (getController() != null) {
802 getController().removeStartingWindow();
803 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700804 }
805 }
806
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700807 void removeDeadWindows() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700808 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700809 WindowState win = mChildren.get(winNdx);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800810 if (win.mAppDied) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700811 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700812 "removeDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800813 // Set mDestroying, we don't want any animation or delayed removal here.
814 win.mDestroying = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700815 // Also removes child windows.
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700816 win.removeIfPossible();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800817 }
818 }
819 }
820
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700821 boolean hasWindowsAlive() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700822 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700823 // No need to loop through child windows as the answer should be the same as that of the
824 // parent window.
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700825 if (!(mChildren.get(i)).mAppDied) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700826 return true;
827 }
828 }
829 return false;
830 }
831
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700832 void setWillReplaceWindows(boolean animate) {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700833 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
834 "Marking app token " + this + " with replacing windows.");
Robert Carra1eb4392015-12-10 12:43:51 -0800835
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700836 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700837 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700838 w.setWillReplaceWindow(animate);
Robert Carra1eb4392015-12-10 12:43:51 -0800839 }
840 if (animate) {
841 // Set-up dummy animation so we can start treating windows associated with this
842 // token like they are in transition before the new app window is ready for us to
843 // run the real transition animation.
844 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700845 "setWillReplaceWindow() Setting dummy animation on: " + this);
Robert Carra1eb4392015-12-10 12:43:51 -0800846 mAppAnimator.setDummyAnimation();
847 }
848 }
849
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700850 void setWillReplaceChildWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700851 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this
Robert Carr23fa16b2016-01-13 13:19:58 -0800852 + " with replacing child windows.");
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700853 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700854 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700855 w.setWillReplaceChildWindows();
Robert Carr23fa16b2016-01-13 13:19:58 -0800856 }
857 }
858
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700859 void clearWillReplaceWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700860 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
861 "Resetting app token " + this + " of replacing window marks.");
Chong Zhangf596cd52016-01-05 13:42:44 -0800862
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700863 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700864 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700865 w.clearWillReplaceWindow();
Chong Zhangf596cd52016-01-05 13:42:44 -0800866 }
867 }
868
Chong Zhang4d7369a2016-04-25 16:09:14 -0700869 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700870 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700871 final WindowState w = mChildren.get(i);
Chong Zhang4d7369a2016-04-25 16:09:14 -0700872 w.requestUpdateWallpaperIfNeeded();
873 }
874 }
875
Chong Zhangd78ddb42016-03-02 17:01:14 -0800876 boolean isRelaunching() {
877 return mPendingRelaunchCount > 0;
878 }
879
880 void startRelaunching() {
881 if (canFreezeBounds()) {
882 freezeBounds();
883 }
Robert Carrd5c7dd62017-03-08 10:39:30 -0800884
885 // In the process of tearing down before relaunching, the app will
886 // try and clean up it's child surfaces. We need to prevent this from
887 // happening, so we sever the children, transfering their ownership
888 // from the client it-self to the parent surface (owned by us).
889 for (int i = mChildren.size() - 1; i >= 0; i--) {
890 final WindowState w = mChildren.get(i);
891 w.mWinAnimator.detachChildren();
892 }
893
Chong Zhangd78ddb42016-03-02 17:01:14 -0800894 mPendingRelaunchCount++;
895 }
896
897 void finishRelaunching() {
898 if (canFreezeBounds()) {
899 unfreezeBounds();
900 }
901 if (mPendingRelaunchCount > 0) {
902 mPendingRelaunchCount--;
903 }
Matthew Ng498c71d2017-04-18 13:55:45 -0700904 updateAllDrawn();
Chong Zhangd78ddb42016-03-02 17:01:14 -0800905 }
906
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700907 void clearRelaunching() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700908 if (mPendingRelaunchCount == 0) {
909 return;
910 }
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700911 if (canFreezeBounds()) {
912 unfreezeBounds();
913 }
914 mPendingRelaunchCount = 0;
915 }
916
Wale Ogunwale07bcab72016-10-14 15:30:09 -0700917 /**
918 * Returns true if the new child window we are adding to this token is considered greater than
919 * the existing child window in this token in terms of z-order.
920 */
921 @Override
922 protected boolean isFirstChildWindowGreaterThanSecond(WindowState newWindow,
923 WindowState existingWindow) {
924 final int type1 = newWindow.mAttrs.type;
925 final int type2 = existingWindow.mAttrs.type;
926
927 // Base application windows should be z-ordered BELOW all other windows in the app token.
928 if (type1 == TYPE_BASE_APPLICATION && type2 != TYPE_BASE_APPLICATION) {
929 return false;
930 } else if (type1 != TYPE_BASE_APPLICATION && type2 == TYPE_BASE_APPLICATION) {
931 return true;
932 }
933
934 // Starting windows should be z-ordered ABOVE all other windows in the app token.
935 if (type1 == TYPE_APPLICATION_STARTING && type2 != TYPE_APPLICATION_STARTING) {
936 return true;
937 } else if (type1 != TYPE_APPLICATION_STARTING && type2 == TYPE_APPLICATION_STARTING) {
938 return false;
939 }
940
941 // Otherwise the new window is greater than the existing window.
942 return true;
943 }
944
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700945 @Override
Robert Carra1eb4392015-12-10 12:43:51 -0800946 void addWindow(WindowState w) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700947 super.addWindow(w);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700948
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700949 boolean gotReplacementWindow = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700950 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700951 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700952 gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w);
953 }
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700954
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700955 // if we got a replacement window, reset the timeout to give drawing more time
956 if (gotReplacementWindow) {
957 mService.scheduleWindowReplacementTimeouts(this);
Robert Carra1eb4392015-12-10 12:43:51 -0800958 }
Jorim Jaggife762342016-10-13 14:33:27 +0200959 checkKeyguardFlagsChanged();
960 }
961
962 @Override
963 void removeChild(WindowState child) {
964 super.removeChild(child);
965 checkKeyguardFlagsChanged();
Robert Carra1eb4392015-12-10 12:43:51 -0800966 }
967
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700968 private boolean waitingForReplacement() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700969 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700970 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700971 if (candidate.waitingForReplacement()) {
Robert Carra1eb4392015-12-10 12:43:51 -0800972 return true;
973 }
974 }
975 return false;
976 }
977
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700978 void onWindowReplacementTimeout() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700979 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700980 (mChildren.get(i)).onWindowReplacementTimeout();
Robert Carra1eb4392015-12-10 12:43:51 -0800981 }
982 }
983
Winson Chung30480042017-01-26 10:55:34 -0800984 void reparent(Task task, int position) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800985 final Task currentTask = getTask();
986 if (task == currentTask) {
Winson Chung30480042017-01-26 10:55:34 -0800987 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800988 "window token=" + this + " already child of task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -0800989 }
Bryce Lee6d410262017-02-28 15:30:17 -0800990
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800991 if (currentTask.mStack != task.mStack) {
Bryce Lee6d410262017-02-28 15:30:17 -0800992 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800993 "window token=" + this + " current task=" + currentTask
Bryce Lee6d410262017-02-28 15:30:17 -0800994 + " belongs to a different stack than " + task);
995 }
996
Winson Chung30480042017-01-26 10:55:34 -0800997 if (DEBUG_ADD_REMOVE) Slog.i(TAG, "reParentWindowToken: removing window token=" + this
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800998 + " from task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -0800999 final DisplayContent prevDisplayContent = getDisplayContent();
1000
Bryce Lee6d410262017-02-28 15:30:17 -08001001 mReparenting = true;
1002
Winson Chung30480042017-01-26 10:55:34 -08001003 getParent().removeChild(this);
1004 task.addChild(this, position);
1005
Bryce Lee6d410262017-02-28 15:30:17 -08001006 mReparenting = false;
1007
Winson Chung30480042017-01-26 10:55:34 -08001008 // Relayout display(s).
1009 final DisplayContent displayContent = task.getDisplayContent();
1010 displayContent.setLayoutNeeded();
1011 if (prevDisplayContent != displayContent) {
1012 onDisplayChanged(displayContent);
1013 prevDisplayContent.setLayoutNeeded();
1014 }
1015 }
1016
Chong Zhangd78ddb42016-03-02 17:01:14 -08001017 private boolean canFreezeBounds() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001018 final Task task = getTask();
1019
Chong Zhangd78ddb42016-03-02 17:01:14 -08001020 // For freeform windows, we can't freeze the bounds at the moment because this would make
1021 // the resizing unresponsive.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001022 return task != null && !task.inFreeformWorkspace();
Chong Zhangd78ddb42016-03-02 17:01:14 -08001023 }
1024
Jorim Jaggi0429f352015-12-22 16:29:16 +01001025 /**
1026 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
1027 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
1028 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
1029 * with a queue.
1030 */
Chong Zhangd78ddb42016-03-02 17:01:14 -08001031 private void freezeBounds() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001032 final Task task = getTask();
1033 mFrozenBounds.offer(new Rect(task.mPreparedFrozenBounds));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001034
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001035 if (task.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) {
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001036 // We didn't call prepareFreezingBounds on the task, so use the current value.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001037 mFrozenMergedConfig.offer(new Configuration(task.getConfiguration()));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001038 } else {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001039 mFrozenMergedConfig.offer(new Configuration(task.mPreparedFrozenMergedConfig));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001040 }
Andrii Kulianb10330d2016-09-16 13:51:46 -07001041 // Calling unset() to make it equal to Configuration.EMPTY.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001042 task.mPreparedFrozenMergedConfig.unset();
Jorim Jaggi0429f352015-12-22 16:29:16 +01001043 }
1044
1045 /**
1046 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
1047 */
Chong Zhangd78ddb42016-03-02 17:01:14 -08001048 private void unfreezeBounds() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -07001049 if (!mFrozenBounds.isEmpty()) {
1050 mFrozenBounds.remove();
1051 }
1052 if (!mFrozenMergedConfig.isEmpty()) {
1053 mFrozenMergedConfig.remove();
1054 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001055 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001056 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001057 win.onUnfreezeBounds();
Jorim Jaggi4846ee32016-01-07 17:39:12 +01001058 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001059 mService.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +01001060 }
1061
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001062 void setAppLayoutChanges(int changes, String reason) {
1063 if (!mChildren.isEmpty()) {
1064 final DisplayContent dc = getDisplayContent();
1065 dc.pendingLayoutChanges |= changes;
1066 if (DEBUG_LAYOUT_REPEATS) {
1067 mService.mWindowPlacerLocked.debugLayoutRepeats(reason, dc.pendingLayoutChanges);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001068 }
1069 }
1070 }
1071
1072 void removeReplacedWindowIfNeeded(WindowState replacement) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001073 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001074 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001075 if (win.removeReplacedWindowIfNeeded(replacement)) {
1076 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001077 }
1078 }
1079 }
1080
1081 void startFreezingScreen() {
1082 if (DEBUG_ORIENTATION) logWithStack(TAG, "Set freezing of " + appToken + ": hidden="
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001083 + hidden + " freezing=" + mAppAnimator.freezingScreen + " hiddenRequested="
1084 + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001085 if (!hiddenRequested) {
1086 if (!mAppAnimator.freezingScreen) {
1087 mAppAnimator.freezingScreen = true;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001088 mService.registerAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001089 mAppAnimator.lastFreezeDuration = 0;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001090 mService.mAppsFreezingScreen++;
1091 if (mService.mAppsFreezingScreen == 1) {
1092 mService.startFreezingDisplayLocked(false, 0, 0);
1093 mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT);
1094 mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001095 }
1096 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001097 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001098 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001099 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001100 w.onStartFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001101 }
1102 }
1103 }
1104
1105 void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) {
1106 if (!mAppAnimator.freezingScreen) {
1107 return;
1108 }
1109 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + this + " force=" + force);
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001110 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001111 boolean unfrozeWindows = false;
1112 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001113 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001114 unfrozeWindows |= w.onStopFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001115 }
1116 if (force || unfrozeWindows) {
1117 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this);
1118 mAppAnimator.freezingScreen = false;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001119 mService.unregisterAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001120 mAppAnimator.lastFreezeDuration =
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001121 (int)(SystemClock.elapsedRealtime() - mService.mDisplayFreezeTime);
1122 mService.mAppsFreezingScreen--;
1123 mService.mLastFinishedFreezeSource = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001124 }
1125 if (unfreezeSurfaceNow) {
1126 if (unfrozeWindows) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001127 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001128 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001129 mService.stopFreezingDisplayLocked();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001130 }
1131 }
1132
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001133 @Override
1134 public void onAppFreezeTimeout() {
1135 Slog.w(TAG_WM, "Force clearing freeze: " + this);
1136 stopFreezingScreen(true, true);
1137 }
1138
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001139 boolean transferStartingWindow(IBinder transferFrom) {
Wale Ogunwale02319a62016-09-26 15:21:22 -07001140 final AppWindowToken fromToken = getDisplayContent().getAppWindowToken(transferFrom);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001141 if (fromToken == null) {
1142 return false;
1143 }
1144
1145 final WindowState tStartingWindow = fromToken.startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001146 if (tStartingWindow != null && fromToken.startingSurface != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001147 // In this case, the starting icon has already been displayed, so start
1148 // letting windows get shown immediately without any more transitions.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001149 mService.mSkipAppTransitionAnimation = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001150
1151 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow
1152 + " from " + fromToken + " to " + this);
1153
1154 final long origId = Binder.clearCallingIdentity();
1155
1156 // Transfer the starting window over to the new token.
1157 startingData = fromToken.startingData;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001158 startingSurface = fromToken.startingSurface;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001159 startingDisplayed = fromToken.startingDisplayed;
1160 fromToken.startingDisplayed = false;
1161 startingWindow = tStartingWindow;
1162 reportedVisible = fromToken.reportedVisible;
1163 fromToken.startingData = null;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001164 fromToken.startingSurface = null;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001165 fromToken.startingWindow = null;
1166 fromToken.startingMoved = true;
1167 tStartingWindow.mToken = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001168 tStartingWindow.mAppToken = this;
1169
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001170 if (DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001171 "Removing starting " + tStartingWindow + " from " + fromToken);
Wale Ogunwalefa854eb2016-09-20 13:43:52 -07001172 fromToken.removeChild(tStartingWindow);
1173 fromToken.postWindowRemoveStartingWindowCleanup(tStartingWindow);
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001174 addWindow(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001175
1176 // Propagate other interesting state between the tokens. If the old token is displayed,
1177 // we should immediately force the new one to be displayed. If it is animating, we need
1178 // to move that animation to the new one.
1179 if (fromToken.allDrawn) {
1180 allDrawn = true;
1181 deferClearAllDrawn = fromToken.deferClearAllDrawn;
1182 }
1183 if (fromToken.firstWindowDrawn) {
1184 firstWindowDrawn = true;
1185 }
1186 if (!fromToken.hidden) {
1187 hidden = false;
1188 hiddenRequested = false;
1189 }
Wale Ogunwale89973222017-04-23 18:39:45 -07001190 setClientHidden(fromToken.mClientHidden);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001191 fromToken.mAppAnimator.transferCurrentAnimation(
1192 mAppAnimator, tStartingWindow.mWinAnimator);
1193
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001194 mService.updateFocusedWindowLocked(
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001195 UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/);
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001196 getDisplayContent().setLayoutNeeded();
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001197 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001198 Binder.restoreCallingIdentity(origId);
1199 return true;
1200 } else if (fromToken.startingData != null) {
1201 // The previous app was getting ready to show a
1202 // starting window, but hasn't yet done so. Steal it!
1203 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1204 "Moving pending starting from " + fromToken + " to " + this);
1205 startingData = fromToken.startingData;
1206 fromToken.startingData = null;
1207 fromToken.startingMoved = true;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001208 if (getController() != null) {
1209 getController().scheduleAddStartingWindow();
1210 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001211 return true;
1212 }
1213
1214 final AppWindowAnimator tAppAnimator = fromToken.mAppAnimator;
1215 final AppWindowAnimator wAppAnimator = mAppAnimator;
1216 if (tAppAnimator.thumbnail != null) {
1217 // The old token is animating with a thumbnail, transfer that to the new token.
1218 if (wAppAnimator.thumbnail != null) {
1219 wAppAnimator.thumbnail.destroy();
1220 }
1221 wAppAnimator.thumbnail = tAppAnimator.thumbnail;
1222 wAppAnimator.thumbnailLayer = tAppAnimator.thumbnailLayer;
1223 wAppAnimator.thumbnailAnimation = tAppAnimator.thumbnailAnimation;
1224 tAppAnimator.thumbnail = null;
1225 }
1226 return false;
1227 }
1228
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001229 boolean isLastWindow(WindowState win) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001230 return mChildren.size() == 1 && mChildren.get(0) == win;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001231 }
1232
1233 void setAllAppWinAnimators() {
1234 final ArrayList<WindowStateAnimator> allAppWinAnimators = mAppAnimator.mAllAppWinAnimators;
1235 allAppWinAnimators.clear();
1236
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001237 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001238 for (int j = 0; j < windowsCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001239 (mChildren.get(j)).addWinAnimatorToList(allAppWinAnimators);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001240 }
1241 }
1242
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001243 @Override
1244 void onAppTransitionDone() {
1245 sendingToBottom = false;
1246 }
1247
Wale Ogunwale51362492016-09-08 17:49:17 -07001248 /**
1249 * We override because this class doesn't want its children affecting its reported orientation
1250 * in anyway.
1251 */
1252 @Override
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001253 int getOrientation(int candidate) {
Bryce Leed1ac18c2017-05-11 07:59:41 -07001254 // We do not allow non-fullscreen apps to influence orientation beyond O. While we do
Bryce Lee39791592017-04-26 09:29:12 -07001255 // throw an exception in {@link Activity#onCreate} and
1256 // {@link Activity#setRequestedOrientation}, we also ignore the orientation here so that
1257 // other calculations aren't affected.
Bryce Leed1ac18c2017-05-11 07:59:41 -07001258 if (!fillsParent() && mTargetSdk > O) {
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001259 // Can't specify orientation if app doesn't fill parent.
1260 return SCREEN_ORIENTATION_UNSET;
1261 }
1262
1263 if (candidate == SCREEN_ORIENTATION_BEHIND) {
1264 // Allow app to specify orientation regardless of its visibility state if the current
1265 // candidate want us to use orientation behind. I.e. the visible app on-top of this one
1266 // wants us to use the orientation of the app behind it.
1267 return mOrientation;
1268 }
1269
Bryce Lee61fbcbc2017-03-10 14:14:03 -08001270 // The {@link AppWindowToken} should only specify an orientation when it is not closing or
1271 // going to the bottom. Allowing closing {@link AppWindowToken} to participate can lead to
1272 // an Activity in another task being started in the wrong orientation during the transition.
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001273 if (!(sendingToBottom || mService.mClosingApps.contains(this))
Bryce Lee61fbcbc2017-03-10 14:14:03 -08001274 && (isVisible() || mService.mOpeningApps.contains(this))) {
Bryce Leea163b762017-01-24 11:05:01 -08001275 return mOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001276 }
Bryce Leea163b762017-01-24 11:05:01 -08001277
1278 return SCREEN_ORIENTATION_UNSET;
Wale Ogunwale51362492016-09-08 17:49:17 -07001279 }
1280
Wale Ogunwaleb198b742016-12-01 08:44:09 -08001281 /** Returns the app's preferred orientation regardless of its currently visibility state. */
1282 int getOrientationIgnoreVisibility() {
1283 return mOrientation;
1284 }
1285
Craig Mautnerdbb79912012-03-01 18:59:14 -08001286 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001287 void checkAppWindowsReadyToShow() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001288 if (allDrawn == mAppAnimator.allDrawn) {
1289 return;
1290 }
1291
1292 mAppAnimator.allDrawn = allDrawn;
1293 if (!allDrawn) {
1294 return;
1295 }
1296
1297 // The token has now changed state to having all windows shown... what to do, what to do?
1298 if (mAppAnimator.freezingScreen) {
1299 mAppAnimator.showAllWindowsLocked();
1300 stopFreezingScreen(false, true);
1301 if (DEBUG_ORIENTATION) Slog.i(TAG,
1302 "Setting mOrientationChangeComplete=true because wtoken " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001303 + " numInteresting=" + mNumInterestingWindows + " numDrawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001304 // This will set mOrientationChangeComplete and cause a pass through layout.
1305 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001306 "checkAppWindowsReadyToShow: freezingScreen");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001307 } else {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001308 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001309
1310 // We can now show all of the drawn windows!
1311 if (!mService.mOpeningApps.contains(this)) {
1312 mService.mAnimator.orAnimating(mAppAnimator.showAllWindowsLocked());
1313 }
1314 }
1315 }
1316
Matthew Ng498c71d2017-04-18 13:55:45 -07001317 void updateAllDrawn() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001318 if (!allDrawn) {
Matthew Ng498c71d2017-04-18 13:55:45 -07001319 // Number of drawn windows can be less when a window is being relaunched, wait for
1320 // all windows to be launched and drawn for this token be considered all drawn
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001321 final int numInteresting = mNumInterestingWindows;
Matthew Ng498c71d2017-04-18 13:55:45 -07001322 if (numInteresting > 0 && mNumDrawnWindows >= numInteresting && !isRelaunching()) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001323 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawn: " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001324 + " interesting=" + numInteresting + " drawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001325 allDrawn = true;
1326 // Force an additional layout pass where
1327 // WindowStateAnimator#commitFinishDrawingLocked() will call performShowLocked().
Matthew Ng498c71d2017-04-18 13:55:45 -07001328 if (mDisplayContent != null) {
1329 mDisplayContent.setLayoutNeeded();
1330 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001331 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Robert Carrecc06b32017-04-18 14:25:10 -07001332
1333 final TaskStack s = getStack();
1334 if (s != null) {
1335 s.onAllWindowsDrawn();
1336 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001337 }
1338 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001339
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001340 if (!allDrawnExcludingSaved) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001341 int numInteresting = mNumInterestingWindowsExcludingSaved;
1342 if (numInteresting > 0 && mNumDrawnWindowsExcludingSaved >= numInteresting) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001343 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawnExcludingSaved: " + this
1344 + " interesting=" + numInteresting
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001345 + " drawn=" + mNumDrawnWindowsExcludingSaved);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001346 allDrawnExcludingSaved = true;
Matthew Ng498c71d2017-04-18 13:55:45 -07001347 if (mDisplayContent != null) {
1348 mDisplayContent.setLayoutNeeded();
1349 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001350 if (isAnimatingInvisibleWithSavedSurface()
1351 && !mService.mFinishedEarlyAnim.contains(this)) {
1352 mService.mFinishedEarlyAnim.add(this);
1353 }
1354 }
1355 }
1356 }
1357
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001358 /**
1359 * Updated this app token tracking states for interesting and drawn windows based on the window.
1360 *
1361 * @return Returns true if the input window is considered interesting and drawn while all the
1362 * windows in this app token where not considered drawn as of the last pass.
1363 */
1364 boolean updateDrawnWindowStates(WindowState w) {
1365 if (DEBUG_STARTING_WINDOW && w == startingWindow) {
1366 Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" + w.isOnScreen()
1367 + " allDrawn=" + allDrawn + " freezingScreen=" + mAppAnimator.freezingScreen);
1368 }
1369
1370 if (allDrawn && allDrawnExcludingSaved && !mAppAnimator.freezingScreen) {
1371 return false;
1372 }
1373
1374 if (mLastTransactionSequence != mService.mTransactionSequence) {
1375 mLastTransactionSequence = mService.mTransactionSequence;
1376 mNumInterestingWindows = mNumDrawnWindows = 0;
1377 mNumInterestingWindowsExcludingSaved = 0;
1378 mNumDrawnWindowsExcludingSaved = 0;
1379 startingDisplayed = false;
1380 }
1381
1382 final WindowStateAnimator winAnimator = w.mWinAnimator;
1383
1384 boolean isInterestingAndDrawn = false;
1385
1386 if (!allDrawn && w.mightAffectAllDrawn(false /* visibleOnly */)) {
1387 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
1388 Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw()
1389 + ", isAnimationSet=" + winAnimator.isAnimationSet());
1390 if (!w.isDrawnLw()) {
1391 Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController
1392 + " pv=" + w.mPolicyVisibility
1393 + " mDrawState=" + winAnimator.drawStateToString()
1394 + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested
1395 + " a=" + winAnimator.mAnimating);
1396 }
1397 }
1398
1399 if (w != startingWindow) {
1400 if (w.isInteresting()) {
1401 mNumInterestingWindows++;
1402 if (w.isDrawnLw()) {
1403 mNumDrawnWindows++;
1404
1405 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, "tokenMayBeDrawn: "
1406 + this + " w=" + w + " numInteresting=" + mNumInterestingWindows
1407 + " freezingScreen=" + mAppAnimator.freezingScreen
1408 + " mAppFreezing=" + w.mAppFreezing);
1409
1410 isInterestingAndDrawn = true;
1411 }
1412 }
1413 } else if (w.isDrawnLw()) {
Jorim Jaggi3878ca32017-02-02 17:13:05 -08001414 if (getController() != null) {
1415 getController().reportStartingWindowDrawn();
1416 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001417 startingDisplayed = true;
1418 }
1419 }
1420
1421 if (!allDrawnExcludingSaved && w.mightAffectAllDrawn(true /* visibleOnly */)) {
1422 if (w != startingWindow && w.isInteresting()) {
1423 mNumInterestingWindowsExcludingSaved++;
1424 if (w.isDrawnLw() && !w.isAnimatingWithSavedSurface()) {
1425 mNumDrawnWindowsExcludingSaved++;
1426
1427 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
1428 "tokenMayBeDrawnExcludingSaved: " + this + " w=" + w
1429 + " numInteresting=" + mNumInterestingWindowsExcludingSaved
1430 + " freezingScreen=" + mAppAnimator.freezingScreen
1431 + " mAppFreezing=" + w.mAppFreezing);
1432
1433 isInterestingAndDrawn = true;
1434 }
1435 }
1436 }
1437
1438 return isInterestingAndDrawn;
1439 }
1440
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001441 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001442 void stepAppWindowsAnimation(long currentTime) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001443 mAppAnimator.wasAnimating = mAppAnimator.animating;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001444 if (mAppAnimator.stepAnimationLocked(currentTime)) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001445 mAppAnimator.animating = true;
1446 mService.mAnimator.setAnimating(true);
1447 mService.mAnimator.mAppWindowAnimating = true;
1448 } else if (mAppAnimator.wasAnimating) {
1449 // stopped animating, do one more pass through the layout
Wale Ogunwale1e129a42016-11-21 13:03:47 -08001450 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
1451 DEBUG_LAYOUT_REPEATS ? "appToken " + this + " done" : null);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001452 if (DEBUG_ANIM) Slog.v(TAG, "updateWindowsApps...: done animating " + this);
1453 }
1454 }
1455
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001456 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001457 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001458 // For legacy reasons we process the TaskStack.mExitingAppTokens first in DisplayContent
1459 // before the non-exiting app tokens. So, we skip the exiting app tokens here.
1460 // TODO: Investigate if we need to continue to do this or if we can just process them
1461 // in-order.
1462 if (mIsExiting && !waitingForReplacement()) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001463 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001464 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001465 return forAllWindowsUnchecked(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001466 }
1467
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001468 boolean forAllWindowsUnchecked(ToBooleanFunction<WindowState> callback,
1469 boolean traverseTopToBottom) {
1470 return super.forAllWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001471 }
1472
1473 @Override
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001474 AppWindowToken asAppWindowToken() {
1475 // I am an app window token!
1476 return this;
1477 }
1478
1479 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -07001480 boolean fillsParent() {
1481 return mFillsParent;
1482 }
1483
1484 void setFillsParent(boolean fillsParent) {
1485 mFillsParent = fillsParent;
1486 }
1487
Jorim Jaggife762342016-10-13 14:33:27 +02001488 boolean containsDismissKeyguardWindow() {
1489 for (int i = mChildren.size() - 1; i >= 0; i--) {
1490 if ((mChildren.get(i).mAttrs.flags & FLAG_DISMISS_KEYGUARD) != 0) {
1491 return true;
1492 }
1493 }
1494 return false;
1495 }
1496
1497 boolean containsShowWhenLockedWindow() {
1498 for (int i = mChildren.size() - 1; i >= 0; i--) {
1499 if ((mChildren.get(i).mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
1500 return true;
1501 }
1502 }
1503 return false;
1504 }
1505
1506 void checkKeyguardFlagsChanged() {
1507 final boolean containsDismissKeyguard = containsDismissKeyguardWindow();
1508 final boolean containsShowWhenLocked = containsShowWhenLockedWindow();
1509 if (containsDismissKeyguard != mLastContainsDismissKeyguardWindow
1510 || containsShowWhenLocked != mLastContainsShowWhenLockedWindow) {
1511 mService.notifyKeyguardFlagsChanged(null /* callback */);
1512 }
1513 mLastContainsDismissKeyguardWindow = containsDismissKeyguard;
1514 mLastContainsShowWhenLockedWindow = containsShowWhenLocked;
1515 }
1516
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001517 WindowState getImeTargetBelowWindow(WindowState w) {
1518 final int index = mChildren.indexOf(w);
1519 if (index > 0) {
1520 final WindowState target = mChildren.get(index - 1);
1521 if (target.canBeImeTarget()) {
1522 return target;
1523 }
1524 }
1525 return null;
1526 }
1527
1528 WindowState getHighestAnimLayerWindow(WindowState currentTarget) {
1529 WindowState candidate = null;
1530 for (int i = mChildren.indexOf(currentTarget); i >= 0; i--) {
1531 final WindowState w = mChildren.get(i);
1532 if (w.mRemoved) {
1533 continue;
1534 }
1535 if (candidate == null || w.mWinAnimator.mAnimLayer >
1536 candidate.mWinAnimator.mAnimLayer) {
1537 candidate = w;
1538 }
1539 }
1540 return candidate;
1541 }
1542
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001543 /**
1544 * See {@link Activity#setDisablePreviewScreenshots}.
1545 */
1546 void setDisablePreviewScreenshots(boolean disable) {
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001547 mDisbalePreviewScreenshots = disable;
1548 }
1549
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001550 /**
1551 * Retrieves whether we'd like to generate a snapshot that's based solely on the theme. This is
1552 * the case when preview screenshots are disabled {@link #setDisablePreviewScreenshots} or when
1553 * we can't take a snapshot for other reasons, for example, if we have a secure window.
1554 *
1555 * @return True if we need to generate an app theme snapshot, false if we'd like to take a real
1556 * screenshot.
1557 */
1558 boolean shouldUseAppThemeSnapshot() {
1559 return mDisbalePreviewScreenshots || forAllWindows(w -> (w.mAttrs.flags & FLAG_SECURE) != 0,
1560 true /* topToBottom */);
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001561 }
1562
Wale Ogunwale51362492016-09-08 17:49:17 -07001563 @Override
Robert Carrdee1b3f2017-02-27 11:33:33 -08001564 int getAnimLayerAdjustment() {
1565 return mAppAnimator.animLayerAdjustment;
1566 }
1567
1568 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001569 void dump(PrintWriter pw, String prefix) {
1570 super.dump(pw, prefix);
1571 if (appToken != null) {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001572 pw.println(prefix + "app=true mVoiceInteraction=" + mVoiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001573 }
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001574 pw.print(prefix); pw.print("task="); pw.println(getTask());
Wale Ogunwale51362492016-09-08 17:49:17 -07001575 pw.print(prefix); pw.print(" mFillsParent="); pw.print(mFillsParent);
1576 pw.print(" mOrientation="); pw.println(mOrientation);
Wale Ogunwale89973222017-04-23 18:39:45 -07001577 pw.println(prefix + "hiddenRequested=" + hiddenRequested + " mClientHidden=" + mClientHidden
1578 + ((mDeferHidingClient) ? " mDeferHidingClient=" + mDeferHidingClient : "")
1579 + " reportedDrawn=" + reportedDrawn + " reportedVisible=" + reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -07001580 if (paused) {
1581 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001582 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001583 if (mAppStopped) {
1584 pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped);
1585 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001586 if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0
Craig Mautner6fbda632012-07-03 09:26:39 -07001587 || allDrawn || mAppAnimator.allDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001588 pw.print(prefix); pw.print("mNumInterestingWindows=");
1589 pw.print(mNumInterestingWindows);
1590 pw.print(" mNumDrawnWindows="); pw.print(mNumDrawnWindows);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001591 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -07001592 pw.print(" allDrawn="); pw.print(allDrawn);
1593 pw.print(" (animator="); pw.print(mAppAnimator.allDrawn);
1594 pw.println(")");
1595 }
1596 if (inPendingTransaction) {
1597 pw.print(prefix); pw.print("inPendingTransaction=");
1598 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001599 }
Craig Mautner799bc1d2015-01-14 10:33:48 -08001600 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001601 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
1602 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -08001603 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -08001604 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001605 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001606 if (startingWindow != null || startingSurface != null
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001607 || startingDisplayed || startingMoved) {
1608 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001609 pw.print(" startingSurface="); pw.print(startingSurface);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001610 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001611 pw.print(" startingMoved="); pw.println(startingMoved);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001612 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01001613 if (!mFrozenBounds.isEmpty()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -08001614 pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds);
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001615 pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig);
Chong Zhangd78ddb42016-03-02 17:01:14 -08001616 }
1617 if (mPendingRelaunchCount != 0) {
1618 pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount);
Jorim Jaggi0429f352015-12-22 16:29:16 +01001619 }
Wale Ogunwale9c64cb62017-04-12 13:39:59 -07001620 if (getController() != null) {
1621 pw.print(prefix); pw.print("controller="); pw.println(getController());
1622 }
Wale Ogunwalee287e192017-04-21 09:30:12 -07001623 if (mRemovingFromDisplay) {
1624 pw.println(prefix + "mRemovingFromDisplay=" + mRemovingFromDisplay);
1625 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001626 }
1627
1628 @Override
1629 public String toString() {
1630 if (stringName == null) {
1631 StringBuilder sb = new StringBuilder();
1632 sb.append("AppWindowToken{");
1633 sb.append(Integer.toHexString(System.identityHashCode(this)));
1634 sb.append(" token="); sb.append(token); sb.append('}');
1635 stringName = sb.toString();
1636 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001637 return stringName + ((mIsExiting) ? " mIsExiting=" : "");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001638 }
Jeff Browne9bdb312012-04-05 15:30:10 -07001639}