blob: c39ce982e4cbb0e538370043ee5a484ee26d38ee [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 Ogunwale72919d22016-12-08 18:58:50 -080019import static android.content.pm.ActivityInfo.CONFIG_ORIENTATION;
20import static android.content.pm.ActivityInfo.CONFIG_SCREEN_SIZE;
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -070021import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND;
Wale Ogunwale51362492016-09-08 17:49:17 -070022import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070023import static android.view.Display.DEFAULT_DISPLAY;
Jorim Jaggife762342016-10-13 14:33:27 +020024import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
Jorim Jaggid635a4a2017-05-03 15:21:26 +020025import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
Jorim Jaggife762342016-10-13 14:33:27 +020026import 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;
Adrian Roose99bc052017-11-20 17:55:31 +010030import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
31import static com.android.server.policy.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;
Jorim Jaggie4b0f282017-05-17 15:10:29 +020040import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW_VERBOSE;
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;
Steven Timotiusaf03df62017-07-18 16:56:43 -070050import static com.android.server.wm.proto.AppWindowTokenProto.NAME;
51import static com.android.server.wm.proto.AppWindowTokenProto.WINDOW_TOKEN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080052
Wale Ogunwale0d5609b2017-09-13 05:55:07 -070053import android.annotation.CallSuper;
Filip Gruszczynskia590c992015-11-25 16:45:26 -080054import android.annotation.NonNull;
Jorim Jaggid635a4a2017-05-03 15:21:26 +020055import android.app.Activity;
Jorim Jaggi26c8c422016-05-09 19:57:25 -070056import android.content.res.Configuration;
Jorim Jaggi0429f352015-12-22 16:29:16 +010057import android.graphics.Rect;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070058import android.os.Binder;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080059import android.os.Debug;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070060import android.os.IBinder;
Steven Timotiusaf03df62017-07-18 16:56:43 -070061import android.os.RemoteException;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070062import android.os.SystemClock;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080063import android.util.Slog;
Steven Timotiusaf03df62017-07-18 16:56:43 -070064import android.util.proto.ProtoOutputStream;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080065import android.view.IApplicationToken;
Robert Carr6914f082017-03-20 19:04:30 -070066import android.view.SurfaceControl;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080067import android.view.WindowManager;
Jorim Jaggi87fdbcb2017-08-17 13:41:11 +020068import android.view.WindowManager.LayoutParams;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080069
70import com.android.internal.util.ToBooleanFunction;
71import com.android.server.input.InputApplicationHandle;
Adrian Roose99bc052017-11-20 17:55:31 +010072import com.android.server.policy.WindowManagerPolicy.StartingSurface;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080073import com.android.server.wm.WindowManagerService.H;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080074
75import java.io.PrintWriter;
Jorim Jaggi0429f352015-12-22 16:29:16 +010076import java.util.ArrayDeque;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080077import java.util.ArrayList;
78
79class AppTokenList extends ArrayList<AppWindowToken> {
80}
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080081
82/**
83 * Version of WindowToken that is specifically for a particular application (or
84 * really activity) that is displaying windows.
85 */
Wale Ogunwale3f4433d2016-08-18 20:42:42 -070086class AppWindowToken extends WindowToken implements WindowManagerService.AppFreezeListener {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080087 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppWindowToken" : TAG_WM;
88
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080089 // Non-null only for application tokens.
90 final IApplicationToken appToken;
91
Filip Gruszczynskia590c992015-11-25 16:45:26 -080092 @NonNull final AppWindowAnimator mAppAnimator;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -070093
Wale Ogunwale72919d22016-12-08 18:58:50 -080094 final boolean mVoiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -070095
Wale Ogunwale51362492016-09-08 17:49:17 -070096 /** @see WindowContainer#fillsParent() */
97 private boolean mFillsParent;
Craig Mautner4c5eb222013-11-18 12:59:05 -080098 boolean layoutConfigChanges;
Wale Ogunwale72919d22016-12-08 18:58:50 -080099 boolean mShowForAllUsers;
100 int mTargetSdk;
Craig Mautnera2c77052012-03-26 12:14:43 -0700101
Bryce Lee6d410262017-02-28 15:30:17 -0800102 // Flag set while reparenting to prevent actions normally triggered by an individual parent
103 // change.
104 private boolean mReparenting;
105
Wale Ogunwalee287e192017-04-21 09:30:12 -0700106 // True if we are current in the process of removing this app token from the display
107 private boolean mRemovingFromDisplay = false;
108
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800109 // The input dispatching timeout for this application token in nanoseconds.
Wale Ogunwale72919d22016-12-08 18:58:50 -0800110 long mInputDispatchingTimeoutNanos;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800111
112 // These are used for determining when all windows associated with
113 // an activity have been drawn, so they can be made visible together
114 // at the same time.
Craig Mautner764983d2012-03-22 11:37:36 -0700115 // initialize so that it doesn't match mTransactionSequence which is an int.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700116 private long mLastTransactionSequence = Long.MIN_VALUE;
117 private int mNumInterestingWindows;
118 private int mNumDrawnWindows;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800119 boolean inPendingTransaction;
120 boolean allDrawn;
Craig Mautner7636dfb2012-11-16 15:24:11 -0800121 // Set to true when this app creates a surface while in the middle of an animation. In that
122 // case do not clear allDrawn until the animation completes.
123 boolean deferClearAllDrawn;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800124
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;
Wale Ogunwale6c459212017-05-17 08:56:03 -0700153 // True if the hidden state of this token was forced to false due to a transferred starting
154 // window.
155 private boolean mHiddenSetFromTransferredStartingWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800156 boolean firstWindowDrawn;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700157 private final WindowState.UpdateReportedVisibilityResults mReportedVisibilityResults =
158 new WindowState.UpdateReportedVisibilityResults();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800159
160 // Input application handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700161 final InputApplicationHandle mInputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800162
Wale Ogunwale571771c2016-08-26 13:18:50 -0700163 // TODO: Have a WindowContainer state for tracking exiting/deferred removal.
Craig Mautner799bc1d2015-01-14 10:33:48 -0800164 boolean mIsExiting;
Craig Mautner9ef471f2014-02-07 13:11:47 -0800165
Craig Mautnerbb742462014-07-07 15:28:55 -0700166 boolean mLaunchTaskBehind;
Craig Mautner8746a472014-07-24 15:12:54 -0700167 boolean mEnteringAnimation;
Craig Mautnerbb742462014-07-07 15:28:55 -0700168
Wale Ogunwale72919d22016-12-08 18:58:50 -0800169 private boolean mAlwaysFocusable;
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800170
Robert Carre12aece2016-02-02 22:43:27 -0800171 boolean mAppStopped;
Robert Carrfd10cd12016-06-29 16:41:50 -0700172 int mRotationAnimationHint;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700173 private int mPendingRelaunchCount;
Robert Carre12aece2016-02-02 22:43:27 -0800174
Jorim Jaggife762342016-10-13 14:33:27 +0200175 private boolean mLastContainsShowWhenLockedWindow;
176 private boolean mLastContainsDismissKeyguardWindow;
177
Jorim Jaggi0429f352015-12-22 16:29:16 +0100178 ArrayDeque<Rect> mFrozenBounds = new ArrayDeque<>();
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700179 ArrayDeque<Configuration> mFrozenMergedConfig = new ArrayDeque<>();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100180
Wale Ogunwale6c459212017-05-17 08:56:03 -0700181 private boolean mDisablePreviewScreenshots;
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +0100182
Wale Ogunwale034a8ec2017-09-02 17:14:40 -0700183 private Task mLastParent;
Robert Carred3e83b2017-04-21 13:26:55 -0700184
chaviwd3bf08d2017-08-01 17:24:59 -0700185 /**
186 * See {@link #canTurnScreenOn()}
187 */
188 private boolean mCanTurnScreenOn = true;
189
Wale Ogunwale72919d22016-12-08 18:58:50 -0800190 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
191 DisplayContent dc, long inputDispatchingTimeoutNanos, boolean fullscreen,
192 boolean showForAllUsers, int targetSdk, int orientation, int rotationAnimationHint,
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800193 int configChanges, boolean launchTaskBehind, boolean alwaysFocusable,
Bryce Leef3c6a472017-11-14 14:53:06 -0800194 AppWindowContainerController controller) {
195 this(service, token, voiceInteraction, dc, fullscreen);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800196 setController(controller);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800197 mInputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800198 mShowForAllUsers = showForAllUsers;
199 mTargetSdk = targetSdk;
200 mOrientation = orientation;
201 layoutConfigChanges = (configChanges & (CONFIG_SCREEN_SIZE | CONFIG_ORIENTATION)) != 0;
202 mLaunchTaskBehind = launchTaskBehind;
203 mAlwaysFocusable = alwaysFocusable;
204 mRotationAnimationHint = rotationAnimationHint;
205
206 // Application tokens start out hidden.
207 hidden = true;
208 hiddenRequested = true;
209 }
210
211 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
Bryce Leef3c6a472017-11-14 14:53:06 -0800212 DisplayContent dc, boolean fillsParent) {
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800213 super(service, token != null ? token.asBinder() : null, TYPE_APPLICATION, true, dc,
214 false /* ownerCanManageAppTokens */);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700215 appToken = token;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800216 mVoiceInteraction = voiceInteraction;
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800217 mFillsParent = fillsParent;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800218 mInputApplicationHandle = new InputApplicationHandle(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700219 mAppAnimator = new AppWindowAnimator(this, service);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800220 }
221
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800222 void onFirstWindowDrawn(WindowState win, WindowStateAnimator winAnimator) {
223 firstWindowDrawn = true;
224
225 // We now have a good window to show, remove dead placeholders
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700226 removeDeadWindows();
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800227
Jorim Jaggi02886a82016-12-06 09:10:06 -0800228 if (startingWindow != null) {
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800229 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, "Finish starting "
230 + win.mToken + ": first real window is shown, no animation");
231 // If this initial window is animating, stop it -- we will do an animation to reveal
232 // it from behind the starting window, so there is no need for it to also be doing its
233 // own stuff.
234 winAnimator.clearAnimation();
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800235 if (getController() != null) {
236 getController().removeStartingWindow();
237 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800238 }
239 updateReportedVisibilityLocked();
240 }
241
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800242 void updateReportedVisibilityLocked() {
243 if (appToken == null) {
244 return;
245 }
246
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700247 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700248 final int count = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800249
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700250 mReportedVisibilityResults.reset();
251
252 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700253 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700254 win.updateReportedVisibility(mReportedVisibilityResults);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800255 }
256
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700257 int numInteresting = mReportedVisibilityResults.numInteresting;
258 int numVisible = mReportedVisibilityResults.numVisible;
259 int numDrawn = mReportedVisibilityResults.numDrawn;
260 boolean nowGone = mReportedVisibilityResults.nowGone;
261
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700262 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Jorim Jaggi6dfd9ba2017-08-03 15:00:01 +0200263 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting && !hidden;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700264 if (!nowGone) {
265 // If the app is not yet gone, then it can only become visible/drawn.
266 if (!nowDrawn) {
267 nowDrawn = reportedDrawn;
268 }
269 if (!nowVisible) {
270 nowVisible = reportedVisible;
271 }
272 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800273 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800274 + numInteresting + " visible=" + numVisible);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800275 final AppWindowContainerController controller = getController();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700276 if (nowDrawn != reportedDrawn) {
277 if (nowDrawn) {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800278 if (controller != null) {
279 controller.reportWindowsDrawn();
280 }
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700281 }
282 reportedDrawn = nowDrawn;
283 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800284 if (nowVisible != reportedVisible) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700285 if (DEBUG_VISIBILITY) Slog.v(TAG,
286 "Visibility changed in " + this + ": vis=" + nowVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800287 reportedVisible = nowVisible;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800288 if (controller != null) {
289 if (nowVisible) {
290 controller.reportWindowsVisible();
291 } else {
292 controller.reportWindowsGone();
293 }
294 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800295 }
296 }
297
Wale Ogunwale89973222017-04-23 18:39:45 -0700298 boolean isClientHidden() {
299 return mClientHidden;
300 }
301
302 void setClientHidden(boolean hideClient) {
303 if (mClientHidden == hideClient || (hideClient && mDeferHidingClient)) {
304 return;
305 }
306 mClientHidden = hideClient;
307 sendAppVisibilityToClients();
308 }
309
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700310 boolean setVisibility(WindowManager.LayoutParams lp,
311 boolean visible, int transit, boolean performLayout, boolean isVoiceInteraction) {
312
313 boolean delayed = false;
314 inPendingTransaction = false;
Wale Ogunwale9e4721f2017-05-23 19:37:30 -0700315 // Reset the state of mHiddenSetFromTransferredStartingWindow since visibility is actually
316 // been set by the app now.
317 mHiddenSetFromTransferredStartingWindow = false;
Wale Ogunwale89973222017-04-23 18:39:45 -0700318 setClientHidden(!visible);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700319
320 // Allow for state changes and animation to be applied if:
321 // * token is transitioning visibility state
322 // * or the token was marked as hidden and is exiting before we had a chance to play the
323 // transition animation
324 // * or this is an opening app and windows are being replaced.
325 boolean visibilityChanged = false;
326 if (hidden == visible || (hidden && mIsExiting) || (visible && waitingForReplacement())) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700327 final AccessibilityController accessibilityController = mService.mAccessibilityController;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700328 boolean changed = false;
329 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
330 "Changing app " + this + " hidden=" + hidden + " performLayout=" + performLayout);
331
332 boolean runningAppAnimation = false;
333
Jorim Jaggi4d1835d2017-08-31 17:28:27 +0200334 if (mAppAnimator.animation == AppWindowAnimator.sDummyAnimation) {
335 mAppAnimator.setNullAnimation();
336 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700337 if (transit != AppTransition.TRANSIT_UNSET) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700338 if (mService.applyAnimationLocked(this, lp, transit, visible, isVoiceInteraction)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700339 delayed = runningAppAnimation = true;
340 }
341 final WindowState window = findMainWindow();
342 //TODO (multidisplay): Magnification is supported only for the default display.
343 if (window != null && accessibilityController != null
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700344 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700345 accessibilityController.onAppWindowTransitionLocked(window, transit);
346 }
347 changed = true;
348 }
349
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700350 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700351 for (int i = 0; i < windowsCount; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700352 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700353 changed |= win.onAppVisibilityChanged(visible, runningAppAnimation);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700354 }
355
356 hidden = hiddenRequested = !visible;
357 visibilityChanged = true;
358 if (!visible) {
359 stopFreezingScreen(true, true);
360 } else {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700361 // If we are being set visible, and the starting window is not yet displayed,
362 // then make sure it doesn't get displayed.
363 if (startingWindow != null && !startingWindow.isDrawnLw()) {
364 startingWindow.mPolicyVisibility = false;
365 startingWindow.mPolicyVisibilityAfterAnim = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700366 }
Jorim Jaggi38d44ec2017-06-14 16:04:59 -0700367
368 // We are becoming visible, so better freeze the screen with the windows that are
369 // getting visible so we also wait for them.
370 forAllWindows(mService::makeWindowFreezingScreenIfNeededLocked, true);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700371 }
372
373 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setVisibility: " + this
374 + ": hidden=" + hidden + " hiddenRequested=" + hiddenRequested);
375
376 if (changed) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700377 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700378 if (performLayout) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700379 mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700380 false /*updateInputWindows*/);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700381 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700382 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700383 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700384 }
385 }
386
387 if (mAppAnimator.animation != null) {
388 delayed = true;
389 }
390
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700391 for (int i = mChildren.size() - 1; i >= 0 && !delayed; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700392 if ((mChildren.get(i)).isWindowAnimationSet()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700393 delayed = true;
394 }
395 }
396
397 if (visibilityChanged) {
398 if (visible && !delayed) {
399 // The token was made immediately visible, there will be no entrance animation.
400 // We need to inform the client the enter animation was finished.
401 mEnteringAnimation = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700402 mService.mActivityManagerAppTransitionNotifier.onAppTransitionFinishedLocked(token);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700403 }
Robert Carr61b81112017-07-17 18:08:15 -0700404
Robert Carre7cc44d2017-03-20 19:04:30 -0700405 // If we are hidden but there is no delay needed we immediately
406 // apply the Surface transaction so that the ActivityManager
Robert Carr61b81112017-07-17 18:08:15 -0700407 // can have some guarantee on the Surface state following
408 // setting the visibility. This captures cases like dismissing
409 // the docked or pinned stack where there is no app transition.
410 //
411 // In the case of a "Null" animation, there will be
412 // no animation but there will still be a transition set.
413 // We still need to delay hiding the surface such that it
414 // can be synchronized with showing the next surface in the transition.
415 if (hidden && !delayed && !mService.mAppTransition.isTransitionSet()) {
Robert Carr6914f082017-03-20 19:04:30 -0700416 SurfaceControl.openTransaction();
417 for (int i = mChildren.size() - 1; i >= 0; i--) {
418 mChildren.get(i).mWinAnimator.hide("immediately hidden");
419 }
420 SurfaceControl.closeTransaction();
421 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700422
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700423 if (!mService.mClosingApps.contains(this) && !mService.mOpeningApps.contains(this)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700424 // The token is not closing nor opening, so even if there is an animation set, that
425 // doesn't mean that it goes through the normal app transition cycle so we have
426 // to inform the docked controller about visibility change.
Andrii Kulian1e32e022016-09-16 15:29:34 -0700427 // TODO(multi-display): notify docked divider on all displays where visibility was
428 // affected.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700429 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700430 .notifyAppVisibilityChanged();
Jorim Jaggi8b702ed2017-01-20 16:59:03 +0100431 mService.mTaskSnapshotController.notifyAppVisibilityChanged(this, visible);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700432 }
433 }
434
435 return delayed;
436 }
437
Jorim Jaggi87fdbcb2017-08-17 13:41:11 +0200438 /**
439 * @return The to top most child window for which {@link LayoutParams#isFullscreen()} returns
440 * true.
441 */
442 WindowState getTopFullscreenWindow() {
443 for (int i = mChildren.size() - 1; i >= 0; i--) {
444 final WindowState win = mChildren.get(i);
445 if (win != null && win.mAttrs.isFullscreen()) {
446 return win;
447 }
448 }
449 return null;
450 }
451
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800452 WindowState findMainWindow() {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700453 WindowState candidate = null;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700454 int j = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800455 while (j > 0) {
456 j--;
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700457 final WindowState win = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700458 final int type = win.mAttrs.type;
459 // No need to loop through child window as base application and starting types can't be
460 // child windows.
461 if (type == TYPE_BASE_APPLICATION || type == TYPE_APPLICATION_STARTING) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700462 // In cases where there are multiple windows, we prefer the non-exiting window. This
Sungsoo Lim0d3d1f82015-12-02 14:47:59 +0900463 // happens for example when replacing windows during an activity relaunch. When
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700464 // constructing the animation, we want the new window, not the exiting one.
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800465 if (win.mAnimatingExit) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700466 candidate = win;
467 } else {
468 return win;
469 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800470 }
471 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700472 return candidate;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800473 }
474
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800475 boolean windowsAreFocusable() {
Wale Ogunwale3382ab12017-07-27 08:55:03 -0700476 return getWindowConfiguration().canReceiveKeys() || mAlwaysFocusable;
Wale Ogunwaled045c822015-12-02 09:14:28 -0800477 }
478
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800479 AppWindowContainerController getController() {
480 final WindowContainerController controller = super.getController();
481 return controller != null ? (AppWindowContainerController) controller : null;
482 }
483
Wale Ogunwale571771c2016-08-26 13:18:50 -0700484 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -0700485 boolean isVisible() {
Wale Ogunwalee471be62016-10-03 07:53:55 -0700486 // If the app token isn't hidden then it is considered visible and there is no need to check
487 // its children windows to see if they are visible.
488 return !hidden;
Wale Ogunwale44f21802016-09-02 12:49:48 -0700489 }
490
491 @Override
Wale Ogunwalee287e192017-04-21 09:30:12 -0700492 void removeImmediately() {
493 onRemovedFromDisplay();
494 super.removeImmediately();
495 }
496
497 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -0700498 void removeIfPossible() {
Craig Mautnere3119b72015-01-20 15:02:36 -0800499 mIsExiting = false;
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800500 removeAllWindowsIfPossible();
Bryce Lee6d410262017-02-28 15:30:17 -0800501 removeImmediately();
Craig Mautnere3119b72015-01-20 15:02:36 -0800502 }
503
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700504 @Override
505 boolean checkCompleteDeferredRemoval() {
506 if (mIsExiting) {
507 removeIfPossible();
508 }
509 return super.checkCompleteDeferredRemoval();
510 }
511
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700512 void onRemovedFromDisplay() {
Wale Ogunwalee287e192017-04-21 09:30:12 -0700513 if (mRemovingFromDisplay) {
514 return;
515 }
516 mRemovingFromDisplay = true;
517
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700518 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app token: " + this);
519
Wale Ogunwale72919d22016-12-08 18:58:50 -0800520 boolean delayed = setVisibility(null, false, TRANSIT_UNSET, true, mVoiceInteraction);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700521
522 mService.mOpeningApps.remove(this);
Jorim Jaggi45ca0542017-05-30 16:16:01 -0700523 mService.mUnknownAppVisibilityController.appRemovedOrHidden(this);
Jorim Jaggi10abe2f2017-01-03 16:44:46 +0100524 mService.mTaskSnapshotController.onAppRemoved(this);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700525 waitingToShow = false;
526 if (mService.mClosingApps.contains(this)) {
527 delayed = true;
528 } else if (mService.mAppTransition.isTransitionSet()) {
529 mService.mClosingApps.add(this);
530 delayed = true;
531 }
532
533 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app " + this + " delayed=" + delayed
534 + " animation=" + mAppAnimator.animation + " animating=" + mAppAnimator.animating);
535
536 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM, "removeAppToken: "
537 + this + " delayed=" + delayed + " Callers=" + Debug.getCallers(4));
538
Jorim Jaggi19be6052017-08-03 18:33:43 +0200539 if (startingData != null && getController() != null) {
540 getController().removeStartingWindow();
541 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800542
Winson Chung87e5d552017-04-05 11:49:38 -0700543 // If this window was animating, then we need to ensure that the app transition notifies
544 // that animations have completed in WMS.handleAnimatingStoppedAndTransitionLocked(), so
545 // add to that list now
546 if (mAppAnimator.animating) {
547 mService.mNoAnimationNotifyOnTransitionFinished.add(token);
548 }
549
Wale Ogunwalee287e192017-04-21 09:30:12 -0700550 final TaskStack stack = getStack();
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700551 if (delayed && !isEmpty()) {
552 // set the token aside because it has an active animation to be finished
553 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM,
554 "removeAppToken make exiting: " + this);
Wale Ogunwalee287e192017-04-21 09:30:12 -0700555 if (stack != null) {
556 stack.mExitingAppTokens.add(this);
557 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700558 mIsExiting = true;
559 } else {
560 // Make sure there is no animation running on this token, so any windows associated
561 // with it will be removed as soon as their animations are complete
562 mAppAnimator.clearAnimation();
563 mAppAnimator.animating = false;
Wale Ogunwale3106ae012017-05-16 08:56:37 -0700564 if (stack != null) {
565 stack.mExitingAppTokens.remove(this);
566 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700567 removeIfPossible();
568 }
569
570 removed = true;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700571 stopFreezingScreen(true, true);
Bryce Lee6d410262017-02-28 15:30:17 -0800572
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700573 if (mService.mFocusedApp == this) {
574 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "Removing focused app token:" + this);
575 mService.mFocusedApp = null;
576 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
577 mService.mInputMonitor.setFocusedAppLw(null);
578 }
579
580 if (!delayed) {
581 updateReportedVisibilityLocked();
582 }
Wale Ogunwalee287e192017-04-21 09:30:12 -0700583
584 mRemovingFromDisplay = false;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700585 }
586
Chong Zhange05bcb12016-07-26 17:47:29 -0700587 void clearAnimatingFlags() {
Chong Zhangb0d26702016-08-12 16:03:29 -0700588 boolean wallpaperMightChange = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700589 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700590 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700591 wallpaperMightChange |= win.clearAnimatingFlags();
Chong Zhange05bcb12016-07-26 17:47:29 -0700592 }
Chong Zhangb0d26702016-08-12 16:03:29 -0700593 if (wallpaperMightChange) {
594 requestUpdateWallpaperIfNeeded();
595 }
Chong Zhange05bcb12016-07-26 17:47:29 -0700596 }
597
Robert Carre12aece2016-02-02 22:43:27 -0800598 void destroySurfaces() {
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700599 destroySurfaces(false /*cleanupOnResume*/);
600 }
601
602 /**
603 * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure
604 * the client has finished with them.
605 *
606 * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If
607 * set to true, destroy only surfaces of removed windows, and clear relevant flags of the
608 * others so that they are ready to be reused. If set to false (common case), destroy all
609 * surfaces that's eligible, if the app is already stopped.
610 */
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700611 private void destroySurfaces(boolean cleanupOnResume) {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700612 boolean destroyedSomething = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700613 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700614 final WindowState win = mChildren.get(i);
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700615 destroyedSomething |= win.destroySurface(cleanupOnResume, mAppStopped);
Robert Carre12aece2016-02-02 22:43:27 -0800616 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700617 if (destroyedSomething) {
618 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700619 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Robert Carre12aece2016-02-02 22:43:27 -0800620 }
621 }
622
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800623 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700624 * Notify that the app is now resumed, and it was not stopped before, perform a clean
625 * up of the surfaces
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800626 */
Jorim Jaggibae01b12017-04-11 16:29:10 -0700627 void notifyAppResumed(boolean wasStopped) {
Chong Zhangad24f962016-08-25 12:12:33 -0700628 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped
Jorim Jaggibae01b12017-04-11 16:29:10 -0700629 + " " + this);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700630 mAppStopped = false;
chaviwd3bf08d2017-08-01 17:24:59 -0700631 // Allow the window to turn the screen on once the app is resumed again.
632 setCanTurnScreenOn(true);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700633 if (!wasStopped) {
634 destroySurfaces(true /*cleanupOnResume*/);
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800635 }
Robert Carre12aece2016-02-02 22:43:27 -0800636 }
637
Chong Zhangbef461f2015-10-27 11:38:24 -0700638 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700639 * Notify that the app has stopped, and it is okay to destroy any surfaces which were
640 * keeping alive in case they were still being used.
641 */
642 void notifyAppStopped() {
643 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this);
644 mAppStopped = true;
645 destroySurfaces();
646 // Remove any starting window that was added for this app if they are still around.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800647 if (getController() != null) {
648 getController().removeStartingWindow();
649 }
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700650 }
651
Chong Zhang92147042016-05-09 12:47:11 -0700652 void clearAllDrawn() {
653 allDrawn = false;
654 deferClearAllDrawn = false;
Chong Zhangbef461f2015-10-27 11:38:24 -0700655 }
656
Bryce Lee6d410262017-02-28 15:30:17 -0800657 Task getTask() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800658 return (Task) getParent();
Bryce Lee6d410262017-02-28 15:30:17 -0800659 }
660
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800661 TaskStack getStack() {
662 final Task task = getTask();
663 if (task != null) {
664 return task.mStack;
665 } else {
666 return null;
667 }
668 }
669
Bryce Lee6d410262017-02-28 15:30:17 -0800670 @Override
671 void onParentSet() {
672 super.onParentSet();
673
Robert Carred3e83b2017-04-21 13:26:55 -0700674 final Task task = getTask();
675
Bryce Lee6d410262017-02-28 15:30:17 -0800676 // When the associated task is {@code null}, the {@link AppWindowToken} can no longer
677 // access visual elements like the {@link DisplayContent}. We must remove any associations
678 // such as animations.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800679 if (!mReparenting) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800680 if (task == null) {
681 // It is possible we have been marked as a closing app earlier. We must remove ourselves
682 // from this list so we do not participate in any future animations.
683 mService.mClosingApps.remove(this);
Robert Carred3e83b2017-04-21 13:26:55 -0700684 } else if (mLastParent != null && mLastParent.mStack != null) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800685 task.mStack.mExitingAppTokens.remove(this);
686 }
Bryce Lee6d410262017-02-28 15:30:17 -0800687 }
Robert Carred3e83b2017-04-21 13:26:55 -0700688 mLastParent = task;
Bryce Lee6d410262017-02-28 15:30:17 -0800689 }
690
Wale Ogunwalefa854eb2016-09-20 13:43:52 -0700691 void postWindowRemoveStartingWindowCleanup(WindowState win) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700692 // TODO: Something smells about the code below...Is there a better way?
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700693 if (startingWindow == win) {
694 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800695 if (getController() != null) {
696 getController().removeStartingWindow();
697 }
Wale Ogunwale6c459212017-05-17 08:56:03 -0700698 } else if (mChildren.size() == 0) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700699 // If this is the last window and we had requested a starting transition window,
700 // well there is no point now.
Jorim Jaggi02886a82016-12-06 09:10:06 -0800701 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingData");
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700702 startingData = null;
Wale Ogunwale6c459212017-05-17 08:56:03 -0700703 if (mHiddenSetFromTransferredStartingWindow) {
704 // We set the hidden state to false for the token from a transferred starting window.
705 // We now reset it back to true since the starting window was the last window in the
706 // token.
707 hidden = true;
708 }
Jorim Jaggi829b9cd2017-01-23 16:20:53 +0100709 } else if (mChildren.size() == 1 && startingSurface != null && !isRelaunching()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700710 // If this is the last window except for a starting transition window,
711 // we need to get rid of the starting transition.
Jorim Jaggie4b0f282017-05-17 15:10:29 +0200712 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Last window, removing starting window "
713 + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800714 if (getController() != null) {
715 getController().removeStartingWindow();
716 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700717 }
718 }
719
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700720 void removeDeadWindows() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700721 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700722 WindowState win = mChildren.get(winNdx);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800723 if (win.mAppDied) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700724 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700725 "removeDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800726 // Set mDestroying, we don't want any animation or delayed removal here.
727 win.mDestroying = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700728 // Also removes child windows.
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700729 win.removeIfPossible();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800730 }
731 }
732 }
733
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700734 boolean hasWindowsAlive() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700735 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700736 // No need to loop through child windows as the answer should be the same as that of the
737 // parent window.
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700738 if (!(mChildren.get(i)).mAppDied) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700739 return true;
740 }
741 }
742 return false;
743 }
744
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700745 void setWillReplaceWindows(boolean animate) {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700746 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
747 "Marking app token " + this + " with replacing windows.");
Robert Carra1eb4392015-12-10 12:43:51 -0800748
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700749 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700750 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700751 w.setWillReplaceWindow(animate);
Robert Carra1eb4392015-12-10 12:43:51 -0800752 }
753 if (animate) {
754 // Set-up dummy animation so we can start treating windows associated with this
755 // token like they are in transition before the new app window is ready for us to
756 // run the real transition animation.
757 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700758 "setWillReplaceWindow() Setting dummy animation on: " + this);
Robert Carra1eb4392015-12-10 12:43:51 -0800759 mAppAnimator.setDummyAnimation();
760 }
761 }
762
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700763 void setWillReplaceChildWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700764 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this
Robert Carr23fa16b2016-01-13 13:19:58 -0800765 + " with replacing child windows.");
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700766 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700767 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700768 w.setWillReplaceChildWindows();
Robert Carr23fa16b2016-01-13 13:19:58 -0800769 }
770 }
771
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700772 void clearWillReplaceWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700773 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
774 "Resetting app token " + this + " of replacing window marks.");
Chong Zhangf596cd52016-01-05 13:42:44 -0800775
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700776 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700777 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700778 w.clearWillReplaceWindow();
Chong Zhangf596cd52016-01-05 13:42:44 -0800779 }
780 }
781
Chong Zhang4d7369a2016-04-25 16:09:14 -0700782 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700783 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700784 final WindowState w = mChildren.get(i);
Chong Zhang4d7369a2016-04-25 16:09:14 -0700785 w.requestUpdateWallpaperIfNeeded();
786 }
787 }
788
Chong Zhangd78ddb42016-03-02 17:01:14 -0800789 boolean isRelaunching() {
790 return mPendingRelaunchCount > 0;
791 }
792
Robert Carr68375192017-06-13 12:41:53 -0700793 boolean shouldFreezeBounds() {
794 final Task task = getTask();
795
796 // For freeform windows, we can't freeze the bounds at the moment because this would make
797 // the resizing unresponsive.
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700798 if (task == null || task.inFreeformWindowingMode()) {
Robert Carr68375192017-06-13 12:41:53 -0700799 return false;
800 }
801
802 // We freeze the bounds while drag resizing to deal with the time between
803 // the divider/drag handle being released, and the handling it's new
804 // configuration. If we are relaunched outside of the drag resizing state,
805 // we need to be careful not to do this.
806 return getTask().isDragResizing();
807 }
808
Chong Zhangd78ddb42016-03-02 17:01:14 -0800809 void startRelaunching() {
Robert Carr68375192017-06-13 12:41:53 -0700810 if (shouldFreezeBounds()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -0800811 freezeBounds();
812 }
Robert Carrd5c7dd62017-03-08 10:39:30 -0800813
814 // In the process of tearing down before relaunching, the app will
815 // try and clean up it's child surfaces. We need to prevent this from
816 // happening, so we sever the children, transfering their ownership
817 // from the client it-self to the parent surface (owned by us).
818 for (int i = mChildren.size() - 1; i >= 0; i--) {
819 final WindowState w = mChildren.get(i);
820 w.mWinAnimator.detachChildren();
821 }
822
Chong Zhangd78ddb42016-03-02 17:01:14 -0800823 mPendingRelaunchCount++;
824 }
825
826 void finishRelaunching() {
Robert Carr68375192017-06-13 12:41:53 -0700827 unfreezeBounds();
828
Chong Zhangd78ddb42016-03-02 17:01:14 -0800829 if (mPendingRelaunchCount > 0) {
830 mPendingRelaunchCount--;
Bryce Lee081554b2017-05-25 07:52:12 -0700831 } else {
832 // Update keyguard flags upon finishing relaunch.
833 checkKeyguardFlagsChanged();
Chong Zhangd78ddb42016-03-02 17:01:14 -0800834 }
835 }
836
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700837 void clearRelaunching() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700838 if (mPendingRelaunchCount == 0) {
839 return;
840 }
Robert Carr68375192017-06-13 12:41:53 -0700841 unfreezeBounds();
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700842 mPendingRelaunchCount = 0;
843 }
844
Wale Ogunwale07bcab72016-10-14 15:30:09 -0700845 /**
846 * Returns true if the new child window we are adding to this token is considered greater than
847 * the existing child window in this token in terms of z-order.
848 */
849 @Override
850 protected boolean isFirstChildWindowGreaterThanSecond(WindowState newWindow,
851 WindowState existingWindow) {
852 final int type1 = newWindow.mAttrs.type;
853 final int type2 = existingWindow.mAttrs.type;
854
855 // Base application windows should be z-ordered BELOW all other windows in the app token.
856 if (type1 == TYPE_BASE_APPLICATION && type2 != TYPE_BASE_APPLICATION) {
857 return false;
858 } else if (type1 != TYPE_BASE_APPLICATION && type2 == TYPE_BASE_APPLICATION) {
859 return true;
860 }
861
862 // Starting windows should be z-ordered ABOVE all other windows in the app token.
863 if (type1 == TYPE_APPLICATION_STARTING && type2 != TYPE_APPLICATION_STARTING) {
864 return true;
865 } else if (type1 != TYPE_APPLICATION_STARTING && type2 == TYPE_APPLICATION_STARTING) {
866 return false;
867 }
868
869 // Otherwise the new window is greater than the existing window.
870 return true;
871 }
872
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700873 @Override
Robert Carra1eb4392015-12-10 12:43:51 -0800874 void addWindow(WindowState w) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700875 super.addWindow(w);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700876
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700877 boolean gotReplacementWindow = false;
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 candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700880 gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w);
881 }
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700882
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700883 // if we got a replacement window, reset the timeout to give drawing more time
884 if (gotReplacementWindow) {
885 mService.scheduleWindowReplacementTimeouts(this);
Robert Carra1eb4392015-12-10 12:43:51 -0800886 }
Jorim Jaggife762342016-10-13 14:33:27 +0200887 checkKeyguardFlagsChanged();
888 }
889
890 @Override
891 void removeChild(WindowState child) {
892 super.removeChild(child);
893 checkKeyguardFlagsChanged();
Robert Carra1eb4392015-12-10 12:43:51 -0800894 }
895
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700896 private boolean waitingForReplacement() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700897 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700898 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700899 if (candidate.waitingForReplacement()) {
Robert Carra1eb4392015-12-10 12:43:51 -0800900 return true;
901 }
902 }
903 return false;
904 }
905
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700906 void onWindowReplacementTimeout() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700907 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700908 (mChildren.get(i)).onWindowReplacementTimeout();
Robert Carra1eb4392015-12-10 12:43:51 -0800909 }
910 }
911
Winson Chung30480042017-01-26 10:55:34 -0800912 void reparent(Task task, int position) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800913 final Task currentTask = getTask();
914 if (task == currentTask) {
Winson Chung30480042017-01-26 10:55:34 -0800915 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800916 "window token=" + this + " already child of task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -0800917 }
Bryce Lee6d410262017-02-28 15:30:17 -0800918
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800919 if (currentTask.mStack != task.mStack) {
Bryce Lee6d410262017-02-28 15:30:17 -0800920 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800921 "window token=" + this + " current task=" + currentTask
Bryce Lee6d410262017-02-28 15:30:17 -0800922 + " belongs to a different stack than " + task);
923 }
924
Winson Chung30480042017-01-26 10:55:34 -0800925 if (DEBUG_ADD_REMOVE) Slog.i(TAG, "reParentWindowToken: removing window token=" + this
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800926 + " from task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -0800927 final DisplayContent prevDisplayContent = getDisplayContent();
928
Bryce Lee6d410262017-02-28 15:30:17 -0800929 mReparenting = true;
930
Winson Chung30480042017-01-26 10:55:34 -0800931 getParent().removeChild(this);
932 task.addChild(this, position);
933
Bryce Lee6d410262017-02-28 15:30:17 -0800934 mReparenting = false;
935
Winson Chung30480042017-01-26 10:55:34 -0800936 // Relayout display(s).
937 final DisplayContent displayContent = task.getDisplayContent();
938 displayContent.setLayoutNeeded();
939 if (prevDisplayContent != displayContent) {
940 onDisplayChanged(displayContent);
941 prevDisplayContent.setLayoutNeeded();
942 }
943 }
944
Jorim Jaggi0429f352015-12-22 16:29:16 +0100945 /**
946 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
947 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
948 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
949 * with a queue.
950 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800951 private void freezeBounds() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800952 final Task task = getTask();
953 mFrozenBounds.offer(new Rect(task.mPreparedFrozenBounds));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700954
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800955 if (task.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) {
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700956 // We didn't call prepareFreezingBounds on the task, so use the current value.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800957 mFrozenMergedConfig.offer(new Configuration(task.getConfiguration()));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700958 } else {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800959 mFrozenMergedConfig.offer(new Configuration(task.mPreparedFrozenMergedConfig));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700960 }
Andrii Kulianb10330d2016-09-16 13:51:46 -0700961 // Calling unset() to make it equal to Configuration.EMPTY.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800962 task.mPreparedFrozenMergedConfig.unset();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100963 }
964
965 /**
966 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
967 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800968 private void unfreezeBounds() {
Robert Carr68375192017-06-13 12:41:53 -0700969 if (mFrozenBounds.isEmpty()) {
970 return;
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700971 }
Robert Carr68375192017-06-13 12:41:53 -0700972 mFrozenBounds.remove();
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700973 if (!mFrozenMergedConfig.isEmpty()) {
974 mFrozenMergedConfig.remove();
975 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700976 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700977 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700978 win.onUnfreezeBounds();
Jorim Jaggi4846ee32016-01-07 17:39:12 +0100979 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700980 mService.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100981 }
982
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700983 void setAppLayoutChanges(int changes, String reason) {
984 if (!mChildren.isEmpty()) {
985 final DisplayContent dc = getDisplayContent();
986 dc.pendingLayoutChanges |= changes;
987 if (DEBUG_LAYOUT_REPEATS) {
988 mService.mWindowPlacerLocked.debugLayoutRepeats(reason, dc.pendingLayoutChanges);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700989 }
990 }
991 }
992
993 void removeReplacedWindowIfNeeded(WindowState replacement) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700994 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700995 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700996 if (win.removeReplacedWindowIfNeeded(replacement)) {
997 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700998 }
999 }
1000 }
1001
1002 void startFreezingScreen() {
1003 if (DEBUG_ORIENTATION) logWithStack(TAG, "Set freezing of " + appToken + ": hidden="
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001004 + hidden + " freezing=" + mAppAnimator.freezingScreen + " hiddenRequested="
1005 + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001006 if (!hiddenRequested) {
1007 if (!mAppAnimator.freezingScreen) {
1008 mAppAnimator.freezingScreen = true;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001009 mService.registerAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001010 mAppAnimator.lastFreezeDuration = 0;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001011 mService.mAppsFreezingScreen++;
1012 if (mService.mAppsFreezingScreen == 1) {
Bryce Lee8f853582017-06-05 17:25:59 -07001013 mService.startFreezingDisplayLocked(false, 0, 0, getDisplayContent());
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001014 mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT);
1015 mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001016 }
1017 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001018 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001019 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001020 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001021 w.onStartFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001022 }
1023 }
1024 }
1025
1026 void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) {
1027 if (!mAppAnimator.freezingScreen) {
1028 return;
1029 }
1030 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + this + " force=" + force);
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001031 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001032 boolean unfrozeWindows = false;
1033 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001034 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001035 unfrozeWindows |= w.onStopFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001036 }
1037 if (force || unfrozeWindows) {
1038 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this);
1039 mAppAnimator.freezingScreen = false;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001040 mService.unregisterAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001041 mAppAnimator.lastFreezeDuration =
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001042 (int)(SystemClock.elapsedRealtime() - mService.mDisplayFreezeTime);
1043 mService.mAppsFreezingScreen--;
1044 mService.mLastFinishedFreezeSource = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001045 }
1046 if (unfreezeSurfaceNow) {
1047 if (unfrozeWindows) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001048 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001049 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001050 mService.stopFreezingDisplayLocked();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001051 }
1052 }
1053
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001054 @Override
1055 public void onAppFreezeTimeout() {
1056 Slog.w(TAG_WM, "Force clearing freeze: " + this);
1057 stopFreezingScreen(true, true);
1058 }
1059
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001060 boolean transferStartingWindow(IBinder transferFrom) {
Wale Ogunwale02319a62016-09-26 15:21:22 -07001061 final AppWindowToken fromToken = getDisplayContent().getAppWindowToken(transferFrom);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001062 if (fromToken == null) {
1063 return false;
1064 }
1065
1066 final WindowState tStartingWindow = fromToken.startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001067 if (tStartingWindow != null && fromToken.startingSurface != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001068 // In this case, the starting icon has already been displayed, so start
1069 // letting windows get shown immediately without any more transitions.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001070 mService.mSkipAppTransitionAnimation = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001071
1072 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow
1073 + " from " + fromToken + " to " + this);
1074
1075 final long origId = Binder.clearCallingIdentity();
Peter Visontay3556a3b2017-11-01 17:23:17 +00001076 try {
1077 // Transfer the starting window over to the new token.
1078 startingData = fromToken.startingData;
1079 startingSurface = fromToken.startingSurface;
1080 startingDisplayed = fromToken.startingDisplayed;
1081 fromToken.startingDisplayed = false;
1082 startingWindow = tStartingWindow;
1083 reportedVisible = fromToken.reportedVisible;
1084 fromToken.startingData = null;
1085 fromToken.startingSurface = null;
1086 fromToken.startingWindow = null;
1087 fromToken.startingMoved = true;
1088 tStartingWindow.mToken = this;
1089 tStartingWindow.mAppToken = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001090
Peter Visontay3556a3b2017-11-01 17:23:17 +00001091 if (DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1092 "Removing starting " + tStartingWindow + " from " + fromToken);
1093 fromToken.removeChild(tStartingWindow);
1094 fromToken.postWindowRemoveStartingWindowCleanup(tStartingWindow);
1095 fromToken.mHiddenSetFromTransferredStartingWindow = false;
1096 addWindow(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001097
Peter Visontay3556a3b2017-11-01 17:23:17 +00001098 // Propagate other interesting state between the tokens. If the old token is displayed,
1099 // we should immediately force the new one to be displayed. If it is animating, we need
1100 // to move that animation to the new one.
1101 if (fromToken.allDrawn) {
1102 allDrawn = true;
1103 deferClearAllDrawn = fromToken.deferClearAllDrawn;
1104 }
1105 if (fromToken.firstWindowDrawn) {
1106 firstWindowDrawn = true;
1107 }
1108 if (!fromToken.hidden) {
1109 hidden = false;
1110 hiddenRequested = false;
1111 mHiddenSetFromTransferredStartingWindow = true;
1112 }
1113 setClientHidden(fromToken.mClientHidden);
1114 fromToken.mAppAnimator.transferCurrentAnimation(
1115 mAppAnimator, tStartingWindow.mWinAnimator);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001116
Peter Visontay3556a3b2017-11-01 17:23:17 +00001117 mService.updateFocusedWindowLocked(
1118 UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/);
1119 getDisplayContent().setLayoutNeeded();
1120 mService.mWindowPlacerLocked.performSurfacePlacement();
1121 } finally {
1122 Binder.restoreCallingIdentity(origId);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001123 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001124 return true;
1125 } else if (fromToken.startingData != null) {
1126 // The previous app was getting ready to show a
1127 // starting window, but hasn't yet done so. Steal it!
1128 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1129 "Moving pending starting from " + fromToken + " to " + this);
1130 startingData = fromToken.startingData;
1131 fromToken.startingData = null;
1132 fromToken.startingMoved = true;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001133 if (getController() != null) {
1134 getController().scheduleAddStartingWindow();
1135 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001136 return true;
1137 }
1138
1139 final AppWindowAnimator tAppAnimator = fromToken.mAppAnimator;
1140 final AppWindowAnimator wAppAnimator = mAppAnimator;
1141 if (tAppAnimator.thumbnail != null) {
1142 // The old token is animating with a thumbnail, transfer that to the new token.
1143 if (wAppAnimator.thumbnail != null) {
1144 wAppAnimator.thumbnail.destroy();
1145 }
1146 wAppAnimator.thumbnail = tAppAnimator.thumbnail;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001147 wAppAnimator.thumbnailAnimation = tAppAnimator.thumbnailAnimation;
1148 tAppAnimator.thumbnail = null;
1149 }
1150 return false;
1151 }
1152
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001153 boolean isLastWindow(WindowState win) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001154 return mChildren.size() == 1 && mChildren.get(0) == win;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001155 }
1156
1157 void setAllAppWinAnimators() {
1158 final ArrayList<WindowStateAnimator> allAppWinAnimators = mAppAnimator.mAllAppWinAnimators;
1159 allAppWinAnimators.clear();
1160
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001161 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001162 for (int j = 0; j < windowsCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001163 (mChildren.get(j)).addWinAnimatorToList(allAppWinAnimators);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001164 }
1165 }
1166
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001167 @Override
1168 void onAppTransitionDone() {
1169 sendingToBottom = false;
1170 }
1171
Wale Ogunwale51362492016-09-08 17:49:17 -07001172 /**
1173 * We override because this class doesn't want its children affecting its reported orientation
1174 * in anyway.
1175 */
1176 @Override
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001177 int getOrientation(int candidate) {
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001178 if (candidate == SCREEN_ORIENTATION_BEHIND) {
1179 // Allow app to specify orientation regardless of its visibility state if the current
1180 // candidate want us to use orientation behind. I.e. the visible app on-top of this one
1181 // wants us to use the orientation of the app behind it.
1182 return mOrientation;
1183 }
1184
Bryce Lee61fbcbc2017-03-10 14:14:03 -08001185 // The {@link AppWindowToken} should only specify an orientation when it is not closing or
1186 // going to the bottom. Allowing closing {@link AppWindowToken} to participate can lead to
1187 // an Activity in another task being started in the wrong orientation during the transition.
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001188 if (!(sendingToBottom || mService.mClosingApps.contains(this))
Bryce Lee00d586d2017-07-28 20:48:43 -07001189 && (isVisible() || mService.mOpeningApps.contains(this) || isOnTop())) {
Bryce Leea163b762017-01-24 11:05:01 -08001190 return mOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001191 }
Bryce Leea163b762017-01-24 11:05:01 -08001192
1193 return SCREEN_ORIENTATION_UNSET;
Wale Ogunwale51362492016-09-08 17:49:17 -07001194 }
1195
Wale Ogunwaleb198b742016-12-01 08:44:09 -08001196 /** Returns the app's preferred orientation regardless of its currently visibility state. */
1197 int getOrientationIgnoreVisibility() {
1198 return mOrientation;
1199 }
1200
Craig Mautnerdbb79912012-03-01 18:59:14 -08001201 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001202 void checkAppWindowsReadyToShow() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001203 if (allDrawn == mAppAnimator.allDrawn) {
1204 return;
1205 }
1206
1207 mAppAnimator.allDrawn = allDrawn;
1208 if (!allDrawn) {
1209 return;
1210 }
1211
1212 // The token has now changed state to having all windows shown... what to do, what to do?
1213 if (mAppAnimator.freezingScreen) {
1214 mAppAnimator.showAllWindowsLocked();
1215 stopFreezingScreen(false, true);
1216 if (DEBUG_ORIENTATION) Slog.i(TAG,
1217 "Setting mOrientationChangeComplete=true because wtoken " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001218 + " numInteresting=" + mNumInterestingWindows + " numDrawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001219 // This will set mOrientationChangeComplete and cause a pass through layout.
1220 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001221 "checkAppWindowsReadyToShow: freezingScreen");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001222 } else {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001223 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001224
1225 // We can now show all of the drawn windows!
1226 if (!mService.mOpeningApps.contains(this)) {
1227 mService.mAnimator.orAnimating(mAppAnimator.showAllWindowsLocked());
1228 }
1229 }
1230 }
1231
Matthew Ng5d23afa2017-06-21 16:16:24 -07001232 /**
Bryce Leed390deb2017-06-22 13:14:28 -07001233 * Returns whether the drawn window states of this {@link AppWindowToken} has considered every
1234 * child {@link WindowState}. A child is considered if it has been passed into
1235 * {@link #updateDrawnWindowStates(WindowState)} after being added. This is used to determine
1236 * whether states, such as {@code allDrawn}, can be set, which relies on state variables such as
1237 * {@code mNumInterestingWindows}, which depend on all {@link WindowState}s being considered.
1238 *
1239 * @return {@code true} If all children have been considered, {@code false}.
1240 */
1241 private boolean allDrawnStatesConsidered() {
Bryce Lee6311c4b2017-07-06 14:09:29 -07001242 for (int i = mChildren.size() - 1; i >= 0; --i) {
1243 final WindowState child = mChildren.get(i);
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001244 if (child.mightAffectAllDrawn() && !child.getDrawnStateEvaluated()) {
Bryce Leed390deb2017-06-22 13:14:28 -07001245 return false;
1246 }
1247 }
1248 return true;
1249 }
1250
1251 /**
Matthew Ng5d23afa2017-06-21 16:16:24 -07001252 * Determines if the token has finished drawing. This should only be called from
1253 * {@link DisplayContent#applySurfaceChangesTransaction}
1254 */
Matthew Ng498c71d2017-04-18 13:55:45 -07001255 void updateAllDrawn() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001256 if (!allDrawn) {
Matthew Ng498c71d2017-04-18 13:55:45 -07001257 // Number of drawn windows can be less when a window is being relaunched, wait for
Bryce Leed390deb2017-06-22 13:14:28 -07001258 // all windows to be launched and drawn for this token be considered all drawn.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001259 final int numInteresting = mNumInterestingWindows;
Bryce Leed390deb2017-06-22 13:14:28 -07001260
1261 // We must make sure that all present children have been considered (determined by
1262 // {@link #allDrawnStatesConsidered}) before evaluating whether everything has been
1263 // drawn.
1264 if (numInteresting > 0 && allDrawnStatesConsidered()
1265 && mNumDrawnWindows >= numInteresting && !isRelaunching()) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001266 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawn: " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001267 + " interesting=" + numInteresting + " drawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001268 allDrawn = true;
1269 // Force an additional layout pass where
1270 // WindowStateAnimator#commitFinishDrawingLocked() will call performShowLocked().
Matthew Ng498c71d2017-04-18 13:55:45 -07001271 if (mDisplayContent != null) {
1272 mDisplayContent.setLayoutNeeded();
1273 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001274 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Robert Carrecc06b32017-04-18 14:25:10 -07001275
Winson Chunge7ba6862017-05-24 12:13:33 -07001276 // Notify the pinned stack upon all windows drawn. If there was an animation in
1277 // progress then this signal will resume that animation.
Wale Ogunwale61911492017-10-11 08:50:50 -07001278 final TaskStack pinnedStack = mDisplayContent.getPinnedStack();
Winson Chunge7ba6862017-05-24 12:13:33 -07001279 if (pinnedStack != null) {
1280 pinnedStack.onAllWindowsDrawn();
Robert Carrecc06b32017-04-18 14:25:10 -07001281 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001282 }
1283 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001284 }
1285
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001286 /**
1287 * Updated this app token tracking states for interesting and drawn windows based on the window.
1288 *
1289 * @return Returns true if the input window is considered interesting and drawn while all the
1290 * windows in this app token where not considered drawn as of the last pass.
1291 */
1292 boolean updateDrawnWindowStates(WindowState w) {
Bryce Leed390deb2017-06-22 13:14:28 -07001293 w.setDrawnStateEvaluated(true /*evaluated*/);
1294
Jorim Jaggie4b0f282017-05-17 15:10:29 +02001295 if (DEBUG_STARTING_WINDOW_VERBOSE && w == startingWindow) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001296 Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" + w.isOnScreen()
1297 + " allDrawn=" + allDrawn + " freezingScreen=" + mAppAnimator.freezingScreen);
1298 }
1299
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001300 if (allDrawn && !mAppAnimator.freezingScreen) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001301 return false;
1302 }
1303
1304 if (mLastTransactionSequence != mService.mTransactionSequence) {
1305 mLastTransactionSequence = mService.mTransactionSequence;
1306 mNumInterestingWindows = mNumDrawnWindows = 0;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001307 startingDisplayed = false;
1308 }
1309
1310 final WindowStateAnimator winAnimator = w.mWinAnimator;
1311
1312 boolean isInterestingAndDrawn = false;
1313
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001314 if (!allDrawn && w.mightAffectAllDrawn()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001315 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
1316 Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw()
1317 + ", isAnimationSet=" + winAnimator.isAnimationSet());
1318 if (!w.isDrawnLw()) {
1319 Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController
1320 + " pv=" + w.mPolicyVisibility
1321 + " mDrawState=" + winAnimator.drawStateToString()
1322 + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested
1323 + " a=" + winAnimator.mAnimating);
1324 }
1325 }
1326
1327 if (w != startingWindow) {
1328 if (w.isInteresting()) {
1329 mNumInterestingWindows++;
1330 if (w.isDrawnLw()) {
1331 mNumDrawnWindows++;
1332
1333 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, "tokenMayBeDrawn: "
1334 + this + " w=" + w + " numInteresting=" + mNumInterestingWindows
1335 + " freezingScreen=" + mAppAnimator.freezingScreen
1336 + " mAppFreezing=" + w.mAppFreezing);
1337
1338 isInterestingAndDrawn = true;
1339 }
1340 }
1341 } else if (w.isDrawnLw()) {
Jorim Jaggi3878ca32017-02-02 17:13:05 -08001342 if (getController() != null) {
1343 getController().reportStartingWindowDrawn();
1344 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001345 startingDisplayed = true;
1346 }
1347 }
1348
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001349 return isInterestingAndDrawn;
1350 }
1351
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001352 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001353 void stepAppWindowsAnimation(long currentTime) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001354 mAppAnimator.wasAnimating = mAppAnimator.animating;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001355 if (mAppAnimator.stepAnimationLocked(currentTime)) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001356 mAppAnimator.animating = true;
1357 mService.mAnimator.setAnimating(true);
1358 mService.mAnimator.mAppWindowAnimating = true;
1359 } else if (mAppAnimator.wasAnimating) {
1360 // stopped animating, do one more pass through the layout
Wale Ogunwale1e129a42016-11-21 13:03:47 -08001361 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
1362 DEBUG_LAYOUT_REPEATS ? "appToken " + this + " done" : null);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001363 if (DEBUG_ANIM) Slog.v(TAG, "updateWindowsApps...: done animating " + this);
1364 }
1365 }
1366
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001367 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001368 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001369 // For legacy reasons we process the TaskStack.mExitingAppTokens first in DisplayContent
1370 // before the non-exiting app tokens. So, we skip the exiting app tokens here.
1371 // TODO: Investigate if we need to continue to do this or if we can just process them
1372 // in-order.
1373 if (mIsExiting && !waitingForReplacement()) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001374 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001375 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001376 return forAllWindowsUnchecked(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001377 }
1378
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001379 boolean forAllWindowsUnchecked(ToBooleanFunction<WindowState> callback,
1380 boolean traverseTopToBottom) {
1381 return super.forAllWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001382 }
1383
1384 @Override
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001385 AppWindowToken asAppWindowToken() {
1386 // I am an app window token!
1387 return this;
1388 }
1389
1390 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -07001391 boolean fillsParent() {
1392 return mFillsParent;
1393 }
1394
1395 void setFillsParent(boolean fillsParent) {
1396 mFillsParent = fillsParent;
1397 }
1398
Jorim Jaggife762342016-10-13 14:33:27 +02001399 boolean containsDismissKeyguardWindow() {
Bryce Lee081554b2017-05-25 07:52:12 -07001400 // Window state is transient during relaunch. We are not guaranteed to be frozen during the
1401 // entirety of the relaunch.
1402 if (isRelaunching()) {
1403 return mLastContainsDismissKeyguardWindow;
1404 }
1405
Jorim Jaggife762342016-10-13 14:33:27 +02001406 for (int i = mChildren.size() - 1; i >= 0; i--) {
1407 if ((mChildren.get(i).mAttrs.flags & FLAG_DISMISS_KEYGUARD) != 0) {
1408 return true;
1409 }
1410 }
1411 return false;
1412 }
1413
1414 boolean containsShowWhenLockedWindow() {
Bryce Lee081554b2017-05-25 07:52:12 -07001415 // When we are relaunching, it is possible for us to be unfrozen before our previous
1416 // windows have been added back. Using the cached value ensures that our previous
1417 // showWhenLocked preference is honored until relaunching is complete.
1418 if (isRelaunching()) {
1419 return mLastContainsShowWhenLockedWindow;
1420 }
1421
Jorim Jaggife762342016-10-13 14:33:27 +02001422 for (int i = mChildren.size() - 1; i >= 0; i--) {
1423 if ((mChildren.get(i).mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
1424 return true;
1425 }
1426 }
Bryce Lee081554b2017-05-25 07:52:12 -07001427
Jorim Jaggife762342016-10-13 14:33:27 +02001428 return false;
1429 }
1430
1431 void checkKeyguardFlagsChanged() {
1432 final boolean containsDismissKeyguard = containsDismissKeyguardWindow();
1433 final boolean containsShowWhenLocked = containsShowWhenLockedWindow();
1434 if (containsDismissKeyguard != mLastContainsDismissKeyguardWindow
1435 || containsShowWhenLocked != mLastContainsShowWhenLockedWindow) {
1436 mService.notifyKeyguardFlagsChanged(null /* callback */);
1437 }
1438 mLastContainsDismissKeyguardWindow = containsDismissKeyguard;
1439 mLastContainsShowWhenLockedWindow = containsShowWhenLocked;
1440 }
1441
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001442 WindowState getImeTargetBelowWindow(WindowState w) {
1443 final int index = mChildren.indexOf(w);
1444 if (index > 0) {
1445 final WindowState target = mChildren.get(index - 1);
1446 if (target.canBeImeTarget()) {
1447 return target;
1448 }
1449 }
1450 return null;
1451 }
1452
Winson Chungbe9be7f2017-06-28 10:55:22 -07001453 int getLowestAnimLayer() {
1454 for (int i = 0; i < mChildren.size(); i++) {
1455 final WindowState w = mChildren.get(i);
1456 if (w.mRemoved) {
1457 continue;
1458 }
1459 return w.mWinAnimator.mAnimLayer;
1460 }
1461 return Integer.MAX_VALUE;
1462 }
1463
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001464 WindowState getHighestAnimLayerWindow(WindowState currentTarget) {
1465 WindowState candidate = null;
1466 for (int i = mChildren.indexOf(currentTarget); i >= 0; i--) {
1467 final WindowState w = mChildren.get(i);
1468 if (w.mRemoved) {
1469 continue;
1470 }
1471 if (candidate == null || w.mWinAnimator.mAnimLayer >
1472 candidate.mWinAnimator.mAnimLayer) {
1473 candidate = w;
1474 }
1475 }
1476 return candidate;
1477 }
1478
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001479 /**
1480 * See {@link Activity#setDisablePreviewScreenshots}.
1481 */
1482 void setDisablePreviewScreenshots(boolean disable) {
Wale Ogunwale6c459212017-05-17 08:56:03 -07001483 mDisablePreviewScreenshots = disable;
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001484 }
1485
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001486 /**
chaviwd3bf08d2017-08-01 17:24:59 -07001487 * Sets whether the current launch can turn the screen on. See {@link #canTurnScreenOn()}
1488 */
1489 void setCanTurnScreenOn(boolean canTurnScreenOn) {
1490 mCanTurnScreenOn = canTurnScreenOn;
1491 }
1492
1493 /**
1494 * Indicates whether the current launch can turn the screen on. This is to prevent multiple
1495 * relayouts from turning the screen back on. The screen should only turn on at most
1496 * once per activity resume.
1497 *
1498 * @return true if the screen can be turned on.
1499 */
1500 boolean canTurnScreenOn() {
1501 return mCanTurnScreenOn;
1502 }
1503
1504 /**
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001505 * Retrieves whether we'd like to generate a snapshot that's based solely on the theme. This is
1506 * the case when preview screenshots are disabled {@link #setDisablePreviewScreenshots} or when
1507 * we can't take a snapshot for other reasons, for example, if we have a secure window.
1508 *
1509 * @return True if we need to generate an app theme snapshot, false if we'd like to take a real
1510 * screenshot.
1511 */
1512 boolean shouldUseAppThemeSnapshot() {
Wale Ogunwale6c459212017-05-17 08:56:03 -07001513 return mDisablePreviewScreenshots || forAllWindows(w -> (w.mAttrs.flags & FLAG_SECURE) != 0,
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001514 true /* topToBottom */);
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001515 }
1516
Wale Ogunwale51362492016-09-08 17:49:17 -07001517 @Override
Robert Carrdee1b3f2017-02-27 11:33:33 -08001518 int getAnimLayerAdjustment() {
1519 return mAppAnimator.animLayerAdjustment;
1520 }
1521
1522 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001523 void dump(PrintWriter pw, String prefix) {
1524 super.dump(pw, prefix);
1525 if (appToken != null) {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001526 pw.println(prefix + "app=true mVoiceInteraction=" + mVoiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001527 }
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001528 pw.print(prefix); pw.print("task="); pw.println(getTask());
Wale Ogunwale51362492016-09-08 17:49:17 -07001529 pw.print(prefix); pw.print(" mFillsParent="); pw.print(mFillsParent);
1530 pw.print(" mOrientation="); pw.println(mOrientation);
Wale Ogunwale89973222017-04-23 18:39:45 -07001531 pw.println(prefix + "hiddenRequested=" + hiddenRequested + " mClientHidden=" + mClientHidden
1532 + ((mDeferHidingClient) ? " mDeferHidingClient=" + mDeferHidingClient : "")
1533 + " reportedDrawn=" + reportedDrawn + " reportedVisible=" + reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -07001534 if (paused) {
1535 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001536 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001537 if (mAppStopped) {
1538 pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped);
1539 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001540 if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0
Craig Mautner6fbda632012-07-03 09:26:39 -07001541 || allDrawn || mAppAnimator.allDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001542 pw.print(prefix); pw.print("mNumInterestingWindows=");
1543 pw.print(mNumInterestingWindows);
1544 pw.print(" mNumDrawnWindows="); pw.print(mNumDrawnWindows);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001545 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -07001546 pw.print(" allDrawn="); pw.print(allDrawn);
1547 pw.print(" (animator="); pw.print(mAppAnimator.allDrawn);
1548 pw.println(")");
1549 }
1550 if (inPendingTransaction) {
1551 pw.print(prefix); pw.print("inPendingTransaction=");
1552 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001553 }
Craig Mautner799bc1d2015-01-14 10:33:48 -08001554 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001555 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
1556 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -08001557 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -08001558 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001559 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001560 if (startingWindow != null || startingSurface != null
Wale Ogunwale6c459212017-05-17 08:56:03 -07001561 || startingDisplayed || startingMoved || mHiddenSetFromTransferredStartingWindow) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001562 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001563 pw.print(" startingSurface="); pw.print(startingSurface);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001564 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
Wale Ogunwale6c459212017-05-17 08:56:03 -07001565 pw.print(" startingMoved="); pw.print(startingMoved);
1566 pw.println(" mHiddenSetFromTransferredStartingWindow="
1567 + mHiddenSetFromTransferredStartingWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001568 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01001569 if (!mFrozenBounds.isEmpty()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -08001570 pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds);
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001571 pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig);
Chong Zhangd78ddb42016-03-02 17:01:14 -08001572 }
1573 if (mPendingRelaunchCount != 0) {
1574 pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount);
Jorim Jaggi0429f352015-12-22 16:29:16 +01001575 }
Wale Ogunwale9c64cb62017-04-12 13:39:59 -07001576 if (getController() != null) {
1577 pw.print(prefix); pw.print("controller="); pw.println(getController());
1578 }
Wale Ogunwalee287e192017-04-21 09:30:12 -07001579 if (mRemovingFromDisplay) {
1580 pw.println(prefix + "mRemovingFromDisplay=" + mRemovingFromDisplay);
1581 }
Jorim Jaggi4d1835d2017-08-31 17:28:27 +02001582 if (mAppAnimator.isAnimating()) {
1583 mAppAnimator.dump(pw, prefix + " ");
1584 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001585 }
1586
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07001587 @CallSuper
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001588 @Override
Adrian Roos4921ccf2017-09-28 16:54:06 +02001589 public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07001590 final long token = proto.start(fieldId);
1591 writeNameToProto(proto, NAME);
Adrian Roos4921ccf2017-09-28 16:54:06 +02001592 super.writeToProto(proto, WINDOW_TOKEN, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07001593 proto.end(token);
1594 }
1595
1596 void writeNameToProto(ProtoOutputStream proto, long fieldId) {
1597 if (appToken == null) {
1598 return;
1599 }
1600 try {
1601 proto.write(fieldId, appToken.getName());
1602 } catch (RemoteException e) {
1603 // This shouldn't happen, but in this case fall back to outputting nothing
1604 Slog.e(TAG, e.toString());
1605 }
1606 }
1607
1608 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001609 public String toString() {
1610 if (stringName == null) {
1611 StringBuilder sb = new StringBuilder();
1612 sb.append("AppWindowToken{");
1613 sb.append(Integer.toHexString(System.identityHashCode(this)));
1614 sb.append(" token="); sb.append(token); sb.append('}');
1615 stringName = sb.toString();
1616 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001617 return stringName + ((mIsExiting) ? " mIsExiting=" : "");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001618 }
Jeff Browne9bdb312012-04-05 15:30:10 -07001619}