blob: 518b9b5618d339daa1d1fbd71eeeafafd0ff990a [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 Ogunwale9f25bee2016-08-02 07:23:47 -070020import static android.view.Display.DEFAULT_DISPLAY;
Wale Ogunwaled1c37912016-08-16 03:19:39 -070021import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080022import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070023import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080024import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
25import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
Robert Carra1eb4392015-12-10 12:43:51 -080026import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070027import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
28import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
Wale Ogunwale9017ec02016-02-25 08:55:25 -080029import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080030import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
31import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_MOVEMENT;
32import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
33import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Chong Zhang92147042016-05-09 12:47:11 -070034import static com.android.server.wm.WindowManagerService.H.NOTIFY_ACTIVITY_DRAWN;
Jorim Jaggi6626f542016-08-22 13:08:44 -070035import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_NONE;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070036import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070037import static com.android.server.wm.WindowManagerService.logWithStack;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080038
Jeff Brown4532e612012-04-05 14:27:12 -070039import com.android.server.input.InputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080040import com.android.server.wm.WindowManagerService.H;
41
Filip Gruszczynskia590c992015-11-25 16:45:26 -080042import android.annotation.NonNull;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080043import android.content.pm.ActivityInfo;
Jorim Jaggi26c8c422016-05-09 19:57:25 -070044import android.content.res.Configuration;
Jorim Jaggi0429f352015-12-22 16:29:16 +010045import android.graphics.Rect;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070046import android.os.Binder;
47import android.os.IBinder;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080048import android.os.Message;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070049import android.os.SystemClock;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080050import android.util.Slog;
51import android.view.IApplicationToken;
52import android.view.View;
53import android.view.WindowManager;
Jorim Jaggi6626f542016-08-22 13:08:44 -070054import android.view.animation.Animation;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080055
56import java.io.PrintWriter;
Jorim Jaggi0429f352015-12-22 16:29:16 +010057import java.util.ArrayDeque;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080058import java.util.ArrayList;
59
60class AppTokenList extends ArrayList<AppWindowToken> {
61}
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080062
63/**
64 * Version of WindowToken that is specifically for a particular application (or
65 * really activity) that is displaying windows.
66 */
Craig Mautnere32c3072012-03-12 15:25:35 -070067class AppWindowToken extends WindowToken {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080068 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppWindowToken" : TAG_WM;
69
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080070 // Non-null only for application tokens.
71 final IApplicationToken appToken;
72
Filip Gruszczynskia590c992015-11-25 16:45:26 -080073 @NonNull final AppWindowAnimator mAppAnimator;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -070074
Dianne Hackborne30e02f2014-05-27 18:24:45 -070075 final boolean voiceInteraction;
76
Craig Mautner83162a92015-01-26 14:43:30 -080077 Task mTask;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080078 boolean appFullscreen;
79 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Craig Mautner4c5eb222013-11-18 12:59:05 -080080 boolean layoutConfigChanges;
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -070081 boolean showForAllUsers;
Yorke Lee0e852472016-06-15 10:03:18 -070082 int targetSdk;
Craig Mautnera2c77052012-03-26 12:14:43 -070083
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080084 // The input dispatching timeout for this application token in nanoseconds.
85 long inputDispatchingTimeoutNanos;
86
87 // These are used for determining when all windows associated with
88 // an activity have been drawn, so they can be made visible together
89 // at the same time.
Craig Mautner764983d2012-03-22 11:37:36 -070090 // initialize so that it doesn't match mTransactionSequence which is an int.
91 long lastTransactionSequence = Long.MIN_VALUE;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080092 int numInterestingWindows;
93 int numDrawnWindows;
94 boolean inPendingTransaction;
95 boolean allDrawn;
Craig Mautner7636dfb2012-11-16 15:24:11 -080096 // Set to true when this app creates a surface while in the middle of an animation. In that
97 // case do not clear allDrawn until the animation completes.
98 boolean deferClearAllDrawn;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080099
Chong Zhang8e4bda92016-05-04 15:08:18 -0700100 // These are to track the app's real drawing status if there were no saved surfaces.
101 boolean allDrawnExcludingSaved;
102 int numInterestingWindowsExcludingSaved;
103 int numDrawnWindowsExclusingSaved;
104
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800105 // Is this window's surface needed? This is almost like hidden, except
106 // it will sometimes be true a little earlier: when the token has
107 // been shown, but is still waiting for its app transition to execute
108 // before making its windows shown.
109 boolean hiddenRequested;
110
111 // Have we told the window clients to hide themselves?
112 boolean clientHidden;
113
114 // Last visibility state we reported to the app token.
115 boolean reportedVisible;
116
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700117 // Last drawn state we reported to the app token.
118 boolean reportedDrawn;
119
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800120 // Set to true when the token has been removed from the window mgr.
121 boolean removed;
122
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800123 // Information about an application starting window if displayed.
124 StartingData startingData;
125 WindowState startingWindow;
126 View startingView;
127 boolean startingDisplayed;
128 boolean startingMoved;
129 boolean firstWindowDrawn;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700130 private final WindowState.UpdateReportedVisibilityResults mReportedVisibilityResults =
131 new WindowState.UpdateReportedVisibilityResults();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800132
133 // Input application handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700134 final InputApplicationHandle mInputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800135
Craig Mautner799bc1d2015-01-14 10:33:48 -0800136 boolean mIsExiting;
Craig Mautner9ef471f2014-02-07 13:11:47 -0800137
Craig Mautnerbb742462014-07-07 15:28:55 -0700138 boolean mLaunchTaskBehind;
Craig Mautner8746a472014-07-24 15:12:54 -0700139 boolean mEnteringAnimation;
Craig Mautnerbb742462014-07-07 15:28:55 -0700140
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800141 boolean mAlwaysFocusable;
142
Robert Carre12aece2016-02-02 22:43:27 -0800143 boolean mAppStopped;
Robert Carrfd10cd12016-06-29 16:41:50 -0700144 int mRotationAnimationHint;
Chong Zhangd78ddb42016-03-02 17:01:14 -0800145 int mPendingRelaunchCount;
Robert Carre12aece2016-02-02 22:43:27 -0800146
Robert Carr91b228092016-06-28 17:32:37 -0700147 private ArrayList<WindowSurfaceController.SurfaceControlWithBackground> mSurfaceViewBackgrounds =
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700148 new ArrayList<>();
Robert Carr91b228092016-06-28 17:32:37 -0700149
Jorim Jaggi0429f352015-12-22 16:29:16 +0100150 ArrayDeque<Rect> mFrozenBounds = new ArrayDeque<>();
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700151 ArrayDeque<Configuration> mFrozenMergedConfig = new ArrayDeque<>();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100152
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700153 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean _voiceInteraction) {
154 super(service, token != null ? token.asBinder() : null, TYPE_APPLICATION, true);
155 appToken = token;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700156 voiceInteraction = _voiceInteraction;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800157 mInputApplicationHandle = new InputApplicationHandle(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700158 mAppAnimator = new AppWindowAnimator(this, service);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800159 }
160
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800161 void onFirstWindowDrawn(WindowState win, WindowStateAnimator winAnimator) {
162 firstWindowDrawn = true;
163
164 // We now have a good window to show, remove dead placeholders
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700165 removeDeadWindows();
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800166
167 if (startingData != null) {
168 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, "Finish starting "
169 + win.mToken + ": first real window is shown, no animation");
170 // If this initial window is animating, stop it -- we will do an animation to reveal
171 // it from behind the starting window, so there is no need for it to also be doing its
172 // own stuff.
173 winAnimator.clearAnimation();
174 winAnimator.mService.mFinishedStarting.add(this);
175 winAnimator.mService.mH.sendEmptyMessage(H.FINISHED_STARTING);
176 }
177 updateReportedVisibilityLocked();
178 }
179
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800180 void updateReportedVisibilityLocked() {
181 if (appToken == null) {
182 return;
183 }
184
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700185 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700186 final int count = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800187
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700188 mReportedVisibilityResults.reset();
189
190 for (int i = 0; i < count; i++) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700191 final WindowState win = (WindowState) mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700192 win.updateReportedVisibility(mReportedVisibilityResults);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800193 }
194
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700195 int numInteresting = mReportedVisibilityResults.numInteresting;
196 int numVisible = mReportedVisibilityResults.numVisible;
197 int numDrawn = mReportedVisibilityResults.numDrawn;
198 boolean nowGone = mReportedVisibilityResults.nowGone;
199
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700200 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800201 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700202 if (!nowGone) {
203 // If the app is not yet gone, then it can only become visible/drawn.
204 if (!nowDrawn) {
205 nowDrawn = reportedDrawn;
206 }
207 if (!nowVisible) {
208 nowVisible = reportedVisible;
209 }
210 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800211 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800212 + numInteresting + " visible=" + numVisible);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700213 if (nowDrawn != reportedDrawn) {
214 if (nowDrawn) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700215 mService.mH.obtainMessage(H.REPORT_APPLICATION_TOKEN_DRAWN, this).sendToTarget();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700216 }
217 reportedDrawn = nowDrawn;
218 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800219 if (nowVisible != reportedVisible) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700220 if (DEBUG_VISIBILITY) Slog.v(TAG,
221 "Visibility changed in " + this + ": vis=" + nowVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800222 reportedVisible = nowVisible;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700223 mService.mH.obtainMessage(H.REPORT_APPLICATION_TOKEN_WINDOWS,
224 nowVisible ? 1 : 0, nowGone ? 1 : 0, this).sendToTarget();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800225 }
226 }
227
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700228 boolean setVisibility(WindowManager.LayoutParams lp,
229 boolean visible, int transit, boolean performLayout, boolean isVoiceInteraction) {
230
231 boolean delayed = false;
232 inPendingTransaction = false;
233
234 if (clientHidden == visible) {
235 clientHidden = !visible;
236 sendAppVisibilityToClients();
237 }
238
239 // Allow for state changes and animation to be applied if:
240 // * token is transitioning visibility state
241 // * or the token was marked as hidden and is exiting before we had a chance to play the
242 // transition animation
243 // * or this is an opening app and windows are being replaced.
244 boolean visibilityChanged = false;
245 if (hidden == visible || (hidden && mIsExiting) || (visible && waitingForReplacement())) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700246 final AccessibilityController accessibilityController = mService.mAccessibilityController;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700247 boolean changed = false;
248 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
249 "Changing app " + this + " hidden=" + hidden + " performLayout=" + performLayout);
250
251 boolean runningAppAnimation = false;
252
253 if (transit != AppTransition.TRANSIT_UNSET) {
254 if (mAppAnimator.animation == AppWindowAnimator.sDummyAnimation) {
255 mAppAnimator.setNullAnimation();
256 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700257 if (mService.applyAnimationLocked(this, lp, transit, visible, isVoiceInteraction)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700258 delayed = runningAppAnimation = true;
259 }
260 final WindowState window = findMainWindow();
261 //TODO (multidisplay): Magnification is supported only for the default display.
262 if (window != null && accessibilityController != null
263 && window.getDisplayId() == DEFAULT_DISPLAY) {
264 accessibilityController.onAppWindowTransitionLocked(window, transit);
265 }
266 changed = true;
267 }
268
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700269 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700270 for (int i = 0; i < windowsCount; i++) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700271 final WindowState win = (WindowState) mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700272 changed |= win.onAppVisibilityChanged(visible, runningAppAnimation);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700273 }
274
275 hidden = hiddenRequested = !visible;
276 visibilityChanged = true;
277 if (!visible) {
278 stopFreezingScreen(true, true);
279 } else {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700280 // If we are being set visible, and the starting window is not yet displayed,
281 // then make sure it doesn't get displayed.
282 if (startingWindow != null && !startingWindow.isDrawnLw()) {
283 startingWindow.mPolicyVisibility = false;
284 startingWindow.mPolicyVisibilityAfterAnim = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700285 }
286 }
287
288 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setVisibility: " + this
289 + ": hidden=" + hidden + " hiddenRequested=" + hiddenRequested);
290
291 if (changed) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700292 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700293 if (performLayout) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700294 mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700295 false /*updateInputWindows*/);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700296 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700297 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700298 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700299 }
300 }
301
302 if (mAppAnimator.animation != null) {
303 delayed = true;
304 }
305
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700306 for (int i = mChildren.size() - 1; i >= 0 && !delayed; i--) {
307 if (((WindowState) mChildren.get(i)).isWindowAnimationSet()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700308 delayed = true;
309 }
310 }
311
312 if (visibilityChanged) {
313 if (visible && !delayed) {
314 // The token was made immediately visible, there will be no entrance animation.
315 // We need to inform the client the enter animation was finished.
316 mEnteringAnimation = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700317 mService.mActivityManagerAppTransitionNotifier.onAppTransitionFinishedLocked(token);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700318 }
319
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700320 if (!mService.mClosingApps.contains(this) && !mService.mOpeningApps.contains(this)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700321 // The token is not closing nor opening, so even if there is an animation set, that
322 // doesn't mean that it goes through the normal app transition cycle so we have
323 // to inform the docked controller about visibility change.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700324 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700325 .notifyAppVisibilityChanged();
326 }
327 }
328
329 return delayed;
330 }
331
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800332 WindowState findMainWindow() {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700333 WindowState candidate = null;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700334 int j = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800335 while (j > 0) {
336 j--;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700337 final WindowState win = (WindowState) mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700338 final int type = win.mAttrs.type;
339 // No need to loop through child window as base application and starting types can't be
340 // child windows.
341 if (type == TYPE_BASE_APPLICATION || type == TYPE_APPLICATION_STARTING) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700342 // In cases where there are multiple windows, we prefer the non-exiting window. This
Sungsoo Lim0d3d1f82015-12-02 14:47:59 +0900343 // happens for example when replacing windows during an activity relaunch. When
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700344 // constructing the animation, we want the new window, not the exiting one.
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800345 if (win.mAnimatingExit) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700346 candidate = win;
347 } else {
348 return win;
349 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800350 }
351 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700352 return candidate;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800353 }
354
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800355 boolean windowsAreFocusable() {
356 return StackId.canReceiveKeys(mTask.mStack.mStackId) || mAlwaysFocusable;
Wale Ogunwaled045c822015-12-02 09:14:28 -0800357 }
358
Craig Mautnere3119b72015-01-20 15:02:36 -0800359 void removeAppFromTaskLocked() {
360 mIsExiting = false;
361 removeAllWindows();
362
Craig Mautner83162a92015-01-26 14:43:30 -0800363 // Use local variable because removeAppToken will null out mTask.
364 final Task task = mTask;
Craig Mautnere3119b72015-01-20 15:02:36 -0800365 if (task != null) {
366 if (!task.removeAppToken(this)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800367 Slog.e(TAG, "removeAppFromTaskLocked: token=" + this
Craig Mautnere3119b72015-01-20 15:02:36 -0800368 + " not found.");
369 }
370 task.mStack.mExitingAppTokens.remove(this);
371 }
372 }
373
Chong Zhange05bcb12016-07-26 17:47:29 -0700374 void clearAnimatingFlags() {
Chong Zhangb0d26702016-08-12 16:03:29 -0700375 boolean wallpaperMightChange = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700376 for (int i = mChildren.size() - 1; i >= 0; i--) {
377 final WindowState win = (WindowState) mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700378 wallpaperMightChange |= win.clearAnimatingFlags();
Chong Zhange05bcb12016-07-26 17:47:29 -0700379 }
Chong Zhangb0d26702016-08-12 16:03:29 -0700380 if (wallpaperMightChange) {
381 requestUpdateWallpaperIfNeeded();
382 }
Chong Zhange05bcb12016-07-26 17:47:29 -0700383 }
384
Robert Carre12aece2016-02-02 22:43:27 -0800385 void destroySurfaces() {
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700386 destroySurfaces(false /*cleanupOnResume*/);
387 }
388
389 /**
390 * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure
391 * the client has finished with them.
392 *
393 * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If
394 * set to true, destroy only surfaces of removed windows, and clear relevant flags of the
395 * others so that they are ready to be reused. If set to false (common case), destroy all
396 * surfaces that's eligible, if the app is already stopped.
397 */
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700398 private void destroySurfaces(boolean cleanupOnResume) {
Robert Carre12aece2016-02-02 22:43:27 -0800399 final DisplayContentList displayList = new DisplayContentList();
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700400 for (int i = mChildren.size() - 1; i >= 0; i--) {
401 final WindowState win = (WindowState) mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700402 final boolean destroyed = win.destroySurface(cleanupOnResume, mAppStopped);
Chong Zhangeb665572016-05-09 18:28:27 -0700403
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700404 if (destroyed) {
405 final DisplayContent displayContent = win.getDisplayContent();
406 if (displayContent != null && !displayList.contains(displayContent)) {
407 displayList.add(displayContent);
408 }
Robert Carre12aece2016-02-02 22:43:27 -0800409 }
Robert Carre12aece2016-02-02 22:43:27 -0800410 }
411 for (int i = 0; i < displayList.size(); i++) {
412 final DisplayContent displayContent = displayList.get(i);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700413 mService.mLayersController.assignLayersLocked(displayContent.getWindowList());
Robert Carre12aece2016-02-02 22:43:27 -0800414 displayContent.layoutNeeded = true;
415 }
416 }
417
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800418 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700419 * Notify that the app is now resumed, and it was not stopped before, perform a clean
420 * up of the surfaces
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800421 */
Chong Zhangad24f962016-08-25 12:12:33 -0700422 void notifyAppResumed(boolean wasStopped, boolean allowSavedSurface) {
423 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped
424 + " allowSavedSurface=" + allowSavedSurface + " " + this);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700425 mAppStopped = false;
426 if (!wasStopped) {
427 destroySurfaces(true /*cleanupOnResume*/);
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800428 }
Chong Zhangad24f962016-08-25 12:12:33 -0700429 if (!allowSavedSurface) {
430 destroySavedSurfaces();
431 }
Robert Carre12aece2016-02-02 22:43:27 -0800432 }
433
Chong Zhangbef461f2015-10-27 11:38:24 -0700434 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700435 * Notify that the app has stopped, and it is okay to destroy any surfaces which were
436 * keeping alive in case they were still being used.
437 */
438 void notifyAppStopped() {
439 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this);
440 mAppStopped = true;
441 destroySurfaces();
442 // Remove any starting window that was added for this app if they are still around.
443 mTask.mService.scheduleRemoveStartingWindowLocked(this);
444 }
445
446 /**
Chong Zhangbef461f2015-10-27 11:38:24 -0700447 * Checks whether we should save surfaces for this app.
448 *
449 * @return true if the surfaces should be saved, false otherwise.
450 */
451 boolean shouldSaveSurface() {
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800452 // We want to save surface if the app's windows are "allDrawn".
453 // (If we started entering animation early with saved surfaces, allDrawn
454 // should have been restored to true. So we'll save again in that case
455 // even if app didn't actually finish drawing.)
456 return allDrawn;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800457 }
458
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700459 private boolean canRestoreSurfaces() {
460 for (int i = mChildren.size() -1; i >= 0; i--) {
461 final WindowState w = (WindowState) mChildren.get(i);
Chong Zhang92147042016-05-09 12:47:11 -0700462 if (w.canRestoreSurface()) {
Robert Carr13f7be9e2015-12-02 18:39:45 -0800463 return true;
464 }
Chong Zhangbef461f2015-10-27 11:38:24 -0700465 }
466 return false;
467 }
468
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700469 private void clearWasVisibleBeforeClientHidden() {
470 for (int i = mChildren.size() - 1; i >= 0; i--) {
471 final WindowState w = (WindowState) mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700472 w.clearWasVisibleBeforeClientHidden();
Chong Zhang92147042016-05-09 12:47:11 -0700473 }
474 }
475
Chong Zhang8e4bda92016-05-04 15:08:18 -0700476 /**
477 * Whether the app has some window that is invisible in layout, but
478 * animating with saved surface.
479 */
480 boolean isAnimatingInvisibleWithSavedSurface() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700481 for (int i = mChildren.size() - 1; i >= 0; i--) {
482 final WindowState w = (WindowState) mChildren.get(i);
Chong Zhang8e4bda92016-05-04 15:08:18 -0700483 if (w.isAnimatingInvisibleWithSavedSurface()) {
484 return true;
485 }
486 }
487 return false;
488 }
489
490 /**
491 * Hide all window surfaces that's still invisible in layout but animating
492 * with a saved surface, and mark them destroying.
493 */
494 void stopUsingSavedSurfaceLocked() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700495 for (int i = mChildren.size() - 1; i >= 0; i--) {
496 final WindowState w = (WindowState) mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700497 w.stopUsingSavedSurface();
Chong Zhang8e4bda92016-05-04 15:08:18 -0700498 }
499 destroySurfaces();
500 }
501
Chong Zhangf58631a2016-05-24 16:02:10 -0700502 void markSavedSurfaceExiting() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700503 for (int i = mChildren.size() - 1; i >= 0; i--) {
504 final WindowState w = (WindowState) mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700505 w.markSavedSurfaceExiting();
Chong Zhangf58631a2016-05-24 16:02:10 -0700506 }
507 }
508
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700509 void restoreSavedSurfaceForInterestingWindows() {
Chong Zhang92147042016-05-09 12:47:11 -0700510 if (!canRestoreSurfaces()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700511 clearWasVisibleBeforeClientHidden();
Chong Zhangbef461f2015-10-27 11:38:24 -0700512 return;
513 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700514
515 // Check if all interesting windows are drawn and we can mark allDrawn=true.
516 int interestingNotDrawn = -1;
517
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700518 for (int i = mChildren.size() - 1; i >= 0; i--) {
519 final WindowState w = (WindowState) mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700520 interestingNotDrawn = w.restoreSavedSurfaceForInterestingWindow();
Chong Zhangbef461f2015-10-27 11:38:24 -0700521 }
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800522
Chong Zhang92147042016-05-09 12:47:11 -0700523 if (!allDrawn) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700524 allDrawn = (interestingNotDrawn == 0);
Chong Zhang92147042016-05-09 12:47:11 -0700525 if (allDrawn) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700526 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Chong Zhang92147042016-05-09 12:47:11 -0700527 }
528 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700529 clearWasVisibleBeforeClientHidden();
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800530
531 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700532 "restoreSavedSurfaceForInterestingWindows: " + this + " allDrawn=" + allDrawn
533 + " interestingNotDrawn=" + interestingNotDrawn);
Chong Zhangbef461f2015-10-27 11:38:24 -0700534 }
535
536 void destroySavedSurfaces() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700537 for (int i = mChildren.size() - 1; i >= 0; i--) {
538 final WindowState win = (WindowState) mChildren.get(i);
Robert Carr13f7be9e2015-12-02 18:39:45 -0800539 win.destroySavedSurface();
Chong Zhangbef461f2015-10-27 11:38:24 -0700540 }
Chong Zhang92147042016-05-09 12:47:11 -0700541 }
542
543 void clearAllDrawn() {
544 allDrawn = false;
545 deferClearAllDrawn = false;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700546 allDrawnExcludingSaved = false;
Chong Zhangbef461f2015-10-27 11:38:24 -0700547 }
548
Wale Ogunwale98e70d02014-11-10 12:12:27 -0800549 @Override
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700550 void removeWindow(WindowState win) {
551 super.removeWindow(win);
552
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700553 // TODO: Something smells about the code below...Is there a better way?
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700554 if (startingWindow == win) {
555 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700556 mService.scheduleRemoveStartingWindowLocked(this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700557 } else if (mChildren.size() == 0 && startingData != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700558 // If this is the last window and we had requested a starting transition window,
559 // well there is no point now.
560 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingWindow");
561 startingData = null;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700562 } else if (mChildren.size() == 1 && startingView != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700563 // If this is the last window except for a starting transition window,
564 // we need to get rid of the starting transition.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700565 mService.scheduleRemoveStartingWindowLocked(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700566 }
567 }
568
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700569 void removeDeadWindows() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700570 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
571 WindowState win = (WindowState) mChildren.get(winNdx);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800572 if (win.mAppDied) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700573 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700574 "removeDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800575 // Set mDestroying, we don't want any animation or delayed removal here.
576 win.mDestroying = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700577 // Also removes child windows.
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700578 win.removeIfPossible();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800579 }
580 }
581 }
582
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700583 boolean hasWindowsAlive() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700584 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700585 // No need to loop through child windows as the answer should be the same as that of the
586 // parent window.
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700587 if (!((WindowState) mChildren.get(i)).mAppDied) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700588 return true;
589 }
590 }
591 return false;
592 }
593
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700594 void setWillReplaceWindows(boolean animate) {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700595 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
596 "Marking app token " + this + " with replacing windows.");
Robert Carra1eb4392015-12-10 12:43:51 -0800597
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700598 for (int i = mChildren.size() - 1; i >= 0; i--) {
599 final WindowState w = (WindowState) mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700600 w.setWillReplaceWindow(animate);
Robert Carra1eb4392015-12-10 12:43:51 -0800601 }
602 if (animate) {
603 // Set-up dummy animation so we can start treating windows associated with this
604 // token like they are in transition before the new app window is ready for us to
605 // run the real transition animation.
606 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700607 "setWillReplaceWindow() Setting dummy animation on: " + this);
Robert Carra1eb4392015-12-10 12:43:51 -0800608 mAppAnimator.setDummyAnimation();
609 }
610 }
611
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700612 void setWillReplaceChildWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700613 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this
Robert Carr23fa16b2016-01-13 13:19:58 -0800614 + " with replacing child windows.");
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700615 for (int i = mChildren.size() - 1; i >= 0; i--) {
616 final WindowState w = (WindowState) mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700617 w.setWillReplaceChildWindows();
Robert Carr23fa16b2016-01-13 13:19:58 -0800618 }
619 }
620
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700621 void clearWillReplaceWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700622 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
623 "Resetting app token " + this + " of replacing window marks.");
Chong Zhangf596cd52016-01-05 13:42:44 -0800624
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700625 for (int i = mChildren.size() - 1; i >= 0; i--) {
626 final WindowState w = (WindowState) mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700627 w.clearWillReplaceWindow();
Chong Zhangf596cd52016-01-05 13:42:44 -0800628 }
629 }
630
Chong Zhang4d7369a2016-04-25 16:09:14 -0700631 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700632 for (int i = mChildren.size() - 1; i >= 0; i--) {
633 final WindowState w = (WindowState) mChildren.get(i);
Chong Zhang4d7369a2016-04-25 16:09:14 -0700634 w.requestUpdateWallpaperIfNeeded();
635 }
636 }
637
Chong Zhangd78ddb42016-03-02 17:01:14 -0800638 boolean isRelaunching() {
639 return mPendingRelaunchCount > 0;
640 }
641
642 void startRelaunching() {
643 if (canFreezeBounds()) {
644 freezeBounds();
645 }
646 mPendingRelaunchCount++;
647 }
648
649 void finishRelaunching() {
650 if (canFreezeBounds()) {
651 unfreezeBounds();
652 }
653 if (mPendingRelaunchCount > 0) {
654 mPendingRelaunchCount--;
655 }
656 }
657
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700658 void clearRelaunching() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700659 if (mPendingRelaunchCount == 0) {
660 return;
661 }
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700662 if (canFreezeBounds()) {
663 unfreezeBounds();
664 }
665 mPendingRelaunchCount = 0;
666 }
667
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700668 @Override
Robert Carra1eb4392015-12-10 12:43:51 -0800669 void addWindow(WindowState w) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700670 super.addWindow(w);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700671
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700672 boolean gotReplacementWindow = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700673 for (int i = mChildren.size() - 1; i >= 0; i--) {
674 final WindowState candidate = (WindowState) mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700675 gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w);
676 }
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700677
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700678 // if we got a replacement window, reset the timeout to give drawing more time
679 if (gotReplacementWindow) {
680 mService.scheduleWindowReplacementTimeouts(this);
Robert Carra1eb4392015-12-10 12:43:51 -0800681 }
Robert Carra1eb4392015-12-10 12:43:51 -0800682 }
683
684 boolean waitingForReplacement() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700685 for (int i = mChildren.size() - 1; i >= 0; i--) {
686 final WindowState candidate = (WindowState) mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700687 if (candidate.waitingForReplacement()) {
Robert Carra1eb4392015-12-10 12:43:51 -0800688 return true;
689 }
690 }
691 return false;
692 }
693
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700694 void onWindowReplacementTimeout() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700695 for (int i = mChildren.size() - 1; i >= 0; --i) {
696 ((WindowState) mChildren.get(i)).onWindowReplacementTimeout();
Robert Carra1eb4392015-12-10 12:43:51 -0800697 }
698 }
699
Chong Zhangd78ddb42016-03-02 17:01:14 -0800700 private boolean canFreezeBounds() {
701 // For freeform windows, we can't freeze the bounds at the moment because this would make
702 // the resizing unresponsive.
703 return mTask != null && !mTask.inFreeformWorkspace();
704 }
705
Jorim Jaggi0429f352015-12-22 16:29:16 +0100706 /**
707 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
708 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
709 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
710 * with a queue.
711 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800712 private void freezeBounds() {
Jorim Jaggi0429f352015-12-22 16:29:16 +0100713 mFrozenBounds.offer(new Rect(mTask.mPreparedFrozenBounds));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700714
715 if (mTask.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) {
716 // We didn't call prepareFreezingBounds on the task, so use the current value.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700717 final Configuration config = new Configuration(mService.mCurConfiguration);
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700718 config.updateFrom(mTask.mOverrideConfig);
719 mFrozenMergedConfig.offer(config);
720 } else {
721 mFrozenMergedConfig.offer(new Configuration(mTask.mPreparedFrozenMergedConfig));
722 }
723 mTask.mPreparedFrozenMergedConfig.setToDefaults();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100724 }
725
726 /**
727 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
728 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800729 private void unfreezeBounds() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700730 if (!mFrozenBounds.isEmpty()) {
731 mFrozenBounds.remove();
732 }
733 if (!mFrozenMergedConfig.isEmpty()) {
734 mFrozenMergedConfig.remove();
735 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700736 for (int i = mChildren.size() - 1; i >= 0; i--) {
737 final WindowState win = (WindowState) mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700738 win.onUnfreezeBounds();
Jorim Jaggi4846ee32016-01-07 17:39:12 +0100739 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700740 mService.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100741 }
742
Robert Carr91b228092016-06-28 17:32:37 -0700743 void addSurfaceViewBackground(WindowSurfaceController.SurfaceControlWithBackground background) {
744 mSurfaceViewBackgrounds.add(background);
745 }
746
747 void removeSurfaceViewBackground(WindowSurfaceController.SurfaceControlWithBackground background) {
748 mSurfaceViewBackgrounds.remove(background);
749 updateSurfaceViewBackgroundVisibilities();
750 }
751
752 // We use DimLayers behind SurfaceViews to prevent holes while resizing and creating.
753 // However, we need to ensure one SurfaceView doesn't cover another when they are both placed
754 // below the main app window (as traditionally a SurfaceView which is never drawn
755 // to is totally translucent). So we look at all our SurfaceView backgrounds and only enable
756 // the background for the SurfaceView with lowest Z order
757 void updateSurfaceViewBackgroundVisibilities() {
758 WindowSurfaceController.SurfaceControlWithBackground bottom = null;
759 int bottomLayer = Integer.MAX_VALUE;
760 for (int i = 0; i < mSurfaceViewBackgrounds.size(); i++) {
761 WindowSurfaceController.SurfaceControlWithBackground sc = mSurfaceViewBackgrounds.get(i);
762 if (sc.mVisible && sc.mLayer < bottomLayer) {
763 bottomLayer = sc.mLayer;
764 bottom = sc;
765 }
766 }
767 for (int i = 0; i < mSurfaceViewBackgrounds.size(); i++) {
768 WindowSurfaceController.SurfaceControlWithBackground sc = mSurfaceViewBackgrounds.get(i);
769 sc.updateBackgroundVisibility(sc != bottom);
770 }
771 }
772
Jorim Jaggi6626f542016-08-22 13:08:44 -0700773 /**
774 * See {@link WindowManagerService#overridePlayingAppAnimationsLw}
775 */
776 void overridePlayingAppAnimations(Animation a) {
777 if (mAppAnimator.isAnimating()) {
778 final WindowState win = findMainWindow();
779 final int width = win.mContainingFrame.width();
780 final int height = win.mContainingFrame.height();
781 mAppAnimator.setAnimation(a, width, height, false, STACK_CLIP_NONE);
782 }
783 }
784
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700785 void resetJustMovedInStack() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700786 for (int i = mChildren.size() - 1; i >= 0; i--) {
787 ((WindowState) mChildren.get(i)).resetJustMovedInStack();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700788 }
789 }
790
791 void notifyMovedInStack() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700792 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
793 final WindowState win = (WindowState) mChildren.get(winNdx);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700794 win.notifyMovedInStack();
795 }
796 }
797
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700798 void setAppLayoutChanges(int changes, String reason, int displayId) {
799 final WindowAnimator windowAnimator = mAppAnimator.mAnimator;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700800 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700801 // Child windows will be on the same display as their parents.
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700802 if (displayId == ((WindowState) mChildren.get(i)).getDisplayId()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700803 windowAnimator.setPendingLayoutChanges(displayId, changes);
804 if (DEBUG_LAYOUT_REPEATS) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700805 mService.mWindowPlacerLocked.debugLayoutRepeats(
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700806 reason, windowAnimator.getPendingLayoutChanges(displayId));
807 }
808 break;
809 }
810 }
811 }
812
813 void removeReplacedWindowIfNeeded(WindowState replacement) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700814 for (int i = mChildren.size() - 1; i >= 0; i--) {
815 final WindowState win = (WindowState) mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700816 if (win.removeReplacedWindowIfNeeded(replacement)) {
817 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700818 }
819 }
820 }
821
822 void startFreezingScreen() {
823 if (DEBUG_ORIENTATION) logWithStack(TAG, "Set freezing of " + appToken + ": hidden="
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700824 + hidden + " freezing=" + mAppAnimator.freezingScreen + " hiddenRequested="
825 + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700826 if (!hiddenRequested) {
827 if (!mAppAnimator.freezingScreen) {
828 mAppAnimator.freezingScreen = true;
829 mAppAnimator.lastFreezeDuration = 0;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700830 mService.mAppsFreezingScreen++;
831 if (mService.mAppsFreezingScreen == 1) {
832 mService.startFreezingDisplayLocked(false, 0, 0);
833 mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT);
834 mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700835 }
836 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700837 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700838 for (int i = 0; i < count; i++) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700839 final WindowState w = (WindowState) mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700840 w.onStartFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700841 }
842 }
843 }
844
845 void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) {
846 if (!mAppAnimator.freezingScreen) {
847 return;
848 }
849 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + this + " force=" + force);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700850 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700851 boolean unfrozeWindows = false;
852 for (int i = 0; i < count; i++) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700853 final WindowState w = (WindowState) mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700854 unfrozeWindows |= w.onStopFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700855 }
856 if (force || unfrozeWindows) {
857 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this);
858 mAppAnimator.freezingScreen = false;
859 mAppAnimator.lastFreezeDuration =
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700860 (int)(SystemClock.elapsedRealtime() - mService.mDisplayFreezeTime);
861 mService.mAppsFreezingScreen--;
862 mService.mLastFinishedFreezeSource = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700863 }
864 if (unfreezeSurfaceNow) {
865 if (unfrozeWindows) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700866 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700867 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700868 mService.stopFreezingDisplayLocked();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700869 }
870 }
871
872 boolean transferStartingWindow(IBinder transferFrom) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700873 final AppWindowToken fromToken = mService.findAppWindowToken(transferFrom);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700874 if (fromToken == null) {
875 return false;
876 }
877
878 final WindowState tStartingWindow = fromToken.startingWindow;
879 if (tStartingWindow != null && fromToken.startingView != null) {
880 // In this case, the starting icon has already been displayed, so start
881 // letting windows get shown immediately without any more transitions.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700882 mService.mSkipAppTransitionAnimation = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700883
884 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow
885 + " from " + fromToken + " to " + this);
886
887 final long origId = Binder.clearCallingIdentity();
888
889 // Transfer the starting window over to the new token.
890 startingData = fromToken.startingData;
891 startingView = fromToken.startingView;
892 startingDisplayed = fromToken.startingDisplayed;
893 fromToken.startingDisplayed = false;
894 startingWindow = tStartingWindow;
895 reportedVisible = fromToken.reportedVisible;
896 fromToken.startingData = null;
897 fromToken.startingView = null;
898 fromToken.startingWindow = null;
899 fromToken.startingMoved = true;
900 tStartingWindow.mToken = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700901 tStartingWindow.mAppToken = this;
902
903 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
904 "Removing starting window: " + tStartingWindow);
905 tStartingWindow.getWindowList().remove(tStartingWindow);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700906 mService.mWindowsChanged = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700907 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
908 "Removing starting " + tStartingWindow + " from " + fromToken);
909 fromToken.removeWindow(tStartingWindow);
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700910 addWindow(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700911
912 // Propagate other interesting state between the tokens. If the old token is displayed,
913 // we should immediately force the new one to be displayed. If it is animating, we need
914 // to move that animation to the new one.
915 if (fromToken.allDrawn) {
916 allDrawn = true;
917 deferClearAllDrawn = fromToken.deferClearAllDrawn;
918 }
919 if (fromToken.firstWindowDrawn) {
920 firstWindowDrawn = true;
921 }
922 if (!fromToken.hidden) {
923 hidden = false;
924 hiddenRequested = false;
925 }
926 if (clientHidden != fromToken.clientHidden) {
927 clientHidden = fromToken.clientHidden;
928 sendAppVisibilityToClients();
929 }
930 fromToken.mAppAnimator.transferCurrentAnimation(
931 mAppAnimator, tStartingWindow.mWinAnimator);
932
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700933 mService.updateFocusedWindowLocked(
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700934 UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700935 mService.getDefaultDisplayContentLocked().layoutNeeded = true;
936 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700937 Binder.restoreCallingIdentity(origId);
938 return true;
939 } else if (fromToken.startingData != null) {
940 // The previous app was getting ready to show a
941 // starting window, but hasn't yet done so. Steal it!
942 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
943 "Moving pending starting from " + fromToken + " to " + this);
944 startingData = fromToken.startingData;
945 fromToken.startingData = null;
946 fromToken.startingMoved = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700947 final Message m = mService.mH.obtainMessage(H.ADD_STARTING, this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700948 // Note: we really want to do sendMessageAtFrontOfQueue() because we want to process the
949 // message ASAP, before any other queued messages.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700950 mService.mH.sendMessageAtFrontOfQueue(m);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700951 return true;
952 }
953
954 final AppWindowAnimator tAppAnimator = fromToken.mAppAnimator;
955 final AppWindowAnimator wAppAnimator = mAppAnimator;
956 if (tAppAnimator.thumbnail != null) {
957 // The old token is animating with a thumbnail, transfer that to the new token.
958 if (wAppAnimator.thumbnail != null) {
959 wAppAnimator.thumbnail.destroy();
960 }
961 wAppAnimator.thumbnail = tAppAnimator.thumbnail;
962 wAppAnimator.thumbnailLayer = tAppAnimator.thumbnailLayer;
963 wAppAnimator.thumbnailAnimation = tAppAnimator.thumbnailAnimation;
964 tAppAnimator.thumbnail = null;
965 }
966 return false;
967 }
968
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700969 boolean isLastWindow(WindowState win) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700970 return mChildren.size() == 1 && mChildren.get(0) == win;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700971 }
972
973 void setAllAppWinAnimators() {
974 final ArrayList<WindowStateAnimator> allAppWinAnimators = mAppAnimator.mAllAppWinAnimators;
975 allAppWinAnimators.clear();
976
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700977 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700978 for (int j = 0; j < windowsCount; j++) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700979 ((WindowState) mChildren.get(j)).addWinAnimatorToList(allAppWinAnimators);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700980 }
981 }
982
Craig Mautnerdbb79912012-03-01 18:59:14 -0800983 @Override
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700984 AppWindowToken asAppWindowToken() {
985 // I am an app window token!
986 return this;
987 }
988
989 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800990 void dump(PrintWriter pw, String prefix) {
991 super.dump(pw, prefix);
992 if (appToken != null) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700993 pw.print(prefix); pw.print("app=true voiceInteraction="); pw.println(voiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800994 }
Craig Mautner83162a92015-01-26 14:43:30 -0800995 pw.print(prefix); pw.print("task="); pw.println(mTask);
996 pw.print(prefix); pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800997 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
998 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
999 pw.print(" clientHidden="); pw.print(clientHidden);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -07001000 pw.print(" reportedDrawn="); pw.print(reportedDrawn);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001001 pw.print(" reportedVisible="); pw.println(reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -07001002 if (paused) {
1003 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001004 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001005 if (mAppStopped) {
1006 pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped);
1007 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001008 if (numInterestingWindows != 0 || numDrawnWindows != 0
Craig Mautner6fbda632012-07-03 09:26:39 -07001009 || allDrawn || mAppAnimator.allDrawn) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001010 pw.print(prefix); pw.print("numInterestingWindows=");
1011 pw.print(numInterestingWindows);
1012 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
1013 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -07001014 pw.print(" allDrawn="); pw.print(allDrawn);
1015 pw.print(" (animator="); pw.print(mAppAnimator.allDrawn);
1016 pw.println(")");
1017 }
1018 if (inPendingTransaction) {
1019 pw.print(prefix); pw.print("inPendingTransaction=");
1020 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001021 }
Craig Mautner799bc1d2015-01-14 10:33:48 -08001022 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001023 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
1024 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -08001025 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -08001026 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001027 }
1028 if (startingWindow != null || startingView != null
1029 || startingDisplayed || startingMoved) {
1030 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
1031 pw.print(" startingView="); pw.print(startingView);
1032 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001033 pw.print(" startingMoved="); pw.println(startingMoved);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001034 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01001035 if (!mFrozenBounds.isEmpty()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -08001036 pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds);
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001037 pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig);
Chong Zhangd78ddb42016-03-02 17:01:14 -08001038 }
1039 if (mPendingRelaunchCount != 0) {
1040 pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount);
Jorim Jaggi0429f352015-12-22 16:29:16 +01001041 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001042 }
1043
1044 @Override
1045 public String toString() {
1046 if (stringName == null) {
1047 StringBuilder sb = new StringBuilder();
1048 sb.append("AppWindowToken{");
1049 sb.append(Integer.toHexString(System.identityHashCode(this)));
1050 sb.append(" token="); sb.append(token); sb.append('}');
1051 stringName = sb.toString();
1052 }
1053 return stringName;
1054 }
Jeff Browne9bdb312012-04-05 15:30:10 -07001055}