blob: a3f7ac6d6c0d4cfc65c9d5a6dda26e981d845183 [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;
Wale Ogunwale51362492016-09-08 17:49:17 -070020import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070021import static android.view.Display.DEFAULT_DISPLAY;
Wale Ogunwaled1c37912016-08-16 03:19:39 -070022import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080023import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070024import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -070025import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
26import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080027import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
28import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
Robert Carra1eb4392015-12-10 12:43:51 -080029import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070030import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
31import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
Wale Ogunwale9017ec02016-02-25 08:55:25 -080032import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080033import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
34import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_MOVEMENT;
35import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
36import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Chong Zhang92147042016-05-09 12:47:11 -070037import static com.android.server.wm.WindowManagerService.H.NOTIFY_ACTIVITY_DRAWN;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -070038import static com.android.server.wm.WindowManagerService.H.NOTIFY_STARTING_WINDOW_DRAWN;
Jorim Jaggi6626f542016-08-22 13:08:44 -070039import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_NONE;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070040import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070041import static com.android.server.wm.WindowManagerService.logWithStack;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080042
Jeff Brown4532e612012-04-05 14:27:12 -070043import com.android.server.input.InputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080044import com.android.server.wm.WindowManagerService.H;
45
Filip Gruszczynskia590c992015-11-25 16:45:26 -080046import android.annotation.NonNull;
Jorim Jaggi26c8c422016-05-09 19:57:25 -070047import android.content.res.Configuration;
Jorim Jaggi0429f352015-12-22 16:29:16 +010048import android.graphics.Rect;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070049import android.os.Binder;
50import android.os.IBinder;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080051import android.os.Message;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070052import android.os.SystemClock;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080053import android.util.Slog;
54import android.view.IApplicationToken;
55import android.view.View;
56import android.view.WindowManager;
Jorim Jaggi6626f542016-08-22 13:08:44 -070057import android.view.animation.Animation;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080058
59import java.io.PrintWriter;
Jorim Jaggi0429f352015-12-22 16:29:16 +010060import java.util.ArrayDeque;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080061import java.util.ArrayList;
62
63class AppTokenList extends ArrayList<AppWindowToken> {
64}
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080065
66/**
67 * Version of WindowToken that is specifically for a particular application (or
68 * really activity) that is displaying windows.
69 */
Wale Ogunwale3f4433d2016-08-18 20:42:42 -070070class AppWindowToken extends WindowToken implements WindowManagerService.AppFreezeListener {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080071 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppWindowToken" : TAG_WM;
72
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080073 // Non-null only for application tokens.
74 final IApplicationToken appToken;
75
Filip Gruszczynskia590c992015-11-25 16:45:26 -080076 @NonNull final AppWindowAnimator mAppAnimator;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -070077
Dianne Hackborne30e02f2014-05-27 18:24:45 -070078 final boolean voiceInteraction;
79
Wale Ogunwalef6192862016-09-10 13:42:30 -070080 // TODO: Use getParent instead?
Craig Mautner83162a92015-01-26 14:43:30 -080081 Task mTask;
Wale Ogunwale51362492016-09-08 17:49:17 -070082 /** @see WindowContainer#fillsParent() */
83 private boolean mFillsParent;
Craig Mautner4c5eb222013-11-18 12:59:05 -080084 boolean layoutConfigChanges;
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -070085 boolean showForAllUsers;
Yorke Lee0e852472016-06-15 10:03:18 -070086 int targetSdk;
Craig Mautnera2c77052012-03-26 12:14:43 -070087
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080088 // The input dispatching timeout for this application token in nanoseconds.
89 long inputDispatchingTimeoutNanos;
90
91 // These are used for determining when all windows associated with
92 // an activity have been drawn, so they can be made visible together
93 // at the same time.
Craig Mautner764983d2012-03-22 11:37:36 -070094 // initialize so that it doesn't match mTransactionSequence which is an int.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -070095 private long mLastTransactionSequence = Long.MIN_VALUE;
96 private int mNumInterestingWindows;
97 private int mNumDrawnWindows;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080098 boolean inPendingTransaction;
99 boolean allDrawn;
Craig Mautner7636dfb2012-11-16 15:24:11 -0800100 // Set to true when this app creates a surface while in the middle of an animation. In that
101 // case do not clear allDrawn until the animation completes.
102 boolean deferClearAllDrawn;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800103
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700104 /**
105 * These are to track the app's real drawing status if there were no saved surfaces.
106 * @see #updateDrawnWindowStates
107 */
Chong Zhang8e4bda92016-05-04 15:08:18 -0700108 boolean allDrawnExcludingSaved;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700109 private int mNumInterestingWindowsExcludingSaved;
110 private int mNumDrawnWindowsExcludingSaved;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700111
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800112 // Is this window's surface needed? This is almost like hidden, except
113 // it will sometimes be true a little earlier: when the token has
114 // been shown, but is still waiting for its app transition to execute
115 // before making its windows shown.
116 boolean hiddenRequested;
117
118 // Have we told the window clients to hide themselves?
119 boolean clientHidden;
120
121 // Last visibility state we reported to the app token.
122 boolean reportedVisible;
123
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700124 // Last drawn state we reported to the app token.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700125 private boolean reportedDrawn;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700126
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800127 // Set to true when the token has been removed from the window mgr.
128 boolean removed;
129
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800130 // Information about an application starting window if displayed.
131 StartingData startingData;
132 WindowState startingWindow;
133 View startingView;
134 boolean startingDisplayed;
135 boolean startingMoved;
136 boolean firstWindowDrawn;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700137 private final WindowState.UpdateReportedVisibilityResults mReportedVisibilityResults =
138 new WindowState.UpdateReportedVisibilityResults();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800139
140 // Input application handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700141 final InputApplicationHandle mInputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800142
Wale Ogunwale571771c2016-08-26 13:18:50 -0700143 // TODO: Have a WindowContainer state for tracking exiting/deferred removal.
Craig Mautner799bc1d2015-01-14 10:33:48 -0800144 boolean mIsExiting;
Craig Mautner9ef471f2014-02-07 13:11:47 -0800145
Craig Mautnerbb742462014-07-07 15:28:55 -0700146 boolean mLaunchTaskBehind;
Craig Mautner8746a472014-07-24 15:12:54 -0700147 boolean mEnteringAnimation;
Craig Mautnerbb742462014-07-07 15:28:55 -0700148
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800149 boolean mAlwaysFocusable;
150
Robert Carre12aece2016-02-02 22:43:27 -0800151 boolean mAppStopped;
Robert Carrfd10cd12016-06-29 16:41:50 -0700152 int mRotationAnimationHint;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700153 private int mPendingRelaunchCount;
Robert Carre12aece2016-02-02 22:43:27 -0800154
Robert Carr91b228092016-06-28 17:32:37 -0700155 private ArrayList<WindowSurfaceController.SurfaceControlWithBackground> mSurfaceViewBackgrounds =
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700156 new ArrayList<>();
Robert Carr91b228092016-06-28 17:32:37 -0700157
Jorim Jaggi0429f352015-12-22 16:29:16 +0100158 ArrayDeque<Rect> mFrozenBounds = new ArrayDeque<>();
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700159 ArrayDeque<Configuration> mFrozenMergedConfig = new ArrayDeque<>();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100160
Wale Ogunwale02319a62016-09-26 15:21:22 -0700161 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean _voiceInteraction,
162 DisplayContent displayContent) {
163 super(service, token != null ? token.asBinder() : null, TYPE_APPLICATION, true,
164 displayContent);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700165 appToken = token;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700166 voiceInteraction = _voiceInteraction;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800167 mInputApplicationHandle = new InputApplicationHandle(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700168 mAppAnimator = new AppWindowAnimator(this, service);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800169 }
170
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800171 void onFirstWindowDrawn(WindowState win, WindowStateAnimator winAnimator) {
172 firstWindowDrawn = true;
173
174 // We now have a good window to show, remove dead placeholders
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700175 removeDeadWindows();
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800176
177 if (startingData != null) {
178 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, "Finish starting "
179 + win.mToken + ": first real window is shown, no animation");
180 // If this initial window is animating, stop it -- we will do an animation to reveal
181 // it from behind the starting window, so there is no need for it to also be doing its
182 // own stuff.
183 winAnimator.clearAnimation();
184 winAnimator.mService.mFinishedStarting.add(this);
185 winAnimator.mService.mH.sendEmptyMessage(H.FINISHED_STARTING);
186 }
187 updateReportedVisibilityLocked();
188 }
189
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800190 void updateReportedVisibilityLocked() {
191 if (appToken == null) {
192 return;
193 }
194
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700195 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700196 final int count = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800197
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700198 mReportedVisibilityResults.reset();
199
200 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700201 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700202 win.updateReportedVisibility(mReportedVisibilityResults);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800203 }
204
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700205 int numInteresting = mReportedVisibilityResults.numInteresting;
206 int numVisible = mReportedVisibilityResults.numVisible;
207 int numDrawn = mReportedVisibilityResults.numDrawn;
208 boolean nowGone = mReportedVisibilityResults.nowGone;
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) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700225 mService.mH.obtainMessage(H.REPORT_APPLICATION_TOKEN_DRAWN, this).sendToTarget();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700226 }
227 reportedDrawn = nowDrawn;
228 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800229 if (nowVisible != reportedVisible) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700230 if (DEBUG_VISIBILITY) Slog.v(TAG,
231 "Visibility changed in " + this + ": vis=" + nowVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800232 reportedVisible = nowVisible;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700233 mService.mH.obtainMessage(H.REPORT_APPLICATION_TOKEN_WINDOWS,
234 nowVisible ? 1 : 0, nowGone ? 1 : 0, this).sendToTarget();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800235 }
236 }
237
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700238 boolean setVisibility(WindowManager.LayoutParams lp,
239 boolean visible, int transit, boolean performLayout, boolean isVoiceInteraction) {
240
241 boolean delayed = false;
242 inPendingTransaction = false;
243
244 if (clientHidden == visible) {
245 clientHidden = !visible;
246 sendAppVisibilityToClients();
247 }
248
249 // Allow for state changes and animation to be applied if:
250 // * token is transitioning visibility state
251 // * or the token was marked as hidden and is exiting before we had a chance to play the
252 // transition animation
253 // * or this is an opening app and windows are being replaced.
254 boolean visibilityChanged = false;
255 if (hidden == visible || (hidden && mIsExiting) || (visible && waitingForReplacement())) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700256 final AccessibilityController accessibilityController = mService.mAccessibilityController;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700257 boolean changed = false;
258 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
259 "Changing app " + this + " hidden=" + hidden + " performLayout=" + performLayout);
260
261 boolean runningAppAnimation = false;
262
263 if (transit != AppTransition.TRANSIT_UNSET) {
264 if (mAppAnimator.animation == AppWindowAnimator.sDummyAnimation) {
265 mAppAnimator.setNullAnimation();
266 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700267 if (mService.applyAnimationLocked(this, lp, transit, visible, isVoiceInteraction)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700268 delayed = runningAppAnimation = true;
269 }
270 final WindowState window = findMainWindow();
271 //TODO (multidisplay): Magnification is supported only for the default display.
272 if (window != null && accessibilityController != null
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700273 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700274 accessibilityController.onAppWindowTransitionLocked(window, transit);
275 }
276 changed = true;
277 }
278
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700279 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700280 for (int i = 0; i < windowsCount; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700281 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700282 changed |= win.onAppVisibilityChanged(visible, runningAppAnimation);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700283 }
284
285 hidden = hiddenRequested = !visible;
286 visibilityChanged = true;
287 if (!visible) {
288 stopFreezingScreen(true, true);
289 } else {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700290 // If we are being set visible, and the starting window is not yet displayed,
291 // then make sure it doesn't get displayed.
292 if (startingWindow != null && !startingWindow.isDrawnLw()) {
293 startingWindow.mPolicyVisibility = false;
294 startingWindow.mPolicyVisibilityAfterAnim = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700295 }
296 }
297
298 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setVisibility: " + this
299 + ": hidden=" + hidden + " hiddenRequested=" + hiddenRequested);
300
301 if (changed) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700302 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700303 if (performLayout) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700304 mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700305 false /*updateInputWindows*/);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700306 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700307 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700308 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700309 }
310 }
311
312 if (mAppAnimator.animation != null) {
313 delayed = true;
314 }
315
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700316 for (int i = mChildren.size() - 1; i >= 0 && !delayed; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700317 if ((mChildren.get(i)).isWindowAnimationSet()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700318 delayed = true;
319 }
320 }
321
322 if (visibilityChanged) {
323 if (visible && !delayed) {
324 // The token was made immediately visible, there will be no entrance animation.
325 // We need to inform the client the enter animation was finished.
326 mEnteringAnimation = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700327 mService.mActivityManagerAppTransitionNotifier.onAppTransitionFinishedLocked(token);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700328 }
329
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700330 if (!mService.mClosingApps.contains(this) && !mService.mOpeningApps.contains(this)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700331 // The token is not closing nor opening, so even if there is an animation set, that
332 // doesn't mean that it goes through the normal app transition cycle so we have
333 // to inform the docked controller about visibility change.
Andrii Kulian1e32e022016-09-16 15:29:34 -0700334 // TODO(multi-display): notify docked divider on all displays where visibility was
335 // affected.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700336 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700337 .notifyAppVisibilityChanged();
338 }
339 }
340
341 return delayed;
342 }
343
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800344 WindowState findMainWindow() {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700345 WindowState candidate = null;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700346 int j = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800347 while (j > 0) {
348 j--;
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700349 final WindowState win = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700350 final int type = win.mAttrs.type;
351 // No need to loop through child window as base application and starting types can't be
352 // child windows.
353 if (type == TYPE_BASE_APPLICATION || type == TYPE_APPLICATION_STARTING) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700354 // In cases where there are multiple windows, we prefer the non-exiting window. This
Sungsoo Lim0d3d1f82015-12-02 14:47:59 +0900355 // happens for example when replacing windows during an activity relaunch. When
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700356 // constructing the animation, we want the new window, not the exiting one.
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800357 if (win.mAnimatingExit) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700358 candidate = win;
359 } else {
360 return win;
361 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800362 }
363 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700364 return candidate;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800365 }
366
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800367 boolean windowsAreFocusable() {
368 return StackId.canReceiveKeys(mTask.mStack.mStackId) || mAlwaysFocusable;
Wale Ogunwaled045c822015-12-02 09:14:28 -0800369 }
370
Wale Ogunwale571771c2016-08-26 13:18:50 -0700371 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -0700372 boolean isVisible() {
Wale Ogunwalee471be62016-10-03 07:53:55 -0700373 // If the app token isn't hidden then it is considered visible and there is no need to check
374 // its children windows to see if they are visible.
375 return !hidden;
Wale Ogunwale44f21802016-09-02 12:49:48 -0700376 }
377
378 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -0700379 void removeIfPossible() {
Craig Mautnere3119b72015-01-20 15:02:36 -0800380 mIsExiting = false;
381 removeAllWindows();
Wale Ogunwale571771c2016-08-26 13:18:50 -0700382 if (mTask != null) {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700383 mTask.mStack.mExitingAppTokens.remove(this);
384 mTask.removeChild(this);
Craig Mautnere3119b72015-01-20 15:02:36 -0800385 }
386 }
387
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700388 @Override
389 boolean checkCompleteDeferredRemoval() {
390 if (mIsExiting) {
391 removeIfPossible();
392 }
393 return super.checkCompleteDeferredRemoval();
394 }
395
Chong Zhange05bcb12016-07-26 17:47:29 -0700396 void clearAnimatingFlags() {
Chong Zhangb0d26702016-08-12 16:03:29 -0700397 boolean wallpaperMightChange = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700398 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700399 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700400 wallpaperMightChange |= win.clearAnimatingFlags();
Chong Zhange05bcb12016-07-26 17:47:29 -0700401 }
Chong Zhangb0d26702016-08-12 16:03:29 -0700402 if (wallpaperMightChange) {
403 requestUpdateWallpaperIfNeeded();
404 }
Chong Zhange05bcb12016-07-26 17:47:29 -0700405 }
406
Robert Carre12aece2016-02-02 22:43:27 -0800407 void destroySurfaces() {
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700408 destroySurfaces(false /*cleanupOnResume*/);
409 }
410
411 /**
412 * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure
413 * the client has finished with them.
414 *
415 * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If
416 * set to true, destroy only surfaces of removed windows, and clear relevant flags of the
417 * others so that they are ready to be reused. If set to false (common case), destroy all
418 * surfaces that's eligible, if the app is already stopped.
419 */
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700420 private void destroySurfaces(boolean cleanupOnResume) {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700421 boolean destroyedSomething = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700422 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700423 final WindowState win = mChildren.get(i);
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700424 destroyedSomething |= win.destroySurface(cleanupOnResume, mAppStopped);
Robert Carre12aece2016-02-02 22:43:27 -0800425 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700426 if (destroyedSomething) {
427 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700428 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Robert Carre12aece2016-02-02 22:43:27 -0800429 }
430 }
431
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800432 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700433 * Notify that the app is now resumed, and it was not stopped before, perform a clean
434 * up of the surfaces
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800435 */
Chong Zhangad24f962016-08-25 12:12:33 -0700436 void notifyAppResumed(boolean wasStopped, boolean allowSavedSurface) {
437 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped
438 + " allowSavedSurface=" + allowSavedSurface + " " + this);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700439 mAppStopped = false;
440 if (!wasStopped) {
441 destroySurfaces(true /*cleanupOnResume*/);
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800442 }
Chong Zhangad24f962016-08-25 12:12:33 -0700443 if (!allowSavedSurface) {
444 destroySavedSurfaces();
445 }
Robert Carre12aece2016-02-02 22:43:27 -0800446 }
447
Chong Zhangbef461f2015-10-27 11:38:24 -0700448 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700449 * Notify that the app has stopped, and it is okay to destroy any surfaces which were
450 * keeping alive in case they were still being used.
451 */
452 void notifyAppStopped() {
453 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this);
454 mAppStopped = true;
455 destroySurfaces();
456 // Remove any starting window that was added for this app if they are still around.
457 mTask.mService.scheduleRemoveStartingWindowLocked(this);
458 }
459
460 /**
Chong Zhangbef461f2015-10-27 11:38:24 -0700461 * Checks whether we should save surfaces for this app.
462 *
463 * @return true if the surfaces should be saved, false otherwise.
464 */
465 boolean shouldSaveSurface() {
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800466 // We want to save surface if the app's windows are "allDrawn".
467 // (If we started entering animation early with saved surfaces, allDrawn
468 // should have been restored to true. So we'll save again in that case
469 // even if app didn't actually finish drawing.)
470 return allDrawn;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800471 }
472
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700473 private boolean canRestoreSurfaces() {
474 for (int i = mChildren.size() -1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700475 final WindowState w = mChildren.get(i);
Chong Zhang92147042016-05-09 12:47:11 -0700476 if (w.canRestoreSurface()) {
Robert Carr13f7be9e2015-12-02 18:39:45 -0800477 return true;
478 }
Chong Zhangbef461f2015-10-27 11:38:24 -0700479 }
480 return false;
481 }
482
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700483 private void clearWasVisibleBeforeClientHidden() {
484 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700485 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700486 w.clearWasVisibleBeforeClientHidden();
Chong Zhang92147042016-05-09 12:47:11 -0700487 }
488 }
489
Chong Zhang8e4bda92016-05-04 15:08:18 -0700490 /**
491 * Whether the app has some window that is invisible in layout, but
492 * animating with saved surface.
493 */
494 boolean isAnimatingInvisibleWithSavedSurface() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700495 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700496 final WindowState w = mChildren.get(i);
Chong Zhang8e4bda92016-05-04 15:08:18 -0700497 if (w.isAnimatingInvisibleWithSavedSurface()) {
498 return true;
499 }
500 }
501 return false;
502 }
503
504 /**
505 * Hide all window surfaces that's still invisible in layout but animating
506 * with a saved surface, and mark them destroying.
507 */
508 void stopUsingSavedSurfaceLocked() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700509 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700510 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700511 w.stopUsingSavedSurface();
Chong Zhang8e4bda92016-05-04 15:08:18 -0700512 }
513 destroySurfaces();
514 }
515
Chong Zhangf58631a2016-05-24 16:02:10 -0700516 void markSavedSurfaceExiting() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700517 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700518 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700519 w.markSavedSurfaceExiting();
Chong Zhangf58631a2016-05-24 16:02:10 -0700520 }
521 }
522
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700523 void restoreSavedSurfaceForInterestingWindows() {
Chong Zhang92147042016-05-09 12:47:11 -0700524 if (!canRestoreSurfaces()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700525 clearWasVisibleBeforeClientHidden();
Chong Zhangbef461f2015-10-27 11:38:24 -0700526 return;
527 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700528
529 // Check if all interesting windows are drawn and we can mark allDrawn=true.
530 int interestingNotDrawn = -1;
531
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700532 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700533 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700534 interestingNotDrawn = w.restoreSavedSurfaceForInterestingWindow();
Chong Zhangbef461f2015-10-27 11:38:24 -0700535 }
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800536
Chong Zhang92147042016-05-09 12:47:11 -0700537 if (!allDrawn) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700538 allDrawn = (interestingNotDrawn == 0);
Chong Zhang92147042016-05-09 12:47:11 -0700539 if (allDrawn) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700540 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Chong Zhang92147042016-05-09 12:47:11 -0700541 }
542 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700543 clearWasVisibleBeforeClientHidden();
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800544
545 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700546 "restoreSavedSurfaceForInterestingWindows: " + this + " allDrawn=" + allDrawn
547 + " interestingNotDrawn=" + interestingNotDrawn);
Chong Zhangbef461f2015-10-27 11:38:24 -0700548 }
549
550 void destroySavedSurfaces() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700551 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700552 final WindowState win = mChildren.get(i);
Robert Carr13f7be9e2015-12-02 18:39:45 -0800553 win.destroySavedSurface();
Chong Zhangbef461f2015-10-27 11:38:24 -0700554 }
Chong Zhang92147042016-05-09 12:47:11 -0700555 }
556
557 void clearAllDrawn() {
558 allDrawn = false;
559 deferClearAllDrawn = false;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700560 allDrawnExcludingSaved = false;
Chong Zhangbef461f2015-10-27 11:38:24 -0700561 }
562
Wale Ogunwalefa854eb2016-09-20 13:43:52 -0700563 void postWindowRemoveStartingWindowCleanup(WindowState win) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700564 // TODO: Something smells about the code below...Is there a better way?
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700565 if (startingWindow == win) {
566 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700567 mService.scheduleRemoveStartingWindowLocked(this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700568 } else if (mChildren.size() == 0 && startingData != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700569 // If this is the last window and we had requested a starting transition window,
570 // well there is no point now.
571 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingWindow");
572 startingData = null;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700573 } else if (mChildren.size() == 1 && startingView != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700574 // If this is the last window except for a starting transition window,
575 // we need to get rid of the starting transition.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700576 mService.scheduleRemoveStartingWindowLocked(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700577 }
578 }
579
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700580 void removeDeadWindows() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700581 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700582 WindowState win = mChildren.get(winNdx);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800583 if (win.mAppDied) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700584 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700585 "removeDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800586 // Set mDestroying, we don't want any animation or delayed removal here.
587 win.mDestroying = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700588 // Also removes child windows.
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700589 win.removeIfPossible();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800590 }
591 }
592 }
593
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700594 boolean hasWindowsAlive() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700595 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700596 // No need to loop through child windows as the answer should be the same as that of the
597 // parent window.
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700598 if (!(mChildren.get(i)).mAppDied) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700599 return true;
600 }
601 }
602 return false;
603 }
604
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700605 void setWillReplaceWindows(boolean animate) {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700606 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
607 "Marking app token " + this + " with replacing windows.");
Robert Carra1eb4392015-12-10 12:43:51 -0800608
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700609 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700610 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700611 w.setWillReplaceWindow(animate);
Robert Carra1eb4392015-12-10 12:43:51 -0800612 }
613 if (animate) {
614 // Set-up dummy animation so we can start treating windows associated with this
615 // token like they are in transition before the new app window is ready for us to
616 // run the real transition animation.
617 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700618 "setWillReplaceWindow() Setting dummy animation on: " + this);
Robert Carra1eb4392015-12-10 12:43:51 -0800619 mAppAnimator.setDummyAnimation();
620 }
621 }
622
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700623 void setWillReplaceChildWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700624 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this
Robert Carr23fa16b2016-01-13 13:19:58 -0800625 + " with replacing child windows.");
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700626 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700627 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700628 w.setWillReplaceChildWindows();
Robert Carr23fa16b2016-01-13 13:19:58 -0800629 }
630 }
631
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700632 void clearWillReplaceWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700633 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
634 "Resetting app token " + this + " of replacing window marks.");
Chong Zhangf596cd52016-01-05 13:42:44 -0800635
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700636 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700637 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700638 w.clearWillReplaceWindow();
Chong Zhangf596cd52016-01-05 13:42:44 -0800639 }
640 }
641
Chong Zhang4d7369a2016-04-25 16:09:14 -0700642 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700643 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700644 final WindowState w = mChildren.get(i);
Chong Zhang4d7369a2016-04-25 16:09:14 -0700645 w.requestUpdateWallpaperIfNeeded();
646 }
647 }
648
Chong Zhangd78ddb42016-03-02 17:01:14 -0800649 boolean isRelaunching() {
650 return mPendingRelaunchCount > 0;
651 }
652
653 void startRelaunching() {
654 if (canFreezeBounds()) {
655 freezeBounds();
656 }
657 mPendingRelaunchCount++;
658 }
659
660 void finishRelaunching() {
661 if (canFreezeBounds()) {
662 unfreezeBounds();
663 }
664 if (mPendingRelaunchCount > 0) {
665 mPendingRelaunchCount--;
666 }
667 }
668
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700669 void clearRelaunching() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700670 if (mPendingRelaunchCount == 0) {
671 return;
672 }
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700673 if (canFreezeBounds()) {
674 unfreezeBounds();
675 }
676 mPendingRelaunchCount = 0;
677 }
678
Wale Ogunwale07bcab72016-10-14 15:30:09 -0700679 /**
680 * Returns true if the new child window we are adding to this token is considered greater than
681 * the existing child window in this token in terms of z-order.
682 */
683 @Override
684 protected boolean isFirstChildWindowGreaterThanSecond(WindowState newWindow,
685 WindowState existingWindow) {
686 final int type1 = newWindow.mAttrs.type;
687 final int type2 = existingWindow.mAttrs.type;
688
689 // Base application windows should be z-ordered BELOW all other windows in the app token.
690 if (type1 == TYPE_BASE_APPLICATION && type2 != TYPE_BASE_APPLICATION) {
691 return false;
692 } else if (type1 != TYPE_BASE_APPLICATION && type2 == TYPE_BASE_APPLICATION) {
693 return true;
694 }
695
696 // Starting windows should be z-ordered ABOVE all other windows in the app token.
697 if (type1 == TYPE_APPLICATION_STARTING && type2 != TYPE_APPLICATION_STARTING) {
698 return true;
699 } else if (type1 != TYPE_APPLICATION_STARTING && type2 == TYPE_APPLICATION_STARTING) {
700 return false;
701 }
702
703 // Otherwise the new window is greater than the existing window.
704 return true;
705 }
706
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700707 @Override
Robert Carra1eb4392015-12-10 12:43:51 -0800708 void addWindow(WindowState w) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700709 super.addWindow(w);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700710
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700711 boolean gotReplacementWindow = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700712 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700713 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700714 gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w);
715 }
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700716
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700717 // if we got a replacement window, reset the timeout to give drawing more time
718 if (gotReplacementWindow) {
719 mService.scheduleWindowReplacementTimeouts(this);
Robert Carra1eb4392015-12-10 12:43:51 -0800720 }
Robert Carra1eb4392015-12-10 12:43:51 -0800721 }
722
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700723 private boolean waitingForReplacement() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700724 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700725 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700726 if (candidate.waitingForReplacement()) {
Robert Carra1eb4392015-12-10 12:43:51 -0800727 return true;
728 }
729 }
730 return false;
731 }
732
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700733 void onWindowReplacementTimeout() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700734 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700735 (mChildren.get(i)).onWindowReplacementTimeout();
Robert Carra1eb4392015-12-10 12:43:51 -0800736 }
737 }
738
Chong Zhangd78ddb42016-03-02 17:01:14 -0800739 private boolean canFreezeBounds() {
740 // For freeform windows, we can't freeze the bounds at the moment because this would make
741 // the resizing unresponsive.
742 return mTask != null && !mTask.inFreeformWorkspace();
743 }
744
Jorim Jaggi0429f352015-12-22 16:29:16 +0100745 /**
746 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
747 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
748 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
749 * with a queue.
750 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800751 private void freezeBounds() {
Jorim Jaggi0429f352015-12-22 16:29:16 +0100752 mFrozenBounds.offer(new Rect(mTask.mPreparedFrozenBounds));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700753
754 if (mTask.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) {
755 // We didn't call prepareFreezingBounds on the task, so use the current value.
Andrii Kulian441e4492016-09-29 15:25:00 -0700756 mFrozenMergedConfig.offer(new Configuration(mTask.getConfiguration()));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700757 } else {
758 mFrozenMergedConfig.offer(new Configuration(mTask.mPreparedFrozenMergedConfig));
759 }
Andrii Kulianb10330d2016-09-16 13:51:46 -0700760 // Calling unset() to make it equal to Configuration.EMPTY.
761 mTask.mPreparedFrozenMergedConfig.unset();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100762 }
763
764 /**
765 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
766 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800767 private void unfreezeBounds() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700768 if (!mFrozenBounds.isEmpty()) {
769 mFrozenBounds.remove();
770 }
771 if (!mFrozenMergedConfig.isEmpty()) {
772 mFrozenMergedConfig.remove();
773 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700774 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700775 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700776 win.onUnfreezeBounds();
Jorim Jaggi4846ee32016-01-07 17:39:12 +0100777 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700778 mService.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100779 }
780
Robert Carr91b228092016-06-28 17:32:37 -0700781 void addSurfaceViewBackground(WindowSurfaceController.SurfaceControlWithBackground background) {
782 mSurfaceViewBackgrounds.add(background);
783 }
784
785 void removeSurfaceViewBackground(WindowSurfaceController.SurfaceControlWithBackground background) {
786 mSurfaceViewBackgrounds.remove(background);
787 updateSurfaceViewBackgroundVisibilities();
788 }
789
790 // We use DimLayers behind SurfaceViews to prevent holes while resizing and creating.
791 // However, we need to ensure one SurfaceView doesn't cover another when they are both placed
792 // below the main app window (as traditionally a SurfaceView which is never drawn
793 // to is totally translucent). So we look at all our SurfaceView backgrounds and only enable
794 // the background for the SurfaceView with lowest Z order
795 void updateSurfaceViewBackgroundVisibilities() {
796 WindowSurfaceController.SurfaceControlWithBackground bottom = null;
797 int bottomLayer = Integer.MAX_VALUE;
798 for (int i = 0; i < mSurfaceViewBackgrounds.size(); i++) {
799 WindowSurfaceController.SurfaceControlWithBackground sc = mSurfaceViewBackgrounds.get(i);
800 if (sc.mVisible && sc.mLayer < bottomLayer) {
801 bottomLayer = sc.mLayer;
802 bottom = sc;
803 }
804 }
805 for (int i = 0; i < mSurfaceViewBackgrounds.size(); i++) {
806 WindowSurfaceController.SurfaceControlWithBackground sc = mSurfaceViewBackgrounds.get(i);
807 sc.updateBackgroundVisibility(sc != bottom);
808 }
809 }
810
Jorim Jaggi6626f542016-08-22 13:08:44 -0700811 /**
812 * See {@link WindowManagerService#overridePlayingAppAnimationsLw}
813 */
814 void overridePlayingAppAnimations(Animation a) {
815 if (mAppAnimator.isAnimating()) {
816 final WindowState win = findMainWindow();
Jorim Jaggi6e5f3d22016-09-28 13:30:27 +0200817 if (win == null) {
818 return;
819 }
Jorim Jaggi6626f542016-08-22 13:08:44 -0700820 final int width = win.mContainingFrame.width();
821 final int height = win.mContainingFrame.height();
822 mAppAnimator.setAnimation(a, width, height, false, STACK_CLIP_NONE);
823 }
824 }
825
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700826 void resetJustMovedInStack() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700827 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700828 (mChildren.get(i)).resetJustMovedInStack();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700829 }
830 }
831
832 void notifyMovedInStack() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700833 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700834 final WindowState win = mChildren.get(winNdx);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700835 win.notifyMovedInStack();
836 }
837 }
838
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700839 void setAppLayoutChanges(int changes, String reason) {
840 if (!mChildren.isEmpty()) {
841 final DisplayContent dc = getDisplayContent();
842 dc.pendingLayoutChanges |= changes;
843 if (DEBUG_LAYOUT_REPEATS) {
844 mService.mWindowPlacerLocked.debugLayoutRepeats(reason, dc.pendingLayoutChanges);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700845 }
846 }
847 }
848
849 void removeReplacedWindowIfNeeded(WindowState replacement) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700850 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700851 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700852 if (win.removeReplacedWindowIfNeeded(replacement)) {
853 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700854 }
855 }
856 }
857
858 void startFreezingScreen() {
859 if (DEBUG_ORIENTATION) logWithStack(TAG, "Set freezing of " + appToken + ": hidden="
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700860 + hidden + " freezing=" + mAppAnimator.freezingScreen + " hiddenRequested="
861 + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700862 if (!hiddenRequested) {
863 if (!mAppAnimator.freezingScreen) {
864 mAppAnimator.freezingScreen = true;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700865 mService.registerAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700866 mAppAnimator.lastFreezeDuration = 0;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700867 mService.mAppsFreezingScreen++;
868 if (mService.mAppsFreezingScreen == 1) {
869 mService.startFreezingDisplayLocked(false, 0, 0);
870 mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT);
871 mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700872 }
873 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700874 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700875 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700876 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700877 w.onStartFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700878 }
879 }
880 }
881
882 void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) {
883 if (!mAppAnimator.freezingScreen) {
884 return;
885 }
886 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + this + " force=" + force);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700887 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700888 boolean unfrozeWindows = false;
889 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700890 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700891 unfrozeWindows |= w.onStopFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700892 }
893 if (force || unfrozeWindows) {
894 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this);
895 mAppAnimator.freezingScreen = false;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700896 mService.unregisterAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700897 mAppAnimator.lastFreezeDuration =
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700898 (int)(SystemClock.elapsedRealtime() - mService.mDisplayFreezeTime);
899 mService.mAppsFreezingScreen--;
900 mService.mLastFinishedFreezeSource = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700901 }
902 if (unfreezeSurfaceNow) {
903 if (unfrozeWindows) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700904 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700905 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700906 mService.stopFreezingDisplayLocked();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700907 }
908 }
909
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700910 @Override
911 public void onAppFreezeTimeout() {
912 Slog.w(TAG_WM, "Force clearing freeze: " + this);
913 stopFreezingScreen(true, true);
914 }
915
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700916 boolean transferStartingWindow(IBinder transferFrom) {
Wale Ogunwale02319a62016-09-26 15:21:22 -0700917 final AppWindowToken fromToken = getDisplayContent().getAppWindowToken(transferFrom);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700918 if (fromToken == null) {
919 return false;
920 }
921
922 final WindowState tStartingWindow = fromToken.startingWindow;
923 if (tStartingWindow != null && fromToken.startingView != null) {
924 // In this case, the starting icon has already been displayed, so start
925 // letting windows get shown immediately without any more transitions.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700926 mService.mSkipAppTransitionAnimation = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700927
928 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow
929 + " from " + fromToken + " to " + this);
930
931 final long origId = Binder.clearCallingIdentity();
932
933 // Transfer the starting window over to the new token.
934 startingData = fromToken.startingData;
935 startingView = fromToken.startingView;
936 startingDisplayed = fromToken.startingDisplayed;
937 fromToken.startingDisplayed = false;
938 startingWindow = tStartingWindow;
939 reportedVisible = fromToken.reportedVisible;
940 fromToken.startingData = null;
941 fromToken.startingView = null;
942 fromToken.startingWindow = null;
943 fromToken.startingMoved = true;
944 tStartingWindow.mToken = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700945 tStartingWindow.mAppToken = this;
946
947 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
948 "Removing starting window: " + tStartingWindow);
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700949 getDisplayContent().getWindowList().remove(tStartingWindow);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700950 mService.mWindowsChanged = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700951 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
952 "Removing starting " + tStartingWindow + " from " + fromToken);
Wale Ogunwalefa854eb2016-09-20 13:43:52 -0700953 fromToken.removeChild(tStartingWindow);
954 fromToken.postWindowRemoveStartingWindowCleanup(tStartingWindow);
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700955 addWindow(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700956
957 // Propagate other interesting state between the tokens. If the old token is displayed,
958 // we should immediately force the new one to be displayed. If it is animating, we need
959 // to move that animation to the new one.
960 if (fromToken.allDrawn) {
961 allDrawn = true;
962 deferClearAllDrawn = fromToken.deferClearAllDrawn;
963 }
964 if (fromToken.firstWindowDrawn) {
965 firstWindowDrawn = true;
966 }
967 if (!fromToken.hidden) {
968 hidden = false;
969 hiddenRequested = false;
970 }
971 if (clientHidden != fromToken.clientHidden) {
972 clientHidden = fromToken.clientHidden;
973 sendAppVisibilityToClients();
974 }
975 fromToken.mAppAnimator.transferCurrentAnimation(
976 mAppAnimator, tStartingWindow.mWinAnimator);
977
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700978 mService.updateFocusedWindowLocked(
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700979 UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/);
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700980 getDisplayContent().setLayoutNeeded();
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700981 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700982 Binder.restoreCallingIdentity(origId);
983 return true;
984 } else if (fromToken.startingData != null) {
985 // The previous app was getting ready to show a
986 // starting window, but hasn't yet done so. Steal it!
987 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
988 "Moving pending starting from " + fromToken + " to " + this);
989 startingData = fromToken.startingData;
990 fromToken.startingData = null;
991 fromToken.startingMoved = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700992 final Message m = mService.mH.obtainMessage(H.ADD_STARTING, this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700993 // Note: we really want to do sendMessageAtFrontOfQueue() because we want to process the
994 // message ASAP, before any other queued messages.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700995 mService.mH.sendMessageAtFrontOfQueue(m);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700996 return true;
997 }
998
999 final AppWindowAnimator tAppAnimator = fromToken.mAppAnimator;
1000 final AppWindowAnimator wAppAnimator = mAppAnimator;
1001 if (tAppAnimator.thumbnail != null) {
1002 // The old token is animating with a thumbnail, transfer that to the new token.
1003 if (wAppAnimator.thumbnail != null) {
1004 wAppAnimator.thumbnail.destroy();
1005 }
1006 wAppAnimator.thumbnail = tAppAnimator.thumbnail;
1007 wAppAnimator.thumbnailLayer = tAppAnimator.thumbnailLayer;
1008 wAppAnimator.thumbnailAnimation = tAppAnimator.thumbnailAnimation;
1009 tAppAnimator.thumbnail = null;
1010 }
1011 return false;
1012 }
1013
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001014 boolean isLastWindow(WindowState win) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001015 return mChildren.size() == 1 && mChildren.get(0) == win;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001016 }
1017
1018 void setAllAppWinAnimators() {
1019 final ArrayList<WindowStateAnimator> allAppWinAnimators = mAppAnimator.mAllAppWinAnimators;
1020 allAppWinAnimators.clear();
1021
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001022 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001023 for (int j = 0; j < windowsCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001024 (mChildren.get(j)).addWinAnimatorToList(allAppWinAnimators);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001025 }
1026 }
1027
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001028 @Override
1029 void onAppTransitionDone() {
1030 sendingToBottom = false;
1031 }
1032
Wale Ogunwale51362492016-09-08 17:49:17 -07001033 /**
1034 * We override because this class doesn't want its children affecting its reported orientation
1035 * in anyway.
1036 */
1037 @Override
1038 int getOrientation() {
1039 if (hidden || hiddenRequested) {
1040 return SCREEN_ORIENTATION_UNSET;
1041 }
1042 return mOrientation;
1043 }
1044
Craig Mautnerdbb79912012-03-01 18:59:14 -08001045 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001046 void checkAppWindowsReadyToShow() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001047 if (allDrawn == mAppAnimator.allDrawn) {
1048 return;
1049 }
1050
1051 mAppAnimator.allDrawn = allDrawn;
1052 if (!allDrawn) {
1053 return;
1054 }
1055
1056 // The token has now changed state to having all windows shown... what to do, what to do?
1057 if (mAppAnimator.freezingScreen) {
1058 mAppAnimator.showAllWindowsLocked();
1059 stopFreezingScreen(false, true);
1060 if (DEBUG_ORIENTATION) Slog.i(TAG,
1061 "Setting mOrientationChangeComplete=true because wtoken " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001062 + " numInteresting=" + mNumInterestingWindows + " numDrawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001063 // This will set mOrientationChangeComplete and cause a pass through layout.
1064 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001065 "checkAppWindowsReadyToShow: freezingScreen");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001066 } else {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001067 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001068
1069 // We can now show all of the drawn windows!
1070 if (!mService.mOpeningApps.contains(this)) {
1071 mService.mAnimator.orAnimating(mAppAnimator.showAllWindowsLocked());
1072 }
1073 }
1074 }
1075
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001076 void updateAllDrawn(DisplayContent dc) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001077 if (!allDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001078 final int numInteresting = mNumInterestingWindows;
1079 if (numInteresting > 0 && mNumDrawnWindows >= numInteresting) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001080 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawn: " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001081 + " interesting=" + numInteresting + " drawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001082 allDrawn = true;
1083 // Force an additional layout pass where
1084 // WindowStateAnimator#commitFinishDrawingLocked() will call performShowLocked().
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001085 dc.setLayoutNeeded();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001086 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
1087 }
1088 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001089
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001090 if (!allDrawnExcludingSaved) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001091 int numInteresting = mNumInterestingWindowsExcludingSaved;
1092 if (numInteresting > 0 && mNumDrawnWindowsExcludingSaved >= numInteresting) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001093 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawnExcludingSaved: " + this
1094 + " interesting=" + numInteresting
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001095 + " drawn=" + mNumDrawnWindowsExcludingSaved);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001096 allDrawnExcludingSaved = true;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001097 dc.setLayoutNeeded();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001098 if (isAnimatingInvisibleWithSavedSurface()
1099 && !mService.mFinishedEarlyAnim.contains(this)) {
1100 mService.mFinishedEarlyAnim.add(this);
1101 }
1102 }
1103 }
1104 }
1105
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001106 /**
1107 * Updated this app token tracking states for interesting and drawn windows based on the window.
1108 *
1109 * @return Returns true if the input window is considered interesting and drawn while all the
1110 * windows in this app token where not considered drawn as of the last pass.
1111 */
1112 boolean updateDrawnWindowStates(WindowState w) {
1113 if (DEBUG_STARTING_WINDOW && w == startingWindow) {
1114 Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" + w.isOnScreen()
1115 + " allDrawn=" + allDrawn + " freezingScreen=" + mAppAnimator.freezingScreen);
1116 }
1117
1118 if (allDrawn && allDrawnExcludingSaved && !mAppAnimator.freezingScreen) {
1119 return false;
1120 }
1121
1122 if (mLastTransactionSequence != mService.mTransactionSequence) {
1123 mLastTransactionSequence = mService.mTransactionSequence;
1124 mNumInterestingWindows = mNumDrawnWindows = 0;
1125 mNumInterestingWindowsExcludingSaved = 0;
1126 mNumDrawnWindowsExcludingSaved = 0;
1127 startingDisplayed = false;
1128 }
1129
1130 final WindowStateAnimator winAnimator = w.mWinAnimator;
1131
1132 boolean isInterestingAndDrawn = false;
1133
1134 if (!allDrawn && w.mightAffectAllDrawn(false /* visibleOnly */)) {
1135 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
1136 Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw()
1137 + ", isAnimationSet=" + winAnimator.isAnimationSet());
1138 if (!w.isDrawnLw()) {
1139 Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController
1140 + " pv=" + w.mPolicyVisibility
1141 + " mDrawState=" + winAnimator.drawStateToString()
1142 + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested
1143 + " a=" + winAnimator.mAnimating);
1144 }
1145 }
1146
1147 if (w != startingWindow) {
1148 if (w.isInteresting()) {
1149 mNumInterestingWindows++;
1150 if (w.isDrawnLw()) {
1151 mNumDrawnWindows++;
1152
1153 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, "tokenMayBeDrawn: "
1154 + this + " w=" + w + " numInteresting=" + mNumInterestingWindows
1155 + " freezingScreen=" + mAppAnimator.freezingScreen
1156 + " mAppFreezing=" + w.mAppFreezing);
1157
1158 isInterestingAndDrawn = true;
1159 }
1160 }
1161 } else if (w.isDrawnLw()) {
1162 mService.mH.sendEmptyMessage(NOTIFY_STARTING_WINDOW_DRAWN);
1163 startingDisplayed = true;
1164 }
1165 }
1166
1167 if (!allDrawnExcludingSaved && w.mightAffectAllDrawn(true /* visibleOnly */)) {
1168 if (w != startingWindow && w.isInteresting()) {
1169 mNumInterestingWindowsExcludingSaved++;
1170 if (w.isDrawnLw() && !w.isAnimatingWithSavedSurface()) {
1171 mNumDrawnWindowsExcludingSaved++;
1172
1173 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
1174 "tokenMayBeDrawnExcludingSaved: " + this + " w=" + w
1175 + " numInteresting=" + mNumInterestingWindowsExcludingSaved
1176 + " freezingScreen=" + mAppAnimator.freezingScreen
1177 + " mAppFreezing=" + w.mAppFreezing);
1178
1179 isInterestingAndDrawn = true;
1180 }
1181 }
1182 }
1183
1184 return isInterestingAndDrawn;
1185 }
1186
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001187 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001188 void stepAppWindowsAnimation(long currentTime) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001189 mAppAnimator.wasAnimating = mAppAnimator.animating;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001190 if (mAppAnimator.stepAnimationLocked(currentTime)) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001191 mAppAnimator.animating = true;
1192 mService.mAnimator.setAnimating(true);
1193 mService.mAnimator.mAppWindowAnimating = true;
1194 } else if (mAppAnimator.wasAnimating) {
1195 // stopped animating, do one more pass through the layout
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001196 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER, "appToken " + this + " done");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001197 if (DEBUG_ANIM) Slog.v(TAG, "updateWindowsApps...: done animating " + this);
1198 }
1199 }
1200
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001201 int rebuildWindowListUnchecked(int addIndex) {
1202 return super.rebuildWindowList(addIndex);
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001203 }
1204
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001205 @Override
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001206 int rebuildWindowList(int addIndex) {
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001207 if (mIsExiting && !waitingForReplacement()) {
1208 return addIndex;
1209 }
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001210 return rebuildWindowListUnchecked(addIndex);
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001211 }
1212
1213 @Override
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001214 AppWindowToken asAppWindowToken() {
1215 // I am an app window token!
1216 return this;
1217 }
1218
1219 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -07001220 boolean fillsParent() {
1221 return mFillsParent;
1222 }
1223
1224 void setFillsParent(boolean fillsParent) {
1225 mFillsParent = fillsParent;
1226 }
1227
1228 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001229 void dump(PrintWriter pw, String prefix) {
1230 super.dump(pw, prefix);
1231 if (appToken != null) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001232 pw.print(prefix); pw.print("app=true voiceInteraction="); pw.println(voiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001233 }
Craig Mautner83162a92015-01-26 14:43:30 -08001234 pw.print(prefix); pw.print("task="); pw.println(mTask);
Wale Ogunwale51362492016-09-08 17:49:17 -07001235 pw.print(prefix); pw.print(" mFillsParent="); pw.print(mFillsParent);
1236 pw.print(" mOrientation="); pw.println(mOrientation);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001237 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
1238 pw.print(" clientHidden="); pw.print(clientHidden);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -07001239 pw.print(" reportedDrawn="); pw.print(reportedDrawn);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001240 pw.print(" reportedVisible="); pw.println(reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -07001241 if (paused) {
1242 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001243 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001244 if (mAppStopped) {
1245 pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped);
1246 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001247 if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0
Craig Mautner6fbda632012-07-03 09:26:39 -07001248 || allDrawn || mAppAnimator.allDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001249 pw.print(prefix); pw.print("mNumInterestingWindows=");
1250 pw.print(mNumInterestingWindows);
1251 pw.print(" mNumDrawnWindows="); pw.print(mNumDrawnWindows);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001252 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -07001253 pw.print(" allDrawn="); pw.print(allDrawn);
1254 pw.print(" (animator="); pw.print(mAppAnimator.allDrawn);
1255 pw.println(")");
1256 }
1257 if (inPendingTransaction) {
1258 pw.print(prefix); pw.print("inPendingTransaction=");
1259 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001260 }
Craig Mautner799bc1d2015-01-14 10:33:48 -08001261 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001262 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
1263 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -08001264 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -08001265 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001266 }
1267 if (startingWindow != null || startingView != null
1268 || startingDisplayed || startingMoved) {
1269 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
1270 pw.print(" startingView="); pw.print(startingView);
1271 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001272 pw.print(" startingMoved="); pw.println(startingMoved);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001273 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01001274 if (!mFrozenBounds.isEmpty()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -08001275 pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds);
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001276 pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig);
Chong Zhangd78ddb42016-03-02 17:01:14 -08001277 }
1278 if (mPendingRelaunchCount != 0) {
1279 pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount);
Jorim Jaggi0429f352015-12-22 16:29:16 +01001280 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001281 }
1282
1283 @Override
1284 public String toString() {
1285 if (stringName == null) {
1286 StringBuilder sb = new StringBuilder();
1287 sb.append("AppWindowToken{");
1288 sb.append(Integer.toHexString(System.identityHashCode(this)));
1289 sb.append(" token="); sb.append(token); sb.append('}');
1290 stringName = sb.toString();
1291 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001292 return stringName + ((mIsExiting) ? " mIsExiting=" : "");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001293 }
Jeff Browne9bdb312012-04-05 15:30:10 -07001294}