blob: 4624078355db17b8f6b9b0b0d0acb3536d81698b [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 Ogunwale61b009e2015-09-16 15:43:05 -0700128 // True if the windows associated with this token should be cropped to their stack bounds.
129 boolean mCropWindowsToStack;
130
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800131 boolean mAlwaysFocusable;
132
Jorim Jaggi0429f352015-12-22 16:29:16 +0100133 ArrayDeque<Rect> mFrozenBounds = new ArrayDeque<>();
134
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700135 AppWindowToken(WindowManagerService _service, IApplicationToken _token,
136 boolean _voiceInteraction) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800137 super(_service, _token.asBinder(),
138 WindowManager.LayoutParams.TYPE_APPLICATION, true);
139 appWindowToken = this;
140 appToken = _token;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700141 voiceInteraction = _voiceInteraction;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800142 mInputApplicationHandle = new InputApplicationHandle(this);
Craig Mautner322e4032012-07-13 13:35:20 -0700143 mAppAnimator = new AppWindowAnimator(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800144 }
145
146 void sendAppVisibilityToClients() {
147 final int N = allAppWindows.size();
148 for (int i=0; i<N; i++) {
149 WindowState win = allAppWindows.get(i);
150 if (win == startingWindow && clientHidden) {
151 // Don't hide the starting window.
152 continue;
153 }
154 try {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800155 if (DEBUG_VISIBILITY) Slog.v(TAG,
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800156 "Setting visibility of " + win + ": " + (!clientHidden));
157 win.mClient.dispatchAppVisibility(!clientHidden);
158 } catch (RemoteException e) {
159 }
160 }
161 }
162
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800163 void updateReportedVisibilityLocked() {
164 if (appToken == null) {
165 return;
166 }
167
168 int numInteresting = 0;
169 int numVisible = 0;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700170 int numDrawn = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800171 boolean nowGone = true;
172
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800173 if (DEBUG_VISIBILITY) Slog.v(TAG,
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700174 "Update reported visibility: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800175 final int N = allAppWindows.size();
176 for (int i=0; i<N; i++) {
177 WindowState win = allAppWindows.get(i);
178 if (win == startingWindow || win.mAppFreezing
179 || win.mViewVisibility != View.VISIBLE
180 || win.mAttrs.type == TYPE_APPLICATION_STARTING
181 || win.mDestroying) {
182 continue;
183 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800184 if (DEBUG_VISIBILITY) {
185 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800186 + win.isDrawnLw()
Craig Mautnera2c77052012-03-26 12:14:43 -0700187 + ", isAnimating=" + win.mWinAnimator.isAnimating());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800188 if (!win.isDrawnLw()) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800189 Slog.v(TAG, "Not displayed: s=" +
Robert Carre6a83512015-11-03 16:09:21 -0800190 win.mWinAnimator.mSurfaceController
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800191 + " pv=" + win.mPolicyVisibility
Craig Mautner749a7bb2012-04-02 13:49:53 -0700192 + " mDrawState=" + win.mWinAnimator.mDrawState
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800193 + " ah=" + win.mAttachedHidden
194 + " th="
195 + (win.mAppToken != null
196 ? win.mAppToken.hiddenRequested : false)
Craig Mautnera2c77052012-03-26 12:14:43 -0700197 + " a=" + win.mWinAnimator.mAnimating);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800198 }
199 }
200 numInteresting++;
201 if (win.isDrawnLw()) {
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700202 numDrawn++;
Craig Mautnera2c77052012-03-26 12:14:43 -0700203 if (!win.mWinAnimator.isAnimating()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800204 numVisible++;
205 }
206 nowGone = false;
Craig Mautnera2c77052012-03-26 12:14:43 -0700207 } else if (win.mWinAnimator.isAnimating()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800208 nowGone = false;
209 }
210 }
211
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700212 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800213 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700214 if (!nowGone) {
215 // If the app is not yet gone, then it can only become visible/drawn.
216 if (!nowDrawn) {
217 nowDrawn = reportedDrawn;
218 }
219 if (!nowVisible) {
220 nowVisible = reportedVisible;
221 }
222 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800223 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800224 + numInteresting + " visible=" + numVisible);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700225 if (nowDrawn != reportedDrawn) {
226 if (nowDrawn) {
227 Message m = service.mH.obtainMessage(
228 H.REPORT_APPLICATION_TOKEN_DRAWN, this);
229 service.mH.sendMessage(m);
230 }
231 reportedDrawn = nowDrawn;
232 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800233 if (nowVisible != reportedVisible) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800234 if (DEBUG_VISIBILITY) Slog.v(
235 TAG, "Visibility changed in " + this
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800236 + ": vis=" + nowVisible);
237 reportedVisible = nowVisible;
238 Message m = service.mH.obtainMessage(
239 H.REPORT_APPLICATION_TOKEN_WINDOWS,
240 nowVisible ? 1 : 0,
241 nowGone ? 1 : 0,
242 this);
243 service.mH.sendMessage(m);
244 }
245 }
246
247 WindowState findMainWindow() {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700248 WindowState candidate = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800249 int j = windows.size();
250 while (j > 0) {
251 j--;
252 WindowState win = windows.get(j);
253 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
254 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700255 // In cases where there are multiple windows, we prefer the non-exiting window. This
Sungsoo Lim0d3d1f82015-12-02 14:47:59 +0900256 // happens for example when replacing windows during an activity relaunch. When
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700257 // constructing the animation, we want the new window, not the exiting one.
258 if (win.mExiting) {
259 candidate = win;
260 } else {
261 return win;
262 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800263 }
264 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700265 return candidate;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800266 }
267
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800268 boolean windowsAreFocusable() {
269 return StackId.canReceiveKeys(mTask.mStack.mStackId) || mAlwaysFocusable;
Wale Ogunwaled045c822015-12-02 09:14:28 -0800270 }
271
Craig Mautner72669d12012-12-18 17:23:54 -0800272 boolean isVisible() {
273 final int N = allAppWindows.size();
Craig Mautner72669d12012-12-18 17:23:54 -0800274 for (int i=0; i<N; i++) {
275 WindowState win = allAppWindows.get(i);
Chong Zhangdb20b5f2015-10-23 14:01:43 -0700276 // If we're animating with a saved surface, we're already visible.
277 // Return true so that the alpha doesn't get cleared.
Craig Mautner72669d12012-12-18 17:23:54 -0800278 if (!win.mAppFreezing
Filip Gruszczynski57f76f12015-11-04 16:10:54 -0800279 && (win.mViewVisibility == View.VISIBLE || mAnimatingWithSavedSurface
280 || (win.mWinAnimator.isAnimating()
281 && !service.mAppTransition.isTransitionSet()))
282 && !win.mDestroying
283 && win.isDrawnLw()) {
Craig Mautner72669d12012-12-18 17:23:54 -0800284 return true;
285 }
286 }
287 return false;
288 }
289
Craig Mautnere3119b72015-01-20 15:02:36 -0800290 void removeAppFromTaskLocked() {
291 mIsExiting = false;
292 removeAllWindows();
293
Craig Mautner83162a92015-01-26 14:43:30 -0800294 // Use local variable because removeAppToken will null out mTask.
295 final Task task = mTask;
Craig Mautnere3119b72015-01-20 15:02:36 -0800296 if (task != null) {
297 if (!task.removeAppToken(this)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800298 Slog.e(TAG, "removeAppFromTaskLocked: token=" + this
Craig Mautnere3119b72015-01-20 15:02:36 -0800299 + " not found.");
300 }
301 task.mStack.mExitingAppTokens.remove(this);
302 }
303 }
304
Chong Zhangbef461f2015-10-27 11:38:24 -0700305 /**
306 * Checks whether we should save surfaces for this app.
307 *
308 * @return true if the surfaces should be saved, false otherwise.
309 */
310 boolean shouldSaveSurface() {
311 // We want to save surface if the app's windows are "allDrawn", or if we're
312 // currently animating with save surfaces. (If the app didn't even finish
313 // drawing when the user exits, but we have a saved surface from last time,
314 // we still want to keep that surface.)
Robert Carr13f7be9e2015-12-02 18:39:45 -0800315 return allDrawn || mAnimatingWithSavedSurface;
316 }
317
318 boolean hasSavedSurface() {
319 for (int i = windows.size() -1; i >= 0; i--) {
320 final WindowState ws = windows.get(i);
321 if (ws.hasSavedSurface()) {
322 return true;
323 }
Chong Zhangbef461f2015-10-27 11:38:24 -0700324 }
325 return false;
326 }
327
328 void restoreSavedSurfaces() {
Robert Carr13f7be9e2015-12-02 18:39:45 -0800329 if (!hasSavedSurface()) {
Chong Zhangbef461f2015-10-27 11:38:24 -0700330 return;
331 }
332
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800333 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG_WM,
Chong Zhangbef461f2015-10-27 11:38:24 -0700334 "Restoring saved surfaces: " + this + ", allDrawn=" + allDrawn);
335
Chong Zhangbef461f2015-10-27 11:38:24 -0700336 mAnimatingWithSavedSurface = true;
337 for (int i = windows.size() - 1; i >= 0; i--) {
338 WindowState ws = windows.get(i);
Robert Carr13f7be9e2015-12-02 18:39:45 -0800339 ws.restoreSavedSurface();
Chong Zhangbef461f2015-10-27 11:38:24 -0700340 }
341 }
342
343 void destroySavedSurfaces() {
Robert Carr13f7be9e2015-12-02 18:39:45 -0800344 for (int i = windows.size() - 1; i >= 0; i--) {
345 WindowState win = windows.get(i);
346 win.destroySavedSurface();
Chong Zhangbef461f2015-10-27 11:38:24 -0700347 }
348 }
349
Wale Ogunwale98e70d02014-11-10 12:12:27 -0800350 @Override
Craig Mautner7c9ee192014-08-14 16:08:26 -0700351 void removeAllWindows() {
Craig Mautner7b4655d2014-11-20 12:13:22 -0800352 for (int winNdx = allAppWindows.size() - 1; winNdx >= 0;
353 // removeWindowLocked at bottom of loop may remove multiple entries from
354 // allAppWindows if the window to be removed has child windows. It also may
355 // not remove any windows from allAppWindows at all if win is exiting and
356 // currently animating away. This ensures that winNdx is monotonically decreasing
357 // and never beyond allAppWindows bounds.
358 winNdx = Math.min(winNdx - 1, allAppWindows.size() - 1)) {
359 WindowState win = allAppWindows.get(winNdx);
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800360 if (DEBUG_WINDOW_MOVEMENT) {
361 Slog.w(TAG, "removeAllWindows: removing win=" + win);
Wale Ogunwale98e70d02014-11-10 12:12:27 -0800362 }
363
Wale Ogunwalea6ab5c42015-04-24 09:00:25 -0700364 service.removeWindowLocked(win);
Craig Mautner7c9ee192014-08-14 16:08:26 -0700365 }
Craig Mautnere3119b72015-01-20 15:02:36 -0800366 allAppWindows.clear();
367 windows.clear();
Craig Mautner7c9ee192014-08-14 16:08:26 -0700368 }
369
Chong Zhang112eb8c2015-11-02 11:17:00 -0800370 void removeAllDeadWindows() {
371 for (int winNdx = allAppWindows.size() - 1; winNdx >= 0;
372 // removeWindowLocked at bottom of loop may remove multiple entries from
373 // allAppWindows if the window to be removed has child windows. It also may
374 // not remove any windows from allAppWindows at all if win is exiting and
375 // currently animating away. This ensures that winNdx is monotonically decreasing
376 // and never beyond allAppWindows bounds.
377 winNdx = Math.min(winNdx - 1, allAppWindows.size() - 1)) {
378 WindowState win = allAppWindows.get(winNdx);
379 if (win.mAppDied) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800380 if (DEBUG_WINDOW_MOVEMENT) {
381 Slog.w(TAG, "removeAllDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800382 }
383 // Set mDestroying, we don't want any animation or delayed removal here.
384 win.mDestroying = true;
385 service.removeWindowLocked(win);
386 }
387 }
388 }
389
Robert Carra1eb4392015-12-10 12:43:51 -0800390 void setReplacingWindows(boolean animate) {
391 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + appWindowToken
392 + " with replacing windows.");
393
394 for (int i = allAppWindows.size() - 1; i >= 0; i--) {
395 final WindowState w = allAppWindows.get(i);
396 w.setReplacing(animate);
397 }
398 if (animate) {
399 // Set-up dummy animation so we can start treating windows associated with this
400 // token like they are in transition before the new app window is ready for us to
401 // run the real transition animation.
402 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
403 "setReplacingWindow() Setting dummy animation on: " + this);
404 mAppAnimator.setDummyAnimation();
405 }
406 }
407
Chong Zhangf596cd52016-01-05 13:42:44 -0800408 void resetReplacingWindows() {
409 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Resetting app token " + appWindowToken
410 + " of replacing window marks.");
411
412 for (int i = allAppWindows.size() - 1; i >= 0; i--) {
413 final WindowState w = allAppWindows.get(i);
414 w.resetReplacing();
415 }
416 }
417
Robert Carra1eb4392015-12-10 12:43:51 -0800418 void addWindow(WindowState w) {
419 for (int i = allAppWindows.size() - 1; i >= 0; i--) {
420 WindowState candidate = allAppWindows.get(i);
421 if (candidate.mWillReplaceWindow && candidate.mReplacingWindow == null &&
422 candidate.getWindowTag().equals(w.getWindowTag().toString())) {
423 candidate.mReplacingWindow = w;
Chong Zhangf596cd52016-01-05 13:42:44 -0800424
425 // if we got a replacement window, reset the timeout to give drawing more time
426 service.mH.removeMessages(H.WINDOW_REPLACEMENT_TIMEOUT);
427 service.mH.sendMessageDelayed(
428 service.mH.obtainMessage(H.WINDOW_REPLACEMENT_TIMEOUT, this),
429 WINDOW_REPLACEMENT_TIMEOUT_DURATION);
Robert Carra1eb4392015-12-10 12:43:51 -0800430 }
431 }
432 allAppWindows.add(w);
433 }
434
435 boolean waitingForReplacement() {
436 for (int i = allAppWindows.size() -1; i >= 0; i--) {
437 WindowState candidate = allAppWindows.get(i);
438 if (candidate.mWillReplaceWindow) {
439 return true;
440 }
441 }
442 return false;
443 }
444
Chong Zhangf596cd52016-01-05 13:42:44 -0800445 void clearTimedoutReplacesLocked() {
Robert Carra1eb4392015-12-10 12:43:51 -0800446 for (int i = allAppWindows.size() - 1; i >= 0;
447 // removeWindowLocked at bottom of loop may remove multiple entries from
448 // allAppWindows if the window to be removed has child windows. It also may
449 // not remove any windows from allAppWindows at all if win is exiting and
450 // currently animating away. This ensures that winNdx is monotonically decreasing
451 // and never beyond allAppWindows bounds.
452 i = Math.min(i - 1, allAppWindows.size() - 1)) {
453 WindowState candidate = allAppWindows.get(i);
454 if (candidate.mWillReplaceWindow == false) {
455 continue;
456 }
457 candidate.mWillReplaceWindow = false;
Chong Zhangf596cd52016-01-05 13:42:44 -0800458 // Since the window already timed out, remove it immediately now.
459 // Use removeWindowInnerLocked() instead of removeWindowLocked(), as the latter
460 // delays removal on certain conditions, which will leave the stale window in the
461 // stack and marked mWillReplaceWindow=false, so the window will never be removed.
462 service.removeWindowInnerLocked(candidate);
Robert Carra1eb4392015-12-10 12:43:51 -0800463 }
464 }
465
Jorim Jaggi0429f352015-12-22 16:29:16 +0100466 /**
467 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
468 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
469 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
470 * with a queue.
471 */
472 void freezeBounds() {
473 mFrozenBounds.offer(new Rect(mTask.mPreparedFrozenBounds));
474 }
475
476 /**
477 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
478 */
479 void unfreezeBounds() {
480 mFrozenBounds.remove();
Jorim Jaggi4846ee32016-01-07 17:39:12 +0100481 for (int i = windows.size() - 1; i >= 0; i--) {
482 final WindowState win = windows.get(i);
483 win.mLayoutNeeded = true;
484 win.setDisplayLayoutNeeded();
485 if (!service.mResizingWindows.contains(win)) {
486 service.mResizingWindows.add(win);
487 }
488 }
489 service.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100490 }
491
Craig Mautnerdbb79912012-03-01 18:59:14 -0800492 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800493 void dump(PrintWriter pw, String prefix) {
494 super.dump(pw, prefix);
495 if (appToken != null) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700496 pw.print(prefix); pw.print("app=true voiceInteraction="); pw.println(voiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800497 }
498 if (allAppWindows.size() > 0) {
499 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
500 }
Craig Mautner83162a92015-01-26 14:43:30 -0800501 pw.print(prefix); pw.print("task="); pw.println(mTask);
502 pw.print(prefix); pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800503 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
504 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
505 pw.print(" clientHidden="); pw.print(clientHidden);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700506 pw.print(" reportedDrawn="); pw.print(reportedDrawn);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800507 pw.print(" reportedVisible="); pw.println(reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -0700508 if (paused) {
509 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800510 }
511 if (numInterestingWindows != 0 || numDrawnWindows != 0
Craig Mautner6fbda632012-07-03 09:26:39 -0700512 || allDrawn || mAppAnimator.allDrawn) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800513 pw.print(prefix); pw.print("numInterestingWindows=");
514 pw.print(numInterestingWindows);
515 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
516 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -0700517 pw.print(" allDrawn="); pw.print(allDrawn);
518 pw.print(" (animator="); pw.print(mAppAnimator.allDrawn);
519 pw.println(")");
520 }
521 if (inPendingTransaction) {
522 pw.print(prefix); pw.print("inPendingTransaction=");
523 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800524 }
Craig Mautner799bc1d2015-01-14 10:33:48 -0800525 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800526 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
527 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -0800528 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -0800529 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800530 }
531 if (startingWindow != null || startingView != null
532 || startingDisplayed || startingMoved) {
533 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
534 pw.print(" startingView="); pw.print(startingView);
535 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
536 pw.print(" startingMoved"); pw.println(startingMoved);
537 }
Jorim Jaggi0429f352015-12-22 16:29:16 +0100538 if (!mFrozenBounds.isEmpty()) {
539 pw.print(prefix); pw.print("mFrozenBounds="); pw.print(mFrozenBounds);
540 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800541 }
542
543 @Override
544 public String toString() {
545 if (stringName == null) {
546 StringBuilder sb = new StringBuilder();
547 sb.append("AppWindowToken{");
548 sb.append(Integer.toHexString(System.identityHashCode(this)));
549 sb.append(" token="); sb.append(token); sb.append('}');
550 stringName = sb.toString();
551 }
552 return stringName;
553 }
Jeff Browne9bdb312012-04-05 15:30:10 -0700554}