blob: 573aaec034cfd2bf9de54a2ca1588bc732955cad [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;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080020import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080021import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
22import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
Robert Carra1eb4392015-12-10 12:43:51 -080023import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080024import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
25import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_MOVEMENT;
26import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
27import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080028
Jeff Brown4532e612012-04-05 14:27:12 -070029import com.android.server.input.InputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080030import com.android.server.wm.WindowManagerService.H;
31
Filip Gruszczynskia590c992015-11-25 16:45:26 -080032import android.annotation.NonNull;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080033import android.content.pm.ActivityInfo;
Jorim Jaggi0429f352015-12-22 16:29:16 +010034import android.graphics.Rect;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080035import android.os.Message;
36import android.os.RemoteException;
37import android.util.Slog;
38import android.view.IApplicationToken;
39import android.view.View;
40import android.view.WindowManager;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080041
42import java.io.PrintWriter;
Jorim Jaggi0429f352015-12-22 16:29:16 +010043import java.util.ArrayDeque;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080044import java.util.ArrayList;
45
46class AppTokenList extends ArrayList<AppWindowToken> {
47}
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080048
49/**
50 * Version of WindowToken that is specifically for a particular application (or
51 * really activity) that is displaying windows.
52 */
Craig Mautnere32c3072012-03-12 15:25:35 -070053class AppWindowToken extends WindowToken {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080054 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppWindowToken" : TAG_WM;
55
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080056 // Non-null only for application tokens.
57 final IApplicationToken appToken;
58
59 // All of the windows and child windows that are included in this
60 // application token. Note this list is NOT sorted!
Craig Mautner96868332012-12-04 14:29:11 -080061 final WindowList allAppWindows = new WindowList();
Filip Gruszczynskia590c992015-11-25 16:45:26 -080062 @NonNull final AppWindowAnimator mAppAnimator;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -070063
Dianne Hackborne30e02f2014-05-27 18:24:45 -070064 final boolean voiceInteraction;
65
Chong Zhangdb20b5f2015-10-23 14:01:43 -070066 // Whether we're performing an entering animation with a saved surface.
67 boolean mAnimatingWithSavedSurface;
68
Craig Mautner83162a92015-01-26 14:43:30 -080069 Task mTask;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080070 boolean appFullscreen;
71 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Craig Mautner4c5eb222013-11-18 12:59:05 -080072 boolean layoutConfigChanges;
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -070073 boolean showForAllUsers;
Craig Mautnera2c77052012-03-26 12:14:43 -070074
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080075 // The input dispatching timeout for this application token in nanoseconds.
76 long inputDispatchingTimeoutNanos;
77
78 // These are used for determining when all windows associated with
79 // an activity have been drawn, so they can be made visible together
80 // at the same time.
Craig Mautner764983d2012-03-22 11:37:36 -070081 // initialize so that it doesn't match mTransactionSequence which is an int.
82 long lastTransactionSequence = Long.MIN_VALUE;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080083 int numInterestingWindows;
84 int numDrawnWindows;
85 boolean inPendingTransaction;
86 boolean allDrawn;
Craig Mautner7636dfb2012-11-16 15:24:11 -080087 // Set to true when this app creates a surface while in the middle of an animation. In that
88 // case do not clear allDrawn until the animation completes.
89 boolean deferClearAllDrawn;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080090
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080091 // Is this window's surface needed? This is almost like hidden, except
92 // it will sometimes be true a little earlier: when the token has
93 // been shown, but is still waiting for its app transition to execute
94 // before making its windows shown.
95 boolean hiddenRequested;
96
97 // Have we told the window clients to hide themselves?
98 boolean clientHidden;
99
100 // Last visibility state we reported to the app token.
101 boolean reportedVisible;
102
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700103 // Last drawn state we reported to the app token.
104 boolean reportedDrawn;
105
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800106 // Set to true when the token has been removed from the window mgr.
107 boolean removed;
108
Chong Zhang112eb8c2015-11-02 11:17:00 -0800109 boolean appDied;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800110 // Information about an application starting window if displayed.
111 StartingData startingData;
112 WindowState startingWindow;
113 View startingView;
114 boolean startingDisplayed;
115 boolean startingMoved;
116 boolean firstWindowDrawn;
117
118 // Input application handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700119 final InputApplicationHandle mInputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800120
Craig Mautner799bc1d2015-01-14 10:33:48 -0800121 boolean mIsExiting;
Craig Mautner9ef471f2014-02-07 13:11:47 -0800122
Craig Mautnerbb742462014-07-07 15:28:55 -0700123 boolean mLaunchTaskBehind;
Craig Mautner8746a472014-07-24 15:12:54 -0700124 boolean mEnteringAnimation;
Craig Mautnerbb742462014-07-07 15:28:55 -0700125
Wale Ogunwale61b009e2015-09-16 15:43:05 -0700126 // True if the windows associated with this token should be cropped to their stack bounds.
127 boolean mCropWindowsToStack;
128
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800129 boolean mAlwaysFocusable;
130
Jorim Jaggi0429f352015-12-22 16:29:16 +0100131 ArrayDeque<Rect> mFrozenBounds = new ArrayDeque<>();
132
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700133 AppWindowToken(WindowManagerService _service, IApplicationToken _token,
134 boolean _voiceInteraction) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800135 super(_service, _token.asBinder(),
136 WindowManager.LayoutParams.TYPE_APPLICATION, true);
137 appWindowToken = this;
138 appToken = _token;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700139 voiceInteraction = _voiceInteraction;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800140 mInputApplicationHandle = new InputApplicationHandle(this);
Craig Mautner322e4032012-07-13 13:35:20 -0700141 mAppAnimator = new AppWindowAnimator(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800142 }
143
144 void sendAppVisibilityToClients() {
145 final int N = allAppWindows.size();
146 for (int i=0; i<N; i++) {
147 WindowState win = allAppWindows.get(i);
148 if (win == startingWindow && clientHidden) {
149 // Don't hide the starting window.
150 continue;
151 }
152 try {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800153 if (DEBUG_VISIBILITY) Slog.v(TAG,
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800154 "Setting visibility of " + win + ": " + (!clientHidden));
155 win.mClient.dispatchAppVisibility(!clientHidden);
156 } catch (RemoteException e) {
157 }
158 }
159 }
160
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800161 void updateReportedVisibilityLocked() {
162 if (appToken == null) {
163 return;
164 }
165
166 int numInteresting = 0;
167 int numVisible = 0;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700168 int numDrawn = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800169 boolean nowGone = true;
170
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800171 if (DEBUG_VISIBILITY) Slog.v(TAG,
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700172 "Update reported visibility: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800173 final int N = allAppWindows.size();
174 for (int i=0; i<N; i++) {
175 WindowState win = allAppWindows.get(i);
176 if (win == startingWindow || win.mAppFreezing
177 || win.mViewVisibility != View.VISIBLE
178 || win.mAttrs.type == TYPE_APPLICATION_STARTING
179 || win.mDestroying) {
180 continue;
181 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800182 if (DEBUG_VISIBILITY) {
183 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800184 + win.isDrawnLw()
Craig Mautnera2c77052012-03-26 12:14:43 -0700185 + ", isAnimating=" + win.mWinAnimator.isAnimating());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800186 if (!win.isDrawnLw()) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800187 Slog.v(TAG, "Not displayed: s=" +
Robert Carre6a83512015-11-03 16:09:21 -0800188 win.mWinAnimator.mSurfaceController
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800189 + " pv=" + win.mPolicyVisibility
Craig Mautner749a7bb2012-04-02 13:49:53 -0700190 + " mDrawState=" + win.mWinAnimator.mDrawState
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800191 + " ah=" + win.mAttachedHidden
192 + " th="
193 + (win.mAppToken != null
194 ? win.mAppToken.hiddenRequested : false)
Craig Mautnera2c77052012-03-26 12:14:43 -0700195 + " a=" + win.mWinAnimator.mAnimating);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800196 }
197 }
198 numInteresting++;
199 if (win.isDrawnLw()) {
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700200 numDrawn++;
Craig Mautnera2c77052012-03-26 12:14:43 -0700201 if (!win.mWinAnimator.isAnimating()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800202 numVisible++;
203 }
204 nowGone = false;
Craig Mautnera2c77052012-03-26 12:14:43 -0700205 } else if (win.mWinAnimator.isAnimating()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800206 nowGone = false;
207 }
208 }
209
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700210 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800211 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700212 if (!nowGone) {
213 // If the app is not yet gone, then it can only become visible/drawn.
214 if (!nowDrawn) {
215 nowDrawn = reportedDrawn;
216 }
217 if (!nowVisible) {
218 nowVisible = reportedVisible;
219 }
220 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800221 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800222 + numInteresting + " visible=" + numVisible);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700223 if (nowDrawn != reportedDrawn) {
224 if (nowDrawn) {
225 Message m = service.mH.obtainMessage(
226 H.REPORT_APPLICATION_TOKEN_DRAWN, this);
227 service.mH.sendMessage(m);
228 }
229 reportedDrawn = nowDrawn;
230 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800231 if (nowVisible != reportedVisible) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800232 if (DEBUG_VISIBILITY) Slog.v(
233 TAG, "Visibility changed in " + this
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800234 + ": vis=" + nowVisible);
235 reportedVisible = nowVisible;
236 Message m = service.mH.obtainMessage(
237 H.REPORT_APPLICATION_TOKEN_WINDOWS,
238 nowVisible ? 1 : 0,
239 nowGone ? 1 : 0,
240 this);
241 service.mH.sendMessage(m);
242 }
243 }
244
245 WindowState findMainWindow() {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700246 WindowState candidate = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800247 int j = windows.size();
248 while (j > 0) {
249 j--;
250 WindowState win = windows.get(j);
251 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
252 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700253 // In cases where there are multiple windows, we prefer the non-exiting window. This
Sungsoo Lim0d3d1f82015-12-02 14:47:59 +0900254 // happens for example when replacing windows during an activity relaunch. When
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700255 // constructing the animation, we want the new window, not the exiting one.
256 if (win.mExiting) {
257 candidate = win;
258 } else {
259 return win;
260 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800261 }
262 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700263 return candidate;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800264 }
265
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800266 boolean windowsAreFocusable() {
267 return StackId.canReceiveKeys(mTask.mStack.mStackId) || mAlwaysFocusable;
Wale Ogunwaled045c822015-12-02 09:14:28 -0800268 }
269
Craig Mautner72669d12012-12-18 17:23:54 -0800270 boolean isVisible() {
271 final int N = allAppWindows.size();
Craig Mautner72669d12012-12-18 17:23:54 -0800272 for (int i=0; i<N; i++) {
273 WindowState win = allAppWindows.get(i);
Chong Zhangdb20b5f2015-10-23 14:01:43 -0700274 // If we're animating with a saved surface, we're already visible.
275 // Return true so that the alpha doesn't get cleared.
Craig Mautner72669d12012-12-18 17:23:54 -0800276 if (!win.mAppFreezing
Filip Gruszczynski57f76f12015-11-04 16:10:54 -0800277 && (win.mViewVisibility == View.VISIBLE || mAnimatingWithSavedSurface
278 || (win.mWinAnimator.isAnimating()
279 && !service.mAppTransition.isTransitionSet()))
280 && !win.mDestroying
281 && win.isDrawnLw()) {
Craig Mautner72669d12012-12-18 17:23:54 -0800282 return true;
283 }
284 }
285 return false;
286 }
287
Craig Mautnere3119b72015-01-20 15:02:36 -0800288 void removeAppFromTaskLocked() {
289 mIsExiting = false;
290 removeAllWindows();
291
Craig Mautner83162a92015-01-26 14:43:30 -0800292 // Use local variable because removeAppToken will null out mTask.
293 final Task task = mTask;
Craig Mautnere3119b72015-01-20 15:02:36 -0800294 if (task != null) {
295 if (!task.removeAppToken(this)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800296 Slog.e(TAG, "removeAppFromTaskLocked: token=" + this
Craig Mautnere3119b72015-01-20 15:02:36 -0800297 + " not found.");
298 }
299 task.mStack.mExitingAppTokens.remove(this);
300 }
301 }
302
Chong Zhangbef461f2015-10-27 11:38:24 -0700303 /**
304 * Checks whether we should save surfaces for this app.
305 *
306 * @return true if the surfaces should be saved, false otherwise.
307 */
308 boolean shouldSaveSurface() {
309 // We want to save surface if the app's windows are "allDrawn", or if we're
310 // currently animating with save surfaces. (If the app didn't even finish
311 // drawing when the user exits, but we have a saved surface from last time,
312 // we still want to keep that surface.)
Robert Carr13f7be9e2015-12-02 18:39:45 -0800313 return allDrawn || mAnimatingWithSavedSurface;
314 }
315
316 boolean hasSavedSurface() {
317 for (int i = windows.size() -1; i >= 0; i--) {
318 final WindowState ws = windows.get(i);
319 if (ws.hasSavedSurface()) {
320 return true;
321 }
Chong Zhangbef461f2015-10-27 11:38:24 -0700322 }
323 return false;
324 }
325
326 void restoreSavedSurfaces() {
Robert Carr13f7be9e2015-12-02 18:39:45 -0800327 if (!hasSavedSurface()) {
Chong Zhangbef461f2015-10-27 11:38:24 -0700328 return;
329 }
330
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800331 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG_WM,
Chong Zhangbef461f2015-10-27 11:38:24 -0700332 "Restoring saved surfaces: " + this + ", allDrawn=" + allDrawn);
333
Chong Zhangbef461f2015-10-27 11:38:24 -0700334 mAnimatingWithSavedSurface = true;
335 for (int i = windows.size() - 1; i >= 0; i--) {
336 WindowState ws = windows.get(i);
Robert Carr13f7be9e2015-12-02 18:39:45 -0800337 ws.restoreSavedSurface();
Chong Zhangbef461f2015-10-27 11:38:24 -0700338 }
339 }
340
341 void destroySavedSurfaces() {
Robert Carr13f7be9e2015-12-02 18:39:45 -0800342 for (int i = windows.size() - 1; i >= 0; i--) {
343 WindowState win = windows.get(i);
344 win.destroySavedSurface();
Chong Zhangbef461f2015-10-27 11:38:24 -0700345 }
346 }
347
Wale Ogunwale98e70d02014-11-10 12:12:27 -0800348 @Override
Craig Mautner7c9ee192014-08-14 16:08:26 -0700349 void removeAllWindows() {
Craig Mautner7b4655d2014-11-20 12:13:22 -0800350 for (int winNdx = allAppWindows.size() - 1; winNdx >= 0;
351 // removeWindowLocked at bottom of loop may remove multiple entries from
352 // allAppWindows if the window to be removed has child windows. It also may
353 // not remove any windows from allAppWindows at all if win is exiting and
354 // currently animating away. This ensures that winNdx is monotonically decreasing
355 // and never beyond allAppWindows bounds.
356 winNdx = Math.min(winNdx - 1, allAppWindows.size() - 1)) {
357 WindowState win = allAppWindows.get(winNdx);
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800358 if (DEBUG_WINDOW_MOVEMENT) {
359 Slog.w(TAG, "removeAllWindows: removing win=" + win);
Wale Ogunwale98e70d02014-11-10 12:12:27 -0800360 }
361
Wale Ogunwalea6ab5c42015-04-24 09:00:25 -0700362 service.removeWindowLocked(win);
Craig Mautner7c9ee192014-08-14 16:08:26 -0700363 }
Craig Mautnere3119b72015-01-20 15:02:36 -0800364 allAppWindows.clear();
365 windows.clear();
Craig Mautner7c9ee192014-08-14 16:08:26 -0700366 }
367
Chong Zhang112eb8c2015-11-02 11:17:00 -0800368 void removeAllDeadWindows() {
369 for (int winNdx = allAppWindows.size() - 1; winNdx >= 0;
370 // removeWindowLocked at bottom of loop may remove multiple entries from
371 // allAppWindows if the window to be removed has child windows. It also may
372 // not remove any windows from allAppWindows at all if win is exiting and
373 // currently animating away. This ensures that winNdx is monotonically decreasing
374 // and never beyond allAppWindows bounds.
375 winNdx = Math.min(winNdx - 1, allAppWindows.size() - 1)) {
376 WindowState win = allAppWindows.get(winNdx);
377 if (win.mAppDied) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800378 if (DEBUG_WINDOW_MOVEMENT) {
379 Slog.w(TAG, "removeAllDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800380 }
381 // Set mDestroying, we don't want any animation or delayed removal here.
382 win.mDestroying = true;
383 service.removeWindowLocked(win);
384 }
385 }
386 }
387
Robert Carra1eb4392015-12-10 12:43:51 -0800388 void setReplacingWindows(boolean animate) {
389 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + appWindowToken
390 + " with replacing windows.");
391
392 for (int i = allAppWindows.size() - 1; i >= 0; i--) {
393 final WindowState w = allAppWindows.get(i);
394 w.setReplacing(animate);
395 }
396 if (animate) {
397 // Set-up dummy animation so we can start treating windows associated with this
398 // token like they are in transition before the new app window is ready for us to
399 // run the real transition animation.
400 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
401 "setReplacingWindow() Setting dummy animation on: " + this);
402 mAppAnimator.setDummyAnimation();
403 }
404 }
405
406 void addWindow(WindowState w) {
407 for (int i = allAppWindows.size() - 1; i >= 0; i--) {
408 WindowState candidate = allAppWindows.get(i);
409 if (candidate.mWillReplaceWindow && candidate.mReplacingWindow == null &&
410 candidate.getWindowTag().equals(w.getWindowTag().toString())) {
411 candidate.mReplacingWindow = w;
412 }
413 }
414 allAppWindows.add(w);
415 }
416
417 boolean waitingForReplacement() {
418 for (int i = allAppWindows.size() -1; i >= 0; i--) {
419 WindowState candidate = allAppWindows.get(i);
420 if (candidate.mWillReplaceWindow) {
421 return true;
422 }
423 }
424 return false;
425 }
426
427 void clearTimedoutReplaceesLocked() {
428 for (int i = allAppWindows.size() - 1; i >= 0;
429 // removeWindowLocked at bottom of loop may remove multiple entries from
430 // allAppWindows if the window to be removed has child windows. It also may
431 // not remove any windows from allAppWindows at all if win is exiting and
432 // currently animating away. This ensures that winNdx is monotonically decreasing
433 // and never beyond allAppWindows bounds.
434 i = Math.min(i - 1, allAppWindows.size() - 1)) {
435 WindowState candidate = allAppWindows.get(i);
436 if (candidate.mWillReplaceWindow == false) {
437 continue;
438 }
439 candidate.mWillReplaceWindow = false;
440 service.removeWindowLocked(candidate);
441 }
442 }
443
Jorim Jaggi0429f352015-12-22 16:29:16 +0100444 /**
445 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
446 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
447 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
448 * with a queue.
449 */
450 void freezeBounds() {
451 mFrozenBounds.offer(new Rect(mTask.mPreparedFrozenBounds));
452 }
453
454 /**
455 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
456 */
457 void unfreezeBounds() {
458 mFrozenBounds.remove();
459 }
460
Craig Mautnerdbb79912012-03-01 18:59:14 -0800461 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800462 void dump(PrintWriter pw, String prefix) {
463 super.dump(pw, prefix);
464 if (appToken != null) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700465 pw.print(prefix); pw.print("app=true voiceInteraction="); pw.println(voiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800466 }
467 if (allAppWindows.size() > 0) {
468 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
469 }
Craig Mautner83162a92015-01-26 14:43:30 -0800470 pw.print(prefix); pw.print("task="); pw.println(mTask);
471 pw.print(prefix); pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800472 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
473 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
474 pw.print(" clientHidden="); pw.print(clientHidden);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700475 pw.print(" reportedDrawn="); pw.print(reportedDrawn);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800476 pw.print(" reportedVisible="); pw.println(reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -0700477 if (paused) {
478 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800479 }
480 if (numInterestingWindows != 0 || numDrawnWindows != 0
Craig Mautner6fbda632012-07-03 09:26:39 -0700481 || allDrawn || mAppAnimator.allDrawn) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800482 pw.print(prefix); pw.print("numInterestingWindows=");
483 pw.print(numInterestingWindows);
484 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
485 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -0700486 pw.print(" allDrawn="); pw.print(allDrawn);
487 pw.print(" (animator="); pw.print(mAppAnimator.allDrawn);
488 pw.println(")");
489 }
490 if (inPendingTransaction) {
491 pw.print(prefix); pw.print("inPendingTransaction=");
492 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800493 }
Craig Mautner799bc1d2015-01-14 10:33:48 -0800494 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800495 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
496 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -0800497 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -0800498 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800499 }
500 if (startingWindow != null || startingView != null
501 || startingDisplayed || startingMoved) {
502 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
503 pw.print(" startingView="); pw.print(startingView);
504 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
505 pw.print(" startingMoved"); pw.println(startingMoved);
506 }
Jorim Jaggi0429f352015-12-22 16:29:16 +0100507 if (!mFrozenBounds.isEmpty()) {
508 pw.print(prefix); pw.print("mFrozenBounds="); pw.print(mFrozenBounds);
509 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800510 }
511
512 @Override
513 public String toString() {
514 if (stringName == null) {
515 StringBuilder sb = new StringBuilder();
516 sb.append("AppWindowToken{");
517 sb.append(Integer.toHexString(System.identityHashCode(this)));
518 sb.append(" token="); sb.append(token); sb.append('}');
519 stringName = sb.toString();
520 }
521 return stringName;
522 }
Jeff Browne9bdb312012-04-05 15:30:10 -0700523}