blob: 52eb2fb01d79178ce9749c73e743d64218562fe2 [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;
Jorim Jaggid635a4a2017-05-03 15:21:26 +020026import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
Jorim Jaggife762342016-10-13 14:33:27 +020027import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
Wale Ogunwaled1c37912016-08-16 03:19:39 -070028import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080029import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070030import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -070031import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
32import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070033import static com.android.server.wm.AppTransition.TRANSIT_UNSET;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080034import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080035import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
36import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070037import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070038import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
39import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
Wale Ogunwale9017ec02016-02-25 08:55:25 -080040import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070041import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TOKEN_MOVEMENT;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080042import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
43import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_MOVEMENT;
44import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
45import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Chong Zhang92147042016-05-09 12:47:11 -070046import static com.android.server.wm.WindowManagerService.H.NOTIFY_ACTIVITY_DRAWN;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070047import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070048import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070049import static com.android.server.wm.WindowManagerService.logWithStack;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080050
Filip Gruszczynskia590c992015-11-25 16:45:26 -080051import android.annotation.NonNull;
Jorim Jaggid635a4a2017-05-03 15:21:26 +020052import android.app.Activity;
Jorim Jaggi26c8c422016-05-09 19:57:25 -070053import android.content.res.Configuration;
Jorim Jaggi0429f352015-12-22 16:29:16 +010054import android.graphics.Rect;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070055import android.os.Binder;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080056import android.os.Debug;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070057import android.os.IBinder;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070058import android.os.SystemClock;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080059import android.util.Slog;
60import android.view.IApplicationToken;
Robert Carr6914f082017-03-20 19:04:30 -070061import android.view.SurfaceControl;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080062import android.view.WindowManager;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080063import android.view.WindowManagerPolicy.StartingSurface;
64
65import com.android.internal.util.ToBooleanFunction;
66import com.android.server.input.InputApplicationHandle;
67import com.android.server.wm.WindowManagerService.H;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080068
69import java.io.PrintWriter;
Jorim Jaggi0429f352015-12-22 16:29:16 +010070import java.util.ArrayDeque;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080071import java.util.ArrayList;
72
Bryce Lee39791592017-04-26 09:29:12 -070073import static android.os.Build.VERSION_CODES.O;
74
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080075class AppTokenList extends ArrayList<AppWindowToken> {
76}
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080077
78/**
79 * Version of WindowToken that is specifically for a particular application (or
80 * really activity) that is displaying windows.
81 */
Wale Ogunwale3f4433d2016-08-18 20:42:42 -070082class AppWindowToken extends WindowToken implements WindowManagerService.AppFreezeListener {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080083 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppWindowToken" : TAG_WM;
84
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080085 // Non-null only for application tokens.
86 final IApplicationToken appToken;
87
Filip Gruszczynskia590c992015-11-25 16:45:26 -080088 @NonNull final AppWindowAnimator mAppAnimator;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -070089
Wale Ogunwale72919d22016-12-08 18:58:50 -080090 final boolean mVoiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -070091
Wale Ogunwale51362492016-09-08 17:49:17 -070092 /** @see WindowContainer#fillsParent() */
93 private boolean mFillsParent;
Craig Mautner4c5eb222013-11-18 12:59:05 -080094 boolean layoutConfigChanges;
Wale Ogunwale72919d22016-12-08 18:58:50 -080095 boolean mShowForAllUsers;
96 int mTargetSdk;
Craig Mautnera2c77052012-03-26 12:14:43 -070097
Bryce Lee6d410262017-02-28 15:30:17 -080098 // Flag set while reparenting to prevent actions normally triggered by an individual parent
99 // change.
100 private boolean mReparenting;
101
Wale Ogunwalee287e192017-04-21 09:30:12 -0700102 // True if we are current in the process of removing this app token from the display
103 private boolean mRemovingFromDisplay = false;
104
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800105 // The input dispatching timeout for this application token in nanoseconds.
Wale Ogunwale72919d22016-12-08 18:58:50 -0800106 long mInputDispatchingTimeoutNanos;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800107
108 // These are used for determining when all windows associated with
109 // an activity have been drawn, so they can be made visible together
110 // at the same time.
Craig Mautner764983d2012-03-22 11:37:36 -0700111 // initialize so that it doesn't match mTransactionSequence which is an int.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700112 private long mLastTransactionSequence = Long.MIN_VALUE;
113 private int mNumInterestingWindows;
114 private int mNumDrawnWindows;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800115 boolean inPendingTransaction;
116 boolean allDrawn;
Craig Mautner7636dfb2012-11-16 15:24:11 -0800117 // Set to true when this app creates a surface while in the middle of an animation. In that
118 // case do not clear allDrawn until the animation completes.
119 boolean deferClearAllDrawn;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800120
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700121 /**
122 * These are to track the app's real drawing status if there were no saved surfaces.
123 * @see #updateDrawnWindowStates
124 */
Chong Zhang8e4bda92016-05-04 15:08:18 -0700125 boolean allDrawnExcludingSaved;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700126 private int mNumInterestingWindowsExcludingSaved;
127 private int mNumDrawnWindowsExcludingSaved;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700128
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800129 // Is this window's surface needed? This is almost like hidden, except
130 // it will sometimes be true a little earlier: when the token has
131 // been shown, but is still waiting for its app transition to execute
132 // before making its windows shown.
133 boolean hiddenRequested;
134
135 // Have we told the window clients to hide themselves?
Wale Ogunwale89973222017-04-23 18:39:45 -0700136 private boolean mClientHidden;
137
138 // If true we will defer setting mClientHidden to true and reporting to the client that it is
139 // hidden.
140 boolean mDeferHidingClient;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800141
142 // Last visibility state we reported to the app token.
143 boolean reportedVisible;
144
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700145 // Last drawn state we reported to the app token.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700146 private boolean reportedDrawn;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700147
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800148 // Set to true when the token has been removed from the window mgr.
149 boolean removed;
150
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800151 // Information about an application starting window if displayed.
152 StartingData startingData;
153 WindowState startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800154 StartingSurface startingSurface;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800155 boolean startingDisplayed;
156 boolean startingMoved;
Wale Ogunwale6c459212017-05-17 08:56:03 -0700157 // True if the hidden state of this token was forced to false due to a transferred starting
158 // window.
159 private boolean mHiddenSetFromTransferredStartingWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800160 boolean firstWindowDrawn;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700161 private final WindowState.UpdateReportedVisibilityResults mReportedVisibilityResults =
162 new WindowState.UpdateReportedVisibilityResults();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800163
164 // Input application handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700165 final InputApplicationHandle mInputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800166
Wale Ogunwale571771c2016-08-26 13:18:50 -0700167 // TODO: Have a WindowContainer state for tracking exiting/deferred removal.
Craig Mautner799bc1d2015-01-14 10:33:48 -0800168 boolean mIsExiting;
Craig Mautner9ef471f2014-02-07 13:11:47 -0800169
Craig Mautnerbb742462014-07-07 15:28:55 -0700170 boolean mLaunchTaskBehind;
Craig Mautner8746a472014-07-24 15:12:54 -0700171 boolean mEnteringAnimation;
Craig Mautnerbb742462014-07-07 15:28:55 -0700172
Wale Ogunwale72919d22016-12-08 18:58:50 -0800173 private boolean mAlwaysFocusable;
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800174
Robert Carre12aece2016-02-02 22:43:27 -0800175 boolean mAppStopped;
Robert Carrfd10cd12016-06-29 16:41:50 -0700176 int mRotationAnimationHint;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700177 private int mPendingRelaunchCount;
Robert Carre12aece2016-02-02 22:43:27 -0800178
Jorim Jaggife762342016-10-13 14:33:27 +0200179 private boolean mLastContainsShowWhenLockedWindow;
180 private boolean mLastContainsDismissKeyguardWindow;
181
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700182 // The bounds of this activity. Mainly used for aspect-ratio compatibility.
183 // TODO(b/36505427): Every level on WindowContainer now has bounds information, which directly
184 // affects the configuration. We should probably move this into that class.
185 private final Rect mBounds = new Rect();
186
Jorim Jaggi0429f352015-12-22 16:29:16 +0100187 ArrayDeque<Rect> mFrozenBounds = new ArrayDeque<>();
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700188 ArrayDeque<Configuration> mFrozenMergedConfig = new ArrayDeque<>();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100189
Wale Ogunwale6c459212017-05-17 08:56:03 -0700190 private boolean mDisablePreviewScreenshots;
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +0100191
Robert Carred3e83b2017-04-21 13:26:55 -0700192 Task mLastParent;
193
Wale Ogunwale72919d22016-12-08 18:58:50 -0800194 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
195 DisplayContent dc, long inputDispatchingTimeoutNanos, boolean fullscreen,
196 boolean showForAllUsers, int targetSdk, int orientation, int rotationAnimationHint,
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800197 int configChanges, boolean launchTaskBehind, boolean alwaysFocusable,
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700198 AppWindowContainerController controller, Configuration overrideConfig, Rect bounds) {
199 this(service, token, voiceInteraction, dc, fullscreen, overrideConfig, bounds);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800200 setController(controller);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800201 mInputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800202 mShowForAllUsers = showForAllUsers;
203 mTargetSdk = targetSdk;
204 mOrientation = orientation;
205 layoutConfigChanges = (configChanges & (CONFIG_SCREEN_SIZE | CONFIG_ORIENTATION)) != 0;
206 mLaunchTaskBehind = launchTaskBehind;
207 mAlwaysFocusable = alwaysFocusable;
208 mRotationAnimationHint = rotationAnimationHint;
209
210 // Application tokens start out hidden.
211 hidden = true;
212 hiddenRequested = true;
213 }
214
215 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700216 DisplayContent dc, boolean fillsParent, Configuration overrideConfig, Rect bounds) {
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800217 super(service, token != null ? token.asBinder() : null, TYPE_APPLICATION, true, dc,
218 false /* ownerCanManageAppTokens */);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700219 appToken = token;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800220 mVoiceInteraction = voiceInteraction;
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800221 mFillsParent = fillsParent;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800222 mInputApplicationHandle = new InputApplicationHandle(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700223 mAppAnimator = new AppWindowAnimator(this, service);
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700224 if (overrideConfig != null) {
225 onOverrideConfigurationChanged(overrideConfig);
226 }
227 if (bounds != null) {
228 mBounds.set(bounds);
229 }
230 }
231
232 void onOverrideConfigurationChanged(Configuration overrideConfiguration, Rect bounds) {
233 onOverrideConfigurationChanged(overrideConfiguration);
234 if (mBounds.equals(bounds)) {
235 return;
236 }
237 // TODO(b/36505427): If bounds is in WC, then we can automatically call onResize() when set.
238 mBounds.set(bounds);
239 onResize();
240 }
241
242 void getBounds(Rect outBounds) {
243 outBounds.set(mBounds);
244 }
245
246 boolean hasBounds() {
247 return !mBounds.isEmpty();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800248 }
249
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800250 void onFirstWindowDrawn(WindowState win, WindowStateAnimator winAnimator) {
251 firstWindowDrawn = true;
252
253 // We now have a good window to show, remove dead placeholders
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700254 removeDeadWindows();
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800255
Jorim Jaggi02886a82016-12-06 09:10:06 -0800256 if (startingWindow != null) {
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800257 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, "Finish starting "
258 + win.mToken + ": first real window is shown, no animation");
259 // If this initial window is animating, stop it -- we will do an animation to reveal
260 // it from behind the starting window, so there is no need for it to also be doing its
261 // own stuff.
262 winAnimator.clearAnimation();
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800263 if (getController() != null) {
264 getController().removeStartingWindow();
265 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800266 }
267 updateReportedVisibilityLocked();
268 }
269
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800270 void updateReportedVisibilityLocked() {
271 if (appToken == null) {
272 return;
273 }
274
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700275 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700276 final int count = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800277
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700278 mReportedVisibilityResults.reset();
279
280 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700281 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700282 win.updateReportedVisibility(mReportedVisibilityResults);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800283 }
284
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700285 int numInteresting = mReportedVisibilityResults.numInteresting;
286 int numVisible = mReportedVisibilityResults.numVisible;
287 int numDrawn = mReportedVisibilityResults.numDrawn;
288 boolean nowGone = mReportedVisibilityResults.nowGone;
289
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700290 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800291 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700292 if (!nowGone) {
293 // If the app is not yet gone, then it can only become visible/drawn.
294 if (!nowDrawn) {
295 nowDrawn = reportedDrawn;
296 }
297 if (!nowVisible) {
298 nowVisible = reportedVisible;
299 }
300 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800301 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800302 + numInteresting + " visible=" + numVisible);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800303 final AppWindowContainerController controller = getController();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700304 if (nowDrawn != reportedDrawn) {
305 if (nowDrawn) {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800306 if (controller != null) {
307 controller.reportWindowsDrawn();
308 }
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700309 }
310 reportedDrawn = nowDrawn;
311 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800312 if (nowVisible != reportedVisible) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700313 if (DEBUG_VISIBILITY) Slog.v(TAG,
314 "Visibility changed in " + this + ": vis=" + nowVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800315 reportedVisible = nowVisible;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800316 if (controller != null) {
317 if (nowVisible) {
318 controller.reportWindowsVisible();
319 } else {
320 controller.reportWindowsGone();
321 }
322 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800323 }
324 }
325
Wale Ogunwale89973222017-04-23 18:39:45 -0700326 boolean isClientHidden() {
327 return mClientHidden;
328 }
329
330 void setClientHidden(boolean hideClient) {
331 if (mClientHidden == hideClient || (hideClient && mDeferHidingClient)) {
332 return;
333 }
334 mClientHidden = hideClient;
335 sendAppVisibilityToClients();
336 }
337
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700338 boolean setVisibility(WindowManager.LayoutParams lp,
339 boolean visible, int transit, boolean performLayout, boolean isVoiceInteraction) {
340
341 boolean delayed = false;
342 inPendingTransaction = false;
343
Wale Ogunwale89973222017-04-23 18:39:45 -0700344 setClientHidden(!visible);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700345
346 // Allow for state changes and animation to be applied if:
347 // * token is transitioning visibility state
348 // * or the token was marked as hidden and is exiting before we had a chance to play the
349 // transition animation
350 // * or this is an opening app and windows are being replaced.
351 boolean visibilityChanged = false;
352 if (hidden == visible || (hidden && mIsExiting) || (visible && waitingForReplacement())) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700353 final AccessibilityController accessibilityController = mService.mAccessibilityController;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700354 boolean changed = false;
355 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
356 "Changing app " + this + " hidden=" + hidden + " performLayout=" + performLayout);
357
358 boolean runningAppAnimation = false;
359
360 if (transit != AppTransition.TRANSIT_UNSET) {
361 if (mAppAnimator.animation == AppWindowAnimator.sDummyAnimation) {
362 mAppAnimator.setNullAnimation();
363 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700364 if (mService.applyAnimationLocked(this, lp, transit, visible, isVoiceInteraction)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700365 delayed = runningAppAnimation = true;
366 }
367 final WindowState window = findMainWindow();
368 //TODO (multidisplay): Magnification is supported only for the default display.
369 if (window != null && accessibilityController != null
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700370 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700371 accessibilityController.onAppWindowTransitionLocked(window, transit);
372 }
373 changed = true;
374 }
375
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700376 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700377 for (int i = 0; i < windowsCount; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700378 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700379 changed |= win.onAppVisibilityChanged(visible, runningAppAnimation);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700380 }
381
382 hidden = hiddenRequested = !visible;
383 visibilityChanged = true;
384 if (!visible) {
385 stopFreezingScreen(true, true);
386 } else {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700387 // If we are being set visible, and the starting window is not yet displayed,
388 // then make sure it doesn't get displayed.
389 if (startingWindow != null && !startingWindow.isDrawnLw()) {
390 startingWindow.mPolicyVisibility = false;
391 startingWindow.mPolicyVisibilityAfterAnim = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700392 }
393 }
394
395 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setVisibility: " + this
396 + ": hidden=" + hidden + " hiddenRequested=" + hiddenRequested);
397
398 if (changed) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700399 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700400 if (performLayout) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700401 mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700402 false /*updateInputWindows*/);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700403 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700404 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700405 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700406 }
407 }
408
409 if (mAppAnimator.animation != null) {
410 delayed = true;
411 }
412
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700413 for (int i = mChildren.size() - 1; i >= 0 && !delayed; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700414 if ((mChildren.get(i)).isWindowAnimationSet()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700415 delayed = true;
416 }
417 }
418
419 if (visibilityChanged) {
420 if (visible && !delayed) {
421 // The token was made immediately visible, there will be no entrance animation.
422 // We need to inform the client the enter animation was finished.
423 mEnteringAnimation = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700424 mService.mActivityManagerAppTransitionNotifier.onAppTransitionFinishedLocked(token);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700425 }
Robert Carre7cc44d2017-03-20 19:04:30 -0700426 // If we are hidden but there is no delay needed we immediately
427 // apply the Surface transaction so that the ActivityManager
428 // can have some guarantee on the Surface state
429 // following setting the visibility.
Robert Carr6914f082017-03-20 19:04:30 -0700430 if (hidden && !delayed) {
431 SurfaceControl.openTransaction();
432 for (int i = mChildren.size() - 1; i >= 0; i--) {
433 mChildren.get(i).mWinAnimator.hide("immediately hidden");
434 }
435 SurfaceControl.closeTransaction();
436 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700437
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700438 if (!mService.mClosingApps.contains(this) && !mService.mOpeningApps.contains(this)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700439 // The token is not closing nor opening, so even if there is an animation set, that
440 // doesn't mean that it goes through the normal app transition cycle so we have
441 // to inform the docked controller about visibility change.
Andrii Kulian1e32e022016-09-16 15:29:34 -0700442 // TODO(multi-display): notify docked divider on all displays where visibility was
443 // affected.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700444 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700445 .notifyAppVisibilityChanged();
Jorim Jaggi8b702ed2017-01-20 16:59:03 +0100446 mService.mTaskSnapshotController.notifyAppVisibilityChanged(this, visible);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700447 }
448 }
449
450 return delayed;
451 }
452
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800453 WindowState findMainWindow() {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700454 WindowState candidate = null;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700455 int j = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800456 while (j > 0) {
457 j--;
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700458 final WindowState win = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700459 final int type = win.mAttrs.type;
460 // No need to loop through child window as base application and starting types can't be
461 // child windows.
462 if (type == TYPE_BASE_APPLICATION || type == TYPE_APPLICATION_STARTING) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700463 // In cases where there are multiple windows, we prefer the non-exiting window. This
Sungsoo Lim0d3d1f82015-12-02 14:47:59 +0900464 // happens for example when replacing windows during an activity relaunch. When
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700465 // constructing the animation, we want the new window, not the exiting one.
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800466 if (win.mAnimatingExit) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700467 candidate = win;
468 } else {
469 return win;
470 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800471 }
472 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700473 return candidate;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800474 }
475
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800476 boolean windowsAreFocusable() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800477 return StackId.canReceiveKeys(getTask().mStack.mStackId) || mAlwaysFocusable;
Wale Ogunwaled045c822015-12-02 09:14:28 -0800478 }
479
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800480 AppWindowContainerController getController() {
481 final WindowContainerController controller = super.getController();
482 return controller != null ? (AppWindowContainerController) controller : null;
483 }
484
Wale Ogunwale571771c2016-08-26 13:18:50 -0700485 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -0700486 boolean isVisible() {
Wale Ogunwalee471be62016-10-03 07:53:55 -0700487 // If the app token isn't hidden then it is considered visible and there is no need to check
488 // its children windows to see if they are visible.
489 return !hidden;
Wale Ogunwale44f21802016-09-02 12:49:48 -0700490 }
491
492 @Override
Wale Ogunwalee287e192017-04-21 09:30:12 -0700493 void removeImmediately() {
494 onRemovedFromDisplay();
495 super.removeImmediately();
496 }
497
498 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -0700499 void removeIfPossible() {
Craig Mautnere3119b72015-01-20 15:02:36 -0800500 mIsExiting = false;
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800501 removeAllWindowsIfPossible();
Bryce Lee6d410262017-02-28 15:30:17 -0800502 removeImmediately();
Craig Mautnere3119b72015-01-20 15:02:36 -0800503 }
504
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700505 @Override
506 boolean checkCompleteDeferredRemoval() {
507 if (mIsExiting) {
508 removeIfPossible();
509 }
510 return super.checkCompleteDeferredRemoval();
511 }
512
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700513 void onRemovedFromDisplay() {
Wale Ogunwalee287e192017-04-21 09:30:12 -0700514 if (mRemovingFromDisplay) {
515 return;
516 }
517 mRemovingFromDisplay = true;
518
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700519 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app token: " + this);
520
Wale Ogunwale72919d22016-12-08 18:58:50 -0800521 boolean delayed = setVisibility(null, false, TRANSIT_UNSET, true, mVoiceInteraction);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700522
523 mService.mOpeningApps.remove(this);
Jorim Jaggi1b4b23e2016-11-15 16:30:12 -0800524 mService.mUnknownAppVisibilityController.appRemoved(this);
Jorim Jaggi10abe2f2017-01-03 16:44:46 +0100525 mService.mTaskSnapshotController.onAppRemoved(this);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700526 waitingToShow = false;
527 if (mService.mClosingApps.contains(this)) {
528 delayed = true;
529 } else if (mService.mAppTransition.isTransitionSet()) {
530 mService.mClosingApps.add(this);
531 delayed = true;
532 }
533
534 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app " + this + " delayed=" + delayed
535 + " animation=" + mAppAnimator.animation + " animating=" + mAppAnimator.animating);
536
537 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM, "removeAppToken: "
538 + this + " delayed=" + delayed + " Callers=" + Debug.getCallers(4));
539
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800540 if (startingData != null && getController() != null) {
541 getController().removeStartingWindow();
542 }
543
Winson Chung87e5d552017-04-05 11:49:38 -0700544 // If this window was animating, then we need to ensure that the app transition notifies
545 // that animations have completed in WMS.handleAnimatingStoppedAndTransitionLocked(), so
546 // add to that list now
547 if (mAppAnimator.animating) {
548 mService.mNoAnimationNotifyOnTransitionFinished.add(token);
549 }
550
Wale Ogunwalee287e192017-04-21 09:30:12 -0700551 final TaskStack stack = getStack();
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700552 if (delayed && !isEmpty()) {
553 // set the token aside because it has an active animation to be finished
554 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM,
555 "removeAppToken make exiting: " + this);
Wale Ogunwalee287e192017-04-21 09:30:12 -0700556 if (stack != null) {
557 stack.mExitingAppTokens.add(this);
558 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700559 mIsExiting = true;
560 } else {
561 // Make sure there is no animation running on this token, so any windows associated
562 // with it will be removed as soon as their animations are complete
563 mAppAnimator.clearAnimation();
564 mAppAnimator.animating = false;
Wale Ogunwale3106ae012017-05-16 08:56:37 -0700565 if (stack != null) {
566 stack.mExitingAppTokens.remove(this);
567 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700568 removeIfPossible();
569 }
570
571 removed = true;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700572 stopFreezingScreen(true, true);
Bryce Lee6d410262017-02-28 15:30:17 -0800573
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700574 if (mService.mFocusedApp == this) {
575 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "Removing focused app token:" + this);
576 mService.mFocusedApp = null;
577 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
578 mService.mInputMonitor.setFocusedAppLw(null);
579 }
580
581 if (!delayed) {
582 updateReportedVisibilityLocked();
583 }
Wale Ogunwalee287e192017-04-21 09:30:12 -0700584
585 mRemovingFromDisplay = false;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700586 }
587
Chong Zhange05bcb12016-07-26 17:47:29 -0700588 void clearAnimatingFlags() {
Chong Zhangb0d26702016-08-12 16:03:29 -0700589 boolean wallpaperMightChange = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700590 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700591 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700592 wallpaperMightChange |= win.clearAnimatingFlags();
Chong Zhange05bcb12016-07-26 17:47:29 -0700593 }
Chong Zhangb0d26702016-08-12 16:03:29 -0700594 if (wallpaperMightChange) {
595 requestUpdateWallpaperIfNeeded();
596 }
Chong Zhange05bcb12016-07-26 17:47:29 -0700597 }
598
Robert Carre12aece2016-02-02 22:43:27 -0800599 void destroySurfaces() {
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700600 destroySurfaces(false /*cleanupOnResume*/);
601 }
602
603 /**
604 * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure
605 * the client has finished with them.
606 *
607 * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If
608 * set to true, destroy only surfaces of removed windows, and clear relevant flags of the
609 * others so that they are ready to be reused. If set to false (common case), destroy all
610 * surfaces that's eligible, if the app is already stopped.
611 */
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700612 private void destroySurfaces(boolean cleanupOnResume) {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700613 boolean destroyedSomething = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700614 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700615 final WindowState win = mChildren.get(i);
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700616 destroyedSomething |= win.destroySurface(cleanupOnResume, mAppStopped);
Robert Carre12aece2016-02-02 22:43:27 -0800617 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700618 if (destroyedSomething) {
619 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700620 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Robert Carre12aece2016-02-02 22:43:27 -0800621 }
622 }
623
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800624 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700625 * Notify that the app is now resumed, and it was not stopped before, perform a clean
626 * up of the surfaces
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800627 */
Jorim Jaggibae01b12017-04-11 16:29:10 -0700628 void notifyAppResumed(boolean wasStopped) {
Chong Zhangad24f962016-08-25 12:12:33 -0700629 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped
Jorim Jaggibae01b12017-04-11 16:29:10 -0700630 + " " + this);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700631 mAppStopped = false;
632 if (!wasStopped) {
633 destroySurfaces(true /*cleanupOnResume*/);
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800634 }
Robert Carre12aece2016-02-02 22:43:27 -0800635 }
636
Chong Zhangbef461f2015-10-27 11:38:24 -0700637 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700638 * Notify that the app has stopped, and it is okay to destroy any surfaces which were
639 * keeping alive in case they were still being used.
640 */
641 void notifyAppStopped() {
642 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this);
643 mAppStopped = true;
644 destroySurfaces();
645 // Remove any starting window that was added for this app if they are still around.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800646 if (getController() != null) {
647 getController().removeStartingWindow();
648 }
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700649 }
650
651 /**
Chong Zhangbef461f2015-10-27 11:38:24 -0700652 * Checks whether we should save surfaces for this app.
653 *
654 * @return true if the surfaces should be saved, false otherwise.
655 */
656 boolean shouldSaveSurface() {
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800657 // We want to save surface if the app's windows are "allDrawn".
658 // (If we started entering animation early with saved surfaces, allDrawn
659 // should have been restored to true. So we'll save again in that case
660 // even if app didn't actually finish drawing.)
661 return allDrawn;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800662 }
663
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700664 private boolean canRestoreSurfaces() {
665 for (int i = mChildren.size() -1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700666 final WindowState w = mChildren.get(i);
Chong Zhang92147042016-05-09 12:47:11 -0700667 if (w.canRestoreSurface()) {
Robert Carr13f7be9e2015-12-02 18:39:45 -0800668 return true;
669 }
Chong Zhangbef461f2015-10-27 11:38:24 -0700670 }
671 return false;
672 }
673
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700674 private void clearWasVisibleBeforeClientHidden() {
675 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700676 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700677 w.clearWasVisibleBeforeClientHidden();
Chong Zhang92147042016-05-09 12:47:11 -0700678 }
679 }
680
Chong Zhang8e4bda92016-05-04 15:08:18 -0700681 /**
682 * Whether the app has some window that is invisible in layout, but
683 * animating with saved surface.
684 */
685 boolean isAnimatingInvisibleWithSavedSurface() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700686 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700687 final WindowState w = mChildren.get(i);
Chong Zhang8e4bda92016-05-04 15:08:18 -0700688 if (w.isAnimatingInvisibleWithSavedSurface()) {
689 return true;
690 }
691 }
692 return false;
693 }
694
695 /**
696 * Hide all window surfaces that's still invisible in layout but animating
697 * with a saved surface, and mark them destroying.
698 */
699 void stopUsingSavedSurfaceLocked() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700700 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700701 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700702 w.stopUsingSavedSurface();
Chong Zhang8e4bda92016-05-04 15:08:18 -0700703 }
704 destroySurfaces();
705 }
706
Chong Zhangf58631a2016-05-24 16:02:10 -0700707 void markSavedSurfaceExiting() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700708 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700709 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700710 w.markSavedSurfaceExiting();
Chong Zhangf58631a2016-05-24 16:02:10 -0700711 }
712 }
713
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700714 void restoreSavedSurfaceForInterestingWindows() {
Chong Zhang92147042016-05-09 12:47:11 -0700715 if (!canRestoreSurfaces()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700716 clearWasVisibleBeforeClientHidden();
Chong Zhangbef461f2015-10-27 11:38:24 -0700717 return;
718 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700719
720 // Check if all interesting windows are drawn and we can mark allDrawn=true.
721 int interestingNotDrawn = -1;
722
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700723 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700724 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700725 interestingNotDrawn = w.restoreSavedSurfaceForInterestingWindow();
Chong Zhangbef461f2015-10-27 11:38:24 -0700726 }
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800727
Chong Zhang92147042016-05-09 12:47:11 -0700728 if (!allDrawn) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700729 allDrawn = (interestingNotDrawn == 0);
Chong Zhang92147042016-05-09 12:47:11 -0700730 if (allDrawn) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700731 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Chong Zhang92147042016-05-09 12:47:11 -0700732 }
733 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700734 clearWasVisibleBeforeClientHidden();
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800735
736 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700737 "restoreSavedSurfaceForInterestingWindows: " + this + " allDrawn=" + allDrawn
738 + " interestingNotDrawn=" + interestingNotDrawn);
Chong Zhangbef461f2015-10-27 11:38:24 -0700739 }
740
741 void destroySavedSurfaces() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700742 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700743 final WindowState win = mChildren.get(i);
Robert Carr13f7be9e2015-12-02 18:39:45 -0800744 win.destroySavedSurface();
Chong Zhangbef461f2015-10-27 11:38:24 -0700745 }
Chong Zhang92147042016-05-09 12:47:11 -0700746 }
747
748 void clearAllDrawn() {
749 allDrawn = false;
750 deferClearAllDrawn = false;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700751 allDrawnExcludingSaved = false;
Chong Zhangbef461f2015-10-27 11:38:24 -0700752 }
753
Bryce Lee6d410262017-02-28 15:30:17 -0800754 Task getTask() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800755 return (Task) getParent();
Bryce Lee6d410262017-02-28 15:30:17 -0800756 }
757
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800758 TaskStack getStack() {
759 final Task task = getTask();
760 if (task != null) {
761 return task.mStack;
762 } else {
763 return null;
764 }
765 }
766
Bryce Lee6d410262017-02-28 15:30:17 -0800767 @Override
768 void onParentSet() {
769 super.onParentSet();
770
Robert Carred3e83b2017-04-21 13:26:55 -0700771 final Task task = getTask();
772
Bryce Lee6d410262017-02-28 15:30:17 -0800773 // When the associated task is {@code null}, the {@link AppWindowToken} can no longer
774 // access visual elements like the {@link DisplayContent}. We must remove any associations
775 // such as animations.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800776 if (!mReparenting) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800777 if (task == null) {
778 // It is possible we have been marked as a closing app earlier. We must remove ourselves
779 // from this list so we do not participate in any future animations.
780 mService.mClosingApps.remove(this);
Robert Carred3e83b2017-04-21 13:26:55 -0700781 } else if (mLastParent != null && mLastParent.mStack != null) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800782 task.mStack.mExitingAppTokens.remove(this);
783 }
Bryce Lee6d410262017-02-28 15:30:17 -0800784 }
Robert Carred3e83b2017-04-21 13:26:55 -0700785 mLastParent = task;
Bryce Lee6d410262017-02-28 15:30:17 -0800786 }
787
Wale Ogunwalefa854eb2016-09-20 13:43:52 -0700788 void postWindowRemoveStartingWindowCleanup(WindowState win) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700789 // TODO: Something smells about the code below...Is there a better way?
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700790 if (startingWindow == win) {
791 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800792 if (getController() != null) {
793 getController().removeStartingWindow();
794 }
Wale Ogunwale6c459212017-05-17 08:56:03 -0700795 } else if (mChildren.size() == 0) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700796 // If this is the last window and we had requested a starting transition window,
797 // well there is no point now.
Jorim Jaggi02886a82016-12-06 09:10:06 -0800798 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingData");
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700799 startingData = null;
Wale Ogunwale6c459212017-05-17 08:56:03 -0700800 if (mHiddenSetFromTransferredStartingWindow) {
801 // We set the hidden state to false for the token from a transferred starting window.
802 // We now reset it back to true since the starting window was the last window in the
803 // token.
804 hidden = true;
805 }
Jorim Jaggi829b9cd2017-01-23 16:20:53 +0100806 } else if (mChildren.size() == 1 && startingSurface != null && !isRelaunching()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700807 // If this is the last window except for a starting transition window,
808 // we need to get rid of the starting transition.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800809 if (getController() != null) {
810 getController().removeStartingWindow();
811 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700812 }
813 }
814
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700815 void removeDeadWindows() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700816 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700817 WindowState win = mChildren.get(winNdx);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800818 if (win.mAppDied) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700819 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700820 "removeDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800821 // Set mDestroying, we don't want any animation or delayed removal here.
822 win.mDestroying = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700823 // Also removes child windows.
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700824 win.removeIfPossible();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800825 }
826 }
827 }
828
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700829 boolean hasWindowsAlive() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700830 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700831 // No need to loop through child windows as the answer should be the same as that of the
832 // parent window.
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700833 if (!(mChildren.get(i)).mAppDied) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700834 return true;
835 }
836 }
837 return false;
838 }
839
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700840 void setWillReplaceWindows(boolean animate) {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700841 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
842 "Marking app token " + this + " with replacing windows.");
Robert Carra1eb4392015-12-10 12:43:51 -0800843
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700844 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700845 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700846 w.setWillReplaceWindow(animate);
Robert Carra1eb4392015-12-10 12:43:51 -0800847 }
848 if (animate) {
849 // Set-up dummy animation so we can start treating windows associated with this
850 // token like they are in transition before the new app window is ready for us to
851 // run the real transition animation.
852 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700853 "setWillReplaceWindow() Setting dummy animation on: " + this);
Robert Carra1eb4392015-12-10 12:43:51 -0800854 mAppAnimator.setDummyAnimation();
855 }
856 }
857
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700858 void setWillReplaceChildWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700859 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this
Robert Carr23fa16b2016-01-13 13:19:58 -0800860 + " with replacing child windows.");
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700861 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700862 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700863 w.setWillReplaceChildWindows();
Robert Carr23fa16b2016-01-13 13:19:58 -0800864 }
865 }
866
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700867 void clearWillReplaceWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700868 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
869 "Resetting app token " + this + " of replacing window marks.");
Chong Zhangf596cd52016-01-05 13:42:44 -0800870
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700871 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700872 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700873 w.clearWillReplaceWindow();
Chong Zhangf596cd52016-01-05 13:42:44 -0800874 }
875 }
876
Chong Zhang4d7369a2016-04-25 16:09:14 -0700877 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700878 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700879 final WindowState w = mChildren.get(i);
Chong Zhang4d7369a2016-04-25 16:09:14 -0700880 w.requestUpdateWallpaperIfNeeded();
881 }
882 }
883
Chong Zhangd78ddb42016-03-02 17:01:14 -0800884 boolean isRelaunching() {
885 return mPendingRelaunchCount > 0;
886 }
887
888 void startRelaunching() {
889 if (canFreezeBounds()) {
890 freezeBounds();
891 }
Robert Carrd5c7dd62017-03-08 10:39:30 -0800892
893 // In the process of tearing down before relaunching, the app will
894 // try and clean up it's child surfaces. We need to prevent this from
895 // happening, so we sever the children, transfering their ownership
896 // from the client it-self to the parent surface (owned by us).
897 for (int i = mChildren.size() - 1; i >= 0; i--) {
898 final WindowState w = mChildren.get(i);
899 w.mWinAnimator.detachChildren();
900 }
901
Chong Zhangd78ddb42016-03-02 17:01:14 -0800902 mPendingRelaunchCount++;
903 }
904
905 void finishRelaunching() {
906 if (canFreezeBounds()) {
907 unfreezeBounds();
908 }
909 if (mPendingRelaunchCount > 0) {
910 mPendingRelaunchCount--;
911 }
Matthew Ng498c71d2017-04-18 13:55:45 -0700912 updateAllDrawn();
Chong Zhangd78ddb42016-03-02 17:01:14 -0800913 }
914
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700915 void clearRelaunching() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700916 if (mPendingRelaunchCount == 0) {
917 return;
918 }
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700919 if (canFreezeBounds()) {
920 unfreezeBounds();
921 }
922 mPendingRelaunchCount = 0;
923 }
924
Wale Ogunwale07bcab72016-10-14 15:30:09 -0700925 /**
926 * Returns true if the new child window we are adding to this token is considered greater than
927 * the existing child window in this token in terms of z-order.
928 */
929 @Override
930 protected boolean isFirstChildWindowGreaterThanSecond(WindowState newWindow,
931 WindowState existingWindow) {
932 final int type1 = newWindow.mAttrs.type;
933 final int type2 = existingWindow.mAttrs.type;
934
935 // Base application windows should be z-ordered BELOW all other windows in the app token.
936 if (type1 == TYPE_BASE_APPLICATION && type2 != TYPE_BASE_APPLICATION) {
937 return false;
938 } else if (type1 != TYPE_BASE_APPLICATION && type2 == TYPE_BASE_APPLICATION) {
939 return true;
940 }
941
942 // Starting windows should be z-ordered ABOVE all other windows in the app token.
943 if (type1 == TYPE_APPLICATION_STARTING && type2 != TYPE_APPLICATION_STARTING) {
944 return true;
945 } else if (type1 != TYPE_APPLICATION_STARTING && type2 == TYPE_APPLICATION_STARTING) {
946 return false;
947 }
948
949 // Otherwise the new window is greater than the existing window.
950 return true;
951 }
952
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700953 @Override
Robert Carra1eb4392015-12-10 12:43:51 -0800954 void addWindow(WindowState w) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700955 super.addWindow(w);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700956
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700957 boolean gotReplacementWindow = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700958 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700959 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700960 gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w);
961 }
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700962
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700963 // if we got a replacement window, reset the timeout to give drawing more time
964 if (gotReplacementWindow) {
965 mService.scheduleWindowReplacementTimeouts(this);
Robert Carra1eb4392015-12-10 12:43:51 -0800966 }
Jorim Jaggife762342016-10-13 14:33:27 +0200967 checkKeyguardFlagsChanged();
968 }
969
970 @Override
971 void removeChild(WindowState child) {
972 super.removeChild(child);
973 checkKeyguardFlagsChanged();
Robert Carra1eb4392015-12-10 12:43:51 -0800974 }
975
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700976 private boolean waitingForReplacement() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700977 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700978 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700979 if (candidate.waitingForReplacement()) {
Robert Carra1eb4392015-12-10 12:43:51 -0800980 return true;
981 }
982 }
983 return false;
984 }
985
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700986 void onWindowReplacementTimeout() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700987 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700988 (mChildren.get(i)).onWindowReplacementTimeout();
Robert Carra1eb4392015-12-10 12:43:51 -0800989 }
990 }
991
Winson Chung30480042017-01-26 10:55:34 -0800992 void reparent(Task task, int position) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800993 final Task currentTask = getTask();
994 if (task == currentTask) {
Winson Chung30480042017-01-26 10:55:34 -0800995 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800996 "window token=" + this + " already child of task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -0800997 }
Bryce Lee6d410262017-02-28 15:30:17 -0800998
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800999 if (currentTask.mStack != task.mStack) {
Bryce Lee6d410262017-02-28 15:30:17 -08001000 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001001 "window token=" + this + " current task=" + currentTask
Bryce Lee6d410262017-02-28 15:30:17 -08001002 + " belongs to a different stack than " + task);
1003 }
1004
Winson Chung30480042017-01-26 10:55:34 -08001005 if (DEBUG_ADD_REMOVE) Slog.i(TAG, "reParentWindowToken: removing window token=" + this
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001006 + " from task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -08001007 final DisplayContent prevDisplayContent = getDisplayContent();
1008
Bryce Lee6d410262017-02-28 15:30:17 -08001009 mReparenting = true;
1010
Winson Chung30480042017-01-26 10:55:34 -08001011 getParent().removeChild(this);
1012 task.addChild(this, position);
1013
Bryce Lee6d410262017-02-28 15:30:17 -08001014 mReparenting = false;
1015
Winson Chung30480042017-01-26 10:55:34 -08001016 // Relayout display(s).
1017 final DisplayContent displayContent = task.getDisplayContent();
1018 displayContent.setLayoutNeeded();
1019 if (prevDisplayContent != displayContent) {
1020 onDisplayChanged(displayContent);
1021 prevDisplayContent.setLayoutNeeded();
1022 }
1023 }
1024
Chong Zhangd78ddb42016-03-02 17:01:14 -08001025 private boolean canFreezeBounds() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001026 final Task task = getTask();
1027
Chong Zhangd78ddb42016-03-02 17:01:14 -08001028 // For freeform windows, we can't freeze the bounds at the moment because this would make
1029 // the resizing unresponsive.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001030 return task != null && !task.inFreeformWorkspace();
Chong Zhangd78ddb42016-03-02 17:01:14 -08001031 }
1032
Jorim Jaggi0429f352015-12-22 16:29:16 +01001033 /**
1034 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
1035 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
1036 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
1037 * with a queue.
1038 */
Chong Zhangd78ddb42016-03-02 17:01:14 -08001039 private void freezeBounds() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001040 final Task task = getTask();
1041 mFrozenBounds.offer(new Rect(task.mPreparedFrozenBounds));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001042
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001043 if (task.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) {
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001044 // We didn't call prepareFreezingBounds on the task, so use the current value.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001045 mFrozenMergedConfig.offer(new Configuration(task.getConfiguration()));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001046 } else {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001047 mFrozenMergedConfig.offer(new Configuration(task.mPreparedFrozenMergedConfig));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001048 }
Andrii Kulianb10330d2016-09-16 13:51:46 -07001049 // Calling unset() to make it equal to Configuration.EMPTY.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001050 task.mPreparedFrozenMergedConfig.unset();
Jorim Jaggi0429f352015-12-22 16:29:16 +01001051 }
1052
1053 /**
1054 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
1055 */
Chong Zhangd78ddb42016-03-02 17:01:14 -08001056 private void unfreezeBounds() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -07001057 if (!mFrozenBounds.isEmpty()) {
1058 mFrozenBounds.remove();
1059 }
1060 if (!mFrozenMergedConfig.isEmpty()) {
1061 mFrozenMergedConfig.remove();
1062 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001063 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001064 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001065 win.onUnfreezeBounds();
Jorim Jaggi4846ee32016-01-07 17:39:12 +01001066 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001067 mService.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +01001068 }
1069
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001070 void setAppLayoutChanges(int changes, String reason) {
1071 if (!mChildren.isEmpty()) {
1072 final DisplayContent dc = getDisplayContent();
1073 dc.pendingLayoutChanges |= changes;
1074 if (DEBUG_LAYOUT_REPEATS) {
1075 mService.mWindowPlacerLocked.debugLayoutRepeats(reason, dc.pendingLayoutChanges);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001076 }
1077 }
1078 }
1079
1080 void removeReplacedWindowIfNeeded(WindowState replacement) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001081 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001082 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001083 if (win.removeReplacedWindowIfNeeded(replacement)) {
1084 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001085 }
1086 }
1087 }
1088
1089 void startFreezingScreen() {
1090 if (DEBUG_ORIENTATION) logWithStack(TAG, "Set freezing of " + appToken + ": hidden="
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001091 + hidden + " freezing=" + mAppAnimator.freezingScreen + " hiddenRequested="
1092 + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001093 if (!hiddenRequested) {
1094 if (!mAppAnimator.freezingScreen) {
1095 mAppAnimator.freezingScreen = true;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001096 mService.registerAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001097 mAppAnimator.lastFreezeDuration = 0;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001098 mService.mAppsFreezingScreen++;
1099 if (mService.mAppsFreezingScreen == 1) {
1100 mService.startFreezingDisplayLocked(false, 0, 0);
1101 mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT);
1102 mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001103 }
1104 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001105 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001106 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001107 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001108 w.onStartFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001109 }
1110 }
1111 }
1112
1113 void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) {
1114 if (!mAppAnimator.freezingScreen) {
1115 return;
1116 }
1117 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + this + " force=" + force);
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001118 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001119 boolean unfrozeWindows = false;
1120 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001121 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001122 unfrozeWindows |= w.onStopFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001123 }
1124 if (force || unfrozeWindows) {
1125 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this);
1126 mAppAnimator.freezingScreen = false;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001127 mService.unregisterAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001128 mAppAnimator.lastFreezeDuration =
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001129 (int)(SystemClock.elapsedRealtime() - mService.mDisplayFreezeTime);
1130 mService.mAppsFreezingScreen--;
1131 mService.mLastFinishedFreezeSource = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001132 }
1133 if (unfreezeSurfaceNow) {
1134 if (unfrozeWindows) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001135 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001136 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001137 mService.stopFreezingDisplayLocked();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001138 }
1139 }
1140
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001141 @Override
1142 public void onAppFreezeTimeout() {
1143 Slog.w(TAG_WM, "Force clearing freeze: " + this);
1144 stopFreezingScreen(true, true);
1145 }
1146
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001147 boolean transferStartingWindow(IBinder transferFrom) {
Wale Ogunwale02319a62016-09-26 15:21:22 -07001148 final AppWindowToken fromToken = getDisplayContent().getAppWindowToken(transferFrom);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001149 if (fromToken == null) {
1150 return false;
1151 }
1152
1153 final WindowState tStartingWindow = fromToken.startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001154 if (tStartingWindow != null && fromToken.startingSurface != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001155 // In this case, the starting icon has already been displayed, so start
1156 // letting windows get shown immediately without any more transitions.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001157 mService.mSkipAppTransitionAnimation = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001158
1159 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow
1160 + " from " + fromToken + " to " + this);
1161
1162 final long origId = Binder.clearCallingIdentity();
1163
1164 // Transfer the starting window over to the new token.
1165 startingData = fromToken.startingData;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001166 startingSurface = fromToken.startingSurface;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001167 startingDisplayed = fromToken.startingDisplayed;
1168 fromToken.startingDisplayed = false;
1169 startingWindow = tStartingWindow;
1170 reportedVisible = fromToken.reportedVisible;
1171 fromToken.startingData = null;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001172 fromToken.startingSurface = null;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001173 fromToken.startingWindow = null;
1174 fromToken.startingMoved = true;
1175 tStartingWindow.mToken = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001176 tStartingWindow.mAppToken = this;
1177
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001178 if (DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001179 "Removing starting " + tStartingWindow + " from " + fromToken);
Wale Ogunwalefa854eb2016-09-20 13:43:52 -07001180 fromToken.removeChild(tStartingWindow);
1181 fromToken.postWindowRemoveStartingWindowCleanup(tStartingWindow);
Wale Ogunwale6c459212017-05-17 08:56:03 -07001182 fromToken.mHiddenSetFromTransferredStartingWindow = false;
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001183 addWindow(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001184
1185 // Propagate other interesting state between the tokens. If the old token is displayed,
1186 // we should immediately force the new one to be displayed. If it is animating, we need
1187 // to move that animation to the new one.
1188 if (fromToken.allDrawn) {
1189 allDrawn = true;
1190 deferClearAllDrawn = fromToken.deferClearAllDrawn;
1191 }
1192 if (fromToken.firstWindowDrawn) {
1193 firstWindowDrawn = true;
1194 }
1195 if (!fromToken.hidden) {
1196 hidden = false;
1197 hiddenRequested = false;
Wale Ogunwale6c459212017-05-17 08:56:03 -07001198 mHiddenSetFromTransferredStartingWindow = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001199 }
Wale Ogunwale89973222017-04-23 18:39:45 -07001200 setClientHidden(fromToken.mClientHidden);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001201 fromToken.mAppAnimator.transferCurrentAnimation(
1202 mAppAnimator, tStartingWindow.mWinAnimator);
1203
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001204 mService.updateFocusedWindowLocked(
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001205 UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/);
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001206 getDisplayContent().setLayoutNeeded();
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001207 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001208 Binder.restoreCallingIdentity(origId);
1209 return true;
1210 } else if (fromToken.startingData != null) {
1211 // The previous app was getting ready to show a
1212 // starting window, but hasn't yet done so. Steal it!
1213 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1214 "Moving pending starting from " + fromToken + " to " + this);
1215 startingData = fromToken.startingData;
1216 fromToken.startingData = null;
1217 fromToken.startingMoved = true;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001218 if (getController() != null) {
1219 getController().scheduleAddStartingWindow();
1220 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001221 return true;
1222 }
1223
1224 final AppWindowAnimator tAppAnimator = fromToken.mAppAnimator;
1225 final AppWindowAnimator wAppAnimator = mAppAnimator;
1226 if (tAppAnimator.thumbnail != null) {
1227 // The old token is animating with a thumbnail, transfer that to the new token.
1228 if (wAppAnimator.thumbnail != null) {
1229 wAppAnimator.thumbnail.destroy();
1230 }
1231 wAppAnimator.thumbnail = tAppAnimator.thumbnail;
1232 wAppAnimator.thumbnailLayer = tAppAnimator.thumbnailLayer;
1233 wAppAnimator.thumbnailAnimation = tAppAnimator.thumbnailAnimation;
1234 tAppAnimator.thumbnail = null;
1235 }
1236 return false;
1237 }
1238
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001239 boolean isLastWindow(WindowState win) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001240 return mChildren.size() == 1 && mChildren.get(0) == win;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001241 }
1242
1243 void setAllAppWinAnimators() {
1244 final ArrayList<WindowStateAnimator> allAppWinAnimators = mAppAnimator.mAllAppWinAnimators;
1245 allAppWinAnimators.clear();
1246
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001247 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001248 for (int j = 0; j < windowsCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001249 (mChildren.get(j)).addWinAnimatorToList(allAppWinAnimators);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001250 }
1251 }
1252
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001253 @Override
1254 void onAppTransitionDone() {
1255 sendingToBottom = false;
1256 }
1257
Wale Ogunwale51362492016-09-08 17:49:17 -07001258 /**
1259 * We override because this class doesn't want its children affecting its reported orientation
1260 * in anyway.
1261 */
1262 @Override
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001263 int getOrientation(int candidate) {
Bryce Leed1ac18c2017-05-11 07:59:41 -07001264 // We do not allow non-fullscreen apps to influence orientation beyond O. While we do
Bryce Lee39791592017-04-26 09:29:12 -07001265 // throw an exception in {@link Activity#onCreate} and
1266 // {@link Activity#setRequestedOrientation}, we also ignore the orientation here so that
1267 // other calculations aren't affected.
Bryce Leed1ac18c2017-05-11 07:59:41 -07001268 if (!fillsParent() && mTargetSdk > O) {
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001269 // Can't specify orientation if app doesn't fill parent.
1270 return SCREEN_ORIENTATION_UNSET;
1271 }
1272
1273 if (candidate == SCREEN_ORIENTATION_BEHIND) {
1274 // Allow app to specify orientation regardless of its visibility state if the current
1275 // candidate want us to use orientation behind. I.e. the visible app on-top of this one
1276 // wants us to use the orientation of the app behind it.
1277 return mOrientation;
1278 }
1279
Bryce Lee61fbcbc2017-03-10 14:14:03 -08001280 // The {@link AppWindowToken} should only specify an orientation when it is not closing or
1281 // going to the bottom. Allowing closing {@link AppWindowToken} to participate can lead to
1282 // an Activity in another task being started in the wrong orientation during the transition.
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001283 if (!(sendingToBottom || mService.mClosingApps.contains(this))
Bryce Lee61fbcbc2017-03-10 14:14:03 -08001284 && (isVisible() || mService.mOpeningApps.contains(this))) {
Bryce Leea163b762017-01-24 11:05:01 -08001285 return mOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001286 }
Bryce Leea163b762017-01-24 11:05:01 -08001287
1288 return SCREEN_ORIENTATION_UNSET;
Wale Ogunwale51362492016-09-08 17:49:17 -07001289 }
1290
Wale Ogunwaleb198b742016-12-01 08:44:09 -08001291 /** Returns the app's preferred orientation regardless of its currently visibility state. */
1292 int getOrientationIgnoreVisibility() {
1293 return mOrientation;
1294 }
1295
Craig Mautnerdbb79912012-03-01 18:59:14 -08001296 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001297 void checkAppWindowsReadyToShow() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001298 if (allDrawn == mAppAnimator.allDrawn) {
1299 return;
1300 }
1301
1302 mAppAnimator.allDrawn = allDrawn;
1303 if (!allDrawn) {
1304 return;
1305 }
1306
1307 // The token has now changed state to having all windows shown... what to do, what to do?
1308 if (mAppAnimator.freezingScreen) {
1309 mAppAnimator.showAllWindowsLocked();
1310 stopFreezingScreen(false, true);
1311 if (DEBUG_ORIENTATION) Slog.i(TAG,
1312 "Setting mOrientationChangeComplete=true because wtoken " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001313 + " numInteresting=" + mNumInterestingWindows + " numDrawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001314 // This will set mOrientationChangeComplete and cause a pass through layout.
1315 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001316 "checkAppWindowsReadyToShow: freezingScreen");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001317 } else {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001318 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001319
1320 // We can now show all of the drawn windows!
1321 if (!mService.mOpeningApps.contains(this)) {
1322 mService.mAnimator.orAnimating(mAppAnimator.showAllWindowsLocked());
1323 }
1324 }
1325 }
1326
Matthew Ng498c71d2017-04-18 13:55:45 -07001327 void updateAllDrawn() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001328 if (!allDrawn) {
Matthew Ng498c71d2017-04-18 13:55:45 -07001329 // Number of drawn windows can be less when a window is being relaunched, wait for
1330 // all windows to be launched and drawn for this token be considered all drawn
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001331 final int numInteresting = mNumInterestingWindows;
Matthew Ng498c71d2017-04-18 13:55:45 -07001332 if (numInteresting > 0 && mNumDrawnWindows >= numInteresting && !isRelaunching()) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001333 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawn: " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001334 + " interesting=" + numInteresting + " drawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001335 allDrawn = true;
1336 // Force an additional layout pass where
1337 // WindowStateAnimator#commitFinishDrawingLocked() will call performShowLocked().
Matthew Ng498c71d2017-04-18 13:55:45 -07001338 if (mDisplayContent != null) {
1339 mDisplayContent.setLayoutNeeded();
1340 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001341 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Robert Carrecc06b32017-04-18 14:25:10 -07001342
1343 final TaskStack s = getStack();
1344 if (s != null) {
1345 s.onAllWindowsDrawn();
1346 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001347 }
1348 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001349
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001350 if (!allDrawnExcludingSaved) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001351 int numInteresting = mNumInterestingWindowsExcludingSaved;
1352 if (numInteresting > 0 && mNumDrawnWindowsExcludingSaved >= numInteresting) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001353 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawnExcludingSaved: " + this
1354 + " interesting=" + numInteresting
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001355 + " drawn=" + mNumDrawnWindowsExcludingSaved);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001356 allDrawnExcludingSaved = true;
Matthew Ng498c71d2017-04-18 13:55:45 -07001357 if (mDisplayContent != null) {
1358 mDisplayContent.setLayoutNeeded();
1359 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001360 if (isAnimatingInvisibleWithSavedSurface()
1361 && !mService.mFinishedEarlyAnim.contains(this)) {
1362 mService.mFinishedEarlyAnim.add(this);
1363 }
1364 }
1365 }
1366 }
1367
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001368 /**
1369 * Updated this app token tracking states for interesting and drawn windows based on the window.
1370 *
1371 * @return Returns true if the input window is considered interesting and drawn while all the
1372 * windows in this app token where not considered drawn as of the last pass.
1373 */
1374 boolean updateDrawnWindowStates(WindowState w) {
1375 if (DEBUG_STARTING_WINDOW && w == startingWindow) {
1376 Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" + w.isOnScreen()
1377 + " allDrawn=" + allDrawn + " freezingScreen=" + mAppAnimator.freezingScreen);
1378 }
1379
1380 if (allDrawn && allDrawnExcludingSaved && !mAppAnimator.freezingScreen) {
1381 return false;
1382 }
1383
1384 if (mLastTransactionSequence != mService.mTransactionSequence) {
1385 mLastTransactionSequence = mService.mTransactionSequence;
1386 mNumInterestingWindows = mNumDrawnWindows = 0;
1387 mNumInterestingWindowsExcludingSaved = 0;
1388 mNumDrawnWindowsExcludingSaved = 0;
1389 startingDisplayed = false;
1390 }
1391
1392 final WindowStateAnimator winAnimator = w.mWinAnimator;
1393
1394 boolean isInterestingAndDrawn = false;
1395
1396 if (!allDrawn && w.mightAffectAllDrawn(false /* visibleOnly */)) {
1397 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
1398 Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw()
1399 + ", isAnimationSet=" + winAnimator.isAnimationSet());
1400 if (!w.isDrawnLw()) {
1401 Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController
1402 + " pv=" + w.mPolicyVisibility
1403 + " mDrawState=" + winAnimator.drawStateToString()
1404 + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested
1405 + " a=" + winAnimator.mAnimating);
1406 }
1407 }
1408
1409 if (w != startingWindow) {
1410 if (w.isInteresting()) {
1411 mNumInterestingWindows++;
1412 if (w.isDrawnLw()) {
1413 mNumDrawnWindows++;
1414
1415 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, "tokenMayBeDrawn: "
1416 + this + " w=" + w + " numInteresting=" + mNumInterestingWindows
1417 + " freezingScreen=" + mAppAnimator.freezingScreen
1418 + " mAppFreezing=" + w.mAppFreezing);
1419
1420 isInterestingAndDrawn = true;
1421 }
1422 }
1423 } else if (w.isDrawnLw()) {
Jorim Jaggi3878ca32017-02-02 17:13:05 -08001424 if (getController() != null) {
1425 getController().reportStartingWindowDrawn();
1426 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001427 startingDisplayed = true;
1428 }
1429 }
1430
1431 if (!allDrawnExcludingSaved && w.mightAffectAllDrawn(true /* visibleOnly */)) {
1432 if (w != startingWindow && w.isInteresting()) {
1433 mNumInterestingWindowsExcludingSaved++;
1434 if (w.isDrawnLw() && !w.isAnimatingWithSavedSurface()) {
1435 mNumDrawnWindowsExcludingSaved++;
1436
1437 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
1438 "tokenMayBeDrawnExcludingSaved: " + this + " w=" + w
1439 + " numInteresting=" + mNumInterestingWindowsExcludingSaved
1440 + " freezingScreen=" + mAppAnimator.freezingScreen
1441 + " mAppFreezing=" + w.mAppFreezing);
1442
1443 isInterestingAndDrawn = true;
1444 }
1445 }
1446 }
1447
1448 return isInterestingAndDrawn;
1449 }
1450
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001451 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001452 void stepAppWindowsAnimation(long currentTime) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001453 mAppAnimator.wasAnimating = mAppAnimator.animating;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001454 if (mAppAnimator.stepAnimationLocked(currentTime)) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001455 mAppAnimator.animating = true;
1456 mService.mAnimator.setAnimating(true);
1457 mService.mAnimator.mAppWindowAnimating = true;
1458 } else if (mAppAnimator.wasAnimating) {
1459 // stopped animating, do one more pass through the layout
Wale Ogunwale1e129a42016-11-21 13:03:47 -08001460 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
1461 DEBUG_LAYOUT_REPEATS ? "appToken " + this + " done" : null);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001462 if (DEBUG_ANIM) Slog.v(TAG, "updateWindowsApps...: done animating " + this);
1463 }
1464 }
1465
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001466 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001467 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001468 // For legacy reasons we process the TaskStack.mExitingAppTokens first in DisplayContent
1469 // before the non-exiting app tokens. So, we skip the exiting app tokens here.
1470 // TODO: Investigate if we need to continue to do this or if we can just process them
1471 // in-order.
1472 if (mIsExiting && !waitingForReplacement()) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001473 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001474 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001475 return forAllWindowsUnchecked(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001476 }
1477
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001478 boolean forAllWindowsUnchecked(ToBooleanFunction<WindowState> callback,
1479 boolean traverseTopToBottom) {
1480 return super.forAllWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001481 }
1482
1483 @Override
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001484 AppWindowToken asAppWindowToken() {
1485 // I am an app window token!
1486 return this;
1487 }
1488
1489 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -07001490 boolean fillsParent() {
1491 return mFillsParent;
1492 }
1493
1494 void setFillsParent(boolean fillsParent) {
1495 mFillsParent = fillsParent;
1496 }
1497
Jorim Jaggife762342016-10-13 14:33:27 +02001498 boolean containsDismissKeyguardWindow() {
1499 for (int i = mChildren.size() - 1; i >= 0; i--) {
1500 if ((mChildren.get(i).mAttrs.flags & FLAG_DISMISS_KEYGUARD) != 0) {
1501 return true;
1502 }
1503 }
1504 return false;
1505 }
1506
1507 boolean containsShowWhenLockedWindow() {
1508 for (int i = mChildren.size() - 1; i >= 0; i--) {
1509 if ((mChildren.get(i).mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
1510 return true;
1511 }
1512 }
1513 return false;
1514 }
1515
1516 void checkKeyguardFlagsChanged() {
1517 final boolean containsDismissKeyguard = containsDismissKeyguardWindow();
1518 final boolean containsShowWhenLocked = containsShowWhenLockedWindow();
1519 if (containsDismissKeyguard != mLastContainsDismissKeyguardWindow
1520 || containsShowWhenLocked != mLastContainsShowWhenLockedWindow) {
1521 mService.notifyKeyguardFlagsChanged(null /* callback */);
1522 }
1523 mLastContainsDismissKeyguardWindow = containsDismissKeyguard;
1524 mLastContainsShowWhenLockedWindow = containsShowWhenLocked;
1525 }
1526
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001527 WindowState getImeTargetBelowWindow(WindowState w) {
1528 final int index = mChildren.indexOf(w);
1529 if (index > 0) {
1530 final WindowState target = mChildren.get(index - 1);
1531 if (target.canBeImeTarget()) {
1532 return target;
1533 }
1534 }
1535 return null;
1536 }
1537
1538 WindowState getHighestAnimLayerWindow(WindowState currentTarget) {
1539 WindowState candidate = null;
1540 for (int i = mChildren.indexOf(currentTarget); i >= 0; i--) {
1541 final WindowState w = mChildren.get(i);
1542 if (w.mRemoved) {
1543 continue;
1544 }
1545 if (candidate == null || w.mWinAnimator.mAnimLayer >
1546 candidate.mWinAnimator.mAnimLayer) {
1547 candidate = w;
1548 }
1549 }
1550 return candidate;
1551 }
1552
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001553 /**
1554 * See {@link Activity#setDisablePreviewScreenshots}.
1555 */
1556 void setDisablePreviewScreenshots(boolean disable) {
Wale Ogunwale6c459212017-05-17 08:56:03 -07001557 mDisablePreviewScreenshots = disable;
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001558 }
1559
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001560 /**
1561 * Retrieves whether we'd like to generate a snapshot that's based solely on the theme. This is
1562 * the case when preview screenshots are disabled {@link #setDisablePreviewScreenshots} or when
1563 * we can't take a snapshot for other reasons, for example, if we have a secure window.
1564 *
1565 * @return True if we need to generate an app theme snapshot, false if we'd like to take a real
1566 * screenshot.
1567 */
1568 boolean shouldUseAppThemeSnapshot() {
Wale Ogunwale6c459212017-05-17 08:56:03 -07001569 return mDisablePreviewScreenshots || forAllWindows(w -> (w.mAttrs.flags & FLAG_SECURE) != 0,
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001570 true /* topToBottom */);
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001571 }
1572
Wale Ogunwale51362492016-09-08 17:49:17 -07001573 @Override
Robert Carrdee1b3f2017-02-27 11:33:33 -08001574 int getAnimLayerAdjustment() {
1575 return mAppAnimator.animLayerAdjustment;
1576 }
1577
1578 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001579 void dump(PrintWriter pw, String prefix) {
1580 super.dump(pw, prefix);
1581 if (appToken != null) {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001582 pw.println(prefix + "app=true mVoiceInteraction=" + mVoiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001583 }
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001584 pw.print(prefix); pw.print("task="); pw.println(getTask());
Wale Ogunwale51362492016-09-08 17:49:17 -07001585 pw.print(prefix); pw.print(" mFillsParent="); pw.print(mFillsParent);
1586 pw.print(" mOrientation="); pw.println(mOrientation);
Wale Ogunwale89973222017-04-23 18:39:45 -07001587 pw.println(prefix + "hiddenRequested=" + hiddenRequested + " mClientHidden=" + mClientHidden
1588 + ((mDeferHidingClient) ? " mDeferHidingClient=" + mDeferHidingClient : "")
1589 + " reportedDrawn=" + reportedDrawn + " reportedVisible=" + reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -07001590 if (paused) {
1591 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001592 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001593 if (mAppStopped) {
1594 pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped);
1595 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001596 if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0
Craig Mautner6fbda632012-07-03 09:26:39 -07001597 || allDrawn || mAppAnimator.allDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001598 pw.print(prefix); pw.print("mNumInterestingWindows=");
1599 pw.print(mNumInterestingWindows);
1600 pw.print(" mNumDrawnWindows="); pw.print(mNumDrawnWindows);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001601 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -07001602 pw.print(" allDrawn="); pw.print(allDrawn);
1603 pw.print(" (animator="); pw.print(mAppAnimator.allDrawn);
1604 pw.println(")");
1605 }
1606 if (inPendingTransaction) {
1607 pw.print(prefix); pw.print("inPendingTransaction=");
1608 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001609 }
Craig Mautner799bc1d2015-01-14 10:33:48 -08001610 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001611 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
1612 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -08001613 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -08001614 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001615 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001616 if (startingWindow != null || startingSurface != null
Wale Ogunwale6c459212017-05-17 08:56:03 -07001617 || startingDisplayed || startingMoved || mHiddenSetFromTransferredStartingWindow) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001618 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001619 pw.print(" startingSurface="); pw.print(startingSurface);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001620 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
Wale Ogunwale6c459212017-05-17 08:56:03 -07001621 pw.print(" startingMoved="); pw.print(startingMoved);
1622 pw.println(" mHiddenSetFromTransferredStartingWindow="
1623 + mHiddenSetFromTransferredStartingWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001624 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01001625 if (!mFrozenBounds.isEmpty()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -08001626 pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds);
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001627 pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig);
Chong Zhangd78ddb42016-03-02 17:01:14 -08001628 }
1629 if (mPendingRelaunchCount != 0) {
1630 pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount);
Jorim Jaggi0429f352015-12-22 16:29:16 +01001631 }
Wale Ogunwale9c64cb62017-04-12 13:39:59 -07001632 if (getController() != null) {
1633 pw.print(prefix); pw.print("controller="); pw.println(getController());
1634 }
Wale Ogunwalee287e192017-04-21 09:30:12 -07001635 if (mRemovingFromDisplay) {
1636 pw.println(prefix + "mRemovingFromDisplay=" + mRemovingFromDisplay);
1637 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001638 }
1639
1640 @Override
1641 public String toString() {
1642 if (stringName == null) {
1643 StringBuilder sb = new StringBuilder();
1644 sb.append("AppWindowToken{");
1645 sb.append(Integer.toHexString(System.identityHashCode(this)));
1646 sb.append(" token="); sb.append(token); sb.append('}');
1647 stringName = sb.toString();
1648 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001649 return stringName + ((mIsExiting) ? " mIsExiting=" : "");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001650 }
Jeff Browne9bdb312012-04-05 15:30:10 -07001651}