blob: a44c8aa3da8130e5fa3db7df281e22684cb98aa2 [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;
Jorim Jaggife762342016-10-13 14:33:27 +020022import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
23import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
Wale Ogunwaled1c37912016-08-16 03:19:39 -070024import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080025import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070026import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -070027import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
28import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080029import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
30import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
Robert Carra1eb4392015-12-10 12:43:51 -080031import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070032import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
33import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
Wale Ogunwale9017ec02016-02-25 08:55:25 -080034import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080035import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
36import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_MOVEMENT;
37import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
38import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Chong Zhang92147042016-05-09 12:47:11 -070039import static com.android.server.wm.WindowManagerService.H.NOTIFY_ACTIVITY_DRAWN;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -070040import static com.android.server.wm.WindowManagerService.H.NOTIFY_STARTING_WINDOW_DRAWN;
Jorim Jaggi6626f542016-08-22 13:08:44 -070041import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_NONE;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070042import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070043import static com.android.server.wm.WindowManagerService.logWithStack;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080044
Jeff Brown4532e612012-04-05 14:27:12 -070045import com.android.server.input.InputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080046import com.android.server.wm.WindowManagerService.H;
47
Filip Gruszczynskia590c992015-11-25 16:45:26 -080048import android.annotation.NonNull;
Jorim Jaggi26c8c422016-05-09 19:57:25 -070049import android.content.res.Configuration;
Jorim Jaggi0429f352015-12-22 16:29:16 +010050import android.graphics.Rect;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070051import android.os.Binder;
52import android.os.IBinder;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080053import android.os.Message;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070054import android.os.SystemClock;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080055import android.util.Slog;
56import android.view.IApplicationToken;
57import android.view.View;
58import android.view.WindowManager;
Jorim Jaggi6626f542016-08-22 13:08:44 -070059import android.view.animation.Animation;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080060
61import java.io.PrintWriter;
Jorim Jaggi0429f352015-12-22 16:29:16 +010062import java.util.ArrayDeque;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080063import java.util.ArrayList;
64
65class AppTokenList extends ArrayList<AppWindowToken> {
66}
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080067
68/**
69 * Version of WindowToken that is specifically for a particular application (or
70 * really activity) that is displaying windows.
71 */
Wale Ogunwale3f4433d2016-08-18 20:42:42 -070072class AppWindowToken extends WindowToken implements WindowManagerService.AppFreezeListener {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080073 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppWindowToken" : TAG_WM;
74
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080075 // Non-null only for application tokens.
76 final IApplicationToken appToken;
77
Filip Gruszczynskia590c992015-11-25 16:45:26 -080078 @NonNull final AppWindowAnimator mAppAnimator;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -070079
Dianne Hackborne30e02f2014-05-27 18:24:45 -070080 final boolean voiceInteraction;
81
Wale Ogunwalef6192862016-09-10 13:42:30 -070082 // TODO: Use getParent instead?
Craig Mautner83162a92015-01-26 14:43:30 -080083 Task mTask;
Wale Ogunwale51362492016-09-08 17:49:17 -070084 /** @see WindowContainer#fillsParent() */
85 private boolean mFillsParent;
Craig Mautner4c5eb222013-11-18 12:59:05 -080086 boolean layoutConfigChanges;
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -070087 boolean showForAllUsers;
Yorke Lee0e852472016-06-15 10:03:18 -070088 int targetSdk;
Craig Mautnera2c77052012-03-26 12:14:43 -070089
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080090 // The input dispatching timeout for this application token in nanoseconds.
91 long inputDispatchingTimeoutNanos;
92
93 // These are used for determining when all windows associated with
94 // an activity have been drawn, so they can be made visible together
95 // at the same time.
Craig Mautner764983d2012-03-22 11:37:36 -070096 // initialize so that it doesn't match mTransactionSequence which is an int.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -070097 private long mLastTransactionSequence = Long.MIN_VALUE;
98 private int mNumInterestingWindows;
99 private int mNumDrawnWindows;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800100 boolean inPendingTransaction;
101 boolean allDrawn;
Craig Mautner7636dfb2012-11-16 15:24:11 -0800102 // Set to true when this app creates a surface while in the middle of an animation. In that
103 // case do not clear allDrawn until the animation completes.
104 boolean deferClearAllDrawn;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800105
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700106 /**
107 * These are to track the app's real drawing status if there were no saved surfaces.
108 * @see #updateDrawnWindowStates
109 */
Chong Zhang8e4bda92016-05-04 15:08:18 -0700110 boolean allDrawnExcludingSaved;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700111 private int mNumInterestingWindowsExcludingSaved;
112 private int mNumDrawnWindowsExcludingSaved;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700113
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800114 // Is this window's surface needed? This is almost like hidden, except
115 // it will sometimes be true a little earlier: when the token has
116 // been shown, but is still waiting for its app transition to execute
117 // before making its windows shown.
118 boolean hiddenRequested;
119
120 // Have we told the window clients to hide themselves?
121 boolean clientHidden;
122
123 // Last visibility state we reported to the app token.
124 boolean reportedVisible;
125
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700126 // Last drawn state we reported to the app token.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700127 private boolean reportedDrawn;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700128
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800129 // Set to true when the token has been removed from the window mgr.
130 boolean removed;
131
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800132 // Information about an application starting window if displayed.
133 StartingData startingData;
134 WindowState startingWindow;
135 View startingView;
136 boolean startingDisplayed;
137 boolean startingMoved;
138 boolean firstWindowDrawn;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700139 private final WindowState.UpdateReportedVisibilityResults mReportedVisibilityResults =
140 new WindowState.UpdateReportedVisibilityResults();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800141
142 // Input application handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700143 final InputApplicationHandle mInputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800144
Wale Ogunwale571771c2016-08-26 13:18:50 -0700145 // TODO: Have a WindowContainer state for tracking exiting/deferred removal.
Craig Mautner799bc1d2015-01-14 10:33:48 -0800146 boolean mIsExiting;
Craig Mautner9ef471f2014-02-07 13:11:47 -0800147
Craig Mautnerbb742462014-07-07 15:28:55 -0700148 boolean mLaunchTaskBehind;
Craig Mautner8746a472014-07-24 15:12:54 -0700149 boolean mEnteringAnimation;
Craig Mautnerbb742462014-07-07 15:28:55 -0700150
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800151 boolean mAlwaysFocusable;
152
Robert Carre12aece2016-02-02 22:43:27 -0800153 boolean mAppStopped;
Robert Carrfd10cd12016-06-29 16:41:50 -0700154 int mRotationAnimationHint;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700155 private int mPendingRelaunchCount;
Robert Carre12aece2016-02-02 22:43:27 -0800156
Jorim Jaggife762342016-10-13 14:33:27 +0200157 private boolean mLastContainsShowWhenLockedWindow;
158 private boolean mLastContainsDismissKeyguardWindow;
159
Robert Carr91b228092016-06-28 17:32:37 -0700160 private ArrayList<WindowSurfaceController.SurfaceControlWithBackground> mSurfaceViewBackgrounds =
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700161 new ArrayList<>();
Robert Carr91b228092016-06-28 17:32:37 -0700162
Jorim Jaggi0429f352015-12-22 16:29:16 +0100163 ArrayDeque<Rect> mFrozenBounds = new ArrayDeque<>();
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700164 ArrayDeque<Configuration> mFrozenMergedConfig = new ArrayDeque<>();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100165
Wale Ogunwale02319a62016-09-26 15:21:22 -0700166 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean _voiceInteraction,
167 DisplayContent displayContent) {
168 super(service, token != null ? token.asBinder() : null, TYPE_APPLICATION, true,
169 displayContent);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700170 appToken = token;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700171 voiceInteraction = _voiceInteraction;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800172 mInputApplicationHandle = new InputApplicationHandle(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700173 mAppAnimator = new AppWindowAnimator(this, service);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800174 }
175
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800176 void onFirstWindowDrawn(WindowState win, WindowStateAnimator winAnimator) {
177 firstWindowDrawn = true;
178
179 // We now have a good window to show, remove dead placeholders
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700180 removeDeadWindows();
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800181
182 if (startingData != null) {
183 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, "Finish starting "
184 + win.mToken + ": first real window is shown, no animation");
185 // If this initial window is animating, stop it -- we will do an animation to reveal
186 // it from behind the starting window, so there is no need for it to also be doing its
187 // own stuff.
188 winAnimator.clearAnimation();
189 winAnimator.mService.mFinishedStarting.add(this);
190 winAnimator.mService.mH.sendEmptyMessage(H.FINISHED_STARTING);
191 }
192 updateReportedVisibilityLocked();
193 }
194
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800195 void updateReportedVisibilityLocked() {
196 if (appToken == null) {
197 return;
198 }
199
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700200 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700201 final int count = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800202
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700203 mReportedVisibilityResults.reset();
204
205 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700206 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700207 win.updateReportedVisibility(mReportedVisibilityResults);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800208 }
209
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700210 int numInteresting = mReportedVisibilityResults.numInteresting;
211 int numVisible = mReportedVisibilityResults.numVisible;
212 int numDrawn = mReportedVisibilityResults.numDrawn;
213 boolean nowGone = mReportedVisibilityResults.nowGone;
214
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700215 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800216 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700217 if (!nowGone) {
218 // If the app is not yet gone, then it can only become visible/drawn.
219 if (!nowDrawn) {
220 nowDrawn = reportedDrawn;
221 }
222 if (!nowVisible) {
223 nowVisible = reportedVisible;
224 }
225 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800226 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800227 + numInteresting + " visible=" + numVisible);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700228 if (nowDrawn != reportedDrawn) {
229 if (nowDrawn) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700230 mService.mH.obtainMessage(H.REPORT_APPLICATION_TOKEN_DRAWN, this).sendToTarget();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700231 }
232 reportedDrawn = nowDrawn;
233 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800234 if (nowVisible != reportedVisible) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700235 if (DEBUG_VISIBILITY) Slog.v(TAG,
236 "Visibility changed in " + this + ": vis=" + nowVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800237 reportedVisible = nowVisible;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700238 mService.mH.obtainMessage(H.REPORT_APPLICATION_TOKEN_WINDOWS,
239 nowVisible ? 1 : 0, nowGone ? 1 : 0, this).sendToTarget();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800240 }
241 }
242
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700243 boolean setVisibility(WindowManager.LayoutParams lp,
244 boolean visible, int transit, boolean performLayout, boolean isVoiceInteraction) {
245
246 boolean delayed = false;
247 inPendingTransaction = false;
248
249 if (clientHidden == visible) {
250 clientHidden = !visible;
251 sendAppVisibilityToClients();
252 }
253
254 // Allow for state changes and animation to be applied if:
255 // * token is transitioning visibility state
256 // * or the token was marked as hidden and is exiting before we had a chance to play the
257 // transition animation
258 // * or this is an opening app and windows are being replaced.
259 boolean visibilityChanged = false;
260 if (hidden == visible || (hidden && mIsExiting) || (visible && waitingForReplacement())) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700261 final AccessibilityController accessibilityController = mService.mAccessibilityController;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700262 boolean changed = false;
263 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
264 "Changing app " + this + " hidden=" + hidden + " performLayout=" + performLayout);
265
266 boolean runningAppAnimation = false;
267
268 if (transit != AppTransition.TRANSIT_UNSET) {
269 if (mAppAnimator.animation == AppWindowAnimator.sDummyAnimation) {
270 mAppAnimator.setNullAnimation();
271 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700272 if (mService.applyAnimationLocked(this, lp, transit, visible, isVoiceInteraction)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700273 delayed = runningAppAnimation = true;
274 }
275 final WindowState window = findMainWindow();
276 //TODO (multidisplay): Magnification is supported only for the default display.
277 if (window != null && accessibilityController != null
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700278 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700279 accessibilityController.onAppWindowTransitionLocked(window, transit);
280 }
281 changed = true;
282 }
283
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700284 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700285 for (int i = 0; i < windowsCount; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700286 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700287 changed |= win.onAppVisibilityChanged(visible, runningAppAnimation);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700288 }
289
290 hidden = hiddenRequested = !visible;
291 visibilityChanged = true;
292 if (!visible) {
293 stopFreezingScreen(true, true);
294 } else {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700295 // If we are being set visible, and the starting window is not yet displayed,
296 // then make sure it doesn't get displayed.
297 if (startingWindow != null && !startingWindow.isDrawnLw()) {
298 startingWindow.mPolicyVisibility = false;
299 startingWindow.mPolicyVisibilityAfterAnim = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700300 }
301 }
302
303 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setVisibility: " + this
304 + ": hidden=" + hidden + " hiddenRequested=" + hiddenRequested);
305
306 if (changed) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700307 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700308 if (performLayout) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700309 mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700310 false /*updateInputWindows*/);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700311 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700312 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700313 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700314 }
315 }
316
317 if (mAppAnimator.animation != null) {
318 delayed = true;
319 }
320
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700321 for (int i = mChildren.size() - 1; i >= 0 && !delayed; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700322 if ((mChildren.get(i)).isWindowAnimationSet()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700323 delayed = true;
324 }
325 }
326
327 if (visibilityChanged) {
328 if (visible && !delayed) {
329 // The token was made immediately visible, there will be no entrance animation.
330 // We need to inform the client the enter animation was finished.
331 mEnteringAnimation = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700332 mService.mActivityManagerAppTransitionNotifier.onAppTransitionFinishedLocked(token);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700333 }
334
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700335 if (!mService.mClosingApps.contains(this) && !mService.mOpeningApps.contains(this)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700336 // The token is not closing nor opening, so even if there is an animation set, that
337 // doesn't mean that it goes through the normal app transition cycle so we have
338 // to inform the docked controller about visibility change.
Andrii Kulian1e32e022016-09-16 15:29:34 -0700339 // TODO(multi-display): notify docked divider on all displays where visibility was
340 // affected.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700341 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700342 .notifyAppVisibilityChanged();
343 }
344 }
345
346 return delayed;
347 }
348
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800349 WindowState findMainWindow() {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700350 WindowState candidate = null;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700351 int j = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800352 while (j > 0) {
353 j--;
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700354 final WindowState win = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700355 final int type = win.mAttrs.type;
356 // No need to loop through child window as base application and starting types can't be
357 // child windows.
358 if (type == TYPE_BASE_APPLICATION || type == TYPE_APPLICATION_STARTING) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700359 // In cases where there are multiple windows, we prefer the non-exiting window. This
Sungsoo Lim0d3d1f82015-12-02 14:47:59 +0900360 // happens for example when replacing windows during an activity relaunch. When
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700361 // constructing the animation, we want the new window, not the exiting one.
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800362 if (win.mAnimatingExit) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700363 candidate = win;
364 } else {
365 return win;
366 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800367 }
368 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700369 return candidate;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800370 }
371
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800372 boolean windowsAreFocusable() {
373 return StackId.canReceiveKeys(mTask.mStack.mStackId) || mAlwaysFocusable;
Wale Ogunwaled045c822015-12-02 09:14:28 -0800374 }
375
Wale Ogunwale571771c2016-08-26 13:18:50 -0700376 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -0700377 boolean isVisible() {
Wale Ogunwalee471be62016-10-03 07:53:55 -0700378 // If the app token isn't hidden then it is considered visible and there is no need to check
379 // its children windows to see if they are visible.
380 return !hidden;
Wale Ogunwale44f21802016-09-02 12:49:48 -0700381 }
382
383 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -0700384 void removeIfPossible() {
Craig Mautnere3119b72015-01-20 15:02:36 -0800385 mIsExiting = false;
386 removeAllWindows();
Wale Ogunwale571771c2016-08-26 13:18:50 -0700387 if (mTask != null) {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700388 mTask.mStack.mExitingAppTokens.remove(this);
389 mTask.removeChild(this);
Craig Mautnere3119b72015-01-20 15:02:36 -0800390 }
391 }
392
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700393 @Override
394 boolean checkCompleteDeferredRemoval() {
395 if (mIsExiting) {
396 removeIfPossible();
397 }
398 return super.checkCompleteDeferredRemoval();
399 }
400
Chong Zhange05bcb12016-07-26 17:47:29 -0700401 void clearAnimatingFlags() {
Chong Zhangb0d26702016-08-12 16:03:29 -0700402 boolean wallpaperMightChange = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700403 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700404 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700405 wallpaperMightChange |= win.clearAnimatingFlags();
Chong Zhange05bcb12016-07-26 17:47:29 -0700406 }
Chong Zhangb0d26702016-08-12 16:03:29 -0700407 if (wallpaperMightChange) {
408 requestUpdateWallpaperIfNeeded();
409 }
Chong Zhange05bcb12016-07-26 17:47:29 -0700410 }
411
Robert Carre12aece2016-02-02 22:43:27 -0800412 void destroySurfaces() {
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700413 destroySurfaces(false /*cleanupOnResume*/);
414 }
415
416 /**
417 * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure
418 * the client has finished with them.
419 *
420 * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If
421 * set to true, destroy only surfaces of removed windows, and clear relevant flags of the
422 * others so that they are ready to be reused. If set to false (common case), destroy all
423 * surfaces that's eligible, if the app is already stopped.
424 */
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700425 private void destroySurfaces(boolean cleanupOnResume) {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700426 boolean destroyedSomething = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700427 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700428 final WindowState win = mChildren.get(i);
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700429 destroyedSomething |= win.destroySurface(cleanupOnResume, mAppStopped);
Robert Carre12aece2016-02-02 22:43:27 -0800430 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700431 if (destroyedSomething) {
432 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700433 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Robert Carre12aece2016-02-02 22:43:27 -0800434 }
435 }
436
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800437 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700438 * Notify that the app is now resumed, and it was not stopped before, perform a clean
439 * up of the surfaces
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800440 */
Chong Zhangad24f962016-08-25 12:12:33 -0700441 void notifyAppResumed(boolean wasStopped, boolean allowSavedSurface) {
442 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped
443 + " allowSavedSurface=" + allowSavedSurface + " " + this);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700444 mAppStopped = false;
445 if (!wasStopped) {
446 destroySurfaces(true /*cleanupOnResume*/);
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800447 }
Chong Zhangad24f962016-08-25 12:12:33 -0700448 if (!allowSavedSurface) {
449 destroySavedSurfaces();
450 }
Robert Carre12aece2016-02-02 22:43:27 -0800451 }
452
Chong Zhangbef461f2015-10-27 11:38:24 -0700453 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700454 * Notify that the app has stopped, and it is okay to destroy any surfaces which were
455 * keeping alive in case they were still being used.
456 */
457 void notifyAppStopped() {
458 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this);
459 mAppStopped = true;
460 destroySurfaces();
461 // Remove any starting window that was added for this app if they are still around.
462 mTask.mService.scheduleRemoveStartingWindowLocked(this);
463 }
464
465 /**
Chong Zhangbef461f2015-10-27 11:38:24 -0700466 * Checks whether we should save surfaces for this app.
467 *
468 * @return true if the surfaces should be saved, false otherwise.
469 */
470 boolean shouldSaveSurface() {
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800471 // We want to save surface if the app's windows are "allDrawn".
472 // (If we started entering animation early with saved surfaces, allDrawn
473 // should have been restored to true. So we'll save again in that case
474 // even if app didn't actually finish drawing.)
475 return allDrawn;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800476 }
477
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700478 private boolean canRestoreSurfaces() {
479 for (int i = mChildren.size() -1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700480 final WindowState w = mChildren.get(i);
Chong Zhang92147042016-05-09 12:47:11 -0700481 if (w.canRestoreSurface()) {
Robert Carr13f7be9e2015-12-02 18:39:45 -0800482 return true;
483 }
Chong Zhangbef461f2015-10-27 11:38:24 -0700484 }
485 return false;
486 }
487
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700488 private void clearWasVisibleBeforeClientHidden() {
489 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700490 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700491 w.clearWasVisibleBeforeClientHidden();
Chong Zhang92147042016-05-09 12:47:11 -0700492 }
493 }
494
Chong Zhang8e4bda92016-05-04 15:08:18 -0700495 /**
496 * Whether the app has some window that is invisible in layout, but
497 * animating with saved surface.
498 */
499 boolean isAnimatingInvisibleWithSavedSurface() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700500 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700501 final WindowState w = mChildren.get(i);
Chong Zhang8e4bda92016-05-04 15:08:18 -0700502 if (w.isAnimatingInvisibleWithSavedSurface()) {
503 return true;
504 }
505 }
506 return false;
507 }
508
509 /**
510 * Hide all window surfaces that's still invisible in layout but animating
511 * with a saved surface, and mark them destroying.
512 */
513 void stopUsingSavedSurfaceLocked() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700514 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700515 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700516 w.stopUsingSavedSurface();
Chong Zhang8e4bda92016-05-04 15:08:18 -0700517 }
518 destroySurfaces();
519 }
520
Chong Zhangf58631a2016-05-24 16:02:10 -0700521 void markSavedSurfaceExiting() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700522 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700523 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700524 w.markSavedSurfaceExiting();
Chong Zhangf58631a2016-05-24 16:02:10 -0700525 }
526 }
527
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700528 void restoreSavedSurfaceForInterestingWindows() {
Chong Zhang92147042016-05-09 12:47:11 -0700529 if (!canRestoreSurfaces()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700530 clearWasVisibleBeforeClientHidden();
Chong Zhangbef461f2015-10-27 11:38:24 -0700531 return;
532 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700533
534 // Check if all interesting windows are drawn and we can mark allDrawn=true.
535 int interestingNotDrawn = -1;
536
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700537 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700538 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700539 interestingNotDrawn = w.restoreSavedSurfaceForInterestingWindow();
Chong Zhangbef461f2015-10-27 11:38:24 -0700540 }
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800541
Chong Zhang92147042016-05-09 12:47:11 -0700542 if (!allDrawn) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700543 allDrawn = (interestingNotDrawn == 0);
Chong Zhang92147042016-05-09 12:47:11 -0700544 if (allDrawn) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700545 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Chong Zhang92147042016-05-09 12:47:11 -0700546 }
547 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700548 clearWasVisibleBeforeClientHidden();
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800549
550 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700551 "restoreSavedSurfaceForInterestingWindows: " + this + " allDrawn=" + allDrawn
552 + " interestingNotDrawn=" + interestingNotDrawn);
Chong Zhangbef461f2015-10-27 11:38:24 -0700553 }
554
555 void destroySavedSurfaces() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700556 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700557 final WindowState win = mChildren.get(i);
Robert Carr13f7be9e2015-12-02 18:39:45 -0800558 win.destroySavedSurface();
Chong Zhangbef461f2015-10-27 11:38:24 -0700559 }
Chong Zhang92147042016-05-09 12:47:11 -0700560 }
561
562 void clearAllDrawn() {
563 allDrawn = false;
564 deferClearAllDrawn = false;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700565 allDrawnExcludingSaved = false;
Chong Zhangbef461f2015-10-27 11:38:24 -0700566 }
567
Wale Ogunwalefa854eb2016-09-20 13:43:52 -0700568 void postWindowRemoveStartingWindowCleanup(WindowState win) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700569 // TODO: Something smells about the code below...Is there a better way?
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700570 if (startingWindow == win) {
571 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700572 mService.scheduleRemoveStartingWindowLocked(this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700573 } else if (mChildren.size() == 0 && startingData != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700574 // If this is the last window and we had requested a starting transition window,
575 // well there is no point now.
576 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingWindow");
577 startingData = null;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700578 } else if (mChildren.size() == 1 && startingView != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700579 // If this is the last window except for a starting transition window,
580 // we need to get rid of the starting transition.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700581 mService.scheduleRemoveStartingWindowLocked(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700582 }
583 }
584
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700585 void removeDeadWindows() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700586 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700587 WindowState win = mChildren.get(winNdx);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800588 if (win.mAppDied) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700589 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700590 "removeDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800591 // Set mDestroying, we don't want any animation or delayed removal here.
592 win.mDestroying = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700593 // Also removes child windows.
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700594 win.removeIfPossible();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800595 }
596 }
597 }
598
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700599 boolean hasWindowsAlive() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700600 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700601 // No need to loop through child windows as the answer should be the same as that of the
602 // parent window.
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700603 if (!(mChildren.get(i)).mAppDied) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700604 return true;
605 }
606 }
607 return false;
608 }
609
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700610 void setWillReplaceWindows(boolean animate) {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700611 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
612 "Marking app token " + this + " with replacing windows.");
Robert Carra1eb4392015-12-10 12:43:51 -0800613
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700614 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700615 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700616 w.setWillReplaceWindow(animate);
Robert Carra1eb4392015-12-10 12:43:51 -0800617 }
618 if (animate) {
619 // Set-up dummy animation so we can start treating windows associated with this
620 // token like they are in transition before the new app window is ready for us to
621 // run the real transition animation.
622 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700623 "setWillReplaceWindow() Setting dummy animation on: " + this);
Robert Carra1eb4392015-12-10 12:43:51 -0800624 mAppAnimator.setDummyAnimation();
625 }
626 }
627
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700628 void setWillReplaceChildWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700629 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this
Robert Carr23fa16b2016-01-13 13:19:58 -0800630 + " with replacing child windows.");
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700631 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700632 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700633 w.setWillReplaceChildWindows();
Robert Carr23fa16b2016-01-13 13:19:58 -0800634 }
635 }
636
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700637 void clearWillReplaceWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700638 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
639 "Resetting app token " + this + " of replacing window marks.");
Chong Zhangf596cd52016-01-05 13:42:44 -0800640
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700641 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700642 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700643 w.clearWillReplaceWindow();
Chong Zhangf596cd52016-01-05 13:42:44 -0800644 }
645 }
646
Chong Zhang4d7369a2016-04-25 16:09:14 -0700647 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700648 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700649 final WindowState w = mChildren.get(i);
Chong Zhang4d7369a2016-04-25 16:09:14 -0700650 w.requestUpdateWallpaperIfNeeded();
651 }
652 }
653
Chong Zhangd78ddb42016-03-02 17:01:14 -0800654 boolean isRelaunching() {
655 return mPendingRelaunchCount > 0;
656 }
657
658 void startRelaunching() {
659 if (canFreezeBounds()) {
660 freezeBounds();
661 }
662 mPendingRelaunchCount++;
663 }
664
665 void finishRelaunching() {
666 if (canFreezeBounds()) {
667 unfreezeBounds();
668 }
669 if (mPendingRelaunchCount > 0) {
670 mPendingRelaunchCount--;
671 }
672 }
673
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700674 void clearRelaunching() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700675 if (mPendingRelaunchCount == 0) {
676 return;
677 }
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700678 if (canFreezeBounds()) {
679 unfreezeBounds();
680 }
681 mPendingRelaunchCount = 0;
682 }
683
Wale Ogunwale07bcab72016-10-14 15:30:09 -0700684 /**
685 * Returns true if the new child window we are adding to this token is considered greater than
686 * the existing child window in this token in terms of z-order.
687 */
688 @Override
689 protected boolean isFirstChildWindowGreaterThanSecond(WindowState newWindow,
690 WindowState existingWindow) {
691 final int type1 = newWindow.mAttrs.type;
692 final int type2 = existingWindow.mAttrs.type;
693
694 // Base application windows should be z-ordered BELOW all other windows in the app token.
695 if (type1 == TYPE_BASE_APPLICATION && type2 != TYPE_BASE_APPLICATION) {
696 return false;
697 } else if (type1 != TYPE_BASE_APPLICATION && type2 == TYPE_BASE_APPLICATION) {
698 return true;
699 }
700
701 // Starting windows should be z-ordered ABOVE all other windows in the app token.
702 if (type1 == TYPE_APPLICATION_STARTING && type2 != TYPE_APPLICATION_STARTING) {
703 return true;
704 } else if (type1 != TYPE_APPLICATION_STARTING && type2 == TYPE_APPLICATION_STARTING) {
705 return false;
706 }
707
708 // Otherwise the new window is greater than the existing window.
709 return true;
710 }
711
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700712 @Override
Robert Carra1eb4392015-12-10 12:43:51 -0800713 void addWindow(WindowState w) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700714 super.addWindow(w);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700715
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700716 boolean gotReplacementWindow = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700717 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700718 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700719 gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w);
720 }
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700721
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700722 // if we got a replacement window, reset the timeout to give drawing more time
723 if (gotReplacementWindow) {
724 mService.scheduleWindowReplacementTimeouts(this);
Robert Carra1eb4392015-12-10 12:43:51 -0800725 }
Jorim Jaggife762342016-10-13 14:33:27 +0200726 checkKeyguardFlagsChanged();
727 }
728
729 @Override
730 void removeChild(WindowState child) {
731 super.removeChild(child);
732 checkKeyguardFlagsChanged();
Robert Carra1eb4392015-12-10 12:43:51 -0800733 }
734
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700735 private boolean waitingForReplacement() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700736 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700737 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700738 if (candidate.waitingForReplacement()) {
Robert Carra1eb4392015-12-10 12:43:51 -0800739 return true;
740 }
741 }
742 return false;
743 }
744
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700745 void onWindowReplacementTimeout() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700746 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700747 (mChildren.get(i)).onWindowReplacementTimeout();
Robert Carra1eb4392015-12-10 12:43:51 -0800748 }
749 }
750
Chong Zhangd78ddb42016-03-02 17:01:14 -0800751 private boolean canFreezeBounds() {
752 // For freeform windows, we can't freeze the bounds at the moment because this would make
753 // the resizing unresponsive.
754 return mTask != null && !mTask.inFreeformWorkspace();
755 }
756
Jorim Jaggi0429f352015-12-22 16:29:16 +0100757 /**
758 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
759 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
760 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
761 * with a queue.
762 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800763 private void freezeBounds() {
Jorim Jaggi0429f352015-12-22 16:29:16 +0100764 mFrozenBounds.offer(new Rect(mTask.mPreparedFrozenBounds));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700765
766 if (mTask.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) {
767 // We didn't call prepareFreezingBounds on the task, so use the current value.
Andrii Kulian441e4492016-09-29 15:25:00 -0700768 mFrozenMergedConfig.offer(new Configuration(mTask.getConfiguration()));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700769 } else {
770 mFrozenMergedConfig.offer(new Configuration(mTask.mPreparedFrozenMergedConfig));
771 }
Andrii Kulianb10330d2016-09-16 13:51:46 -0700772 // Calling unset() to make it equal to Configuration.EMPTY.
773 mTask.mPreparedFrozenMergedConfig.unset();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100774 }
775
776 /**
777 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
778 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800779 private void unfreezeBounds() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700780 if (!mFrozenBounds.isEmpty()) {
781 mFrozenBounds.remove();
782 }
783 if (!mFrozenMergedConfig.isEmpty()) {
784 mFrozenMergedConfig.remove();
785 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700786 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700787 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700788 win.onUnfreezeBounds();
Jorim Jaggi4846ee32016-01-07 17:39:12 +0100789 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700790 mService.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100791 }
792
Robert Carr91b228092016-06-28 17:32:37 -0700793 void addSurfaceViewBackground(WindowSurfaceController.SurfaceControlWithBackground background) {
794 mSurfaceViewBackgrounds.add(background);
795 }
796
797 void removeSurfaceViewBackground(WindowSurfaceController.SurfaceControlWithBackground background) {
798 mSurfaceViewBackgrounds.remove(background);
799 updateSurfaceViewBackgroundVisibilities();
800 }
801
802 // We use DimLayers behind SurfaceViews to prevent holes while resizing and creating.
803 // However, we need to ensure one SurfaceView doesn't cover another when they are both placed
804 // below the main app window (as traditionally a SurfaceView which is never drawn
805 // to is totally translucent). So we look at all our SurfaceView backgrounds and only enable
806 // the background for the SurfaceView with lowest Z order
807 void updateSurfaceViewBackgroundVisibilities() {
808 WindowSurfaceController.SurfaceControlWithBackground bottom = null;
809 int bottomLayer = Integer.MAX_VALUE;
810 for (int i = 0; i < mSurfaceViewBackgrounds.size(); i++) {
811 WindowSurfaceController.SurfaceControlWithBackground sc = mSurfaceViewBackgrounds.get(i);
812 if (sc.mVisible && sc.mLayer < bottomLayer) {
813 bottomLayer = sc.mLayer;
814 bottom = sc;
815 }
816 }
817 for (int i = 0; i < mSurfaceViewBackgrounds.size(); i++) {
818 WindowSurfaceController.SurfaceControlWithBackground sc = mSurfaceViewBackgrounds.get(i);
819 sc.updateBackgroundVisibility(sc != bottom);
820 }
821 }
822
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700823 void resetJustMovedInStack() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700824 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700825 (mChildren.get(i)).resetJustMovedInStack();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700826 }
827 }
828
829 void notifyMovedInStack() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700830 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700831 final WindowState win = mChildren.get(winNdx);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700832 win.notifyMovedInStack();
833 }
834 }
835
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700836 void setAppLayoutChanges(int changes, String reason) {
837 if (!mChildren.isEmpty()) {
838 final DisplayContent dc = getDisplayContent();
839 dc.pendingLayoutChanges |= changes;
840 if (DEBUG_LAYOUT_REPEATS) {
841 mService.mWindowPlacerLocked.debugLayoutRepeats(reason, dc.pendingLayoutChanges);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700842 }
843 }
844 }
845
846 void removeReplacedWindowIfNeeded(WindowState replacement) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700847 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700848 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700849 if (win.removeReplacedWindowIfNeeded(replacement)) {
850 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700851 }
852 }
853 }
854
855 void startFreezingScreen() {
856 if (DEBUG_ORIENTATION) logWithStack(TAG, "Set freezing of " + appToken + ": hidden="
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700857 + hidden + " freezing=" + mAppAnimator.freezingScreen + " hiddenRequested="
858 + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700859 if (!hiddenRequested) {
860 if (!mAppAnimator.freezingScreen) {
861 mAppAnimator.freezingScreen = true;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700862 mService.registerAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700863 mAppAnimator.lastFreezeDuration = 0;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700864 mService.mAppsFreezingScreen++;
865 if (mService.mAppsFreezingScreen == 1) {
866 mService.startFreezingDisplayLocked(false, 0, 0);
867 mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT);
868 mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700869 }
870 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700871 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700872 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 w.onStartFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700875 }
876 }
877 }
878
879 void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) {
880 if (!mAppAnimator.freezingScreen) {
881 return;
882 }
883 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + this + " force=" + force);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700884 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700885 boolean unfrozeWindows = false;
886 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700887 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700888 unfrozeWindows |= w.onStopFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700889 }
890 if (force || unfrozeWindows) {
891 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this);
892 mAppAnimator.freezingScreen = false;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700893 mService.unregisterAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700894 mAppAnimator.lastFreezeDuration =
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700895 (int)(SystemClock.elapsedRealtime() - mService.mDisplayFreezeTime);
896 mService.mAppsFreezingScreen--;
897 mService.mLastFinishedFreezeSource = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700898 }
899 if (unfreezeSurfaceNow) {
900 if (unfrozeWindows) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700901 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700902 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700903 mService.stopFreezingDisplayLocked();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700904 }
905 }
906
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700907 @Override
908 public void onAppFreezeTimeout() {
909 Slog.w(TAG_WM, "Force clearing freeze: " + this);
910 stopFreezingScreen(true, true);
911 }
912
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700913 boolean transferStartingWindow(IBinder transferFrom) {
Wale Ogunwale02319a62016-09-26 15:21:22 -0700914 final AppWindowToken fromToken = getDisplayContent().getAppWindowToken(transferFrom);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700915 if (fromToken == null) {
916 return false;
917 }
918
919 final WindowState tStartingWindow = fromToken.startingWindow;
920 if (tStartingWindow != null && fromToken.startingView != null) {
921 // In this case, the starting icon has already been displayed, so start
922 // letting windows get shown immediately without any more transitions.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700923 mService.mSkipAppTransitionAnimation = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700924
925 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow
926 + " from " + fromToken + " to " + this);
927
928 final long origId = Binder.clearCallingIdentity();
929
930 // Transfer the starting window over to the new token.
931 startingData = fromToken.startingData;
932 startingView = fromToken.startingView;
933 startingDisplayed = fromToken.startingDisplayed;
934 fromToken.startingDisplayed = false;
935 startingWindow = tStartingWindow;
936 reportedVisible = fromToken.reportedVisible;
937 fromToken.startingData = null;
938 fromToken.startingView = null;
939 fromToken.startingWindow = null;
940 fromToken.startingMoved = true;
941 tStartingWindow.mToken = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700942 tStartingWindow.mAppToken = this;
943
944 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
945 "Removing starting window: " + tStartingWindow);
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700946 getDisplayContent().removeFromWindowList(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700947 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
948 "Removing starting " + tStartingWindow + " from " + fromToken);
Wale Ogunwalefa854eb2016-09-20 13:43:52 -0700949 fromToken.removeChild(tStartingWindow);
950 fromToken.postWindowRemoveStartingWindowCleanup(tStartingWindow);
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700951 addWindow(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700952
953 // Propagate other interesting state between the tokens. If the old token is displayed,
954 // we should immediately force the new one to be displayed. If it is animating, we need
955 // to move that animation to the new one.
956 if (fromToken.allDrawn) {
957 allDrawn = true;
958 deferClearAllDrawn = fromToken.deferClearAllDrawn;
959 }
960 if (fromToken.firstWindowDrawn) {
961 firstWindowDrawn = true;
962 }
963 if (!fromToken.hidden) {
964 hidden = false;
965 hiddenRequested = false;
966 }
967 if (clientHidden != fromToken.clientHidden) {
968 clientHidden = fromToken.clientHidden;
969 sendAppVisibilityToClients();
970 }
971 fromToken.mAppAnimator.transferCurrentAnimation(
972 mAppAnimator, tStartingWindow.mWinAnimator);
973
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700974 mService.updateFocusedWindowLocked(
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700975 UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/);
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700976 getDisplayContent().setLayoutNeeded();
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700977 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700978 Binder.restoreCallingIdentity(origId);
979 return true;
980 } else if (fromToken.startingData != null) {
981 // The previous app was getting ready to show a
982 // starting window, but hasn't yet done so. Steal it!
983 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
984 "Moving pending starting from " + fromToken + " to " + this);
985 startingData = fromToken.startingData;
986 fromToken.startingData = null;
987 fromToken.startingMoved = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700988 final Message m = mService.mH.obtainMessage(H.ADD_STARTING, this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700989 // Note: we really want to do sendMessageAtFrontOfQueue() because we want to process the
990 // message ASAP, before any other queued messages.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700991 mService.mH.sendMessageAtFrontOfQueue(m);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700992 return true;
993 }
994
995 final AppWindowAnimator tAppAnimator = fromToken.mAppAnimator;
996 final AppWindowAnimator wAppAnimator = mAppAnimator;
997 if (tAppAnimator.thumbnail != null) {
998 // The old token is animating with a thumbnail, transfer that to the new token.
999 if (wAppAnimator.thumbnail != null) {
1000 wAppAnimator.thumbnail.destroy();
1001 }
1002 wAppAnimator.thumbnail = tAppAnimator.thumbnail;
1003 wAppAnimator.thumbnailLayer = tAppAnimator.thumbnailLayer;
1004 wAppAnimator.thumbnailAnimation = tAppAnimator.thumbnailAnimation;
1005 tAppAnimator.thumbnail = null;
1006 }
1007 return false;
1008 }
1009
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001010 boolean isLastWindow(WindowState win) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001011 return mChildren.size() == 1 && mChildren.get(0) == win;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001012 }
1013
1014 void setAllAppWinAnimators() {
1015 final ArrayList<WindowStateAnimator> allAppWinAnimators = mAppAnimator.mAllAppWinAnimators;
1016 allAppWinAnimators.clear();
1017
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001018 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001019 for (int j = 0; j < windowsCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001020 (mChildren.get(j)).addWinAnimatorToList(allAppWinAnimators);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001021 }
1022 }
1023
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001024 @Override
1025 void onAppTransitionDone() {
1026 sendingToBottom = false;
1027 }
1028
Wale Ogunwale51362492016-09-08 17:49:17 -07001029 /**
1030 * We override because this class doesn't want its children affecting its reported orientation
1031 * in anyway.
1032 */
1033 @Override
1034 int getOrientation() {
1035 if (hidden || hiddenRequested) {
1036 return SCREEN_ORIENTATION_UNSET;
1037 }
1038 return mOrientation;
1039 }
1040
Craig Mautnerdbb79912012-03-01 18:59:14 -08001041 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001042 void checkAppWindowsReadyToShow() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001043 if (allDrawn == mAppAnimator.allDrawn) {
1044 return;
1045 }
1046
1047 mAppAnimator.allDrawn = allDrawn;
1048 if (!allDrawn) {
1049 return;
1050 }
1051
1052 // The token has now changed state to having all windows shown... what to do, what to do?
1053 if (mAppAnimator.freezingScreen) {
1054 mAppAnimator.showAllWindowsLocked();
1055 stopFreezingScreen(false, true);
1056 if (DEBUG_ORIENTATION) Slog.i(TAG,
1057 "Setting mOrientationChangeComplete=true because wtoken " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001058 + " numInteresting=" + mNumInterestingWindows + " numDrawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001059 // This will set mOrientationChangeComplete and cause a pass through layout.
1060 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001061 "checkAppWindowsReadyToShow: freezingScreen");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001062 } else {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001063 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001064
1065 // We can now show all of the drawn windows!
1066 if (!mService.mOpeningApps.contains(this)) {
1067 mService.mAnimator.orAnimating(mAppAnimator.showAllWindowsLocked());
1068 }
1069 }
1070 }
1071
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001072 void updateAllDrawn(DisplayContent dc) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001073 if (!allDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001074 final int numInteresting = mNumInterestingWindows;
1075 if (numInteresting > 0 && mNumDrawnWindows >= numInteresting) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001076 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawn: " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001077 + " interesting=" + numInteresting + " drawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001078 allDrawn = true;
1079 // Force an additional layout pass where
1080 // WindowStateAnimator#commitFinishDrawingLocked() will call performShowLocked().
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001081 dc.setLayoutNeeded();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001082 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
1083 }
1084 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001085
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001086 if (!allDrawnExcludingSaved) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001087 int numInteresting = mNumInterestingWindowsExcludingSaved;
1088 if (numInteresting > 0 && mNumDrawnWindowsExcludingSaved >= numInteresting) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001089 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawnExcludingSaved: " + this
1090 + " interesting=" + numInteresting
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001091 + " drawn=" + mNumDrawnWindowsExcludingSaved);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001092 allDrawnExcludingSaved = true;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001093 dc.setLayoutNeeded();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001094 if (isAnimatingInvisibleWithSavedSurface()
1095 && !mService.mFinishedEarlyAnim.contains(this)) {
1096 mService.mFinishedEarlyAnim.add(this);
1097 }
1098 }
1099 }
1100 }
1101
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001102 /**
1103 * Updated this app token tracking states for interesting and drawn windows based on the window.
1104 *
1105 * @return Returns true if the input window is considered interesting and drawn while all the
1106 * windows in this app token where not considered drawn as of the last pass.
1107 */
1108 boolean updateDrawnWindowStates(WindowState w) {
1109 if (DEBUG_STARTING_WINDOW && w == startingWindow) {
1110 Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" + w.isOnScreen()
1111 + " allDrawn=" + allDrawn + " freezingScreen=" + mAppAnimator.freezingScreen);
1112 }
1113
1114 if (allDrawn && allDrawnExcludingSaved && !mAppAnimator.freezingScreen) {
1115 return false;
1116 }
1117
1118 if (mLastTransactionSequence != mService.mTransactionSequence) {
1119 mLastTransactionSequence = mService.mTransactionSequence;
1120 mNumInterestingWindows = mNumDrawnWindows = 0;
1121 mNumInterestingWindowsExcludingSaved = 0;
1122 mNumDrawnWindowsExcludingSaved = 0;
1123 startingDisplayed = false;
1124 }
1125
1126 final WindowStateAnimator winAnimator = w.mWinAnimator;
1127
1128 boolean isInterestingAndDrawn = false;
1129
1130 if (!allDrawn && w.mightAffectAllDrawn(false /* visibleOnly */)) {
1131 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
1132 Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw()
1133 + ", isAnimationSet=" + winAnimator.isAnimationSet());
1134 if (!w.isDrawnLw()) {
1135 Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController
1136 + " pv=" + w.mPolicyVisibility
1137 + " mDrawState=" + winAnimator.drawStateToString()
1138 + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested
1139 + " a=" + winAnimator.mAnimating);
1140 }
1141 }
1142
1143 if (w != startingWindow) {
1144 if (w.isInteresting()) {
1145 mNumInterestingWindows++;
1146 if (w.isDrawnLw()) {
1147 mNumDrawnWindows++;
1148
1149 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, "tokenMayBeDrawn: "
1150 + this + " w=" + w + " numInteresting=" + mNumInterestingWindows
1151 + " freezingScreen=" + mAppAnimator.freezingScreen
1152 + " mAppFreezing=" + w.mAppFreezing);
1153
1154 isInterestingAndDrawn = true;
1155 }
1156 }
1157 } else if (w.isDrawnLw()) {
1158 mService.mH.sendEmptyMessage(NOTIFY_STARTING_WINDOW_DRAWN);
1159 startingDisplayed = true;
1160 }
1161 }
1162
1163 if (!allDrawnExcludingSaved && w.mightAffectAllDrawn(true /* visibleOnly */)) {
1164 if (w != startingWindow && w.isInteresting()) {
1165 mNumInterestingWindowsExcludingSaved++;
1166 if (w.isDrawnLw() && !w.isAnimatingWithSavedSurface()) {
1167 mNumDrawnWindowsExcludingSaved++;
1168
1169 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
1170 "tokenMayBeDrawnExcludingSaved: " + this + " w=" + w
1171 + " numInteresting=" + mNumInterestingWindowsExcludingSaved
1172 + " freezingScreen=" + mAppAnimator.freezingScreen
1173 + " mAppFreezing=" + w.mAppFreezing);
1174
1175 isInterestingAndDrawn = true;
1176 }
1177 }
1178 }
1179
1180 return isInterestingAndDrawn;
1181 }
1182
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001183 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001184 void stepAppWindowsAnimation(long currentTime) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001185 mAppAnimator.wasAnimating = mAppAnimator.animating;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001186 if (mAppAnimator.stepAnimationLocked(currentTime)) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001187 mAppAnimator.animating = true;
1188 mService.mAnimator.setAnimating(true);
1189 mService.mAnimator.mAppWindowAnimating = true;
1190 } else if (mAppAnimator.wasAnimating) {
1191 // stopped animating, do one more pass through the layout
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001192 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER, "appToken " + this + " done");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001193 if (DEBUG_ANIM) Slog.v(TAG, "updateWindowsApps...: done animating " + this);
1194 }
1195 }
1196
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001197 int rebuildWindowListUnchecked(int addIndex) {
1198 return super.rebuildWindowList(addIndex);
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001199 }
1200
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001201 @Override
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001202 int rebuildWindowList(int addIndex) {
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001203 if (mIsExiting && !waitingForReplacement()) {
1204 return addIndex;
1205 }
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001206 return rebuildWindowListUnchecked(addIndex);
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001207 }
1208
1209 @Override
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001210 AppWindowToken asAppWindowToken() {
1211 // I am an app window token!
1212 return this;
1213 }
1214
1215 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -07001216 boolean fillsParent() {
1217 return mFillsParent;
1218 }
1219
1220 void setFillsParent(boolean fillsParent) {
1221 mFillsParent = fillsParent;
1222 }
1223
Jorim Jaggife762342016-10-13 14:33:27 +02001224 boolean containsDismissKeyguardWindow() {
1225 for (int i = mChildren.size() - 1; i >= 0; i--) {
1226 if ((mChildren.get(i).mAttrs.flags & FLAG_DISMISS_KEYGUARD) != 0) {
1227 return true;
1228 }
1229 }
1230 return false;
1231 }
1232
1233 boolean containsShowWhenLockedWindow() {
1234 for (int i = mChildren.size() - 1; i >= 0; i--) {
1235 if ((mChildren.get(i).mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
1236 return true;
1237 }
1238 }
1239 return false;
1240 }
1241
1242 void checkKeyguardFlagsChanged() {
1243 final boolean containsDismissKeyguard = containsDismissKeyguardWindow();
1244 final boolean containsShowWhenLocked = containsShowWhenLockedWindow();
1245 if (containsDismissKeyguard != mLastContainsDismissKeyguardWindow
1246 || containsShowWhenLocked != mLastContainsShowWhenLockedWindow) {
1247 mService.notifyKeyguardFlagsChanged(null /* callback */);
1248 }
1249 mLastContainsDismissKeyguardWindow = containsDismissKeyguard;
1250 mLastContainsShowWhenLockedWindow = containsShowWhenLocked;
1251 }
1252
Wale Ogunwale51362492016-09-08 17:49:17 -07001253 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001254 void dump(PrintWriter pw, String prefix) {
1255 super.dump(pw, prefix);
1256 if (appToken != null) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001257 pw.print(prefix); pw.print("app=true voiceInteraction="); pw.println(voiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001258 }
Craig Mautner83162a92015-01-26 14:43:30 -08001259 pw.print(prefix); pw.print("task="); pw.println(mTask);
Wale Ogunwale51362492016-09-08 17:49:17 -07001260 pw.print(prefix); pw.print(" mFillsParent="); pw.print(mFillsParent);
1261 pw.print(" mOrientation="); pw.println(mOrientation);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001262 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
1263 pw.print(" clientHidden="); pw.print(clientHidden);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -07001264 pw.print(" reportedDrawn="); pw.print(reportedDrawn);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001265 pw.print(" reportedVisible="); pw.println(reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -07001266 if (paused) {
1267 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001268 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001269 if (mAppStopped) {
1270 pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped);
1271 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001272 if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0
Craig Mautner6fbda632012-07-03 09:26:39 -07001273 || allDrawn || mAppAnimator.allDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001274 pw.print(prefix); pw.print("mNumInterestingWindows=");
1275 pw.print(mNumInterestingWindows);
1276 pw.print(" mNumDrawnWindows="); pw.print(mNumDrawnWindows);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001277 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -07001278 pw.print(" allDrawn="); pw.print(allDrawn);
1279 pw.print(" (animator="); pw.print(mAppAnimator.allDrawn);
1280 pw.println(")");
1281 }
1282 if (inPendingTransaction) {
1283 pw.print(prefix); pw.print("inPendingTransaction=");
1284 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001285 }
Craig Mautner799bc1d2015-01-14 10:33:48 -08001286 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001287 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
1288 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -08001289 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -08001290 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001291 }
1292 if (startingWindow != null || startingView != null
1293 || startingDisplayed || startingMoved) {
1294 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
1295 pw.print(" startingView="); pw.print(startingView);
1296 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001297 pw.print(" startingMoved="); pw.println(startingMoved);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001298 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01001299 if (!mFrozenBounds.isEmpty()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -08001300 pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds);
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001301 pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig);
Chong Zhangd78ddb42016-03-02 17:01:14 -08001302 }
1303 if (mPendingRelaunchCount != 0) {
1304 pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount);
Jorim Jaggi0429f352015-12-22 16:29:16 +01001305 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001306 }
1307
1308 @Override
1309 public String toString() {
1310 if (stringName == null) {
1311 StringBuilder sb = new StringBuilder();
1312 sb.append("AppWindowToken{");
1313 sb.append(Integer.toHexString(System.identityHashCode(this)));
1314 sb.append(" token="); sb.append(token); sb.append('}');
1315 stringName = sb.toString();
1316 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001317 return stringName + ((mIsExiting) ? " mIsExiting=" : "");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001318 }
Jeff Browne9bdb312012-04-05 15:30:10 -07001319}