blob: 622eece52ca1b95871a1690d01dd912b85b80260 [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;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070029import static com.android.server.wm.AppTransition.TRANSIT_UNSET;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080030import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
31import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
Robert Carra1eb4392015-12-10 12:43:51 -080032import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070033import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070034import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
35import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
Wale Ogunwale9017ec02016-02-25 08:55:25 -080036import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070037import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TOKEN_MOVEMENT;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080038import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
39import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_MOVEMENT;
40import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
41import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Chong Zhang92147042016-05-09 12:47:11 -070042import static com.android.server.wm.WindowManagerService.H.NOTIFY_ACTIVITY_DRAWN;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -070043import static com.android.server.wm.WindowManagerService.H.NOTIFY_STARTING_WINDOW_DRAWN;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070044import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
Jorim Jaggi6626f542016-08-22 13:08:44 -070045import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_NONE;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070046import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070047import static com.android.server.wm.WindowManagerService.logWithStack;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080048
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070049import android.os.Debug;
Jeff Brown4532e612012-04-05 14:27:12 -070050import com.android.server.input.InputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080051import com.android.server.wm.WindowManagerService.H;
52
Filip Gruszczynskia590c992015-11-25 16:45:26 -080053import android.annotation.NonNull;
Jorim Jaggi26c8c422016-05-09 19:57:25 -070054import android.content.res.Configuration;
Jorim Jaggi0429f352015-12-22 16:29:16 +010055import android.graphics.Rect;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070056import android.os.Binder;
57import android.os.IBinder;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080058import android.os.Message;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070059import android.os.SystemClock;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080060import android.util.Slog;
61import android.view.IApplicationToken;
62import android.view.View;
63import android.view.WindowManager;
Jorim Jaggi6626f542016-08-22 13:08:44 -070064import android.view.animation.Animation;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080065
66import java.io.PrintWriter;
Jorim Jaggi0429f352015-12-22 16:29:16 +010067import java.util.ArrayDeque;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080068import java.util.ArrayList;
69
70class AppTokenList extends ArrayList<AppWindowToken> {
71}
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080072
73/**
74 * Version of WindowToken that is specifically for a particular application (or
75 * really activity) that is displaying windows.
76 */
Wale Ogunwale3f4433d2016-08-18 20:42:42 -070077class AppWindowToken extends WindowToken implements WindowManagerService.AppFreezeListener {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080078 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppWindowToken" : TAG_WM;
79
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080080 // Non-null only for application tokens.
81 final IApplicationToken appToken;
82
Filip Gruszczynskia590c992015-11-25 16:45:26 -080083 @NonNull final AppWindowAnimator mAppAnimator;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -070084
Dianne Hackborne30e02f2014-05-27 18:24:45 -070085 final boolean voiceInteraction;
86
Wale Ogunwalef6192862016-09-10 13:42:30 -070087 // TODO: Use getParent instead?
Craig Mautner83162a92015-01-26 14:43:30 -080088 Task mTask;
Wale Ogunwale51362492016-09-08 17:49:17 -070089 /** @see WindowContainer#fillsParent() */
90 private boolean mFillsParent;
Craig Mautner4c5eb222013-11-18 12:59:05 -080091 boolean layoutConfigChanges;
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -070092 boolean showForAllUsers;
Yorke Lee0e852472016-06-15 10:03:18 -070093 int targetSdk;
Craig Mautnera2c77052012-03-26 12:14:43 -070094
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080095 // The input dispatching timeout for this application token in nanoseconds.
96 long inputDispatchingTimeoutNanos;
97
98 // These are used for determining when all windows associated with
99 // an activity have been drawn, so they can be made visible together
100 // at the same time.
Craig Mautner764983d2012-03-22 11:37:36 -0700101 // initialize so that it doesn't match mTransactionSequence which is an int.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700102 private long mLastTransactionSequence = Long.MIN_VALUE;
103 private int mNumInterestingWindows;
104 private int mNumDrawnWindows;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800105 boolean inPendingTransaction;
106 boolean allDrawn;
Craig Mautner7636dfb2012-11-16 15:24:11 -0800107 // Set to true when this app creates a surface while in the middle of an animation. In that
108 // case do not clear allDrawn until the animation completes.
109 boolean deferClearAllDrawn;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800110
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700111 /**
112 * These are to track the app's real drawing status if there were no saved surfaces.
113 * @see #updateDrawnWindowStates
114 */
Chong Zhang8e4bda92016-05-04 15:08:18 -0700115 boolean allDrawnExcludingSaved;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700116 private int mNumInterestingWindowsExcludingSaved;
117 private int mNumDrawnWindowsExcludingSaved;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700118
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800119 // Is this window's surface needed? This is almost like hidden, except
120 // it will sometimes be true a little earlier: when the token has
121 // been shown, but is still waiting for its app transition to execute
122 // before making its windows shown.
123 boolean hiddenRequested;
124
125 // Have we told the window clients to hide themselves?
126 boolean clientHidden;
127
128 // Last visibility state we reported to the app token.
129 boolean reportedVisible;
130
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700131 // Last drawn state we reported to the app token.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700132 private boolean reportedDrawn;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700133
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800134 // Set to true when the token has been removed from the window mgr.
135 boolean removed;
136
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800137 // Information about an application starting window if displayed.
138 StartingData startingData;
139 WindowState startingWindow;
140 View startingView;
141 boolean startingDisplayed;
142 boolean startingMoved;
143 boolean firstWindowDrawn;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700144 private final WindowState.UpdateReportedVisibilityResults mReportedVisibilityResults =
145 new WindowState.UpdateReportedVisibilityResults();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800146
147 // Input application handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700148 final InputApplicationHandle mInputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800149
Wale Ogunwale571771c2016-08-26 13:18:50 -0700150 // TODO: Have a WindowContainer state for tracking exiting/deferred removal.
Craig Mautner799bc1d2015-01-14 10:33:48 -0800151 boolean mIsExiting;
Craig Mautner9ef471f2014-02-07 13:11:47 -0800152
Craig Mautnerbb742462014-07-07 15:28:55 -0700153 boolean mLaunchTaskBehind;
Craig Mautner8746a472014-07-24 15:12:54 -0700154 boolean mEnteringAnimation;
Craig Mautnerbb742462014-07-07 15:28:55 -0700155
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800156 boolean mAlwaysFocusable;
157
Robert Carre12aece2016-02-02 22:43:27 -0800158 boolean mAppStopped;
Robert Carrfd10cd12016-06-29 16:41:50 -0700159 int mRotationAnimationHint;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700160 private int mPendingRelaunchCount;
Robert Carre12aece2016-02-02 22:43:27 -0800161
Jorim Jaggife762342016-10-13 14:33:27 +0200162 private boolean mLastContainsShowWhenLockedWindow;
163 private boolean mLastContainsDismissKeyguardWindow;
164
Robert Carr91b228092016-06-28 17:32:37 -0700165 private ArrayList<WindowSurfaceController.SurfaceControlWithBackground> mSurfaceViewBackgrounds =
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700166 new ArrayList<>();
Robert Carr91b228092016-06-28 17:32:37 -0700167
Jorim Jaggi0429f352015-12-22 16:29:16 +0100168 ArrayDeque<Rect> mFrozenBounds = new ArrayDeque<>();
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700169 ArrayDeque<Configuration> mFrozenMergedConfig = new ArrayDeque<>();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100170
Wale Ogunwale02319a62016-09-26 15:21:22 -0700171 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean _voiceInteraction,
172 DisplayContent displayContent) {
173 super(service, token != null ? token.asBinder() : null, TYPE_APPLICATION, true,
174 displayContent);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700175 appToken = token;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700176 voiceInteraction = _voiceInteraction;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800177 mInputApplicationHandle = new InputApplicationHandle(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700178 mAppAnimator = new AppWindowAnimator(this, service);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800179 }
180
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800181 void onFirstWindowDrawn(WindowState win, WindowStateAnimator winAnimator) {
182 firstWindowDrawn = true;
183
184 // We now have a good window to show, remove dead placeholders
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700185 removeDeadWindows();
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800186
187 if (startingData != null) {
188 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, "Finish starting "
189 + win.mToken + ": first real window is shown, no animation");
190 // If this initial window is animating, stop it -- we will do an animation to reveal
191 // it from behind the starting window, so there is no need for it to also be doing its
192 // own stuff.
193 winAnimator.clearAnimation();
194 winAnimator.mService.mFinishedStarting.add(this);
195 winAnimator.mService.mH.sendEmptyMessage(H.FINISHED_STARTING);
196 }
197 updateReportedVisibilityLocked();
198 }
199
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800200 void updateReportedVisibilityLocked() {
201 if (appToken == null) {
202 return;
203 }
204
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700205 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700206 final int count = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800207
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700208 mReportedVisibilityResults.reset();
209
210 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700211 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700212 win.updateReportedVisibility(mReportedVisibilityResults);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800213 }
214
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700215 int numInteresting = mReportedVisibilityResults.numInteresting;
216 int numVisible = mReportedVisibilityResults.numVisible;
217 int numDrawn = mReportedVisibilityResults.numDrawn;
218 boolean nowGone = mReportedVisibilityResults.nowGone;
219
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700220 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800221 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700222 if (!nowGone) {
223 // If the app is not yet gone, then it can only become visible/drawn.
224 if (!nowDrawn) {
225 nowDrawn = reportedDrawn;
226 }
227 if (!nowVisible) {
228 nowVisible = reportedVisible;
229 }
230 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800231 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800232 + numInteresting + " visible=" + numVisible);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700233 if (nowDrawn != reportedDrawn) {
234 if (nowDrawn) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700235 mService.mH.obtainMessage(H.REPORT_APPLICATION_TOKEN_DRAWN, this).sendToTarget();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700236 }
237 reportedDrawn = nowDrawn;
238 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800239 if (nowVisible != reportedVisible) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700240 if (DEBUG_VISIBILITY) Slog.v(TAG,
241 "Visibility changed in " + this + ": vis=" + nowVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800242 reportedVisible = nowVisible;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700243 mService.mH.obtainMessage(H.REPORT_APPLICATION_TOKEN_WINDOWS,
244 nowVisible ? 1 : 0, nowGone ? 1 : 0, this).sendToTarget();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800245 }
246 }
247
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700248 boolean setVisibility(WindowManager.LayoutParams lp,
249 boolean visible, int transit, boolean performLayout, boolean isVoiceInteraction) {
250
251 boolean delayed = false;
252 inPendingTransaction = false;
253
254 if (clientHidden == visible) {
255 clientHidden = !visible;
256 sendAppVisibilityToClients();
257 }
258
259 // Allow for state changes and animation to be applied if:
260 // * token is transitioning visibility state
261 // * or the token was marked as hidden and is exiting before we had a chance to play the
262 // transition animation
263 // * or this is an opening app and windows are being replaced.
264 boolean visibilityChanged = false;
265 if (hidden == visible || (hidden && mIsExiting) || (visible && waitingForReplacement())) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700266 final AccessibilityController accessibilityController = mService.mAccessibilityController;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700267 boolean changed = false;
268 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
269 "Changing app " + this + " hidden=" + hidden + " performLayout=" + performLayout);
270
271 boolean runningAppAnimation = false;
272
273 if (transit != AppTransition.TRANSIT_UNSET) {
274 if (mAppAnimator.animation == AppWindowAnimator.sDummyAnimation) {
275 mAppAnimator.setNullAnimation();
276 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700277 if (mService.applyAnimationLocked(this, lp, transit, visible, isVoiceInteraction)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700278 delayed = runningAppAnimation = true;
279 }
280 final WindowState window = findMainWindow();
281 //TODO (multidisplay): Magnification is supported only for the default display.
282 if (window != null && accessibilityController != null
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700283 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700284 accessibilityController.onAppWindowTransitionLocked(window, transit);
285 }
286 changed = true;
287 }
288
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700289 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700290 for (int i = 0; i < windowsCount; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700291 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700292 changed |= win.onAppVisibilityChanged(visible, runningAppAnimation);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700293 }
294
295 hidden = hiddenRequested = !visible;
296 visibilityChanged = true;
297 if (!visible) {
298 stopFreezingScreen(true, true);
299 } else {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700300 // If we are being set visible, and the starting window is not yet displayed,
301 // then make sure it doesn't get displayed.
302 if (startingWindow != null && !startingWindow.isDrawnLw()) {
303 startingWindow.mPolicyVisibility = false;
304 startingWindow.mPolicyVisibilityAfterAnim = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700305 }
306 }
307
308 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setVisibility: " + this
309 + ": hidden=" + hidden + " hiddenRequested=" + hiddenRequested);
310
311 if (changed) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700312 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700313 if (performLayout) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700314 mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700315 false /*updateInputWindows*/);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700316 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700317 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700318 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700319 }
320 }
321
322 if (mAppAnimator.animation != null) {
323 delayed = true;
324 }
325
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700326 for (int i = mChildren.size() - 1; i >= 0 && !delayed; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700327 if ((mChildren.get(i)).isWindowAnimationSet()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700328 delayed = true;
329 }
330 }
331
332 if (visibilityChanged) {
333 if (visible && !delayed) {
334 // The token was made immediately visible, there will be no entrance animation.
335 // We need to inform the client the enter animation was finished.
336 mEnteringAnimation = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700337 mService.mActivityManagerAppTransitionNotifier.onAppTransitionFinishedLocked(token);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700338 }
339
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700340 if (!mService.mClosingApps.contains(this) && !mService.mOpeningApps.contains(this)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700341 // The token is not closing nor opening, so even if there is an animation set, that
342 // doesn't mean that it goes through the normal app transition cycle so we have
343 // to inform the docked controller about visibility change.
Andrii Kulian1e32e022016-09-16 15:29:34 -0700344 // TODO(multi-display): notify docked divider on all displays where visibility was
345 // affected.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700346 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700347 .notifyAppVisibilityChanged();
348 }
349 }
350
351 return delayed;
352 }
353
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800354 WindowState findMainWindow() {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700355 WindowState candidate = null;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700356 int j = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800357 while (j > 0) {
358 j--;
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700359 final WindowState win = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700360 final int type = win.mAttrs.type;
361 // No need to loop through child window as base application and starting types can't be
362 // child windows.
363 if (type == TYPE_BASE_APPLICATION || type == TYPE_APPLICATION_STARTING) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700364 // In cases where there are multiple windows, we prefer the non-exiting window. This
Sungsoo Lim0d3d1f82015-12-02 14:47:59 +0900365 // happens for example when replacing windows during an activity relaunch. When
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700366 // constructing the animation, we want the new window, not the exiting one.
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800367 if (win.mAnimatingExit) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700368 candidate = win;
369 } else {
370 return win;
371 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800372 }
373 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700374 return candidate;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800375 }
376
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800377 boolean windowsAreFocusable() {
378 return StackId.canReceiveKeys(mTask.mStack.mStackId) || mAlwaysFocusable;
Wale Ogunwaled045c822015-12-02 09:14:28 -0800379 }
380
Wale Ogunwale571771c2016-08-26 13:18:50 -0700381 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -0700382 boolean isVisible() {
Wale Ogunwalee471be62016-10-03 07:53:55 -0700383 // If the app token isn't hidden then it is considered visible and there is no need to check
384 // its children windows to see if they are visible.
385 return !hidden;
Wale Ogunwale44f21802016-09-02 12:49:48 -0700386 }
387
388 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -0700389 void removeIfPossible() {
Craig Mautnere3119b72015-01-20 15:02:36 -0800390 mIsExiting = false;
391 removeAllWindows();
Wale Ogunwale571771c2016-08-26 13:18:50 -0700392 if (mTask != null) {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700393 mTask.mStack.mExitingAppTokens.remove(this);
394 mTask.removeChild(this);
Craig Mautnere3119b72015-01-20 15:02:36 -0800395 }
396 }
397
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700398 @Override
399 boolean checkCompleteDeferredRemoval() {
400 if (mIsExiting) {
401 removeIfPossible();
402 }
403 return super.checkCompleteDeferredRemoval();
404 }
405
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700406 void onRemovedFromDisplay() {
407 AppWindowToken startingToken = null;
408
409 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app token: " + this);
410
411 boolean delayed = setVisibility(null, false, TRANSIT_UNSET, true, voiceInteraction);
412
413 mService.mOpeningApps.remove(this);
414 waitingToShow = false;
415 if (mService.mClosingApps.contains(this)) {
416 delayed = true;
417 } else if (mService.mAppTransition.isTransitionSet()) {
418 mService.mClosingApps.add(this);
419 delayed = true;
420 }
421
422 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app " + this + " delayed=" + delayed
423 + " animation=" + mAppAnimator.animation + " animating=" + mAppAnimator.animating);
424
425 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM, "removeAppToken: "
426 + this + " delayed=" + delayed + " Callers=" + Debug.getCallers(4));
427
428 final TaskStack stack = mTask.mStack;
429 if (delayed && !isEmpty()) {
430 // set the token aside because it has an active animation to be finished
431 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM,
432 "removeAppToken make exiting: " + this);
433 stack.mExitingAppTokens.add(this);
434 mIsExiting = true;
435 } else {
436 // Make sure there is no animation running on this token, so any windows associated
437 // with it will be removed as soon as their animations are complete
438 mAppAnimator.clearAnimation();
439 mAppAnimator.animating = false;
440 removeIfPossible();
441 }
442
443 removed = true;
444 if (startingData != null) {
445 startingToken = this;
446 }
447 stopFreezingScreen(true, true);
448 if (mService.mFocusedApp == this) {
449 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "Removing focused app token:" + this);
450 mService.mFocusedApp = null;
451 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
452 mService.mInputMonitor.setFocusedAppLw(null);
453 }
454
455 if (!delayed) {
456 updateReportedVisibilityLocked();
457 }
458
459 // Will only remove if startingToken non null.
460 mService.scheduleRemoveStartingWindowLocked(startingToken);
461 }
462
Chong Zhange05bcb12016-07-26 17:47:29 -0700463 void clearAnimatingFlags() {
Chong Zhangb0d26702016-08-12 16:03:29 -0700464 boolean wallpaperMightChange = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700465 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700466 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700467 wallpaperMightChange |= win.clearAnimatingFlags();
Chong Zhange05bcb12016-07-26 17:47:29 -0700468 }
Chong Zhangb0d26702016-08-12 16:03:29 -0700469 if (wallpaperMightChange) {
470 requestUpdateWallpaperIfNeeded();
471 }
Chong Zhange05bcb12016-07-26 17:47:29 -0700472 }
473
Robert Carre12aece2016-02-02 22:43:27 -0800474 void destroySurfaces() {
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700475 destroySurfaces(false /*cleanupOnResume*/);
476 }
477
478 /**
479 * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure
480 * the client has finished with them.
481 *
482 * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If
483 * set to true, destroy only surfaces of removed windows, and clear relevant flags of the
484 * others so that they are ready to be reused. If set to false (common case), destroy all
485 * surfaces that's eligible, if the app is already stopped.
486 */
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700487 private void destroySurfaces(boolean cleanupOnResume) {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700488 boolean destroyedSomething = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700489 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700490 final WindowState win = mChildren.get(i);
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700491 destroyedSomething |= win.destroySurface(cleanupOnResume, mAppStopped);
Robert Carre12aece2016-02-02 22:43:27 -0800492 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700493 if (destroyedSomething) {
494 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700495 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Robert Carre12aece2016-02-02 22:43:27 -0800496 }
497 }
498
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800499 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700500 * Notify that the app is now resumed, and it was not stopped before, perform a clean
501 * up of the surfaces
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800502 */
Chong Zhangad24f962016-08-25 12:12:33 -0700503 void notifyAppResumed(boolean wasStopped, boolean allowSavedSurface) {
504 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped
505 + " allowSavedSurface=" + allowSavedSurface + " " + this);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700506 mAppStopped = false;
507 if (!wasStopped) {
508 destroySurfaces(true /*cleanupOnResume*/);
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800509 }
Chong Zhangad24f962016-08-25 12:12:33 -0700510 if (!allowSavedSurface) {
511 destroySavedSurfaces();
512 }
Robert Carre12aece2016-02-02 22:43:27 -0800513 }
514
Chong Zhangbef461f2015-10-27 11:38:24 -0700515 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700516 * Notify that the app has stopped, and it is okay to destroy any surfaces which were
517 * keeping alive in case they were still being used.
518 */
519 void notifyAppStopped() {
520 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this);
521 mAppStopped = true;
522 destroySurfaces();
523 // Remove any starting window that was added for this app if they are still around.
524 mTask.mService.scheduleRemoveStartingWindowLocked(this);
525 }
526
527 /**
Chong Zhangbef461f2015-10-27 11:38:24 -0700528 * Checks whether we should save surfaces for this app.
529 *
530 * @return true if the surfaces should be saved, false otherwise.
531 */
532 boolean shouldSaveSurface() {
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800533 // We want to save surface if the app's windows are "allDrawn".
534 // (If we started entering animation early with saved surfaces, allDrawn
535 // should have been restored to true. So we'll save again in that case
536 // even if app didn't actually finish drawing.)
537 return allDrawn;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800538 }
539
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700540 private boolean canRestoreSurfaces() {
541 for (int i = mChildren.size() -1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700542 final WindowState w = mChildren.get(i);
Chong Zhang92147042016-05-09 12:47:11 -0700543 if (w.canRestoreSurface()) {
Robert Carr13f7be9e2015-12-02 18:39:45 -0800544 return true;
545 }
Chong Zhangbef461f2015-10-27 11:38:24 -0700546 }
547 return false;
548 }
549
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700550 private void clearWasVisibleBeforeClientHidden() {
551 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700552 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700553 w.clearWasVisibleBeforeClientHidden();
Chong Zhang92147042016-05-09 12:47:11 -0700554 }
555 }
556
Chong Zhang8e4bda92016-05-04 15:08:18 -0700557 /**
558 * Whether the app has some window that is invisible in layout, but
559 * animating with saved surface.
560 */
561 boolean isAnimatingInvisibleWithSavedSurface() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700562 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700563 final WindowState w = mChildren.get(i);
Chong Zhang8e4bda92016-05-04 15:08:18 -0700564 if (w.isAnimatingInvisibleWithSavedSurface()) {
565 return true;
566 }
567 }
568 return false;
569 }
570
571 /**
572 * Hide all window surfaces that's still invisible in layout but animating
573 * with a saved surface, and mark them destroying.
574 */
575 void stopUsingSavedSurfaceLocked() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700576 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700577 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700578 w.stopUsingSavedSurface();
Chong Zhang8e4bda92016-05-04 15:08:18 -0700579 }
580 destroySurfaces();
581 }
582
Chong Zhangf58631a2016-05-24 16:02:10 -0700583 void markSavedSurfaceExiting() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700584 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700585 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700586 w.markSavedSurfaceExiting();
Chong Zhangf58631a2016-05-24 16:02:10 -0700587 }
588 }
589
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700590 void restoreSavedSurfaceForInterestingWindows() {
Chong Zhang92147042016-05-09 12:47:11 -0700591 if (!canRestoreSurfaces()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700592 clearWasVisibleBeforeClientHidden();
Chong Zhangbef461f2015-10-27 11:38:24 -0700593 return;
594 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700595
596 // Check if all interesting windows are drawn and we can mark allDrawn=true.
597 int interestingNotDrawn = -1;
598
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700599 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700600 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700601 interestingNotDrawn = w.restoreSavedSurfaceForInterestingWindow();
Chong Zhangbef461f2015-10-27 11:38:24 -0700602 }
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800603
Chong Zhang92147042016-05-09 12:47:11 -0700604 if (!allDrawn) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700605 allDrawn = (interestingNotDrawn == 0);
Chong Zhang92147042016-05-09 12:47:11 -0700606 if (allDrawn) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700607 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Chong Zhang92147042016-05-09 12:47:11 -0700608 }
609 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700610 clearWasVisibleBeforeClientHidden();
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800611
612 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700613 "restoreSavedSurfaceForInterestingWindows: " + this + " allDrawn=" + allDrawn
614 + " interestingNotDrawn=" + interestingNotDrawn);
Chong Zhangbef461f2015-10-27 11:38:24 -0700615 }
616
617 void destroySavedSurfaces() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700618 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700619 final WindowState win = mChildren.get(i);
Robert Carr13f7be9e2015-12-02 18:39:45 -0800620 win.destroySavedSurface();
Chong Zhangbef461f2015-10-27 11:38:24 -0700621 }
Chong Zhang92147042016-05-09 12:47:11 -0700622 }
623
624 void clearAllDrawn() {
625 allDrawn = false;
626 deferClearAllDrawn = false;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700627 allDrawnExcludingSaved = false;
Chong Zhangbef461f2015-10-27 11:38:24 -0700628 }
629
Wale Ogunwalefa854eb2016-09-20 13:43:52 -0700630 void postWindowRemoveStartingWindowCleanup(WindowState win) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700631 // TODO: Something smells about the code below...Is there a better way?
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700632 if (startingWindow == win) {
633 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700634 mService.scheduleRemoveStartingWindowLocked(this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700635 } else if (mChildren.size() == 0 && startingData != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700636 // If this is the last window and we had requested a starting transition window,
637 // well there is no point now.
638 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingWindow");
639 startingData = null;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700640 } else if (mChildren.size() == 1 && startingView != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700641 // If this is the last window except for a starting transition window,
642 // we need to get rid of the starting transition.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700643 mService.scheduleRemoveStartingWindowLocked(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700644 }
645 }
646
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700647 void removeDeadWindows() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700648 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700649 WindowState win = mChildren.get(winNdx);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800650 if (win.mAppDied) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700651 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700652 "removeDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800653 // Set mDestroying, we don't want any animation or delayed removal here.
654 win.mDestroying = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700655 // Also removes child windows.
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700656 win.removeIfPossible();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800657 }
658 }
659 }
660
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700661 boolean hasWindowsAlive() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700662 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700663 // No need to loop through child windows as the answer should be the same as that of the
664 // parent window.
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700665 if (!(mChildren.get(i)).mAppDied) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700666 return true;
667 }
668 }
669 return false;
670 }
671
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700672 void setWillReplaceWindows(boolean animate) {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700673 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
674 "Marking app token " + this + " with replacing windows.");
Robert Carra1eb4392015-12-10 12:43:51 -0800675
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700676 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700677 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700678 w.setWillReplaceWindow(animate);
Robert Carra1eb4392015-12-10 12:43:51 -0800679 }
680 if (animate) {
681 // Set-up dummy animation so we can start treating windows associated with this
682 // token like they are in transition before the new app window is ready for us to
683 // run the real transition animation.
684 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700685 "setWillReplaceWindow() Setting dummy animation on: " + this);
Robert Carra1eb4392015-12-10 12:43:51 -0800686 mAppAnimator.setDummyAnimation();
687 }
688 }
689
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700690 void setWillReplaceChildWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700691 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this
Robert Carr23fa16b2016-01-13 13:19:58 -0800692 + " with replacing child windows.");
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700693 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700694 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700695 w.setWillReplaceChildWindows();
Robert Carr23fa16b2016-01-13 13:19:58 -0800696 }
697 }
698
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700699 void clearWillReplaceWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700700 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
701 "Resetting app token " + this + " of replacing window marks.");
Chong Zhangf596cd52016-01-05 13:42:44 -0800702
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700703 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700704 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700705 w.clearWillReplaceWindow();
Chong Zhangf596cd52016-01-05 13:42:44 -0800706 }
707 }
708
Chong Zhang4d7369a2016-04-25 16:09:14 -0700709 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700710 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700711 final WindowState w = mChildren.get(i);
Chong Zhang4d7369a2016-04-25 16:09:14 -0700712 w.requestUpdateWallpaperIfNeeded();
713 }
714 }
715
Chong Zhangd78ddb42016-03-02 17:01:14 -0800716 boolean isRelaunching() {
717 return mPendingRelaunchCount > 0;
718 }
719
720 void startRelaunching() {
721 if (canFreezeBounds()) {
722 freezeBounds();
723 }
724 mPendingRelaunchCount++;
725 }
726
727 void finishRelaunching() {
728 if (canFreezeBounds()) {
729 unfreezeBounds();
730 }
731 if (mPendingRelaunchCount > 0) {
732 mPendingRelaunchCount--;
733 }
734 }
735
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700736 void clearRelaunching() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700737 if (mPendingRelaunchCount == 0) {
738 return;
739 }
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700740 if (canFreezeBounds()) {
741 unfreezeBounds();
742 }
743 mPendingRelaunchCount = 0;
744 }
745
Wale Ogunwale07bcab72016-10-14 15:30:09 -0700746 /**
747 * Returns true if the new child window we are adding to this token is considered greater than
748 * the existing child window in this token in terms of z-order.
749 */
750 @Override
751 protected boolean isFirstChildWindowGreaterThanSecond(WindowState newWindow,
752 WindowState existingWindow) {
753 final int type1 = newWindow.mAttrs.type;
754 final int type2 = existingWindow.mAttrs.type;
755
756 // Base application windows should be z-ordered BELOW all other windows in the app token.
757 if (type1 == TYPE_BASE_APPLICATION && type2 != TYPE_BASE_APPLICATION) {
758 return false;
759 } else if (type1 != TYPE_BASE_APPLICATION && type2 == TYPE_BASE_APPLICATION) {
760 return true;
761 }
762
763 // Starting windows should be z-ordered ABOVE all other windows in the app token.
764 if (type1 == TYPE_APPLICATION_STARTING && type2 != TYPE_APPLICATION_STARTING) {
765 return true;
766 } else if (type1 != TYPE_APPLICATION_STARTING && type2 == TYPE_APPLICATION_STARTING) {
767 return false;
768 }
769
770 // Otherwise the new window is greater than the existing window.
771 return true;
772 }
773
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700774 @Override
Robert Carra1eb4392015-12-10 12:43:51 -0800775 void addWindow(WindowState w) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700776 super.addWindow(w);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700777
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700778 boolean gotReplacementWindow = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700779 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700780 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700781 gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w);
782 }
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700783
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700784 // if we got a replacement window, reset the timeout to give drawing more time
785 if (gotReplacementWindow) {
786 mService.scheduleWindowReplacementTimeouts(this);
Robert Carra1eb4392015-12-10 12:43:51 -0800787 }
Jorim Jaggife762342016-10-13 14:33:27 +0200788 checkKeyguardFlagsChanged();
789 }
790
791 @Override
792 void removeChild(WindowState child) {
793 super.removeChild(child);
794 checkKeyguardFlagsChanged();
Robert Carra1eb4392015-12-10 12:43:51 -0800795 }
796
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700797 private boolean waitingForReplacement() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700798 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700799 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700800 if (candidate.waitingForReplacement()) {
Robert Carra1eb4392015-12-10 12:43:51 -0800801 return true;
802 }
803 }
804 return false;
805 }
806
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700807 void onWindowReplacementTimeout() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700808 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700809 (mChildren.get(i)).onWindowReplacementTimeout();
Robert Carra1eb4392015-12-10 12:43:51 -0800810 }
811 }
812
Chong Zhangd78ddb42016-03-02 17:01:14 -0800813 private boolean canFreezeBounds() {
814 // For freeform windows, we can't freeze the bounds at the moment because this would make
815 // the resizing unresponsive.
816 return mTask != null && !mTask.inFreeformWorkspace();
817 }
818
Jorim Jaggi0429f352015-12-22 16:29:16 +0100819 /**
820 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
821 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
822 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
823 * with a queue.
824 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800825 private void freezeBounds() {
Jorim Jaggi0429f352015-12-22 16:29:16 +0100826 mFrozenBounds.offer(new Rect(mTask.mPreparedFrozenBounds));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700827
828 if (mTask.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) {
829 // We didn't call prepareFreezingBounds on the task, so use the current value.
Andrii Kulian441e4492016-09-29 15:25:00 -0700830 mFrozenMergedConfig.offer(new Configuration(mTask.getConfiguration()));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700831 } else {
832 mFrozenMergedConfig.offer(new Configuration(mTask.mPreparedFrozenMergedConfig));
833 }
Andrii Kulianb10330d2016-09-16 13:51:46 -0700834 // Calling unset() to make it equal to Configuration.EMPTY.
835 mTask.mPreparedFrozenMergedConfig.unset();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100836 }
837
838 /**
839 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
840 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800841 private void unfreezeBounds() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700842 if (!mFrozenBounds.isEmpty()) {
843 mFrozenBounds.remove();
844 }
845 if (!mFrozenMergedConfig.isEmpty()) {
846 mFrozenMergedConfig.remove();
847 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700848 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700849 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700850 win.onUnfreezeBounds();
Jorim Jaggi4846ee32016-01-07 17:39:12 +0100851 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700852 mService.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100853 }
854
Robert Carr91b228092016-06-28 17:32:37 -0700855 void addSurfaceViewBackground(WindowSurfaceController.SurfaceControlWithBackground background) {
856 mSurfaceViewBackgrounds.add(background);
857 }
858
859 void removeSurfaceViewBackground(WindowSurfaceController.SurfaceControlWithBackground background) {
860 mSurfaceViewBackgrounds.remove(background);
861 updateSurfaceViewBackgroundVisibilities();
862 }
863
864 // We use DimLayers behind SurfaceViews to prevent holes while resizing and creating.
865 // However, we need to ensure one SurfaceView doesn't cover another when they are both placed
866 // below the main app window (as traditionally a SurfaceView which is never drawn
867 // to is totally translucent). So we look at all our SurfaceView backgrounds and only enable
868 // the background for the SurfaceView with lowest Z order
869 void updateSurfaceViewBackgroundVisibilities() {
870 WindowSurfaceController.SurfaceControlWithBackground bottom = null;
871 int bottomLayer = Integer.MAX_VALUE;
872 for (int i = 0; i < mSurfaceViewBackgrounds.size(); i++) {
873 WindowSurfaceController.SurfaceControlWithBackground sc = mSurfaceViewBackgrounds.get(i);
874 if (sc.mVisible && sc.mLayer < bottomLayer) {
875 bottomLayer = sc.mLayer;
876 bottom = sc;
877 }
878 }
879 for (int i = 0; i < mSurfaceViewBackgrounds.size(); i++) {
880 WindowSurfaceController.SurfaceControlWithBackground sc = mSurfaceViewBackgrounds.get(i);
881 sc.updateBackgroundVisibility(sc != bottom);
882 }
883 }
884
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700885 void resetJustMovedInStack() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700886 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700887 (mChildren.get(i)).resetJustMovedInStack();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700888 }
889 }
890
891 void notifyMovedInStack() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700892 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700893 final WindowState win = mChildren.get(winNdx);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700894 win.notifyMovedInStack();
895 }
896 }
897
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700898 void setAppLayoutChanges(int changes, String reason) {
899 if (!mChildren.isEmpty()) {
900 final DisplayContent dc = getDisplayContent();
901 dc.pendingLayoutChanges |= changes;
902 if (DEBUG_LAYOUT_REPEATS) {
903 mService.mWindowPlacerLocked.debugLayoutRepeats(reason, dc.pendingLayoutChanges);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700904 }
905 }
906 }
907
908 void removeReplacedWindowIfNeeded(WindowState replacement) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700909 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700910 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700911 if (win.removeReplacedWindowIfNeeded(replacement)) {
912 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700913 }
914 }
915 }
916
917 void startFreezingScreen() {
918 if (DEBUG_ORIENTATION) logWithStack(TAG, "Set freezing of " + appToken + ": hidden="
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700919 + hidden + " freezing=" + mAppAnimator.freezingScreen + " hiddenRequested="
920 + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700921 if (!hiddenRequested) {
922 if (!mAppAnimator.freezingScreen) {
923 mAppAnimator.freezingScreen = true;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700924 mService.registerAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700925 mAppAnimator.lastFreezeDuration = 0;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700926 mService.mAppsFreezingScreen++;
927 if (mService.mAppsFreezingScreen == 1) {
928 mService.startFreezingDisplayLocked(false, 0, 0);
929 mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT);
930 mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700931 }
932 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700933 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700934 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700935 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700936 w.onStartFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700937 }
938 }
939 }
940
941 void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) {
942 if (!mAppAnimator.freezingScreen) {
943 return;
944 }
945 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + this + " force=" + force);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700946 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700947 boolean unfrozeWindows = false;
948 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700949 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700950 unfrozeWindows |= w.onStopFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700951 }
952 if (force || unfrozeWindows) {
953 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this);
954 mAppAnimator.freezingScreen = false;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700955 mService.unregisterAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700956 mAppAnimator.lastFreezeDuration =
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700957 (int)(SystemClock.elapsedRealtime() - mService.mDisplayFreezeTime);
958 mService.mAppsFreezingScreen--;
959 mService.mLastFinishedFreezeSource = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700960 }
961 if (unfreezeSurfaceNow) {
962 if (unfrozeWindows) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700963 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700964 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700965 mService.stopFreezingDisplayLocked();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700966 }
967 }
968
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700969 @Override
970 public void onAppFreezeTimeout() {
971 Slog.w(TAG_WM, "Force clearing freeze: " + this);
972 stopFreezingScreen(true, true);
973 }
974
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700975 boolean transferStartingWindow(IBinder transferFrom) {
Wale Ogunwale02319a62016-09-26 15:21:22 -0700976 final AppWindowToken fromToken = getDisplayContent().getAppWindowToken(transferFrom);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700977 if (fromToken == null) {
978 return false;
979 }
980
981 final WindowState tStartingWindow = fromToken.startingWindow;
982 if (tStartingWindow != null && fromToken.startingView != null) {
983 // In this case, the starting icon has already been displayed, so start
984 // letting windows get shown immediately without any more transitions.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700985 mService.mSkipAppTransitionAnimation = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700986
987 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow
988 + " from " + fromToken + " to " + this);
989
990 final long origId = Binder.clearCallingIdentity();
991
992 // Transfer the starting window over to the new token.
993 startingData = fromToken.startingData;
994 startingView = fromToken.startingView;
995 startingDisplayed = fromToken.startingDisplayed;
996 fromToken.startingDisplayed = false;
997 startingWindow = tStartingWindow;
998 reportedVisible = fromToken.reportedVisible;
999 fromToken.startingData = null;
1000 fromToken.startingView = null;
1001 fromToken.startingWindow = null;
1002 fromToken.startingMoved = true;
1003 tStartingWindow.mToken = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001004 tStartingWindow.mAppToken = this;
1005
1006 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1007 "Removing starting window: " + tStartingWindow);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001008 getDisplayContent().removeFromWindowList(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001009 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1010 "Removing starting " + tStartingWindow + " from " + fromToken);
Wale Ogunwalefa854eb2016-09-20 13:43:52 -07001011 fromToken.removeChild(tStartingWindow);
1012 fromToken.postWindowRemoveStartingWindowCleanup(tStartingWindow);
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001013 addWindow(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001014
1015 // Propagate other interesting state between the tokens. If the old token is displayed,
1016 // we should immediately force the new one to be displayed. If it is animating, we need
1017 // to move that animation to the new one.
1018 if (fromToken.allDrawn) {
1019 allDrawn = true;
1020 deferClearAllDrawn = fromToken.deferClearAllDrawn;
1021 }
1022 if (fromToken.firstWindowDrawn) {
1023 firstWindowDrawn = true;
1024 }
1025 if (!fromToken.hidden) {
1026 hidden = false;
1027 hiddenRequested = false;
1028 }
1029 if (clientHidden != fromToken.clientHidden) {
1030 clientHidden = fromToken.clientHidden;
1031 sendAppVisibilityToClients();
1032 }
1033 fromToken.mAppAnimator.transferCurrentAnimation(
1034 mAppAnimator, tStartingWindow.mWinAnimator);
1035
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001036 mService.updateFocusedWindowLocked(
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001037 UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/);
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001038 getDisplayContent().setLayoutNeeded();
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001039 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001040 Binder.restoreCallingIdentity(origId);
1041 return true;
1042 } else if (fromToken.startingData != null) {
1043 // The previous app was getting ready to show a
1044 // starting window, but hasn't yet done so. Steal it!
1045 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1046 "Moving pending starting from " + fromToken + " to " + this);
1047 startingData = fromToken.startingData;
1048 fromToken.startingData = null;
1049 fromToken.startingMoved = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001050 final Message m = mService.mH.obtainMessage(H.ADD_STARTING, this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001051 // Note: we really want to do sendMessageAtFrontOfQueue() because we want to process the
1052 // message ASAP, before any other queued messages.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001053 mService.mH.sendMessageAtFrontOfQueue(m);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001054 return true;
1055 }
1056
1057 final AppWindowAnimator tAppAnimator = fromToken.mAppAnimator;
1058 final AppWindowAnimator wAppAnimator = mAppAnimator;
1059 if (tAppAnimator.thumbnail != null) {
1060 // The old token is animating with a thumbnail, transfer that to the new token.
1061 if (wAppAnimator.thumbnail != null) {
1062 wAppAnimator.thumbnail.destroy();
1063 }
1064 wAppAnimator.thumbnail = tAppAnimator.thumbnail;
1065 wAppAnimator.thumbnailLayer = tAppAnimator.thumbnailLayer;
1066 wAppAnimator.thumbnailAnimation = tAppAnimator.thumbnailAnimation;
1067 tAppAnimator.thumbnail = null;
1068 }
1069 return false;
1070 }
1071
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001072 boolean isLastWindow(WindowState win) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001073 return mChildren.size() == 1 && mChildren.get(0) == win;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001074 }
1075
1076 void setAllAppWinAnimators() {
1077 final ArrayList<WindowStateAnimator> allAppWinAnimators = mAppAnimator.mAllAppWinAnimators;
1078 allAppWinAnimators.clear();
1079
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001080 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001081 for (int j = 0; j < windowsCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001082 (mChildren.get(j)).addWinAnimatorToList(allAppWinAnimators);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001083 }
1084 }
1085
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001086 @Override
1087 void onAppTransitionDone() {
1088 sendingToBottom = false;
1089 }
1090
Wale Ogunwale51362492016-09-08 17:49:17 -07001091 /**
1092 * We override because this class doesn't want its children affecting its reported orientation
1093 * in anyway.
1094 */
1095 @Override
1096 int getOrientation() {
1097 if (hidden || hiddenRequested) {
1098 return SCREEN_ORIENTATION_UNSET;
1099 }
1100 return mOrientation;
1101 }
1102
Craig Mautnerdbb79912012-03-01 18:59:14 -08001103 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001104 void checkAppWindowsReadyToShow() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001105 if (allDrawn == mAppAnimator.allDrawn) {
1106 return;
1107 }
1108
1109 mAppAnimator.allDrawn = allDrawn;
1110 if (!allDrawn) {
1111 return;
1112 }
1113
1114 // The token has now changed state to having all windows shown... what to do, what to do?
1115 if (mAppAnimator.freezingScreen) {
1116 mAppAnimator.showAllWindowsLocked();
1117 stopFreezingScreen(false, true);
1118 if (DEBUG_ORIENTATION) Slog.i(TAG,
1119 "Setting mOrientationChangeComplete=true because wtoken " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001120 + " numInteresting=" + mNumInterestingWindows + " numDrawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001121 // This will set mOrientationChangeComplete and cause a pass through layout.
1122 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001123 "checkAppWindowsReadyToShow: freezingScreen");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001124 } else {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001125 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001126
1127 // We can now show all of the drawn windows!
1128 if (!mService.mOpeningApps.contains(this)) {
1129 mService.mAnimator.orAnimating(mAppAnimator.showAllWindowsLocked());
1130 }
1131 }
1132 }
1133
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001134 void updateAllDrawn(DisplayContent dc) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001135 if (!allDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001136 final int numInteresting = mNumInterestingWindows;
1137 if (numInteresting > 0 && mNumDrawnWindows >= numInteresting) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001138 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawn: " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001139 + " interesting=" + numInteresting + " drawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001140 allDrawn = true;
1141 // Force an additional layout pass where
1142 // WindowStateAnimator#commitFinishDrawingLocked() will call performShowLocked().
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001143 dc.setLayoutNeeded();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001144 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
1145 }
1146 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001147
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001148 if (!allDrawnExcludingSaved) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001149 int numInteresting = mNumInterestingWindowsExcludingSaved;
1150 if (numInteresting > 0 && mNumDrawnWindowsExcludingSaved >= numInteresting) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001151 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawnExcludingSaved: " + this
1152 + " interesting=" + numInteresting
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001153 + " drawn=" + mNumDrawnWindowsExcludingSaved);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001154 allDrawnExcludingSaved = true;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001155 dc.setLayoutNeeded();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001156 if (isAnimatingInvisibleWithSavedSurface()
1157 && !mService.mFinishedEarlyAnim.contains(this)) {
1158 mService.mFinishedEarlyAnim.add(this);
1159 }
1160 }
1161 }
1162 }
1163
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001164 /**
1165 * Updated this app token tracking states for interesting and drawn windows based on the window.
1166 *
1167 * @return Returns true if the input window is considered interesting and drawn while all the
1168 * windows in this app token where not considered drawn as of the last pass.
1169 */
1170 boolean updateDrawnWindowStates(WindowState w) {
1171 if (DEBUG_STARTING_WINDOW && w == startingWindow) {
1172 Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" + w.isOnScreen()
1173 + " allDrawn=" + allDrawn + " freezingScreen=" + mAppAnimator.freezingScreen);
1174 }
1175
1176 if (allDrawn && allDrawnExcludingSaved && !mAppAnimator.freezingScreen) {
1177 return false;
1178 }
1179
1180 if (mLastTransactionSequence != mService.mTransactionSequence) {
1181 mLastTransactionSequence = mService.mTransactionSequence;
1182 mNumInterestingWindows = mNumDrawnWindows = 0;
1183 mNumInterestingWindowsExcludingSaved = 0;
1184 mNumDrawnWindowsExcludingSaved = 0;
1185 startingDisplayed = false;
1186 }
1187
1188 final WindowStateAnimator winAnimator = w.mWinAnimator;
1189
1190 boolean isInterestingAndDrawn = false;
1191
1192 if (!allDrawn && w.mightAffectAllDrawn(false /* visibleOnly */)) {
1193 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
1194 Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw()
1195 + ", isAnimationSet=" + winAnimator.isAnimationSet());
1196 if (!w.isDrawnLw()) {
1197 Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController
1198 + " pv=" + w.mPolicyVisibility
1199 + " mDrawState=" + winAnimator.drawStateToString()
1200 + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested
1201 + " a=" + winAnimator.mAnimating);
1202 }
1203 }
1204
1205 if (w != startingWindow) {
1206 if (w.isInteresting()) {
1207 mNumInterestingWindows++;
1208 if (w.isDrawnLw()) {
1209 mNumDrawnWindows++;
1210
1211 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, "tokenMayBeDrawn: "
1212 + this + " w=" + w + " numInteresting=" + mNumInterestingWindows
1213 + " freezingScreen=" + mAppAnimator.freezingScreen
1214 + " mAppFreezing=" + w.mAppFreezing);
1215
1216 isInterestingAndDrawn = true;
1217 }
1218 }
1219 } else if (w.isDrawnLw()) {
1220 mService.mH.sendEmptyMessage(NOTIFY_STARTING_WINDOW_DRAWN);
1221 startingDisplayed = true;
1222 }
1223 }
1224
1225 if (!allDrawnExcludingSaved && w.mightAffectAllDrawn(true /* visibleOnly */)) {
1226 if (w != startingWindow && w.isInteresting()) {
1227 mNumInterestingWindowsExcludingSaved++;
1228 if (w.isDrawnLw() && !w.isAnimatingWithSavedSurface()) {
1229 mNumDrawnWindowsExcludingSaved++;
1230
1231 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
1232 "tokenMayBeDrawnExcludingSaved: " + this + " w=" + w
1233 + " numInteresting=" + mNumInterestingWindowsExcludingSaved
1234 + " freezingScreen=" + mAppAnimator.freezingScreen
1235 + " mAppFreezing=" + w.mAppFreezing);
1236
1237 isInterestingAndDrawn = true;
1238 }
1239 }
1240 }
1241
1242 return isInterestingAndDrawn;
1243 }
1244
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001245 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001246 void stepAppWindowsAnimation(long currentTime) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001247 mAppAnimator.wasAnimating = mAppAnimator.animating;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001248 if (mAppAnimator.stepAnimationLocked(currentTime)) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001249 mAppAnimator.animating = true;
1250 mService.mAnimator.setAnimating(true);
1251 mService.mAnimator.mAppWindowAnimating = true;
1252 } else if (mAppAnimator.wasAnimating) {
1253 // stopped animating, do one more pass through the layout
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001254 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER, "appToken " + this + " done");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001255 if (DEBUG_ANIM) Slog.v(TAG, "updateWindowsApps...: done animating " + this);
1256 }
1257 }
1258
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001259 int rebuildWindowListUnchecked(int addIndex) {
1260 return super.rebuildWindowList(addIndex);
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001261 }
1262
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001263 @Override
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001264 int rebuildWindowList(int addIndex) {
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001265 if (mIsExiting && !waitingForReplacement()) {
1266 return addIndex;
1267 }
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001268 return rebuildWindowListUnchecked(addIndex);
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001269 }
1270
1271 @Override
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001272 AppWindowToken asAppWindowToken() {
1273 // I am an app window token!
1274 return this;
1275 }
1276
1277 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -07001278 boolean fillsParent() {
1279 return mFillsParent;
1280 }
1281
1282 void setFillsParent(boolean fillsParent) {
1283 mFillsParent = fillsParent;
1284 }
1285
Jorim Jaggife762342016-10-13 14:33:27 +02001286 boolean containsDismissKeyguardWindow() {
1287 for (int i = mChildren.size() - 1; i >= 0; i--) {
1288 if ((mChildren.get(i).mAttrs.flags & FLAG_DISMISS_KEYGUARD) != 0) {
1289 return true;
1290 }
1291 }
1292 return false;
1293 }
1294
1295 boolean containsShowWhenLockedWindow() {
1296 for (int i = mChildren.size() - 1; i >= 0; i--) {
1297 if ((mChildren.get(i).mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
1298 return true;
1299 }
1300 }
1301 return false;
1302 }
1303
1304 void checkKeyguardFlagsChanged() {
1305 final boolean containsDismissKeyguard = containsDismissKeyguardWindow();
1306 final boolean containsShowWhenLocked = containsShowWhenLockedWindow();
1307 if (containsDismissKeyguard != mLastContainsDismissKeyguardWindow
1308 || containsShowWhenLocked != mLastContainsShowWhenLockedWindow) {
1309 mService.notifyKeyguardFlagsChanged(null /* callback */);
1310 }
1311 mLastContainsDismissKeyguardWindow = containsDismissKeyguard;
1312 mLastContainsShowWhenLockedWindow = containsShowWhenLocked;
1313 }
1314
Wale Ogunwale51362492016-09-08 17:49:17 -07001315 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001316 void dump(PrintWriter pw, String prefix) {
1317 super.dump(pw, prefix);
1318 if (appToken != null) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001319 pw.print(prefix); pw.print("app=true voiceInteraction="); pw.println(voiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001320 }
Craig Mautner83162a92015-01-26 14:43:30 -08001321 pw.print(prefix); pw.print("task="); pw.println(mTask);
Wale Ogunwale51362492016-09-08 17:49:17 -07001322 pw.print(prefix); pw.print(" mFillsParent="); pw.print(mFillsParent);
1323 pw.print(" mOrientation="); pw.println(mOrientation);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001324 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
1325 pw.print(" clientHidden="); pw.print(clientHidden);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -07001326 pw.print(" reportedDrawn="); pw.print(reportedDrawn);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001327 pw.print(" reportedVisible="); pw.println(reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -07001328 if (paused) {
1329 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001330 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001331 if (mAppStopped) {
1332 pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped);
1333 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001334 if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0
Craig Mautner6fbda632012-07-03 09:26:39 -07001335 || allDrawn || mAppAnimator.allDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001336 pw.print(prefix); pw.print("mNumInterestingWindows=");
1337 pw.print(mNumInterestingWindows);
1338 pw.print(" mNumDrawnWindows="); pw.print(mNumDrawnWindows);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001339 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -07001340 pw.print(" allDrawn="); pw.print(allDrawn);
1341 pw.print(" (animator="); pw.print(mAppAnimator.allDrawn);
1342 pw.println(")");
1343 }
1344 if (inPendingTransaction) {
1345 pw.print(prefix); pw.print("inPendingTransaction=");
1346 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001347 }
Craig Mautner799bc1d2015-01-14 10:33:48 -08001348 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001349 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
1350 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -08001351 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -08001352 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001353 }
1354 if (startingWindow != null || startingView != null
1355 || startingDisplayed || startingMoved) {
1356 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
1357 pw.print(" startingView="); pw.print(startingView);
1358 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001359 pw.print(" startingMoved="); pw.println(startingMoved);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001360 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01001361 if (!mFrozenBounds.isEmpty()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -08001362 pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds);
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001363 pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig);
Chong Zhangd78ddb42016-03-02 17:01:14 -08001364 }
1365 if (mPendingRelaunchCount != 0) {
1366 pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount);
Jorim Jaggi0429f352015-12-22 16:29:16 +01001367 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001368 }
1369
1370 @Override
1371 public String toString() {
1372 if (stringName == null) {
1373 StringBuilder sb = new StringBuilder();
1374 sb.append("AppWindowToken{");
1375 sb.append(Integer.toHexString(System.identityHashCode(this)));
1376 sb.append(" token="); sb.append(token); sb.append('}');
1377 stringName = sb.toString();
1378 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001379 return stringName + ((mIsExiting) ? " mIsExiting=" : "");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001380 }
Jeff Browne9bdb312012-04-05 15:30:10 -07001381}