blob: 5838a37bf9c9ca59e70109c62c8d414b877d973d [file] [log] [blame]
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server.wm;
18
Wale Ogunwale6cae7652015-12-26 07:36:26 -080019import static android.app.ActivityManager.StackId;
Wale Ogunwale51362492016-09-08 17:49:17 -070020import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070021import static android.view.Display.DEFAULT_DISPLAY;
Jorim Jaggife762342016-10-13 14:33:27 +020022import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
23import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
Wale Ogunwaled1c37912016-08-16 03:19:39 -070024import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080025import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070026import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -070027import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
28import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070029import static com.android.server.wm.AppTransition.TRANSIT_UNSET;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080030import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
31import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
Robert Carra1eb4392015-12-10 12:43:51 -080032import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070033import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070034import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
35import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
Wale Ogunwale9017ec02016-02-25 08:55:25 -080036import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070037import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TOKEN_MOVEMENT;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080038import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
39import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_MOVEMENT;
40import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
41import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Chong Zhang92147042016-05-09 12:47:11 -070042import static com.android.server.wm.WindowManagerService.H.NOTIFY_ACTIVITY_DRAWN;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -070043import static com.android.server.wm.WindowManagerService.H.NOTIFY_STARTING_WINDOW_DRAWN;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070044import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
Jorim Jaggi6626f542016-08-22 13:08:44 -070045import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_NONE;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070046import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070047import static com.android.server.wm.WindowManagerService.logWithStack;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080048
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070049import android.os.Debug;
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -080050import com.android.internal.util.ToBooleanFunction;
Jeff Brown4532e612012-04-05 14:27:12 -070051import com.android.server.input.InputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080052import com.android.server.wm.WindowManagerService.H;
53
Filip Gruszczynskia590c992015-11-25 16:45:26 -080054import android.annotation.NonNull;
Jorim Jaggi26c8c422016-05-09 19:57:25 -070055import android.content.res.Configuration;
Jorim Jaggi0429f352015-12-22 16:29:16 +010056import android.graphics.Rect;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070057import android.os.Binder;
58import android.os.IBinder;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080059import android.os.Message;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070060import android.os.SystemClock;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080061import android.util.Slog;
62import android.view.IApplicationToken;
63import android.view.View;
64import android.view.WindowManager;
Jorim Jaggi6626f542016-08-22 13:08:44 -070065import android.view.animation.Animation;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080066
67import java.io.PrintWriter;
Jorim Jaggi0429f352015-12-22 16:29:16 +010068import java.util.ArrayDeque;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080069import java.util.ArrayList;
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -080070import java.util.function.Function;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080071
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
Dianne Hackborne30e02f2014-05-27 18:24:45 -070087 final boolean voiceInteraction;
88
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 Ogunwale6dfdfd62015-04-15 12:01:38 -070094 boolean showForAllUsers;
Yorke Lee0e852472016-06-15 10:03:18 -070095 int targetSdk;
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.
98 long inputDispatchingTimeoutNanos;
99
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 Ogunwale6cae7652015-12-26 07:36:26 -0800158 boolean mAlwaysFocusable;
159
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 Ogunwale02319a62016-09-26 15:21:22 -0700173 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean _voiceInteraction,
174 DisplayContent displayContent) {
175 super(service, token != null ? token.asBinder() : null, TYPE_APPLICATION, true,
176 displayContent);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700177 appToken = token;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700178 voiceInteraction = _voiceInteraction;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800179 mInputApplicationHandle = new InputApplicationHandle(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700180 mAppAnimator = new AppWindowAnimator(this, service);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800181 }
182
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800183 void onFirstWindowDrawn(WindowState win, WindowStateAnimator winAnimator) {
184 firstWindowDrawn = true;
185
186 // We now have a good window to show, remove dead placeholders
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700187 removeDeadWindows();
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800188
189 if (startingData != null) {
190 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, "Finish starting "
191 + win.mToken + ": first real window is shown, no animation");
192 // If this initial window is animating, stop it -- we will do an animation to reveal
193 // it from behind the starting window, so there is no need for it to also be doing its
194 // own stuff.
195 winAnimator.clearAnimation();
196 winAnimator.mService.mFinishedStarting.add(this);
197 winAnimator.mService.mH.sendEmptyMessage(H.FINISHED_STARTING);
198 }
199 updateReportedVisibilityLocked();
200 }
201
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800202 void updateReportedVisibilityLocked() {
203 if (appToken == null) {
204 return;
205 }
206
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700207 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700208 final int count = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800209
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700210 mReportedVisibilityResults.reset();
211
212 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700213 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700214 win.updateReportedVisibility(mReportedVisibilityResults);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800215 }
216
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700217 int numInteresting = mReportedVisibilityResults.numInteresting;
218 int numVisible = mReportedVisibilityResults.numVisible;
219 int numDrawn = mReportedVisibilityResults.numDrawn;
220 boolean nowGone = mReportedVisibilityResults.nowGone;
221
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700222 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800223 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700224 if (!nowGone) {
225 // If the app is not yet gone, then it can only become visible/drawn.
226 if (!nowDrawn) {
227 nowDrawn = reportedDrawn;
228 }
229 if (!nowVisible) {
230 nowVisible = reportedVisible;
231 }
232 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800233 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800234 + numInteresting + " visible=" + numVisible);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700235 if (nowDrawn != reportedDrawn) {
236 if (nowDrawn) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700237 mService.mH.obtainMessage(H.REPORT_APPLICATION_TOKEN_DRAWN, this).sendToTarget();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700238 }
239 reportedDrawn = nowDrawn;
240 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800241 if (nowVisible != reportedVisible) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700242 if (DEBUG_VISIBILITY) Slog.v(TAG,
243 "Visibility changed in " + this + ": vis=" + nowVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800244 reportedVisible = nowVisible;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700245 mService.mH.obtainMessage(H.REPORT_APPLICATION_TOKEN_WINDOWS,
246 nowVisible ? 1 : 0, nowGone ? 1 : 0, this).sendToTarget();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800247 }
248 }
249
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700250 boolean setVisibility(WindowManager.LayoutParams lp,
251 boolean visible, int transit, boolean performLayout, boolean isVoiceInteraction) {
252
253 boolean delayed = false;
254 inPendingTransaction = false;
255
256 if (clientHidden == visible) {
257 clientHidden = !visible;
258 sendAppVisibilityToClients();
259 }
260
261 // Allow for state changes and animation to be applied if:
262 // * token is transitioning visibility state
263 // * or the token was marked as hidden and is exiting before we had a chance to play the
264 // transition animation
265 // * or this is an opening app and windows are being replaced.
266 boolean visibilityChanged = false;
267 if (hidden == visible || (hidden && mIsExiting) || (visible && waitingForReplacement())) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700268 final AccessibilityController accessibilityController = mService.mAccessibilityController;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700269 boolean changed = false;
270 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
271 "Changing app " + this + " hidden=" + hidden + " performLayout=" + performLayout);
272
273 boolean runningAppAnimation = false;
274
275 if (transit != AppTransition.TRANSIT_UNSET) {
276 if (mAppAnimator.animation == AppWindowAnimator.sDummyAnimation) {
277 mAppAnimator.setNullAnimation();
278 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700279 if (mService.applyAnimationLocked(this, lp, transit, visible, isVoiceInteraction)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700280 delayed = runningAppAnimation = true;
281 }
282 final WindowState window = findMainWindow();
283 //TODO (multidisplay): Magnification is supported only for the default display.
284 if (window != null && accessibilityController != null
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700285 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700286 accessibilityController.onAppWindowTransitionLocked(window, transit);
287 }
288 changed = true;
289 }
290
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700291 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700292 for (int i = 0; i < windowsCount; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700293 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700294 changed |= win.onAppVisibilityChanged(visible, runningAppAnimation);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700295 }
296
297 hidden = hiddenRequested = !visible;
298 visibilityChanged = true;
299 if (!visible) {
300 stopFreezingScreen(true, true);
301 } else {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700302 // If we are being set visible, and the starting window is not yet displayed,
303 // then make sure it doesn't get displayed.
304 if (startingWindow != null && !startingWindow.isDrawnLw()) {
305 startingWindow.mPolicyVisibility = false;
306 startingWindow.mPolicyVisibilityAfterAnim = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700307 }
308 }
309
310 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setVisibility: " + this
311 + ": hidden=" + hidden + " hiddenRequested=" + hiddenRequested);
312
313 if (changed) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700314 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700315 if (performLayout) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700316 mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700317 false /*updateInputWindows*/);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700318 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700319 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700320 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700321 }
322 }
323
324 if (mAppAnimator.animation != null) {
325 delayed = true;
326 }
327
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700328 for (int i = mChildren.size() - 1; i >= 0 && !delayed; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700329 if ((mChildren.get(i)).isWindowAnimationSet()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700330 delayed = true;
331 }
332 }
333
334 if (visibilityChanged) {
335 if (visible && !delayed) {
336 // The token was made immediately visible, there will be no entrance animation.
337 // We need to inform the client the enter animation was finished.
338 mEnteringAnimation = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700339 mService.mActivityManagerAppTransitionNotifier.onAppTransitionFinishedLocked(token);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700340 }
341
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700342 if (!mService.mClosingApps.contains(this) && !mService.mOpeningApps.contains(this)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700343 // The token is not closing nor opening, so even if there is an animation set, that
344 // doesn't mean that it goes through the normal app transition cycle so we have
345 // to inform the docked controller about visibility change.
Andrii Kulian1e32e022016-09-16 15:29:34 -0700346 // TODO(multi-display): notify docked divider on all displays where visibility was
347 // affected.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700348 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700349 .notifyAppVisibilityChanged();
350 }
351 }
352
353 return delayed;
354 }
355
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800356 WindowState findMainWindow() {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700357 WindowState candidate = null;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700358 int j = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800359 while (j > 0) {
360 j--;
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700361 final WindowState win = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700362 final int type = win.mAttrs.type;
363 // No need to loop through child window as base application and starting types can't be
364 // child windows.
365 if (type == TYPE_BASE_APPLICATION || type == TYPE_APPLICATION_STARTING) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700366 // In cases where there are multiple windows, we prefer the non-exiting window. This
Sungsoo Lim0d3d1f82015-12-02 14:47:59 +0900367 // happens for example when replacing windows during an activity relaunch. When
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700368 // constructing the animation, we want the new window, not the exiting one.
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800369 if (win.mAnimatingExit) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700370 candidate = win;
371 } else {
372 return win;
373 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800374 }
375 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700376 return candidate;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800377 }
378
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800379 boolean windowsAreFocusable() {
380 return StackId.canReceiveKeys(mTask.mStack.mStackId) || mAlwaysFocusable;
Wale Ogunwaled045c822015-12-02 09:14:28 -0800381 }
382
Wale Ogunwale571771c2016-08-26 13:18:50 -0700383 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -0700384 boolean isVisible() {
Wale Ogunwalee471be62016-10-03 07:53:55 -0700385 // If the app token isn't hidden then it is considered visible and there is no need to check
386 // its children windows to see if they are visible.
387 return !hidden;
Wale Ogunwale44f21802016-09-02 12:49:48 -0700388 }
389
390 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -0700391 void removeIfPossible() {
Craig Mautnere3119b72015-01-20 15:02:36 -0800392 mIsExiting = false;
393 removeAllWindows();
Wale Ogunwale571771c2016-08-26 13:18:50 -0700394 if (mTask != null) {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700395 mTask.mStack.mExitingAppTokens.remove(this);
396 mTask.removeChild(this);
Craig Mautnere3119b72015-01-20 15:02:36 -0800397 }
398 }
399
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700400 @Override
401 boolean checkCompleteDeferredRemoval() {
402 if (mIsExiting) {
403 removeIfPossible();
404 }
405 return super.checkCompleteDeferredRemoval();
406 }
407
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700408 void onRemovedFromDisplay() {
409 AppWindowToken startingToken = null;
410
411 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app token: " + this);
412
413 boolean delayed = setVisibility(null, false, TRANSIT_UNSET, true, voiceInteraction);
414
415 mService.mOpeningApps.remove(this);
Jorim Jaggi1b4b23e2016-11-15 16:30:12 -0800416 mService.mUnknownAppVisibilityController.appRemoved(this);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700417 waitingToShow = false;
418 if (mService.mClosingApps.contains(this)) {
419 delayed = true;
420 } else if (mService.mAppTransition.isTransitionSet()) {
421 mService.mClosingApps.add(this);
422 delayed = true;
423 }
424
425 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app " + this + " delayed=" + delayed
426 + " animation=" + mAppAnimator.animation + " animating=" + mAppAnimator.animating);
427
428 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM, "removeAppToken: "
429 + this + " delayed=" + delayed + " Callers=" + Debug.getCallers(4));
430
431 final TaskStack stack = mTask.mStack;
432 if (delayed && !isEmpty()) {
433 // set the token aside because it has an active animation to be finished
434 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM,
435 "removeAppToken make exiting: " + this);
436 stack.mExitingAppTokens.add(this);
437 mIsExiting = true;
438 } else {
439 // Make sure there is no animation running on this token, so any windows associated
440 // with it will be removed as soon as their animations are complete
441 mAppAnimator.clearAnimation();
442 mAppAnimator.animating = false;
443 removeIfPossible();
444 }
445
446 removed = true;
447 if (startingData != null) {
448 startingToken = this;
449 }
450 stopFreezingScreen(true, true);
451 if (mService.mFocusedApp == this) {
452 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "Removing focused app token:" + this);
453 mService.mFocusedApp = null;
454 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
455 mService.mInputMonitor.setFocusedAppLw(null);
456 }
457
458 if (!delayed) {
459 updateReportedVisibilityLocked();
460 }
461
462 // Will only remove if startingToken non null.
463 mService.scheduleRemoveStartingWindowLocked(startingToken);
464 }
465
Chong Zhange05bcb12016-07-26 17:47:29 -0700466 void clearAnimatingFlags() {
Chong Zhangb0d26702016-08-12 16:03:29 -0700467 boolean wallpaperMightChange = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700468 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700469 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700470 wallpaperMightChange |= win.clearAnimatingFlags();
Chong Zhange05bcb12016-07-26 17:47:29 -0700471 }
Chong Zhangb0d26702016-08-12 16:03:29 -0700472 if (wallpaperMightChange) {
473 requestUpdateWallpaperIfNeeded();
474 }
Chong Zhange05bcb12016-07-26 17:47:29 -0700475 }
476
Robert Carre12aece2016-02-02 22:43:27 -0800477 void destroySurfaces() {
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700478 destroySurfaces(false /*cleanupOnResume*/);
479 }
480
481 /**
482 * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure
483 * the client has finished with them.
484 *
485 * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If
486 * set to true, destroy only surfaces of removed windows, and clear relevant flags of the
487 * others so that they are ready to be reused. If set to false (common case), destroy all
488 * surfaces that's eligible, if the app is already stopped.
489 */
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700490 private void destroySurfaces(boolean cleanupOnResume) {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700491 boolean destroyedSomething = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700492 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700493 final WindowState win = mChildren.get(i);
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700494 destroyedSomething |= win.destroySurface(cleanupOnResume, mAppStopped);
Robert Carre12aece2016-02-02 22:43:27 -0800495 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700496 if (destroyedSomething) {
497 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700498 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Robert Carre12aece2016-02-02 22:43:27 -0800499 }
500 }
501
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800502 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700503 * Notify that the app is now resumed, and it was not stopped before, perform a clean
504 * up of the surfaces
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800505 */
Chong Zhangad24f962016-08-25 12:12:33 -0700506 void notifyAppResumed(boolean wasStopped, boolean allowSavedSurface) {
507 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped
508 + " allowSavedSurface=" + allowSavedSurface + " " + this);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700509 mAppStopped = false;
510 if (!wasStopped) {
511 destroySurfaces(true /*cleanupOnResume*/);
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800512 }
Chong Zhangad24f962016-08-25 12:12:33 -0700513 if (!allowSavedSurface) {
514 destroySavedSurfaces();
515 }
Robert Carre12aece2016-02-02 22:43:27 -0800516 }
517
Chong Zhangbef461f2015-10-27 11:38:24 -0700518 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700519 * Notify that the app has stopped, and it is okay to destroy any surfaces which were
520 * keeping alive in case they were still being used.
521 */
522 void notifyAppStopped() {
523 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this);
524 mAppStopped = true;
525 destroySurfaces();
526 // Remove any starting window that was added for this app if they are still around.
527 mTask.mService.scheduleRemoveStartingWindowLocked(this);
528 }
529
530 /**
Chong Zhangbef461f2015-10-27 11:38:24 -0700531 * Checks whether we should save surfaces for this app.
532 *
533 * @return true if the surfaces should be saved, false otherwise.
534 */
535 boolean shouldSaveSurface() {
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800536 // We want to save surface if the app's windows are "allDrawn".
537 // (If we started entering animation early with saved surfaces, allDrawn
538 // should have been restored to true. So we'll save again in that case
539 // even if app didn't actually finish drawing.)
540 return allDrawn;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800541 }
542
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700543 private boolean canRestoreSurfaces() {
544 for (int i = mChildren.size() -1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700545 final WindowState w = mChildren.get(i);
Chong Zhang92147042016-05-09 12:47:11 -0700546 if (w.canRestoreSurface()) {
Robert Carr13f7be9e2015-12-02 18:39:45 -0800547 return true;
548 }
Chong Zhangbef461f2015-10-27 11:38:24 -0700549 }
550 return false;
551 }
552
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700553 private void clearWasVisibleBeforeClientHidden() {
554 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700555 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700556 w.clearWasVisibleBeforeClientHidden();
Chong Zhang92147042016-05-09 12:47:11 -0700557 }
558 }
559
Chong Zhang8e4bda92016-05-04 15:08:18 -0700560 /**
561 * Whether the app has some window that is invisible in layout, but
562 * animating with saved surface.
563 */
564 boolean isAnimatingInvisibleWithSavedSurface() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700565 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700566 final WindowState w = mChildren.get(i);
Chong Zhang8e4bda92016-05-04 15:08:18 -0700567 if (w.isAnimatingInvisibleWithSavedSurface()) {
568 return true;
569 }
570 }
571 return false;
572 }
573
574 /**
575 * Hide all window surfaces that's still invisible in layout but animating
576 * with a saved surface, and mark them destroying.
577 */
578 void stopUsingSavedSurfaceLocked() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700579 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700580 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700581 w.stopUsingSavedSurface();
Chong Zhang8e4bda92016-05-04 15:08:18 -0700582 }
583 destroySurfaces();
584 }
585
Chong Zhangf58631a2016-05-24 16:02:10 -0700586 void markSavedSurfaceExiting() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700587 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.markSavedSurfaceExiting();
Chong Zhangf58631a2016-05-24 16:02:10 -0700590 }
591 }
592
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700593 void restoreSavedSurfaceForInterestingWindows() {
Chong Zhang92147042016-05-09 12:47:11 -0700594 if (!canRestoreSurfaces()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700595 clearWasVisibleBeforeClientHidden();
Chong Zhangbef461f2015-10-27 11:38:24 -0700596 return;
597 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700598
599 // Check if all interesting windows are drawn and we can mark allDrawn=true.
600 int interestingNotDrawn = -1;
601
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700602 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700603 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700604 interestingNotDrawn = w.restoreSavedSurfaceForInterestingWindow();
Chong Zhangbef461f2015-10-27 11:38:24 -0700605 }
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800606
Chong Zhang92147042016-05-09 12:47:11 -0700607 if (!allDrawn) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700608 allDrawn = (interestingNotDrawn == 0);
Chong Zhang92147042016-05-09 12:47:11 -0700609 if (allDrawn) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700610 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Chong Zhang92147042016-05-09 12:47:11 -0700611 }
612 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700613 clearWasVisibleBeforeClientHidden();
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800614
615 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700616 "restoreSavedSurfaceForInterestingWindows: " + this + " allDrawn=" + allDrawn
617 + " interestingNotDrawn=" + interestingNotDrawn);
Chong Zhangbef461f2015-10-27 11:38:24 -0700618 }
619
620 void destroySavedSurfaces() {
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 win = mChildren.get(i);
Robert Carr13f7be9e2015-12-02 18:39:45 -0800623 win.destroySavedSurface();
Chong Zhangbef461f2015-10-27 11:38:24 -0700624 }
Chong Zhang92147042016-05-09 12:47:11 -0700625 }
626
627 void clearAllDrawn() {
628 allDrawn = false;
629 deferClearAllDrawn = false;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700630 allDrawnExcludingSaved = false;
Chong Zhangbef461f2015-10-27 11:38:24 -0700631 }
632
Wale Ogunwalefa854eb2016-09-20 13:43:52 -0700633 void postWindowRemoveStartingWindowCleanup(WindowState win) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700634 // TODO: Something smells about the code below...Is there a better way?
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700635 if (startingWindow == win) {
636 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700637 mService.scheduleRemoveStartingWindowLocked(this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700638 } else if (mChildren.size() == 0 && startingData != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700639 // If this is the last window and we had requested a starting transition window,
640 // well there is no point now.
641 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingWindow");
642 startingData = null;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700643 } else if (mChildren.size() == 1 && startingView != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700644 // If this is the last window except for a starting transition window,
645 // we need to get rid of the starting transition.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700646 mService.scheduleRemoveStartingWindowLocked(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700647 }
648 }
649
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700650 void removeDeadWindows() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700651 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700652 WindowState win = mChildren.get(winNdx);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800653 if (win.mAppDied) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700654 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700655 "removeDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800656 // Set mDestroying, we don't want any animation or delayed removal here.
657 win.mDestroying = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700658 // Also removes child windows.
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700659 win.removeIfPossible();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800660 }
661 }
662 }
663
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700664 boolean hasWindowsAlive() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700665 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700666 // No need to loop through child windows as the answer should be the same as that of the
667 // parent window.
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700668 if (!(mChildren.get(i)).mAppDied) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700669 return true;
670 }
671 }
672 return false;
673 }
674
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700675 void setWillReplaceWindows(boolean animate) {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700676 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
677 "Marking app token " + this + " with replacing windows.");
Robert Carra1eb4392015-12-10 12:43:51 -0800678
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700679 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700680 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700681 w.setWillReplaceWindow(animate);
Robert Carra1eb4392015-12-10 12:43:51 -0800682 }
683 if (animate) {
684 // Set-up dummy animation so we can start treating windows associated with this
685 // token like they are in transition before the new app window is ready for us to
686 // run the real transition animation.
687 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700688 "setWillReplaceWindow() Setting dummy animation on: " + this);
Robert Carra1eb4392015-12-10 12:43:51 -0800689 mAppAnimator.setDummyAnimation();
690 }
691 }
692
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700693 void setWillReplaceChildWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700694 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this
Robert Carr23fa16b2016-01-13 13:19:58 -0800695 + " with replacing child windows.");
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700696 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700697 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700698 w.setWillReplaceChildWindows();
Robert Carr23fa16b2016-01-13 13:19:58 -0800699 }
700 }
701
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700702 void clearWillReplaceWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700703 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
704 "Resetting app token " + this + " of replacing window marks.");
Chong Zhangf596cd52016-01-05 13:42:44 -0800705
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700706 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700707 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700708 w.clearWillReplaceWindow();
Chong Zhangf596cd52016-01-05 13:42:44 -0800709 }
710 }
711
Chong Zhang4d7369a2016-04-25 16:09:14 -0700712 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700713 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700714 final WindowState w = mChildren.get(i);
Chong Zhang4d7369a2016-04-25 16:09:14 -0700715 w.requestUpdateWallpaperIfNeeded();
716 }
717 }
718
Chong Zhangd78ddb42016-03-02 17:01:14 -0800719 boolean isRelaunching() {
720 return mPendingRelaunchCount > 0;
721 }
722
723 void startRelaunching() {
724 if (canFreezeBounds()) {
725 freezeBounds();
726 }
727 mPendingRelaunchCount++;
728 }
729
730 void finishRelaunching() {
731 if (canFreezeBounds()) {
732 unfreezeBounds();
733 }
734 if (mPendingRelaunchCount > 0) {
735 mPendingRelaunchCount--;
736 }
737 }
738
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700739 void clearRelaunching() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700740 if (mPendingRelaunchCount == 0) {
741 return;
742 }
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700743 if (canFreezeBounds()) {
744 unfreezeBounds();
745 }
746 mPendingRelaunchCount = 0;
747 }
748
Wale Ogunwale07bcab72016-10-14 15:30:09 -0700749 /**
750 * Returns true if the new child window we are adding to this token is considered greater than
751 * the existing child window in this token in terms of z-order.
752 */
753 @Override
754 protected boolean isFirstChildWindowGreaterThanSecond(WindowState newWindow,
755 WindowState existingWindow) {
756 final int type1 = newWindow.mAttrs.type;
757 final int type2 = existingWindow.mAttrs.type;
758
759 // Base application windows should be z-ordered BELOW all other windows in the app token.
760 if (type1 == TYPE_BASE_APPLICATION && type2 != TYPE_BASE_APPLICATION) {
761 return false;
762 } else if (type1 != TYPE_BASE_APPLICATION && type2 == TYPE_BASE_APPLICATION) {
763 return true;
764 }
765
766 // Starting windows should be z-ordered ABOVE all other windows in the app token.
767 if (type1 == TYPE_APPLICATION_STARTING && type2 != TYPE_APPLICATION_STARTING) {
768 return true;
769 } else if (type1 != TYPE_APPLICATION_STARTING && type2 == TYPE_APPLICATION_STARTING) {
770 return false;
771 }
772
773 // Otherwise the new window is greater than the existing window.
774 return true;
775 }
776
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700777 @Override
Robert Carra1eb4392015-12-10 12:43:51 -0800778 void addWindow(WindowState w) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700779 super.addWindow(w);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700780
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700781 boolean gotReplacementWindow = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700782 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700783 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700784 gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w);
785 }
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700786
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700787 // if we got a replacement window, reset the timeout to give drawing more time
788 if (gotReplacementWindow) {
789 mService.scheduleWindowReplacementTimeouts(this);
Robert Carra1eb4392015-12-10 12:43:51 -0800790 }
Jorim Jaggife762342016-10-13 14:33:27 +0200791 checkKeyguardFlagsChanged();
792 }
793
794 @Override
795 void removeChild(WindowState child) {
796 super.removeChild(child);
797 checkKeyguardFlagsChanged();
Robert Carra1eb4392015-12-10 12:43:51 -0800798 }
799
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700800 private boolean waitingForReplacement() {
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 if (candidate.waitingForReplacement()) {
Robert Carra1eb4392015-12-10 12:43:51 -0800804 return true;
805 }
806 }
807 return false;
808 }
809
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700810 void onWindowReplacementTimeout() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700811 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700812 (mChildren.get(i)).onWindowReplacementTimeout();
Robert Carra1eb4392015-12-10 12:43:51 -0800813 }
814 }
815
Chong Zhangd78ddb42016-03-02 17:01:14 -0800816 private boolean canFreezeBounds() {
817 // For freeform windows, we can't freeze the bounds at the moment because this would make
818 // the resizing unresponsive.
819 return mTask != null && !mTask.inFreeformWorkspace();
820 }
821
Jorim Jaggi0429f352015-12-22 16:29:16 +0100822 /**
823 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
824 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
825 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
826 * with a queue.
827 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800828 private void freezeBounds() {
Jorim Jaggi0429f352015-12-22 16:29:16 +0100829 mFrozenBounds.offer(new Rect(mTask.mPreparedFrozenBounds));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700830
831 if (mTask.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) {
832 // We didn't call prepareFreezingBounds on the task, so use the current value.
Andrii Kulian441e4492016-09-29 15:25:00 -0700833 mFrozenMergedConfig.offer(new Configuration(mTask.getConfiguration()));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700834 } else {
835 mFrozenMergedConfig.offer(new Configuration(mTask.mPreparedFrozenMergedConfig));
836 }
Andrii Kulianb10330d2016-09-16 13:51:46 -0700837 // Calling unset() to make it equal to Configuration.EMPTY.
838 mTask.mPreparedFrozenMergedConfig.unset();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100839 }
840
841 /**
842 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
843 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800844 private void unfreezeBounds() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700845 if (!mFrozenBounds.isEmpty()) {
846 mFrozenBounds.remove();
847 }
848 if (!mFrozenMergedConfig.isEmpty()) {
849 mFrozenMergedConfig.remove();
850 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700851 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700852 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700853 win.onUnfreezeBounds();
Jorim Jaggi4846ee32016-01-07 17:39:12 +0100854 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700855 mService.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100856 }
857
Robert Carr91b228092016-06-28 17:32:37 -0700858 void addSurfaceViewBackground(WindowSurfaceController.SurfaceControlWithBackground background) {
859 mSurfaceViewBackgrounds.add(background);
860 }
861
862 void removeSurfaceViewBackground(WindowSurfaceController.SurfaceControlWithBackground background) {
863 mSurfaceViewBackgrounds.remove(background);
864 updateSurfaceViewBackgroundVisibilities();
865 }
866
867 // We use DimLayers behind SurfaceViews to prevent holes while resizing and creating.
868 // However, we need to ensure one SurfaceView doesn't cover another when they are both placed
869 // below the main app window (as traditionally a SurfaceView which is never drawn
870 // to is totally translucent). So we look at all our SurfaceView backgrounds and only enable
871 // the background for the SurfaceView with lowest Z order
872 void updateSurfaceViewBackgroundVisibilities() {
873 WindowSurfaceController.SurfaceControlWithBackground bottom = null;
874 int bottomLayer = Integer.MAX_VALUE;
875 for (int i = 0; i < mSurfaceViewBackgrounds.size(); i++) {
876 WindowSurfaceController.SurfaceControlWithBackground sc = mSurfaceViewBackgrounds.get(i);
877 if (sc.mVisible && sc.mLayer < bottomLayer) {
878 bottomLayer = sc.mLayer;
879 bottom = sc;
880 }
881 }
882 for (int i = 0; i < mSurfaceViewBackgrounds.size(); i++) {
883 WindowSurfaceController.SurfaceControlWithBackground sc = mSurfaceViewBackgrounds.get(i);
884 sc.updateBackgroundVisibility(sc != bottom);
885 }
886 }
887
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700888 void resetJustMovedInStack() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700889 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700890 (mChildren.get(i)).resetJustMovedInStack();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700891 }
892 }
893
894 void notifyMovedInStack() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700895 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700896 final WindowState win = mChildren.get(winNdx);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700897 win.notifyMovedInStack();
898 }
899 }
900
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700901 void setAppLayoutChanges(int changes, String reason) {
902 if (!mChildren.isEmpty()) {
903 final DisplayContent dc = getDisplayContent();
904 dc.pendingLayoutChanges |= changes;
905 if (DEBUG_LAYOUT_REPEATS) {
906 mService.mWindowPlacerLocked.debugLayoutRepeats(reason, dc.pendingLayoutChanges);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700907 }
908 }
909 }
910
911 void removeReplacedWindowIfNeeded(WindowState replacement) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700912 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700913 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700914 if (win.removeReplacedWindowIfNeeded(replacement)) {
915 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700916 }
917 }
918 }
919
920 void startFreezingScreen() {
921 if (DEBUG_ORIENTATION) logWithStack(TAG, "Set freezing of " + appToken + ": hidden="
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700922 + hidden + " freezing=" + mAppAnimator.freezingScreen + " hiddenRequested="
923 + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700924 if (!hiddenRequested) {
925 if (!mAppAnimator.freezingScreen) {
926 mAppAnimator.freezingScreen = true;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700927 mService.registerAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700928 mAppAnimator.lastFreezeDuration = 0;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700929 mService.mAppsFreezingScreen++;
930 if (mService.mAppsFreezingScreen == 1) {
931 mService.startFreezingDisplayLocked(false, 0, 0);
932 mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT);
933 mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700934 }
935 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700936 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700937 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700938 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700939 w.onStartFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700940 }
941 }
942 }
943
944 void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) {
945 if (!mAppAnimator.freezingScreen) {
946 return;
947 }
948 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + this + " force=" + force);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700949 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700950 boolean unfrozeWindows = false;
951 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700952 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700953 unfrozeWindows |= w.onStopFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700954 }
955 if (force || unfrozeWindows) {
956 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this);
957 mAppAnimator.freezingScreen = false;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700958 mService.unregisterAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700959 mAppAnimator.lastFreezeDuration =
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700960 (int)(SystemClock.elapsedRealtime() - mService.mDisplayFreezeTime);
961 mService.mAppsFreezingScreen--;
962 mService.mLastFinishedFreezeSource = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700963 }
964 if (unfreezeSurfaceNow) {
965 if (unfrozeWindows) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700966 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700967 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700968 mService.stopFreezingDisplayLocked();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700969 }
970 }
971
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700972 @Override
973 public void onAppFreezeTimeout() {
974 Slog.w(TAG_WM, "Force clearing freeze: " + this);
975 stopFreezingScreen(true, true);
976 }
977
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700978 boolean transferStartingWindow(IBinder transferFrom) {
Wale Ogunwale02319a62016-09-26 15:21:22 -0700979 final AppWindowToken fromToken = getDisplayContent().getAppWindowToken(transferFrom);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700980 if (fromToken == null) {
981 return false;
982 }
983
984 final WindowState tStartingWindow = fromToken.startingWindow;
985 if (tStartingWindow != null && fromToken.startingView != null) {
986 // In this case, the starting icon has already been displayed, so start
987 // letting windows get shown immediately without any more transitions.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700988 mService.mSkipAppTransitionAnimation = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700989
990 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow
991 + " from " + fromToken + " to " + this);
992
993 final long origId = Binder.clearCallingIdentity();
994
995 // Transfer the starting window over to the new token.
996 startingData = fromToken.startingData;
997 startingView = fromToken.startingView;
998 startingDisplayed = fromToken.startingDisplayed;
999 fromToken.startingDisplayed = false;
1000 startingWindow = tStartingWindow;
1001 reportedVisible = fromToken.reportedVisible;
1002 fromToken.startingData = null;
1003 fromToken.startingView = null;
1004 fromToken.startingWindow = null;
1005 fromToken.startingMoved = true;
1006 tStartingWindow.mToken = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001007 tStartingWindow.mAppToken = this;
1008
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001009 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1010 "Removing starting window: " + tStartingWindow);
1011 getDisplayContent().removeFromWindowList(tStartingWindow);
1012 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001013 "Removing starting " + tStartingWindow + " from " + fromToken);
Wale Ogunwalefa854eb2016-09-20 13:43:52 -07001014 fromToken.removeChild(tStartingWindow);
1015 fromToken.postWindowRemoveStartingWindowCleanup(tStartingWindow);
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001016 addWindow(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001017
1018 // Propagate other interesting state between the tokens. If the old token is displayed,
1019 // we should immediately force the new one to be displayed. If it is animating, we need
1020 // to move that animation to the new one.
1021 if (fromToken.allDrawn) {
1022 allDrawn = true;
1023 deferClearAllDrawn = fromToken.deferClearAllDrawn;
1024 }
1025 if (fromToken.firstWindowDrawn) {
1026 firstWindowDrawn = true;
1027 }
1028 if (!fromToken.hidden) {
1029 hidden = false;
1030 hiddenRequested = false;
1031 }
1032 if (clientHidden != fromToken.clientHidden) {
1033 clientHidden = fromToken.clientHidden;
1034 sendAppVisibilityToClients();
1035 }
1036 fromToken.mAppAnimator.transferCurrentAnimation(
1037 mAppAnimator, tStartingWindow.mWinAnimator);
1038
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001039 mService.updateFocusedWindowLocked(
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001040 UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/);
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001041 getDisplayContent().setLayoutNeeded();
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001042 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001043 Binder.restoreCallingIdentity(origId);
1044 return true;
1045 } else if (fromToken.startingData != null) {
1046 // The previous app was getting ready to show a
1047 // starting window, but hasn't yet done so. Steal it!
1048 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1049 "Moving pending starting from " + fromToken + " to " + this);
1050 startingData = fromToken.startingData;
1051 fromToken.startingData = null;
1052 fromToken.startingMoved = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001053 final Message m = mService.mH.obtainMessage(H.ADD_STARTING, this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001054 // Note: we really want to do sendMessageAtFrontOfQueue() because we want to process the
1055 // message ASAP, before any other queued messages.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001056 mService.mH.sendMessageAtFrontOfQueue(m);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001057 return true;
1058 }
1059
1060 final AppWindowAnimator tAppAnimator = fromToken.mAppAnimator;
1061 final AppWindowAnimator wAppAnimator = mAppAnimator;
1062 if (tAppAnimator.thumbnail != null) {
1063 // The old token is animating with a thumbnail, transfer that to the new token.
1064 if (wAppAnimator.thumbnail != null) {
1065 wAppAnimator.thumbnail.destroy();
1066 }
1067 wAppAnimator.thumbnail = tAppAnimator.thumbnail;
1068 wAppAnimator.thumbnailLayer = tAppAnimator.thumbnailLayer;
1069 wAppAnimator.thumbnailAnimation = tAppAnimator.thumbnailAnimation;
1070 tAppAnimator.thumbnail = null;
1071 }
1072 return false;
1073 }
1074
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001075 boolean isLastWindow(WindowState win) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001076 return mChildren.size() == 1 && mChildren.get(0) == win;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001077 }
1078
1079 void setAllAppWinAnimators() {
1080 final ArrayList<WindowStateAnimator> allAppWinAnimators = mAppAnimator.mAllAppWinAnimators;
1081 allAppWinAnimators.clear();
1082
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001083 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001084 for (int j = 0; j < windowsCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001085 (mChildren.get(j)).addWinAnimatorToList(allAppWinAnimators);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001086 }
1087 }
1088
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001089 @Override
1090 void onAppTransitionDone() {
1091 sendingToBottom = false;
1092 }
1093
Wale Ogunwale51362492016-09-08 17:49:17 -07001094 /**
1095 * We override because this class doesn't want its children affecting its reported orientation
1096 * in anyway.
1097 */
1098 @Override
1099 int getOrientation() {
1100 if (hidden || hiddenRequested) {
1101 return SCREEN_ORIENTATION_UNSET;
1102 }
1103 return mOrientation;
1104 }
1105
Wale Ogunwaleb198b742016-12-01 08:44:09 -08001106 /** Returns the app's preferred orientation regardless of its currently visibility state. */
1107 int getOrientationIgnoreVisibility() {
1108 return mOrientation;
1109 }
1110
Craig Mautnerdbb79912012-03-01 18:59:14 -08001111 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001112 void checkAppWindowsReadyToShow() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001113 if (allDrawn == mAppAnimator.allDrawn) {
1114 return;
1115 }
1116
1117 mAppAnimator.allDrawn = allDrawn;
1118 if (!allDrawn) {
1119 return;
1120 }
1121
1122 // The token has now changed state to having all windows shown... what to do, what to do?
1123 if (mAppAnimator.freezingScreen) {
1124 mAppAnimator.showAllWindowsLocked();
1125 stopFreezingScreen(false, true);
1126 if (DEBUG_ORIENTATION) Slog.i(TAG,
1127 "Setting mOrientationChangeComplete=true because wtoken " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001128 + " numInteresting=" + mNumInterestingWindows + " numDrawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001129 // This will set mOrientationChangeComplete and cause a pass through layout.
1130 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001131 "checkAppWindowsReadyToShow: freezingScreen");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001132 } else {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001133 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001134
1135 // We can now show all of the drawn windows!
1136 if (!mService.mOpeningApps.contains(this)) {
1137 mService.mAnimator.orAnimating(mAppAnimator.showAllWindowsLocked());
1138 }
1139 }
1140 }
1141
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001142 void updateAllDrawn(DisplayContent dc) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001143 if (!allDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001144 final int numInteresting = mNumInterestingWindows;
1145 if (numInteresting > 0 && mNumDrawnWindows >= numInteresting) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001146 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawn: " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001147 + " interesting=" + numInteresting + " drawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001148 allDrawn = true;
1149 // Force an additional layout pass where
1150 // WindowStateAnimator#commitFinishDrawingLocked() will call performShowLocked().
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001151 dc.setLayoutNeeded();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001152 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
1153 }
1154 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001155
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001156 if (!allDrawnExcludingSaved) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001157 int numInteresting = mNumInterestingWindowsExcludingSaved;
1158 if (numInteresting > 0 && mNumDrawnWindowsExcludingSaved >= numInteresting) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001159 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawnExcludingSaved: " + this
1160 + " interesting=" + numInteresting
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001161 + " drawn=" + mNumDrawnWindowsExcludingSaved);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001162 allDrawnExcludingSaved = true;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001163 dc.setLayoutNeeded();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001164 if (isAnimatingInvisibleWithSavedSurface()
1165 && !mService.mFinishedEarlyAnim.contains(this)) {
1166 mService.mFinishedEarlyAnim.add(this);
1167 }
1168 }
1169 }
1170 }
1171
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001172 /**
1173 * Updated this app token tracking states for interesting and drawn windows based on the window.
1174 *
1175 * @return Returns true if the input window is considered interesting and drawn while all the
1176 * windows in this app token where not considered drawn as of the last pass.
1177 */
1178 boolean updateDrawnWindowStates(WindowState w) {
1179 if (DEBUG_STARTING_WINDOW && w == startingWindow) {
1180 Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" + w.isOnScreen()
1181 + " allDrawn=" + allDrawn + " freezingScreen=" + mAppAnimator.freezingScreen);
1182 }
1183
1184 if (allDrawn && allDrawnExcludingSaved && !mAppAnimator.freezingScreen) {
1185 return false;
1186 }
1187
1188 if (mLastTransactionSequence != mService.mTransactionSequence) {
1189 mLastTransactionSequence = mService.mTransactionSequence;
1190 mNumInterestingWindows = mNumDrawnWindows = 0;
1191 mNumInterestingWindowsExcludingSaved = 0;
1192 mNumDrawnWindowsExcludingSaved = 0;
1193 startingDisplayed = false;
1194 }
1195
1196 final WindowStateAnimator winAnimator = w.mWinAnimator;
1197
1198 boolean isInterestingAndDrawn = false;
1199
1200 if (!allDrawn && w.mightAffectAllDrawn(false /* visibleOnly */)) {
1201 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
1202 Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw()
1203 + ", isAnimationSet=" + winAnimator.isAnimationSet());
1204 if (!w.isDrawnLw()) {
1205 Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController
1206 + " pv=" + w.mPolicyVisibility
1207 + " mDrawState=" + winAnimator.drawStateToString()
1208 + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested
1209 + " a=" + winAnimator.mAnimating);
1210 }
1211 }
1212
1213 if (w != startingWindow) {
1214 if (w.isInteresting()) {
1215 mNumInterestingWindows++;
1216 if (w.isDrawnLw()) {
1217 mNumDrawnWindows++;
1218
1219 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, "tokenMayBeDrawn: "
1220 + this + " w=" + w + " numInteresting=" + mNumInterestingWindows
1221 + " freezingScreen=" + mAppAnimator.freezingScreen
1222 + " mAppFreezing=" + w.mAppFreezing);
1223
1224 isInterestingAndDrawn = true;
1225 }
1226 }
1227 } else if (w.isDrawnLw()) {
1228 mService.mH.sendEmptyMessage(NOTIFY_STARTING_WINDOW_DRAWN);
1229 startingDisplayed = true;
1230 }
1231 }
1232
1233 if (!allDrawnExcludingSaved && w.mightAffectAllDrawn(true /* visibleOnly */)) {
1234 if (w != startingWindow && w.isInteresting()) {
1235 mNumInterestingWindowsExcludingSaved++;
1236 if (w.isDrawnLw() && !w.isAnimatingWithSavedSurface()) {
1237 mNumDrawnWindowsExcludingSaved++;
1238
1239 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
1240 "tokenMayBeDrawnExcludingSaved: " + this + " w=" + w
1241 + " numInteresting=" + mNumInterestingWindowsExcludingSaved
1242 + " freezingScreen=" + mAppAnimator.freezingScreen
1243 + " mAppFreezing=" + w.mAppFreezing);
1244
1245 isInterestingAndDrawn = true;
1246 }
1247 }
1248 }
1249
1250 return isInterestingAndDrawn;
1251 }
1252
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001253 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001254 void stepAppWindowsAnimation(long currentTime) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001255 mAppAnimator.wasAnimating = mAppAnimator.animating;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001256 if (mAppAnimator.stepAnimationLocked(currentTime)) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001257 mAppAnimator.animating = true;
1258 mService.mAnimator.setAnimating(true);
1259 mService.mAnimator.mAppWindowAnimating = true;
1260 } else if (mAppAnimator.wasAnimating) {
1261 // stopped animating, do one more pass through the layout
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001262 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER, "appToken " + this + " done");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001263 if (DEBUG_ANIM) Slog.v(TAG, "updateWindowsApps...: done animating " + this);
1264 }
1265 }
1266
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001267 int rebuildWindowListUnchecked(int addIndex) {
1268 return super.rebuildWindowList(addIndex);
1269 }
1270
1271 @Override
1272 int rebuildWindowList(int addIndex) {
1273 if (mIsExiting && !waitingForReplacement()) {
1274 return addIndex;
1275 }
1276 return rebuildWindowListUnchecked(addIndex);
1277 }
1278
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001279 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001280 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001281 // For legacy reasons we process the TaskStack.mExitingAppTokens first in DisplayContent
1282 // before the non-exiting app tokens. So, we skip the exiting app tokens here.
1283 // TODO: Investigate if we need to continue to do this or if we can just process them
1284 // in-order.
1285 if (mIsExiting && !waitingForReplacement()) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001286 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001287 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001288 return forAllWindowsUnchecked(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001289 }
1290
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001291 boolean forAllWindowsUnchecked(ToBooleanFunction<WindowState> callback,
1292 boolean traverseTopToBottom) {
1293 return super.forAllWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001294 }
1295
1296 @Override
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001297 AppWindowToken asAppWindowToken() {
1298 // I am an app window token!
1299 return this;
1300 }
1301
1302 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -07001303 boolean fillsParent() {
1304 return mFillsParent;
1305 }
1306
1307 void setFillsParent(boolean fillsParent) {
1308 mFillsParent = fillsParent;
1309 }
1310
Jorim Jaggife762342016-10-13 14:33:27 +02001311 boolean containsDismissKeyguardWindow() {
1312 for (int i = mChildren.size() - 1; i >= 0; i--) {
1313 if ((mChildren.get(i).mAttrs.flags & FLAG_DISMISS_KEYGUARD) != 0) {
1314 return true;
1315 }
1316 }
1317 return false;
1318 }
1319
1320 boolean containsShowWhenLockedWindow() {
1321 for (int i = mChildren.size() - 1; i >= 0; i--) {
1322 if ((mChildren.get(i).mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
1323 return true;
1324 }
1325 }
1326 return false;
1327 }
1328
1329 void checkKeyguardFlagsChanged() {
1330 final boolean containsDismissKeyguard = containsDismissKeyguardWindow();
1331 final boolean containsShowWhenLocked = containsShowWhenLockedWindow();
1332 if (containsDismissKeyguard != mLastContainsDismissKeyguardWindow
1333 || containsShowWhenLocked != mLastContainsShowWhenLockedWindow) {
1334 mService.notifyKeyguardFlagsChanged(null /* callback */);
1335 }
1336 mLastContainsDismissKeyguardWindow = containsDismissKeyguard;
1337 mLastContainsShowWhenLockedWindow = containsShowWhenLocked;
1338 }
1339
Wale Ogunwale51362492016-09-08 17:49:17 -07001340 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001341 void dump(PrintWriter pw, String prefix) {
1342 super.dump(pw, prefix);
1343 if (appToken != null) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001344 pw.print(prefix); pw.print("app=true voiceInteraction="); pw.println(voiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001345 }
Craig Mautner83162a92015-01-26 14:43:30 -08001346 pw.print(prefix); pw.print("task="); pw.println(mTask);
Wale Ogunwale51362492016-09-08 17:49:17 -07001347 pw.print(prefix); pw.print(" mFillsParent="); pw.print(mFillsParent);
1348 pw.print(" mOrientation="); pw.println(mOrientation);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001349 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
1350 pw.print(" clientHidden="); pw.print(clientHidden);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -07001351 pw.print(" reportedDrawn="); pw.print(reportedDrawn);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001352 pw.print(" reportedVisible="); pw.println(reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -07001353 if (paused) {
1354 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001355 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001356 if (mAppStopped) {
1357 pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped);
1358 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001359 if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0
Craig Mautner6fbda632012-07-03 09:26:39 -07001360 || allDrawn || mAppAnimator.allDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001361 pw.print(prefix); pw.print("mNumInterestingWindows=");
1362 pw.print(mNumInterestingWindows);
1363 pw.print(" mNumDrawnWindows="); pw.print(mNumDrawnWindows);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001364 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -07001365 pw.print(" allDrawn="); pw.print(allDrawn);
1366 pw.print(" (animator="); pw.print(mAppAnimator.allDrawn);
1367 pw.println(")");
1368 }
1369 if (inPendingTransaction) {
1370 pw.print(prefix); pw.print("inPendingTransaction=");
1371 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001372 }
Craig Mautner799bc1d2015-01-14 10:33:48 -08001373 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001374 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
1375 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -08001376 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -08001377 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001378 }
1379 if (startingWindow != null || startingView != null
1380 || startingDisplayed || startingMoved) {
1381 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
1382 pw.print(" startingView="); pw.print(startingView);
1383 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001384 pw.print(" startingMoved="); pw.println(startingMoved);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001385 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01001386 if (!mFrozenBounds.isEmpty()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -08001387 pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds);
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001388 pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig);
Chong Zhangd78ddb42016-03-02 17:01:14 -08001389 }
1390 if (mPendingRelaunchCount != 0) {
1391 pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount);
Jorim Jaggi0429f352015-12-22 16:29:16 +01001392 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001393 }
1394
1395 @Override
1396 public String toString() {
1397 if (stringName == null) {
1398 StringBuilder sb = new StringBuilder();
1399 sb.append("AppWindowToken{");
1400 sb.append(Integer.toHexString(System.identityHashCode(this)));
1401 sb.append(" token="); sb.append(token); sb.append('}');
1402 stringName = sb.toString();
1403 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001404 return stringName + ((mIsExiting) ? " mIsExiting=" : "");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001405 }
Jeff Browne9bdb312012-04-05 15:30:10 -07001406}