blob: 10d1d8b7c1c4a6593f028138c93d3a0259e2d950 [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;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080032import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080033import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
34import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
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
Filip Gruszczynskia590c992015-11-25 16:45:26 -080050import android.annotation.NonNull;
Jorim Jaggi26c8c422016-05-09 19:57:25 -070051import android.content.res.Configuration;
Jorim Jaggi0429f352015-12-22 16:29:16 +010052import android.graphics.Rect;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070053import android.os.Binder;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080054import android.os.Debug;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070055import android.os.IBinder;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070056import android.os.SystemClock;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080057import android.util.Slog;
58import android.view.IApplicationToken;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080059import android.view.WindowManager;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080060import android.view.WindowManagerPolicy.StartingSurface;
61
62import com.android.internal.util.ToBooleanFunction;
63import com.android.server.input.InputApplicationHandle;
64import com.android.server.wm.WindowManagerService.H;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080065
66import java.io.PrintWriter;
Jorim Jaggi0429f352015-12-22 16:29:16 +010067import java.util.ArrayDeque;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080068import java.util.ArrayList;
69
70class AppTokenList extends ArrayList<AppWindowToken> {
71}
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080072
73/**
74 * Version of WindowToken that is specifically for a particular application (or
75 * really activity) that is displaying windows.
76 */
Wale Ogunwale3f4433d2016-08-18 20:42:42 -070077class AppWindowToken extends WindowToken implements WindowManagerService.AppFreezeListener {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080078 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppWindowToken" : TAG_WM;
79
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080080 // Non-null only for application tokens.
81 final IApplicationToken appToken;
82
Filip Gruszczynskia590c992015-11-25 16:45:26 -080083 @NonNull final AppWindowAnimator mAppAnimator;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -070084
Wale Ogunwale72919d22016-12-08 18:58:50 -080085 final boolean mVoiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -070086
Wale Ogunwalef6192862016-09-10 13:42:30 -070087 // TODO: Use getParent instead?
Craig Mautner83162a92015-01-26 14:43:30 -080088 Task mTask;
Wale Ogunwale51362492016-09-08 17:49:17 -070089 /** @see WindowContainer#fillsParent() */
90 private boolean mFillsParent;
Craig Mautner4c5eb222013-11-18 12:59:05 -080091 boolean layoutConfigChanges;
Wale Ogunwale72919d22016-12-08 18:58:50 -080092 boolean mShowForAllUsers;
93 int mTargetSdk;
Craig Mautnera2c77052012-03-26 12:14:43 -070094
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080095 // The input dispatching timeout for this application token in nanoseconds.
Wale Ogunwale72919d22016-12-08 18:58:50 -080096 long mInputDispatchingTimeoutNanos;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080097
98 // These are used for determining when all windows associated with
99 // an activity have been drawn, so they can be made visible together
100 // at the same time.
Craig Mautner764983d2012-03-22 11:37:36 -0700101 // initialize so that it doesn't match mTransactionSequence which is an int.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700102 private long mLastTransactionSequence = Long.MIN_VALUE;
103 private int mNumInterestingWindows;
104 private int mNumDrawnWindows;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800105 boolean inPendingTransaction;
106 boolean allDrawn;
Craig Mautner7636dfb2012-11-16 15:24:11 -0800107 // Set to true when this app creates a surface while in the middle of an animation. In that
108 // case do not clear allDrawn until the animation completes.
109 boolean deferClearAllDrawn;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800110
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700111 /**
112 * These are to track the app's real drawing status if there were no saved surfaces.
113 * @see #updateDrawnWindowStates
114 */
Chong Zhang8e4bda92016-05-04 15:08:18 -0700115 boolean allDrawnExcludingSaved;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700116 private int mNumInterestingWindowsExcludingSaved;
117 private int mNumDrawnWindowsExcludingSaved;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700118
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800119 // Is this window's surface needed? This is almost like hidden, except
120 // it will sometimes be true a little earlier: when the token has
121 // been shown, but is still waiting for its app transition to execute
122 // before making its windows shown.
123 boolean hiddenRequested;
124
125 // Have we told the window clients to hide themselves?
126 boolean clientHidden;
127
128 // Last visibility state we reported to the app token.
129 boolean reportedVisible;
130
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700131 // Last drawn state we reported to the app token.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700132 private boolean reportedDrawn;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700133
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800134 // Set to true when the token has been removed from the window mgr.
135 boolean removed;
136
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800137 // Information about an application starting window if displayed.
138 StartingData startingData;
139 WindowState startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800140 StartingSurface startingSurface;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800141 boolean startingDisplayed;
142 boolean startingMoved;
143 boolean firstWindowDrawn;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700144 private final WindowState.UpdateReportedVisibilityResults mReportedVisibilityResults =
145 new WindowState.UpdateReportedVisibilityResults();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800146
147 // Input application handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700148 final InputApplicationHandle mInputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800149
Wale Ogunwale571771c2016-08-26 13:18:50 -0700150 // TODO: Have a WindowContainer state for tracking exiting/deferred removal.
Craig Mautner799bc1d2015-01-14 10:33:48 -0800151 boolean mIsExiting;
Craig Mautner9ef471f2014-02-07 13:11:47 -0800152
Craig Mautnerbb742462014-07-07 15:28:55 -0700153 boolean mLaunchTaskBehind;
Craig Mautner8746a472014-07-24 15:12:54 -0700154 boolean mEnteringAnimation;
Craig Mautnerbb742462014-07-07 15:28:55 -0700155
Wale Ogunwale72919d22016-12-08 18:58:50 -0800156 private boolean mAlwaysFocusable;
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800157
Robert Carre12aece2016-02-02 22:43:27 -0800158 boolean mAppStopped;
Robert Carrfd10cd12016-06-29 16:41:50 -0700159 int mRotationAnimationHint;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700160 private int mPendingRelaunchCount;
Robert Carre12aece2016-02-02 22:43:27 -0800161
Jorim Jaggife762342016-10-13 14:33:27 +0200162 private boolean mLastContainsShowWhenLockedWindow;
163 private boolean mLastContainsDismissKeyguardWindow;
164
Robert Carr91b228092016-06-28 17:32:37 -0700165 private ArrayList<WindowSurfaceController.SurfaceControlWithBackground> mSurfaceViewBackgrounds =
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700166 new ArrayList<>();
Robert Carr91b228092016-06-28 17:32:37 -0700167
Jorim Jaggi0429f352015-12-22 16:29:16 +0100168 ArrayDeque<Rect> mFrozenBounds = new ArrayDeque<>();
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700169 ArrayDeque<Configuration> mFrozenMergedConfig = new ArrayDeque<>();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100170
Wale Ogunwale72919d22016-12-08 18:58:50 -0800171 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
172 DisplayContent dc, long inputDispatchingTimeoutNanos, boolean fullscreen,
173 boolean showForAllUsers, int targetSdk, int orientation, int rotationAnimationHint,
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800174 int configChanges, boolean launchTaskBehind, boolean alwaysFocusable,
175 AppWindowContainerController controller) {
Wale Ogunwale72919d22016-12-08 18:58:50 -0800176 this(service, token, voiceInteraction, dc);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800177 setController(controller);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800178 mInputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
179 mFillsParent = fullscreen;
180 mShowForAllUsers = showForAllUsers;
181 mTargetSdk = targetSdk;
182 mOrientation = orientation;
183 layoutConfigChanges = (configChanges & (CONFIG_SCREEN_SIZE | CONFIG_ORIENTATION)) != 0;
184 mLaunchTaskBehind = launchTaskBehind;
185 mAlwaysFocusable = alwaysFocusable;
186 mRotationAnimationHint = rotationAnimationHint;
187
188 // Application tokens start out hidden.
189 hidden = true;
190 hiddenRequested = true;
191 }
192
193 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
194 DisplayContent dc) {
195 super(service, token != null ? token.asBinder() : null, TYPE_APPLICATION, true, dc);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700196 appToken = token;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800197 mVoiceInteraction = voiceInteraction;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800198 mInputApplicationHandle = new InputApplicationHandle(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700199 mAppAnimator = new AppWindowAnimator(this, service);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800200 }
201
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800202 void onFirstWindowDrawn(WindowState win, WindowStateAnimator winAnimator) {
203 firstWindowDrawn = true;
204
205 // We now have a good window to show, remove dead placeholders
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700206 removeDeadWindows();
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800207
Jorim Jaggi02886a82016-12-06 09:10:06 -0800208 if (startingWindow != null) {
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800209 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, "Finish starting "
210 + win.mToken + ": first real window is shown, no animation");
211 // If this initial window is animating, stop it -- we will do an animation to reveal
212 // it from behind the starting window, so there is no need for it to also be doing its
213 // own stuff.
214 winAnimator.clearAnimation();
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800215 if (getController() != null) {
216 getController().removeStartingWindow();
217 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800218 }
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() {
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700442 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app token: " + this);
443
Wale Ogunwale72919d22016-12-08 18:58:50 -0800444 boolean delayed = setVisibility(null, false, TRANSIT_UNSET, true, mVoiceInteraction);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700445
446 mService.mOpeningApps.remove(this);
Jorim Jaggi1b4b23e2016-11-15 16:30:12 -0800447 mService.mUnknownAppVisibilityController.appRemoved(this);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700448 waitingToShow = false;
449 if (mService.mClosingApps.contains(this)) {
450 delayed = true;
451 } else if (mService.mAppTransition.isTransitionSet()) {
452 mService.mClosingApps.add(this);
453 delayed = true;
454 }
455
456 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app " + this + " delayed=" + delayed
457 + " animation=" + mAppAnimator.animation + " animating=" + mAppAnimator.animating);
458
459 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM, "removeAppToken: "
460 + this + " delayed=" + delayed + " Callers=" + Debug.getCallers(4));
461
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800462 if (startingData != null && getController() != null) {
463 getController().removeStartingWindow();
464 }
465
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700466 final TaskStack stack = mTask.mStack;
467 if (delayed && !isEmpty()) {
468 // set the token aside because it has an active animation to be finished
469 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM,
470 "removeAppToken make exiting: " + this);
471 stack.mExitingAppTokens.add(this);
472 mIsExiting = true;
473 } else {
474 // Make sure there is no animation running on this token, so any windows associated
475 // with it will be removed as soon as their animations are complete
476 mAppAnimator.clearAnimation();
477 mAppAnimator.animating = false;
478 removeIfPossible();
479 }
480
481 removed = true;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700482 stopFreezingScreen(true, true);
483 if (mService.mFocusedApp == this) {
484 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "Removing focused app token:" + this);
485 mService.mFocusedApp = null;
486 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
487 mService.mInputMonitor.setFocusedAppLw(null);
488 }
489
490 if (!delayed) {
491 updateReportedVisibilityLocked();
492 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700493 }
494
Chong Zhange05bcb12016-07-26 17:47:29 -0700495 void clearAnimatingFlags() {
Chong Zhangb0d26702016-08-12 16:03:29 -0700496 boolean wallpaperMightChange = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700497 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700498 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700499 wallpaperMightChange |= win.clearAnimatingFlags();
Chong Zhange05bcb12016-07-26 17:47:29 -0700500 }
Chong Zhangb0d26702016-08-12 16:03:29 -0700501 if (wallpaperMightChange) {
502 requestUpdateWallpaperIfNeeded();
503 }
Chong Zhange05bcb12016-07-26 17:47:29 -0700504 }
505
Robert Carre12aece2016-02-02 22:43:27 -0800506 void destroySurfaces() {
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700507 destroySurfaces(false /*cleanupOnResume*/);
508 }
509
510 /**
511 * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure
512 * the client has finished with them.
513 *
514 * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If
515 * set to true, destroy only surfaces of removed windows, and clear relevant flags of the
516 * others so that they are ready to be reused. If set to false (common case), destroy all
517 * surfaces that's eligible, if the app is already stopped.
518 */
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700519 private void destroySurfaces(boolean cleanupOnResume) {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700520 boolean destroyedSomething = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700521 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700522 final WindowState win = mChildren.get(i);
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700523 destroyedSomething |= win.destroySurface(cleanupOnResume, mAppStopped);
Robert Carre12aece2016-02-02 22:43:27 -0800524 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700525 if (destroyedSomething) {
526 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700527 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Robert Carre12aece2016-02-02 22:43:27 -0800528 }
529 }
530
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800531 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700532 * Notify that the app is now resumed, and it was not stopped before, perform a clean
533 * up of the surfaces
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800534 */
Chong Zhangad24f962016-08-25 12:12:33 -0700535 void notifyAppResumed(boolean wasStopped, boolean allowSavedSurface) {
536 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped
537 + " allowSavedSurface=" + allowSavedSurface + " " + this);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700538 mAppStopped = false;
539 if (!wasStopped) {
540 destroySurfaces(true /*cleanupOnResume*/);
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800541 }
Chong Zhangad24f962016-08-25 12:12:33 -0700542 if (!allowSavedSurface) {
543 destroySavedSurfaces();
544 }
Robert Carre12aece2016-02-02 22:43:27 -0800545 }
546
Chong Zhangbef461f2015-10-27 11:38:24 -0700547 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700548 * Notify that the app has stopped, and it is okay to destroy any surfaces which were
549 * keeping alive in case they were still being used.
550 */
551 void notifyAppStopped() {
552 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this);
553 mAppStopped = true;
554 destroySurfaces();
555 // Remove any starting window that was added for this app if they are still around.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800556 if (getController() != null) {
557 getController().removeStartingWindow();
558 }
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700559 }
560
561 /**
Chong Zhangbef461f2015-10-27 11:38:24 -0700562 * Checks whether we should save surfaces for this app.
563 *
564 * @return true if the surfaces should be saved, false otherwise.
565 */
566 boolean shouldSaveSurface() {
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800567 // We want to save surface if the app's windows are "allDrawn".
568 // (If we started entering animation early with saved surfaces, allDrawn
569 // should have been restored to true. So we'll save again in that case
570 // even if app didn't actually finish drawing.)
571 return allDrawn;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800572 }
573
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700574 private boolean canRestoreSurfaces() {
575 for (int i = mChildren.size() -1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700576 final WindowState w = mChildren.get(i);
Chong Zhang92147042016-05-09 12:47:11 -0700577 if (w.canRestoreSurface()) {
Robert Carr13f7be9e2015-12-02 18:39:45 -0800578 return true;
579 }
Chong Zhangbef461f2015-10-27 11:38:24 -0700580 }
581 return false;
582 }
583
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700584 private void clearWasVisibleBeforeClientHidden() {
585 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700586 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700587 w.clearWasVisibleBeforeClientHidden();
Chong Zhang92147042016-05-09 12:47:11 -0700588 }
589 }
590
Chong Zhang8e4bda92016-05-04 15:08:18 -0700591 /**
592 * Whether the app has some window that is invisible in layout, but
593 * animating with saved surface.
594 */
595 boolean isAnimatingInvisibleWithSavedSurface() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700596 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700597 final WindowState w = mChildren.get(i);
Chong Zhang8e4bda92016-05-04 15:08:18 -0700598 if (w.isAnimatingInvisibleWithSavedSurface()) {
599 return true;
600 }
601 }
602 return false;
603 }
604
605 /**
606 * Hide all window surfaces that's still invisible in layout but animating
607 * with a saved surface, and mark them destroying.
608 */
609 void stopUsingSavedSurfaceLocked() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700610 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700611 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700612 w.stopUsingSavedSurface();
Chong Zhang8e4bda92016-05-04 15:08:18 -0700613 }
614 destroySurfaces();
615 }
616
Chong Zhangf58631a2016-05-24 16:02:10 -0700617 void markSavedSurfaceExiting() {
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 w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700620 w.markSavedSurfaceExiting();
Chong Zhangf58631a2016-05-24 16:02:10 -0700621 }
622 }
623
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700624 void restoreSavedSurfaceForInterestingWindows() {
Chong Zhang92147042016-05-09 12:47:11 -0700625 if (!canRestoreSurfaces()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700626 clearWasVisibleBeforeClientHidden();
Chong Zhangbef461f2015-10-27 11:38:24 -0700627 return;
628 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700629
630 // Check if all interesting windows are drawn and we can mark allDrawn=true.
631 int interestingNotDrawn = -1;
632
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700633 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700634 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700635 interestingNotDrawn = w.restoreSavedSurfaceForInterestingWindow();
Chong Zhangbef461f2015-10-27 11:38:24 -0700636 }
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800637
Chong Zhang92147042016-05-09 12:47:11 -0700638 if (!allDrawn) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700639 allDrawn = (interestingNotDrawn == 0);
Chong Zhang92147042016-05-09 12:47:11 -0700640 if (allDrawn) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700641 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Chong Zhang92147042016-05-09 12:47:11 -0700642 }
643 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700644 clearWasVisibleBeforeClientHidden();
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800645
646 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700647 "restoreSavedSurfaceForInterestingWindows: " + this + " allDrawn=" + allDrawn
648 + " interestingNotDrawn=" + interestingNotDrawn);
Chong Zhangbef461f2015-10-27 11:38:24 -0700649 }
650
651 void destroySavedSurfaces() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700652 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700653 final WindowState win = mChildren.get(i);
Robert Carr13f7be9e2015-12-02 18:39:45 -0800654 win.destroySavedSurface();
Chong Zhangbef461f2015-10-27 11:38:24 -0700655 }
Chong Zhang92147042016-05-09 12:47:11 -0700656 }
657
658 void clearAllDrawn() {
659 allDrawn = false;
660 deferClearAllDrawn = false;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700661 allDrawnExcludingSaved = false;
Chong Zhangbef461f2015-10-27 11:38:24 -0700662 }
663
Wale Ogunwalefa854eb2016-09-20 13:43:52 -0700664 void postWindowRemoveStartingWindowCleanup(WindowState win) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700665 // TODO: Something smells about the code below...Is there a better way?
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700666 if (startingWindow == win) {
667 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800668 if (getController() != null) {
669 getController().removeStartingWindow();
670 }
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.
Jorim Jaggi02886a82016-12-06 09:10:06 -0800674 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingData");
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700675 startingData = null;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800676 } else if (mChildren.size() == 1 && startingSurface != 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.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800679 if (getController() != null) {
680 getController().removeStartingWindow();
681 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700682 }
683 }
684
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700685 void removeDeadWindows() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700686 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700687 WindowState win = mChildren.get(winNdx);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800688 if (win.mAppDied) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700689 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700690 "removeDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800691 // Set mDestroying, we don't want any animation or delayed removal here.
692 win.mDestroying = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700693 // Also removes child windows.
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700694 win.removeIfPossible();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800695 }
696 }
697 }
698
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700699 boolean hasWindowsAlive() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700700 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700701 // No need to loop through child windows as the answer should be the same as that of the
702 // parent window.
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700703 if (!(mChildren.get(i)).mAppDied) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700704 return true;
705 }
706 }
707 return false;
708 }
709
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700710 void setWillReplaceWindows(boolean animate) {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700711 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
712 "Marking app token " + this + " with replacing windows.");
Robert Carra1eb4392015-12-10 12:43:51 -0800713
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700714 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700715 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700716 w.setWillReplaceWindow(animate);
Robert Carra1eb4392015-12-10 12:43:51 -0800717 }
718 if (animate) {
719 // Set-up dummy animation so we can start treating windows associated with this
720 // token like they are in transition before the new app window is ready for us to
721 // run the real transition animation.
722 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700723 "setWillReplaceWindow() Setting dummy animation on: " + this);
Robert Carra1eb4392015-12-10 12:43:51 -0800724 mAppAnimator.setDummyAnimation();
725 }
726 }
727
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700728 void setWillReplaceChildWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700729 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this
Robert Carr23fa16b2016-01-13 13:19:58 -0800730 + " with replacing child windows.");
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700731 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700732 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700733 w.setWillReplaceChildWindows();
Robert Carr23fa16b2016-01-13 13:19:58 -0800734 }
735 }
736
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700737 void clearWillReplaceWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700738 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
739 "Resetting app token " + this + " of replacing window marks.");
Chong Zhangf596cd52016-01-05 13:42:44 -0800740
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700741 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700742 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700743 w.clearWillReplaceWindow();
Chong Zhangf596cd52016-01-05 13:42:44 -0800744 }
745 }
746
Chong Zhang4d7369a2016-04-25 16:09:14 -0700747 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700748 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700749 final WindowState w = mChildren.get(i);
Chong Zhang4d7369a2016-04-25 16:09:14 -0700750 w.requestUpdateWallpaperIfNeeded();
751 }
752 }
753
Chong Zhangd78ddb42016-03-02 17:01:14 -0800754 boolean isRelaunching() {
755 return mPendingRelaunchCount > 0;
756 }
757
758 void startRelaunching() {
759 if (canFreezeBounds()) {
760 freezeBounds();
761 }
762 mPendingRelaunchCount++;
763 }
764
765 void finishRelaunching() {
766 if (canFreezeBounds()) {
767 unfreezeBounds();
768 }
769 if (mPendingRelaunchCount > 0) {
770 mPendingRelaunchCount--;
771 }
772 }
773
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700774 void clearRelaunching() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700775 if (mPendingRelaunchCount == 0) {
776 return;
777 }
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700778 if (canFreezeBounds()) {
779 unfreezeBounds();
780 }
781 mPendingRelaunchCount = 0;
782 }
783
Wale Ogunwale07bcab72016-10-14 15:30:09 -0700784 /**
785 * Returns true if the new child window we are adding to this token is considered greater than
786 * the existing child window in this token in terms of z-order.
787 */
788 @Override
789 protected boolean isFirstChildWindowGreaterThanSecond(WindowState newWindow,
790 WindowState existingWindow) {
791 final int type1 = newWindow.mAttrs.type;
792 final int type2 = existingWindow.mAttrs.type;
793
794 // Base application windows should be z-ordered BELOW all other windows in the app token.
795 if (type1 == TYPE_BASE_APPLICATION && type2 != TYPE_BASE_APPLICATION) {
796 return false;
797 } else if (type1 != TYPE_BASE_APPLICATION && type2 == TYPE_BASE_APPLICATION) {
798 return true;
799 }
800
801 // Starting windows should be z-ordered ABOVE all other windows in the app token.
802 if (type1 == TYPE_APPLICATION_STARTING && type2 != TYPE_APPLICATION_STARTING) {
803 return true;
804 } else if (type1 != TYPE_APPLICATION_STARTING && type2 == TYPE_APPLICATION_STARTING) {
805 return false;
806 }
807
808 // Otherwise the new window is greater than the existing window.
809 return true;
810 }
811
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700812 @Override
Robert Carra1eb4392015-12-10 12:43:51 -0800813 void addWindow(WindowState w) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700814 super.addWindow(w);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700815
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700816 boolean gotReplacementWindow = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700817 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700818 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700819 gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w);
820 }
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700821
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700822 // if we got a replacement window, reset the timeout to give drawing more time
823 if (gotReplacementWindow) {
824 mService.scheduleWindowReplacementTimeouts(this);
Robert Carra1eb4392015-12-10 12:43:51 -0800825 }
Jorim Jaggife762342016-10-13 14:33:27 +0200826 checkKeyguardFlagsChanged();
827 }
828
829 @Override
830 void removeChild(WindowState child) {
831 super.removeChild(child);
832 checkKeyguardFlagsChanged();
Robert Carra1eb4392015-12-10 12:43:51 -0800833 }
834
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700835 private boolean waitingForReplacement() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700836 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700837 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700838 if (candidate.waitingForReplacement()) {
Robert Carra1eb4392015-12-10 12:43:51 -0800839 return true;
840 }
841 }
842 return false;
843 }
844
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700845 void onWindowReplacementTimeout() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700846 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700847 (mChildren.get(i)).onWindowReplacementTimeout();
Robert Carra1eb4392015-12-10 12:43:51 -0800848 }
849 }
850
Chong Zhangd78ddb42016-03-02 17:01:14 -0800851 private boolean canFreezeBounds() {
852 // For freeform windows, we can't freeze the bounds at the moment because this would make
853 // the resizing unresponsive.
854 return mTask != null && !mTask.inFreeformWorkspace();
855 }
856
Jorim Jaggi0429f352015-12-22 16:29:16 +0100857 /**
858 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
859 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
860 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
861 * with a queue.
862 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800863 private void freezeBounds() {
Jorim Jaggi0429f352015-12-22 16:29:16 +0100864 mFrozenBounds.offer(new Rect(mTask.mPreparedFrozenBounds));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700865
866 if (mTask.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) {
867 // We didn't call prepareFreezingBounds on the task, so use the current value.
Andrii Kulian441e4492016-09-29 15:25:00 -0700868 mFrozenMergedConfig.offer(new Configuration(mTask.getConfiguration()));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700869 } else {
870 mFrozenMergedConfig.offer(new Configuration(mTask.mPreparedFrozenMergedConfig));
871 }
Andrii Kulianb10330d2016-09-16 13:51:46 -0700872 // Calling unset() to make it equal to Configuration.EMPTY.
873 mTask.mPreparedFrozenMergedConfig.unset();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100874 }
875
876 /**
877 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
878 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800879 private void unfreezeBounds() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700880 if (!mFrozenBounds.isEmpty()) {
881 mFrozenBounds.remove();
882 }
883 if (!mFrozenMergedConfig.isEmpty()) {
884 mFrozenMergedConfig.remove();
885 }
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 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700888 win.onUnfreezeBounds();
Jorim Jaggi4846ee32016-01-07 17:39:12 +0100889 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700890 mService.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100891 }
892
Robert Carr91b228092016-06-28 17:32:37 -0700893 void addSurfaceViewBackground(WindowSurfaceController.SurfaceControlWithBackground background) {
894 mSurfaceViewBackgrounds.add(background);
895 }
896
897 void removeSurfaceViewBackground(WindowSurfaceController.SurfaceControlWithBackground background) {
898 mSurfaceViewBackgrounds.remove(background);
899 updateSurfaceViewBackgroundVisibilities();
900 }
901
902 // We use DimLayers behind SurfaceViews to prevent holes while resizing and creating.
903 // However, we need to ensure one SurfaceView doesn't cover another when they are both placed
904 // below the main app window (as traditionally a SurfaceView which is never drawn
905 // to is totally translucent). So we look at all our SurfaceView backgrounds and only enable
906 // the background for the SurfaceView with lowest Z order
907 void updateSurfaceViewBackgroundVisibilities() {
908 WindowSurfaceController.SurfaceControlWithBackground bottom = null;
909 int bottomLayer = Integer.MAX_VALUE;
910 for (int i = 0; i < mSurfaceViewBackgrounds.size(); i++) {
911 WindowSurfaceController.SurfaceControlWithBackground sc = mSurfaceViewBackgrounds.get(i);
912 if (sc.mVisible && sc.mLayer < bottomLayer) {
913 bottomLayer = sc.mLayer;
914 bottom = sc;
915 }
916 }
917 for (int i = 0; i < mSurfaceViewBackgrounds.size(); i++) {
918 WindowSurfaceController.SurfaceControlWithBackground sc = mSurfaceViewBackgrounds.get(i);
919 sc.updateBackgroundVisibility(sc != bottom);
920 }
921 }
922
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700923 void resetJustMovedInStack() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700924 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700925 (mChildren.get(i)).resetJustMovedInStack();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700926 }
927 }
928
929 void notifyMovedInStack() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700930 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700931 final WindowState win = mChildren.get(winNdx);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700932 win.notifyMovedInStack();
933 }
934 }
935
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700936 void setAppLayoutChanges(int changes, String reason) {
937 if (!mChildren.isEmpty()) {
938 final DisplayContent dc = getDisplayContent();
939 dc.pendingLayoutChanges |= changes;
940 if (DEBUG_LAYOUT_REPEATS) {
941 mService.mWindowPlacerLocked.debugLayoutRepeats(reason, dc.pendingLayoutChanges);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700942 }
943 }
944 }
945
946 void removeReplacedWindowIfNeeded(WindowState replacement) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700947 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700948 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700949 if (win.removeReplacedWindowIfNeeded(replacement)) {
950 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700951 }
952 }
953 }
954
955 void startFreezingScreen() {
956 if (DEBUG_ORIENTATION) logWithStack(TAG, "Set freezing of " + appToken + ": hidden="
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700957 + hidden + " freezing=" + mAppAnimator.freezingScreen + " hiddenRequested="
958 + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700959 if (!hiddenRequested) {
960 if (!mAppAnimator.freezingScreen) {
961 mAppAnimator.freezingScreen = true;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700962 mService.registerAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700963 mAppAnimator.lastFreezeDuration = 0;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700964 mService.mAppsFreezingScreen++;
965 if (mService.mAppsFreezingScreen == 1) {
966 mService.startFreezingDisplayLocked(false, 0, 0);
967 mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT);
968 mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700969 }
970 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700971 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700972 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700973 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700974 w.onStartFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700975 }
976 }
977 }
978
979 void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) {
980 if (!mAppAnimator.freezingScreen) {
981 return;
982 }
983 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + this + " force=" + force);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700984 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700985 boolean unfrozeWindows = false;
986 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700987 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700988 unfrozeWindows |= w.onStopFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700989 }
990 if (force || unfrozeWindows) {
991 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this);
992 mAppAnimator.freezingScreen = false;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700993 mService.unregisterAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700994 mAppAnimator.lastFreezeDuration =
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700995 (int)(SystemClock.elapsedRealtime() - mService.mDisplayFreezeTime);
996 mService.mAppsFreezingScreen--;
997 mService.mLastFinishedFreezeSource = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700998 }
999 if (unfreezeSurfaceNow) {
1000 if (unfrozeWindows) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001001 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001002 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001003 mService.stopFreezingDisplayLocked();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001004 }
1005 }
1006
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001007 @Override
1008 public void onAppFreezeTimeout() {
1009 Slog.w(TAG_WM, "Force clearing freeze: " + this);
1010 stopFreezingScreen(true, true);
1011 }
1012
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001013 boolean transferStartingWindow(IBinder transferFrom) {
Wale Ogunwale02319a62016-09-26 15:21:22 -07001014 final AppWindowToken fromToken = getDisplayContent().getAppWindowToken(transferFrom);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001015 if (fromToken == null) {
1016 return false;
1017 }
1018
1019 final WindowState tStartingWindow = fromToken.startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001020 if (tStartingWindow != null && fromToken.startingSurface != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001021 // In this case, the starting icon has already been displayed, so start
1022 // letting windows get shown immediately without any more transitions.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001023 mService.mSkipAppTransitionAnimation = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001024
1025 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow
1026 + " from " + fromToken + " to " + this);
1027
1028 final long origId = Binder.clearCallingIdentity();
1029
1030 // Transfer the starting window over to the new token.
1031 startingData = fromToken.startingData;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001032 startingSurface = fromToken.startingSurface;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001033 startingDisplayed = fromToken.startingDisplayed;
1034 fromToken.startingDisplayed = false;
1035 startingWindow = tStartingWindow;
1036 reportedVisible = fromToken.reportedVisible;
1037 fromToken.startingData = null;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001038 fromToken.startingSurface = null;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001039 fromToken.startingWindow = null;
1040 fromToken.startingMoved = true;
1041 tStartingWindow.mToken = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001042 tStartingWindow.mAppToken = this;
1043
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001044 if (DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001045 "Removing starting " + tStartingWindow + " from " + fromToken);
Wale Ogunwalefa854eb2016-09-20 13:43:52 -07001046 fromToken.removeChild(tStartingWindow);
1047 fromToken.postWindowRemoveStartingWindowCleanup(tStartingWindow);
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001048 addWindow(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001049
1050 // Propagate other interesting state between the tokens. If the old token is displayed,
1051 // we should immediately force the new one to be displayed. If it is animating, we need
1052 // to move that animation to the new one.
1053 if (fromToken.allDrawn) {
1054 allDrawn = true;
1055 deferClearAllDrawn = fromToken.deferClearAllDrawn;
1056 }
1057 if (fromToken.firstWindowDrawn) {
1058 firstWindowDrawn = true;
1059 }
1060 if (!fromToken.hidden) {
1061 hidden = false;
1062 hiddenRequested = false;
1063 }
1064 if (clientHidden != fromToken.clientHidden) {
1065 clientHidden = fromToken.clientHidden;
1066 sendAppVisibilityToClients();
1067 }
1068 fromToken.mAppAnimator.transferCurrentAnimation(
1069 mAppAnimator, tStartingWindow.mWinAnimator);
1070
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001071 mService.updateFocusedWindowLocked(
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001072 UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/);
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001073 getDisplayContent().setLayoutNeeded();
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001074 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001075 Binder.restoreCallingIdentity(origId);
1076 return true;
1077 } else if (fromToken.startingData != null) {
1078 // The previous app was getting ready to show a
1079 // starting window, but hasn't yet done so. Steal it!
1080 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1081 "Moving pending starting from " + fromToken + " to " + this);
1082 startingData = fromToken.startingData;
1083 fromToken.startingData = null;
1084 fromToken.startingMoved = true;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001085 if (getController() != null) {
1086 getController().scheduleAddStartingWindow();
1087 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001088 return true;
1089 }
1090
1091 final AppWindowAnimator tAppAnimator = fromToken.mAppAnimator;
1092 final AppWindowAnimator wAppAnimator = mAppAnimator;
1093 if (tAppAnimator.thumbnail != null) {
1094 // The old token is animating with a thumbnail, transfer that to the new token.
1095 if (wAppAnimator.thumbnail != null) {
1096 wAppAnimator.thumbnail.destroy();
1097 }
1098 wAppAnimator.thumbnail = tAppAnimator.thumbnail;
1099 wAppAnimator.thumbnailLayer = tAppAnimator.thumbnailLayer;
1100 wAppAnimator.thumbnailAnimation = tAppAnimator.thumbnailAnimation;
1101 tAppAnimator.thumbnail = null;
1102 }
1103 return false;
1104 }
1105
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001106 boolean isLastWindow(WindowState win) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001107 return mChildren.size() == 1 && mChildren.get(0) == win;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001108 }
1109
1110 void setAllAppWinAnimators() {
1111 final ArrayList<WindowStateAnimator> allAppWinAnimators = mAppAnimator.mAllAppWinAnimators;
1112 allAppWinAnimators.clear();
1113
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001114 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001115 for (int j = 0; j < windowsCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001116 (mChildren.get(j)).addWinAnimatorToList(allAppWinAnimators);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001117 }
1118 }
1119
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001120 @Override
1121 void onAppTransitionDone() {
1122 sendingToBottom = false;
1123 }
1124
Wale Ogunwale51362492016-09-08 17:49:17 -07001125 /**
1126 * We override because this class doesn't want its children affecting its reported orientation
1127 * in anyway.
1128 */
1129 @Override
1130 int getOrientation() {
1131 if (hidden || hiddenRequested) {
1132 return SCREEN_ORIENTATION_UNSET;
1133 }
1134 return mOrientation;
1135 }
1136
Wale Ogunwaleb198b742016-12-01 08:44:09 -08001137 /** Returns the app's preferred orientation regardless of its currently visibility state. */
1138 int getOrientationIgnoreVisibility() {
1139 return mOrientation;
1140 }
1141
Craig Mautnerdbb79912012-03-01 18:59:14 -08001142 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001143 void checkAppWindowsReadyToShow() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001144 if (allDrawn == mAppAnimator.allDrawn) {
1145 return;
1146 }
1147
1148 mAppAnimator.allDrawn = allDrawn;
1149 if (!allDrawn) {
1150 return;
1151 }
1152
1153 // The token has now changed state to having all windows shown... what to do, what to do?
1154 if (mAppAnimator.freezingScreen) {
1155 mAppAnimator.showAllWindowsLocked();
1156 stopFreezingScreen(false, true);
1157 if (DEBUG_ORIENTATION) Slog.i(TAG,
1158 "Setting mOrientationChangeComplete=true because wtoken " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001159 + " numInteresting=" + mNumInterestingWindows + " numDrawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001160 // This will set mOrientationChangeComplete and cause a pass through layout.
1161 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001162 "checkAppWindowsReadyToShow: freezingScreen");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001163 } else {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001164 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001165
1166 // We can now show all of the drawn windows!
1167 if (!mService.mOpeningApps.contains(this)) {
1168 mService.mAnimator.orAnimating(mAppAnimator.showAllWindowsLocked());
1169 }
1170 }
1171 }
1172
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001173 void updateAllDrawn(DisplayContent dc) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001174 if (!allDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001175 final int numInteresting = mNumInterestingWindows;
1176 if (numInteresting > 0 && mNumDrawnWindows >= numInteresting) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001177 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawn: " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001178 + " interesting=" + numInteresting + " drawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001179 allDrawn = true;
1180 // Force an additional layout pass where
1181 // WindowStateAnimator#commitFinishDrawingLocked() will call performShowLocked().
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001182 dc.setLayoutNeeded();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001183 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
1184 }
1185 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001186
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001187 if (!allDrawnExcludingSaved) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001188 int numInteresting = mNumInterestingWindowsExcludingSaved;
1189 if (numInteresting > 0 && mNumDrawnWindowsExcludingSaved >= numInteresting) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001190 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawnExcludingSaved: " + this
1191 + " interesting=" + numInteresting
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001192 + " drawn=" + mNumDrawnWindowsExcludingSaved);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001193 allDrawnExcludingSaved = true;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001194 dc.setLayoutNeeded();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001195 if (isAnimatingInvisibleWithSavedSurface()
1196 && !mService.mFinishedEarlyAnim.contains(this)) {
1197 mService.mFinishedEarlyAnim.add(this);
1198 }
1199 }
1200 }
1201 }
1202
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001203 /**
1204 * Updated this app token tracking states for interesting and drawn windows based on the window.
1205 *
1206 * @return Returns true if the input window is considered interesting and drawn while all the
1207 * windows in this app token where not considered drawn as of the last pass.
1208 */
1209 boolean updateDrawnWindowStates(WindowState w) {
1210 if (DEBUG_STARTING_WINDOW && w == startingWindow) {
1211 Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" + w.isOnScreen()
1212 + " allDrawn=" + allDrawn + " freezingScreen=" + mAppAnimator.freezingScreen);
1213 }
1214
1215 if (allDrawn && allDrawnExcludingSaved && !mAppAnimator.freezingScreen) {
1216 return false;
1217 }
1218
1219 if (mLastTransactionSequence != mService.mTransactionSequence) {
1220 mLastTransactionSequence = mService.mTransactionSequence;
1221 mNumInterestingWindows = mNumDrawnWindows = 0;
1222 mNumInterestingWindowsExcludingSaved = 0;
1223 mNumDrawnWindowsExcludingSaved = 0;
1224 startingDisplayed = false;
1225 }
1226
1227 final WindowStateAnimator winAnimator = w.mWinAnimator;
1228
1229 boolean isInterestingAndDrawn = false;
1230
1231 if (!allDrawn && w.mightAffectAllDrawn(false /* visibleOnly */)) {
1232 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
1233 Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw()
1234 + ", isAnimationSet=" + winAnimator.isAnimationSet());
1235 if (!w.isDrawnLw()) {
1236 Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController
1237 + " pv=" + w.mPolicyVisibility
1238 + " mDrawState=" + winAnimator.drawStateToString()
1239 + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested
1240 + " a=" + winAnimator.mAnimating);
1241 }
1242 }
1243
1244 if (w != startingWindow) {
1245 if (w.isInteresting()) {
1246 mNumInterestingWindows++;
1247 if (w.isDrawnLw()) {
1248 mNumDrawnWindows++;
1249
1250 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, "tokenMayBeDrawn: "
1251 + this + " w=" + w + " numInteresting=" + mNumInterestingWindows
1252 + " freezingScreen=" + mAppAnimator.freezingScreen
1253 + " mAppFreezing=" + w.mAppFreezing);
1254
1255 isInterestingAndDrawn = true;
1256 }
1257 }
1258 } else if (w.isDrawnLw()) {
1259 mService.mH.sendEmptyMessage(NOTIFY_STARTING_WINDOW_DRAWN);
1260 startingDisplayed = true;
1261 }
1262 }
1263
1264 if (!allDrawnExcludingSaved && w.mightAffectAllDrawn(true /* visibleOnly */)) {
1265 if (w != startingWindow && w.isInteresting()) {
1266 mNumInterestingWindowsExcludingSaved++;
1267 if (w.isDrawnLw() && !w.isAnimatingWithSavedSurface()) {
1268 mNumDrawnWindowsExcludingSaved++;
1269
1270 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
1271 "tokenMayBeDrawnExcludingSaved: " + this + " w=" + w
1272 + " numInteresting=" + mNumInterestingWindowsExcludingSaved
1273 + " freezingScreen=" + mAppAnimator.freezingScreen
1274 + " mAppFreezing=" + w.mAppFreezing);
1275
1276 isInterestingAndDrawn = true;
1277 }
1278 }
1279 }
1280
1281 return isInterestingAndDrawn;
1282 }
1283
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001284 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001285 void stepAppWindowsAnimation(long currentTime) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001286 mAppAnimator.wasAnimating = mAppAnimator.animating;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001287 if (mAppAnimator.stepAnimationLocked(currentTime)) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001288 mAppAnimator.animating = true;
1289 mService.mAnimator.setAnimating(true);
1290 mService.mAnimator.mAppWindowAnimating = true;
1291 } else if (mAppAnimator.wasAnimating) {
1292 // stopped animating, do one more pass through the layout
Wale Ogunwale1e129a42016-11-21 13:03:47 -08001293 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
1294 DEBUG_LAYOUT_REPEATS ? "appToken " + this + " done" : null);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001295 if (DEBUG_ANIM) Slog.v(TAG, "updateWindowsApps...: done animating " + this);
1296 }
1297 }
1298
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001299 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001300 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001301 // For legacy reasons we process the TaskStack.mExitingAppTokens first in DisplayContent
1302 // before the non-exiting app tokens. So, we skip the exiting app tokens here.
1303 // TODO: Investigate if we need to continue to do this or if we can just process them
1304 // in-order.
1305 if (mIsExiting && !waitingForReplacement()) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001306 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001307 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001308 return forAllWindowsUnchecked(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001309 }
1310
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001311 boolean forAllWindowsUnchecked(ToBooleanFunction<WindowState> callback,
1312 boolean traverseTopToBottom) {
1313 return super.forAllWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001314 }
1315
1316 @Override
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001317 AppWindowToken asAppWindowToken() {
1318 // I am an app window token!
1319 return this;
1320 }
1321
1322 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -07001323 boolean fillsParent() {
1324 return mFillsParent;
1325 }
1326
1327 void setFillsParent(boolean fillsParent) {
1328 mFillsParent = fillsParent;
1329 }
1330
Jorim Jaggife762342016-10-13 14:33:27 +02001331 boolean containsDismissKeyguardWindow() {
1332 for (int i = mChildren.size() - 1; i >= 0; i--) {
1333 if ((mChildren.get(i).mAttrs.flags & FLAG_DISMISS_KEYGUARD) != 0) {
1334 return true;
1335 }
1336 }
1337 return false;
1338 }
1339
1340 boolean containsShowWhenLockedWindow() {
1341 for (int i = mChildren.size() - 1; i >= 0; i--) {
1342 if ((mChildren.get(i).mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
1343 return true;
1344 }
1345 }
1346 return false;
1347 }
1348
1349 void checkKeyguardFlagsChanged() {
1350 final boolean containsDismissKeyguard = containsDismissKeyguardWindow();
1351 final boolean containsShowWhenLocked = containsShowWhenLockedWindow();
1352 if (containsDismissKeyguard != mLastContainsDismissKeyguardWindow
1353 || containsShowWhenLocked != mLastContainsShowWhenLockedWindow) {
1354 mService.notifyKeyguardFlagsChanged(null /* callback */);
1355 }
1356 mLastContainsDismissKeyguardWindow = containsDismissKeyguard;
1357 mLastContainsShowWhenLockedWindow = containsShowWhenLocked;
1358 }
1359
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001360 WindowState getImeTargetBelowWindow(WindowState w) {
1361 final int index = mChildren.indexOf(w);
1362 if (index > 0) {
1363 final WindowState target = mChildren.get(index - 1);
1364 if (target.canBeImeTarget()) {
1365 return target;
1366 }
1367 }
1368 return null;
1369 }
1370
1371 WindowState getHighestAnimLayerWindow(WindowState currentTarget) {
1372 WindowState candidate = null;
1373 for (int i = mChildren.indexOf(currentTarget); i >= 0; i--) {
1374 final WindowState w = mChildren.get(i);
1375 if (w.mRemoved) {
1376 continue;
1377 }
1378 if (candidate == null || w.mWinAnimator.mAnimLayer >
1379 candidate.mWinAnimator.mAnimLayer) {
1380 candidate = w;
1381 }
1382 }
1383 return candidate;
1384 }
1385
Wale Ogunwale51362492016-09-08 17:49:17 -07001386 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001387 void dump(PrintWriter pw, String prefix) {
1388 super.dump(pw, prefix);
1389 if (appToken != null) {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001390 pw.println(prefix + "app=true mVoiceInteraction=" + mVoiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001391 }
Craig Mautner83162a92015-01-26 14:43:30 -08001392 pw.print(prefix); pw.print("task="); pw.println(mTask);
Wale Ogunwale51362492016-09-08 17:49:17 -07001393 pw.print(prefix); pw.print(" mFillsParent="); pw.print(mFillsParent);
1394 pw.print(" mOrientation="); pw.println(mOrientation);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001395 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
1396 pw.print(" clientHidden="); pw.print(clientHidden);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -07001397 pw.print(" reportedDrawn="); pw.print(reportedDrawn);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001398 pw.print(" reportedVisible="); pw.println(reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -07001399 if (paused) {
1400 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001401 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001402 if (mAppStopped) {
1403 pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped);
1404 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001405 if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0
Craig Mautner6fbda632012-07-03 09:26:39 -07001406 || allDrawn || mAppAnimator.allDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001407 pw.print(prefix); pw.print("mNumInterestingWindows=");
1408 pw.print(mNumInterestingWindows);
1409 pw.print(" mNumDrawnWindows="); pw.print(mNumDrawnWindows);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001410 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -07001411 pw.print(" allDrawn="); pw.print(allDrawn);
1412 pw.print(" (animator="); pw.print(mAppAnimator.allDrawn);
1413 pw.println(")");
1414 }
1415 if (inPendingTransaction) {
1416 pw.print(prefix); pw.print("inPendingTransaction=");
1417 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001418 }
Craig Mautner799bc1d2015-01-14 10:33:48 -08001419 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001420 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
1421 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -08001422 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -08001423 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001424 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001425 if (startingWindow != null || startingSurface != null
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001426 || startingDisplayed || startingMoved) {
1427 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001428 pw.print(" startingSurface="); pw.print(startingSurface);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001429 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001430 pw.print(" startingMoved="); pw.println(startingMoved);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001431 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01001432 if (!mFrozenBounds.isEmpty()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -08001433 pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds);
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001434 pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig);
Chong Zhangd78ddb42016-03-02 17:01:14 -08001435 }
1436 if (mPendingRelaunchCount != 0) {
1437 pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount);
Jorim Jaggi0429f352015-12-22 16:29:16 +01001438 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001439 }
1440
1441 @Override
1442 public String toString() {
1443 if (stringName == null) {
1444 StringBuilder sb = new StringBuilder();
1445 sb.append("AppWindowToken{");
1446 sb.append(Integer.toHexString(System.identityHashCode(this)));
1447 sb.append(" token="); sb.append(token); sb.append('}');
1448 stringName = sb.toString();
1449 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001450 return stringName + ((mIsExiting) ? " mIsExiting=" : "");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001451 }
Jeff Browne9bdb312012-04-05 15:30:10 -07001452}