blob: 71816fed8dfe5aa1324d0c7ffdb7186a3a5b48a4 [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;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070045import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070046import static com.android.server.wm.WindowManagerService.logWithStack;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080047
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070048import android.os.Debug;
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -080049import com.android.internal.util.ToBooleanFunction;
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;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080064
65import java.io.PrintWriter;
Jorim Jaggi0429f352015-12-22 16:29:16 +010066import java.util.ArrayDeque;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080067import java.util.ArrayList;
68
69class AppTokenList extends ArrayList<AppWindowToken> {
70}
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080071
72/**
73 * Version of WindowToken that is specifically for a particular application (or
74 * really activity) that is displaying windows.
75 */
Wale Ogunwale3f4433d2016-08-18 20:42:42 -070076class AppWindowToken extends WindowToken implements WindowManagerService.AppFreezeListener {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080077 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppWindowToken" : TAG_WM;
78
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080079 // Non-null only for application tokens.
80 final IApplicationToken appToken;
81
Filip Gruszczynskia590c992015-11-25 16:45:26 -080082 @NonNull final AppWindowAnimator mAppAnimator;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -070083
Dianne Hackborne30e02f2014-05-27 18:24:45 -070084 final boolean voiceInteraction;
85
Wale Ogunwalef6192862016-09-10 13:42:30 -070086 // TODO: Use getParent instead?
Craig Mautner83162a92015-01-26 14:43:30 -080087 Task mTask;
Wale Ogunwale51362492016-09-08 17:49:17 -070088 /** @see WindowContainer#fillsParent() */
89 private boolean mFillsParent;
Craig Mautner4c5eb222013-11-18 12:59:05 -080090 boolean layoutConfigChanges;
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -070091 boolean showForAllUsers;
Yorke Lee0e852472016-06-15 10:03:18 -070092 int targetSdk;
Craig Mautnera2c77052012-03-26 12:14:43 -070093
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080094 // The input dispatching timeout for this application token in nanoseconds.
95 long inputDispatchingTimeoutNanos;
96
97 // These are used for determining when all windows associated with
98 // an activity have been drawn, so they can be made visible together
99 // at the same time.
Craig Mautner764983d2012-03-22 11:37:36 -0700100 // initialize so that it doesn't match mTransactionSequence which is an int.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700101 private long mLastTransactionSequence = Long.MIN_VALUE;
102 private int mNumInterestingWindows;
103 private int mNumDrawnWindows;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800104 boolean inPendingTransaction;
105 boolean allDrawn;
Craig Mautner7636dfb2012-11-16 15:24:11 -0800106 // Set to true when this app creates a surface while in the middle of an animation. In that
107 // case do not clear allDrawn until the animation completes.
108 boolean deferClearAllDrawn;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800109
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700110 /**
111 * These are to track the app's real drawing status if there were no saved surfaces.
112 * @see #updateDrawnWindowStates
113 */
Chong Zhang8e4bda92016-05-04 15:08:18 -0700114 boolean allDrawnExcludingSaved;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700115 private int mNumInterestingWindowsExcludingSaved;
116 private int mNumDrawnWindowsExcludingSaved;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700117
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800118 // Is this window's surface needed? This is almost like hidden, except
119 // it will sometimes be true a little earlier: when the token has
120 // been shown, but is still waiting for its app transition to execute
121 // before making its windows shown.
122 boolean hiddenRequested;
123
124 // Have we told the window clients to hide themselves?
125 boolean clientHidden;
126
127 // Last visibility state we reported to the app token.
128 boolean reportedVisible;
129
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700130 // Last drawn state we reported to the app token.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700131 private boolean reportedDrawn;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700132
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800133 // Set to true when the token has been removed from the window mgr.
134 boolean removed;
135
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800136 // Information about an application starting window if displayed.
137 StartingData startingData;
138 WindowState startingWindow;
139 View startingView;
140 boolean startingDisplayed;
141 boolean startingMoved;
142 boolean firstWindowDrawn;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700143 private final WindowState.UpdateReportedVisibilityResults mReportedVisibilityResults =
144 new WindowState.UpdateReportedVisibilityResults();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800145
146 // Input application handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700147 final InputApplicationHandle mInputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800148
Wale Ogunwale571771c2016-08-26 13:18:50 -0700149 // TODO: Have a WindowContainer state for tracking exiting/deferred removal.
Craig Mautner799bc1d2015-01-14 10:33:48 -0800150 boolean mIsExiting;
Craig Mautner9ef471f2014-02-07 13:11:47 -0800151
Craig Mautnerbb742462014-07-07 15:28:55 -0700152 boolean mLaunchTaskBehind;
Craig Mautner8746a472014-07-24 15:12:54 -0700153 boolean mEnteringAnimation;
Craig Mautnerbb742462014-07-07 15:28:55 -0700154
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800155 boolean mAlwaysFocusable;
156
Robert Carre12aece2016-02-02 22:43:27 -0800157 boolean mAppStopped;
Robert Carrfd10cd12016-06-29 16:41:50 -0700158 int mRotationAnimationHint;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700159 private int mPendingRelaunchCount;
Robert Carre12aece2016-02-02 22:43:27 -0800160
Jorim Jaggife762342016-10-13 14:33:27 +0200161 private boolean mLastContainsShowWhenLockedWindow;
162 private boolean mLastContainsDismissKeyguardWindow;
163
Robert Carr91b228092016-06-28 17:32:37 -0700164 private ArrayList<WindowSurfaceController.SurfaceControlWithBackground> mSurfaceViewBackgrounds =
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700165 new ArrayList<>();
Robert Carr91b228092016-06-28 17:32:37 -0700166
Jorim Jaggi0429f352015-12-22 16:29:16 +0100167 ArrayDeque<Rect> mFrozenBounds = new ArrayDeque<>();
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700168 ArrayDeque<Configuration> mFrozenMergedConfig = new ArrayDeque<>();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100169
Wale Ogunwale02319a62016-09-26 15:21:22 -0700170 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean _voiceInteraction,
171 DisplayContent displayContent) {
172 super(service, token != null ? token.asBinder() : null, TYPE_APPLICATION, true,
173 displayContent);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700174 appToken = token;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700175 voiceInteraction = _voiceInteraction;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800176 mInputApplicationHandle = new InputApplicationHandle(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700177 mAppAnimator = new AppWindowAnimator(this, service);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800178 }
179
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800180 void onFirstWindowDrawn(WindowState win, WindowStateAnimator winAnimator) {
181 firstWindowDrawn = true;
182
183 // We now have a good window to show, remove dead placeholders
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700184 removeDeadWindows();
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800185
186 if (startingData != null) {
187 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, "Finish starting "
188 + win.mToken + ": first real window is shown, no animation");
189 // If this initial window is animating, stop it -- we will do an animation to reveal
190 // it from behind the starting window, so there is no need for it to also be doing its
191 // own stuff.
192 winAnimator.clearAnimation();
193 winAnimator.mService.mFinishedStarting.add(this);
194 winAnimator.mService.mH.sendEmptyMessage(H.FINISHED_STARTING);
195 }
196 updateReportedVisibilityLocked();
197 }
198
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800199 void updateReportedVisibilityLocked() {
200 if (appToken == null) {
201 return;
202 }
203
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700204 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700205 final int count = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800206
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700207 mReportedVisibilityResults.reset();
208
209 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700210 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700211 win.updateReportedVisibility(mReportedVisibilityResults);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800212 }
213
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700214 int numInteresting = mReportedVisibilityResults.numInteresting;
215 int numVisible = mReportedVisibilityResults.numVisible;
216 int numDrawn = mReportedVisibilityResults.numDrawn;
217 boolean nowGone = mReportedVisibilityResults.nowGone;
218
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700219 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800220 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700221 if (!nowGone) {
222 // If the app is not yet gone, then it can only become visible/drawn.
223 if (!nowDrawn) {
224 nowDrawn = reportedDrawn;
225 }
226 if (!nowVisible) {
227 nowVisible = reportedVisible;
228 }
229 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800230 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800231 + numInteresting + " visible=" + numVisible);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700232 if (nowDrawn != reportedDrawn) {
233 if (nowDrawn) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700234 mService.mH.obtainMessage(H.REPORT_APPLICATION_TOKEN_DRAWN, this).sendToTarget();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700235 }
236 reportedDrawn = nowDrawn;
237 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800238 if (nowVisible != reportedVisible) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700239 if (DEBUG_VISIBILITY) Slog.v(TAG,
240 "Visibility changed in " + this + ": vis=" + nowVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800241 reportedVisible = nowVisible;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700242 mService.mH.obtainMessage(H.REPORT_APPLICATION_TOKEN_WINDOWS,
243 nowVisible ? 1 : 0, nowGone ? 1 : 0, this).sendToTarget();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800244 }
245 }
246
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700247 boolean setVisibility(WindowManager.LayoutParams lp,
248 boolean visible, int transit, boolean performLayout, boolean isVoiceInteraction) {
249
250 boolean delayed = false;
251 inPendingTransaction = false;
252
253 if (clientHidden == visible) {
254 clientHidden = !visible;
255 sendAppVisibilityToClients();
256 }
257
258 // Allow for state changes and animation to be applied if:
259 // * token is transitioning visibility state
260 // * or the token was marked as hidden and is exiting before we had a chance to play the
261 // transition animation
262 // * or this is an opening app and windows are being replaced.
263 boolean visibilityChanged = false;
264 if (hidden == visible || (hidden && mIsExiting) || (visible && waitingForReplacement())) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700265 final AccessibilityController accessibilityController = mService.mAccessibilityController;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700266 boolean changed = false;
267 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
268 "Changing app " + this + " hidden=" + hidden + " performLayout=" + performLayout);
269
270 boolean runningAppAnimation = false;
271
272 if (transit != AppTransition.TRANSIT_UNSET) {
273 if (mAppAnimator.animation == AppWindowAnimator.sDummyAnimation) {
274 mAppAnimator.setNullAnimation();
275 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700276 if (mService.applyAnimationLocked(this, lp, transit, visible, isVoiceInteraction)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700277 delayed = runningAppAnimation = true;
278 }
279 final WindowState window = findMainWindow();
280 //TODO (multidisplay): Magnification is supported only for the default display.
281 if (window != null && accessibilityController != null
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700282 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700283 accessibilityController.onAppWindowTransitionLocked(window, transit);
284 }
285 changed = true;
286 }
287
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700288 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700289 for (int i = 0; i < windowsCount; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700290 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700291 changed |= win.onAppVisibilityChanged(visible, runningAppAnimation);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700292 }
293
294 hidden = hiddenRequested = !visible;
295 visibilityChanged = true;
296 if (!visible) {
297 stopFreezingScreen(true, true);
298 } else {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700299 // If we are being set visible, and the starting window is not yet displayed,
300 // then make sure it doesn't get displayed.
301 if (startingWindow != null && !startingWindow.isDrawnLw()) {
302 startingWindow.mPolicyVisibility = false;
303 startingWindow.mPolicyVisibilityAfterAnim = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700304 }
305 }
306
307 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setVisibility: " + this
308 + ": hidden=" + hidden + " hiddenRequested=" + hiddenRequested);
309
310 if (changed) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700311 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700312 if (performLayout) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700313 mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700314 false /*updateInputWindows*/);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700315 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700316 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700317 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700318 }
319 }
320
321 if (mAppAnimator.animation != null) {
322 delayed = true;
323 }
324
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700325 for (int i = mChildren.size() - 1; i >= 0 && !delayed; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700326 if ((mChildren.get(i)).isWindowAnimationSet()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700327 delayed = true;
328 }
329 }
330
331 if (visibilityChanged) {
332 if (visible && !delayed) {
333 // The token was made immediately visible, there will be no entrance animation.
334 // We need to inform the client the enter animation was finished.
335 mEnteringAnimation = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700336 mService.mActivityManagerAppTransitionNotifier.onAppTransitionFinishedLocked(token);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700337 }
338
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700339 if (!mService.mClosingApps.contains(this) && !mService.mOpeningApps.contains(this)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700340 // The token is not closing nor opening, so even if there is an animation set, that
341 // doesn't mean that it goes through the normal app transition cycle so we have
342 // to inform the docked controller about visibility change.
Andrii Kulian1e32e022016-09-16 15:29:34 -0700343 // TODO(multi-display): notify docked divider on all displays where visibility was
344 // affected.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700345 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700346 .notifyAppVisibilityChanged();
347 }
348 }
349
350 return delayed;
351 }
352
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800353 WindowState findMainWindow() {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700354 WindowState candidate = null;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700355 int j = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800356 while (j > 0) {
357 j--;
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700358 final WindowState win = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700359 final int type = win.mAttrs.type;
360 // No need to loop through child window as base application and starting types can't be
361 // child windows.
362 if (type == TYPE_BASE_APPLICATION || type == TYPE_APPLICATION_STARTING) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700363 // In cases where there are multiple windows, we prefer the non-exiting window. This
Sungsoo Lim0d3d1f82015-12-02 14:47:59 +0900364 // happens for example when replacing windows during an activity relaunch. When
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700365 // constructing the animation, we want the new window, not the exiting one.
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800366 if (win.mAnimatingExit) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700367 candidate = win;
368 } else {
369 return win;
370 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800371 }
372 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700373 return candidate;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800374 }
375
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800376 boolean windowsAreFocusable() {
377 return StackId.canReceiveKeys(mTask.mStack.mStackId) || mAlwaysFocusable;
Wale Ogunwaled045c822015-12-02 09:14:28 -0800378 }
379
Wale Ogunwale571771c2016-08-26 13:18:50 -0700380 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -0700381 boolean isVisible() {
Wale Ogunwalee471be62016-10-03 07:53:55 -0700382 // If the app token isn't hidden then it is considered visible and there is no need to check
383 // its children windows to see if they are visible.
384 return !hidden;
Wale Ogunwale44f21802016-09-02 12:49:48 -0700385 }
386
387 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -0700388 void removeIfPossible() {
Craig Mautnere3119b72015-01-20 15:02:36 -0800389 mIsExiting = false;
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800390 removeAllWindowsIfPossible();
Wale Ogunwale571771c2016-08-26 13:18:50 -0700391 if (mTask != null) {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700392 mTask.mStack.mExitingAppTokens.remove(this);
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800393 removeImmediately();
Craig Mautnere3119b72015-01-20 15:02:36 -0800394 }
395 }
396
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700397 @Override
398 boolean checkCompleteDeferredRemoval() {
399 if (mIsExiting) {
400 removeIfPossible();
401 }
402 return super.checkCompleteDeferredRemoval();
403 }
404
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700405 void onRemovedFromDisplay() {
406 AppWindowToken startingToken = null;
407
408 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app token: " + this);
409
410 boolean delayed = setVisibility(null, false, TRANSIT_UNSET, true, voiceInteraction);
411
412 mService.mOpeningApps.remove(this);
Jorim Jaggi1b4b23e2016-11-15 16:30:12 -0800413 mService.mUnknownAppVisibilityController.appRemoved(this);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700414 waitingToShow = false;
415 if (mService.mClosingApps.contains(this)) {
416 delayed = true;
417 } else if (mService.mAppTransition.isTransitionSet()) {
418 mService.mClosingApps.add(this);
419 delayed = true;
420 }
421
422 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app " + this + " delayed=" + delayed
423 + " animation=" + mAppAnimator.animation + " animating=" + mAppAnimator.animating);
424
425 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM, "removeAppToken: "
426 + this + " delayed=" + delayed + " Callers=" + Debug.getCallers(4));
427
428 final TaskStack stack = mTask.mStack;
429 if (delayed && !isEmpty()) {
430 // set the token aside because it has an active animation to be finished
431 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM,
432 "removeAppToken make exiting: " + this);
433 stack.mExitingAppTokens.add(this);
434 mIsExiting = true;
435 } else {
436 // Make sure there is no animation running on this token, so any windows associated
437 // with it will be removed as soon as their animations are complete
438 mAppAnimator.clearAnimation();
439 mAppAnimator.animating = false;
440 removeIfPossible();
441 }
442
443 removed = true;
444 if (startingData != null) {
445 startingToken = this;
446 }
447 stopFreezingScreen(true, true);
448 if (mService.mFocusedApp == this) {
449 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "Removing focused app token:" + this);
450 mService.mFocusedApp = null;
451 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
452 mService.mInputMonitor.setFocusedAppLw(null);
453 }
454
455 if (!delayed) {
456 updateReportedVisibilityLocked();
457 }
458
459 // Will only remove if startingToken non null.
460 mService.scheduleRemoveStartingWindowLocked(startingToken);
461 }
462
Chong Zhange05bcb12016-07-26 17:47:29 -0700463 void clearAnimatingFlags() {
Chong Zhangb0d26702016-08-12 16:03:29 -0700464 boolean wallpaperMightChange = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700465 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700466 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700467 wallpaperMightChange |= win.clearAnimatingFlags();
Chong Zhange05bcb12016-07-26 17:47:29 -0700468 }
Chong Zhangb0d26702016-08-12 16:03:29 -0700469 if (wallpaperMightChange) {
470 requestUpdateWallpaperIfNeeded();
471 }
Chong Zhange05bcb12016-07-26 17:47:29 -0700472 }
473
Robert Carre12aece2016-02-02 22:43:27 -0800474 void destroySurfaces() {
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700475 destroySurfaces(false /*cleanupOnResume*/);
476 }
477
478 /**
479 * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure
480 * the client has finished with them.
481 *
482 * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If
483 * set to true, destroy only surfaces of removed windows, and clear relevant flags of the
484 * others so that they are ready to be reused. If set to false (common case), destroy all
485 * surfaces that's eligible, if the app is already stopped.
486 */
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700487 private void destroySurfaces(boolean cleanupOnResume) {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700488 boolean destroyedSomething = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700489 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700490 final WindowState win = mChildren.get(i);
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700491 destroyedSomething |= win.destroySurface(cleanupOnResume, mAppStopped);
Robert Carre12aece2016-02-02 22:43:27 -0800492 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700493 if (destroyedSomething) {
494 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700495 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Robert Carre12aece2016-02-02 22:43:27 -0800496 }
497 }
498
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800499 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700500 * Notify that the app is now resumed, and it was not stopped before, perform a clean
501 * up of the surfaces
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800502 */
Chong Zhangad24f962016-08-25 12:12:33 -0700503 void notifyAppResumed(boolean wasStopped, boolean allowSavedSurface) {
504 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped
505 + " allowSavedSurface=" + allowSavedSurface + " " + this);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700506 mAppStopped = false;
507 if (!wasStopped) {
508 destroySurfaces(true /*cleanupOnResume*/);
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800509 }
Chong Zhangad24f962016-08-25 12:12:33 -0700510 if (!allowSavedSurface) {
511 destroySavedSurfaces();
512 }
Robert Carre12aece2016-02-02 22:43:27 -0800513 }
514
Chong Zhangbef461f2015-10-27 11:38:24 -0700515 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700516 * Notify that the app has stopped, and it is okay to destroy any surfaces which were
517 * keeping alive in case they were still being used.
518 */
519 void notifyAppStopped() {
520 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this);
521 mAppStopped = true;
522 destroySurfaces();
523 // Remove any starting window that was added for this app if they are still around.
524 mTask.mService.scheduleRemoveStartingWindowLocked(this);
525 }
526
527 /**
Chong Zhangbef461f2015-10-27 11:38:24 -0700528 * Checks whether we should save surfaces for this app.
529 *
530 * @return true if the surfaces should be saved, false otherwise.
531 */
532 boolean shouldSaveSurface() {
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800533 // We want to save surface if the app's windows are "allDrawn".
534 // (If we started entering animation early with saved surfaces, allDrawn
535 // should have been restored to true. So we'll save again in that case
536 // even if app didn't actually finish drawing.)
537 return allDrawn;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800538 }
539
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700540 private boolean canRestoreSurfaces() {
541 for (int i = mChildren.size() -1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700542 final WindowState w = mChildren.get(i);
Chong Zhang92147042016-05-09 12:47:11 -0700543 if (w.canRestoreSurface()) {
Robert Carr13f7be9e2015-12-02 18:39:45 -0800544 return true;
545 }
Chong Zhangbef461f2015-10-27 11:38:24 -0700546 }
547 return false;
548 }
549
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700550 private void clearWasVisibleBeforeClientHidden() {
551 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700552 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700553 w.clearWasVisibleBeforeClientHidden();
Chong Zhang92147042016-05-09 12:47:11 -0700554 }
555 }
556
Chong Zhang8e4bda92016-05-04 15:08:18 -0700557 /**
558 * Whether the app has some window that is invisible in layout, but
559 * animating with saved surface.
560 */
561 boolean isAnimatingInvisibleWithSavedSurface() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700562 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700563 final WindowState w = mChildren.get(i);
Chong Zhang8e4bda92016-05-04 15:08:18 -0700564 if (w.isAnimatingInvisibleWithSavedSurface()) {
565 return true;
566 }
567 }
568 return false;
569 }
570
571 /**
572 * Hide all window surfaces that's still invisible in layout but animating
573 * with a saved surface, and mark them destroying.
574 */
575 void stopUsingSavedSurfaceLocked() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700576 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700577 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700578 w.stopUsingSavedSurface();
Chong Zhang8e4bda92016-05-04 15:08:18 -0700579 }
580 destroySurfaces();
581 }
582
Chong Zhangf58631a2016-05-24 16:02:10 -0700583 void markSavedSurfaceExiting() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700584 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700585 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700586 w.markSavedSurfaceExiting();
Chong Zhangf58631a2016-05-24 16:02:10 -0700587 }
588 }
589
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700590 void restoreSavedSurfaceForInterestingWindows() {
Chong Zhang92147042016-05-09 12:47:11 -0700591 if (!canRestoreSurfaces()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700592 clearWasVisibleBeforeClientHidden();
Chong Zhangbef461f2015-10-27 11:38:24 -0700593 return;
594 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700595
596 // Check if all interesting windows are drawn and we can mark allDrawn=true.
597 int interestingNotDrawn = -1;
598
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700599 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700600 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700601 interestingNotDrawn = w.restoreSavedSurfaceForInterestingWindow();
Chong Zhangbef461f2015-10-27 11:38:24 -0700602 }
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800603
Chong Zhang92147042016-05-09 12:47:11 -0700604 if (!allDrawn) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700605 allDrawn = (interestingNotDrawn == 0);
Chong Zhang92147042016-05-09 12:47:11 -0700606 if (allDrawn) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700607 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Chong Zhang92147042016-05-09 12:47:11 -0700608 }
609 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700610 clearWasVisibleBeforeClientHidden();
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800611
612 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700613 "restoreSavedSurfaceForInterestingWindows: " + this + " allDrawn=" + allDrawn
614 + " interestingNotDrawn=" + interestingNotDrawn);
Chong Zhangbef461f2015-10-27 11:38:24 -0700615 }
616
617 void destroySavedSurfaces() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700618 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700619 final WindowState win = mChildren.get(i);
Robert Carr13f7be9e2015-12-02 18:39:45 -0800620 win.destroySavedSurface();
Chong Zhangbef461f2015-10-27 11:38:24 -0700621 }
Chong Zhang92147042016-05-09 12:47:11 -0700622 }
623
624 void clearAllDrawn() {
625 allDrawn = false;
626 deferClearAllDrawn = false;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700627 allDrawnExcludingSaved = false;
Chong Zhangbef461f2015-10-27 11:38:24 -0700628 }
629
Wale Ogunwalefa854eb2016-09-20 13:43:52 -0700630 void postWindowRemoveStartingWindowCleanup(WindowState win) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700631 // TODO: Something smells about the code below...Is there a better way?
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700632 if (startingWindow == win) {
633 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700634 mService.scheduleRemoveStartingWindowLocked(this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700635 } else if (mChildren.size() == 0 && startingData != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700636 // If this is the last window and we had requested a starting transition window,
637 // well there is no point now.
638 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingWindow");
639 startingData = null;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700640 } else if (mChildren.size() == 1 && startingView != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700641 // If this is the last window except for a starting transition window,
642 // we need to get rid of the starting transition.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700643 mService.scheduleRemoveStartingWindowLocked(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700644 }
645 }
646
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700647 void removeDeadWindows() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700648 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700649 WindowState win = mChildren.get(winNdx);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800650 if (win.mAppDied) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700651 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700652 "removeDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800653 // Set mDestroying, we don't want any animation or delayed removal here.
654 win.mDestroying = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700655 // Also removes child windows.
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700656 win.removeIfPossible();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800657 }
658 }
659 }
660
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700661 boolean hasWindowsAlive() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700662 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700663 // No need to loop through child windows as the answer should be the same as that of the
664 // parent window.
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700665 if (!(mChildren.get(i)).mAppDied) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700666 return true;
667 }
668 }
669 return false;
670 }
671
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700672 void setWillReplaceWindows(boolean animate) {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700673 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
674 "Marking app token " + this + " with replacing windows.");
Robert Carra1eb4392015-12-10 12:43:51 -0800675
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700676 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700677 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700678 w.setWillReplaceWindow(animate);
Robert Carra1eb4392015-12-10 12:43:51 -0800679 }
680 if (animate) {
681 // Set-up dummy animation so we can start treating windows associated with this
682 // token like they are in transition before the new app window is ready for us to
683 // run the real transition animation.
684 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700685 "setWillReplaceWindow() Setting dummy animation on: " + this);
Robert Carra1eb4392015-12-10 12:43:51 -0800686 mAppAnimator.setDummyAnimation();
687 }
688 }
689
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700690 void setWillReplaceChildWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700691 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this
Robert Carr23fa16b2016-01-13 13:19:58 -0800692 + " with replacing child windows.");
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700693 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700694 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700695 w.setWillReplaceChildWindows();
Robert Carr23fa16b2016-01-13 13:19:58 -0800696 }
697 }
698
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700699 void clearWillReplaceWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700700 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
701 "Resetting app token " + this + " of replacing window marks.");
Chong Zhangf596cd52016-01-05 13:42:44 -0800702
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700703 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700704 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700705 w.clearWillReplaceWindow();
Chong Zhangf596cd52016-01-05 13:42:44 -0800706 }
707 }
708
Chong Zhang4d7369a2016-04-25 16:09:14 -0700709 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700710 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700711 final WindowState w = mChildren.get(i);
Chong Zhang4d7369a2016-04-25 16:09:14 -0700712 w.requestUpdateWallpaperIfNeeded();
713 }
714 }
715
Chong Zhangd78ddb42016-03-02 17:01:14 -0800716 boolean isRelaunching() {
717 return mPendingRelaunchCount > 0;
718 }
719
720 void startRelaunching() {
721 if (canFreezeBounds()) {
722 freezeBounds();
723 }
724 mPendingRelaunchCount++;
725 }
726
727 void finishRelaunching() {
728 if (canFreezeBounds()) {
729 unfreezeBounds();
730 }
731 if (mPendingRelaunchCount > 0) {
732 mPendingRelaunchCount--;
733 }
734 }
735
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700736 void clearRelaunching() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700737 if (mPendingRelaunchCount == 0) {
738 return;
739 }
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700740 if (canFreezeBounds()) {
741 unfreezeBounds();
742 }
743 mPendingRelaunchCount = 0;
744 }
745
Wale Ogunwale07bcab72016-10-14 15:30:09 -0700746 /**
747 * Returns true if the new child window we are adding to this token is considered greater than
748 * the existing child window in this token in terms of z-order.
749 */
750 @Override
751 protected boolean isFirstChildWindowGreaterThanSecond(WindowState newWindow,
752 WindowState existingWindow) {
753 final int type1 = newWindow.mAttrs.type;
754 final int type2 = existingWindow.mAttrs.type;
755
756 // Base application windows should be z-ordered BELOW all other windows in the app token.
757 if (type1 == TYPE_BASE_APPLICATION && type2 != TYPE_BASE_APPLICATION) {
758 return false;
759 } else if (type1 != TYPE_BASE_APPLICATION && type2 == TYPE_BASE_APPLICATION) {
760 return true;
761 }
762
763 // Starting windows should be z-ordered ABOVE all other windows in the app token.
764 if (type1 == TYPE_APPLICATION_STARTING && type2 != TYPE_APPLICATION_STARTING) {
765 return true;
766 } else if (type1 != TYPE_APPLICATION_STARTING && type2 == TYPE_APPLICATION_STARTING) {
767 return false;
768 }
769
770 // Otherwise the new window is greater than the existing window.
771 return true;
772 }
773
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700774 @Override
Robert Carra1eb4392015-12-10 12:43:51 -0800775 void addWindow(WindowState w) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700776 super.addWindow(w);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700777
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700778 boolean gotReplacementWindow = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700779 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700780 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700781 gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w);
782 }
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700783
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700784 // if we got a replacement window, reset the timeout to give drawing more time
785 if (gotReplacementWindow) {
786 mService.scheduleWindowReplacementTimeouts(this);
Robert Carra1eb4392015-12-10 12:43:51 -0800787 }
Jorim Jaggife762342016-10-13 14:33:27 +0200788 checkKeyguardFlagsChanged();
789 }
790
791 @Override
792 void removeChild(WindowState child) {
793 super.removeChild(child);
794 checkKeyguardFlagsChanged();
Robert Carra1eb4392015-12-10 12:43:51 -0800795 }
796
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700797 private boolean waitingForReplacement() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700798 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700799 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700800 if (candidate.waitingForReplacement()) {
Robert Carra1eb4392015-12-10 12:43:51 -0800801 return true;
802 }
803 }
804 return false;
805 }
806
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700807 void onWindowReplacementTimeout() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700808 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700809 (mChildren.get(i)).onWindowReplacementTimeout();
Robert Carra1eb4392015-12-10 12:43:51 -0800810 }
811 }
812
Chong Zhangd78ddb42016-03-02 17:01:14 -0800813 private boolean canFreezeBounds() {
814 // For freeform windows, we can't freeze the bounds at the moment because this would make
815 // the resizing unresponsive.
816 return mTask != null && !mTask.inFreeformWorkspace();
817 }
818
Jorim Jaggi0429f352015-12-22 16:29:16 +0100819 /**
820 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
821 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
822 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
823 * with a queue.
824 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800825 private void freezeBounds() {
Jorim Jaggi0429f352015-12-22 16:29:16 +0100826 mFrozenBounds.offer(new Rect(mTask.mPreparedFrozenBounds));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700827
828 if (mTask.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) {
829 // We didn't call prepareFreezingBounds on the task, so use the current value.
Andrii Kulian441e4492016-09-29 15:25:00 -0700830 mFrozenMergedConfig.offer(new Configuration(mTask.getConfiguration()));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700831 } else {
832 mFrozenMergedConfig.offer(new Configuration(mTask.mPreparedFrozenMergedConfig));
833 }
Andrii Kulianb10330d2016-09-16 13:51:46 -0700834 // Calling unset() to make it equal to Configuration.EMPTY.
835 mTask.mPreparedFrozenMergedConfig.unset();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100836 }
837
838 /**
839 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
840 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800841 private void unfreezeBounds() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700842 if (!mFrozenBounds.isEmpty()) {
843 mFrozenBounds.remove();
844 }
845 if (!mFrozenMergedConfig.isEmpty()) {
846 mFrozenMergedConfig.remove();
847 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700848 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700849 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700850 win.onUnfreezeBounds();
Jorim Jaggi4846ee32016-01-07 17:39:12 +0100851 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700852 mService.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100853 }
854
Robert Carr91b228092016-06-28 17:32:37 -0700855 void addSurfaceViewBackground(WindowSurfaceController.SurfaceControlWithBackground background) {
856 mSurfaceViewBackgrounds.add(background);
857 }
858
859 void removeSurfaceViewBackground(WindowSurfaceController.SurfaceControlWithBackground background) {
860 mSurfaceViewBackgrounds.remove(background);
861 updateSurfaceViewBackgroundVisibilities();
862 }
863
864 // We use DimLayers behind SurfaceViews to prevent holes while resizing and creating.
865 // However, we need to ensure one SurfaceView doesn't cover another when they are both placed
866 // below the main app window (as traditionally a SurfaceView which is never drawn
867 // to is totally translucent). So we look at all our SurfaceView backgrounds and only enable
868 // the background for the SurfaceView with lowest Z order
869 void updateSurfaceViewBackgroundVisibilities() {
870 WindowSurfaceController.SurfaceControlWithBackground bottom = null;
871 int bottomLayer = Integer.MAX_VALUE;
872 for (int i = 0; i < mSurfaceViewBackgrounds.size(); i++) {
873 WindowSurfaceController.SurfaceControlWithBackground sc = mSurfaceViewBackgrounds.get(i);
874 if (sc.mVisible && sc.mLayer < bottomLayer) {
875 bottomLayer = sc.mLayer;
876 bottom = sc;
877 }
878 }
879 for (int i = 0; i < mSurfaceViewBackgrounds.size(); i++) {
880 WindowSurfaceController.SurfaceControlWithBackground sc = mSurfaceViewBackgrounds.get(i);
881 sc.updateBackgroundVisibility(sc != bottom);
882 }
883 }
884
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700885 void resetJustMovedInStack() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700886 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700887 (mChildren.get(i)).resetJustMovedInStack();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700888 }
889 }
890
891 void notifyMovedInStack() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700892 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700893 final WindowState win = mChildren.get(winNdx);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700894 win.notifyMovedInStack();
895 }
896 }
897
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700898 void setAppLayoutChanges(int changes, String reason) {
899 if (!mChildren.isEmpty()) {
900 final DisplayContent dc = getDisplayContent();
901 dc.pendingLayoutChanges |= changes;
902 if (DEBUG_LAYOUT_REPEATS) {
903 mService.mWindowPlacerLocked.debugLayoutRepeats(reason, dc.pendingLayoutChanges);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700904 }
905 }
906 }
907
908 void removeReplacedWindowIfNeeded(WindowState replacement) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700909 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700910 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700911 if (win.removeReplacedWindowIfNeeded(replacement)) {
912 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700913 }
914 }
915 }
916
917 void startFreezingScreen() {
918 if (DEBUG_ORIENTATION) logWithStack(TAG, "Set freezing of " + appToken + ": hidden="
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700919 + hidden + " freezing=" + mAppAnimator.freezingScreen + " hiddenRequested="
920 + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700921 if (!hiddenRequested) {
922 if (!mAppAnimator.freezingScreen) {
923 mAppAnimator.freezingScreen = true;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700924 mService.registerAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700925 mAppAnimator.lastFreezeDuration = 0;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700926 mService.mAppsFreezingScreen++;
927 if (mService.mAppsFreezingScreen == 1) {
928 mService.startFreezingDisplayLocked(false, 0, 0);
929 mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT);
930 mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700931 }
932 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700933 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700934 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700935 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700936 w.onStartFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700937 }
938 }
939 }
940
941 void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) {
942 if (!mAppAnimator.freezingScreen) {
943 return;
944 }
945 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + this + " force=" + force);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700946 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700947 boolean unfrozeWindows = false;
948 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700949 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700950 unfrozeWindows |= w.onStopFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700951 }
952 if (force || unfrozeWindows) {
953 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this);
954 mAppAnimator.freezingScreen = false;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700955 mService.unregisterAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700956 mAppAnimator.lastFreezeDuration =
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700957 (int)(SystemClock.elapsedRealtime() - mService.mDisplayFreezeTime);
958 mService.mAppsFreezingScreen--;
959 mService.mLastFinishedFreezeSource = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700960 }
961 if (unfreezeSurfaceNow) {
962 if (unfrozeWindows) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700963 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700964 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700965 mService.stopFreezingDisplayLocked();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700966 }
967 }
968
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700969 @Override
970 public void onAppFreezeTimeout() {
971 Slog.w(TAG_WM, "Force clearing freeze: " + this);
972 stopFreezingScreen(true, true);
973 }
974
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700975 boolean transferStartingWindow(IBinder transferFrom) {
Wale Ogunwale02319a62016-09-26 15:21:22 -0700976 final AppWindowToken fromToken = getDisplayContent().getAppWindowToken(transferFrom);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700977 if (fromToken == null) {
978 return false;
979 }
980
981 final WindowState tStartingWindow = fromToken.startingWindow;
982 if (tStartingWindow != null && fromToken.startingView != null) {
983 // In this case, the starting icon has already been displayed, so start
984 // letting windows get shown immediately without any more transitions.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700985 mService.mSkipAppTransitionAnimation = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700986
987 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow
988 + " from " + fromToken + " to " + this);
989
990 final long origId = Binder.clearCallingIdentity();
991
992 // Transfer the starting window over to the new token.
993 startingData = fromToken.startingData;
994 startingView = fromToken.startingView;
995 startingDisplayed = fromToken.startingDisplayed;
996 fromToken.startingDisplayed = false;
997 startingWindow = tStartingWindow;
998 reportedVisible = fromToken.reportedVisible;
999 fromToken.startingData = null;
1000 fromToken.startingView = null;
1001 fromToken.startingWindow = null;
1002 fromToken.startingMoved = true;
1003 tStartingWindow.mToken = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001004 tStartingWindow.mAppToken = this;
1005
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001006 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1007 "Removing starting window: " + tStartingWindow);
1008 getDisplayContent().removeFromWindowList(tStartingWindow);
1009 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001010 "Removing starting " + tStartingWindow + " from " + fromToken);
Wale Ogunwalefa854eb2016-09-20 13:43:52 -07001011 fromToken.removeChild(tStartingWindow);
1012 fromToken.postWindowRemoveStartingWindowCleanup(tStartingWindow);
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001013 addWindow(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001014
1015 // Propagate other interesting state between the tokens. If the old token is displayed,
1016 // we should immediately force the new one to be displayed. If it is animating, we need
1017 // to move that animation to the new one.
1018 if (fromToken.allDrawn) {
1019 allDrawn = true;
1020 deferClearAllDrawn = fromToken.deferClearAllDrawn;
1021 }
1022 if (fromToken.firstWindowDrawn) {
1023 firstWindowDrawn = true;
1024 }
1025 if (!fromToken.hidden) {
1026 hidden = false;
1027 hiddenRequested = false;
1028 }
1029 if (clientHidden != fromToken.clientHidden) {
1030 clientHidden = fromToken.clientHidden;
1031 sendAppVisibilityToClients();
1032 }
1033 fromToken.mAppAnimator.transferCurrentAnimation(
1034 mAppAnimator, tStartingWindow.mWinAnimator);
1035
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001036 mService.updateFocusedWindowLocked(
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001037 UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/);
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001038 getDisplayContent().setLayoutNeeded();
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001039 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001040 Binder.restoreCallingIdentity(origId);
1041 return true;
1042 } else if (fromToken.startingData != null) {
1043 // The previous app was getting ready to show a
1044 // starting window, but hasn't yet done so. Steal it!
1045 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1046 "Moving pending starting from " + fromToken + " to " + this);
1047 startingData = fromToken.startingData;
1048 fromToken.startingData = null;
1049 fromToken.startingMoved = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001050 final Message m = mService.mH.obtainMessage(H.ADD_STARTING, this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001051 // Note: we really want to do sendMessageAtFrontOfQueue() because we want to process the
1052 // message ASAP, before any other queued messages.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001053 mService.mH.sendMessageAtFrontOfQueue(m);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001054 return true;
1055 }
1056
1057 final AppWindowAnimator tAppAnimator = fromToken.mAppAnimator;
1058 final AppWindowAnimator wAppAnimator = mAppAnimator;
1059 if (tAppAnimator.thumbnail != null) {
1060 // The old token is animating with a thumbnail, transfer that to the new token.
1061 if (wAppAnimator.thumbnail != null) {
1062 wAppAnimator.thumbnail.destroy();
1063 }
1064 wAppAnimator.thumbnail = tAppAnimator.thumbnail;
1065 wAppAnimator.thumbnailLayer = tAppAnimator.thumbnailLayer;
1066 wAppAnimator.thumbnailAnimation = tAppAnimator.thumbnailAnimation;
1067 tAppAnimator.thumbnail = null;
1068 }
1069 return false;
1070 }
1071
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001072 boolean isLastWindow(WindowState win) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001073 return mChildren.size() == 1 && mChildren.get(0) == win;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001074 }
1075
1076 void setAllAppWinAnimators() {
1077 final ArrayList<WindowStateAnimator> allAppWinAnimators = mAppAnimator.mAllAppWinAnimators;
1078 allAppWinAnimators.clear();
1079
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001080 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001081 for (int j = 0; j < windowsCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001082 (mChildren.get(j)).addWinAnimatorToList(allAppWinAnimators);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001083 }
1084 }
1085
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001086 @Override
1087 void onAppTransitionDone() {
1088 sendingToBottom = false;
1089 }
1090
Wale Ogunwale51362492016-09-08 17:49:17 -07001091 /**
1092 * We override because this class doesn't want its children affecting its reported orientation
1093 * in anyway.
1094 */
1095 @Override
1096 int getOrientation() {
1097 if (hidden || hiddenRequested) {
1098 return SCREEN_ORIENTATION_UNSET;
1099 }
1100 return mOrientation;
1101 }
1102
Wale Ogunwaleb198b742016-12-01 08:44:09 -08001103 /** Returns the app's preferred orientation regardless of its currently visibility state. */
1104 int getOrientationIgnoreVisibility() {
1105 return mOrientation;
1106 }
1107
Craig Mautnerdbb79912012-03-01 18:59:14 -08001108 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001109 void checkAppWindowsReadyToShow() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001110 if (allDrawn == mAppAnimator.allDrawn) {
1111 return;
1112 }
1113
1114 mAppAnimator.allDrawn = allDrawn;
1115 if (!allDrawn) {
1116 return;
1117 }
1118
1119 // The token has now changed state to having all windows shown... what to do, what to do?
1120 if (mAppAnimator.freezingScreen) {
1121 mAppAnimator.showAllWindowsLocked();
1122 stopFreezingScreen(false, true);
1123 if (DEBUG_ORIENTATION) Slog.i(TAG,
1124 "Setting mOrientationChangeComplete=true because wtoken " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001125 + " numInteresting=" + mNumInterestingWindows + " numDrawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001126 // This will set mOrientationChangeComplete and cause a pass through layout.
1127 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001128 "checkAppWindowsReadyToShow: freezingScreen");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001129 } else {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001130 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001131
1132 // We can now show all of the drawn windows!
1133 if (!mService.mOpeningApps.contains(this)) {
1134 mService.mAnimator.orAnimating(mAppAnimator.showAllWindowsLocked());
1135 }
1136 }
1137 }
1138
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001139 void updateAllDrawn(DisplayContent dc) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001140 if (!allDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001141 final int numInteresting = mNumInterestingWindows;
1142 if (numInteresting > 0 && mNumDrawnWindows >= numInteresting) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001143 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawn: " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001144 + " interesting=" + numInteresting + " drawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001145 allDrawn = true;
1146 // Force an additional layout pass where
1147 // WindowStateAnimator#commitFinishDrawingLocked() will call performShowLocked().
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001148 dc.setLayoutNeeded();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001149 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
1150 }
1151 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001152
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001153 if (!allDrawnExcludingSaved) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001154 int numInteresting = mNumInterestingWindowsExcludingSaved;
1155 if (numInteresting > 0 && mNumDrawnWindowsExcludingSaved >= numInteresting) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001156 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawnExcludingSaved: " + this
1157 + " interesting=" + numInteresting
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001158 + " drawn=" + mNumDrawnWindowsExcludingSaved);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001159 allDrawnExcludingSaved = true;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001160 dc.setLayoutNeeded();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001161 if (isAnimatingInvisibleWithSavedSurface()
1162 && !mService.mFinishedEarlyAnim.contains(this)) {
1163 mService.mFinishedEarlyAnim.add(this);
1164 }
1165 }
1166 }
1167 }
1168
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001169 /**
1170 * Updated this app token tracking states for interesting and drawn windows based on the window.
1171 *
1172 * @return Returns true if the input window is considered interesting and drawn while all the
1173 * windows in this app token where not considered drawn as of the last pass.
1174 */
1175 boolean updateDrawnWindowStates(WindowState w) {
1176 if (DEBUG_STARTING_WINDOW && w == startingWindow) {
1177 Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" + w.isOnScreen()
1178 + " allDrawn=" + allDrawn + " freezingScreen=" + mAppAnimator.freezingScreen);
1179 }
1180
1181 if (allDrawn && allDrawnExcludingSaved && !mAppAnimator.freezingScreen) {
1182 return false;
1183 }
1184
1185 if (mLastTransactionSequence != mService.mTransactionSequence) {
1186 mLastTransactionSequence = mService.mTransactionSequence;
1187 mNumInterestingWindows = mNumDrawnWindows = 0;
1188 mNumInterestingWindowsExcludingSaved = 0;
1189 mNumDrawnWindowsExcludingSaved = 0;
1190 startingDisplayed = false;
1191 }
1192
1193 final WindowStateAnimator winAnimator = w.mWinAnimator;
1194
1195 boolean isInterestingAndDrawn = false;
1196
1197 if (!allDrawn && w.mightAffectAllDrawn(false /* visibleOnly */)) {
1198 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
1199 Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw()
1200 + ", isAnimationSet=" + winAnimator.isAnimationSet());
1201 if (!w.isDrawnLw()) {
1202 Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController
1203 + " pv=" + w.mPolicyVisibility
1204 + " mDrawState=" + winAnimator.drawStateToString()
1205 + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested
1206 + " a=" + winAnimator.mAnimating);
1207 }
1208 }
1209
1210 if (w != startingWindow) {
1211 if (w.isInteresting()) {
1212 mNumInterestingWindows++;
1213 if (w.isDrawnLw()) {
1214 mNumDrawnWindows++;
1215
1216 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, "tokenMayBeDrawn: "
1217 + this + " w=" + w + " numInteresting=" + mNumInterestingWindows
1218 + " freezingScreen=" + mAppAnimator.freezingScreen
1219 + " mAppFreezing=" + w.mAppFreezing);
1220
1221 isInterestingAndDrawn = true;
1222 }
1223 }
1224 } else if (w.isDrawnLw()) {
1225 mService.mH.sendEmptyMessage(NOTIFY_STARTING_WINDOW_DRAWN);
1226 startingDisplayed = true;
1227 }
1228 }
1229
1230 if (!allDrawnExcludingSaved && w.mightAffectAllDrawn(true /* visibleOnly */)) {
1231 if (w != startingWindow && w.isInteresting()) {
1232 mNumInterestingWindowsExcludingSaved++;
1233 if (w.isDrawnLw() && !w.isAnimatingWithSavedSurface()) {
1234 mNumDrawnWindowsExcludingSaved++;
1235
1236 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
1237 "tokenMayBeDrawnExcludingSaved: " + this + " w=" + w
1238 + " numInteresting=" + mNumInterestingWindowsExcludingSaved
1239 + " freezingScreen=" + mAppAnimator.freezingScreen
1240 + " mAppFreezing=" + w.mAppFreezing);
1241
1242 isInterestingAndDrawn = true;
1243 }
1244 }
1245 }
1246
1247 return isInterestingAndDrawn;
1248 }
1249
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001250 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001251 void stepAppWindowsAnimation(long currentTime) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001252 mAppAnimator.wasAnimating = mAppAnimator.animating;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001253 if (mAppAnimator.stepAnimationLocked(currentTime)) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001254 mAppAnimator.animating = true;
1255 mService.mAnimator.setAnimating(true);
1256 mService.mAnimator.mAppWindowAnimating = true;
1257 } else if (mAppAnimator.wasAnimating) {
1258 // stopped animating, do one more pass through the layout
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001259 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER, "appToken " + this + " done");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001260 if (DEBUG_ANIM) Slog.v(TAG, "updateWindowsApps...: done animating " + this);
1261 }
1262 }
1263
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001264 int rebuildWindowListUnchecked(int addIndex) {
1265 return super.rebuildWindowList(addIndex);
1266 }
1267
1268 @Override
1269 int rebuildWindowList(int addIndex) {
1270 if (mIsExiting && !waitingForReplacement()) {
1271 return addIndex;
1272 }
1273 return rebuildWindowListUnchecked(addIndex);
1274 }
1275
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001276 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001277 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001278 // For legacy reasons we process the TaskStack.mExitingAppTokens first in DisplayContent
1279 // before the non-exiting app tokens. So, we skip the exiting app tokens here.
1280 // TODO: Investigate if we need to continue to do this or if we can just process them
1281 // in-order.
1282 if (mIsExiting && !waitingForReplacement()) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001283 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001284 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001285 return forAllWindowsUnchecked(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001286 }
1287
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001288 boolean forAllWindowsUnchecked(ToBooleanFunction<WindowState> callback,
1289 boolean traverseTopToBottom) {
1290 return super.forAllWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001291 }
1292
1293 @Override
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001294 AppWindowToken asAppWindowToken() {
1295 // I am an app window token!
1296 return this;
1297 }
1298
1299 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -07001300 boolean fillsParent() {
1301 return mFillsParent;
1302 }
1303
1304 void setFillsParent(boolean fillsParent) {
1305 mFillsParent = fillsParent;
1306 }
1307
Jorim Jaggife762342016-10-13 14:33:27 +02001308 boolean containsDismissKeyguardWindow() {
1309 for (int i = mChildren.size() - 1; i >= 0; i--) {
1310 if ((mChildren.get(i).mAttrs.flags & FLAG_DISMISS_KEYGUARD) != 0) {
1311 return true;
1312 }
1313 }
1314 return false;
1315 }
1316
1317 boolean containsShowWhenLockedWindow() {
1318 for (int i = mChildren.size() - 1; i >= 0; i--) {
1319 if ((mChildren.get(i).mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
1320 return true;
1321 }
1322 }
1323 return false;
1324 }
1325
1326 void checkKeyguardFlagsChanged() {
1327 final boolean containsDismissKeyguard = containsDismissKeyguardWindow();
1328 final boolean containsShowWhenLocked = containsShowWhenLockedWindow();
1329 if (containsDismissKeyguard != mLastContainsDismissKeyguardWindow
1330 || containsShowWhenLocked != mLastContainsShowWhenLockedWindow) {
1331 mService.notifyKeyguardFlagsChanged(null /* callback */);
1332 }
1333 mLastContainsDismissKeyguardWindow = containsDismissKeyguard;
1334 mLastContainsShowWhenLockedWindow = containsShowWhenLocked;
1335 }
1336
Wale Ogunwale51362492016-09-08 17:49:17 -07001337 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001338 void dump(PrintWriter pw, String prefix) {
1339 super.dump(pw, prefix);
1340 if (appToken != null) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001341 pw.print(prefix); pw.print("app=true voiceInteraction="); pw.println(voiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001342 }
Craig Mautner83162a92015-01-26 14:43:30 -08001343 pw.print(prefix); pw.print("task="); pw.println(mTask);
Wale Ogunwale51362492016-09-08 17:49:17 -07001344 pw.print(prefix); pw.print(" mFillsParent="); pw.print(mFillsParent);
1345 pw.print(" mOrientation="); pw.println(mOrientation);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001346 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
1347 pw.print(" clientHidden="); pw.print(clientHidden);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -07001348 pw.print(" reportedDrawn="); pw.print(reportedDrawn);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001349 pw.print(" reportedVisible="); pw.println(reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -07001350 if (paused) {
1351 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001352 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001353 if (mAppStopped) {
1354 pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped);
1355 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001356 if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0
Craig Mautner6fbda632012-07-03 09:26:39 -07001357 || allDrawn || mAppAnimator.allDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001358 pw.print(prefix); pw.print("mNumInterestingWindows=");
1359 pw.print(mNumInterestingWindows);
1360 pw.print(" mNumDrawnWindows="); pw.print(mNumDrawnWindows);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001361 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -07001362 pw.print(" allDrawn="); pw.print(allDrawn);
1363 pw.print(" (animator="); pw.print(mAppAnimator.allDrawn);
1364 pw.println(")");
1365 }
1366 if (inPendingTransaction) {
1367 pw.print(prefix); pw.print("inPendingTransaction=");
1368 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001369 }
Craig Mautner799bc1d2015-01-14 10:33:48 -08001370 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001371 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
1372 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -08001373 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -08001374 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001375 }
1376 if (startingWindow != null || startingView != null
1377 || startingDisplayed || startingMoved) {
1378 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
1379 pw.print(" startingView="); pw.print(startingView);
1380 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001381 pw.print(" startingMoved="); pw.println(startingMoved);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001382 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01001383 if (!mFrozenBounds.isEmpty()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -08001384 pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds);
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001385 pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig);
Chong Zhangd78ddb42016-03-02 17:01:14 -08001386 }
1387 if (mPendingRelaunchCount != 0) {
1388 pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount);
Jorim Jaggi0429f352015-12-22 16:29:16 +01001389 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001390 }
1391
1392 @Override
1393 public String toString() {
1394 if (stringName == null) {
1395 StringBuilder sb = new StringBuilder();
1396 sb.append("AppWindowToken{");
1397 sb.append(Integer.toHexString(System.identityHashCode(this)));
1398 sb.append(" token="); sb.append(token); sb.append('}');
1399 stringName = sb.toString();
1400 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001401 return stringName + ((mIsExiting) ? " mIsExiting=" : "");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001402 }
Jeff Browne9bdb312012-04-05 15:30:10 -07001403}