blob: fc0564d35a3f7c070be0f0e5ee35ce8820188757 [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
Winson Chunge55c0192017-08-24 14:50:48 -070019import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
20import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;
Wale Ogunwale72919d22016-12-08 18:58:50 -080021import static android.content.pm.ActivityInfo.CONFIG_ORIENTATION;
22import static android.content.pm.ActivityInfo.CONFIG_SCREEN_SIZE;
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -070023import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND;
Wale Ogunwale51362492016-09-08 17:49:17 -070024import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET;
Jorim Jaggif5f9e122017-10-24 18:21:09 +020025import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070026import static android.view.Display.DEFAULT_DISPLAY;
Jorim Jaggife762342016-10-13 14:33:27 +020027import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
Jorim Jaggid635a4a2017-05-03 15:21:26 +020028import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
Jorim Jaggife762342016-10-13 14:33:27 +020029import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
Wale Ogunwaled1c37912016-08-16 03:19:39 -070030import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080031import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070032import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
Tony Mak64b8d562017-12-28 17:44:02 +000033
Adrian Roose99bc052017-11-20 17:55:31 +010034import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
35import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070036import static com.android.server.wm.AppTransition.TRANSIT_UNSET;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080037import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080038import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
39import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070040import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070041import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
42import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
Wale Ogunwale9017ec02016-02-25 08:55:25 -080043import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
Jorim Jaggie4b0f282017-05-17 15:10:29 +020044import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW_VERBOSE;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070045import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TOKEN_MOVEMENT;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080046import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
47import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_MOVEMENT;
48import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
49import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Chong Zhang92147042016-05-09 12:47:11 -070050import static com.android.server.wm.WindowManagerService.H.NOTIFY_ACTIVITY_DRAWN;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070051import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070052import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070053import static com.android.server.wm.WindowManagerService.logWithStack;
Steven Timotiusaf03df62017-07-18 16:56:43 -070054import static com.android.server.wm.proto.AppWindowTokenProto.NAME;
55import static com.android.server.wm.proto.AppWindowTokenProto.WINDOW_TOKEN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080056
Wale Ogunwale0d5609b2017-09-13 05:55:07 -070057import android.annotation.CallSuper;
Jorim Jaggid635a4a2017-05-03 15:21:26 +020058import android.app.Activity;
Jorim Jaggi26c8c422016-05-09 19:57:25 -070059import android.content.res.Configuration;
Jorim Jaggi988f6682017-11-17 17:46:43 +010060import android.graphics.GraphicBuffer;
Jorim Jaggif5f9e122017-10-24 18:21:09 +020061import android.graphics.Point;
Jorim Jaggi0429f352015-12-22 16:29:16 +010062import android.graphics.Rect;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070063import android.os.Binder;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080064import android.os.Debug;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070065import android.os.IBinder;
Steven Timotiusaf03df62017-07-18 16:56:43 -070066import android.os.RemoteException;
Jorim Jaggif5f9e122017-10-24 18:21:09 +020067import android.os.Trace;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080068import android.util.Slog;
Steven Timotiusaf03df62017-07-18 16:56:43 -070069import android.util.proto.ProtoOutputStream;
Jorim Jaggif5f9e122017-10-24 18:21:09 +020070import android.view.DisplayInfo;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080071import android.view.IApplicationToken;
Robert Carr6914f082017-03-20 19:04:30 -070072import android.view.SurfaceControl;
Tony Mak64b8d562017-12-28 17:44:02 +000073import android.view.SurfaceControl.Transaction;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080074import android.view.WindowManager;
Jorim Jaggi87fdbcb2017-08-17 13:41:11 +020075import android.view.WindowManager.LayoutParams;
Tony Mak64b8d562017-12-28 17:44:02 +000076import android.view.animation.Animation;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080077
Tony Mak64b8d562017-12-28 17:44:02 +000078import com.android.internal.R;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080079import com.android.internal.util.ToBooleanFunction;
80import com.android.server.input.InputApplicationHandle;
Adrian Roose99bc052017-11-20 17:55:31 +010081import com.android.server.policy.WindowManagerPolicy.StartingSurface;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080082import com.android.server.wm.WindowManagerService.H;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080083
84import java.io.PrintWriter;
Jorim Jaggi0429f352015-12-22 16:29:16 +010085import java.util.ArrayDeque;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080086import java.util.ArrayList;
Jorim Jaggia5e10572017-11-15 14:36:26 +010087import java.util.LinkedList;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080088
89class AppTokenList extends ArrayList<AppWindowToken> {
90}
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080091
92/**
93 * Version of WindowToken that is specifically for a particular application (or
94 * really activity) that is displaying windows.
95 */
Wale Ogunwale3f4433d2016-08-18 20:42:42 -070096class AppWindowToken extends WindowToken implements WindowManagerService.AppFreezeListener {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080097 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppWindowToken" : TAG_WM;
98
Jorim Jaggi619c9f72017-12-19 18:04:29 +010099 /**
100 * Value to increment the z-layer when boosting a layer during animations. BOOST in l33tsp34k.
101 */
102 private static final int Z_BOOST_BASE = 800570000;
103
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800104 // Non-null only for application tokens.
105 final IApplicationToken appToken;
106
Wale Ogunwale72919d22016-12-08 18:58:50 -0800107 final boolean mVoiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700108
Wale Ogunwale51362492016-09-08 17:49:17 -0700109 /** @see WindowContainer#fillsParent() */
110 private boolean mFillsParent;
Craig Mautner4c5eb222013-11-18 12:59:05 -0800111 boolean layoutConfigChanges;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800112 boolean mShowForAllUsers;
113 int mTargetSdk;
Craig Mautnera2c77052012-03-26 12:14:43 -0700114
Bryce Lee6d410262017-02-28 15:30:17 -0800115 // Flag set while reparenting to prevent actions normally triggered by an individual parent
116 // change.
117 private boolean mReparenting;
118
Wale Ogunwalee287e192017-04-21 09:30:12 -0700119 // True if we are current in the process of removing this app token from the display
120 private boolean mRemovingFromDisplay = false;
121
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800122 // The input dispatching timeout for this application token in nanoseconds.
Wale Ogunwale72919d22016-12-08 18:58:50 -0800123 long mInputDispatchingTimeoutNanos;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800124
125 // These are used for determining when all windows associated with
126 // an activity have been drawn, so they can be made visible together
127 // at the same time.
Craig Mautner764983d2012-03-22 11:37:36 -0700128 // initialize so that it doesn't match mTransactionSequence which is an int.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700129 private long mLastTransactionSequence = Long.MIN_VALUE;
130 private int mNumInterestingWindows;
131 private int mNumDrawnWindows;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800132 boolean inPendingTransaction;
133 boolean allDrawn;
Jorim Jaggib0fc8172017-11-23 17:04:08 +0000134 private boolean mLastAllDrawn;
135
Craig Mautner7636dfb2012-11-16 15:24:11 -0800136 // Set to true when this app creates a surface while in the middle of an animation. In that
137 // case do not clear allDrawn until the animation completes.
138 boolean deferClearAllDrawn;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800139
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800140 // Is this window's surface needed? This is almost like hidden, except
141 // it will sometimes be true a little earlier: when the token has
142 // been shown, but is still waiting for its app transition to execute
143 // before making its windows shown.
144 boolean hiddenRequested;
145
146 // Have we told the window clients to hide themselves?
Wale Ogunwale89973222017-04-23 18:39:45 -0700147 private boolean mClientHidden;
148
149 // If true we will defer setting mClientHidden to true and reporting to the client that it is
150 // hidden.
151 boolean mDeferHidingClient;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800152
153 // Last visibility state we reported to the app token.
154 boolean reportedVisible;
155
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700156 // Last drawn state we reported to the app token.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700157 private boolean reportedDrawn;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700158
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800159 // Set to true when the token has been removed from the window mgr.
160 boolean removed;
161
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800162 // Information about an application starting window if displayed.
163 StartingData startingData;
164 WindowState startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800165 StartingSurface startingSurface;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800166 boolean startingDisplayed;
167 boolean startingMoved;
Wale Ogunwale6c459212017-05-17 08:56:03 -0700168 // True if the hidden state of this token was forced to false due to a transferred starting
169 // window.
170 private boolean mHiddenSetFromTransferredStartingWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800171 boolean firstWindowDrawn;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700172 private final WindowState.UpdateReportedVisibilityResults mReportedVisibilityResults =
173 new WindowState.UpdateReportedVisibilityResults();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800174
175 // Input application handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700176 final InputApplicationHandle mInputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800177
Wale Ogunwale571771c2016-08-26 13:18:50 -0700178 // TODO: Have a WindowContainer state for tracking exiting/deferred removal.
Craig Mautner799bc1d2015-01-14 10:33:48 -0800179 boolean mIsExiting;
Craig Mautner9ef471f2014-02-07 13:11:47 -0800180
Craig Mautnerbb742462014-07-07 15:28:55 -0700181 boolean mLaunchTaskBehind;
Craig Mautner8746a472014-07-24 15:12:54 -0700182 boolean mEnteringAnimation;
Craig Mautnerbb742462014-07-07 15:28:55 -0700183
Wale Ogunwale72919d22016-12-08 18:58:50 -0800184 private boolean mAlwaysFocusable;
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800185
Robert Carre12aece2016-02-02 22:43:27 -0800186 boolean mAppStopped;
Robert Carrfd10cd12016-06-29 16:41:50 -0700187 int mRotationAnimationHint;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700188 private int mPendingRelaunchCount;
Robert Carre12aece2016-02-02 22:43:27 -0800189
Jorim Jaggife762342016-10-13 14:33:27 +0200190 private boolean mLastContainsShowWhenLockedWindow;
191 private boolean mLastContainsDismissKeyguardWindow;
192
Jorim Jaggi0429f352015-12-22 16:29:16 +0100193 ArrayDeque<Rect> mFrozenBounds = new ArrayDeque<>();
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700194 ArrayDeque<Configuration> mFrozenMergedConfig = new ArrayDeque<>();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100195
Wale Ogunwale6c459212017-05-17 08:56:03 -0700196 private boolean mDisablePreviewScreenshots;
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +0100197
Wale Ogunwale034a8ec2017-09-02 17:14:40 -0700198 private Task mLastParent;
Robert Carred3e83b2017-04-21 13:26:55 -0700199
chaviwd3bf08d2017-08-01 17:24:59 -0700200 /**
201 * See {@link #canTurnScreenOn()}
202 */
203 private boolean mCanTurnScreenOn = true;
204
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200205 /**
206 * If we are running an animation, this determines the transition type. Must be one of
207 * AppTransition.TRANSIT_* constants.
208 */
209 private int mTransit;
210
211 /**
212 * If we are running an animation, this determines the flags during this animation. Must be a
213 * bitwise combination of AppTransition.TRANSIT_FLAG_* constants.
214 */
215 private int mTransitFlags;
216
217 /** Whether our surface was set to be showing in the last call to {@link #prepareSurfaces} */
Jorim Jaggifd1891462017-12-29 15:41:36 +0100218 private boolean mLastSurfaceShowing = true;
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200219
Jorim Jaggi988f6682017-11-17 17:46:43 +0100220 private AppWindowThumbnail mThumbnail;
221
Jorim Jaggib0fc8172017-11-23 17:04:08 +0000222 /** Have we been asked to have this token keep the screen frozen? */
223 private boolean mFreezingScreen;
224
225 /** Whether this token should be boosted at the top of all app window tokens. */
226 private boolean mNeedsZBoost;
227
chaviw23ee71c2017-12-18 11:29:41 -0800228 private final Point mTmpPoint = new Point();
chaviw23012112017-12-20 15:29:04 -0800229 private final Rect mTmpRect = new Rect();
chaviw23ee71c2017-12-18 11:29:41 -0800230
Wale Ogunwale72919d22016-12-08 18:58:50 -0800231 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
232 DisplayContent dc, long inputDispatchingTimeoutNanos, boolean fullscreen,
233 boolean showForAllUsers, int targetSdk, int orientation, int rotationAnimationHint,
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800234 int configChanges, boolean launchTaskBehind, boolean alwaysFocusable,
Bryce Leef3c6a472017-11-14 14:53:06 -0800235 AppWindowContainerController controller) {
236 this(service, token, voiceInteraction, dc, fullscreen);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800237 setController(controller);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800238 mInputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800239 mShowForAllUsers = showForAllUsers;
240 mTargetSdk = targetSdk;
241 mOrientation = orientation;
242 layoutConfigChanges = (configChanges & (CONFIG_SCREEN_SIZE | CONFIG_ORIENTATION)) != 0;
243 mLaunchTaskBehind = launchTaskBehind;
244 mAlwaysFocusable = alwaysFocusable;
245 mRotationAnimationHint = rotationAnimationHint;
246
247 // Application tokens start out hidden.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200248 setHidden(true);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800249 hiddenRequested = true;
250 }
251
252 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
Bryce Leef3c6a472017-11-14 14:53:06 -0800253 DisplayContent dc, boolean fillsParent) {
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800254 super(service, token != null ? token.asBinder() : null, TYPE_APPLICATION, true, dc,
255 false /* ownerCanManageAppTokens */);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700256 appToken = token;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800257 mVoiceInteraction = voiceInteraction;
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800258 mFillsParent = fillsParent;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800259 mInputApplicationHandle = new InputApplicationHandle(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800260 }
261
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800262 void onFirstWindowDrawn(WindowState win, WindowStateAnimator winAnimator) {
263 firstWindowDrawn = true;
264
265 // We now have a good window to show, remove dead placeholders
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700266 removeDeadWindows();
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800267
Jorim Jaggi02886a82016-12-06 09:10:06 -0800268 if (startingWindow != null) {
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800269 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, "Finish starting "
270 + win.mToken + ": first real window is shown, no animation");
271 // If this initial window is animating, stop it -- we will do an animation to reveal
272 // it from behind the starting window, so there is no need for it to also be doing its
273 // own stuff.
Jorim Jaggia5e10572017-11-15 14:36:26 +0100274 win.cancelAnimation();
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800275 if (getController() != null) {
276 getController().removeStartingWindow();
277 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800278 }
279 updateReportedVisibilityLocked();
280 }
281
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800282 void updateReportedVisibilityLocked() {
283 if (appToken == null) {
284 return;
285 }
286
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700287 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700288 final int count = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800289
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700290 mReportedVisibilityResults.reset();
291
292 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700293 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700294 win.updateReportedVisibility(mReportedVisibilityResults);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800295 }
296
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700297 int numInteresting = mReportedVisibilityResults.numInteresting;
298 int numVisible = mReportedVisibilityResults.numVisible;
299 int numDrawn = mReportedVisibilityResults.numDrawn;
300 boolean nowGone = mReportedVisibilityResults.nowGone;
301
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700302 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200303 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting && !isHidden();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700304 if (!nowGone) {
305 // If the app is not yet gone, then it can only become visible/drawn.
306 if (!nowDrawn) {
307 nowDrawn = reportedDrawn;
308 }
309 if (!nowVisible) {
310 nowVisible = reportedVisible;
311 }
312 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800313 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800314 + numInteresting + " visible=" + numVisible);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800315 final AppWindowContainerController controller = getController();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700316 if (nowDrawn != reportedDrawn) {
317 if (nowDrawn) {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800318 if (controller != null) {
319 controller.reportWindowsDrawn();
320 }
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700321 }
322 reportedDrawn = nowDrawn;
323 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800324 if (nowVisible != reportedVisible) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700325 if (DEBUG_VISIBILITY) Slog.v(TAG,
326 "Visibility changed in " + this + ": vis=" + nowVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800327 reportedVisible = nowVisible;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800328 if (controller != null) {
329 if (nowVisible) {
330 controller.reportWindowsVisible();
331 } else {
332 controller.reportWindowsGone();
333 }
334 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800335 }
336 }
337
Wale Ogunwale89973222017-04-23 18:39:45 -0700338 boolean isClientHidden() {
339 return mClientHidden;
340 }
341
342 void setClientHidden(boolean hideClient) {
343 if (mClientHidden == hideClient || (hideClient && mDeferHidingClient)) {
344 return;
345 }
346 mClientHidden = hideClient;
347 sendAppVisibilityToClients();
348 }
349
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700350 boolean setVisibility(WindowManager.LayoutParams lp,
351 boolean visible, int transit, boolean performLayout, boolean isVoiceInteraction) {
352
353 boolean delayed = false;
354 inPendingTransaction = false;
Wale Ogunwale9e4721f2017-05-23 19:37:30 -0700355 // Reset the state of mHiddenSetFromTransferredStartingWindow since visibility is actually
356 // been set by the app now.
357 mHiddenSetFromTransferredStartingWindow = false;
Wale Ogunwale89973222017-04-23 18:39:45 -0700358 setClientHidden(!visible);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700359
360 // Allow for state changes and animation to be applied if:
361 // * token is transitioning visibility state
362 // * or the token was marked as hidden and is exiting before we had a chance to play the
363 // transition animation
364 // * or this is an opening app and windows are being replaced.
365 boolean visibilityChanged = false;
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200366 if (isHidden() == visible || (isHidden() && mIsExiting) || (visible && waitingForReplacement())) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700367 final AccessibilityController accessibilityController = mService.mAccessibilityController;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700368 boolean changed = false;
369 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200370 "Changing app " + this + " hidden=" + isHidden() + " performLayout=" + performLayout);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700371
372 boolean runningAppAnimation = false;
373
374 if (transit != AppTransition.TRANSIT_UNSET) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200375 if (applyAnimationLocked(lp, transit, visible, isVoiceInteraction)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700376 delayed = runningAppAnimation = true;
377 }
378 final WindowState window = findMainWindow();
379 //TODO (multidisplay): Magnification is supported only for the default display.
380 if (window != null && accessibilityController != null
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700381 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700382 accessibilityController.onAppWindowTransitionLocked(window, transit);
383 }
384 changed = true;
385 }
386
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700387 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700388 for (int i = 0; i < windowsCount; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700389 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700390 changed |= win.onAppVisibilityChanged(visible, runningAppAnimation);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700391 }
392
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200393 setHidden(!visible);
394 hiddenRequested = !visible;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700395 visibilityChanged = true;
396 if (!visible) {
397 stopFreezingScreen(true, true);
398 } else {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700399 // If we are being set visible, and the starting window is not yet displayed,
400 // then make sure it doesn't get displayed.
401 if (startingWindow != null && !startingWindow.isDrawnLw()) {
402 startingWindow.mPolicyVisibility = false;
403 startingWindow.mPolicyVisibilityAfterAnim = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700404 }
Jorim Jaggi38d44ec2017-06-14 16:04:59 -0700405
406 // We are becoming visible, so better freeze the screen with the windows that are
407 // getting visible so we also wait for them.
408 forAllWindows(mService::makeWindowFreezingScreenIfNeededLocked, true);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700409 }
410
411 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setVisibility: " + this
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200412 + ": hidden=" + isHidden() + " hiddenRequested=" + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700413
414 if (changed) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700415 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700416 if (performLayout) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700417 mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700418 false /*updateInputWindows*/);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700419 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700420 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700421 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700422 }
423 }
424
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200425 if (isReallyAnimating()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700426 delayed = true;
427 }
428
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700429 for (int i = mChildren.size() - 1; i >= 0 && !delayed; i--) {
Jorim Jaggia5e10572017-11-15 14:36:26 +0100430 if ((mChildren.get(i)).isSelfOrChildAnimating()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700431 delayed = true;
432 }
433 }
434
435 if (visibilityChanged) {
436 if (visible && !delayed) {
437 // The token was made immediately visible, there will be no entrance animation.
438 // We need to inform the client the enter animation was finished.
439 mEnteringAnimation = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700440 mService.mActivityManagerAppTransitionNotifier.onAppTransitionFinishedLocked(token);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700441 }
Robert Carr61b81112017-07-17 18:08:15 -0700442
Robert Carre7cc44d2017-03-20 19:04:30 -0700443 // If we are hidden but there is no delay needed we immediately
444 // apply the Surface transaction so that the ActivityManager
Robert Carr61b81112017-07-17 18:08:15 -0700445 // can have some guarantee on the Surface state following
446 // setting the visibility. This captures cases like dismissing
447 // the docked or pinned stack where there is no app transition.
448 //
449 // In the case of a "Null" animation, there will be
450 // no animation but there will still be a transition set.
451 // We still need to delay hiding the surface such that it
452 // can be synchronized with showing the next surface in the transition.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200453 if (isHidden() && !delayed && !mService.mAppTransition.isTransitionSet()) {
Robert Carr6914f082017-03-20 19:04:30 -0700454 SurfaceControl.openTransaction();
455 for (int i = mChildren.size() - 1; i >= 0; i--) {
456 mChildren.get(i).mWinAnimator.hide("immediately hidden");
457 }
458 SurfaceControl.closeTransaction();
459 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700460
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700461 if (!mService.mClosingApps.contains(this) && !mService.mOpeningApps.contains(this)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700462 // The token is not closing nor opening, so even if there is an animation set, that
463 // doesn't mean that it goes through the normal app transition cycle so we have
464 // to inform the docked controller about visibility change.
Andrii Kulian1e32e022016-09-16 15:29:34 -0700465 // TODO(multi-display): notify docked divider on all displays where visibility was
466 // affected.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700467 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700468 .notifyAppVisibilityChanged();
Jorim Jaggi8b702ed2017-01-20 16:59:03 +0100469 mService.mTaskSnapshotController.notifyAppVisibilityChanged(this, visible);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700470 }
471 }
472
473 return delayed;
474 }
475
Jorim Jaggi87fdbcb2017-08-17 13:41:11 +0200476 /**
477 * @return The to top most child window for which {@link LayoutParams#isFullscreen()} returns
478 * true.
479 */
480 WindowState getTopFullscreenWindow() {
481 for (int i = mChildren.size() - 1; i >= 0; i--) {
482 final WindowState win = mChildren.get(i);
483 if (win != null && win.mAttrs.isFullscreen()) {
484 return win;
485 }
486 }
487 return null;
488 }
489
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800490 WindowState findMainWindow() {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700491 WindowState candidate = null;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700492 int j = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800493 while (j > 0) {
494 j--;
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700495 final WindowState win = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700496 final int type = win.mAttrs.type;
497 // No need to loop through child window as base application and starting types can't be
498 // child windows.
499 if (type == TYPE_BASE_APPLICATION || type == TYPE_APPLICATION_STARTING) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700500 // In cases where there are multiple windows, we prefer the non-exiting window. This
Sungsoo Lim0d3d1f82015-12-02 14:47:59 +0900501 // happens for example when replacing windows during an activity relaunch. When
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700502 // constructing the animation, we want the new window, not the exiting one.
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800503 if (win.mAnimatingExit) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700504 candidate = win;
505 } else {
506 return win;
507 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800508 }
509 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700510 return candidate;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800511 }
512
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800513 boolean windowsAreFocusable() {
Wale Ogunwale3382ab12017-07-27 08:55:03 -0700514 return getWindowConfiguration().canReceiveKeys() || mAlwaysFocusable;
Wale Ogunwaled045c822015-12-02 09:14:28 -0800515 }
516
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800517 AppWindowContainerController getController() {
518 final WindowContainerController controller = super.getController();
519 return controller != null ? (AppWindowContainerController) controller : null;
520 }
521
Wale Ogunwale571771c2016-08-26 13:18:50 -0700522 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -0700523 boolean isVisible() {
Wale Ogunwalee471be62016-10-03 07:53:55 -0700524 // If the app token isn't hidden then it is considered visible and there is no need to check
525 // its children windows to see if they are visible.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200526 return !isHidden();
Wale Ogunwale44f21802016-09-02 12:49:48 -0700527 }
528
529 @Override
Wale Ogunwalee287e192017-04-21 09:30:12 -0700530 void removeImmediately() {
531 onRemovedFromDisplay();
532 super.removeImmediately();
533 }
534
535 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -0700536 void removeIfPossible() {
Craig Mautnere3119b72015-01-20 15:02:36 -0800537 mIsExiting = false;
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800538 removeAllWindowsIfPossible();
Bryce Lee6d410262017-02-28 15:30:17 -0800539 removeImmediately();
Craig Mautnere3119b72015-01-20 15:02:36 -0800540 }
541
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700542 @Override
543 boolean checkCompleteDeferredRemoval() {
544 if (mIsExiting) {
545 removeIfPossible();
546 }
547 return super.checkCompleteDeferredRemoval();
548 }
549
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700550 void onRemovedFromDisplay() {
Wale Ogunwalee287e192017-04-21 09:30:12 -0700551 if (mRemovingFromDisplay) {
552 return;
553 }
554 mRemovingFromDisplay = true;
555
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700556 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app token: " + this);
557
Wale Ogunwale72919d22016-12-08 18:58:50 -0800558 boolean delayed = setVisibility(null, false, TRANSIT_UNSET, true, mVoiceInteraction);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700559
560 mService.mOpeningApps.remove(this);
Jorim Jaggi45ca0542017-05-30 16:16:01 -0700561 mService.mUnknownAppVisibilityController.appRemovedOrHidden(this);
Jorim Jaggi10abe2f2017-01-03 16:44:46 +0100562 mService.mTaskSnapshotController.onAppRemoved(this);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700563 waitingToShow = false;
564 if (mService.mClosingApps.contains(this)) {
565 delayed = true;
566 } else if (mService.mAppTransition.isTransitionSet()) {
567 mService.mClosingApps.add(this);
568 delayed = true;
569 }
570
571 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app " + this + " delayed=" + delayed
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200572 + " animation=" + getAnimation() + " animating=" + isSelfAnimating());
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700573
574 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM, "removeAppToken: "
575 + this + " delayed=" + delayed + " Callers=" + Debug.getCallers(4));
576
Jorim Jaggi19be6052017-08-03 18:33:43 +0200577 if (startingData != null && getController() != null) {
578 getController().removeStartingWindow();
579 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800580
Winson Chung87e5d552017-04-05 11:49:38 -0700581 // If this window was animating, then we need to ensure that the app transition notifies
582 // that animations have completed in WMS.handleAnimatingStoppedAndTransitionLocked(), so
583 // add to that list now
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200584 if (isSelfAnimating()) {
Winson Chung87e5d552017-04-05 11:49:38 -0700585 mService.mNoAnimationNotifyOnTransitionFinished.add(token);
586 }
587
Wale Ogunwalee287e192017-04-21 09:30:12 -0700588 final TaskStack stack = getStack();
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700589 if (delayed && !isEmpty()) {
590 // set the token aside because it has an active animation to be finished
591 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM,
592 "removeAppToken make exiting: " + this);
Wale Ogunwalee287e192017-04-21 09:30:12 -0700593 if (stack != null) {
594 stack.mExitingAppTokens.add(this);
595 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700596 mIsExiting = true;
597 } else {
598 // Make sure there is no animation running on this token, so any windows associated
599 // with it will be removed as soon as their animations are complete
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200600 cancelAnimation();
Wale Ogunwale3106ae012017-05-16 08:56:37 -0700601 if (stack != null) {
602 stack.mExitingAppTokens.remove(this);
603 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700604 removeIfPossible();
605 }
606
607 removed = true;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700608 stopFreezingScreen(true, true);
Bryce Lee6d410262017-02-28 15:30:17 -0800609
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700610 if (mService.mFocusedApp == this) {
611 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "Removing focused app token:" + this);
612 mService.mFocusedApp = null;
613 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
614 mService.mInputMonitor.setFocusedAppLw(null);
615 }
616
617 if (!delayed) {
618 updateReportedVisibilityLocked();
619 }
Wale Ogunwalee287e192017-04-21 09:30:12 -0700620
621 mRemovingFromDisplay = false;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700622 }
623
Chong Zhange05bcb12016-07-26 17:47:29 -0700624 void clearAnimatingFlags() {
Chong Zhangb0d26702016-08-12 16:03:29 -0700625 boolean wallpaperMightChange = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700626 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700627 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700628 wallpaperMightChange |= win.clearAnimatingFlags();
Chong Zhange05bcb12016-07-26 17:47:29 -0700629 }
Chong Zhangb0d26702016-08-12 16:03:29 -0700630 if (wallpaperMightChange) {
631 requestUpdateWallpaperIfNeeded();
632 }
Chong Zhange05bcb12016-07-26 17:47:29 -0700633 }
634
Robert Carre12aece2016-02-02 22:43:27 -0800635 void destroySurfaces() {
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700636 destroySurfaces(false /*cleanupOnResume*/);
637 }
638
639 /**
640 * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure
641 * the client has finished with them.
642 *
643 * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If
644 * set to true, destroy only surfaces of removed windows, and clear relevant flags of the
645 * others so that they are ready to be reused. If set to false (common case), destroy all
646 * surfaces that's eligible, if the app is already stopped.
647 */
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700648 private void destroySurfaces(boolean cleanupOnResume) {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700649 boolean destroyedSomething = false;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100650
651 // Copying to a different list as multiple children can be removed.
Jorim Jaggi59f3e922018-01-05 15:40:32 +0100652 final ArrayList<WindowState> children = new ArrayList<>(mChildren);
Jorim Jaggia5e10572017-11-15 14:36:26 +0100653 for (int i = children.size() - 1; i >= 0; i--) {
654 final WindowState win = children.get(i);
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700655 destroyedSomething |= win.destroySurface(cleanupOnResume, mAppStopped);
Robert Carre12aece2016-02-02 22:43:27 -0800656 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700657 if (destroyedSomething) {
658 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700659 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Robert Carre12aece2016-02-02 22:43:27 -0800660 }
661 }
662
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800663 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700664 * Notify that the app is now resumed, and it was not stopped before, perform a clean
665 * up of the surfaces
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800666 */
Jorim Jaggibae01b12017-04-11 16:29:10 -0700667 void notifyAppResumed(boolean wasStopped) {
Chong Zhangad24f962016-08-25 12:12:33 -0700668 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped
Jorim Jaggibae01b12017-04-11 16:29:10 -0700669 + " " + this);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700670 mAppStopped = false;
chaviwd3bf08d2017-08-01 17:24:59 -0700671 // Allow the window to turn the screen on once the app is resumed again.
672 setCanTurnScreenOn(true);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700673 if (!wasStopped) {
674 destroySurfaces(true /*cleanupOnResume*/);
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800675 }
Robert Carre12aece2016-02-02 22:43:27 -0800676 }
677
Chong Zhangbef461f2015-10-27 11:38:24 -0700678 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700679 * Notify that the app has stopped, and it is okay to destroy any surfaces which were
680 * keeping alive in case they were still being used.
681 */
682 void notifyAppStopped() {
683 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this);
684 mAppStopped = true;
685 destroySurfaces();
686 // Remove any starting window that was added for this app if they are still around.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800687 if (getController() != null) {
688 getController().removeStartingWindow();
689 }
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700690 }
691
Chong Zhang92147042016-05-09 12:47:11 -0700692 void clearAllDrawn() {
693 allDrawn = false;
694 deferClearAllDrawn = false;
Chong Zhangbef461f2015-10-27 11:38:24 -0700695 }
696
Bryce Lee6d410262017-02-28 15:30:17 -0800697 Task getTask() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800698 return (Task) getParent();
Bryce Lee6d410262017-02-28 15:30:17 -0800699 }
700
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800701 TaskStack getStack() {
702 final Task task = getTask();
703 if (task != null) {
704 return task.mStack;
705 } else {
706 return null;
707 }
708 }
709
Bryce Lee6d410262017-02-28 15:30:17 -0800710 @Override
711 void onParentSet() {
712 super.onParentSet();
713
Robert Carred3e83b2017-04-21 13:26:55 -0700714 final Task task = getTask();
715
Bryce Lee6d410262017-02-28 15:30:17 -0800716 // When the associated task is {@code null}, the {@link AppWindowToken} can no longer
717 // access visual elements like the {@link DisplayContent}. We must remove any associations
718 // such as animations.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800719 if (!mReparenting) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800720 if (task == null) {
721 // It is possible we have been marked as a closing app earlier. We must remove ourselves
722 // from this list so we do not participate in any future animations.
723 mService.mClosingApps.remove(this);
Robert Carred3e83b2017-04-21 13:26:55 -0700724 } else if (mLastParent != null && mLastParent.mStack != null) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800725 task.mStack.mExitingAppTokens.remove(this);
726 }
Bryce Lee6d410262017-02-28 15:30:17 -0800727 }
Robert Carred3e83b2017-04-21 13:26:55 -0700728 mLastParent = task;
Bryce Lee6d410262017-02-28 15:30:17 -0800729 }
730
Wale Ogunwalefa854eb2016-09-20 13:43:52 -0700731 void postWindowRemoveStartingWindowCleanup(WindowState win) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700732 // TODO: Something smells about the code below...Is there a better way?
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700733 if (startingWindow == win) {
734 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800735 if (getController() != null) {
736 getController().removeStartingWindow();
737 }
Wale Ogunwale6c459212017-05-17 08:56:03 -0700738 } else if (mChildren.size() == 0) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700739 // If this is the last window and we had requested a starting transition window,
740 // well there is no point now.
Jorim Jaggi02886a82016-12-06 09:10:06 -0800741 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingData");
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700742 startingData = null;
Wale Ogunwale6c459212017-05-17 08:56:03 -0700743 if (mHiddenSetFromTransferredStartingWindow) {
744 // We set the hidden state to false for the token from a transferred starting window.
745 // We now reset it back to true since the starting window was the last window in the
746 // token.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200747 setHidden(true);
Wale Ogunwale6c459212017-05-17 08:56:03 -0700748 }
Jorim Jaggi829b9cd2017-01-23 16:20:53 +0100749 } else if (mChildren.size() == 1 && startingSurface != null && !isRelaunching()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700750 // If this is the last window except for a starting transition window,
751 // we need to get rid of the starting transition.
Jorim Jaggie4b0f282017-05-17 15:10:29 +0200752 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Last window, removing starting window "
753 + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800754 if (getController() != null) {
755 getController().removeStartingWindow();
756 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700757 }
758 }
759
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700760 void removeDeadWindows() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700761 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700762 WindowState win = mChildren.get(winNdx);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800763 if (win.mAppDied) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700764 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700765 "removeDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800766 // Set mDestroying, we don't want any animation or delayed removal here.
767 win.mDestroying = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700768 // Also removes child windows.
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700769 win.removeIfPossible();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800770 }
771 }
772 }
773
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700774 boolean hasWindowsAlive() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700775 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700776 // No need to loop through child windows as the answer should be the same as that of the
777 // parent window.
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700778 if (!(mChildren.get(i)).mAppDied) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700779 return true;
780 }
781 }
782 return false;
783 }
784
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700785 void setWillReplaceWindows(boolean animate) {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700786 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
787 "Marking app token " + this + " with replacing windows.");
Robert Carra1eb4392015-12-10 12:43:51 -0800788
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700789 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700790 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700791 w.setWillReplaceWindow(animate);
Robert Carra1eb4392015-12-10 12:43:51 -0800792 }
Robert Carra1eb4392015-12-10 12:43:51 -0800793 }
794
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700795 void setWillReplaceChildWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700796 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this
Robert Carr23fa16b2016-01-13 13:19:58 -0800797 + " with replacing child windows.");
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700798 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700799 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700800 w.setWillReplaceChildWindows();
Robert Carr23fa16b2016-01-13 13:19:58 -0800801 }
802 }
803
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700804 void clearWillReplaceWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700805 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
806 "Resetting app token " + this + " of replacing window marks.");
Chong Zhangf596cd52016-01-05 13:42:44 -0800807
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700808 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700809 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700810 w.clearWillReplaceWindow();
Chong Zhangf596cd52016-01-05 13:42:44 -0800811 }
812 }
813
Chong Zhang4d7369a2016-04-25 16:09:14 -0700814 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700815 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700816 final WindowState w = mChildren.get(i);
Chong Zhang4d7369a2016-04-25 16:09:14 -0700817 w.requestUpdateWallpaperIfNeeded();
818 }
819 }
820
Chong Zhangd78ddb42016-03-02 17:01:14 -0800821 boolean isRelaunching() {
822 return mPendingRelaunchCount > 0;
823 }
824
Robert Carr68375192017-06-13 12:41:53 -0700825 boolean shouldFreezeBounds() {
826 final Task task = getTask();
827
828 // For freeform windows, we can't freeze the bounds at the moment because this would make
829 // the resizing unresponsive.
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700830 if (task == null || task.inFreeformWindowingMode()) {
Robert Carr68375192017-06-13 12:41:53 -0700831 return false;
832 }
833
834 // We freeze the bounds while drag resizing to deal with the time between
835 // the divider/drag handle being released, and the handling it's new
836 // configuration. If we are relaunched outside of the drag resizing state,
837 // we need to be careful not to do this.
838 return getTask().isDragResizing();
839 }
840
Chong Zhangd78ddb42016-03-02 17:01:14 -0800841 void startRelaunching() {
Robert Carr68375192017-06-13 12:41:53 -0700842 if (shouldFreezeBounds()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -0800843 freezeBounds();
844 }
Robert Carrd5c7dd62017-03-08 10:39:30 -0800845
846 // In the process of tearing down before relaunching, the app will
847 // try and clean up it's child surfaces. We need to prevent this from
848 // happening, so we sever the children, transfering their ownership
849 // from the client it-self to the parent surface (owned by us).
850 for (int i = mChildren.size() - 1; i >= 0; i--) {
851 final WindowState w = mChildren.get(i);
852 w.mWinAnimator.detachChildren();
853 }
854
Chong Zhangd78ddb42016-03-02 17:01:14 -0800855 mPendingRelaunchCount++;
856 }
857
858 void finishRelaunching() {
Robert Carr68375192017-06-13 12:41:53 -0700859 unfreezeBounds();
860
Chong Zhangd78ddb42016-03-02 17:01:14 -0800861 if (mPendingRelaunchCount > 0) {
862 mPendingRelaunchCount--;
Bryce Lee081554b2017-05-25 07:52:12 -0700863 } else {
864 // Update keyguard flags upon finishing relaunch.
865 checkKeyguardFlagsChanged();
Chong Zhangd78ddb42016-03-02 17:01:14 -0800866 }
867 }
868
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700869 void clearRelaunching() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700870 if (mPendingRelaunchCount == 0) {
871 return;
872 }
Robert Carr68375192017-06-13 12:41:53 -0700873 unfreezeBounds();
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700874 mPendingRelaunchCount = 0;
875 }
876
Wale Ogunwale07bcab72016-10-14 15:30:09 -0700877 /**
878 * Returns true if the new child window we are adding to this token is considered greater than
879 * the existing child window in this token in terms of z-order.
880 */
881 @Override
882 protected boolean isFirstChildWindowGreaterThanSecond(WindowState newWindow,
883 WindowState existingWindow) {
884 final int type1 = newWindow.mAttrs.type;
885 final int type2 = existingWindow.mAttrs.type;
886
887 // Base application windows should be z-ordered BELOW all other windows in the app token.
888 if (type1 == TYPE_BASE_APPLICATION && type2 != TYPE_BASE_APPLICATION) {
889 return false;
890 } else if (type1 != TYPE_BASE_APPLICATION && type2 == TYPE_BASE_APPLICATION) {
891 return true;
892 }
893
894 // Starting windows should be z-ordered ABOVE all other windows in the app token.
895 if (type1 == TYPE_APPLICATION_STARTING && type2 != TYPE_APPLICATION_STARTING) {
896 return true;
897 } else if (type1 != TYPE_APPLICATION_STARTING && type2 == TYPE_APPLICATION_STARTING) {
898 return false;
899 }
900
901 // Otherwise the new window is greater than the existing window.
902 return true;
903 }
904
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700905 @Override
Robert Carra1eb4392015-12-10 12:43:51 -0800906 void addWindow(WindowState w) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700907 super.addWindow(w);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700908
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700909 boolean gotReplacementWindow = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700910 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700911 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700912 gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w);
913 }
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700914
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700915 // if we got a replacement window, reset the timeout to give drawing more time
916 if (gotReplacementWindow) {
917 mService.scheduleWindowReplacementTimeouts(this);
Robert Carra1eb4392015-12-10 12:43:51 -0800918 }
Jorim Jaggife762342016-10-13 14:33:27 +0200919 checkKeyguardFlagsChanged();
920 }
921
922 @Override
923 void removeChild(WindowState child) {
924 super.removeChild(child);
925 checkKeyguardFlagsChanged();
Robert Carra1eb4392015-12-10 12:43:51 -0800926 }
927
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700928 private boolean waitingForReplacement() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700929 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700930 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700931 if (candidate.waitingForReplacement()) {
Robert Carra1eb4392015-12-10 12:43:51 -0800932 return true;
933 }
934 }
935 return false;
936 }
937
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700938 void onWindowReplacementTimeout() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700939 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700940 (mChildren.get(i)).onWindowReplacementTimeout();
Robert Carra1eb4392015-12-10 12:43:51 -0800941 }
942 }
943
Winson Chung30480042017-01-26 10:55:34 -0800944 void reparent(Task task, int position) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800945 final Task currentTask = getTask();
946 if (task == currentTask) {
Winson Chung30480042017-01-26 10:55:34 -0800947 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800948 "window token=" + this + " already child of task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -0800949 }
Bryce Lee6d410262017-02-28 15:30:17 -0800950
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800951 if (currentTask.mStack != task.mStack) {
Bryce Lee6d410262017-02-28 15:30:17 -0800952 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800953 "window token=" + this + " current task=" + currentTask
Bryce Lee6d410262017-02-28 15:30:17 -0800954 + " belongs to a different stack than " + task);
955 }
956
Winson Chung30480042017-01-26 10:55:34 -0800957 if (DEBUG_ADD_REMOVE) Slog.i(TAG, "reParentWindowToken: removing window token=" + this
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800958 + " from task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -0800959 final DisplayContent prevDisplayContent = getDisplayContent();
960
Bryce Lee6d410262017-02-28 15:30:17 -0800961 mReparenting = true;
962
Winson Chung30480042017-01-26 10:55:34 -0800963 getParent().removeChild(this);
964 task.addChild(this, position);
965
Bryce Lee6d410262017-02-28 15:30:17 -0800966 mReparenting = false;
967
Winson Chung30480042017-01-26 10:55:34 -0800968 // Relayout display(s).
969 final DisplayContent displayContent = task.getDisplayContent();
970 displayContent.setLayoutNeeded();
971 if (prevDisplayContent != displayContent) {
972 onDisplayChanged(displayContent);
973 prevDisplayContent.setLayoutNeeded();
974 }
975 }
976
Jorim Jaggi0429f352015-12-22 16:29:16 +0100977 /**
978 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
979 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
980 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
981 * with a queue.
982 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800983 private void freezeBounds() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800984 final Task task = getTask();
985 mFrozenBounds.offer(new Rect(task.mPreparedFrozenBounds));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700986
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800987 if (task.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) {
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700988 // We didn't call prepareFreezingBounds on the task, so use the current value.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800989 mFrozenMergedConfig.offer(new Configuration(task.getConfiguration()));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700990 } else {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800991 mFrozenMergedConfig.offer(new Configuration(task.mPreparedFrozenMergedConfig));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700992 }
Andrii Kulianb10330d2016-09-16 13:51:46 -0700993 // Calling unset() to make it equal to Configuration.EMPTY.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800994 task.mPreparedFrozenMergedConfig.unset();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100995 }
996
997 /**
998 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
999 */
Chong Zhangd78ddb42016-03-02 17:01:14 -08001000 private void unfreezeBounds() {
Robert Carr68375192017-06-13 12:41:53 -07001001 if (mFrozenBounds.isEmpty()) {
1002 return;
Wale Ogunwale37dbafc2016-06-27 10:15:20 -07001003 }
Robert Carr68375192017-06-13 12:41:53 -07001004 mFrozenBounds.remove();
Wale Ogunwale37dbafc2016-06-27 10:15:20 -07001005 if (!mFrozenMergedConfig.isEmpty()) {
1006 mFrozenMergedConfig.remove();
1007 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001008 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001009 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001010 win.onUnfreezeBounds();
Jorim Jaggi4846ee32016-01-07 17:39:12 +01001011 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001012 mService.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +01001013 }
1014
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001015 void setAppLayoutChanges(int changes, String reason) {
1016 if (!mChildren.isEmpty()) {
1017 final DisplayContent dc = getDisplayContent();
1018 dc.pendingLayoutChanges |= changes;
1019 if (DEBUG_LAYOUT_REPEATS) {
1020 mService.mWindowPlacerLocked.debugLayoutRepeats(reason, dc.pendingLayoutChanges);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001021 }
1022 }
1023 }
1024
1025 void removeReplacedWindowIfNeeded(WindowState replacement) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001026 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001027 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001028 if (win.removeReplacedWindowIfNeeded(replacement)) {
1029 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001030 }
1031 }
1032 }
1033
1034 void startFreezingScreen() {
1035 if (DEBUG_ORIENTATION) logWithStack(TAG, "Set freezing of " + appToken + ": hidden="
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001036 + isHidden() + " freezing=" + mFreezingScreen + " hiddenRequested="
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001037 + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001038 if (!hiddenRequested) {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001039 if (!mFreezingScreen) {
1040 mFreezingScreen = true;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001041 mService.registerAppFreezeListener(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001042 mService.mAppsFreezingScreen++;
1043 if (mService.mAppsFreezingScreen == 1) {
Bryce Lee8f853582017-06-05 17:25:59 -07001044 mService.startFreezingDisplayLocked(false, 0, 0, getDisplayContent());
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001045 mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT);
1046 mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001047 }
1048 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001049 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001050 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001051 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001052 w.onStartFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001053 }
1054 }
1055 }
1056
1057 void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001058 if (!mFreezingScreen) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001059 return;
1060 }
1061 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + this + " force=" + force);
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001062 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001063 boolean unfrozeWindows = false;
1064 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001065 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001066 unfrozeWindows |= w.onStopFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001067 }
1068 if (force || unfrozeWindows) {
1069 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this);
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001070 mFreezingScreen = false;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001071 mService.unregisterAppFreezeListener(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001072 mService.mAppsFreezingScreen--;
1073 mService.mLastFinishedFreezeSource = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001074 }
1075 if (unfreezeSurfaceNow) {
1076 if (unfrozeWindows) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001077 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001078 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001079 mService.stopFreezingDisplayLocked();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001080 }
1081 }
1082
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001083 @Override
1084 public void onAppFreezeTimeout() {
1085 Slog.w(TAG_WM, "Force clearing freeze: " + this);
1086 stopFreezingScreen(true, true);
1087 }
1088
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001089 boolean transferStartingWindow(IBinder transferFrom) {
Wale Ogunwale02319a62016-09-26 15:21:22 -07001090 final AppWindowToken fromToken = getDisplayContent().getAppWindowToken(transferFrom);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001091 if (fromToken == null) {
1092 return false;
1093 }
1094
1095 final WindowState tStartingWindow = fromToken.startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001096 if (tStartingWindow != null && fromToken.startingSurface != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001097 // In this case, the starting icon has already been displayed, so start
1098 // letting windows get shown immediately without any more transitions.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001099 mService.mSkipAppTransitionAnimation = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001100
1101 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow
1102 + " from " + fromToken + " to " + this);
1103
1104 final long origId = Binder.clearCallingIdentity();
Peter Visontay3556a3b2017-11-01 17:23:17 +00001105 try {
1106 // Transfer the starting window over to the new token.
1107 startingData = fromToken.startingData;
1108 startingSurface = fromToken.startingSurface;
1109 startingDisplayed = fromToken.startingDisplayed;
1110 fromToken.startingDisplayed = false;
1111 startingWindow = tStartingWindow;
1112 reportedVisible = fromToken.reportedVisible;
1113 fromToken.startingData = null;
1114 fromToken.startingSurface = null;
1115 fromToken.startingWindow = null;
1116 fromToken.startingMoved = true;
1117 tStartingWindow.mToken = this;
1118 tStartingWindow.mAppToken = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001119
Peter Visontay3556a3b2017-11-01 17:23:17 +00001120 if (DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1121 "Removing starting " + tStartingWindow + " from " + fromToken);
1122 fromToken.removeChild(tStartingWindow);
1123 fromToken.postWindowRemoveStartingWindowCleanup(tStartingWindow);
1124 fromToken.mHiddenSetFromTransferredStartingWindow = false;
1125 addWindow(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001126
Peter Visontay3556a3b2017-11-01 17:23:17 +00001127 // Propagate other interesting state between the tokens. If the old token is displayed,
1128 // we should immediately force the new one to be displayed. If it is animating, we need
1129 // to move that animation to the new one.
1130 if (fromToken.allDrawn) {
1131 allDrawn = true;
1132 deferClearAllDrawn = fromToken.deferClearAllDrawn;
1133 }
1134 if (fromToken.firstWindowDrawn) {
1135 firstWindowDrawn = true;
1136 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001137 if (!fromToken.isHidden()) {
1138 setHidden(false);
Peter Visontay3556a3b2017-11-01 17:23:17 +00001139 hiddenRequested = false;
1140 mHiddenSetFromTransferredStartingWindow = true;
1141 }
1142 setClientHidden(fromToken.mClientHidden);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001143
Jorim Jaggi980c9de2017-11-17 01:41:37 +01001144 transferAnimation(fromToken);
1145
1146 // When transferring an animation, we no longer need to apply an animation to the
1147 // the token we transfer the animation over. Thus, remove the animation from
1148 // pending opening apps.
1149 mService.mOpeningApps.remove(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001150
Peter Visontay3556a3b2017-11-01 17:23:17 +00001151 mService.updateFocusedWindowLocked(
1152 UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/);
1153 getDisplayContent().setLayoutNeeded();
1154 mService.mWindowPlacerLocked.performSurfacePlacement();
1155 } finally {
1156 Binder.restoreCallingIdentity(origId);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001157 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001158 return true;
1159 } else if (fromToken.startingData != null) {
1160 // The previous app was getting ready to show a
1161 // starting window, but hasn't yet done so. Steal it!
1162 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1163 "Moving pending starting from " + fromToken + " to " + this);
1164 startingData = fromToken.startingData;
1165 fromToken.startingData = null;
1166 fromToken.startingMoved = true;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001167 if (getController() != null) {
1168 getController().scheduleAddStartingWindow();
1169 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001170 return true;
1171 }
1172
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001173 // TODO: Transfer thumbnail
1174
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001175 return false;
1176 }
1177
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001178 boolean isLastWindow(WindowState win) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001179 return mChildren.size() == 1 && mChildren.get(0) == win;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001180 }
1181
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001182 @Override
1183 void onAppTransitionDone() {
1184 sendingToBottom = false;
1185 }
1186
Wale Ogunwale51362492016-09-08 17:49:17 -07001187 /**
1188 * We override because this class doesn't want its children affecting its reported orientation
1189 * in anyway.
1190 */
1191 @Override
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001192 int getOrientation(int candidate) {
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001193 if (candidate == SCREEN_ORIENTATION_BEHIND) {
1194 // Allow app to specify orientation regardless of its visibility state if the current
1195 // candidate want us to use orientation behind. I.e. the visible app on-top of this one
1196 // wants us to use the orientation of the app behind it.
1197 return mOrientation;
1198 }
1199
Bryce Lee61fbcbc2017-03-10 14:14:03 -08001200 // The {@link AppWindowToken} should only specify an orientation when it is not closing or
1201 // going to the bottom. Allowing closing {@link AppWindowToken} to participate can lead to
1202 // an Activity in another task being started in the wrong orientation during the transition.
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001203 if (!(sendingToBottom || mService.mClosingApps.contains(this))
Bryce Lee00d586d2017-07-28 20:48:43 -07001204 && (isVisible() || mService.mOpeningApps.contains(this) || isOnTop())) {
Bryce Leea163b762017-01-24 11:05:01 -08001205 return mOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001206 }
Bryce Leea163b762017-01-24 11:05:01 -08001207
1208 return SCREEN_ORIENTATION_UNSET;
Wale Ogunwale51362492016-09-08 17:49:17 -07001209 }
1210
Wale Ogunwaleb198b742016-12-01 08:44:09 -08001211 /** Returns the app's preferred orientation regardless of its currently visibility state. */
1212 int getOrientationIgnoreVisibility() {
1213 return mOrientation;
1214 }
1215
Craig Mautnerdbb79912012-03-01 18:59:14 -08001216 @Override
Winson Chunge55c0192017-08-24 14:50:48 -07001217 public void onConfigurationChanged(Configuration newParentConfig) {
1218 final int prevWinMode = getWindowingMode();
1219 super.onConfigurationChanged(newParentConfig);
1220 final int winMode = getWindowingMode();
1221
1222 if (prevWinMode == winMode) {
1223 return;
1224 }
1225
1226 if (prevWinMode != WINDOWING_MODE_UNDEFINED && winMode == WINDOWING_MODE_PINNED) {
1227 // Entering PiP from fullscreen, reset the snap fraction
1228 mDisplayContent.mPinnedStackControllerLocked.resetReentrySnapFraction(this);
1229 } else if (prevWinMode == WINDOWING_MODE_PINNED && winMode != WINDOWING_MODE_UNDEFINED) {
1230 // Leaving PiP to fullscreen, save the snap fraction based on the pre-animation bounds
1231 // for the next re-entry into PiP (assuming the activity is not hidden or destroyed)
1232 final TaskStack pinnedStack = mDisplayContent.getPinnedStack();
1233 if (pinnedStack != null) {
1234 mDisplayContent.mPinnedStackControllerLocked.saveReentrySnapFraction(this,
1235 pinnedStack.mPreAnimationBounds);
1236 }
1237 }
1238 }
1239
1240 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001241 void checkAppWindowsReadyToShow() {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001242 if (allDrawn == mLastAllDrawn) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001243 return;
1244 }
1245
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001246 mLastAllDrawn = allDrawn;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001247 if (!allDrawn) {
1248 return;
1249 }
1250
1251 // The token has now changed state to having all windows shown... what to do, what to do?
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001252 if (mFreezingScreen) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001253 showAllWindowsLocked();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001254 stopFreezingScreen(false, true);
1255 if (DEBUG_ORIENTATION) Slog.i(TAG,
1256 "Setting mOrientationChangeComplete=true because wtoken " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001257 + " numInteresting=" + mNumInterestingWindows + " numDrawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001258 // This will set mOrientationChangeComplete and cause a pass through layout.
1259 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001260 "checkAppWindowsReadyToShow: freezingScreen");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001261 } else {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001262 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001263
1264 // We can now show all of the drawn windows!
1265 if (!mService.mOpeningApps.contains(this)) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001266 showAllWindowsLocked();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001267 }
1268 }
1269 }
1270
Matthew Ng5d23afa2017-06-21 16:16:24 -07001271 /**
Bryce Leed390deb2017-06-22 13:14:28 -07001272 * Returns whether the drawn window states of this {@link AppWindowToken} has considered every
1273 * child {@link WindowState}. A child is considered if it has been passed into
1274 * {@link #updateDrawnWindowStates(WindowState)} after being added. This is used to determine
1275 * whether states, such as {@code allDrawn}, can be set, which relies on state variables such as
1276 * {@code mNumInterestingWindows}, which depend on all {@link WindowState}s being considered.
1277 *
1278 * @return {@code true} If all children have been considered, {@code false}.
1279 */
1280 private boolean allDrawnStatesConsidered() {
Bryce Lee6311c4b2017-07-06 14:09:29 -07001281 for (int i = mChildren.size() - 1; i >= 0; --i) {
1282 final WindowState child = mChildren.get(i);
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001283 if (child.mightAffectAllDrawn() && !child.getDrawnStateEvaluated()) {
Bryce Leed390deb2017-06-22 13:14:28 -07001284 return false;
1285 }
1286 }
1287 return true;
1288 }
1289
1290 /**
Matthew Ng5d23afa2017-06-21 16:16:24 -07001291 * Determines if the token has finished drawing. This should only be called from
1292 * {@link DisplayContent#applySurfaceChangesTransaction}
1293 */
Matthew Ng498c71d2017-04-18 13:55:45 -07001294 void updateAllDrawn() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001295 if (!allDrawn) {
Matthew Ng498c71d2017-04-18 13:55:45 -07001296 // Number of drawn windows can be less when a window is being relaunched, wait for
Bryce Leed390deb2017-06-22 13:14:28 -07001297 // all windows to be launched and drawn for this token be considered all drawn.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001298 final int numInteresting = mNumInterestingWindows;
Bryce Leed390deb2017-06-22 13:14:28 -07001299
1300 // We must make sure that all present children have been considered (determined by
1301 // {@link #allDrawnStatesConsidered}) before evaluating whether everything has been
1302 // drawn.
1303 if (numInteresting > 0 && allDrawnStatesConsidered()
1304 && mNumDrawnWindows >= numInteresting && !isRelaunching()) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001305 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawn: " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001306 + " interesting=" + numInteresting + " drawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001307 allDrawn = true;
1308 // Force an additional layout pass where
1309 // WindowStateAnimator#commitFinishDrawingLocked() will call performShowLocked().
Matthew Ng498c71d2017-04-18 13:55:45 -07001310 if (mDisplayContent != null) {
1311 mDisplayContent.setLayoutNeeded();
1312 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001313 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Robert Carrecc06b32017-04-18 14:25:10 -07001314
Winson Chunge7ba6862017-05-24 12:13:33 -07001315 // Notify the pinned stack upon all windows drawn. If there was an animation in
1316 // progress then this signal will resume that animation.
Wale Ogunwale61911492017-10-11 08:50:50 -07001317 final TaskStack pinnedStack = mDisplayContent.getPinnedStack();
Winson Chunge7ba6862017-05-24 12:13:33 -07001318 if (pinnedStack != null) {
1319 pinnedStack.onAllWindowsDrawn();
Robert Carrecc06b32017-04-18 14:25:10 -07001320 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001321 }
1322 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001323 }
1324
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001325 /**
1326 * Updated this app token tracking states for interesting and drawn windows based on the window.
1327 *
1328 * @return Returns true if the input window is considered interesting and drawn while all the
1329 * windows in this app token where not considered drawn as of the last pass.
1330 */
1331 boolean updateDrawnWindowStates(WindowState w) {
Bryce Leed390deb2017-06-22 13:14:28 -07001332 w.setDrawnStateEvaluated(true /*evaluated*/);
1333
Jorim Jaggie4b0f282017-05-17 15:10:29 +02001334 if (DEBUG_STARTING_WINDOW_VERBOSE && w == startingWindow) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001335 Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" + w.isOnScreen()
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001336 + " allDrawn=" + allDrawn + " freezingScreen=" + mFreezingScreen);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001337 }
1338
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001339 if (allDrawn && !mFreezingScreen) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001340 return false;
1341 }
1342
1343 if (mLastTransactionSequence != mService.mTransactionSequence) {
1344 mLastTransactionSequence = mService.mTransactionSequence;
1345 mNumInterestingWindows = mNumDrawnWindows = 0;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001346 startingDisplayed = false;
1347 }
1348
1349 final WindowStateAnimator winAnimator = w.mWinAnimator;
1350
1351 boolean isInterestingAndDrawn = false;
1352
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001353 if (!allDrawn && w.mightAffectAllDrawn()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001354 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
1355 Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw()
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001356 + ", isAnimationSet=" + isSelfAnimating());
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001357 if (!w.isDrawnLw()) {
1358 Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController
1359 + " pv=" + w.mPolicyVisibility
1360 + " mDrawState=" + winAnimator.drawStateToString()
1361 + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001362 + " a=" + isSelfAnimating());
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001363 }
1364 }
1365
1366 if (w != startingWindow) {
1367 if (w.isInteresting()) {
1368 mNumInterestingWindows++;
1369 if (w.isDrawnLw()) {
1370 mNumDrawnWindows++;
1371
1372 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, "tokenMayBeDrawn: "
1373 + this + " w=" + w + " numInteresting=" + mNumInterestingWindows
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001374 + " freezingScreen=" + mFreezingScreen
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001375 + " mAppFreezing=" + w.mAppFreezing);
1376
1377 isInterestingAndDrawn = true;
1378 }
1379 }
1380 } else if (w.isDrawnLw()) {
Jorim Jaggi3878ca32017-02-02 17:13:05 -08001381 if (getController() != null) {
1382 getController().reportStartingWindowDrawn();
1383 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001384 startingDisplayed = true;
1385 }
1386 }
1387
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001388 return isInterestingAndDrawn;
1389 }
1390
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001391 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001392 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001393 // For legacy reasons we process the TaskStack.mExitingAppTokens first in DisplayContent
1394 // before the non-exiting app tokens. So, we skip the exiting app tokens here.
1395 // TODO: Investigate if we need to continue to do this or if we can just process them
1396 // in-order.
1397 if (mIsExiting && !waitingForReplacement()) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001398 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001399 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001400 return forAllWindowsUnchecked(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001401 }
1402
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001403 boolean forAllWindowsUnchecked(ToBooleanFunction<WindowState> callback,
1404 boolean traverseTopToBottom) {
1405 return super.forAllWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001406 }
1407
1408 @Override
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001409 AppWindowToken asAppWindowToken() {
1410 // I am an app window token!
1411 return this;
1412 }
1413
1414 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -07001415 boolean fillsParent() {
1416 return mFillsParent;
1417 }
1418
1419 void setFillsParent(boolean fillsParent) {
1420 mFillsParent = fillsParent;
1421 }
1422
Jorim Jaggife762342016-10-13 14:33:27 +02001423 boolean containsDismissKeyguardWindow() {
Bryce Lee081554b2017-05-25 07:52:12 -07001424 // Window state is transient during relaunch. We are not guaranteed to be frozen during the
1425 // entirety of the relaunch.
1426 if (isRelaunching()) {
1427 return mLastContainsDismissKeyguardWindow;
1428 }
1429
Jorim Jaggife762342016-10-13 14:33:27 +02001430 for (int i = mChildren.size() - 1; i >= 0; i--) {
1431 if ((mChildren.get(i).mAttrs.flags & FLAG_DISMISS_KEYGUARD) != 0) {
1432 return true;
1433 }
1434 }
1435 return false;
1436 }
1437
1438 boolean containsShowWhenLockedWindow() {
Bryce Lee081554b2017-05-25 07:52:12 -07001439 // When we are relaunching, it is possible for us to be unfrozen before our previous
1440 // windows have been added back. Using the cached value ensures that our previous
1441 // showWhenLocked preference is honored until relaunching is complete.
1442 if (isRelaunching()) {
1443 return mLastContainsShowWhenLockedWindow;
1444 }
1445
Jorim Jaggife762342016-10-13 14:33:27 +02001446 for (int i = mChildren.size() - 1; i >= 0; i--) {
1447 if ((mChildren.get(i).mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
1448 return true;
1449 }
1450 }
Bryce Lee081554b2017-05-25 07:52:12 -07001451
Jorim Jaggife762342016-10-13 14:33:27 +02001452 return false;
1453 }
1454
1455 void checkKeyguardFlagsChanged() {
1456 final boolean containsDismissKeyguard = containsDismissKeyguardWindow();
1457 final boolean containsShowWhenLocked = containsShowWhenLockedWindow();
1458 if (containsDismissKeyguard != mLastContainsDismissKeyguardWindow
1459 || containsShowWhenLocked != mLastContainsShowWhenLockedWindow) {
1460 mService.notifyKeyguardFlagsChanged(null /* callback */);
1461 }
1462 mLastContainsDismissKeyguardWindow = containsDismissKeyguard;
1463 mLastContainsShowWhenLockedWindow = containsShowWhenLocked;
1464 }
1465
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001466 WindowState getImeTargetBelowWindow(WindowState w) {
1467 final int index = mChildren.indexOf(w);
1468 if (index > 0) {
1469 final WindowState target = mChildren.get(index - 1);
1470 if (target.canBeImeTarget()) {
1471 return target;
1472 }
1473 }
1474 return null;
1475 }
1476
Winson Chungbe9be7f2017-06-28 10:55:22 -07001477 int getLowestAnimLayer() {
1478 for (int i = 0; i < mChildren.size(); i++) {
1479 final WindowState w = mChildren.get(i);
1480 if (w.mRemoved) {
1481 continue;
1482 }
1483 return w.mWinAnimator.mAnimLayer;
1484 }
1485 return Integer.MAX_VALUE;
1486 }
1487
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001488 WindowState getHighestAnimLayerWindow(WindowState currentTarget) {
1489 WindowState candidate = null;
1490 for (int i = mChildren.indexOf(currentTarget); i >= 0; i--) {
1491 final WindowState w = mChildren.get(i);
1492 if (w.mRemoved) {
1493 continue;
1494 }
1495 if (candidate == null || w.mWinAnimator.mAnimLayer >
1496 candidate.mWinAnimator.mAnimLayer) {
1497 candidate = w;
1498 }
1499 }
1500 return candidate;
1501 }
1502
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001503 /**
1504 * See {@link Activity#setDisablePreviewScreenshots}.
1505 */
1506 void setDisablePreviewScreenshots(boolean disable) {
Wale Ogunwale6c459212017-05-17 08:56:03 -07001507 mDisablePreviewScreenshots = disable;
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001508 }
1509
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001510 /**
chaviwd3bf08d2017-08-01 17:24:59 -07001511 * Sets whether the current launch can turn the screen on. See {@link #canTurnScreenOn()}
1512 */
1513 void setCanTurnScreenOn(boolean canTurnScreenOn) {
1514 mCanTurnScreenOn = canTurnScreenOn;
1515 }
1516
1517 /**
1518 * Indicates whether the current launch can turn the screen on. This is to prevent multiple
1519 * relayouts from turning the screen back on. The screen should only turn on at most
1520 * once per activity resume.
1521 *
1522 * @return true if the screen can be turned on.
1523 */
1524 boolean canTurnScreenOn() {
1525 return mCanTurnScreenOn;
1526 }
1527
1528 /**
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001529 * Retrieves whether we'd like to generate a snapshot that's based solely on the theme. This is
1530 * the case when preview screenshots are disabled {@link #setDisablePreviewScreenshots} or when
1531 * we can't take a snapshot for other reasons, for example, if we have a secure window.
1532 *
1533 * @return True if we need to generate an app theme snapshot, false if we'd like to take a real
1534 * screenshot.
1535 */
1536 boolean shouldUseAppThemeSnapshot() {
Wale Ogunwale6c459212017-05-17 08:56:03 -07001537 return mDisablePreviewScreenshots || forAllWindows(w -> (w.mAttrs.flags & FLAG_SECURE) != 0,
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001538 true /* topToBottom */);
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001539 }
1540
chaviw23ee71c2017-12-18 11:29:41 -08001541 @Override
Jorim Jaggi596a1992017-12-29 14:48:02 +01001542 public SurfaceControl getAnimationLeashParent() {
1543 return getAppAnimationLayer();
chaviw23ee71c2017-12-18 11:29:41 -08001544 }
1545
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001546 boolean applyAnimationLocked(WindowManager.LayoutParams lp, int transit, boolean enter,
1547 boolean isVoiceInteraction) {
1548
1549 if (mService.mDisableTransitionAnimation) {
1550 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1551 Slog.v(TAG_WM, "applyAnimation: transition animation is disabled. atoken=" + this);
1552 }
1553 cancelAnimation();
1554 return false;
1555 }
1556
1557 // Only apply an animation if the display isn't frozen. If it is frozen, there is no reason
1558 // to animate and it can cause strange artifacts when we unfreeze the display if some
1559 // different animation is running.
1560 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "AWT#applyAnimationLocked");
1561 if (okToAnimate()) {
1562 final Animation a = loadAnimation(lp, transit, enter, isVoiceInteraction);
1563 if (a != null) {
chaviw23ee71c2017-12-18 11:29:41 -08001564 final TaskStack stack = getStack();
1565 mTmpPoint.set(0, 0);
chaviw23012112017-12-20 15:29:04 -08001566 mTmpRect.setEmpty();
chaviw23ee71c2017-12-18 11:29:41 -08001567 if (stack != null) {
1568 stack.getRelativePosition(mTmpPoint);
chaviw23012112017-12-20 15:29:04 -08001569 stack.getBounds(mTmpRect);
chaviw977482a2017-12-28 11:35:53 -08001570 mTmpRect.offsetTo(0, 0);
chaviw23ee71c2017-12-18 11:29:41 -08001571 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001572 final AnimationAdapter adapter = new LocalAnimationAdapter(
chaviw23012112017-12-20 15:29:04 -08001573 new WindowAnimationSpec(a, mTmpPoint, mTmpRect,
1574 mService.mAppTransition.canSkipFirstFrame(),
1575 mService.mAppTransition.getAppStackClipMode()),
Jorim Jaggi2e3c31d2017-11-20 19:49:00 +01001576 mService.mSurfaceAnimationRunner);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001577 if (a.getZAdjustment() == Animation.ZORDER_TOP) {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001578 mNeedsZBoost = true;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001579 }
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001580 startAnimation(getPendingTransaction(), adapter, !isVisible());
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001581 mTransit = transit;
1582 mTransitFlags = mService.mAppTransition.getTransitFlags();
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001583 }
1584 } else {
1585 cancelAnimation();
1586 }
1587 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
1588
1589 return isReallyAnimating();
1590 }
1591
1592 private Animation loadAnimation(WindowManager.LayoutParams lp, int transit, boolean enter,
1593 boolean isVoiceInteraction) {
1594 final DisplayContent displayContent = getTask().getDisplayContent();
1595 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
1596 final int width = displayInfo.appWidth;
1597 final int height = displayInfo.appHeight;
1598 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG_WM,
1599 "applyAnimation: atoken=" + this);
1600
1601 // Determine the visible rect to calculate the thumbnail clip
1602 final WindowState win = findMainWindow();
1603 final Rect frame = new Rect(0, 0, width, height);
1604 final Rect displayFrame = new Rect(0, 0,
1605 displayInfo.logicalWidth, displayInfo.logicalHeight);
1606 final Rect insets = new Rect();
1607 final Rect stableInsets = new Rect();
1608 Rect surfaceInsets = null;
1609 final boolean freeform = win != null && win.inFreeformWindowingMode();
1610 if (win != null) {
1611 // Containing frame will usually cover the whole screen, including dialog windows.
1612 // For freeform workspace windows it will not cover the whole screen and it also
1613 // won't exactly match the final freeform window frame (e.g. when overlapping with
1614 // the status bar). In that case we need to use the final frame.
1615 if (freeform) {
1616 frame.set(win.mFrame);
1617 } else {
1618 frame.set(win.mContainingFrame);
1619 }
1620 surfaceInsets = win.getAttrs().surfaceInsets;
1621 insets.set(win.mContentInsets);
1622 stableInsets.set(win.mStableInsets);
1623 }
1624
1625 if (mLaunchTaskBehind) {
1626 // Differentiate the two animations. This one which is briefly on the screen
1627 // gets the !enter animation, and the other activity which remains on the
1628 // screen gets the enter animation. Both appear in the mOpeningApps set.
1629 enter = false;
1630 }
1631 if (DEBUG_APP_TRANSITIONS) Slog.d(TAG_WM, "Loading animation for app transition."
1632 + " transit=" + AppTransition.appTransitionToString(transit) + " enter=" + enter
1633 + " frame=" + frame + " insets=" + insets + " surfaceInsets=" + surfaceInsets);
1634 final Configuration displayConfig = displayContent.getConfiguration();
1635 final Animation a = mService.mAppTransition.loadAnimation(lp, transit, enter,
1636 displayConfig.uiMode, displayConfig.orientation, frame, displayFrame, insets,
1637 surfaceInsets, stableInsets, isVoiceInteraction, freeform, getTask().mTaskId);
1638 if (a != null) {
1639 if (DEBUG_ANIM) logWithStack(TAG, "Loaded animation " + a + " for " + this);
1640 final int containingWidth = frame.width();
1641 final int containingHeight = frame.height();
1642 a.initialize(containingWidth, containingHeight, width, height);
1643 a.scaleCurrentDuration(mService.getTransitionAnimationScaleLocked());
1644 }
1645 return a;
1646 }
1647
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001648 @Override
1649 protected void setLayer(Transaction t, int layer) {
1650 if (!mSurfaceAnimator.hasLeash()) {
1651 t.setLayer(mSurfaceControl, layer);
1652 }
1653 }
1654
1655 @Override
1656 protected void setRelativeLayer(Transaction t, SurfaceControl relativeTo, int layer) {
1657 if (!mSurfaceAnimator.hasLeash()) {
1658 t.setRelativeLayer(mSurfaceControl, relativeTo, layer);
1659 }
1660 }
1661
1662 @Override
1663 protected void reparentSurfaceControl(Transaction t, SurfaceControl newParent) {
1664 if (!mSurfaceAnimator.hasLeash()) {
1665 t.reparent(mSurfaceControl, newParent.getHandle());
1666 }
1667 }
1668
1669 @Override
1670 public void onAnimationLeashCreated(Transaction t, SurfaceControl leash) {
1671
1672 // The leash is parented to the animation layer. We need to preserve the z-order by using
1673 // the prefix order index, but we boost if necessary.
1674 int layer = getPrefixOrderIndex();
1675 if (mNeedsZBoost) {
1676 layer += Z_BOOST_BASE;
1677 }
1678 leash.setLayer(layer);
1679 }
1680
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001681 /**
1682 * This must be called while inside a transaction.
1683 */
1684 void showAllWindowsLocked() {
1685 forAllWindows(windowState -> {
1686 if (DEBUG_VISIBILITY) Slog.v(TAG, "performing show on: " + windowState);
1687 windowState.performShowLocked();
1688 }, false /* traverseTopToBottom */);
Jorim Jaggia5e10572017-11-15 14:36:26 +01001689 }
1690
1691 @Override
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001692 protected void onAnimationFinished() {
1693 super.onAnimationFinished();
1694
1695 mTransit = TRANSIT_UNSET;
1696 mTransitFlags = 0;
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001697 mNeedsZBoost = false;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001698
1699 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM | FINISH_LAYOUT_REDO_WALLPAPER,
1700 "AppWindowToken");
1701
Jorim Jaggi988f6682017-11-17 17:46:43 +01001702 clearThumbnail();
1703
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001704 if (mService.mInputMethodTarget != null && mService.mInputMethodTarget.mAppToken == this) {
1705 getDisplayContent().computeImeTarget(true /* updateImeTarget */);
1706 }
1707
1708 if (DEBUG_ANIM) Slog.v(TAG, "Animation done in " + this
1709 + ": reportedVisible=" + reportedVisible
1710 + " okToDisplay=" + okToDisplay()
1711 + " okToAnimate=" + okToAnimate()
1712 + " startingDisplayed=" + startingDisplayed);
1713
1714 // WindowState.onExitAnimationDone might modify the children list, so make a copy and then
1715 // traverse the copy.
1716 final ArrayList<WindowState> children = new ArrayList<>(mChildren);
1717 children.forEach(WindowState::onExitAnimationDone);
1718
1719 mService.mAppTransition.notifyAppTransitionFinishedLocked(token);
1720 scheduleAnimation();
1721 }
1722
1723 @Override
1724 boolean isAppAnimating() {
1725 return isSelfAnimating();
1726 }
1727
1728 @Override
1729 boolean isSelfAnimating() {
1730 // If we are about to start a transition, we also need to be considered animating.
1731 return isWaitingForTransitionStart() || isReallyAnimating();
1732 }
1733
1734 /**
1735 * @return True if and only if we are actually running an animation. Note that
1736 * {@link #isSelfAnimating} also returns true if we are waiting for an animation to
1737 * start.
1738 */
1739 private boolean isReallyAnimating() {
1740 return super.isSelfAnimating();
1741 }
1742
Jorim Jaggi988f6682017-11-17 17:46:43 +01001743 @Override
1744 void cancelAnimation() {
1745 super.cancelAnimation();
1746 clearThumbnail();
1747 }
1748
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001749 boolean isWaitingForTransitionStart() {
1750 return mService.mAppTransition.isTransitionSet()
1751 && (mService.mOpeningApps.contains(this) || mService.mClosingApps.contains(this));
1752 }
1753
1754 public int getTransit() {
1755 return mTransit;
1756 }
1757
1758 int getTransitFlags() {
1759 return mTransitFlags;
1760 }
1761
Jorim Jaggi988f6682017-11-17 17:46:43 +01001762 void attachThumbnailAnimation() {
1763 if (!isReallyAnimating()) {
1764 return;
1765 }
1766 final int taskId = getTask().mTaskId;
1767 final GraphicBuffer thumbnailHeader =
1768 mService.mAppTransition.getAppTransitionThumbnailHeader(taskId);
1769 if (thumbnailHeader == null) {
1770 if (DEBUG_APP_TRANSITIONS) Slog.d(TAG, "No thumbnail header bitmap for: " + taskId);
1771 return;
1772 }
1773 clearThumbnail();
1774 mThumbnail = new AppWindowThumbnail(getPendingTransaction(), this, thumbnailHeader);
1775 mThumbnail.startAnimation(getPendingTransaction(), loadThumbnailAnimation(thumbnailHeader));
1776 }
1777
Tony Mak64b8d562017-12-28 17:44:02 +00001778 /**
1779 * Attaches a surface with a thumbnail for the
1780 * {@link android.app.ActivityOptions#ANIM_OPEN_CROSS_PROFILE_APPS} animation.
1781 */
1782 void attachCrossProfileAppsThumbnailAnimation() {
1783 if (!isReallyAnimating()) {
1784 return;
1785 }
1786 clearThumbnail();
1787
1788 final WindowState win = findMainWindow();
1789 if (win == null) {
1790 return;
1791 }
1792 final Rect frame = win.mFrame;
1793 final int thumbnailDrawableRes = getTask().mUserId == mService.mCurrentUserId
1794 ? R.drawable.ic_account_circle
1795 : R.drawable.ic_corp_badge_no_background;
1796 final GraphicBuffer thumbnail =
1797 mService.mAppTransition
1798 .createCrossProfileAppsThumbnail(thumbnailDrawableRes, frame);
1799 if (thumbnail == null) {
1800 return;
1801 }
1802 mThumbnail = new AppWindowThumbnail(getPendingTransaction(), this, thumbnail);
1803 final Animation animation =
1804 mService.mAppTransition.createCrossProfileAppsThumbnailAnimationLocked(win.mFrame);
1805 mThumbnail.startAnimation(getPendingTransaction(), animation, new Point(frame.left,
1806 frame.top));
1807 }
1808
Jorim Jaggi988f6682017-11-17 17:46:43 +01001809 private Animation loadThumbnailAnimation(GraphicBuffer thumbnailHeader) {
1810 final DisplayInfo displayInfo = mDisplayContent.getDisplayInfo();
1811
1812 // If this is a multi-window scenario, we use the windows frame as
1813 // destination of the thumbnail header animation. If this is a full screen
1814 // window scenario, we use the whole display as the target.
1815 WindowState win = findMainWindow();
1816 Rect appRect = win != null ? win.getContentFrameLw() :
1817 new Rect(0, 0, displayInfo.appWidth, displayInfo.appHeight);
1818 Rect insets = win != null ? win.mContentInsets : null;
1819 final Configuration displayConfig = mDisplayContent.getConfiguration();
1820 return mService.mAppTransition.createThumbnailAspectScaleAnimationLocked(
1821 appRect, insets, thumbnailHeader, getTask().mTaskId, displayConfig.uiMode,
1822 displayConfig.orientation);
1823 }
1824
1825 private void clearThumbnail() {
1826 if (mThumbnail == null) {
1827 return;
1828 }
1829 mThumbnail.destroy();
1830 mThumbnail = null;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001831 }
1832
1833 @Override
1834 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
1835 super.dump(pw, prefix, dumpAll);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001836 if (appToken != null) {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001837 pw.println(prefix + "app=true mVoiceInteraction=" + mVoiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001838 }
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001839 pw.print(prefix); pw.print("task="); pw.println(getTask());
Wale Ogunwale51362492016-09-08 17:49:17 -07001840 pw.print(prefix); pw.print(" mFillsParent="); pw.print(mFillsParent);
1841 pw.print(" mOrientation="); pw.println(mOrientation);
Wale Ogunwale89973222017-04-23 18:39:45 -07001842 pw.println(prefix + "hiddenRequested=" + hiddenRequested + " mClientHidden=" + mClientHidden
1843 + ((mDeferHidingClient) ? " mDeferHidingClient=" + mDeferHidingClient : "")
1844 + " reportedDrawn=" + reportedDrawn + " reportedVisible=" + reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -07001845 if (paused) {
1846 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001847 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001848 if (mAppStopped) {
1849 pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped);
1850 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001851 if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001852 || allDrawn || mLastAllDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001853 pw.print(prefix); pw.print("mNumInterestingWindows=");
1854 pw.print(mNumInterestingWindows);
1855 pw.print(" mNumDrawnWindows="); pw.print(mNumDrawnWindows);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001856 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -07001857 pw.print(" allDrawn="); pw.print(allDrawn);
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001858 pw.print(" lastAllDrawn="); pw.print(mLastAllDrawn);
Craig Mautner6fbda632012-07-03 09:26:39 -07001859 pw.println(")");
1860 }
1861 if (inPendingTransaction) {
1862 pw.print(prefix); pw.print("inPendingTransaction=");
1863 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001864 }
Craig Mautner799bc1d2015-01-14 10:33:48 -08001865 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001866 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
1867 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -08001868 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -08001869 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001870 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001871 if (startingWindow != null || startingSurface != null
Wale Ogunwale6c459212017-05-17 08:56:03 -07001872 || startingDisplayed || startingMoved || mHiddenSetFromTransferredStartingWindow) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001873 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001874 pw.print(" startingSurface="); pw.print(startingSurface);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001875 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
Wale Ogunwale6c459212017-05-17 08:56:03 -07001876 pw.print(" startingMoved="); pw.print(startingMoved);
1877 pw.println(" mHiddenSetFromTransferredStartingWindow="
1878 + mHiddenSetFromTransferredStartingWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001879 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01001880 if (!mFrozenBounds.isEmpty()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -08001881 pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds);
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001882 pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig);
Chong Zhangd78ddb42016-03-02 17:01:14 -08001883 }
1884 if (mPendingRelaunchCount != 0) {
1885 pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount);
Jorim Jaggi0429f352015-12-22 16:29:16 +01001886 }
Wale Ogunwale9c64cb62017-04-12 13:39:59 -07001887 if (getController() != null) {
1888 pw.print(prefix); pw.print("controller="); pw.println(getController());
1889 }
Wale Ogunwalee287e192017-04-21 09:30:12 -07001890 if (mRemovingFromDisplay) {
1891 pw.println(prefix + "mRemovingFromDisplay=" + mRemovingFromDisplay);
1892 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001893 }
1894
1895 @Override
1896 void setHidden(boolean hidden) {
1897 super.setHidden(hidden);
Winson Chunge55c0192017-08-24 14:50:48 -07001898
1899 if (hidden) {
1900 // Once the app window is hidden, reset the last saved PiP snap fraction
1901 mDisplayContent.mPinnedStackControllerLocked.resetReentrySnapFraction(this);
1902 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001903 scheduleAnimation();
1904 }
1905
1906 @Override
1907 void prepareSurfaces() {
1908 // isSelfAnimating also returns true when we are about to start a transition, so we need
1909 // to check super here.
1910 final boolean reallyAnimating = super.isSelfAnimating();
1911 final boolean show = !isHidden() || reallyAnimating;
1912 if (show && !mLastSurfaceShowing) {
1913 mPendingTransaction.show(mSurfaceControl);
1914 } else if (!show && mLastSurfaceShowing) {
1915 mPendingTransaction.hide(mSurfaceControl);
Jorim Jaggi4d1835d2017-08-31 17:28:27 +02001916 }
Jorim Jaggi988f6682017-11-17 17:46:43 +01001917 if (mThumbnail != null) {
1918 mThumbnail.setShowing(mPendingTransaction, show);
1919 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001920 mLastSurfaceShowing = show;
1921 super.prepareSurfaces();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001922 }
1923
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001924 boolean isFreezingScreen() {
1925 return mFreezingScreen;
1926 }
1927
1928 @Override
1929 boolean needsZBoost() {
1930 return mNeedsZBoost || super.needsZBoost();
1931 }
1932
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07001933 @CallSuper
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001934 @Override
Adrian Roos4921ccf2017-09-28 16:54:06 +02001935 public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07001936 final long token = proto.start(fieldId);
1937 writeNameToProto(proto, NAME);
Adrian Roos4921ccf2017-09-28 16:54:06 +02001938 super.writeToProto(proto, WINDOW_TOKEN, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07001939 proto.end(token);
1940 }
1941
1942 void writeNameToProto(ProtoOutputStream proto, long fieldId) {
1943 if (appToken == null) {
1944 return;
1945 }
1946 try {
1947 proto.write(fieldId, appToken.getName());
1948 } catch (RemoteException e) {
1949 // This shouldn't happen, but in this case fall back to outputting nothing
1950 Slog.e(TAG, e.toString());
1951 }
1952 }
1953
1954 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001955 public String toString() {
1956 if (stringName == null) {
1957 StringBuilder sb = new StringBuilder();
1958 sb.append("AppWindowToken{");
1959 sb.append(Integer.toHexString(System.identityHashCode(this)));
1960 sb.append(" token="); sb.append(token); sb.append('}');
1961 stringName = sb.toString();
1962 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001963 return stringName + ((mIsExiting) ? " mIsExiting=" : "");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001964 }
Jeff Browne9bdb312012-04-05 15:30:10 -07001965}