blob: 9f9ca8f2643c32c86a197d0f4d2355481a2ecc70 [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_FULLSCREEN;
20import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
21import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;
Wale Ogunwale72919d22016-12-08 18:58:50 -080022import static android.content.pm.ActivityInfo.CONFIG_ORIENTATION;
23import static android.content.pm.ActivityInfo.CONFIG_SCREEN_SIZE;
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -070024import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND;
Wale Ogunwale51362492016-09-08 17:49:17 -070025import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET;
Jorim Jaggif5f9e122017-10-24 18:21:09 +020026import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070027import static android.view.Display.DEFAULT_DISPLAY;
Jorim Jaggife762342016-10-13 14:33:27 +020028import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
Jorim Jaggid635a4a2017-05-03 15:21:26 +020029import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
Jorim Jaggife762342016-10-13 14:33:27 +020030import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
Wale Ogunwaled1c37912016-08-16 03:19:39 -070031import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080032import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070033import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
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;
Winson Chunge55c0192017-08-24 14:50:48 -070059import android.app.WindowConfiguration.WindowingMode;
Jorim Jaggi26c8c422016-05-09 19:57:25 -070060import android.content.res.Configuration;
Jorim Jaggi988f6682017-11-17 17:46:43 +010061import android.graphics.GraphicBuffer;
Jorim Jaggif5f9e122017-10-24 18:21:09 +020062import android.graphics.Point;
Jorim Jaggi0429f352015-12-22 16:29:16 +010063import android.graphics.Rect;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070064import android.os.Binder;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080065import android.os.Debug;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070066import android.os.IBinder;
Steven Timotiusaf03df62017-07-18 16:56:43 -070067import android.os.RemoteException;
Jorim Jaggif5f9e122017-10-24 18:21:09 +020068import android.os.Trace;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080069import android.util.Slog;
Steven Timotiusaf03df62017-07-18 16:56:43 -070070import android.util.proto.ProtoOutputStream;
Jorim Jaggif5f9e122017-10-24 18:21:09 +020071import android.view.DisplayInfo;
Jorim Jaggi619c9f72017-12-19 18:04:29 +010072import android.view.SurfaceControl.Transaction;
Jorim Jaggif5f9e122017-10-24 18:21:09 +020073import android.view.animation.Animation;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080074import android.view.IApplicationToken;
Robert Carr6914f082017-03-20 19:04:30 -070075import android.view.SurfaceControl;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080076import android.view.WindowManager;
Jorim Jaggi87fdbcb2017-08-17 13:41:11 +020077import android.view.WindowManager.LayoutParams;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080078
79import 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.
652 // TODO: Not sure why this is needed.
653 final LinkedList<WindowState> children = new LinkedList<>(mChildren);
654 for (int i = children.size() - 1; i >= 0; i--) {
655 final WindowState win = children.get(i);
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700656 destroyedSomething |= win.destroySurface(cleanupOnResume, mAppStopped);
Robert Carre12aece2016-02-02 22:43:27 -0800657 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700658 if (destroyedSomething) {
659 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700660 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Robert Carre12aece2016-02-02 22:43:27 -0800661 }
662 }
663
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800664 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700665 * Notify that the app is now resumed, and it was not stopped before, perform a clean
666 * up of the surfaces
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800667 */
Jorim Jaggibae01b12017-04-11 16:29:10 -0700668 void notifyAppResumed(boolean wasStopped) {
Chong Zhangad24f962016-08-25 12:12:33 -0700669 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped
Jorim Jaggibae01b12017-04-11 16:29:10 -0700670 + " " + this);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700671 mAppStopped = false;
chaviwd3bf08d2017-08-01 17:24:59 -0700672 // Allow the window to turn the screen on once the app is resumed again.
673 setCanTurnScreenOn(true);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700674 if (!wasStopped) {
675 destroySurfaces(true /*cleanupOnResume*/);
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800676 }
Robert Carre12aece2016-02-02 22:43:27 -0800677 }
678
Chong Zhangbef461f2015-10-27 11:38:24 -0700679 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700680 * Notify that the app has stopped, and it is okay to destroy any surfaces which were
681 * keeping alive in case they were still being used.
682 */
683 void notifyAppStopped() {
684 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this);
685 mAppStopped = true;
686 destroySurfaces();
687 // Remove any starting window that was added for this app if they are still around.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800688 if (getController() != null) {
689 getController().removeStartingWindow();
690 }
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700691 }
692
Chong Zhang92147042016-05-09 12:47:11 -0700693 void clearAllDrawn() {
694 allDrawn = false;
695 deferClearAllDrawn = false;
Chong Zhangbef461f2015-10-27 11:38:24 -0700696 }
697
Bryce Lee6d410262017-02-28 15:30:17 -0800698 Task getTask() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800699 return (Task) getParent();
Bryce Lee6d410262017-02-28 15:30:17 -0800700 }
701
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800702 TaskStack getStack() {
703 final Task task = getTask();
704 if (task != null) {
705 return task.mStack;
706 } else {
707 return null;
708 }
709 }
710
Bryce Lee6d410262017-02-28 15:30:17 -0800711 @Override
712 void onParentSet() {
713 super.onParentSet();
714
Robert Carred3e83b2017-04-21 13:26:55 -0700715 final Task task = getTask();
716
Bryce Lee6d410262017-02-28 15:30:17 -0800717 // When the associated task is {@code null}, the {@link AppWindowToken} can no longer
718 // access visual elements like the {@link DisplayContent}. We must remove any associations
719 // such as animations.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800720 if (!mReparenting) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800721 if (task == null) {
722 // It is possible we have been marked as a closing app earlier. We must remove ourselves
723 // from this list so we do not participate in any future animations.
724 mService.mClosingApps.remove(this);
Robert Carred3e83b2017-04-21 13:26:55 -0700725 } else if (mLastParent != null && mLastParent.mStack != null) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800726 task.mStack.mExitingAppTokens.remove(this);
727 }
Bryce Lee6d410262017-02-28 15:30:17 -0800728 }
Robert Carred3e83b2017-04-21 13:26:55 -0700729 mLastParent = task;
Bryce Lee6d410262017-02-28 15:30:17 -0800730 }
731
Wale Ogunwalefa854eb2016-09-20 13:43:52 -0700732 void postWindowRemoveStartingWindowCleanup(WindowState win) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700733 // TODO: Something smells about the code below...Is there a better way?
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700734 if (startingWindow == win) {
735 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800736 if (getController() != null) {
737 getController().removeStartingWindow();
738 }
Wale Ogunwale6c459212017-05-17 08:56:03 -0700739 } else if (mChildren.size() == 0) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700740 // If this is the last window and we had requested a starting transition window,
741 // well there is no point now.
Jorim Jaggi02886a82016-12-06 09:10:06 -0800742 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingData");
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700743 startingData = null;
Wale Ogunwale6c459212017-05-17 08:56:03 -0700744 if (mHiddenSetFromTransferredStartingWindow) {
745 // We set the hidden state to false for the token from a transferred starting window.
746 // We now reset it back to true since the starting window was the last window in the
747 // token.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200748 setHidden(true);
Wale Ogunwale6c459212017-05-17 08:56:03 -0700749 }
Jorim Jaggi829b9cd2017-01-23 16:20:53 +0100750 } else if (mChildren.size() == 1 && startingSurface != null && !isRelaunching()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700751 // If this is the last window except for a starting transition window,
752 // we need to get rid of the starting transition.
Jorim Jaggie4b0f282017-05-17 15:10:29 +0200753 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Last window, removing starting window "
754 + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800755 if (getController() != null) {
756 getController().removeStartingWindow();
757 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700758 }
759 }
760
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700761 void removeDeadWindows() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700762 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700763 WindowState win = mChildren.get(winNdx);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800764 if (win.mAppDied) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700765 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700766 "removeDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800767 // Set mDestroying, we don't want any animation or delayed removal here.
768 win.mDestroying = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700769 // Also removes child windows.
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700770 win.removeIfPossible();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800771 }
772 }
773 }
774
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700775 boolean hasWindowsAlive() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700776 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700777 // No need to loop through child windows as the answer should be the same as that of the
778 // parent window.
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700779 if (!(mChildren.get(i)).mAppDied) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700780 return true;
781 }
782 }
783 return false;
784 }
785
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700786 void setWillReplaceWindows(boolean animate) {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700787 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
788 "Marking app token " + this + " with replacing windows.");
Robert Carra1eb4392015-12-10 12:43:51 -0800789
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700790 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700791 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700792 w.setWillReplaceWindow(animate);
Robert Carra1eb4392015-12-10 12:43:51 -0800793 }
Robert Carra1eb4392015-12-10 12:43:51 -0800794 }
795
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700796 void setWillReplaceChildWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700797 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this
Robert Carr23fa16b2016-01-13 13:19:58 -0800798 + " with replacing child windows.");
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700799 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700800 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700801 w.setWillReplaceChildWindows();
Robert Carr23fa16b2016-01-13 13:19:58 -0800802 }
803 }
804
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700805 void clearWillReplaceWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700806 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
807 "Resetting app token " + this + " of replacing window marks.");
Chong Zhangf596cd52016-01-05 13:42:44 -0800808
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700809 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700810 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700811 w.clearWillReplaceWindow();
Chong Zhangf596cd52016-01-05 13:42:44 -0800812 }
813 }
814
Chong Zhang4d7369a2016-04-25 16:09:14 -0700815 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700816 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700817 final WindowState w = mChildren.get(i);
Chong Zhang4d7369a2016-04-25 16:09:14 -0700818 w.requestUpdateWallpaperIfNeeded();
819 }
820 }
821
Chong Zhangd78ddb42016-03-02 17:01:14 -0800822 boolean isRelaunching() {
823 return mPendingRelaunchCount > 0;
824 }
825
Robert Carr68375192017-06-13 12:41:53 -0700826 boolean shouldFreezeBounds() {
827 final Task task = getTask();
828
829 // For freeform windows, we can't freeze the bounds at the moment because this would make
830 // the resizing unresponsive.
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700831 if (task == null || task.inFreeformWindowingMode()) {
Robert Carr68375192017-06-13 12:41:53 -0700832 return false;
833 }
834
835 // We freeze the bounds while drag resizing to deal with the time between
836 // the divider/drag handle being released, and the handling it's new
837 // configuration. If we are relaunched outside of the drag resizing state,
838 // we need to be careful not to do this.
839 return getTask().isDragResizing();
840 }
841
Chong Zhangd78ddb42016-03-02 17:01:14 -0800842 void startRelaunching() {
Robert Carr68375192017-06-13 12:41:53 -0700843 if (shouldFreezeBounds()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -0800844 freezeBounds();
845 }
Robert Carrd5c7dd62017-03-08 10:39:30 -0800846
847 // In the process of tearing down before relaunching, the app will
848 // try and clean up it's child surfaces. We need to prevent this from
849 // happening, so we sever the children, transfering their ownership
850 // from the client it-self to the parent surface (owned by us).
851 for (int i = mChildren.size() - 1; i >= 0; i--) {
852 final WindowState w = mChildren.get(i);
853 w.mWinAnimator.detachChildren();
854 }
855
Chong Zhangd78ddb42016-03-02 17:01:14 -0800856 mPendingRelaunchCount++;
857 }
858
859 void finishRelaunching() {
Robert Carr68375192017-06-13 12:41:53 -0700860 unfreezeBounds();
861
Chong Zhangd78ddb42016-03-02 17:01:14 -0800862 if (mPendingRelaunchCount > 0) {
863 mPendingRelaunchCount--;
Bryce Lee081554b2017-05-25 07:52:12 -0700864 } else {
865 // Update keyguard flags upon finishing relaunch.
866 checkKeyguardFlagsChanged();
Chong Zhangd78ddb42016-03-02 17:01:14 -0800867 }
868 }
869
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700870 void clearRelaunching() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700871 if (mPendingRelaunchCount == 0) {
872 return;
873 }
Robert Carr68375192017-06-13 12:41:53 -0700874 unfreezeBounds();
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700875 mPendingRelaunchCount = 0;
876 }
877
Wale Ogunwale07bcab72016-10-14 15:30:09 -0700878 /**
879 * Returns true if the new child window we are adding to this token is considered greater than
880 * the existing child window in this token in terms of z-order.
881 */
882 @Override
883 protected boolean isFirstChildWindowGreaterThanSecond(WindowState newWindow,
884 WindowState existingWindow) {
885 final int type1 = newWindow.mAttrs.type;
886 final int type2 = existingWindow.mAttrs.type;
887
888 // Base application windows should be z-ordered BELOW all other windows in the app token.
889 if (type1 == TYPE_BASE_APPLICATION && type2 != TYPE_BASE_APPLICATION) {
890 return false;
891 } else if (type1 != TYPE_BASE_APPLICATION && type2 == TYPE_BASE_APPLICATION) {
892 return true;
893 }
894
895 // Starting windows should be z-ordered ABOVE all other windows in the app token.
896 if (type1 == TYPE_APPLICATION_STARTING && type2 != TYPE_APPLICATION_STARTING) {
897 return true;
898 } else if (type1 != TYPE_APPLICATION_STARTING && type2 == TYPE_APPLICATION_STARTING) {
899 return false;
900 }
901
902 // Otherwise the new window is greater than the existing window.
903 return true;
904 }
905
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700906 @Override
Robert Carra1eb4392015-12-10 12:43:51 -0800907 void addWindow(WindowState w) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700908 super.addWindow(w);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700909
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700910 boolean gotReplacementWindow = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700911 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700912 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700913 gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w);
914 }
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700915
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700916 // if we got a replacement window, reset the timeout to give drawing more time
917 if (gotReplacementWindow) {
918 mService.scheduleWindowReplacementTimeouts(this);
Robert Carra1eb4392015-12-10 12:43:51 -0800919 }
Jorim Jaggife762342016-10-13 14:33:27 +0200920 checkKeyguardFlagsChanged();
921 }
922
923 @Override
924 void removeChild(WindowState child) {
925 super.removeChild(child);
926 checkKeyguardFlagsChanged();
Robert Carra1eb4392015-12-10 12:43:51 -0800927 }
928
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700929 private boolean waitingForReplacement() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700930 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700931 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700932 if (candidate.waitingForReplacement()) {
Robert Carra1eb4392015-12-10 12:43:51 -0800933 return true;
934 }
935 }
936 return false;
937 }
938
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700939 void onWindowReplacementTimeout() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700940 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700941 (mChildren.get(i)).onWindowReplacementTimeout();
Robert Carra1eb4392015-12-10 12:43:51 -0800942 }
943 }
944
Winson Chung30480042017-01-26 10:55:34 -0800945 void reparent(Task task, int position) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800946 final Task currentTask = getTask();
947 if (task == currentTask) {
Winson Chung30480042017-01-26 10:55:34 -0800948 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800949 "window token=" + this + " already child of task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -0800950 }
Bryce Lee6d410262017-02-28 15:30:17 -0800951
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800952 if (currentTask.mStack != task.mStack) {
Bryce Lee6d410262017-02-28 15:30:17 -0800953 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800954 "window token=" + this + " current task=" + currentTask
Bryce Lee6d410262017-02-28 15:30:17 -0800955 + " belongs to a different stack than " + task);
956 }
957
Winson Chung30480042017-01-26 10:55:34 -0800958 if (DEBUG_ADD_REMOVE) Slog.i(TAG, "reParentWindowToken: removing window token=" + this
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800959 + " from task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -0800960 final DisplayContent prevDisplayContent = getDisplayContent();
961
Bryce Lee6d410262017-02-28 15:30:17 -0800962 mReparenting = true;
963
Winson Chung30480042017-01-26 10:55:34 -0800964 getParent().removeChild(this);
965 task.addChild(this, position);
966
Bryce Lee6d410262017-02-28 15:30:17 -0800967 mReparenting = false;
968
Winson Chung30480042017-01-26 10:55:34 -0800969 // Relayout display(s).
970 final DisplayContent displayContent = task.getDisplayContent();
971 displayContent.setLayoutNeeded();
972 if (prevDisplayContent != displayContent) {
973 onDisplayChanged(displayContent);
974 prevDisplayContent.setLayoutNeeded();
975 }
976 }
977
Jorim Jaggi0429f352015-12-22 16:29:16 +0100978 /**
979 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
980 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
981 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
982 * with a queue.
983 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800984 private void freezeBounds() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800985 final Task task = getTask();
986 mFrozenBounds.offer(new Rect(task.mPreparedFrozenBounds));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700987
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800988 if (task.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) {
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700989 // We didn't call prepareFreezingBounds on the task, so use the current value.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800990 mFrozenMergedConfig.offer(new Configuration(task.getConfiguration()));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700991 } else {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800992 mFrozenMergedConfig.offer(new Configuration(task.mPreparedFrozenMergedConfig));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700993 }
Andrii Kulianb10330d2016-09-16 13:51:46 -0700994 // Calling unset() to make it equal to Configuration.EMPTY.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800995 task.mPreparedFrozenMergedConfig.unset();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100996 }
997
998 /**
999 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
1000 */
Chong Zhangd78ddb42016-03-02 17:01:14 -08001001 private void unfreezeBounds() {
Robert Carr68375192017-06-13 12:41:53 -07001002 if (mFrozenBounds.isEmpty()) {
1003 return;
Wale Ogunwale37dbafc2016-06-27 10:15:20 -07001004 }
Robert Carr68375192017-06-13 12:41:53 -07001005 mFrozenBounds.remove();
Wale Ogunwale37dbafc2016-06-27 10:15:20 -07001006 if (!mFrozenMergedConfig.isEmpty()) {
1007 mFrozenMergedConfig.remove();
1008 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001009 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001010 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001011 win.onUnfreezeBounds();
Jorim Jaggi4846ee32016-01-07 17:39:12 +01001012 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001013 mService.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +01001014 }
1015
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001016 void setAppLayoutChanges(int changes, String reason) {
1017 if (!mChildren.isEmpty()) {
1018 final DisplayContent dc = getDisplayContent();
1019 dc.pendingLayoutChanges |= changes;
1020 if (DEBUG_LAYOUT_REPEATS) {
1021 mService.mWindowPlacerLocked.debugLayoutRepeats(reason, dc.pendingLayoutChanges);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001022 }
1023 }
1024 }
1025
1026 void removeReplacedWindowIfNeeded(WindowState replacement) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001027 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001028 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001029 if (win.removeReplacedWindowIfNeeded(replacement)) {
1030 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001031 }
1032 }
1033 }
1034
1035 void startFreezingScreen() {
1036 if (DEBUG_ORIENTATION) logWithStack(TAG, "Set freezing of " + appToken + ": hidden="
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001037 + isHidden() + " freezing=" + mFreezingScreen + " hiddenRequested="
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001038 + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001039 if (!hiddenRequested) {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001040 if (!mFreezingScreen) {
1041 mFreezingScreen = true;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001042 mService.registerAppFreezeListener(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001043 mService.mAppsFreezingScreen++;
1044 if (mService.mAppsFreezingScreen == 1) {
Bryce Lee8f853582017-06-05 17:25:59 -07001045 mService.startFreezingDisplayLocked(false, 0, 0, getDisplayContent());
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001046 mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT);
1047 mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001048 }
1049 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001050 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001051 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001052 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001053 w.onStartFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001054 }
1055 }
1056 }
1057
1058 void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001059 if (!mFreezingScreen) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001060 return;
1061 }
1062 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + this + " force=" + force);
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001063 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001064 boolean unfrozeWindows = false;
1065 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001066 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001067 unfrozeWindows |= w.onStopFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001068 }
1069 if (force || unfrozeWindows) {
1070 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this);
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001071 mFreezingScreen = false;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001072 mService.unregisterAppFreezeListener(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001073 mService.mAppsFreezingScreen--;
1074 mService.mLastFinishedFreezeSource = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001075 }
1076 if (unfreezeSurfaceNow) {
1077 if (unfrozeWindows) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001078 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001079 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001080 mService.stopFreezingDisplayLocked();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001081 }
1082 }
1083
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001084 @Override
1085 public void onAppFreezeTimeout() {
1086 Slog.w(TAG_WM, "Force clearing freeze: " + this);
1087 stopFreezingScreen(true, true);
1088 }
1089
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001090 boolean transferStartingWindow(IBinder transferFrom) {
Wale Ogunwale02319a62016-09-26 15:21:22 -07001091 final AppWindowToken fromToken = getDisplayContent().getAppWindowToken(transferFrom);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001092 if (fromToken == null) {
1093 return false;
1094 }
1095
1096 final WindowState tStartingWindow = fromToken.startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001097 if (tStartingWindow != null && fromToken.startingSurface != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001098 // In this case, the starting icon has already been displayed, so start
1099 // letting windows get shown immediately without any more transitions.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001100 mService.mSkipAppTransitionAnimation = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001101
1102 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow
1103 + " from " + fromToken + " to " + this);
1104
1105 final long origId = Binder.clearCallingIdentity();
Peter Visontay3556a3b2017-11-01 17:23:17 +00001106 try {
1107 // Transfer the starting window over to the new token.
1108 startingData = fromToken.startingData;
1109 startingSurface = fromToken.startingSurface;
1110 startingDisplayed = fromToken.startingDisplayed;
1111 fromToken.startingDisplayed = false;
1112 startingWindow = tStartingWindow;
1113 reportedVisible = fromToken.reportedVisible;
1114 fromToken.startingData = null;
1115 fromToken.startingSurface = null;
1116 fromToken.startingWindow = null;
1117 fromToken.startingMoved = true;
1118 tStartingWindow.mToken = this;
1119 tStartingWindow.mAppToken = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001120
Peter Visontay3556a3b2017-11-01 17:23:17 +00001121 if (DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1122 "Removing starting " + tStartingWindow + " from " + fromToken);
1123 fromToken.removeChild(tStartingWindow);
1124 fromToken.postWindowRemoveStartingWindowCleanup(tStartingWindow);
1125 fromToken.mHiddenSetFromTransferredStartingWindow = false;
1126 addWindow(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001127
Peter Visontay3556a3b2017-11-01 17:23:17 +00001128 // Propagate other interesting state between the tokens. If the old token is displayed,
1129 // we should immediately force the new one to be displayed. If it is animating, we need
1130 // to move that animation to the new one.
1131 if (fromToken.allDrawn) {
1132 allDrawn = true;
1133 deferClearAllDrawn = fromToken.deferClearAllDrawn;
1134 }
1135 if (fromToken.firstWindowDrawn) {
1136 firstWindowDrawn = true;
1137 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001138 if (!fromToken.isHidden()) {
1139 setHidden(false);
Peter Visontay3556a3b2017-11-01 17:23:17 +00001140 hiddenRequested = false;
1141 mHiddenSetFromTransferredStartingWindow = true;
1142 }
1143 setClientHidden(fromToken.mClientHidden);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001144
Jorim Jaggi980c9de2017-11-17 01:41:37 +01001145 transferAnimation(fromToken);
1146
1147 // When transferring an animation, we no longer need to apply an animation to the
1148 // the token we transfer the animation over. Thus, remove the animation from
1149 // pending opening apps.
1150 mService.mOpeningApps.remove(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001151
Peter Visontay3556a3b2017-11-01 17:23:17 +00001152 mService.updateFocusedWindowLocked(
1153 UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/);
1154 getDisplayContent().setLayoutNeeded();
1155 mService.mWindowPlacerLocked.performSurfacePlacement();
1156 } finally {
1157 Binder.restoreCallingIdentity(origId);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001158 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001159 return true;
1160 } else if (fromToken.startingData != null) {
1161 // The previous app was getting ready to show a
1162 // starting window, but hasn't yet done so. Steal it!
1163 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1164 "Moving pending starting from " + fromToken + " to " + this);
1165 startingData = fromToken.startingData;
1166 fromToken.startingData = null;
1167 fromToken.startingMoved = true;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001168 if (getController() != null) {
1169 getController().scheduleAddStartingWindow();
1170 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001171 return true;
1172 }
1173
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001174 // TODO: Transfer thumbnail
1175
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001176 return false;
1177 }
1178
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001179 boolean isLastWindow(WindowState win) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001180 return mChildren.size() == 1 && mChildren.get(0) == win;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001181 }
1182
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001183 @Override
1184 void onAppTransitionDone() {
1185 sendingToBottom = false;
1186 }
1187
Wale Ogunwale51362492016-09-08 17:49:17 -07001188 /**
1189 * We override because this class doesn't want its children affecting its reported orientation
1190 * in anyway.
1191 */
1192 @Override
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001193 int getOrientation(int candidate) {
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001194 if (candidate == SCREEN_ORIENTATION_BEHIND) {
1195 // Allow app to specify orientation regardless of its visibility state if the current
1196 // candidate want us to use orientation behind. I.e. the visible app on-top of this one
1197 // wants us to use the orientation of the app behind it.
1198 return mOrientation;
1199 }
1200
Bryce Lee61fbcbc2017-03-10 14:14:03 -08001201 // The {@link AppWindowToken} should only specify an orientation when it is not closing or
1202 // going to the bottom. Allowing closing {@link AppWindowToken} to participate can lead to
1203 // an Activity in another task being started in the wrong orientation during the transition.
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001204 if (!(sendingToBottom || mService.mClosingApps.contains(this))
Bryce Lee00d586d2017-07-28 20:48:43 -07001205 && (isVisible() || mService.mOpeningApps.contains(this) || isOnTop())) {
Bryce Leea163b762017-01-24 11:05:01 -08001206 return mOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001207 }
Bryce Leea163b762017-01-24 11:05:01 -08001208
1209 return SCREEN_ORIENTATION_UNSET;
Wale Ogunwale51362492016-09-08 17:49:17 -07001210 }
1211
Wale Ogunwaleb198b742016-12-01 08:44:09 -08001212 /** Returns the app's preferred orientation regardless of its currently visibility state. */
1213 int getOrientationIgnoreVisibility() {
1214 return mOrientation;
1215 }
1216
Craig Mautnerdbb79912012-03-01 18:59:14 -08001217 @Override
Winson Chunge55c0192017-08-24 14:50:48 -07001218 public void onConfigurationChanged(Configuration newParentConfig) {
1219 final int prevWinMode = getWindowingMode();
1220 super.onConfigurationChanged(newParentConfig);
1221 final int winMode = getWindowingMode();
1222
1223 if (prevWinMode == winMode) {
1224 return;
1225 }
1226
1227 if (prevWinMode != WINDOWING_MODE_UNDEFINED && winMode == WINDOWING_MODE_PINNED) {
1228 // Entering PiP from fullscreen, reset the snap fraction
1229 mDisplayContent.mPinnedStackControllerLocked.resetReentrySnapFraction(this);
1230 } else if (prevWinMode == WINDOWING_MODE_PINNED && winMode != WINDOWING_MODE_UNDEFINED) {
1231 // Leaving PiP to fullscreen, save the snap fraction based on the pre-animation bounds
1232 // for the next re-entry into PiP (assuming the activity is not hidden or destroyed)
1233 final TaskStack pinnedStack = mDisplayContent.getPinnedStack();
1234 if (pinnedStack != null) {
1235 mDisplayContent.mPinnedStackControllerLocked.saveReentrySnapFraction(this,
1236 pinnedStack.mPreAnimationBounds);
1237 }
1238 }
1239 }
1240
1241 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001242 void checkAppWindowsReadyToShow() {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001243 if (allDrawn == mLastAllDrawn) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001244 return;
1245 }
1246
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001247 mLastAllDrawn = allDrawn;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001248 if (!allDrawn) {
1249 return;
1250 }
1251
1252 // The token has now changed state to having all windows shown... what to do, what to do?
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001253 if (mFreezingScreen) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001254 showAllWindowsLocked();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001255 stopFreezingScreen(false, true);
1256 if (DEBUG_ORIENTATION) Slog.i(TAG,
1257 "Setting mOrientationChangeComplete=true because wtoken " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001258 + " numInteresting=" + mNumInterestingWindows + " numDrawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001259 // This will set mOrientationChangeComplete and cause a pass through layout.
1260 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001261 "checkAppWindowsReadyToShow: freezingScreen");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001262 } else {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001263 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001264
1265 // We can now show all of the drawn windows!
1266 if (!mService.mOpeningApps.contains(this)) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001267 showAllWindowsLocked();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001268 }
1269 }
1270 }
1271
Matthew Ng5d23afa2017-06-21 16:16:24 -07001272 /**
Bryce Leed390deb2017-06-22 13:14:28 -07001273 * Returns whether the drawn window states of this {@link AppWindowToken} has considered every
1274 * child {@link WindowState}. A child is considered if it has been passed into
1275 * {@link #updateDrawnWindowStates(WindowState)} after being added. This is used to determine
1276 * whether states, such as {@code allDrawn}, can be set, which relies on state variables such as
1277 * {@code mNumInterestingWindows}, which depend on all {@link WindowState}s being considered.
1278 *
1279 * @return {@code true} If all children have been considered, {@code false}.
1280 */
1281 private boolean allDrawnStatesConsidered() {
Bryce Lee6311c4b2017-07-06 14:09:29 -07001282 for (int i = mChildren.size() - 1; i >= 0; --i) {
1283 final WindowState child = mChildren.get(i);
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001284 if (child.mightAffectAllDrawn() && !child.getDrawnStateEvaluated()) {
Bryce Leed390deb2017-06-22 13:14:28 -07001285 return false;
1286 }
1287 }
1288 return true;
1289 }
1290
1291 /**
Matthew Ng5d23afa2017-06-21 16:16:24 -07001292 * Determines if the token has finished drawing. This should only be called from
1293 * {@link DisplayContent#applySurfaceChangesTransaction}
1294 */
Matthew Ng498c71d2017-04-18 13:55:45 -07001295 void updateAllDrawn() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001296 if (!allDrawn) {
Matthew Ng498c71d2017-04-18 13:55:45 -07001297 // Number of drawn windows can be less when a window is being relaunched, wait for
Bryce Leed390deb2017-06-22 13:14:28 -07001298 // all windows to be launched and drawn for this token be considered all drawn.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001299 final int numInteresting = mNumInterestingWindows;
Bryce Leed390deb2017-06-22 13:14:28 -07001300
1301 // We must make sure that all present children have been considered (determined by
1302 // {@link #allDrawnStatesConsidered}) before evaluating whether everything has been
1303 // drawn.
1304 if (numInteresting > 0 && allDrawnStatesConsidered()
1305 && mNumDrawnWindows >= numInteresting && !isRelaunching()) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001306 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawn: " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001307 + " interesting=" + numInteresting + " drawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001308 allDrawn = true;
1309 // Force an additional layout pass where
1310 // WindowStateAnimator#commitFinishDrawingLocked() will call performShowLocked().
Matthew Ng498c71d2017-04-18 13:55:45 -07001311 if (mDisplayContent != null) {
1312 mDisplayContent.setLayoutNeeded();
1313 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001314 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Robert Carrecc06b32017-04-18 14:25:10 -07001315
Winson Chunge7ba6862017-05-24 12:13:33 -07001316 // Notify the pinned stack upon all windows drawn. If there was an animation in
1317 // progress then this signal will resume that animation.
Wale Ogunwale61911492017-10-11 08:50:50 -07001318 final TaskStack pinnedStack = mDisplayContent.getPinnedStack();
Winson Chunge7ba6862017-05-24 12:13:33 -07001319 if (pinnedStack != null) {
1320 pinnedStack.onAllWindowsDrawn();
Robert Carrecc06b32017-04-18 14:25:10 -07001321 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001322 }
1323 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001324 }
1325
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001326 /**
1327 * Updated this app token tracking states for interesting and drawn windows based on the window.
1328 *
1329 * @return Returns true if the input window is considered interesting and drawn while all the
1330 * windows in this app token where not considered drawn as of the last pass.
1331 */
1332 boolean updateDrawnWindowStates(WindowState w) {
Bryce Leed390deb2017-06-22 13:14:28 -07001333 w.setDrawnStateEvaluated(true /*evaluated*/);
1334
Jorim Jaggie4b0f282017-05-17 15:10:29 +02001335 if (DEBUG_STARTING_WINDOW_VERBOSE && w == startingWindow) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001336 Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" + w.isOnScreen()
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001337 + " allDrawn=" + allDrawn + " freezingScreen=" + mFreezingScreen);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001338 }
1339
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001340 if (allDrawn && !mFreezingScreen) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001341 return false;
1342 }
1343
1344 if (mLastTransactionSequence != mService.mTransactionSequence) {
1345 mLastTransactionSequence = mService.mTransactionSequence;
1346 mNumInterestingWindows = mNumDrawnWindows = 0;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001347 startingDisplayed = false;
1348 }
1349
1350 final WindowStateAnimator winAnimator = w.mWinAnimator;
1351
1352 boolean isInterestingAndDrawn = false;
1353
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001354 if (!allDrawn && w.mightAffectAllDrawn()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001355 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
1356 Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw()
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001357 + ", isAnimationSet=" + isSelfAnimating());
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001358 if (!w.isDrawnLw()) {
1359 Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController
1360 + " pv=" + w.mPolicyVisibility
1361 + " mDrawState=" + winAnimator.drawStateToString()
1362 + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001363 + " a=" + isSelfAnimating());
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001364 }
1365 }
1366
1367 if (w != startingWindow) {
1368 if (w.isInteresting()) {
1369 mNumInterestingWindows++;
1370 if (w.isDrawnLw()) {
1371 mNumDrawnWindows++;
1372
1373 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, "tokenMayBeDrawn: "
1374 + this + " w=" + w + " numInteresting=" + mNumInterestingWindows
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001375 + " freezingScreen=" + mFreezingScreen
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001376 + " mAppFreezing=" + w.mAppFreezing);
1377
1378 isInterestingAndDrawn = true;
1379 }
1380 }
1381 } else if (w.isDrawnLw()) {
Jorim Jaggi3878ca32017-02-02 17:13:05 -08001382 if (getController() != null) {
1383 getController().reportStartingWindowDrawn();
1384 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001385 startingDisplayed = true;
1386 }
1387 }
1388
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001389 return isInterestingAndDrawn;
1390 }
1391
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001392 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001393 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001394 // For legacy reasons we process the TaskStack.mExitingAppTokens first in DisplayContent
1395 // before the non-exiting app tokens. So, we skip the exiting app tokens here.
1396 // TODO: Investigate if we need to continue to do this or if we can just process them
1397 // in-order.
1398 if (mIsExiting && !waitingForReplacement()) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001399 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001400 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001401 return forAllWindowsUnchecked(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001402 }
1403
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001404 boolean forAllWindowsUnchecked(ToBooleanFunction<WindowState> callback,
1405 boolean traverseTopToBottom) {
1406 return super.forAllWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001407 }
1408
1409 @Override
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001410 AppWindowToken asAppWindowToken() {
1411 // I am an app window token!
1412 return this;
1413 }
1414
1415 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -07001416 boolean fillsParent() {
1417 return mFillsParent;
1418 }
1419
1420 void setFillsParent(boolean fillsParent) {
1421 mFillsParent = fillsParent;
1422 }
1423
Jorim Jaggife762342016-10-13 14:33:27 +02001424 boolean containsDismissKeyguardWindow() {
Bryce Lee081554b2017-05-25 07:52:12 -07001425 // Window state is transient during relaunch. We are not guaranteed to be frozen during the
1426 // entirety of the relaunch.
1427 if (isRelaunching()) {
1428 return mLastContainsDismissKeyguardWindow;
1429 }
1430
Jorim Jaggife762342016-10-13 14:33:27 +02001431 for (int i = mChildren.size() - 1; i >= 0; i--) {
1432 if ((mChildren.get(i).mAttrs.flags & FLAG_DISMISS_KEYGUARD) != 0) {
1433 return true;
1434 }
1435 }
1436 return false;
1437 }
1438
1439 boolean containsShowWhenLockedWindow() {
Bryce Lee081554b2017-05-25 07:52:12 -07001440 // When we are relaunching, it is possible for us to be unfrozen before our previous
1441 // windows have been added back. Using the cached value ensures that our previous
1442 // showWhenLocked preference is honored until relaunching is complete.
1443 if (isRelaunching()) {
1444 return mLastContainsShowWhenLockedWindow;
1445 }
1446
Jorim Jaggife762342016-10-13 14:33:27 +02001447 for (int i = mChildren.size() - 1; i >= 0; i--) {
1448 if ((mChildren.get(i).mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
1449 return true;
1450 }
1451 }
Bryce Lee081554b2017-05-25 07:52:12 -07001452
Jorim Jaggife762342016-10-13 14:33:27 +02001453 return false;
1454 }
1455
1456 void checkKeyguardFlagsChanged() {
1457 final boolean containsDismissKeyguard = containsDismissKeyguardWindow();
1458 final boolean containsShowWhenLocked = containsShowWhenLockedWindow();
1459 if (containsDismissKeyguard != mLastContainsDismissKeyguardWindow
1460 || containsShowWhenLocked != mLastContainsShowWhenLockedWindow) {
1461 mService.notifyKeyguardFlagsChanged(null /* callback */);
1462 }
1463 mLastContainsDismissKeyguardWindow = containsDismissKeyguard;
1464 mLastContainsShowWhenLockedWindow = containsShowWhenLocked;
1465 }
1466
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001467 WindowState getImeTargetBelowWindow(WindowState w) {
1468 final int index = mChildren.indexOf(w);
1469 if (index > 0) {
1470 final WindowState target = mChildren.get(index - 1);
1471 if (target.canBeImeTarget()) {
1472 return target;
1473 }
1474 }
1475 return null;
1476 }
1477
Winson Chungbe9be7f2017-06-28 10:55:22 -07001478 int getLowestAnimLayer() {
1479 for (int i = 0; i < mChildren.size(); i++) {
1480 final WindowState w = mChildren.get(i);
1481 if (w.mRemoved) {
1482 continue;
1483 }
1484 return w.mWinAnimator.mAnimLayer;
1485 }
1486 return Integer.MAX_VALUE;
1487 }
1488
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001489 WindowState getHighestAnimLayerWindow(WindowState currentTarget) {
1490 WindowState candidate = null;
1491 for (int i = mChildren.indexOf(currentTarget); i >= 0; i--) {
1492 final WindowState w = mChildren.get(i);
1493 if (w.mRemoved) {
1494 continue;
1495 }
1496 if (candidate == null || w.mWinAnimator.mAnimLayer >
1497 candidate.mWinAnimator.mAnimLayer) {
1498 candidate = w;
1499 }
1500 }
1501 return candidate;
1502 }
1503
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001504 /**
1505 * See {@link Activity#setDisablePreviewScreenshots}.
1506 */
1507 void setDisablePreviewScreenshots(boolean disable) {
Wale Ogunwale6c459212017-05-17 08:56:03 -07001508 mDisablePreviewScreenshots = disable;
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001509 }
1510
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001511 /**
chaviwd3bf08d2017-08-01 17:24:59 -07001512 * Sets whether the current launch can turn the screen on. See {@link #canTurnScreenOn()}
1513 */
1514 void setCanTurnScreenOn(boolean canTurnScreenOn) {
1515 mCanTurnScreenOn = canTurnScreenOn;
1516 }
1517
1518 /**
1519 * Indicates whether the current launch can turn the screen on. This is to prevent multiple
1520 * relayouts from turning the screen back on. The screen should only turn on at most
1521 * once per activity resume.
1522 *
1523 * @return true if the screen can be turned on.
1524 */
1525 boolean canTurnScreenOn() {
1526 return mCanTurnScreenOn;
1527 }
1528
1529 /**
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001530 * Retrieves whether we'd like to generate a snapshot that's based solely on the theme. This is
1531 * the case when preview screenshots are disabled {@link #setDisablePreviewScreenshots} or when
1532 * we can't take a snapshot for other reasons, for example, if we have a secure window.
1533 *
1534 * @return True if we need to generate an app theme snapshot, false if we'd like to take a real
1535 * screenshot.
1536 */
1537 boolean shouldUseAppThemeSnapshot() {
Wale Ogunwale6c459212017-05-17 08:56:03 -07001538 return mDisablePreviewScreenshots || forAllWindows(w -> (w.mAttrs.flags & FLAG_SECURE) != 0,
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001539 true /* topToBottom */);
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001540 }
1541
chaviw23ee71c2017-12-18 11:29:41 -08001542 @Override
1543 public SurfaceControl.Builder makeAnimationLeash() {
1544 return super.makeAnimationLeash()
1545 .setParent(getAppAnimationLayer());
1546 }
1547
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001548 boolean applyAnimationLocked(WindowManager.LayoutParams lp, int transit, boolean enter,
1549 boolean isVoiceInteraction) {
1550
1551 if (mService.mDisableTransitionAnimation) {
1552 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1553 Slog.v(TAG_WM, "applyAnimation: transition animation is disabled. atoken=" + this);
1554 }
1555 cancelAnimation();
1556 return false;
1557 }
1558
1559 // Only apply an animation if the display isn't frozen. If it is frozen, there is no reason
1560 // to animate and it can cause strange artifacts when we unfreeze the display if some
1561 // different animation is running.
1562 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "AWT#applyAnimationLocked");
1563 if (okToAnimate()) {
1564 final Animation a = loadAnimation(lp, transit, enter, isVoiceInteraction);
1565 if (a != null) {
chaviw23ee71c2017-12-18 11:29:41 -08001566 final TaskStack stack = getStack();
1567 mTmpPoint.set(0, 0);
chaviw23012112017-12-20 15:29:04 -08001568 mTmpRect.setEmpty();
chaviw23ee71c2017-12-18 11:29:41 -08001569 if (stack != null) {
1570 stack.getRelativePosition(mTmpPoint);
chaviw23012112017-12-20 15:29:04 -08001571 stack.getBounds(mTmpRect);
chaviw23ee71c2017-12-18 11:29:41 -08001572 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001573 final AnimationAdapter adapter = new LocalAnimationAdapter(
chaviw23012112017-12-20 15:29:04 -08001574 new WindowAnimationSpec(a, mTmpPoint, mTmpRect,
1575 mService.mAppTransition.canSkipFirstFrame(),
1576 mService.mAppTransition.getAppStackClipMode()),
Jorim Jaggi2e3c31d2017-11-20 19:49:00 +01001577 mService.mSurfaceAnimationRunner);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001578 if (a.getZAdjustment() == Animation.ZORDER_TOP) {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001579 mNeedsZBoost = true;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001580 }
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001581 startAnimation(getPendingTransaction(), adapter, !isVisible());
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001582 mTransit = transit;
1583 mTransitFlags = mService.mAppTransition.getTransitFlags();
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001584 }
1585 } else {
1586 cancelAnimation();
1587 }
1588 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
1589
1590 return isReallyAnimating();
1591 }
1592
1593 private Animation loadAnimation(WindowManager.LayoutParams lp, int transit, boolean enter,
1594 boolean isVoiceInteraction) {
1595 final DisplayContent displayContent = getTask().getDisplayContent();
1596 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
1597 final int width = displayInfo.appWidth;
1598 final int height = displayInfo.appHeight;
1599 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG_WM,
1600 "applyAnimation: atoken=" + this);
1601
1602 // Determine the visible rect to calculate the thumbnail clip
1603 final WindowState win = findMainWindow();
1604 final Rect frame = new Rect(0, 0, width, height);
1605 final Rect displayFrame = new Rect(0, 0,
1606 displayInfo.logicalWidth, displayInfo.logicalHeight);
1607 final Rect insets = new Rect();
1608 final Rect stableInsets = new Rect();
1609 Rect surfaceInsets = null;
1610 final boolean freeform = win != null && win.inFreeformWindowingMode();
1611 if (win != null) {
1612 // Containing frame will usually cover the whole screen, including dialog windows.
1613 // For freeform workspace windows it will not cover the whole screen and it also
1614 // won't exactly match the final freeform window frame (e.g. when overlapping with
1615 // the status bar). In that case we need to use the final frame.
1616 if (freeform) {
1617 frame.set(win.mFrame);
1618 } else {
1619 frame.set(win.mContainingFrame);
1620 }
1621 surfaceInsets = win.getAttrs().surfaceInsets;
1622 insets.set(win.mContentInsets);
1623 stableInsets.set(win.mStableInsets);
1624 }
1625
1626 if (mLaunchTaskBehind) {
1627 // Differentiate the two animations. This one which is briefly on the screen
1628 // gets the !enter animation, and the other activity which remains on the
1629 // screen gets the enter animation. Both appear in the mOpeningApps set.
1630 enter = false;
1631 }
1632 if (DEBUG_APP_TRANSITIONS) Slog.d(TAG_WM, "Loading animation for app transition."
1633 + " transit=" + AppTransition.appTransitionToString(transit) + " enter=" + enter
1634 + " frame=" + frame + " insets=" + insets + " surfaceInsets=" + surfaceInsets);
1635 final Configuration displayConfig = displayContent.getConfiguration();
1636 final Animation a = mService.mAppTransition.loadAnimation(lp, transit, enter,
1637 displayConfig.uiMode, displayConfig.orientation, frame, displayFrame, insets,
1638 surfaceInsets, stableInsets, isVoiceInteraction, freeform, getTask().mTaskId);
1639 if (a != null) {
1640 if (DEBUG_ANIM) logWithStack(TAG, "Loaded animation " + a + " for " + this);
1641 final int containingWidth = frame.width();
1642 final int containingHeight = frame.height();
1643 a.initialize(containingWidth, containingHeight, width, height);
1644 a.scaleCurrentDuration(mService.getTransitionAnimationScaleLocked());
1645 }
1646 return a;
1647 }
1648
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001649 @Override
1650 protected void setLayer(Transaction t, int layer) {
1651 if (!mSurfaceAnimator.hasLeash()) {
1652 t.setLayer(mSurfaceControl, layer);
1653 }
1654 }
1655
1656 @Override
1657 protected void setRelativeLayer(Transaction t, SurfaceControl relativeTo, int layer) {
1658 if (!mSurfaceAnimator.hasLeash()) {
1659 t.setRelativeLayer(mSurfaceControl, relativeTo, layer);
1660 }
1661 }
1662
1663 @Override
1664 protected void reparentSurfaceControl(Transaction t, SurfaceControl newParent) {
1665 if (!mSurfaceAnimator.hasLeash()) {
1666 t.reparent(mSurfaceControl, newParent.getHandle());
1667 }
1668 }
1669
1670 @Override
1671 public void onAnimationLeashCreated(Transaction t, SurfaceControl leash) {
1672
1673 // The leash is parented to the animation layer. We need to preserve the z-order by using
1674 // the prefix order index, but we boost if necessary.
1675 int layer = getPrefixOrderIndex();
1676 if (mNeedsZBoost) {
1677 layer += Z_BOOST_BASE;
1678 }
1679 leash.setLayer(layer);
1680 }
1681
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001682 /**
1683 * This must be called while inside a transaction.
1684 */
1685 void showAllWindowsLocked() {
1686 forAllWindows(windowState -> {
1687 if (DEBUG_VISIBILITY) Slog.v(TAG, "performing show on: " + windowState);
1688 windowState.performShowLocked();
1689 }, false /* traverseTopToBottom */);
Jorim Jaggia5e10572017-11-15 14:36:26 +01001690 }
1691
1692 @Override
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001693 protected void onAnimationFinished() {
1694 super.onAnimationFinished();
1695
1696 mTransit = TRANSIT_UNSET;
1697 mTransitFlags = 0;
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001698 mNeedsZBoost = false;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001699
1700 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM | FINISH_LAYOUT_REDO_WALLPAPER,
1701 "AppWindowToken");
1702
Jorim Jaggi988f6682017-11-17 17:46:43 +01001703 clearThumbnail();
1704
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001705 if (mService.mInputMethodTarget != null && mService.mInputMethodTarget.mAppToken == this) {
1706 getDisplayContent().computeImeTarget(true /* updateImeTarget */);
1707 }
1708
1709 if (DEBUG_ANIM) Slog.v(TAG, "Animation done in " + this
1710 + ": reportedVisible=" + reportedVisible
1711 + " okToDisplay=" + okToDisplay()
1712 + " okToAnimate=" + okToAnimate()
1713 + " startingDisplayed=" + startingDisplayed);
1714
1715 // WindowState.onExitAnimationDone might modify the children list, so make a copy and then
1716 // traverse the copy.
1717 final ArrayList<WindowState> children = new ArrayList<>(mChildren);
1718 children.forEach(WindowState::onExitAnimationDone);
1719
1720 mService.mAppTransition.notifyAppTransitionFinishedLocked(token);
1721 scheduleAnimation();
1722 }
1723
1724 @Override
1725 boolean isAppAnimating() {
1726 return isSelfAnimating();
1727 }
1728
1729 @Override
1730 boolean isSelfAnimating() {
1731 // If we are about to start a transition, we also need to be considered animating.
1732 return isWaitingForTransitionStart() || isReallyAnimating();
1733 }
1734
1735 /**
1736 * @return True if and only if we are actually running an animation. Note that
1737 * {@link #isSelfAnimating} also returns true if we are waiting for an animation to
1738 * start.
1739 */
1740 private boolean isReallyAnimating() {
1741 return super.isSelfAnimating();
1742 }
1743
Jorim Jaggi988f6682017-11-17 17:46:43 +01001744 @Override
1745 void cancelAnimation() {
1746 super.cancelAnimation();
1747 clearThumbnail();
1748 }
1749
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001750 boolean isWaitingForTransitionStart() {
1751 return mService.mAppTransition.isTransitionSet()
1752 && (mService.mOpeningApps.contains(this) || mService.mClosingApps.contains(this));
1753 }
1754
1755 public int getTransit() {
1756 return mTransit;
1757 }
1758
1759 int getTransitFlags() {
1760 return mTransitFlags;
1761 }
1762
Jorim Jaggi988f6682017-11-17 17:46:43 +01001763 void attachThumbnailAnimation() {
1764 if (!isReallyAnimating()) {
1765 return;
1766 }
1767 final int taskId = getTask().mTaskId;
1768 final GraphicBuffer thumbnailHeader =
1769 mService.mAppTransition.getAppTransitionThumbnailHeader(taskId);
1770 if (thumbnailHeader == null) {
1771 if (DEBUG_APP_TRANSITIONS) Slog.d(TAG, "No thumbnail header bitmap for: " + taskId);
1772 return;
1773 }
1774 clearThumbnail();
1775 mThumbnail = new AppWindowThumbnail(getPendingTransaction(), this, thumbnailHeader);
1776 mThumbnail.startAnimation(getPendingTransaction(), loadThumbnailAnimation(thumbnailHeader));
1777 }
1778
1779 private Animation loadThumbnailAnimation(GraphicBuffer thumbnailHeader) {
1780 final DisplayInfo displayInfo = mDisplayContent.getDisplayInfo();
1781
1782 // If this is a multi-window scenario, we use the windows frame as
1783 // destination of the thumbnail header animation. If this is a full screen
1784 // window scenario, we use the whole display as the target.
1785 WindowState win = findMainWindow();
1786 Rect appRect = win != null ? win.getContentFrameLw() :
1787 new Rect(0, 0, displayInfo.appWidth, displayInfo.appHeight);
1788 Rect insets = win != null ? win.mContentInsets : null;
1789 final Configuration displayConfig = mDisplayContent.getConfiguration();
1790 return mService.mAppTransition.createThumbnailAspectScaleAnimationLocked(
1791 appRect, insets, thumbnailHeader, getTask().mTaskId, displayConfig.uiMode,
1792 displayConfig.orientation);
1793 }
1794
1795 private void clearThumbnail() {
1796 if (mThumbnail == null) {
1797 return;
1798 }
1799 mThumbnail.destroy();
1800 mThumbnail = null;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001801 }
1802
1803 @Override
1804 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
1805 super.dump(pw, prefix, dumpAll);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001806 if (appToken != null) {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001807 pw.println(prefix + "app=true mVoiceInteraction=" + mVoiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001808 }
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001809 pw.print(prefix); pw.print("task="); pw.println(getTask());
Wale Ogunwale51362492016-09-08 17:49:17 -07001810 pw.print(prefix); pw.print(" mFillsParent="); pw.print(mFillsParent);
1811 pw.print(" mOrientation="); pw.println(mOrientation);
Wale Ogunwale89973222017-04-23 18:39:45 -07001812 pw.println(prefix + "hiddenRequested=" + hiddenRequested + " mClientHidden=" + mClientHidden
1813 + ((mDeferHidingClient) ? " mDeferHidingClient=" + mDeferHidingClient : "")
1814 + " reportedDrawn=" + reportedDrawn + " reportedVisible=" + reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -07001815 if (paused) {
1816 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001817 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001818 if (mAppStopped) {
1819 pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped);
1820 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001821 if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001822 || allDrawn || mLastAllDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001823 pw.print(prefix); pw.print("mNumInterestingWindows=");
1824 pw.print(mNumInterestingWindows);
1825 pw.print(" mNumDrawnWindows="); pw.print(mNumDrawnWindows);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001826 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -07001827 pw.print(" allDrawn="); pw.print(allDrawn);
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001828 pw.print(" lastAllDrawn="); pw.print(mLastAllDrawn);
Craig Mautner6fbda632012-07-03 09:26:39 -07001829 pw.println(")");
1830 }
1831 if (inPendingTransaction) {
1832 pw.print(prefix); pw.print("inPendingTransaction=");
1833 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001834 }
Craig Mautner799bc1d2015-01-14 10:33:48 -08001835 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001836 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
1837 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -08001838 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -08001839 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001840 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001841 if (startingWindow != null || startingSurface != null
Wale Ogunwale6c459212017-05-17 08:56:03 -07001842 || startingDisplayed || startingMoved || mHiddenSetFromTransferredStartingWindow) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001843 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001844 pw.print(" startingSurface="); pw.print(startingSurface);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001845 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
Wale Ogunwale6c459212017-05-17 08:56:03 -07001846 pw.print(" startingMoved="); pw.print(startingMoved);
1847 pw.println(" mHiddenSetFromTransferredStartingWindow="
1848 + mHiddenSetFromTransferredStartingWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001849 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01001850 if (!mFrozenBounds.isEmpty()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -08001851 pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds);
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001852 pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig);
Chong Zhangd78ddb42016-03-02 17:01:14 -08001853 }
1854 if (mPendingRelaunchCount != 0) {
1855 pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount);
Jorim Jaggi0429f352015-12-22 16:29:16 +01001856 }
Wale Ogunwale9c64cb62017-04-12 13:39:59 -07001857 if (getController() != null) {
1858 pw.print(prefix); pw.print("controller="); pw.println(getController());
1859 }
Wale Ogunwalee287e192017-04-21 09:30:12 -07001860 if (mRemovingFromDisplay) {
1861 pw.println(prefix + "mRemovingFromDisplay=" + mRemovingFromDisplay);
1862 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001863 }
1864
1865 @Override
1866 void setHidden(boolean hidden) {
1867 super.setHidden(hidden);
Winson Chunge55c0192017-08-24 14:50:48 -07001868
1869 if (hidden) {
1870 // Once the app window is hidden, reset the last saved PiP snap fraction
1871 mDisplayContent.mPinnedStackControllerLocked.resetReentrySnapFraction(this);
1872 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001873 scheduleAnimation();
1874 }
1875
1876 @Override
1877 void prepareSurfaces() {
1878 // isSelfAnimating also returns true when we are about to start a transition, so we need
1879 // to check super here.
1880 final boolean reallyAnimating = super.isSelfAnimating();
1881 final boolean show = !isHidden() || reallyAnimating;
1882 if (show && !mLastSurfaceShowing) {
1883 mPendingTransaction.show(mSurfaceControl);
1884 } else if (!show && mLastSurfaceShowing) {
1885 mPendingTransaction.hide(mSurfaceControl);
Jorim Jaggi4d1835d2017-08-31 17:28:27 +02001886 }
Jorim Jaggi988f6682017-11-17 17:46:43 +01001887 if (mThumbnail != null) {
1888 mThumbnail.setShowing(mPendingTransaction, show);
1889 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001890 mLastSurfaceShowing = show;
1891 super.prepareSurfaces();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001892 }
1893
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001894 boolean isFreezingScreen() {
1895 return mFreezingScreen;
1896 }
1897
1898 @Override
1899 boolean needsZBoost() {
1900 return mNeedsZBoost || super.needsZBoost();
1901 }
1902
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07001903 @CallSuper
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001904 @Override
Adrian Roos4921ccf2017-09-28 16:54:06 +02001905 public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07001906 final long token = proto.start(fieldId);
1907 writeNameToProto(proto, NAME);
Adrian Roos4921ccf2017-09-28 16:54:06 +02001908 super.writeToProto(proto, WINDOW_TOKEN, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07001909 proto.end(token);
1910 }
1911
1912 void writeNameToProto(ProtoOutputStream proto, long fieldId) {
1913 if (appToken == null) {
1914 return;
1915 }
1916 try {
1917 proto.write(fieldId, appToken.getName());
1918 } catch (RemoteException e) {
1919 // This shouldn't happen, but in this case fall back to outputting nothing
1920 Slog.e(TAG, e.toString());
1921 }
1922 }
1923
1924 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001925 public String toString() {
1926 if (stringName == null) {
1927 StringBuilder sb = new StringBuilder();
1928 sb.append("AppWindowToken{");
1929 sb.append(Integer.toHexString(System.identityHashCode(this)));
1930 sb.append(" token="); sb.append(token); sb.append('}');
1931 stringName = sb.toString();
1932 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001933 return stringName + ((mIsExiting) ? " mIsExiting=" : "");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001934 }
Jeff Browne9bdb312012-04-05 15:30:10 -07001935}