blob: 0844d48b866967f8635b156f95982533d2d86b8b [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;
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -080050import com.android.internal.util.ToBooleanFunction;
Jeff Brown4532e612012-04-05 14:27:12 -070051import com.android.server.input.InputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080052import com.android.server.wm.WindowManagerService.H;
53
Filip Gruszczynskia590c992015-11-25 16:45:26 -080054import android.annotation.NonNull;
Jorim Jaggi26c8c422016-05-09 19:57:25 -070055import android.content.res.Configuration;
Jorim Jaggi0429f352015-12-22 16:29:16 +010056import android.graphics.Rect;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070057import android.os.Binder;
58import android.os.IBinder;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080059import android.os.Message;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070060import android.os.SystemClock;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080061import android.util.Slog;
62import android.view.IApplicationToken;
63import android.view.View;
64import android.view.WindowManager;
Jorim Jaggi6626f542016-08-22 13:08:44 -070065import android.view.animation.Animation;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080066
67import java.io.PrintWriter;
Jorim Jaggi0429f352015-12-22 16:29:16 +010068import java.util.ArrayDeque;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080069import java.util.ArrayList;
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -080070import java.util.function.Function;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080071
72class AppTokenList extends ArrayList<AppWindowToken> {
73}
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080074
75/**
76 * Version of WindowToken that is specifically for a particular application (or
77 * really activity) that is displaying windows.
78 */
Wale Ogunwale3f4433d2016-08-18 20:42:42 -070079class AppWindowToken extends WindowToken implements WindowManagerService.AppFreezeListener {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080080 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppWindowToken" : TAG_WM;
81
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080082 // Non-null only for application tokens.
83 final IApplicationToken appToken;
84
Filip Gruszczynskia590c992015-11-25 16:45:26 -080085 @NonNull final AppWindowAnimator mAppAnimator;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -070086
Dianne Hackborne30e02f2014-05-27 18:24:45 -070087 final boolean voiceInteraction;
88
Wale Ogunwalef6192862016-09-10 13:42:30 -070089 // TODO: Use getParent instead?
Craig Mautner83162a92015-01-26 14:43:30 -080090 Task mTask;
Wale Ogunwale51362492016-09-08 17:49:17 -070091 /** @see WindowContainer#fillsParent() */
92 private boolean mFillsParent;
Craig Mautner4c5eb222013-11-18 12:59:05 -080093 boolean layoutConfigChanges;
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -070094 boolean showForAllUsers;
Yorke Lee0e852472016-06-15 10:03:18 -070095 int targetSdk;
Craig Mautnera2c77052012-03-26 12:14:43 -070096
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080097 // The input dispatching timeout for this application token in nanoseconds.
98 long inputDispatchingTimeoutNanos;
99
100 // These are used for determining when all windows associated with
101 // an activity have been drawn, so they can be made visible together
102 // at the same time.
Craig Mautner764983d2012-03-22 11:37:36 -0700103 // initialize so that it doesn't match mTransactionSequence which is an int.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700104 private long mLastTransactionSequence = Long.MIN_VALUE;
105 private int mNumInterestingWindows;
106 private int mNumDrawnWindows;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800107 boolean inPendingTransaction;
108 boolean allDrawn;
Craig Mautner7636dfb2012-11-16 15:24:11 -0800109 // Set to true when this app creates a surface while in the middle of an animation. In that
110 // case do not clear allDrawn until the animation completes.
111 boolean deferClearAllDrawn;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800112
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700113 /**
114 * These are to track the app's real drawing status if there were no saved surfaces.
115 * @see #updateDrawnWindowStates
116 */
Chong Zhang8e4bda92016-05-04 15:08:18 -0700117 boolean allDrawnExcludingSaved;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700118 private int mNumInterestingWindowsExcludingSaved;
119 private int mNumDrawnWindowsExcludingSaved;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700120
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800121 // Is this window's surface needed? This is almost like hidden, except
122 // it will sometimes be true a little earlier: when the token has
123 // been shown, but is still waiting for its app transition to execute
124 // before making its windows shown.
125 boolean hiddenRequested;
126
127 // Have we told the window clients to hide themselves?
128 boolean clientHidden;
129
130 // Last visibility state we reported to the app token.
131 boolean reportedVisible;
132
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700133 // Last drawn state we reported to the app token.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700134 private boolean reportedDrawn;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700135
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800136 // Set to true when the token has been removed from the window mgr.
137 boolean removed;
138
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800139 // Information about an application starting window if displayed.
140 StartingData startingData;
141 WindowState startingWindow;
142 View startingView;
143 boolean startingDisplayed;
144 boolean startingMoved;
145 boolean firstWindowDrawn;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700146 private final WindowState.UpdateReportedVisibilityResults mReportedVisibilityResults =
147 new WindowState.UpdateReportedVisibilityResults();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800148
149 // Input application handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700150 final InputApplicationHandle mInputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800151
Wale Ogunwale571771c2016-08-26 13:18:50 -0700152 // TODO: Have a WindowContainer state for tracking exiting/deferred removal.
Craig Mautner799bc1d2015-01-14 10:33:48 -0800153 boolean mIsExiting;
Craig Mautner9ef471f2014-02-07 13:11:47 -0800154
Craig Mautnerbb742462014-07-07 15:28:55 -0700155 boolean mLaunchTaskBehind;
Craig Mautner8746a472014-07-24 15:12:54 -0700156 boolean mEnteringAnimation;
Craig Mautnerbb742462014-07-07 15:28:55 -0700157
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800158 boolean mAlwaysFocusable;
159
Robert Carre12aece2016-02-02 22:43:27 -0800160 boolean mAppStopped;
Robert Carrfd10cd12016-06-29 16:41:50 -0700161 int mRotationAnimationHint;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700162 private int mPendingRelaunchCount;
Robert Carre12aece2016-02-02 22:43:27 -0800163
Jorim Jaggife762342016-10-13 14:33:27 +0200164 private boolean mLastContainsShowWhenLockedWindow;
165 private boolean mLastContainsDismissKeyguardWindow;
166
Robert Carr91b228092016-06-28 17:32:37 -0700167 private ArrayList<WindowSurfaceController.SurfaceControlWithBackground> mSurfaceViewBackgrounds =
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700168 new ArrayList<>();
Robert Carr91b228092016-06-28 17:32:37 -0700169
Jorim Jaggi0429f352015-12-22 16:29:16 +0100170 ArrayDeque<Rect> mFrozenBounds = new ArrayDeque<>();
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700171 ArrayDeque<Configuration> mFrozenMergedConfig = new ArrayDeque<>();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100172
Wale Ogunwale02319a62016-09-26 15:21:22 -0700173 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean _voiceInteraction,
174 DisplayContent displayContent) {
175 super(service, token != null ? token.asBinder() : null, TYPE_APPLICATION, true,
176 displayContent);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700177 appToken = token;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700178 voiceInteraction = _voiceInteraction;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800179 mInputApplicationHandle = new InputApplicationHandle(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700180 mAppAnimator = new AppWindowAnimator(this, service);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800181 }
182
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800183 void onFirstWindowDrawn(WindowState win, WindowStateAnimator winAnimator) {
184 firstWindowDrawn = true;
185
186 // We now have a good window to show, remove dead placeholders
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700187 removeDeadWindows();
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800188
189 if (startingData != null) {
190 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, "Finish starting "
191 + win.mToken + ": first real window is shown, no animation");
192 // If this initial window is animating, stop it -- we will do an animation to reveal
193 // it from behind the starting window, so there is no need for it to also be doing its
194 // own stuff.
195 winAnimator.clearAnimation();
196 winAnimator.mService.mFinishedStarting.add(this);
197 winAnimator.mService.mH.sendEmptyMessage(H.FINISHED_STARTING);
198 }
199 updateReportedVisibilityLocked();
200 }
201
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800202 void updateReportedVisibilityLocked() {
203 if (appToken == null) {
204 return;
205 }
206
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700207 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700208 final int count = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800209
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700210 mReportedVisibilityResults.reset();
211
212 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700213 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700214 win.updateReportedVisibility(mReportedVisibilityResults);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800215 }
216
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700217 int numInteresting = mReportedVisibilityResults.numInteresting;
218 int numVisible = mReportedVisibilityResults.numVisible;
219 int numDrawn = mReportedVisibilityResults.numDrawn;
220 boolean nowGone = mReportedVisibilityResults.nowGone;
221
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700222 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800223 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700224 if (!nowGone) {
225 // If the app is not yet gone, then it can only become visible/drawn.
226 if (!nowDrawn) {
227 nowDrawn = reportedDrawn;
228 }
229 if (!nowVisible) {
230 nowVisible = reportedVisible;
231 }
232 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800233 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800234 + numInteresting + " visible=" + numVisible);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700235 if (nowDrawn != reportedDrawn) {
236 if (nowDrawn) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700237 mService.mH.obtainMessage(H.REPORT_APPLICATION_TOKEN_DRAWN, this).sendToTarget();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700238 }
239 reportedDrawn = nowDrawn;
240 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800241 if (nowVisible != reportedVisible) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700242 if (DEBUG_VISIBILITY) Slog.v(TAG,
243 "Visibility changed in " + this + ": vis=" + nowVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800244 reportedVisible = nowVisible;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700245 mService.mH.obtainMessage(H.REPORT_APPLICATION_TOKEN_WINDOWS,
246 nowVisible ? 1 : 0, nowGone ? 1 : 0, this).sendToTarget();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800247 }
248 }
249
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700250 boolean setVisibility(WindowManager.LayoutParams lp,
251 boolean visible, int transit, boolean performLayout, boolean isVoiceInteraction) {
252
253 boolean delayed = false;
254 inPendingTransaction = false;
255
256 if (clientHidden == visible) {
257 clientHidden = !visible;
258 sendAppVisibilityToClients();
259 }
260
261 // Allow for state changes and animation to be applied if:
262 // * token is transitioning visibility state
263 // * or the token was marked as hidden and is exiting before we had a chance to play the
264 // transition animation
265 // * or this is an opening app and windows are being replaced.
266 boolean visibilityChanged = false;
267 if (hidden == visible || (hidden && mIsExiting) || (visible && waitingForReplacement())) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700268 final AccessibilityController accessibilityController = mService.mAccessibilityController;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700269 boolean changed = false;
270 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
271 "Changing app " + this + " hidden=" + hidden + " performLayout=" + performLayout);
272
273 boolean runningAppAnimation = false;
274
275 if (transit != AppTransition.TRANSIT_UNSET) {
276 if (mAppAnimator.animation == AppWindowAnimator.sDummyAnimation) {
277 mAppAnimator.setNullAnimation();
278 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700279 if (mService.applyAnimationLocked(this, lp, transit, visible, isVoiceInteraction)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700280 delayed = runningAppAnimation = true;
281 }
282 final WindowState window = findMainWindow();
283 //TODO (multidisplay): Magnification is supported only for the default display.
284 if (window != null && accessibilityController != null
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700285 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700286 accessibilityController.onAppWindowTransitionLocked(window, transit);
287 }
288 changed = true;
289 }
290
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700291 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700292 for (int i = 0; i < windowsCount; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700293 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700294 changed |= win.onAppVisibilityChanged(visible, runningAppAnimation);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700295 }
296
297 hidden = hiddenRequested = !visible;
298 visibilityChanged = true;
299 if (!visible) {
300 stopFreezingScreen(true, true);
301 } else {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700302 // If we are being set visible, and the starting window is not yet displayed,
303 // then make sure it doesn't get displayed.
304 if (startingWindow != null && !startingWindow.isDrawnLw()) {
305 startingWindow.mPolicyVisibility = false;
306 startingWindow.mPolicyVisibilityAfterAnim = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700307 }
308 }
309
310 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setVisibility: " + this
311 + ": hidden=" + hidden + " hiddenRequested=" + hiddenRequested);
312
313 if (changed) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700314 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700315 if (performLayout) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700316 mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700317 false /*updateInputWindows*/);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700318 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700319 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700320 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700321 }
322 }
323
324 if (mAppAnimator.animation != null) {
325 delayed = true;
326 }
327
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700328 for (int i = mChildren.size() - 1; i >= 0 && !delayed; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700329 if ((mChildren.get(i)).isWindowAnimationSet()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700330 delayed = true;
331 }
332 }
333
334 if (visibilityChanged) {
335 if (visible && !delayed) {
336 // The token was made immediately visible, there will be no entrance animation.
337 // We need to inform the client the enter animation was finished.
338 mEnteringAnimation = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700339 mService.mActivityManagerAppTransitionNotifier.onAppTransitionFinishedLocked(token);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700340 }
341
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700342 if (!mService.mClosingApps.contains(this) && !mService.mOpeningApps.contains(this)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700343 // The token is not closing nor opening, so even if there is an animation set, that
344 // doesn't mean that it goes through the normal app transition cycle so we have
345 // to inform the docked controller about visibility change.
Andrii Kulian1e32e022016-09-16 15:29:34 -0700346 // TODO(multi-display): notify docked divider on all displays where visibility was
347 // affected.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700348 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700349 .notifyAppVisibilityChanged();
350 }
351 }
352
353 return delayed;
354 }
355
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800356 WindowState findMainWindow() {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700357 WindowState candidate = null;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700358 int j = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800359 while (j > 0) {
360 j--;
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700361 final WindowState win = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700362 final int type = win.mAttrs.type;
363 // No need to loop through child window as base application and starting types can't be
364 // child windows.
365 if (type == TYPE_BASE_APPLICATION || type == TYPE_APPLICATION_STARTING) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700366 // In cases where there are multiple windows, we prefer the non-exiting window. This
Sungsoo Lim0d3d1f82015-12-02 14:47:59 +0900367 // happens for example when replacing windows during an activity relaunch. When
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700368 // constructing the animation, we want the new window, not the exiting one.
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800369 if (win.mAnimatingExit) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700370 candidate = win;
371 } else {
372 return win;
373 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800374 }
375 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700376 return candidate;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800377 }
378
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800379 boolean windowsAreFocusable() {
380 return StackId.canReceiveKeys(mTask.mStack.mStackId) || mAlwaysFocusable;
Wale Ogunwaled045c822015-12-02 09:14:28 -0800381 }
382
Wale Ogunwale571771c2016-08-26 13:18:50 -0700383 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -0700384 boolean isVisible() {
Wale Ogunwalee471be62016-10-03 07:53:55 -0700385 // If the app token isn't hidden then it is considered visible and there is no need to check
386 // its children windows to see if they are visible.
387 return !hidden;
Wale Ogunwale44f21802016-09-02 12:49:48 -0700388 }
389
390 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -0700391 void removeIfPossible() {
Craig Mautnere3119b72015-01-20 15:02:36 -0800392 mIsExiting = false;
393 removeAllWindows();
Wale Ogunwale571771c2016-08-26 13:18:50 -0700394 if (mTask != null) {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700395 mTask.mStack.mExitingAppTokens.remove(this);
396 mTask.removeChild(this);
Craig Mautnere3119b72015-01-20 15:02:36 -0800397 }
398 }
399
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700400 @Override
401 boolean checkCompleteDeferredRemoval() {
402 if (mIsExiting) {
403 removeIfPossible();
404 }
405 return super.checkCompleteDeferredRemoval();
406 }
407
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700408 void onRemovedFromDisplay() {
409 AppWindowToken startingToken = null;
410
411 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app token: " + this);
412
413 boolean delayed = setVisibility(null, false, TRANSIT_UNSET, true, voiceInteraction);
414
415 mService.mOpeningApps.remove(this);
416 waitingToShow = false;
417 if (mService.mClosingApps.contains(this)) {
418 delayed = true;
419 } else if (mService.mAppTransition.isTransitionSet()) {
420 mService.mClosingApps.add(this);
421 delayed = true;
422 }
423
424 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app " + this + " delayed=" + delayed
425 + " animation=" + mAppAnimator.animation + " animating=" + mAppAnimator.animating);
426
427 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM, "removeAppToken: "
428 + this + " delayed=" + delayed + " Callers=" + Debug.getCallers(4));
429
430 final TaskStack stack = mTask.mStack;
431 if (delayed && !isEmpty()) {
432 // set the token aside because it has an active animation to be finished
433 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM,
434 "removeAppToken make exiting: " + this);
435 stack.mExitingAppTokens.add(this);
436 mIsExiting = true;
437 } else {
438 // Make sure there is no animation running on this token, so any windows associated
439 // with it will be removed as soon as their animations are complete
440 mAppAnimator.clearAnimation();
441 mAppAnimator.animating = false;
442 removeIfPossible();
443 }
444
445 removed = true;
446 if (startingData != null) {
447 startingToken = this;
448 }
449 stopFreezingScreen(true, true);
450 if (mService.mFocusedApp == this) {
451 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "Removing focused app token:" + this);
452 mService.mFocusedApp = null;
453 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
454 mService.mInputMonitor.setFocusedAppLw(null);
455 }
456
457 if (!delayed) {
458 updateReportedVisibilityLocked();
459 }
460
461 // Will only remove if startingToken non null.
462 mService.scheduleRemoveStartingWindowLocked(startingToken);
463 }
464
Chong Zhange05bcb12016-07-26 17:47:29 -0700465 void clearAnimatingFlags() {
Chong Zhangb0d26702016-08-12 16:03:29 -0700466 boolean wallpaperMightChange = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700467 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700468 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700469 wallpaperMightChange |= win.clearAnimatingFlags();
Chong Zhange05bcb12016-07-26 17:47:29 -0700470 }
Chong Zhangb0d26702016-08-12 16:03:29 -0700471 if (wallpaperMightChange) {
472 requestUpdateWallpaperIfNeeded();
473 }
Chong Zhange05bcb12016-07-26 17:47:29 -0700474 }
475
Robert Carre12aece2016-02-02 22:43:27 -0800476 void destroySurfaces() {
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700477 destroySurfaces(false /*cleanupOnResume*/);
478 }
479
480 /**
481 * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure
482 * the client has finished with them.
483 *
484 * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If
485 * set to true, destroy only surfaces of removed windows, and clear relevant flags of the
486 * others so that they are ready to be reused. If set to false (common case), destroy all
487 * surfaces that's eligible, if the app is already stopped.
488 */
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700489 private void destroySurfaces(boolean cleanupOnResume) {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700490 boolean destroyedSomething = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700491 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700492 final WindowState win = mChildren.get(i);
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700493 destroyedSomething |= win.destroySurface(cleanupOnResume, mAppStopped);
Robert Carre12aece2016-02-02 22:43:27 -0800494 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700495 if (destroyedSomething) {
496 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700497 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Robert Carre12aece2016-02-02 22:43:27 -0800498 }
499 }
500
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800501 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700502 * Notify that the app is now resumed, and it was not stopped before, perform a clean
503 * up of the surfaces
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800504 */
Chong Zhangad24f962016-08-25 12:12:33 -0700505 void notifyAppResumed(boolean wasStopped, boolean allowSavedSurface) {
506 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped
507 + " allowSavedSurface=" + allowSavedSurface + " " + this);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700508 mAppStopped = false;
509 if (!wasStopped) {
510 destroySurfaces(true /*cleanupOnResume*/);
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800511 }
Chong Zhangad24f962016-08-25 12:12:33 -0700512 if (!allowSavedSurface) {
513 destroySavedSurfaces();
514 }
Robert Carre12aece2016-02-02 22:43:27 -0800515 }
516
Chong Zhangbef461f2015-10-27 11:38:24 -0700517 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700518 * Notify that the app has stopped, and it is okay to destroy any surfaces which were
519 * keeping alive in case they were still being used.
520 */
521 void notifyAppStopped() {
522 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this);
523 mAppStopped = true;
524 destroySurfaces();
525 // Remove any starting window that was added for this app if they are still around.
526 mTask.mService.scheduleRemoveStartingWindowLocked(this);
527 }
528
529 /**
Chong Zhangbef461f2015-10-27 11:38:24 -0700530 * Checks whether we should save surfaces for this app.
531 *
532 * @return true if the surfaces should be saved, false otherwise.
533 */
534 boolean shouldSaveSurface() {
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800535 // We want to save surface if the app's windows are "allDrawn".
536 // (If we started entering animation early with saved surfaces, allDrawn
537 // should have been restored to true. So we'll save again in that case
538 // even if app didn't actually finish drawing.)
539 return allDrawn;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800540 }
541
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700542 private boolean canRestoreSurfaces() {
543 for (int i = mChildren.size() -1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700544 final WindowState w = mChildren.get(i);
Chong Zhang92147042016-05-09 12:47:11 -0700545 if (w.canRestoreSurface()) {
Robert Carr13f7be9e2015-12-02 18:39:45 -0800546 return true;
547 }
Chong Zhangbef461f2015-10-27 11:38:24 -0700548 }
549 return false;
550 }
551
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700552 private void clearWasVisibleBeforeClientHidden() {
553 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700554 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700555 w.clearWasVisibleBeforeClientHidden();
Chong Zhang92147042016-05-09 12:47:11 -0700556 }
557 }
558
Chong Zhang8e4bda92016-05-04 15:08:18 -0700559 /**
560 * Whether the app has some window that is invisible in layout, but
561 * animating with saved surface.
562 */
563 boolean isAnimatingInvisibleWithSavedSurface() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700564 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700565 final WindowState w = mChildren.get(i);
Chong Zhang8e4bda92016-05-04 15:08:18 -0700566 if (w.isAnimatingInvisibleWithSavedSurface()) {
567 return true;
568 }
569 }
570 return false;
571 }
572
573 /**
574 * Hide all window surfaces that's still invisible in layout but animating
575 * with a saved surface, and mark them destroying.
576 */
577 void stopUsingSavedSurfaceLocked() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700578 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700579 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700580 w.stopUsingSavedSurface();
Chong Zhang8e4bda92016-05-04 15:08:18 -0700581 }
582 destroySurfaces();
583 }
584
Chong Zhangf58631a2016-05-24 16:02:10 -0700585 void markSavedSurfaceExiting() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700586 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700587 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700588 w.markSavedSurfaceExiting();
Chong Zhangf58631a2016-05-24 16:02:10 -0700589 }
590 }
591
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700592 void restoreSavedSurfaceForInterestingWindows() {
Chong Zhang92147042016-05-09 12:47:11 -0700593 if (!canRestoreSurfaces()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700594 clearWasVisibleBeforeClientHidden();
Chong Zhangbef461f2015-10-27 11:38:24 -0700595 return;
596 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700597
598 // Check if all interesting windows are drawn and we can mark allDrawn=true.
599 int interestingNotDrawn = -1;
600
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700601 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700602 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700603 interestingNotDrawn = w.restoreSavedSurfaceForInterestingWindow();
Chong Zhangbef461f2015-10-27 11:38:24 -0700604 }
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800605
Chong Zhang92147042016-05-09 12:47:11 -0700606 if (!allDrawn) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700607 allDrawn = (interestingNotDrawn == 0);
Chong Zhang92147042016-05-09 12:47:11 -0700608 if (allDrawn) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700609 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Chong Zhang92147042016-05-09 12:47:11 -0700610 }
611 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700612 clearWasVisibleBeforeClientHidden();
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800613
614 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700615 "restoreSavedSurfaceForInterestingWindows: " + this + " allDrawn=" + allDrawn
616 + " interestingNotDrawn=" + interestingNotDrawn);
Chong Zhangbef461f2015-10-27 11:38:24 -0700617 }
618
619 void destroySavedSurfaces() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700620 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700621 final WindowState win = mChildren.get(i);
Robert Carr13f7be9e2015-12-02 18:39:45 -0800622 win.destroySavedSurface();
Chong Zhangbef461f2015-10-27 11:38:24 -0700623 }
Chong Zhang92147042016-05-09 12:47:11 -0700624 }
625
626 void clearAllDrawn() {
627 allDrawn = false;
628 deferClearAllDrawn = false;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700629 allDrawnExcludingSaved = false;
Chong Zhangbef461f2015-10-27 11:38:24 -0700630 }
631
Wale Ogunwalefa854eb2016-09-20 13:43:52 -0700632 void postWindowRemoveStartingWindowCleanup(WindowState win) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700633 // TODO: Something smells about the code below...Is there a better way?
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700634 if (startingWindow == win) {
635 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700636 mService.scheduleRemoveStartingWindowLocked(this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700637 } else if (mChildren.size() == 0 && startingData != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700638 // If this is the last window and we had requested a starting transition window,
639 // well there is no point now.
640 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingWindow");
641 startingData = null;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700642 } else if (mChildren.size() == 1 && startingView != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700643 // If this is the last window except for a starting transition window,
644 // we need to get rid of the starting transition.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700645 mService.scheduleRemoveStartingWindowLocked(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700646 }
647 }
648
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700649 void removeDeadWindows() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700650 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700651 WindowState win = mChildren.get(winNdx);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800652 if (win.mAppDied) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700653 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700654 "removeDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800655 // Set mDestroying, we don't want any animation or delayed removal here.
656 win.mDestroying = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700657 // Also removes child windows.
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700658 win.removeIfPossible();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800659 }
660 }
661 }
662
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700663 boolean hasWindowsAlive() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700664 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700665 // No need to loop through child windows as the answer should be the same as that of the
666 // parent window.
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700667 if (!(mChildren.get(i)).mAppDied) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700668 return true;
669 }
670 }
671 return false;
672 }
673
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700674 void setWillReplaceWindows(boolean animate) {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700675 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
676 "Marking app token " + this + " with replacing windows.");
Robert Carra1eb4392015-12-10 12:43:51 -0800677
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700678 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700679 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700680 w.setWillReplaceWindow(animate);
Robert Carra1eb4392015-12-10 12:43:51 -0800681 }
682 if (animate) {
683 // Set-up dummy animation so we can start treating windows associated with this
684 // token like they are in transition before the new app window is ready for us to
685 // run the real transition animation.
686 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700687 "setWillReplaceWindow() Setting dummy animation on: " + this);
Robert Carra1eb4392015-12-10 12:43:51 -0800688 mAppAnimator.setDummyAnimation();
689 }
690 }
691
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700692 void setWillReplaceChildWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700693 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this
Robert Carr23fa16b2016-01-13 13:19:58 -0800694 + " with replacing child windows.");
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700695 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700696 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700697 w.setWillReplaceChildWindows();
Robert Carr23fa16b2016-01-13 13:19:58 -0800698 }
699 }
700
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700701 void clearWillReplaceWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700702 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
703 "Resetting app token " + this + " of replacing window marks.");
Chong Zhangf596cd52016-01-05 13:42:44 -0800704
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700705 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700706 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700707 w.clearWillReplaceWindow();
Chong Zhangf596cd52016-01-05 13:42:44 -0800708 }
709 }
710
Chong Zhang4d7369a2016-04-25 16:09:14 -0700711 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700712 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700713 final WindowState w = mChildren.get(i);
Chong Zhang4d7369a2016-04-25 16:09:14 -0700714 w.requestUpdateWallpaperIfNeeded();
715 }
716 }
717
Chong Zhangd78ddb42016-03-02 17:01:14 -0800718 boolean isRelaunching() {
719 return mPendingRelaunchCount > 0;
720 }
721
722 void startRelaunching() {
723 if (canFreezeBounds()) {
724 freezeBounds();
725 }
726 mPendingRelaunchCount++;
727 }
728
729 void finishRelaunching() {
730 if (canFreezeBounds()) {
731 unfreezeBounds();
732 }
733 if (mPendingRelaunchCount > 0) {
734 mPendingRelaunchCount--;
735 }
736 }
737
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700738 void clearRelaunching() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700739 if (mPendingRelaunchCount == 0) {
740 return;
741 }
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700742 if (canFreezeBounds()) {
743 unfreezeBounds();
744 }
745 mPendingRelaunchCount = 0;
746 }
747
Wale Ogunwale07bcab72016-10-14 15:30:09 -0700748 /**
749 * Returns true if the new child window we are adding to this token is considered greater than
750 * the existing child window in this token in terms of z-order.
751 */
752 @Override
753 protected boolean isFirstChildWindowGreaterThanSecond(WindowState newWindow,
754 WindowState existingWindow) {
755 final int type1 = newWindow.mAttrs.type;
756 final int type2 = existingWindow.mAttrs.type;
757
758 // Base application windows should be z-ordered BELOW all other windows in the app token.
759 if (type1 == TYPE_BASE_APPLICATION && type2 != TYPE_BASE_APPLICATION) {
760 return false;
761 } else if (type1 != TYPE_BASE_APPLICATION && type2 == TYPE_BASE_APPLICATION) {
762 return true;
763 }
764
765 // Starting windows should be z-ordered ABOVE all other windows in the app token.
766 if (type1 == TYPE_APPLICATION_STARTING && type2 != TYPE_APPLICATION_STARTING) {
767 return true;
768 } else if (type1 != TYPE_APPLICATION_STARTING && type2 == TYPE_APPLICATION_STARTING) {
769 return false;
770 }
771
772 // Otherwise the new window is greater than the existing window.
773 return true;
774 }
775
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700776 @Override
Robert Carra1eb4392015-12-10 12:43:51 -0800777 void addWindow(WindowState w) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700778 super.addWindow(w);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700779
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700780 boolean gotReplacementWindow = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700781 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700782 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700783 gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w);
784 }
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700785
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700786 // if we got a replacement window, reset the timeout to give drawing more time
787 if (gotReplacementWindow) {
788 mService.scheduleWindowReplacementTimeouts(this);
Robert Carra1eb4392015-12-10 12:43:51 -0800789 }
Jorim Jaggife762342016-10-13 14:33:27 +0200790 checkKeyguardFlagsChanged();
791 }
792
793 @Override
794 void removeChild(WindowState child) {
795 super.removeChild(child);
796 checkKeyguardFlagsChanged();
Robert Carra1eb4392015-12-10 12:43:51 -0800797 }
798
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700799 private boolean waitingForReplacement() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700800 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700801 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700802 if (candidate.waitingForReplacement()) {
Robert Carra1eb4392015-12-10 12:43:51 -0800803 return true;
804 }
805 }
806 return false;
807 }
808
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700809 void onWindowReplacementTimeout() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700810 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700811 (mChildren.get(i)).onWindowReplacementTimeout();
Robert Carra1eb4392015-12-10 12:43:51 -0800812 }
813 }
814
Chong Zhangd78ddb42016-03-02 17:01:14 -0800815 private boolean canFreezeBounds() {
816 // For freeform windows, we can't freeze the bounds at the moment because this would make
817 // the resizing unresponsive.
818 return mTask != null && !mTask.inFreeformWorkspace();
819 }
820
Jorim Jaggi0429f352015-12-22 16:29:16 +0100821 /**
822 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
823 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
824 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
825 * with a queue.
826 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800827 private void freezeBounds() {
Jorim Jaggi0429f352015-12-22 16:29:16 +0100828 mFrozenBounds.offer(new Rect(mTask.mPreparedFrozenBounds));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700829
830 if (mTask.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) {
831 // We didn't call prepareFreezingBounds on the task, so use the current value.
Andrii Kulian441e4492016-09-29 15:25:00 -0700832 mFrozenMergedConfig.offer(new Configuration(mTask.getConfiguration()));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700833 } else {
834 mFrozenMergedConfig.offer(new Configuration(mTask.mPreparedFrozenMergedConfig));
835 }
Andrii Kulianb10330d2016-09-16 13:51:46 -0700836 // Calling unset() to make it equal to Configuration.EMPTY.
837 mTask.mPreparedFrozenMergedConfig.unset();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100838 }
839
840 /**
841 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
842 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800843 private void unfreezeBounds() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700844 if (!mFrozenBounds.isEmpty()) {
845 mFrozenBounds.remove();
846 }
847 if (!mFrozenMergedConfig.isEmpty()) {
848 mFrozenMergedConfig.remove();
849 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700850 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700851 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700852 win.onUnfreezeBounds();
Jorim Jaggi4846ee32016-01-07 17:39:12 +0100853 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700854 mService.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100855 }
856
Robert Carr91b228092016-06-28 17:32:37 -0700857 void addSurfaceViewBackground(WindowSurfaceController.SurfaceControlWithBackground background) {
858 mSurfaceViewBackgrounds.add(background);
859 }
860
861 void removeSurfaceViewBackground(WindowSurfaceController.SurfaceControlWithBackground background) {
862 mSurfaceViewBackgrounds.remove(background);
863 updateSurfaceViewBackgroundVisibilities();
864 }
865
866 // We use DimLayers behind SurfaceViews to prevent holes while resizing and creating.
867 // However, we need to ensure one SurfaceView doesn't cover another when they are both placed
868 // below the main app window (as traditionally a SurfaceView which is never drawn
869 // to is totally translucent). So we look at all our SurfaceView backgrounds and only enable
870 // the background for the SurfaceView with lowest Z order
871 void updateSurfaceViewBackgroundVisibilities() {
872 WindowSurfaceController.SurfaceControlWithBackground bottom = null;
873 int bottomLayer = Integer.MAX_VALUE;
874 for (int i = 0; i < mSurfaceViewBackgrounds.size(); i++) {
875 WindowSurfaceController.SurfaceControlWithBackground sc = mSurfaceViewBackgrounds.get(i);
876 if (sc.mVisible && sc.mLayer < bottomLayer) {
877 bottomLayer = sc.mLayer;
878 bottom = sc;
879 }
880 }
881 for (int i = 0; i < mSurfaceViewBackgrounds.size(); i++) {
882 WindowSurfaceController.SurfaceControlWithBackground sc = mSurfaceViewBackgrounds.get(i);
883 sc.updateBackgroundVisibility(sc != bottom);
884 }
885 }
886
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700887 void resetJustMovedInStack() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700888 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700889 (mChildren.get(i)).resetJustMovedInStack();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700890 }
891 }
892
893 void notifyMovedInStack() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700894 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700895 final WindowState win = mChildren.get(winNdx);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700896 win.notifyMovedInStack();
897 }
898 }
899
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700900 void setAppLayoutChanges(int changes, String reason) {
901 if (!mChildren.isEmpty()) {
902 final DisplayContent dc = getDisplayContent();
903 dc.pendingLayoutChanges |= changes;
904 if (DEBUG_LAYOUT_REPEATS) {
905 mService.mWindowPlacerLocked.debugLayoutRepeats(reason, dc.pendingLayoutChanges);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700906 }
907 }
908 }
909
910 void removeReplacedWindowIfNeeded(WindowState replacement) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700911 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700912 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700913 if (win.removeReplacedWindowIfNeeded(replacement)) {
914 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700915 }
916 }
917 }
918
919 void startFreezingScreen() {
920 if (DEBUG_ORIENTATION) logWithStack(TAG, "Set freezing of " + appToken + ": hidden="
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700921 + hidden + " freezing=" + mAppAnimator.freezingScreen + " hiddenRequested="
922 + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700923 if (!hiddenRequested) {
924 if (!mAppAnimator.freezingScreen) {
925 mAppAnimator.freezingScreen = true;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700926 mService.registerAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700927 mAppAnimator.lastFreezeDuration = 0;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700928 mService.mAppsFreezingScreen++;
929 if (mService.mAppsFreezingScreen == 1) {
930 mService.startFreezingDisplayLocked(false, 0, 0);
931 mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT);
932 mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700933 }
934 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700935 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700936 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700937 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700938 w.onStartFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700939 }
940 }
941 }
942
943 void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) {
944 if (!mAppAnimator.freezingScreen) {
945 return;
946 }
947 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + this + " force=" + force);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700948 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700949 boolean unfrozeWindows = false;
950 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700951 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700952 unfrozeWindows |= w.onStopFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700953 }
954 if (force || unfrozeWindows) {
955 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this);
956 mAppAnimator.freezingScreen = false;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700957 mService.unregisterAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700958 mAppAnimator.lastFreezeDuration =
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700959 (int)(SystemClock.elapsedRealtime() - mService.mDisplayFreezeTime);
960 mService.mAppsFreezingScreen--;
961 mService.mLastFinishedFreezeSource = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700962 }
963 if (unfreezeSurfaceNow) {
964 if (unfrozeWindows) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700965 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700966 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700967 mService.stopFreezingDisplayLocked();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700968 }
969 }
970
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700971 @Override
972 public void onAppFreezeTimeout() {
973 Slog.w(TAG_WM, "Force clearing freeze: " + this);
974 stopFreezingScreen(true, true);
975 }
976
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700977 boolean transferStartingWindow(IBinder transferFrom) {
Wale Ogunwale02319a62016-09-26 15:21:22 -0700978 final AppWindowToken fromToken = getDisplayContent().getAppWindowToken(transferFrom);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700979 if (fromToken == null) {
980 return false;
981 }
982
983 final WindowState tStartingWindow = fromToken.startingWindow;
984 if (tStartingWindow != null && fromToken.startingView != null) {
985 // In this case, the starting icon has already been displayed, so start
986 // letting windows get shown immediately without any more transitions.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700987 mService.mSkipAppTransitionAnimation = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700988
989 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow
990 + " from " + fromToken + " to " + this);
991
992 final long origId = Binder.clearCallingIdentity();
993
994 // Transfer the starting window over to the new token.
995 startingData = fromToken.startingData;
996 startingView = fromToken.startingView;
997 startingDisplayed = fromToken.startingDisplayed;
998 fromToken.startingDisplayed = false;
999 startingWindow = tStartingWindow;
1000 reportedVisible = fromToken.reportedVisible;
1001 fromToken.startingData = null;
1002 fromToken.startingView = null;
1003 fromToken.startingWindow = null;
1004 fromToken.startingMoved = true;
1005 tStartingWindow.mToken = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001006 tStartingWindow.mAppToken = this;
1007
1008 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1009 "Removing starting window: " + tStartingWindow);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001010 getDisplayContent().removeFromWindowList(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001011 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1012 "Removing starting " + tStartingWindow + " from " + fromToken);
Wale Ogunwalefa854eb2016-09-20 13:43:52 -07001013 fromToken.removeChild(tStartingWindow);
1014 fromToken.postWindowRemoveStartingWindowCleanup(tStartingWindow);
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001015 addWindow(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001016
1017 // Propagate other interesting state between the tokens. If the old token is displayed,
1018 // we should immediately force the new one to be displayed. If it is animating, we need
1019 // to move that animation to the new one.
1020 if (fromToken.allDrawn) {
1021 allDrawn = true;
1022 deferClearAllDrawn = fromToken.deferClearAllDrawn;
1023 }
1024 if (fromToken.firstWindowDrawn) {
1025 firstWindowDrawn = true;
1026 }
1027 if (!fromToken.hidden) {
1028 hidden = false;
1029 hiddenRequested = false;
1030 }
1031 if (clientHidden != fromToken.clientHidden) {
1032 clientHidden = fromToken.clientHidden;
1033 sendAppVisibilityToClients();
1034 }
1035 fromToken.mAppAnimator.transferCurrentAnimation(
1036 mAppAnimator, tStartingWindow.mWinAnimator);
1037
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001038 mService.updateFocusedWindowLocked(
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001039 UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/);
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001040 getDisplayContent().setLayoutNeeded();
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001041 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001042 Binder.restoreCallingIdentity(origId);
1043 return true;
1044 } else if (fromToken.startingData != null) {
1045 // The previous app was getting ready to show a
1046 // starting window, but hasn't yet done so. Steal it!
1047 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1048 "Moving pending starting from " + fromToken + " to " + this);
1049 startingData = fromToken.startingData;
1050 fromToken.startingData = null;
1051 fromToken.startingMoved = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001052 final Message m = mService.mH.obtainMessage(H.ADD_STARTING, this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001053 // Note: we really want to do sendMessageAtFrontOfQueue() because we want to process the
1054 // message ASAP, before any other queued messages.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001055 mService.mH.sendMessageAtFrontOfQueue(m);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001056 return true;
1057 }
1058
1059 final AppWindowAnimator tAppAnimator = fromToken.mAppAnimator;
1060 final AppWindowAnimator wAppAnimator = mAppAnimator;
1061 if (tAppAnimator.thumbnail != null) {
1062 // The old token is animating with a thumbnail, transfer that to the new token.
1063 if (wAppAnimator.thumbnail != null) {
1064 wAppAnimator.thumbnail.destroy();
1065 }
1066 wAppAnimator.thumbnail = tAppAnimator.thumbnail;
1067 wAppAnimator.thumbnailLayer = tAppAnimator.thumbnailLayer;
1068 wAppAnimator.thumbnailAnimation = tAppAnimator.thumbnailAnimation;
1069 tAppAnimator.thumbnail = null;
1070 }
1071 return false;
1072 }
1073
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001074 boolean isLastWindow(WindowState win) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001075 return mChildren.size() == 1 && mChildren.get(0) == win;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001076 }
1077
1078 void setAllAppWinAnimators() {
1079 final ArrayList<WindowStateAnimator> allAppWinAnimators = mAppAnimator.mAllAppWinAnimators;
1080 allAppWinAnimators.clear();
1081
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001082 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001083 for (int j = 0; j < windowsCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001084 (mChildren.get(j)).addWinAnimatorToList(allAppWinAnimators);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001085 }
1086 }
1087
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001088 @Override
1089 void onAppTransitionDone() {
1090 sendingToBottom = false;
1091 }
1092
Wale Ogunwale51362492016-09-08 17:49:17 -07001093 /**
1094 * We override because this class doesn't want its children affecting its reported orientation
1095 * in anyway.
1096 */
1097 @Override
1098 int getOrientation() {
1099 if (hidden || hiddenRequested) {
1100 return SCREEN_ORIENTATION_UNSET;
1101 }
1102 return mOrientation;
1103 }
1104
Craig Mautnerdbb79912012-03-01 18:59:14 -08001105 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001106 void checkAppWindowsReadyToShow() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001107 if (allDrawn == mAppAnimator.allDrawn) {
1108 return;
1109 }
1110
1111 mAppAnimator.allDrawn = allDrawn;
1112 if (!allDrawn) {
1113 return;
1114 }
1115
1116 // The token has now changed state to having all windows shown... what to do, what to do?
1117 if (mAppAnimator.freezingScreen) {
1118 mAppAnimator.showAllWindowsLocked();
1119 stopFreezingScreen(false, true);
1120 if (DEBUG_ORIENTATION) Slog.i(TAG,
1121 "Setting mOrientationChangeComplete=true because wtoken " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001122 + " numInteresting=" + mNumInterestingWindows + " numDrawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001123 // This will set mOrientationChangeComplete and cause a pass through layout.
1124 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001125 "checkAppWindowsReadyToShow: freezingScreen");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001126 } else {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001127 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001128
1129 // We can now show all of the drawn windows!
1130 if (!mService.mOpeningApps.contains(this)) {
1131 mService.mAnimator.orAnimating(mAppAnimator.showAllWindowsLocked());
1132 }
1133 }
1134 }
1135
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001136 void updateAllDrawn(DisplayContent dc) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001137 if (!allDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001138 final int numInteresting = mNumInterestingWindows;
1139 if (numInteresting > 0 && mNumDrawnWindows >= numInteresting) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001140 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawn: " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001141 + " interesting=" + numInteresting + " drawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001142 allDrawn = true;
1143 // Force an additional layout pass where
1144 // WindowStateAnimator#commitFinishDrawingLocked() will call performShowLocked().
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001145 dc.setLayoutNeeded();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001146 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
1147 }
1148 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001149
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001150 if (!allDrawnExcludingSaved) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001151 int numInteresting = mNumInterestingWindowsExcludingSaved;
1152 if (numInteresting > 0 && mNumDrawnWindowsExcludingSaved >= numInteresting) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001153 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawnExcludingSaved: " + this
1154 + " interesting=" + numInteresting
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001155 + " drawn=" + mNumDrawnWindowsExcludingSaved);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001156 allDrawnExcludingSaved = true;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001157 dc.setLayoutNeeded();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001158 if (isAnimatingInvisibleWithSavedSurface()
1159 && !mService.mFinishedEarlyAnim.contains(this)) {
1160 mService.mFinishedEarlyAnim.add(this);
1161 }
1162 }
1163 }
1164 }
1165
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001166 /**
1167 * Updated this app token tracking states for interesting and drawn windows based on the window.
1168 *
1169 * @return Returns true if the input window is considered interesting and drawn while all the
1170 * windows in this app token where not considered drawn as of the last pass.
1171 */
1172 boolean updateDrawnWindowStates(WindowState w) {
1173 if (DEBUG_STARTING_WINDOW && w == startingWindow) {
1174 Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" + w.isOnScreen()
1175 + " allDrawn=" + allDrawn + " freezingScreen=" + mAppAnimator.freezingScreen);
1176 }
1177
1178 if (allDrawn && allDrawnExcludingSaved && !mAppAnimator.freezingScreen) {
1179 return false;
1180 }
1181
1182 if (mLastTransactionSequence != mService.mTransactionSequence) {
1183 mLastTransactionSequence = mService.mTransactionSequence;
1184 mNumInterestingWindows = mNumDrawnWindows = 0;
1185 mNumInterestingWindowsExcludingSaved = 0;
1186 mNumDrawnWindowsExcludingSaved = 0;
1187 startingDisplayed = false;
1188 }
1189
1190 final WindowStateAnimator winAnimator = w.mWinAnimator;
1191
1192 boolean isInterestingAndDrawn = false;
1193
1194 if (!allDrawn && w.mightAffectAllDrawn(false /* visibleOnly */)) {
1195 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
1196 Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw()
1197 + ", isAnimationSet=" + winAnimator.isAnimationSet());
1198 if (!w.isDrawnLw()) {
1199 Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController
1200 + " pv=" + w.mPolicyVisibility
1201 + " mDrawState=" + winAnimator.drawStateToString()
1202 + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested
1203 + " a=" + winAnimator.mAnimating);
1204 }
1205 }
1206
1207 if (w != startingWindow) {
1208 if (w.isInteresting()) {
1209 mNumInterestingWindows++;
1210 if (w.isDrawnLw()) {
1211 mNumDrawnWindows++;
1212
1213 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, "tokenMayBeDrawn: "
1214 + this + " w=" + w + " numInteresting=" + mNumInterestingWindows
1215 + " freezingScreen=" + mAppAnimator.freezingScreen
1216 + " mAppFreezing=" + w.mAppFreezing);
1217
1218 isInterestingAndDrawn = true;
1219 }
1220 }
1221 } else if (w.isDrawnLw()) {
1222 mService.mH.sendEmptyMessage(NOTIFY_STARTING_WINDOW_DRAWN);
1223 startingDisplayed = true;
1224 }
1225 }
1226
1227 if (!allDrawnExcludingSaved && w.mightAffectAllDrawn(true /* visibleOnly */)) {
1228 if (w != startingWindow && w.isInteresting()) {
1229 mNumInterestingWindowsExcludingSaved++;
1230 if (w.isDrawnLw() && !w.isAnimatingWithSavedSurface()) {
1231 mNumDrawnWindowsExcludingSaved++;
1232
1233 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
1234 "tokenMayBeDrawnExcludingSaved: " + this + " w=" + w
1235 + " numInteresting=" + mNumInterestingWindowsExcludingSaved
1236 + " freezingScreen=" + mAppAnimator.freezingScreen
1237 + " mAppFreezing=" + w.mAppFreezing);
1238
1239 isInterestingAndDrawn = true;
1240 }
1241 }
1242 }
1243
1244 return isInterestingAndDrawn;
1245 }
1246
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001247 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001248 void stepAppWindowsAnimation(long currentTime) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001249 mAppAnimator.wasAnimating = mAppAnimator.animating;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001250 if (mAppAnimator.stepAnimationLocked(currentTime)) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001251 mAppAnimator.animating = true;
1252 mService.mAnimator.setAnimating(true);
1253 mService.mAnimator.mAppWindowAnimating = true;
1254 } else if (mAppAnimator.wasAnimating) {
1255 // stopped animating, do one more pass through the layout
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001256 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER, "appToken " + this + " done");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001257 if (DEBUG_ANIM) Slog.v(TAG, "updateWindowsApps...: done animating " + this);
1258 }
1259 }
1260
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001261 int rebuildWindowListUnchecked(int addIndex) {
1262 return super.rebuildWindowList(addIndex);
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001263 }
1264
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001265 @Override
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001266 int rebuildWindowList(int addIndex) {
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001267 if (mIsExiting && !waitingForReplacement()) {
1268 return addIndex;
1269 }
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001270 return rebuildWindowListUnchecked(addIndex);
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001271 }
1272
1273 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001274 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001275 // For legacy reasons we process the TaskStack.mExitingAppTokens first in DisplayContent
1276 // before the non-exiting app tokens. So, we skip the exiting app tokens here.
1277 // TODO: Investigate if we need to continue to do this or if we can just process them
1278 // in-order.
1279 if (mIsExiting && !waitingForReplacement()) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001280 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001281 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001282 return forAllWindowsUnchecked(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001283 }
1284
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001285 boolean forAllWindowsUnchecked(ToBooleanFunction<WindowState> callback,
1286 boolean traverseTopToBottom) {
1287 return super.forAllWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001288 }
1289
1290 @Override
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001291 AppWindowToken asAppWindowToken() {
1292 // I am an app window token!
1293 return this;
1294 }
1295
1296 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -07001297 boolean fillsParent() {
1298 return mFillsParent;
1299 }
1300
1301 void setFillsParent(boolean fillsParent) {
1302 mFillsParent = fillsParent;
1303 }
1304
Jorim Jaggife762342016-10-13 14:33:27 +02001305 boolean containsDismissKeyguardWindow() {
1306 for (int i = mChildren.size() - 1; i >= 0; i--) {
1307 if ((mChildren.get(i).mAttrs.flags & FLAG_DISMISS_KEYGUARD) != 0) {
1308 return true;
1309 }
1310 }
1311 return false;
1312 }
1313
1314 boolean containsShowWhenLockedWindow() {
1315 for (int i = mChildren.size() - 1; i >= 0; i--) {
1316 if ((mChildren.get(i).mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
1317 return true;
1318 }
1319 }
1320 return false;
1321 }
1322
1323 void checkKeyguardFlagsChanged() {
1324 final boolean containsDismissKeyguard = containsDismissKeyguardWindow();
1325 final boolean containsShowWhenLocked = containsShowWhenLockedWindow();
1326 if (containsDismissKeyguard != mLastContainsDismissKeyguardWindow
1327 || containsShowWhenLocked != mLastContainsShowWhenLockedWindow) {
1328 mService.notifyKeyguardFlagsChanged(null /* callback */);
1329 }
1330 mLastContainsDismissKeyguardWindow = containsDismissKeyguard;
1331 mLastContainsShowWhenLockedWindow = containsShowWhenLocked;
1332 }
1333
Wale Ogunwale51362492016-09-08 17:49:17 -07001334 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001335 void dump(PrintWriter pw, String prefix) {
1336 super.dump(pw, prefix);
1337 if (appToken != null) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001338 pw.print(prefix); pw.print("app=true voiceInteraction="); pw.println(voiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001339 }
Craig Mautner83162a92015-01-26 14:43:30 -08001340 pw.print(prefix); pw.print("task="); pw.println(mTask);
Wale Ogunwale51362492016-09-08 17:49:17 -07001341 pw.print(prefix); pw.print(" mFillsParent="); pw.print(mFillsParent);
1342 pw.print(" mOrientation="); pw.println(mOrientation);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001343 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
1344 pw.print(" clientHidden="); pw.print(clientHidden);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -07001345 pw.print(" reportedDrawn="); pw.print(reportedDrawn);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001346 pw.print(" reportedVisible="); pw.println(reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -07001347 if (paused) {
1348 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001349 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001350 if (mAppStopped) {
1351 pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped);
1352 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001353 if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0
Craig Mautner6fbda632012-07-03 09:26:39 -07001354 || allDrawn || mAppAnimator.allDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001355 pw.print(prefix); pw.print("mNumInterestingWindows=");
1356 pw.print(mNumInterestingWindows);
1357 pw.print(" mNumDrawnWindows="); pw.print(mNumDrawnWindows);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001358 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -07001359 pw.print(" allDrawn="); pw.print(allDrawn);
1360 pw.print(" (animator="); pw.print(mAppAnimator.allDrawn);
1361 pw.println(")");
1362 }
1363 if (inPendingTransaction) {
1364 pw.print(prefix); pw.print("inPendingTransaction=");
1365 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001366 }
Craig Mautner799bc1d2015-01-14 10:33:48 -08001367 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001368 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
1369 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -08001370 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -08001371 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001372 }
1373 if (startingWindow != null || startingView != null
1374 || startingDisplayed || startingMoved) {
1375 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
1376 pw.print(" startingView="); pw.print(startingView);
1377 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001378 pw.print(" startingMoved="); pw.println(startingMoved);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001379 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01001380 if (!mFrozenBounds.isEmpty()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -08001381 pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds);
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001382 pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig);
Chong Zhangd78ddb42016-03-02 17:01:14 -08001383 }
1384 if (mPendingRelaunchCount != 0) {
1385 pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount);
Jorim Jaggi0429f352015-12-22 16:29:16 +01001386 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001387 }
1388
1389 @Override
1390 public String toString() {
1391 if (stringName == null) {
1392 StringBuilder sb = new StringBuilder();
1393 sb.append("AppWindowToken{");
1394 sb.append(Integer.toHexString(System.identityHashCode(this)));
1395 sb.append(" token="); sb.append(token); sb.append('}');
1396 stringName = sb.toString();
1397 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001398 return stringName + ((mIsExiting) ? " mIsExiting=" : "");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001399 }
Jeff Browne9bdb312012-04-05 15:30:10 -07001400}