blob: 7ec945d74e52ae6fadf647b17f273659bea39702 [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;
Chong Zhangf596cd52016-01-05 13:42:44 -080028import static com.android.server.wm.WindowManagerService.WINDOW_REPLACEMENT_TIMEOUT_DURATION;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080029
Jeff Brown4532e612012-04-05 14:27:12 -070030import com.android.server.input.InputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080031import com.android.server.wm.WindowManagerService.H;
32
Filip Gruszczynskia590c992015-11-25 16:45:26 -080033import android.annotation.NonNull;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080034import android.content.pm.ActivityInfo;
Jorim Jaggi0429f352015-12-22 16:29:16 +010035import android.graphics.Rect;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080036import android.os.Message;
37import android.os.RemoteException;
38import android.util.Slog;
39import android.view.IApplicationToken;
40import android.view.View;
41import android.view.WindowManager;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080042
43import java.io.PrintWriter;
Jorim Jaggi0429f352015-12-22 16:29:16 +010044import java.util.ArrayDeque;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080045import java.util.ArrayList;
46
47class AppTokenList extends ArrayList<AppWindowToken> {
48}
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080049
50/**
51 * Version of WindowToken that is specifically for a particular application (or
52 * really activity) that is displaying windows.
53 */
Craig Mautnere32c3072012-03-12 15:25:35 -070054class AppWindowToken extends WindowToken {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080055 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppWindowToken" : TAG_WM;
56
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080057 // Non-null only for application tokens.
58 final IApplicationToken appToken;
59
60 // All of the windows and child windows that are included in this
61 // application token. Note this list is NOT sorted!
Craig Mautner96868332012-12-04 14:29:11 -080062 final WindowList allAppWindows = new WindowList();
Filip Gruszczynskia590c992015-11-25 16:45:26 -080063 @NonNull final AppWindowAnimator mAppAnimator;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -070064
Dianne Hackborne30e02f2014-05-27 18:24:45 -070065 final boolean voiceInteraction;
66
Chong Zhangdb20b5f2015-10-23 14:01:43 -070067 // Whether we're performing an entering animation with a saved surface.
68 boolean mAnimatingWithSavedSurface;
69
Jorim Jaggi4846ee32016-01-07 17:39:12 +010070
Craig Mautner83162a92015-01-26 14:43:30 -080071 Task mTask;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080072 boolean appFullscreen;
73 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Craig Mautner4c5eb222013-11-18 12:59:05 -080074 boolean layoutConfigChanges;
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -070075 boolean showForAllUsers;
Craig Mautnera2c77052012-03-26 12:14:43 -070076
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080077 // The input dispatching timeout for this application token in nanoseconds.
78 long inputDispatchingTimeoutNanos;
79
80 // These are used for determining when all windows associated with
81 // an activity have been drawn, so they can be made visible together
82 // at the same time.
Craig Mautner764983d2012-03-22 11:37:36 -070083 // initialize so that it doesn't match mTransactionSequence which is an int.
84 long lastTransactionSequence = Long.MIN_VALUE;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080085 int numInterestingWindows;
86 int numDrawnWindows;
87 boolean inPendingTransaction;
88 boolean allDrawn;
Craig Mautner7636dfb2012-11-16 15:24:11 -080089 // Set to true when this app creates a surface while in the middle of an animation. In that
90 // case do not clear allDrawn until the animation completes.
91 boolean deferClearAllDrawn;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080092
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080093 // Is this window's surface needed? This is almost like hidden, except
94 // it will sometimes be true a little earlier: when the token has
95 // been shown, but is still waiting for its app transition to execute
96 // before making its windows shown.
97 boolean hiddenRequested;
98
99 // Have we told the window clients to hide themselves?
100 boolean clientHidden;
101
102 // Last visibility state we reported to the app token.
103 boolean reportedVisible;
104
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700105 // Last drawn state we reported to the app token.
106 boolean reportedDrawn;
107
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800108 // Set to true when the token has been removed from the window mgr.
109 boolean removed;
110
Chong Zhang112eb8c2015-11-02 11:17:00 -0800111 boolean appDied;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800112 // Information about an application starting window if displayed.
113 StartingData startingData;
114 WindowState startingWindow;
115 View startingView;
116 boolean startingDisplayed;
117 boolean startingMoved;
118 boolean firstWindowDrawn;
119
120 // Input application handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700121 final InputApplicationHandle mInputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800122
Craig Mautner799bc1d2015-01-14 10:33:48 -0800123 boolean mIsExiting;
Craig Mautner9ef471f2014-02-07 13:11:47 -0800124
Craig Mautnerbb742462014-07-07 15:28:55 -0700125 boolean mLaunchTaskBehind;
Craig Mautner8746a472014-07-24 15:12:54 -0700126 boolean mEnteringAnimation;
Craig Mautnerbb742462014-07-07 15:28:55 -0700127
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800128 boolean mAlwaysFocusable;
129
Jorim Jaggi0429f352015-12-22 16:29:16 +0100130 ArrayDeque<Rect> mFrozenBounds = new ArrayDeque<>();
131
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700132 AppWindowToken(WindowManagerService _service, IApplicationToken _token,
133 boolean _voiceInteraction) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800134 super(_service, _token.asBinder(),
135 WindowManager.LayoutParams.TYPE_APPLICATION, true);
136 appWindowToken = this;
137 appToken = _token;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700138 voiceInteraction = _voiceInteraction;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800139 mInputApplicationHandle = new InputApplicationHandle(this);
Craig Mautner322e4032012-07-13 13:35:20 -0700140 mAppAnimator = new AppWindowAnimator(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800141 }
142
143 void sendAppVisibilityToClients() {
144 final int N = allAppWindows.size();
145 for (int i=0; i<N; i++) {
146 WindowState win = allAppWindows.get(i);
147 if (win == startingWindow && clientHidden) {
148 // Don't hide the starting window.
149 continue;
150 }
151 try {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800152 if (DEBUG_VISIBILITY) Slog.v(TAG,
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800153 "Setting visibility of " + win + ": " + (!clientHidden));
154 win.mClient.dispatchAppVisibility(!clientHidden);
155 } catch (RemoteException e) {
156 }
157 }
158 }
159
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800160 void updateReportedVisibilityLocked() {
161 if (appToken == null) {
162 return;
163 }
164
165 int numInteresting = 0;
166 int numVisible = 0;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700167 int numDrawn = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800168 boolean nowGone = true;
169
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800170 if (DEBUG_VISIBILITY) Slog.v(TAG,
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700171 "Update reported visibility: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800172 final int N = allAppWindows.size();
173 for (int i=0; i<N; i++) {
174 WindowState win = allAppWindows.get(i);
175 if (win == startingWindow || win.mAppFreezing
176 || win.mViewVisibility != View.VISIBLE
177 || win.mAttrs.type == TYPE_APPLICATION_STARTING
178 || win.mDestroying) {
179 continue;
180 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800181 if (DEBUG_VISIBILITY) {
182 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800183 + win.isDrawnLw()
Craig Mautnera2c77052012-03-26 12:14:43 -0700184 + ", isAnimating=" + win.mWinAnimator.isAnimating());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800185 if (!win.isDrawnLw()) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800186 Slog.v(TAG, "Not displayed: s=" +
Robert Carre6a83512015-11-03 16:09:21 -0800187 win.mWinAnimator.mSurfaceController
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800188 + " pv=" + win.mPolicyVisibility
Craig Mautner749a7bb2012-04-02 13:49:53 -0700189 + " mDrawState=" + win.mWinAnimator.mDrawState
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800190 + " ah=" + win.mAttachedHidden
191 + " th="
192 + (win.mAppToken != null
193 ? win.mAppToken.hiddenRequested : false)
Craig Mautnera2c77052012-03-26 12:14:43 -0700194 + " a=" + win.mWinAnimator.mAnimating);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800195 }
196 }
197 numInteresting++;
198 if (win.isDrawnLw()) {
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700199 numDrawn++;
Craig Mautnera2c77052012-03-26 12:14:43 -0700200 if (!win.mWinAnimator.isAnimating()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800201 numVisible++;
202 }
203 nowGone = false;
Craig Mautnera2c77052012-03-26 12:14:43 -0700204 } else if (win.mWinAnimator.isAnimating()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800205 nowGone = false;
206 }
207 }
208
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700209 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800210 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700211 if (!nowGone) {
212 // If the app is not yet gone, then it can only become visible/drawn.
213 if (!nowDrawn) {
214 nowDrawn = reportedDrawn;
215 }
216 if (!nowVisible) {
217 nowVisible = reportedVisible;
218 }
219 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800220 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800221 + numInteresting + " visible=" + numVisible);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700222 if (nowDrawn != reportedDrawn) {
223 if (nowDrawn) {
224 Message m = service.mH.obtainMessage(
225 H.REPORT_APPLICATION_TOKEN_DRAWN, this);
226 service.mH.sendMessage(m);
227 }
228 reportedDrawn = nowDrawn;
229 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800230 if (nowVisible != reportedVisible) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800231 if (DEBUG_VISIBILITY) Slog.v(
232 TAG, "Visibility changed in " + this
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800233 + ": vis=" + nowVisible);
234 reportedVisible = nowVisible;
235 Message m = service.mH.obtainMessage(
236 H.REPORT_APPLICATION_TOKEN_WINDOWS,
237 nowVisible ? 1 : 0,
238 nowGone ? 1 : 0,
239 this);
240 service.mH.sendMessage(m);
241 }
242 }
243
244 WindowState findMainWindow() {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700245 WindowState candidate = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800246 int j = windows.size();
247 while (j > 0) {
248 j--;
249 WindowState win = windows.get(j);
250 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
251 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700252 // In cases where there are multiple windows, we prefer the non-exiting window. This
Sungsoo Lim0d3d1f82015-12-02 14:47:59 +0900253 // happens for example when replacing windows during an activity relaunch. When
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700254 // constructing the animation, we want the new window, not the exiting one.
255 if (win.mExiting) {
256 candidate = win;
257 } else {
258 return win;
259 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800260 }
261 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700262 return candidate;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800263 }
264
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800265 boolean windowsAreFocusable() {
266 return StackId.canReceiveKeys(mTask.mStack.mStackId) || mAlwaysFocusable;
Wale Ogunwaled045c822015-12-02 09:14:28 -0800267 }
268
Craig Mautner72669d12012-12-18 17:23:54 -0800269 boolean isVisible() {
270 final int N = allAppWindows.size();
Craig Mautner72669d12012-12-18 17:23:54 -0800271 for (int i=0; i<N; i++) {
272 WindowState win = allAppWindows.get(i);
Chong Zhangdb20b5f2015-10-23 14:01:43 -0700273 // If we're animating with a saved surface, we're already visible.
274 // Return true so that the alpha doesn't get cleared.
Craig Mautner72669d12012-12-18 17:23:54 -0800275 if (!win.mAppFreezing
Filip Gruszczynski57f76f12015-11-04 16:10:54 -0800276 && (win.mViewVisibility == View.VISIBLE || mAnimatingWithSavedSurface
277 || (win.mWinAnimator.isAnimating()
278 && !service.mAppTransition.isTransitionSet()))
279 && !win.mDestroying
280 && win.isDrawnLw()) {
Craig Mautner72669d12012-12-18 17:23:54 -0800281 return true;
282 }
283 }
284 return false;
285 }
286
Craig Mautnere3119b72015-01-20 15:02:36 -0800287 void removeAppFromTaskLocked() {
288 mIsExiting = false;
289 removeAllWindows();
290
Craig Mautner83162a92015-01-26 14:43:30 -0800291 // Use local variable because removeAppToken will null out mTask.
292 final Task task = mTask;
Craig Mautnere3119b72015-01-20 15:02:36 -0800293 if (task != null) {
294 if (!task.removeAppToken(this)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800295 Slog.e(TAG, "removeAppFromTaskLocked: token=" + this
Craig Mautnere3119b72015-01-20 15:02:36 -0800296 + " not found.");
297 }
298 task.mStack.mExitingAppTokens.remove(this);
299 }
300 }
301
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800302 void setWindowsExiting(boolean exiting) {
Chong Zhangeb22e8e2016-01-20 19:52:22 -0800303 for (int i = allAppWindows.size() - 1; i >= 0; i--) {
304 WindowState win = allAppWindows.get(i);
Chong Zhang6bb82502016-02-02 14:13:48 -0800305 // If the app already requested to remove its window, we don't modify
306 // its exiting state. Otherwise the stale window won't get removed on
307 // exit and could cause focus to be given to the wrong window.
308 if (!(win.mRemoveOnExit && win.mExiting)) {
309 win.mExiting = exiting;
310 }
Chong Zhangeb22e8e2016-01-20 19:52:22 -0800311 }
312 }
313
Chong Zhangbef461f2015-10-27 11:38:24 -0700314 /**
315 * Checks whether we should save surfaces for this app.
316 *
317 * @return true if the surfaces should be saved, false otherwise.
318 */
319 boolean shouldSaveSurface() {
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800320 // We want to save surface if the app's windows are "allDrawn".
321 // (If we started entering animation early with saved surfaces, allDrawn
322 // should have been restored to true. So we'll save again in that case
323 // even if app didn't actually finish drawing.)
324 return allDrawn;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800325 }
326
327 boolean hasSavedSurface() {
328 for (int i = windows.size() -1; i >= 0; i--) {
329 final WindowState ws = windows.get(i);
330 if (ws.hasSavedSurface()) {
331 return true;
332 }
Chong Zhangbef461f2015-10-27 11:38:24 -0700333 }
334 return false;
335 }
336
337 void restoreSavedSurfaces() {
Robert Carr13f7be9e2015-12-02 18:39:45 -0800338 if (!hasSavedSurface()) {
Chong Zhangbef461f2015-10-27 11:38:24 -0700339 return;
340 }
Chong Zhangbef461f2015-10-27 11:38:24 -0700341 mAnimatingWithSavedSurface = true;
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800342
343 // Check if we have enough drawn windows to mark allDrawn= true.
344 int numInteresting = 0;
345 int numDrawn = 0;
Chong Zhangbef461f2015-10-27 11:38:24 -0700346 for (int i = windows.size() - 1; i >= 0; i--) {
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800347 WindowState w = windows.get(i);
348 w.restoreSavedSurface();
349 if (w != startingWindow && !w.mAppDied
350 && (!mAppAnimator.freezingScreen || !w.mAppFreezing)) {
351 numInteresting++;
352 if (w.isDrawnLw()) {
353 numDrawn++;
354 }
355 }
Chong Zhangbef461f2015-10-27 11:38:24 -0700356 }
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800357
358 allDrawn |= (numInteresting == numDrawn);
359
360 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG,
361 "restoreSavedSurfaces: " + appWindowToken + " allDrawn=" + allDrawn);
Chong Zhangbef461f2015-10-27 11:38:24 -0700362 }
363
364 void destroySavedSurfaces() {
Robert Carr13f7be9e2015-12-02 18:39:45 -0800365 for (int i = windows.size() - 1; i >= 0; i--) {
366 WindowState win = windows.get(i);
367 win.destroySavedSurface();
Chong Zhangbef461f2015-10-27 11:38:24 -0700368 }
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800369 mAnimatingWithSavedSurface = false;
Chong Zhangbef461f2015-10-27 11:38:24 -0700370 }
371
Wale Ogunwale98e70d02014-11-10 12:12:27 -0800372 @Override
Craig Mautner7c9ee192014-08-14 16:08:26 -0700373 void removeAllWindows() {
Craig Mautner7b4655d2014-11-20 12:13:22 -0800374 for (int winNdx = allAppWindows.size() - 1; winNdx >= 0;
375 // removeWindowLocked at bottom of loop may remove multiple entries from
376 // allAppWindows if the window to be removed has child windows. It also may
377 // not remove any windows from allAppWindows at all if win is exiting and
378 // currently animating away. This ensures that winNdx is monotonically decreasing
379 // and never beyond allAppWindows bounds.
380 winNdx = Math.min(winNdx - 1, allAppWindows.size() - 1)) {
381 WindowState win = allAppWindows.get(winNdx);
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800382 if (DEBUG_WINDOW_MOVEMENT) {
383 Slog.w(TAG, "removeAllWindows: removing win=" + win);
Wale Ogunwale98e70d02014-11-10 12:12:27 -0800384 }
385
Wale Ogunwalea6ab5c42015-04-24 09:00:25 -0700386 service.removeWindowLocked(win);
Craig Mautner7c9ee192014-08-14 16:08:26 -0700387 }
Craig Mautnere3119b72015-01-20 15:02:36 -0800388 allAppWindows.clear();
389 windows.clear();
Craig Mautner7c9ee192014-08-14 16:08:26 -0700390 }
391
Chong Zhang112eb8c2015-11-02 11:17:00 -0800392 void removeAllDeadWindows() {
393 for (int winNdx = allAppWindows.size() - 1; winNdx >= 0;
394 // removeWindowLocked at bottom of loop may remove multiple entries from
395 // allAppWindows if the window to be removed has child windows. It also may
396 // not remove any windows from allAppWindows at all if win is exiting and
397 // currently animating away. This ensures that winNdx is monotonically decreasing
398 // and never beyond allAppWindows bounds.
399 winNdx = Math.min(winNdx - 1, allAppWindows.size() - 1)) {
400 WindowState win = allAppWindows.get(winNdx);
401 if (win.mAppDied) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800402 if (DEBUG_WINDOW_MOVEMENT) {
403 Slog.w(TAG, "removeAllDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800404 }
405 // Set mDestroying, we don't want any animation or delayed removal here.
406 win.mDestroying = true;
407 service.removeWindowLocked(win);
408 }
409 }
410 }
411
Robert Carra1eb4392015-12-10 12:43:51 -0800412 void setReplacingWindows(boolean animate) {
413 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + appWindowToken
414 + " with replacing windows.");
415
416 for (int i = allAppWindows.size() - 1; i >= 0; i--) {
417 final WindowState w = allAppWindows.get(i);
418 w.setReplacing(animate);
419 }
420 if (animate) {
421 // Set-up dummy animation so we can start treating windows associated with this
422 // token like they are in transition before the new app window is ready for us to
423 // run the real transition animation.
424 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
425 "setReplacingWindow() Setting dummy animation on: " + this);
426 mAppAnimator.setDummyAnimation();
427 }
428 }
429
Robert Carr23fa16b2016-01-13 13:19:58 -0800430 void setReplacingChildren() {
431 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + appWindowToken
432 + " with replacing child windows.");
433 for (int i = allAppWindows.size() - 1; i >= 0; i--) {
434 final WindowState w = allAppWindows.get(i);
435 if (w.isChildWindow()) {
436 w.setReplacing(false /* animate */);
437 }
438 }
439 }
440
Chong Zhangf596cd52016-01-05 13:42:44 -0800441 void resetReplacingWindows() {
442 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Resetting app token " + appWindowToken
443 + " of replacing window marks.");
444
445 for (int i = allAppWindows.size() - 1; i >= 0; i--) {
446 final WindowState w = allAppWindows.get(i);
447 w.resetReplacing();
448 }
449 }
450
Robert Carra1eb4392015-12-10 12:43:51 -0800451 void addWindow(WindowState w) {
452 for (int i = allAppWindows.size() - 1; i >= 0; i--) {
453 WindowState candidate = allAppWindows.get(i);
454 if (candidate.mWillReplaceWindow && candidate.mReplacingWindow == null &&
455 candidate.getWindowTag().equals(w.getWindowTag().toString())) {
456 candidate.mReplacingWindow = w;
Chong Zhangf596cd52016-01-05 13:42:44 -0800457
458 // if we got a replacement window, reset the timeout to give drawing more time
459 service.mH.removeMessages(H.WINDOW_REPLACEMENT_TIMEOUT);
460 service.mH.sendMessageDelayed(
461 service.mH.obtainMessage(H.WINDOW_REPLACEMENT_TIMEOUT, this),
462 WINDOW_REPLACEMENT_TIMEOUT_DURATION);
Robert Carra1eb4392015-12-10 12:43:51 -0800463 }
464 }
465 allAppWindows.add(w);
466 }
467
468 boolean waitingForReplacement() {
469 for (int i = allAppWindows.size() -1; i >= 0; i--) {
470 WindowState candidate = allAppWindows.get(i);
471 if (candidate.mWillReplaceWindow) {
472 return true;
473 }
474 }
475 return false;
476 }
477
Chong Zhangf596cd52016-01-05 13:42:44 -0800478 void clearTimedoutReplacesLocked() {
Robert Carra1eb4392015-12-10 12:43:51 -0800479 for (int i = allAppWindows.size() - 1; i >= 0;
480 // removeWindowLocked at bottom of loop may remove multiple entries from
481 // allAppWindows if the window to be removed has child windows. It also may
482 // not remove any windows from allAppWindows at all if win is exiting and
483 // currently animating away. This ensures that winNdx is monotonically decreasing
484 // and never beyond allAppWindows bounds.
485 i = Math.min(i - 1, allAppWindows.size() - 1)) {
486 WindowState candidate = allAppWindows.get(i);
487 if (candidate.mWillReplaceWindow == false) {
488 continue;
489 }
490 candidate.mWillReplaceWindow = false;
Chong Zhangf596cd52016-01-05 13:42:44 -0800491 // Since the window already timed out, remove it immediately now.
492 // Use removeWindowInnerLocked() instead of removeWindowLocked(), as the latter
493 // delays removal on certain conditions, which will leave the stale window in the
494 // stack and marked mWillReplaceWindow=false, so the window will never be removed.
495 service.removeWindowInnerLocked(candidate);
Robert Carra1eb4392015-12-10 12:43:51 -0800496 }
497 }
498
Jorim Jaggi0429f352015-12-22 16:29:16 +0100499 /**
500 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
501 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
502 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
503 * with a queue.
504 */
505 void freezeBounds() {
506 mFrozenBounds.offer(new Rect(mTask.mPreparedFrozenBounds));
507 }
508
509 /**
510 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
511 */
512 void unfreezeBounds() {
513 mFrozenBounds.remove();
Jorim Jaggi4846ee32016-01-07 17:39:12 +0100514 for (int i = windows.size() - 1; i >= 0; i--) {
515 final WindowState win = windows.get(i);
516 win.mLayoutNeeded = true;
517 win.setDisplayLayoutNeeded();
518 if (!service.mResizingWindows.contains(win)) {
519 service.mResizingWindows.add(win);
520 }
521 }
522 service.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100523 }
524
Craig Mautnerdbb79912012-03-01 18:59:14 -0800525 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800526 void dump(PrintWriter pw, String prefix) {
527 super.dump(pw, prefix);
528 if (appToken != null) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700529 pw.print(prefix); pw.print("app=true voiceInteraction="); pw.println(voiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800530 }
531 if (allAppWindows.size() > 0) {
532 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
533 }
Craig Mautner83162a92015-01-26 14:43:30 -0800534 pw.print(prefix); pw.print("task="); pw.println(mTask);
535 pw.print(prefix); pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800536 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
537 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
538 pw.print(" clientHidden="); pw.print(clientHidden);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700539 pw.print(" reportedDrawn="); pw.print(reportedDrawn);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800540 pw.print(" reportedVisible="); pw.println(reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -0700541 if (paused) {
542 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800543 }
544 if (numInterestingWindows != 0 || numDrawnWindows != 0
Craig Mautner6fbda632012-07-03 09:26:39 -0700545 || allDrawn || mAppAnimator.allDrawn) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800546 pw.print(prefix); pw.print("numInterestingWindows=");
547 pw.print(numInterestingWindows);
548 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
549 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -0700550 pw.print(" allDrawn="); pw.print(allDrawn);
551 pw.print(" (animator="); pw.print(mAppAnimator.allDrawn);
552 pw.println(")");
553 }
554 if (inPendingTransaction) {
555 pw.print(prefix); pw.print("inPendingTransaction=");
556 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800557 }
Craig Mautner799bc1d2015-01-14 10:33:48 -0800558 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800559 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
560 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -0800561 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -0800562 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800563 }
564 if (startingWindow != null || startingView != null
565 || startingDisplayed || startingMoved) {
566 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
567 pw.print(" startingView="); pw.print(startingView);
568 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
569 pw.print(" startingMoved"); pw.println(startingMoved);
570 }
Jorim Jaggi0429f352015-12-22 16:29:16 +0100571 if (!mFrozenBounds.isEmpty()) {
572 pw.print(prefix); pw.print("mFrozenBounds="); pw.print(mFrozenBounds);
573 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800574 }
575
576 @Override
577 public String toString() {
578 if (stringName == null) {
579 StringBuilder sb = new StringBuilder();
580 sb.append("AppWindowToken{");
581 sb.append(Integer.toHexString(System.identityHashCode(this)));
582 sb.append(" token="); sb.append(token); sb.append('}');
583 stringName = sb.toString();
584 }
585 return stringName;
586 }
Jeff Browne9bdb312012-04-05 15:30:10 -0700587}