blob: 6147885a4a2e5d6d03853f777b593260a38368b9 [file] [log] [blame]
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server.wm;
18
Wale Ogunwale6cae7652015-12-26 07:36:26 -080019import static android.app.ActivityManager.StackId;
Wale Ogunwale72919d22016-12-08 18:58:50 -080020import static android.content.pm.ActivityInfo.CONFIG_ORIENTATION;
21import static android.content.pm.ActivityInfo.CONFIG_SCREEN_SIZE;
Wale Ogunwale51362492016-09-08 17:49:17 -070022import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070023import static android.view.Display.DEFAULT_DISPLAY;
Jorim Jaggife762342016-10-13 14:33:27 +020024import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
25import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
Wale Ogunwaled1c37912016-08-16 03:19:39 -070026import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080027import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070028import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -070029import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
30import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070031import static com.android.server.wm.AppTransition.TRANSIT_UNSET;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080032import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
33import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
Robert Carra1eb4392015-12-10 12:43:51 -080034import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070035import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070036import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
37import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
Wale Ogunwale9017ec02016-02-25 08:55:25 -080038import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070039import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TOKEN_MOVEMENT;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080040import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
41import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_MOVEMENT;
42import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
43import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Chong Zhang92147042016-05-09 12:47:11 -070044import static com.android.server.wm.WindowManagerService.H.NOTIFY_ACTIVITY_DRAWN;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -070045import static com.android.server.wm.WindowManagerService.H.NOTIFY_STARTING_WINDOW_DRAWN;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070046import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070047import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070048import static com.android.server.wm.WindowManagerService.logWithStack;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080049
Wale Ogunwale72919d22016-12-08 18:58:50 -080050import android.content.pm.ActivityInfo;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070051import android.os.Debug;
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -080052import com.android.internal.util.ToBooleanFunction;
Jeff Brown4532e612012-04-05 14:27:12 -070053import com.android.server.input.InputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080054import com.android.server.wm.WindowManagerService.H;
55
Filip Gruszczynskia590c992015-11-25 16:45:26 -080056import android.annotation.NonNull;
Jorim Jaggi26c8c422016-05-09 19:57:25 -070057import android.content.res.Configuration;
Jorim Jaggi0429f352015-12-22 16:29:16 +010058import android.graphics.Rect;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070059import android.os.Binder;
60import android.os.IBinder;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080061import android.os.Message;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070062import android.os.SystemClock;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080063import android.util.Slog;
64import android.view.IApplicationToken;
65import android.view.View;
66import android.view.WindowManager;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080067
68import java.io.PrintWriter;
Jorim Jaggi0429f352015-12-22 16:29:16 +010069import java.util.ArrayDeque;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080070import java.util.ArrayList;
71
72class AppTokenList extends ArrayList<AppWindowToken> {
73}
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080074
75/**
76 * Version of WindowToken that is specifically for a particular application (or
77 * really activity) that is displaying windows.
78 */
Wale Ogunwale3f4433d2016-08-18 20:42:42 -070079class AppWindowToken extends WindowToken implements WindowManagerService.AppFreezeListener {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080080 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppWindowToken" : TAG_WM;
81
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080082 // Non-null only for application tokens.
83 final IApplicationToken appToken;
84
Filip Gruszczynskia590c992015-11-25 16:45:26 -080085 @NonNull final AppWindowAnimator mAppAnimator;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -070086
Wale Ogunwale72919d22016-12-08 18:58:50 -080087 final boolean mVoiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -070088
Wale Ogunwalef6192862016-09-10 13:42:30 -070089 // TODO: Use getParent instead?
Craig Mautner83162a92015-01-26 14:43:30 -080090 Task mTask;
Wale Ogunwale51362492016-09-08 17:49:17 -070091 /** @see WindowContainer#fillsParent() */
92 private boolean mFillsParent;
Craig Mautner4c5eb222013-11-18 12:59:05 -080093 boolean layoutConfigChanges;
Wale Ogunwale72919d22016-12-08 18:58:50 -080094 boolean mShowForAllUsers;
95 int mTargetSdk;
Craig Mautnera2c77052012-03-26 12:14:43 -070096
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080097 // The input dispatching timeout for this application token in nanoseconds.
Wale Ogunwale72919d22016-12-08 18:58:50 -080098 long mInputDispatchingTimeoutNanos;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080099
100 // These are used for determining when all windows associated with
101 // an activity have been drawn, so they can be made visible together
102 // at the same time.
Craig Mautner764983d2012-03-22 11:37:36 -0700103 // initialize so that it doesn't match mTransactionSequence which is an int.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700104 private long mLastTransactionSequence = Long.MIN_VALUE;
105 private int mNumInterestingWindows;
106 private int mNumDrawnWindows;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800107 boolean inPendingTransaction;
108 boolean allDrawn;
Craig Mautner7636dfb2012-11-16 15:24:11 -0800109 // Set to true when this app creates a surface while in the middle of an animation. In that
110 // case do not clear allDrawn until the animation completes.
111 boolean deferClearAllDrawn;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800112
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700113 /**
114 * These are to track the app's real drawing status if there were no saved surfaces.
115 * @see #updateDrawnWindowStates
116 */
Chong Zhang8e4bda92016-05-04 15:08:18 -0700117 boolean allDrawnExcludingSaved;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700118 private int mNumInterestingWindowsExcludingSaved;
119 private int mNumDrawnWindowsExcludingSaved;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700120
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800121 // Is this window's surface needed? This is almost like hidden, except
122 // it will sometimes be true a little earlier: when the token has
123 // been shown, but is still waiting for its app transition to execute
124 // before making its windows shown.
125 boolean hiddenRequested;
126
127 // Have we told the window clients to hide themselves?
128 boolean clientHidden;
129
130 // Last visibility state we reported to the app token.
131 boolean reportedVisible;
132
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700133 // Last drawn state we reported to the app token.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700134 private boolean reportedDrawn;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700135
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800136 // Set to true when the token has been removed from the window mgr.
137 boolean removed;
138
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800139 // Information about an application starting window if displayed.
140 StartingData startingData;
141 WindowState startingWindow;
142 View startingView;
143 boolean startingDisplayed;
144 boolean startingMoved;
145 boolean firstWindowDrawn;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700146 private final WindowState.UpdateReportedVisibilityResults mReportedVisibilityResults =
147 new WindowState.UpdateReportedVisibilityResults();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800148
149 // Input application handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700150 final InputApplicationHandle mInputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800151
Wale Ogunwale571771c2016-08-26 13:18:50 -0700152 // TODO: Have a WindowContainer state for tracking exiting/deferred removal.
Craig Mautner799bc1d2015-01-14 10:33:48 -0800153 boolean mIsExiting;
Craig Mautner9ef471f2014-02-07 13:11:47 -0800154
Craig Mautnerbb742462014-07-07 15:28:55 -0700155 boolean mLaunchTaskBehind;
Craig Mautner8746a472014-07-24 15:12:54 -0700156 boolean mEnteringAnimation;
Craig Mautnerbb742462014-07-07 15:28:55 -0700157
Wale Ogunwale72919d22016-12-08 18:58:50 -0800158 private boolean mAlwaysFocusable;
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800159
Robert Carre12aece2016-02-02 22:43:27 -0800160 boolean mAppStopped;
Robert Carrfd10cd12016-06-29 16:41:50 -0700161 int mRotationAnimationHint;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700162 private int mPendingRelaunchCount;
Robert Carre12aece2016-02-02 22:43:27 -0800163
Jorim Jaggife762342016-10-13 14:33:27 +0200164 private boolean mLastContainsShowWhenLockedWindow;
165 private boolean mLastContainsDismissKeyguardWindow;
166
Robert Carr91b228092016-06-28 17:32:37 -0700167 private ArrayList<WindowSurfaceController.SurfaceControlWithBackground> mSurfaceViewBackgrounds =
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700168 new ArrayList<>();
Robert Carr91b228092016-06-28 17:32:37 -0700169
Jorim Jaggi0429f352015-12-22 16:29:16 +0100170 ArrayDeque<Rect> mFrozenBounds = new ArrayDeque<>();
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700171 ArrayDeque<Configuration> mFrozenMergedConfig = new ArrayDeque<>();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100172
Wale Ogunwale72919d22016-12-08 18:58:50 -0800173 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
174 DisplayContent dc, long inputDispatchingTimeoutNanos, boolean fullscreen,
175 boolean showForAllUsers, int targetSdk, int orientation, int rotationAnimationHint,
176 int configChanges, boolean launchTaskBehind, boolean alwaysFocusable) {
177 this(service, token, voiceInteraction, dc);
178 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
208 if (startingData != null) {
209 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();
215 winAnimator.mService.mFinishedStarting.add(this);
216 winAnimator.mService.mH.sendEmptyMessage(H.FINISHED_STARTING);
217 }
218 updateReportedVisibilityLocked();
219 }
220
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800221 void updateReportedVisibilityLocked() {
222 if (appToken == null) {
223 return;
224 }
225
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700226 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700227 final int count = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800228
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700229 mReportedVisibilityResults.reset();
230
231 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700232 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700233 win.updateReportedVisibility(mReportedVisibilityResults);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800234 }
235
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700236 int numInteresting = mReportedVisibilityResults.numInteresting;
237 int numVisible = mReportedVisibilityResults.numVisible;
238 int numDrawn = mReportedVisibilityResults.numDrawn;
239 boolean nowGone = mReportedVisibilityResults.nowGone;
240
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700241 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800242 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700243 if (!nowGone) {
244 // If the app is not yet gone, then it can only become visible/drawn.
245 if (!nowDrawn) {
246 nowDrawn = reportedDrawn;
247 }
248 if (!nowVisible) {
249 nowVisible = reportedVisible;
250 }
251 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800252 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800253 + numInteresting + " visible=" + numVisible);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700254 if (nowDrawn != reportedDrawn) {
255 if (nowDrawn) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700256 mService.mH.obtainMessage(H.REPORT_APPLICATION_TOKEN_DRAWN, this).sendToTarget();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700257 }
258 reportedDrawn = nowDrawn;
259 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800260 if (nowVisible != reportedVisible) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700261 if (DEBUG_VISIBILITY) Slog.v(TAG,
262 "Visibility changed in " + this + ": vis=" + nowVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800263 reportedVisible = nowVisible;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700264 mService.mH.obtainMessage(H.REPORT_APPLICATION_TOKEN_WINDOWS,
265 nowVisible ? 1 : 0, nowGone ? 1 : 0, this).sendToTarget();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800266 }
267 }
268
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700269 boolean setVisibility(WindowManager.LayoutParams lp,
270 boolean visible, int transit, boolean performLayout, boolean isVoiceInteraction) {
271
272 boolean delayed = false;
273 inPendingTransaction = false;
274
275 if (clientHidden == visible) {
276 clientHidden = !visible;
277 sendAppVisibilityToClients();
278 }
279
280 // Allow for state changes and animation to be applied if:
281 // * token is transitioning visibility state
282 // * or the token was marked as hidden and is exiting before we had a chance to play the
283 // transition animation
284 // * or this is an opening app and windows are being replaced.
285 boolean visibilityChanged = false;
286 if (hidden == visible || (hidden && mIsExiting) || (visible && waitingForReplacement())) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700287 final AccessibilityController accessibilityController = mService.mAccessibilityController;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700288 boolean changed = false;
289 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
290 "Changing app " + this + " hidden=" + hidden + " performLayout=" + performLayout);
291
292 boolean runningAppAnimation = false;
293
294 if (transit != AppTransition.TRANSIT_UNSET) {
295 if (mAppAnimator.animation == AppWindowAnimator.sDummyAnimation) {
296 mAppAnimator.setNullAnimation();
297 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700298 if (mService.applyAnimationLocked(this, lp, transit, visible, isVoiceInteraction)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700299 delayed = runningAppAnimation = true;
300 }
301 final WindowState window = findMainWindow();
302 //TODO (multidisplay): Magnification is supported only for the default display.
303 if (window != null && accessibilityController != null
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700304 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700305 accessibilityController.onAppWindowTransitionLocked(window, transit);
306 }
307 changed = true;
308 }
309
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700310 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700311 for (int i = 0; i < windowsCount; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700312 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700313 changed |= win.onAppVisibilityChanged(visible, runningAppAnimation);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700314 }
315
316 hidden = hiddenRequested = !visible;
317 visibilityChanged = true;
318 if (!visible) {
319 stopFreezingScreen(true, true);
320 } else {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700321 // If we are being set visible, and the starting window is not yet displayed,
322 // then make sure it doesn't get displayed.
323 if (startingWindow != null && !startingWindow.isDrawnLw()) {
324 startingWindow.mPolicyVisibility = false;
325 startingWindow.mPolicyVisibilityAfterAnim = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700326 }
327 }
328
329 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setVisibility: " + this
330 + ": hidden=" + hidden + " hiddenRequested=" + hiddenRequested);
331
332 if (changed) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700333 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700334 if (performLayout) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700335 mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700336 false /*updateInputWindows*/);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700337 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700338 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700339 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700340 }
341 }
342
343 if (mAppAnimator.animation != null) {
344 delayed = true;
345 }
346
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700347 for (int i = mChildren.size() - 1; i >= 0 && !delayed; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700348 if ((mChildren.get(i)).isWindowAnimationSet()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700349 delayed = true;
350 }
351 }
352
353 if (visibilityChanged) {
354 if (visible && !delayed) {
355 // The token was made immediately visible, there will be no entrance animation.
356 // We need to inform the client the enter animation was finished.
357 mEnteringAnimation = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700358 mService.mActivityManagerAppTransitionNotifier.onAppTransitionFinishedLocked(token);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700359 }
360
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700361 if (!mService.mClosingApps.contains(this) && !mService.mOpeningApps.contains(this)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700362 // The token is not closing nor opening, so even if there is an animation set, that
363 // doesn't mean that it goes through the normal app transition cycle so we have
364 // to inform the docked controller about visibility change.
Andrii Kulian1e32e022016-09-16 15:29:34 -0700365 // TODO(multi-display): notify docked divider on all displays where visibility was
366 // affected.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700367 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700368 .notifyAppVisibilityChanged();
369 }
370 }
371
372 return delayed;
373 }
374
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800375 WindowState findMainWindow() {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700376 WindowState candidate = null;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700377 int j = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800378 while (j > 0) {
379 j--;
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700380 final WindowState win = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700381 final int type = win.mAttrs.type;
382 // No need to loop through child window as base application and starting types can't be
383 // child windows.
384 if (type == TYPE_BASE_APPLICATION || type == TYPE_APPLICATION_STARTING) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700385 // In cases where there are multiple windows, we prefer the non-exiting window. This
Sungsoo Lim0d3d1f82015-12-02 14:47:59 +0900386 // happens for example when replacing windows during an activity relaunch. When
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700387 // constructing the animation, we want the new window, not the exiting one.
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800388 if (win.mAnimatingExit) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700389 candidate = win;
390 } else {
391 return win;
392 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800393 }
394 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700395 return candidate;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800396 }
397
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800398 boolean windowsAreFocusable() {
399 return StackId.canReceiveKeys(mTask.mStack.mStackId) || mAlwaysFocusable;
Wale Ogunwaled045c822015-12-02 09:14:28 -0800400 }
401
Wale Ogunwale571771c2016-08-26 13:18:50 -0700402 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -0700403 boolean isVisible() {
Wale Ogunwalee471be62016-10-03 07:53:55 -0700404 // If the app token isn't hidden then it is considered visible and there is no need to check
405 // its children windows to see if they are visible.
406 return !hidden;
Wale Ogunwale44f21802016-09-02 12:49:48 -0700407 }
408
409 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -0700410 void removeIfPossible() {
Craig Mautnere3119b72015-01-20 15:02:36 -0800411 mIsExiting = false;
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800412 removeAllWindowsIfPossible();
Wale Ogunwale571771c2016-08-26 13:18:50 -0700413 if (mTask != null) {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700414 mTask.mStack.mExitingAppTokens.remove(this);
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800415 removeImmediately();
Craig Mautnere3119b72015-01-20 15:02:36 -0800416 }
417 }
418
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700419 @Override
420 boolean checkCompleteDeferredRemoval() {
421 if (mIsExiting) {
422 removeIfPossible();
423 }
424 return super.checkCompleteDeferredRemoval();
425 }
426
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700427 void onRemovedFromDisplay() {
428 AppWindowToken startingToken = null;
429
430 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app token: " + this);
431
Wale Ogunwale72919d22016-12-08 18:58:50 -0800432 boolean delayed = setVisibility(null, false, TRANSIT_UNSET, true, mVoiceInteraction);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700433
434 mService.mOpeningApps.remove(this);
Jorim Jaggi1b4b23e2016-11-15 16:30:12 -0800435 mService.mUnknownAppVisibilityController.appRemoved(this);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700436 waitingToShow = false;
437 if (mService.mClosingApps.contains(this)) {
438 delayed = true;
439 } else if (mService.mAppTransition.isTransitionSet()) {
440 mService.mClosingApps.add(this);
441 delayed = true;
442 }
443
444 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app " + this + " delayed=" + delayed
445 + " animation=" + mAppAnimator.animation + " animating=" + mAppAnimator.animating);
446
447 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM, "removeAppToken: "
448 + this + " delayed=" + delayed + " Callers=" + Debug.getCallers(4));
449
450 final TaskStack stack = mTask.mStack;
451 if (delayed && !isEmpty()) {
452 // set the token aside because it has an active animation to be finished
453 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM,
454 "removeAppToken make exiting: " + this);
455 stack.mExitingAppTokens.add(this);
456 mIsExiting = true;
457 } else {
458 // Make sure there is no animation running on this token, so any windows associated
459 // with it will be removed as soon as their animations are complete
460 mAppAnimator.clearAnimation();
461 mAppAnimator.animating = false;
462 removeIfPossible();
463 }
464
465 removed = true;
466 if (startingData != null) {
467 startingToken = this;
468 }
469 stopFreezingScreen(true, true);
470 if (mService.mFocusedApp == this) {
471 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "Removing focused app token:" + this);
472 mService.mFocusedApp = null;
473 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
474 mService.mInputMonitor.setFocusedAppLw(null);
475 }
476
477 if (!delayed) {
478 updateReportedVisibilityLocked();
479 }
480
481 // Will only remove if startingToken non null.
482 mService.scheduleRemoveStartingWindowLocked(startingToken);
483 }
484
Chong Zhange05bcb12016-07-26 17:47:29 -0700485 void clearAnimatingFlags() {
Chong Zhangb0d26702016-08-12 16:03:29 -0700486 boolean wallpaperMightChange = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700487 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700488 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700489 wallpaperMightChange |= win.clearAnimatingFlags();
Chong Zhange05bcb12016-07-26 17:47:29 -0700490 }
Chong Zhangb0d26702016-08-12 16:03:29 -0700491 if (wallpaperMightChange) {
492 requestUpdateWallpaperIfNeeded();
493 }
Chong Zhange05bcb12016-07-26 17:47:29 -0700494 }
495
Robert Carre12aece2016-02-02 22:43:27 -0800496 void destroySurfaces() {
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700497 destroySurfaces(false /*cleanupOnResume*/);
498 }
499
500 /**
501 * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure
502 * the client has finished with them.
503 *
504 * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If
505 * set to true, destroy only surfaces of removed windows, and clear relevant flags of the
506 * others so that they are ready to be reused. If set to false (common case), destroy all
507 * surfaces that's eligible, if the app is already stopped.
508 */
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700509 private void destroySurfaces(boolean cleanupOnResume) {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700510 boolean destroyedSomething = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700511 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700512 final WindowState win = mChildren.get(i);
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700513 destroyedSomething |= win.destroySurface(cleanupOnResume, mAppStopped);
Robert Carre12aece2016-02-02 22:43:27 -0800514 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700515 if (destroyedSomething) {
516 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700517 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Robert Carre12aece2016-02-02 22:43:27 -0800518 }
519 }
520
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800521 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700522 * Notify that the app is now resumed, and it was not stopped before, perform a clean
523 * up of the surfaces
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800524 */
Chong Zhangad24f962016-08-25 12:12:33 -0700525 void notifyAppResumed(boolean wasStopped, boolean allowSavedSurface) {
526 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped
527 + " allowSavedSurface=" + allowSavedSurface + " " + this);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700528 mAppStopped = false;
529 if (!wasStopped) {
530 destroySurfaces(true /*cleanupOnResume*/);
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800531 }
Chong Zhangad24f962016-08-25 12:12:33 -0700532 if (!allowSavedSurface) {
533 destroySavedSurfaces();
534 }
Robert Carre12aece2016-02-02 22:43:27 -0800535 }
536
Chong Zhangbef461f2015-10-27 11:38:24 -0700537 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700538 * Notify that the app has stopped, and it is okay to destroy any surfaces which were
539 * keeping alive in case they were still being used.
540 */
541 void notifyAppStopped() {
542 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this);
543 mAppStopped = true;
544 destroySurfaces();
545 // Remove any starting window that was added for this app if they are still around.
546 mTask.mService.scheduleRemoveStartingWindowLocked(this);
547 }
548
549 /**
Chong Zhangbef461f2015-10-27 11:38:24 -0700550 * Checks whether we should save surfaces for this app.
551 *
552 * @return true if the surfaces should be saved, false otherwise.
553 */
554 boolean shouldSaveSurface() {
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800555 // We want to save surface if the app's windows are "allDrawn".
556 // (If we started entering animation early with saved surfaces, allDrawn
557 // should have been restored to true. So we'll save again in that case
558 // even if app didn't actually finish drawing.)
559 return allDrawn;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800560 }
561
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700562 private boolean canRestoreSurfaces() {
563 for (int i = mChildren.size() -1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700564 final WindowState w = mChildren.get(i);
Chong Zhang92147042016-05-09 12:47:11 -0700565 if (w.canRestoreSurface()) {
Robert Carr13f7be9e2015-12-02 18:39:45 -0800566 return true;
567 }
Chong Zhangbef461f2015-10-27 11:38:24 -0700568 }
569 return false;
570 }
571
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700572 private void clearWasVisibleBeforeClientHidden() {
573 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700574 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700575 w.clearWasVisibleBeforeClientHidden();
Chong Zhang92147042016-05-09 12:47:11 -0700576 }
577 }
578
Chong Zhang8e4bda92016-05-04 15:08:18 -0700579 /**
580 * Whether the app has some window that is invisible in layout, but
581 * animating with saved surface.
582 */
583 boolean isAnimatingInvisibleWithSavedSurface() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700584 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700585 final WindowState w = mChildren.get(i);
Chong Zhang8e4bda92016-05-04 15:08:18 -0700586 if (w.isAnimatingInvisibleWithSavedSurface()) {
587 return true;
588 }
589 }
590 return false;
591 }
592
593 /**
594 * Hide all window surfaces that's still invisible in layout but animating
595 * with a saved surface, and mark them destroying.
596 */
597 void stopUsingSavedSurfaceLocked() {
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);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700600 w.stopUsingSavedSurface();
Chong Zhang8e4bda92016-05-04 15:08:18 -0700601 }
602 destroySurfaces();
603 }
604
Chong Zhangf58631a2016-05-24 16:02:10 -0700605 void markSavedSurfaceExiting() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700606 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700607 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700608 w.markSavedSurfaceExiting();
Chong Zhangf58631a2016-05-24 16:02:10 -0700609 }
610 }
611
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700612 void restoreSavedSurfaceForInterestingWindows() {
Chong Zhang92147042016-05-09 12:47:11 -0700613 if (!canRestoreSurfaces()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700614 clearWasVisibleBeforeClientHidden();
Chong Zhangbef461f2015-10-27 11:38:24 -0700615 return;
616 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700617
618 // Check if all interesting windows are drawn and we can mark allDrawn=true.
619 int interestingNotDrawn = -1;
620
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700621 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700622 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700623 interestingNotDrawn = w.restoreSavedSurfaceForInterestingWindow();
Chong Zhangbef461f2015-10-27 11:38:24 -0700624 }
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800625
Chong Zhang92147042016-05-09 12:47:11 -0700626 if (!allDrawn) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700627 allDrawn = (interestingNotDrawn == 0);
Chong Zhang92147042016-05-09 12:47:11 -0700628 if (allDrawn) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700629 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Chong Zhang92147042016-05-09 12:47:11 -0700630 }
631 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700632 clearWasVisibleBeforeClientHidden();
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800633
634 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700635 "restoreSavedSurfaceForInterestingWindows: " + this + " allDrawn=" + allDrawn
636 + " interestingNotDrawn=" + interestingNotDrawn);
Chong Zhangbef461f2015-10-27 11:38:24 -0700637 }
638
639 void destroySavedSurfaces() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700640 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700641 final WindowState win = mChildren.get(i);
Robert Carr13f7be9e2015-12-02 18:39:45 -0800642 win.destroySavedSurface();
Chong Zhangbef461f2015-10-27 11:38:24 -0700643 }
Chong Zhang92147042016-05-09 12:47:11 -0700644 }
645
646 void clearAllDrawn() {
647 allDrawn = false;
648 deferClearAllDrawn = false;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700649 allDrawnExcludingSaved = false;
Chong Zhangbef461f2015-10-27 11:38:24 -0700650 }
651
Wale Ogunwalefa854eb2016-09-20 13:43:52 -0700652 void postWindowRemoveStartingWindowCleanup(WindowState win) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700653 // TODO: Something smells about the code below...Is there a better way?
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700654 if (startingWindow == win) {
655 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700656 mService.scheduleRemoveStartingWindowLocked(this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700657 } else if (mChildren.size() == 0 && startingData != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700658 // If this is the last window and we had requested a starting transition window,
659 // well there is no point now.
660 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingWindow");
661 startingData = null;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700662 } else if (mChildren.size() == 1 && startingView != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700663 // If this is the last window except for a starting transition window,
664 // we need to get rid of the starting transition.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700665 mService.scheduleRemoveStartingWindowLocked(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700666 }
667 }
668
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700669 void removeDeadWindows() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700670 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700671 WindowState win = mChildren.get(winNdx);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800672 if (win.mAppDied) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700673 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700674 "removeDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800675 // Set mDestroying, we don't want any animation or delayed removal here.
676 win.mDestroying = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700677 // Also removes child windows.
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700678 win.removeIfPossible();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800679 }
680 }
681 }
682
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700683 boolean hasWindowsAlive() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700684 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700685 // No need to loop through child windows as the answer should be the same as that of the
686 // parent window.
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700687 if (!(mChildren.get(i)).mAppDied) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700688 return true;
689 }
690 }
691 return false;
692 }
693
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700694 void setWillReplaceWindows(boolean animate) {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700695 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
696 "Marking app token " + this + " with replacing windows.");
Robert Carra1eb4392015-12-10 12:43:51 -0800697
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700698 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700699 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700700 w.setWillReplaceWindow(animate);
Robert Carra1eb4392015-12-10 12:43:51 -0800701 }
702 if (animate) {
703 // Set-up dummy animation so we can start treating windows associated with this
704 // token like they are in transition before the new app window is ready for us to
705 // run the real transition animation.
706 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700707 "setWillReplaceWindow() Setting dummy animation on: " + this);
Robert Carra1eb4392015-12-10 12:43:51 -0800708 mAppAnimator.setDummyAnimation();
709 }
710 }
711
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700712 void setWillReplaceChildWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700713 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this
Robert Carr23fa16b2016-01-13 13:19:58 -0800714 + " with replacing child windows.");
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700715 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700716 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700717 w.setWillReplaceChildWindows();
Robert Carr23fa16b2016-01-13 13:19:58 -0800718 }
719 }
720
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700721 void clearWillReplaceWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700722 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
723 "Resetting app token " + this + " of replacing window marks.");
Chong Zhangf596cd52016-01-05 13:42:44 -0800724
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700725 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700726 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700727 w.clearWillReplaceWindow();
Chong Zhangf596cd52016-01-05 13:42:44 -0800728 }
729 }
730
Chong Zhang4d7369a2016-04-25 16:09:14 -0700731 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700732 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700733 final WindowState w = mChildren.get(i);
Chong Zhang4d7369a2016-04-25 16:09:14 -0700734 w.requestUpdateWallpaperIfNeeded();
735 }
736 }
737
Chong Zhangd78ddb42016-03-02 17:01:14 -0800738 boolean isRelaunching() {
739 return mPendingRelaunchCount > 0;
740 }
741
742 void startRelaunching() {
743 if (canFreezeBounds()) {
744 freezeBounds();
745 }
746 mPendingRelaunchCount++;
747 }
748
749 void finishRelaunching() {
750 if (canFreezeBounds()) {
751 unfreezeBounds();
752 }
753 if (mPendingRelaunchCount > 0) {
754 mPendingRelaunchCount--;
755 }
756 }
757
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700758 void clearRelaunching() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700759 if (mPendingRelaunchCount == 0) {
760 return;
761 }
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700762 if (canFreezeBounds()) {
763 unfreezeBounds();
764 }
765 mPendingRelaunchCount = 0;
766 }
767
Wale Ogunwale07bcab72016-10-14 15:30:09 -0700768 /**
769 * Returns true if the new child window we are adding to this token is considered greater than
770 * the existing child window in this token in terms of z-order.
771 */
772 @Override
773 protected boolean isFirstChildWindowGreaterThanSecond(WindowState newWindow,
774 WindowState existingWindow) {
775 final int type1 = newWindow.mAttrs.type;
776 final int type2 = existingWindow.mAttrs.type;
777
778 // Base application windows should be z-ordered BELOW all other windows in the app token.
779 if (type1 == TYPE_BASE_APPLICATION && type2 != TYPE_BASE_APPLICATION) {
780 return false;
781 } else if (type1 != TYPE_BASE_APPLICATION && type2 == TYPE_BASE_APPLICATION) {
782 return true;
783 }
784
785 // Starting windows should be z-ordered ABOVE all other windows in the app token.
786 if (type1 == TYPE_APPLICATION_STARTING && type2 != TYPE_APPLICATION_STARTING) {
787 return true;
788 } else if (type1 != TYPE_APPLICATION_STARTING && type2 == TYPE_APPLICATION_STARTING) {
789 return false;
790 }
791
792 // Otherwise the new window is greater than the existing window.
793 return true;
794 }
795
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700796 @Override
Robert Carra1eb4392015-12-10 12:43:51 -0800797 void addWindow(WindowState w) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700798 super.addWindow(w);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700799
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700800 boolean gotReplacementWindow = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700801 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700802 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700803 gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w);
804 }
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700805
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700806 // if we got a replacement window, reset the timeout to give drawing more time
807 if (gotReplacementWindow) {
808 mService.scheduleWindowReplacementTimeouts(this);
Robert Carra1eb4392015-12-10 12:43:51 -0800809 }
Jorim Jaggife762342016-10-13 14:33:27 +0200810 checkKeyguardFlagsChanged();
811 }
812
813 @Override
814 void removeChild(WindowState child) {
815 super.removeChild(child);
816 checkKeyguardFlagsChanged();
Robert Carra1eb4392015-12-10 12:43:51 -0800817 }
818
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700819 private boolean waitingForReplacement() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700820 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700821 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700822 if (candidate.waitingForReplacement()) {
Robert Carra1eb4392015-12-10 12:43:51 -0800823 return true;
824 }
825 }
826 return false;
827 }
828
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700829 void onWindowReplacementTimeout() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700830 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700831 (mChildren.get(i)).onWindowReplacementTimeout();
Robert Carra1eb4392015-12-10 12:43:51 -0800832 }
833 }
834
Chong Zhangd78ddb42016-03-02 17:01:14 -0800835 private boolean canFreezeBounds() {
836 // For freeform windows, we can't freeze the bounds at the moment because this would make
837 // the resizing unresponsive.
838 return mTask != null && !mTask.inFreeformWorkspace();
839 }
840
Jorim Jaggi0429f352015-12-22 16:29:16 +0100841 /**
842 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
843 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
844 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
845 * with a queue.
846 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800847 private void freezeBounds() {
Jorim Jaggi0429f352015-12-22 16:29:16 +0100848 mFrozenBounds.offer(new Rect(mTask.mPreparedFrozenBounds));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700849
850 if (mTask.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) {
851 // We didn't call prepareFreezingBounds on the task, so use the current value.
Andrii Kulian441e4492016-09-29 15:25:00 -0700852 mFrozenMergedConfig.offer(new Configuration(mTask.getConfiguration()));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700853 } else {
854 mFrozenMergedConfig.offer(new Configuration(mTask.mPreparedFrozenMergedConfig));
855 }
Andrii Kulianb10330d2016-09-16 13:51:46 -0700856 // Calling unset() to make it equal to Configuration.EMPTY.
857 mTask.mPreparedFrozenMergedConfig.unset();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100858 }
859
860 /**
861 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
862 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800863 private void unfreezeBounds() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700864 if (!mFrozenBounds.isEmpty()) {
865 mFrozenBounds.remove();
866 }
867 if (!mFrozenMergedConfig.isEmpty()) {
868 mFrozenMergedConfig.remove();
869 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700870 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700871 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700872 win.onUnfreezeBounds();
Jorim Jaggi4846ee32016-01-07 17:39:12 +0100873 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700874 mService.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100875 }
876
Robert Carr91b228092016-06-28 17:32:37 -0700877 void addSurfaceViewBackground(WindowSurfaceController.SurfaceControlWithBackground background) {
878 mSurfaceViewBackgrounds.add(background);
879 }
880
881 void removeSurfaceViewBackground(WindowSurfaceController.SurfaceControlWithBackground background) {
882 mSurfaceViewBackgrounds.remove(background);
883 updateSurfaceViewBackgroundVisibilities();
884 }
885
886 // We use DimLayers behind SurfaceViews to prevent holes while resizing and creating.
887 // However, we need to ensure one SurfaceView doesn't cover another when they are both placed
888 // below the main app window (as traditionally a SurfaceView which is never drawn
889 // to is totally translucent). So we look at all our SurfaceView backgrounds and only enable
890 // the background for the SurfaceView with lowest Z order
891 void updateSurfaceViewBackgroundVisibilities() {
892 WindowSurfaceController.SurfaceControlWithBackground bottom = null;
893 int bottomLayer = Integer.MAX_VALUE;
894 for (int i = 0; i < mSurfaceViewBackgrounds.size(); i++) {
895 WindowSurfaceController.SurfaceControlWithBackground sc = mSurfaceViewBackgrounds.get(i);
896 if (sc.mVisible && sc.mLayer < bottomLayer) {
897 bottomLayer = sc.mLayer;
898 bottom = sc;
899 }
900 }
901 for (int i = 0; i < mSurfaceViewBackgrounds.size(); i++) {
902 WindowSurfaceController.SurfaceControlWithBackground sc = mSurfaceViewBackgrounds.get(i);
903 sc.updateBackgroundVisibility(sc != bottom);
904 }
905 }
906
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700907 void resetJustMovedInStack() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700908 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700909 (mChildren.get(i)).resetJustMovedInStack();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700910 }
911 }
912
913 void notifyMovedInStack() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700914 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700915 final WindowState win = mChildren.get(winNdx);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700916 win.notifyMovedInStack();
917 }
918 }
919
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700920 void setAppLayoutChanges(int changes, String reason) {
921 if (!mChildren.isEmpty()) {
922 final DisplayContent dc = getDisplayContent();
923 dc.pendingLayoutChanges |= changes;
924 if (DEBUG_LAYOUT_REPEATS) {
925 mService.mWindowPlacerLocked.debugLayoutRepeats(reason, dc.pendingLayoutChanges);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700926 }
927 }
928 }
929
930 void removeReplacedWindowIfNeeded(WindowState replacement) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700931 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700932 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700933 if (win.removeReplacedWindowIfNeeded(replacement)) {
934 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700935 }
936 }
937 }
938
939 void startFreezingScreen() {
940 if (DEBUG_ORIENTATION) logWithStack(TAG, "Set freezing of " + appToken + ": hidden="
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700941 + hidden + " freezing=" + mAppAnimator.freezingScreen + " hiddenRequested="
942 + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700943 if (!hiddenRequested) {
944 if (!mAppAnimator.freezingScreen) {
945 mAppAnimator.freezingScreen = true;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700946 mService.registerAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700947 mAppAnimator.lastFreezeDuration = 0;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700948 mService.mAppsFreezingScreen++;
949 if (mService.mAppsFreezingScreen == 1) {
950 mService.startFreezingDisplayLocked(false, 0, 0);
951 mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT);
952 mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700953 }
954 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700955 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700956 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700957 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700958 w.onStartFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700959 }
960 }
961 }
962
963 void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) {
964 if (!mAppAnimator.freezingScreen) {
965 return;
966 }
967 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + this + " force=" + force);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700968 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700969 boolean unfrozeWindows = false;
970 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700971 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700972 unfrozeWindows |= w.onStopFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700973 }
974 if (force || unfrozeWindows) {
975 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this);
976 mAppAnimator.freezingScreen = false;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700977 mService.unregisterAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700978 mAppAnimator.lastFreezeDuration =
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700979 (int)(SystemClock.elapsedRealtime() - mService.mDisplayFreezeTime);
980 mService.mAppsFreezingScreen--;
981 mService.mLastFinishedFreezeSource = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700982 }
983 if (unfreezeSurfaceNow) {
984 if (unfrozeWindows) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700985 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700986 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700987 mService.stopFreezingDisplayLocked();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700988 }
989 }
990
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700991 @Override
992 public void onAppFreezeTimeout() {
993 Slog.w(TAG_WM, "Force clearing freeze: " + this);
994 stopFreezingScreen(true, true);
995 }
996
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700997 boolean transferStartingWindow(IBinder transferFrom) {
Wale Ogunwale02319a62016-09-26 15:21:22 -0700998 final AppWindowToken fromToken = getDisplayContent().getAppWindowToken(transferFrom);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700999 if (fromToken == null) {
1000 return false;
1001 }
1002
1003 final WindowState tStartingWindow = fromToken.startingWindow;
1004 if (tStartingWindow != null && fromToken.startingView != null) {
1005 // In this case, the starting icon has already been displayed, so start
1006 // letting windows get shown immediately without any more transitions.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001007 mService.mSkipAppTransitionAnimation = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001008
1009 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow
1010 + " from " + fromToken + " to " + this);
1011
1012 final long origId = Binder.clearCallingIdentity();
1013
1014 // Transfer the starting window over to the new token.
1015 startingData = fromToken.startingData;
1016 startingView = fromToken.startingView;
1017 startingDisplayed = fromToken.startingDisplayed;
1018 fromToken.startingDisplayed = false;
1019 startingWindow = tStartingWindow;
1020 reportedVisible = fromToken.reportedVisible;
1021 fromToken.startingData = null;
1022 fromToken.startingView = null;
1023 fromToken.startingWindow = null;
1024 fromToken.startingMoved = true;
1025 tStartingWindow.mToken = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001026 tStartingWindow.mAppToken = this;
1027
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001028 if (DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001029 "Removing starting " + tStartingWindow + " from " + fromToken);
Wale Ogunwalefa854eb2016-09-20 13:43:52 -07001030 fromToken.removeChild(tStartingWindow);
1031 fromToken.postWindowRemoveStartingWindowCleanup(tStartingWindow);
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001032 addWindow(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001033
1034 // Propagate other interesting state between the tokens. If the old token is displayed,
1035 // we should immediately force the new one to be displayed. If it is animating, we need
1036 // to move that animation to the new one.
1037 if (fromToken.allDrawn) {
1038 allDrawn = true;
1039 deferClearAllDrawn = fromToken.deferClearAllDrawn;
1040 }
1041 if (fromToken.firstWindowDrawn) {
1042 firstWindowDrawn = true;
1043 }
1044 if (!fromToken.hidden) {
1045 hidden = false;
1046 hiddenRequested = false;
1047 }
1048 if (clientHidden != fromToken.clientHidden) {
1049 clientHidden = fromToken.clientHidden;
1050 sendAppVisibilityToClients();
1051 }
1052 fromToken.mAppAnimator.transferCurrentAnimation(
1053 mAppAnimator, tStartingWindow.mWinAnimator);
1054
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001055 mService.updateFocusedWindowLocked(
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001056 UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/);
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001057 getDisplayContent().setLayoutNeeded();
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001058 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001059 Binder.restoreCallingIdentity(origId);
1060 return true;
1061 } else if (fromToken.startingData != null) {
1062 // The previous app was getting ready to show a
1063 // starting window, but hasn't yet done so. Steal it!
1064 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1065 "Moving pending starting from " + fromToken + " to " + this);
1066 startingData = fromToken.startingData;
1067 fromToken.startingData = null;
1068 fromToken.startingMoved = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001069 final Message m = mService.mH.obtainMessage(H.ADD_STARTING, this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001070 // Note: we really want to do sendMessageAtFrontOfQueue() because we want to process the
1071 // message ASAP, before any other queued messages.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001072 mService.mH.sendMessageAtFrontOfQueue(m);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001073 return true;
1074 }
1075
1076 final AppWindowAnimator tAppAnimator = fromToken.mAppAnimator;
1077 final AppWindowAnimator wAppAnimator = mAppAnimator;
1078 if (tAppAnimator.thumbnail != null) {
1079 // The old token is animating with a thumbnail, transfer that to the new token.
1080 if (wAppAnimator.thumbnail != null) {
1081 wAppAnimator.thumbnail.destroy();
1082 }
1083 wAppAnimator.thumbnail = tAppAnimator.thumbnail;
1084 wAppAnimator.thumbnailLayer = tAppAnimator.thumbnailLayer;
1085 wAppAnimator.thumbnailAnimation = tAppAnimator.thumbnailAnimation;
1086 tAppAnimator.thumbnail = null;
1087 }
1088 return false;
1089 }
1090
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001091 boolean isLastWindow(WindowState win) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001092 return mChildren.size() == 1 && mChildren.get(0) == win;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001093 }
1094
1095 void setAllAppWinAnimators() {
1096 final ArrayList<WindowStateAnimator> allAppWinAnimators = mAppAnimator.mAllAppWinAnimators;
1097 allAppWinAnimators.clear();
1098
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001099 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001100 for (int j = 0; j < windowsCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001101 (mChildren.get(j)).addWinAnimatorToList(allAppWinAnimators);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001102 }
1103 }
1104
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001105 @Override
1106 void onAppTransitionDone() {
1107 sendingToBottom = false;
1108 }
1109
Wale Ogunwale51362492016-09-08 17:49:17 -07001110 /**
1111 * We override because this class doesn't want its children affecting its reported orientation
1112 * in anyway.
1113 */
1114 @Override
1115 int getOrientation() {
1116 if (hidden || hiddenRequested) {
1117 return SCREEN_ORIENTATION_UNSET;
1118 }
1119 return mOrientation;
1120 }
1121
Wale Ogunwaleb198b742016-12-01 08:44:09 -08001122 /** Returns the app's preferred orientation regardless of its currently visibility state. */
1123 int getOrientationIgnoreVisibility() {
1124 return mOrientation;
1125 }
1126
Craig Mautnerdbb79912012-03-01 18:59:14 -08001127 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001128 void checkAppWindowsReadyToShow() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001129 if (allDrawn == mAppAnimator.allDrawn) {
1130 return;
1131 }
1132
1133 mAppAnimator.allDrawn = allDrawn;
1134 if (!allDrawn) {
1135 return;
1136 }
1137
1138 // The token has now changed state to having all windows shown... what to do, what to do?
1139 if (mAppAnimator.freezingScreen) {
1140 mAppAnimator.showAllWindowsLocked();
1141 stopFreezingScreen(false, true);
1142 if (DEBUG_ORIENTATION) Slog.i(TAG,
1143 "Setting mOrientationChangeComplete=true because wtoken " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001144 + " numInteresting=" + mNumInterestingWindows + " numDrawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001145 // This will set mOrientationChangeComplete and cause a pass through layout.
1146 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001147 "checkAppWindowsReadyToShow: freezingScreen");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001148 } else {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001149 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001150
1151 // We can now show all of the drawn windows!
1152 if (!mService.mOpeningApps.contains(this)) {
1153 mService.mAnimator.orAnimating(mAppAnimator.showAllWindowsLocked());
1154 }
1155 }
1156 }
1157
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001158 void updateAllDrawn(DisplayContent dc) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001159 if (!allDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001160 final int numInteresting = mNumInterestingWindows;
1161 if (numInteresting > 0 && mNumDrawnWindows >= numInteresting) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001162 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawn: " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001163 + " interesting=" + numInteresting + " drawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001164 allDrawn = true;
1165 // Force an additional layout pass where
1166 // WindowStateAnimator#commitFinishDrawingLocked() will call performShowLocked().
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001167 dc.setLayoutNeeded();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001168 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
1169 }
1170 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001171
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001172 if (!allDrawnExcludingSaved) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001173 int numInteresting = mNumInterestingWindowsExcludingSaved;
1174 if (numInteresting > 0 && mNumDrawnWindowsExcludingSaved >= numInteresting) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001175 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawnExcludingSaved: " + this
1176 + " interesting=" + numInteresting
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001177 + " drawn=" + mNumDrawnWindowsExcludingSaved);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001178 allDrawnExcludingSaved = true;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001179 dc.setLayoutNeeded();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001180 if (isAnimatingInvisibleWithSavedSurface()
1181 && !mService.mFinishedEarlyAnim.contains(this)) {
1182 mService.mFinishedEarlyAnim.add(this);
1183 }
1184 }
1185 }
1186 }
1187
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001188 /**
1189 * Updated this app token tracking states for interesting and drawn windows based on the window.
1190 *
1191 * @return Returns true if the input window is considered interesting and drawn while all the
1192 * windows in this app token where not considered drawn as of the last pass.
1193 */
1194 boolean updateDrawnWindowStates(WindowState w) {
1195 if (DEBUG_STARTING_WINDOW && w == startingWindow) {
1196 Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" + w.isOnScreen()
1197 + " allDrawn=" + allDrawn + " freezingScreen=" + mAppAnimator.freezingScreen);
1198 }
1199
1200 if (allDrawn && allDrawnExcludingSaved && !mAppAnimator.freezingScreen) {
1201 return false;
1202 }
1203
1204 if (mLastTransactionSequence != mService.mTransactionSequence) {
1205 mLastTransactionSequence = mService.mTransactionSequence;
1206 mNumInterestingWindows = mNumDrawnWindows = 0;
1207 mNumInterestingWindowsExcludingSaved = 0;
1208 mNumDrawnWindowsExcludingSaved = 0;
1209 startingDisplayed = false;
1210 }
1211
1212 final WindowStateAnimator winAnimator = w.mWinAnimator;
1213
1214 boolean isInterestingAndDrawn = false;
1215
1216 if (!allDrawn && w.mightAffectAllDrawn(false /* visibleOnly */)) {
1217 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
1218 Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw()
1219 + ", isAnimationSet=" + winAnimator.isAnimationSet());
1220 if (!w.isDrawnLw()) {
1221 Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController
1222 + " pv=" + w.mPolicyVisibility
1223 + " mDrawState=" + winAnimator.drawStateToString()
1224 + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested
1225 + " a=" + winAnimator.mAnimating);
1226 }
1227 }
1228
1229 if (w != startingWindow) {
1230 if (w.isInteresting()) {
1231 mNumInterestingWindows++;
1232 if (w.isDrawnLw()) {
1233 mNumDrawnWindows++;
1234
1235 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, "tokenMayBeDrawn: "
1236 + this + " w=" + w + " numInteresting=" + mNumInterestingWindows
1237 + " freezingScreen=" + mAppAnimator.freezingScreen
1238 + " mAppFreezing=" + w.mAppFreezing);
1239
1240 isInterestingAndDrawn = true;
1241 }
1242 }
1243 } else if (w.isDrawnLw()) {
1244 mService.mH.sendEmptyMessage(NOTIFY_STARTING_WINDOW_DRAWN);
1245 startingDisplayed = true;
1246 }
1247 }
1248
1249 if (!allDrawnExcludingSaved && w.mightAffectAllDrawn(true /* visibleOnly */)) {
1250 if (w != startingWindow && w.isInteresting()) {
1251 mNumInterestingWindowsExcludingSaved++;
1252 if (w.isDrawnLw() && !w.isAnimatingWithSavedSurface()) {
1253 mNumDrawnWindowsExcludingSaved++;
1254
1255 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
1256 "tokenMayBeDrawnExcludingSaved: " + this + " w=" + w
1257 + " numInteresting=" + mNumInterestingWindowsExcludingSaved
1258 + " freezingScreen=" + mAppAnimator.freezingScreen
1259 + " mAppFreezing=" + w.mAppFreezing);
1260
1261 isInterestingAndDrawn = true;
1262 }
1263 }
1264 }
1265
1266 return isInterestingAndDrawn;
1267 }
1268
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001269 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001270 void stepAppWindowsAnimation(long currentTime) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001271 mAppAnimator.wasAnimating = mAppAnimator.animating;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001272 if (mAppAnimator.stepAnimationLocked(currentTime)) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001273 mAppAnimator.animating = true;
1274 mService.mAnimator.setAnimating(true);
1275 mService.mAnimator.mAppWindowAnimating = true;
1276 } else if (mAppAnimator.wasAnimating) {
1277 // stopped animating, do one more pass through the layout
Wale Ogunwale1e129a42016-11-21 13:03:47 -08001278 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
1279 DEBUG_LAYOUT_REPEATS ? "appToken " + this + " done" : null);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001280 if (DEBUG_ANIM) Slog.v(TAG, "updateWindowsApps...: done animating " + this);
1281 }
1282 }
1283
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001284 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001285 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001286 // For legacy reasons we process the TaskStack.mExitingAppTokens first in DisplayContent
1287 // before the non-exiting app tokens. So, we skip the exiting app tokens here.
1288 // TODO: Investigate if we need to continue to do this or if we can just process them
1289 // in-order.
1290 if (mIsExiting && !waitingForReplacement()) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001291 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001292 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001293 return forAllWindowsUnchecked(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001294 }
1295
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001296 boolean forAllWindowsUnchecked(ToBooleanFunction<WindowState> callback,
1297 boolean traverseTopToBottom) {
1298 return super.forAllWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001299 }
1300
1301 @Override
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001302 AppWindowToken asAppWindowToken() {
1303 // I am an app window token!
1304 return this;
1305 }
1306
1307 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -07001308 boolean fillsParent() {
1309 return mFillsParent;
1310 }
1311
1312 void setFillsParent(boolean fillsParent) {
1313 mFillsParent = fillsParent;
1314 }
1315
Jorim Jaggife762342016-10-13 14:33:27 +02001316 boolean containsDismissKeyguardWindow() {
1317 for (int i = mChildren.size() - 1; i >= 0; i--) {
1318 if ((mChildren.get(i).mAttrs.flags & FLAG_DISMISS_KEYGUARD) != 0) {
1319 return true;
1320 }
1321 }
1322 return false;
1323 }
1324
1325 boolean containsShowWhenLockedWindow() {
1326 for (int i = mChildren.size() - 1; i >= 0; i--) {
1327 if ((mChildren.get(i).mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
1328 return true;
1329 }
1330 }
1331 return false;
1332 }
1333
1334 void checkKeyguardFlagsChanged() {
1335 final boolean containsDismissKeyguard = containsDismissKeyguardWindow();
1336 final boolean containsShowWhenLocked = containsShowWhenLockedWindow();
1337 if (containsDismissKeyguard != mLastContainsDismissKeyguardWindow
1338 || containsShowWhenLocked != mLastContainsShowWhenLockedWindow) {
1339 mService.notifyKeyguardFlagsChanged(null /* callback */);
1340 }
1341 mLastContainsDismissKeyguardWindow = containsDismissKeyguard;
1342 mLastContainsShowWhenLockedWindow = containsShowWhenLocked;
1343 }
1344
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001345 WindowState getImeTargetBelowWindow(WindowState w) {
1346 final int index = mChildren.indexOf(w);
1347 if (index > 0) {
1348 final WindowState target = mChildren.get(index - 1);
1349 if (target.canBeImeTarget()) {
1350 return target;
1351 }
1352 }
1353 return null;
1354 }
1355
1356 WindowState getHighestAnimLayerWindow(WindowState currentTarget) {
1357 WindowState candidate = null;
1358 for (int i = mChildren.indexOf(currentTarget); i >= 0; i--) {
1359 final WindowState w = mChildren.get(i);
1360 if (w.mRemoved) {
1361 continue;
1362 }
1363 if (candidate == null || w.mWinAnimator.mAnimLayer >
1364 candidate.mWinAnimator.mAnimLayer) {
1365 candidate = w;
1366 }
1367 }
1368 return candidate;
1369 }
1370
Wale Ogunwale51362492016-09-08 17:49:17 -07001371 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001372 void dump(PrintWriter pw, String prefix) {
1373 super.dump(pw, prefix);
1374 if (appToken != null) {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001375 pw.println(prefix + "app=true mVoiceInteraction=" + mVoiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001376 }
Craig Mautner83162a92015-01-26 14:43:30 -08001377 pw.print(prefix); pw.print("task="); pw.println(mTask);
Wale Ogunwale51362492016-09-08 17:49:17 -07001378 pw.print(prefix); pw.print(" mFillsParent="); pw.print(mFillsParent);
1379 pw.print(" mOrientation="); pw.println(mOrientation);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001380 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
1381 pw.print(" clientHidden="); pw.print(clientHidden);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -07001382 pw.print(" reportedDrawn="); pw.print(reportedDrawn);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001383 pw.print(" reportedVisible="); pw.println(reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -07001384 if (paused) {
1385 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001386 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001387 if (mAppStopped) {
1388 pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped);
1389 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001390 if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0
Craig Mautner6fbda632012-07-03 09:26:39 -07001391 || allDrawn || mAppAnimator.allDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001392 pw.print(prefix); pw.print("mNumInterestingWindows=");
1393 pw.print(mNumInterestingWindows);
1394 pw.print(" mNumDrawnWindows="); pw.print(mNumDrawnWindows);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001395 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -07001396 pw.print(" allDrawn="); pw.print(allDrawn);
1397 pw.print(" (animator="); pw.print(mAppAnimator.allDrawn);
1398 pw.println(")");
1399 }
1400 if (inPendingTransaction) {
1401 pw.print(prefix); pw.print("inPendingTransaction=");
1402 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001403 }
Craig Mautner799bc1d2015-01-14 10:33:48 -08001404 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001405 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
1406 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -08001407 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -08001408 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001409 }
1410 if (startingWindow != null || startingView != null
1411 || startingDisplayed || startingMoved) {
1412 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
1413 pw.print(" startingView="); pw.print(startingView);
1414 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001415 pw.print(" startingMoved="); pw.println(startingMoved);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001416 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01001417 if (!mFrozenBounds.isEmpty()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -08001418 pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds);
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001419 pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig);
Chong Zhangd78ddb42016-03-02 17:01:14 -08001420 }
1421 if (mPendingRelaunchCount != 0) {
1422 pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount);
Jorim Jaggi0429f352015-12-22 16:29:16 +01001423 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001424 }
1425
1426 @Override
1427 public String toString() {
1428 if (stringName == null) {
1429 StringBuilder sb = new StringBuilder();
1430 sb.append("AppWindowToken{");
1431 sb.append(Integer.toHexString(System.identityHashCode(this)));
1432 sb.append(" token="); sb.append(token); sb.append('}');
1433 stringName = sb.toString();
1434 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001435 return stringName + ((mIsExiting) ? " mIsExiting=" : "");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001436 }
Jeff Browne9bdb312012-04-05 15:30:10 -07001437}