blob: b9d02a900d1c3d1abcfef27d60c52c0a0234052d [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;
Winson Chunge7ba6862017-05-24 12:13:33 -070020import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
Wale Ogunwale72919d22016-12-08 18:58:50 -080021import static android.content.pm.ActivityInfo.CONFIG_ORIENTATION;
22import static android.content.pm.ActivityInfo.CONFIG_SCREEN_SIZE;
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -070023import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND;
Wale Ogunwale51362492016-09-08 17:49:17 -070024import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070025import static android.view.Display.DEFAULT_DISPLAY;
Jorim Jaggife762342016-10-13 14:33:27 +020026import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
Jorim Jaggid635a4a2017-05-03 15:21:26 +020027import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
Jorim Jaggife762342016-10-13 14:33:27 +020028import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
Wale Ogunwaled1c37912016-08-16 03:19:39 -070029import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080030import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070031import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -070032import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
33import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070034import static com.android.server.wm.AppTransition.TRANSIT_UNSET;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080035import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080036import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
37import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070038import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070039import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
40import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
Wale Ogunwale9017ec02016-02-25 08:55:25 -080041import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
Jorim Jaggie4b0f282017-05-17 15:10:29 +020042import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW_VERBOSE;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070043import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TOKEN_MOVEMENT;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080044import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
45import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_MOVEMENT;
46import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
47import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Chong Zhang92147042016-05-09 12:47:11 -070048import static com.android.server.wm.WindowManagerService.H.NOTIFY_ACTIVITY_DRAWN;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070049import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070050import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070051import static com.android.server.wm.WindowManagerService.logWithStack;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080052
Filip Gruszczynskia590c992015-11-25 16:45:26 -080053import android.annotation.NonNull;
Jorim Jaggid635a4a2017-05-03 15:21:26 +020054import android.app.Activity;
Jorim Jaggi26c8c422016-05-09 19:57:25 -070055import android.content.res.Configuration;
Jorim Jaggi0429f352015-12-22 16:29:16 +010056import android.graphics.Rect;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070057import android.os.Binder;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080058import android.os.Debug;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070059import android.os.IBinder;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070060import android.os.SystemClock;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080061import android.util.Slog;
62import android.view.IApplicationToken;
Robert Carr6914f082017-03-20 19:04:30 -070063import android.view.SurfaceControl;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080064import android.view.WindowManager;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080065import android.view.WindowManagerPolicy.StartingSurface;
66
67import com.android.internal.util.ToBooleanFunction;
68import com.android.server.input.InputApplicationHandle;
69import com.android.server.wm.WindowManagerService.H;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080070
71import java.io.PrintWriter;
Jorim Jaggi0429f352015-12-22 16:29:16 +010072import java.util.ArrayDeque;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080073import java.util.ArrayList;
74
Bryce Lee39791592017-04-26 09:29:12 -070075import static android.os.Build.VERSION_CODES.O;
76
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080077class AppTokenList extends ArrayList<AppWindowToken> {
78}
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080079
80/**
81 * Version of WindowToken that is specifically for a particular application (or
82 * really activity) that is displaying windows.
83 */
Wale Ogunwale3f4433d2016-08-18 20:42:42 -070084class AppWindowToken extends WindowToken implements WindowManagerService.AppFreezeListener {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080085 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppWindowToken" : TAG_WM;
86
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080087 // Non-null only for application tokens.
88 final IApplicationToken appToken;
89
Filip Gruszczynskia590c992015-11-25 16:45:26 -080090 @NonNull final AppWindowAnimator mAppAnimator;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -070091
Wale Ogunwale72919d22016-12-08 18:58:50 -080092 final boolean mVoiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -070093
Wale Ogunwale51362492016-09-08 17:49:17 -070094 /** @see WindowContainer#fillsParent() */
95 private boolean mFillsParent;
Craig Mautner4c5eb222013-11-18 12:59:05 -080096 boolean layoutConfigChanges;
Wale Ogunwale72919d22016-12-08 18:58:50 -080097 boolean mShowForAllUsers;
98 int mTargetSdk;
Craig Mautnera2c77052012-03-26 12:14:43 -070099
Bryce Lee6d410262017-02-28 15:30:17 -0800100 // Flag set while reparenting to prevent actions normally triggered by an individual parent
101 // change.
102 private boolean mReparenting;
103
Wale Ogunwalee287e192017-04-21 09:30:12 -0700104 // True if we are current in the process of removing this app token from the display
105 private boolean mRemovingFromDisplay = false;
106
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800107 // The input dispatching timeout for this application token in nanoseconds.
Wale Ogunwale72919d22016-12-08 18:58:50 -0800108 long mInputDispatchingTimeoutNanos;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800109
110 // These are used for determining when all windows associated with
111 // an activity have been drawn, so they can be made visible together
112 // at the same time.
Craig Mautner764983d2012-03-22 11:37:36 -0700113 // initialize so that it doesn't match mTransactionSequence which is an int.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700114 private long mLastTransactionSequence = Long.MIN_VALUE;
115 private int mNumInterestingWindows;
116 private int mNumDrawnWindows;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800117 boolean inPendingTransaction;
118 boolean allDrawn;
Craig Mautner7636dfb2012-11-16 15:24:11 -0800119 // Set to true when this app creates a surface while in the middle of an animation. In that
120 // case do not clear allDrawn until the animation completes.
121 boolean deferClearAllDrawn;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800122
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700123 /**
124 * These are to track the app's real drawing status if there were no saved surfaces.
125 * @see #updateDrawnWindowStates
126 */
Chong Zhang8e4bda92016-05-04 15:08:18 -0700127 boolean allDrawnExcludingSaved;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700128 private int mNumInterestingWindowsExcludingSaved;
129 private int mNumDrawnWindowsExcludingSaved;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700130
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800131 // Is this window's surface needed? This is almost like hidden, except
132 // it will sometimes be true a little earlier: when the token has
133 // been shown, but is still waiting for its app transition to execute
134 // before making its windows shown.
135 boolean hiddenRequested;
136
137 // Have we told the window clients to hide themselves?
Wale Ogunwale89973222017-04-23 18:39:45 -0700138 private boolean mClientHidden;
139
140 // If true we will defer setting mClientHidden to true and reporting to the client that it is
141 // hidden.
142 boolean mDeferHidingClient;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800143
144 // Last visibility state we reported to the app token.
145 boolean reportedVisible;
146
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700147 // Last drawn state we reported to the app token.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700148 private boolean reportedDrawn;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700149
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800150 // Set to true when the token has been removed from the window mgr.
151 boolean removed;
152
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800153 // Information about an application starting window if displayed.
154 StartingData startingData;
155 WindowState startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800156 StartingSurface startingSurface;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800157 boolean startingDisplayed;
158 boolean startingMoved;
Wale Ogunwale6c459212017-05-17 08:56:03 -0700159 // True if the hidden state of this token was forced to false due to a transferred starting
160 // window.
161 private boolean mHiddenSetFromTransferredStartingWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800162 boolean firstWindowDrawn;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700163 private final WindowState.UpdateReportedVisibilityResults mReportedVisibilityResults =
164 new WindowState.UpdateReportedVisibilityResults();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800165
166 // Input application handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700167 final InputApplicationHandle mInputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800168
Wale Ogunwale571771c2016-08-26 13:18:50 -0700169 // TODO: Have a WindowContainer state for tracking exiting/deferred removal.
Craig Mautner799bc1d2015-01-14 10:33:48 -0800170 boolean mIsExiting;
Craig Mautner9ef471f2014-02-07 13:11:47 -0800171
Craig Mautnerbb742462014-07-07 15:28:55 -0700172 boolean mLaunchTaskBehind;
Craig Mautner8746a472014-07-24 15:12:54 -0700173 boolean mEnteringAnimation;
Craig Mautnerbb742462014-07-07 15:28:55 -0700174
Wale Ogunwale72919d22016-12-08 18:58:50 -0800175 private boolean mAlwaysFocusable;
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800176
Robert Carre12aece2016-02-02 22:43:27 -0800177 boolean mAppStopped;
Robert Carrfd10cd12016-06-29 16:41:50 -0700178 int mRotationAnimationHint;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700179 private int mPendingRelaunchCount;
Robert Carre12aece2016-02-02 22:43:27 -0800180
Jorim Jaggife762342016-10-13 14:33:27 +0200181 private boolean mLastContainsShowWhenLockedWindow;
182 private boolean mLastContainsDismissKeyguardWindow;
183
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700184 // The bounds of this activity. Mainly used for aspect-ratio compatibility.
185 // TODO(b/36505427): Every level on WindowContainer now has bounds information, which directly
186 // affects the configuration. We should probably move this into that class.
187 private final Rect mBounds = new Rect();
188
Jorim Jaggi0429f352015-12-22 16:29:16 +0100189 ArrayDeque<Rect> mFrozenBounds = new ArrayDeque<>();
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700190 ArrayDeque<Configuration> mFrozenMergedConfig = new ArrayDeque<>();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100191
Wale Ogunwale6c459212017-05-17 08:56:03 -0700192 private boolean mDisablePreviewScreenshots;
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +0100193
Robert Carred3e83b2017-04-21 13:26:55 -0700194 Task mLastParent;
195
Wale Ogunwale72919d22016-12-08 18:58:50 -0800196 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
197 DisplayContent dc, long inputDispatchingTimeoutNanos, boolean fullscreen,
198 boolean showForAllUsers, int targetSdk, int orientation, int rotationAnimationHint,
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800199 int configChanges, boolean launchTaskBehind, boolean alwaysFocusable,
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700200 AppWindowContainerController controller, Configuration overrideConfig, Rect bounds) {
201 this(service, token, voiceInteraction, dc, fullscreen, overrideConfig, bounds);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800202 setController(controller);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800203 mInputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800204 mShowForAllUsers = showForAllUsers;
205 mTargetSdk = targetSdk;
206 mOrientation = orientation;
207 layoutConfigChanges = (configChanges & (CONFIG_SCREEN_SIZE | CONFIG_ORIENTATION)) != 0;
208 mLaunchTaskBehind = launchTaskBehind;
209 mAlwaysFocusable = alwaysFocusable;
210 mRotationAnimationHint = rotationAnimationHint;
211
212 // Application tokens start out hidden.
213 hidden = true;
214 hiddenRequested = true;
215 }
216
217 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700218 DisplayContent dc, boolean fillsParent, Configuration overrideConfig, Rect bounds) {
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800219 super(service, token != null ? token.asBinder() : null, TYPE_APPLICATION, true, dc,
220 false /* ownerCanManageAppTokens */);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700221 appToken = token;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800222 mVoiceInteraction = voiceInteraction;
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800223 mFillsParent = fillsParent;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800224 mInputApplicationHandle = new InputApplicationHandle(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700225 mAppAnimator = new AppWindowAnimator(this, service);
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700226 if (overrideConfig != null) {
227 onOverrideConfigurationChanged(overrideConfig);
228 }
229 if (bounds != null) {
230 mBounds.set(bounds);
231 }
232 }
233
234 void onOverrideConfigurationChanged(Configuration overrideConfiguration, Rect bounds) {
235 onOverrideConfigurationChanged(overrideConfiguration);
236 if (mBounds.equals(bounds)) {
237 return;
238 }
239 // TODO(b/36505427): If bounds is in WC, then we can automatically call onResize() when set.
240 mBounds.set(bounds);
241 onResize();
242 }
243
244 void getBounds(Rect outBounds) {
245 outBounds.set(mBounds);
246 }
247
248 boolean hasBounds() {
249 return !mBounds.isEmpty();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800250 }
251
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800252 void onFirstWindowDrawn(WindowState win, WindowStateAnimator winAnimator) {
253 firstWindowDrawn = true;
254
255 // We now have a good window to show, remove dead placeholders
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700256 removeDeadWindows();
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800257
Jorim Jaggi02886a82016-12-06 09:10:06 -0800258 if (startingWindow != null) {
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800259 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, "Finish starting "
260 + win.mToken + ": first real window is shown, no animation");
261 // If this initial window is animating, stop it -- we will do an animation to reveal
262 // it from behind the starting window, so there is no need for it to also be doing its
263 // own stuff.
264 winAnimator.clearAnimation();
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800265 if (getController() != null) {
266 getController().removeStartingWindow();
267 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800268 }
269 updateReportedVisibilityLocked();
270 }
271
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800272 void updateReportedVisibilityLocked() {
273 if (appToken == null) {
274 return;
275 }
276
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700277 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700278 final int count = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800279
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700280 mReportedVisibilityResults.reset();
281
282 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700283 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700284 win.updateReportedVisibility(mReportedVisibilityResults);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800285 }
286
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700287 int numInteresting = mReportedVisibilityResults.numInteresting;
288 int numVisible = mReportedVisibilityResults.numVisible;
289 int numDrawn = mReportedVisibilityResults.numDrawn;
290 boolean nowGone = mReportedVisibilityResults.nowGone;
291
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700292 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800293 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700294 if (!nowGone) {
295 // If the app is not yet gone, then it can only become visible/drawn.
296 if (!nowDrawn) {
297 nowDrawn = reportedDrawn;
298 }
299 if (!nowVisible) {
300 nowVisible = reportedVisible;
301 }
302 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800303 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800304 + numInteresting + " visible=" + numVisible);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800305 final AppWindowContainerController controller = getController();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700306 if (nowDrawn != reportedDrawn) {
307 if (nowDrawn) {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800308 if (controller != null) {
309 controller.reportWindowsDrawn();
310 }
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700311 }
312 reportedDrawn = nowDrawn;
313 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800314 if (nowVisible != reportedVisible) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700315 if (DEBUG_VISIBILITY) Slog.v(TAG,
316 "Visibility changed in " + this + ": vis=" + nowVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800317 reportedVisible = nowVisible;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800318 if (controller != null) {
319 if (nowVisible) {
320 controller.reportWindowsVisible();
321 } else {
322 controller.reportWindowsGone();
323 }
324 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800325 }
326 }
327
Wale Ogunwale89973222017-04-23 18:39:45 -0700328 boolean isClientHidden() {
329 return mClientHidden;
330 }
331
332 void setClientHidden(boolean hideClient) {
333 if (mClientHidden == hideClient || (hideClient && mDeferHidingClient)) {
334 return;
335 }
336 mClientHidden = hideClient;
337 sendAppVisibilityToClients();
338 }
339
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700340 boolean setVisibility(WindowManager.LayoutParams lp,
341 boolean visible, int transit, boolean performLayout, boolean isVoiceInteraction) {
342
343 boolean delayed = false;
344 inPendingTransaction = false;
Wale Ogunwale9e4721f2017-05-23 19:37:30 -0700345 // Reset the state of mHiddenSetFromTransferredStartingWindow since visibility is actually
346 // been set by the app now.
347 mHiddenSetFromTransferredStartingWindow = false;
Wale Ogunwale89973222017-04-23 18:39:45 -0700348 setClientHidden(!visible);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700349
350 // Allow for state changes and animation to be applied if:
351 // * token is transitioning visibility state
352 // * or the token was marked as hidden and is exiting before we had a chance to play the
353 // transition animation
354 // * or this is an opening app and windows are being replaced.
355 boolean visibilityChanged = false;
356 if (hidden == visible || (hidden && mIsExiting) || (visible && waitingForReplacement())) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700357 final AccessibilityController accessibilityController = mService.mAccessibilityController;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700358 boolean changed = false;
359 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
360 "Changing app " + this + " hidden=" + hidden + " performLayout=" + performLayout);
361
362 boolean runningAppAnimation = false;
363
364 if (transit != AppTransition.TRANSIT_UNSET) {
365 if (mAppAnimator.animation == AppWindowAnimator.sDummyAnimation) {
366 mAppAnimator.setNullAnimation();
367 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700368 if (mService.applyAnimationLocked(this, lp, transit, visible, isVoiceInteraction)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700369 delayed = runningAppAnimation = true;
370 }
371 final WindowState window = findMainWindow();
372 //TODO (multidisplay): Magnification is supported only for the default display.
373 if (window != null && accessibilityController != null
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700374 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700375 accessibilityController.onAppWindowTransitionLocked(window, transit);
376 }
377 changed = true;
378 }
379
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700380 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700381 for (int i = 0; i < windowsCount; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700382 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700383 changed |= win.onAppVisibilityChanged(visible, runningAppAnimation);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700384 }
385
386 hidden = hiddenRequested = !visible;
387 visibilityChanged = true;
388 if (!visible) {
389 stopFreezingScreen(true, true);
390 } else {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700391 // If we are being set visible, and the starting window is not yet displayed,
392 // then make sure it doesn't get displayed.
393 if (startingWindow != null && !startingWindow.isDrawnLw()) {
394 startingWindow.mPolicyVisibility = false;
395 startingWindow.mPolicyVisibilityAfterAnim = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700396 }
Jorim Jaggi38d44ec2017-06-14 16:04:59 -0700397
398 // We are becoming visible, so better freeze the screen with the windows that are
399 // getting visible so we also wait for them.
400 forAllWindows(mService::makeWindowFreezingScreenIfNeededLocked, true);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700401 }
402
403 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setVisibility: " + this
404 + ": hidden=" + hidden + " hiddenRequested=" + hiddenRequested);
405
406 if (changed) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700407 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700408 if (performLayout) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700409 mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700410 false /*updateInputWindows*/);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700411 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700412 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700413 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700414 }
415 }
416
417 if (mAppAnimator.animation != null) {
418 delayed = true;
419 }
420
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700421 for (int i = mChildren.size() - 1; i >= 0 && !delayed; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700422 if ((mChildren.get(i)).isWindowAnimationSet()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700423 delayed = true;
424 }
425 }
426
427 if (visibilityChanged) {
428 if (visible && !delayed) {
429 // The token was made immediately visible, there will be no entrance animation.
430 // We need to inform the client the enter animation was finished.
431 mEnteringAnimation = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700432 mService.mActivityManagerAppTransitionNotifier.onAppTransitionFinishedLocked(token);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700433 }
Robert Carre7cc44d2017-03-20 19:04:30 -0700434 // If we are hidden but there is no delay needed we immediately
435 // apply the Surface transaction so that the ActivityManager
436 // can have some guarantee on the Surface state
437 // following setting the visibility.
Robert Carr6914f082017-03-20 19:04:30 -0700438 if (hidden && !delayed) {
439 SurfaceControl.openTransaction();
440 for (int i = mChildren.size() - 1; i >= 0; i--) {
441 mChildren.get(i).mWinAnimator.hide("immediately hidden");
442 }
443 SurfaceControl.closeTransaction();
Wale Ogunwale2c596d52017-07-06 15:30:55 -0700444 removeStartingWindow();
Robert Carr6914f082017-03-20 19:04:30 -0700445 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700446
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700447 if (!mService.mClosingApps.contains(this) && !mService.mOpeningApps.contains(this)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700448 // The token is not closing nor opening, so even if there is an animation set, that
449 // doesn't mean that it goes through the normal app transition cycle so we have
450 // to inform the docked controller about visibility change.
Andrii Kulian1e32e022016-09-16 15:29:34 -0700451 // TODO(multi-display): notify docked divider on all displays where visibility was
452 // affected.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700453 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700454 .notifyAppVisibilityChanged();
Jorim Jaggi8b702ed2017-01-20 16:59:03 +0100455 mService.mTaskSnapshotController.notifyAppVisibilityChanged(this, visible);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700456 }
457 }
458
459 return delayed;
460 }
461
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800462 WindowState findMainWindow() {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700463 WindowState candidate = null;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700464 int j = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800465 while (j > 0) {
466 j--;
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700467 final WindowState win = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700468 final int type = win.mAttrs.type;
469 // No need to loop through child window as base application and starting types can't be
470 // child windows.
471 if (type == TYPE_BASE_APPLICATION || type == TYPE_APPLICATION_STARTING) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700472 // In cases where there are multiple windows, we prefer the non-exiting window. This
Sungsoo Lim0d3d1f82015-12-02 14:47:59 +0900473 // happens for example when replacing windows during an activity relaunch. When
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700474 // constructing the animation, we want the new window, not the exiting one.
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800475 if (win.mAnimatingExit) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700476 candidate = win;
477 } else {
478 return win;
479 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800480 }
481 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700482 return candidate;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800483 }
484
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800485 boolean windowsAreFocusable() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800486 return StackId.canReceiveKeys(getTask().mStack.mStackId) || mAlwaysFocusable;
Wale Ogunwaled045c822015-12-02 09:14:28 -0800487 }
488
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800489 AppWindowContainerController getController() {
490 final WindowContainerController controller = super.getController();
491 return controller != null ? (AppWindowContainerController) controller : null;
492 }
493
Wale Ogunwale571771c2016-08-26 13:18:50 -0700494 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -0700495 boolean isVisible() {
Wale Ogunwalee471be62016-10-03 07:53:55 -0700496 // If the app token isn't hidden then it is considered visible and there is no need to check
497 // its children windows to see if they are visible.
498 return !hidden;
Wale Ogunwale44f21802016-09-02 12:49:48 -0700499 }
500
501 @Override
Wale Ogunwalee287e192017-04-21 09:30:12 -0700502 void removeImmediately() {
503 onRemovedFromDisplay();
504 super.removeImmediately();
505 }
506
507 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -0700508 void removeIfPossible() {
Craig Mautnere3119b72015-01-20 15:02:36 -0800509 mIsExiting = false;
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800510 removeAllWindowsIfPossible();
Bryce Lee6d410262017-02-28 15:30:17 -0800511 removeImmediately();
Craig Mautnere3119b72015-01-20 15:02:36 -0800512 }
513
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700514 @Override
515 boolean checkCompleteDeferredRemoval() {
516 if (mIsExiting) {
517 removeIfPossible();
518 }
519 return super.checkCompleteDeferredRemoval();
520 }
521
Wale Ogunwale2c596d52017-07-06 15:30:55 -0700522 private void removeStartingWindow() {
523 if (startingData != null && getController() != null) {
524 getController().removeStartingWindow();
525 }
526 }
527
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700528 void onRemovedFromDisplay() {
Wale Ogunwalee287e192017-04-21 09:30:12 -0700529 if (mRemovingFromDisplay) {
530 return;
531 }
532 mRemovingFromDisplay = true;
533
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700534 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app token: " + this);
535
Wale Ogunwale72919d22016-12-08 18:58:50 -0800536 boolean delayed = setVisibility(null, false, TRANSIT_UNSET, true, mVoiceInteraction);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700537
538 mService.mOpeningApps.remove(this);
Jorim Jaggi45ca0542017-05-30 16:16:01 -0700539 mService.mUnknownAppVisibilityController.appRemovedOrHidden(this);
Jorim Jaggi10abe2f2017-01-03 16:44:46 +0100540 mService.mTaskSnapshotController.onAppRemoved(this);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700541 waitingToShow = false;
542 if (mService.mClosingApps.contains(this)) {
543 delayed = true;
544 } else if (mService.mAppTransition.isTransitionSet()) {
545 mService.mClosingApps.add(this);
546 delayed = true;
547 }
548
549 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app " + this + " delayed=" + delayed
550 + " animation=" + mAppAnimator.animation + " animating=" + mAppAnimator.animating);
551
552 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM, "removeAppToken: "
553 + this + " delayed=" + delayed + " Callers=" + Debug.getCallers(4));
554
Wale Ogunwale2c596d52017-07-06 15:30:55 -0700555 removeStartingWindow();
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800556
Winson Chung87e5d552017-04-05 11:49:38 -0700557 // If this window was animating, then we need to ensure that the app transition notifies
558 // that animations have completed in WMS.handleAnimatingStoppedAndTransitionLocked(), so
559 // add to that list now
560 if (mAppAnimator.animating) {
561 mService.mNoAnimationNotifyOnTransitionFinished.add(token);
562 }
563
Wale Ogunwalee287e192017-04-21 09:30:12 -0700564 final TaskStack stack = getStack();
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700565 if (delayed && !isEmpty()) {
566 // set the token aside because it has an active animation to be finished
567 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM,
568 "removeAppToken make exiting: " + this);
Wale Ogunwalee287e192017-04-21 09:30:12 -0700569 if (stack != null) {
570 stack.mExitingAppTokens.add(this);
571 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700572 mIsExiting = true;
573 } else {
574 // Make sure there is no animation running on this token, so any windows associated
575 // with it will be removed as soon as their animations are complete
576 mAppAnimator.clearAnimation();
577 mAppAnimator.animating = false;
Wale Ogunwale3106ae012017-05-16 08:56:37 -0700578 if (stack != null) {
579 stack.mExitingAppTokens.remove(this);
580 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700581 removeIfPossible();
582 }
583
584 removed = true;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700585 stopFreezingScreen(true, true);
Bryce Lee6d410262017-02-28 15:30:17 -0800586
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700587 if (mService.mFocusedApp == this) {
588 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "Removing focused app token:" + this);
589 mService.mFocusedApp = null;
590 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
591 mService.mInputMonitor.setFocusedAppLw(null);
592 }
593
594 if (!delayed) {
595 updateReportedVisibilityLocked();
596 }
Wale Ogunwalee287e192017-04-21 09:30:12 -0700597
598 mRemovingFromDisplay = false;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700599 }
600
Chong Zhange05bcb12016-07-26 17:47:29 -0700601 void clearAnimatingFlags() {
Chong Zhangb0d26702016-08-12 16:03:29 -0700602 boolean wallpaperMightChange = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700603 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700604 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700605 wallpaperMightChange |= win.clearAnimatingFlags();
Chong Zhange05bcb12016-07-26 17:47:29 -0700606 }
Chong Zhangb0d26702016-08-12 16:03:29 -0700607 if (wallpaperMightChange) {
608 requestUpdateWallpaperIfNeeded();
609 }
Chong Zhange05bcb12016-07-26 17:47:29 -0700610 }
611
Robert Carre12aece2016-02-02 22:43:27 -0800612 void destroySurfaces() {
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700613 destroySurfaces(false /*cleanupOnResume*/);
614 }
615
616 /**
617 * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure
618 * the client has finished with them.
619 *
620 * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If
621 * set to true, destroy only surfaces of removed windows, and clear relevant flags of the
622 * others so that they are ready to be reused. If set to false (common case), destroy all
623 * surfaces that's eligible, if the app is already stopped.
624 */
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700625 private void destroySurfaces(boolean cleanupOnResume) {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700626 boolean destroyedSomething = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700627 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700628 final WindowState win = mChildren.get(i);
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700629 destroyedSomething |= win.destroySurface(cleanupOnResume, mAppStopped);
Robert Carre12aece2016-02-02 22:43:27 -0800630 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700631 if (destroyedSomething) {
632 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700633 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Robert Carre12aece2016-02-02 22:43:27 -0800634 }
635 }
636
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800637 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700638 * Notify that the app is now resumed, and it was not stopped before, perform a clean
639 * up of the surfaces
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800640 */
Jorim Jaggibae01b12017-04-11 16:29:10 -0700641 void notifyAppResumed(boolean wasStopped) {
Chong Zhangad24f962016-08-25 12:12:33 -0700642 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped
Jorim Jaggibae01b12017-04-11 16:29:10 -0700643 + " " + this);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700644 mAppStopped = false;
645 if (!wasStopped) {
646 destroySurfaces(true /*cleanupOnResume*/);
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800647 }
Robert Carre12aece2016-02-02 22:43:27 -0800648 }
649
Chong Zhangbef461f2015-10-27 11:38:24 -0700650 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700651 * Notify that the app has stopped, and it is okay to destroy any surfaces which were
652 * keeping alive in case they were still being used.
653 */
654 void notifyAppStopped() {
655 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this);
656 mAppStopped = true;
657 destroySurfaces();
658 // Remove any starting window that was added for this app if they are still around.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800659 if (getController() != null) {
660 getController().removeStartingWindow();
661 }
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700662 }
663
664 /**
Chong Zhangbef461f2015-10-27 11:38:24 -0700665 * Checks whether we should save surfaces for this app.
666 *
667 * @return true if the surfaces should be saved, false otherwise.
668 */
669 boolean shouldSaveSurface() {
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800670 // We want to save surface if the app's windows are "allDrawn".
671 // (If we started entering animation early with saved surfaces, allDrawn
672 // should have been restored to true. So we'll save again in that case
673 // even if app didn't actually finish drawing.)
674 return allDrawn;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800675 }
676
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700677 private boolean canRestoreSurfaces() {
678 for (int i = mChildren.size() -1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700679 final WindowState w = mChildren.get(i);
Chong Zhang92147042016-05-09 12:47:11 -0700680 if (w.canRestoreSurface()) {
Robert Carr13f7be9e2015-12-02 18:39:45 -0800681 return true;
682 }
Chong Zhangbef461f2015-10-27 11:38:24 -0700683 }
684 return false;
685 }
686
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700687 private void clearWasVisibleBeforeClientHidden() {
688 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700689 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700690 w.clearWasVisibleBeforeClientHidden();
Chong Zhang92147042016-05-09 12:47:11 -0700691 }
692 }
693
Chong Zhang8e4bda92016-05-04 15:08:18 -0700694 /**
695 * Whether the app has some window that is invisible in layout, but
696 * animating with saved surface.
697 */
698 boolean isAnimatingInvisibleWithSavedSurface() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700699 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700700 final WindowState w = mChildren.get(i);
Chong Zhang8e4bda92016-05-04 15:08:18 -0700701 if (w.isAnimatingInvisibleWithSavedSurface()) {
702 return true;
703 }
704 }
705 return false;
706 }
707
708 /**
709 * Hide all window surfaces that's still invisible in layout but animating
710 * with a saved surface, and mark them destroying.
711 */
712 void stopUsingSavedSurfaceLocked() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700713 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700714 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700715 w.stopUsingSavedSurface();
Chong Zhang8e4bda92016-05-04 15:08:18 -0700716 }
717 destroySurfaces();
718 }
719
Chong Zhangf58631a2016-05-24 16:02:10 -0700720 void markSavedSurfaceExiting() {
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 w.markSavedSurfaceExiting();
Chong Zhangf58631a2016-05-24 16:02:10 -0700724 }
725 }
726
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700727 void restoreSavedSurfaceForInterestingWindows() {
Chong Zhang92147042016-05-09 12:47:11 -0700728 if (!canRestoreSurfaces()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700729 clearWasVisibleBeforeClientHidden();
Chong Zhangbef461f2015-10-27 11:38:24 -0700730 return;
731 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700732
733 // Check if all interesting windows are drawn and we can mark allDrawn=true.
734 int interestingNotDrawn = -1;
735
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700736 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700737 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700738 interestingNotDrawn = w.restoreSavedSurfaceForInterestingWindow();
Chong Zhangbef461f2015-10-27 11:38:24 -0700739 }
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800740
Chong Zhang92147042016-05-09 12:47:11 -0700741 if (!allDrawn) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700742 allDrawn = (interestingNotDrawn == 0);
Chong Zhang92147042016-05-09 12:47:11 -0700743 if (allDrawn) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700744 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Chong Zhang92147042016-05-09 12:47:11 -0700745 }
746 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700747 clearWasVisibleBeforeClientHidden();
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800748
749 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700750 "restoreSavedSurfaceForInterestingWindows: " + this + " allDrawn=" + allDrawn
751 + " interestingNotDrawn=" + interestingNotDrawn);
Chong Zhangbef461f2015-10-27 11:38:24 -0700752 }
753
754 void destroySavedSurfaces() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700755 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700756 final WindowState win = mChildren.get(i);
Robert Carr13f7be9e2015-12-02 18:39:45 -0800757 win.destroySavedSurface();
Chong Zhangbef461f2015-10-27 11:38:24 -0700758 }
Chong Zhang92147042016-05-09 12:47:11 -0700759 }
760
761 void clearAllDrawn() {
762 allDrawn = false;
763 deferClearAllDrawn = false;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700764 allDrawnExcludingSaved = false;
Chong Zhangbef461f2015-10-27 11:38:24 -0700765 }
766
Bryce Lee6d410262017-02-28 15:30:17 -0800767 Task getTask() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800768 return (Task) getParent();
Bryce Lee6d410262017-02-28 15:30:17 -0800769 }
770
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800771 TaskStack getStack() {
772 final Task task = getTask();
773 if (task != null) {
774 return task.mStack;
775 } else {
776 return null;
777 }
778 }
779
Bryce Lee6d410262017-02-28 15:30:17 -0800780 @Override
781 void onParentSet() {
782 super.onParentSet();
783
Robert Carred3e83b2017-04-21 13:26:55 -0700784 final Task task = getTask();
785
Bryce Lee6d410262017-02-28 15:30:17 -0800786 // When the associated task is {@code null}, the {@link AppWindowToken} can no longer
787 // access visual elements like the {@link DisplayContent}. We must remove any associations
788 // such as animations.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800789 if (!mReparenting) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800790 if (task == null) {
791 // It is possible we have been marked as a closing app earlier. We must remove ourselves
792 // from this list so we do not participate in any future animations.
793 mService.mClosingApps.remove(this);
Robert Carred3e83b2017-04-21 13:26:55 -0700794 } else if (mLastParent != null && mLastParent.mStack != null) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800795 task.mStack.mExitingAppTokens.remove(this);
796 }
Bryce Lee6d410262017-02-28 15:30:17 -0800797 }
Robert Carred3e83b2017-04-21 13:26:55 -0700798 mLastParent = task;
Bryce Lee6d410262017-02-28 15:30:17 -0800799 }
800
Wale Ogunwalefa854eb2016-09-20 13:43:52 -0700801 void postWindowRemoveStartingWindowCleanup(WindowState win) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700802 // TODO: Something smells about the code below...Is there a better way?
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700803 if (startingWindow == win) {
804 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800805 if (getController() != null) {
806 getController().removeStartingWindow();
807 }
Wale Ogunwale6c459212017-05-17 08:56:03 -0700808 } else if (mChildren.size() == 0) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700809 // If this is the last window and we had requested a starting transition window,
810 // well there is no point now.
Jorim Jaggi02886a82016-12-06 09:10:06 -0800811 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingData");
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700812 startingData = null;
Wale Ogunwale6c459212017-05-17 08:56:03 -0700813 if (mHiddenSetFromTransferredStartingWindow) {
814 // We set the hidden state to false for the token from a transferred starting window.
815 // We now reset it back to true since the starting window was the last window in the
816 // token.
817 hidden = true;
818 }
Jorim Jaggi829b9cd2017-01-23 16:20:53 +0100819 } else if (mChildren.size() == 1 && startingSurface != null && !isRelaunching()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700820 // If this is the last window except for a starting transition window,
821 // we need to get rid of the starting transition.
Jorim Jaggie4b0f282017-05-17 15:10:29 +0200822 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Last window, removing starting window "
823 + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800824 if (getController() != null) {
825 getController().removeStartingWindow();
826 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700827 }
828 }
829
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700830 void removeDeadWindows() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700831 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700832 WindowState win = mChildren.get(winNdx);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800833 if (win.mAppDied) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700834 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700835 "removeDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800836 // Set mDestroying, we don't want any animation or delayed removal here.
837 win.mDestroying = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700838 // Also removes child windows.
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700839 win.removeIfPossible();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800840 }
841 }
842 }
843
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700844 boolean hasWindowsAlive() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700845 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700846 // No need to loop through child windows as the answer should be the same as that of the
847 // parent window.
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700848 if (!(mChildren.get(i)).mAppDied) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700849 return true;
850 }
851 }
852 return false;
853 }
854
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700855 void setWillReplaceWindows(boolean animate) {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700856 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
857 "Marking app token " + this + " with replacing windows.");
Robert Carra1eb4392015-12-10 12:43:51 -0800858
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700859 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700860 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700861 w.setWillReplaceWindow(animate);
Robert Carra1eb4392015-12-10 12:43:51 -0800862 }
863 if (animate) {
864 // Set-up dummy animation so we can start treating windows associated with this
865 // token like they are in transition before the new app window is ready for us to
866 // run the real transition animation.
867 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700868 "setWillReplaceWindow() Setting dummy animation on: " + this);
Robert Carra1eb4392015-12-10 12:43:51 -0800869 mAppAnimator.setDummyAnimation();
870 }
871 }
872
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700873 void setWillReplaceChildWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700874 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this
Robert Carr23fa16b2016-01-13 13:19:58 -0800875 + " with replacing child windows.");
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.setWillReplaceChildWindows();
Robert Carr23fa16b2016-01-13 13:19:58 -0800879 }
880 }
881
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700882 void clearWillReplaceWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700883 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
884 "Resetting app token " + this + " of replacing window marks.");
Chong Zhangf596cd52016-01-05 13:42:44 -0800885
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700886 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700887 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700888 w.clearWillReplaceWindow();
Chong Zhangf596cd52016-01-05 13:42:44 -0800889 }
890 }
891
Chong Zhang4d7369a2016-04-25 16:09:14 -0700892 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700893 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700894 final WindowState w = mChildren.get(i);
Chong Zhang4d7369a2016-04-25 16:09:14 -0700895 w.requestUpdateWallpaperIfNeeded();
896 }
897 }
898
Chong Zhangd78ddb42016-03-02 17:01:14 -0800899 boolean isRelaunching() {
900 return mPendingRelaunchCount > 0;
901 }
902
Robert Carr68375192017-06-13 12:41:53 -0700903 boolean shouldFreezeBounds() {
904 final Task task = getTask();
905
906 // For freeform windows, we can't freeze the bounds at the moment because this would make
907 // the resizing unresponsive.
908 if (task == null || task.inFreeformWorkspace()) {
909 return false;
910 }
911
912 // We freeze the bounds while drag resizing to deal with the time between
913 // the divider/drag handle being released, and the handling it's new
914 // configuration. If we are relaunched outside of the drag resizing state,
915 // we need to be careful not to do this.
916 return getTask().isDragResizing();
917 }
918
Chong Zhangd78ddb42016-03-02 17:01:14 -0800919 void startRelaunching() {
Robert Carr68375192017-06-13 12:41:53 -0700920 if (shouldFreezeBounds()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -0800921 freezeBounds();
922 }
Robert Carrd5c7dd62017-03-08 10:39:30 -0800923
924 // In the process of tearing down before relaunching, the app will
925 // try and clean up it's child surfaces. We need to prevent this from
926 // happening, so we sever the children, transfering their ownership
927 // from the client it-self to the parent surface (owned by us).
928 for (int i = mChildren.size() - 1; i >= 0; i--) {
929 final WindowState w = mChildren.get(i);
930 w.mWinAnimator.detachChildren();
931 }
932
Chong Zhangd78ddb42016-03-02 17:01:14 -0800933 mPendingRelaunchCount++;
934 }
935
936 void finishRelaunching() {
Robert Carr68375192017-06-13 12:41:53 -0700937 unfreezeBounds();
938
Chong Zhangd78ddb42016-03-02 17:01:14 -0800939 if (mPendingRelaunchCount > 0) {
940 mPendingRelaunchCount--;
Bryce Lee081554b2017-05-25 07:52:12 -0700941 } else {
942 // Update keyguard flags upon finishing relaunch.
943 checkKeyguardFlagsChanged();
Chong Zhangd78ddb42016-03-02 17:01:14 -0800944 }
945 }
946
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700947 void clearRelaunching() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700948 if (mPendingRelaunchCount == 0) {
949 return;
950 }
Robert Carr68375192017-06-13 12:41:53 -0700951 unfreezeBounds();
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700952 mPendingRelaunchCount = 0;
953 }
954
Wale Ogunwale07bcab72016-10-14 15:30:09 -0700955 /**
956 * Returns true if the new child window we are adding to this token is considered greater than
957 * the existing child window in this token in terms of z-order.
958 */
959 @Override
960 protected boolean isFirstChildWindowGreaterThanSecond(WindowState newWindow,
961 WindowState existingWindow) {
962 final int type1 = newWindow.mAttrs.type;
963 final int type2 = existingWindow.mAttrs.type;
964
965 // Base application windows should be z-ordered BELOW all other windows in the app token.
966 if (type1 == TYPE_BASE_APPLICATION && type2 != TYPE_BASE_APPLICATION) {
967 return false;
968 } else if (type1 != TYPE_BASE_APPLICATION && type2 == TYPE_BASE_APPLICATION) {
969 return true;
970 }
971
972 // Starting windows should be z-ordered ABOVE all other windows in the app token.
973 if (type1 == TYPE_APPLICATION_STARTING && type2 != TYPE_APPLICATION_STARTING) {
974 return true;
975 } else if (type1 != TYPE_APPLICATION_STARTING && type2 == TYPE_APPLICATION_STARTING) {
976 return false;
977 }
978
979 // Otherwise the new window is greater than the existing window.
980 return true;
981 }
982
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700983 @Override
Robert Carra1eb4392015-12-10 12:43:51 -0800984 void addWindow(WindowState w) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700985 super.addWindow(w);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700986
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700987 boolean gotReplacementWindow = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700988 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700989 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700990 gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w);
991 }
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700992
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700993 // if we got a replacement window, reset the timeout to give drawing more time
994 if (gotReplacementWindow) {
995 mService.scheduleWindowReplacementTimeouts(this);
Robert Carra1eb4392015-12-10 12:43:51 -0800996 }
Jorim Jaggife762342016-10-13 14:33:27 +0200997 checkKeyguardFlagsChanged();
998 }
999
1000 @Override
1001 void removeChild(WindowState child) {
1002 super.removeChild(child);
1003 checkKeyguardFlagsChanged();
Robert Carra1eb4392015-12-10 12:43:51 -08001004 }
1005
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001006 private boolean waitingForReplacement() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001007 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001008 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001009 if (candidate.waitingForReplacement()) {
Robert Carra1eb4392015-12-10 12:43:51 -08001010 return true;
1011 }
1012 }
1013 return false;
1014 }
1015
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001016 void onWindowReplacementTimeout() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001017 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001018 (mChildren.get(i)).onWindowReplacementTimeout();
Robert Carra1eb4392015-12-10 12:43:51 -08001019 }
1020 }
1021
Winson Chung30480042017-01-26 10:55:34 -08001022 void reparent(Task task, int position) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001023 final Task currentTask = getTask();
1024 if (task == currentTask) {
Winson Chung30480042017-01-26 10:55:34 -08001025 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001026 "window token=" + this + " already child of task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -08001027 }
Bryce Lee6d410262017-02-28 15:30:17 -08001028
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001029 if (currentTask.mStack != task.mStack) {
Bryce Lee6d410262017-02-28 15:30:17 -08001030 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001031 "window token=" + this + " current task=" + currentTask
Bryce Lee6d410262017-02-28 15:30:17 -08001032 + " belongs to a different stack than " + task);
1033 }
1034
Winson Chung30480042017-01-26 10:55:34 -08001035 if (DEBUG_ADD_REMOVE) Slog.i(TAG, "reParentWindowToken: removing window token=" + this
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001036 + " from task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -08001037 final DisplayContent prevDisplayContent = getDisplayContent();
1038
Bryce Lee6d410262017-02-28 15:30:17 -08001039 mReparenting = true;
1040
Winson Chung30480042017-01-26 10:55:34 -08001041 getParent().removeChild(this);
1042 task.addChild(this, position);
1043
Bryce Lee6d410262017-02-28 15:30:17 -08001044 mReparenting = false;
1045
Winson Chung30480042017-01-26 10:55:34 -08001046 // Relayout display(s).
1047 final DisplayContent displayContent = task.getDisplayContent();
1048 displayContent.setLayoutNeeded();
1049 if (prevDisplayContent != displayContent) {
1050 onDisplayChanged(displayContent);
1051 prevDisplayContent.setLayoutNeeded();
1052 }
1053 }
1054
Jorim Jaggi0429f352015-12-22 16:29:16 +01001055 /**
1056 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
1057 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
1058 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
1059 * with a queue.
1060 */
Chong Zhangd78ddb42016-03-02 17:01:14 -08001061 private void freezeBounds() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001062 final Task task = getTask();
1063 mFrozenBounds.offer(new Rect(task.mPreparedFrozenBounds));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001064
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001065 if (task.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) {
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001066 // We didn't call prepareFreezingBounds on the task, so use the current value.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001067 mFrozenMergedConfig.offer(new Configuration(task.getConfiguration()));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001068 } else {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001069 mFrozenMergedConfig.offer(new Configuration(task.mPreparedFrozenMergedConfig));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001070 }
Andrii Kulianb10330d2016-09-16 13:51:46 -07001071 // Calling unset() to make it equal to Configuration.EMPTY.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001072 task.mPreparedFrozenMergedConfig.unset();
Jorim Jaggi0429f352015-12-22 16:29:16 +01001073 }
1074
1075 /**
1076 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
1077 */
Chong Zhangd78ddb42016-03-02 17:01:14 -08001078 private void unfreezeBounds() {
Robert Carr68375192017-06-13 12:41:53 -07001079 if (mFrozenBounds.isEmpty()) {
1080 return;
Wale Ogunwale37dbafc2016-06-27 10:15:20 -07001081 }
Robert Carr68375192017-06-13 12:41:53 -07001082 mFrozenBounds.remove();
Wale Ogunwale37dbafc2016-06-27 10:15:20 -07001083 if (!mFrozenMergedConfig.isEmpty()) {
1084 mFrozenMergedConfig.remove();
1085 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001086 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001087 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001088 win.onUnfreezeBounds();
Jorim Jaggi4846ee32016-01-07 17:39:12 +01001089 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001090 mService.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +01001091 }
1092
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001093 void setAppLayoutChanges(int changes, String reason) {
1094 if (!mChildren.isEmpty()) {
1095 final DisplayContent dc = getDisplayContent();
1096 dc.pendingLayoutChanges |= changes;
1097 if (DEBUG_LAYOUT_REPEATS) {
1098 mService.mWindowPlacerLocked.debugLayoutRepeats(reason, dc.pendingLayoutChanges);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001099 }
1100 }
1101 }
1102
1103 void removeReplacedWindowIfNeeded(WindowState replacement) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001104 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001105 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001106 if (win.removeReplacedWindowIfNeeded(replacement)) {
1107 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001108 }
1109 }
1110 }
1111
1112 void startFreezingScreen() {
1113 if (DEBUG_ORIENTATION) logWithStack(TAG, "Set freezing of " + appToken + ": hidden="
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001114 + hidden + " freezing=" + mAppAnimator.freezingScreen + " hiddenRequested="
1115 + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001116 if (!hiddenRequested) {
1117 if (!mAppAnimator.freezingScreen) {
1118 mAppAnimator.freezingScreen = true;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001119 mService.registerAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001120 mAppAnimator.lastFreezeDuration = 0;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001121 mService.mAppsFreezingScreen++;
1122 if (mService.mAppsFreezingScreen == 1) {
Bryce Lee8f853582017-06-05 17:25:59 -07001123 mService.startFreezingDisplayLocked(false, 0, 0, getDisplayContent());
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001124 mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT);
1125 mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001126 }
1127 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001128 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001129 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 w.onStartFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001132 }
1133 }
1134 }
1135
1136 void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) {
1137 if (!mAppAnimator.freezingScreen) {
1138 return;
1139 }
1140 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + this + " force=" + force);
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001141 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001142 boolean unfrozeWindows = false;
1143 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001144 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001145 unfrozeWindows |= w.onStopFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001146 }
1147 if (force || unfrozeWindows) {
1148 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this);
1149 mAppAnimator.freezingScreen = false;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001150 mService.unregisterAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001151 mAppAnimator.lastFreezeDuration =
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001152 (int)(SystemClock.elapsedRealtime() - mService.mDisplayFreezeTime);
1153 mService.mAppsFreezingScreen--;
1154 mService.mLastFinishedFreezeSource = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001155 }
1156 if (unfreezeSurfaceNow) {
1157 if (unfrozeWindows) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001158 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001159 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001160 mService.stopFreezingDisplayLocked();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001161 }
1162 }
1163
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001164 @Override
1165 public void onAppFreezeTimeout() {
1166 Slog.w(TAG_WM, "Force clearing freeze: " + this);
1167 stopFreezingScreen(true, true);
1168 }
1169
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001170 boolean transferStartingWindow(IBinder transferFrom) {
Wale Ogunwale02319a62016-09-26 15:21:22 -07001171 final AppWindowToken fromToken = getDisplayContent().getAppWindowToken(transferFrom);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001172 if (fromToken == null) {
1173 return false;
1174 }
1175
1176 final WindowState tStartingWindow = fromToken.startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001177 if (tStartingWindow != null && fromToken.startingSurface != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001178 // In this case, the starting icon has already been displayed, so start
1179 // letting windows get shown immediately without any more transitions.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001180 mService.mSkipAppTransitionAnimation = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001181
1182 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow
1183 + " from " + fromToken + " to " + this);
1184
1185 final long origId = Binder.clearCallingIdentity();
1186
1187 // Transfer the starting window over to the new token.
1188 startingData = fromToken.startingData;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001189 startingSurface = fromToken.startingSurface;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001190 startingDisplayed = fromToken.startingDisplayed;
1191 fromToken.startingDisplayed = false;
1192 startingWindow = tStartingWindow;
1193 reportedVisible = fromToken.reportedVisible;
1194 fromToken.startingData = null;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001195 fromToken.startingSurface = null;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001196 fromToken.startingWindow = null;
1197 fromToken.startingMoved = true;
1198 tStartingWindow.mToken = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001199 tStartingWindow.mAppToken = this;
1200
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001201 if (DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001202 "Removing starting " + tStartingWindow + " from " + fromToken);
Wale Ogunwalefa854eb2016-09-20 13:43:52 -07001203 fromToken.removeChild(tStartingWindow);
1204 fromToken.postWindowRemoveStartingWindowCleanup(tStartingWindow);
Wale Ogunwale6c459212017-05-17 08:56:03 -07001205 fromToken.mHiddenSetFromTransferredStartingWindow = false;
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001206 addWindow(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001207
1208 // Propagate other interesting state between the tokens. If the old token is displayed,
1209 // we should immediately force the new one to be displayed. If it is animating, we need
1210 // to move that animation to the new one.
1211 if (fromToken.allDrawn) {
1212 allDrawn = true;
1213 deferClearAllDrawn = fromToken.deferClearAllDrawn;
1214 }
1215 if (fromToken.firstWindowDrawn) {
1216 firstWindowDrawn = true;
1217 }
1218 if (!fromToken.hidden) {
1219 hidden = false;
1220 hiddenRequested = false;
Wale Ogunwale6c459212017-05-17 08:56:03 -07001221 mHiddenSetFromTransferredStartingWindow = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001222 }
Wale Ogunwale89973222017-04-23 18:39:45 -07001223 setClientHidden(fromToken.mClientHidden);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001224 fromToken.mAppAnimator.transferCurrentAnimation(
1225 mAppAnimator, tStartingWindow.mWinAnimator);
1226
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001227 mService.updateFocusedWindowLocked(
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001228 UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/);
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001229 getDisplayContent().setLayoutNeeded();
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001230 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001231 Binder.restoreCallingIdentity(origId);
1232 return true;
1233 } else if (fromToken.startingData != null) {
1234 // The previous app was getting ready to show a
1235 // starting window, but hasn't yet done so. Steal it!
1236 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1237 "Moving pending starting from " + fromToken + " to " + this);
1238 startingData = fromToken.startingData;
1239 fromToken.startingData = null;
1240 fromToken.startingMoved = true;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001241 if (getController() != null) {
1242 getController().scheduleAddStartingWindow();
1243 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001244 return true;
1245 }
1246
1247 final AppWindowAnimator tAppAnimator = fromToken.mAppAnimator;
1248 final AppWindowAnimator wAppAnimator = mAppAnimator;
1249 if (tAppAnimator.thumbnail != null) {
1250 // The old token is animating with a thumbnail, transfer that to the new token.
1251 if (wAppAnimator.thumbnail != null) {
1252 wAppAnimator.thumbnail.destroy();
1253 }
1254 wAppAnimator.thumbnail = tAppAnimator.thumbnail;
1255 wAppAnimator.thumbnailLayer = tAppAnimator.thumbnailLayer;
1256 wAppAnimator.thumbnailAnimation = tAppAnimator.thumbnailAnimation;
1257 tAppAnimator.thumbnail = null;
1258 }
1259 return false;
1260 }
1261
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001262 boolean isLastWindow(WindowState win) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001263 return mChildren.size() == 1 && mChildren.get(0) == win;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001264 }
1265
1266 void setAllAppWinAnimators() {
1267 final ArrayList<WindowStateAnimator> allAppWinAnimators = mAppAnimator.mAllAppWinAnimators;
1268 allAppWinAnimators.clear();
1269
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001270 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001271 for (int j = 0; j < windowsCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001272 (mChildren.get(j)).addWinAnimatorToList(allAppWinAnimators);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001273 }
1274 }
1275
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001276 @Override
1277 void onAppTransitionDone() {
1278 sendingToBottom = false;
1279 }
1280
Wale Ogunwale51362492016-09-08 17:49:17 -07001281 /**
1282 * We override because this class doesn't want its children affecting its reported orientation
1283 * in anyway.
1284 */
1285 @Override
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001286 int getOrientation(int candidate) {
Bryce Leed1ac18c2017-05-11 07:59:41 -07001287 // We do not allow non-fullscreen apps to influence orientation beyond O. While we do
Bryce Lee39791592017-04-26 09:29:12 -07001288 // throw an exception in {@link Activity#onCreate} and
1289 // {@link Activity#setRequestedOrientation}, we also ignore the orientation here so that
1290 // other calculations aren't affected.
Bryce Leed1ac18c2017-05-11 07:59:41 -07001291 if (!fillsParent() && mTargetSdk > O) {
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001292 // Can't specify orientation if app doesn't fill parent.
1293 return SCREEN_ORIENTATION_UNSET;
1294 }
1295
1296 if (candidate == SCREEN_ORIENTATION_BEHIND) {
1297 // Allow app to specify orientation regardless of its visibility state if the current
1298 // candidate want us to use orientation behind. I.e. the visible app on-top of this one
1299 // wants us to use the orientation of the app behind it.
1300 return mOrientation;
1301 }
1302
Bryce Lee61fbcbc2017-03-10 14:14:03 -08001303 // The {@link AppWindowToken} should only specify an orientation when it is not closing or
1304 // going to the bottom. Allowing closing {@link AppWindowToken} to participate can lead to
1305 // an Activity in another task being started in the wrong orientation during the transition.
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001306 if (!(sendingToBottom || mService.mClosingApps.contains(this))
Bryce Lee61fbcbc2017-03-10 14:14:03 -08001307 && (isVisible() || mService.mOpeningApps.contains(this))) {
Bryce Leea163b762017-01-24 11:05:01 -08001308 return mOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001309 }
Bryce Leea163b762017-01-24 11:05:01 -08001310
1311 return SCREEN_ORIENTATION_UNSET;
Wale Ogunwale51362492016-09-08 17:49:17 -07001312 }
1313
Wale Ogunwaleb198b742016-12-01 08:44:09 -08001314 /** Returns the app's preferred orientation regardless of its currently visibility state. */
1315 int getOrientationIgnoreVisibility() {
1316 return mOrientation;
1317 }
1318
Craig Mautnerdbb79912012-03-01 18:59:14 -08001319 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001320 void checkAppWindowsReadyToShow() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001321 if (allDrawn == mAppAnimator.allDrawn) {
1322 return;
1323 }
1324
1325 mAppAnimator.allDrawn = allDrawn;
1326 if (!allDrawn) {
1327 return;
1328 }
1329
1330 // The token has now changed state to having all windows shown... what to do, what to do?
1331 if (mAppAnimator.freezingScreen) {
1332 mAppAnimator.showAllWindowsLocked();
1333 stopFreezingScreen(false, true);
1334 if (DEBUG_ORIENTATION) Slog.i(TAG,
1335 "Setting mOrientationChangeComplete=true because wtoken " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001336 + " numInteresting=" + mNumInterestingWindows + " numDrawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001337 // This will set mOrientationChangeComplete and cause a pass through layout.
1338 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001339 "checkAppWindowsReadyToShow: freezingScreen");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001340 } else {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001341 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001342
1343 // We can now show all of the drawn windows!
1344 if (!mService.mOpeningApps.contains(this)) {
1345 mService.mAnimator.orAnimating(mAppAnimator.showAllWindowsLocked());
1346 }
1347 }
1348 }
1349
Matthew Ng5d23afa2017-06-21 16:16:24 -07001350 /**
Bryce Leed390deb2017-06-22 13:14:28 -07001351 * Returns whether the drawn window states of this {@link AppWindowToken} has considered every
1352 * child {@link WindowState}. A child is considered if it has been passed into
1353 * {@link #updateDrawnWindowStates(WindowState)} after being added. This is used to determine
1354 * whether states, such as {@code allDrawn}, can be set, which relies on state variables such as
1355 * {@code mNumInterestingWindows}, which depend on all {@link WindowState}s being considered.
1356 *
1357 * @return {@code true} If all children have been considered, {@code false}.
1358 */
1359 private boolean allDrawnStatesConsidered() {
Bryce Lee6311c4b2017-07-06 14:09:29 -07001360 for (int i = mChildren.size() - 1; i >= 0; --i) {
1361 final WindowState child = mChildren.get(i);
1362 if (child.mightAffectAllDrawn(false /*visibleOnly*/ )
1363 && !child.getDrawnStateEvaluated()) {
Bryce Leed390deb2017-06-22 13:14:28 -07001364 return false;
1365 }
1366 }
1367 return true;
1368 }
1369
1370 /**
Matthew Ng5d23afa2017-06-21 16:16:24 -07001371 * Determines if the token has finished drawing. This should only be called from
1372 * {@link DisplayContent#applySurfaceChangesTransaction}
1373 */
Matthew Ng498c71d2017-04-18 13:55:45 -07001374 void updateAllDrawn() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001375 if (!allDrawn) {
Matthew Ng498c71d2017-04-18 13:55:45 -07001376 // Number of drawn windows can be less when a window is being relaunched, wait for
Bryce Leed390deb2017-06-22 13:14:28 -07001377 // all windows to be launched and drawn for this token be considered all drawn.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001378 final int numInteresting = mNumInterestingWindows;
Bryce Leed390deb2017-06-22 13:14:28 -07001379
1380 // We must make sure that all present children have been considered (determined by
1381 // {@link #allDrawnStatesConsidered}) before evaluating whether everything has been
1382 // drawn.
1383 if (numInteresting > 0 && allDrawnStatesConsidered()
1384 && mNumDrawnWindows >= numInteresting && !isRelaunching()) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001385 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawn: " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001386 + " interesting=" + numInteresting + " drawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001387 allDrawn = true;
1388 // Force an additional layout pass where
1389 // WindowStateAnimator#commitFinishDrawingLocked() will call performShowLocked().
Matthew Ng498c71d2017-04-18 13:55:45 -07001390 if (mDisplayContent != null) {
1391 mDisplayContent.setLayoutNeeded();
1392 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001393 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Robert Carrecc06b32017-04-18 14:25:10 -07001394
Winson Chunge7ba6862017-05-24 12:13:33 -07001395 // Notify the pinned stack upon all windows drawn. If there was an animation in
1396 // progress then this signal will resume that animation.
1397 final TaskStack pinnedStack = mDisplayContent.getStackById(PINNED_STACK_ID);
1398 if (pinnedStack != null) {
1399 pinnedStack.onAllWindowsDrawn();
Robert Carrecc06b32017-04-18 14:25:10 -07001400 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001401 }
1402 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001403
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001404 if (!allDrawnExcludingSaved) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001405 int numInteresting = mNumInterestingWindowsExcludingSaved;
1406 if (numInteresting > 0 && mNumDrawnWindowsExcludingSaved >= numInteresting) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001407 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawnExcludingSaved: " + this
1408 + " interesting=" + numInteresting
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001409 + " drawn=" + mNumDrawnWindowsExcludingSaved);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001410 allDrawnExcludingSaved = true;
Matthew Ng498c71d2017-04-18 13:55:45 -07001411 if (mDisplayContent != null) {
1412 mDisplayContent.setLayoutNeeded();
1413 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001414 if (isAnimatingInvisibleWithSavedSurface()
1415 && !mService.mFinishedEarlyAnim.contains(this)) {
1416 mService.mFinishedEarlyAnim.add(this);
1417 }
1418 }
1419 }
1420 }
1421
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001422 /**
1423 * Updated this app token tracking states for interesting and drawn windows based on the window.
1424 *
1425 * @return Returns true if the input window is considered interesting and drawn while all the
1426 * windows in this app token where not considered drawn as of the last pass.
1427 */
1428 boolean updateDrawnWindowStates(WindowState w) {
Bryce Leed390deb2017-06-22 13:14:28 -07001429 w.setDrawnStateEvaluated(true /*evaluated*/);
1430
Jorim Jaggie4b0f282017-05-17 15:10:29 +02001431 if (DEBUG_STARTING_WINDOW_VERBOSE && w == startingWindow) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001432 Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" + w.isOnScreen()
1433 + " allDrawn=" + allDrawn + " freezingScreen=" + mAppAnimator.freezingScreen);
1434 }
1435
1436 if (allDrawn && allDrawnExcludingSaved && !mAppAnimator.freezingScreen) {
1437 return false;
1438 }
1439
1440 if (mLastTransactionSequence != mService.mTransactionSequence) {
1441 mLastTransactionSequence = mService.mTransactionSequence;
1442 mNumInterestingWindows = mNumDrawnWindows = 0;
1443 mNumInterestingWindowsExcludingSaved = 0;
1444 mNumDrawnWindowsExcludingSaved = 0;
1445 startingDisplayed = false;
1446 }
1447
1448 final WindowStateAnimator winAnimator = w.mWinAnimator;
1449
1450 boolean isInterestingAndDrawn = false;
1451
1452 if (!allDrawn && w.mightAffectAllDrawn(false /* visibleOnly */)) {
1453 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
1454 Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw()
1455 + ", isAnimationSet=" + winAnimator.isAnimationSet());
1456 if (!w.isDrawnLw()) {
1457 Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController
1458 + " pv=" + w.mPolicyVisibility
1459 + " mDrawState=" + winAnimator.drawStateToString()
1460 + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested
1461 + " a=" + winAnimator.mAnimating);
1462 }
1463 }
1464
1465 if (w != startingWindow) {
1466 if (w.isInteresting()) {
1467 mNumInterestingWindows++;
1468 if (w.isDrawnLw()) {
1469 mNumDrawnWindows++;
1470
1471 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, "tokenMayBeDrawn: "
1472 + this + " w=" + w + " numInteresting=" + mNumInterestingWindows
1473 + " freezingScreen=" + mAppAnimator.freezingScreen
1474 + " mAppFreezing=" + w.mAppFreezing);
1475
1476 isInterestingAndDrawn = true;
1477 }
1478 }
1479 } else if (w.isDrawnLw()) {
Jorim Jaggi3878ca32017-02-02 17:13:05 -08001480 if (getController() != null) {
1481 getController().reportStartingWindowDrawn();
1482 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001483 startingDisplayed = true;
1484 }
1485 }
1486
1487 if (!allDrawnExcludingSaved && w.mightAffectAllDrawn(true /* visibleOnly */)) {
1488 if (w != startingWindow && w.isInteresting()) {
1489 mNumInterestingWindowsExcludingSaved++;
1490 if (w.isDrawnLw() && !w.isAnimatingWithSavedSurface()) {
1491 mNumDrawnWindowsExcludingSaved++;
1492
1493 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
1494 "tokenMayBeDrawnExcludingSaved: " + this + " w=" + w
1495 + " numInteresting=" + mNumInterestingWindowsExcludingSaved
1496 + " freezingScreen=" + mAppAnimator.freezingScreen
1497 + " mAppFreezing=" + w.mAppFreezing);
1498
1499 isInterestingAndDrawn = true;
1500 }
1501 }
1502 }
1503
1504 return isInterestingAndDrawn;
1505 }
1506
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001507 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001508 void stepAppWindowsAnimation(long currentTime) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001509 mAppAnimator.wasAnimating = mAppAnimator.animating;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001510 if (mAppAnimator.stepAnimationLocked(currentTime)) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001511 mAppAnimator.animating = true;
1512 mService.mAnimator.setAnimating(true);
1513 mService.mAnimator.mAppWindowAnimating = true;
1514 } else if (mAppAnimator.wasAnimating) {
1515 // stopped animating, do one more pass through the layout
Wale Ogunwale1e129a42016-11-21 13:03:47 -08001516 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
1517 DEBUG_LAYOUT_REPEATS ? "appToken " + this + " done" : null);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001518 if (DEBUG_ANIM) Slog.v(TAG, "updateWindowsApps...: done animating " + this);
1519 }
1520 }
1521
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001522 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001523 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001524 // For legacy reasons we process the TaskStack.mExitingAppTokens first in DisplayContent
1525 // before the non-exiting app tokens. So, we skip the exiting app tokens here.
1526 // TODO: Investigate if we need to continue to do this or if we can just process them
1527 // in-order.
1528 if (mIsExiting && !waitingForReplacement()) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001529 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001530 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001531 return forAllWindowsUnchecked(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001532 }
1533
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001534 boolean forAllWindowsUnchecked(ToBooleanFunction<WindowState> callback,
1535 boolean traverseTopToBottom) {
1536 return super.forAllWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001537 }
1538
1539 @Override
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001540 AppWindowToken asAppWindowToken() {
1541 // I am an app window token!
1542 return this;
1543 }
1544
1545 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -07001546 boolean fillsParent() {
1547 return mFillsParent;
1548 }
1549
1550 void setFillsParent(boolean fillsParent) {
1551 mFillsParent = fillsParent;
1552 }
1553
Jorim Jaggife762342016-10-13 14:33:27 +02001554 boolean containsDismissKeyguardWindow() {
Bryce Lee081554b2017-05-25 07:52:12 -07001555 // Window state is transient during relaunch. We are not guaranteed to be frozen during the
1556 // entirety of the relaunch.
1557 if (isRelaunching()) {
1558 return mLastContainsDismissKeyguardWindow;
1559 }
1560
Jorim Jaggife762342016-10-13 14:33:27 +02001561 for (int i = mChildren.size() - 1; i >= 0; i--) {
1562 if ((mChildren.get(i).mAttrs.flags & FLAG_DISMISS_KEYGUARD) != 0) {
1563 return true;
1564 }
1565 }
1566 return false;
1567 }
1568
1569 boolean containsShowWhenLockedWindow() {
Bryce Lee081554b2017-05-25 07:52:12 -07001570 // When we are relaunching, it is possible for us to be unfrozen before our previous
1571 // windows have been added back. Using the cached value ensures that our previous
1572 // showWhenLocked preference is honored until relaunching is complete.
1573 if (isRelaunching()) {
1574 return mLastContainsShowWhenLockedWindow;
1575 }
1576
Jorim Jaggife762342016-10-13 14:33:27 +02001577 for (int i = mChildren.size() - 1; i >= 0; i--) {
1578 if ((mChildren.get(i).mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
1579 return true;
1580 }
1581 }
Bryce Lee081554b2017-05-25 07:52:12 -07001582
Jorim Jaggife762342016-10-13 14:33:27 +02001583 return false;
1584 }
1585
1586 void checkKeyguardFlagsChanged() {
1587 final boolean containsDismissKeyguard = containsDismissKeyguardWindow();
1588 final boolean containsShowWhenLocked = containsShowWhenLockedWindow();
1589 if (containsDismissKeyguard != mLastContainsDismissKeyguardWindow
1590 || containsShowWhenLocked != mLastContainsShowWhenLockedWindow) {
1591 mService.notifyKeyguardFlagsChanged(null /* callback */);
1592 }
1593 mLastContainsDismissKeyguardWindow = containsDismissKeyguard;
1594 mLastContainsShowWhenLockedWindow = containsShowWhenLocked;
1595 }
1596
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001597 WindowState getImeTargetBelowWindow(WindowState w) {
1598 final int index = mChildren.indexOf(w);
1599 if (index > 0) {
1600 final WindowState target = mChildren.get(index - 1);
1601 if (target.canBeImeTarget()) {
1602 return target;
1603 }
1604 }
1605 return null;
1606 }
1607
Winson Chungbe9be7f2017-06-28 10:55:22 -07001608 int getLowestAnimLayer() {
1609 for (int i = 0; i < mChildren.size(); i++) {
1610 final WindowState w = mChildren.get(i);
1611 if (w.mRemoved) {
1612 continue;
1613 }
1614 return w.mWinAnimator.mAnimLayer;
1615 }
1616 return Integer.MAX_VALUE;
1617 }
1618
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001619 WindowState getHighestAnimLayerWindow(WindowState currentTarget) {
1620 WindowState candidate = null;
1621 for (int i = mChildren.indexOf(currentTarget); i >= 0; i--) {
1622 final WindowState w = mChildren.get(i);
1623 if (w.mRemoved) {
1624 continue;
1625 }
1626 if (candidate == null || w.mWinAnimator.mAnimLayer >
1627 candidate.mWinAnimator.mAnimLayer) {
1628 candidate = w;
1629 }
1630 }
1631 return candidate;
1632 }
1633
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001634 /**
1635 * See {@link Activity#setDisablePreviewScreenshots}.
1636 */
1637 void setDisablePreviewScreenshots(boolean disable) {
Wale Ogunwale6c459212017-05-17 08:56:03 -07001638 mDisablePreviewScreenshots = disable;
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001639 }
1640
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001641 /**
1642 * Retrieves whether we'd like to generate a snapshot that's based solely on the theme. This is
1643 * the case when preview screenshots are disabled {@link #setDisablePreviewScreenshots} or when
1644 * we can't take a snapshot for other reasons, for example, if we have a secure window.
1645 *
1646 * @return True if we need to generate an app theme snapshot, false if we'd like to take a real
1647 * screenshot.
1648 */
1649 boolean shouldUseAppThemeSnapshot() {
Wale Ogunwale6c459212017-05-17 08:56:03 -07001650 return mDisablePreviewScreenshots || forAllWindows(w -> (w.mAttrs.flags & FLAG_SECURE) != 0,
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001651 true /* topToBottom */);
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001652 }
1653
Wale Ogunwale51362492016-09-08 17:49:17 -07001654 @Override
Robert Carrdee1b3f2017-02-27 11:33:33 -08001655 int getAnimLayerAdjustment() {
1656 return mAppAnimator.animLayerAdjustment;
1657 }
1658
1659 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001660 void dump(PrintWriter pw, String prefix) {
1661 super.dump(pw, prefix);
1662 if (appToken != null) {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001663 pw.println(prefix + "app=true mVoiceInteraction=" + mVoiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001664 }
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001665 pw.print(prefix); pw.print("task="); pw.println(getTask());
Wale Ogunwale51362492016-09-08 17:49:17 -07001666 pw.print(prefix); pw.print(" mFillsParent="); pw.print(mFillsParent);
1667 pw.print(" mOrientation="); pw.println(mOrientation);
Wale Ogunwale89973222017-04-23 18:39:45 -07001668 pw.println(prefix + "hiddenRequested=" + hiddenRequested + " mClientHidden=" + mClientHidden
1669 + ((mDeferHidingClient) ? " mDeferHidingClient=" + mDeferHidingClient : "")
1670 + " reportedDrawn=" + reportedDrawn + " reportedVisible=" + reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -07001671 if (paused) {
1672 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001673 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001674 if (mAppStopped) {
1675 pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped);
1676 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001677 if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0
Craig Mautner6fbda632012-07-03 09:26:39 -07001678 || allDrawn || mAppAnimator.allDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001679 pw.print(prefix); pw.print("mNumInterestingWindows=");
1680 pw.print(mNumInterestingWindows);
1681 pw.print(" mNumDrawnWindows="); pw.print(mNumDrawnWindows);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001682 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -07001683 pw.print(" allDrawn="); pw.print(allDrawn);
1684 pw.print(" (animator="); pw.print(mAppAnimator.allDrawn);
1685 pw.println(")");
1686 }
1687 if (inPendingTransaction) {
1688 pw.print(prefix); pw.print("inPendingTransaction=");
1689 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001690 }
Craig Mautner799bc1d2015-01-14 10:33:48 -08001691 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001692 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
1693 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -08001694 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -08001695 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001696 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001697 if (startingWindow != null || startingSurface != null
Wale Ogunwale6c459212017-05-17 08:56:03 -07001698 || startingDisplayed || startingMoved || mHiddenSetFromTransferredStartingWindow) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001699 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001700 pw.print(" startingSurface="); pw.print(startingSurface);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001701 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
Wale Ogunwale6c459212017-05-17 08:56:03 -07001702 pw.print(" startingMoved="); pw.print(startingMoved);
1703 pw.println(" mHiddenSetFromTransferredStartingWindow="
1704 + mHiddenSetFromTransferredStartingWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001705 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01001706 if (!mFrozenBounds.isEmpty()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -08001707 pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds);
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001708 pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig);
Chong Zhangd78ddb42016-03-02 17:01:14 -08001709 }
1710 if (mPendingRelaunchCount != 0) {
1711 pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount);
Jorim Jaggi0429f352015-12-22 16:29:16 +01001712 }
Wale Ogunwale9c64cb62017-04-12 13:39:59 -07001713 if (getController() != null) {
1714 pw.print(prefix); pw.print("controller="); pw.println(getController());
1715 }
Wale Ogunwalee287e192017-04-21 09:30:12 -07001716 if (mRemovingFromDisplay) {
1717 pw.println(prefix + "mRemovingFromDisplay=" + mRemovingFromDisplay);
1718 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001719 }
1720
1721 @Override
1722 public String toString() {
1723 if (stringName == null) {
1724 StringBuilder sb = new StringBuilder();
1725 sb.append("AppWindowToken{");
1726 sb.append(Integer.toHexString(System.identityHashCode(this)));
1727 sb.append(" token="); sb.append(token); sb.append('}');
1728 stringName = sb.toString();
1729 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001730 return stringName + ((mIsExiting) ? " mIsExiting=" : "");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001731 }
Jeff Browne9bdb312012-04-05 15:30:10 -07001732}