blob: 079dc8f2b0ada720119bb626cb639eaefb20cc55 [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();
Jorim Jaggi8b702ed2017-01-20 16:59:03 +0100378 mService.mTaskSnapshotController.notifyAppVisibilityChanged(this, visible);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700379 }
380 }
381
382 return delayed;
383 }
384
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800385 WindowState findMainWindow() {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700386 WindowState candidate = null;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700387 int j = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800388 while (j > 0) {
389 j--;
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700390 final WindowState win = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700391 final int type = win.mAttrs.type;
392 // No need to loop through child window as base application and starting types can't be
393 // child windows.
394 if (type == TYPE_BASE_APPLICATION || type == TYPE_APPLICATION_STARTING) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700395 // In cases where there are multiple windows, we prefer the non-exiting window. This
Sungsoo Lim0d3d1f82015-12-02 14:47:59 +0900396 // happens for example when replacing windows during an activity relaunch. When
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700397 // constructing the animation, we want the new window, not the exiting one.
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800398 if (win.mAnimatingExit) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700399 candidate = win;
400 } else {
401 return win;
402 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800403 }
404 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700405 return candidate;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800406 }
407
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800408 boolean windowsAreFocusable() {
409 return StackId.canReceiveKeys(mTask.mStack.mStackId) || mAlwaysFocusable;
Wale Ogunwaled045c822015-12-02 09:14:28 -0800410 }
411
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800412 AppWindowContainerController getController() {
413 final WindowContainerController controller = super.getController();
414 return controller != null ? (AppWindowContainerController) controller : null;
415 }
416
Wale Ogunwale571771c2016-08-26 13:18:50 -0700417 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -0700418 boolean isVisible() {
Wale Ogunwalee471be62016-10-03 07:53:55 -0700419 // If the app token isn't hidden then it is considered visible and there is no need to check
420 // its children windows to see if they are visible.
421 return !hidden;
Wale Ogunwale44f21802016-09-02 12:49:48 -0700422 }
423
424 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -0700425 void removeIfPossible() {
Craig Mautnere3119b72015-01-20 15:02:36 -0800426 mIsExiting = false;
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800427 removeAllWindowsIfPossible();
Wale Ogunwale571771c2016-08-26 13:18:50 -0700428 if (mTask != null) {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700429 mTask.mStack.mExitingAppTokens.remove(this);
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800430 removeImmediately();
Craig Mautnere3119b72015-01-20 15:02:36 -0800431 }
432 }
433
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700434 @Override
435 boolean checkCompleteDeferredRemoval() {
436 if (mIsExiting) {
437 removeIfPossible();
438 }
439 return super.checkCompleteDeferredRemoval();
440 }
441
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700442 void onRemovedFromDisplay() {
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700443 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app token: " + this);
444
Wale Ogunwale72919d22016-12-08 18:58:50 -0800445 boolean delayed = setVisibility(null, false, TRANSIT_UNSET, true, mVoiceInteraction);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700446
447 mService.mOpeningApps.remove(this);
Jorim Jaggi1b4b23e2016-11-15 16:30:12 -0800448 mService.mUnknownAppVisibilityController.appRemoved(this);
Jorim Jaggi10abe2f2017-01-03 16:44:46 +0100449 mService.mTaskSnapshotController.onAppRemoved(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
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800464 if (startingData != null && getController() != null) {
465 getController().removeStartingWindow();
466 }
467
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700468 final TaskStack stack = mTask.mStack;
469 if (delayed && !isEmpty()) {
470 // set the token aside because it has an active animation to be finished
471 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM,
472 "removeAppToken make exiting: " + this);
473 stack.mExitingAppTokens.add(this);
474 mIsExiting = true;
475 } else {
476 // Make sure there is no animation running on this token, so any windows associated
477 // with it will be removed as soon as their animations are complete
478 mAppAnimator.clearAnimation();
479 mAppAnimator.animating = false;
480 removeIfPossible();
481 }
482
483 removed = true;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700484 stopFreezingScreen(true, true);
485 if (mService.mFocusedApp == this) {
486 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "Removing focused app token:" + this);
487 mService.mFocusedApp = null;
488 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
489 mService.mInputMonitor.setFocusedAppLw(null);
490 }
491
492 if (!delayed) {
493 updateReportedVisibilityLocked();
494 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700495 }
496
Chong Zhange05bcb12016-07-26 17:47:29 -0700497 void clearAnimatingFlags() {
Chong Zhangb0d26702016-08-12 16:03:29 -0700498 boolean wallpaperMightChange = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700499 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700500 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700501 wallpaperMightChange |= win.clearAnimatingFlags();
Chong Zhange05bcb12016-07-26 17:47:29 -0700502 }
Chong Zhangb0d26702016-08-12 16:03:29 -0700503 if (wallpaperMightChange) {
504 requestUpdateWallpaperIfNeeded();
505 }
Chong Zhange05bcb12016-07-26 17:47:29 -0700506 }
507
Robert Carre12aece2016-02-02 22:43:27 -0800508 void destroySurfaces() {
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700509 destroySurfaces(false /*cleanupOnResume*/);
510 }
511
512 /**
513 * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure
514 * the client has finished with them.
515 *
516 * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If
517 * set to true, destroy only surfaces of removed windows, and clear relevant flags of the
518 * others so that they are ready to be reused. If set to false (common case), destroy all
519 * surfaces that's eligible, if the app is already stopped.
520 */
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700521 private void destroySurfaces(boolean cleanupOnResume) {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700522 boolean destroyedSomething = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700523 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700524 final WindowState win = mChildren.get(i);
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700525 destroyedSomething |= win.destroySurface(cleanupOnResume, mAppStopped);
Robert Carre12aece2016-02-02 22:43:27 -0800526 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700527 if (destroyedSomething) {
528 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700529 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Robert Carre12aece2016-02-02 22:43:27 -0800530 }
531 }
532
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800533 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700534 * Notify that the app is now resumed, and it was not stopped before, perform a clean
535 * up of the surfaces
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800536 */
Chong Zhangad24f962016-08-25 12:12:33 -0700537 void notifyAppResumed(boolean wasStopped, boolean allowSavedSurface) {
538 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped
539 + " allowSavedSurface=" + allowSavedSurface + " " + this);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700540 mAppStopped = false;
541 if (!wasStopped) {
542 destroySurfaces(true /*cleanupOnResume*/);
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800543 }
Chong Zhangad24f962016-08-25 12:12:33 -0700544 if (!allowSavedSurface) {
545 destroySavedSurfaces();
546 }
Robert Carre12aece2016-02-02 22:43:27 -0800547 }
548
Chong Zhangbef461f2015-10-27 11:38:24 -0700549 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700550 * Notify that the app has stopped, and it is okay to destroy any surfaces which were
551 * keeping alive in case they were still being used.
552 */
553 void notifyAppStopped() {
554 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this);
555 mAppStopped = true;
556 destroySurfaces();
557 // Remove any starting window that was added for this app if they are still around.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800558 if (getController() != null) {
559 getController().removeStartingWindow();
560 }
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700561 }
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);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800670 if (getController() != null) {
671 getController().removeStartingWindow();
672 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700673 } else if (mChildren.size() == 0 && startingData != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700674 // If this is the last window and we had requested a starting transition window,
675 // well there is no point now.
Jorim Jaggi02886a82016-12-06 09:10:06 -0800676 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingData");
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700677 startingData = null;
Jorim Jaggi829b9cd2017-01-23 16:20:53 +0100678 } else if (mChildren.size() == 1 && startingSurface != null && !isRelaunching()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700679 // If this is the last window except for a starting transition window,
680 // we need to get rid of the starting transition.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800681 if (getController() != null) {
682 getController().removeStartingWindow();
683 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700684 }
685 }
686
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700687 void removeDeadWindows() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700688 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700689 WindowState win = mChildren.get(winNdx);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800690 if (win.mAppDied) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700691 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700692 "removeDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800693 // Set mDestroying, we don't want any animation or delayed removal here.
694 win.mDestroying = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700695 // Also removes child windows.
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700696 win.removeIfPossible();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800697 }
698 }
699 }
700
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700701 boolean hasWindowsAlive() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700702 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700703 // No need to loop through child windows as the answer should be the same as that of the
704 // parent window.
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700705 if (!(mChildren.get(i)).mAppDied) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700706 return true;
707 }
708 }
709 return false;
710 }
711
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700712 void setWillReplaceWindows(boolean animate) {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700713 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
714 "Marking app token " + this + " with replacing windows.");
Robert Carra1eb4392015-12-10 12:43:51 -0800715
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700716 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700717 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700718 w.setWillReplaceWindow(animate);
Robert Carra1eb4392015-12-10 12:43:51 -0800719 }
720 if (animate) {
721 // Set-up dummy animation so we can start treating windows associated with this
722 // token like they are in transition before the new app window is ready for us to
723 // run the real transition animation.
724 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700725 "setWillReplaceWindow() Setting dummy animation on: " + this);
Robert Carra1eb4392015-12-10 12:43:51 -0800726 mAppAnimator.setDummyAnimation();
727 }
728 }
729
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700730 void setWillReplaceChildWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700731 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this
Robert Carr23fa16b2016-01-13 13:19:58 -0800732 + " with replacing child windows.");
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700733 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700734 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700735 w.setWillReplaceChildWindows();
Robert Carr23fa16b2016-01-13 13:19:58 -0800736 }
737 }
738
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700739 void clearWillReplaceWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700740 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
741 "Resetting app token " + this + " of replacing window marks.");
Chong Zhangf596cd52016-01-05 13:42:44 -0800742
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700743 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700744 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700745 w.clearWillReplaceWindow();
Chong Zhangf596cd52016-01-05 13:42:44 -0800746 }
747 }
748
Chong Zhang4d7369a2016-04-25 16:09:14 -0700749 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700750 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700751 final WindowState w = mChildren.get(i);
Chong Zhang4d7369a2016-04-25 16:09:14 -0700752 w.requestUpdateWallpaperIfNeeded();
753 }
754 }
755
Chong Zhangd78ddb42016-03-02 17:01:14 -0800756 boolean isRelaunching() {
757 return mPendingRelaunchCount > 0;
758 }
759
760 void startRelaunching() {
761 if (canFreezeBounds()) {
762 freezeBounds();
763 }
764 mPendingRelaunchCount++;
765 }
766
767 void finishRelaunching() {
768 if (canFreezeBounds()) {
769 unfreezeBounds();
770 }
771 if (mPendingRelaunchCount > 0) {
772 mPendingRelaunchCount--;
773 }
774 }
775
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700776 void clearRelaunching() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700777 if (mPendingRelaunchCount == 0) {
778 return;
779 }
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700780 if (canFreezeBounds()) {
781 unfreezeBounds();
782 }
783 mPendingRelaunchCount = 0;
784 }
785
Wale Ogunwale07bcab72016-10-14 15:30:09 -0700786 /**
787 * Returns true if the new child window we are adding to this token is considered greater than
788 * the existing child window in this token in terms of z-order.
789 */
790 @Override
791 protected boolean isFirstChildWindowGreaterThanSecond(WindowState newWindow,
792 WindowState existingWindow) {
793 final int type1 = newWindow.mAttrs.type;
794 final int type2 = existingWindow.mAttrs.type;
795
796 // Base application windows should be z-ordered BELOW all other windows in the app token.
797 if (type1 == TYPE_BASE_APPLICATION && type2 != TYPE_BASE_APPLICATION) {
798 return false;
799 } else if (type1 != TYPE_BASE_APPLICATION && type2 == TYPE_BASE_APPLICATION) {
800 return true;
801 }
802
803 // Starting windows should be z-ordered ABOVE all other windows in the app token.
804 if (type1 == TYPE_APPLICATION_STARTING && type2 != TYPE_APPLICATION_STARTING) {
805 return true;
806 } else if (type1 != TYPE_APPLICATION_STARTING && type2 == TYPE_APPLICATION_STARTING) {
807 return false;
808 }
809
810 // Otherwise the new window is greater than the existing window.
811 return true;
812 }
813
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700814 @Override
Robert Carra1eb4392015-12-10 12:43:51 -0800815 void addWindow(WindowState w) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700816 super.addWindow(w);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700817
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700818 boolean gotReplacementWindow = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700819 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700820 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700821 gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w);
822 }
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700823
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700824 // if we got a replacement window, reset the timeout to give drawing more time
825 if (gotReplacementWindow) {
826 mService.scheduleWindowReplacementTimeouts(this);
Robert Carra1eb4392015-12-10 12:43:51 -0800827 }
Jorim Jaggife762342016-10-13 14:33:27 +0200828 checkKeyguardFlagsChanged();
829 }
830
831 @Override
832 void removeChild(WindowState child) {
833 super.removeChild(child);
834 checkKeyguardFlagsChanged();
Robert Carra1eb4392015-12-10 12:43:51 -0800835 }
836
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700837 private boolean waitingForReplacement() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700838 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700839 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700840 if (candidate.waitingForReplacement()) {
Robert Carra1eb4392015-12-10 12:43:51 -0800841 return true;
842 }
843 }
844 return false;
845 }
846
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700847 void onWindowReplacementTimeout() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700848 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700849 (mChildren.get(i)).onWindowReplacementTimeout();
Robert Carra1eb4392015-12-10 12:43:51 -0800850 }
851 }
852
Chong Zhangd78ddb42016-03-02 17:01:14 -0800853 private boolean canFreezeBounds() {
854 // For freeform windows, we can't freeze the bounds at the moment because this would make
855 // the resizing unresponsive.
856 return mTask != null && !mTask.inFreeformWorkspace();
857 }
858
Jorim Jaggi0429f352015-12-22 16:29:16 +0100859 /**
860 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
861 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
862 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
863 * with a queue.
864 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800865 private void freezeBounds() {
Jorim Jaggi0429f352015-12-22 16:29:16 +0100866 mFrozenBounds.offer(new Rect(mTask.mPreparedFrozenBounds));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700867
868 if (mTask.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) {
869 // We didn't call prepareFreezingBounds on the task, so use the current value.
Andrii Kulian441e4492016-09-29 15:25:00 -0700870 mFrozenMergedConfig.offer(new Configuration(mTask.getConfiguration()));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700871 } else {
872 mFrozenMergedConfig.offer(new Configuration(mTask.mPreparedFrozenMergedConfig));
873 }
Andrii Kulianb10330d2016-09-16 13:51:46 -0700874 // Calling unset() to make it equal to Configuration.EMPTY.
875 mTask.mPreparedFrozenMergedConfig.unset();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100876 }
877
878 /**
879 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
880 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800881 private void unfreezeBounds() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700882 if (!mFrozenBounds.isEmpty()) {
883 mFrozenBounds.remove();
884 }
885 if (!mFrozenMergedConfig.isEmpty()) {
886 mFrozenMergedConfig.remove();
887 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700888 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700889 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700890 win.onUnfreezeBounds();
Jorim Jaggi4846ee32016-01-07 17:39:12 +0100891 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700892 mService.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100893 }
894
Robert Carr91b228092016-06-28 17:32:37 -0700895 void addSurfaceViewBackground(WindowSurfaceController.SurfaceControlWithBackground background) {
896 mSurfaceViewBackgrounds.add(background);
897 }
898
899 void removeSurfaceViewBackground(WindowSurfaceController.SurfaceControlWithBackground background) {
900 mSurfaceViewBackgrounds.remove(background);
901 updateSurfaceViewBackgroundVisibilities();
902 }
903
904 // We use DimLayers behind SurfaceViews to prevent holes while resizing and creating.
905 // However, we need to ensure one SurfaceView doesn't cover another when they are both placed
906 // below the main app window (as traditionally a SurfaceView which is never drawn
907 // to is totally translucent). So we look at all our SurfaceView backgrounds and only enable
908 // the background for the SurfaceView with lowest Z order
909 void updateSurfaceViewBackgroundVisibilities() {
910 WindowSurfaceController.SurfaceControlWithBackground bottom = null;
911 int bottomLayer = Integer.MAX_VALUE;
912 for (int i = 0; i < mSurfaceViewBackgrounds.size(); i++) {
913 WindowSurfaceController.SurfaceControlWithBackground sc = mSurfaceViewBackgrounds.get(i);
914 if (sc.mVisible && sc.mLayer < bottomLayer) {
915 bottomLayer = sc.mLayer;
916 bottom = sc;
917 }
918 }
919 for (int i = 0; i < mSurfaceViewBackgrounds.size(); i++) {
920 WindowSurfaceController.SurfaceControlWithBackground sc = mSurfaceViewBackgrounds.get(i);
921 sc.updateBackgroundVisibility(sc != bottom);
922 }
923 }
924
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700925 void resetJustMovedInStack() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700926 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700927 (mChildren.get(i)).resetJustMovedInStack();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700928 }
929 }
930
931 void notifyMovedInStack() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700932 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700933 final WindowState win = mChildren.get(winNdx);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700934 win.notifyMovedInStack();
935 }
936 }
937
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700938 void setAppLayoutChanges(int changes, String reason) {
939 if (!mChildren.isEmpty()) {
940 final DisplayContent dc = getDisplayContent();
941 dc.pendingLayoutChanges |= changes;
942 if (DEBUG_LAYOUT_REPEATS) {
943 mService.mWindowPlacerLocked.debugLayoutRepeats(reason, dc.pendingLayoutChanges);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700944 }
945 }
946 }
947
948 void removeReplacedWindowIfNeeded(WindowState replacement) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700949 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700950 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700951 if (win.removeReplacedWindowIfNeeded(replacement)) {
952 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700953 }
954 }
955 }
956
957 void startFreezingScreen() {
958 if (DEBUG_ORIENTATION) logWithStack(TAG, "Set freezing of " + appToken + ": hidden="
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700959 + hidden + " freezing=" + mAppAnimator.freezingScreen + " hiddenRequested="
960 + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700961 if (!hiddenRequested) {
962 if (!mAppAnimator.freezingScreen) {
963 mAppAnimator.freezingScreen = true;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700964 mService.registerAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700965 mAppAnimator.lastFreezeDuration = 0;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700966 mService.mAppsFreezingScreen++;
967 if (mService.mAppsFreezingScreen == 1) {
968 mService.startFreezingDisplayLocked(false, 0, 0);
969 mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT);
970 mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700971 }
972 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700973 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700974 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700975 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700976 w.onStartFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700977 }
978 }
979 }
980
981 void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) {
982 if (!mAppAnimator.freezingScreen) {
983 return;
984 }
985 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + this + " force=" + force);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700986 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700987 boolean unfrozeWindows = false;
988 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700989 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700990 unfrozeWindows |= w.onStopFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700991 }
992 if (force || unfrozeWindows) {
993 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this);
994 mAppAnimator.freezingScreen = false;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700995 mService.unregisterAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700996 mAppAnimator.lastFreezeDuration =
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700997 (int)(SystemClock.elapsedRealtime() - mService.mDisplayFreezeTime);
998 mService.mAppsFreezingScreen--;
999 mService.mLastFinishedFreezeSource = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001000 }
1001 if (unfreezeSurfaceNow) {
1002 if (unfrozeWindows) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001003 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001004 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001005 mService.stopFreezingDisplayLocked();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001006 }
1007 }
1008
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001009 @Override
1010 public void onAppFreezeTimeout() {
1011 Slog.w(TAG_WM, "Force clearing freeze: " + this);
1012 stopFreezingScreen(true, true);
1013 }
1014
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001015 boolean transferStartingWindow(IBinder transferFrom) {
Wale Ogunwale02319a62016-09-26 15:21:22 -07001016 final AppWindowToken fromToken = getDisplayContent().getAppWindowToken(transferFrom);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001017 if (fromToken == null) {
1018 return false;
1019 }
1020
1021 final WindowState tStartingWindow = fromToken.startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001022 if (tStartingWindow != null && fromToken.startingSurface != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001023 // In this case, the starting icon has already been displayed, so start
1024 // letting windows get shown immediately without any more transitions.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001025 mService.mSkipAppTransitionAnimation = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001026
1027 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow
1028 + " from " + fromToken + " to " + this);
1029
1030 final long origId = Binder.clearCallingIdentity();
1031
1032 // Transfer the starting window over to the new token.
1033 startingData = fromToken.startingData;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001034 startingSurface = fromToken.startingSurface;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001035 startingDisplayed = fromToken.startingDisplayed;
1036 fromToken.startingDisplayed = false;
1037 startingWindow = tStartingWindow;
1038 reportedVisible = fromToken.reportedVisible;
1039 fromToken.startingData = null;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001040 fromToken.startingSurface = null;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001041 fromToken.startingWindow = null;
1042 fromToken.startingMoved = true;
1043 tStartingWindow.mToken = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001044 tStartingWindow.mAppToken = this;
1045
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001046 if (DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001047 "Removing starting " + tStartingWindow + " from " + fromToken);
Wale Ogunwalefa854eb2016-09-20 13:43:52 -07001048 fromToken.removeChild(tStartingWindow);
1049 fromToken.postWindowRemoveStartingWindowCleanup(tStartingWindow);
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001050 addWindow(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001051
1052 // Propagate other interesting state between the tokens. If the old token is displayed,
1053 // we should immediately force the new one to be displayed. If it is animating, we need
1054 // to move that animation to the new one.
1055 if (fromToken.allDrawn) {
1056 allDrawn = true;
1057 deferClearAllDrawn = fromToken.deferClearAllDrawn;
1058 }
1059 if (fromToken.firstWindowDrawn) {
1060 firstWindowDrawn = true;
1061 }
1062 if (!fromToken.hidden) {
1063 hidden = false;
1064 hiddenRequested = false;
1065 }
1066 if (clientHidden != fromToken.clientHidden) {
1067 clientHidden = fromToken.clientHidden;
1068 sendAppVisibilityToClients();
1069 }
1070 fromToken.mAppAnimator.transferCurrentAnimation(
1071 mAppAnimator, tStartingWindow.mWinAnimator);
1072
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001073 mService.updateFocusedWindowLocked(
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001074 UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/);
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001075 getDisplayContent().setLayoutNeeded();
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001076 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001077 Binder.restoreCallingIdentity(origId);
1078 return true;
1079 } else if (fromToken.startingData != null) {
1080 // The previous app was getting ready to show a
1081 // starting window, but hasn't yet done so. Steal it!
1082 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1083 "Moving pending starting from " + fromToken + " to " + this);
1084 startingData = fromToken.startingData;
1085 fromToken.startingData = null;
1086 fromToken.startingMoved = true;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001087 if (getController() != null) {
1088 getController().scheduleAddStartingWindow();
1089 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001090 return true;
1091 }
1092
1093 final AppWindowAnimator tAppAnimator = fromToken.mAppAnimator;
1094 final AppWindowAnimator wAppAnimator = mAppAnimator;
1095 if (tAppAnimator.thumbnail != null) {
1096 // The old token is animating with a thumbnail, transfer that to the new token.
1097 if (wAppAnimator.thumbnail != null) {
1098 wAppAnimator.thumbnail.destroy();
1099 }
1100 wAppAnimator.thumbnail = tAppAnimator.thumbnail;
1101 wAppAnimator.thumbnailLayer = tAppAnimator.thumbnailLayer;
1102 wAppAnimator.thumbnailAnimation = tAppAnimator.thumbnailAnimation;
1103 tAppAnimator.thumbnail = null;
1104 }
1105 return false;
1106 }
1107
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001108 boolean isLastWindow(WindowState win) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001109 return mChildren.size() == 1 && mChildren.get(0) == win;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001110 }
1111
1112 void setAllAppWinAnimators() {
1113 final ArrayList<WindowStateAnimator> allAppWinAnimators = mAppAnimator.mAllAppWinAnimators;
1114 allAppWinAnimators.clear();
1115
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001116 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001117 for (int j = 0; j < windowsCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001118 (mChildren.get(j)).addWinAnimatorToList(allAppWinAnimators);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001119 }
1120 }
1121
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001122 @Override
1123 void onAppTransitionDone() {
1124 sendingToBottom = false;
1125 }
1126
Wale Ogunwale51362492016-09-08 17:49:17 -07001127 /**
1128 * We override because this class doesn't want its children affecting its reported orientation
1129 * in anyway.
1130 */
1131 @Override
1132 int getOrientation() {
1133 if (hidden || hiddenRequested) {
1134 return SCREEN_ORIENTATION_UNSET;
1135 }
1136 return mOrientation;
1137 }
1138
Wale Ogunwaleb198b742016-12-01 08:44:09 -08001139 /** Returns the app's preferred orientation regardless of its currently visibility state. */
1140 int getOrientationIgnoreVisibility() {
1141 return mOrientation;
1142 }
1143
Craig Mautnerdbb79912012-03-01 18:59:14 -08001144 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001145 void checkAppWindowsReadyToShow() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001146 if (allDrawn == mAppAnimator.allDrawn) {
1147 return;
1148 }
1149
1150 mAppAnimator.allDrawn = allDrawn;
1151 if (!allDrawn) {
1152 return;
1153 }
1154
1155 // The token has now changed state to having all windows shown... what to do, what to do?
1156 if (mAppAnimator.freezingScreen) {
1157 mAppAnimator.showAllWindowsLocked();
1158 stopFreezingScreen(false, true);
1159 if (DEBUG_ORIENTATION) Slog.i(TAG,
1160 "Setting mOrientationChangeComplete=true because wtoken " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001161 + " numInteresting=" + mNumInterestingWindows + " numDrawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001162 // This will set mOrientationChangeComplete and cause a pass through layout.
1163 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001164 "checkAppWindowsReadyToShow: freezingScreen");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001165 } else {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001166 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001167
1168 // We can now show all of the drawn windows!
1169 if (!mService.mOpeningApps.contains(this)) {
1170 mService.mAnimator.orAnimating(mAppAnimator.showAllWindowsLocked());
1171 }
1172 }
1173 }
1174
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001175 void updateAllDrawn(DisplayContent dc) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001176 if (!allDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001177 final int numInteresting = mNumInterestingWindows;
1178 if (numInteresting > 0 && mNumDrawnWindows >= numInteresting) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001179 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawn: " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001180 + " interesting=" + numInteresting + " drawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001181 allDrawn = true;
1182 // Force an additional layout pass where
1183 // WindowStateAnimator#commitFinishDrawingLocked() will call performShowLocked().
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001184 dc.setLayoutNeeded();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001185 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
1186 }
1187 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001188
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001189 if (!allDrawnExcludingSaved) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001190 int numInteresting = mNumInterestingWindowsExcludingSaved;
1191 if (numInteresting > 0 && mNumDrawnWindowsExcludingSaved >= numInteresting) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001192 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawnExcludingSaved: " + this
1193 + " interesting=" + numInteresting
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001194 + " drawn=" + mNumDrawnWindowsExcludingSaved);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001195 allDrawnExcludingSaved = true;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001196 dc.setLayoutNeeded();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001197 if (isAnimatingInvisibleWithSavedSurface()
1198 && !mService.mFinishedEarlyAnim.contains(this)) {
1199 mService.mFinishedEarlyAnim.add(this);
1200 }
1201 }
1202 }
1203 }
1204
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001205 /**
1206 * Updated this app token tracking states for interesting and drawn windows based on the window.
1207 *
1208 * @return Returns true if the input window is considered interesting and drawn while all the
1209 * windows in this app token where not considered drawn as of the last pass.
1210 */
1211 boolean updateDrawnWindowStates(WindowState w) {
1212 if (DEBUG_STARTING_WINDOW && w == startingWindow) {
1213 Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" + w.isOnScreen()
1214 + " allDrawn=" + allDrawn + " freezingScreen=" + mAppAnimator.freezingScreen);
1215 }
1216
1217 if (allDrawn && allDrawnExcludingSaved && !mAppAnimator.freezingScreen) {
1218 return false;
1219 }
1220
1221 if (mLastTransactionSequence != mService.mTransactionSequence) {
1222 mLastTransactionSequence = mService.mTransactionSequence;
1223 mNumInterestingWindows = mNumDrawnWindows = 0;
1224 mNumInterestingWindowsExcludingSaved = 0;
1225 mNumDrawnWindowsExcludingSaved = 0;
1226 startingDisplayed = false;
1227 }
1228
1229 final WindowStateAnimator winAnimator = w.mWinAnimator;
1230
1231 boolean isInterestingAndDrawn = false;
1232
1233 if (!allDrawn && w.mightAffectAllDrawn(false /* visibleOnly */)) {
1234 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
1235 Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw()
1236 + ", isAnimationSet=" + winAnimator.isAnimationSet());
1237 if (!w.isDrawnLw()) {
1238 Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController
1239 + " pv=" + w.mPolicyVisibility
1240 + " mDrawState=" + winAnimator.drawStateToString()
1241 + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested
1242 + " a=" + winAnimator.mAnimating);
1243 }
1244 }
1245
1246 if (w != startingWindow) {
1247 if (w.isInteresting()) {
1248 mNumInterestingWindows++;
1249 if (w.isDrawnLw()) {
1250 mNumDrawnWindows++;
1251
1252 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, "tokenMayBeDrawn: "
1253 + this + " w=" + w + " numInteresting=" + mNumInterestingWindows
1254 + " freezingScreen=" + mAppAnimator.freezingScreen
1255 + " mAppFreezing=" + w.mAppFreezing);
1256
1257 isInterestingAndDrawn = true;
1258 }
1259 }
1260 } else if (w.isDrawnLw()) {
1261 mService.mH.sendEmptyMessage(NOTIFY_STARTING_WINDOW_DRAWN);
1262 startingDisplayed = true;
1263 }
1264 }
1265
1266 if (!allDrawnExcludingSaved && w.mightAffectAllDrawn(true /* visibleOnly */)) {
1267 if (w != startingWindow && w.isInteresting()) {
1268 mNumInterestingWindowsExcludingSaved++;
1269 if (w.isDrawnLw() && !w.isAnimatingWithSavedSurface()) {
1270 mNumDrawnWindowsExcludingSaved++;
1271
1272 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
1273 "tokenMayBeDrawnExcludingSaved: " + this + " w=" + w
1274 + " numInteresting=" + mNumInterestingWindowsExcludingSaved
1275 + " freezingScreen=" + mAppAnimator.freezingScreen
1276 + " mAppFreezing=" + w.mAppFreezing);
1277
1278 isInterestingAndDrawn = true;
1279 }
1280 }
1281 }
1282
1283 return isInterestingAndDrawn;
1284 }
1285
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001286 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001287 void stepAppWindowsAnimation(long currentTime) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001288 mAppAnimator.wasAnimating = mAppAnimator.animating;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001289 if (mAppAnimator.stepAnimationLocked(currentTime)) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001290 mAppAnimator.animating = true;
1291 mService.mAnimator.setAnimating(true);
1292 mService.mAnimator.mAppWindowAnimating = true;
1293 } else if (mAppAnimator.wasAnimating) {
1294 // stopped animating, do one more pass through the layout
Wale Ogunwale1e129a42016-11-21 13:03:47 -08001295 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
1296 DEBUG_LAYOUT_REPEATS ? "appToken " + this + " done" : null);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001297 if (DEBUG_ANIM) Slog.v(TAG, "updateWindowsApps...: done animating " + this);
1298 }
1299 }
1300
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001301 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001302 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001303 // For legacy reasons we process the TaskStack.mExitingAppTokens first in DisplayContent
1304 // before the non-exiting app tokens. So, we skip the exiting app tokens here.
1305 // TODO: Investigate if we need to continue to do this or if we can just process them
1306 // in-order.
1307 if (mIsExiting && !waitingForReplacement()) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001308 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001309 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001310 return forAllWindowsUnchecked(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001311 }
1312
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001313 boolean forAllWindowsUnchecked(ToBooleanFunction<WindowState> callback,
1314 boolean traverseTopToBottom) {
1315 return super.forAllWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001316 }
1317
1318 @Override
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001319 AppWindowToken asAppWindowToken() {
1320 // I am an app window token!
1321 return this;
1322 }
1323
1324 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -07001325 boolean fillsParent() {
1326 return mFillsParent;
1327 }
1328
1329 void setFillsParent(boolean fillsParent) {
1330 mFillsParent = fillsParent;
1331 }
1332
Jorim Jaggife762342016-10-13 14:33:27 +02001333 boolean containsDismissKeyguardWindow() {
1334 for (int i = mChildren.size() - 1; i >= 0; i--) {
1335 if ((mChildren.get(i).mAttrs.flags & FLAG_DISMISS_KEYGUARD) != 0) {
1336 return true;
1337 }
1338 }
1339 return false;
1340 }
1341
1342 boolean containsShowWhenLockedWindow() {
1343 for (int i = mChildren.size() - 1; i >= 0; i--) {
1344 if ((mChildren.get(i).mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
1345 return true;
1346 }
1347 }
1348 return false;
1349 }
1350
1351 void checkKeyguardFlagsChanged() {
1352 final boolean containsDismissKeyguard = containsDismissKeyguardWindow();
1353 final boolean containsShowWhenLocked = containsShowWhenLockedWindow();
1354 if (containsDismissKeyguard != mLastContainsDismissKeyguardWindow
1355 || containsShowWhenLocked != mLastContainsShowWhenLockedWindow) {
1356 mService.notifyKeyguardFlagsChanged(null /* callback */);
1357 }
1358 mLastContainsDismissKeyguardWindow = containsDismissKeyguard;
1359 mLastContainsShowWhenLockedWindow = containsShowWhenLocked;
1360 }
1361
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001362 WindowState getImeTargetBelowWindow(WindowState w) {
1363 final int index = mChildren.indexOf(w);
1364 if (index > 0) {
1365 final WindowState target = mChildren.get(index - 1);
1366 if (target.canBeImeTarget()) {
1367 return target;
1368 }
1369 }
1370 return null;
1371 }
1372
1373 WindowState getHighestAnimLayerWindow(WindowState currentTarget) {
1374 WindowState candidate = null;
1375 for (int i = mChildren.indexOf(currentTarget); i >= 0; i--) {
1376 final WindowState w = mChildren.get(i);
1377 if (w.mRemoved) {
1378 continue;
1379 }
1380 if (candidate == null || w.mWinAnimator.mAnimLayer >
1381 candidate.mWinAnimator.mAnimLayer) {
1382 candidate = w;
1383 }
1384 }
1385 return candidate;
1386 }
1387
Wale Ogunwale51362492016-09-08 17:49:17 -07001388 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001389 void dump(PrintWriter pw, String prefix) {
1390 super.dump(pw, prefix);
1391 if (appToken != null) {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001392 pw.println(prefix + "app=true mVoiceInteraction=" + mVoiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001393 }
Craig Mautner83162a92015-01-26 14:43:30 -08001394 pw.print(prefix); pw.print("task="); pw.println(mTask);
Wale Ogunwale51362492016-09-08 17:49:17 -07001395 pw.print(prefix); pw.print(" mFillsParent="); pw.print(mFillsParent);
1396 pw.print(" mOrientation="); pw.println(mOrientation);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001397 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
1398 pw.print(" clientHidden="); pw.print(clientHidden);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -07001399 pw.print(" reportedDrawn="); pw.print(reportedDrawn);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001400 pw.print(" reportedVisible="); pw.println(reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -07001401 if (paused) {
1402 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001403 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001404 if (mAppStopped) {
1405 pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped);
1406 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001407 if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0
Craig Mautner6fbda632012-07-03 09:26:39 -07001408 || allDrawn || mAppAnimator.allDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001409 pw.print(prefix); pw.print("mNumInterestingWindows=");
1410 pw.print(mNumInterestingWindows);
1411 pw.print(" mNumDrawnWindows="); pw.print(mNumDrawnWindows);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001412 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -07001413 pw.print(" allDrawn="); pw.print(allDrawn);
1414 pw.print(" (animator="); pw.print(mAppAnimator.allDrawn);
1415 pw.println(")");
1416 }
1417 if (inPendingTransaction) {
1418 pw.print(prefix); pw.print("inPendingTransaction=");
1419 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001420 }
Craig Mautner799bc1d2015-01-14 10:33:48 -08001421 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001422 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
1423 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -08001424 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -08001425 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001426 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001427 if (startingWindow != null || startingSurface != null
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001428 || startingDisplayed || startingMoved) {
1429 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001430 pw.print(" startingSurface="); pw.print(startingSurface);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001431 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001432 pw.print(" startingMoved="); pw.println(startingMoved);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001433 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01001434 if (!mFrozenBounds.isEmpty()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -08001435 pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds);
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001436 pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig);
Chong Zhangd78ddb42016-03-02 17:01:14 -08001437 }
1438 if (mPendingRelaunchCount != 0) {
1439 pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount);
Jorim Jaggi0429f352015-12-22 16:29:16 +01001440 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001441 }
1442
1443 @Override
1444 public String toString() {
1445 if (stringName == null) {
1446 StringBuilder sb = new StringBuilder();
1447 sb.append("AppWindowToken{");
1448 sb.append(Integer.toHexString(System.identityHashCode(this)));
1449 sb.append(" token="); sb.append(token); sb.append('}');
1450 stringName = sb.toString();
1451 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001452 return stringName + ((mIsExiting) ? " mIsExiting=" : "");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001453 }
Jeff Browne9bdb312012-04-05 15:30:10 -07001454}