blob: a8a0b0efb784799cb952c964ca80abe97f34dfc0 [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;
Chong Zhangf96cb3c2016-08-15 11:09:29 -070020import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080021import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Chong Zhangf96cb3c2016-08-15 11:09:29 -070022import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080023import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
24import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
Robert Carra1eb4392015-12-10 12:43:51 -080025import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
Wale Ogunwale9017ec02016-02-25 08:55:25 -080026import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080027import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
28import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_MOVEMENT;
29import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
30import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Chong Zhangf596cd52016-01-05 13:42:44 -080031import static com.android.server.wm.WindowManagerService.WINDOW_REPLACEMENT_TIMEOUT_DURATION;
Chong Zhang92147042016-05-09 12:47:11 -070032import static com.android.server.wm.WindowManagerService.H.NOTIFY_ACTIVITY_DRAWN;
Jorim Jaggi6626f542016-08-22 13:08:44 -070033import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_NONE;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080034
Jeff Brown4532e612012-04-05 14:27:12 -070035import com.android.server.input.InputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080036import com.android.server.wm.WindowManagerService.H;
37
Filip Gruszczynskia590c992015-11-25 16:45:26 -080038import android.annotation.NonNull;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080039import android.content.pm.ActivityInfo;
Jorim Jaggi26c8c422016-05-09 19:57:25 -070040import android.content.res.Configuration;
Jorim Jaggi0429f352015-12-22 16:29:16 +010041import android.graphics.Rect;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080042import android.os.Message;
43import android.os.RemoteException;
44import android.util.Slog;
45import android.view.IApplicationToken;
46import android.view.View;
47import android.view.WindowManager;
Jorim Jaggi6626f542016-08-22 13:08:44 -070048import android.view.animation.Animation;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080049
50import java.io.PrintWriter;
Jorim Jaggi0429f352015-12-22 16:29:16 +010051import java.util.ArrayDeque;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080052import java.util.ArrayList;
53
54class AppTokenList extends ArrayList<AppWindowToken> {
55}
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080056
57/**
58 * Version of WindowToken that is specifically for a particular application (or
59 * really activity) that is displaying windows.
60 */
Craig Mautnere32c3072012-03-12 15:25:35 -070061class AppWindowToken extends WindowToken {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080062 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppWindowToken" : TAG_WM;
63
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080064 // Non-null only for application tokens.
65 final IApplicationToken appToken;
66
67 // All of the windows and child windows that are included in this
68 // application token. Note this list is NOT sorted!
Craig Mautner96868332012-12-04 14:29:11 -080069 final WindowList allAppWindows = new WindowList();
Filip Gruszczynskia590c992015-11-25 16:45:26 -080070 @NonNull final AppWindowAnimator mAppAnimator;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -070071
Dianne Hackborne30e02f2014-05-27 18:24:45 -070072 final boolean voiceInteraction;
73
Craig Mautner83162a92015-01-26 14:43:30 -080074 Task mTask;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080075 boolean appFullscreen;
76 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Craig Mautner4c5eb222013-11-18 12:59:05 -080077 boolean layoutConfigChanges;
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -070078 boolean showForAllUsers;
Yorke Lee0e852472016-06-15 10:03:18 -070079 int targetSdk;
Craig Mautnera2c77052012-03-26 12:14:43 -070080
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080081 // The input dispatching timeout for this application token in nanoseconds.
82 long inputDispatchingTimeoutNanos;
83
84 // These are used for determining when all windows associated with
85 // an activity have been drawn, so they can be made visible together
86 // at the same time.
Craig Mautner764983d2012-03-22 11:37:36 -070087 // initialize so that it doesn't match mTransactionSequence which is an int.
88 long lastTransactionSequence = Long.MIN_VALUE;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080089 int numInterestingWindows;
90 int numDrawnWindows;
91 boolean inPendingTransaction;
92 boolean allDrawn;
Craig Mautner7636dfb2012-11-16 15:24:11 -080093 // Set to true when this app creates a surface while in the middle of an animation. In that
94 // case do not clear allDrawn until the animation completes.
95 boolean deferClearAllDrawn;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080096
Chong Zhang8e4bda92016-05-04 15:08:18 -070097 // These are to track the app's real drawing status if there were no saved surfaces.
98 boolean allDrawnExcludingSaved;
99 int numInterestingWindowsExcludingSaved;
100 int numDrawnWindowsExclusingSaved;
101
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800102 // Is this window's surface needed? This is almost like hidden, except
103 // it will sometimes be true a little earlier: when the token has
104 // been shown, but is still waiting for its app transition to execute
105 // before making its windows shown.
106 boolean hiddenRequested;
107
108 // Have we told the window clients to hide themselves?
109 boolean clientHidden;
110
111 // Last visibility state we reported to the app token.
112 boolean reportedVisible;
113
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700114 // Last drawn state we reported to the app token.
115 boolean reportedDrawn;
116
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800117 // Set to true when the token has been removed from the window mgr.
118 boolean removed;
119
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800120 // Information about an application starting window if displayed.
121 StartingData startingData;
122 WindowState startingWindow;
123 View startingView;
124 boolean startingDisplayed;
125 boolean startingMoved;
126 boolean firstWindowDrawn;
127
128 // Input application handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700129 final InputApplicationHandle mInputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800130
Craig Mautner799bc1d2015-01-14 10:33:48 -0800131 boolean mIsExiting;
Craig Mautner9ef471f2014-02-07 13:11:47 -0800132
Craig Mautnerbb742462014-07-07 15:28:55 -0700133 boolean mLaunchTaskBehind;
Craig Mautner8746a472014-07-24 15:12:54 -0700134 boolean mEnteringAnimation;
Craig Mautnerbb742462014-07-07 15:28:55 -0700135
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800136 boolean mAlwaysFocusable;
137
Robert Carre12aece2016-02-02 22:43:27 -0800138 boolean mAppStopped;
Robert Carrfd10cd12016-06-29 16:41:50 -0700139 int mRotationAnimationHint;
Chong Zhangd78ddb42016-03-02 17:01:14 -0800140 int mPendingRelaunchCount;
Robert Carre12aece2016-02-02 22:43:27 -0800141
Robert Carr91b228092016-06-28 17:32:37 -0700142 private ArrayList<WindowSurfaceController.SurfaceControlWithBackground> mSurfaceViewBackgrounds =
143 new ArrayList<WindowSurfaceController.SurfaceControlWithBackground>();
144
Jorim Jaggi0429f352015-12-22 16:29:16 +0100145 ArrayDeque<Rect> mFrozenBounds = new ArrayDeque<>();
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700146 ArrayDeque<Configuration> mFrozenMergedConfig = new ArrayDeque<>();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100147
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700148 AppWindowToken(WindowManagerService _service, IApplicationToken _token,
149 boolean _voiceInteraction) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800150 super(_service, _token.asBinder(),
151 WindowManager.LayoutParams.TYPE_APPLICATION, true);
152 appWindowToken = this;
153 appToken = _token;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700154 voiceInteraction = _voiceInteraction;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800155 mInputApplicationHandle = new InputApplicationHandle(this);
Craig Mautner322e4032012-07-13 13:35:20 -0700156 mAppAnimator = new AppWindowAnimator(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800157 }
158
159 void sendAppVisibilityToClients() {
160 final int N = allAppWindows.size();
161 for (int i=0; i<N; i++) {
162 WindowState win = allAppWindows.get(i);
163 if (win == startingWindow && clientHidden) {
164 // Don't hide the starting window.
165 continue;
166 }
167 try {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800168 if (DEBUG_VISIBILITY) Slog.v(TAG,
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800169 "Setting visibility of " + win + ": " + (!clientHidden));
170 win.mClient.dispatchAppVisibility(!clientHidden);
171 } catch (RemoteException e) {
172 }
173 }
174 }
175
Chong Zhang92147042016-05-09 12:47:11 -0700176 void setVisibleBeforeClientHidden() {
177 for (int i = allAppWindows.size() - 1; i >= 0; i--) {
178 final WindowState w = allAppWindows.get(i);
179 w.setVisibleBeforeClientHidden();
180 }
181 }
182
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800183 void onFirstWindowDrawn(WindowState win, WindowStateAnimator winAnimator) {
184 firstWindowDrawn = true;
185
186 // We now have a good window to show, remove dead placeholders
187 removeAllDeadWindows();
188
189 if (startingData != null) {
190 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, "Finish starting "
191 + win.mToken + ": first real window is shown, no animation");
192 // If this initial window is animating, stop it -- we will do an animation to reveal
193 // it from behind the starting window, so there is no need for it to also be doing its
194 // own stuff.
195 winAnimator.clearAnimation();
196 winAnimator.mService.mFinishedStarting.add(this);
197 winAnimator.mService.mH.sendEmptyMessage(H.FINISHED_STARTING);
198 }
199 updateReportedVisibilityLocked();
200 }
201
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800202 void updateReportedVisibilityLocked() {
203 if (appToken == null) {
204 return;
205 }
206
207 int numInteresting = 0;
208 int numVisible = 0;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700209 int numDrawn = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800210 boolean nowGone = true;
211
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800212 if (DEBUG_VISIBILITY) Slog.v(TAG,
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700213 "Update reported visibility: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800214 final int N = allAppWindows.size();
215 for (int i=0; i<N; i++) {
216 WindowState win = allAppWindows.get(i);
217 if (win == startingWindow || win.mAppFreezing
218 || win.mViewVisibility != View.VISIBLE
219 || win.mAttrs.type == TYPE_APPLICATION_STARTING
220 || win.mDestroying) {
221 continue;
222 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800223 if (DEBUG_VISIBILITY) {
224 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800225 + win.isDrawnLw()
Jorim Jaggi5c80c412016-04-19 20:03:47 -0700226 + ", isAnimationSet=" + win.mWinAnimator.isAnimationSet());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800227 if (!win.isDrawnLw()) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800228 Slog.v(TAG, "Not displayed: s=" +
Robert Carre6a83512015-11-03 16:09:21 -0800229 win.mWinAnimator.mSurfaceController
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800230 + " pv=" + win.mPolicyVisibility
Craig Mautner749a7bb2012-04-02 13:49:53 -0700231 + " mDrawState=" + win.mWinAnimator.mDrawState
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800232 + " ah=" + win.mAttachedHidden
233 + " th="
234 + (win.mAppToken != null
235 ? win.mAppToken.hiddenRequested : false)
Craig Mautnera2c77052012-03-26 12:14:43 -0700236 + " a=" + win.mWinAnimator.mAnimating);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800237 }
238 }
239 numInteresting++;
240 if (win.isDrawnLw()) {
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700241 numDrawn++;
Jorim Jaggi5c80c412016-04-19 20:03:47 -0700242 if (!win.mWinAnimator.isAnimationSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800243 numVisible++;
244 }
245 nowGone = false;
Jorim Jaggi5c80c412016-04-19 20:03:47 -0700246 } else if (win.mWinAnimator.isAnimationSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800247 nowGone = false;
248 }
249 }
250
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700251 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800252 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700253 if (!nowGone) {
254 // If the app is not yet gone, then it can only become visible/drawn.
255 if (!nowDrawn) {
256 nowDrawn = reportedDrawn;
257 }
258 if (!nowVisible) {
259 nowVisible = reportedVisible;
260 }
261 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800262 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800263 + numInteresting + " visible=" + numVisible);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700264 if (nowDrawn != reportedDrawn) {
265 if (nowDrawn) {
266 Message m = service.mH.obtainMessage(
267 H.REPORT_APPLICATION_TOKEN_DRAWN, this);
268 service.mH.sendMessage(m);
269 }
270 reportedDrawn = nowDrawn;
271 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800272 if (nowVisible != reportedVisible) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800273 if (DEBUG_VISIBILITY) Slog.v(
274 TAG, "Visibility changed in " + this
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800275 + ": vis=" + nowVisible);
276 reportedVisible = nowVisible;
277 Message m = service.mH.obtainMessage(
278 H.REPORT_APPLICATION_TOKEN_WINDOWS,
279 nowVisible ? 1 : 0,
280 nowGone ? 1 : 0,
281 this);
282 service.mH.sendMessage(m);
283 }
284 }
285
286 WindowState findMainWindow() {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700287 WindowState candidate = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800288 int j = windows.size();
289 while (j > 0) {
290 j--;
291 WindowState win = windows.get(j);
292 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
293 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700294 // In cases where there are multiple windows, we prefer the non-exiting window. This
Sungsoo Lim0d3d1f82015-12-02 14:47:59 +0900295 // happens for example when replacing windows during an activity relaunch. When
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700296 // constructing the animation, we want the new window, not the exiting one.
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800297 if (win.mAnimatingExit) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700298 candidate = win;
299 } else {
300 return win;
301 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800302 }
303 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700304 return candidate;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800305 }
306
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800307 boolean windowsAreFocusable() {
308 return StackId.canReceiveKeys(mTask.mStack.mStackId) || mAlwaysFocusable;
Wale Ogunwaled045c822015-12-02 09:14:28 -0800309 }
310
Craig Mautner72669d12012-12-18 17:23:54 -0800311 boolean isVisible() {
312 final int N = allAppWindows.size();
Craig Mautner72669d12012-12-18 17:23:54 -0800313 for (int i=0; i<N; i++) {
314 WindowState win = allAppWindows.get(i);
Chong Zhangdb20b5f2015-10-23 14:01:43 -0700315 // If we're animating with a saved surface, we're already visible.
316 // Return true so that the alpha doesn't get cleared.
Craig Mautner72669d12012-12-18 17:23:54 -0800317 if (!win.mAppFreezing
Chong Zhang92147042016-05-09 12:47:11 -0700318 && (win.mViewVisibility == View.VISIBLE || win.isAnimatingWithSavedSurface()
Jorim Jaggi5c80c412016-04-19 20:03:47 -0700319 || (win.mWinAnimator.isAnimationSet()
Filip Gruszczynski57f76f12015-11-04 16:10:54 -0800320 && !service.mAppTransition.isTransitionSet()))
321 && !win.mDestroying
322 && win.isDrawnLw()) {
Craig Mautner72669d12012-12-18 17:23:54 -0800323 return true;
324 }
325 }
326 return false;
327 }
328
Craig Mautnere3119b72015-01-20 15:02:36 -0800329 void removeAppFromTaskLocked() {
330 mIsExiting = false;
331 removeAllWindows();
332
Craig Mautner83162a92015-01-26 14:43:30 -0800333 // Use local variable because removeAppToken will null out mTask.
334 final Task task = mTask;
Craig Mautnere3119b72015-01-20 15:02:36 -0800335 if (task != null) {
336 if (!task.removeAppToken(this)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800337 Slog.e(TAG, "removeAppFromTaskLocked: token=" + this
Craig Mautnere3119b72015-01-20 15:02:36 -0800338 + " not found.");
339 }
340 task.mStack.mExitingAppTokens.remove(this);
341 }
342 }
343
Chong Zhange05bcb12016-07-26 17:47:29 -0700344 void clearAnimatingFlags() {
Chong Zhangb0d26702016-08-12 16:03:29 -0700345 boolean wallpaperMightChange = false;
Chong Zhange05bcb12016-07-26 17:47:29 -0700346 for (int i = allAppWindows.size() - 1; i >= 0; i--) {
347 final WindowState win = allAppWindows.get(i);
348 // We don't want to clear it out for windows that get replaced, because the
349 // animation depends on the flag to remove the replaced window.
350 //
351 // We also don't clear the mAnimatingExit flag for windows which have the
352 // mRemoveOnExit flag. This indicates an explicit remove request has been issued
353 // by the client. We should let animation proceed and not clear this flag or
354 // they won't eventually be removed by WindowStateAnimator#finishExit.
355 if (!win.mWillReplaceWindow && !win.mRemoveOnExit) {
Chong Zhange05bcb12016-07-26 17:47:29 -0700356 // Clear mAnimating flag together with mAnimatingExit. When animation
357 // changes from exiting to entering, we need to clear this flag until the
358 // new animation gets applied, so that isAnimationStarting() becomes true
359 // until then.
360 // Otherwise applySurfaceChangesTransaction will faill to skip surface
361 // placement for this window during this period, one or more frame will
362 // show up with wrong position or scale.
Chong Zhangb0d26702016-08-12 16:03:29 -0700363 if (win.mAnimatingExit) {
364 win.mAnimatingExit = false;
365 wallpaperMightChange = true;
366 }
367 if (win.mWinAnimator.mAnimating) {
368 win.mWinAnimator.mAnimating = false;
369 wallpaperMightChange = true;
370 }
Chong Zhangf96cb3c2016-08-15 11:09:29 -0700371 if (win.mDestroying) {
372 win.mDestroying = false;
373 service.mDestroySurface.remove(win);
Chong Zhangb0d26702016-08-12 16:03:29 -0700374 wallpaperMightChange = true;
Chong Zhangf96cb3c2016-08-15 11:09:29 -0700375 }
Chong Zhange05bcb12016-07-26 17:47:29 -0700376 }
377 }
Chong Zhangb0d26702016-08-12 16:03:29 -0700378 if (wallpaperMightChange) {
379 requestUpdateWallpaperIfNeeded();
380 }
Chong Zhange05bcb12016-07-26 17:47:29 -0700381 }
382
Robert Carre12aece2016-02-02 22:43:27 -0800383 void destroySurfaces() {
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700384 destroySurfaces(false /*cleanupOnResume*/);
385 }
386
387 /**
388 * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure
389 * the client has finished with them.
390 *
391 * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If
392 * set to true, destroy only surfaces of removed windows, and clear relevant flags of the
393 * others so that they are ready to be reused. If set to false (common case), destroy all
394 * surfaces that's eligible, if the app is already stopped.
395 */
396
397 private void destroySurfaces(boolean cleanupOnResume) {
Robert Carre12aece2016-02-02 22:43:27 -0800398 final ArrayList<WindowState> allWindows = (ArrayList<WindowState>) allAppWindows.clone();
399 final DisplayContentList displayList = new DisplayContentList();
400 for (int i = allWindows.size() - 1; i >= 0; i--) {
401 final WindowState win = allWindows.get(i);
Chong Zhangeb665572016-05-09 18:28:27 -0700402
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700403 if (!(mAppStopped || win.mWindowRemovalAllowed || cleanupOnResume)) {
Robert Carre12aece2016-02-02 22:43:27 -0800404 continue;
405 }
406
Chong Zhangeb665572016-05-09 18:28:27 -0700407 win.mWinAnimator.destroyPreservedSurfaceLocked();
408
409 if (!win.mDestroying) {
Chong Zhang5471e902016-02-12 15:34:10 -0800410 continue;
Robert Carre12aece2016-02-02 22:43:27 -0800411 }
412
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800413 if (DEBUG_ADD_REMOVE) Slog.e(TAG_WM, "win=" + win
414 + " destroySurfaces: mAppStopped=" + mAppStopped
415 + " win.mWindowRemovalAllowed=" + win.mWindowRemovalAllowed
416 + " win.mRemoveOnExit=" + win.mRemoveOnExit);
417
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700418 if (!cleanupOnResume || win.mRemoveOnExit) {
419 win.destroyOrSaveSurface();
420 }
Robert Carre12aece2016-02-02 22:43:27 -0800421 if (win.mRemoveOnExit) {
Robert Carre12aece2016-02-02 22:43:27 -0800422 service.removeWindowInnerLocked(win);
423 }
424 final DisplayContent displayContent = win.getDisplayContent();
425 if (displayContent != null && !displayList.contains(displayContent)) {
426 displayList.add(displayContent);
427 }
Chong Zhangf96cb3c2016-08-15 11:09:29 -0700428 if (cleanupOnResume) {
429 win.requestUpdateWallpaperIfNeeded();
430 }
Robert Carre12aece2016-02-02 22:43:27 -0800431 win.mDestroying = false;
432 }
433 for (int i = 0; i < displayList.size(); i++) {
434 final DisplayContent displayContent = displayList.get(i);
435 service.mLayersController.assignLayersLocked(displayContent.getWindowList());
436 displayContent.layoutNeeded = true;
437 }
438 }
439
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800440 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700441 * Notify that the app is now resumed, and it was not stopped before, perform a clean
442 * up of the surfaces
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800443 */
Chong Zhang813be132016-08-25 12:12:33 -0700444 void notifyAppResumed(boolean wasStopped, boolean allowSavedSurface) {
445 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped
446 + " allowSavedSurface=" + allowSavedSurface + " " + this);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700447 mAppStopped = false;
448 if (!wasStopped) {
449 destroySurfaces(true /*cleanupOnResume*/);
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800450 }
Chong Zhang813be132016-08-25 12:12:33 -0700451 if (!allowSavedSurface) {
452 destroySavedSurfaces();
453 }
Robert Carre12aece2016-02-02 22:43:27 -0800454 }
455
Chong Zhangbef461f2015-10-27 11:38:24 -0700456 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700457 * Notify that the app has stopped, and it is okay to destroy any surfaces which were
458 * keeping alive in case they were still being used.
459 */
460 void notifyAppStopped() {
461 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this);
462 mAppStopped = true;
463 destroySurfaces();
464 // Remove any starting window that was added for this app if they are still around.
465 mTask.mService.scheduleRemoveStartingWindowLocked(this);
466 }
467
468 /**
Chong Zhangbef461f2015-10-27 11:38:24 -0700469 * Checks whether we should save surfaces for this app.
470 *
471 * @return true if the surfaces should be saved, false otherwise.
472 */
473 boolean shouldSaveSurface() {
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800474 // We want to save surface if the app's windows are "allDrawn".
475 // (If we started entering animation early with saved surfaces, allDrawn
476 // should have been restored to true. So we'll save again in that case
477 // even if app didn't actually finish drawing.)
478 return allDrawn;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800479 }
480
Chong Zhang92147042016-05-09 12:47:11 -0700481 boolean canRestoreSurfaces() {
Chong Zhangb7b4a562016-04-28 15:30:33 -0700482 for (int i = allAppWindows.size() -1; i >= 0; i--) {
Chong Zhang92147042016-05-09 12:47:11 -0700483 final WindowState w = allAppWindows.get(i);
484 if (w.canRestoreSurface()) {
Robert Carr13f7be9e2015-12-02 18:39:45 -0800485 return true;
486 }
Chong Zhangbef461f2015-10-27 11:38:24 -0700487 }
488 return false;
489 }
490
Chong Zhang92147042016-05-09 12:47:11 -0700491 void clearVisibleBeforeClientHidden() {
492 for (int i = allAppWindows.size() - 1; i >= 0; i--) {
493 final WindowState w = allAppWindows.get(i);
494 w.clearVisibleBeforeClientHidden();
495 }
496 }
497
Chong Zhang8e4bda92016-05-04 15:08:18 -0700498 /**
499 * Whether the app has some window that is invisible in layout, but
500 * animating with saved surface.
501 */
502 boolean isAnimatingInvisibleWithSavedSurface() {
503 for (int i = allAppWindows.size() - 1; i >= 0; i--) {
504 final WindowState w = allAppWindows.get(i);
505 if (w.isAnimatingInvisibleWithSavedSurface()) {
506 return true;
507 }
508 }
509 return false;
510 }
511
512 /**
513 * Hide all window surfaces that's still invisible in layout but animating
514 * with a saved surface, and mark them destroying.
515 */
516 void stopUsingSavedSurfaceLocked() {
517 for (int i = allAppWindows.size() - 1; i >= 0; i--) {
518 final WindowState w = allAppWindows.get(i);
519 if (w.isAnimatingInvisibleWithSavedSurface()) {
520 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG,
521 "stopUsingSavedSurfaceLocked: " + w);
522 w.clearAnimatingWithSavedSurface();
523 w.mDestroying = true;
524 w.mWinAnimator.hide("stopUsingSavedSurfaceLocked");
525 w.mWinAnimator.mWallpaperControllerLocked.hideWallpapers(w);
526 }
527 }
528 destroySurfaces();
529 }
530
Chong Zhangf58631a2016-05-24 16:02:10 -0700531 void markSavedSurfaceExiting() {
532 for (int i = allAppWindows.size() - 1; i >= 0; i--) {
533 final WindowState w = allAppWindows.get(i);
534 if (w.isAnimatingInvisibleWithSavedSurface()) {
535 w.mAnimatingExit = true;
536 w.mWinAnimator.mAnimating = true;
537 }
538 }
539 }
540
Chong Zhangbef461f2015-10-27 11:38:24 -0700541 void restoreSavedSurfaces() {
Chong Zhang92147042016-05-09 12:47:11 -0700542 if (!canRestoreSurfaces()) {
543 clearVisibleBeforeClientHidden();
Chong Zhangbef461f2015-10-27 11:38:24 -0700544 return;
545 }
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800546 // Check if we have enough drawn windows to mark allDrawn= true.
547 int numInteresting = 0;
548 int numDrawn = 0;
Chong Zhangb7b4a562016-04-28 15:30:33 -0700549 for (int i = allAppWindows.size() - 1; i >= 0; i--) {
550 WindowState w = allAppWindows.get(i);
Chong Zhang92147042016-05-09 12:47:11 -0700551 if (w != startingWindow && !w.mAppDied && w.wasVisibleBeforeClientHidden()
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800552 && (!mAppAnimator.freezingScreen || !w.mAppFreezing)) {
553 numInteresting++;
Chong Zhang92147042016-05-09 12:47:11 -0700554 if (w.hasSavedSurface()) {
555 w.restoreSavedSurface();
556 }
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800557 if (w.isDrawnLw()) {
558 numDrawn++;
559 }
560 }
Chong Zhangbef461f2015-10-27 11:38:24 -0700561 }
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800562
Chong Zhang92147042016-05-09 12:47:11 -0700563 if (!allDrawn) {
564 allDrawn = (numInteresting > 0) && (numInteresting == numDrawn);
565 if (allDrawn) {
566 service.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
567 }
568 }
569 clearVisibleBeforeClientHidden();
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800570
571 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG,
Chong Zhang92147042016-05-09 12:47:11 -0700572 "restoreSavedSurfaces: " + appWindowToken + " allDrawn=" + allDrawn
573 + " numInteresting=" + numInteresting + " numDrawn=" + numDrawn);
Chong Zhangbef461f2015-10-27 11:38:24 -0700574 }
575
576 void destroySavedSurfaces() {
Chong Zhangb7b4a562016-04-28 15:30:33 -0700577 for (int i = allAppWindows.size() - 1; i >= 0; i--) {
578 WindowState win = allAppWindows.get(i);
Robert Carr13f7be9e2015-12-02 18:39:45 -0800579 win.destroySavedSurface();
Chong Zhangbef461f2015-10-27 11:38:24 -0700580 }
Chong Zhang92147042016-05-09 12:47:11 -0700581 }
582
583 void clearAllDrawn() {
584 allDrawn = false;
585 deferClearAllDrawn = false;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700586 allDrawnExcludingSaved = false;
Chong Zhangbef461f2015-10-27 11:38:24 -0700587 }
588
Wale Ogunwale98e70d02014-11-10 12:12:27 -0800589 @Override
Craig Mautner7c9ee192014-08-14 16:08:26 -0700590 void removeAllWindows() {
Craig Mautner7b4655d2014-11-20 12:13:22 -0800591 for (int winNdx = allAppWindows.size() - 1; winNdx >= 0;
592 // removeWindowLocked at bottom of loop may remove multiple entries from
593 // allAppWindows if the window to be removed has child windows. It also may
594 // not remove any windows from allAppWindows at all if win is exiting and
595 // currently animating away. This ensures that winNdx is monotonically decreasing
596 // and never beyond allAppWindows bounds.
597 winNdx = Math.min(winNdx - 1, allAppWindows.size() - 1)) {
598 WindowState win = allAppWindows.get(winNdx);
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800599 if (DEBUG_WINDOW_MOVEMENT) {
600 Slog.w(TAG, "removeAllWindows: removing win=" + win);
Wale Ogunwale98e70d02014-11-10 12:12:27 -0800601 }
602
Wale Ogunwalea6ab5c42015-04-24 09:00:25 -0700603 service.removeWindowLocked(win);
Craig Mautner7c9ee192014-08-14 16:08:26 -0700604 }
Craig Mautnere3119b72015-01-20 15:02:36 -0800605 allAppWindows.clear();
606 windows.clear();
Craig Mautner7c9ee192014-08-14 16:08:26 -0700607 }
608
Chong Zhang112eb8c2015-11-02 11:17:00 -0800609 void removeAllDeadWindows() {
610 for (int winNdx = allAppWindows.size() - 1; winNdx >= 0;
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700611 // removeWindowLocked at bottom of loop may remove multiple entries from
612 // allAppWindows if the window to be removed has child windows. It also may
613 // not remove any windows from allAppWindows at all if win is exiting and
614 // currently animating away. This ensures that winNdx is monotonically decreasing
615 // and never beyond allAppWindows bounds.
616 winNdx = Math.min(winNdx - 1, allAppWindows.size() - 1)) {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800617 WindowState win = allAppWindows.get(winNdx);
618 if (win.mAppDied) {
Wale Ogunwale2728bf42016-03-03 11:03:26 -0800619 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800620 Slog.w(TAG, "removeAllDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800621 }
622 // Set mDestroying, we don't want any animation or delayed removal here.
623 win.mDestroying = true;
624 service.removeWindowLocked(win);
625 }
626 }
627 }
628
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700629 boolean hasWindowsAlive() {
630 for (int i = allAppWindows.size() - 1; i >= 0; i--) {
631 if (!allAppWindows.get(i).mAppDied) {
632 return true;
633 }
634 }
635 return false;
636 }
637
Robert Carra1eb4392015-12-10 12:43:51 -0800638 void setReplacingWindows(boolean animate) {
639 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + appWindowToken
640 + " with replacing windows.");
641
642 for (int i = allAppWindows.size() - 1; i >= 0; i--) {
643 final WindowState w = allAppWindows.get(i);
644 w.setReplacing(animate);
645 }
646 if (animate) {
647 // Set-up dummy animation so we can start treating windows associated with this
648 // token like they are in transition before the new app window is ready for us to
649 // run the real transition animation.
650 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
651 "setReplacingWindow() Setting dummy animation on: " + this);
652 mAppAnimator.setDummyAnimation();
653 }
654 }
655
Robert Carr23fa16b2016-01-13 13:19:58 -0800656 void setReplacingChildren() {
657 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + appWindowToken
658 + " with replacing child windows.");
659 for (int i = allAppWindows.size() - 1; i >= 0; i--) {
660 final WindowState w = allAppWindows.get(i);
Robert Carrd1a010f2016-04-07 22:36:22 -0700661 if (w.shouldBeReplacedWithChildren()) {
Robert Carr23fa16b2016-01-13 13:19:58 -0800662 w.setReplacing(false /* animate */);
663 }
664 }
665 }
666
Chong Zhangf596cd52016-01-05 13:42:44 -0800667 void resetReplacingWindows() {
668 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Resetting app token " + appWindowToken
669 + " of replacing window marks.");
670
671 for (int i = allAppWindows.size() - 1; i >= 0; i--) {
672 final WindowState w = allAppWindows.get(i);
673 w.resetReplacing();
674 }
675 }
676
Chong Zhang4d7369a2016-04-25 16:09:14 -0700677 void requestUpdateWallpaperIfNeeded() {
678 for (int i = allAppWindows.size() - 1; i >= 0; i--) {
679 final WindowState w = allAppWindows.get(i);
680 w.requestUpdateWallpaperIfNeeded();
681 }
682 }
683
Chong Zhangd78ddb42016-03-02 17:01:14 -0800684 boolean isRelaunching() {
685 return mPendingRelaunchCount > 0;
686 }
687
688 void startRelaunching() {
689 if (canFreezeBounds()) {
690 freezeBounds();
691 }
692 mPendingRelaunchCount++;
693 }
694
695 void finishRelaunching() {
696 if (canFreezeBounds()) {
697 unfreezeBounds();
698 }
699 if (mPendingRelaunchCount > 0) {
700 mPendingRelaunchCount--;
701 }
702 }
703
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700704 void clearRelaunching() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700705 if (mPendingRelaunchCount == 0) {
706 return;
707 }
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700708 if (canFreezeBounds()) {
709 unfreezeBounds();
710 }
711 mPendingRelaunchCount = 0;
712 }
713
Robert Carra1eb4392015-12-10 12:43:51 -0800714 void addWindow(WindowState w) {
715 for (int i = allAppWindows.size() - 1; i >= 0; i--) {
716 WindowState candidate = allAppWindows.get(i);
717 if (candidate.mWillReplaceWindow && candidate.mReplacingWindow == null &&
Robert Carr8bc89072016-04-08 13:29:59 -0700718 candidate.getWindowTag().toString().equals(w.getWindowTag().toString())) {
Robert Carra1eb4392015-12-10 12:43:51 -0800719 candidate.mReplacingWindow = w;
Robert Carrb439a632016-04-07 22:52:10 -0700720 w.mSkipEnterAnimationForSeamlessReplacement = !candidate.mAnimateReplacingWindow;
Chong Zhangf596cd52016-01-05 13:42:44 -0800721
722 // if we got a replacement window, reset the timeout to give drawing more time
Chong Zhang32de3652016-05-12 16:00:01 -0700723 service.scheduleReplacingWindowTimeouts(this);
Robert Carra1eb4392015-12-10 12:43:51 -0800724 }
725 }
726 allAppWindows.add(w);
727 }
728
729 boolean waitingForReplacement() {
730 for (int i = allAppWindows.size() -1; i >= 0; i--) {
731 WindowState candidate = allAppWindows.get(i);
732 if (candidate.mWillReplaceWindow) {
733 return true;
734 }
735 }
736 return false;
737 }
738
Chong Zhangf596cd52016-01-05 13:42:44 -0800739 void clearTimedoutReplacesLocked() {
Robert Carra1eb4392015-12-10 12:43:51 -0800740 for (int i = allAppWindows.size() - 1; i >= 0;
741 // removeWindowLocked at bottom of loop may remove multiple entries from
742 // allAppWindows if the window to be removed has child windows. It also may
743 // not remove any windows from allAppWindows at all if win is exiting and
744 // currently animating away. This ensures that winNdx is monotonically decreasing
745 // and never beyond allAppWindows bounds.
746 i = Math.min(i - 1, allAppWindows.size() - 1)) {
747 WindowState candidate = allAppWindows.get(i);
748 if (candidate.mWillReplaceWindow == false) {
749 continue;
750 }
751 candidate.mWillReplaceWindow = false;
Robert Carrb439a632016-04-07 22:52:10 -0700752 if (candidate.mReplacingWindow != null) {
753 candidate.mReplacingWindow.mSkipEnterAnimationForSeamlessReplacement = false;
754 }
Chong Zhangf596cd52016-01-05 13:42:44 -0800755 // Since the window already timed out, remove it immediately now.
756 // Use removeWindowInnerLocked() instead of removeWindowLocked(), as the latter
757 // delays removal on certain conditions, which will leave the stale window in the
758 // stack and marked mWillReplaceWindow=false, so the window will never be removed.
759 service.removeWindowInnerLocked(candidate);
Robert Carra1eb4392015-12-10 12:43:51 -0800760 }
761 }
762
Chong Zhangd78ddb42016-03-02 17:01:14 -0800763 private boolean canFreezeBounds() {
764 // For freeform windows, we can't freeze the bounds at the moment because this would make
765 // the resizing unresponsive.
766 return mTask != null && !mTask.inFreeformWorkspace();
767 }
768
Jorim Jaggi0429f352015-12-22 16:29:16 +0100769 /**
770 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
771 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
772 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
773 * with a queue.
774 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800775 private void freezeBounds() {
Jorim Jaggi0429f352015-12-22 16:29:16 +0100776 mFrozenBounds.offer(new Rect(mTask.mPreparedFrozenBounds));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700777
778 if (mTask.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) {
779 // We didn't call prepareFreezingBounds on the task, so use the current value.
780 final Configuration config = new Configuration(service.mCurConfiguration);
781 config.updateFrom(mTask.mOverrideConfig);
782 mFrozenMergedConfig.offer(config);
783 } else {
784 mFrozenMergedConfig.offer(new Configuration(mTask.mPreparedFrozenMergedConfig));
785 }
786 mTask.mPreparedFrozenMergedConfig.setToDefaults();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100787 }
788
789 /**
790 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
791 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800792 private void unfreezeBounds() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700793 if (!mFrozenBounds.isEmpty()) {
794 mFrozenBounds.remove();
795 }
796 if (!mFrozenMergedConfig.isEmpty()) {
797 mFrozenMergedConfig.remove();
798 }
Jorim Jaggi4846ee32016-01-07 17:39:12 +0100799 for (int i = windows.size() - 1; i >= 0; i--) {
800 final WindowState win = windows.get(i);
Jorim Jaggi69abc192016-02-04 19:34:00 -0800801 if (!win.mHasSurface) {
802 continue;
803 }
Jorim Jaggi4846ee32016-01-07 17:39:12 +0100804 win.mLayoutNeeded = true;
805 win.setDisplayLayoutNeeded();
806 if (!service.mResizingWindows.contains(win)) {
807 service.mResizingWindows.add(win);
808 }
809 }
810 service.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100811 }
812
Robert Carr91b228092016-06-28 17:32:37 -0700813 void addSurfaceViewBackground(WindowSurfaceController.SurfaceControlWithBackground background) {
814 mSurfaceViewBackgrounds.add(background);
815 }
816
817 void removeSurfaceViewBackground(WindowSurfaceController.SurfaceControlWithBackground background) {
818 mSurfaceViewBackgrounds.remove(background);
819 updateSurfaceViewBackgroundVisibilities();
820 }
821
822 // We use DimLayers behind SurfaceViews to prevent holes while resizing and creating.
823 // However, we need to ensure one SurfaceView doesn't cover another when they are both placed
824 // below the main app window (as traditionally a SurfaceView which is never drawn
825 // to is totally translucent). So we look at all our SurfaceView backgrounds and only enable
826 // the background for the SurfaceView with lowest Z order
827 void updateSurfaceViewBackgroundVisibilities() {
828 WindowSurfaceController.SurfaceControlWithBackground bottom = null;
829 int bottomLayer = Integer.MAX_VALUE;
830 for (int i = 0; i < mSurfaceViewBackgrounds.size(); i++) {
831 WindowSurfaceController.SurfaceControlWithBackground sc = mSurfaceViewBackgrounds.get(i);
832 if (sc.mVisible && sc.mLayer < bottomLayer) {
833 bottomLayer = sc.mLayer;
834 bottom = sc;
835 }
836 }
837 for (int i = 0; i < mSurfaceViewBackgrounds.size(); i++) {
838 WindowSurfaceController.SurfaceControlWithBackground sc = mSurfaceViewBackgrounds.get(i);
839 sc.updateBackgroundVisibility(sc != bottom);
840 }
841 }
842
Jorim Jaggi6626f542016-08-22 13:08:44 -0700843 /**
844 * See {@link WindowManagerService#overridePlayingAppAnimationsLw}
845 */
846 void overridePlayingAppAnimations(Animation a) {
847 if (mAppAnimator.isAnimating()) {
848 final WindowState win = findMainWindow();
849 final int width = win.mContainingFrame.width();
850 final int height = win.mContainingFrame.height();
851 mAppAnimator.setAnimation(a, width, height, false, STACK_CLIP_NONE);
852 }
853 }
854
Craig Mautnerdbb79912012-03-01 18:59:14 -0800855 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800856 void dump(PrintWriter pw, String prefix) {
857 super.dump(pw, prefix);
858 if (appToken != null) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700859 pw.print(prefix); pw.print("app=true voiceInteraction="); pw.println(voiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800860 }
861 if (allAppWindows.size() > 0) {
862 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
863 }
Craig Mautner83162a92015-01-26 14:43:30 -0800864 pw.print(prefix); pw.print("task="); pw.println(mTask);
865 pw.print(prefix); pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800866 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
867 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
868 pw.print(" clientHidden="); pw.print(clientHidden);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700869 pw.print(" reportedDrawn="); pw.print(reportedDrawn);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800870 pw.print(" reportedVisible="); pw.println(reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -0700871 if (paused) {
872 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800873 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800874 if (mAppStopped) {
875 pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped);
876 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800877 if (numInterestingWindows != 0 || numDrawnWindows != 0
Craig Mautner6fbda632012-07-03 09:26:39 -0700878 || allDrawn || mAppAnimator.allDrawn) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800879 pw.print(prefix); pw.print("numInterestingWindows=");
880 pw.print(numInterestingWindows);
881 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
882 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -0700883 pw.print(" allDrawn="); pw.print(allDrawn);
884 pw.print(" (animator="); pw.print(mAppAnimator.allDrawn);
885 pw.println(")");
886 }
887 if (inPendingTransaction) {
888 pw.print(prefix); pw.print("inPendingTransaction=");
889 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800890 }
Craig Mautner799bc1d2015-01-14 10:33:48 -0800891 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800892 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
893 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -0800894 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -0800895 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800896 }
897 if (startingWindow != null || startingView != null
898 || startingDisplayed || startingMoved) {
899 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
900 pw.print(" startingView="); pw.print(startingView);
901 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800902 pw.print(" startingMoved="); pw.println(startingMoved);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800903 }
Jorim Jaggi0429f352015-12-22 16:29:16 +0100904 if (!mFrozenBounds.isEmpty()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -0800905 pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds);
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700906 pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig);
Chong Zhangd78ddb42016-03-02 17:01:14 -0800907 }
908 if (mPendingRelaunchCount != 0) {
909 pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount);
Jorim Jaggi0429f352015-12-22 16:29:16 +0100910 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800911 }
912
913 @Override
914 public String toString() {
915 if (stringName == null) {
916 StringBuilder sb = new StringBuilder();
917 sb.append("AppWindowToken{");
918 sb.append(Integer.toHexString(System.identityHashCode(this)));
919 sb.append(" token="); sb.append(token); sb.append('}');
920 stringName = sb.toString();
921 }
922 return stringName;
923 }
Jeff Browne9bdb312012-04-05 15:30:10 -0700924}