blob: 12c62bdc93bf52e09252cf170c09039d0026036d [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
Robert Carre12aece2016-02-02 22:43:27 -0800130 boolean mAppStopped;
131
Jorim Jaggi0429f352015-12-22 16:29:16 +0100132 ArrayDeque<Rect> mFrozenBounds = new ArrayDeque<>();
133
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700134 AppWindowToken(WindowManagerService _service, IApplicationToken _token,
135 boolean _voiceInteraction) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800136 super(_service, _token.asBinder(),
137 WindowManager.LayoutParams.TYPE_APPLICATION, true);
138 appWindowToken = this;
139 appToken = _token;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700140 voiceInteraction = _voiceInteraction;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800141 mInputApplicationHandle = new InputApplicationHandle(this);
Craig Mautner322e4032012-07-13 13:35:20 -0700142 mAppAnimator = new AppWindowAnimator(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800143 }
144
145 void sendAppVisibilityToClients() {
146 final int N = allAppWindows.size();
147 for (int i=0; i<N; i++) {
148 WindowState win = allAppWindows.get(i);
149 if (win == startingWindow && clientHidden) {
150 // Don't hide the starting window.
151 continue;
152 }
153 try {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800154 if (DEBUG_VISIBILITY) Slog.v(TAG,
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800155 "Setting visibility of " + win + ": " + (!clientHidden));
156 win.mClient.dispatchAppVisibility(!clientHidden);
157 } catch (RemoteException e) {
158 }
159 }
160 }
161
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800162 void updateReportedVisibilityLocked() {
163 if (appToken == null) {
164 return;
165 }
166
167 int numInteresting = 0;
168 int numVisible = 0;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700169 int numDrawn = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800170 boolean nowGone = true;
171
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800172 if (DEBUG_VISIBILITY) Slog.v(TAG,
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700173 "Update reported visibility: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800174 final int N = allAppWindows.size();
175 for (int i=0; i<N; i++) {
176 WindowState win = allAppWindows.get(i);
177 if (win == startingWindow || win.mAppFreezing
178 || win.mViewVisibility != View.VISIBLE
179 || win.mAttrs.type == TYPE_APPLICATION_STARTING
180 || win.mDestroying) {
181 continue;
182 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800183 if (DEBUG_VISIBILITY) {
184 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800185 + win.isDrawnLw()
Craig Mautnera2c77052012-03-26 12:14:43 -0700186 + ", isAnimating=" + win.mWinAnimator.isAnimating());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800187 if (!win.isDrawnLw()) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800188 Slog.v(TAG, "Not displayed: s=" +
Robert Carre6a83512015-11-03 16:09:21 -0800189 win.mWinAnimator.mSurfaceController
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800190 + " pv=" + win.mPolicyVisibility
Craig Mautner749a7bb2012-04-02 13:49:53 -0700191 + " mDrawState=" + win.mWinAnimator.mDrawState
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800192 + " ah=" + win.mAttachedHidden
193 + " th="
194 + (win.mAppToken != null
195 ? win.mAppToken.hiddenRequested : false)
Craig Mautnera2c77052012-03-26 12:14:43 -0700196 + " a=" + win.mWinAnimator.mAnimating);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800197 }
198 }
199 numInteresting++;
200 if (win.isDrawnLw()) {
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700201 numDrawn++;
Craig Mautnera2c77052012-03-26 12:14:43 -0700202 if (!win.mWinAnimator.isAnimating()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800203 numVisible++;
204 }
205 nowGone = false;
Craig Mautnera2c77052012-03-26 12:14:43 -0700206 } else if (win.mWinAnimator.isAnimating()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800207 nowGone = false;
208 }
209 }
210
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700211 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800212 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700213 if (!nowGone) {
214 // If the app is not yet gone, then it can only become visible/drawn.
215 if (!nowDrawn) {
216 nowDrawn = reportedDrawn;
217 }
218 if (!nowVisible) {
219 nowVisible = reportedVisible;
220 }
221 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800222 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800223 + numInteresting + " visible=" + numVisible);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700224 if (nowDrawn != reportedDrawn) {
225 if (nowDrawn) {
226 Message m = service.mH.obtainMessage(
227 H.REPORT_APPLICATION_TOKEN_DRAWN, this);
228 service.mH.sendMessage(m);
229 }
230 reportedDrawn = nowDrawn;
231 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800232 if (nowVisible != reportedVisible) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800233 if (DEBUG_VISIBILITY) Slog.v(
234 TAG, "Visibility changed in " + this
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800235 + ": vis=" + nowVisible);
236 reportedVisible = nowVisible;
237 Message m = service.mH.obtainMessage(
238 H.REPORT_APPLICATION_TOKEN_WINDOWS,
239 nowVisible ? 1 : 0,
240 nowGone ? 1 : 0,
241 this);
242 service.mH.sendMessage(m);
243 }
244 }
245
246 WindowState findMainWindow() {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700247 WindowState candidate = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800248 int j = windows.size();
249 while (j > 0) {
250 j--;
251 WindowState win = windows.get(j);
252 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
253 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700254 // In cases where there are multiple windows, we prefer the non-exiting window. This
Sungsoo Lim0d3d1f82015-12-02 14:47:59 +0900255 // happens for example when replacing windows during an activity relaunch. When
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700256 // constructing the animation, we want the new window, not the exiting one.
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800257 if (win.mAnimatingExit) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700258 candidate = win;
259 } else {
260 return win;
261 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800262 }
263 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700264 return candidate;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800265 }
266
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800267 boolean windowsAreFocusable() {
268 return StackId.canReceiveKeys(mTask.mStack.mStackId) || mAlwaysFocusable;
Wale Ogunwaled045c822015-12-02 09:14:28 -0800269 }
270
Craig Mautner72669d12012-12-18 17:23:54 -0800271 boolean isVisible() {
272 final int N = allAppWindows.size();
Craig Mautner72669d12012-12-18 17:23:54 -0800273 for (int i=0; i<N; i++) {
274 WindowState win = allAppWindows.get(i);
Chong Zhangdb20b5f2015-10-23 14:01:43 -0700275 // If we're animating with a saved surface, we're already visible.
276 // Return true so that the alpha doesn't get cleared.
Craig Mautner72669d12012-12-18 17:23:54 -0800277 if (!win.mAppFreezing
Filip Gruszczynski57f76f12015-11-04 16:10:54 -0800278 && (win.mViewVisibility == View.VISIBLE || mAnimatingWithSavedSurface
279 || (win.mWinAnimator.isAnimating()
280 && !service.mAppTransition.isTransitionSet()))
281 && !win.mDestroying
282 && win.isDrawnLw()) {
Craig Mautner72669d12012-12-18 17:23:54 -0800283 return true;
284 }
285 }
286 return false;
287 }
288
Craig Mautnere3119b72015-01-20 15:02:36 -0800289 void removeAppFromTaskLocked() {
290 mIsExiting = false;
291 removeAllWindows();
292
Craig Mautner83162a92015-01-26 14:43:30 -0800293 // Use local variable because removeAppToken will null out mTask.
294 final Task task = mTask;
Craig Mautnere3119b72015-01-20 15:02:36 -0800295 if (task != null) {
296 if (!task.removeAppToken(this)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800297 Slog.e(TAG, "removeAppFromTaskLocked: token=" + this
Craig Mautnere3119b72015-01-20 15:02:36 -0800298 + " not found.");
299 }
300 task.mStack.mExitingAppTokens.remove(this);
301 }
302 }
303
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800304 void setWindowsExiting(boolean exiting) {
Chong Zhangeb22e8e2016-01-20 19:52:22 -0800305 for (int i = allAppWindows.size() - 1; i >= 0; i--) {
306 WindowState win = allAppWindows.get(i);
Chong Zhang6bb82502016-02-02 14:13:48 -0800307 // If the app already requested to remove its window, we don't modify
308 // its exiting state. Otherwise the stale window won't get removed on
309 // exit and could cause focus to be given to the wrong window.
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800310 if (!(win.mRemoveOnExit && win.mAnimatingExit)) {
311 win.mAnimatingExit = exiting;
Chong Zhang6bb82502016-02-02 14:13:48 -0800312 }
Chong Zhang5471e902016-02-12 15:34:10 -0800313 // If we're no longer exiting, remove the window from destroying list
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800314 if (!win.mAnimatingExit && win.mDestroying) {
Chong Zhang5471e902016-02-12 15:34:10 -0800315 win.mDestroying = false;
316 service.mDestroySurface.remove(win);
317 }
Chong Zhangeb22e8e2016-01-20 19:52:22 -0800318 }
319 }
320
Robert Carre12aece2016-02-02 22:43:27 -0800321 // Here we destroy surfaces which have been marked as eligible by the animator, taking care
322 // to ensure the client has finished with them. If the client could still be using them
323 // we will skip destruction and try again when the client has stopped.
324 void destroySurfaces() {
325 final ArrayList<WindowState> allWindows = (ArrayList<WindowState>) allAppWindows.clone();
326 final DisplayContentList displayList = new DisplayContentList();
327 for (int i = allWindows.size() - 1; i >= 0; i--) {
328 final WindowState win = allWindows.get(i);
329 if (!win.mDestroying) {
330 continue;
331 }
332
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800333 if (!(mAppStopped || win.mWindowRemovalAllowed)) {
Chong Zhang5471e902016-02-12 15:34:10 -0800334 continue;
Robert Carre12aece2016-02-02 22:43:27 -0800335 }
336
337 win.destroyOrSaveSurface();
338 if (win.mRemoveOnExit) {
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800339 win.mAnimatingExit = false;
Robert Carre12aece2016-02-02 22:43:27 -0800340 service.removeWindowInnerLocked(win);
341 }
342 final DisplayContent displayContent = win.getDisplayContent();
343 if (displayContent != null && !displayList.contains(displayContent)) {
344 displayList.add(displayContent);
345 }
346 win.mDestroying = false;
347 }
348 for (int i = 0; i < displayList.size(); i++) {
349 final DisplayContent displayContent = displayList.get(i);
350 service.mLayersController.assignLayersLocked(displayContent.getWindowList());
351 displayContent.layoutNeeded = true;
352 }
353 }
354
355 // The application has stopped, so destroy any surfaces which were keeping alive
356 // in case they were still being used.
357 void notifyAppStopped() {
358 mAppStopped = true;
359 destroySurfaces();
360 }
361
Chong Zhangbef461f2015-10-27 11:38:24 -0700362 /**
363 * Checks whether we should save surfaces for this app.
364 *
365 * @return true if the surfaces should be saved, false otherwise.
366 */
367 boolean shouldSaveSurface() {
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800368 // We want to save surface if the app's windows are "allDrawn".
369 // (If we started entering animation early with saved surfaces, allDrawn
370 // should have been restored to true. So we'll save again in that case
371 // even if app didn't actually finish drawing.)
372 return allDrawn;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800373 }
374
375 boolean hasSavedSurface() {
376 for (int i = windows.size() -1; i >= 0; i--) {
377 final WindowState ws = windows.get(i);
378 if (ws.hasSavedSurface()) {
379 return true;
380 }
Chong Zhangbef461f2015-10-27 11:38:24 -0700381 }
382 return false;
383 }
384
385 void restoreSavedSurfaces() {
Robert Carr13f7be9e2015-12-02 18:39:45 -0800386 if (!hasSavedSurface()) {
Chong Zhangbef461f2015-10-27 11:38:24 -0700387 return;
388 }
Chong Zhangbef461f2015-10-27 11:38:24 -0700389 mAnimatingWithSavedSurface = true;
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800390
391 // Check if we have enough drawn windows to mark allDrawn= true.
392 int numInteresting = 0;
393 int numDrawn = 0;
Chong Zhangbef461f2015-10-27 11:38:24 -0700394 for (int i = windows.size() - 1; i >= 0; i--) {
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800395 WindowState w = windows.get(i);
Chong Zhang4113ffa2016-02-18 12:39:13 -0800396 if (w.hasSavedSurface()) {
397 w.restoreSavedSurface();
398 }
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800399 if (w != startingWindow && !w.mAppDied
400 && (!mAppAnimator.freezingScreen || !w.mAppFreezing)) {
401 numInteresting++;
402 if (w.isDrawnLw()) {
403 numDrawn++;
404 }
405 }
Chong Zhangbef461f2015-10-27 11:38:24 -0700406 }
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800407
Chong Zhang4113ffa2016-02-18 12:39:13 -0800408 allDrawn |= (numInteresting > 0) && (numInteresting == numDrawn);
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800409
410 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG,
411 "restoreSavedSurfaces: " + appWindowToken + " allDrawn=" + allDrawn);
Chong Zhangbef461f2015-10-27 11:38:24 -0700412 }
413
414 void destroySavedSurfaces() {
Robert Carr13f7be9e2015-12-02 18:39:45 -0800415 for (int i = windows.size() - 1; i >= 0; i--) {
416 WindowState win = windows.get(i);
417 win.destroySavedSurface();
Chong Zhangbef461f2015-10-27 11:38:24 -0700418 }
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800419 mAnimatingWithSavedSurface = false;
Chong Zhangbef461f2015-10-27 11:38:24 -0700420 }
421
Wale Ogunwale98e70d02014-11-10 12:12:27 -0800422 @Override
Craig Mautner7c9ee192014-08-14 16:08:26 -0700423 void removeAllWindows() {
Craig Mautner7b4655d2014-11-20 12:13:22 -0800424 for (int winNdx = allAppWindows.size() - 1; winNdx >= 0;
425 // removeWindowLocked at bottom of loop may remove multiple entries from
426 // allAppWindows if the window to be removed has child windows. It also may
427 // not remove any windows from allAppWindows at all if win is exiting and
428 // currently animating away. This ensures that winNdx is monotonically decreasing
429 // and never beyond allAppWindows bounds.
430 winNdx = Math.min(winNdx - 1, allAppWindows.size() - 1)) {
431 WindowState win = allAppWindows.get(winNdx);
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800432 if (DEBUG_WINDOW_MOVEMENT) {
433 Slog.w(TAG, "removeAllWindows: removing win=" + win);
Wale Ogunwale98e70d02014-11-10 12:12:27 -0800434 }
435
Wale Ogunwalea6ab5c42015-04-24 09:00:25 -0700436 service.removeWindowLocked(win);
Craig Mautner7c9ee192014-08-14 16:08:26 -0700437 }
Craig Mautnere3119b72015-01-20 15:02:36 -0800438 allAppWindows.clear();
439 windows.clear();
Craig Mautner7c9ee192014-08-14 16:08:26 -0700440 }
441
Chong Zhang112eb8c2015-11-02 11:17:00 -0800442 void removeAllDeadWindows() {
443 for (int winNdx = allAppWindows.size() - 1; winNdx >= 0;
444 // removeWindowLocked at bottom of loop may remove multiple entries from
445 // allAppWindows if the window to be removed has child windows. It also may
446 // not remove any windows from allAppWindows at all if win is exiting and
447 // currently animating away. This ensures that winNdx is monotonically decreasing
448 // and never beyond allAppWindows bounds.
449 winNdx = Math.min(winNdx - 1, allAppWindows.size() - 1)) {
450 WindowState win = allAppWindows.get(winNdx);
451 if (win.mAppDied) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800452 if (DEBUG_WINDOW_MOVEMENT) {
453 Slog.w(TAG, "removeAllDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800454 }
455 // Set mDestroying, we don't want any animation or delayed removal here.
456 win.mDestroying = true;
457 service.removeWindowLocked(win);
458 }
459 }
460 }
461
Robert Carra1eb4392015-12-10 12:43:51 -0800462 void setReplacingWindows(boolean animate) {
463 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + appWindowToken
464 + " with replacing windows.");
465
466 for (int i = allAppWindows.size() - 1; i >= 0; i--) {
467 final WindowState w = allAppWindows.get(i);
468 w.setReplacing(animate);
469 }
470 if (animate) {
471 // Set-up dummy animation so we can start treating windows associated with this
472 // token like they are in transition before the new app window is ready for us to
473 // run the real transition animation.
474 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
475 "setReplacingWindow() Setting dummy animation on: " + this);
476 mAppAnimator.setDummyAnimation();
477 }
478 }
479
Robert Carr23fa16b2016-01-13 13:19:58 -0800480 void setReplacingChildren() {
481 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + appWindowToken
482 + " with replacing child windows.");
483 for (int i = allAppWindows.size() - 1; i >= 0; i--) {
484 final WindowState w = allAppWindows.get(i);
485 if (w.isChildWindow()) {
486 w.setReplacing(false /* animate */);
487 }
488 }
489 }
490
Chong Zhangf596cd52016-01-05 13:42:44 -0800491 void resetReplacingWindows() {
492 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Resetting app token " + appWindowToken
493 + " of replacing window marks.");
494
495 for (int i = allAppWindows.size() - 1; i >= 0; i--) {
496 final WindowState w = allAppWindows.get(i);
497 w.resetReplacing();
498 }
499 }
500
Robert Carra1eb4392015-12-10 12:43:51 -0800501 void addWindow(WindowState w) {
502 for (int i = allAppWindows.size() - 1; i >= 0; i--) {
503 WindowState candidate = allAppWindows.get(i);
504 if (candidate.mWillReplaceWindow && candidate.mReplacingWindow == null &&
505 candidate.getWindowTag().equals(w.getWindowTag().toString())) {
506 candidate.mReplacingWindow = w;
Chong Zhangf596cd52016-01-05 13:42:44 -0800507
508 // if we got a replacement window, reset the timeout to give drawing more time
509 service.mH.removeMessages(H.WINDOW_REPLACEMENT_TIMEOUT);
510 service.mH.sendMessageDelayed(
511 service.mH.obtainMessage(H.WINDOW_REPLACEMENT_TIMEOUT, this),
512 WINDOW_REPLACEMENT_TIMEOUT_DURATION);
Robert Carra1eb4392015-12-10 12:43:51 -0800513 }
514 }
515 allAppWindows.add(w);
516 }
517
518 boolean waitingForReplacement() {
519 for (int i = allAppWindows.size() -1; i >= 0; i--) {
520 WindowState candidate = allAppWindows.get(i);
521 if (candidate.mWillReplaceWindow) {
522 return true;
523 }
524 }
525 return false;
526 }
527
Chong Zhangf596cd52016-01-05 13:42:44 -0800528 void clearTimedoutReplacesLocked() {
Robert Carra1eb4392015-12-10 12:43:51 -0800529 for (int i = allAppWindows.size() - 1; i >= 0;
530 // removeWindowLocked at bottom of loop may remove multiple entries from
531 // allAppWindows if the window to be removed has child windows. It also may
532 // not remove any windows from allAppWindows at all if win is exiting and
533 // currently animating away. This ensures that winNdx is monotonically decreasing
534 // and never beyond allAppWindows bounds.
535 i = Math.min(i - 1, allAppWindows.size() - 1)) {
536 WindowState candidate = allAppWindows.get(i);
537 if (candidate.mWillReplaceWindow == false) {
538 continue;
539 }
540 candidate.mWillReplaceWindow = false;
Chong Zhangf596cd52016-01-05 13:42:44 -0800541 // Since the window already timed out, remove it immediately now.
542 // Use removeWindowInnerLocked() instead of removeWindowLocked(), as the latter
543 // delays removal on certain conditions, which will leave the stale window in the
544 // stack and marked mWillReplaceWindow=false, so the window will never be removed.
545 service.removeWindowInnerLocked(candidate);
Robert Carra1eb4392015-12-10 12:43:51 -0800546 }
547 }
548
Jorim Jaggi0429f352015-12-22 16:29:16 +0100549 /**
550 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
551 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
552 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
553 * with a queue.
554 */
555 void freezeBounds() {
556 mFrozenBounds.offer(new Rect(mTask.mPreparedFrozenBounds));
557 }
558
559 /**
560 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
561 */
562 void unfreezeBounds() {
563 mFrozenBounds.remove();
Jorim Jaggi4846ee32016-01-07 17:39:12 +0100564 for (int i = windows.size() - 1; i >= 0; i--) {
565 final WindowState win = windows.get(i);
Jorim Jaggi69abc192016-02-04 19:34:00 -0800566 if (!win.mHasSurface) {
567 continue;
568 }
Jorim Jaggi4846ee32016-01-07 17:39:12 +0100569 win.mLayoutNeeded = true;
570 win.setDisplayLayoutNeeded();
571 if (!service.mResizingWindows.contains(win)) {
572 service.mResizingWindows.add(win);
573 }
574 }
575 service.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100576 }
577
Craig Mautnerdbb79912012-03-01 18:59:14 -0800578 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800579 void dump(PrintWriter pw, String prefix) {
580 super.dump(pw, prefix);
581 if (appToken != null) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700582 pw.print(prefix); pw.print("app=true voiceInteraction="); pw.println(voiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800583 }
584 if (allAppWindows.size() > 0) {
585 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
586 }
Craig Mautner83162a92015-01-26 14:43:30 -0800587 pw.print(prefix); pw.print("task="); pw.println(mTask);
588 pw.print(prefix); pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800589 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
590 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
591 pw.print(" clientHidden="); pw.print(clientHidden);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700592 pw.print(" reportedDrawn="); pw.print(reportedDrawn);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800593 pw.print(" reportedVisible="); pw.println(reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -0700594 if (paused) {
595 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800596 }
597 if (numInterestingWindows != 0 || numDrawnWindows != 0
Craig Mautner6fbda632012-07-03 09:26:39 -0700598 || allDrawn || mAppAnimator.allDrawn) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800599 pw.print(prefix); pw.print("numInterestingWindows=");
600 pw.print(numInterestingWindows);
601 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
602 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -0700603 pw.print(" allDrawn="); pw.print(allDrawn);
604 pw.print(" (animator="); pw.print(mAppAnimator.allDrawn);
605 pw.println(")");
606 }
607 if (inPendingTransaction) {
608 pw.print(prefix); pw.print("inPendingTransaction=");
609 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800610 }
Craig Mautner799bc1d2015-01-14 10:33:48 -0800611 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800612 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
613 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -0800614 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -0800615 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800616 }
617 if (startingWindow != null || startingView != null
618 || startingDisplayed || startingMoved) {
619 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
620 pw.print(" startingView="); pw.print(startingView);
621 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
622 pw.print(" startingMoved"); pw.println(startingMoved);
623 }
Jorim Jaggi0429f352015-12-22 16:29:16 +0100624 if (!mFrozenBounds.isEmpty()) {
625 pw.print(prefix); pw.print("mFrozenBounds="); pw.print(mFrozenBounds);
626 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800627 }
628
629 @Override
630 public String toString() {
631 if (stringName == null) {
632 StringBuilder sb = new StringBuilder();
633 sb.append("AppWindowToken{");
634 sb.append(Integer.toHexString(System.identityHashCode(this)));
635 sb.append(" token="); sb.append(token); sb.append('}');
636 stringName = sb.toString();
637 }
638 return stringName;
639 }
Jeff Browne9bdb312012-04-05 15:30:10 -0700640}