blob: 2e4de8c58650318cbe3312250e1907f86f8765c8 [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
chaviwd3bf08d2017-08-01 17:24:59 -0700196 /**
197 * See {@link #canTurnScreenOn()}
198 */
199 private boolean mCanTurnScreenOn = true;
200
Wale Ogunwale72919d22016-12-08 18:58:50 -0800201 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
202 DisplayContent dc, long inputDispatchingTimeoutNanos, boolean fullscreen,
203 boolean showForAllUsers, int targetSdk, int orientation, int rotationAnimationHint,
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800204 int configChanges, boolean launchTaskBehind, boolean alwaysFocusable,
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700205 AppWindowContainerController controller, Configuration overrideConfig, Rect bounds) {
206 this(service, token, voiceInteraction, dc, fullscreen, overrideConfig, bounds);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800207 setController(controller);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800208 mInputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800209 mShowForAllUsers = showForAllUsers;
210 mTargetSdk = targetSdk;
211 mOrientation = orientation;
212 layoutConfigChanges = (configChanges & (CONFIG_SCREEN_SIZE | CONFIG_ORIENTATION)) != 0;
213 mLaunchTaskBehind = launchTaskBehind;
214 mAlwaysFocusable = alwaysFocusable;
215 mRotationAnimationHint = rotationAnimationHint;
216
217 // Application tokens start out hidden.
218 hidden = true;
219 hiddenRequested = true;
220 }
221
222 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700223 DisplayContent dc, boolean fillsParent, Configuration overrideConfig, Rect bounds) {
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800224 super(service, token != null ? token.asBinder() : null, TYPE_APPLICATION, true, dc,
225 false /* ownerCanManageAppTokens */);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700226 appToken = token;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800227 mVoiceInteraction = voiceInteraction;
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800228 mFillsParent = fillsParent;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800229 mInputApplicationHandle = new InputApplicationHandle(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700230 mAppAnimator = new AppWindowAnimator(this, service);
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700231 if (overrideConfig != null) {
232 onOverrideConfigurationChanged(overrideConfig);
233 }
234 if (bounds != null) {
235 mBounds.set(bounds);
236 }
237 }
238
239 void onOverrideConfigurationChanged(Configuration overrideConfiguration, Rect bounds) {
240 onOverrideConfigurationChanged(overrideConfiguration);
241 if (mBounds.equals(bounds)) {
242 return;
243 }
244 // TODO(b/36505427): If bounds is in WC, then we can automatically call onResize() when set.
245 mBounds.set(bounds);
246 onResize();
247 }
248
249 void getBounds(Rect outBounds) {
250 outBounds.set(mBounds);
251 }
252
253 boolean hasBounds() {
254 return !mBounds.isEmpty();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800255 }
256
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800257 void onFirstWindowDrawn(WindowState win, WindowStateAnimator winAnimator) {
258 firstWindowDrawn = true;
259
260 // We now have a good window to show, remove dead placeholders
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700261 removeDeadWindows();
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800262
Jorim Jaggi02886a82016-12-06 09:10:06 -0800263 if (startingWindow != null) {
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800264 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, "Finish starting "
265 + win.mToken + ": first real window is shown, no animation");
266 // If this initial window is animating, stop it -- we will do an animation to reveal
267 // it from behind the starting window, so there is no need for it to also be doing its
268 // own stuff.
269 winAnimator.clearAnimation();
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800270 if (getController() != null) {
271 getController().removeStartingWindow();
272 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800273 }
274 updateReportedVisibilityLocked();
275 }
276
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800277 void updateReportedVisibilityLocked() {
278 if (appToken == null) {
279 return;
280 }
281
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700282 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700283 final int count = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800284
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700285 mReportedVisibilityResults.reset();
286
287 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700288 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700289 win.updateReportedVisibility(mReportedVisibilityResults);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800290 }
291
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700292 int numInteresting = mReportedVisibilityResults.numInteresting;
293 int numVisible = mReportedVisibilityResults.numVisible;
294 int numDrawn = mReportedVisibilityResults.numDrawn;
295 boolean nowGone = mReportedVisibilityResults.nowGone;
296
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700297 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Jorim Jaggi6dfd9ba2017-08-03 15:00:01 +0200298 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting && !hidden;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700299 if (!nowGone) {
300 // If the app is not yet gone, then it can only become visible/drawn.
301 if (!nowDrawn) {
302 nowDrawn = reportedDrawn;
303 }
304 if (!nowVisible) {
305 nowVisible = reportedVisible;
306 }
307 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800308 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800309 + numInteresting + " visible=" + numVisible);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800310 final AppWindowContainerController controller = getController();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700311 if (nowDrawn != reportedDrawn) {
312 if (nowDrawn) {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800313 if (controller != null) {
314 controller.reportWindowsDrawn();
315 }
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700316 }
317 reportedDrawn = nowDrawn;
318 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800319 if (nowVisible != reportedVisible) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700320 if (DEBUG_VISIBILITY) Slog.v(TAG,
321 "Visibility changed in " + this + ": vis=" + nowVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800322 reportedVisible = nowVisible;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800323 if (controller != null) {
324 if (nowVisible) {
325 controller.reportWindowsVisible();
326 } else {
327 controller.reportWindowsGone();
328 }
329 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800330 }
331 }
332
Wale Ogunwale89973222017-04-23 18:39:45 -0700333 boolean isClientHidden() {
334 return mClientHidden;
335 }
336
337 void setClientHidden(boolean hideClient) {
338 if (mClientHidden == hideClient || (hideClient && mDeferHidingClient)) {
339 return;
340 }
341 mClientHidden = hideClient;
342 sendAppVisibilityToClients();
343 }
344
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700345 boolean setVisibility(WindowManager.LayoutParams lp,
346 boolean visible, int transit, boolean performLayout, boolean isVoiceInteraction) {
347
348 boolean delayed = false;
349 inPendingTransaction = false;
Wale Ogunwale9e4721f2017-05-23 19:37:30 -0700350 // Reset the state of mHiddenSetFromTransferredStartingWindow since visibility is actually
351 // been set by the app now.
352 mHiddenSetFromTransferredStartingWindow = false;
Wale Ogunwale89973222017-04-23 18:39:45 -0700353 setClientHidden(!visible);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700354
355 // Allow for state changes and animation to be applied if:
356 // * token is transitioning visibility state
357 // * or the token was marked as hidden and is exiting before we had a chance to play the
358 // transition animation
359 // * or this is an opening app and windows are being replaced.
360 boolean visibilityChanged = false;
361 if (hidden == visible || (hidden && mIsExiting) || (visible && waitingForReplacement())) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700362 final AccessibilityController accessibilityController = mService.mAccessibilityController;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700363 boolean changed = false;
364 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
365 "Changing app " + this + " hidden=" + hidden + " performLayout=" + performLayout);
366
367 boolean runningAppAnimation = false;
368
369 if (transit != AppTransition.TRANSIT_UNSET) {
370 if (mAppAnimator.animation == AppWindowAnimator.sDummyAnimation) {
371 mAppAnimator.setNullAnimation();
372 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700373 if (mService.applyAnimationLocked(this, lp, transit, visible, isVoiceInteraction)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700374 delayed = runningAppAnimation = true;
375 }
376 final WindowState window = findMainWindow();
377 //TODO (multidisplay): Magnification is supported only for the default display.
378 if (window != null && accessibilityController != null
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700379 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700380 accessibilityController.onAppWindowTransitionLocked(window, transit);
381 }
382 changed = true;
383 }
384
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700385 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700386 for (int i = 0; i < windowsCount; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700387 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700388 changed |= win.onAppVisibilityChanged(visible, runningAppAnimation);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700389 }
390
391 hidden = hiddenRequested = !visible;
392 visibilityChanged = true;
393 if (!visible) {
394 stopFreezingScreen(true, true);
395 } else {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700396 // If we are being set visible, and the starting window is not yet displayed,
397 // then make sure it doesn't get displayed.
398 if (startingWindow != null && !startingWindow.isDrawnLw()) {
399 startingWindow.mPolicyVisibility = false;
400 startingWindow.mPolicyVisibilityAfterAnim = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700401 }
Jorim Jaggi38d44ec2017-06-14 16:04:59 -0700402
403 // We are becoming visible, so better freeze the screen with the windows that are
404 // getting visible so we also wait for them.
405 forAllWindows(mService::makeWindowFreezingScreenIfNeededLocked, true);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700406 }
407
408 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setVisibility: " + this
409 + ": hidden=" + hidden + " hiddenRequested=" + hiddenRequested);
410
411 if (changed) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700412 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700413 if (performLayout) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700414 mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700415 false /*updateInputWindows*/);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700416 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700417 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700418 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700419 }
420 }
421
422 if (mAppAnimator.animation != null) {
423 delayed = true;
424 }
425
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700426 for (int i = mChildren.size() - 1; i >= 0 && !delayed; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700427 if ((mChildren.get(i)).isWindowAnimationSet()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700428 delayed = true;
429 }
430 }
431
432 if (visibilityChanged) {
433 if (visible && !delayed) {
434 // The token was made immediately visible, there will be no entrance animation.
435 // We need to inform the client the enter animation was finished.
436 mEnteringAnimation = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700437 mService.mActivityManagerAppTransitionNotifier.onAppTransitionFinishedLocked(token);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700438 }
Robert Carr61b81112017-07-17 18:08:15 -0700439
Robert Carre7cc44d2017-03-20 19:04:30 -0700440 // If we are hidden but there is no delay needed we immediately
441 // apply the Surface transaction so that the ActivityManager
Robert Carr61b81112017-07-17 18:08:15 -0700442 // can have some guarantee on the Surface state following
443 // setting the visibility. This captures cases like dismissing
444 // the docked or pinned stack where there is no app transition.
445 //
446 // In the case of a "Null" animation, there will be
447 // no animation but there will still be a transition set.
448 // We still need to delay hiding the surface such that it
449 // can be synchronized with showing the next surface in the transition.
450 if (hidden && !delayed && !mService.mAppTransition.isTransitionSet()) {
Robert Carr6914f082017-03-20 19:04:30 -0700451 SurfaceControl.openTransaction();
452 for (int i = mChildren.size() - 1; i >= 0; i--) {
453 mChildren.get(i).mWinAnimator.hide("immediately hidden");
454 }
455 SurfaceControl.closeTransaction();
456 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700457
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700458 if (!mService.mClosingApps.contains(this) && !mService.mOpeningApps.contains(this)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700459 // The token is not closing nor opening, so even if there is an animation set, that
460 // doesn't mean that it goes through the normal app transition cycle so we have
461 // to inform the docked controller about visibility change.
Andrii Kulian1e32e022016-09-16 15:29:34 -0700462 // TODO(multi-display): notify docked divider on all displays where visibility was
463 // affected.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700464 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700465 .notifyAppVisibilityChanged();
Jorim Jaggi8b702ed2017-01-20 16:59:03 +0100466 mService.mTaskSnapshotController.notifyAppVisibilityChanged(this, visible);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700467 }
468 }
469
470 return delayed;
471 }
472
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800473 WindowState findMainWindow() {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700474 WindowState candidate = null;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700475 int j = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800476 while (j > 0) {
477 j--;
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700478 final WindowState win = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700479 final int type = win.mAttrs.type;
480 // No need to loop through child window as base application and starting types can't be
481 // child windows.
482 if (type == TYPE_BASE_APPLICATION || type == TYPE_APPLICATION_STARTING) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700483 // In cases where there are multiple windows, we prefer the non-exiting window. This
Sungsoo Lim0d3d1f82015-12-02 14:47:59 +0900484 // happens for example when replacing windows during an activity relaunch. When
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700485 // constructing the animation, we want the new window, not the exiting one.
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800486 if (win.mAnimatingExit) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700487 candidate = win;
488 } else {
489 return win;
490 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800491 }
492 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700493 return candidate;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800494 }
495
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800496 boolean windowsAreFocusable() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800497 return StackId.canReceiveKeys(getTask().mStack.mStackId) || mAlwaysFocusable;
Wale Ogunwaled045c822015-12-02 09:14:28 -0800498 }
499
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800500 AppWindowContainerController getController() {
501 final WindowContainerController controller = super.getController();
502 return controller != null ? (AppWindowContainerController) controller : null;
503 }
504
Wale Ogunwale571771c2016-08-26 13:18:50 -0700505 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -0700506 boolean isVisible() {
Wale Ogunwalee471be62016-10-03 07:53:55 -0700507 // If the app token isn't hidden then it is considered visible and there is no need to check
508 // its children windows to see if they are visible.
509 return !hidden;
Wale Ogunwale44f21802016-09-02 12:49:48 -0700510 }
511
512 @Override
Wale Ogunwalee287e192017-04-21 09:30:12 -0700513 void removeImmediately() {
514 onRemovedFromDisplay();
515 super.removeImmediately();
516 }
517
518 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -0700519 void removeIfPossible() {
Craig Mautnere3119b72015-01-20 15:02:36 -0800520 mIsExiting = false;
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800521 removeAllWindowsIfPossible();
Bryce Lee6d410262017-02-28 15:30:17 -0800522 removeImmediately();
Craig Mautnere3119b72015-01-20 15:02:36 -0800523 }
524
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700525 @Override
526 boolean checkCompleteDeferredRemoval() {
527 if (mIsExiting) {
528 removeIfPossible();
529 }
530 return super.checkCompleteDeferredRemoval();
531 }
532
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700533 void onRemovedFromDisplay() {
Wale Ogunwalee287e192017-04-21 09:30:12 -0700534 if (mRemovingFromDisplay) {
535 return;
536 }
537 mRemovingFromDisplay = true;
538
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700539 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app token: " + this);
540
Wale Ogunwale72919d22016-12-08 18:58:50 -0800541 boolean delayed = setVisibility(null, false, TRANSIT_UNSET, true, mVoiceInteraction);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700542
543 mService.mOpeningApps.remove(this);
Jorim Jaggi45ca0542017-05-30 16:16:01 -0700544 mService.mUnknownAppVisibilityController.appRemovedOrHidden(this);
Jorim Jaggi10abe2f2017-01-03 16:44:46 +0100545 mService.mTaskSnapshotController.onAppRemoved(this);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700546 waitingToShow = false;
547 if (mService.mClosingApps.contains(this)) {
548 delayed = true;
549 } else if (mService.mAppTransition.isTransitionSet()) {
550 mService.mClosingApps.add(this);
551 delayed = true;
552 }
553
554 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app " + this + " delayed=" + delayed
555 + " animation=" + mAppAnimator.animation + " animating=" + mAppAnimator.animating);
556
557 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM, "removeAppToken: "
558 + this + " delayed=" + delayed + " Callers=" + Debug.getCallers(4));
559
Jorim Jaggi19be6052017-08-03 18:33:43 +0200560 if (startingData != null && getController() != null) {
561 getController().removeStartingWindow();
562 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800563
Winson Chung87e5d552017-04-05 11:49:38 -0700564 // If this window was animating, then we need to ensure that the app transition notifies
565 // that animations have completed in WMS.handleAnimatingStoppedAndTransitionLocked(), so
566 // add to that list now
567 if (mAppAnimator.animating) {
568 mService.mNoAnimationNotifyOnTransitionFinished.add(token);
569 }
570
Wale Ogunwalee287e192017-04-21 09:30:12 -0700571 final TaskStack stack = getStack();
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700572 if (delayed && !isEmpty()) {
573 // set the token aside because it has an active animation to be finished
574 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM,
575 "removeAppToken make exiting: " + this);
Wale Ogunwalee287e192017-04-21 09:30:12 -0700576 if (stack != null) {
577 stack.mExitingAppTokens.add(this);
578 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700579 mIsExiting = true;
580 } else {
581 // Make sure there is no animation running on this token, so any windows associated
582 // with it will be removed as soon as their animations are complete
583 mAppAnimator.clearAnimation();
584 mAppAnimator.animating = false;
Wale Ogunwale3106ae012017-05-16 08:56:37 -0700585 if (stack != null) {
586 stack.mExitingAppTokens.remove(this);
587 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700588 removeIfPossible();
589 }
590
591 removed = true;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700592 stopFreezingScreen(true, true);
Bryce Lee6d410262017-02-28 15:30:17 -0800593
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700594 if (mService.mFocusedApp == this) {
595 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "Removing focused app token:" + this);
596 mService.mFocusedApp = null;
597 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
598 mService.mInputMonitor.setFocusedAppLw(null);
599 }
600
601 if (!delayed) {
602 updateReportedVisibilityLocked();
603 }
Wale Ogunwalee287e192017-04-21 09:30:12 -0700604
605 mRemovingFromDisplay = false;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700606 }
607
Chong Zhange05bcb12016-07-26 17:47:29 -0700608 void clearAnimatingFlags() {
Chong Zhangb0d26702016-08-12 16:03:29 -0700609 boolean wallpaperMightChange = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700610 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700611 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700612 wallpaperMightChange |= win.clearAnimatingFlags();
Chong Zhange05bcb12016-07-26 17:47:29 -0700613 }
Chong Zhangb0d26702016-08-12 16:03:29 -0700614 if (wallpaperMightChange) {
615 requestUpdateWallpaperIfNeeded();
616 }
Chong Zhange05bcb12016-07-26 17:47:29 -0700617 }
618
Robert Carre12aece2016-02-02 22:43:27 -0800619 void destroySurfaces() {
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700620 destroySurfaces(false /*cleanupOnResume*/);
621 }
622
623 /**
624 * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure
625 * the client has finished with them.
626 *
627 * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If
628 * set to true, destroy only surfaces of removed windows, and clear relevant flags of the
629 * others so that they are ready to be reused. If set to false (common case), destroy all
630 * surfaces that's eligible, if the app is already stopped.
631 */
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700632 private void destroySurfaces(boolean cleanupOnResume) {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700633 boolean destroyedSomething = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700634 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700635 final WindowState win = mChildren.get(i);
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700636 destroyedSomething |= win.destroySurface(cleanupOnResume, mAppStopped);
Robert Carre12aece2016-02-02 22:43:27 -0800637 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700638 if (destroyedSomething) {
639 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700640 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Robert Carre12aece2016-02-02 22:43:27 -0800641 }
642 }
643
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800644 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700645 * Notify that the app is now resumed, and it was not stopped before, perform a clean
646 * up of the surfaces
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800647 */
Jorim Jaggibae01b12017-04-11 16:29:10 -0700648 void notifyAppResumed(boolean wasStopped) {
Chong Zhangad24f962016-08-25 12:12:33 -0700649 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped
Jorim Jaggibae01b12017-04-11 16:29:10 -0700650 + " " + this);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700651 mAppStopped = false;
chaviwd3bf08d2017-08-01 17:24:59 -0700652 // Allow the window to turn the screen on once the app is resumed again.
653 setCanTurnScreenOn(true);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700654 if (!wasStopped) {
655 destroySurfaces(true /*cleanupOnResume*/);
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800656 }
Robert Carre12aece2016-02-02 22:43:27 -0800657 }
658
Chong Zhangbef461f2015-10-27 11:38:24 -0700659 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700660 * Notify that the app has stopped, and it is okay to destroy any surfaces which were
661 * keeping alive in case they were still being used.
662 */
663 void notifyAppStopped() {
664 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this);
665 mAppStopped = true;
666 destroySurfaces();
667 // Remove any starting window that was added for this app if they are still around.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800668 if (getController() != null) {
669 getController().removeStartingWindow();
670 }
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700671 }
672
673 /**
Chong Zhangbef461f2015-10-27 11:38:24 -0700674 * Checks whether we should save surfaces for this app.
675 *
676 * @return true if the surfaces should be saved, false otherwise.
677 */
678 boolean shouldSaveSurface() {
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800679 // We want to save surface if the app's windows are "allDrawn".
680 // (If we started entering animation early with saved surfaces, allDrawn
681 // should have been restored to true. So we'll save again in that case
682 // even if app didn't actually finish drawing.)
683 return allDrawn;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800684 }
685
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700686 private boolean canRestoreSurfaces() {
687 for (int i = mChildren.size() -1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700688 final WindowState w = mChildren.get(i);
Chong Zhang92147042016-05-09 12:47:11 -0700689 if (w.canRestoreSurface()) {
Robert Carr13f7be9e2015-12-02 18:39:45 -0800690 return true;
691 }
Chong Zhangbef461f2015-10-27 11:38:24 -0700692 }
693 return false;
694 }
695
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700696 private void clearWasVisibleBeforeClientHidden() {
697 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700698 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700699 w.clearWasVisibleBeforeClientHidden();
Chong Zhang92147042016-05-09 12:47:11 -0700700 }
701 }
702
Chong Zhang8e4bda92016-05-04 15:08:18 -0700703 /**
704 * Whether the app has some window that is invisible in layout, but
705 * animating with saved surface.
706 */
707 boolean isAnimatingInvisibleWithSavedSurface() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700708 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700709 final WindowState w = mChildren.get(i);
Chong Zhang8e4bda92016-05-04 15:08:18 -0700710 if (w.isAnimatingInvisibleWithSavedSurface()) {
711 return true;
712 }
713 }
714 return false;
715 }
716
717 /**
718 * Hide all window surfaces that's still invisible in layout but animating
719 * with a saved surface, and mark them destroying.
720 */
721 void stopUsingSavedSurfaceLocked() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700722 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700723 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700724 w.stopUsingSavedSurface();
Chong Zhang8e4bda92016-05-04 15:08:18 -0700725 }
726 destroySurfaces();
727 }
728
Chong Zhangf58631a2016-05-24 16:02:10 -0700729 void markSavedSurfaceExiting() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700730 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700731 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700732 w.markSavedSurfaceExiting();
Chong Zhangf58631a2016-05-24 16:02:10 -0700733 }
734 }
735
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700736 void restoreSavedSurfaceForInterestingWindows() {
Chong Zhang92147042016-05-09 12:47:11 -0700737 if (!canRestoreSurfaces()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700738 clearWasVisibleBeforeClientHidden();
Chong Zhangbef461f2015-10-27 11:38:24 -0700739 return;
740 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700741
742 // Check if all interesting windows are drawn and we can mark allDrawn=true.
743 int interestingNotDrawn = -1;
744
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700745 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700746 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700747 interestingNotDrawn = w.restoreSavedSurfaceForInterestingWindow();
Chong Zhangbef461f2015-10-27 11:38:24 -0700748 }
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800749
Chong Zhang92147042016-05-09 12:47:11 -0700750 if (!allDrawn) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700751 allDrawn = (interestingNotDrawn == 0);
Chong Zhang92147042016-05-09 12:47:11 -0700752 if (allDrawn) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700753 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Chong Zhang92147042016-05-09 12:47:11 -0700754 }
755 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700756 clearWasVisibleBeforeClientHidden();
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800757
758 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700759 "restoreSavedSurfaceForInterestingWindows: " + this + " allDrawn=" + allDrawn
760 + " interestingNotDrawn=" + interestingNotDrawn);
Chong Zhangbef461f2015-10-27 11:38:24 -0700761 }
762
763 void destroySavedSurfaces() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700764 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700765 final WindowState win = mChildren.get(i);
Robert Carr13f7be9e2015-12-02 18:39:45 -0800766 win.destroySavedSurface();
Chong Zhangbef461f2015-10-27 11:38:24 -0700767 }
Chong Zhang92147042016-05-09 12:47:11 -0700768 }
769
770 void clearAllDrawn() {
771 allDrawn = false;
772 deferClearAllDrawn = false;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700773 allDrawnExcludingSaved = false;
Chong Zhangbef461f2015-10-27 11:38:24 -0700774 }
775
Bryce Lee6d410262017-02-28 15:30:17 -0800776 Task getTask() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800777 return (Task) getParent();
Bryce Lee6d410262017-02-28 15:30:17 -0800778 }
779
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800780 TaskStack getStack() {
781 final Task task = getTask();
782 if (task != null) {
783 return task.mStack;
784 } else {
785 return null;
786 }
787 }
788
Bryce Lee6d410262017-02-28 15:30:17 -0800789 @Override
790 void onParentSet() {
791 super.onParentSet();
792
Robert Carred3e83b2017-04-21 13:26:55 -0700793 final Task task = getTask();
794
Bryce Lee6d410262017-02-28 15:30:17 -0800795 // When the associated task is {@code null}, the {@link AppWindowToken} can no longer
796 // access visual elements like the {@link DisplayContent}. We must remove any associations
797 // such as animations.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800798 if (!mReparenting) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800799 if (task == null) {
800 // It is possible we have been marked as a closing app earlier. We must remove ourselves
801 // from this list so we do not participate in any future animations.
802 mService.mClosingApps.remove(this);
Robert Carred3e83b2017-04-21 13:26:55 -0700803 } else if (mLastParent != null && mLastParent.mStack != null) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800804 task.mStack.mExitingAppTokens.remove(this);
805 }
Bryce Lee6d410262017-02-28 15:30:17 -0800806 }
Robert Carred3e83b2017-04-21 13:26:55 -0700807 mLastParent = task;
Bryce Lee6d410262017-02-28 15:30:17 -0800808 }
809
Wale Ogunwalefa854eb2016-09-20 13:43:52 -0700810 void postWindowRemoveStartingWindowCleanup(WindowState win) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700811 // TODO: Something smells about the code below...Is there a better way?
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700812 if (startingWindow == win) {
813 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800814 if (getController() != null) {
815 getController().removeStartingWindow();
816 }
Wale Ogunwale6c459212017-05-17 08:56:03 -0700817 } else if (mChildren.size() == 0) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700818 // If this is the last window and we had requested a starting transition window,
819 // well there is no point now.
Jorim Jaggi02886a82016-12-06 09:10:06 -0800820 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingData");
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700821 startingData = null;
Wale Ogunwale6c459212017-05-17 08:56:03 -0700822 if (mHiddenSetFromTransferredStartingWindow) {
823 // We set the hidden state to false for the token from a transferred starting window.
824 // We now reset it back to true since the starting window was the last window in the
825 // token.
826 hidden = true;
827 }
Jorim Jaggi829b9cd2017-01-23 16:20:53 +0100828 } else if (mChildren.size() == 1 && startingSurface != null && !isRelaunching()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700829 // If this is the last window except for a starting transition window,
830 // we need to get rid of the starting transition.
Jorim Jaggie4b0f282017-05-17 15:10:29 +0200831 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Last window, removing starting window "
832 + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800833 if (getController() != null) {
834 getController().removeStartingWindow();
835 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700836 }
837 }
838
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700839 void removeDeadWindows() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700840 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700841 WindowState win = mChildren.get(winNdx);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800842 if (win.mAppDied) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700843 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700844 "removeDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800845 // Set mDestroying, we don't want any animation or delayed removal here.
846 win.mDestroying = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700847 // Also removes child windows.
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700848 win.removeIfPossible();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800849 }
850 }
851 }
852
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700853 boolean hasWindowsAlive() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700854 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700855 // No need to loop through child windows as the answer should be the same as that of the
856 // parent window.
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700857 if (!(mChildren.get(i)).mAppDied) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700858 return true;
859 }
860 }
861 return false;
862 }
863
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700864 void setWillReplaceWindows(boolean animate) {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700865 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
866 "Marking app token " + this + " with replacing windows.");
Robert Carra1eb4392015-12-10 12:43:51 -0800867
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700868 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700869 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700870 w.setWillReplaceWindow(animate);
Robert Carra1eb4392015-12-10 12:43:51 -0800871 }
872 if (animate) {
873 // Set-up dummy animation so we can start treating windows associated with this
874 // token like they are in transition before the new app window is ready for us to
875 // run the real transition animation.
876 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700877 "setWillReplaceWindow() Setting dummy animation on: " + this);
Robert Carra1eb4392015-12-10 12:43:51 -0800878 mAppAnimator.setDummyAnimation();
879 }
880 }
881
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700882 void setWillReplaceChildWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700883 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this
Robert Carr23fa16b2016-01-13 13:19:58 -0800884 + " with replacing child windows.");
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700885 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700886 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700887 w.setWillReplaceChildWindows();
Robert Carr23fa16b2016-01-13 13:19:58 -0800888 }
889 }
890
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700891 void clearWillReplaceWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700892 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
893 "Resetting app token " + this + " of replacing window marks.");
Chong Zhangf596cd52016-01-05 13:42:44 -0800894
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700895 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700896 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700897 w.clearWillReplaceWindow();
Chong Zhangf596cd52016-01-05 13:42:44 -0800898 }
899 }
900
Chong Zhang4d7369a2016-04-25 16:09:14 -0700901 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700902 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700903 final WindowState w = mChildren.get(i);
Chong Zhang4d7369a2016-04-25 16:09:14 -0700904 w.requestUpdateWallpaperIfNeeded();
905 }
906 }
907
Chong Zhangd78ddb42016-03-02 17:01:14 -0800908 boolean isRelaunching() {
909 return mPendingRelaunchCount > 0;
910 }
911
Robert Carr68375192017-06-13 12:41:53 -0700912 boolean shouldFreezeBounds() {
913 final Task task = getTask();
914
915 // For freeform windows, we can't freeze the bounds at the moment because this would make
916 // the resizing unresponsive.
917 if (task == null || task.inFreeformWorkspace()) {
918 return false;
919 }
920
921 // We freeze the bounds while drag resizing to deal with the time between
922 // the divider/drag handle being released, and the handling it's new
923 // configuration. If we are relaunched outside of the drag resizing state,
924 // we need to be careful not to do this.
925 return getTask().isDragResizing();
926 }
927
Chong Zhangd78ddb42016-03-02 17:01:14 -0800928 void startRelaunching() {
Robert Carr68375192017-06-13 12:41:53 -0700929 if (shouldFreezeBounds()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -0800930 freezeBounds();
931 }
Robert Carrd5c7dd62017-03-08 10:39:30 -0800932
933 // In the process of tearing down before relaunching, the app will
934 // try and clean up it's child surfaces. We need to prevent this from
935 // happening, so we sever the children, transfering their ownership
936 // from the client it-self to the parent surface (owned by us).
937 for (int i = mChildren.size() - 1; i >= 0; i--) {
938 final WindowState w = mChildren.get(i);
939 w.mWinAnimator.detachChildren();
940 }
941
Chong Zhangd78ddb42016-03-02 17:01:14 -0800942 mPendingRelaunchCount++;
943 }
944
945 void finishRelaunching() {
Robert Carr68375192017-06-13 12:41:53 -0700946 unfreezeBounds();
947
Chong Zhangd78ddb42016-03-02 17:01:14 -0800948 if (mPendingRelaunchCount > 0) {
949 mPendingRelaunchCount--;
Bryce Lee081554b2017-05-25 07:52:12 -0700950 } else {
951 // Update keyguard flags upon finishing relaunch.
952 checkKeyguardFlagsChanged();
Chong Zhangd78ddb42016-03-02 17:01:14 -0800953 }
954 }
955
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700956 void clearRelaunching() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700957 if (mPendingRelaunchCount == 0) {
958 return;
959 }
Robert Carr68375192017-06-13 12:41:53 -0700960 unfreezeBounds();
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700961 mPendingRelaunchCount = 0;
962 }
963
Wale Ogunwale07bcab72016-10-14 15:30:09 -0700964 /**
965 * Returns true if the new child window we are adding to this token is considered greater than
966 * the existing child window in this token in terms of z-order.
967 */
968 @Override
969 protected boolean isFirstChildWindowGreaterThanSecond(WindowState newWindow,
970 WindowState existingWindow) {
971 final int type1 = newWindow.mAttrs.type;
972 final int type2 = existingWindow.mAttrs.type;
973
974 // Base application windows should be z-ordered BELOW all other windows in the app token.
975 if (type1 == TYPE_BASE_APPLICATION && type2 != TYPE_BASE_APPLICATION) {
976 return false;
977 } else if (type1 != TYPE_BASE_APPLICATION && type2 == TYPE_BASE_APPLICATION) {
978 return true;
979 }
980
981 // Starting windows should be z-ordered ABOVE all other windows in the app token.
982 if (type1 == TYPE_APPLICATION_STARTING && type2 != TYPE_APPLICATION_STARTING) {
983 return true;
984 } else if (type1 != TYPE_APPLICATION_STARTING && type2 == TYPE_APPLICATION_STARTING) {
985 return false;
986 }
987
988 // Otherwise the new window is greater than the existing window.
989 return true;
990 }
991
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700992 @Override
Robert Carra1eb4392015-12-10 12:43:51 -0800993 void addWindow(WindowState w) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700994 super.addWindow(w);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700995
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700996 boolean gotReplacementWindow = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700997 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700998 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700999 gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w);
1000 }
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001001
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001002 // if we got a replacement window, reset the timeout to give drawing more time
1003 if (gotReplacementWindow) {
1004 mService.scheduleWindowReplacementTimeouts(this);
Robert Carra1eb4392015-12-10 12:43:51 -08001005 }
Jorim Jaggife762342016-10-13 14:33:27 +02001006 checkKeyguardFlagsChanged();
1007 }
1008
1009 @Override
1010 void removeChild(WindowState child) {
1011 super.removeChild(child);
1012 checkKeyguardFlagsChanged();
Robert Carra1eb4392015-12-10 12:43:51 -08001013 }
1014
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001015 private boolean waitingForReplacement() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001016 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001017 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001018 if (candidate.waitingForReplacement()) {
Robert Carra1eb4392015-12-10 12:43:51 -08001019 return true;
1020 }
1021 }
1022 return false;
1023 }
1024
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001025 void onWindowReplacementTimeout() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001026 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001027 (mChildren.get(i)).onWindowReplacementTimeout();
Robert Carra1eb4392015-12-10 12:43:51 -08001028 }
1029 }
1030
Winson Chung30480042017-01-26 10:55:34 -08001031 void reparent(Task task, int position) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001032 final Task currentTask = getTask();
1033 if (task == currentTask) {
Winson Chung30480042017-01-26 10:55:34 -08001034 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001035 "window token=" + this + " already child of task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -08001036 }
Bryce Lee6d410262017-02-28 15:30:17 -08001037
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001038 if (currentTask.mStack != task.mStack) {
Bryce Lee6d410262017-02-28 15:30:17 -08001039 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001040 "window token=" + this + " current task=" + currentTask
Bryce Lee6d410262017-02-28 15:30:17 -08001041 + " belongs to a different stack than " + task);
1042 }
1043
Winson Chung30480042017-01-26 10:55:34 -08001044 if (DEBUG_ADD_REMOVE) Slog.i(TAG, "reParentWindowToken: removing window token=" + this
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001045 + " from task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -08001046 final DisplayContent prevDisplayContent = getDisplayContent();
1047
Bryce Lee6d410262017-02-28 15:30:17 -08001048 mReparenting = true;
1049
Winson Chung30480042017-01-26 10:55:34 -08001050 getParent().removeChild(this);
1051 task.addChild(this, position);
1052
Bryce Lee6d410262017-02-28 15:30:17 -08001053 mReparenting = false;
1054
Winson Chung30480042017-01-26 10:55:34 -08001055 // Relayout display(s).
1056 final DisplayContent displayContent = task.getDisplayContent();
1057 displayContent.setLayoutNeeded();
1058 if (prevDisplayContent != displayContent) {
1059 onDisplayChanged(displayContent);
1060 prevDisplayContent.setLayoutNeeded();
1061 }
1062 }
1063
Jorim Jaggi0429f352015-12-22 16:29:16 +01001064 /**
1065 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
1066 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
1067 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
1068 * with a queue.
1069 */
Chong Zhangd78ddb42016-03-02 17:01:14 -08001070 private void freezeBounds() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001071 final Task task = getTask();
1072 mFrozenBounds.offer(new Rect(task.mPreparedFrozenBounds));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001073
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001074 if (task.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) {
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001075 // We didn't call prepareFreezingBounds on the task, so use the current value.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001076 mFrozenMergedConfig.offer(new Configuration(task.getConfiguration()));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001077 } else {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001078 mFrozenMergedConfig.offer(new Configuration(task.mPreparedFrozenMergedConfig));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001079 }
Andrii Kulianb10330d2016-09-16 13:51:46 -07001080 // Calling unset() to make it equal to Configuration.EMPTY.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001081 task.mPreparedFrozenMergedConfig.unset();
Jorim Jaggi0429f352015-12-22 16:29:16 +01001082 }
1083
1084 /**
1085 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
1086 */
Chong Zhangd78ddb42016-03-02 17:01:14 -08001087 private void unfreezeBounds() {
Robert Carr68375192017-06-13 12:41:53 -07001088 if (mFrozenBounds.isEmpty()) {
1089 return;
Wale Ogunwale37dbafc2016-06-27 10:15:20 -07001090 }
Robert Carr68375192017-06-13 12:41:53 -07001091 mFrozenBounds.remove();
Wale Ogunwale37dbafc2016-06-27 10:15:20 -07001092 if (!mFrozenMergedConfig.isEmpty()) {
1093 mFrozenMergedConfig.remove();
1094 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001095 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001096 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001097 win.onUnfreezeBounds();
Jorim Jaggi4846ee32016-01-07 17:39:12 +01001098 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001099 mService.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +01001100 }
1101
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001102 void setAppLayoutChanges(int changes, String reason) {
1103 if (!mChildren.isEmpty()) {
1104 final DisplayContent dc = getDisplayContent();
1105 dc.pendingLayoutChanges |= changes;
1106 if (DEBUG_LAYOUT_REPEATS) {
1107 mService.mWindowPlacerLocked.debugLayoutRepeats(reason, dc.pendingLayoutChanges);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001108 }
1109 }
1110 }
1111
1112 void removeReplacedWindowIfNeeded(WindowState replacement) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001113 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001114 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001115 if (win.removeReplacedWindowIfNeeded(replacement)) {
1116 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001117 }
1118 }
1119 }
1120
1121 void startFreezingScreen() {
1122 if (DEBUG_ORIENTATION) logWithStack(TAG, "Set freezing of " + appToken + ": hidden="
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001123 + hidden + " freezing=" + mAppAnimator.freezingScreen + " hiddenRequested="
1124 + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001125 if (!hiddenRequested) {
1126 if (!mAppAnimator.freezingScreen) {
1127 mAppAnimator.freezingScreen = true;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001128 mService.registerAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001129 mAppAnimator.lastFreezeDuration = 0;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001130 mService.mAppsFreezingScreen++;
1131 if (mService.mAppsFreezingScreen == 1) {
Bryce Lee8f853582017-06-05 17:25:59 -07001132 mService.startFreezingDisplayLocked(false, 0, 0, getDisplayContent());
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001133 mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT);
1134 mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001135 }
1136 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001137 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001138 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001139 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001140 w.onStartFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001141 }
1142 }
1143 }
1144
1145 void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) {
1146 if (!mAppAnimator.freezingScreen) {
1147 return;
1148 }
1149 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + this + " force=" + force);
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001150 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001151 boolean unfrozeWindows = false;
1152 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001153 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001154 unfrozeWindows |= w.onStopFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001155 }
1156 if (force || unfrozeWindows) {
1157 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this);
1158 mAppAnimator.freezingScreen = false;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001159 mService.unregisterAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001160 mAppAnimator.lastFreezeDuration =
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001161 (int)(SystemClock.elapsedRealtime() - mService.mDisplayFreezeTime);
1162 mService.mAppsFreezingScreen--;
1163 mService.mLastFinishedFreezeSource = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001164 }
1165 if (unfreezeSurfaceNow) {
1166 if (unfrozeWindows) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001167 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001168 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001169 mService.stopFreezingDisplayLocked();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001170 }
1171 }
1172
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001173 @Override
1174 public void onAppFreezeTimeout() {
1175 Slog.w(TAG_WM, "Force clearing freeze: " + this);
1176 stopFreezingScreen(true, true);
1177 }
1178
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001179 boolean transferStartingWindow(IBinder transferFrom) {
Wale Ogunwale02319a62016-09-26 15:21:22 -07001180 final AppWindowToken fromToken = getDisplayContent().getAppWindowToken(transferFrom);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001181 if (fromToken == null) {
1182 return false;
1183 }
1184
1185 final WindowState tStartingWindow = fromToken.startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001186 if (tStartingWindow != null && fromToken.startingSurface != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001187 // In this case, the starting icon has already been displayed, so start
1188 // letting windows get shown immediately without any more transitions.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001189 mService.mSkipAppTransitionAnimation = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001190
1191 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow
1192 + " from " + fromToken + " to " + this);
1193
1194 final long origId = Binder.clearCallingIdentity();
1195
1196 // Transfer the starting window over to the new token.
1197 startingData = fromToken.startingData;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001198 startingSurface = fromToken.startingSurface;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001199 startingDisplayed = fromToken.startingDisplayed;
1200 fromToken.startingDisplayed = false;
1201 startingWindow = tStartingWindow;
1202 reportedVisible = fromToken.reportedVisible;
1203 fromToken.startingData = null;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001204 fromToken.startingSurface = null;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001205 fromToken.startingWindow = null;
1206 fromToken.startingMoved = true;
1207 tStartingWindow.mToken = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001208 tStartingWindow.mAppToken = this;
1209
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001210 if (DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001211 "Removing starting " + tStartingWindow + " from " + fromToken);
Wale Ogunwalefa854eb2016-09-20 13:43:52 -07001212 fromToken.removeChild(tStartingWindow);
1213 fromToken.postWindowRemoveStartingWindowCleanup(tStartingWindow);
Wale Ogunwale6c459212017-05-17 08:56:03 -07001214 fromToken.mHiddenSetFromTransferredStartingWindow = false;
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001215 addWindow(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001216
1217 // Propagate other interesting state between the tokens. If the old token is displayed,
1218 // we should immediately force the new one to be displayed. If it is animating, we need
1219 // to move that animation to the new one.
1220 if (fromToken.allDrawn) {
1221 allDrawn = true;
1222 deferClearAllDrawn = fromToken.deferClearAllDrawn;
1223 }
1224 if (fromToken.firstWindowDrawn) {
1225 firstWindowDrawn = true;
1226 }
1227 if (!fromToken.hidden) {
1228 hidden = false;
1229 hiddenRequested = false;
Wale Ogunwale6c459212017-05-17 08:56:03 -07001230 mHiddenSetFromTransferredStartingWindow = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001231 }
Wale Ogunwale89973222017-04-23 18:39:45 -07001232 setClientHidden(fromToken.mClientHidden);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001233 fromToken.mAppAnimator.transferCurrentAnimation(
1234 mAppAnimator, tStartingWindow.mWinAnimator);
1235
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001236 mService.updateFocusedWindowLocked(
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001237 UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/);
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001238 getDisplayContent().setLayoutNeeded();
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001239 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001240 Binder.restoreCallingIdentity(origId);
1241 return true;
1242 } else if (fromToken.startingData != null) {
1243 // The previous app was getting ready to show a
1244 // starting window, but hasn't yet done so. Steal it!
1245 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1246 "Moving pending starting from " + fromToken + " to " + this);
1247 startingData = fromToken.startingData;
1248 fromToken.startingData = null;
1249 fromToken.startingMoved = true;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001250 if (getController() != null) {
1251 getController().scheduleAddStartingWindow();
1252 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001253 return true;
1254 }
1255
1256 final AppWindowAnimator tAppAnimator = fromToken.mAppAnimator;
1257 final AppWindowAnimator wAppAnimator = mAppAnimator;
1258 if (tAppAnimator.thumbnail != null) {
1259 // The old token is animating with a thumbnail, transfer that to the new token.
1260 if (wAppAnimator.thumbnail != null) {
1261 wAppAnimator.thumbnail.destroy();
1262 }
1263 wAppAnimator.thumbnail = tAppAnimator.thumbnail;
1264 wAppAnimator.thumbnailLayer = tAppAnimator.thumbnailLayer;
1265 wAppAnimator.thumbnailAnimation = tAppAnimator.thumbnailAnimation;
1266 tAppAnimator.thumbnail = null;
1267 }
1268 return false;
1269 }
1270
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001271 boolean isLastWindow(WindowState win) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001272 return mChildren.size() == 1 && mChildren.get(0) == win;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001273 }
1274
1275 void setAllAppWinAnimators() {
1276 final ArrayList<WindowStateAnimator> allAppWinAnimators = mAppAnimator.mAllAppWinAnimators;
1277 allAppWinAnimators.clear();
1278
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001279 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001280 for (int j = 0; j < windowsCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001281 (mChildren.get(j)).addWinAnimatorToList(allAppWinAnimators);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001282 }
1283 }
1284
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001285 @Override
1286 void onAppTransitionDone() {
1287 sendingToBottom = false;
1288 }
1289
Wale Ogunwale51362492016-09-08 17:49:17 -07001290 /**
1291 * We override because this class doesn't want its children affecting its reported orientation
1292 * in anyway.
1293 */
1294 @Override
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001295 int getOrientation(int candidate) {
Bryce Leed1ac18c2017-05-11 07:59:41 -07001296 // We do not allow non-fullscreen apps to influence orientation beyond O. While we do
Bryce Lee39791592017-04-26 09:29:12 -07001297 // throw an exception in {@link Activity#onCreate} and
1298 // {@link Activity#setRequestedOrientation}, we also ignore the orientation here so that
1299 // other calculations aren't affected.
Bryce Leed1ac18c2017-05-11 07:59:41 -07001300 if (!fillsParent() && mTargetSdk > O) {
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001301 // Can't specify orientation if app doesn't fill parent.
1302 return SCREEN_ORIENTATION_UNSET;
1303 }
1304
1305 if (candidate == SCREEN_ORIENTATION_BEHIND) {
1306 // Allow app to specify orientation regardless of its visibility state if the current
1307 // candidate want us to use orientation behind. I.e. the visible app on-top of this one
1308 // wants us to use the orientation of the app behind it.
1309 return mOrientation;
1310 }
1311
Bryce Lee61fbcbc2017-03-10 14:14:03 -08001312 // The {@link AppWindowToken} should only specify an orientation when it is not closing or
1313 // going to the bottom. Allowing closing {@link AppWindowToken} to participate can lead to
1314 // an Activity in another task being started in the wrong orientation during the transition.
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001315 if (!(sendingToBottom || mService.mClosingApps.contains(this))
Bryce Lee00d586d2017-07-28 20:48:43 -07001316 && (isVisible() || mService.mOpeningApps.contains(this) || isOnTop())) {
Bryce Leea163b762017-01-24 11:05:01 -08001317 return mOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001318 }
Bryce Leea163b762017-01-24 11:05:01 -08001319
1320 return SCREEN_ORIENTATION_UNSET;
Wale Ogunwale51362492016-09-08 17:49:17 -07001321 }
1322
Wale Ogunwaleb198b742016-12-01 08:44:09 -08001323 /** Returns the app's preferred orientation regardless of its currently visibility state. */
1324 int getOrientationIgnoreVisibility() {
1325 return mOrientation;
1326 }
1327
Craig Mautnerdbb79912012-03-01 18:59:14 -08001328 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001329 void checkAppWindowsReadyToShow() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001330 if (allDrawn == mAppAnimator.allDrawn) {
1331 return;
1332 }
1333
1334 mAppAnimator.allDrawn = allDrawn;
1335 if (!allDrawn) {
1336 return;
1337 }
1338
1339 // The token has now changed state to having all windows shown... what to do, what to do?
1340 if (mAppAnimator.freezingScreen) {
1341 mAppAnimator.showAllWindowsLocked();
1342 stopFreezingScreen(false, true);
1343 if (DEBUG_ORIENTATION) Slog.i(TAG,
1344 "Setting mOrientationChangeComplete=true because wtoken " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001345 + " numInteresting=" + mNumInterestingWindows + " numDrawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001346 // This will set mOrientationChangeComplete and cause a pass through layout.
1347 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001348 "checkAppWindowsReadyToShow: freezingScreen");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001349 } else {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001350 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001351
1352 // We can now show all of the drawn windows!
1353 if (!mService.mOpeningApps.contains(this)) {
1354 mService.mAnimator.orAnimating(mAppAnimator.showAllWindowsLocked());
1355 }
1356 }
1357 }
1358
Matthew Ng5d23afa2017-06-21 16:16:24 -07001359 /**
Bryce Leed390deb2017-06-22 13:14:28 -07001360 * Returns whether the drawn window states of this {@link AppWindowToken} has considered every
1361 * child {@link WindowState}. A child is considered if it has been passed into
1362 * {@link #updateDrawnWindowStates(WindowState)} after being added. This is used to determine
1363 * whether states, such as {@code allDrawn}, can be set, which relies on state variables such as
1364 * {@code mNumInterestingWindows}, which depend on all {@link WindowState}s being considered.
1365 *
1366 * @return {@code true} If all children have been considered, {@code false}.
1367 */
1368 private boolean allDrawnStatesConsidered() {
Bryce Lee6311c4b2017-07-06 14:09:29 -07001369 for (int i = mChildren.size() - 1; i >= 0; --i) {
1370 final WindowState child = mChildren.get(i);
1371 if (child.mightAffectAllDrawn(false /*visibleOnly*/ )
1372 && !child.getDrawnStateEvaluated()) {
Bryce Leed390deb2017-06-22 13:14:28 -07001373 return false;
1374 }
1375 }
1376 return true;
1377 }
1378
1379 /**
Matthew Ng5d23afa2017-06-21 16:16:24 -07001380 * Determines if the token has finished drawing. This should only be called from
1381 * {@link DisplayContent#applySurfaceChangesTransaction}
1382 */
Matthew Ng498c71d2017-04-18 13:55:45 -07001383 void updateAllDrawn() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001384 if (!allDrawn) {
Matthew Ng498c71d2017-04-18 13:55:45 -07001385 // Number of drawn windows can be less when a window is being relaunched, wait for
Bryce Leed390deb2017-06-22 13:14:28 -07001386 // all windows to be launched and drawn for this token be considered all drawn.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001387 final int numInteresting = mNumInterestingWindows;
Bryce Leed390deb2017-06-22 13:14:28 -07001388
1389 // We must make sure that all present children have been considered (determined by
1390 // {@link #allDrawnStatesConsidered}) before evaluating whether everything has been
1391 // drawn.
1392 if (numInteresting > 0 && allDrawnStatesConsidered()
1393 && mNumDrawnWindows >= numInteresting && !isRelaunching()) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001394 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawn: " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001395 + " interesting=" + numInteresting + " drawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001396 allDrawn = true;
1397 // Force an additional layout pass where
1398 // WindowStateAnimator#commitFinishDrawingLocked() will call performShowLocked().
Matthew Ng498c71d2017-04-18 13:55:45 -07001399 if (mDisplayContent != null) {
1400 mDisplayContent.setLayoutNeeded();
1401 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001402 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Robert Carrecc06b32017-04-18 14:25:10 -07001403
Winson Chunge7ba6862017-05-24 12:13:33 -07001404 // Notify the pinned stack upon all windows drawn. If there was an animation in
1405 // progress then this signal will resume that animation.
1406 final TaskStack pinnedStack = mDisplayContent.getStackById(PINNED_STACK_ID);
1407 if (pinnedStack != null) {
1408 pinnedStack.onAllWindowsDrawn();
Robert Carrecc06b32017-04-18 14:25:10 -07001409 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001410 }
1411 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001412
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001413 if (!allDrawnExcludingSaved) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001414 int numInteresting = mNumInterestingWindowsExcludingSaved;
1415 if (numInteresting > 0 && mNumDrawnWindowsExcludingSaved >= numInteresting) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001416 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawnExcludingSaved: " + this
1417 + " interesting=" + numInteresting
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001418 + " drawn=" + mNumDrawnWindowsExcludingSaved);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001419 allDrawnExcludingSaved = true;
Matthew Ng498c71d2017-04-18 13:55:45 -07001420 if (mDisplayContent != null) {
1421 mDisplayContent.setLayoutNeeded();
1422 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001423 if (isAnimatingInvisibleWithSavedSurface()
1424 && !mService.mFinishedEarlyAnim.contains(this)) {
1425 mService.mFinishedEarlyAnim.add(this);
1426 }
1427 }
1428 }
1429 }
1430
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001431 /**
1432 * Updated this app token tracking states for interesting and drawn windows based on the window.
1433 *
1434 * @return Returns true if the input window is considered interesting and drawn while all the
1435 * windows in this app token where not considered drawn as of the last pass.
1436 */
1437 boolean updateDrawnWindowStates(WindowState w) {
Bryce Leed390deb2017-06-22 13:14:28 -07001438 w.setDrawnStateEvaluated(true /*evaluated*/);
1439
Jorim Jaggie4b0f282017-05-17 15:10:29 +02001440 if (DEBUG_STARTING_WINDOW_VERBOSE && w == startingWindow) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001441 Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" + w.isOnScreen()
1442 + " allDrawn=" + allDrawn + " freezingScreen=" + mAppAnimator.freezingScreen);
1443 }
1444
1445 if (allDrawn && allDrawnExcludingSaved && !mAppAnimator.freezingScreen) {
1446 return false;
1447 }
1448
1449 if (mLastTransactionSequence != mService.mTransactionSequence) {
1450 mLastTransactionSequence = mService.mTransactionSequence;
1451 mNumInterestingWindows = mNumDrawnWindows = 0;
1452 mNumInterestingWindowsExcludingSaved = 0;
1453 mNumDrawnWindowsExcludingSaved = 0;
1454 startingDisplayed = false;
1455 }
1456
1457 final WindowStateAnimator winAnimator = w.mWinAnimator;
1458
1459 boolean isInterestingAndDrawn = false;
1460
1461 if (!allDrawn && w.mightAffectAllDrawn(false /* visibleOnly */)) {
1462 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
1463 Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw()
1464 + ", isAnimationSet=" + winAnimator.isAnimationSet());
1465 if (!w.isDrawnLw()) {
1466 Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController
1467 + " pv=" + w.mPolicyVisibility
1468 + " mDrawState=" + winAnimator.drawStateToString()
1469 + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested
1470 + " a=" + winAnimator.mAnimating);
1471 }
1472 }
1473
1474 if (w != startingWindow) {
1475 if (w.isInteresting()) {
1476 mNumInterestingWindows++;
1477 if (w.isDrawnLw()) {
1478 mNumDrawnWindows++;
1479
1480 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, "tokenMayBeDrawn: "
1481 + this + " w=" + w + " numInteresting=" + mNumInterestingWindows
1482 + " freezingScreen=" + mAppAnimator.freezingScreen
1483 + " mAppFreezing=" + w.mAppFreezing);
1484
1485 isInterestingAndDrawn = true;
1486 }
1487 }
1488 } else if (w.isDrawnLw()) {
Jorim Jaggi3878ca32017-02-02 17:13:05 -08001489 if (getController() != null) {
1490 getController().reportStartingWindowDrawn();
1491 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001492 startingDisplayed = true;
1493 }
1494 }
1495
1496 if (!allDrawnExcludingSaved && w.mightAffectAllDrawn(true /* visibleOnly */)) {
1497 if (w != startingWindow && w.isInteresting()) {
1498 mNumInterestingWindowsExcludingSaved++;
1499 if (w.isDrawnLw() && !w.isAnimatingWithSavedSurface()) {
1500 mNumDrawnWindowsExcludingSaved++;
1501
1502 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
1503 "tokenMayBeDrawnExcludingSaved: " + this + " w=" + w
1504 + " numInteresting=" + mNumInterestingWindowsExcludingSaved
1505 + " freezingScreen=" + mAppAnimator.freezingScreen
1506 + " mAppFreezing=" + w.mAppFreezing);
1507
1508 isInterestingAndDrawn = true;
1509 }
1510 }
1511 }
1512
1513 return isInterestingAndDrawn;
1514 }
1515
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001516 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001517 void stepAppWindowsAnimation(long currentTime) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001518 mAppAnimator.wasAnimating = mAppAnimator.animating;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001519 if (mAppAnimator.stepAnimationLocked(currentTime)) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001520 mAppAnimator.animating = true;
1521 mService.mAnimator.setAnimating(true);
1522 mService.mAnimator.mAppWindowAnimating = true;
1523 } else if (mAppAnimator.wasAnimating) {
1524 // stopped animating, do one more pass through the layout
Wale Ogunwale1e129a42016-11-21 13:03:47 -08001525 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
1526 DEBUG_LAYOUT_REPEATS ? "appToken " + this + " done" : null);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001527 if (DEBUG_ANIM) Slog.v(TAG, "updateWindowsApps...: done animating " + this);
1528 }
1529 }
1530
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001531 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001532 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001533 // For legacy reasons we process the TaskStack.mExitingAppTokens first in DisplayContent
1534 // before the non-exiting app tokens. So, we skip the exiting app tokens here.
1535 // TODO: Investigate if we need to continue to do this or if we can just process them
1536 // in-order.
1537 if (mIsExiting && !waitingForReplacement()) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001538 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001539 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001540 return forAllWindowsUnchecked(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001541 }
1542
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001543 boolean forAllWindowsUnchecked(ToBooleanFunction<WindowState> callback,
1544 boolean traverseTopToBottom) {
1545 return super.forAllWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001546 }
1547
1548 @Override
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001549 AppWindowToken asAppWindowToken() {
1550 // I am an app window token!
1551 return this;
1552 }
1553
1554 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -07001555 boolean fillsParent() {
1556 return mFillsParent;
1557 }
1558
1559 void setFillsParent(boolean fillsParent) {
1560 mFillsParent = fillsParent;
1561 }
1562
Jorim Jaggife762342016-10-13 14:33:27 +02001563 boolean containsDismissKeyguardWindow() {
Bryce Lee081554b2017-05-25 07:52:12 -07001564 // Window state is transient during relaunch. We are not guaranteed to be frozen during the
1565 // entirety of the relaunch.
1566 if (isRelaunching()) {
1567 return mLastContainsDismissKeyguardWindow;
1568 }
1569
Jorim Jaggife762342016-10-13 14:33:27 +02001570 for (int i = mChildren.size() - 1; i >= 0; i--) {
1571 if ((mChildren.get(i).mAttrs.flags & FLAG_DISMISS_KEYGUARD) != 0) {
1572 return true;
1573 }
1574 }
1575 return false;
1576 }
1577
1578 boolean containsShowWhenLockedWindow() {
Bryce Lee081554b2017-05-25 07:52:12 -07001579 // When we are relaunching, it is possible for us to be unfrozen before our previous
1580 // windows have been added back. Using the cached value ensures that our previous
1581 // showWhenLocked preference is honored until relaunching is complete.
1582 if (isRelaunching()) {
1583 return mLastContainsShowWhenLockedWindow;
1584 }
1585
Jorim Jaggife762342016-10-13 14:33:27 +02001586 for (int i = mChildren.size() - 1; i >= 0; i--) {
1587 if ((mChildren.get(i).mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
1588 return true;
1589 }
1590 }
Bryce Lee081554b2017-05-25 07:52:12 -07001591
Jorim Jaggife762342016-10-13 14:33:27 +02001592 return false;
1593 }
1594
1595 void checkKeyguardFlagsChanged() {
1596 final boolean containsDismissKeyguard = containsDismissKeyguardWindow();
1597 final boolean containsShowWhenLocked = containsShowWhenLockedWindow();
1598 if (containsDismissKeyguard != mLastContainsDismissKeyguardWindow
1599 || containsShowWhenLocked != mLastContainsShowWhenLockedWindow) {
1600 mService.notifyKeyguardFlagsChanged(null /* callback */);
1601 }
1602 mLastContainsDismissKeyguardWindow = containsDismissKeyguard;
1603 mLastContainsShowWhenLockedWindow = containsShowWhenLocked;
1604 }
1605
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001606 WindowState getImeTargetBelowWindow(WindowState w) {
1607 final int index = mChildren.indexOf(w);
1608 if (index > 0) {
1609 final WindowState target = mChildren.get(index - 1);
1610 if (target.canBeImeTarget()) {
1611 return target;
1612 }
1613 }
1614 return null;
1615 }
1616
Winson Chungbe9be7f2017-06-28 10:55:22 -07001617 int getLowestAnimLayer() {
1618 for (int i = 0; i < mChildren.size(); i++) {
1619 final WindowState w = mChildren.get(i);
1620 if (w.mRemoved) {
1621 continue;
1622 }
1623 return w.mWinAnimator.mAnimLayer;
1624 }
1625 return Integer.MAX_VALUE;
1626 }
1627
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001628 WindowState getHighestAnimLayerWindow(WindowState currentTarget) {
1629 WindowState candidate = null;
1630 for (int i = mChildren.indexOf(currentTarget); i >= 0; i--) {
1631 final WindowState w = mChildren.get(i);
1632 if (w.mRemoved) {
1633 continue;
1634 }
1635 if (candidate == null || w.mWinAnimator.mAnimLayer >
1636 candidate.mWinAnimator.mAnimLayer) {
1637 candidate = w;
1638 }
1639 }
1640 return candidate;
1641 }
1642
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001643 /**
1644 * See {@link Activity#setDisablePreviewScreenshots}.
1645 */
1646 void setDisablePreviewScreenshots(boolean disable) {
Wale Ogunwale6c459212017-05-17 08:56:03 -07001647 mDisablePreviewScreenshots = disable;
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001648 }
1649
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001650 /**
chaviwd3bf08d2017-08-01 17:24:59 -07001651 * Sets whether the current launch can turn the screen on. See {@link #canTurnScreenOn()}
1652 */
1653 void setCanTurnScreenOn(boolean canTurnScreenOn) {
1654 mCanTurnScreenOn = canTurnScreenOn;
1655 }
1656
1657 /**
1658 * Indicates whether the current launch can turn the screen on. This is to prevent multiple
1659 * relayouts from turning the screen back on. The screen should only turn on at most
1660 * once per activity resume.
1661 *
1662 * @return true if the screen can be turned on.
1663 */
1664 boolean canTurnScreenOn() {
1665 return mCanTurnScreenOn;
1666 }
1667
1668 /**
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001669 * Retrieves whether we'd like to generate a snapshot that's based solely on the theme. This is
1670 * the case when preview screenshots are disabled {@link #setDisablePreviewScreenshots} or when
1671 * we can't take a snapshot for other reasons, for example, if we have a secure window.
1672 *
1673 * @return True if we need to generate an app theme snapshot, false if we'd like to take a real
1674 * screenshot.
1675 */
1676 boolean shouldUseAppThemeSnapshot() {
Wale Ogunwale6c459212017-05-17 08:56:03 -07001677 return mDisablePreviewScreenshots || forAllWindows(w -> (w.mAttrs.flags & FLAG_SECURE) != 0,
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001678 true /* topToBottom */);
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001679 }
1680
Wale Ogunwale51362492016-09-08 17:49:17 -07001681 @Override
Robert Carrdee1b3f2017-02-27 11:33:33 -08001682 int getAnimLayerAdjustment() {
1683 return mAppAnimator.animLayerAdjustment;
1684 }
1685
1686 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001687 void dump(PrintWriter pw, String prefix) {
1688 super.dump(pw, prefix);
1689 if (appToken != null) {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001690 pw.println(prefix + "app=true mVoiceInteraction=" + mVoiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001691 }
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001692 pw.print(prefix); pw.print("task="); pw.println(getTask());
Wale Ogunwale51362492016-09-08 17:49:17 -07001693 pw.print(prefix); pw.print(" mFillsParent="); pw.print(mFillsParent);
1694 pw.print(" mOrientation="); pw.println(mOrientation);
Wale Ogunwale89973222017-04-23 18:39:45 -07001695 pw.println(prefix + "hiddenRequested=" + hiddenRequested + " mClientHidden=" + mClientHidden
1696 + ((mDeferHidingClient) ? " mDeferHidingClient=" + mDeferHidingClient : "")
1697 + " reportedDrawn=" + reportedDrawn + " reportedVisible=" + reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -07001698 if (paused) {
1699 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001700 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001701 if (mAppStopped) {
1702 pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped);
1703 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001704 if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0
Craig Mautner6fbda632012-07-03 09:26:39 -07001705 || allDrawn || mAppAnimator.allDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001706 pw.print(prefix); pw.print("mNumInterestingWindows=");
1707 pw.print(mNumInterestingWindows);
1708 pw.print(" mNumDrawnWindows="); pw.print(mNumDrawnWindows);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001709 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -07001710 pw.print(" allDrawn="); pw.print(allDrawn);
1711 pw.print(" (animator="); pw.print(mAppAnimator.allDrawn);
1712 pw.println(")");
1713 }
1714 if (inPendingTransaction) {
1715 pw.print(prefix); pw.print("inPendingTransaction=");
1716 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001717 }
Craig Mautner799bc1d2015-01-14 10:33:48 -08001718 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001719 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
1720 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -08001721 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -08001722 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001723 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001724 if (startingWindow != null || startingSurface != null
Wale Ogunwale6c459212017-05-17 08:56:03 -07001725 || startingDisplayed || startingMoved || mHiddenSetFromTransferredStartingWindow) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001726 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001727 pw.print(" startingSurface="); pw.print(startingSurface);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001728 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
Wale Ogunwale6c459212017-05-17 08:56:03 -07001729 pw.print(" startingMoved="); pw.print(startingMoved);
1730 pw.println(" mHiddenSetFromTransferredStartingWindow="
1731 + mHiddenSetFromTransferredStartingWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001732 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01001733 if (!mFrozenBounds.isEmpty()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -08001734 pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds);
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001735 pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig);
Chong Zhangd78ddb42016-03-02 17:01:14 -08001736 }
1737 if (mPendingRelaunchCount != 0) {
1738 pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount);
Jorim Jaggi0429f352015-12-22 16:29:16 +01001739 }
Wale Ogunwale9c64cb62017-04-12 13:39:59 -07001740 if (getController() != null) {
1741 pw.print(prefix); pw.print("controller="); pw.println(getController());
1742 }
Wale Ogunwalee287e192017-04-21 09:30:12 -07001743 if (mRemovingFromDisplay) {
1744 pw.println(prefix + "mRemovingFromDisplay=" + mRemovingFromDisplay);
1745 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001746 }
1747
1748 @Override
1749 public String toString() {
1750 if (stringName == null) {
1751 StringBuilder sb = new StringBuilder();
1752 sb.append("AppWindowToken{");
1753 sb.append(Integer.toHexString(System.identityHashCode(this)));
1754 sb.append(" token="); sb.append(token); sb.append('}');
1755 stringName = sb.toString();
1756 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001757 return stringName + ((mIsExiting) ? " mIsExiting=" : "");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001758 }
Jeff Browne9bdb312012-04-05 15:30:10 -07001759}