blob: 0a4875810aba233848650cd82c1b72c59145f53a [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 Ogunwale72919d22016-12-08 18:58:50 -080020import static android.content.pm.ActivityInfo.CONFIG_ORIENTATION;
21import static android.content.pm.ActivityInfo.CONFIG_SCREEN_SIZE;
Wale Ogunwale51362492016-09-08 17:49:17 -070022import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070023import static android.view.Display.DEFAULT_DISPLAY;
Jorim Jaggife762342016-10-13 14:33:27 +020024import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
25import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
Wale Ogunwaled1c37912016-08-16 03:19:39 -070026import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080027import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070028import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -070029import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
30import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070031import static com.android.server.wm.AppTransition.TRANSIT_UNSET;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080032import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
33import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
Robert Carra1eb4392015-12-10 12:43:51 -080034import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070035import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070036import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
37import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
Wale Ogunwale9017ec02016-02-25 08:55:25 -080038import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070039import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TOKEN_MOVEMENT;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080040import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
41import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_MOVEMENT;
42import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
43import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Chong Zhang92147042016-05-09 12:47:11 -070044import static com.android.server.wm.WindowManagerService.H.NOTIFY_ACTIVITY_DRAWN;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -070045import static com.android.server.wm.WindowManagerService.H.NOTIFY_STARTING_WINDOW_DRAWN;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070046import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070047import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070048import static com.android.server.wm.WindowManagerService.logWithStack;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080049
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070050import android.os.Debug;
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -080051import com.android.internal.util.ToBooleanFunction;
Jeff Brown4532e612012-04-05 14:27:12 -070052import com.android.server.input.InputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080053import com.android.server.wm.WindowManagerService.H;
54
Filip Gruszczynskia590c992015-11-25 16:45:26 -080055import android.annotation.NonNull;
Jorim Jaggi26c8c422016-05-09 19:57:25 -070056import android.content.res.Configuration;
Jorim Jaggi0429f352015-12-22 16:29:16 +010057import android.graphics.Rect;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070058import android.os.Binder;
59import android.os.IBinder;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080060import android.os.Message;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070061import android.os.SystemClock;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080062import android.util.Slog;
63import android.view.IApplicationToken;
64import android.view.View;
65import android.view.WindowManager;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080066
67import java.io.PrintWriter;
Jorim Jaggi0429f352015-12-22 16:29:16 +010068import java.util.ArrayDeque;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080069import java.util.ArrayList;
70
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
Wale Ogunwale72919d22016-12-08 18:58:50 -080086 final boolean mVoiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -070087
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 Ogunwale72919d22016-12-08 18:58:50 -080093 boolean mShowForAllUsers;
94 int mTargetSdk;
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.
Wale Ogunwale72919d22016-12-08 18:58:50 -080097 long mInputDispatchingTimeoutNanos;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080098
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 Ogunwale72919d22016-12-08 18:58:50 -0800157 private boolean mAlwaysFocusable;
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800158
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 Ogunwale72919d22016-12-08 18:58:50 -0800172 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
173 DisplayContent dc, long inputDispatchingTimeoutNanos, boolean fullscreen,
174 boolean showForAllUsers, int targetSdk, int orientation, int rotationAnimationHint,
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800175 int configChanges, boolean launchTaskBehind, boolean alwaysFocusable,
176 AppWindowContainerController controller) {
Wale Ogunwale72919d22016-12-08 18:58:50 -0800177 this(service, token, voiceInteraction, dc);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800178 setController(controller);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800179 mInputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
180 mFillsParent = fullscreen;
181 mShowForAllUsers = showForAllUsers;
182 mTargetSdk = targetSdk;
183 mOrientation = orientation;
184 layoutConfigChanges = (configChanges & (CONFIG_SCREEN_SIZE | CONFIG_ORIENTATION)) != 0;
185 mLaunchTaskBehind = launchTaskBehind;
186 mAlwaysFocusable = alwaysFocusable;
187 mRotationAnimationHint = rotationAnimationHint;
188
189 // Application tokens start out hidden.
190 hidden = true;
191 hiddenRequested = true;
192 }
193
194 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
195 DisplayContent dc) {
196 super(service, token != null ? token.asBinder() : null, TYPE_APPLICATION, true, dc);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700197 appToken = token;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800198 mVoiceInteraction = voiceInteraction;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800199 mInputApplicationHandle = new InputApplicationHandle(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700200 mAppAnimator = new AppWindowAnimator(this, service);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800201 }
202
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800203 void onFirstWindowDrawn(WindowState win, WindowStateAnimator winAnimator) {
204 firstWindowDrawn = true;
205
206 // We now have a good window to show, remove dead placeholders
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700207 removeDeadWindows();
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800208
209 if (startingData != null) {
210 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, "Finish starting "
211 + win.mToken + ": first real window is shown, no animation");
212 // If this initial window is animating, stop it -- we will do an animation to reveal
213 // it from behind the starting window, so there is no need for it to also be doing its
214 // own stuff.
215 winAnimator.clearAnimation();
216 winAnimator.mService.mFinishedStarting.add(this);
217 winAnimator.mService.mH.sendEmptyMessage(H.FINISHED_STARTING);
218 }
219 updateReportedVisibilityLocked();
220 }
221
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800222 void updateReportedVisibilityLocked() {
223 if (appToken == null) {
224 return;
225 }
226
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700227 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700228 final int count = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800229
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700230 mReportedVisibilityResults.reset();
231
232 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700233 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700234 win.updateReportedVisibility(mReportedVisibilityResults);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800235 }
236
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700237 int numInteresting = mReportedVisibilityResults.numInteresting;
238 int numVisible = mReportedVisibilityResults.numVisible;
239 int numDrawn = mReportedVisibilityResults.numDrawn;
240 boolean nowGone = mReportedVisibilityResults.nowGone;
241
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700242 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800243 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700244 if (!nowGone) {
245 // If the app is not yet gone, then it can only become visible/drawn.
246 if (!nowDrawn) {
247 nowDrawn = reportedDrawn;
248 }
249 if (!nowVisible) {
250 nowVisible = reportedVisible;
251 }
252 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800253 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800254 + numInteresting + " visible=" + numVisible);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800255 final AppWindowContainerController controller = getController();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700256 if (nowDrawn != reportedDrawn) {
257 if (nowDrawn) {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800258 if (controller != null) {
259 controller.reportWindowsDrawn();
260 }
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700261 }
262 reportedDrawn = nowDrawn;
263 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800264 if (nowVisible != reportedVisible) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700265 if (DEBUG_VISIBILITY) Slog.v(TAG,
266 "Visibility changed in " + this + ": vis=" + nowVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800267 reportedVisible = nowVisible;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800268 if (controller != null) {
269 if (nowVisible) {
270 controller.reportWindowsVisible();
271 } else {
272 controller.reportWindowsGone();
273 }
274 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800275 }
276 }
277
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700278 boolean setVisibility(WindowManager.LayoutParams lp,
279 boolean visible, int transit, boolean performLayout, boolean isVoiceInteraction) {
280
281 boolean delayed = false;
282 inPendingTransaction = false;
283
284 if (clientHidden == visible) {
285 clientHidden = !visible;
286 sendAppVisibilityToClients();
287 }
288
289 // Allow for state changes and animation to be applied if:
290 // * token is transitioning visibility state
291 // * or the token was marked as hidden and is exiting before we had a chance to play the
292 // transition animation
293 // * or this is an opening app and windows are being replaced.
294 boolean visibilityChanged = false;
295 if (hidden == visible || (hidden && mIsExiting) || (visible && waitingForReplacement())) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700296 final AccessibilityController accessibilityController = mService.mAccessibilityController;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700297 boolean changed = false;
298 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
299 "Changing app " + this + " hidden=" + hidden + " performLayout=" + performLayout);
300
301 boolean runningAppAnimation = false;
302
303 if (transit != AppTransition.TRANSIT_UNSET) {
304 if (mAppAnimator.animation == AppWindowAnimator.sDummyAnimation) {
305 mAppAnimator.setNullAnimation();
306 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700307 if (mService.applyAnimationLocked(this, lp, transit, visible, isVoiceInteraction)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700308 delayed = runningAppAnimation = true;
309 }
310 final WindowState window = findMainWindow();
311 //TODO (multidisplay): Magnification is supported only for the default display.
312 if (window != null && accessibilityController != null
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700313 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700314 accessibilityController.onAppWindowTransitionLocked(window, transit);
315 }
316 changed = true;
317 }
318
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700319 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700320 for (int i = 0; i < windowsCount; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700321 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700322 changed |= win.onAppVisibilityChanged(visible, runningAppAnimation);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700323 }
324
325 hidden = hiddenRequested = !visible;
326 visibilityChanged = true;
327 if (!visible) {
328 stopFreezingScreen(true, true);
329 } else {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700330 // If we are being set visible, and the starting window is not yet displayed,
331 // then make sure it doesn't get displayed.
332 if (startingWindow != null && !startingWindow.isDrawnLw()) {
333 startingWindow.mPolicyVisibility = false;
334 startingWindow.mPolicyVisibilityAfterAnim = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700335 }
336 }
337
338 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setVisibility: " + this
339 + ": hidden=" + hidden + " hiddenRequested=" + hiddenRequested);
340
341 if (changed) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700342 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700343 if (performLayout) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700344 mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700345 false /*updateInputWindows*/);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700346 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700347 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700348 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700349 }
350 }
351
352 if (mAppAnimator.animation != null) {
353 delayed = true;
354 }
355
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700356 for (int i = mChildren.size() - 1; i >= 0 && !delayed; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700357 if ((mChildren.get(i)).isWindowAnimationSet()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700358 delayed = true;
359 }
360 }
361
362 if (visibilityChanged) {
363 if (visible && !delayed) {
364 // The token was made immediately visible, there will be no entrance animation.
365 // We need to inform the client the enter animation was finished.
366 mEnteringAnimation = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700367 mService.mActivityManagerAppTransitionNotifier.onAppTransitionFinishedLocked(token);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700368 }
369
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700370 if (!mService.mClosingApps.contains(this) && !mService.mOpeningApps.contains(this)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700371 // The token is not closing nor opening, so even if there is an animation set, that
372 // doesn't mean that it goes through the normal app transition cycle so we have
373 // to inform the docked controller about visibility change.
Andrii Kulian1e32e022016-09-16 15:29:34 -0700374 // TODO(multi-display): notify docked divider on all displays where visibility was
375 // affected.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700376 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700377 .notifyAppVisibilityChanged();
378 }
379 }
380
381 return delayed;
382 }
383
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800384 WindowState findMainWindow() {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700385 WindowState candidate = null;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700386 int j = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800387 while (j > 0) {
388 j--;
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700389 final WindowState win = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700390 final int type = win.mAttrs.type;
391 // No need to loop through child window as base application and starting types can't be
392 // child windows.
393 if (type == TYPE_BASE_APPLICATION || type == TYPE_APPLICATION_STARTING) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700394 // In cases where there are multiple windows, we prefer the non-exiting window. This
Sungsoo Lim0d3d1f82015-12-02 14:47:59 +0900395 // happens for example when replacing windows during an activity relaunch. When
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700396 // constructing the animation, we want the new window, not the exiting one.
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800397 if (win.mAnimatingExit) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700398 candidate = win;
399 } else {
400 return win;
401 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800402 }
403 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700404 return candidate;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800405 }
406
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800407 boolean windowsAreFocusable() {
408 return StackId.canReceiveKeys(mTask.mStack.mStackId) || mAlwaysFocusable;
Wale Ogunwaled045c822015-12-02 09:14:28 -0800409 }
410
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800411 AppWindowContainerController getController() {
412 final WindowContainerController controller = super.getController();
413 return controller != null ? (AppWindowContainerController) controller : null;
414 }
415
Wale Ogunwale571771c2016-08-26 13:18:50 -0700416 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -0700417 boolean isVisible() {
Wale Ogunwalee471be62016-10-03 07:53:55 -0700418 // If the app token isn't hidden then it is considered visible and there is no need to check
419 // its children windows to see if they are visible.
420 return !hidden;
Wale Ogunwale44f21802016-09-02 12:49:48 -0700421 }
422
423 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -0700424 void removeIfPossible() {
Craig Mautnere3119b72015-01-20 15:02:36 -0800425 mIsExiting = false;
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800426 removeAllWindowsIfPossible();
Wale Ogunwale571771c2016-08-26 13:18:50 -0700427 if (mTask != null) {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700428 mTask.mStack.mExitingAppTokens.remove(this);
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800429 removeImmediately();
Craig Mautnere3119b72015-01-20 15:02:36 -0800430 }
431 }
432
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700433 @Override
434 boolean checkCompleteDeferredRemoval() {
435 if (mIsExiting) {
436 removeIfPossible();
437 }
438 return super.checkCompleteDeferredRemoval();
439 }
440
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700441 void onRemovedFromDisplay() {
442 AppWindowToken startingToken = null;
443
444 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app token: " + this);
445
Wale Ogunwale72919d22016-12-08 18:58:50 -0800446 boolean delayed = setVisibility(null, false, TRANSIT_UNSET, true, mVoiceInteraction);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700447
448 mService.mOpeningApps.remove(this);
Jorim Jaggi1b4b23e2016-11-15 16:30:12 -0800449 mService.mUnknownAppVisibilityController.appRemoved(this);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700450 waitingToShow = false;
451 if (mService.mClosingApps.contains(this)) {
452 delayed = true;
453 } else if (mService.mAppTransition.isTransitionSet()) {
454 mService.mClosingApps.add(this);
455 delayed = true;
456 }
457
458 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app " + this + " delayed=" + delayed
459 + " animation=" + mAppAnimator.animation + " animating=" + mAppAnimator.animating);
460
461 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM, "removeAppToken: "
462 + this + " delayed=" + delayed + " Callers=" + Debug.getCallers(4));
463
464 final TaskStack stack = mTask.mStack;
465 if (delayed && !isEmpty()) {
466 // set the token aside because it has an active animation to be finished
467 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM,
468 "removeAppToken make exiting: " + this);
469 stack.mExitingAppTokens.add(this);
470 mIsExiting = true;
471 } else {
472 // Make sure there is no animation running on this token, so any windows associated
473 // with it will be removed as soon as their animations are complete
474 mAppAnimator.clearAnimation();
475 mAppAnimator.animating = false;
476 removeIfPossible();
477 }
478
479 removed = true;
480 if (startingData != null) {
481 startingToken = this;
482 }
483 stopFreezingScreen(true, true);
484 if (mService.mFocusedApp == this) {
485 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "Removing focused app token:" + this);
486 mService.mFocusedApp = null;
487 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
488 mService.mInputMonitor.setFocusedAppLw(null);
489 }
490
491 if (!delayed) {
492 updateReportedVisibilityLocked();
493 }
494
495 // Will only remove if startingToken non null.
496 mService.scheduleRemoveStartingWindowLocked(startingToken);
497 }
498
Chong Zhange05bcb12016-07-26 17:47:29 -0700499 void clearAnimatingFlags() {
Chong Zhangb0d26702016-08-12 16:03:29 -0700500 boolean wallpaperMightChange = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700501 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700502 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700503 wallpaperMightChange |= win.clearAnimatingFlags();
Chong Zhange05bcb12016-07-26 17:47:29 -0700504 }
Chong Zhangb0d26702016-08-12 16:03:29 -0700505 if (wallpaperMightChange) {
506 requestUpdateWallpaperIfNeeded();
507 }
Chong Zhange05bcb12016-07-26 17:47:29 -0700508 }
509
Robert Carre12aece2016-02-02 22:43:27 -0800510 void destroySurfaces() {
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700511 destroySurfaces(false /*cleanupOnResume*/);
512 }
513
514 /**
515 * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure
516 * the client has finished with them.
517 *
518 * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If
519 * set to true, destroy only surfaces of removed windows, and clear relevant flags of the
520 * others so that they are ready to be reused. If set to false (common case), destroy all
521 * surfaces that's eligible, if the app is already stopped.
522 */
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700523 private void destroySurfaces(boolean cleanupOnResume) {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700524 boolean destroyedSomething = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700525 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700526 final WindowState win = mChildren.get(i);
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700527 destroyedSomething |= win.destroySurface(cleanupOnResume, mAppStopped);
Robert Carre12aece2016-02-02 22:43:27 -0800528 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700529 if (destroyedSomething) {
530 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700531 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Robert Carre12aece2016-02-02 22:43:27 -0800532 }
533 }
534
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800535 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700536 * Notify that the app is now resumed, and it was not stopped before, perform a clean
537 * up of the surfaces
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800538 */
Chong Zhangad24f962016-08-25 12:12:33 -0700539 void notifyAppResumed(boolean wasStopped, boolean allowSavedSurface) {
540 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped
541 + " allowSavedSurface=" + allowSavedSurface + " " + this);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700542 mAppStopped = false;
543 if (!wasStopped) {
544 destroySurfaces(true /*cleanupOnResume*/);
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800545 }
Chong Zhangad24f962016-08-25 12:12:33 -0700546 if (!allowSavedSurface) {
547 destroySavedSurfaces();
548 }
Robert Carre12aece2016-02-02 22:43:27 -0800549 }
550
Chong Zhangbef461f2015-10-27 11:38:24 -0700551 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700552 * Notify that the app has stopped, and it is okay to destroy any surfaces which were
553 * keeping alive in case they were still being used.
554 */
555 void notifyAppStopped() {
556 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this);
557 mAppStopped = true;
558 destroySurfaces();
559 // Remove any starting window that was added for this app if they are still around.
560 mTask.mService.scheduleRemoveStartingWindowLocked(this);
561 }
562
563 /**
Chong Zhangbef461f2015-10-27 11:38:24 -0700564 * Checks whether we should save surfaces for this app.
565 *
566 * @return true if the surfaces should be saved, false otherwise.
567 */
568 boolean shouldSaveSurface() {
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800569 // We want to save surface if the app's windows are "allDrawn".
570 // (If we started entering animation early with saved surfaces, allDrawn
571 // should have been restored to true. So we'll save again in that case
572 // even if app didn't actually finish drawing.)
573 return allDrawn;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800574 }
575
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700576 private boolean canRestoreSurfaces() {
577 for (int i = mChildren.size() -1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700578 final WindowState w = mChildren.get(i);
Chong Zhang92147042016-05-09 12:47:11 -0700579 if (w.canRestoreSurface()) {
Robert Carr13f7be9e2015-12-02 18:39:45 -0800580 return true;
581 }
Chong Zhangbef461f2015-10-27 11:38:24 -0700582 }
583 return false;
584 }
585
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700586 private void clearWasVisibleBeforeClientHidden() {
587 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700588 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700589 w.clearWasVisibleBeforeClientHidden();
Chong Zhang92147042016-05-09 12:47:11 -0700590 }
591 }
592
Chong Zhang8e4bda92016-05-04 15:08:18 -0700593 /**
594 * Whether the app has some window that is invisible in layout, but
595 * animating with saved surface.
596 */
597 boolean isAnimatingInvisibleWithSavedSurface() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700598 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700599 final WindowState w = mChildren.get(i);
Chong Zhang8e4bda92016-05-04 15:08:18 -0700600 if (w.isAnimatingInvisibleWithSavedSurface()) {
601 return true;
602 }
603 }
604 return false;
605 }
606
607 /**
608 * Hide all window surfaces that's still invisible in layout but animating
609 * with a saved surface, and mark them destroying.
610 */
611 void stopUsingSavedSurfaceLocked() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700612 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700613 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700614 w.stopUsingSavedSurface();
Chong Zhang8e4bda92016-05-04 15:08:18 -0700615 }
616 destroySurfaces();
617 }
618
Chong Zhangf58631a2016-05-24 16:02:10 -0700619 void markSavedSurfaceExiting() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700620 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700621 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700622 w.markSavedSurfaceExiting();
Chong Zhangf58631a2016-05-24 16:02:10 -0700623 }
624 }
625
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700626 void restoreSavedSurfaceForInterestingWindows() {
Chong Zhang92147042016-05-09 12:47:11 -0700627 if (!canRestoreSurfaces()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700628 clearWasVisibleBeforeClientHidden();
Chong Zhangbef461f2015-10-27 11:38:24 -0700629 return;
630 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700631
632 // Check if all interesting windows are drawn and we can mark allDrawn=true.
633 int interestingNotDrawn = -1;
634
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700635 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700636 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700637 interestingNotDrawn = w.restoreSavedSurfaceForInterestingWindow();
Chong Zhangbef461f2015-10-27 11:38:24 -0700638 }
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800639
Chong Zhang92147042016-05-09 12:47:11 -0700640 if (!allDrawn) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700641 allDrawn = (interestingNotDrawn == 0);
Chong Zhang92147042016-05-09 12:47:11 -0700642 if (allDrawn) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700643 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Chong Zhang92147042016-05-09 12:47:11 -0700644 }
645 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700646 clearWasVisibleBeforeClientHidden();
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800647
648 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700649 "restoreSavedSurfaceForInterestingWindows: " + this + " allDrawn=" + allDrawn
650 + " interestingNotDrawn=" + interestingNotDrawn);
Chong Zhangbef461f2015-10-27 11:38:24 -0700651 }
652
653 void destroySavedSurfaces() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700654 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700655 final WindowState win = mChildren.get(i);
Robert Carr13f7be9e2015-12-02 18:39:45 -0800656 win.destroySavedSurface();
Chong Zhangbef461f2015-10-27 11:38:24 -0700657 }
Chong Zhang92147042016-05-09 12:47:11 -0700658 }
659
660 void clearAllDrawn() {
661 allDrawn = false;
662 deferClearAllDrawn = false;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700663 allDrawnExcludingSaved = false;
Chong Zhangbef461f2015-10-27 11:38:24 -0700664 }
665
Wale Ogunwalefa854eb2016-09-20 13:43:52 -0700666 void postWindowRemoveStartingWindowCleanup(WindowState win) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700667 // TODO: Something smells about the code below...Is there a better way?
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700668 if (startingWindow == win) {
669 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700670 mService.scheduleRemoveStartingWindowLocked(this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700671 } else if (mChildren.size() == 0 && startingData != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700672 // If this is the last window and we had requested a starting transition window,
673 // well there is no point now.
674 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingWindow");
675 startingData = null;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700676 } else if (mChildren.size() == 1 && startingView != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700677 // If this is the last window except for a starting transition window,
678 // we need to get rid of the starting transition.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700679 mService.scheduleRemoveStartingWindowLocked(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700680 }
681 }
682
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700683 void removeDeadWindows() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700684 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700685 WindowState win = mChildren.get(winNdx);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800686 if (win.mAppDied) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700687 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700688 "removeDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800689 // Set mDestroying, we don't want any animation or delayed removal here.
690 win.mDestroying = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700691 // Also removes child windows.
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700692 win.removeIfPossible();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800693 }
694 }
695 }
696
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700697 boolean hasWindowsAlive() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700698 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700699 // No need to loop through child windows as the answer should be the same as that of the
700 // parent window.
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700701 if (!(mChildren.get(i)).mAppDied) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700702 return true;
703 }
704 }
705 return false;
706 }
707
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700708 void setWillReplaceWindows(boolean animate) {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700709 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
710 "Marking app token " + this + " with replacing windows.");
Robert Carra1eb4392015-12-10 12:43:51 -0800711
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700712 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700713 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700714 w.setWillReplaceWindow(animate);
Robert Carra1eb4392015-12-10 12:43:51 -0800715 }
716 if (animate) {
717 // Set-up dummy animation so we can start treating windows associated with this
718 // token like they are in transition before the new app window is ready for us to
719 // run the real transition animation.
720 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700721 "setWillReplaceWindow() Setting dummy animation on: " + this);
Robert Carra1eb4392015-12-10 12:43:51 -0800722 mAppAnimator.setDummyAnimation();
723 }
724 }
725
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700726 void setWillReplaceChildWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700727 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this
Robert Carr23fa16b2016-01-13 13:19:58 -0800728 + " with replacing child windows.");
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700729 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700730 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700731 w.setWillReplaceChildWindows();
Robert Carr23fa16b2016-01-13 13:19:58 -0800732 }
733 }
734
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700735 void clearWillReplaceWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700736 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
737 "Resetting app token " + this + " of replacing window marks.");
Chong Zhangf596cd52016-01-05 13:42:44 -0800738
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700739 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700740 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700741 w.clearWillReplaceWindow();
Chong Zhangf596cd52016-01-05 13:42:44 -0800742 }
743 }
744
Chong Zhang4d7369a2016-04-25 16:09:14 -0700745 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700746 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700747 final WindowState w = mChildren.get(i);
Chong Zhang4d7369a2016-04-25 16:09:14 -0700748 w.requestUpdateWallpaperIfNeeded();
749 }
750 }
751
Chong Zhangd78ddb42016-03-02 17:01:14 -0800752 boolean isRelaunching() {
753 return mPendingRelaunchCount > 0;
754 }
755
756 void startRelaunching() {
757 if (canFreezeBounds()) {
758 freezeBounds();
759 }
760 mPendingRelaunchCount++;
761 }
762
763 void finishRelaunching() {
764 if (canFreezeBounds()) {
765 unfreezeBounds();
766 }
767 if (mPendingRelaunchCount > 0) {
768 mPendingRelaunchCount--;
769 }
770 }
771
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700772 void clearRelaunching() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700773 if (mPendingRelaunchCount == 0) {
774 return;
775 }
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700776 if (canFreezeBounds()) {
777 unfreezeBounds();
778 }
779 mPendingRelaunchCount = 0;
780 }
781
Wale Ogunwale07bcab72016-10-14 15:30:09 -0700782 /**
783 * Returns true if the new child window we are adding to this token is considered greater than
784 * the existing child window in this token in terms of z-order.
785 */
786 @Override
787 protected boolean isFirstChildWindowGreaterThanSecond(WindowState newWindow,
788 WindowState existingWindow) {
789 final int type1 = newWindow.mAttrs.type;
790 final int type2 = existingWindow.mAttrs.type;
791
792 // Base application windows should be z-ordered BELOW all other windows in the app token.
793 if (type1 == TYPE_BASE_APPLICATION && type2 != TYPE_BASE_APPLICATION) {
794 return false;
795 } else if (type1 != TYPE_BASE_APPLICATION && type2 == TYPE_BASE_APPLICATION) {
796 return true;
797 }
798
799 // Starting windows should be z-ordered ABOVE all other windows in the app token.
800 if (type1 == TYPE_APPLICATION_STARTING && type2 != TYPE_APPLICATION_STARTING) {
801 return true;
802 } else if (type1 != TYPE_APPLICATION_STARTING && type2 == TYPE_APPLICATION_STARTING) {
803 return false;
804 }
805
806 // Otherwise the new window is greater than the existing window.
807 return true;
808 }
809
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700810 @Override
Robert Carra1eb4392015-12-10 12:43:51 -0800811 void addWindow(WindowState w) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700812 super.addWindow(w);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700813
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700814 boolean gotReplacementWindow = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700815 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700816 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700817 gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w);
818 }
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700819
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700820 // if we got a replacement window, reset the timeout to give drawing more time
821 if (gotReplacementWindow) {
822 mService.scheduleWindowReplacementTimeouts(this);
Robert Carra1eb4392015-12-10 12:43:51 -0800823 }
Jorim Jaggife762342016-10-13 14:33:27 +0200824 checkKeyguardFlagsChanged();
825 }
826
827 @Override
828 void removeChild(WindowState child) {
829 super.removeChild(child);
830 checkKeyguardFlagsChanged();
Robert Carra1eb4392015-12-10 12:43:51 -0800831 }
832
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700833 private boolean waitingForReplacement() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700834 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700835 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700836 if (candidate.waitingForReplacement()) {
Robert Carra1eb4392015-12-10 12:43:51 -0800837 return true;
838 }
839 }
840 return false;
841 }
842
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700843 void onWindowReplacementTimeout() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700844 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700845 (mChildren.get(i)).onWindowReplacementTimeout();
Robert Carra1eb4392015-12-10 12:43:51 -0800846 }
847 }
848
Chong Zhangd78ddb42016-03-02 17:01:14 -0800849 private boolean canFreezeBounds() {
850 // For freeform windows, we can't freeze the bounds at the moment because this would make
851 // the resizing unresponsive.
852 return mTask != null && !mTask.inFreeformWorkspace();
853 }
854
Jorim Jaggi0429f352015-12-22 16:29:16 +0100855 /**
856 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
857 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
858 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
859 * with a queue.
860 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800861 private void freezeBounds() {
Jorim Jaggi0429f352015-12-22 16:29:16 +0100862 mFrozenBounds.offer(new Rect(mTask.mPreparedFrozenBounds));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700863
864 if (mTask.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) {
865 // We didn't call prepareFreezingBounds on the task, so use the current value.
Andrii Kulian441e4492016-09-29 15:25:00 -0700866 mFrozenMergedConfig.offer(new Configuration(mTask.getConfiguration()));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700867 } else {
868 mFrozenMergedConfig.offer(new Configuration(mTask.mPreparedFrozenMergedConfig));
869 }
Andrii Kulianb10330d2016-09-16 13:51:46 -0700870 // Calling unset() to make it equal to Configuration.EMPTY.
871 mTask.mPreparedFrozenMergedConfig.unset();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100872 }
873
874 /**
875 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
876 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800877 private void unfreezeBounds() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700878 if (!mFrozenBounds.isEmpty()) {
879 mFrozenBounds.remove();
880 }
881 if (!mFrozenMergedConfig.isEmpty()) {
882 mFrozenMergedConfig.remove();
883 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700884 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700885 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700886 win.onUnfreezeBounds();
Jorim Jaggi4846ee32016-01-07 17:39:12 +0100887 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700888 mService.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100889 }
890
Robert Carr91b228092016-06-28 17:32:37 -0700891 void addSurfaceViewBackground(WindowSurfaceController.SurfaceControlWithBackground background) {
892 mSurfaceViewBackgrounds.add(background);
893 }
894
895 void removeSurfaceViewBackground(WindowSurfaceController.SurfaceControlWithBackground background) {
896 mSurfaceViewBackgrounds.remove(background);
897 updateSurfaceViewBackgroundVisibilities();
898 }
899
900 // We use DimLayers behind SurfaceViews to prevent holes while resizing and creating.
901 // However, we need to ensure one SurfaceView doesn't cover another when they are both placed
902 // below the main app window (as traditionally a SurfaceView which is never drawn
903 // to is totally translucent). So we look at all our SurfaceView backgrounds and only enable
904 // the background for the SurfaceView with lowest Z order
905 void updateSurfaceViewBackgroundVisibilities() {
906 WindowSurfaceController.SurfaceControlWithBackground bottom = null;
907 int bottomLayer = Integer.MAX_VALUE;
908 for (int i = 0; i < mSurfaceViewBackgrounds.size(); i++) {
909 WindowSurfaceController.SurfaceControlWithBackground sc = mSurfaceViewBackgrounds.get(i);
910 if (sc.mVisible && sc.mLayer < bottomLayer) {
911 bottomLayer = sc.mLayer;
912 bottom = sc;
913 }
914 }
915 for (int i = 0; i < mSurfaceViewBackgrounds.size(); i++) {
916 WindowSurfaceController.SurfaceControlWithBackground sc = mSurfaceViewBackgrounds.get(i);
917 sc.updateBackgroundVisibility(sc != bottom);
918 }
919 }
920
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700921 void resetJustMovedInStack() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700922 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700923 (mChildren.get(i)).resetJustMovedInStack();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700924 }
925 }
926
927 void notifyMovedInStack() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700928 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700929 final WindowState win = mChildren.get(winNdx);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700930 win.notifyMovedInStack();
931 }
932 }
933
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700934 void setAppLayoutChanges(int changes, String reason) {
935 if (!mChildren.isEmpty()) {
936 final DisplayContent dc = getDisplayContent();
937 dc.pendingLayoutChanges |= changes;
938 if (DEBUG_LAYOUT_REPEATS) {
939 mService.mWindowPlacerLocked.debugLayoutRepeats(reason, dc.pendingLayoutChanges);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700940 }
941 }
942 }
943
944 void removeReplacedWindowIfNeeded(WindowState replacement) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700945 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700946 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700947 if (win.removeReplacedWindowIfNeeded(replacement)) {
948 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700949 }
950 }
951 }
952
953 void startFreezingScreen() {
954 if (DEBUG_ORIENTATION) logWithStack(TAG, "Set freezing of " + appToken + ": hidden="
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700955 + hidden + " freezing=" + mAppAnimator.freezingScreen + " hiddenRequested="
956 + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700957 if (!hiddenRequested) {
958 if (!mAppAnimator.freezingScreen) {
959 mAppAnimator.freezingScreen = true;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700960 mService.registerAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700961 mAppAnimator.lastFreezeDuration = 0;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700962 mService.mAppsFreezingScreen++;
963 if (mService.mAppsFreezingScreen == 1) {
964 mService.startFreezingDisplayLocked(false, 0, 0);
965 mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT);
966 mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700967 }
968 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700969 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700970 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700971 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700972 w.onStartFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700973 }
974 }
975 }
976
977 void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) {
978 if (!mAppAnimator.freezingScreen) {
979 return;
980 }
981 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + this + " force=" + force);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700982 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700983 boolean unfrozeWindows = false;
984 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700985 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700986 unfrozeWindows |= w.onStopFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700987 }
988 if (force || unfrozeWindows) {
989 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this);
990 mAppAnimator.freezingScreen = false;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700991 mService.unregisterAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700992 mAppAnimator.lastFreezeDuration =
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700993 (int)(SystemClock.elapsedRealtime() - mService.mDisplayFreezeTime);
994 mService.mAppsFreezingScreen--;
995 mService.mLastFinishedFreezeSource = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700996 }
997 if (unfreezeSurfaceNow) {
998 if (unfrozeWindows) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700999 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001000 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001001 mService.stopFreezingDisplayLocked();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001002 }
1003 }
1004
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001005 @Override
1006 public void onAppFreezeTimeout() {
1007 Slog.w(TAG_WM, "Force clearing freeze: " + this);
1008 stopFreezingScreen(true, true);
1009 }
1010
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001011 boolean transferStartingWindow(IBinder transferFrom) {
Wale Ogunwale02319a62016-09-26 15:21:22 -07001012 final AppWindowToken fromToken = getDisplayContent().getAppWindowToken(transferFrom);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001013 if (fromToken == null) {
1014 return false;
1015 }
1016
1017 final WindowState tStartingWindow = fromToken.startingWindow;
1018 if (tStartingWindow != null && fromToken.startingView != null) {
1019 // In this case, the starting icon has already been displayed, so start
1020 // letting windows get shown immediately without any more transitions.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001021 mService.mSkipAppTransitionAnimation = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001022
1023 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow
1024 + " from " + fromToken + " to " + this);
1025
1026 final long origId = Binder.clearCallingIdentity();
1027
1028 // Transfer the starting window over to the new token.
1029 startingData = fromToken.startingData;
1030 startingView = fromToken.startingView;
1031 startingDisplayed = fromToken.startingDisplayed;
1032 fromToken.startingDisplayed = false;
1033 startingWindow = tStartingWindow;
1034 reportedVisible = fromToken.reportedVisible;
1035 fromToken.startingData = null;
1036 fromToken.startingView = null;
1037 fromToken.startingWindow = null;
1038 fromToken.startingMoved = true;
1039 tStartingWindow.mToken = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001040 tStartingWindow.mAppToken = this;
1041
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001042 if (DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001043 "Removing starting " + tStartingWindow + " from " + fromToken);
Wale Ogunwalefa854eb2016-09-20 13:43:52 -07001044 fromToken.removeChild(tStartingWindow);
1045 fromToken.postWindowRemoveStartingWindowCleanup(tStartingWindow);
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001046 addWindow(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001047
1048 // Propagate other interesting state between the tokens. If the old token is displayed,
1049 // we should immediately force the new one to be displayed. If it is animating, we need
1050 // to move that animation to the new one.
1051 if (fromToken.allDrawn) {
1052 allDrawn = true;
1053 deferClearAllDrawn = fromToken.deferClearAllDrawn;
1054 }
1055 if (fromToken.firstWindowDrawn) {
1056 firstWindowDrawn = true;
1057 }
1058 if (!fromToken.hidden) {
1059 hidden = false;
1060 hiddenRequested = false;
1061 }
1062 if (clientHidden != fromToken.clientHidden) {
1063 clientHidden = fromToken.clientHidden;
1064 sendAppVisibilityToClients();
1065 }
1066 fromToken.mAppAnimator.transferCurrentAnimation(
1067 mAppAnimator, tStartingWindow.mWinAnimator);
1068
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001069 mService.updateFocusedWindowLocked(
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001070 UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/);
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001071 getDisplayContent().setLayoutNeeded();
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001072 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001073 Binder.restoreCallingIdentity(origId);
1074 return true;
1075 } else if (fromToken.startingData != null) {
1076 // The previous app was getting ready to show a
1077 // starting window, but hasn't yet done so. Steal it!
1078 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1079 "Moving pending starting from " + fromToken + " to " + this);
1080 startingData = fromToken.startingData;
1081 fromToken.startingData = null;
1082 fromToken.startingMoved = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001083 final Message m = mService.mH.obtainMessage(H.ADD_STARTING, this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001084 // Note: we really want to do sendMessageAtFrontOfQueue() because we want to process the
1085 // message ASAP, before any other queued messages.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001086 mService.mH.sendMessageAtFrontOfQueue(m);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001087 return true;
1088 }
1089
1090 final AppWindowAnimator tAppAnimator = fromToken.mAppAnimator;
1091 final AppWindowAnimator wAppAnimator = mAppAnimator;
1092 if (tAppAnimator.thumbnail != null) {
1093 // The old token is animating with a thumbnail, transfer that to the new token.
1094 if (wAppAnimator.thumbnail != null) {
1095 wAppAnimator.thumbnail.destroy();
1096 }
1097 wAppAnimator.thumbnail = tAppAnimator.thumbnail;
1098 wAppAnimator.thumbnailLayer = tAppAnimator.thumbnailLayer;
1099 wAppAnimator.thumbnailAnimation = tAppAnimator.thumbnailAnimation;
1100 tAppAnimator.thumbnail = null;
1101 }
1102 return false;
1103 }
1104
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001105 boolean isLastWindow(WindowState win) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001106 return mChildren.size() == 1 && mChildren.get(0) == win;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001107 }
1108
1109 void setAllAppWinAnimators() {
1110 final ArrayList<WindowStateAnimator> allAppWinAnimators = mAppAnimator.mAllAppWinAnimators;
1111 allAppWinAnimators.clear();
1112
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001113 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001114 for (int j = 0; j < windowsCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001115 (mChildren.get(j)).addWinAnimatorToList(allAppWinAnimators);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001116 }
1117 }
1118
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001119 @Override
1120 void onAppTransitionDone() {
1121 sendingToBottom = false;
1122 }
1123
Wale Ogunwale51362492016-09-08 17:49:17 -07001124 /**
1125 * We override because this class doesn't want its children affecting its reported orientation
1126 * in anyway.
1127 */
1128 @Override
1129 int getOrientation() {
1130 if (hidden || hiddenRequested) {
1131 return SCREEN_ORIENTATION_UNSET;
1132 }
1133 return mOrientation;
1134 }
1135
Wale Ogunwaleb198b742016-12-01 08:44:09 -08001136 /** Returns the app's preferred orientation regardless of its currently visibility state. */
1137 int getOrientationIgnoreVisibility() {
1138 return mOrientation;
1139 }
1140
Craig Mautnerdbb79912012-03-01 18:59:14 -08001141 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001142 void checkAppWindowsReadyToShow() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001143 if (allDrawn == mAppAnimator.allDrawn) {
1144 return;
1145 }
1146
1147 mAppAnimator.allDrawn = allDrawn;
1148 if (!allDrawn) {
1149 return;
1150 }
1151
1152 // The token has now changed state to having all windows shown... what to do, what to do?
1153 if (mAppAnimator.freezingScreen) {
1154 mAppAnimator.showAllWindowsLocked();
1155 stopFreezingScreen(false, true);
1156 if (DEBUG_ORIENTATION) Slog.i(TAG,
1157 "Setting mOrientationChangeComplete=true because wtoken " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001158 + " numInteresting=" + mNumInterestingWindows + " numDrawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001159 // This will set mOrientationChangeComplete and cause a pass through layout.
1160 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001161 "checkAppWindowsReadyToShow: freezingScreen");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001162 } else {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001163 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001164
1165 // We can now show all of the drawn windows!
1166 if (!mService.mOpeningApps.contains(this)) {
1167 mService.mAnimator.orAnimating(mAppAnimator.showAllWindowsLocked());
1168 }
1169 }
1170 }
1171
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001172 void updateAllDrawn(DisplayContent dc) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001173 if (!allDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001174 final int numInteresting = mNumInterestingWindows;
1175 if (numInteresting > 0 && mNumDrawnWindows >= numInteresting) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001176 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawn: " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001177 + " interesting=" + numInteresting + " drawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001178 allDrawn = true;
1179 // Force an additional layout pass where
1180 // WindowStateAnimator#commitFinishDrawingLocked() will call performShowLocked().
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001181 dc.setLayoutNeeded();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001182 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
1183 }
1184 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001185
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001186 if (!allDrawnExcludingSaved) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001187 int numInteresting = mNumInterestingWindowsExcludingSaved;
1188 if (numInteresting > 0 && mNumDrawnWindowsExcludingSaved >= numInteresting) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001189 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawnExcludingSaved: " + this
1190 + " interesting=" + numInteresting
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001191 + " drawn=" + mNumDrawnWindowsExcludingSaved);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001192 allDrawnExcludingSaved = true;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001193 dc.setLayoutNeeded();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001194 if (isAnimatingInvisibleWithSavedSurface()
1195 && !mService.mFinishedEarlyAnim.contains(this)) {
1196 mService.mFinishedEarlyAnim.add(this);
1197 }
1198 }
1199 }
1200 }
1201
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001202 /**
1203 * Updated this app token tracking states for interesting and drawn windows based on the window.
1204 *
1205 * @return Returns true if the input window is considered interesting and drawn while all the
1206 * windows in this app token where not considered drawn as of the last pass.
1207 */
1208 boolean updateDrawnWindowStates(WindowState w) {
1209 if (DEBUG_STARTING_WINDOW && w == startingWindow) {
1210 Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" + w.isOnScreen()
1211 + " allDrawn=" + allDrawn + " freezingScreen=" + mAppAnimator.freezingScreen);
1212 }
1213
1214 if (allDrawn && allDrawnExcludingSaved && !mAppAnimator.freezingScreen) {
1215 return false;
1216 }
1217
1218 if (mLastTransactionSequence != mService.mTransactionSequence) {
1219 mLastTransactionSequence = mService.mTransactionSequence;
1220 mNumInterestingWindows = mNumDrawnWindows = 0;
1221 mNumInterestingWindowsExcludingSaved = 0;
1222 mNumDrawnWindowsExcludingSaved = 0;
1223 startingDisplayed = false;
1224 }
1225
1226 final WindowStateAnimator winAnimator = w.mWinAnimator;
1227
1228 boolean isInterestingAndDrawn = false;
1229
1230 if (!allDrawn && w.mightAffectAllDrawn(false /* visibleOnly */)) {
1231 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
1232 Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw()
1233 + ", isAnimationSet=" + winAnimator.isAnimationSet());
1234 if (!w.isDrawnLw()) {
1235 Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController
1236 + " pv=" + w.mPolicyVisibility
1237 + " mDrawState=" + winAnimator.drawStateToString()
1238 + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested
1239 + " a=" + winAnimator.mAnimating);
1240 }
1241 }
1242
1243 if (w != startingWindow) {
1244 if (w.isInteresting()) {
1245 mNumInterestingWindows++;
1246 if (w.isDrawnLw()) {
1247 mNumDrawnWindows++;
1248
1249 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, "tokenMayBeDrawn: "
1250 + this + " w=" + w + " numInteresting=" + mNumInterestingWindows
1251 + " freezingScreen=" + mAppAnimator.freezingScreen
1252 + " mAppFreezing=" + w.mAppFreezing);
1253
1254 isInterestingAndDrawn = true;
1255 }
1256 }
1257 } else if (w.isDrawnLw()) {
1258 mService.mH.sendEmptyMessage(NOTIFY_STARTING_WINDOW_DRAWN);
1259 startingDisplayed = true;
1260 }
1261 }
1262
1263 if (!allDrawnExcludingSaved && w.mightAffectAllDrawn(true /* visibleOnly */)) {
1264 if (w != startingWindow && w.isInteresting()) {
1265 mNumInterestingWindowsExcludingSaved++;
1266 if (w.isDrawnLw() && !w.isAnimatingWithSavedSurface()) {
1267 mNumDrawnWindowsExcludingSaved++;
1268
1269 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
1270 "tokenMayBeDrawnExcludingSaved: " + this + " w=" + w
1271 + " numInteresting=" + mNumInterestingWindowsExcludingSaved
1272 + " freezingScreen=" + mAppAnimator.freezingScreen
1273 + " mAppFreezing=" + w.mAppFreezing);
1274
1275 isInterestingAndDrawn = true;
1276 }
1277 }
1278 }
1279
1280 return isInterestingAndDrawn;
1281 }
1282
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001283 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001284 void stepAppWindowsAnimation(long currentTime) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001285 mAppAnimator.wasAnimating = mAppAnimator.animating;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001286 if (mAppAnimator.stepAnimationLocked(currentTime)) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001287 mAppAnimator.animating = true;
1288 mService.mAnimator.setAnimating(true);
1289 mService.mAnimator.mAppWindowAnimating = true;
1290 } else if (mAppAnimator.wasAnimating) {
1291 // stopped animating, do one more pass through the layout
Wale Ogunwale1e129a42016-11-21 13:03:47 -08001292 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
1293 DEBUG_LAYOUT_REPEATS ? "appToken " + this + " done" : null);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001294 if (DEBUG_ANIM) Slog.v(TAG, "updateWindowsApps...: done animating " + this);
1295 }
1296 }
1297
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001298 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001299 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001300 // For legacy reasons we process the TaskStack.mExitingAppTokens first in DisplayContent
1301 // before the non-exiting app tokens. So, we skip the exiting app tokens here.
1302 // TODO: Investigate if we need to continue to do this or if we can just process them
1303 // in-order.
1304 if (mIsExiting && !waitingForReplacement()) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001305 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001306 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001307 return forAllWindowsUnchecked(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001308 }
1309
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001310 boolean forAllWindowsUnchecked(ToBooleanFunction<WindowState> callback,
1311 boolean traverseTopToBottom) {
1312 return super.forAllWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001313 }
1314
1315 @Override
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001316 AppWindowToken asAppWindowToken() {
1317 // I am an app window token!
1318 return this;
1319 }
1320
1321 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -07001322 boolean fillsParent() {
1323 return mFillsParent;
1324 }
1325
1326 void setFillsParent(boolean fillsParent) {
1327 mFillsParent = fillsParent;
1328 }
1329
Jorim Jaggife762342016-10-13 14:33:27 +02001330 boolean containsDismissKeyguardWindow() {
1331 for (int i = mChildren.size() - 1; i >= 0; i--) {
1332 if ((mChildren.get(i).mAttrs.flags & FLAG_DISMISS_KEYGUARD) != 0) {
1333 return true;
1334 }
1335 }
1336 return false;
1337 }
1338
1339 boolean containsShowWhenLockedWindow() {
1340 for (int i = mChildren.size() - 1; i >= 0; i--) {
1341 if ((mChildren.get(i).mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
1342 return true;
1343 }
1344 }
1345 return false;
1346 }
1347
1348 void checkKeyguardFlagsChanged() {
1349 final boolean containsDismissKeyguard = containsDismissKeyguardWindow();
1350 final boolean containsShowWhenLocked = containsShowWhenLockedWindow();
1351 if (containsDismissKeyguard != mLastContainsDismissKeyguardWindow
1352 || containsShowWhenLocked != mLastContainsShowWhenLockedWindow) {
1353 mService.notifyKeyguardFlagsChanged(null /* callback */);
1354 }
1355 mLastContainsDismissKeyguardWindow = containsDismissKeyguard;
1356 mLastContainsShowWhenLockedWindow = containsShowWhenLocked;
1357 }
1358
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001359 WindowState getImeTargetBelowWindow(WindowState w) {
1360 final int index = mChildren.indexOf(w);
1361 if (index > 0) {
1362 final WindowState target = mChildren.get(index - 1);
1363 if (target.canBeImeTarget()) {
1364 return target;
1365 }
1366 }
1367 return null;
1368 }
1369
1370 WindowState getHighestAnimLayerWindow(WindowState currentTarget) {
1371 WindowState candidate = null;
1372 for (int i = mChildren.indexOf(currentTarget); i >= 0; i--) {
1373 final WindowState w = mChildren.get(i);
1374 if (w.mRemoved) {
1375 continue;
1376 }
1377 if (candidate == null || w.mWinAnimator.mAnimLayer >
1378 candidate.mWinAnimator.mAnimLayer) {
1379 candidate = w;
1380 }
1381 }
1382 return candidate;
1383 }
1384
Wale Ogunwale51362492016-09-08 17:49:17 -07001385 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001386 void dump(PrintWriter pw, String prefix) {
1387 super.dump(pw, prefix);
1388 if (appToken != null) {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001389 pw.println(prefix + "app=true mVoiceInteraction=" + mVoiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001390 }
Craig Mautner83162a92015-01-26 14:43:30 -08001391 pw.print(prefix); pw.print("task="); pw.println(mTask);
Wale Ogunwale51362492016-09-08 17:49:17 -07001392 pw.print(prefix); pw.print(" mFillsParent="); pw.print(mFillsParent);
1393 pw.print(" mOrientation="); pw.println(mOrientation);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001394 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
1395 pw.print(" clientHidden="); pw.print(clientHidden);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -07001396 pw.print(" reportedDrawn="); pw.print(reportedDrawn);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001397 pw.print(" reportedVisible="); pw.println(reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -07001398 if (paused) {
1399 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001400 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001401 if (mAppStopped) {
1402 pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped);
1403 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001404 if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0
Craig Mautner6fbda632012-07-03 09:26:39 -07001405 || allDrawn || mAppAnimator.allDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001406 pw.print(prefix); pw.print("mNumInterestingWindows=");
1407 pw.print(mNumInterestingWindows);
1408 pw.print(" mNumDrawnWindows="); pw.print(mNumDrawnWindows);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001409 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -07001410 pw.print(" allDrawn="); pw.print(allDrawn);
1411 pw.print(" (animator="); pw.print(mAppAnimator.allDrawn);
1412 pw.println(")");
1413 }
1414 if (inPendingTransaction) {
1415 pw.print(prefix); pw.print("inPendingTransaction=");
1416 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001417 }
Craig Mautner799bc1d2015-01-14 10:33:48 -08001418 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001419 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
1420 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -08001421 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -08001422 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001423 }
1424 if (startingWindow != null || startingView != null
1425 || startingDisplayed || startingMoved) {
1426 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
1427 pw.print(" startingView="); pw.print(startingView);
1428 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001429 pw.print(" startingMoved="); pw.println(startingMoved);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001430 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01001431 if (!mFrozenBounds.isEmpty()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -08001432 pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds);
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001433 pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig);
Chong Zhangd78ddb42016-03-02 17:01:14 -08001434 }
1435 if (mPendingRelaunchCount != 0) {
1436 pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount);
Jorim Jaggi0429f352015-12-22 16:29:16 +01001437 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001438 }
1439
1440 @Override
1441 public String toString() {
1442 if (stringName == null) {
1443 StringBuilder sb = new StringBuilder();
1444 sb.append("AppWindowToken{");
1445 sb.append(Integer.toHexString(System.identityHashCode(this)));
1446 sb.append(" token="); sb.append(token); sb.append('}');
1447 stringName = sb.toString();
1448 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001449 return stringName + ((mIsExiting) ? " mIsExiting=" : "");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001450 }
Jeff Browne9bdb312012-04-05 15:30:10 -07001451}