blob: 508cf24a7cab532ffe178d07abe0d63f29f731ac [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 Ogunwaled1c37912016-08-16 03:19:39 -0700161 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean _voiceInteraction) {
162 super(service, token != null ? token.asBinder() : null, TYPE_APPLICATION, true);
163 appToken = token;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700164 voiceInteraction = _voiceInteraction;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800165 mInputApplicationHandle = new InputApplicationHandle(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700166 mAppAnimator = new AppWindowAnimator(this, service);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800167 }
168
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800169 void onFirstWindowDrawn(WindowState win, WindowStateAnimator winAnimator) {
170 firstWindowDrawn = true;
171
172 // We now have a good window to show, remove dead placeholders
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700173 removeDeadWindows();
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800174
175 if (startingData != null) {
176 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, "Finish starting "
177 + win.mToken + ": first real window is shown, no animation");
178 // If this initial window is animating, stop it -- we will do an animation to reveal
179 // it from behind the starting window, so there is no need for it to also be doing its
180 // own stuff.
181 winAnimator.clearAnimation();
182 winAnimator.mService.mFinishedStarting.add(this);
183 winAnimator.mService.mH.sendEmptyMessage(H.FINISHED_STARTING);
184 }
185 updateReportedVisibilityLocked();
186 }
187
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800188 void updateReportedVisibilityLocked() {
189 if (appToken == null) {
190 return;
191 }
192
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700193 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700194 final int count = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800195
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700196 mReportedVisibilityResults.reset();
197
198 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700199 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700200 win.updateReportedVisibility(mReportedVisibilityResults);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800201 }
202
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700203 int numInteresting = mReportedVisibilityResults.numInteresting;
204 int numVisible = mReportedVisibilityResults.numVisible;
205 int numDrawn = mReportedVisibilityResults.numDrawn;
206 boolean nowGone = mReportedVisibilityResults.nowGone;
207
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700208 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800209 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700210 if (!nowGone) {
211 // If the app is not yet gone, then it can only become visible/drawn.
212 if (!nowDrawn) {
213 nowDrawn = reportedDrawn;
214 }
215 if (!nowVisible) {
216 nowVisible = reportedVisible;
217 }
218 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800219 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800220 + numInteresting + " visible=" + numVisible);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700221 if (nowDrawn != reportedDrawn) {
222 if (nowDrawn) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700223 mService.mH.obtainMessage(H.REPORT_APPLICATION_TOKEN_DRAWN, this).sendToTarget();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700224 }
225 reportedDrawn = nowDrawn;
226 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800227 if (nowVisible != reportedVisible) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700228 if (DEBUG_VISIBILITY) Slog.v(TAG,
229 "Visibility changed in " + this + ": vis=" + nowVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800230 reportedVisible = nowVisible;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700231 mService.mH.obtainMessage(H.REPORT_APPLICATION_TOKEN_WINDOWS,
232 nowVisible ? 1 : 0, nowGone ? 1 : 0, this).sendToTarget();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800233 }
234 }
235
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700236 boolean setVisibility(WindowManager.LayoutParams lp,
237 boolean visible, int transit, boolean performLayout, boolean isVoiceInteraction) {
238
239 boolean delayed = false;
240 inPendingTransaction = false;
241
242 if (clientHidden == visible) {
243 clientHidden = !visible;
244 sendAppVisibilityToClients();
245 }
246
247 // Allow for state changes and animation to be applied if:
248 // * token is transitioning visibility state
249 // * or the token was marked as hidden and is exiting before we had a chance to play the
250 // transition animation
251 // * or this is an opening app and windows are being replaced.
252 boolean visibilityChanged = false;
253 if (hidden == visible || (hidden && mIsExiting) || (visible && waitingForReplacement())) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700254 final AccessibilityController accessibilityController = mService.mAccessibilityController;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700255 boolean changed = false;
256 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
257 "Changing app " + this + " hidden=" + hidden + " performLayout=" + performLayout);
258
259 boolean runningAppAnimation = false;
260
261 if (transit != AppTransition.TRANSIT_UNSET) {
262 if (mAppAnimator.animation == AppWindowAnimator.sDummyAnimation) {
263 mAppAnimator.setNullAnimation();
264 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700265 if (mService.applyAnimationLocked(this, lp, transit, visible, isVoiceInteraction)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700266 delayed = runningAppAnimation = true;
267 }
268 final WindowState window = findMainWindow();
269 //TODO (multidisplay): Magnification is supported only for the default display.
270 if (window != null && accessibilityController != null
271 && window.getDisplayId() == DEFAULT_DISPLAY) {
272 accessibilityController.onAppWindowTransitionLocked(window, transit);
273 }
274 changed = true;
275 }
276
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700277 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700278 for (int i = 0; i < windowsCount; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700279 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700280 changed |= win.onAppVisibilityChanged(visible, runningAppAnimation);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700281 }
282
283 hidden = hiddenRequested = !visible;
284 visibilityChanged = true;
285 if (!visible) {
286 stopFreezingScreen(true, true);
287 } else {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700288 // If we are being set visible, and the starting window is not yet displayed,
289 // then make sure it doesn't get displayed.
290 if (startingWindow != null && !startingWindow.isDrawnLw()) {
291 startingWindow.mPolicyVisibility = false;
292 startingWindow.mPolicyVisibilityAfterAnim = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700293 }
294 }
295
296 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setVisibility: " + this
297 + ": hidden=" + hidden + " hiddenRequested=" + hiddenRequested);
298
299 if (changed) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700300 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700301 if (performLayout) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700302 mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700303 false /*updateInputWindows*/);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700304 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700305 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700306 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700307 }
308 }
309
310 if (mAppAnimator.animation != null) {
311 delayed = true;
312 }
313
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700314 for (int i = mChildren.size() - 1; i >= 0 && !delayed; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700315 if ((mChildren.get(i)).isWindowAnimationSet()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700316 delayed = true;
317 }
318 }
319
320 if (visibilityChanged) {
321 if (visible && !delayed) {
322 // The token was made immediately visible, there will be no entrance animation.
323 // We need to inform the client the enter animation was finished.
324 mEnteringAnimation = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700325 mService.mActivityManagerAppTransitionNotifier.onAppTransitionFinishedLocked(token);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700326 }
327
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700328 if (!mService.mClosingApps.contains(this) && !mService.mOpeningApps.contains(this)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700329 // The token is not closing nor opening, so even if there is an animation set, that
330 // doesn't mean that it goes through the normal app transition cycle so we have
331 // to inform the docked controller about visibility change.
Andrii Kulian1e32e022016-09-16 15:29:34 -0700332 // TODO(multi-display): notify docked divider on all displays where visibility was
333 // affected.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700334 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700335 .notifyAppVisibilityChanged();
336 }
337 }
338
339 return delayed;
340 }
341
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800342 WindowState findMainWindow() {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700343 WindowState candidate = null;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700344 int j = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800345 while (j > 0) {
346 j--;
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700347 final WindowState win = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700348 final int type = win.mAttrs.type;
349 // No need to loop through child window as base application and starting types can't be
350 // child windows.
351 if (type == TYPE_BASE_APPLICATION || type == TYPE_APPLICATION_STARTING) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700352 // In cases where there are multiple windows, we prefer the non-exiting window. This
Sungsoo Lim0d3d1f82015-12-02 14:47:59 +0900353 // happens for example when replacing windows during an activity relaunch. When
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700354 // constructing the animation, we want the new window, not the exiting one.
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800355 if (win.mAnimatingExit) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700356 candidate = win;
357 } else {
358 return win;
359 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800360 }
361 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700362 return candidate;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800363 }
364
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800365 boolean windowsAreFocusable() {
366 return StackId.canReceiveKeys(mTask.mStack.mStackId) || mAlwaysFocusable;
Wale Ogunwaled045c822015-12-02 09:14:28 -0800367 }
368
Wale Ogunwale571771c2016-08-26 13:18:50 -0700369 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -0700370 boolean isVisible() {
Wale Ogunwalee471be62016-10-03 07:53:55 -0700371 // If the app token isn't hidden then it is considered visible and there is no need to check
372 // its children windows to see if they are visible.
373 return !hidden;
Wale Ogunwale44f21802016-09-02 12:49:48 -0700374 }
375
376 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -0700377 void removeIfPossible() {
Craig Mautnere3119b72015-01-20 15:02:36 -0800378 mIsExiting = false;
379 removeAllWindows();
Wale Ogunwale571771c2016-08-26 13:18:50 -0700380 if (mTask != null) {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700381 mTask.mStack.mExitingAppTokens.remove(this);
382 mTask.removeChild(this);
Craig Mautnere3119b72015-01-20 15:02:36 -0800383 }
384 }
385
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700386 @Override
387 boolean checkCompleteDeferredRemoval() {
388 if (mIsExiting) {
389 removeIfPossible();
390 }
391 return super.checkCompleteDeferredRemoval();
392 }
393
Chong Zhange05bcb12016-07-26 17:47:29 -0700394 void clearAnimatingFlags() {
Chong Zhangb0d26702016-08-12 16:03:29 -0700395 boolean wallpaperMightChange = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700396 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700397 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700398 wallpaperMightChange |= win.clearAnimatingFlags();
Chong Zhange05bcb12016-07-26 17:47:29 -0700399 }
Chong Zhangb0d26702016-08-12 16:03:29 -0700400 if (wallpaperMightChange) {
401 requestUpdateWallpaperIfNeeded();
402 }
Chong Zhange05bcb12016-07-26 17:47:29 -0700403 }
404
Robert Carre12aece2016-02-02 22:43:27 -0800405 void destroySurfaces() {
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700406 destroySurfaces(false /*cleanupOnResume*/);
407 }
408
409 /**
410 * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure
411 * the client has finished with them.
412 *
413 * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If
414 * set to true, destroy only surfaces of removed windows, and clear relevant flags of the
415 * others so that they are ready to be reused. If set to false (common case), destroy all
416 * surfaces that's eligible, if the app is already stopped.
417 */
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700418 private void destroySurfaces(boolean cleanupOnResume) {
Robert Carre12aece2016-02-02 22:43:27 -0800419 final DisplayContentList displayList = new DisplayContentList();
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700420 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700421 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700422 final boolean destroyed = win.destroySurface(cleanupOnResume, mAppStopped);
Chong Zhangeb665572016-05-09 18:28:27 -0700423
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700424 if (destroyed) {
425 final DisplayContent displayContent = win.getDisplayContent();
426 if (displayContent != null && !displayList.contains(displayContent)) {
427 displayList.add(displayContent);
428 }
Robert Carre12aece2016-02-02 22:43:27 -0800429 }
Robert Carre12aece2016-02-02 22:43:27 -0800430 }
431 for (int i = 0; i < displayList.size(); i++) {
432 final DisplayContent displayContent = displayList.get(i);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700433 mService.mLayersController.assignLayersLocked(displayContent.getWindowList());
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700434 displayContent.setLayoutNeeded();
Robert Carre12aece2016-02-02 22:43:27 -0800435 }
436 }
437
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800438 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700439 * Notify that the app is now resumed, and it was not stopped before, perform a clean
440 * up of the surfaces
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800441 */
Chong Zhangad24f962016-08-25 12:12:33 -0700442 void notifyAppResumed(boolean wasStopped, boolean allowSavedSurface) {
443 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped
444 + " allowSavedSurface=" + allowSavedSurface + " " + this);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700445 mAppStopped = false;
446 if (!wasStopped) {
447 destroySurfaces(true /*cleanupOnResume*/);
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800448 }
Chong Zhangad24f962016-08-25 12:12:33 -0700449 if (!allowSavedSurface) {
450 destroySavedSurfaces();
451 }
Robert Carre12aece2016-02-02 22:43:27 -0800452 }
453
Chong Zhangbef461f2015-10-27 11:38:24 -0700454 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700455 * Notify that the app has stopped, and it is okay to destroy any surfaces which were
456 * keeping alive in case they were still being used.
457 */
458 void notifyAppStopped() {
459 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this);
460 mAppStopped = true;
461 destroySurfaces();
462 // Remove any starting window that was added for this app if they are still around.
463 mTask.mService.scheduleRemoveStartingWindowLocked(this);
464 }
465
466 /**
Chong Zhangbef461f2015-10-27 11:38:24 -0700467 * Checks whether we should save surfaces for this app.
468 *
469 * @return true if the surfaces should be saved, false otherwise.
470 */
471 boolean shouldSaveSurface() {
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800472 // We want to save surface if the app's windows are "allDrawn".
473 // (If we started entering animation early with saved surfaces, allDrawn
474 // should have been restored to true. So we'll save again in that case
475 // even if app didn't actually finish drawing.)
476 return allDrawn;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800477 }
478
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700479 private boolean canRestoreSurfaces() {
480 for (int i = mChildren.size() -1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700481 final WindowState w = mChildren.get(i);
Chong Zhang92147042016-05-09 12:47:11 -0700482 if (w.canRestoreSurface()) {
Robert Carr13f7be9e2015-12-02 18:39:45 -0800483 return true;
484 }
Chong Zhangbef461f2015-10-27 11:38:24 -0700485 }
486 return false;
487 }
488
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700489 private void clearWasVisibleBeforeClientHidden() {
490 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700491 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700492 w.clearWasVisibleBeforeClientHidden();
Chong Zhang92147042016-05-09 12:47:11 -0700493 }
494 }
495
Chong Zhang8e4bda92016-05-04 15:08:18 -0700496 /**
497 * Whether the app has some window that is invisible in layout, but
498 * animating with saved surface.
499 */
500 boolean isAnimatingInvisibleWithSavedSurface() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700501 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700502 final WindowState w = mChildren.get(i);
Chong Zhang8e4bda92016-05-04 15:08:18 -0700503 if (w.isAnimatingInvisibleWithSavedSurface()) {
504 return true;
505 }
506 }
507 return false;
508 }
509
510 /**
511 * Hide all window surfaces that's still invisible in layout but animating
512 * with a saved surface, and mark them destroying.
513 */
514 void stopUsingSavedSurfaceLocked() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700515 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700516 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700517 w.stopUsingSavedSurface();
Chong Zhang8e4bda92016-05-04 15:08:18 -0700518 }
519 destroySurfaces();
520 }
521
Chong Zhangf58631a2016-05-24 16:02:10 -0700522 void markSavedSurfaceExiting() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700523 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700524 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700525 w.markSavedSurfaceExiting();
Chong Zhangf58631a2016-05-24 16:02:10 -0700526 }
527 }
528
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700529 void restoreSavedSurfaceForInterestingWindows() {
Chong Zhang92147042016-05-09 12:47:11 -0700530 if (!canRestoreSurfaces()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700531 clearWasVisibleBeforeClientHidden();
Chong Zhangbef461f2015-10-27 11:38:24 -0700532 return;
533 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700534
535 // Check if all interesting windows are drawn and we can mark allDrawn=true.
536 int interestingNotDrawn = -1;
537
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700538 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700539 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700540 interestingNotDrawn = w.restoreSavedSurfaceForInterestingWindow();
Chong Zhangbef461f2015-10-27 11:38:24 -0700541 }
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800542
Chong Zhang92147042016-05-09 12:47:11 -0700543 if (!allDrawn) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700544 allDrawn = (interestingNotDrawn == 0);
Chong Zhang92147042016-05-09 12:47:11 -0700545 if (allDrawn) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700546 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Chong Zhang92147042016-05-09 12:47:11 -0700547 }
548 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700549 clearWasVisibleBeforeClientHidden();
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800550
551 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700552 "restoreSavedSurfaceForInterestingWindows: " + this + " allDrawn=" + allDrawn
553 + " interestingNotDrawn=" + interestingNotDrawn);
Chong Zhangbef461f2015-10-27 11:38:24 -0700554 }
555
556 void destroySavedSurfaces() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700557 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700558 final WindowState win = mChildren.get(i);
Robert Carr13f7be9e2015-12-02 18:39:45 -0800559 win.destroySavedSurface();
Chong Zhangbef461f2015-10-27 11:38:24 -0700560 }
Chong Zhang92147042016-05-09 12:47:11 -0700561 }
562
563 void clearAllDrawn() {
564 allDrawn = false;
565 deferClearAllDrawn = false;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700566 allDrawnExcludingSaved = false;
Chong Zhangbef461f2015-10-27 11:38:24 -0700567 }
568
Wale Ogunwalefa854eb2016-09-20 13:43:52 -0700569 void postWindowRemoveStartingWindowCleanup(WindowState win) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700570 // TODO: Something smells about the code below...Is there a better way?
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700571 if (startingWindow == win) {
572 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700573 mService.scheduleRemoveStartingWindowLocked(this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700574 } else if (mChildren.size() == 0 && startingData != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700575 // If this is the last window and we had requested a starting transition window,
576 // well there is no point now.
577 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingWindow");
578 startingData = null;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700579 } else if (mChildren.size() == 1 && startingView != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700580 // If this is the last window except for a starting transition window,
581 // we need to get rid of the starting transition.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700582 mService.scheduleRemoveStartingWindowLocked(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700583 }
584 }
585
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700586 void removeDeadWindows() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700587 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700588 WindowState win = mChildren.get(winNdx);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800589 if (win.mAppDied) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700590 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700591 "removeDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800592 // Set mDestroying, we don't want any animation or delayed removal here.
593 win.mDestroying = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700594 // Also removes child windows.
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700595 win.removeIfPossible();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800596 }
597 }
598 }
599
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700600 boolean hasWindowsAlive() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700601 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700602 // No need to loop through child windows as the answer should be the same as that of the
603 // parent window.
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700604 if (!(mChildren.get(i)).mAppDied) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700605 return true;
606 }
607 }
608 return false;
609 }
610
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700611 void setWillReplaceWindows(boolean animate) {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700612 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
613 "Marking app token " + this + " with replacing windows.");
Robert Carra1eb4392015-12-10 12:43:51 -0800614
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700615 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700616 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700617 w.setWillReplaceWindow(animate);
Robert Carra1eb4392015-12-10 12:43:51 -0800618 }
619 if (animate) {
620 // Set-up dummy animation so we can start treating windows associated with this
621 // token like they are in transition before the new app window is ready for us to
622 // run the real transition animation.
623 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700624 "setWillReplaceWindow() Setting dummy animation on: " + this);
Robert Carra1eb4392015-12-10 12:43:51 -0800625 mAppAnimator.setDummyAnimation();
626 }
627 }
628
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700629 void setWillReplaceChildWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700630 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this
Robert Carr23fa16b2016-01-13 13:19:58 -0800631 + " with replacing child windows.");
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700632 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700633 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700634 w.setWillReplaceChildWindows();
Robert Carr23fa16b2016-01-13 13:19:58 -0800635 }
636 }
637
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700638 void clearWillReplaceWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700639 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
640 "Resetting app token " + this + " of replacing window marks.");
Chong Zhangf596cd52016-01-05 13:42:44 -0800641
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700642 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700643 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700644 w.clearWillReplaceWindow();
Chong Zhangf596cd52016-01-05 13:42:44 -0800645 }
646 }
647
Chong Zhang4d7369a2016-04-25 16:09:14 -0700648 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700649 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700650 final WindowState w = mChildren.get(i);
Chong Zhang4d7369a2016-04-25 16:09:14 -0700651 w.requestUpdateWallpaperIfNeeded();
652 }
653 }
654
Chong Zhangd78ddb42016-03-02 17:01:14 -0800655 boolean isRelaunching() {
656 return mPendingRelaunchCount > 0;
657 }
658
659 void startRelaunching() {
660 if (canFreezeBounds()) {
661 freezeBounds();
662 }
663 mPendingRelaunchCount++;
664 }
665
666 void finishRelaunching() {
667 if (canFreezeBounds()) {
668 unfreezeBounds();
669 }
670 if (mPendingRelaunchCount > 0) {
671 mPendingRelaunchCount--;
672 }
673 }
674
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700675 void clearRelaunching() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700676 if (mPendingRelaunchCount == 0) {
677 return;
678 }
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700679 if (canFreezeBounds()) {
680 unfreezeBounds();
681 }
682 mPendingRelaunchCount = 0;
683 }
684
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700685 @Override
Robert Carra1eb4392015-12-10 12:43:51 -0800686 void addWindow(WindowState w) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700687 super.addWindow(w);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700688
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700689 boolean gotReplacementWindow = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700690 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700691 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700692 gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w);
693 }
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700694
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700695 // if we got a replacement window, reset the timeout to give drawing more time
696 if (gotReplacementWindow) {
697 mService.scheduleWindowReplacementTimeouts(this);
Robert Carra1eb4392015-12-10 12:43:51 -0800698 }
Robert Carra1eb4392015-12-10 12:43:51 -0800699 }
700
701 boolean waitingForReplacement() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700702 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700703 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700704 if (candidate.waitingForReplacement()) {
Robert Carra1eb4392015-12-10 12:43:51 -0800705 return true;
706 }
707 }
708 return false;
709 }
710
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700711 void onWindowReplacementTimeout() {
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 (mChildren.get(i)).onWindowReplacementTimeout();
Robert Carra1eb4392015-12-10 12:43:51 -0800714 }
715 }
716
Chong Zhangd78ddb42016-03-02 17:01:14 -0800717 private boolean canFreezeBounds() {
718 // For freeform windows, we can't freeze the bounds at the moment because this would make
719 // the resizing unresponsive.
720 return mTask != null && !mTask.inFreeformWorkspace();
721 }
722
Jorim Jaggi0429f352015-12-22 16:29:16 +0100723 /**
724 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
725 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
726 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
727 * with a queue.
728 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800729 private void freezeBounds() {
Jorim Jaggi0429f352015-12-22 16:29:16 +0100730 mFrozenBounds.offer(new Rect(mTask.mPreparedFrozenBounds));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700731
732 if (mTask.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) {
733 // We didn't call prepareFreezingBounds on the task, so use the current value.
Andrii Kulian441e4492016-09-29 15:25:00 -0700734 mFrozenMergedConfig.offer(new Configuration(mTask.getConfiguration()));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700735 } else {
736 mFrozenMergedConfig.offer(new Configuration(mTask.mPreparedFrozenMergedConfig));
737 }
Andrii Kulianb10330d2016-09-16 13:51:46 -0700738 // Calling unset() to make it equal to Configuration.EMPTY.
739 mTask.mPreparedFrozenMergedConfig.unset();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100740 }
741
742 /**
743 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
744 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800745 private void unfreezeBounds() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700746 if (!mFrozenBounds.isEmpty()) {
747 mFrozenBounds.remove();
748 }
749 if (!mFrozenMergedConfig.isEmpty()) {
750 mFrozenMergedConfig.remove();
751 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700752 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700753 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700754 win.onUnfreezeBounds();
Jorim Jaggi4846ee32016-01-07 17:39:12 +0100755 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700756 mService.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100757 }
758
Robert Carr91b228092016-06-28 17:32:37 -0700759 void addSurfaceViewBackground(WindowSurfaceController.SurfaceControlWithBackground background) {
760 mSurfaceViewBackgrounds.add(background);
761 }
762
763 void removeSurfaceViewBackground(WindowSurfaceController.SurfaceControlWithBackground background) {
764 mSurfaceViewBackgrounds.remove(background);
765 updateSurfaceViewBackgroundVisibilities();
766 }
767
768 // We use DimLayers behind SurfaceViews to prevent holes while resizing and creating.
769 // However, we need to ensure one SurfaceView doesn't cover another when they are both placed
770 // below the main app window (as traditionally a SurfaceView which is never drawn
771 // to is totally translucent). So we look at all our SurfaceView backgrounds and only enable
772 // the background for the SurfaceView with lowest Z order
773 void updateSurfaceViewBackgroundVisibilities() {
774 WindowSurfaceController.SurfaceControlWithBackground bottom = null;
775 int bottomLayer = Integer.MAX_VALUE;
776 for (int i = 0; i < mSurfaceViewBackgrounds.size(); i++) {
777 WindowSurfaceController.SurfaceControlWithBackground sc = mSurfaceViewBackgrounds.get(i);
778 if (sc.mVisible && sc.mLayer < bottomLayer) {
779 bottomLayer = sc.mLayer;
780 bottom = sc;
781 }
782 }
783 for (int i = 0; i < mSurfaceViewBackgrounds.size(); i++) {
784 WindowSurfaceController.SurfaceControlWithBackground sc = mSurfaceViewBackgrounds.get(i);
785 sc.updateBackgroundVisibility(sc != bottom);
786 }
787 }
788
Jorim Jaggi6626f542016-08-22 13:08:44 -0700789 /**
790 * See {@link WindowManagerService#overridePlayingAppAnimationsLw}
791 */
792 void overridePlayingAppAnimations(Animation a) {
793 if (mAppAnimator.isAnimating()) {
794 final WindowState win = findMainWindow();
Jorim Jaggi6e5f3d22016-09-28 13:30:27 +0200795 if (win == null) {
796 return;
797 }
Jorim Jaggi6626f542016-08-22 13:08:44 -0700798 final int width = win.mContainingFrame.width();
799 final int height = win.mContainingFrame.height();
800 mAppAnimator.setAnimation(a, width, height, false, STACK_CLIP_NONE);
801 }
802 }
803
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700804 void resetJustMovedInStack() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700805 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700806 (mChildren.get(i)).resetJustMovedInStack();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700807 }
808 }
809
810 void notifyMovedInStack() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700811 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700812 final WindowState win = mChildren.get(winNdx);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700813 win.notifyMovedInStack();
814 }
815 }
816
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700817 void setAppLayoutChanges(int changes, String reason, int displayId) {
818 final WindowAnimator windowAnimator = mAppAnimator.mAnimator;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700819 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700820 // Child windows will be on the same display as their parents.
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700821 if (displayId == (mChildren.get(i)).getDisplayId()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700822 windowAnimator.setPendingLayoutChanges(displayId, changes);
823 if (DEBUG_LAYOUT_REPEATS) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700824 mService.mWindowPlacerLocked.debugLayoutRepeats(
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700825 reason, windowAnimator.getPendingLayoutChanges(displayId));
826 }
827 break;
828 }
829 }
830 }
831
832 void removeReplacedWindowIfNeeded(WindowState replacement) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700833 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700834 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700835 if (win.removeReplacedWindowIfNeeded(replacement)) {
836 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700837 }
838 }
839 }
840
841 void startFreezingScreen() {
842 if (DEBUG_ORIENTATION) logWithStack(TAG, "Set freezing of " + appToken + ": hidden="
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700843 + hidden + " freezing=" + mAppAnimator.freezingScreen + " hiddenRequested="
844 + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700845 if (!hiddenRequested) {
846 if (!mAppAnimator.freezingScreen) {
847 mAppAnimator.freezingScreen = true;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700848 mService.registerAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700849 mAppAnimator.lastFreezeDuration = 0;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700850 mService.mAppsFreezingScreen++;
851 if (mService.mAppsFreezingScreen == 1) {
852 mService.startFreezingDisplayLocked(false, 0, 0);
853 mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT);
854 mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700855 }
856 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700857 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700858 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700859 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700860 w.onStartFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700861 }
862 }
863 }
864
865 void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) {
866 if (!mAppAnimator.freezingScreen) {
867 return;
868 }
869 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + this + " force=" + force);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700870 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700871 boolean unfrozeWindows = false;
872 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700873 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700874 unfrozeWindows |= w.onStopFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700875 }
876 if (force || unfrozeWindows) {
877 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this);
878 mAppAnimator.freezingScreen = false;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700879 mService.unregisterAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700880 mAppAnimator.lastFreezeDuration =
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700881 (int)(SystemClock.elapsedRealtime() - mService.mDisplayFreezeTime);
882 mService.mAppsFreezingScreen--;
883 mService.mLastFinishedFreezeSource = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700884 }
885 if (unfreezeSurfaceNow) {
886 if (unfrozeWindows) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700887 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700888 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700889 mService.stopFreezingDisplayLocked();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700890 }
891 }
892
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700893 @Override
894 public void onAppFreezeTimeout() {
895 Slog.w(TAG_WM, "Force clearing freeze: " + this);
896 stopFreezingScreen(true, true);
897 }
898
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700899 boolean transferStartingWindow(IBinder transferFrom) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700900 final AppWindowToken fromToken = mService.findAppWindowToken(transferFrom);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700901 if (fromToken == null) {
902 return false;
903 }
904
905 final WindowState tStartingWindow = fromToken.startingWindow;
906 if (tStartingWindow != null && fromToken.startingView != null) {
907 // In this case, the starting icon has already been displayed, so start
908 // letting windows get shown immediately without any more transitions.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700909 mService.mSkipAppTransitionAnimation = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700910
911 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow
912 + " from " + fromToken + " to " + this);
913
914 final long origId = Binder.clearCallingIdentity();
915
916 // Transfer the starting window over to the new token.
917 startingData = fromToken.startingData;
918 startingView = fromToken.startingView;
919 startingDisplayed = fromToken.startingDisplayed;
920 fromToken.startingDisplayed = false;
921 startingWindow = tStartingWindow;
922 reportedVisible = fromToken.reportedVisible;
923 fromToken.startingData = null;
924 fromToken.startingView = null;
925 fromToken.startingWindow = null;
926 fromToken.startingMoved = true;
927 tStartingWindow.mToken = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700928 tStartingWindow.mAppToken = this;
929
930 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
931 "Removing starting window: " + tStartingWindow);
932 tStartingWindow.getWindowList().remove(tStartingWindow);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700933 mService.mWindowsChanged = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700934 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
935 "Removing starting " + tStartingWindow + " from " + fromToken);
Wale Ogunwalefa854eb2016-09-20 13:43:52 -0700936 fromToken.removeChild(tStartingWindow);
937 fromToken.postWindowRemoveStartingWindowCleanup(tStartingWindow);
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700938 addWindow(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700939
940 // Propagate other interesting state between the tokens. If the old token is displayed,
941 // we should immediately force the new one to be displayed. If it is animating, we need
942 // to move that animation to the new one.
943 if (fromToken.allDrawn) {
944 allDrawn = true;
945 deferClearAllDrawn = fromToken.deferClearAllDrawn;
946 }
947 if (fromToken.firstWindowDrawn) {
948 firstWindowDrawn = true;
949 }
950 if (!fromToken.hidden) {
951 hidden = false;
952 hiddenRequested = false;
953 }
954 if (clientHidden != fromToken.clientHidden) {
955 clientHidden = fromToken.clientHidden;
956 sendAppVisibilityToClients();
957 }
958 fromToken.mAppAnimator.transferCurrentAnimation(
959 mAppAnimator, tStartingWindow.mWinAnimator);
960
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700961 mService.updateFocusedWindowLocked(
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700962 UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/);
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700963 mService.getDefaultDisplayContentLocked().setLayoutNeeded();
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700964 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700965 Binder.restoreCallingIdentity(origId);
966 return true;
967 } else if (fromToken.startingData != null) {
968 // The previous app was getting ready to show a
969 // starting window, but hasn't yet done so. Steal it!
970 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
971 "Moving pending starting from " + fromToken + " to " + this);
972 startingData = fromToken.startingData;
973 fromToken.startingData = null;
974 fromToken.startingMoved = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700975 final Message m = mService.mH.obtainMessage(H.ADD_STARTING, this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700976 // Note: we really want to do sendMessageAtFrontOfQueue() because we want to process the
977 // message ASAP, before any other queued messages.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700978 mService.mH.sendMessageAtFrontOfQueue(m);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700979 return true;
980 }
981
982 final AppWindowAnimator tAppAnimator = fromToken.mAppAnimator;
983 final AppWindowAnimator wAppAnimator = mAppAnimator;
984 if (tAppAnimator.thumbnail != null) {
985 // The old token is animating with a thumbnail, transfer that to the new token.
986 if (wAppAnimator.thumbnail != null) {
987 wAppAnimator.thumbnail.destroy();
988 }
989 wAppAnimator.thumbnail = tAppAnimator.thumbnail;
990 wAppAnimator.thumbnailLayer = tAppAnimator.thumbnailLayer;
991 wAppAnimator.thumbnailAnimation = tAppAnimator.thumbnailAnimation;
992 tAppAnimator.thumbnail = null;
993 }
994 return false;
995 }
996
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700997 boolean isLastWindow(WindowState win) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700998 return mChildren.size() == 1 && mChildren.get(0) == win;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700999 }
1000
1001 void setAllAppWinAnimators() {
1002 final ArrayList<WindowStateAnimator> allAppWinAnimators = mAppAnimator.mAllAppWinAnimators;
1003 allAppWinAnimators.clear();
1004
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001005 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001006 for (int j = 0; j < windowsCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001007 (mChildren.get(j)).addWinAnimatorToList(allAppWinAnimators);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001008 }
1009 }
1010
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001011 @Override
1012 void onAppTransitionDone() {
1013 sendingToBottom = false;
1014 }
1015
Wale Ogunwale51362492016-09-08 17:49:17 -07001016 /**
1017 * We override because this class doesn't want its children affecting its reported orientation
1018 * in anyway.
1019 */
1020 @Override
1021 int getOrientation() {
1022 if (hidden || hiddenRequested) {
1023 return SCREEN_ORIENTATION_UNSET;
1024 }
1025 return mOrientation;
1026 }
1027
Craig Mautnerdbb79912012-03-01 18:59:14 -08001028 @Override
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001029 void checkAppWindowsReadyToShow(int displayId) {
1030 if (allDrawn == mAppAnimator.allDrawn) {
1031 return;
1032 }
1033
1034 mAppAnimator.allDrawn = allDrawn;
1035 if (!allDrawn) {
1036 return;
1037 }
1038
1039 // The token has now changed state to having all windows shown... what to do, what to do?
1040 if (mAppAnimator.freezingScreen) {
1041 mAppAnimator.showAllWindowsLocked();
1042 stopFreezingScreen(false, true);
1043 if (DEBUG_ORIENTATION) Slog.i(TAG,
1044 "Setting mOrientationChangeComplete=true because wtoken " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001045 + " numInteresting=" + mNumInterestingWindows + " numDrawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001046 // This will set mOrientationChangeComplete and cause a pass through layout.
1047 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
1048 "checkAppWindowsReadyToShow: freezingScreen", displayId);
1049 } else {
1050 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow", displayId);
1051
1052 // We can now show all of the drawn windows!
1053 if (!mService.mOpeningApps.contains(this)) {
1054 mService.mAnimator.orAnimating(mAppAnimator.showAllWindowsLocked());
1055 }
1056 }
1057 }
1058
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001059 void updateAllDrawn(DisplayContent dc) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001060 if (!allDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001061 final int numInteresting = mNumInterestingWindows;
1062 if (numInteresting > 0 && mNumDrawnWindows >= numInteresting) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001063 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawn: " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001064 + " interesting=" + numInteresting + " drawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001065 allDrawn = true;
1066 // Force an additional layout pass where
1067 // WindowStateAnimator#commitFinishDrawingLocked() will call performShowLocked().
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001068 dc.setLayoutNeeded();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001069 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
1070 }
1071 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001072
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001073 if (!allDrawnExcludingSaved) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001074 int numInteresting = mNumInterestingWindowsExcludingSaved;
1075 if (numInteresting > 0 && mNumDrawnWindowsExcludingSaved >= numInteresting) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001076 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawnExcludingSaved: " + this
1077 + " interesting=" + numInteresting
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001078 + " drawn=" + mNumDrawnWindowsExcludingSaved);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001079 allDrawnExcludingSaved = true;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001080 dc.setLayoutNeeded();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001081 if (isAnimatingInvisibleWithSavedSurface()
1082 && !mService.mFinishedEarlyAnim.contains(this)) {
1083 mService.mFinishedEarlyAnim.add(this);
1084 }
1085 }
1086 }
1087 }
1088
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001089 /**
1090 * Updated this app token tracking states for interesting and drawn windows based on the window.
1091 *
1092 * @return Returns true if the input window is considered interesting and drawn while all the
1093 * windows in this app token where not considered drawn as of the last pass.
1094 */
1095 boolean updateDrawnWindowStates(WindowState w) {
1096 if (DEBUG_STARTING_WINDOW && w == startingWindow) {
1097 Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" + w.isOnScreen()
1098 + " allDrawn=" + allDrawn + " freezingScreen=" + mAppAnimator.freezingScreen);
1099 }
1100
1101 if (allDrawn && allDrawnExcludingSaved && !mAppAnimator.freezingScreen) {
1102 return false;
1103 }
1104
1105 if (mLastTransactionSequence != mService.mTransactionSequence) {
1106 mLastTransactionSequence = mService.mTransactionSequence;
1107 mNumInterestingWindows = mNumDrawnWindows = 0;
1108 mNumInterestingWindowsExcludingSaved = 0;
1109 mNumDrawnWindowsExcludingSaved = 0;
1110 startingDisplayed = false;
1111 }
1112
1113 final WindowStateAnimator winAnimator = w.mWinAnimator;
1114
1115 boolean isInterestingAndDrawn = false;
1116
1117 if (!allDrawn && w.mightAffectAllDrawn(false /* visibleOnly */)) {
1118 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
1119 Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw()
1120 + ", isAnimationSet=" + winAnimator.isAnimationSet());
1121 if (!w.isDrawnLw()) {
1122 Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController
1123 + " pv=" + w.mPolicyVisibility
1124 + " mDrawState=" + winAnimator.drawStateToString()
1125 + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested
1126 + " a=" + winAnimator.mAnimating);
1127 }
1128 }
1129
1130 if (w != startingWindow) {
1131 if (w.isInteresting()) {
1132 mNumInterestingWindows++;
1133 if (w.isDrawnLw()) {
1134 mNumDrawnWindows++;
1135
1136 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, "tokenMayBeDrawn: "
1137 + this + " w=" + w + " numInteresting=" + mNumInterestingWindows
1138 + " freezingScreen=" + mAppAnimator.freezingScreen
1139 + " mAppFreezing=" + w.mAppFreezing);
1140
1141 isInterestingAndDrawn = true;
1142 }
1143 }
1144 } else if (w.isDrawnLw()) {
1145 mService.mH.sendEmptyMessage(NOTIFY_STARTING_WINDOW_DRAWN);
1146 startingDisplayed = true;
1147 }
1148 }
1149
1150 if (!allDrawnExcludingSaved && w.mightAffectAllDrawn(true /* visibleOnly */)) {
1151 if (w != startingWindow && w.isInteresting()) {
1152 mNumInterestingWindowsExcludingSaved++;
1153 if (w.isDrawnLw() && !w.isAnimatingWithSavedSurface()) {
1154 mNumDrawnWindowsExcludingSaved++;
1155
1156 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
1157 "tokenMayBeDrawnExcludingSaved: " + this + " w=" + w
1158 + " numInteresting=" + mNumInterestingWindowsExcludingSaved
1159 + " freezingScreen=" + mAppAnimator.freezingScreen
1160 + " mAppFreezing=" + w.mAppFreezing);
1161
1162 isInterestingAndDrawn = true;
1163 }
1164 }
1165 }
1166
1167 return isInterestingAndDrawn;
1168 }
1169
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001170 @Override
1171 void stepAppWindowsAnimation(long currentTime, int displayId) {
1172 mAppAnimator.wasAnimating = mAppAnimator.animating;
1173 if (mAppAnimator.stepAnimationLocked(currentTime, displayId)) {
1174 mAppAnimator.animating = true;
1175 mService.mAnimator.setAnimating(true);
1176 mService.mAnimator.mAppWindowAnimating = true;
1177 } else if (mAppAnimator.wasAnimating) {
1178 // stopped animating, do one more pass through the layout
1179 setAppLayoutChanges(
1180 FINISH_LAYOUT_REDO_WALLPAPER, "appToken " + this + " done", displayId);
1181 if (DEBUG_ANIM) Slog.v(TAG, "updateWindowsApps...: done animating " + this);
1182 }
1183 }
1184
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001185 int rebuildWindowListUnchecked(DisplayContent dc, int addIndex) {
1186 return super.rebuildWindowList(dc, addIndex);
1187 }
1188
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001189 @Override
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001190 int rebuildWindowList(DisplayContent dc, int addIndex) {
1191 if (mIsExiting && !waitingForReplacement()) {
1192 return addIndex;
1193 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001194 return rebuildWindowListUnchecked(dc, addIndex);
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001195 }
1196
1197 @Override
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001198 AppWindowToken asAppWindowToken() {
1199 // I am an app window token!
1200 return this;
1201 }
1202
1203 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -07001204 boolean fillsParent() {
1205 return mFillsParent;
1206 }
1207
1208 void setFillsParent(boolean fillsParent) {
1209 mFillsParent = fillsParent;
1210 }
1211
1212 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001213 void dump(PrintWriter pw, String prefix) {
1214 super.dump(pw, prefix);
1215 if (appToken != null) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001216 pw.print(prefix); pw.print("app=true voiceInteraction="); pw.println(voiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001217 }
Craig Mautner83162a92015-01-26 14:43:30 -08001218 pw.print(prefix); pw.print("task="); pw.println(mTask);
Wale Ogunwale51362492016-09-08 17:49:17 -07001219 pw.print(prefix); pw.print(" mFillsParent="); pw.print(mFillsParent);
1220 pw.print(" mOrientation="); pw.println(mOrientation);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001221 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
1222 pw.print(" clientHidden="); pw.print(clientHidden);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -07001223 pw.print(" reportedDrawn="); pw.print(reportedDrawn);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001224 pw.print(" reportedVisible="); pw.println(reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -07001225 if (paused) {
1226 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001227 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001228 if (mAppStopped) {
1229 pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped);
1230 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001231 if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0
Craig Mautner6fbda632012-07-03 09:26:39 -07001232 || allDrawn || mAppAnimator.allDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001233 pw.print(prefix); pw.print("mNumInterestingWindows=");
1234 pw.print(mNumInterestingWindows);
1235 pw.print(" mNumDrawnWindows="); pw.print(mNumDrawnWindows);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001236 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -07001237 pw.print(" allDrawn="); pw.print(allDrawn);
1238 pw.print(" (animator="); pw.print(mAppAnimator.allDrawn);
1239 pw.println(")");
1240 }
1241 if (inPendingTransaction) {
1242 pw.print(prefix); pw.print("inPendingTransaction=");
1243 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001244 }
Craig Mautner799bc1d2015-01-14 10:33:48 -08001245 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001246 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
1247 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -08001248 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -08001249 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001250 }
1251 if (startingWindow != null || startingView != null
1252 || startingDisplayed || startingMoved) {
1253 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
1254 pw.print(" startingView="); pw.print(startingView);
1255 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001256 pw.print(" startingMoved="); pw.println(startingMoved);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001257 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01001258 if (!mFrozenBounds.isEmpty()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -08001259 pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds);
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001260 pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig);
Chong Zhangd78ddb42016-03-02 17:01:14 -08001261 }
1262 if (mPendingRelaunchCount != 0) {
1263 pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount);
Jorim Jaggi0429f352015-12-22 16:29:16 +01001264 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001265 }
1266
1267 @Override
1268 public String toString() {
1269 if (stringName == null) {
1270 StringBuilder sb = new StringBuilder();
1271 sb.append("AppWindowToken{");
1272 sb.append(Integer.toHexString(System.identityHashCode(this)));
1273 sb.append(" token="); sb.append(token); sb.append('}');
1274 stringName = sb.toString();
1275 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001276 return stringName + ((mIsExiting) ? " mIsExiting=" : "");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001277 }
Jeff Browne9bdb312012-04-05 15:30:10 -07001278}