blob: 05e6f96b1b0c4cf9b7dd65949e24f2259921e893 [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;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -070069import java.util.function.Consumer;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080070
71class AppTokenList extends ArrayList<AppWindowToken> {
72}
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080073
74/**
75 * Version of WindowToken that is specifically for a particular application (or
76 * really activity) that is displaying windows.
77 */
Wale Ogunwale3f4433d2016-08-18 20:42:42 -070078class AppWindowToken extends WindowToken implements WindowManagerService.AppFreezeListener {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080079 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppWindowToken" : TAG_WM;
80
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080081 // Non-null only for application tokens.
82 final IApplicationToken appToken;
83
Filip Gruszczynskia590c992015-11-25 16:45:26 -080084 @NonNull final AppWindowAnimator mAppAnimator;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -070085
Dianne Hackborne30e02f2014-05-27 18:24:45 -070086 final boolean voiceInteraction;
87
Wale Ogunwalef6192862016-09-10 13:42:30 -070088 // TODO: Use getParent instead?
Craig Mautner83162a92015-01-26 14:43:30 -080089 Task mTask;
Wale Ogunwale51362492016-09-08 17:49:17 -070090 /** @see WindowContainer#fillsParent() */
91 private boolean mFillsParent;
Craig Mautner4c5eb222013-11-18 12:59:05 -080092 boolean layoutConfigChanges;
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -070093 boolean showForAllUsers;
Yorke Lee0e852472016-06-15 10:03:18 -070094 int targetSdk;
Craig Mautnera2c77052012-03-26 12:14:43 -070095
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080096 // The input dispatching timeout for this application token in nanoseconds.
97 long inputDispatchingTimeoutNanos;
98
99 // These are used for determining when all windows associated with
100 // an activity have been drawn, so they can be made visible together
101 // at the same time.
Craig Mautner764983d2012-03-22 11:37:36 -0700102 // initialize so that it doesn't match mTransactionSequence which is an int.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700103 private long mLastTransactionSequence = Long.MIN_VALUE;
104 private int mNumInterestingWindows;
105 private int mNumDrawnWindows;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800106 boolean inPendingTransaction;
107 boolean allDrawn;
Craig Mautner7636dfb2012-11-16 15:24:11 -0800108 // Set to true when this app creates a surface while in the middle of an animation. In that
109 // case do not clear allDrawn until the animation completes.
110 boolean deferClearAllDrawn;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800111
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700112 /**
113 * These are to track the app's real drawing status if there were no saved surfaces.
114 * @see #updateDrawnWindowStates
115 */
Chong Zhang8e4bda92016-05-04 15:08:18 -0700116 boolean allDrawnExcludingSaved;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700117 private int mNumInterestingWindowsExcludingSaved;
118 private int mNumDrawnWindowsExcludingSaved;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700119
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800120 // Is this window's surface needed? This is almost like hidden, except
121 // it will sometimes be true a little earlier: when the token has
122 // been shown, but is still waiting for its app transition to execute
123 // before making its windows shown.
124 boolean hiddenRequested;
125
126 // Have we told the window clients to hide themselves?
127 boolean clientHidden;
128
129 // Last visibility state we reported to the app token.
130 boolean reportedVisible;
131
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700132 // Last drawn state we reported to the app token.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700133 private boolean reportedDrawn;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700134
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800135 // Set to true when the token has been removed from the window mgr.
136 boolean removed;
137
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800138 // Information about an application starting window if displayed.
139 StartingData startingData;
140 WindowState startingWindow;
141 View startingView;
142 boolean startingDisplayed;
143 boolean startingMoved;
144 boolean firstWindowDrawn;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700145 private final WindowState.UpdateReportedVisibilityResults mReportedVisibilityResults =
146 new WindowState.UpdateReportedVisibilityResults();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800147
148 // Input application handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700149 final InputApplicationHandle mInputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800150
Wale Ogunwale571771c2016-08-26 13:18:50 -0700151 // TODO: Have a WindowContainer state for tracking exiting/deferred removal.
Craig Mautner799bc1d2015-01-14 10:33:48 -0800152 boolean mIsExiting;
Craig Mautner9ef471f2014-02-07 13:11:47 -0800153
Craig Mautnerbb742462014-07-07 15:28:55 -0700154 boolean mLaunchTaskBehind;
Craig Mautner8746a472014-07-24 15:12:54 -0700155 boolean mEnteringAnimation;
Craig Mautnerbb742462014-07-07 15:28:55 -0700156
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800157 boolean mAlwaysFocusable;
158
Robert Carre12aece2016-02-02 22:43:27 -0800159 boolean mAppStopped;
Robert Carrfd10cd12016-06-29 16:41:50 -0700160 int mRotationAnimationHint;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700161 private int mPendingRelaunchCount;
Robert Carre12aece2016-02-02 22:43:27 -0800162
Jorim Jaggife762342016-10-13 14:33:27 +0200163 private boolean mLastContainsShowWhenLockedWindow;
164 private boolean mLastContainsDismissKeyguardWindow;
165
Robert Carr91b228092016-06-28 17:32:37 -0700166 private ArrayList<WindowSurfaceController.SurfaceControlWithBackground> mSurfaceViewBackgrounds =
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700167 new ArrayList<>();
Robert Carr91b228092016-06-28 17:32:37 -0700168
Jorim Jaggi0429f352015-12-22 16:29:16 +0100169 ArrayDeque<Rect> mFrozenBounds = new ArrayDeque<>();
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700170 ArrayDeque<Configuration> mFrozenMergedConfig = new ArrayDeque<>();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100171
Wale Ogunwale02319a62016-09-26 15:21:22 -0700172 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean _voiceInteraction,
173 DisplayContent displayContent) {
174 super(service, token != null ? token.asBinder() : null, TYPE_APPLICATION, true,
175 displayContent);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700176 appToken = token;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700177 voiceInteraction = _voiceInteraction;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800178 mInputApplicationHandle = new InputApplicationHandle(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700179 mAppAnimator = new AppWindowAnimator(this, service);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800180 }
181
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800182 void onFirstWindowDrawn(WindowState win, WindowStateAnimator winAnimator) {
183 firstWindowDrawn = true;
184
185 // We now have a good window to show, remove dead placeholders
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700186 removeDeadWindows();
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800187
188 if (startingData != null) {
189 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, "Finish starting "
190 + win.mToken + ": first real window is shown, no animation");
191 // If this initial window is animating, stop it -- we will do an animation to reveal
192 // it from behind the starting window, so there is no need for it to also be doing its
193 // own stuff.
194 winAnimator.clearAnimation();
195 winAnimator.mService.mFinishedStarting.add(this);
196 winAnimator.mService.mH.sendEmptyMessage(H.FINISHED_STARTING);
197 }
198 updateReportedVisibilityLocked();
199 }
200
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800201 void updateReportedVisibilityLocked() {
202 if (appToken == null) {
203 return;
204 }
205
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700206 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700207 final int count = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800208
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700209 mReportedVisibilityResults.reset();
210
211 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700212 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700213 win.updateReportedVisibility(mReportedVisibilityResults);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800214 }
215
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700216 int numInteresting = mReportedVisibilityResults.numInteresting;
217 int numVisible = mReportedVisibilityResults.numVisible;
218 int numDrawn = mReportedVisibilityResults.numDrawn;
219 boolean nowGone = mReportedVisibilityResults.nowGone;
220
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700221 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800222 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700223 if (!nowGone) {
224 // If the app is not yet gone, then it can only become visible/drawn.
225 if (!nowDrawn) {
226 nowDrawn = reportedDrawn;
227 }
228 if (!nowVisible) {
229 nowVisible = reportedVisible;
230 }
231 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800232 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800233 + numInteresting + " visible=" + numVisible);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700234 if (nowDrawn != reportedDrawn) {
235 if (nowDrawn) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700236 mService.mH.obtainMessage(H.REPORT_APPLICATION_TOKEN_DRAWN, this).sendToTarget();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700237 }
238 reportedDrawn = nowDrawn;
239 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800240 if (nowVisible != reportedVisible) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700241 if (DEBUG_VISIBILITY) Slog.v(TAG,
242 "Visibility changed in " + this + ": vis=" + nowVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800243 reportedVisible = nowVisible;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700244 mService.mH.obtainMessage(H.REPORT_APPLICATION_TOKEN_WINDOWS,
245 nowVisible ? 1 : 0, nowGone ? 1 : 0, this).sendToTarget();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800246 }
247 }
248
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700249 boolean setVisibility(WindowManager.LayoutParams lp,
250 boolean visible, int transit, boolean performLayout, boolean isVoiceInteraction) {
251
252 boolean delayed = false;
253 inPendingTransaction = false;
254
255 if (clientHidden == visible) {
256 clientHidden = !visible;
257 sendAppVisibilityToClients();
258 }
259
260 // Allow for state changes and animation to be applied if:
261 // * token is transitioning visibility state
262 // * or the token was marked as hidden and is exiting before we had a chance to play the
263 // transition animation
264 // * or this is an opening app and windows are being replaced.
265 boolean visibilityChanged = false;
266 if (hidden == visible || (hidden && mIsExiting) || (visible && waitingForReplacement())) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700267 final AccessibilityController accessibilityController = mService.mAccessibilityController;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700268 boolean changed = false;
269 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
270 "Changing app " + this + " hidden=" + hidden + " performLayout=" + performLayout);
271
272 boolean runningAppAnimation = false;
273
274 if (transit != AppTransition.TRANSIT_UNSET) {
275 if (mAppAnimator.animation == AppWindowAnimator.sDummyAnimation) {
276 mAppAnimator.setNullAnimation();
277 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700278 if (mService.applyAnimationLocked(this, lp, transit, visible, isVoiceInteraction)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700279 delayed = runningAppAnimation = true;
280 }
281 final WindowState window = findMainWindow();
282 //TODO (multidisplay): Magnification is supported only for the default display.
283 if (window != null && accessibilityController != null
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700284 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700285 accessibilityController.onAppWindowTransitionLocked(window, transit);
286 }
287 changed = true;
288 }
289
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700290 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700291 for (int i = 0; i < windowsCount; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700292 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700293 changed |= win.onAppVisibilityChanged(visible, runningAppAnimation);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700294 }
295
296 hidden = hiddenRequested = !visible;
297 visibilityChanged = true;
298 if (!visible) {
299 stopFreezingScreen(true, true);
300 } else {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700301 // If we are being set visible, and the starting window is not yet displayed,
302 // then make sure it doesn't get displayed.
303 if (startingWindow != null && !startingWindow.isDrawnLw()) {
304 startingWindow.mPolicyVisibility = false;
305 startingWindow.mPolicyVisibilityAfterAnim = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700306 }
307 }
308
309 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setVisibility: " + this
310 + ": hidden=" + hidden + " hiddenRequested=" + hiddenRequested);
311
312 if (changed) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700313 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700314 if (performLayout) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700315 mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700316 false /*updateInputWindows*/);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700317 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700318 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700319 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700320 }
321 }
322
323 if (mAppAnimator.animation != null) {
324 delayed = true;
325 }
326
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700327 for (int i = mChildren.size() - 1; i >= 0 && !delayed; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700328 if ((mChildren.get(i)).isWindowAnimationSet()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700329 delayed = true;
330 }
331 }
332
333 if (visibilityChanged) {
334 if (visible && !delayed) {
335 // The token was made immediately visible, there will be no entrance animation.
336 // We need to inform the client the enter animation was finished.
337 mEnteringAnimation = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700338 mService.mActivityManagerAppTransitionNotifier.onAppTransitionFinishedLocked(token);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700339 }
340
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700341 if (!mService.mClosingApps.contains(this) && !mService.mOpeningApps.contains(this)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700342 // The token is not closing nor opening, so even if there is an animation set, that
343 // doesn't mean that it goes through the normal app transition cycle so we have
344 // to inform the docked controller about visibility change.
Andrii Kulian1e32e022016-09-16 15:29:34 -0700345 // TODO(multi-display): notify docked divider on all displays where visibility was
346 // affected.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700347 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700348 .notifyAppVisibilityChanged();
349 }
350 }
351
352 return delayed;
353 }
354
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800355 WindowState findMainWindow() {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700356 WindowState candidate = null;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700357 int j = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800358 while (j > 0) {
359 j--;
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700360 final WindowState win = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700361 final int type = win.mAttrs.type;
362 // No need to loop through child window as base application and starting types can't be
363 // child windows.
364 if (type == TYPE_BASE_APPLICATION || type == TYPE_APPLICATION_STARTING) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700365 // In cases where there are multiple windows, we prefer the non-exiting window. This
Sungsoo Lim0d3d1f82015-12-02 14:47:59 +0900366 // happens for example when replacing windows during an activity relaunch. When
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700367 // constructing the animation, we want the new window, not the exiting one.
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800368 if (win.mAnimatingExit) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700369 candidate = win;
370 } else {
371 return win;
372 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800373 }
374 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700375 return candidate;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800376 }
377
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800378 boolean windowsAreFocusable() {
379 return StackId.canReceiveKeys(mTask.mStack.mStackId) || mAlwaysFocusable;
Wale Ogunwaled045c822015-12-02 09:14:28 -0800380 }
381
Wale Ogunwale571771c2016-08-26 13:18:50 -0700382 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -0700383 boolean isVisible() {
Wale Ogunwalee471be62016-10-03 07:53:55 -0700384 // If the app token isn't hidden then it is considered visible and there is no need to check
385 // its children windows to see if they are visible.
386 return !hidden;
Wale Ogunwale44f21802016-09-02 12:49:48 -0700387 }
388
389 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -0700390 void removeIfPossible() {
Craig Mautnere3119b72015-01-20 15:02:36 -0800391 mIsExiting = false;
392 removeAllWindows();
Wale Ogunwale571771c2016-08-26 13:18:50 -0700393 if (mTask != null) {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700394 mTask.mStack.mExitingAppTokens.remove(this);
395 mTask.removeChild(this);
Craig Mautnere3119b72015-01-20 15:02:36 -0800396 }
397 }
398
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700399 @Override
400 boolean checkCompleteDeferredRemoval() {
401 if (mIsExiting) {
402 removeIfPossible();
403 }
404 return super.checkCompleteDeferredRemoval();
405 }
406
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700407 void onRemovedFromDisplay() {
408 AppWindowToken startingToken = null;
409
410 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app token: " + this);
411
412 boolean delayed = setVisibility(null, false, TRANSIT_UNSET, true, voiceInteraction);
413
414 mService.mOpeningApps.remove(this);
415 waitingToShow = false;
416 if (mService.mClosingApps.contains(this)) {
417 delayed = true;
418 } else if (mService.mAppTransition.isTransitionSet()) {
419 mService.mClosingApps.add(this);
420 delayed = true;
421 }
422
423 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app " + this + " delayed=" + delayed
424 + " animation=" + mAppAnimator.animation + " animating=" + mAppAnimator.animating);
425
426 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM, "removeAppToken: "
427 + this + " delayed=" + delayed + " Callers=" + Debug.getCallers(4));
428
429 final TaskStack stack = mTask.mStack;
430 if (delayed && !isEmpty()) {
431 // set the token aside because it has an active animation to be finished
432 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM,
433 "removeAppToken make exiting: " + this);
434 stack.mExitingAppTokens.add(this);
435 mIsExiting = true;
436 } else {
437 // Make sure there is no animation running on this token, so any windows associated
438 // with it will be removed as soon as their animations are complete
439 mAppAnimator.clearAnimation();
440 mAppAnimator.animating = false;
441 removeIfPossible();
442 }
443
444 removed = true;
445 if (startingData != null) {
446 startingToken = this;
447 }
448 stopFreezingScreen(true, true);
449 if (mService.mFocusedApp == this) {
450 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "Removing focused app token:" + this);
451 mService.mFocusedApp = null;
452 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
453 mService.mInputMonitor.setFocusedAppLw(null);
454 }
455
456 if (!delayed) {
457 updateReportedVisibilityLocked();
458 }
459
460 // Will only remove if startingToken non null.
461 mService.scheduleRemoveStartingWindowLocked(startingToken);
462 }
463
Chong Zhange05bcb12016-07-26 17:47:29 -0700464 void clearAnimatingFlags() {
Chong Zhangb0d26702016-08-12 16:03:29 -0700465 boolean wallpaperMightChange = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700466 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700467 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700468 wallpaperMightChange |= win.clearAnimatingFlags();
Chong Zhange05bcb12016-07-26 17:47:29 -0700469 }
Chong Zhangb0d26702016-08-12 16:03:29 -0700470 if (wallpaperMightChange) {
471 requestUpdateWallpaperIfNeeded();
472 }
Chong Zhange05bcb12016-07-26 17:47:29 -0700473 }
474
Robert Carre12aece2016-02-02 22:43:27 -0800475 void destroySurfaces() {
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700476 destroySurfaces(false /*cleanupOnResume*/);
477 }
478
479 /**
480 * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure
481 * the client has finished with them.
482 *
483 * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If
484 * set to true, destroy only surfaces of removed windows, and clear relevant flags of the
485 * others so that they are ready to be reused. If set to false (common case), destroy all
486 * surfaces that's eligible, if the app is already stopped.
487 */
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700488 private void destroySurfaces(boolean cleanupOnResume) {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700489 boolean destroyedSomething = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700490 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700491 final WindowState win = mChildren.get(i);
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700492 destroyedSomething |= win.destroySurface(cleanupOnResume, mAppStopped);
Robert Carre12aece2016-02-02 22:43:27 -0800493 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700494 if (destroyedSomething) {
495 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700496 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Robert Carre12aece2016-02-02 22:43:27 -0800497 }
498 }
499
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800500 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700501 * Notify that the app is now resumed, and it was not stopped before, perform a clean
502 * up of the surfaces
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800503 */
Chong Zhangad24f962016-08-25 12:12:33 -0700504 void notifyAppResumed(boolean wasStopped, boolean allowSavedSurface) {
505 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped
506 + " allowSavedSurface=" + allowSavedSurface + " " + this);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700507 mAppStopped = false;
508 if (!wasStopped) {
509 destroySurfaces(true /*cleanupOnResume*/);
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800510 }
Chong Zhangad24f962016-08-25 12:12:33 -0700511 if (!allowSavedSurface) {
512 destroySavedSurfaces();
513 }
Robert Carre12aece2016-02-02 22:43:27 -0800514 }
515
Chong Zhangbef461f2015-10-27 11:38:24 -0700516 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700517 * Notify that the app has stopped, and it is okay to destroy any surfaces which were
518 * keeping alive in case they were still being used.
519 */
520 void notifyAppStopped() {
521 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this);
522 mAppStopped = true;
523 destroySurfaces();
524 // Remove any starting window that was added for this app if they are still around.
525 mTask.mService.scheduleRemoveStartingWindowLocked(this);
526 }
527
528 /**
Chong Zhangbef461f2015-10-27 11:38:24 -0700529 * Checks whether we should save surfaces for this app.
530 *
531 * @return true if the surfaces should be saved, false otherwise.
532 */
533 boolean shouldSaveSurface() {
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800534 // We want to save surface if the app's windows are "allDrawn".
535 // (If we started entering animation early with saved surfaces, allDrawn
536 // should have been restored to true. So we'll save again in that case
537 // even if app didn't actually finish drawing.)
538 return allDrawn;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800539 }
540
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700541 private boolean canRestoreSurfaces() {
542 for (int i = mChildren.size() -1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700543 final WindowState w = mChildren.get(i);
Chong Zhang92147042016-05-09 12:47:11 -0700544 if (w.canRestoreSurface()) {
Robert Carr13f7be9e2015-12-02 18:39:45 -0800545 return true;
546 }
Chong Zhangbef461f2015-10-27 11:38:24 -0700547 }
548 return false;
549 }
550
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700551 private void clearWasVisibleBeforeClientHidden() {
552 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700553 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700554 w.clearWasVisibleBeforeClientHidden();
Chong Zhang92147042016-05-09 12:47:11 -0700555 }
556 }
557
Chong Zhang8e4bda92016-05-04 15:08:18 -0700558 /**
559 * Whether the app has some window that is invisible in layout, but
560 * animating with saved surface.
561 */
562 boolean isAnimatingInvisibleWithSavedSurface() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700563 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700564 final WindowState w = mChildren.get(i);
Chong Zhang8e4bda92016-05-04 15:08:18 -0700565 if (w.isAnimatingInvisibleWithSavedSurface()) {
566 return true;
567 }
568 }
569 return false;
570 }
571
572 /**
573 * Hide all window surfaces that's still invisible in layout but animating
574 * with a saved surface, and mark them destroying.
575 */
576 void stopUsingSavedSurfaceLocked() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700577 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700578 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700579 w.stopUsingSavedSurface();
Chong Zhang8e4bda92016-05-04 15:08:18 -0700580 }
581 destroySurfaces();
582 }
583
Chong Zhangf58631a2016-05-24 16:02:10 -0700584 void markSavedSurfaceExiting() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700585 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700586 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700587 w.markSavedSurfaceExiting();
Chong Zhangf58631a2016-05-24 16:02:10 -0700588 }
589 }
590
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700591 void restoreSavedSurfaceForInterestingWindows() {
Chong Zhang92147042016-05-09 12:47:11 -0700592 if (!canRestoreSurfaces()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700593 clearWasVisibleBeforeClientHidden();
Chong Zhangbef461f2015-10-27 11:38:24 -0700594 return;
595 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700596
597 // Check if all interesting windows are drawn and we can mark allDrawn=true.
598 int interestingNotDrawn = -1;
599
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700600 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700601 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700602 interestingNotDrawn = w.restoreSavedSurfaceForInterestingWindow();
Chong Zhangbef461f2015-10-27 11:38:24 -0700603 }
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800604
Chong Zhang92147042016-05-09 12:47:11 -0700605 if (!allDrawn) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700606 allDrawn = (interestingNotDrawn == 0);
Chong Zhang92147042016-05-09 12:47:11 -0700607 if (allDrawn) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700608 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Chong Zhang92147042016-05-09 12:47:11 -0700609 }
610 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700611 clearWasVisibleBeforeClientHidden();
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800612
613 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700614 "restoreSavedSurfaceForInterestingWindows: " + this + " allDrawn=" + allDrawn
615 + " interestingNotDrawn=" + interestingNotDrawn);
Chong Zhangbef461f2015-10-27 11:38:24 -0700616 }
617
618 void destroySavedSurfaces() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700619 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700620 final WindowState win = mChildren.get(i);
Robert Carr13f7be9e2015-12-02 18:39:45 -0800621 win.destroySavedSurface();
Chong Zhangbef461f2015-10-27 11:38:24 -0700622 }
Chong Zhang92147042016-05-09 12:47:11 -0700623 }
624
625 void clearAllDrawn() {
626 allDrawn = false;
627 deferClearAllDrawn = false;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700628 allDrawnExcludingSaved = false;
Chong Zhangbef461f2015-10-27 11:38:24 -0700629 }
630
Wale Ogunwalefa854eb2016-09-20 13:43:52 -0700631 void postWindowRemoveStartingWindowCleanup(WindowState win) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700632 // TODO: Something smells about the code below...Is there a better way?
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700633 if (startingWindow == win) {
634 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700635 mService.scheduleRemoveStartingWindowLocked(this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700636 } else if (mChildren.size() == 0 && startingData != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700637 // If this is the last window and we had requested a starting transition window,
638 // well there is no point now.
639 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingWindow");
640 startingData = null;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700641 } else if (mChildren.size() == 1 && startingView != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700642 // If this is the last window except for a starting transition window,
643 // we need to get rid of the starting transition.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700644 mService.scheduleRemoveStartingWindowLocked(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700645 }
646 }
647
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700648 void removeDeadWindows() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700649 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700650 WindowState win = mChildren.get(winNdx);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800651 if (win.mAppDied) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700652 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700653 "removeDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800654 // Set mDestroying, we don't want any animation or delayed removal here.
655 win.mDestroying = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700656 // Also removes child windows.
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700657 win.removeIfPossible();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800658 }
659 }
660 }
661
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700662 boolean hasWindowsAlive() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700663 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700664 // No need to loop through child windows as the answer should be the same as that of the
665 // parent window.
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700666 if (!(mChildren.get(i)).mAppDied) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700667 return true;
668 }
669 }
670 return false;
671 }
672
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700673 void setWillReplaceWindows(boolean animate) {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700674 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
675 "Marking app token " + this + " with replacing windows.");
Robert Carra1eb4392015-12-10 12:43:51 -0800676
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700677 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700678 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700679 w.setWillReplaceWindow(animate);
Robert Carra1eb4392015-12-10 12:43:51 -0800680 }
681 if (animate) {
682 // Set-up dummy animation so we can start treating windows associated with this
683 // token like they are in transition before the new app window is ready for us to
684 // run the real transition animation.
685 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700686 "setWillReplaceWindow() Setting dummy animation on: " + this);
Robert Carra1eb4392015-12-10 12:43:51 -0800687 mAppAnimator.setDummyAnimation();
688 }
689 }
690
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700691 void setWillReplaceChildWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700692 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this
Robert Carr23fa16b2016-01-13 13:19:58 -0800693 + " with replacing child windows.");
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700694 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700695 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700696 w.setWillReplaceChildWindows();
Robert Carr23fa16b2016-01-13 13:19:58 -0800697 }
698 }
699
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700700 void clearWillReplaceWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700701 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
702 "Resetting app token " + this + " of replacing window marks.");
Chong Zhangf596cd52016-01-05 13:42:44 -0800703
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700704 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700705 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700706 w.clearWillReplaceWindow();
Chong Zhangf596cd52016-01-05 13:42:44 -0800707 }
708 }
709
Chong Zhang4d7369a2016-04-25 16:09:14 -0700710 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700711 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700712 final WindowState w = mChildren.get(i);
Chong Zhang4d7369a2016-04-25 16:09:14 -0700713 w.requestUpdateWallpaperIfNeeded();
714 }
715 }
716
Chong Zhangd78ddb42016-03-02 17:01:14 -0800717 boolean isRelaunching() {
718 return mPendingRelaunchCount > 0;
719 }
720
721 void startRelaunching() {
722 if (canFreezeBounds()) {
723 freezeBounds();
724 }
725 mPendingRelaunchCount++;
726 }
727
728 void finishRelaunching() {
729 if (canFreezeBounds()) {
730 unfreezeBounds();
731 }
732 if (mPendingRelaunchCount > 0) {
733 mPendingRelaunchCount--;
734 }
735 }
736
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700737 void clearRelaunching() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700738 if (mPendingRelaunchCount == 0) {
739 return;
740 }
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700741 if (canFreezeBounds()) {
742 unfreezeBounds();
743 }
744 mPendingRelaunchCount = 0;
745 }
746
Wale Ogunwale07bcab72016-10-14 15:30:09 -0700747 /**
748 * Returns true if the new child window we are adding to this token is considered greater than
749 * the existing child window in this token in terms of z-order.
750 */
751 @Override
752 protected boolean isFirstChildWindowGreaterThanSecond(WindowState newWindow,
753 WindowState existingWindow) {
754 final int type1 = newWindow.mAttrs.type;
755 final int type2 = existingWindow.mAttrs.type;
756
757 // Base application windows should be z-ordered BELOW all other windows in the app token.
758 if (type1 == TYPE_BASE_APPLICATION && type2 != TYPE_BASE_APPLICATION) {
759 return false;
760 } else if (type1 != TYPE_BASE_APPLICATION && type2 == TYPE_BASE_APPLICATION) {
761 return true;
762 }
763
764 // Starting windows should be z-ordered ABOVE all other windows in the app token.
765 if (type1 == TYPE_APPLICATION_STARTING && type2 != TYPE_APPLICATION_STARTING) {
766 return true;
767 } else if (type1 != TYPE_APPLICATION_STARTING && type2 == TYPE_APPLICATION_STARTING) {
768 return false;
769 }
770
771 // Otherwise the new window is greater than the existing window.
772 return true;
773 }
774
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700775 @Override
Robert Carra1eb4392015-12-10 12:43:51 -0800776 void addWindow(WindowState w) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700777 super.addWindow(w);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700778
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700779 boolean gotReplacementWindow = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700780 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700781 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700782 gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w);
783 }
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700784
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700785 // if we got a replacement window, reset the timeout to give drawing more time
786 if (gotReplacementWindow) {
787 mService.scheduleWindowReplacementTimeouts(this);
Robert Carra1eb4392015-12-10 12:43:51 -0800788 }
Jorim Jaggife762342016-10-13 14:33:27 +0200789 checkKeyguardFlagsChanged();
790 }
791
792 @Override
793 void removeChild(WindowState child) {
794 super.removeChild(child);
795 checkKeyguardFlagsChanged();
Robert Carra1eb4392015-12-10 12:43:51 -0800796 }
797
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700798 private boolean waitingForReplacement() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700799 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700800 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700801 if (candidate.waitingForReplacement()) {
Robert Carra1eb4392015-12-10 12:43:51 -0800802 return true;
803 }
804 }
805 return false;
806 }
807
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700808 void onWindowReplacementTimeout() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700809 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700810 (mChildren.get(i)).onWindowReplacementTimeout();
Robert Carra1eb4392015-12-10 12:43:51 -0800811 }
812 }
813
Chong Zhangd78ddb42016-03-02 17:01:14 -0800814 private boolean canFreezeBounds() {
815 // For freeform windows, we can't freeze the bounds at the moment because this would make
816 // the resizing unresponsive.
817 return mTask != null && !mTask.inFreeformWorkspace();
818 }
819
Jorim Jaggi0429f352015-12-22 16:29:16 +0100820 /**
821 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
822 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
823 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
824 * with a queue.
825 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800826 private void freezeBounds() {
Jorim Jaggi0429f352015-12-22 16:29:16 +0100827 mFrozenBounds.offer(new Rect(mTask.mPreparedFrozenBounds));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700828
829 if (mTask.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) {
830 // We didn't call prepareFreezingBounds on the task, so use the current value.
Andrii Kulian441e4492016-09-29 15:25:00 -0700831 mFrozenMergedConfig.offer(new Configuration(mTask.getConfiguration()));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700832 } else {
833 mFrozenMergedConfig.offer(new Configuration(mTask.mPreparedFrozenMergedConfig));
834 }
Andrii Kulianb10330d2016-09-16 13:51:46 -0700835 // Calling unset() to make it equal to Configuration.EMPTY.
836 mTask.mPreparedFrozenMergedConfig.unset();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100837 }
838
839 /**
840 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
841 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800842 private void unfreezeBounds() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700843 if (!mFrozenBounds.isEmpty()) {
844 mFrozenBounds.remove();
845 }
846 if (!mFrozenMergedConfig.isEmpty()) {
847 mFrozenMergedConfig.remove();
848 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700849 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700850 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700851 win.onUnfreezeBounds();
Jorim Jaggi4846ee32016-01-07 17:39:12 +0100852 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700853 mService.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100854 }
855
Robert Carr91b228092016-06-28 17:32:37 -0700856 void addSurfaceViewBackground(WindowSurfaceController.SurfaceControlWithBackground background) {
857 mSurfaceViewBackgrounds.add(background);
858 }
859
860 void removeSurfaceViewBackground(WindowSurfaceController.SurfaceControlWithBackground background) {
861 mSurfaceViewBackgrounds.remove(background);
862 updateSurfaceViewBackgroundVisibilities();
863 }
864
865 // We use DimLayers behind SurfaceViews to prevent holes while resizing and creating.
866 // However, we need to ensure one SurfaceView doesn't cover another when they are both placed
867 // below the main app window (as traditionally a SurfaceView which is never drawn
868 // to is totally translucent). So we look at all our SurfaceView backgrounds and only enable
869 // the background for the SurfaceView with lowest Z order
870 void updateSurfaceViewBackgroundVisibilities() {
871 WindowSurfaceController.SurfaceControlWithBackground bottom = null;
872 int bottomLayer = Integer.MAX_VALUE;
873 for (int i = 0; i < mSurfaceViewBackgrounds.size(); i++) {
874 WindowSurfaceController.SurfaceControlWithBackground sc = mSurfaceViewBackgrounds.get(i);
875 if (sc.mVisible && sc.mLayer < bottomLayer) {
876 bottomLayer = sc.mLayer;
877 bottom = sc;
878 }
879 }
880 for (int i = 0; i < mSurfaceViewBackgrounds.size(); i++) {
881 WindowSurfaceController.SurfaceControlWithBackground sc = mSurfaceViewBackgrounds.get(i);
882 sc.updateBackgroundVisibility(sc != bottom);
883 }
884 }
885
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700886 void resetJustMovedInStack() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700887 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700888 (mChildren.get(i)).resetJustMovedInStack();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700889 }
890 }
891
892 void notifyMovedInStack() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700893 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700894 final WindowState win = mChildren.get(winNdx);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700895 win.notifyMovedInStack();
896 }
897 }
898
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700899 void setAppLayoutChanges(int changes, String reason) {
900 if (!mChildren.isEmpty()) {
901 final DisplayContent dc = getDisplayContent();
902 dc.pendingLayoutChanges |= changes;
903 if (DEBUG_LAYOUT_REPEATS) {
904 mService.mWindowPlacerLocked.debugLayoutRepeats(reason, dc.pendingLayoutChanges);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700905 }
906 }
907 }
908
909 void removeReplacedWindowIfNeeded(WindowState replacement) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700910 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700911 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700912 if (win.removeReplacedWindowIfNeeded(replacement)) {
913 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700914 }
915 }
916 }
917
918 void startFreezingScreen() {
919 if (DEBUG_ORIENTATION) logWithStack(TAG, "Set freezing of " + appToken + ": hidden="
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700920 + hidden + " freezing=" + mAppAnimator.freezingScreen + " hiddenRequested="
921 + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700922 if (!hiddenRequested) {
923 if (!mAppAnimator.freezingScreen) {
924 mAppAnimator.freezingScreen = true;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700925 mService.registerAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700926 mAppAnimator.lastFreezeDuration = 0;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700927 mService.mAppsFreezingScreen++;
928 if (mService.mAppsFreezingScreen == 1) {
929 mService.startFreezingDisplayLocked(false, 0, 0);
930 mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT);
931 mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700932 }
933 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700934 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700935 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700936 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700937 w.onStartFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700938 }
939 }
940 }
941
942 void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) {
943 if (!mAppAnimator.freezingScreen) {
944 return;
945 }
946 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + this + " force=" + force);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700947 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700948 boolean unfrozeWindows = false;
949 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700950 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700951 unfrozeWindows |= w.onStopFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700952 }
953 if (force || unfrozeWindows) {
954 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this);
955 mAppAnimator.freezingScreen = false;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700956 mService.unregisterAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700957 mAppAnimator.lastFreezeDuration =
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700958 (int)(SystemClock.elapsedRealtime() - mService.mDisplayFreezeTime);
959 mService.mAppsFreezingScreen--;
960 mService.mLastFinishedFreezeSource = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700961 }
962 if (unfreezeSurfaceNow) {
963 if (unfrozeWindows) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700964 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700965 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700966 mService.stopFreezingDisplayLocked();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700967 }
968 }
969
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700970 @Override
971 public void onAppFreezeTimeout() {
972 Slog.w(TAG_WM, "Force clearing freeze: " + this);
973 stopFreezingScreen(true, true);
974 }
975
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700976 boolean transferStartingWindow(IBinder transferFrom) {
Wale Ogunwale02319a62016-09-26 15:21:22 -0700977 final AppWindowToken fromToken = getDisplayContent().getAppWindowToken(transferFrom);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700978 if (fromToken == null) {
979 return false;
980 }
981
982 final WindowState tStartingWindow = fromToken.startingWindow;
983 if (tStartingWindow != null && fromToken.startingView != null) {
984 // In this case, the starting icon has already been displayed, so start
985 // letting windows get shown immediately without any more transitions.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700986 mService.mSkipAppTransitionAnimation = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700987
988 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow
989 + " from " + fromToken + " to " + this);
990
991 final long origId = Binder.clearCallingIdentity();
992
993 // Transfer the starting window over to the new token.
994 startingData = fromToken.startingData;
995 startingView = fromToken.startingView;
996 startingDisplayed = fromToken.startingDisplayed;
997 fromToken.startingDisplayed = false;
998 startingWindow = tStartingWindow;
999 reportedVisible = fromToken.reportedVisible;
1000 fromToken.startingData = null;
1001 fromToken.startingView = null;
1002 fromToken.startingWindow = null;
1003 fromToken.startingMoved = true;
1004 tStartingWindow.mToken = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001005 tStartingWindow.mAppToken = this;
1006
1007 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1008 "Removing starting window: " + tStartingWindow);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001009 getDisplayContent().removeFromWindowList(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001010 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1011 "Removing starting " + tStartingWindow + " from " + fromToken);
Wale Ogunwalefa854eb2016-09-20 13:43:52 -07001012 fromToken.removeChild(tStartingWindow);
1013 fromToken.postWindowRemoveStartingWindowCleanup(tStartingWindow);
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001014 addWindow(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001015
1016 // Propagate other interesting state between the tokens. If the old token is displayed,
1017 // we should immediately force the new one to be displayed. If it is animating, we need
1018 // to move that animation to the new one.
1019 if (fromToken.allDrawn) {
1020 allDrawn = true;
1021 deferClearAllDrawn = fromToken.deferClearAllDrawn;
1022 }
1023 if (fromToken.firstWindowDrawn) {
1024 firstWindowDrawn = true;
1025 }
1026 if (!fromToken.hidden) {
1027 hidden = false;
1028 hiddenRequested = false;
1029 }
1030 if (clientHidden != fromToken.clientHidden) {
1031 clientHidden = fromToken.clientHidden;
1032 sendAppVisibilityToClients();
1033 }
1034 fromToken.mAppAnimator.transferCurrentAnimation(
1035 mAppAnimator, tStartingWindow.mWinAnimator);
1036
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001037 mService.updateFocusedWindowLocked(
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001038 UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/);
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001039 getDisplayContent().setLayoutNeeded();
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001040 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001041 Binder.restoreCallingIdentity(origId);
1042 return true;
1043 } else if (fromToken.startingData != null) {
1044 // The previous app was getting ready to show a
1045 // starting window, but hasn't yet done so. Steal it!
1046 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1047 "Moving pending starting from " + fromToken + " to " + this);
1048 startingData = fromToken.startingData;
1049 fromToken.startingData = null;
1050 fromToken.startingMoved = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001051 final Message m = mService.mH.obtainMessage(H.ADD_STARTING, this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001052 // Note: we really want to do sendMessageAtFrontOfQueue() because we want to process the
1053 // message ASAP, before any other queued messages.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001054 mService.mH.sendMessageAtFrontOfQueue(m);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001055 return true;
1056 }
1057
1058 final AppWindowAnimator tAppAnimator = fromToken.mAppAnimator;
1059 final AppWindowAnimator wAppAnimator = mAppAnimator;
1060 if (tAppAnimator.thumbnail != null) {
1061 // The old token is animating with a thumbnail, transfer that to the new token.
1062 if (wAppAnimator.thumbnail != null) {
1063 wAppAnimator.thumbnail.destroy();
1064 }
1065 wAppAnimator.thumbnail = tAppAnimator.thumbnail;
1066 wAppAnimator.thumbnailLayer = tAppAnimator.thumbnailLayer;
1067 wAppAnimator.thumbnailAnimation = tAppAnimator.thumbnailAnimation;
1068 tAppAnimator.thumbnail = null;
1069 }
1070 return false;
1071 }
1072
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001073 boolean isLastWindow(WindowState win) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001074 return mChildren.size() == 1 && mChildren.get(0) == win;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001075 }
1076
1077 void setAllAppWinAnimators() {
1078 final ArrayList<WindowStateAnimator> allAppWinAnimators = mAppAnimator.mAllAppWinAnimators;
1079 allAppWinAnimators.clear();
1080
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001081 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001082 for (int j = 0; j < windowsCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001083 (mChildren.get(j)).addWinAnimatorToList(allAppWinAnimators);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001084 }
1085 }
1086
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001087 @Override
1088 void onAppTransitionDone() {
1089 sendingToBottom = false;
1090 }
1091
Wale Ogunwale51362492016-09-08 17:49:17 -07001092 /**
1093 * We override because this class doesn't want its children affecting its reported orientation
1094 * in anyway.
1095 */
1096 @Override
1097 int getOrientation() {
1098 if (hidden || hiddenRequested) {
1099 return SCREEN_ORIENTATION_UNSET;
1100 }
1101 return mOrientation;
1102 }
1103
Craig Mautnerdbb79912012-03-01 18:59:14 -08001104 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001105 void checkAppWindowsReadyToShow() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001106 if (allDrawn == mAppAnimator.allDrawn) {
1107 return;
1108 }
1109
1110 mAppAnimator.allDrawn = allDrawn;
1111 if (!allDrawn) {
1112 return;
1113 }
1114
1115 // The token has now changed state to having all windows shown... what to do, what to do?
1116 if (mAppAnimator.freezingScreen) {
1117 mAppAnimator.showAllWindowsLocked();
1118 stopFreezingScreen(false, true);
1119 if (DEBUG_ORIENTATION) Slog.i(TAG,
1120 "Setting mOrientationChangeComplete=true because wtoken " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001121 + " numInteresting=" + mNumInterestingWindows + " numDrawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001122 // This will set mOrientationChangeComplete and cause a pass through layout.
1123 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001124 "checkAppWindowsReadyToShow: freezingScreen");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001125 } else {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001126 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001127
1128 // We can now show all of the drawn windows!
1129 if (!mService.mOpeningApps.contains(this)) {
1130 mService.mAnimator.orAnimating(mAppAnimator.showAllWindowsLocked());
1131 }
1132 }
1133 }
1134
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001135 void updateAllDrawn(DisplayContent dc) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001136 if (!allDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001137 final int numInteresting = mNumInterestingWindows;
1138 if (numInteresting > 0 && mNumDrawnWindows >= numInteresting) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001139 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawn: " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001140 + " interesting=" + numInteresting + " drawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001141 allDrawn = true;
1142 // Force an additional layout pass where
1143 // WindowStateAnimator#commitFinishDrawingLocked() will call performShowLocked().
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001144 dc.setLayoutNeeded();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001145 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
1146 }
1147 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001148
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001149 if (!allDrawnExcludingSaved) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001150 int numInteresting = mNumInterestingWindowsExcludingSaved;
1151 if (numInteresting > 0 && mNumDrawnWindowsExcludingSaved >= numInteresting) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001152 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawnExcludingSaved: " + this
1153 + " interesting=" + numInteresting
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001154 + " drawn=" + mNumDrawnWindowsExcludingSaved);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001155 allDrawnExcludingSaved = true;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001156 dc.setLayoutNeeded();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001157 if (isAnimatingInvisibleWithSavedSurface()
1158 && !mService.mFinishedEarlyAnim.contains(this)) {
1159 mService.mFinishedEarlyAnim.add(this);
1160 }
1161 }
1162 }
1163 }
1164
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001165 /**
1166 * Updated this app token tracking states for interesting and drawn windows based on the window.
1167 *
1168 * @return Returns true if the input window is considered interesting and drawn while all the
1169 * windows in this app token where not considered drawn as of the last pass.
1170 */
1171 boolean updateDrawnWindowStates(WindowState w) {
1172 if (DEBUG_STARTING_WINDOW && w == startingWindow) {
1173 Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" + w.isOnScreen()
1174 + " allDrawn=" + allDrawn + " freezingScreen=" + mAppAnimator.freezingScreen);
1175 }
1176
1177 if (allDrawn && allDrawnExcludingSaved && !mAppAnimator.freezingScreen) {
1178 return false;
1179 }
1180
1181 if (mLastTransactionSequence != mService.mTransactionSequence) {
1182 mLastTransactionSequence = mService.mTransactionSequence;
1183 mNumInterestingWindows = mNumDrawnWindows = 0;
1184 mNumInterestingWindowsExcludingSaved = 0;
1185 mNumDrawnWindowsExcludingSaved = 0;
1186 startingDisplayed = false;
1187 }
1188
1189 final WindowStateAnimator winAnimator = w.mWinAnimator;
1190
1191 boolean isInterestingAndDrawn = false;
1192
1193 if (!allDrawn && w.mightAffectAllDrawn(false /* visibleOnly */)) {
1194 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
1195 Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw()
1196 + ", isAnimationSet=" + winAnimator.isAnimationSet());
1197 if (!w.isDrawnLw()) {
1198 Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController
1199 + " pv=" + w.mPolicyVisibility
1200 + " mDrawState=" + winAnimator.drawStateToString()
1201 + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested
1202 + " a=" + winAnimator.mAnimating);
1203 }
1204 }
1205
1206 if (w != startingWindow) {
1207 if (w.isInteresting()) {
1208 mNumInterestingWindows++;
1209 if (w.isDrawnLw()) {
1210 mNumDrawnWindows++;
1211
1212 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, "tokenMayBeDrawn: "
1213 + this + " w=" + w + " numInteresting=" + mNumInterestingWindows
1214 + " freezingScreen=" + mAppAnimator.freezingScreen
1215 + " mAppFreezing=" + w.mAppFreezing);
1216
1217 isInterestingAndDrawn = true;
1218 }
1219 }
1220 } else if (w.isDrawnLw()) {
1221 mService.mH.sendEmptyMessage(NOTIFY_STARTING_WINDOW_DRAWN);
1222 startingDisplayed = true;
1223 }
1224 }
1225
1226 if (!allDrawnExcludingSaved && w.mightAffectAllDrawn(true /* visibleOnly */)) {
1227 if (w != startingWindow && w.isInteresting()) {
1228 mNumInterestingWindowsExcludingSaved++;
1229 if (w.isDrawnLw() && !w.isAnimatingWithSavedSurface()) {
1230 mNumDrawnWindowsExcludingSaved++;
1231
1232 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
1233 "tokenMayBeDrawnExcludingSaved: " + this + " w=" + w
1234 + " numInteresting=" + mNumInterestingWindowsExcludingSaved
1235 + " freezingScreen=" + mAppAnimator.freezingScreen
1236 + " mAppFreezing=" + w.mAppFreezing);
1237
1238 isInterestingAndDrawn = true;
1239 }
1240 }
1241 }
1242
1243 return isInterestingAndDrawn;
1244 }
1245
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001246 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001247 void stepAppWindowsAnimation(long currentTime) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001248 mAppAnimator.wasAnimating = mAppAnimator.animating;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001249 if (mAppAnimator.stepAnimationLocked(currentTime)) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001250 mAppAnimator.animating = true;
1251 mService.mAnimator.setAnimating(true);
1252 mService.mAnimator.mAppWindowAnimating = true;
1253 } else if (mAppAnimator.wasAnimating) {
1254 // stopped animating, do one more pass through the layout
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001255 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER, "appToken " + this + " done");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001256 if (DEBUG_ANIM) Slog.v(TAG, "updateWindowsApps...: done animating " + this);
1257 }
1258 }
1259
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001260 int rebuildWindowListUnchecked(int addIndex) {
1261 return super.rebuildWindowList(addIndex);
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001262 }
1263
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001264 @Override
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001265 int rebuildWindowList(int addIndex) {
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001266 if (mIsExiting && !waitingForReplacement()) {
1267 return addIndex;
1268 }
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001269 return rebuildWindowListUnchecked(addIndex);
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001270 }
1271
1272 @Override
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001273 void forAllWindows(Consumer<WindowState> callback, boolean traverseTopToBottom) {
1274 // For legacy reasons we process the TaskStack.mExitingAppTokens first in DisplayContent
1275 // before the non-exiting app tokens. So, we skip the exiting app tokens here.
1276 // TODO: Investigate if we need to continue to do this or if we can just process them
1277 // in-order.
1278 if (mIsExiting && !waitingForReplacement()) {
1279 return;
1280 }
1281 forAllWindowsUnchecked(callback, traverseTopToBottom);
1282 }
1283
1284 void forAllWindowsUnchecked(Consumer<WindowState> callback, boolean traverseTopToBottom) {
1285 super.forAllWindows(callback, traverseTopToBottom);
1286 }
1287
1288 @Override
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001289 AppWindowToken asAppWindowToken() {
1290 // I am an app window token!
1291 return this;
1292 }
1293
1294 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -07001295 boolean fillsParent() {
1296 return mFillsParent;
1297 }
1298
1299 void setFillsParent(boolean fillsParent) {
1300 mFillsParent = fillsParent;
1301 }
1302
Jorim Jaggife762342016-10-13 14:33:27 +02001303 boolean containsDismissKeyguardWindow() {
1304 for (int i = mChildren.size() - 1; i >= 0; i--) {
1305 if ((mChildren.get(i).mAttrs.flags & FLAG_DISMISS_KEYGUARD) != 0) {
1306 return true;
1307 }
1308 }
1309 return false;
1310 }
1311
1312 boolean containsShowWhenLockedWindow() {
1313 for (int i = mChildren.size() - 1; i >= 0; i--) {
1314 if ((mChildren.get(i).mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
1315 return true;
1316 }
1317 }
1318 return false;
1319 }
1320
1321 void checkKeyguardFlagsChanged() {
1322 final boolean containsDismissKeyguard = containsDismissKeyguardWindow();
1323 final boolean containsShowWhenLocked = containsShowWhenLockedWindow();
1324 if (containsDismissKeyguard != mLastContainsDismissKeyguardWindow
1325 || containsShowWhenLocked != mLastContainsShowWhenLockedWindow) {
1326 mService.notifyKeyguardFlagsChanged(null /* callback */);
1327 }
1328 mLastContainsDismissKeyguardWindow = containsDismissKeyguard;
1329 mLastContainsShowWhenLockedWindow = containsShowWhenLocked;
1330 }
1331
Wale Ogunwale51362492016-09-08 17:49:17 -07001332 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001333 void dump(PrintWriter pw, String prefix) {
1334 super.dump(pw, prefix);
1335 if (appToken != null) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001336 pw.print(prefix); pw.print("app=true voiceInteraction="); pw.println(voiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001337 }
Craig Mautner83162a92015-01-26 14:43:30 -08001338 pw.print(prefix); pw.print("task="); pw.println(mTask);
Wale Ogunwale51362492016-09-08 17:49:17 -07001339 pw.print(prefix); pw.print(" mFillsParent="); pw.print(mFillsParent);
1340 pw.print(" mOrientation="); pw.println(mOrientation);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001341 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
1342 pw.print(" clientHidden="); pw.print(clientHidden);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -07001343 pw.print(" reportedDrawn="); pw.print(reportedDrawn);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001344 pw.print(" reportedVisible="); pw.println(reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -07001345 if (paused) {
1346 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001347 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001348 if (mAppStopped) {
1349 pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped);
1350 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001351 if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0
Craig Mautner6fbda632012-07-03 09:26:39 -07001352 || allDrawn || mAppAnimator.allDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001353 pw.print(prefix); pw.print("mNumInterestingWindows=");
1354 pw.print(mNumInterestingWindows);
1355 pw.print(" mNumDrawnWindows="); pw.print(mNumDrawnWindows);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001356 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -07001357 pw.print(" allDrawn="); pw.print(allDrawn);
1358 pw.print(" (animator="); pw.print(mAppAnimator.allDrawn);
1359 pw.println(")");
1360 }
1361 if (inPendingTransaction) {
1362 pw.print(prefix); pw.print("inPendingTransaction=");
1363 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001364 }
Craig Mautner799bc1d2015-01-14 10:33:48 -08001365 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001366 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
1367 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -08001368 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -08001369 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001370 }
1371 if (startingWindow != null || startingView != null
1372 || startingDisplayed || startingMoved) {
1373 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
1374 pw.print(" startingView="); pw.print(startingView);
1375 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001376 pw.print(" startingMoved="); pw.println(startingMoved);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001377 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01001378 if (!mFrozenBounds.isEmpty()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -08001379 pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds);
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001380 pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig);
Chong Zhangd78ddb42016-03-02 17:01:14 -08001381 }
1382 if (mPendingRelaunchCount != 0) {
1383 pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount);
Jorim Jaggi0429f352015-12-22 16:29:16 +01001384 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001385 }
1386
1387 @Override
1388 public String toString() {
1389 if (stringName == null) {
1390 StringBuilder sb = new StringBuilder();
1391 sb.append("AppWindowToken{");
1392 sb.append(Integer.toHexString(System.identityHashCode(this)));
1393 sb.append(" token="); sb.append(token); sb.append('}');
1394 stringName = sb.toString();
1395 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001396 return stringName + ((mIsExiting) ? " mIsExiting=" : "");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001397 }
Jeff Browne9bdb312012-04-05 15:30:10 -07001398}