blob: 7deec051aad513f484ca146b48fd1d2a5f3c3e52 [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;
Jorim Jaggie4b0f282017-05-17 15:10:29 +020041import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW_VERBOSE;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070042import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TOKEN_MOVEMENT;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080043import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
44import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_MOVEMENT;
45import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
46import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Chong Zhang92147042016-05-09 12:47:11 -070047import static com.android.server.wm.WindowManagerService.H.NOTIFY_ACTIVITY_DRAWN;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070048import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070049import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070050import static com.android.server.wm.WindowManagerService.logWithStack;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080051
Filip Gruszczynskia590c992015-11-25 16:45:26 -080052import android.annotation.NonNull;
Jorim Jaggid635a4a2017-05-03 15:21:26 +020053import android.app.Activity;
Jorim Jaggi26c8c422016-05-09 19:57:25 -070054import android.content.res.Configuration;
Jorim Jaggi0429f352015-12-22 16:29:16 +010055import android.graphics.Rect;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070056import android.os.Binder;
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;
Wale Ogunwale6c459212017-05-17 08:56:03 -0700158 // True if the hidden state of this token was forced to false due to a transferred starting
159 // window.
160 private boolean mHiddenSetFromTransferredStartingWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800161 boolean firstWindowDrawn;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700162 private final WindowState.UpdateReportedVisibilityResults mReportedVisibilityResults =
163 new WindowState.UpdateReportedVisibilityResults();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800164
165 // Input application handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700166 final InputApplicationHandle mInputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800167
Wale Ogunwale571771c2016-08-26 13:18:50 -0700168 // TODO: Have a WindowContainer state for tracking exiting/deferred removal.
Craig Mautner799bc1d2015-01-14 10:33:48 -0800169 boolean mIsExiting;
Craig Mautner9ef471f2014-02-07 13:11:47 -0800170
Craig Mautnerbb742462014-07-07 15:28:55 -0700171 boolean mLaunchTaskBehind;
Craig Mautner8746a472014-07-24 15:12:54 -0700172 boolean mEnteringAnimation;
Craig Mautnerbb742462014-07-07 15:28:55 -0700173
Wale Ogunwale72919d22016-12-08 18:58:50 -0800174 private boolean mAlwaysFocusable;
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800175
Robert Carre12aece2016-02-02 22:43:27 -0800176 boolean mAppStopped;
Robert Carrfd10cd12016-06-29 16:41:50 -0700177 int mRotationAnimationHint;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700178 private int mPendingRelaunchCount;
Robert Carre12aece2016-02-02 22:43:27 -0800179
Jorim Jaggife762342016-10-13 14:33:27 +0200180 private boolean mLastContainsShowWhenLockedWindow;
181 private boolean mLastContainsDismissKeyguardWindow;
182
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700183 // The bounds of this activity. Mainly used for aspect-ratio compatibility.
184 // TODO(b/36505427): Every level on WindowContainer now has bounds information, which directly
185 // affects the configuration. We should probably move this into that class.
186 private final Rect mBounds = new Rect();
187
Jorim Jaggi0429f352015-12-22 16:29:16 +0100188 ArrayDeque<Rect> mFrozenBounds = new ArrayDeque<>();
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700189 ArrayDeque<Configuration> mFrozenMergedConfig = new ArrayDeque<>();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100190
Wale Ogunwale6c459212017-05-17 08:56:03 -0700191 private boolean mDisablePreviewScreenshots;
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +0100192
Robert Carred3e83b2017-04-21 13:26:55 -0700193 Task mLastParent;
194
Wale Ogunwale72919d22016-12-08 18:58:50 -0800195 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
196 DisplayContent dc, long inputDispatchingTimeoutNanos, boolean fullscreen,
197 boolean showForAllUsers, int targetSdk, int orientation, int rotationAnimationHint,
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800198 int configChanges, boolean launchTaskBehind, boolean alwaysFocusable,
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700199 AppWindowContainerController controller, Configuration overrideConfig, Rect bounds) {
200 this(service, token, voiceInteraction, dc, fullscreen, overrideConfig, bounds);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800201 setController(controller);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800202 mInputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800203 mShowForAllUsers = showForAllUsers;
204 mTargetSdk = targetSdk;
205 mOrientation = orientation;
206 layoutConfigChanges = (configChanges & (CONFIG_SCREEN_SIZE | CONFIG_ORIENTATION)) != 0;
207 mLaunchTaskBehind = launchTaskBehind;
208 mAlwaysFocusable = alwaysFocusable;
209 mRotationAnimationHint = rotationAnimationHint;
210
211 // Application tokens start out hidden.
212 hidden = true;
213 hiddenRequested = true;
214 }
215
216 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700217 DisplayContent dc, boolean fillsParent, Configuration overrideConfig, Rect bounds) {
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800218 super(service, token != null ? token.asBinder() : null, TYPE_APPLICATION, true, dc,
219 false /* ownerCanManageAppTokens */);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700220 appToken = token;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800221 mVoiceInteraction = voiceInteraction;
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800222 mFillsParent = fillsParent;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800223 mInputApplicationHandle = new InputApplicationHandle(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700224 mAppAnimator = new AppWindowAnimator(this, service);
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700225 if (overrideConfig != null) {
226 onOverrideConfigurationChanged(overrideConfig);
227 }
228 if (bounds != null) {
229 mBounds.set(bounds);
230 }
231 }
232
233 void onOverrideConfigurationChanged(Configuration overrideConfiguration, Rect bounds) {
234 onOverrideConfigurationChanged(overrideConfiguration);
235 if (mBounds.equals(bounds)) {
236 return;
237 }
238 // TODO(b/36505427): If bounds is in WC, then we can automatically call onResize() when set.
239 mBounds.set(bounds);
240 onResize();
241 }
242
243 void getBounds(Rect outBounds) {
244 outBounds.set(mBounds);
245 }
246
247 boolean hasBounds() {
248 return !mBounds.isEmpty();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800249 }
250
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800251 void onFirstWindowDrawn(WindowState win, WindowStateAnimator winAnimator) {
252 firstWindowDrawn = true;
253
254 // We now have a good window to show, remove dead placeholders
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700255 removeDeadWindows();
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800256
Jorim Jaggi02886a82016-12-06 09:10:06 -0800257 if (startingWindow != null) {
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800258 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, "Finish starting "
259 + win.mToken + ": first real window is shown, no animation");
260 // If this initial window is animating, stop it -- we will do an animation to reveal
261 // it from behind the starting window, so there is no need for it to also be doing its
262 // own stuff.
263 winAnimator.clearAnimation();
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800264 if (getController() != null) {
265 getController().removeStartingWindow();
266 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800267 }
268 updateReportedVisibilityLocked();
269 }
270
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800271 void updateReportedVisibilityLocked() {
272 if (appToken == null) {
273 return;
274 }
275
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700276 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700277 final int count = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800278
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700279 mReportedVisibilityResults.reset();
280
281 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700282 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700283 win.updateReportedVisibility(mReportedVisibilityResults);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800284 }
285
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700286 int numInteresting = mReportedVisibilityResults.numInteresting;
287 int numVisible = mReportedVisibilityResults.numVisible;
288 int numDrawn = mReportedVisibilityResults.numDrawn;
289 boolean nowGone = mReportedVisibilityResults.nowGone;
290
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700291 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800292 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700293 if (!nowGone) {
294 // If the app is not yet gone, then it can only become visible/drawn.
295 if (!nowDrawn) {
296 nowDrawn = reportedDrawn;
297 }
298 if (!nowVisible) {
299 nowVisible = reportedVisible;
300 }
301 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800302 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800303 + numInteresting + " visible=" + numVisible);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800304 final AppWindowContainerController controller = getController();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700305 if (nowDrawn != reportedDrawn) {
306 if (nowDrawn) {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800307 if (controller != null) {
308 controller.reportWindowsDrawn();
309 }
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700310 }
311 reportedDrawn = nowDrawn;
312 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800313 if (nowVisible != reportedVisible) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700314 if (DEBUG_VISIBILITY) Slog.v(TAG,
315 "Visibility changed in " + this + ": vis=" + nowVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800316 reportedVisible = nowVisible;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800317 if (controller != null) {
318 if (nowVisible) {
319 controller.reportWindowsVisible();
320 } else {
321 controller.reportWindowsGone();
322 }
323 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800324 }
325 }
326
Wale Ogunwale89973222017-04-23 18:39:45 -0700327 boolean isClientHidden() {
328 return mClientHidden;
329 }
330
331 void setClientHidden(boolean hideClient) {
332 if (mClientHidden == hideClient || (hideClient && mDeferHidingClient)) {
333 return;
334 }
335 mClientHidden = hideClient;
336 sendAppVisibilityToClients();
337 }
338
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700339 boolean setVisibility(WindowManager.LayoutParams lp,
340 boolean visible, int transit, boolean performLayout, boolean isVoiceInteraction) {
341
342 boolean delayed = false;
343 inPendingTransaction = false;
Wale Ogunwale9e4721f2017-05-23 19:37:30 -0700344 // Reset the state of mHiddenSetFromTransferredStartingWindow since visibility is actually
345 // been set by the app now.
346 mHiddenSetFromTransferredStartingWindow = false;
Wale Ogunwale89973222017-04-23 18:39:45 -0700347 setClientHidden(!visible);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700348
349 // Allow for state changes and animation to be applied if:
350 // * token is transitioning visibility state
351 // * or the token was marked as hidden and is exiting before we had a chance to play the
352 // transition animation
353 // * or this is an opening app and windows are being replaced.
354 boolean visibilityChanged = false;
355 if (hidden == visible || (hidden && mIsExiting) || (visible && waitingForReplacement())) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700356 final AccessibilityController accessibilityController = mService.mAccessibilityController;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700357 boolean changed = false;
358 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
359 "Changing app " + this + " hidden=" + hidden + " performLayout=" + performLayout);
360
361 boolean runningAppAnimation = false;
362
363 if (transit != AppTransition.TRANSIT_UNSET) {
364 if (mAppAnimator.animation == AppWindowAnimator.sDummyAnimation) {
365 mAppAnimator.setNullAnimation();
366 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700367 if (mService.applyAnimationLocked(this, lp, transit, visible, isVoiceInteraction)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700368 delayed = runningAppAnimation = true;
369 }
370 final WindowState window = findMainWindow();
371 //TODO (multidisplay): Magnification is supported only for the default display.
372 if (window != null && accessibilityController != null
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700373 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700374 accessibilityController.onAppWindowTransitionLocked(window, transit);
375 }
376 changed = true;
377 }
378
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700379 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700380 for (int i = 0; i < windowsCount; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700381 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700382 changed |= win.onAppVisibilityChanged(visible, runningAppAnimation);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700383 }
384
385 hidden = hiddenRequested = !visible;
386 visibilityChanged = true;
387 if (!visible) {
388 stopFreezingScreen(true, true);
389 } else {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700390 // If we are being set visible, and the starting window is not yet displayed,
391 // then make sure it doesn't get displayed.
392 if (startingWindow != null && !startingWindow.isDrawnLw()) {
393 startingWindow.mPolicyVisibility = false;
394 startingWindow.mPolicyVisibilityAfterAnim = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700395 }
396 }
397
398 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setVisibility: " + this
399 + ": hidden=" + hidden + " hiddenRequested=" + hiddenRequested);
400
401 if (changed) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700402 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700403 if (performLayout) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700404 mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700405 false /*updateInputWindows*/);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700406 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700407 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700408 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700409 }
410 }
411
412 if (mAppAnimator.animation != null) {
413 delayed = true;
414 }
415
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700416 for (int i = mChildren.size() - 1; i >= 0 && !delayed; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700417 if ((mChildren.get(i)).isWindowAnimationSet()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700418 delayed = true;
419 }
420 }
421
422 if (visibilityChanged) {
423 if (visible && !delayed) {
424 // The token was made immediately visible, there will be no entrance animation.
425 // We need to inform the client the enter animation was finished.
426 mEnteringAnimation = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700427 mService.mActivityManagerAppTransitionNotifier.onAppTransitionFinishedLocked(token);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700428 }
Robert Carre7cc44d2017-03-20 19:04:30 -0700429 // If we are hidden but there is no delay needed we immediately
430 // apply the Surface transaction so that the ActivityManager
431 // can have some guarantee on the Surface state
432 // following setting the visibility.
Robert Carr6914f082017-03-20 19:04:30 -0700433 if (hidden && !delayed) {
434 SurfaceControl.openTransaction();
435 for (int i = mChildren.size() - 1; i >= 0; i--) {
436 mChildren.get(i).mWinAnimator.hide("immediately hidden");
437 }
438 SurfaceControl.closeTransaction();
439 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700440
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700441 if (!mService.mClosingApps.contains(this) && !mService.mOpeningApps.contains(this)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700442 // The token is not closing nor opening, so even if there is an animation set, that
443 // doesn't mean that it goes through the normal app transition cycle so we have
444 // to inform the docked controller about visibility change.
Andrii Kulian1e32e022016-09-16 15:29:34 -0700445 // TODO(multi-display): notify docked divider on all displays where visibility was
446 // affected.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700447 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700448 .notifyAppVisibilityChanged();
Jorim Jaggi8b702ed2017-01-20 16:59:03 +0100449 mService.mTaskSnapshotController.notifyAppVisibilityChanged(this, visible);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700450 }
451 }
452
453 return delayed;
454 }
455
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800456 WindowState findMainWindow() {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700457 WindowState candidate = null;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700458 int j = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800459 while (j > 0) {
460 j--;
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700461 final WindowState win = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700462 final int type = win.mAttrs.type;
463 // No need to loop through child window as base application and starting types can't be
464 // child windows.
465 if (type == TYPE_BASE_APPLICATION || type == TYPE_APPLICATION_STARTING) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700466 // In cases where there are multiple windows, we prefer the non-exiting window. This
Sungsoo Lim0d3d1f82015-12-02 14:47:59 +0900467 // happens for example when replacing windows during an activity relaunch. When
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700468 // constructing the animation, we want the new window, not the exiting one.
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800469 if (win.mAnimatingExit) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700470 candidate = win;
471 } else {
472 return win;
473 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800474 }
475 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700476 return candidate;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800477 }
478
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800479 boolean windowsAreFocusable() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800480 return StackId.canReceiveKeys(getTask().mStack.mStackId) || mAlwaysFocusable;
Wale Ogunwaled045c822015-12-02 09:14:28 -0800481 }
482
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800483 AppWindowContainerController getController() {
484 final WindowContainerController controller = super.getController();
485 return controller != null ? (AppWindowContainerController) controller : null;
486 }
487
Wale Ogunwale571771c2016-08-26 13:18:50 -0700488 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -0700489 boolean isVisible() {
Wale Ogunwalee471be62016-10-03 07:53:55 -0700490 // If the app token isn't hidden then it is considered visible and there is no need to check
491 // its children windows to see if they are visible.
492 return !hidden;
Wale Ogunwale44f21802016-09-02 12:49:48 -0700493 }
494
495 @Override
Wale Ogunwalee287e192017-04-21 09:30:12 -0700496 void removeImmediately() {
497 onRemovedFromDisplay();
498 super.removeImmediately();
499 }
500
501 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -0700502 void removeIfPossible() {
Craig Mautnere3119b72015-01-20 15:02:36 -0800503 mIsExiting = false;
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800504 removeAllWindowsIfPossible();
Bryce Lee6d410262017-02-28 15:30:17 -0800505 removeImmediately();
Craig Mautnere3119b72015-01-20 15:02:36 -0800506 }
507
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700508 @Override
509 boolean checkCompleteDeferredRemoval() {
510 if (mIsExiting) {
511 removeIfPossible();
512 }
513 return super.checkCompleteDeferredRemoval();
514 }
515
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700516 void onRemovedFromDisplay() {
Wale Ogunwalee287e192017-04-21 09:30:12 -0700517 if (mRemovingFromDisplay) {
518 return;
519 }
520 mRemovingFromDisplay = true;
521
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700522 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app token: " + this);
523
Wale Ogunwale72919d22016-12-08 18:58:50 -0800524 boolean delayed = setVisibility(null, false, TRANSIT_UNSET, true, mVoiceInteraction);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700525
526 mService.mOpeningApps.remove(this);
Jorim Jaggi1b4b23e2016-11-15 16:30:12 -0800527 mService.mUnknownAppVisibilityController.appRemoved(this);
Jorim Jaggi10abe2f2017-01-03 16:44:46 +0100528 mService.mTaskSnapshotController.onAppRemoved(this);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700529 waitingToShow = false;
530 if (mService.mClosingApps.contains(this)) {
531 delayed = true;
532 } else if (mService.mAppTransition.isTransitionSet()) {
533 mService.mClosingApps.add(this);
534 delayed = true;
535 }
536
537 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app " + this + " delayed=" + delayed
538 + " animation=" + mAppAnimator.animation + " animating=" + mAppAnimator.animating);
539
540 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM, "removeAppToken: "
541 + this + " delayed=" + delayed + " Callers=" + Debug.getCallers(4));
542
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800543 if (startingData != null && getController() != null) {
544 getController().removeStartingWindow();
545 }
546
Winson Chung87e5d552017-04-05 11:49:38 -0700547 // If this window was animating, then we need to ensure that the app transition notifies
548 // that animations have completed in WMS.handleAnimatingStoppedAndTransitionLocked(), so
549 // add to that list now
550 if (mAppAnimator.animating) {
551 mService.mNoAnimationNotifyOnTransitionFinished.add(token);
552 }
553
Wale Ogunwalee287e192017-04-21 09:30:12 -0700554 final TaskStack stack = getStack();
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700555 if (delayed && !isEmpty()) {
556 // set the token aside because it has an active animation to be finished
557 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM,
558 "removeAppToken make exiting: " + this);
Wale Ogunwalee287e192017-04-21 09:30:12 -0700559 if (stack != null) {
560 stack.mExitingAppTokens.add(this);
561 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700562 mIsExiting = true;
563 } else {
564 // Make sure there is no animation running on this token, so any windows associated
565 // with it will be removed as soon as their animations are complete
566 mAppAnimator.clearAnimation();
567 mAppAnimator.animating = false;
Wale Ogunwale3106ae012017-05-16 08:56:37 -0700568 if (stack != null) {
569 stack.mExitingAppTokens.remove(this);
570 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700571 removeIfPossible();
572 }
573
574 removed = true;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700575 stopFreezingScreen(true, true);
Bryce Lee6d410262017-02-28 15:30:17 -0800576
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700577 if (mService.mFocusedApp == this) {
578 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "Removing focused app token:" + this);
579 mService.mFocusedApp = null;
580 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
581 mService.mInputMonitor.setFocusedAppLw(null);
582 }
583
584 if (!delayed) {
585 updateReportedVisibilityLocked();
586 }
Wale Ogunwalee287e192017-04-21 09:30:12 -0700587
588 mRemovingFromDisplay = false;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700589 }
590
Chong Zhange05bcb12016-07-26 17:47:29 -0700591 void clearAnimatingFlags() {
Chong Zhangb0d26702016-08-12 16:03:29 -0700592 boolean wallpaperMightChange = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700593 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700594 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700595 wallpaperMightChange |= win.clearAnimatingFlags();
Chong Zhange05bcb12016-07-26 17:47:29 -0700596 }
Chong Zhangb0d26702016-08-12 16:03:29 -0700597 if (wallpaperMightChange) {
598 requestUpdateWallpaperIfNeeded();
599 }
Chong Zhange05bcb12016-07-26 17:47:29 -0700600 }
601
Robert Carre12aece2016-02-02 22:43:27 -0800602 void destroySurfaces() {
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700603 destroySurfaces(false /*cleanupOnResume*/);
604 }
605
606 /**
607 * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure
608 * the client has finished with them.
609 *
610 * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If
611 * set to true, destroy only surfaces of removed windows, and clear relevant flags of the
612 * others so that they are ready to be reused. If set to false (common case), destroy all
613 * surfaces that's eligible, if the app is already stopped.
614 */
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700615 private void destroySurfaces(boolean cleanupOnResume) {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700616 boolean destroyedSomething = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700617 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700618 final WindowState win = mChildren.get(i);
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700619 destroyedSomething |= win.destroySurface(cleanupOnResume, mAppStopped);
Robert Carre12aece2016-02-02 22:43:27 -0800620 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700621 if (destroyedSomething) {
622 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700623 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Robert Carre12aece2016-02-02 22:43:27 -0800624 }
625 }
626
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800627 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700628 * Notify that the app is now resumed, and it was not stopped before, perform a clean
629 * up of the surfaces
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800630 */
Jorim Jaggibae01b12017-04-11 16:29:10 -0700631 void notifyAppResumed(boolean wasStopped) {
Chong Zhangad24f962016-08-25 12:12:33 -0700632 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped
Jorim Jaggibae01b12017-04-11 16:29:10 -0700633 + " " + this);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700634 mAppStopped = false;
635 if (!wasStopped) {
636 destroySurfaces(true /*cleanupOnResume*/);
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800637 }
Robert Carre12aece2016-02-02 22:43:27 -0800638 }
639
Chong Zhangbef461f2015-10-27 11:38:24 -0700640 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700641 * Notify that the app has stopped, and it is okay to destroy any surfaces which were
642 * keeping alive in case they were still being used.
643 */
644 void notifyAppStopped() {
645 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this);
646 mAppStopped = true;
647 destroySurfaces();
648 // Remove any starting window that was added for this app if they are still around.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800649 if (getController() != null) {
650 getController().removeStartingWindow();
651 }
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700652 }
653
654 /**
Chong Zhangbef461f2015-10-27 11:38:24 -0700655 * Checks whether we should save surfaces for this app.
656 *
657 * @return true if the surfaces should be saved, false otherwise.
658 */
659 boolean shouldSaveSurface() {
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800660 // We want to save surface if the app's windows are "allDrawn".
661 // (If we started entering animation early with saved surfaces, allDrawn
662 // should have been restored to true. So we'll save again in that case
663 // even if app didn't actually finish drawing.)
664 return allDrawn;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800665 }
666
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700667 private boolean canRestoreSurfaces() {
668 for (int i = mChildren.size() -1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700669 final WindowState w = mChildren.get(i);
Chong Zhang92147042016-05-09 12:47:11 -0700670 if (w.canRestoreSurface()) {
Robert Carr13f7be9e2015-12-02 18:39:45 -0800671 return true;
672 }
Chong Zhangbef461f2015-10-27 11:38:24 -0700673 }
674 return false;
675 }
676
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700677 private void clearWasVisibleBeforeClientHidden() {
678 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700679 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700680 w.clearWasVisibleBeforeClientHidden();
Chong Zhang92147042016-05-09 12:47:11 -0700681 }
682 }
683
Chong Zhang8e4bda92016-05-04 15:08:18 -0700684 /**
685 * Whether the app has some window that is invisible in layout, but
686 * animating with saved surface.
687 */
688 boolean isAnimatingInvisibleWithSavedSurface() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700689 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700690 final WindowState w = mChildren.get(i);
Chong Zhang8e4bda92016-05-04 15:08:18 -0700691 if (w.isAnimatingInvisibleWithSavedSurface()) {
692 return true;
693 }
694 }
695 return false;
696 }
697
698 /**
699 * Hide all window surfaces that's still invisible in layout but animating
700 * with a saved surface, and mark them destroying.
701 */
702 void stopUsingSavedSurfaceLocked() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700703 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700704 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700705 w.stopUsingSavedSurface();
Chong Zhang8e4bda92016-05-04 15:08:18 -0700706 }
707 destroySurfaces();
708 }
709
Chong Zhangf58631a2016-05-24 16:02:10 -0700710 void markSavedSurfaceExiting() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700711 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700712 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700713 w.markSavedSurfaceExiting();
Chong Zhangf58631a2016-05-24 16:02:10 -0700714 }
715 }
716
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700717 void restoreSavedSurfaceForInterestingWindows() {
Chong Zhang92147042016-05-09 12:47:11 -0700718 if (!canRestoreSurfaces()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700719 clearWasVisibleBeforeClientHidden();
Chong Zhangbef461f2015-10-27 11:38:24 -0700720 return;
721 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700722
723 // Check if all interesting windows are drawn and we can mark allDrawn=true.
724 int interestingNotDrawn = -1;
725
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700726 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700727 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700728 interestingNotDrawn = w.restoreSavedSurfaceForInterestingWindow();
Chong Zhangbef461f2015-10-27 11:38:24 -0700729 }
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800730
Chong Zhang92147042016-05-09 12:47:11 -0700731 if (!allDrawn) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700732 allDrawn = (interestingNotDrawn == 0);
Chong Zhang92147042016-05-09 12:47:11 -0700733 if (allDrawn) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700734 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Chong Zhang92147042016-05-09 12:47:11 -0700735 }
736 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700737 clearWasVisibleBeforeClientHidden();
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800738
739 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700740 "restoreSavedSurfaceForInterestingWindows: " + this + " allDrawn=" + allDrawn
741 + " interestingNotDrawn=" + interestingNotDrawn);
Chong Zhangbef461f2015-10-27 11:38:24 -0700742 }
743
744 void destroySavedSurfaces() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700745 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700746 final WindowState win = mChildren.get(i);
Robert Carr13f7be9e2015-12-02 18:39:45 -0800747 win.destroySavedSurface();
Chong Zhangbef461f2015-10-27 11:38:24 -0700748 }
Chong Zhang92147042016-05-09 12:47:11 -0700749 }
750
751 void clearAllDrawn() {
752 allDrawn = false;
753 deferClearAllDrawn = false;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700754 allDrawnExcludingSaved = false;
Chong Zhangbef461f2015-10-27 11:38:24 -0700755 }
756
Bryce Lee6d410262017-02-28 15:30:17 -0800757 Task getTask() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800758 return (Task) getParent();
Bryce Lee6d410262017-02-28 15:30:17 -0800759 }
760
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800761 TaskStack getStack() {
762 final Task task = getTask();
763 if (task != null) {
764 return task.mStack;
765 } else {
766 return null;
767 }
768 }
769
Bryce Lee6d410262017-02-28 15:30:17 -0800770 @Override
771 void onParentSet() {
772 super.onParentSet();
773
Robert Carred3e83b2017-04-21 13:26:55 -0700774 final Task task = getTask();
775
Bryce Lee6d410262017-02-28 15:30:17 -0800776 // When the associated task is {@code null}, the {@link AppWindowToken} can no longer
777 // access visual elements like the {@link DisplayContent}. We must remove any associations
778 // such as animations.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800779 if (!mReparenting) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800780 if (task == null) {
781 // It is possible we have been marked as a closing app earlier. We must remove ourselves
782 // from this list so we do not participate in any future animations.
783 mService.mClosingApps.remove(this);
Robert Carred3e83b2017-04-21 13:26:55 -0700784 } else if (mLastParent != null && mLastParent.mStack != null) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800785 task.mStack.mExitingAppTokens.remove(this);
786 }
Bryce Lee6d410262017-02-28 15:30:17 -0800787 }
Robert Carred3e83b2017-04-21 13:26:55 -0700788 mLastParent = task;
Bryce Lee6d410262017-02-28 15:30:17 -0800789 }
790
Wale Ogunwalefa854eb2016-09-20 13:43:52 -0700791 void postWindowRemoveStartingWindowCleanup(WindowState win) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700792 // TODO: Something smells about the code below...Is there a better way?
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700793 if (startingWindow == win) {
794 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800795 if (getController() != null) {
796 getController().removeStartingWindow();
797 }
Wale Ogunwale6c459212017-05-17 08:56:03 -0700798 } else if (mChildren.size() == 0) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700799 // If this is the last window and we had requested a starting transition window,
800 // well there is no point now.
Jorim Jaggi02886a82016-12-06 09:10:06 -0800801 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingData");
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700802 startingData = null;
Wale Ogunwale6c459212017-05-17 08:56:03 -0700803 if (mHiddenSetFromTransferredStartingWindow) {
804 // We set the hidden state to false for the token from a transferred starting window.
805 // We now reset it back to true since the starting window was the last window in the
806 // token.
807 hidden = true;
808 }
Jorim Jaggi829b9cd2017-01-23 16:20:53 +0100809 } else if (mChildren.size() == 1 && startingSurface != null && !isRelaunching()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700810 // If this is the last window except for a starting transition window,
811 // we need to get rid of the starting transition.
Jorim Jaggie4b0f282017-05-17 15:10:29 +0200812 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Last window, removing starting window "
813 + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800814 if (getController() != null) {
815 getController().removeStartingWindow();
816 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700817 }
818 }
819
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700820 void removeDeadWindows() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700821 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700822 WindowState win = mChildren.get(winNdx);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800823 if (win.mAppDied) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700824 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700825 "removeDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800826 // Set mDestroying, we don't want any animation or delayed removal here.
827 win.mDestroying = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700828 // Also removes child windows.
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700829 win.removeIfPossible();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800830 }
831 }
832 }
833
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700834 boolean hasWindowsAlive() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700835 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700836 // No need to loop through child windows as the answer should be the same as that of the
837 // parent window.
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700838 if (!(mChildren.get(i)).mAppDied) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700839 return true;
840 }
841 }
842 return false;
843 }
844
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700845 void setWillReplaceWindows(boolean animate) {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700846 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
847 "Marking app token " + this + " with replacing windows.");
Robert Carra1eb4392015-12-10 12:43:51 -0800848
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700849 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700850 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700851 w.setWillReplaceWindow(animate);
Robert Carra1eb4392015-12-10 12:43:51 -0800852 }
853 if (animate) {
854 // Set-up dummy animation so we can start treating windows associated with this
855 // token like they are in transition before the new app window is ready for us to
856 // run the real transition animation.
857 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700858 "setWillReplaceWindow() Setting dummy animation on: " + this);
Robert Carra1eb4392015-12-10 12:43:51 -0800859 mAppAnimator.setDummyAnimation();
860 }
861 }
862
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700863 void setWillReplaceChildWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700864 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this
Robert Carr23fa16b2016-01-13 13:19:58 -0800865 + " with replacing child windows.");
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700866 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700867 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700868 w.setWillReplaceChildWindows();
Robert Carr23fa16b2016-01-13 13:19:58 -0800869 }
870 }
871
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700872 void clearWillReplaceWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700873 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
874 "Resetting app token " + this + " of replacing window marks.");
Chong Zhangf596cd52016-01-05 13:42:44 -0800875
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700876 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700877 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700878 w.clearWillReplaceWindow();
Chong Zhangf596cd52016-01-05 13:42:44 -0800879 }
880 }
881
Chong Zhang4d7369a2016-04-25 16:09:14 -0700882 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700883 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700884 final WindowState w = mChildren.get(i);
Chong Zhang4d7369a2016-04-25 16:09:14 -0700885 w.requestUpdateWallpaperIfNeeded();
886 }
887 }
888
Chong Zhangd78ddb42016-03-02 17:01:14 -0800889 boolean isRelaunching() {
890 return mPendingRelaunchCount > 0;
891 }
892
893 void startRelaunching() {
894 if (canFreezeBounds()) {
895 freezeBounds();
896 }
Robert Carrd5c7dd62017-03-08 10:39:30 -0800897
898 // In the process of tearing down before relaunching, the app will
899 // try and clean up it's child surfaces. We need to prevent this from
900 // happening, so we sever the children, transfering their ownership
901 // from the client it-self to the parent surface (owned by us).
902 for (int i = mChildren.size() - 1; i >= 0; i--) {
903 final WindowState w = mChildren.get(i);
904 w.mWinAnimator.detachChildren();
905 }
906
Chong Zhangd78ddb42016-03-02 17:01:14 -0800907 mPendingRelaunchCount++;
908 }
909
910 void finishRelaunching() {
911 if (canFreezeBounds()) {
912 unfreezeBounds();
913 }
914 if (mPendingRelaunchCount > 0) {
915 mPendingRelaunchCount--;
Bryce Lee081554b2017-05-25 07:52:12 -0700916 } else {
917 // Update keyguard flags upon finishing relaunch.
918 checkKeyguardFlagsChanged();
Chong Zhangd78ddb42016-03-02 17:01:14 -0800919 }
Bryce Lee081554b2017-05-25 07:52:12 -0700920
Matthew Ng498c71d2017-04-18 13:55:45 -0700921 updateAllDrawn();
Chong Zhangd78ddb42016-03-02 17:01:14 -0800922 }
923
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700924 void clearRelaunching() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700925 if (mPendingRelaunchCount == 0) {
926 return;
927 }
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700928 if (canFreezeBounds()) {
929 unfreezeBounds();
930 }
931 mPendingRelaunchCount = 0;
932 }
933
Wale Ogunwale07bcab72016-10-14 15:30:09 -0700934 /**
935 * Returns true if the new child window we are adding to this token is considered greater than
936 * the existing child window in this token in terms of z-order.
937 */
938 @Override
939 protected boolean isFirstChildWindowGreaterThanSecond(WindowState newWindow,
940 WindowState existingWindow) {
941 final int type1 = newWindow.mAttrs.type;
942 final int type2 = existingWindow.mAttrs.type;
943
944 // Base application windows should be z-ordered BELOW all other windows in the app token.
945 if (type1 == TYPE_BASE_APPLICATION && type2 != TYPE_BASE_APPLICATION) {
946 return false;
947 } else if (type1 != TYPE_BASE_APPLICATION && type2 == TYPE_BASE_APPLICATION) {
948 return true;
949 }
950
951 // Starting windows should be z-ordered ABOVE all other windows in the app token.
952 if (type1 == TYPE_APPLICATION_STARTING && type2 != TYPE_APPLICATION_STARTING) {
953 return true;
954 } else if (type1 != TYPE_APPLICATION_STARTING && type2 == TYPE_APPLICATION_STARTING) {
955 return false;
956 }
957
958 // Otherwise the new window is greater than the existing window.
959 return true;
960 }
961
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700962 @Override
Robert Carra1eb4392015-12-10 12:43:51 -0800963 void addWindow(WindowState w) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700964 super.addWindow(w);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700965
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700966 boolean gotReplacementWindow = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700967 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700968 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700969 gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w);
970 }
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700971
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700972 // if we got a replacement window, reset the timeout to give drawing more time
973 if (gotReplacementWindow) {
974 mService.scheduleWindowReplacementTimeouts(this);
Robert Carra1eb4392015-12-10 12:43:51 -0800975 }
Jorim Jaggife762342016-10-13 14:33:27 +0200976 checkKeyguardFlagsChanged();
977 }
978
979 @Override
980 void removeChild(WindowState child) {
981 super.removeChild(child);
982 checkKeyguardFlagsChanged();
Robert Carra1eb4392015-12-10 12:43:51 -0800983 }
984
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700985 private boolean waitingForReplacement() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700986 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700987 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700988 if (candidate.waitingForReplacement()) {
Robert Carra1eb4392015-12-10 12:43:51 -0800989 return true;
990 }
991 }
992 return false;
993 }
994
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700995 void onWindowReplacementTimeout() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700996 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700997 (mChildren.get(i)).onWindowReplacementTimeout();
Robert Carra1eb4392015-12-10 12:43:51 -0800998 }
999 }
1000
Winson Chung30480042017-01-26 10:55:34 -08001001 void reparent(Task task, int position) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001002 final Task currentTask = getTask();
1003 if (task == currentTask) {
Winson Chung30480042017-01-26 10:55:34 -08001004 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001005 "window token=" + this + " already child of task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -08001006 }
Bryce Lee6d410262017-02-28 15:30:17 -08001007
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001008 if (currentTask.mStack != task.mStack) {
Bryce Lee6d410262017-02-28 15:30:17 -08001009 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001010 "window token=" + this + " current task=" + currentTask
Bryce Lee6d410262017-02-28 15:30:17 -08001011 + " belongs to a different stack than " + task);
1012 }
1013
Winson Chung30480042017-01-26 10:55:34 -08001014 if (DEBUG_ADD_REMOVE) Slog.i(TAG, "reParentWindowToken: removing window token=" + this
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001015 + " from task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -08001016 final DisplayContent prevDisplayContent = getDisplayContent();
1017
Bryce Lee6d410262017-02-28 15:30:17 -08001018 mReparenting = true;
1019
Winson Chung30480042017-01-26 10:55:34 -08001020 getParent().removeChild(this);
1021 task.addChild(this, position);
1022
Bryce Lee6d410262017-02-28 15:30:17 -08001023 mReparenting = false;
1024
Winson Chung30480042017-01-26 10:55:34 -08001025 // Relayout display(s).
1026 final DisplayContent displayContent = task.getDisplayContent();
1027 displayContent.setLayoutNeeded();
1028 if (prevDisplayContent != displayContent) {
1029 onDisplayChanged(displayContent);
1030 prevDisplayContent.setLayoutNeeded();
1031 }
1032 }
1033
Chong Zhangd78ddb42016-03-02 17:01:14 -08001034 private boolean canFreezeBounds() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001035 final Task task = getTask();
1036
Chong Zhangd78ddb42016-03-02 17:01:14 -08001037 // For freeform windows, we can't freeze the bounds at the moment because this would make
1038 // the resizing unresponsive.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001039 return task != null && !task.inFreeformWorkspace();
Chong Zhangd78ddb42016-03-02 17:01:14 -08001040 }
1041
Jorim Jaggi0429f352015-12-22 16:29:16 +01001042 /**
1043 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
1044 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
1045 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
1046 * with a queue.
1047 */
Chong Zhangd78ddb42016-03-02 17:01:14 -08001048 private void freezeBounds() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001049 final Task task = getTask();
1050 mFrozenBounds.offer(new Rect(task.mPreparedFrozenBounds));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001051
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001052 if (task.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) {
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001053 // We didn't call prepareFreezingBounds on the task, so use the current value.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001054 mFrozenMergedConfig.offer(new Configuration(task.getConfiguration()));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001055 } else {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001056 mFrozenMergedConfig.offer(new Configuration(task.mPreparedFrozenMergedConfig));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001057 }
Andrii Kulianb10330d2016-09-16 13:51:46 -07001058 // Calling unset() to make it equal to Configuration.EMPTY.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001059 task.mPreparedFrozenMergedConfig.unset();
Jorim Jaggi0429f352015-12-22 16:29:16 +01001060 }
1061
1062 /**
1063 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
1064 */
Chong Zhangd78ddb42016-03-02 17:01:14 -08001065 private void unfreezeBounds() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -07001066 if (!mFrozenBounds.isEmpty()) {
1067 mFrozenBounds.remove();
1068 }
1069 if (!mFrozenMergedConfig.isEmpty()) {
1070 mFrozenMergedConfig.remove();
1071 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001072 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001073 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001074 win.onUnfreezeBounds();
Jorim Jaggi4846ee32016-01-07 17:39:12 +01001075 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001076 mService.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +01001077 }
1078
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001079 void setAppLayoutChanges(int changes, String reason) {
1080 if (!mChildren.isEmpty()) {
1081 final DisplayContent dc = getDisplayContent();
1082 dc.pendingLayoutChanges |= changes;
1083 if (DEBUG_LAYOUT_REPEATS) {
1084 mService.mWindowPlacerLocked.debugLayoutRepeats(reason, dc.pendingLayoutChanges);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001085 }
1086 }
1087 }
1088
1089 void removeReplacedWindowIfNeeded(WindowState replacement) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001090 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001091 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001092 if (win.removeReplacedWindowIfNeeded(replacement)) {
1093 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001094 }
1095 }
1096 }
1097
1098 void startFreezingScreen() {
1099 if (DEBUG_ORIENTATION) logWithStack(TAG, "Set freezing of " + appToken + ": hidden="
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001100 + hidden + " freezing=" + mAppAnimator.freezingScreen + " hiddenRequested="
1101 + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001102 if (!hiddenRequested) {
1103 if (!mAppAnimator.freezingScreen) {
1104 mAppAnimator.freezingScreen = true;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001105 mService.registerAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001106 mAppAnimator.lastFreezeDuration = 0;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001107 mService.mAppsFreezingScreen++;
1108 if (mService.mAppsFreezingScreen == 1) {
1109 mService.startFreezingDisplayLocked(false, 0, 0);
1110 mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT);
1111 mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001112 }
1113 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001114 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001115 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001116 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001117 w.onStartFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001118 }
1119 }
1120 }
1121
1122 void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) {
1123 if (!mAppAnimator.freezingScreen) {
1124 return;
1125 }
1126 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + this + " force=" + force);
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001127 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001128 boolean unfrozeWindows = false;
1129 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001130 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001131 unfrozeWindows |= w.onStopFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001132 }
1133 if (force || unfrozeWindows) {
1134 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this);
1135 mAppAnimator.freezingScreen = false;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001136 mService.unregisterAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001137 mAppAnimator.lastFreezeDuration =
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001138 (int)(SystemClock.elapsedRealtime() - mService.mDisplayFreezeTime);
1139 mService.mAppsFreezingScreen--;
1140 mService.mLastFinishedFreezeSource = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001141 }
1142 if (unfreezeSurfaceNow) {
1143 if (unfrozeWindows) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001144 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001145 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001146 mService.stopFreezingDisplayLocked();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001147 }
1148 }
1149
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001150 @Override
1151 public void onAppFreezeTimeout() {
1152 Slog.w(TAG_WM, "Force clearing freeze: " + this);
1153 stopFreezingScreen(true, true);
1154 }
1155
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001156 boolean transferStartingWindow(IBinder transferFrom) {
Wale Ogunwale02319a62016-09-26 15:21:22 -07001157 final AppWindowToken fromToken = getDisplayContent().getAppWindowToken(transferFrom);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001158 if (fromToken == null) {
1159 return false;
1160 }
1161
1162 final WindowState tStartingWindow = fromToken.startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001163 if (tStartingWindow != null && fromToken.startingSurface != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001164 // In this case, the starting icon has already been displayed, so start
1165 // letting windows get shown immediately without any more transitions.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001166 mService.mSkipAppTransitionAnimation = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001167
1168 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow
1169 + " from " + fromToken + " to " + this);
1170
1171 final long origId = Binder.clearCallingIdentity();
1172
1173 // Transfer the starting window over to the new token.
1174 startingData = fromToken.startingData;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001175 startingSurface = fromToken.startingSurface;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001176 startingDisplayed = fromToken.startingDisplayed;
1177 fromToken.startingDisplayed = false;
1178 startingWindow = tStartingWindow;
1179 reportedVisible = fromToken.reportedVisible;
1180 fromToken.startingData = null;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001181 fromToken.startingSurface = null;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001182 fromToken.startingWindow = null;
1183 fromToken.startingMoved = true;
1184 tStartingWindow.mToken = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001185 tStartingWindow.mAppToken = this;
1186
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001187 if (DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001188 "Removing starting " + tStartingWindow + " from " + fromToken);
Wale Ogunwalefa854eb2016-09-20 13:43:52 -07001189 fromToken.removeChild(tStartingWindow);
1190 fromToken.postWindowRemoveStartingWindowCleanup(tStartingWindow);
Wale Ogunwale6c459212017-05-17 08:56:03 -07001191 fromToken.mHiddenSetFromTransferredStartingWindow = false;
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001192 addWindow(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001193
1194 // Propagate other interesting state between the tokens. If the old token is displayed,
1195 // we should immediately force the new one to be displayed. If it is animating, we need
1196 // to move that animation to the new one.
1197 if (fromToken.allDrawn) {
1198 allDrawn = true;
1199 deferClearAllDrawn = fromToken.deferClearAllDrawn;
1200 }
1201 if (fromToken.firstWindowDrawn) {
1202 firstWindowDrawn = true;
1203 }
1204 if (!fromToken.hidden) {
1205 hidden = false;
1206 hiddenRequested = false;
Wale Ogunwale6c459212017-05-17 08:56:03 -07001207 mHiddenSetFromTransferredStartingWindow = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001208 }
Wale Ogunwale89973222017-04-23 18:39:45 -07001209 setClientHidden(fromToken.mClientHidden);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001210 fromToken.mAppAnimator.transferCurrentAnimation(
1211 mAppAnimator, tStartingWindow.mWinAnimator);
1212
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001213 mService.updateFocusedWindowLocked(
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001214 UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/);
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001215 getDisplayContent().setLayoutNeeded();
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001216 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001217 Binder.restoreCallingIdentity(origId);
1218 return true;
1219 } else if (fromToken.startingData != null) {
1220 // The previous app was getting ready to show a
1221 // starting window, but hasn't yet done so. Steal it!
1222 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1223 "Moving pending starting from " + fromToken + " to " + this);
1224 startingData = fromToken.startingData;
1225 fromToken.startingData = null;
1226 fromToken.startingMoved = true;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001227 if (getController() != null) {
1228 getController().scheduleAddStartingWindow();
1229 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001230 return true;
1231 }
1232
1233 final AppWindowAnimator tAppAnimator = fromToken.mAppAnimator;
1234 final AppWindowAnimator wAppAnimator = mAppAnimator;
1235 if (tAppAnimator.thumbnail != null) {
1236 // The old token is animating with a thumbnail, transfer that to the new token.
1237 if (wAppAnimator.thumbnail != null) {
1238 wAppAnimator.thumbnail.destroy();
1239 }
1240 wAppAnimator.thumbnail = tAppAnimator.thumbnail;
1241 wAppAnimator.thumbnailLayer = tAppAnimator.thumbnailLayer;
1242 wAppAnimator.thumbnailAnimation = tAppAnimator.thumbnailAnimation;
1243 tAppAnimator.thumbnail = null;
1244 }
1245 return false;
1246 }
1247
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001248 boolean isLastWindow(WindowState win) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001249 return mChildren.size() == 1 && mChildren.get(0) == win;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001250 }
1251
1252 void setAllAppWinAnimators() {
1253 final ArrayList<WindowStateAnimator> allAppWinAnimators = mAppAnimator.mAllAppWinAnimators;
1254 allAppWinAnimators.clear();
1255
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001256 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001257 for (int j = 0; j < windowsCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001258 (mChildren.get(j)).addWinAnimatorToList(allAppWinAnimators);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001259 }
1260 }
1261
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001262 @Override
1263 void onAppTransitionDone() {
1264 sendingToBottom = false;
1265 }
1266
Wale Ogunwale51362492016-09-08 17:49:17 -07001267 /**
1268 * We override because this class doesn't want its children affecting its reported orientation
1269 * in anyway.
1270 */
1271 @Override
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001272 int getOrientation(int candidate) {
Bryce Leed1ac18c2017-05-11 07:59:41 -07001273 // We do not allow non-fullscreen apps to influence orientation beyond O. While we do
Bryce Lee39791592017-04-26 09:29:12 -07001274 // throw an exception in {@link Activity#onCreate} and
1275 // {@link Activity#setRequestedOrientation}, we also ignore the orientation here so that
1276 // other calculations aren't affected.
Bryce Leed1ac18c2017-05-11 07:59:41 -07001277 if (!fillsParent() && mTargetSdk > O) {
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001278 // Can't specify orientation if app doesn't fill parent.
1279 return SCREEN_ORIENTATION_UNSET;
1280 }
1281
1282 if (candidate == SCREEN_ORIENTATION_BEHIND) {
1283 // Allow app to specify orientation regardless of its visibility state if the current
1284 // candidate want us to use orientation behind. I.e. the visible app on-top of this one
1285 // wants us to use the orientation of the app behind it.
1286 return mOrientation;
1287 }
1288
Bryce Lee61fbcbc2017-03-10 14:14:03 -08001289 // The {@link AppWindowToken} should only specify an orientation when it is not closing or
1290 // going to the bottom. Allowing closing {@link AppWindowToken} to participate can lead to
1291 // an Activity in another task being started in the wrong orientation during the transition.
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001292 if (!(sendingToBottom || mService.mClosingApps.contains(this))
Bryce Lee61fbcbc2017-03-10 14:14:03 -08001293 && (isVisible() || mService.mOpeningApps.contains(this))) {
Bryce Leea163b762017-01-24 11:05:01 -08001294 return mOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001295 }
Bryce Leea163b762017-01-24 11:05:01 -08001296
1297 return SCREEN_ORIENTATION_UNSET;
Wale Ogunwale51362492016-09-08 17:49:17 -07001298 }
1299
Wale Ogunwaleb198b742016-12-01 08:44:09 -08001300 /** Returns the app's preferred orientation regardless of its currently visibility state. */
1301 int getOrientationIgnoreVisibility() {
1302 return mOrientation;
1303 }
1304
Craig Mautnerdbb79912012-03-01 18:59:14 -08001305 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001306 void checkAppWindowsReadyToShow() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001307 if (allDrawn == mAppAnimator.allDrawn) {
1308 return;
1309 }
1310
1311 mAppAnimator.allDrawn = allDrawn;
1312 if (!allDrawn) {
1313 return;
1314 }
1315
1316 // The token has now changed state to having all windows shown... what to do, what to do?
1317 if (mAppAnimator.freezingScreen) {
1318 mAppAnimator.showAllWindowsLocked();
1319 stopFreezingScreen(false, true);
1320 if (DEBUG_ORIENTATION) Slog.i(TAG,
1321 "Setting mOrientationChangeComplete=true because wtoken " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001322 + " numInteresting=" + mNumInterestingWindows + " numDrawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001323 // This will set mOrientationChangeComplete and cause a pass through layout.
1324 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001325 "checkAppWindowsReadyToShow: freezingScreen");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001326 } else {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001327 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001328
1329 // We can now show all of the drawn windows!
1330 if (!mService.mOpeningApps.contains(this)) {
1331 mService.mAnimator.orAnimating(mAppAnimator.showAllWindowsLocked());
1332 }
1333 }
1334 }
1335
Matthew Ng498c71d2017-04-18 13:55:45 -07001336 void updateAllDrawn() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001337 if (!allDrawn) {
Matthew Ng498c71d2017-04-18 13:55:45 -07001338 // Number of drawn windows can be less when a window is being relaunched, wait for
1339 // all windows to be launched and drawn for this token be considered all drawn
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001340 final int numInteresting = mNumInterestingWindows;
Matthew Ng498c71d2017-04-18 13:55:45 -07001341 if (numInteresting > 0 && mNumDrawnWindows >= numInteresting && !isRelaunching()) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001342 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawn: " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001343 + " interesting=" + numInteresting + " drawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001344 allDrawn = true;
1345 // Force an additional layout pass where
1346 // WindowStateAnimator#commitFinishDrawingLocked() will call performShowLocked().
Matthew Ng498c71d2017-04-18 13:55:45 -07001347 if (mDisplayContent != null) {
1348 mDisplayContent.setLayoutNeeded();
1349 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001350 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Robert Carrecc06b32017-04-18 14:25:10 -07001351
1352 final TaskStack s = getStack();
1353 if (s != null) {
1354 s.onAllWindowsDrawn();
1355 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001356 }
1357 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001358
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001359 if (!allDrawnExcludingSaved) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001360 int numInteresting = mNumInterestingWindowsExcludingSaved;
1361 if (numInteresting > 0 && mNumDrawnWindowsExcludingSaved >= numInteresting) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001362 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawnExcludingSaved: " + this
1363 + " interesting=" + numInteresting
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001364 + " drawn=" + mNumDrawnWindowsExcludingSaved);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001365 allDrawnExcludingSaved = true;
Matthew Ng498c71d2017-04-18 13:55:45 -07001366 if (mDisplayContent != null) {
1367 mDisplayContent.setLayoutNeeded();
1368 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001369 if (isAnimatingInvisibleWithSavedSurface()
1370 && !mService.mFinishedEarlyAnim.contains(this)) {
1371 mService.mFinishedEarlyAnim.add(this);
1372 }
1373 }
1374 }
1375 }
1376
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001377 /**
1378 * Updated this app token tracking states for interesting and drawn windows based on the window.
1379 *
1380 * @return Returns true if the input window is considered interesting and drawn while all the
1381 * windows in this app token where not considered drawn as of the last pass.
1382 */
1383 boolean updateDrawnWindowStates(WindowState w) {
Jorim Jaggie4b0f282017-05-17 15:10:29 +02001384 if (DEBUG_STARTING_WINDOW_VERBOSE && w == startingWindow) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001385 Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" + w.isOnScreen()
1386 + " allDrawn=" + allDrawn + " freezingScreen=" + mAppAnimator.freezingScreen);
1387 }
1388
1389 if (allDrawn && allDrawnExcludingSaved && !mAppAnimator.freezingScreen) {
1390 return false;
1391 }
1392
1393 if (mLastTransactionSequence != mService.mTransactionSequence) {
1394 mLastTransactionSequence = mService.mTransactionSequence;
1395 mNumInterestingWindows = mNumDrawnWindows = 0;
1396 mNumInterestingWindowsExcludingSaved = 0;
1397 mNumDrawnWindowsExcludingSaved = 0;
1398 startingDisplayed = false;
1399 }
1400
1401 final WindowStateAnimator winAnimator = w.mWinAnimator;
1402
1403 boolean isInterestingAndDrawn = false;
1404
1405 if (!allDrawn && w.mightAffectAllDrawn(false /* visibleOnly */)) {
1406 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
1407 Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw()
1408 + ", isAnimationSet=" + winAnimator.isAnimationSet());
1409 if (!w.isDrawnLw()) {
1410 Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController
1411 + " pv=" + w.mPolicyVisibility
1412 + " mDrawState=" + winAnimator.drawStateToString()
1413 + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested
1414 + " a=" + winAnimator.mAnimating);
1415 }
1416 }
1417
1418 if (w != startingWindow) {
1419 if (w.isInteresting()) {
1420 mNumInterestingWindows++;
1421 if (w.isDrawnLw()) {
1422 mNumDrawnWindows++;
1423
1424 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, "tokenMayBeDrawn: "
1425 + this + " w=" + w + " numInteresting=" + mNumInterestingWindows
1426 + " freezingScreen=" + mAppAnimator.freezingScreen
1427 + " mAppFreezing=" + w.mAppFreezing);
1428
1429 isInterestingAndDrawn = true;
1430 }
1431 }
1432 } else if (w.isDrawnLw()) {
Jorim Jaggi3878ca32017-02-02 17:13:05 -08001433 if (getController() != null) {
1434 getController().reportStartingWindowDrawn();
1435 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001436 startingDisplayed = true;
1437 }
1438 }
1439
1440 if (!allDrawnExcludingSaved && w.mightAffectAllDrawn(true /* visibleOnly */)) {
1441 if (w != startingWindow && w.isInteresting()) {
1442 mNumInterestingWindowsExcludingSaved++;
1443 if (w.isDrawnLw() && !w.isAnimatingWithSavedSurface()) {
1444 mNumDrawnWindowsExcludingSaved++;
1445
1446 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
1447 "tokenMayBeDrawnExcludingSaved: " + this + " w=" + w
1448 + " numInteresting=" + mNumInterestingWindowsExcludingSaved
1449 + " freezingScreen=" + mAppAnimator.freezingScreen
1450 + " mAppFreezing=" + w.mAppFreezing);
1451
1452 isInterestingAndDrawn = true;
1453 }
1454 }
1455 }
1456
1457 return isInterestingAndDrawn;
1458 }
1459
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001460 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001461 void stepAppWindowsAnimation(long currentTime) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001462 mAppAnimator.wasAnimating = mAppAnimator.animating;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001463 if (mAppAnimator.stepAnimationLocked(currentTime)) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001464 mAppAnimator.animating = true;
1465 mService.mAnimator.setAnimating(true);
1466 mService.mAnimator.mAppWindowAnimating = true;
1467 } else if (mAppAnimator.wasAnimating) {
1468 // stopped animating, do one more pass through the layout
Wale Ogunwale1e129a42016-11-21 13:03:47 -08001469 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
1470 DEBUG_LAYOUT_REPEATS ? "appToken " + this + " done" : null);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001471 if (DEBUG_ANIM) Slog.v(TAG, "updateWindowsApps...: done animating " + this);
1472 }
1473 }
1474
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001475 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001476 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001477 // For legacy reasons we process the TaskStack.mExitingAppTokens first in DisplayContent
1478 // before the non-exiting app tokens. So, we skip the exiting app tokens here.
1479 // TODO: Investigate if we need to continue to do this or if we can just process them
1480 // in-order.
1481 if (mIsExiting && !waitingForReplacement()) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001482 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001483 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001484 return forAllWindowsUnchecked(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001485 }
1486
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001487 boolean forAllWindowsUnchecked(ToBooleanFunction<WindowState> callback,
1488 boolean traverseTopToBottom) {
1489 return super.forAllWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001490 }
1491
1492 @Override
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001493 AppWindowToken asAppWindowToken() {
1494 // I am an app window token!
1495 return this;
1496 }
1497
1498 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -07001499 boolean fillsParent() {
1500 return mFillsParent;
1501 }
1502
1503 void setFillsParent(boolean fillsParent) {
1504 mFillsParent = fillsParent;
1505 }
1506
Jorim Jaggife762342016-10-13 14:33:27 +02001507 boolean containsDismissKeyguardWindow() {
Bryce Lee081554b2017-05-25 07:52:12 -07001508 // Window state is transient during relaunch. We are not guaranteed to be frozen during the
1509 // entirety of the relaunch.
1510 if (isRelaunching()) {
1511 return mLastContainsDismissKeyguardWindow;
1512 }
1513
Jorim Jaggife762342016-10-13 14:33:27 +02001514 for (int i = mChildren.size() - 1; i >= 0; i--) {
1515 if ((mChildren.get(i).mAttrs.flags & FLAG_DISMISS_KEYGUARD) != 0) {
1516 return true;
1517 }
1518 }
1519 return false;
1520 }
1521
1522 boolean containsShowWhenLockedWindow() {
Bryce Lee081554b2017-05-25 07:52:12 -07001523 // When we are relaunching, it is possible for us to be unfrozen before our previous
1524 // windows have been added back. Using the cached value ensures that our previous
1525 // showWhenLocked preference is honored until relaunching is complete.
1526 if (isRelaunching()) {
1527 return mLastContainsShowWhenLockedWindow;
1528 }
1529
Jorim Jaggife762342016-10-13 14:33:27 +02001530 for (int i = mChildren.size() - 1; i >= 0; i--) {
1531 if ((mChildren.get(i).mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
1532 return true;
1533 }
1534 }
Bryce Lee081554b2017-05-25 07:52:12 -07001535
Jorim Jaggife762342016-10-13 14:33:27 +02001536 return false;
1537 }
1538
1539 void checkKeyguardFlagsChanged() {
1540 final boolean containsDismissKeyguard = containsDismissKeyguardWindow();
1541 final boolean containsShowWhenLocked = containsShowWhenLockedWindow();
1542 if (containsDismissKeyguard != mLastContainsDismissKeyguardWindow
1543 || containsShowWhenLocked != mLastContainsShowWhenLockedWindow) {
1544 mService.notifyKeyguardFlagsChanged(null /* callback */);
1545 }
1546 mLastContainsDismissKeyguardWindow = containsDismissKeyguard;
1547 mLastContainsShowWhenLockedWindow = containsShowWhenLocked;
1548 }
1549
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001550 WindowState getImeTargetBelowWindow(WindowState w) {
1551 final int index = mChildren.indexOf(w);
1552 if (index > 0) {
1553 final WindowState target = mChildren.get(index - 1);
1554 if (target.canBeImeTarget()) {
1555 return target;
1556 }
1557 }
1558 return null;
1559 }
1560
1561 WindowState getHighestAnimLayerWindow(WindowState currentTarget) {
1562 WindowState candidate = null;
1563 for (int i = mChildren.indexOf(currentTarget); i >= 0; i--) {
1564 final WindowState w = mChildren.get(i);
1565 if (w.mRemoved) {
1566 continue;
1567 }
1568 if (candidate == null || w.mWinAnimator.mAnimLayer >
1569 candidate.mWinAnimator.mAnimLayer) {
1570 candidate = w;
1571 }
1572 }
1573 return candidate;
1574 }
1575
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001576 /**
1577 * See {@link Activity#setDisablePreviewScreenshots}.
1578 */
1579 void setDisablePreviewScreenshots(boolean disable) {
Wale Ogunwale6c459212017-05-17 08:56:03 -07001580 mDisablePreviewScreenshots = disable;
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001581 }
1582
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001583 /**
1584 * Retrieves whether we'd like to generate a snapshot that's based solely on the theme. This is
1585 * the case when preview screenshots are disabled {@link #setDisablePreviewScreenshots} or when
1586 * we can't take a snapshot for other reasons, for example, if we have a secure window.
1587 *
1588 * @return True if we need to generate an app theme snapshot, false if we'd like to take a real
1589 * screenshot.
1590 */
1591 boolean shouldUseAppThemeSnapshot() {
Wale Ogunwale6c459212017-05-17 08:56:03 -07001592 return mDisablePreviewScreenshots || forAllWindows(w -> (w.mAttrs.flags & FLAG_SECURE) != 0,
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001593 true /* topToBottom */);
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001594 }
1595
Wale Ogunwale51362492016-09-08 17:49:17 -07001596 @Override
Robert Carrdee1b3f2017-02-27 11:33:33 -08001597 int getAnimLayerAdjustment() {
1598 return mAppAnimator.animLayerAdjustment;
1599 }
1600
1601 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001602 void dump(PrintWriter pw, String prefix) {
1603 super.dump(pw, prefix);
1604 if (appToken != null) {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001605 pw.println(prefix + "app=true mVoiceInteraction=" + mVoiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001606 }
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001607 pw.print(prefix); pw.print("task="); pw.println(getTask());
Wale Ogunwale51362492016-09-08 17:49:17 -07001608 pw.print(prefix); pw.print(" mFillsParent="); pw.print(mFillsParent);
1609 pw.print(" mOrientation="); pw.println(mOrientation);
Wale Ogunwale89973222017-04-23 18:39:45 -07001610 pw.println(prefix + "hiddenRequested=" + hiddenRequested + " mClientHidden=" + mClientHidden
1611 + ((mDeferHidingClient) ? " mDeferHidingClient=" + mDeferHidingClient : "")
1612 + " reportedDrawn=" + reportedDrawn + " reportedVisible=" + reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -07001613 if (paused) {
1614 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001615 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001616 if (mAppStopped) {
1617 pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped);
1618 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001619 if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0
Craig Mautner6fbda632012-07-03 09:26:39 -07001620 || allDrawn || mAppAnimator.allDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001621 pw.print(prefix); pw.print("mNumInterestingWindows=");
1622 pw.print(mNumInterestingWindows);
1623 pw.print(" mNumDrawnWindows="); pw.print(mNumDrawnWindows);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001624 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -07001625 pw.print(" allDrawn="); pw.print(allDrawn);
1626 pw.print(" (animator="); pw.print(mAppAnimator.allDrawn);
1627 pw.println(")");
1628 }
1629 if (inPendingTransaction) {
1630 pw.print(prefix); pw.print("inPendingTransaction=");
1631 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001632 }
Craig Mautner799bc1d2015-01-14 10:33:48 -08001633 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001634 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
1635 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -08001636 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -08001637 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001638 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001639 if (startingWindow != null || startingSurface != null
Wale Ogunwale6c459212017-05-17 08:56:03 -07001640 || startingDisplayed || startingMoved || mHiddenSetFromTransferredStartingWindow) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001641 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001642 pw.print(" startingSurface="); pw.print(startingSurface);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001643 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
Wale Ogunwale6c459212017-05-17 08:56:03 -07001644 pw.print(" startingMoved="); pw.print(startingMoved);
1645 pw.println(" mHiddenSetFromTransferredStartingWindow="
1646 + mHiddenSetFromTransferredStartingWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001647 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01001648 if (!mFrozenBounds.isEmpty()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -08001649 pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds);
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001650 pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig);
Chong Zhangd78ddb42016-03-02 17:01:14 -08001651 }
1652 if (mPendingRelaunchCount != 0) {
1653 pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount);
Jorim Jaggi0429f352015-12-22 16:29:16 +01001654 }
Wale Ogunwale9c64cb62017-04-12 13:39:59 -07001655 if (getController() != null) {
1656 pw.print(prefix); pw.print("controller="); pw.println(getController());
1657 }
Wale Ogunwalee287e192017-04-21 09:30:12 -07001658 if (mRemovingFromDisplay) {
1659 pw.println(prefix + "mRemovingFromDisplay=" + mRemovingFromDisplay);
1660 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001661 }
1662
1663 @Override
1664 public String toString() {
1665 if (stringName == null) {
1666 StringBuilder sb = new StringBuilder();
1667 sb.append("AppWindowToken{");
1668 sb.append(Integer.toHexString(System.identityHashCode(this)));
1669 sb.append(" token="); sb.append(token); sb.append('}');
1670 stringName = sb.toString();
1671 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001672 return stringName + ((mIsExiting) ? " mIsExiting=" : "");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001673 }
Jeff Browne9bdb312012-04-05 15:30:10 -07001674}