blob: f4f6b63058d4ed7f5ceb615a93824ffdec3734af [file] [log] [blame]
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server.wm;
18
Wale Ogunwale6cae7652015-12-26 07:36:26 -080019import static android.app.ActivityManager.StackId;
Wale Ogunwale72919d22016-12-08 18:58:50 -080020import static android.content.pm.ActivityInfo.CONFIG_ORIENTATION;
21import static android.content.pm.ActivityInfo.CONFIG_SCREEN_SIZE;
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -070022import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND;
Wale Ogunwale51362492016-09-08 17:49:17 -070023import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070024import static android.view.Display.DEFAULT_DISPLAY;
Jorim Jaggife762342016-10-13 14:33:27 +020025import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
26import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
Wale Ogunwaled1c37912016-08-16 03:19:39 -070027import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080028import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070029import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -070030import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
31import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070032import static com.android.server.wm.AppTransition.TRANSIT_UNSET;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080033import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080034import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
35import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070036import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070037import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
38import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
Wale Ogunwale9017ec02016-02-25 08:55:25 -080039import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070040import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TOKEN_MOVEMENT;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080041import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
42import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_MOVEMENT;
43import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
44import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Chong Zhang92147042016-05-09 12:47:11 -070045import static com.android.server.wm.WindowManagerService.H.NOTIFY_ACTIVITY_DRAWN;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070046import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070047import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070048import static com.android.server.wm.WindowManagerService.logWithStack;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080049
Filip Gruszczynskia590c992015-11-25 16:45:26 -080050import android.annotation.NonNull;
Jorim Jaggi26c8c422016-05-09 19:57:25 -070051import android.content.res.Configuration;
Jorim Jaggi0429f352015-12-22 16:29:16 +010052import android.graphics.Rect;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070053import android.os.Binder;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080054import android.os.Debug;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070055import android.os.IBinder;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070056import android.os.SystemClock;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080057import android.util.Slog;
58import android.view.IApplicationToken;
Robert Carr6914f082017-03-20 19:04:30 -070059import android.view.SurfaceControl;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080060import android.view.WindowManager;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080061import android.view.WindowManagerPolicy.StartingSurface;
62
63import com.android.internal.util.ToBooleanFunction;
64import com.android.server.input.InputApplicationHandle;
65import com.android.server.wm.WindowManagerService.H;
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;
70
71class AppTokenList extends ArrayList<AppWindowToken> {
72}
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080073
74/**
75 * Version of WindowToken that is specifically for a particular application (or
76 * really activity) that is displaying windows.
77 */
Wale Ogunwale3f4433d2016-08-18 20:42:42 -070078class AppWindowToken extends WindowToken implements WindowManagerService.AppFreezeListener {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080079 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppWindowToken" : TAG_WM;
80
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080081 // Non-null only for application tokens.
82 final IApplicationToken appToken;
83
Filip Gruszczynskia590c992015-11-25 16:45:26 -080084 @NonNull final AppWindowAnimator mAppAnimator;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -070085
Wale Ogunwale72919d22016-12-08 18:58:50 -080086 final boolean mVoiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -070087
Wale Ogunwale51362492016-09-08 17:49:17 -070088 /** @see WindowContainer#fillsParent() */
89 private boolean mFillsParent;
Craig Mautner4c5eb222013-11-18 12:59:05 -080090 boolean layoutConfigChanges;
Wale Ogunwale72919d22016-12-08 18:58:50 -080091 boolean mShowForAllUsers;
92 int mTargetSdk;
Craig Mautnera2c77052012-03-26 12:14:43 -070093
Bryce Lee6d410262017-02-28 15:30:17 -080094 // Flag set while reparenting to prevent actions normally triggered by an individual parent
95 // change.
96 private boolean mReparenting;
97
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080098 // The input dispatching timeout for this application token in nanoseconds.
Wale Ogunwale72919d22016-12-08 18:58:50 -080099 long mInputDispatchingTimeoutNanos;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800100
101 // These are used for determining when all windows associated with
102 // an activity have been drawn, so they can be made visible together
103 // at the same time.
Craig Mautner764983d2012-03-22 11:37:36 -0700104 // initialize so that it doesn't match mTransactionSequence which is an int.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700105 private long mLastTransactionSequence = Long.MIN_VALUE;
106 private int mNumInterestingWindows;
107 private int mNumDrawnWindows;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800108 boolean inPendingTransaction;
109 boolean allDrawn;
Craig Mautner7636dfb2012-11-16 15:24:11 -0800110 // Set to true when this app creates a surface while in the middle of an animation. In that
111 // case do not clear allDrawn until the animation completes.
112 boolean deferClearAllDrawn;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800113
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700114 /**
115 * These are to track the app's real drawing status if there were no saved surfaces.
116 * @see #updateDrawnWindowStates
117 */
Chong Zhang8e4bda92016-05-04 15:08:18 -0700118 boolean allDrawnExcludingSaved;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700119 private int mNumInterestingWindowsExcludingSaved;
120 private int mNumDrawnWindowsExcludingSaved;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700121
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800122 // Is this window's surface needed? This is almost like hidden, except
123 // it will sometimes be true a little earlier: when the token has
124 // been shown, but is still waiting for its app transition to execute
125 // before making its windows shown.
126 boolean hiddenRequested;
127
128 // Have we told the window clients to hide themselves?
129 boolean clientHidden;
130
131 // Last visibility state we reported to the app token.
132 boolean reportedVisible;
133
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700134 // Last drawn state we reported to the app token.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700135 private boolean reportedDrawn;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700136
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800137 // Set to true when the token has been removed from the window mgr.
138 boolean removed;
139
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800140 // Information about an application starting window if displayed.
141 StartingData startingData;
142 WindowState startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800143 StartingSurface startingSurface;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800144 boolean startingDisplayed;
145 boolean startingMoved;
146 boolean firstWindowDrawn;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700147 private final WindowState.UpdateReportedVisibilityResults mReportedVisibilityResults =
148 new WindowState.UpdateReportedVisibilityResults();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800149
150 // Input application handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700151 final InputApplicationHandle mInputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800152
Wale Ogunwale571771c2016-08-26 13:18:50 -0700153 // TODO: Have a WindowContainer state for tracking exiting/deferred removal.
Craig Mautner799bc1d2015-01-14 10:33:48 -0800154 boolean mIsExiting;
Craig Mautner9ef471f2014-02-07 13:11:47 -0800155
Craig Mautnerbb742462014-07-07 15:28:55 -0700156 boolean mLaunchTaskBehind;
Craig Mautner8746a472014-07-24 15:12:54 -0700157 boolean mEnteringAnimation;
Craig Mautnerbb742462014-07-07 15:28:55 -0700158
Wale Ogunwale72919d22016-12-08 18:58:50 -0800159 private boolean mAlwaysFocusable;
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800160
Robert Carre12aece2016-02-02 22:43:27 -0800161 boolean mAppStopped;
Robert Carrfd10cd12016-06-29 16:41:50 -0700162 int mRotationAnimationHint;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700163 private int mPendingRelaunchCount;
Robert Carre12aece2016-02-02 22:43:27 -0800164
Jorim Jaggife762342016-10-13 14:33:27 +0200165 private boolean mLastContainsShowWhenLockedWindow;
166 private boolean mLastContainsDismissKeyguardWindow;
167
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700168 // The bounds of this activity. Mainly used for aspect-ratio compatibility.
169 // TODO(b/36505427): Every level on WindowContainer now has bounds information, which directly
170 // affects the configuration. We should probably move this into that class.
171 private final Rect mBounds = new Rect();
172
Jorim Jaggi0429f352015-12-22 16:29:16 +0100173 ArrayDeque<Rect> mFrozenBounds = new ArrayDeque<>();
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700174 ArrayDeque<Configuration> mFrozenMergedConfig = new ArrayDeque<>();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100175
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +0100176 private boolean mDisbalePreviewScreenshots;
177
Wale Ogunwale72919d22016-12-08 18:58:50 -0800178 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
179 DisplayContent dc, long inputDispatchingTimeoutNanos, boolean fullscreen,
180 boolean showForAllUsers, int targetSdk, int orientation, int rotationAnimationHint,
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800181 int configChanges, boolean launchTaskBehind, boolean alwaysFocusable,
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700182 AppWindowContainerController controller, Configuration overrideConfig, Rect bounds) {
183 this(service, token, voiceInteraction, dc, fullscreen, overrideConfig, bounds);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800184 setController(controller);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800185 mInputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800186 mShowForAllUsers = showForAllUsers;
187 mTargetSdk = targetSdk;
188 mOrientation = orientation;
189 layoutConfigChanges = (configChanges & (CONFIG_SCREEN_SIZE | CONFIG_ORIENTATION)) != 0;
190 mLaunchTaskBehind = launchTaskBehind;
191 mAlwaysFocusable = alwaysFocusable;
192 mRotationAnimationHint = rotationAnimationHint;
193
194 // Application tokens start out hidden.
195 hidden = true;
196 hiddenRequested = true;
197 }
198
199 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700200 DisplayContent dc, boolean fillsParent, Configuration overrideConfig, Rect bounds) {
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800201 super(service, token != null ? token.asBinder() : null, TYPE_APPLICATION, true, dc,
202 false /* ownerCanManageAppTokens */);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700203 appToken = token;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800204 mVoiceInteraction = voiceInteraction;
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800205 mFillsParent = fillsParent;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800206 mInputApplicationHandle = new InputApplicationHandle(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700207 mAppAnimator = new AppWindowAnimator(this, service);
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700208 if (overrideConfig != null) {
209 onOverrideConfigurationChanged(overrideConfig);
210 }
211 if (bounds != null) {
212 mBounds.set(bounds);
213 }
214 }
215
216 void onOverrideConfigurationChanged(Configuration overrideConfiguration, Rect bounds) {
217 onOverrideConfigurationChanged(overrideConfiguration);
218 if (mBounds.equals(bounds)) {
219 return;
220 }
221 // TODO(b/36505427): If bounds is in WC, then we can automatically call onResize() when set.
222 mBounds.set(bounds);
223 onResize();
224 }
225
226 void getBounds(Rect outBounds) {
227 outBounds.set(mBounds);
228 }
229
230 boolean hasBounds() {
231 return !mBounds.isEmpty();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800232 }
233
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800234 void onFirstWindowDrawn(WindowState win, WindowStateAnimator winAnimator) {
235 firstWindowDrawn = true;
236
237 // We now have a good window to show, remove dead placeholders
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700238 removeDeadWindows();
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800239
Jorim Jaggi02886a82016-12-06 09:10:06 -0800240 if (startingWindow != null) {
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800241 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, "Finish starting "
242 + win.mToken + ": first real window is shown, no animation");
243 // If this initial window is animating, stop it -- we will do an animation to reveal
244 // it from behind the starting window, so there is no need for it to also be doing its
245 // own stuff.
246 winAnimator.clearAnimation();
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800247 if (getController() != null) {
248 getController().removeStartingWindow();
249 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800250 }
251 updateReportedVisibilityLocked();
252 }
253
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800254 void updateReportedVisibilityLocked() {
255 if (appToken == null) {
256 return;
257 }
258
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700259 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700260 final int count = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800261
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700262 mReportedVisibilityResults.reset();
263
264 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700265 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700266 win.updateReportedVisibility(mReportedVisibilityResults);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800267 }
268
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700269 int numInteresting = mReportedVisibilityResults.numInteresting;
270 int numVisible = mReportedVisibilityResults.numVisible;
271 int numDrawn = mReportedVisibilityResults.numDrawn;
272 boolean nowGone = mReportedVisibilityResults.nowGone;
273
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700274 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800275 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700276 if (!nowGone) {
277 // If the app is not yet gone, then it can only become visible/drawn.
278 if (!nowDrawn) {
279 nowDrawn = reportedDrawn;
280 }
281 if (!nowVisible) {
282 nowVisible = reportedVisible;
283 }
284 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800285 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800286 + numInteresting + " visible=" + numVisible);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800287 final AppWindowContainerController controller = getController();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700288 if (nowDrawn != reportedDrawn) {
289 if (nowDrawn) {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800290 if (controller != null) {
291 controller.reportWindowsDrawn();
292 }
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700293 }
294 reportedDrawn = nowDrawn;
295 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800296 if (nowVisible != reportedVisible) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700297 if (DEBUG_VISIBILITY) Slog.v(TAG,
298 "Visibility changed in " + this + ": vis=" + nowVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800299 reportedVisible = nowVisible;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800300 if (controller != null) {
301 if (nowVisible) {
302 controller.reportWindowsVisible();
303 } else {
304 controller.reportWindowsGone();
305 }
306 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800307 }
308 }
309
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700310 boolean setVisibility(WindowManager.LayoutParams lp,
311 boolean visible, int transit, boolean performLayout, boolean isVoiceInteraction) {
312
313 boolean delayed = false;
314 inPendingTransaction = false;
315
316 if (clientHidden == visible) {
317 clientHidden = !visible;
318 sendAppVisibilityToClients();
319 }
320
321 // Allow for state changes and animation to be applied if:
322 // * token is transitioning visibility state
323 // * or the token was marked as hidden and is exiting before we had a chance to play the
324 // transition animation
325 // * or this is an opening app and windows are being replaced.
326 boolean visibilityChanged = false;
327 if (hidden == visible || (hidden && mIsExiting) || (visible && waitingForReplacement())) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700328 final AccessibilityController accessibilityController = mService.mAccessibilityController;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700329 boolean changed = false;
330 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
331 "Changing app " + this + " hidden=" + hidden + " performLayout=" + performLayout);
332
333 boolean runningAppAnimation = false;
334
335 if (transit != AppTransition.TRANSIT_UNSET) {
336 if (mAppAnimator.animation == AppWindowAnimator.sDummyAnimation) {
337 mAppAnimator.setNullAnimation();
338 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700339 if (mService.applyAnimationLocked(this, lp, transit, visible, isVoiceInteraction)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700340 delayed = runningAppAnimation = true;
341 }
342 final WindowState window = findMainWindow();
343 //TODO (multidisplay): Magnification is supported only for the default display.
344 if (window != null && accessibilityController != null
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700345 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700346 accessibilityController.onAppWindowTransitionLocked(window, transit);
347 }
348 changed = true;
349 }
350
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700351 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700352 for (int i = 0; i < windowsCount; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700353 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700354 changed |= win.onAppVisibilityChanged(visible, runningAppAnimation);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700355 }
356
357 hidden = hiddenRequested = !visible;
358 visibilityChanged = true;
359 if (!visible) {
360 stopFreezingScreen(true, true);
361 } else {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700362 // If we are being set visible, and the starting window is not yet displayed,
363 // then make sure it doesn't get displayed.
364 if (startingWindow != null && !startingWindow.isDrawnLw()) {
365 startingWindow.mPolicyVisibility = false;
366 startingWindow.mPolicyVisibilityAfterAnim = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700367 }
368 }
369
370 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setVisibility: " + this
371 + ": hidden=" + hidden + " hiddenRequested=" + hiddenRequested);
372
373 if (changed) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700374 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700375 if (performLayout) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700376 mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700377 false /*updateInputWindows*/);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700378 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700379 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700380 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700381 }
382 }
383
384 if (mAppAnimator.animation != null) {
385 delayed = true;
386 }
387
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700388 for (int i = mChildren.size() - 1; i >= 0 && !delayed; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700389 if ((mChildren.get(i)).isWindowAnimationSet()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700390 delayed = true;
391 }
392 }
393
394 if (visibilityChanged) {
395 if (visible && !delayed) {
396 // The token was made immediately visible, there will be no entrance animation.
397 // We need to inform the client the enter animation was finished.
398 mEnteringAnimation = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700399 mService.mActivityManagerAppTransitionNotifier.onAppTransitionFinishedLocked(token);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700400 }
Robert Carre7cc44d2017-03-20 19:04:30 -0700401 // If we are hidden but there is no delay needed we immediately
402 // apply the Surface transaction so that the ActivityManager
403 // can have some guarantee on the Surface state
404 // following setting the visibility.
Robert Carr6914f082017-03-20 19:04:30 -0700405 if (hidden && !delayed) {
406 SurfaceControl.openTransaction();
407 for (int i = mChildren.size() - 1; i >= 0; i--) {
408 mChildren.get(i).mWinAnimator.hide("immediately hidden");
409 }
410 SurfaceControl.closeTransaction();
411 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700412
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700413 if (!mService.mClosingApps.contains(this) && !mService.mOpeningApps.contains(this)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700414 // The token is not closing nor opening, so even if there is an animation set, that
415 // doesn't mean that it goes through the normal app transition cycle so we have
416 // to inform the docked controller about visibility change.
Andrii Kulian1e32e022016-09-16 15:29:34 -0700417 // TODO(multi-display): notify docked divider on all displays where visibility was
418 // affected.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700419 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700420 .notifyAppVisibilityChanged();
Jorim Jaggi8b702ed2017-01-20 16:59:03 +0100421 mService.mTaskSnapshotController.notifyAppVisibilityChanged(this, visible);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700422 }
423 }
424
425 return delayed;
426 }
427
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800428 WindowState findMainWindow() {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700429 WindowState candidate = null;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700430 int j = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800431 while (j > 0) {
432 j--;
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700433 final WindowState win = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700434 final int type = win.mAttrs.type;
435 // No need to loop through child window as base application and starting types can't be
436 // child windows.
437 if (type == TYPE_BASE_APPLICATION || type == TYPE_APPLICATION_STARTING) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700438 // In cases where there are multiple windows, we prefer the non-exiting window. This
Sungsoo Lim0d3d1f82015-12-02 14:47:59 +0900439 // happens for example when replacing windows during an activity relaunch. When
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700440 // constructing the animation, we want the new window, not the exiting one.
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800441 if (win.mAnimatingExit) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700442 candidate = win;
443 } else {
444 return win;
445 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800446 }
447 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700448 return candidate;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800449 }
450
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800451 boolean windowsAreFocusable() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800452 return StackId.canReceiveKeys(getTask().mStack.mStackId) || mAlwaysFocusable;
Wale Ogunwaled045c822015-12-02 09:14:28 -0800453 }
454
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800455 AppWindowContainerController getController() {
456 final WindowContainerController controller = super.getController();
457 return controller != null ? (AppWindowContainerController) controller : null;
458 }
459
Wale Ogunwale571771c2016-08-26 13:18:50 -0700460 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -0700461 boolean isVisible() {
Wale Ogunwalee471be62016-10-03 07:53:55 -0700462 // If the app token isn't hidden then it is considered visible and there is no need to check
463 // its children windows to see if they are visible.
464 return !hidden;
Wale Ogunwale44f21802016-09-02 12:49:48 -0700465 }
466
467 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -0700468 void removeIfPossible() {
Craig Mautnere3119b72015-01-20 15:02:36 -0800469 mIsExiting = false;
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800470 removeAllWindowsIfPossible();
Bryce Lee6d410262017-02-28 15:30:17 -0800471 removeImmediately();
Craig Mautnere3119b72015-01-20 15:02:36 -0800472 }
473
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700474 @Override
475 boolean checkCompleteDeferredRemoval() {
476 if (mIsExiting) {
477 removeIfPossible();
478 }
479 return super.checkCompleteDeferredRemoval();
480 }
481
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700482 void onRemovedFromDisplay() {
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700483 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app token: " + this);
484
Wale Ogunwale72919d22016-12-08 18:58:50 -0800485 boolean delayed = setVisibility(null, false, TRANSIT_UNSET, true, mVoiceInteraction);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700486
487 mService.mOpeningApps.remove(this);
Jorim Jaggi1b4b23e2016-11-15 16:30:12 -0800488 mService.mUnknownAppVisibilityController.appRemoved(this);
Jorim Jaggi10abe2f2017-01-03 16:44:46 +0100489 mService.mTaskSnapshotController.onAppRemoved(this);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700490 waitingToShow = false;
491 if (mService.mClosingApps.contains(this)) {
492 delayed = true;
493 } else if (mService.mAppTransition.isTransitionSet()) {
494 mService.mClosingApps.add(this);
495 delayed = true;
496 }
497
498 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app " + this + " delayed=" + delayed
499 + " animation=" + mAppAnimator.animation + " animating=" + mAppAnimator.animating);
500
501 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM, "removeAppToken: "
502 + this + " delayed=" + delayed + " Callers=" + Debug.getCallers(4));
503
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800504 if (startingData != null && getController() != null) {
505 getController().removeStartingWindow();
506 }
507
Winson Chung87e5d552017-04-05 11:49:38 -0700508 // If this window was animating, then we need to ensure that the app transition notifies
509 // that animations have completed in WMS.handleAnimatingStoppedAndTransitionLocked(), so
510 // add to that list now
511 if (mAppAnimator.animating) {
512 mService.mNoAnimationNotifyOnTransitionFinished.add(token);
513 }
514
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800515 final TaskStack stack = getTask().mStack;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700516 if (delayed && !isEmpty()) {
517 // set the token aside because it has an active animation to be finished
518 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM,
519 "removeAppToken make exiting: " + this);
520 stack.mExitingAppTokens.add(this);
521 mIsExiting = true;
522 } else {
523 // Make sure there is no animation running on this token, so any windows associated
524 // with it will be removed as soon as their animations are complete
525 mAppAnimator.clearAnimation();
526 mAppAnimator.animating = false;
527 removeIfPossible();
528 }
529
530 removed = true;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700531 stopFreezingScreen(true, true);
Bryce Lee6d410262017-02-28 15:30:17 -0800532
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700533 if (mService.mFocusedApp == this) {
534 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "Removing focused app token:" + this);
535 mService.mFocusedApp = null;
536 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
537 mService.mInputMonitor.setFocusedAppLw(null);
538 }
539
540 if (!delayed) {
541 updateReportedVisibilityLocked();
542 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700543 }
544
Chong Zhange05bcb12016-07-26 17:47:29 -0700545 void clearAnimatingFlags() {
Chong Zhangb0d26702016-08-12 16:03:29 -0700546 boolean wallpaperMightChange = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700547 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700548 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700549 wallpaperMightChange |= win.clearAnimatingFlags();
Chong Zhange05bcb12016-07-26 17:47:29 -0700550 }
Chong Zhangb0d26702016-08-12 16:03:29 -0700551 if (wallpaperMightChange) {
552 requestUpdateWallpaperIfNeeded();
553 }
Chong Zhange05bcb12016-07-26 17:47:29 -0700554 }
555
Robert Carre12aece2016-02-02 22:43:27 -0800556 void destroySurfaces() {
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700557 destroySurfaces(false /*cleanupOnResume*/);
558 }
559
560 /**
561 * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure
562 * the client has finished with them.
563 *
564 * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If
565 * set to true, destroy only surfaces of removed windows, and clear relevant flags of the
566 * others so that they are ready to be reused. If set to false (common case), destroy all
567 * surfaces that's eligible, if the app is already stopped.
568 */
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700569 private void destroySurfaces(boolean cleanupOnResume) {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700570 boolean destroyedSomething = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700571 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700572 final WindowState win = mChildren.get(i);
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700573 destroyedSomething |= win.destroySurface(cleanupOnResume, mAppStopped);
Robert Carre12aece2016-02-02 22:43:27 -0800574 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700575 if (destroyedSomething) {
576 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700577 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Robert Carre12aece2016-02-02 22:43:27 -0800578 }
579 }
580
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800581 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700582 * Notify that the app is now resumed, and it was not stopped before, perform a clean
583 * up of the surfaces
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800584 */
Jorim Jaggibae01b12017-04-11 16:29:10 -0700585 void notifyAppResumed(boolean wasStopped) {
Chong Zhangad24f962016-08-25 12:12:33 -0700586 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped
Jorim Jaggibae01b12017-04-11 16:29:10 -0700587 + " " + this);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700588 mAppStopped = false;
589 if (!wasStopped) {
590 destroySurfaces(true /*cleanupOnResume*/);
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800591 }
Robert Carre12aece2016-02-02 22:43:27 -0800592 }
593
Chong Zhangbef461f2015-10-27 11:38:24 -0700594 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700595 * Notify that the app has stopped, and it is okay to destroy any surfaces which were
596 * keeping alive in case they were still being used.
597 */
598 void notifyAppStopped() {
599 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this);
600 mAppStopped = true;
601 destroySurfaces();
602 // Remove any starting window that was added for this app if they are still around.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800603 if (getController() != null) {
604 getController().removeStartingWindow();
605 }
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700606 }
607
608 /**
Chong Zhangbef461f2015-10-27 11:38:24 -0700609 * Checks whether we should save surfaces for this app.
610 *
611 * @return true if the surfaces should be saved, false otherwise.
612 */
613 boolean shouldSaveSurface() {
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800614 // We want to save surface if the app's windows are "allDrawn".
615 // (If we started entering animation early with saved surfaces, allDrawn
616 // should have been restored to true. So we'll save again in that case
617 // even if app didn't actually finish drawing.)
618 return allDrawn;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800619 }
620
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700621 private boolean canRestoreSurfaces() {
622 for (int i = mChildren.size() -1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700623 final WindowState w = mChildren.get(i);
Chong Zhang92147042016-05-09 12:47:11 -0700624 if (w.canRestoreSurface()) {
Robert Carr13f7be9e2015-12-02 18:39:45 -0800625 return true;
626 }
Chong Zhangbef461f2015-10-27 11:38:24 -0700627 }
628 return false;
629 }
630
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700631 private void clearWasVisibleBeforeClientHidden() {
632 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700633 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700634 w.clearWasVisibleBeforeClientHidden();
Chong Zhang92147042016-05-09 12:47:11 -0700635 }
636 }
637
Chong Zhang8e4bda92016-05-04 15:08:18 -0700638 /**
639 * Whether the app has some window that is invisible in layout, but
640 * animating with saved surface.
641 */
642 boolean isAnimatingInvisibleWithSavedSurface() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700643 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700644 final WindowState w = mChildren.get(i);
Chong Zhang8e4bda92016-05-04 15:08:18 -0700645 if (w.isAnimatingInvisibleWithSavedSurface()) {
646 return true;
647 }
648 }
649 return false;
650 }
651
652 /**
653 * Hide all window surfaces that's still invisible in layout but animating
654 * with a saved surface, and mark them destroying.
655 */
656 void stopUsingSavedSurfaceLocked() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700657 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700658 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700659 w.stopUsingSavedSurface();
Chong Zhang8e4bda92016-05-04 15:08:18 -0700660 }
661 destroySurfaces();
662 }
663
Chong Zhangf58631a2016-05-24 16:02:10 -0700664 void markSavedSurfaceExiting() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700665 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700666 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700667 w.markSavedSurfaceExiting();
Chong Zhangf58631a2016-05-24 16:02:10 -0700668 }
669 }
670
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700671 void restoreSavedSurfaceForInterestingWindows() {
Chong Zhang92147042016-05-09 12:47:11 -0700672 if (!canRestoreSurfaces()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700673 clearWasVisibleBeforeClientHidden();
Chong Zhangbef461f2015-10-27 11:38:24 -0700674 return;
675 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700676
677 // Check if all interesting windows are drawn and we can mark allDrawn=true.
678 int interestingNotDrawn = -1;
679
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700680 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700681 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700682 interestingNotDrawn = w.restoreSavedSurfaceForInterestingWindow();
Chong Zhangbef461f2015-10-27 11:38:24 -0700683 }
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800684
Chong Zhang92147042016-05-09 12:47:11 -0700685 if (!allDrawn) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700686 allDrawn = (interestingNotDrawn == 0);
Chong Zhang92147042016-05-09 12:47:11 -0700687 if (allDrawn) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700688 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Chong Zhang92147042016-05-09 12:47:11 -0700689 }
690 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700691 clearWasVisibleBeforeClientHidden();
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800692
693 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700694 "restoreSavedSurfaceForInterestingWindows: " + this + " allDrawn=" + allDrawn
695 + " interestingNotDrawn=" + interestingNotDrawn);
Chong Zhangbef461f2015-10-27 11:38:24 -0700696 }
697
698 void destroySavedSurfaces() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700699 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700700 final WindowState win = mChildren.get(i);
Robert Carr13f7be9e2015-12-02 18:39:45 -0800701 win.destroySavedSurface();
Chong Zhangbef461f2015-10-27 11:38:24 -0700702 }
Chong Zhang92147042016-05-09 12:47:11 -0700703 }
704
705 void clearAllDrawn() {
706 allDrawn = false;
707 deferClearAllDrawn = false;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700708 allDrawnExcludingSaved = false;
Chong Zhangbef461f2015-10-27 11:38:24 -0700709 }
710
Bryce Lee6d410262017-02-28 15:30:17 -0800711 Task getTask() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800712 return (Task) getParent();
Bryce Lee6d410262017-02-28 15:30:17 -0800713 }
714
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800715 TaskStack getStack() {
716 final Task task = getTask();
717 if (task != null) {
718 return task.mStack;
719 } else {
720 return null;
721 }
722 }
723
Bryce Lee6d410262017-02-28 15:30:17 -0800724 @Override
725 void onParentSet() {
726 super.onParentSet();
727
728 // When the associated task is {@code null}, the {@link AppWindowToken} can no longer
729 // access visual elements like the {@link DisplayContent}. We must remove any associations
730 // such as animations.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800731 if (!mReparenting) {
732 final Task task = getTask();
733 if (task == null) {
734 // It is possible we have been marked as a closing app earlier. We must remove ourselves
735 // from this list so we do not participate in any future animations.
736 mService.mClosingApps.remove(this);
737 } else if (task.mStack != null) {
738 task.mStack.mExitingAppTokens.remove(this);
739 }
Bryce Lee6d410262017-02-28 15:30:17 -0800740 }
741 }
742
Wale Ogunwalefa854eb2016-09-20 13:43:52 -0700743 void postWindowRemoveStartingWindowCleanup(WindowState win) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700744 // TODO: Something smells about the code below...Is there a better way?
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700745 if (startingWindow == win) {
746 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800747 if (getController() != null) {
748 getController().removeStartingWindow();
749 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700750 } else if (mChildren.size() == 0 && startingData != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700751 // If this is the last window and we had requested a starting transition window,
752 // well there is no point now.
Jorim Jaggi02886a82016-12-06 09:10:06 -0800753 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingData");
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700754 startingData = null;
Jorim Jaggi829b9cd2017-01-23 16:20:53 +0100755 } else if (mChildren.size() == 1 && startingSurface != null && !isRelaunching()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700756 // If this is the last window except for a starting transition window,
757 // we need to get rid of the starting transition.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800758 if (getController() != null) {
759 getController().removeStartingWindow();
760 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700761 }
762 }
763
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700764 void removeDeadWindows() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700765 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700766 WindowState win = mChildren.get(winNdx);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800767 if (win.mAppDied) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700768 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700769 "removeDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800770 // Set mDestroying, we don't want any animation or delayed removal here.
771 win.mDestroying = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700772 // Also removes child windows.
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700773 win.removeIfPossible();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800774 }
775 }
776 }
777
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700778 boolean hasWindowsAlive() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700779 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700780 // No need to loop through child windows as the answer should be the same as that of the
781 // parent window.
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700782 if (!(mChildren.get(i)).mAppDied) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700783 return true;
784 }
785 }
786 return false;
787 }
788
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700789 void setWillReplaceWindows(boolean animate) {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700790 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
791 "Marking app token " + this + " with replacing windows.");
Robert Carra1eb4392015-12-10 12:43:51 -0800792
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700793 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700794 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700795 w.setWillReplaceWindow(animate);
Robert Carra1eb4392015-12-10 12:43:51 -0800796 }
797 if (animate) {
798 // Set-up dummy animation so we can start treating windows associated with this
799 // token like they are in transition before the new app window is ready for us to
800 // run the real transition animation.
801 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700802 "setWillReplaceWindow() Setting dummy animation on: " + this);
Robert Carra1eb4392015-12-10 12:43:51 -0800803 mAppAnimator.setDummyAnimation();
804 }
805 }
806
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700807 void setWillReplaceChildWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700808 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this
Robert Carr23fa16b2016-01-13 13:19:58 -0800809 + " with replacing child windows.");
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700810 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700811 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700812 w.setWillReplaceChildWindows();
Robert Carr23fa16b2016-01-13 13:19:58 -0800813 }
814 }
815
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700816 void clearWillReplaceWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700817 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
818 "Resetting app token " + this + " of replacing window marks.");
Chong Zhangf596cd52016-01-05 13:42:44 -0800819
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700820 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700821 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700822 w.clearWillReplaceWindow();
Chong Zhangf596cd52016-01-05 13:42:44 -0800823 }
824 }
825
Chong Zhang4d7369a2016-04-25 16:09:14 -0700826 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700827 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700828 final WindowState w = mChildren.get(i);
Chong Zhang4d7369a2016-04-25 16:09:14 -0700829 w.requestUpdateWallpaperIfNeeded();
830 }
831 }
832
Chong Zhangd78ddb42016-03-02 17:01:14 -0800833 boolean isRelaunching() {
834 return mPendingRelaunchCount > 0;
835 }
836
837 void startRelaunching() {
838 if (canFreezeBounds()) {
839 freezeBounds();
840 }
Robert Carrd5c7dd62017-03-08 10:39:30 -0800841
842 // In the process of tearing down before relaunching, the app will
843 // try and clean up it's child surfaces. We need to prevent this from
844 // happening, so we sever the children, transfering their ownership
845 // from the client it-self to the parent surface (owned by us).
846 for (int i = mChildren.size() - 1; i >= 0; i--) {
847 final WindowState w = mChildren.get(i);
848 w.mWinAnimator.detachChildren();
849 }
850
Chong Zhangd78ddb42016-03-02 17:01:14 -0800851 mPendingRelaunchCount++;
852 }
853
854 void finishRelaunching() {
855 if (canFreezeBounds()) {
856 unfreezeBounds();
857 }
858 if (mPendingRelaunchCount > 0) {
859 mPendingRelaunchCount--;
860 }
861 }
862
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700863 void clearRelaunching() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700864 if (mPendingRelaunchCount == 0) {
865 return;
866 }
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700867 if (canFreezeBounds()) {
868 unfreezeBounds();
869 }
870 mPendingRelaunchCount = 0;
871 }
872
Wale Ogunwale07bcab72016-10-14 15:30:09 -0700873 /**
874 * Returns true if the new child window we are adding to this token is considered greater than
875 * the existing child window in this token in terms of z-order.
876 */
877 @Override
878 protected boolean isFirstChildWindowGreaterThanSecond(WindowState newWindow,
879 WindowState existingWindow) {
880 final int type1 = newWindow.mAttrs.type;
881 final int type2 = existingWindow.mAttrs.type;
882
883 // Base application windows should be z-ordered BELOW all other windows in the app token.
884 if (type1 == TYPE_BASE_APPLICATION && type2 != TYPE_BASE_APPLICATION) {
885 return false;
886 } else if (type1 != TYPE_BASE_APPLICATION && type2 == TYPE_BASE_APPLICATION) {
887 return true;
888 }
889
890 // Starting windows should be z-ordered ABOVE all other windows in the app token.
891 if (type1 == TYPE_APPLICATION_STARTING && type2 != TYPE_APPLICATION_STARTING) {
892 return true;
893 } else if (type1 != TYPE_APPLICATION_STARTING && type2 == TYPE_APPLICATION_STARTING) {
894 return false;
895 }
896
897 // Otherwise the new window is greater than the existing window.
898 return true;
899 }
900
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700901 @Override
Robert Carra1eb4392015-12-10 12:43:51 -0800902 void addWindow(WindowState w) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700903 super.addWindow(w);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700904
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700905 boolean gotReplacementWindow = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700906 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700907 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700908 gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w);
909 }
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700910
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700911 // if we got a replacement window, reset the timeout to give drawing more time
912 if (gotReplacementWindow) {
913 mService.scheduleWindowReplacementTimeouts(this);
Robert Carra1eb4392015-12-10 12:43:51 -0800914 }
Jorim Jaggife762342016-10-13 14:33:27 +0200915 checkKeyguardFlagsChanged();
916 }
917
918 @Override
919 void removeChild(WindowState child) {
920 super.removeChild(child);
921 checkKeyguardFlagsChanged();
Robert Carra1eb4392015-12-10 12:43:51 -0800922 }
923
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700924 private boolean waitingForReplacement() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700925 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700926 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700927 if (candidate.waitingForReplacement()) {
Robert Carra1eb4392015-12-10 12:43:51 -0800928 return true;
929 }
930 }
931 return false;
932 }
933
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700934 void onWindowReplacementTimeout() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700935 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700936 (mChildren.get(i)).onWindowReplacementTimeout();
Robert Carra1eb4392015-12-10 12:43:51 -0800937 }
938 }
939
Winson Chung30480042017-01-26 10:55:34 -0800940 void reparent(Task task, int position) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800941 final Task currentTask = getTask();
942 if (task == currentTask) {
Winson Chung30480042017-01-26 10:55:34 -0800943 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800944 "window token=" + this + " already child of task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -0800945 }
Bryce Lee6d410262017-02-28 15:30:17 -0800946
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800947 if (currentTask.mStack != task.mStack) {
Bryce Lee6d410262017-02-28 15:30:17 -0800948 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800949 "window token=" + this + " current task=" + currentTask
Bryce Lee6d410262017-02-28 15:30:17 -0800950 + " belongs to a different stack than " + task);
951 }
952
Winson Chung30480042017-01-26 10:55:34 -0800953 if (DEBUG_ADD_REMOVE) Slog.i(TAG, "reParentWindowToken: removing window token=" + this
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800954 + " from task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -0800955 final DisplayContent prevDisplayContent = getDisplayContent();
956
Bryce Lee6d410262017-02-28 15:30:17 -0800957 mReparenting = true;
958
Winson Chung30480042017-01-26 10:55:34 -0800959 getParent().removeChild(this);
960 task.addChild(this, position);
961
Bryce Lee6d410262017-02-28 15:30:17 -0800962 mReparenting = false;
963
Winson Chung30480042017-01-26 10:55:34 -0800964 // Relayout display(s).
965 final DisplayContent displayContent = task.getDisplayContent();
966 displayContent.setLayoutNeeded();
967 if (prevDisplayContent != displayContent) {
968 onDisplayChanged(displayContent);
969 prevDisplayContent.setLayoutNeeded();
970 }
971 }
972
Chong Zhangd78ddb42016-03-02 17:01:14 -0800973 private boolean canFreezeBounds() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800974 final Task task = getTask();
975
Chong Zhangd78ddb42016-03-02 17:01:14 -0800976 // For freeform windows, we can't freeze the bounds at the moment because this would make
977 // the resizing unresponsive.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800978 return task != null && !task.inFreeformWorkspace();
Chong Zhangd78ddb42016-03-02 17:01:14 -0800979 }
980
Jorim Jaggi0429f352015-12-22 16:29:16 +0100981 /**
982 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
983 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
984 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
985 * with a queue.
986 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800987 private void freezeBounds() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800988 final Task task = getTask();
989 mFrozenBounds.offer(new Rect(task.mPreparedFrozenBounds));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700990
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800991 if (task.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) {
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700992 // We didn't call prepareFreezingBounds on the task, so use the current value.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800993 mFrozenMergedConfig.offer(new Configuration(task.getConfiguration()));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700994 } else {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800995 mFrozenMergedConfig.offer(new Configuration(task.mPreparedFrozenMergedConfig));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700996 }
Andrii Kulianb10330d2016-09-16 13:51:46 -0700997 // Calling unset() to make it equal to Configuration.EMPTY.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800998 task.mPreparedFrozenMergedConfig.unset();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100999 }
1000
1001 /**
1002 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
1003 */
Chong Zhangd78ddb42016-03-02 17:01:14 -08001004 private void unfreezeBounds() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -07001005 if (!mFrozenBounds.isEmpty()) {
1006 mFrozenBounds.remove();
1007 }
1008 if (!mFrozenMergedConfig.isEmpty()) {
1009 mFrozenMergedConfig.remove();
1010 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001011 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001012 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001013 win.onUnfreezeBounds();
Jorim Jaggi4846ee32016-01-07 17:39:12 +01001014 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001015 mService.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +01001016 }
1017
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001018 void setAppLayoutChanges(int changes, String reason) {
1019 if (!mChildren.isEmpty()) {
1020 final DisplayContent dc = getDisplayContent();
1021 dc.pendingLayoutChanges |= changes;
1022 if (DEBUG_LAYOUT_REPEATS) {
1023 mService.mWindowPlacerLocked.debugLayoutRepeats(reason, dc.pendingLayoutChanges);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001024 }
1025 }
1026 }
1027
1028 void removeReplacedWindowIfNeeded(WindowState replacement) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001029 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001030 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001031 if (win.removeReplacedWindowIfNeeded(replacement)) {
1032 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001033 }
1034 }
1035 }
1036
1037 void startFreezingScreen() {
1038 if (DEBUG_ORIENTATION) logWithStack(TAG, "Set freezing of " + appToken + ": hidden="
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001039 + hidden + " freezing=" + mAppAnimator.freezingScreen + " hiddenRequested="
1040 + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001041 if (!hiddenRequested) {
1042 if (!mAppAnimator.freezingScreen) {
1043 mAppAnimator.freezingScreen = true;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001044 mService.registerAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001045 mAppAnimator.lastFreezeDuration = 0;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001046 mService.mAppsFreezingScreen++;
1047 if (mService.mAppsFreezingScreen == 1) {
1048 mService.startFreezingDisplayLocked(false, 0, 0);
1049 mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT);
1050 mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001051 }
1052 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001053 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001054 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001055 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001056 w.onStartFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001057 }
1058 }
1059 }
1060
1061 void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) {
1062 if (!mAppAnimator.freezingScreen) {
1063 return;
1064 }
1065 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + this + " force=" + force);
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001066 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001067 boolean unfrozeWindows = false;
1068 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001069 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001070 unfrozeWindows |= w.onStopFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001071 }
1072 if (force || unfrozeWindows) {
1073 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this);
1074 mAppAnimator.freezingScreen = false;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001075 mService.unregisterAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001076 mAppAnimator.lastFreezeDuration =
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001077 (int)(SystemClock.elapsedRealtime() - mService.mDisplayFreezeTime);
1078 mService.mAppsFreezingScreen--;
1079 mService.mLastFinishedFreezeSource = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001080 }
1081 if (unfreezeSurfaceNow) {
1082 if (unfrozeWindows) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001083 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001084 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001085 mService.stopFreezingDisplayLocked();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001086 }
1087 }
1088
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001089 @Override
1090 public void onAppFreezeTimeout() {
1091 Slog.w(TAG_WM, "Force clearing freeze: " + this);
1092 stopFreezingScreen(true, true);
1093 }
1094
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001095 boolean transferStartingWindow(IBinder transferFrom) {
Wale Ogunwale02319a62016-09-26 15:21:22 -07001096 final AppWindowToken fromToken = getDisplayContent().getAppWindowToken(transferFrom);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001097 if (fromToken == null) {
1098 return false;
1099 }
1100
1101 final WindowState tStartingWindow = fromToken.startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001102 if (tStartingWindow != null && fromToken.startingSurface != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001103 // In this case, the starting icon has already been displayed, so start
1104 // letting windows get shown immediately without any more transitions.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001105 mService.mSkipAppTransitionAnimation = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001106
1107 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow
1108 + " from " + fromToken + " to " + this);
1109
1110 final long origId = Binder.clearCallingIdentity();
1111
1112 // Transfer the starting window over to the new token.
1113 startingData = fromToken.startingData;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001114 startingSurface = fromToken.startingSurface;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001115 startingDisplayed = fromToken.startingDisplayed;
1116 fromToken.startingDisplayed = false;
1117 startingWindow = tStartingWindow;
1118 reportedVisible = fromToken.reportedVisible;
1119 fromToken.startingData = null;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001120 fromToken.startingSurface = null;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001121 fromToken.startingWindow = null;
1122 fromToken.startingMoved = true;
1123 tStartingWindow.mToken = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001124 tStartingWindow.mAppToken = this;
1125
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001126 if (DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001127 "Removing starting " + tStartingWindow + " from " + fromToken);
Wale Ogunwalefa854eb2016-09-20 13:43:52 -07001128 fromToken.removeChild(tStartingWindow);
1129 fromToken.postWindowRemoveStartingWindowCleanup(tStartingWindow);
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001130 addWindow(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001131
1132 // Propagate other interesting state between the tokens. If the old token is displayed,
1133 // we should immediately force the new one to be displayed. If it is animating, we need
1134 // to move that animation to the new one.
1135 if (fromToken.allDrawn) {
1136 allDrawn = true;
1137 deferClearAllDrawn = fromToken.deferClearAllDrawn;
1138 }
1139 if (fromToken.firstWindowDrawn) {
1140 firstWindowDrawn = true;
1141 }
1142 if (!fromToken.hidden) {
1143 hidden = false;
1144 hiddenRequested = false;
1145 }
1146 if (clientHidden != fromToken.clientHidden) {
1147 clientHidden = fromToken.clientHidden;
1148 sendAppVisibilityToClients();
1149 }
1150 fromToken.mAppAnimator.transferCurrentAnimation(
1151 mAppAnimator, tStartingWindow.mWinAnimator);
1152
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001153 mService.updateFocusedWindowLocked(
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001154 UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/);
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001155 getDisplayContent().setLayoutNeeded();
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001156 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001157 Binder.restoreCallingIdentity(origId);
1158 return true;
1159 } else if (fromToken.startingData != null) {
1160 // The previous app was getting ready to show a
1161 // starting window, but hasn't yet done so. Steal it!
1162 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1163 "Moving pending starting from " + fromToken + " to " + this);
1164 startingData = fromToken.startingData;
1165 fromToken.startingData = null;
1166 fromToken.startingMoved = true;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001167 if (getController() != null) {
1168 getController().scheduleAddStartingWindow();
1169 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001170 return true;
1171 }
1172
1173 final AppWindowAnimator tAppAnimator = fromToken.mAppAnimator;
1174 final AppWindowAnimator wAppAnimator = mAppAnimator;
1175 if (tAppAnimator.thumbnail != null) {
1176 // The old token is animating with a thumbnail, transfer that to the new token.
1177 if (wAppAnimator.thumbnail != null) {
1178 wAppAnimator.thumbnail.destroy();
1179 }
1180 wAppAnimator.thumbnail = tAppAnimator.thumbnail;
1181 wAppAnimator.thumbnailLayer = tAppAnimator.thumbnailLayer;
1182 wAppAnimator.thumbnailAnimation = tAppAnimator.thumbnailAnimation;
1183 tAppAnimator.thumbnail = null;
1184 }
1185 return false;
1186 }
1187
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001188 boolean isLastWindow(WindowState win) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001189 return mChildren.size() == 1 && mChildren.get(0) == win;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001190 }
1191
1192 void setAllAppWinAnimators() {
1193 final ArrayList<WindowStateAnimator> allAppWinAnimators = mAppAnimator.mAllAppWinAnimators;
1194 allAppWinAnimators.clear();
1195
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001196 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001197 for (int j = 0; j < windowsCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001198 (mChildren.get(j)).addWinAnimatorToList(allAppWinAnimators);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001199 }
1200 }
1201
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001202 @Override
1203 void onAppTransitionDone() {
1204 sendingToBottom = false;
1205 }
1206
Wale Ogunwale51362492016-09-08 17:49:17 -07001207 /**
1208 * We override because this class doesn't want its children affecting its reported orientation
1209 * in anyway.
1210 */
1211 @Override
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001212 int getOrientation(int candidate) {
1213 if (!fillsParent()) {
1214 // Can't specify orientation if app doesn't fill parent.
1215 return SCREEN_ORIENTATION_UNSET;
1216 }
1217
1218 if (candidate == SCREEN_ORIENTATION_BEHIND) {
1219 // Allow app to specify orientation regardless of its visibility state if the current
1220 // candidate want us to use orientation behind. I.e. the visible app on-top of this one
1221 // wants us to use the orientation of the app behind it.
1222 return mOrientation;
1223 }
1224
Bryce Lee61fbcbc2017-03-10 14:14:03 -08001225 // The {@link AppWindowToken} should only specify an orientation when it is not closing or
1226 // going to the bottom. Allowing closing {@link AppWindowToken} to participate can lead to
1227 // an Activity in another task being started in the wrong orientation during the transition.
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001228 if (!(sendingToBottom || mService.mClosingApps.contains(this))
Bryce Lee61fbcbc2017-03-10 14:14:03 -08001229 && (isVisible() || mService.mOpeningApps.contains(this))) {
Bryce Leea163b762017-01-24 11:05:01 -08001230 return mOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001231 }
Bryce Leea163b762017-01-24 11:05:01 -08001232
1233 return SCREEN_ORIENTATION_UNSET;
Wale Ogunwale51362492016-09-08 17:49:17 -07001234 }
1235
Wale Ogunwaleb198b742016-12-01 08:44:09 -08001236 /** Returns the app's preferred orientation regardless of its currently visibility state. */
1237 int getOrientationIgnoreVisibility() {
1238 return mOrientation;
1239 }
1240
Craig Mautnerdbb79912012-03-01 18:59:14 -08001241 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001242 void checkAppWindowsReadyToShow() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001243 if (allDrawn == mAppAnimator.allDrawn) {
1244 return;
1245 }
1246
1247 mAppAnimator.allDrawn = allDrawn;
1248 if (!allDrawn) {
1249 return;
1250 }
1251
1252 // The token has now changed state to having all windows shown... what to do, what to do?
1253 if (mAppAnimator.freezingScreen) {
1254 mAppAnimator.showAllWindowsLocked();
1255 stopFreezingScreen(false, true);
1256 if (DEBUG_ORIENTATION) Slog.i(TAG,
1257 "Setting mOrientationChangeComplete=true because wtoken " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001258 + " numInteresting=" + mNumInterestingWindows + " numDrawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001259 // This will set mOrientationChangeComplete and cause a pass through layout.
1260 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001261 "checkAppWindowsReadyToShow: freezingScreen");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001262 } else {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001263 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001264
1265 // We can now show all of the drawn windows!
1266 if (!mService.mOpeningApps.contains(this)) {
1267 mService.mAnimator.orAnimating(mAppAnimator.showAllWindowsLocked());
1268 }
1269 }
1270 }
1271
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001272 void updateAllDrawn(DisplayContent dc) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001273 if (!allDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001274 final int numInteresting = mNumInterestingWindows;
1275 if (numInteresting > 0 && mNumDrawnWindows >= numInteresting) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001276 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawn: " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001277 + " interesting=" + numInteresting + " drawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001278 allDrawn = true;
1279 // Force an additional layout pass where
1280 // WindowStateAnimator#commitFinishDrawingLocked() will call performShowLocked().
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001281 dc.setLayoutNeeded();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001282 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
1283 }
1284 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001285
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001286 if (!allDrawnExcludingSaved) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001287 int numInteresting = mNumInterestingWindowsExcludingSaved;
1288 if (numInteresting > 0 && mNumDrawnWindowsExcludingSaved >= numInteresting) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001289 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawnExcludingSaved: " + this
1290 + " interesting=" + numInteresting
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001291 + " drawn=" + mNumDrawnWindowsExcludingSaved);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001292 allDrawnExcludingSaved = true;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001293 dc.setLayoutNeeded();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001294 if (isAnimatingInvisibleWithSavedSurface()
1295 && !mService.mFinishedEarlyAnim.contains(this)) {
1296 mService.mFinishedEarlyAnim.add(this);
1297 }
1298 }
1299 }
1300 }
1301
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001302 /**
1303 * Updated this app token tracking states for interesting and drawn windows based on the window.
1304 *
1305 * @return Returns true if the input window is considered interesting and drawn while all the
1306 * windows in this app token where not considered drawn as of the last pass.
1307 */
1308 boolean updateDrawnWindowStates(WindowState w) {
1309 if (DEBUG_STARTING_WINDOW && w == startingWindow) {
1310 Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" + w.isOnScreen()
1311 + " allDrawn=" + allDrawn + " freezingScreen=" + mAppAnimator.freezingScreen);
1312 }
1313
1314 if (allDrawn && allDrawnExcludingSaved && !mAppAnimator.freezingScreen) {
1315 return false;
1316 }
1317
1318 if (mLastTransactionSequence != mService.mTransactionSequence) {
1319 mLastTransactionSequence = mService.mTransactionSequence;
1320 mNumInterestingWindows = mNumDrawnWindows = 0;
1321 mNumInterestingWindowsExcludingSaved = 0;
1322 mNumDrawnWindowsExcludingSaved = 0;
1323 startingDisplayed = false;
1324 }
1325
1326 final WindowStateAnimator winAnimator = w.mWinAnimator;
1327
1328 boolean isInterestingAndDrawn = false;
1329
1330 if (!allDrawn && w.mightAffectAllDrawn(false /* visibleOnly */)) {
1331 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
1332 Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw()
1333 + ", isAnimationSet=" + winAnimator.isAnimationSet());
1334 if (!w.isDrawnLw()) {
1335 Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController
1336 + " pv=" + w.mPolicyVisibility
1337 + " mDrawState=" + winAnimator.drawStateToString()
1338 + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested
1339 + " a=" + winAnimator.mAnimating);
1340 }
1341 }
1342
1343 if (w != startingWindow) {
1344 if (w.isInteresting()) {
1345 mNumInterestingWindows++;
1346 if (w.isDrawnLw()) {
1347 mNumDrawnWindows++;
1348
1349 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, "tokenMayBeDrawn: "
1350 + this + " w=" + w + " numInteresting=" + mNumInterestingWindows
1351 + " freezingScreen=" + mAppAnimator.freezingScreen
1352 + " mAppFreezing=" + w.mAppFreezing);
1353
1354 isInterestingAndDrawn = true;
1355 }
1356 }
1357 } else if (w.isDrawnLw()) {
Jorim Jaggi3878ca32017-02-02 17:13:05 -08001358 if (getController() != null) {
1359 getController().reportStartingWindowDrawn();
1360 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001361 startingDisplayed = true;
1362 }
1363 }
1364
1365 if (!allDrawnExcludingSaved && w.mightAffectAllDrawn(true /* visibleOnly */)) {
1366 if (w != startingWindow && w.isInteresting()) {
1367 mNumInterestingWindowsExcludingSaved++;
1368 if (w.isDrawnLw() && !w.isAnimatingWithSavedSurface()) {
1369 mNumDrawnWindowsExcludingSaved++;
1370
1371 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
1372 "tokenMayBeDrawnExcludingSaved: " + this + " w=" + w
1373 + " numInteresting=" + mNumInterestingWindowsExcludingSaved
1374 + " freezingScreen=" + mAppAnimator.freezingScreen
1375 + " mAppFreezing=" + w.mAppFreezing);
1376
1377 isInterestingAndDrawn = true;
1378 }
1379 }
1380 }
1381
1382 return isInterestingAndDrawn;
1383 }
1384
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001385 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001386 void stepAppWindowsAnimation(long currentTime) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001387 mAppAnimator.wasAnimating = mAppAnimator.animating;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001388 if (mAppAnimator.stepAnimationLocked(currentTime)) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001389 mAppAnimator.animating = true;
1390 mService.mAnimator.setAnimating(true);
1391 mService.mAnimator.mAppWindowAnimating = true;
1392 } else if (mAppAnimator.wasAnimating) {
1393 // stopped animating, do one more pass through the layout
Wale Ogunwale1e129a42016-11-21 13:03:47 -08001394 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
1395 DEBUG_LAYOUT_REPEATS ? "appToken " + this + " done" : null);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001396 if (DEBUG_ANIM) Slog.v(TAG, "updateWindowsApps...: done animating " + this);
1397 }
1398 }
1399
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001400 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001401 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001402 // For legacy reasons we process the TaskStack.mExitingAppTokens first in DisplayContent
1403 // before the non-exiting app tokens. So, we skip the exiting app tokens here.
1404 // TODO: Investigate if we need to continue to do this or if we can just process them
1405 // in-order.
1406 if (mIsExiting && !waitingForReplacement()) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001407 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001408 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001409 return forAllWindowsUnchecked(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001410 }
1411
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001412 boolean forAllWindowsUnchecked(ToBooleanFunction<WindowState> callback,
1413 boolean traverseTopToBottom) {
1414 return super.forAllWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001415 }
1416
1417 @Override
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001418 AppWindowToken asAppWindowToken() {
1419 // I am an app window token!
1420 return this;
1421 }
1422
1423 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -07001424 boolean fillsParent() {
1425 return mFillsParent;
1426 }
1427
1428 void setFillsParent(boolean fillsParent) {
1429 mFillsParent = fillsParent;
1430 }
1431
Jorim Jaggife762342016-10-13 14:33:27 +02001432 boolean containsDismissKeyguardWindow() {
1433 for (int i = mChildren.size() - 1; i >= 0; i--) {
1434 if ((mChildren.get(i).mAttrs.flags & FLAG_DISMISS_KEYGUARD) != 0) {
1435 return true;
1436 }
1437 }
1438 return false;
1439 }
1440
1441 boolean containsShowWhenLockedWindow() {
1442 for (int i = mChildren.size() - 1; i >= 0; i--) {
1443 if ((mChildren.get(i).mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
1444 return true;
1445 }
1446 }
1447 return false;
1448 }
1449
1450 void checkKeyguardFlagsChanged() {
1451 final boolean containsDismissKeyguard = containsDismissKeyguardWindow();
1452 final boolean containsShowWhenLocked = containsShowWhenLockedWindow();
1453 if (containsDismissKeyguard != mLastContainsDismissKeyguardWindow
1454 || containsShowWhenLocked != mLastContainsShowWhenLockedWindow) {
1455 mService.notifyKeyguardFlagsChanged(null /* callback */);
1456 }
1457 mLastContainsDismissKeyguardWindow = containsDismissKeyguard;
1458 mLastContainsShowWhenLockedWindow = containsShowWhenLocked;
1459 }
1460
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001461 WindowState getImeTargetBelowWindow(WindowState w) {
1462 final int index = mChildren.indexOf(w);
1463 if (index > 0) {
1464 final WindowState target = mChildren.get(index - 1);
1465 if (target.canBeImeTarget()) {
1466 return target;
1467 }
1468 }
1469 return null;
1470 }
1471
1472 WindowState getHighestAnimLayerWindow(WindowState currentTarget) {
1473 WindowState candidate = null;
1474 for (int i = mChildren.indexOf(currentTarget); i >= 0; i--) {
1475 final WindowState w = mChildren.get(i);
1476 if (w.mRemoved) {
1477 continue;
1478 }
1479 if (candidate == null || w.mWinAnimator.mAnimLayer >
1480 candidate.mWinAnimator.mAnimLayer) {
1481 candidate = w;
1482 }
1483 }
1484 return candidate;
1485 }
1486
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001487 void setDisablePreviewSnapshots(boolean disable) {
1488 mDisbalePreviewScreenshots = disable;
1489 }
1490
1491 boolean shouldDisablePreviewScreenshots() {
1492 return mDisbalePreviewScreenshots;
1493 }
1494
Wale Ogunwale51362492016-09-08 17:49:17 -07001495 @Override
Robert Carrdee1b3f2017-02-27 11:33:33 -08001496 int getAnimLayerAdjustment() {
1497 return mAppAnimator.animLayerAdjustment;
1498 }
1499
1500 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001501 void dump(PrintWriter pw, String prefix) {
1502 super.dump(pw, prefix);
1503 if (appToken != null) {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001504 pw.println(prefix + "app=true mVoiceInteraction=" + mVoiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001505 }
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001506 pw.print(prefix); pw.print("task="); pw.println(getTask());
Wale Ogunwale51362492016-09-08 17:49:17 -07001507 pw.print(prefix); pw.print(" mFillsParent="); pw.print(mFillsParent);
1508 pw.print(" mOrientation="); pw.println(mOrientation);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001509 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
1510 pw.print(" clientHidden="); pw.print(clientHidden);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -07001511 pw.print(" reportedDrawn="); pw.print(reportedDrawn);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001512 pw.print(" reportedVisible="); pw.println(reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -07001513 if (paused) {
1514 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001515 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001516 if (mAppStopped) {
1517 pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped);
1518 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001519 if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0
Craig Mautner6fbda632012-07-03 09:26:39 -07001520 || allDrawn || mAppAnimator.allDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001521 pw.print(prefix); pw.print("mNumInterestingWindows=");
1522 pw.print(mNumInterestingWindows);
1523 pw.print(" mNumDrawnWindows="); pw.print(mNumDrawnWindows);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001524 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -07001525 pw.print(" allDrawn="); pw.print(allDrawn);
1526 pw.print(" (animator="); pw.print(mAppAnimator.allDrawn);
1527 pw.println(")");
1528 }
1529 if (inPendingTransaction) {
1530 pw.print(prefix); pw.print("inPendingTransaction=");
1531 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001532 }
Craig Mautner799bc1d2015-01-14 10:33:48 -08001533 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001534 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
1535 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -08001536 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -08001537 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001538 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001539 if (startingWindow != null || startingSurface != null
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001540 || startingDisplayed || startingMoved) {
1541 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001542 pw.print(" startingSurface="); pw.print(startingSurface);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001543 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001544 pw.print(" startingMoved="); pw.println(startingMoved);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001545 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01001546 if (!mFrozenBounds.isEmpty()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -08001547 pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds);
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001548 pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig);
Chong Zhangd78ddb42016-03-02 17:01:14 -08001549 }
1550 if (mPendingRelaunchCount != 0) {
1551 pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount);
Jorim Jaggi0429f352015-12-22 16:29:16 +01001552 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001553 }
1554
1555 @Override
1556 public String toString() {
1557 if (stringName == null) {
1558 StringBuilder sb = new StringBuilder();
1559 sb.append("AppWindowToken{");
1560 sb.append(Integer.toHexString(System.identityHashCode(this)));
1561 sb.append(" token="); sb.append(token); sb.append('}');
1562 stringName = sb.toString();
1563 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001564 return stringName + ((mIsExiting) ? " mIsExiting=" : "");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001565 }
Jeff Browne9bdb312012-04-05 15:30:10 -07001566}