blob: 36418bea1940ec2326e39e717797a34e52ed4de5 [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
Wale Ogunwalee287e192017-04-21 09:30:12 -070098 // True if we are current in the process of removing this app token from the display
99 private boolean mRemovingFromDisplay = false;
100
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800101 // The input dispatching timeout for this application token in nanoseconds.
Wale Ogunwale72919d22016-12-08 18:58:50 -0800102 long mInputDispatchingTimeoutNanos;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800103
104 // These are used for determining when all windows associated with
105 // an activity have been drawn, so they can be made visible together
106 // at the same time.
Craig Mautner764983d2012-03-22 11:37:36 -0700107 // initialize so that it doesn't match mTransactionSequence which is an int.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700108 private long mLastTransactionSequence = Long.MIN_VALUE;
109 private int mNumInterestingWindows;
110 private int mNumDrawnWindows;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800111 boolean inPendingTransaction;
112 boolean allDrawn;
Craig Mautner7636dfb2012-11-16 15:24:11 -0800113 // Set to true when this app creates a surface while in the middle of an animation. In that
114 // case do not clear allDrawn until the animation completes.
115 boolean deferClearAllDrawn;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800116
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700117 /**
118 * These are to track the app's real drawing status if there were no saved surfaces.
119 * @see #updateDrawnWindowStates
120 */
Chong Zhang8e4bda92016-05-04 15:08:18 -0700121 boolean allDrawnExcludingSaved;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700122 private int mNumInterestingWindowsExcludingSaved;
123 private int mNumDrawnWindowsExcludingSaved;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700124
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800125 // Is this window's surface needed? This is almost like hidden, except
126 // it will sometimes be true a little earlier: when the token has
127 // been shown, but is still waiting for its app transition to execute
128 // before making its windows shown.
129 boolean hiddenRequested;
130
131 // Have we told the window clients to hide themselves?
Wale Ogunwale89973222017-04-23 18:39:45 -0700132 private boolean mClientHidden;
133
134 // If true we will defer setting mClientHidden to true and reporting to the client that it is
135 // hidden.
136 boolean mDeferHidingClient;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800137
138 // Last visibility state we reported to the app token.
139 boolean reportedVisible;
140
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700141 // Last drawn state we reported to the app token.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700142 private boolean reportedDrawn;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700143
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800144 // Set to true when the token has been removed from the window mgr.
145 boolean removed;
146
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800147 // Information about an application starting window if displayed.
148 StartingData startingData;
149 WindowState startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800150 StartingSurface startingSurface;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800151 boolean startingDisplayed;
152 boolean startingMoved;
153 boolean firstWindowDrawn;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700154 private final WindowState.UpdateReportedVisibilityResults mReportedVisibilityResults =
155 new WindowState.UpdateReportedVisibilityResults();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800156
157 // Input application handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700158 final InputApplicationHandle mInputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800159
Wale Ogunwale571771c2016-08-26 13:18:50 -0700160 // TODO: Have a WindowContainer state for tracking exiting/deferred removal.
Craig Mautner799bc1d2015-01-14 10:33:48 -0800161 boolean mIsExiting;
Craig Mautner9ef471f2014-02-07 13:11:47 -0800162
Craig Mautnerbb742462014-07-07 15:28:55 -0700163 boolean mLaunchTaskBehind;
Craig Mautner8746a472014-07-24 15:12:54 -0700164 boolean mEnteringAnimation;
Craig Mautnerbb742462014-07-07 15:28:55 -0700165
Wale Ogunwale72919d22016-12-08 18:58:50 -0800166 private boolean mAlwaysFocusable;
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800167
Robert Carre12aece2016-02-02 22:43:27 -0800168 boolean mAppStopped;
Robert Carrfd10cd12016-06-29 16:41:50 -0700169 int mRotationAnimationHint;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700170 private int mPendingRelaunchCount;
Robert Carre12aece2016-02-02 22:43:27 -0800171
Jorim Jaggife762342016-10-13 14:33:27 +0200172 private boolean mLastContainsShowWhenLockedWindow;
173 private boolean mLastContainsDismissKeyguardWindow;
174
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700175 // The bounds of this activity. Mainly used for aspect-ratio compatibility.
176 // TODO(b/36505427): Every level on WindowContainer now has bounds information, which directly
177 // affects the configuration. We should probably move this into that class.
178 private final Rect mBounds = new Rect();
179
Jorim Jaggi0429f352015-12-22 16:29:16 +0100180 ArrayDeque<Rect> mFrozenBounds = new ArrayDeque<>();
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700181 ArrayDeque<Configuration> mFrozenMergedConfig = new ArrayDeque<>();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100182
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +0100183 private boolean mDisbalePreviewScreenshots;
184
Robert Carred3e83b2017-04-21 13:26:55 -0700185 Task mLastParent;
186
Wale Ogunwale72919d22016-12-08 18:58:50 -0800187 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
188 DisplayContent dc, long inputDispatchingTimeoutNanos, boolean fullscreen,
189 boolean showForAllUsers, int targetSdk, int orientation, int rotationAnimationHint,
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800190 int configChanges, boolean launchTaskBehind, boolean alwaysFocusable,
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700191 AppWindowContainerController controller, Configuration overrideConfig, Rect bounds) {
192 this(service, token, voiceInteraction, dc, fullscreen, overrideConfig, bounds);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800193 setController(controller);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800194 mInputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800195 mShowForAllUsers = showForAllUsers;
196 mTargetSdk = targetSdk;
197 mOrientation = orientation;
198 layoutConfigChanges = (configChanges & (CONFIG_SCREEN_SIZE | CONFIG_ORIENTATION)) != 0;
199 mLaunchTaskBehind = launchTaskBehind;
200 mAlwaysFocusable = alwaysFocusable;
201 mRotationAnimationHint = rotationAnimationHint;
202
203 // Application tokens start out hidden.
204 hidden = true;
205 hiddenRequested = true;
206 }
207
208 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700209 DisplayContent dc, boolean fillsParent, Configuration overrideConfig, Rect bounds) {
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800210 super(service, token != null ? token.asBinder() : null, TYPE_APPLICATION, true, dc,
211 false /* ownerCanManageAppTokens */);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700212 appToken = token;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800213 mVoiceInteraction = voiceInteraction;
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800214 mFillsParent = fillsParent;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800215 mInputApplicationHandle = new InputApplicationHandle(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700216 mAppAnimator = new AppWindowAnimator(this, service);
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700217 if (overrideConfig != null) {
218 onOverrideConfigurationChanged(overrideConfig);
219 }
220 if (bounds != null) {
221 mBounds.set(bounds);
222 }
223 }
224
225 void onOverrideConfigurationChanged(Configuration overrideConfiguration, Rect bounds) {
226 onOverrideConfigurationChanged(overrideConfiguration);
227 if (mBounds.equals(bounds)) {
228 return;
229 }
230 // TODO(b/36505427): If bounds is in WC, then we can automatically call onResize() when set.
231 mBounds.set(bounds);
232 onResize();
233 }
234
235 void getBounds(Rect outBounds) {
236 outBounds.set(mBounds);
237 }
238
239 boolean hasBounds() {
240 return !mBounds.isEmpty();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800241 }
242
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800243 void onFirstWindowDrawn(WindowState win, WindowStateAnimator winAnimator) {
244 firstWindowDrawn = true;
245
246 // We now have a good window to show, remove dead placeholders
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700247 removeDeadWindows();
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800248
Jorim Jaggi02886a82016-12-06 09:10:06 -0800249 if (startingWindow != null) {
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800250 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, "Finish starting "
251 + win.mToken + ": first real window is shown, no animation");
252 // If this initial window is animating, stop it -- we will do an animation to reveal
253 // it from behind the starting window, so there is no need for it to also be doing its
254 // own stuff.
255 winAnimator.clearAnimation();
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800256 if (getController() != null) {
257 getController().removeStartingWindow();
258 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800259 }
260 updateReportedVisibilityLocked();
261 }
262
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800263 void updateReportedVisibilityLocked() {
264 if (appToken == null) {
265 return;
266 }
267
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700268 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700269 final int count = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800270
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700271 mReportedVisibilityResults.reset();
272
273 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700274 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700275 win.updateReportedVisibility(mReportedVisibilityResults);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800276 }
277
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700278 int numInteresting = mReportedVisibilityResults.numInteresting;
279 int numVisible = mReportedVisibilityResults.numVisible;
280 int numDrawn = mReportedVisibilityResults.numDrawn;
281 boolean nowGone = mReportedVisibilityResults.nowGone;
282
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700283 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800284 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700285 if (!nowGone) {
286 // If the app is not yet gone, then it can only become visible/drawn.
287 if (!nowDrawn) {
288 nowDrawn = reportedDrawn;
289 }
290 if (!nowVisible) {
291 nowVisible = reportedVisible;
292 }
293 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800294 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800295 + numInteresting + " visible=" + numVisible);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800296 final AppWindowContainerController controller = getController();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700297 if (nowDrawn != reportedDrawn) {
298 if (nowDrawn) {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800299 if (controller != null) {
300 controller.reportWindowsDrawn();
301 }
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700302 }
303 reportedDrawn = nowDrawn;
304 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800305 if (nowVisible != reportedVisible) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700306 if (DEBUG_VISIBILITY) Slog.v(TAG,
307 "Visibility changed in " + this + ": vis=" + nowVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800308 reportedVisible = nowVisible;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800309 if (controller != null) {
310 if (nowVisible) {
311 controller.reportWindowsVisible();
312 } else {
313 controller.reportWindowsGone();
314 }
315 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800316 }
317 }
318
Wale Ogunwale89973222017-04-23 18:39:45 -0700319 boolean isClientHidden() {
320 return mClientHidden;
321 }
322
323 void setClientHidden(boolean hideClient) {
324 if (mClientHidden == hideClient || (hideClient && mDeferHidingClient)) {
325 return;
326 }
327 mClientHidden = hideClient;
328 sendAppVisibilityToClients();
329 }
330
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700331 boolean setVisibility(WindowManager.LayoutParams lp,
332 boolean visible, int transit, boolean performLayout, boolean isVoiceInteraction) {
333
334 boolean delayed = false;
335 inPendingTransaction = false;
336
Wale Ogunwale89973222017-04-23 18:39:45 -0700337 setClientHidden(!visible);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700338
339 // Allow for state changes and animation to be applied if:
340 // * token is transitioning visibility state
341 // * or the token was marked as hidden and is exiting before we had a chance to play the
342 // transition animation
343 // * or this is an opening app and windows are being replaced.
344 boolean visibilityChanged = false;
345 if (hidden == visible || (hidden && mIsExiting) || (visible && waitingForReplacement())) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700346 final AccessibilityController accessibilityController = mService.mAccessibilityController;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700347 boolean changed = false;
348 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
349 "Changing app " + this + " hidden=" + hidden + " performLayout=" + performLayout);
350
351 boolean runningAppAnimation = false;
352
353 if (transit != AppTransition.TRANSIT_UNSET) {
354 if (mAppAnimator.animation == AppWindowAnimator.sDummyAnimation) {
355 mAppAnimator.setNullAnimation();
356 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700357 if (mService.applyAnimationLocked(this, lp, transit, visible, isVoiceInteraction)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700358 delayed = runningAppAnimation = true;
359 }
360 final WindowState window = findMainWindow();
361 //TODO (multidisplay): Magnification is supported only for the default display.
362 if (window != null && accessibilityController != null
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700363 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700364 accessibilityController.onAppWindowTransitionLocked(window, transit);
365 }
366 changed = true;
367 }
368
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700369 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700370 for (int i = 0; i < windowsCount; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700371 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700372 changed |= win.onAppVisibilityChanged(visible, runningAppAnimation);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700373 }
374
375 hidden = hiddenRequested = !visible;
376 visibilityChanged = true;
377 if (!visible) {
378 stopFreezingScreen(true, true);
379 } else {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700380 // If we are being set visible, and the starting window is not yet displayed,
381 // then make sure it doesn't get displayed.
382 if (startingWindow != null && !startingWindow.isDrawnLw()) {
383 startingWindow.mPolicyVisibility = false;
384 startingWindow.mPolicyVisibilityAfterAnim = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700385 }
386 }
387
388 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setVisibility: " + this
389 + ": hidden=" + hidden + " hiddenRequested=" + hiddenRequested);
390
391 if (changed) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700392 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700393 if (performLayout) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700394 mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700395 false /*updateInputWindows*/);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700396 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700397 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700398 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700399 }
400 }
401
402 if (mAppAnimator.animation != null) {
403 delayed = true;
404 }
405
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700406 for (int i = mChildren.size() - 1; i >= 0 && !delayed; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700407 if ((mChildren.get(i)).isWindowAnimationSet()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700408 delayed = true;
409 }
410 }
411
412 if (visibilityChanged) {
413 if (visible && !delayed) {
414 // The token was made immediately visible, there will be no entrance animation.
415 // We need to inform the client the enter animation was finished.
416 mEnteringAnimation = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700417 mService.mActivityManagerAppTransitionNotifier.onAppTransitionFinishedLocked(token);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700418 }
Robert Carre7cc44d2017-03-20 19:04:30 -0700419 // If we are hidden but there is no delay needed we immediately
420 // apply the Surface transaction so that the ActivityManager
421 // can have some guarantee on the Surface state
422 // following setting the visibility.
Robert Carr6914f082017-03-20 19:04:30 -0700423 if (hidden && !delayed) {
424 SurfaceControl.openTransaction();
425 for (int i = mChildren.size() - 1; i >= 0; i--) {
426 mChildren.get(i).mWinAnimator.hide("immediately hidden");
427 }
428 SurfaceControl.closeTransaction();
429 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700430
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700431 if (!mService.mClosingApps.contains(this) && !mService.mOpeningApps.contains(this)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700432 // The token is not closing nor opening, so even if there is an animation set, that
433 // doesn't mean that it goes through the normal app transition cycle so we have
434 // to inform the docked controller about visibility change.
Andrii Kulian1e32e022016-09-16 15:29:34 -0700435 // TODO(multi-display): notify docked divider on all displays where visibility was
436 // affected.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700437 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700438 .notifyAppVisibilityChanged();
Jorim Jaggi8b702ed2017-01-20 16:59:03 +0100439 mService.mTaskSnapshotController.notifyAppVisibilityChanged(this, visible);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700440 }
441 }
442
443 return delayed;
444 }
445
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800446 WindowState findMainWindow() {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700447 WindowState candidate = null;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700448 int j = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800449 while (j > 0) {
450 j--;
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700451 final WindowState win = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700452 final int type = win.mAttrs.type;
453 // No need to loop through child window as base application and starting types can't be
454 // child windows.
455 if (type == TYPE_BASE_APPLICATION || type == TYPE_APPLICATION_STARTING) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700456 // In cases where there are multiple windows, we prefer the non-exiting window. This
Sungsoo Lim0d3d1f82015-12-02 14:47:59 +0900457 // happens for example when replacing windows during an activity relaunch. When
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700458 // constructing the animation, we want the new window, not the exiting one.
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800459 if (win.mAnimatingExit) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700460 candidate = win;
461 } else {
462 return win;
463 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800464 }
465 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700466 return candidate;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800467 }
468
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800469 boolean windowsAreFocusable() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800470 return StackId.canReceiveKeys(getTask().mStack.mStackId) || mAlwaysFocusable;
Wale Ogunwaled045c822015-12-02 09:14:28 -0800471 }
472
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800473 AppWindowContainerController getController() {
474 final WindowContainerController controller = super.getController();
475 return controller != null ? (AppWindowContainerController) controller : null;
476 }
477
Wale Ogunwale571771c2016-08-26 13:18:50 -0700478 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -0700479 boolean isVisible() {
Wale Ogunwalee471be62016-10-03 07:53:55 -0700480 // If the app token isn't hidden then it is considered visible and there is no need to check
481 // its children windows to see if they are visible.
482 return !hidden;
Wale Ogunwale44f21802016-09-02 12:49:48 -0700483 }
484
485 @Override
Wale Ogunwalee287e192017-04-21 09:30:12 -0700486 void removeImmediately() {
487 onRemovedFromDisplay();
488 super.removeImmediately();
489 }
490
491 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -0700492 void removeIfPossible() {
Craig Mautnere3119b72015-01-20 15:02:36 -0800493 mIsExiting = false;
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800494 removeAllWindowsIfPossible();
Bryce Lee6d410262017-02-28 15:30:17 -0800495 removeImmediately();
Craig Mautnere3119b72015-01-20 15:02:36 -0800496 }
497
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700498 @Override
499 boolean checkCompleteDeferredRemoval() {
500 if (mIsExiting) {
501 removeIfPossible();
502 }
503 return super.checkCompleteDeferredRemoval();
504 }
505
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700506 void onRemovedFromDisplay() {
Wale Ogunwalee287e192017-04-21 09:30:12 -0700507 if (mRemovingFromDisplay) {
508 return;
509 }
510 mRemovingFromDisplay = true;
511
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700512 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app token: " + this);
513
Wale Ogunwale72919d22016-12-08 18:58:50 -0800514 boolean delayed = setVisibility(null, false, TRANSIT_UNSET, true, mVoiceInteraction);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700515
516 mService.mOpeningApps.remove(this);
Jorim Jaggi1b4b23e2016-11-15 16:30:12 -0800517 mService.mUnknownAppVisibilityController.appRemoved(this);
Jorim Jaggi10abe2f2017-01-03 16:44:46 +0100518 mService.mTaskSnapshotController.onAppRemoved(this);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700519 waitingToShow = false;
520 if (mService.mClosingApps.contains(this)) {
521 delayed = true;
522 } else if (mService.mAppTransition.isTransitionSet()) {
523 mService.mClosingApps.add(this);
524 delayed = true;
525 }
526
527 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app " + this + " delayed=" + delayed
528 + " animation=" + mAppAnimator.animation + " animating=" + mAppAnimator.animating);
529
530 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM, "removeAppToken: "
531 + this + " delayed=" + delayed + " Callers=" + Debug.getCallers(4));
532
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800533 if (startingData != null && getController() != null) {
534 getController().removeStartingWindow();
535 }
536
Winson Chung87e5d552017-04-05 11:49:38 -0700537 // If this window was animating, then we need to ensure that the app transition notifies
538 // that animations have completed in WMS.handleAnimatingStoppedAndTransitionLocked(), so
539 // add to that list now
540 if (mAppAnimator.animating) {
541 mService.mNoAnimationNotifyOnTransitionFinished.add(token);
542 }
543
Wale Ogunwalee287e192017-04-21 09:30:12 -0700544 final TaskStack stack = getStack();
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700545 if (delayed && !isEmpty()) {
546 // set the token aside because it has an active animation to be finished
547 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM,
548 "removeAppToken make exiting: " + this);
Wale Ogunwalee287e192017-04-21 09:30:12 -0700549 if (stack != null) {
550 stack.mExitingAppTokens.add(this);
551 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700552 mIsExiting = true;
553 } else {
554 // Make sure there is no animation running on this token, so any windows associated
555 // with it will be removed as soon as their animations are complete
556 mAppAnimator.clearAnimation();
557 mAppAnimator.animating = false;
558 removeIfPossible();
559 }
560
561 removed = true;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700562 stopFreezingScreen(true, true);
Bryce Lee6d410262017-02-28 15:30:17 -0800563
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700564 if (mService.mFocusedApp == this) {
565 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "Removing focused app token:" + this);
566 mService.mFocusedApp = null;
567 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
568 mService.mInputMonitor.setFocusedAppLw(null);
569 }
570
571 if (!delayed) {
572 updateReportedVisibilityLocked();
573 }
Wale Ogunwalee287e192017-04-21 09:30:12 -0700574
575 mRemovingFromDisplay = false;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700576 }
577
Chong Zhange05bcb12016-07-26 17:47:29 -0700578 void clearAnimatingFlags() {
Chong Zhangb0d26702016-08-12 16:03:29 -0700579 boolean wallpaperMightChange = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700580 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700581 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700582 wallpaperMightChange |= win.clearAnimatingFlags();
Chong Zhange05bcb12016-07-26 17:47:29 -0700583 }
Chong Zhangb0d26702016-08-12 16:03:29 -0700584 if (wallpaperMightChange) {
585 requestUpdateWallpaperIfNeeded();
586 }
Chong Zhange05bcb12016-07-26 17:47:29 -0700587 }
588
Robert Carre12aece2016-02-02 22:43:27 -0800589 void destroySurfaces() {
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700590 destroySurfaces(false /*cleanupOnResume*/);
591 }
592
593 /**
594 * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure
595 * the client has finished with them.
596 *
597 * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If
598 * set to true, destroy only surfaces of removed windows, and clear relevant flags of the
599 * others so that they are ready to be reused. If set to false (common case), destroy all
600 * surfaces that's eligible, if the app is already stopped.
601 */
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700602 private void destroySurfaces(boolean cleanupOnResume) {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700603 boolean destroyedSomething = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700604 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700605 final WindowState win = mChildren.get(i);
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700606 destroyedSomething |= win.destroySurface(cleanupOnResume, mAppStopped);
Robert Carre12aece2016-02-02 22:43:27 -0800607 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700608 if (destroyedSomething) {
609 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700610 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Robert Carre12aece2016-02-02 22:43:27 -0800611 }
612 }
613
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800614 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700615 * Notify that the app is now resumed, and it was not stopped before, perform a clean
616 * up of the surfaces
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800617 */
Jorim Jaggibae01b12017-04-11 16:29:10 -0700618 void notifyAppResumed(boolean wasStopped) {
Chong Zhangad24f962016-08-25 12:12:33 -0700619 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped
Jorim Jaggibae01b12017-04-11 16:29:10 -0700620 + " " + this);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700621 mAppStopped = false;
622 if (!wasStopped) {
623 destroySurfaces(true /*cleanupOnResume*/);
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800624 }
Robert Carre12aece2016-02-02 22:43:27 -0800625 }
626
Chong Zhangbef461f2015-10-27 11:38:24 -0700627 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700628 * Notify that the app has stopped, and it is okay to destroy any surfaces which were
629 * keeping alive in case they were still being used.
630 */
631 void notifyAppStopped() {
632 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this);
633 mAppStopped = true;
634 destroySurfaces();
635 // Remove any starting window that was added for this app if they are still around.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800636 if (getController() != null) {
637 getController().removeStartingWindow();
638 }
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700639 }
640
641 /**
Chong Zhangbef461f2015-10-27 11:38:24 -0700642 * Checks whether we should save surfaces for this app.
643 *
644 * @return true if the surfaces should be saved, false otherwise.
645 */
646 boolean shouldSaveSurface() {
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800647 // We want to save surface if the app's windows are "allDrawn".
648 // (If we started entering animation early with saved surfaces, allDrawn
649 // should have been restored to true. So we'll save again in that case
650 // even if app didn't actually finish drawing.)
651 return allDrawn;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800652 }
653
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700654 private boolean canRestoreSurfaces() {
655 for (int i = mChildren.size() -1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700656 final WindowState w = mChildren.get(i);
Chong Zhang92147042016-05-09 12:47:11 -0700657 if (w.canRestoreSurface()) {
Robert Carr13f7be9e2015-12-02 18:39:45 -0800658 return true;
659 }
Chong Zhangbef461f2015-10-27 11:38:24 -0700660 }
661 return false;
662 }
663
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700664 private void clearWasVisibleBeforeClientHidden() {
665 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.clearWasVisibleBeforeClientHidden();
Chong Zhang92147042016-05-09 12:47:11 -0700668 }
669 }
670
Chong Zhang8e4bda92016-05-04 15:08:18 -0700671 /**
672 * Whether the app has some window that is invisible in layout, but
673 * animating with saved surface.
674 */
675 boolean isAnimatingInvisibleWithSavedSurface() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700676 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700677 final WindowState w = mChildren.get(i);
Chong Zhang8e4bda92016-05-04 15:08:18 -0700678 if (w.isAnimatingInvisibleWithSavedSurface()) {
679 return true;
680 }
681 }
682 return false;
683 }
684
685 /**
686 * Hide all window surfaces that's still invisible in layout but animating
687 * with a saved surface, and mark them destroying.
688 */
689 void stopUsingSavedSurfaceLocked() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700690 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700691 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700692 w.stopUsingSavedSurface();
Chong Zhang8e4bda92016-05-04 15:08:18 -0700693 }
694 destroySurfaces();
695 }
696
Chong Zhangf58631a2016-05-24 16:02:10 -0700697 void markSavedSurfaceExiting() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700698 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700699 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700700 w.markSavedSurfaceExiting();
Chong Zhangf58631a2016-05-24 16:02:10 -0700701 }
702 }
703
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700704 void restoreSavedSurfaceForInterestingWindows() {
Chong Zhang92147042016-05-09 12:47:11 -0700705 if (!canRestoreSurfaces()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700706 clearWasVisibleBeforeClientHidden();
Chong Zhangbef461f2015-10-27 11:38:24 -0700707 return;
708 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700709
710 // Check if all interesting windows are drawn and we can mark allDrawn=true.
711 int interestingNotDrawn = -1;
712
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700713 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700714 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700715 interestingNotDrawn = w.restoreSavedSurfaceForInterestingWindow();
Chong Zhangbef461f2015-10-27 11:38:24 -0700716 }
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800717
Chong Zhang92147042016-05-09 12:47:11 -0700718 if (!allDrawn) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700719 allDrawn = (interestingNotDrawn == 0);
Chong Zhang92147042016-05-09 12:47:11 -0700720 if (allDrawn) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700721 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Chong Zhang92147042016-05-09 12:47:11 -0700722 }
723 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700724 clearWasVisibleBeforeClientHidden();
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800725
726 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700727 "restoreSavedSurfaceForInterestingWindows: " + this + " allDrawn=" + allDrawn
728 + " interestingNotDrawn=" + interestingNotDrawn);
Chong Zhangbef461f2015-10-27 11:38:24 -0700729 }
730
731 void destroySavedSurfaces() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700732 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700733 final WindowState win = mChildren.get(i);
Robert Carr13f7be9e2015-12-02 18:39:45 -0800734 win.destroySavedSurface();
Chong Zhangbef461f2015-10-27 11:38:24 -0700735 }
Chong Zhang92147042016-05-09 12:47:11 -0700736 }
737
738 void clearAllDrawn() {
739 allDrawn = false;
740 deferClearAllDrawn = false;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700741 allDrawnExcludingSaved = false;
Chong Zhangbef461f2015-10-27 11:38:24 -0700742 }
743
Bryce Lee6d410262017-02-28 15:30:17 -0800744 Task getTask() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800745 return (Task) getParent();
Bryce Lee6d410262017-02-28 15:30:17 -0800746 }
747
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800748 TaskStack getStack() {
749 final Task task = getTask();
750 if (task != null) {
751 return task.mStack;
752 } else {
753 return null;
754 }
755 }
756
Bryce Lee6d410262017-02-28 15:30:17 -0800757 @Override
758 void onParentSet() {
759 super.onParentSet();
760
Robert Carred3e83b2017-04-21 13:26:55 -0700761 final Task task = getTask();
762
Bryce Lee6d410262017-02-28 15:30:17 -0800763 // When the associated task is {@code null}, the {@link AppWindowToken} can no longer
764 // access visual elements like the {@link DisplayContent}. We must remove any associations
765 // such as animations.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800766 if (!mReparenting) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800767 if (task == null) {
768 // It is possible we have been marked as a closing app earlier. We must remove ourselves
769 // from this list so we do not participate in any future animations.
770 mService.mClosingApps.remove(this);
Robert Carred3e83b2017-04-21 13:26:55 -0700771 } else if (mLastParent != null && mLastParent.mStack != null) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800772 task.mStack.mExitingAppTokens.remove(this);
773 }
Bryce Lee6d410262017-02-28 15:30:17 -0800774 }
Robert Carred3e83b2017-04-21 13:26:55 -0700775 mLastParent = task;
Bryce Lee6d410262017-02-28 15:30:17 -0800776 }
777
Wale Ogunwalefa854eb2016-09-20 13:43:52 -0700778 void postWindowRemoveStartingWindowCleanup(WindowState win) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700779 // TODO: Something smells about the code below...Is there a better way?
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700780 if (startingWindow == win) {
781 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800782 if (getController() != null) {
783 getController().removeStartingWindow();
784 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700785 } else if (mChildren.size() == 0 && startingData != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700786 // If this is the last window and we had requested a starting transition window,
787 // well there is no point now.
Jorim Jaggi02886a82016-12-06 09:10:06 -0800788 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingData");
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700789 startingData = null;
Jorim Jaggi829b9cd2017-01-23 16:20:53 +0100790 } else if (mChildren.size() == 1 && startingSurface != null && !isRelaunching()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700791 // If this is the last window except for a starting transition window,
792 // we need to get rid of the starting transition.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800793 if (getController() != null) {
794 getController().removeStartingWindow();
795 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700796 }
797 }
798
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700799 void removeDeadWindows() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700800 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700801 WindowState win = mChildren.get(winNdx);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800802 if (win.mAppDied) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700803 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700804 "removeDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800805 // Set mDestroying, we don't want any animation or delayed removal here.
806 win.mDestroying = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700807 // Also removes child windows.
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700808 win.removeIfPossible();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800809 }
810 }
811 }
812
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700813 boolean hasWindowsAlive() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700814 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700815 // No need to loop through child windows as the answer should be the same as that of the
816 // parent window.
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700817 if (!(mChildren.get(i)).mAppDied) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700818 return true;
819 }
820 }
821 return false;
822 }
823
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700824 void setWillReplaceWindows(boolean animate) {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700825 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
826 "Marking app token " + this + " with replacing windows.");
Robert Carra1eb4392015-12-10 12:43:51 -0800827
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700828 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700829 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700830 w.setWillReplaceWindow(animate);
Robert Carra1eb4392015-12-10 12:43:51 -0800831 }
832 if (animate) {
833 // Set-up dummy animation so we can start treating windows associated with this
834 // token like they are in transition before the new app window is ready for us to
835 // run the real transition animation.
836 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700837 "setWillReplaceWindow() Setting dummy animation on: " + this);
Robert Carra1eb4392015-12-10 12:43:51 -0800838 mAppAnimator.setDummyAnimation();
839 }
840 }
841
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700842 void setWillReplaceChildWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700843 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this
Robert Carr23fa16b2016-01-13 13:19:58 -0800844 + " with replacing child windows.");
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700845 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700846 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700847 w.setWillReplaceChildWindows();
Robert Carr23fa16b2016-01-13 13:19:58 -0800848 }
849 }
850
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700851 void clearWillReplaceWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700852 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
853 "Resetting app token " + this + " of replacing window marks.");
Chong Zhangf596cd52016-01-05 13:42:44 -0800854
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700855 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700856 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700857 w.clearWillReplaceWindow();
Chong Zhangf596cd52016-01-05 13:42:44 -0800858 }
859 }
860
Chong Zhang4d7369a2016-04-25 16:09:14 -0700861 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700862 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700863 final WindowState w = mChildren.get(i);
Chong Zhang4d7369a2016-04-25 16:09:14 -0700864 w.requestUpdateWallpaperIfNeeded();
865 }
866 }
867
Chong Zhangd78ddb42016-03-02 17:01:14 -0800868 boolean isRelaunching() {
869 return mPendingRelaunchCount > 0;
870 }
871
872 void startRelaunching() {
873 if (canFreezeBounds()) {
874 freezeBounds();
875 }
Robert Carrd5c7dd62017-03-08 10:39:30 -0800876
877 // In the process of tearing down before relaunching, the app will
878 // try and clean up it's child surfaces. We need to prevent this from
879 // happening, so we sever the children, transfering their ownership
880 // from the client it-self to the parent surface (owned by us).
881 for (int i = mChildren.size() - 1; i >= 0; i--) {
882 final WindowState w = mChildren.get(i);
883 w.mWinAnimator.detachChildren();
884 }
885
Chong Zhangd78ddb42016-03-02 17:01:14 -0800886 mPendingRelaunchCount++;
887 }
888
889 void finishRelaunching() {
890 if (canFreezeBounds()) {
891 unfreezeBounds();
892 }
893 if (mPendingRelaunchCount > 0) {
894 mPendingRelaunchCount--;
895 }
Matthew Ng498c71d2017-04-18 13:55:45 -0700896 updateAllDrawn();
Chong Zhangd78ddb42016-03-02 17:01:14 -0800897 }
898
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700899 void clearRelaunching() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700900 if (mPendingRelaunchCount == 0) {
901 return;
902 }
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700903 if (canFreezeBounds()) {
904 unfreezeBounds();
905 }
906 mPendingRelaunchCount = 0;
907 }
908
Wale Ogunwale07bcab72016-10-14 15:30:09 -0700909 /**
910 * Returns true if the new child window we are adding to this token is considered greater than
911 * the existing child window in this token in terms of z-order.
912 */
913 @Override
914 protected boolean isFirstChildWindowGreaterThanSecond(WindowState newWindow,
915 WindowState existingWindow) {
916 final int type1 = newWindow.mAttrs.type;
917 final int type2 = existingWindow.mAttrs.type;
918
919 // Base application windows should be z-ordered BELOW all other windows in the app token.
920 if (type1 == TYPE_BASE_APPLICATION && type2 != TYPE_BASE_APPLICATION) {
921 return false;
922 } else if (type1 != TYPE_BASE_APPLICATION && type2 == TYPE_BASE_APPLICATION) {
923 return true;
924 }
925
926 // Starting windows should be z-ordered ABOVE all other windows in the app token.
927 if (type1 == TYPE_APPLICATION_STARTING && type2 != TYPE_APPLICATION_STARTING) {
928 return true;
929 } else if (type1 != TYPE_APPLICATION_STARTING && type2 == TYPE_APPLICATION_STARTING) {
930 return false;
931 }
932
933 // Otherwise the new window is greater than the existing window.
934 return true;
935 }
936
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700937 @Override
Robert Carra1eb4392015-12-10 12:43:51 -0800938 void addWindow(WindowState w) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700939 super.addWindow(w);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700940
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700941 boolean gotReplacementWindow = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700942 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700943 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700944 gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w);
945 }
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700946
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700947 // if we got a replacement window, reset the timeout to give drawing more time
948 if (gotReplacementWindow) {
949 mService.scheduleWindowReplacementTimeouts(this);
Robert Carra1eb4392015-12-10 12:43:51 -0800950 }
Jorim Jaggife762342016-10-13 14:33:27 +0200951 checkKeyguardFlagsChanged();
952 }
953
954 @Override
955 void removeChild(WindowState child) {
956 super.removeChild(child);
957 checkKeyguardFlagsChanged();
Robert Carra1eb4392015-12-10 12:43:51 -0800958 }
959
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700960 private boolean waitingForReplacement() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700961 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700962 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700963 if (candidate.waitingForReplacement()) {
Robert Carra1eb4392015-12-10 12:43:51 -0800964 return true;
965 }
966 }
967 return false;
968 }
969
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700970 void onWindowReplacementTimeout() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700971 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700972 (mChildren.get(i)).onWindowReplacementTimeout();
Robert Carra1eb4392015-12-10 12:43:51 -0800973 }
974 }
975
Winson Chung30480042017-01-26 10:55:34 -0800976 void reparent(Task task, int position) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800977 final Task currentTask = getTask();
978 if (task == currentTask) {
Winson Chung30480042017-01-26 10:55:34 -0800979 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800980 "window token=" + this + " already child of task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -0800981 }
Bryce Lee6d410262017-02-28 15:30:17 -0800982
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800983 if (currentTask.mStack != task.mStack) {
Bryce Lee6d410262017-02-28 15:30:17 -0800984 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800985 "window token=" + this + " current task=" + currentTask
Bryce Lee6d410262017-02-28 15:30:17 -0800986 + " belongs to a different stack than " + task);
987 }
988
Winson Chung30480042017-01-26 10:55:34 -0800989 if (DEBUG_ADD_REMOVE) Slog.i(TAG, "reParentWindowToken: removing window token=" + this
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800990 + " from task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -0800991 final DisplayContent prevDisplayContent = getDisplayContent();
992
Bryce Lee6d410262017-02-28 15:30:17 -0800993 mReparenting = true;
994
Winson Chung30480042017-01-26 10:55:34 -0800995 getParent().removeChild(this);
996 task.addChild(this, position);
997
Bryce Lee6d410262017-02-28 15:30:17 -0800998 mReparenting = false;
999
Winson Chung30480042017-01-26 10:55:34 -08001000 // Relayout display(s).
1001 final DisplayContent displayContent = task.getDisplayContent();
1002 displayContent.setLayoutNeeded();
1003 if (prevDisplayContent != displayContent) {
1004 onDisplayChanged(displayContent);
1005 prevDisplayContent.setLayoutNeeded();
1006 }
1007 }
1008
Chong Zhangd78ddb42016-03-02 17:01:14 -08001009 private boolean canFreezeBounds() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001010 final Task task = getTask();
1011
Chong Zhangd78ddb42016-03-02 17:01:14 -08001012 // For freeform windows, we can't freeze the bounds at the moment because this would make
1013 // the resizing unresponsive.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001014 return task != null && !task.inFreeformWorkspace();
Chong Zhangd78ddb42016-03-02 17:01:14 -08001015 }
1016
Jorim Jaggi0429f352015-12-22 16:29:16 +01001017 /**
1018 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
1019 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
1020 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
1021 * with a queue.
1022 */
Chong Zhangd78ddb42016-03-02 17:01:14 -08001023 private void freezeBounds() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001024 final Task task = getTask();
1025 mFrozenBounds.offer(new Rect(task.mPreparedFrozenBounds));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001026
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001027 if (task.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) {
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001028 // We didn't call prepareFreezingBounds on the task, so use the current value.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001029 mFrozenMergedConfig.offer(new Configuration(task.getConfiguration()));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001030 } else {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001031 mFrozenMergedConfig.offer(new Configuration(task.mPreparedFrozenMergedConfig));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001032 }
Andrii Kulianb10330d2016-09-16 13:51:46 -07001033 // Calling unset() to make it equal to Configuration.EMPTY.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001034 task.mPreparedFrozenMergedConfig.unset();
Jorim Jaggi0429f352015-12-22 16:29:16 +01001035 }
1036
1037 /**
1038 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
1039 */
Chong Zhangd78ddb42016-03-02 17:01:14 -08001040 private void unfreezeBounds() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -07001041 if (!mFrozenBounds.isEmpty()) {
1042 mFrozenBounds.remove();
1043 }
1044 if (!mFrozenMergedConfig.isEmpty()) {
1045 mFrozenMergedConfig.remove();
1046 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001047 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001048 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001049 win.onUnfreezeBounds();
Jorim Jaggi4846ee32016-01-07 17:39:12 +01001050 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001051 mService.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +01001052 }
1053
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001054 void setAppLayoutChanges(int changes, String reason) {
1055 if (!mChildren.isEmpty()) {
1056 final DisplayContent dc = getDisplayContent();
1057 dc.pendingLayoutChanges |= changes;
1058 if (DEBUG_LAYOUT_REPEATS) {
1059 mService.mWindowPlacerLocked.debugLayoutRepeats(reason, dc.pendingLayoutChanges);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001060 }
1061 }
1062 }
1063
1064 void removeReplacedWindowIfNeeded(WindowState replacement) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001065 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001066 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001067 if (win.removeReplacedWindowIfNeeded(replacement)) {
1068 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001069 }
1070 }
1071 }
1072
1073 void startFreezingScreen() {
1074 if (DEBUG_ORIENTATION) logWithStack(TAG, "Set freezing of " + appToken + ": hidden="
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001075 + hidden + " freezing=" + mAppAnimator.freezingScreen + " hiddenRequested="
1076 + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001077 if (!hiddenRequested) {
1078 if (!mAppAnimator.freezingScreen) {
1079 mAppAnimator.freezingScreen = true;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001080 mService.registerAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001081 mAppAnimator.lastFreezeDuration = 0;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001082 mService.mAppsFreezingScreen++;
1083 if (mService.mAppsFreezingScreen == 1) {
1084 mService.startFreezingDisplayLocked(false, 0, 0);
1085 mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT);
1086 mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001087 }
1088 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001089 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001090 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001091 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001092 w.onStartFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001093 }
1094 }
1095 }
1096
1097 void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) {
1098 if (!mAppAnimator.freezingScreen) {
1099 return;
1100 }
1101 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + this + " force=" + force);
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001102 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001103 boolean unfrozeWindows = false;
1104 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001105 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001106 unfrozeWindows |= w.onStopFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001107 }
1108 if (force || unfrozeWindows) {
1109 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this);
1110 mAppAnimator.freezingScreen = false;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001111 mService.unregisterAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001112 mAppAnimator.lastFreezeDuration =
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001113 (int)(SystemClock.elapsedRealtime() - mService.mDisplayFreezeTime);
1114 mService.mAppsFreezingScreen--;
1115 mService.mLastFinishedFreezeSource = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001116 }
1117 if (unfreezeSurfaceNow) {
1118 if (unfrozeWindows) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001119 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001120 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001121 mService.stopFreezingDisplayLocked();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001122 }
1123 }
1124
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001125 @Override
1126 public void onAppFreezeTimeout() {
1127 Slog.w(TAG_WM, "Force clearing freeze: " + this);
1128 stopFreezingScreen(true, true);
1129 }
1130
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001131 boolean transferStartingWindow(IBinder transferFrom) {
Wale Ogunwale02319a62016-09-26 15:21:22 -07001132 final AppWindowToken fromToken = getDisplayContent().getAppWindowToken(transferFrom);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001133 if (fromToken == null) {
1134 return false;
1135 }
1136
1137 final WindowState tStartingWindow = fromToken.startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001138 if (tStartingWindow != null && fromToken.startingSurface != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001139 // In this case, the starting icon has already been displayed, so start
1140 // letting windows get shown immediately without any more transitions.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001141 mService.mSkipAppTransitionAnimation = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001142
1143 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow
1144 + " from " + fromToken + " to " + this);
1145
1146 final long origId = Binder.clearCallingIdentity();
1147
1148 // Transfer the starting window over to the new token.
1149 startingData = fromToken.startingData;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001150 startingSurface = fromToken.startingSurface;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001151 startingDisplayed = fromToken.startingDisplayed;
1152 fromToken.startingDisplayed = false;
1153 startingWindow = tStartingWindow;
1154 reportedVisible = fromToken.reportedVisible;
1155 fromToken.startingData = null;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001156 fromToken.startingSurface = null;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001157 fromToken.startingWindow = null;
1158 fromToken.startingMoved = true;
1159 tStartingWindow.mToken = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001160 tStartingWindow.mAppToken = this;
1161
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001162 if (DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001163 "Removing starting " + tStartingWindow + " from " + fromToken);
Wale Ogunwalefa854eb2016-09-20 13:43:52 -07001164 fromToken.removeChild(tStartingWindow);
1165 fromToken.postWindowRemoveStartingWindowCleanup(tStartingWindow);
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001166 addWindow(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001167
1168 // Propagate other interesting state between the tokens. If the old token is displayed,
1169 // we should immediately force the new one to be displayed. If it is animating, we need
1170 // to move that animation to the new one.
1171 if (fromToken.allDrawn) {
1172 allDrawn = true;
1173 deferClearAllDrawn = fromToken.deferClearAllDrawn;
1174 }
1175 if (fromToken.firstWindowDrawn) {
1176 firstWindowDrawn = true;
1177 }
1178 if (!fromToken.hidden) {
1179 hidden = false;
1180 hiddenRequested = false;
1181 }
Wale Ogunwale89973222017-04-23 18:39:45 -07001182 setClientHidden(fromToken.mClientHidden);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001183 fromToken.mAppAnimator.transferCurrentAnimation(
1184 mAppAnimator, tStartingWindow.mWinAnimator);
1185
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001186 mService.updateFocusedWindowLocked(
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001187 UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/);
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001188 getDisplayContent().setLayoutNeeded();
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001189 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001190 Binder.restoreCallingIdentity(origId);
1191 return true;
1192 } else if (fromToken.startingData != null) {
1193 // The previous app was getting ready to show a
1194 // starting window, but hasn't yet done so. Steal it!
1195 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1196 "Moving pending starting from " + fromToken + " to " + this);
1197 startingData = fromToken.startingData;
1198 fromToken.startingData = null;
1199 fromToken.startingMoved = true;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001200 if (getController() != null) {
1201 getController().scheduleAddStartingWindow();
1202 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001203 return true;
1204 }
1205
1206 final AppWindowAnimator tAppAnimator = fromToken.mAppAnimator;
1207 final AppWindowAnimator wAppAnimator = mAppAnimator;
1208 if (tAppAnimator.thumbnail != null) {
1209 // The old token is animating with a thumbnail, transfer that to the new token.
1210 if (wAppAnimator.thumbnail != null) {
1211 wAppAnimator.thumbnail.destroy();
1212 }
1213 wAppAnimator.thumbnail = tAppAnimator.thumbnail;
1214 wAppAnimator.thumbnailLayer = tAppAnimator.thumbnailLayer;
1215 wAppAnimator.thumbnailAnimation = tAppAnimator.thumbnailAnimation;
1216 tAppAnimator.thumbnail = null;
1217 }
1218 return false;
1219 }
1220
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001221 boolean isLastWindow(WindowState win) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001222 return mChildren.size() == 1 && mChildren.get(0) == win;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001223 }
1224
1225 void setAllAppWinAnimators() {
1226 final ArrayList<WindowStateAnimator> allAppWinAnimators = mAppAnimator.mAllAppWinAnimators;
1227 allAppWinAnimators.clear();
1228
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001229 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001230 for (int j = 0; j < windowsCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001231 (mChildren.get(j)).addWinAnimatorToList(allAppWinAnimators);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001232 }
1233 }
1234
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001235 @Override
1236 void onAppTransitionDone() {
1237 sendingToBottom = false;
1238 }
1239
Wale Ogunwale51362492016-09-08 17:49:17 -07001240 /**
1241 * We override because this class doesn't want its children affecting its reported orientation
1242 * in anyway.
1243 */
1244 @Override
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001245 int getOrientation(int candidate) {
1246 if (!fillsParent()) {
1247 // Can't specify orientation if app doesn't fill parent.
1248 return SCREEN_ORIENTATION_UNSET;
1249 }
1250
1251 if (candidate == SCREEN_ORIENTATION_BEHIND) {
1252 // Allow app to specify orientation regardless of its visibility state if the current
1253 // candidate want us to use orientation behind. I.e. the visible app on-top of this one
1254 // wants us to use the orientation of the app behind it.
1255 return mOrientation;
1256 }
1257
Bryce Lee61fbcbc2017-03-10 14:14:03 -08001258 // The {@link AppWindowToken} should only specify an orientation when it is not closing or
1259 // going to the bottom. Allowing closing {@link AppWindowToken} to participate can lead to
1260 // an Activity in another task being started in the wrong orientation during the transition.
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001261 if (!(sendingToBottom || mService.mClosingApps.contains(this))
Bryce Lee61fbcbc2017-03-10 14:14:03 -08001262 && (isVisible() || mService.mOpeningApps.contains(this))) {
Bryce Leea163b762017-01-24 11:05:01 -08001263 return mOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001264 }
Bryce Leea163b762017-01-24 11:05:01 -08001265
1266 return SCREEN_ORIENTATION_UNSET;
Wale Ogunwale51362492016-09-08 17:49:17 -07001267 }
1268
Wale Ogunwaleb198b742016-12-01 08:44:09 -08001269 /** Returns the app's preferred orientation regardless of its currently visibility state. */
1270 int getOrientationIgnoreVisibility() {
1271 return mOrientation;
1272 }
1273
Craig Mautnerdbb79912012-03-01 18:59:14 -08001274 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001275 void checkAppWindowsReadyToShow() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001276 if (allDrawn == mAppAnimator.allDrawn) {
1277 return;
1278 }
1279
1280 mAppAnimator.allDrawn = allDrawn;
1281 if (!allDrawn) {
1282 return;
1283 }
1284
1285 // The token has now changed state to having all windows shown... what to do, what to do?
1286 if (mAppAnimator.freezingScreen) {
1287 mAppAnimator.showAllWindowsLocked();
1288 stopFreezingScreen(false, true);
1289 if (DEBUG_ORIENTATION) Slog.i(TAG,
1290 "Setting mOrientationChangeComplete=true because wtoken " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001291 + " numInteresting=" + mNumInterestingWindows + " numDrawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001292 // This will set mOrientationChangeComplete and cause a pass through layout.
1293 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001294 "checkAppWindowsReadyToShow: freezingScreen");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001295 } else {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001296 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001297
1298 // We can now show all of the drawn windows!
1299 if (!mService.mOpeningApps.contains(this)) {
1300 mService.mAnimator.orAnimating(mAppAnimator.showAllWindowsLocked());
1301 }
1302 }
1303 }
1304
Matthew Ng498c71d2017-04-18 13:55:45 -07001305 void updateAllDrawn() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001306 if (!allDrawn) {
Matthew Ng498c71d2017-04-18 13:55:45 -07001307 // Number of drawn windows can be less when a window is being relaunched, wait for
1308 // all windows to be launched and drawn for this token be considered all drawn
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001309 final int numInteresting = mNumInterestingWindows;
Matthew Ng498c71d2017-04-18 13:55:45 -07001310 if (numInteresting > 0 && mNumDrawnWindows >= numInteresting && !isRelaunching()) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001311 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawn: " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001312 + " interesting=" + numInteresting + " drawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001313 allDrawn = true;
1314 // Force an additional layout pass where
1315 // WindowStateAnimator#commitFinishDrawingLocked() will call performShowLocked().
Matthew Ng498c71d2017-04-18 13:55:45 -07001316 if (mDisplayContent != null) {
1317 mDisplayContent.setLayoutNeeded();
1318 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001319 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Robert Carrecc06b32017-04-18 14:25:10 -07001320
1321 final TaskStack s = getStack();
1322 if (s != null) {
1323 s.onAllWindowsDrawn();
1324 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001325 }
1326 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001327
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001328 if (!allDrawnExcludingSaved) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001329 int numInteresting = mNumInterestingWindowsExcludingSaved;
1330 if (numInteresting > 0 && mNumDrawnWindowsExcludingSaved >= numInteresting) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001331 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawnExcludingSaved: " + this
1332 + " interesting=" + numInteresting
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001333 + " drawn=" + mNumDrawnWindowsExcludingSaved);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001334 allDrawnExcludingSaved = true;
Matthew Ng498c71d2017-04-18 13:55:45 -07001335 if (mDisplayContent != null) {
1336 mDisplayContent.setLayoutNeeded();
1337 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001338 if (isAnimatingInvisibleWithSavedSurface()
1339 && !mService.mFinishedEarlyAnim.contains(this)) {
1340 mService.mFinishedEarlyAnim.add(this);
1341 }
1342 }
1343 }
1344 }
1345
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001346 /**
1347 * Updated this app token tracking states for interesting and drawn windows based on the window.
1348 *
1349 * @return Returns true if the input window is considered interesting and drawn while all the
1350 * windows in this app token where not considered drawn as of the last pass.
1351 */
1352 boolean updateDrawnWindowStates(WindowState w) {
1353 if (DEBUG_STARTING_WINDOW && w == startingWindow) {
1354 Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" + w.isOnScreen()
1355 + " allDrawn=" + allDrawn + " freezingScreen=" + mAppAnimator.freezingScreen);
1356 }
1357
1358 if (allDrawn && allDrawnExcludingSaved && !mAppAnimator.freezingScreen) {
1359 return false;
1360 }
1361
1362 if (mLastTransactionSequence != mService.mTransactionSequence) {
1363 mLastTransactionSequence = mService.mTransactionSequence;
1364 mNumInterestingWindows = mNumDrawnWindows = 0;
1365 mNumInterestingWindowsExcludingSaved = 0;
1366 mNumDrawnWindowsExcludingSaved = 0;
1367 startingDisplayed = false;
1368 }
1369
1370 final WindowStateAnimator winAnimator = w.mWinAnimator;
1371
1372 boolean isInterestingAndDrawn = false;
1373
1374 if (!allDrawn && w.mightAffectAllDrawn(false /* visibleOnly */)) {
1375 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
1376 Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw()
1377 + ", isAnimationSet=" + winAnimator.isAnimationSet());
1378 if (!w.isDrawnLw()) {
1379 Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController
1380 + " pv=" + w.mPolicyVisibility
1381 + " mDrawState=" + winAnimator.drawStateToString()
1382 + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested
1383 + " a=" + winAnimator.mAnimating);
1384 }
1385 }
1386
1387 if (w != startingWindow) {
1388 if (w.isInteresting()) {
1389 mNumInterestingWindows++;
1390 if (w.isDrawnLw()) {
1391 mNumDrawnWindows++;
1392
1393 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, "tokenMayBeDrawn: "
1394 + this + " w=" + w + " numInteresting=" + mNumInterestingWindows
1395 + " freezingScreen=" + mAppAnimator.freezingScreen
1396 + " mAppFreezing=" + w.mAppFreezing);
1397
1398 isInterestingAndDrawn = true;
1399 }
1400 }
1401 } else if (w.isDrawnLw()) {
Jorim Jaggi3878ca32017-02-02 17:13:05 -08001402 if (getController() != null) {
1403 getController().reportStartingWindowDrawn();
1404 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001405 startingDisplayed = true;
1406 }
1407 }
1408
1409 if (!allDrawnExcludingSaved && w.mightAffectAllDrawn(true /* visibleOnly */)) {
1410 if (w != startingWindow && w.isInteresting()) {
1411 mNumInterestingWindowsExcludingSaved++;
1412 if (w.isDrawnLw() && !w.isAnimatingWithSavedSurface()) {
1413 mNumDrawnWindowsExcludingSaved++;
1414
1415 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
1416 "tokenMayBeDrawnExcludingSaved: " + this + " w=" + w
1417 + " numInteresting=" + mNumInterestingWindowsExcludingSaved
1418 + " freezingScreen=" + mAppAnimator.freezingScreen
1419 + " mAppFreezing=" + w.mAppFreezing);
1420
1421 isInterestingAndDrawn = true;
1422 }
1423 }
1424 }
1425
1426 return isInterestingAndDrawn;
1427 }
1428
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001429 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001430 void stepAppWindowsAnimation(long currentTime) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001431 mAppAnimator.wasAnimating = mAppAnimator.animating;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001432 if (mAppAnimator.stepAnimationLocked(currentTime)) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001433 mAppAnimator.animating = true;
1434 mService.mAnimator.setAnimating(true);
1435 mService.mAnimator.mAppWindowAnimating = true;
1436 } else if (mAppAnimator.wasAnimating) {
1437 // stopped animating, do one more pass through the layout
Wale Ogunwale1e129a42016-11-21 13:03:47 -08001438 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
1439 DEBUG_LAYOUT_REPEATS ? "appToken " + this + " done" : null);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001440 if (DEBUG_ANIM) Slog.v(TAG, "updateWindowsApps...: done animating " + this);
1441 }
1442 }
1443
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001444 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001445 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001446 // For legacy reasons we process the TaskStack.mExitingAppTokens first in DisplayContent
1447 // before the non-exiting app tokens. So, we skip the exiting app tokens here.
1448 // TODO: Investigate if we need to continue to do this or if we can just process them
1449 // in-order.
1450 if (mIsExiting && !waitingForReplacement()) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001451 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001452 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001453 return forAllWindowsUnchecked(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001454 }
1455
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001456 boolean forAllWindowsUnchecked(ToBooleanFunction<WindowState> callback,
1457 boolean traverseTopToBottom) {
1458 return super.forAllWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001459 }
1460
1461 @Override
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001462 AppWindowToken asAppWindowToken() {
1463 // I am an app window token!
1464 return this;
1465 }
1466
1467 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -07001468 boolean fillsParent() {
1469 return mFillsParent;
1470 }
1471
1472 void setFillsParent(boolean fillsParent) {
1473 mFillsParent = fillsParent;
1474 }
1475
Jorim Jaggife762342016-10-13 14:33:27 +02001476 boolean containsDismissKeyguardWindow() {
1477 for (int i = mChildren.size() - 1; i >= 0; i--) {
1478 if ((mChildren.get(i).mAttrs.flags & FLAG_DISMISS_KEYGUARD) != 0) {
1479 return true;
1480 }
1481 }
1482 return false;
1483 }
1484
1485 boolean containsShowWhenLockedWindow() {
1486 for (int i = mChildren.size() - 1; i >= 0; i--) {
1487 if ((mChildren.get(i).mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
1488 return true;
1489 }
1490 }
1491 return false;
1492 }
1493
1494 void checkKeyguardFlagsChanged() {
1495 final boolean containsDismissKeyguard = containsDismissKeyguardWindow();
1496 final boolean containsShowWhenLocked = containsShowWhenLockedWindow();
1497 if (containsDismissKeyguard != mLastContainsDismissKeyguardWindow
1498 || containsShowWhenLocked != mLastContainsShowWhenLockedWindow) {
1499 mService.notifyKeyguardFlagsChanged(null /* callback */);
1500 }
1501 mLastContainsDismissKeyguardWindow = containsDismissKeyguard;
1502 mLastContainsShowWhenLockedWindow = containsShowWhenLocked;
1503 }
1504
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001505 WindowState getImeTargetBelowWindow(WindowState w) {
1506 final int index = mChildren.indexOf(w);
1507 if (index > 0) {
1508 final WindowState target = mChildren.get(index - 1);
1509 if (target.canBeImeTarget()) {
1510 return target;
1511 }
1512 }
1513 return null;
1514 }
1515
1516 WindowState getHighestAnimLayerWindow(WindowState currentTarget) {
1517 WindowState candidate = null;
1518 for (int i = mChildren.indexOf(currentTarget); i >= 0; i--) {
1519 final WindowState w = mChildren.get(i);
1520 if (w.mRemoved) {
1521 continue;
1522 }
1523 if (candidate == null || w.mWinAnimator.mAnimLayer >
1524 candidate.mWinAnimator.mAnimLayer) {
1525 candidate = w;
1526 }
1527 }
1528 return candidate;
1529 }
1530
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001531 void setDisablePreviewSnapshots(boolean disable) {
1532 mDisbalePreviewScreenshots = disable;
1533 }
1534
1535 boolean shouldDisablePreviewScreenshots() {
1536 return mDisbalePreviewScreenshots;
1537 }
1538
Wale Ogunwale51362492016-09-08 17:49:17 -07001539 @Override
Robert Carrdee1b3f2017-02-27 11:33:33 -08001540 int getAnimLayerAdjustment() {
1541 return mAppAnimator.animLayerAdjustment;
1542 }
1543
1544 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001545 void dump(PrintWriter pw, String prefix) {
1546 super.dump(pw, prefix);
1547 if (appToken != null) {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001548 pw.println(prefix + "app=true mVoiceInteraction=" + mVoiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001549 }
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001550 pw.print(prefix); pw.print("task="); pw.println(getTask());
Wale Ogunwale51362492016-09-08 17:49:17 -07001551 pw.print(prefix); pw.print(" mFillsParent="); pw.print(mFillsParent);
1552 pw.print(" mOrientation="); pw.println(mOrientation);
Wale Ogunwale89973222017-04-23 18:39:45 -07001553 pw.println(prefix + "hiddenRequested=" + hiddenRequested + " mClientHidden=" + mClientHidden
1554 + ((mDeferHidingClient) ? " mDeferHidingClient=" + mDeferHidingClient : "")
1555 + " reportedDrawn=" + reportedDrawn + " reportedVisible=" + reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -07001556 if (paused) {
1557 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001558 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001559 if (mAppStopped) {
1560 pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped);
1561 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001562 if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0
Craig Mautner6fbda632012-07-03 09:26:39 -07001563 || allDrawn || mAppAnimator.allDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001564 pw.print(prefix); pw.print("mNumInterestingWindows=");
1565 pw.print(mNumInterestingWindows);
1566 pw.print(" mNumDrawnWindows="); pw.print(mNumDrawnWindows);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001567 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -07001568 pw.print(" allDrawn="); pw.print(allDrawn);
1569 pw.print(" (animator="); pw.print(mAppAnimator.allDrawn);
1570 pw.println(")");
1571 }
1572 if (inPendingTransaction) {
1573 pw.print(prefix); pw.print("inPendingTransaction=");
1574 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001575 }
Craig Mautner799bc1d2015-01-14 10:33:48 -08001576 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001577 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
1578 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -08001579 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -08001580 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001581 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001582 if (startingWindow != null || startingSurface != null
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001583 || startingDisplayed || startingMoved) {
1584 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001585 pw.print(" startingSurface="); pw.print(startingSurface);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001586 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001587 pw.print(" startingMoved="); pw.println(startingMoved);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001588 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01001589 if (!mFrozenBounds.isEmpty()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -08001590 pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds);
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001591 pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig);
Chong Zhangd78ddb42016-03-02 17:01:14 -08001592 }
1593 if (mPendingRelaunchCount != 0) {
1594 pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount);
Jorim Jaggi0429f352015-12-22 16:29:16 +01001595 }
Wale Ogunwale9c64cb62017-04-12 13:39:59 -07001596 if (getController() != null) {
1597 pw.print(prefix); pw.print("controller="); pw.println(getController());
1598 }
Wale Ogunwalee287e192017-04-21 09:30:12 -07001599 if (mRemovingFromDisplay) {
1600 pw.println(prefix + "mRemovingFromDisplay=" + mRemovingFromDisplay);
1601 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001602 }
1603
1604 @Override
1605 public String toString() {
1606 if (stringName == null) {
1607 StringBuilder sb = new StringBuilder();
1608 sb.append("AppWindowToken{");
1609 sb.append(Integer.toHexString(System.identityHashCode(this)));
1610 sb.append(" token="); sb.append(token); sb.append('}');
1611 stringName = sb.toString();
1612 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001613 return stringName + ((mIsExiting) ? " mIsExiting=" : "");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001614 }
Jeff Browne9bdb312012-04-05 15:30:10 -07001615}