blob: 3473b7d98ad538e556a5f84bc964b58daa02dc67 [file] [log] [blame]
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server.wm;
18
Winson Chunge55c0192017-08-24 14:50:48 -070019import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
20import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;
Wale Ogunwale72919d22016-12-08 18:58:50 -080021import static android.content.pm.ActivityInfo.CONFIG_ORIENTATION;
22import static android.content.pm.ActivityInfo.CONFIG_SCREEN_SIZE;
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -070023import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND;
Wale Ogunwale51362492016-09-08 17:49:17 -070024import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET;
Jorim Jaggif5f9e122017-10-24 18:21:09 +020025import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070026import static android.view.Display.DEFAULT_DISPLAY;
Adrian Roos4d18a2e2017-12-19 19:08:05 +010027import static android.view.SurfaceControl.HIDDEN;
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;
Tony Mak64b8d562017-12-28 17:44:02 +000034
Adrian Roose99bc052017-11-20 17:55:31 +010035import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
36import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070037import static com.android.server.wm.AppTransition.TRANSIT_UNSET;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080038import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080039import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
40import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070041import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070042import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
43import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
Wale Ogunwale9017ec02016-02-25 08:55:25 -080044import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
Jorim Jaggie4b0f282017-05-17 15:10:29 +020045import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW_VERBOSE;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070046import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TOKEN_MOVEMENT;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080047import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
48import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_MOVEMENT;
49import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
50import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Chong Zhang92147042016-05-09 12:47:11 -070051import static com.android.server.wm.WindowManagerService.H.NOTIFY_ACTIVITY_DRAWN;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070052import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070053import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070054import static com.android.server.wm.WindowManagerService.logWithStack;
Steven Timotiusaf03df62017-07-18 16:56:43 -070055import static com.android.server.wm.proto.AppWindowTokenProto.NAME;
56import static com.android.server.wm.proto.AppWindowTokenProto.WINDOW_TOKEN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080057
Wale Ogunwale0d5609b2017-09-13 05:55:07 -070058import android.annotation.CallSuper;
Jorim Jaggid635a4a2017-05-03 15:21:26 +020059import android.app.Activity;
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;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080072import android.view.IApplicationToken;
Robert Carr6914f082017-03-20 19:04:30 -070073import android.view.SurfaceControl;
Tony Mak64b8d562017-12-28 17:44:02 +000074import android.view.SurfaceControl.Transaction;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080075import android.view.WindowManager;
Jorim Jaggi87fdbcb2017-08-17 13:41:11 +020076import android.view.WindowManager.LayoutParams;
Tony Mak64b8d562017-12-28 17:44:02 +000077import android.view.animation.Animation;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080078
Tony Mak64b8d562017-12-28 17:44:02 +000079import com.android.internal.R;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080080import com.android.internal.util.ToBooleanFunction;
81import com.android.server.input.InputApplicationHandle;
Adrian Roose99bc052017-11-20 17:55:31 +010082import com.android.server.policy.WindowManagerPolicy.StartingSurface;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080083import com.android.server.wm.WindowManagerService.H;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080084
85import java.io.PrintWriter;
Jorim Jaggi0429f352015-12-22 16:29:16 +010086import java.util.ArrayDeque;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080087import java.util.ArrayList;
Jorim Jaggia5e10572017-11-15 14:36:26 +010088import java.util.LinkedList;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080089
90class AppTokenList extends ArrayList<AppWindowToken> {
91}
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080092
93/**
94 * Version of WindowToken that is specifically for a particular application (or
95 * really activity) that is displaying windows.
96 */
Wale Ogunwale3f4433d2016-08-18 20:42:42 -070097class AppWindowToken extends WindowToken implements WindowManagerService.AppFreezeListener {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080098 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppWindowToken" : TAG_WM;
99
Jorim Jaggi619c9f72017-12-19 18:04:29 +0100100 /**
101 * Value to increment the z-layer when boosting a layer during animations. BOOST in l33tsp34k.
102 */
103 private static final int Z_BOOST_BASE = 800570000;
104
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800105 // Non-null only for application tokens.
106 final IApplicationToken appToken;
107
Wale Ogunwale72919d22016-12-08 18:58:50 -0800108 final boolean mVoiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700109
Wale Ogunwale51362492016-09-08 17:49:17 -0700110 /** @see WindowContainer#fillsParent() */
111 private boolean mFillsParent;
Craig Mautner4c5eb222013-11-18 12:59:05 -0800112 boolean layoutConfigChanges;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800113 boolean mShowForAllUsers;
114 int mTargetSdk;
Craig Mautnera2c77052012-03-26 12:14:43 -0700115
Bryce Lee6d410262017-02-28 15:30:17 -0800116 // Flag set while reparenting to prevent actions normally triggered by an individual parent
117 // change.
118 private boolean mReparenting;
119
Wale Ogunwalee287e192017-04-21 09:30:12 -0700120 // True if we are current in the process of removing this app token from the display
121 private boolean mRemovingFromDisplay = false;
122
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800123 // The input dispatching timeout for this application token in nanoseconds.
Wale Ogunwale72919d22016-12-08 18:58:50 -0800124 long mInputDispatchingTimeoutNanos;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800125
126 // These are used for determining when all windows associated with
127 // an activity have been drawn, so they can be made visible together
128 // at the same time.
Craig Mautner764983d2012-03-22 11:37:36 -0700129 // initialize so that it doesn't match mTransactionSequence which is an int.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700130 private long mLastTransactionSequence = Long.MIN_VALUE;
131 private int mNumInterestingWindows;
132 private int mNumDrawnWindows;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800133 boolean inPendingTransaction;
134 boolean allDrawn;
Jorim Jaggib0fc8172017-11-23 17:04:08 +0000135 private boolean mLastAllDrawn;
136
Craig Mautner7636dfb2012-11-16 15:24:11 -0800137 // Set to true when this app creates a surface while in the middle of an animation. In that
138 // case do not clear allDrawn until the animation completes.
139 boolean deferClearAllDrawn;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800140
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800141 // Is this window's surface needed? This is almost like hidden, except
142 // it will sometimes be true a little earlier: when the token has
143 // been shown, but is still waiting for its app transition to execute
144 // before making its windows shown.
145 boolean hiddenRequested;
146
147 // Have we told the window clients to hide themselves?
Wale Ogunwale89973222017-04-23 18:39:45 -0700148 private boolean mClientHidden;
149
150 // If true we will defer setting mClientHidden to true and reporting to the client that it is
151 // hidden.
152 boolean mDeferHidingClient;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800153
154 // Last visibility state we reported to the app token.
155 boolean reportedVisible;
156
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700157 // Last drawn state we reported to the app token.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700158 private boolean reportedDrawn;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700159
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800160 // Set to true when the token has been removed from the window mgr.
161 boolean removed;
162
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800163 // Information about an application starting window if displayed.
164 StartingData startingData;
165 WindowState startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800166 StartingSurface startingSurface;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800167 boolean startingDisplayed;
168 boolean startingMoved;
Wale Ogunwale6c459212017-05-17 08:56:03 -0700169 // True if the hidden state of this token was forced to false due to a transferred starting
170 // window.
171 private boolean mHiddenSetFromTransferredStartingWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800172 boolean firstWindowDrawn;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700173 private final WindowState.UpdateReportedVisibilityResults mReportedVisibilityResults =
174 new WindowState.UpdateReportedVisibilityResults();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800175
176 // Input application handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700177 final InputApplicationHandle mInputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800178
Wale Ogunwale571771c2016-08-26 13:18:50 -0700179 // TODO: Have a WindowContainer state for tracking exiting/deferred removal.
Craig Mautner799bc1d2015-01-14 10:33:48 -0800180 boolean mIsExiting;
Craig Mautner9ef471f2014-02-07 13:11:47 -0800181
Craig Mautnerbb742462014-07-07 15:28:55 -0700182 boolean mLaunchTaskBehind;
Craig Mautner8746a472014-07-24 15:12:54 -0700183 boolean mEnteringAnimation;
Craig Mautnerbb742462014-07-07 15:28:55 -0700184
Wale Ogunwale72919d22016-12-08 18:58:50 -0800185 private boolean mAlwaysFocusable;
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800186
Robert Carre12aece2016-02-02 22:43:27 -0800187 boolean mAppStopped;
Robert Carrfd10cd12016-06-29 16:41:50 -0700188 int mRotationAnimationHint;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700189 private int mPendingRelaunchCount;
Robert Carre12aece2016-02-02 22:43:27 -0800190
Jorim Jaggife762342016-10-13 14:33:27 +0200191 private boolean mLastContainsShowWhenLockedWindow;
192 private boolean mLastContainsDismissKeyguardWindow;
193
Jorim Jaggi0429f352015-12-22 16:29:16 +0100194 ArrayDeque<Rect> mFrozenBounds = new ArrayDeque<>();
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700195 ArrayDeque<Configuration> mFrozenMergedConfig = new ArrayDeque<>();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100196
Wale Ogunwale6c459212017-05-17 08:56:03 -0700197 private boolean mDisablePreviewScreenshots;
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +0100198
Wale Ogunwale034a8ec2017-09-02 17:14:40 -0700199 private Task mLastParent;
Robert Carred3e83b2017-04-21 13:26:55 -0700200
chaviwd3bf08d2017-08-01 17:24:59 -0700201 /**
202 * See {@link #canTurnScreenOn()}
203 */
204 private boolean mCanTurnScreenOn = true;
205
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200206 /**
207 * If we are running an animation, this determines the transition type. Must be one of
208 * AppTransition.TRANSIT_* constants.
209 */
210 private int mTransit;
211
212 /**
213 * If we are running an animation, this determines the flags during this animation. Must be a
214 * bitwise combination of AppTransition.TRANSIT_FLAG_* constants.
215 */
216 private int mTransitFlags;
217
218 /** Whether our surface was set to be showing in the last call to {@link #prepareSurfaces} */
Jorim Jaggifd1891462017-12-29 15:41:36 +0100219 private boolean mLastSurfaceShowing = true;
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200220
Jorim Jaggi988f6682017-11-17 17:46:43 +0100221 private AppWindowThumbnail mThumbnail;
222
Jorim Jaggib0fc8172017-11-23 17:04:08 +0000223 /** Have we been asked to have this token keep the screen frozen? */
224 private boolean mFreezingScreen;
225
226 /** Whether this token should be boosted at the top of all app window tokens. */
227 private boolean mNeedsZBoost;
Adrian Roos4d18a2e2017-12-19 19:08:05 +0100228 private Letterbox mLetterbox;
Jorim Jaggib0fc8172017-11-23 17:04:08 +0000229
chaviw23ee71c2017-12-18 11:29:41 -0800230 private final Point mTmpPoint = new Point();
chaviw23012112017-12-20 15:29:04 -0800231 private final Rect mTmpRect = new Rect();
chaviw23ee71c2017-12-18 11:29:41 -0800232
Wale Ogunwale72919d22016-12-08 18:58:50 -0800233 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
234 DisplayContent dc, long inputDispatchingTimeoutNanos, boolean fullscreen,
235 boolean showForAllUsers, int targetSdk, int orientation, int rotationAnimationHint,
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800236 int configChanges, boolean launchTaskBehind, boolean alwaysFocusable,
Bryce Leef3c6a472017-11-14 14:53:06 -0800237 AppWindowContainerController controller) {
238 this(service, token, voiceInteraction, dc, fullscreen);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800239 setController(controller);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800240 mInputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800241 mShowForAllUsers = showForAllUsers;
242 mTargetSdk = targetSdk;
243 mOrientation = orientation;
244 layoutConfigChanges = (configChanges & (CONFIG_SCREEN_SIZE | CONFIG_ORIENTATION)) != 0;
245 mLaunchTaskBehind = launchTaskBehind;
246 mAlwaysFocusable = alwaysFocusable;
247 mRotationAnimationHint = rotationAnimationHint;
248
249 // Application tokens start out hidden.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200250 setHidden(true);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800251 hiddenRequested = true;
252 }
253
254 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
Bryce Leef3c6a472017-11-14 14:53:06 -0800255 DisplayContent dc, boolean fillsParent) {
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800256 super(service, token != null ? token.asBinder() : null, TYPE_APPLICATION, true, dc,
257 false /* ownerCanManageAppTokens */);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700258 appToken = token;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800259 mVoiceInteraction = voiceInteraction;
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800260 mFillsParent = fillsParent;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800261 mInputApplicationHandle = new InputApplicationHandle(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800262 }
263
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800264 void onFirstWindowDrawn(WindowState win, WindowStateAnimator winAnimator) {
265 firstWindowDrawn = true;
266
267 // We now have a good window to show, remove dead placeholders
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700268 removeDeadWindows();
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800269
Jorim Jaggi02886a82016-12-06 09:10:06 -0800270 if (startingWindow != null) {
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800271 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, "Finish starting "
272 + win.mToken + ": first real window is shown, no animation");
273 // If this initial window is animating, stop it -- we will do an animation to reveal
274 // it from behind the starting window, so there is no need for it to also be doing its
275 // own stuff.
Jorim Jaggia5e10572017-11-15 14:36:26 +0100276 win.cancelAnimation();
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800277 if (getController() != null) {
278 getController().removeStartingWindow();
279 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800280 }
281 updateReportedVisibilityLocked();
282 }
283
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800284 void updateReportedVisibilityLocked() {
285 if (appToken == null) {
286 return;
287 }
288
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700289 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700290 final int count = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800291
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700292 mReportedVisibilityResults.reset();
293
294 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700295 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700296 win.updateReportedVisibility(mReportedVisibilityResults);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800297 }
298
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700299 int numInteresting = mReportedVisibilityResults.numInteresting;
300 int numVisible = mReportedVisibilityResults.numVisible;
301 int numDrawn = mReportedVisibilityResults.numDrawn;
302 boolean nowGone = mReportedVisibilityResults.nowGone;
303
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700304 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200305 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting && !isHidden();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700306 if (!nowGone) {
307 // If the app is not yet gone, then it can only become visible/drawn.
308 if (!nowDrawn) {
309 nowDrawn = reportedDrawn;
310 }
311 if (!nowVisible) {
312 nowVisible = reportedVisible;
313 }
314 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800315 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800316 + numInteresting + " visible=" + numVisible);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800317 final AppWindowContainerController controller = getController();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700318 if (nowDrawn != reportedDrawn) {
319 if (nowDrawn) {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800320 if (controller != null) {
321 controller.reportWindowsDrawn();
322 }
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700323 }
324 reportedDrawn = nowDrawn;
325 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800326 if (nowVisible != reportedVisible) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700327 if (DEBUG_VISIBILITY) Slog.v(TAG,
328 "Visibility changed in " + this + ": vis=" + nowVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800329 reportedVisible = nowVisible;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800330 if (controller != null) {
331 if (nowVisible) {
332 controller.reportWindowsVisible();
333 } else {
334 controller.reportWindowsGone();
335 }
336 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800337 }
338 }
339
Wale Ogunwale89973222017-04-23 18:39:45 -0700340 boolean isClientHidden() {
341 return mClientHidden;
342 }
343
344 void setClientHidden(boolean hideClient) {
345 if (mClientHidden == hideClient || (hideClient && mDeferHidingClient)) {
346 return;
347 }
348 mClientHidden = hideClient;
349 sendAppVisibilityToClients();
350 }
351
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700352 boolean setVisibility(WindowManager.LayoutParams lp,
353 boolean visible, int transit, boolean performLayout, boolean isVoiceInteraction) {
354
355 boolean delayed = false;
356 inPendingTransaction = false;
Wale Ogunwale9e4721f2017-05-23 19:37:30 -0700357 // Reset the state of mHiddenSetFromTransferredStartingWindow since visibility is actually
358 // been set by the app now.
359 mHiddenSetFromTransferredStartingWindow = false;
Wale Ogunwale89973222017-04-23 18:39:45 -0700360 setClientHidden(!visible);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700361
362 // Allow for state changes and animation to be applied if:
363 // * token is transitioning visibility state
364 // * or the token was marked as hidden and is exiting before we had a chance to play the
365 // transition animation
366 // * or this is an opening app and windows are being replaced.
367 boolean visibilityChanged = false;
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200368 if (isHidden() == visible || (isHidden() && mIsExiting) || (visible && waitingForReplacement())) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700369 final AccessibilityController accessibilityController = mService.mAccessibilityController;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700370 boolean changed = false;
371 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200372 "Changing app " + this + " hidden=" + isHidden() + " performLayout=" + performLayout);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700373
374 boolean runningAppAnimation = false;
375
376 if (transit != AppTransition.TRANSIT_UNSET) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200377 if (applyAnimationLocked(lp, transit, visible, isVoiceInteraction)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700378 delayed = runningAppAnimation = true;
379 }
380 final WindowState window = findMainWindow();
381 //TODO (multidisplay): Magnification is supported only for the default display.
382 if (window != null && accessibilityController != null
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700383 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700384 accessibilityController.onAppWindowTransitionLocked(window, transit);
385 }
386 changed = true;
387 }
388
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700389 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700390 for (int i = 0; i < windowsCount; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700391 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700392 changed |= win.onAppVisibilityChanged(visible, runningAppAnimation);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700393 }
394
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200395 setHidden(!visible);
396 hiddenRequested = !visible;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700397 visibilityChanged = true;
398 if (!visible) {
399 stopFreezingScreen(true, true);
400 } else {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700401 // If we are being set visible, and the starting window is not yet displayed,
402 // then make sure it doesn't get displayed.
403 if (startingWindow != null && !startingWindow.isDrawnLw()) {
404 startingWindow.mPolicyVisibility = false;
405 startingWindow.mPolicyVisibilityAfterAnim = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700406 }
Jorim Jaggi38d44ec2017-06-14 16:04:59 -0700407
408 // We are becoming visible, so better freeze the screen with the windows that are
409 // getting visible so we also wait for them.
410 forAllWindows(mService::makeWindowFreezingScreenIfNeededLocked, true);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700411 }
412
413 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setVisibility: " + this
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200414 + ": hidden=" + isHidden() + " hiddenRequested=" + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700415
416 if (changed) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700417 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700418 if (performLayout) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700419 mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700420 false /*updateInputWindows*/);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700421 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700422 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700423 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700424 }
425 }
426
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200427 if (isReallyAnimating()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700428 delayed = true;
429 }
430
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700431 for (int i = mChildren.size() - 1; i >= 0 && !delayed; i--) {
Jorim Jaggia5e10572017-11-15 14:36:26 +0100432 if ((mChildren.get(i)).isSelfOrChildAnimating()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700433 delayed = true;
434 }
435 }
436
437 if (visibilityChanged) {
438 if (visible && !delayed) {
439 // The token was made immediately visible, there will be no entrance animation.
440 // We need to inform the client the enter animation was finished.
441 mEnteringAnimation = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700442 mService.mActivityManagerAppTransitionNotifier.onAppTransitionFinishedLocked(token);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700443 }
Robert Carr61b81112017-07-17 18:08:15 -0700444
Robert Carre7cc44d2017-03-20 19:04:30 -0700445 // If we are hidden but there is no delay needed we immediately
446 // apply the Surface transaction so that the ActivityManager
Robert Carr61b81112017-07-17 18:08:15 -0700447 // can have some guarantee on the Surface state following
448 // setting the visibility. This captures cases like dismissing
449 // the docked or pinned stack where there is no app transition.
450 //
451 // In the case of a "Null" animation, there will be
452 // no animation but there will still be a transition set.
453 // We still need to delay hiding the surface such that it
454 // can be synchronized with showing the next surface in the transition.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200455 if (isHidden() && !delayed && !mService.mAppTransition.isTransitionSet()) {
Robert Carr6914f082017-03-20 19:04:30 -0700456 SurfaceControl.openTransaction();
457 for (int i = mChildren.size() - 1; i >= 0; i--) {
458 mChildren.get(i).mWinAnimator.hide("immediately hidden");
459 }
460 SurfaceControl.closeTransaction();
461 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700462
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700463 if (!mService.mClosingApps.contains(this) && !mService.mOpeningApps.contains(this)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700464 // The token is not closing nor opening, so even if there is an animation set, that
465 // doesn't mean that it goes through the normal app transition cycle so we have
466 // to inform the docked controller about visibility change.
Andrii Kulian1e32e022016-09-16 15:29:34 -0700467 // TODO(multi-display): notify docked divider on all displays where visibility was
468 // affected.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700469 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700470 .notifyAppVisibilityChanged();
Jorim Jaggi8b702ed2017-01-20 16:59:03 +0100471 mService.mTaskSnapshotController.notifyAppVisibilityChanged(this, visible);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700472 }
473 }
474
475 return delayed;
476 }
477
Jorim Jaggi87fdbcb2017-08-17 13:41:11 +0200478 /**
479 * @return The to top most child window for which {@link LayoutParams#isFullscreen()} returns
480 * true.
481 */
482 WindowState getTopFullscreenWindow() {
483 for (int i = mChildren.size() - 1; i >= 0; i--) {
484 final WindowState win = mChildren.get(i);
485 if (win != null && win.mAttrs.isFullscreen()) {
486 return win;
487 }
488 }
489 return null;
490 }
491
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800492 WindowState findMainWindow() {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700493 WindowState candidate = null;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700494 int j = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800495 while (j > 0) {
496 j--;
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700497 final WindowState win = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700498 final int type = win.mAttrs.type;
499 // No need to loop through child window as base application and starting types can't be
500 // child windows.
501 if (type == TYPE_BASE_APPLICATION || type == TYPE_APPLICATION_STARTING) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700502 // In cases where there are multiple windows, we prefer the non-exiting window. This
Sungsoo Lim0d3d1f82015-12-02 14:47:59 +0900503 // happens for example when replacing windows during an activity relaunch. When
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700504 // constructing the animation, we want the new window, not the exiting one.
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800505 if (win.mAnimatingExit) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700506 candidate = win;
507 } else {
508 return win;
509 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800510 }
511 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700512 return candidate;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800513 }
514
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800515 boolean windowsAreFocusable() {
Wale Ogunwale3382ab12017-07-27 08:55:03 -0700516 return getWindowConfiguration().canReceiveKeys() || mAlwaysFocusable;
Wale Ogunwaled045c822015-12-02 09:14:28 -0800517 }
518
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800519 AppWindowContainerController getController() {
520 final WindowContainerController controller = super.getController();
521 return controller != null ? (AppWindowContainerController) controller : null;
522 }
523
Wale Ogunwale571771c2016-08-26 13:18:50 -0700524 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -0700525 boolean isVisible() {
Wale Ogunwalee471be62016-10-03 07:53:55 -0700526 // If the app token isn't hidden then it is considered visible and there is no need to check
527 // its children windows to see if they are visible.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200528 return !isHidden();
Wale Ogunwale44f21802016-09-02 12:49:48 -0700529 }
530
531 @Override
Wale Ogunwalee287e192017-04-21 09:30:12 -0700532 void removeImmediately() {
533 onRemovedFromDisplay();
534 super.removeImmediately();
535 }
536
537 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -0700538 void removeIfPossible() {
Craig Mautnere3119b72015-01-20 15:02:36 -0800539 mIsExiting = false;
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800540 removeAllWindowsIfPossible();
Bryce Lee6d410262017-02-28 15:30:17 -0800541 removeImmediately();
Craig Mautnere3119b72015-01-20 15:02:36 -0800542 }
543
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700544 @Override
545 boolean checkCompleteDeferredRemoval() {
546 if (mIsExiting) {
547 removeIfPossible();
548 }
549 return super.checkCompleteDeferredRemoval();
550 }
551
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700552 void onRemovedFromDisplay() {
Wale Ogunwalee287e192017-04-21 09:30:12 -0700553 if (mRemovingFromDisplay) {
554 return;
555 }
556 mRemovingFromDisplay = true;
557
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700558 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app token: " + this);
559
Wale Ogunwale72919d22016-12-08 18:58:50 -0800560 boolean delayed = setVisibility(null, false, TRANSIT_UNSET, true, mVoiceInteraction);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700561
562 mService.mOpeningApps.remove(this);
Jorim Jaggi45ca0542017-05-30 16:16:01 -0700563 mService.mUnknownAppVisibilityController.appRemovedOrHidden(this);
Jorim Jaggi10abe2f2017-01-03 16:44:46 +0100564 mService.mTaskSnapshotController.onAppRemoved(this);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700565 waitingToShow = false;
566 if (mService.mClosingApps.contains(this)) {
567 delayed = true;
568 } else if (mService.mAppTransition.isTransitionSet()) {
569 mService.mClosingApps.add(this);
570 delayed = true;
571 }
572
573 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app " + this + " delayed=" + delayed
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200574 + " animation=" + getAnimation() + " animating=" + isSelfAnimating());
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700575
576 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM, "removeAppToken: "
577 + this + " delayed=" + delayed + " Callers=" + Debug.getCallers(4));
578
Jorim Jaggi19be6052017-08-03 18:33:43 +0200579 if (startingData != null && getController() != null) {
580 getController().removeStartingWindow();
581 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800582
Winson Chung87e5d552017-04-05 11:49:38 -0700583 // If this window was animating, then we need to ensure that the app transition notifies
584 // that animations have completed in WMS.handleAnimatingStoppedAndTransitionLocked(), so
585 // add to that list now
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200586 if (isSelfAnimating()) {
Winson Chung87e5d552017-04-05 11:49:38 -0700587 mService.mNoAnimationNotifyOnTransitionFinished.add(token);
588 }
589
Wale Ogunwalee287e192017-04-21 09:30:12 -0700590 final TaskStack stack = getStack();
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700591 if (delayed && !isEmpty()) {
592 // set the token aside because it has an active animation to be finished
593 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM,
594 "removeAppToken make exiting: " + this);
Wale Ogunwalee287e192017-04-21 09:30:12 -0700595 if (stack != null) {
596 stack.mExitingAppTokens.add(this);
597 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700598 mIsExiting = true;
599 } else {
600 // Make sure there is no animation running on this token, so any windows associated
601 // with it will be removed as soon as their animations are complete
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200602 cancelAnimation();
Wale Ogunwale3106ae012017-05-16 08:56:37 -0700603 if (stack != null) {
604 stack.mExitingAppTokens.remove(this);
605 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700606 removeIfPossible();
607 }
608
609 removed = true;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700610 stopFreezingScreen(true, true);
Bryce Lee6d410262017-02-28 15:30:17 -0800611
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700612 if (mService.mFocusedApp == this) {
613 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "Removing focused app token:" + this);
614 mService.mFocusedApp = null;
615 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
616 mService.mInputMonitor.setFocusedAppLw(null);
617 }
618
619 if (!delayed) {
620 updateReportedVisibilityLocked();
621 }
Wale Ogunwalee287e192017-04-21 09:30:12 -0700622
623 mRemovingFromDisplay = false;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700624 }
625
Chong Zhange05bcb12016-07-26 17:47:29 -0700626 void clearAnimatingFlags() {
Chong Zhangb0d26702016-08-12 16:03:29 -0700627 boolean wallpaperMightChange = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700628 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700629 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700630 wallpaperMightChange |= win.clearAnimatingFlags();
Chong Zhange05bcb12016-07-26 17:47:29 -0700631 }
Chong Zhangb0d26702016-08-12 16:03:29 -0700632 if (wallpaperMightChange) {
633 requestUpdateWallpaperIfNeeded();
634 }
Chong Zhange05bcb12016-07-26 17:47:29 -0700635 }
636
Robert Carre12aece2016-02-02 22:43:27 -0800637 void destroySurfaces() {
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700638 destroySurfaces(false /*cleanupOnResume*/);
639 }
640
641 /**
642 * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure
643 * the client has finished with them.
644 *
645 * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If
646 * set to true, destroy only surfaces of removed windows, and clear relevant flags of the
647 * others so that they are ready to be reused. If set to false (common case), destroy all
648 * surfaces that's eligible, if the app is already stopped.
649 */
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700650 private void destroySurfaces(boolean cleanupOnResume) {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700651 boolean destroyedSomething = false;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100652
653 // Copying to a different list as multiple children can be removed.
Jorim Jaggi59f3e922018-01-05 15:40:32 +0100654 final ArrayList<WindowState> children = new ArrayList<>(mChildren);
Jorim Jaggia5e10572017-11-15 14:36:26 +0100655 for (int i = children.size() - 1; i >= 0; i--) {
656 final WindowState win = children.get(i);
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700657 destroyedSomething |= win.destroySurface(cleanupOnResume, mAppStopped);
Robert Carre12aece2016-02-02 22:43:27 -0800658 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700659 if (destroyedSomething) {
660 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700661 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Adrian Roos4d18a2e2017-12-19 19:08:05 +0100662 updateLetterbox(null);
Robert Carre12aece2016-02-02 22:43:27 -0800663 }
664 }
665
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800666 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700667 * Notify that the app is now resumed, and it was not stopped before, perform a clean
668 * up of the surfaces
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800669 */
Jorim Jaggibae01b12017-04-11 16:29:10 -0700670 void notifyAppResumed(boolean wasStopped) {
Chong Zhangad24f962016-08-25 12:12:33 -0700671 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped
Jorim Jaggibae01b12017-04-11 16:29:10 -0700672 + " " + this);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700673 mAppStopped = false;
chaviwd3bf08d2017-08-01 17:24:59 -0700674 // Allow the window to turn the screen on once the app is resumed again.
675 setCanTurnScreenOn(true);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700676 if (!wasStopped) {
677 destroySurfaces(true /*cleanupOnResume*/);
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800678 }
Robert Carre12aece2016-02-02 22:43:27 -0800679 }
680
Chong Zhangbef461f2015-10-27 11:38:24 -0700681 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700682 * Notify that the app has stopped, and it is okay to destroy any surfaces which were
683 * keeping alive in case they were still being used.
684 */
685 void notifyAppStopped() {
686 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this);
687 mAppStopped = true;
688 destroySurfaces();
689 // Remove any starting window that was added for this app if they are still around.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800690 if (getController() != null) {
691 getController().removeStartingWindow();
692 }
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700693 }
694
Chong Zhang92147042016-05-09 12:47:11 -0700695 void clearAllDrawn() {
696 allDrawn = false;
697 deferClearAllDrawn = false;
Chong Zhangbef461f2015-10-27 11:38:24 -0700698 }
699
Bryce Lee6d410262017-02-28 15:30:17 -0800700 Task getTask() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800701 return (Task) getParent();
Bryce Lee6d410262017-02-28 15:30:17 -0800702 }
703
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800704 TaskStack getStack() {
705 final Task task = getTask();
706 if (task != null) {
707 return task.mStack;
708 } else {
709 return null;
710 }
711 }
712
Bryce Lee6d410262017-02-28 15:30:17 -0800713 @Override
714 void onParentSet() {
715 super.onParentSet();
716
Robert Carred3e83b2017-04-21 13:26:55 -0700717 final Task task = getTask();
718
Bryce Lee6d410262017-02-28 15:30:17 -0800719 // When the associated task is {@code null}, the {@link AppWindowToken} can no longer
720 // access visual elements like the {@link DisplayContent}. We must remove any associations
721 // such as animations.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800722 if (!mReparenting) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800723 if (task == null) {
724 // It is possible we have been marked as a closing app earlier. We must remove ourselves
725 // from this list so we do not participate in any future animations.
726 mService.mClosingApps.remove(this);
Robert Carred3e83b2017-04-21 13:26:55 -0700727 } else if (mLastParent != null && mLastParent.mStack != null) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800728 task.mStack.mExitingAppTokens.remove(this);
729 }
Bryce Lee6d410262017-02-28 15:30:17 -0800730 }
Robert Carred3e83b2017-04-21 13:26:55 -0700731 mLastParent = task;
Bryce Lee6d410262017-02-28 15:30:17 -0800732 }
733
Wale Ogunwalefa854eb2016-09-20 13:43:52 -0700734 void postWindowRemoveStartingWindowCleanup(WindowState win) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700735 // TODO: Something smells about the code below...Is there a better way?
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700736 if (startingWindow == win) {
737 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800738 if (getController() != null) {
739 getController().removeStartingWindow();
740 }
Wale Ogunwale6c459212017-05-17 08:56:03 -0700741 } else if (mChildren.size() == 0) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700742 // If this is the last window and we had requested a starting transition window,
743 // well there is no point now.
Jorim Jaggi02886a82016-12-06 09:10:06 -0800744 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingData");
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700745 startingData = null;
Wale Ogunwale6c459212017-05-17 08:56:03 -0700746 if (mHiddenSetFromTransferredStartingWindow) {
747 // We set the hidden state to false for the token from a transferred starting window.
748 // We now reset it back to true since the starting window was the last window in the
749 // token.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200750 setHidden(true);
Wale Ogunwale6c459212017-05-17 08:56:03 -0700751 }
Jorim Jaggi829b9cd2017-01-23 16:20:53 +0100752 } else if (mChildren.size() == 1 && startingSurface != null && !isRelaunching()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700753 // If this is the last window except for a starting transition window,
754 // we need to get rid of the starting transition.
Jorim Jaggie4b0f282017-05-17 15:10:29 +0200755 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Last window, removing starting window "
756 + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800757 if (getController() != null) {
758 getController().removeStartingWindow();
759 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700760 }
761 }
762
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700763 void removeDeadWindows() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700764 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700765 WindowState win = mChildren.get(winNdx);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800766 if (win.mAppDied) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700767 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700768 "removeDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800769 // Set mDestroying, we don't want any animation or delayed removal here.
770 win.mDestroying = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700771 // Also removes child windows.
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700772 win.removeIfPossible();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800773 }
774 }
775 }
776
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700777 boolean hasWindowsAlive() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700778 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700779 // No need to loop through child windows as the answer should be the same as that of the
780 // parent window.
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700781 if (!(mChildren.get(i)).mAppDied) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700782 return true;
783 }
784 }
785 return false;
786 }
787
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700788 void setWillReplaceWindows(boolean animate) {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700789 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
790 "Marking app token " + this + " with replacing windows.");
Robert Carra1eb4392015-12-10 12:43:51 -0800791
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700792 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700793 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700794 w.setWillReplaceWindow(animate);
Robert Carra1eb4392015-12-10 12:43:51 -0800795 }
Robert Carra1eb4392015-12-10 12:43:51 -0800796 }
797
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700798 void setWillReplaceChildWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700799 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this
Robert Carr23fa16b2016-01-13 13:19:58 -0800800 + " with replacing child windows.");
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700801 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700802 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700803 w.setWillReplaceChildWindows();
Robert Carr23fa16b2016-01-13 13:19:58 -0800804 }
805 }
806
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700807 void clearWillReplaceWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700808 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
809 "Resetting app token " + this + " of replacing window marks.");
Chong Zhangf596cd52016-01-05 13:42:44 -0800810
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700811 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700812 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700813 w.clearWillReplaceWindow();
Chong Zhangf596cd52016-01-05 13:42:44 -0800814 }
815 }
816
Chong Zhang4d7369a2016-04-25 16:09:14 -0700817 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700818 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700819 final WindowState w = mChildren.get(i);
Chong Zhang4d7369a2016-04-25 16:09:14 -0700820 w.requestUpdateWallpaperIfNeeded();
821 }
822 }
823
Chong Zhangd78ddb42016-03-02 17:01:14 -0800824 boolean isRelaunching() {
825 return mPendingRelaunchCount > 0;
826 }
827
Robert Carr68375192017-06-13 12:41:53 -0700828 boolean shouldFreezeBounds() {
829 final Task task = getTask();
830
831 // For freeform windows, we can't freeze the bounds at the moment because this would make
832 // the resizing unresponsive.
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700833 if (task == null || task.inFreeformWindowingMode()) {
Robert Carr68375192017-06-13 12:41:53 -0700834 return false;
835 }
836
837 // We freeze the bounds while drag resizing to deal with the time between
838 // the divider/drag handle being released, and the handling it's new
839 // configuration. If we are relaunched outside of the drag resizing state,
840 // we need to be careful not to do this.
841 return getTask().isDragResizing();
842 }
843
Chong Zhangd78ddb42016-03-02 17:01:14 -0800844 void startRelaunching() {
Robert Carr68375192017-06-13 12:41:53 -0700845 if (shouldFreezeBounds()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -0800846 freezeBounds();
847 }
Robert Carrd5c7dd62017-03-08 10:39:30 -0800848
849 // In the process of tearing down before relaunching, the app will
850 // try and clean up it's child surfaces. We need to prevent this from
851 // happening, so we sever the children, transfering their ownership
852 // from the client it-self to the parent surface (owned by us).
853 for (int i = mChildren.size() - 1; i >= 0; i--) {
854 final WindowState w = mChildren.get(i);
855 w.mWinAnimator.detachChildren();
856 }
857
Chong Zhangd78ddb42016-03-02 17:01:14 -0800858 mPendingRelaunchCount++;
859 }
860
861 void finishRelaunching() {
Robert Carr68375192017-06-13 12:41:53 -0700862 unfreezeBounds();
863
Chong Zhangd78ddb42016-03-02 17:01:14 -0800864 if (mPendingRelaunchCount > 0) {
865 mPendingRelaunchCount--;
Bryce Lee081554b2017-05-25 07:52:12 -0700866 } else {
867 // Update keyguard flags upon finishing relaunch.
868 checkKeyguardFlagsChanged();
Chong Zhangd78ddb42016-03-02 17:01:14 -0800869 }
870 }
871
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700872 void clearRelaunching() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700873 if (mPendingRelaunchCount == 0) {
874 return;
875 }
Robert Carr68375192017-06-13 12:41:53 -0700876 unfreezeBounds();
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700877 mPendingRelaunchCount = 0;
878 }
879
Wale Ogunwale07bcab72016-10-14 15:30:09 -0700880 /**
881 * Returns true if the new child window we are adding to this token is considered greater than
882 * the existing child window in this token in terms of z-order.
883 */
884 @Override
885 protected boolean isFirstChildWindowGreaterThanSecond(WindowState newWindow,
886 WindowState existingWindow) {
887 final int type1 = newWindow.mAttrs.type;
888 final int type2 = existingWindow.mAttrs.type;
889
890 // Base application windows should be z-ordered BELOW all other windows in the app token.
891 if (type1 == TYPE_BASE_APPLICATION && type2 != TYPE_BASE_APPLICATION) {
892 return false;
893 } else if (type1 != TYPE_BASE_APPLICATION && type2 == TYPE_BASE_APPLICATION) {
894 return true;
895 }
896
897 // Starting windows should be z-ordered ABOVE all other windows in the app token.
898 if (type1 == TYPE_APPLICATION_STARTING && type2 != TYPE_APPLICATION_STARTING) {
899 return true;
900 } else if (type1 != TYPE_APPLICATION_STARTING && type2 == TYPE_APPLICATION_STARTING) {
901 return false;
902 }
903
904 // Otherwise the new window is greater than the existing window.
905 return true;
906 }
907
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700908 @Override
Robert Carra1eb4392015-12-10 12:43:51 -0800909 void addWindow(WindowState w) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700910 super.addWindow(w);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700911
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700912 boolean gotReplacementWindow = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700913 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700914 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700915 gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w);
916 }
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700917
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700918 // if we got a replacement window, reset the timeout to give drawing more time
919 if (gotReplacementWindow) {
920 mService.scheduleWindowReplacementTimeouts(this);
Robert Carra1eb4392015-12-10 12:43:51 -0800921 }
Jorim Jaggife762342016-10-13 14:33:27 +0200922 checkKeyguardFlagsChanged();
923 }
924
925 @Override
926 void removeChild(WindowState child) {
927 super.removeChild(child);
928 checkKeyguardFlagsChanged();
Adrian Roos4d18a2e2017-12-19 19:08:05 +0100929 updateLetterbox(child);
Robert Carra1eb4392015-12-10 12:43:51 -0800930 }
931
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700932 private boolean waitingForReplacement() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700933 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700934 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700935 if (candidate.waitingForReplacement()) {
Robert Carra1eb4392015-12-10 12:43:51 -0800936 return true;
937 }
938 }
939 return false;
940 }
941
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700942 void onWindowReplacementTimeout() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700943 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700944 (mChildren.get(i)).onWindowReplacementTimeout();
Robert Carra1eb4392015-12-10 12:43:51 -0800945 }
946 }
947
Winson Chung30480042017-01-26 10:55:34 -0800948 void reparent(Task task, int position) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800949 final Task currentTask = getTask();
950 if (task == currentTask) {
Winson Chung30480042017-01-26 10:55:34 -0800951 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800952 "window token=" + this + " already child of task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -0800953 }
Bryce Lee6d410262017-02-28 15:30:17 -0800954
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800955 if (currentTask.mStack != task.mStack) {
Bryce Lee6d410262017-02-28 15:30:17 -0800956 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800957 "window token=" + this + " current task=" + currentTask
Bryce Lee6d410262017-02-28 15:30:17 -0800958 + " belongs to a different stack than " + task);
959 }
960
Winson Chung30480042017-01-26 10:55:34 -0800961 if (DEBUG_ADD_REMOVE) Slog.i(TAG, "reParentWindowToken: removing window token=" + this
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800962 + " from task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -0800963 final DisplayContent prevDisplayContent = getDisplayContent();
964
Bryce Lee6d410262017-02-28 15:30:17 -0800965 mReparenting = true;
966
Winson Chung30480042017-01-26 10:55:34 -0800967 getParent().removeChild(this);
968 task.addChild(this, position);
969
Bryce Lee6d410262017-02-28 15:30:17 -0800970 mReparenting = false;
971
Winson Chung30480042017-01-26 10:55:34 -0800972 // Relayout display(s).
973 final DisplayContent displayContent = task.getDisplayContent();
974 displayContent.setLayoutNeeded();
975 if (prevDisplayContent != displayContent) {
976 onDisplayChanged(displayContent);
977 prevDisplayContent.setLayoutNeeded();
978 }
979 }
980
Jorim Jaggi0429f352015-12-22 16:29:16 +0100981 /**
982 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
983 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
984 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
985 * with a queue.
986 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800987 private void freezeBounds() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800988 final Task task = getTask();
989 mFrozenBounds.offer(new Rect(task.mPreparedFrozenBounds));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700990
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800991 if (task.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) {
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700992 // We didn't call prepareFreezingBounds on the task, so use the current value.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800993 mFrozenMergedConfig.offer(new Configuration(task.getConfiguration()));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700994 } else {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800995 mFrozenMergedConfig.offer(new Configuration(task.mPreparedFrozenMergedConfig));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700996 }
Andrii Kulianb10330d2016-09-16 13:51:46 -0700997 // Calling unset() to make it equal to Configuration.EMPTY.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800998 task.mPreparedFrozenMergedConfig.unset();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100999 }
1000
1001 /**
1002 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
1003 */
Chong Zhangd78ddb42016-03-02 17:01:14 -08001004 private void unfreezeBounds() {
Robert Carr68375192017-06-13 12:41:53 -07001005 if (mFrozenBounds.isEmpty()) {
1006 return;
Wale Ogunwale37dbafc2016-06-27 10:15:20 -07001007 }
Robert Carr68375192017-06-13 12:41:53 -07001008 mFrozenBounds.remove();
Wale Ogunwale37dbafc2016-06-27 10:15:20 -07001009 if (!mFrozenMergedConfig.isEmpty()) {
1010 mFrozenMergedConfig.remove();
1011 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001012 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001013 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001014 win.onUnfreezeBounds();
Jorim Jaggi4846ee32016-01-07 17:39:12 +01001015 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001016 mService.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +01001017 }
1018
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001019 void setAppLayoutChanges(int changes, String reason) {
1020 if (!mChildren.isEmpty()) {
1021 final DisplayContent dc = getDisplayContent();
1022 dc.pendingLayoutChanges |= changes;
1023 if (DEBUG_LAYOUT_REPEATS) {
1024 mService.mWindowPlacerLocked.debugLayoutRepeats(reason, dc.pendingLayoutChanges);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001025 }
1026 }
1027 }
1028
1029 void removeReplacedWindowIfNeeded(WindowState replacement) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001030 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001031 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001032 if (win.removeReplacedWindowIfNeeded(replacement)) {
1033 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001034 }
1035 }
1036 }
1037
1038 void startFreezingScreen() {
1039 if (DEBUG_ORIENTATION) logWithStack(TAG, "Set freezing of " + appToken + ": hidden="
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001040 + isHidden() + " freezing=" + mFreezingScreen + " hiddenRequested="
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001041 + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001042 if (!hiddenRequested) {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001043 if (!mFreezingScreen) {
1044 mFreezingScreen = true;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001045 mService.registerAppFreezeListener(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001046 mService.mAppsFreezingScreen++;
1047 if (mService.mAppsFreezingScreen == 1) {
Bryce Lee8f853582017-06-05 17:25:59 -07001048 mService.startFreezingDisplayLocked(false, 0, 0, getDisplayContent());
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001049 mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT);
1050 mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001051 }
1052 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001053 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001054 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001055 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001056 w.onStartFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001057 }
1058 }
1059 }
1060
1061 void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001062 if (!mFreezingScreen) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001063 return;
1064 }
1065 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + this + " force=" + force);
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001066 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001067 boolean unfrozeWindows = false;
1068 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001069 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001070 unfrozeWindows |= w.onStopFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001071 }
1072 if (force || unfrozeWindows) {
1073 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this);
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001074 mFreezingScreen = false;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001075 mService.unregisterAppFreezeListener(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001076 mService.mAppsFreezingScreen--;
1077 mService.mLastFinishedFreezeSource = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001078 }
1079 if (unfreezeSurfaceNow) {
1080 if (unfrozeWindows) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001081 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001082 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001083 mService.stopFreezingDisplayLocked();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001084 }
1085 }
1086
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001087 @Override
1088 public void onAppFreezeTimeout() {
1089 Slog.w(TAG_WM, "Force clearing freeze: " + this);
1090 stopFreezingScreen(true, true);
1091 }
1092
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001093 boolean transferStartingWindow(IBinder transferFrom) {
Wale Ogunwale02319a62016-09-26 15:21:22 -07001094 final AppWindowToken fromToken = getDisplayContent().getAppWindowToken(transferFrom);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001095 if (fromToken == null) {
1096 return false;
1097 }
1098
1099 final WindowState tStartingWindow = fromToken.startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001100 if (tStartingWindow != null && fromToken.startingSurface != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001101 // In this case, the starting icon has already been displayed, so start
1102 // letting windows get shown immediately without any more transitions.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001103 mService.mSkipAppTransitionAnimation = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001104
1105 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow
1106 + " from " + fromToken + " to " + this);
1107
1108 final long origId = Binder.clearCallingIdentity();
Peter Visontay3556a3b2017-11-01 17:23:17 +00001109 try {
1110 // Transfer the starting window over to the new token.
1111 startingData = fromToken.startingData;
1112 startingSurface = fromToken.startingSurface;
1113 startingDisplayed = fromToken.startingDisplayed;
1114 fromToken.startingDisplayed = false;
1115 startingWindow = tStartingWindow;
1116 reportedVisible = fromToken.reportedVisible;
1117 fromToken.startingData = null;
1118 fromToken.startingSurface = null;
1119 fromToken.startingWindow = null;
1120 fromToken.startingMoved = true;
1121 tStartingWindow.mToken = this;
1122 tStartingWindow.mAppToken = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001123
Peter Visontay3556a3b2017-11-01 17:23:17 +00001124 if (DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1125 "Removing starting " + tStartingWindow + " from " + fromToken);
1126 fromToken.removeChild(tStartingWindow);
1127 fromToken.postWindowRemoveStartingWindowCleanup(tStartingWindow);
1128 fromToken.mHiddenSetFromTransferredStartingWindow = false;
1129 addWindow(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001130
Peter Visontay3556a3b2017-11-01 17:23:17 +00001131 // Propagate other interesting state between the tokens. If the old token is displayed,
1132 // we should immediately force the new one to be displayed. If it is animating, we need
1133 // to move that animation to the new one.
1134 if (fromToken.allDrawn) {
1135 allDrawn = true;
1136 deferClearAllDrawn = fromToken.deferClearAllDrawn;
1137 }
1138 if (fromToken.firstWindowDrawn) {
1139 firstWindowDrawn = true;
1140 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001141 if (!fromToken.isHidden()) {
1142 setHidden(false);
Peter Visontay3556a3b2017-11-01 17:23:17 +00001143 hiddenRequested = false;
1144 mHiddenSetFromTransferredStartingWindow = true;
1145 }
1146 setClientHidden(fromToken.mClientHidden);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001147
Jorim Jaggi980c9de2017-11-17 01:41:37 +01001148 transferAnimation(fromToken);
1149
1150 // When transferring an animation, we no longer need to apply an animation to the
1151 // the token we transfer the animation over. Thus, remove the animation from
1152 // pending opening apps.
1153 mService.mOpeningApps.remove(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001154
Peter Visontay3556a3b2017-11-01 17:23:17 +00001155 mService.updateFocusedWindowLocked(
1156 UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/);
1157 getDisplayContent().setLayoutNeeded();
1158 mService.mWindowPlacerLocked.performSurfacePlacement();
1159 } finally {
1160 Binder.restoreCallingIdentity(origId);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001161 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001162 return true;
1163 } else if (fromToken.startingData != null) {
1164 // The previous app was getting ready to show a
1165 // starting window, but hasn't yet done so. Steal it!
1166 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1167 "Moving pending starting from " + fromToken + " to " + this);
1168 startingData = fromToken.startingData;
1169 fromToken.startingData = null;
1170 fromToken.startingMoved = true;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001171 if (getController() != null) {
1172 getController().scheduleAddStartingWindow();
1173 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001174 return true;
1175 }
1176
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001177 // TODO: Transfer thumbnail
1178
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001179 return false;
1180 }
1181
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001182 boolean isLastWindow(WindowState win) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001183 return mChildren.size() == 1 && mChildren.get(0) == win;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001184 }
1185
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001186 @Override
1187 void onAppTransitionDone() {
1188 sendingToBottom = false;
1189 }
1190
Wale Ogunwale51362492016-09-08 17:49:17 -07001191 /**
1192 * We override because this class doesn't want its children affecting its reported orientation
1193 * in anyway.
1194 */
1195 @Override
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001196 int getOrientation(int candidate) {
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001197 if (candidate == SCREEN_ORIENTATION_BEHIND) {
1198 // Allow app to specify orientation regardless of its visibility state if the current
1199 // candidate want us to use orientation behind. I.e. the visible app on-top of this one
1200 // wants us to use the orientation of the app behind it.
1201 return mOrientation;
1202 }
1203
Bryce Lee61fbcbc2017-03-10 14:14:03 -08001204 // The {@link AppWindowToken} should only specify an orientation when it is not closing or
1205 // going to the bottom. Allowing closing {@link AppWindowToken} to participate can lead to
1206 // an Activity in another task being started in the wrong orientation during the transition.
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001207 if (!(sendingToBottom || mService.mClosingApps.contains(this))
Bryce Lee00d586d2017-07-28 20:48:43 -07001208 && (isVisible() || mService.mOpeningApps.contains(this) || isOnTop())) {
Bryce Leea163b762017-01-24 11:05:01 -08001209 return mOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001210 }
Bryce Leea163b762017-01-24 11:05:01 -08001211
1212 return SCREEN_ORIENTATION_UNSET;
Wale Ogunwale51362492016-09-08 17:49:17 -07001213 }
1214
Wale Ogunwaleb198b742016-12-01 08:44:09 -08001215 /** Returns the app's preferred orientation regardless of its currently visibility state. */
1216 int getOrientationIgnoreVisibility() {
1217 return mOrientation;
1218 }
1219
Craig Mautnerdbb79912012-03-01 18:59:14 -08001220 @Override
Winson Chunge55c0192017-08-24 14:50:48 -07001221 public void onConfigurationChanged(Configuration newParentConfig) {
1222 final int prevWinMode = getWindowingMode();
1223 super.onConfigurationChanged(newParentConfig);
1224 final int winMode = getWindowingMode();
1225
1226 if (prevWinMode == winMode) {
1227 return;
1228 }
1229
1230 if (prevWinMode != WINDOWING_MODE_UNDEFINED && winMode == WINDOWING_MODE_PINNED) {
1231 // Entering PiP from fullscreen, reset the snap fraction
1232 mDisplayContent.mPinnedStackControllerLocked.resetReentrySnapFraction(this);
1233 } else if (prevWinMode == WINDOWING_MODE_PINNED && winMode != WINDOWING_MODE_UNDEFINED) {
1234 // Leaving PiP to fullscreen, save the snap fraction based on the pre-animation bounds
1235 // for the next re-entry into PiP (assuming the activity is not hidden or destroyed)
1236 final TaskStack pinnedStack = mDisplayContent.getPinnedStack();
1237 if (pinnedStack != null) {
1238 mDisplayContent.mPinnedStackControllerLocked.saveReentrySnapFraction(this,
1239 pinnedStack.mPreAnimationBounds);
1240 }
1241 }
1242 }
1243
1244 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001245 void checkAppWindowsReadyToShow() {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001246 if (allDrawn == mLastAllDrawn) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001247 return;
1248 }
1249
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001250 mLastAllDrawn = allDrawn;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001251 if (!allDrawn) {
1252 return;
1253 }
1254
1255 // The token has now changed state to having all windows shown... what to do, what to do?
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001256 if (mFreezingScreen) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001257 showAllWindowsLocked();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001258 stopFreezingScreen(false, true);
1259 if (DEBUG_ORIENTATION) Slog.i(TAG,
1260 "Setting mOrientationChangeComplete=true because wtoken " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001261 + " numInteresting=" + mNumInterestingWindows + " numDrawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001262 // This will set mOrientationChangeComplete and cause a pass through layout.
1263 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001264 "checkAppWindowsReadyToShow: freezingScreen");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001265 } else {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001266 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001267
1268 // We can now show all of the drawn windows!
1269 if (!mService.mOpeningApps.contains(this)) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001270 showAllWindowsLocked();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001271 }
1272 }
1273 }
1274
Matthew Ng5d23afa2017-06-21 16:16:24 -07001275 /**
Bryce Leed390deb2017-06-22 13:14:28 -07001276 * Returns whether the drawn window states of this {@link AppWindowToken} has considered every
1277 * child {@link WindowState}. A child is considered if it has been passed into
1278 * {@link #updateDrawnWindowStates(WindowState)} after being added. This is used to determine
1279 * whether states, such as {@code allDrawn}, can be set, which relies on state variables such as
1280 * {@code mNumInterestingWindows}, which depend on all {@link WindowState}s being considered.
1281 *
1282 * @return {@code true} If all children have been considered, {@code false}.
1283 */
1284 private boolean allDrawnStatesConsidered() {
Bryce Lee6311c4b2017-07-06 14:09:29 -07001285 for (int i = mChildren.size() - 1; i >= 0; --i) {
1286 final WindowState child = mChildren.get(i);
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001287 if (child.mightAffectAllDrawn() && !child.getDrawnStateEvaluated()) {
Bryce Leed390deb2017-06-22 13:14:28 -07001288 return false;
1289 }
1290 }
1291 return true;
1292 }
1293
1294 /**
Matthew Ng5d23afa2017-06-21 16:16:24 -07001295 * Determines if the token has finished drawing. This should only be called from
1296 * {@link DisplayContent#applySurfaceChangesTransaction}
1297 */
Matthew Ng498c71d2017-04-18 13:55:45 -07001298 void updateAllDrawn() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001299 if (!allDrawn) {
Matthew Ng498c71d2017-04-18 13:55:45 -07001300 // Number of drawn windows can be less when a window is being relaunched, wait for
Bryce Leed390deb2017-06-22 13:14:28 -07001301 // all windows to be launched and drawn for this token be considered all drawn.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001302 final int numInteresting = mNumInterestingWindows;
Bryce Leed390deb2017-06-22 13:14:28 -07001303
1304 // We must make sure that all present children have been considered (determined by
1305 // {@link #allDrawnStatesConsidered}) before evaluating whether everything has been
1306 // drawn.
1307 if (numInteresting > 0 && allDrawnStatesConsidered()
1308 && mNumDrawnWindows >= numInteresting && !isRelaunching()) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001309 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawn: " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001310 + " interesting=" + numInteresting + " drawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001311 allDrawn = true;
1312 // Force an additional layout pass where
1313 // WindowStateAnimator#commitFinishDrawingLocked() will call performShowLocked().
Matthew Ng498c71d2017-04-18 13:55:45 -07001314 if (mDisplayContent != null) {
1315 mDisplayContent.setLayoutNeeded();
1316 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001317 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Robert Carrecc06b32017-04-18 14:25:10 -07001318
Winson Chunge7ba6862017-05-24 12:13:33 -07001319 // Notify the pinned stack upon all windows drawn. If there was an animation in
1320 // progress then this signal will resume that animation.
Wale Ogunwale61911492017-10-11 08:50:50 -07001321 final TaskStack pinnedStack = mDisplayContent.getPinnedStack();
Winson Chunge7ba6862017-05-24 12:13:33 -07001322 if (pinnedStack != null) {
1323 pinnedStack.onAllWindowsDrawn();
Robert Carrecc06b32017-04-18 14:25:10 -07001324 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001325 }
1326 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001327 }
1328
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001329 /**
1330 * Updated this app token tracking states for interesting and drawn windows based on the window.
1331 *
1332 * @return Returns true if the input window is considered interesting and drawn while all the
1333 * windows in this app token where not considered drawn as of the last pass.
1334 */
1335 boolean updateDrawnWindowStates(WindowState w) {
Bryce Leed390deb2017-06-22 13:14:28 -07001336 w.setDrawnStateEvaluated(true /*evaluated*/);
1337
Jorim Jaggie4b0f282017-05-17 15:10:29 +02001338 if (DEBUG_STARTING_WINDOW_VERBOSE && w == startingWindow) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001339 Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" + w.isOnScreen()
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001340 + " allDrawn=" + allDrawn + " freezingScreen=" + mFreezingScreen);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001341 }
1342
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001343 if (allDrawn && !mFreezingScreen) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001344 return false;
1345 }
1346
1347 if (mLastTransactionSequence != mService.mTransactionSequence) {
1348 mLastTransactionSequence = mService.mTransactionSequence;
1349 mNumInterestingWindows = mNumDrawnWindows = 0;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001350 startingDisplayed = false;
1351 }
1352
1353 final WindowStateAnimator winAnimator = w.mWinAnimator;
1354
1355 boolean isInterestingAndDrawn = false;
1356
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001357 if (!allDrawn && w.mightAffectAllDrawn()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001358 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
1359 Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw()
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001360 + ", isAnimationSet=" + isSelfAnimating());
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001361 if (!w.isDrawnLw()) {
1362 Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController
1363 + " pv=" + w.mPolicyVisibility
1364 + " mDrawState=" + winAnimator.drawStateToString()
1365 + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001366 + " a=" + isSelfAnimating());
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001367 }
1368 }
1369
1370 if (w != startingWindow) {
1371 if (w.isInteresting()) {
1372 mNumInterestingWindows++;
1373 if (w.isDrawnLw()) {
1374 mNumDrawnWindows++;
1375
1376 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, "tokenMayBeDrawn: "
1377 + this + " w=" + w + " numInteresting=" + mNumInterestingWindows
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001378 + " freezingScreen=" + mFreezingScreen
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001379 + " mAppFreezing=" + w.mAppFreezing);
1380
1381 isInterestingAndDrawn = true;
1382 }
1383 }
1384 } else if (w.isDrawnLw()) {
Jorim Jaggi3878ca32017-02-02 17:13:05 -08001385 if (getController() != null) {
1386 getController().reportStartingWindowDrawn();
1387 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001388 startingDisplayed = true;
1389 }
1390 }
1391
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001392 return isInterestingAndDrawn;
1393 }
1394
Adrian Roos4d18a2e2017-12-19 19:08:05 +01001395 void updateLetterbox(WindowState winHint) {
1396 final WindowState w = findMainWindow();
1397 if (w != winHint && winHint != null && w != null) {
1398 return;
1399 }
1400 final boolean needsLetterbox = w != null && w.isLetterboxedAppWindow()
1401 && fillsParent() && w.hasDrawnLw();
1402 if (needsLetterbox) {
1403 if (mLetterbox == null) {
1404 mLetterbox = new Letterbox(() -> makeChildSurface(null));
1405 }
1406 mLetterbox.setDimensions(mPendingTransaction, getParent().getBounds(), w.mFrame);
1407 } else if (mLetterbox != null) {
1408 final SurfaceControl.Transaction t = new SurfaceControl.Transaction();
1409 SurfaceControl.openTransaction();
1410 try {
1411 mLetterbox.hide(t);
1412 } finally {
1413 // TODO: This should use pendingTransaction eventually, but right now things
1414 // happening on the animation finished callback are happening on the global
1415 // transaction.
1416 SurfaceControl.mergeToGlobalTransaction(t);
1417 SurfaceControl.closeTransaction();
1418 }
1419 }
1420 }
1421
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001422 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001423 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001424 // For legacy reasons we process the TaskStack.mExitingAppTokens first in DisplayContent
1425 // before the non-exiting app tokens. So, we skip the exiting app tokens here.
1426 // TODO: Investigate if we need to continue to do this or if we can just process them
1427 // in-order.
1428 if (mIsExiting && !waitingForReplacement()) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001429 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001430 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001431 return forAllWindowsUnchecked(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001432 }
1433
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001434 boolean forAllWindowsUnchecked(ToBooleanFunction<WindowState> callback,
1435 boolean traverseTopToBottom) {
1436 return super.forAllWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001437 }
1438
1439 @Override
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001440 AppWindowToken asAppWindowToken() {
1441 // I am an app window token!
1442 return this;
1443 }
1444
1445 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -07001446 boolean fillsParent() {
1447 return mFillsParent;
1448 }
1449
1450 void setFillsParent(boolean fillsParent) {
1451 mFillsParent = fillsParent;
1452 }
1453
Jorim Jaggife762342016-10-13 14:33:27 +02001454 boolean containsDismissKeyguardWindow() {
Bryce Lee081554b2017-05-25 07:52:12 -07001455 // Window state is transient during relaunch. We are not guaranteed to be frozen during the
1456 // entirety of the relaunch.
1457 if (isRelaunching()) {
1458 return mLastContainsDismissKeyguardWindow;
1459 }
1460
Jorim Jaggife762342016-10-13 14:33:27 +02001461 for (int i = mChildren.size() - 1; i >= 0; i--) {
1462 if ((mChildren.get(i).mAttrs.flags & FLAG_DISMISS_KEYGUARD) != 0) {
1463 return true;
1464 }
1465 }
1466 return false;
1467 }
1468
1469 boolean containsShowWhenLockedWindow() {
Bryce Lee081554b2017-05-25 07:52:12 -07001470 // When we are relaunching, it is possible for us to be unfrozen before our previous
1471 // windows have been added back. Using the cached value ensures that our previous
1472 // showWhenLocked preference is honored until relaunching is complete.
1473 if (isRelaunching()) {
1474 return mLastContainsShowWhenLockedWindow;
1475 }
1476
Jorim Jaggife762342016-10-13 14:33:27 +02001477 for (int i = mChildren.size() - 1; i >= 0; i--) {
1478 if ((mChildren.get(i).mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
1479 return true;
1480 }
1481 }
Bryce Lee081554b2017-05-25 07:52:12 -07001482
Jorim Jaggife762342016-10-13 14:33:27 +02001483 return false;
1484 }
1485
1486 void checkKeyguardFlagsChanged() {
1487 final boolean containsDismissKeyguard = containsDismissKeyguardWindow();
1488 final boolean containsShowWhenLocked = containsShowWhenLockedWindow();
1489 if (containsDismissKeyguard != mLastContainsDismissKeyguardWindow
1490 || containsShowWhenLocked != mLastContainsShowWhenLockedWindow) {
1491 mService.notifyKeyguardFlagsChanged(null /* callback */);
1492 }
1493 mLastContainsDismissKeyguardWindow = containsDismissKeyguard;
1494 mLastContainsShowWhenLockedWindow = containsShowWhenLocked;
1495 }
1496
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001497 WindowState getImeTargetBelowWindow(WindowState w) {
1498 final int index = mChildren.indexOf(w);
1499 if (index > 0) {
1500 final WindowState target = mChildren.get(index - 1);
1501 if (target.canBeImeTarget()) {
1502 return target;
1503 }
1504 }
1505 return null;
1506 }
1507
Winson Chungbe9be7f2017-06-28 10:55:22 -07001508 int getLowestAnimLayer() {
1509 for (int i = 0; i < mChildren.size(); i++) {
1510 final WindowState w = mChildren.get(i);
1511 if (w.mRemoved) {
1512 continue;
1513 }
1514 return w.mWinAnimator.mAnimLayer;
1515 }
1516 return Integer.MAX_VALUE;
1517 }
1518
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001519 WindowState getHighestAnimLayerWindow(WindowState currentTarget) {
1520 WindowState candidate = null;
1521 for (int i = mChildren.indexOf(currentTarget); i >= 0; i--) {
1522 final WindowState w = mChildren.get(i);
1523 if (w.mRemoved) {
1524 continue;
1525 }
1526 if (candidate == null || w.mWinAnimator.mAnimLayer >
1527 candidate.mWinAnimator.mAnimLayer) {
1528 candidate = w;
1529 }
1530 }
1531 return candidate;
1532 }
1533
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001534 /**
1535 * See {@link Activity#setDisablePreviewScreenshots}.
1536 */
1537 void setDisablePreviewScreenshots(boolean disable) {
Wale Ogunwale6c459212017-05-17 08:56:03 -07001538 mDisablePreviewScreenshots = disable;
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001539 }
1540
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001541 /**
chaviwd3bf08d2017-08-01 17:24:59 -07001542 * Sets whether the current launch can turn the screen on. See {@link #canTurnScreenOn()}
1543 */
1544 void setCanTurnScreenOn(boolean canTurnScreenOn) {
1545 mCanTurnScreenOn = canTurnScreenOn;
1546 }
1547
1548 /**
1549 * Indicates whether the current launch can turn the screen on. This is to prevent multiple
1550 * relayouts from turning the screen back on. The screen should only turn on at most
1551 * once per activity resume.
1552 *
1553 * @return true if the screen can be turned on.
1554 */
1555 boolean canTurnScreenOn() {
1556 return mCanTurnScreenOn;
1557 }
1558
1559 /**
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001560 * Retrieves whether we'd like to generate a snapshot that's based solely on the theme. This is
1561 * the case when preview screenshots are disabled {@link #setDisablePreviewScreenshots} or when
1562 * we can't take a snapshot for other reasons, for example, if we have a secure window.
1563 *
1564 * @return True if we need to generate an app theme snapshot, false if we'd like to take a real
1565 * screenshot.
1566 */
1567 boolean shouldUseAppThemeSnapshot() {
Wale Ogunwale6c459212017-05-17 08:56:03 -07001568 return mDisablePreviewScreenshots || forAllWindows(w -> (w.mAttrs.flags & FLAG_SECURE) != 0,
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001569 true /* topToBottom */);
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001570 }
1571
chaviw23ee71c2017-12-18 11:29:41 -08001572 @Override
Jorim Jaggi596a1992017-12-29 14:48:02 +01001573 public SurfaceControl getAnimationLeashParent() {
1574 return getAppAnimationLayer();
chaviw23ee71c2017-12-18 11:29:41 -08001575 }
1576
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001577 boolean applyAnimationLocked(WindowManager.LayoutParams lp, int transit, boolean enter,
1578 boolean isVoiceInteraction) {
1579
1580 if (mService.mDisableTransitionAnimation) {
1581 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1582 Slog.v(TAG_WM, "applyAnimation: transition animation is disabled. atoken=" + this);
1583 }
1584 cancelAnimation();
1585 return false;
1586 }
1587
1588 // Only apply an animation if the display isn't frozen. If it is frozen, there is no reason
1589 // to animate and it can cause strange artifacts when we unfreeze the display if some
1590 // different animation is running.
1591 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "AWT#applyAnimationLocked");
1592 if (okToAnimate()) {
1593 final Animation a = loadAnimation(lp, transit, enter, isVoiceInteraction);
1594 if (a != null) {
chaviw23ee71c2017-12-18 11:29:41 -08001595 final TaskStack stack = getStack();
1596 mTmpPoint.set(0, 0);
chaviw23012112017-12-20 15:29:04 -08001597 mTmpRect.setEmpty();
chaviw23ee71c2017-12-18 11:29:41 -08001598 if (stack != null) {
1599 stack.getRelativePosition(mTmpPoint);
chaviw23012112017-12-20 15:29:04 -08001600 stack.getBounds(mTmpRect);
chaviw977482a2017-12-28 11:35:53 -08001601 mTmpRect.offsetTo(0, 0);
chaviw23ee71c2017-12-18 11:29:41 -08001602 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001603 final AnimationAdapter adapter = new LocalAnimationAdapter(
chaviw23012112017-12-20 15:29:04 -08001604 new WindowAnimationSpec(a, mTmpPoint, mTmpRect,
1605 mService.mAppTransition.canSkipFirstFrame(),
1606 mService.mAppTransition.getAppStackClipMode()),
Jorim Jaggi2e3c31d2017-11-20 19:49:00 +01001607 mService.mSurfaceAnimationRunner);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001608 if (a.getZAdjustment() == Animation.ZORDER_TOP) {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001609 mNeedsZBoost = true;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001610 }
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001611 startAnimation(getPendingTransaction(), adapter, !isVisible());
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001612 mTransit = transit;
1613 mTransitFlags = mService.mAppTransition.getTransitFlags();
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001614 }
1615 } else {
1616 cancelAnimation();
1617 }
1618 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
1619
1620 return isReallyAnimating();
1621 }
1622
1623 private Animation loadAnimation(WindowManager.LayoutParams lp, int transit, boolean enter,
1624 boolean isVoiceInteraction) {
1625 final DisplayContent displayContent = getTask().getDisplayContent();
1626 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
1627 final int width = displayInfo.appWidth;
1628 final int height = displayInfo.appHeight;
1629 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG_WM,
1630 "applyAnimation: atoken=" + this);
1631
1632 // Determine the visible rect to calculate the thumbnail clip
1633 final WindowState win = findMainWindow();
1634 final Rect frame = new Rect(0, 0, width, height);
1635 final Rect displayFrame = new Rect(0, 0,
1636 displayInfo.logicalWidth, displayInfo.logicalHeight);
1637 final Rect insets = new Rect();
1638 final Rect stableInsets = new Rect();
1639 Rect surfaceInsets = null;
1640 final boolean freeform = win != null && win.inFreeformWindowingMode();
1641 if (win != null) {
1642 // Containing frame will usually cover the whole screen, including dialog windows.
1643 // For freeform workspace windows it will not cover the whole screen and it also
1644 // won't exactly match the final freeform window frame (e.g. when overlapping with
1645 // the status bar). In that case we need to use the final frame.
1646 if (freeform) {
1647 frame.set(win.mFrame);
Adrian Roos4d18a2e2017-12-19 19:08:05 +01001648 } else if (win.isLetterboxedAppWindow()) {
1649 frame.set(getTask().getBounds());
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001650 } else {
1651 frame.set(win.mContainingFrame);
1652 }
1653 surfaceInsets = win.getAttrs().surfaceInsets;
1654 insets.set(win.mContentInsets);
1655 stableInsets.set(win.mStableInsets);
1656 }
1657
1658 if (mLaunchTaskBehind) {
1659 // Differentiate the two animations. This one which is briefly on the screen
1660 // gets the !enter animation, and the other activity which remains on the
1661 // screen gets the enter animation. Both appear in the mOpeningApps set.
1662 enter = false;
1663 }
1664 if (DEBUG_APP_TRANSITIONS) Slog.d(TAG_WM, "Loading animation for app transition."
1665 + " transit=" + AppTransition.appTransitionToString(transit) + " enter=" + enter
1666 + " frame=" + frame + " insets=" + insets + " surfaceInsets=" + surfaceInsets);
1667 final Configuration displayConfig = displayContent.getConfiguration();
1668 final Animation a = mService.mAppTransition.loadAnimation(lp, transit, enter,
1669 displayConfig.uiMode, displayConfig.orientation, frame, displayFrame, insets,
1670 surfaceInsets, stableInsets, isVoiceInteraction, freeform, getTask().mTaskId);
1671 if (a != null) {
1672 if (DEBUG_ANIM) logWithStack(TAG, "Loaded animation " + a + " for " + this);
1673 final int containingWidth = frame.width();
1674 final int containingHeight = frame.height();
1675 a.initialize(containingWidth, containingHeight, width, height);
1676 a.scaleCurrentDuration(mService.getTransitionAnimationScaleLocked());
1677 }
1678 return a;
1679 }
1680
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001681 @Override
1682 protected void setLayer(Transaction t, int layer) {
1683 if (!mSurfaceAnimator.hasLeash()) {
1684 t.setLayer(mSurfaceControl, layer);
1685 }
1686 }
1687
1688 @Override
1689 protected void setRelativeLayer(Transaction t, SurfaceControl relativeTo, int layer) {
1690 if (!mSurfaceAnimator.hasLeash()) {
1691 t.setRelativeLayer(mSurfaceControl, relativeTo, layer);
1692 }
1693 }
1694
1695 @Override
1696 protected void reparentSurfaceControl(Transaction t, SurfaceControl newParent) {
1697 if (!mSurfaceAnimator.hasLeash()) {
1698 t.reparent(mSurfaceControl, newParent.getHandle());
1699 }
1700 }
1701
1702 @Override
1703 public void onAnimationLeashCreated(Transaction t, SurfaceControl leash) {
1704
1705 // The leash is parented to the animation layer. We need to preserve the z-order by using
1706 // the prefix order index, but we boost if necessary.
1707 int layer = getPrefixOrderIndex();
1708 if (mNeedsZBoost) {
1709 layer += Z_BOOST_BASE;
1710 }
1711 leash.setLayer(layer);
1712 }
1713
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001714 /**
1715 * This must be called while inside a transaction.
1716 */
1717 void showAllWindowsLocked() {
1718 forAllWindows(windowState -> {
1719 if (DEBUG_VISIBILITY) Slog.v(TAG, "performing show on: " + windowState);
1720 windowState.performShowLocked();
1721 }, false /* traverseTopToBottom */);
Jorim Jaggia5e10572017-11-15 14:36:26 +01001722 }
1723
1724 @Override
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001725 protected void onAnimationFinished() {
1726 super.onAnimationFinished();
1727
1728 mTransit = TRANSIT_UNSET;
1729 mTransitFlags = 0;
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001730 mNeedsZBoost = false;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001731
1732 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM | FINISH_LAYOUT_REDO_WALLPAPER,
1733 "AppWindowToken");
1734
Jorim Jaggi988f6682017-11-17 17:46:43 +01001735 clearThumbnail();
1736
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001737 if (mService.mInputMethodTarget != null && mService.mInputMethodTarget.mAppToken == this) {
1738 getDisplayContent().computeImeTarget(true /* updateImeTarget */);
1739 }
1740
1741 if (DEBUG_ANIM) Slog.v(TAG, "Animation done in " + this
1742 + ": reportedVisible=" + reportedVisible
1743 + " okToDisplay=" + okToDisplay()
1744 + " okToAnimate=" + okToAnimate()
1745 + " startingDisplayed=" + startingDisplayed);
1746
1747 // WindowState.onExitAnimationDone might modify the children list, so make a copy and then
1748 // traverse the copy.
1749 final ArrayList<WindowState> children = new ArrayList<>(mChildren);
1750 children.forEach(WindowState::onExitAnimationDone);
1751
1752 mService.mAppTransition.notifyAppTransitionFinishedLocked(token);
1753 scheduleAnimation();
1754 }
1755
1756 @Override
1757 boolean isAppAnimating() {
1758 return isSelfAnimating();
1759 }
1760
1761 @Override
1762 boolean isSelfAnimating() {
1763 // If we are about to start a transition, we also need to be considered animating.
1764 return isWaitingForTransitionStart() || isReallyAnimating();
1765 }
1766
1767 /**
1768 * @return True if and only if we are actually running an animation. Note that
1769 * {@link #isSelfAnimating} also returns true if we are waiting for an animation to
1770 * start.
1771 */
1772 private boolean isReallyAnimating() {
1773 return super.isSelfAnimating();
1774 }
1775
Jorim Jaggi988f6682017-11-17 17:46:43 +01001776 @Override
1777 void cancelAnimation() {
1778 super.cancelAnimation();
1779 clearThumbnail();
1780 }
1781
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001782 boolean isWaitingForTransitionStart() {
1783 return mService.mAppTransition.isTransitionSet()
1784 && (mService.mOpeningApps.contains(this) || mService.mClosingApps.contains(this));
1785 }
1786
1787 public int getTransit() {
1788 return mTransit;
1789 }
1790
1791 int getTransitFlags() {
1792 return mTransitFlags;
1793 }
1794
Jorim Jaggi988f6682017-11-17 17:46:43 +01001795 void attachThumbnailAnimation() {
1796 if (!isReallyAnimating()) {
1797 return;
1798 }
1799 final int taskId = getTask().mTaskId;
1800 final GraphicBuffer thumbnailHeader =
1801 mService.mAppTransition.getAppTransitionThumbnailHeader(taskId);
1802 if (thumbnailHeader == null) {
1803 if (DEBUG_APP_TRANSITIONS) Slog.d(TAG, "No thumbnail header bitmap for: " + taskId);
1804 return;
1805 }
1806 clearThumbnail();
1807 mThumbnail = new AppWindowThumbnail(getPendingTransaction(), this, thumbnailHeader);
1808 mThumbnail.startAnimation(getPendingTransaction(), loadThumbnailAnimation(thumbnailHeader));
1809 }
1810
Tony Mak64b8d562017-12-28 17:44:02 +00001811 /**
1812 * Attaches a surface with a thumbnail for the
1813 * {@link android.app.ActivityOptions#ANIM_OPEN_CROSS_PROFILE_APPS} animation.
1814 */
1815 void attachCrossProfileAppsThumbnailAnimation() {
1816 if (!isReallyAnimating()) {
1817 return;
1818 }
1819 clearThumbnail();
1820
1821 final WindowState win = findMainWindow();
1822 if (win == null) {
1823 return;
1824 }
1825 final Rect frame = win.mFrame;
1826 final int thumbnailDrawableRes = getTask().mUserId == mService.mCurrentUserId
1827 ? R.drawable.ic_account_circle
1828 : R.drawable.ic_corp_badge_no_background;
1829 final GraphicBuffer thumbnail =
1830 mService.mAppTransition
1831 .createCrossProfileAppsThumbnail(thumbnailDrawableRes, frame);
1832 if (thumbnail == null) {
1833 return;
1834 }
1835 mThumbnail = new AppWindowThumbnail(getPendingTransaction(), this, thumbnail);
1836 final Animation animation =
1837 mService.mAppTransition.createCrossProfileAppsThumbnailAnimationLocked(win.mFrame);
1838 mThumbnail.startAnimation(getPendingTransaction(), animation, new Point(frame.left,
1839 frame.top));
1840 }
1841
Jorim Jaggi988f6682017-11-17 17:46:43 +01001842 private Animation loadThumbnailAnimation(GraphicBuffer thumbnailHeader) {
1843 final DisplayInfo displayInfo = mDisplayContent.getDisplayInfo();
1844
1845 // If this is a multi-window scenario, we use the windows frame as
1846 // destination of the thumbnail header animation. If this is a full screen
1847 // window scenario, we use the whole display as the target.
1848 WindowState win = findMainWindow();
1849 Rect appRect = win != null ? win.getContentFrameLw() :
1850 new Rect(0, 0, displayInfo.appWidth, displayInfo.appHeight);
1851 Rect insets = win != null ? win.mContentInsets : null;
1852 final Configuration displayConfig = mDisplayContent.getConfiguration();
1853 return mService.mAppTransition.createThumbnailAspectScaleAnimationLocked(
1854 appRect, insets, thumbnailHeader, getTask().mTaskId, displayConfig.uiMode,
1855 displayConfig.orientation);
1856 }
1857
1858 private void clearThumbnail() {
1859 if (mThumbnail == null) {
1860 return;
1861 }
1862 mThumbnail.destroy();
1863 mThumbnail = null;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001864 }
1865
1866 @Override
1867 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
1868 super.dump(pw, prefix, dumpAll);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001869 if (appToken != null) {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001870 pw.println(prefix + "app=true mVoiceInteraction=" + mVoiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001871 }
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001872 pw.print(prefix); pw.print("task="); pw.println(getTask());
Wale Ogunwale51362492016-09-08 17:49:17 -07001873 pw.print(prefix); pw.print(" mFillsParent="); pw.print(mFillsParent);
1874 pw.print(" mOrientation="); pw.println(mOrientation);
Wale Ogunwale89973222017-04-23 18:39:45 -07001875 pw.println(prefix + "hiddenRequested=" + hiddenRequested + " mClientHidden=" + mClientHidden
1876 + ((mDeferHidingClient) ? " mDeferHidingClient=" + mDeferHidingClient : "")
1877 + " reportedDrawn=" + reportedDrawn + " reportedVisible=" + reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -07001878 if (paused) {
1879 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001880 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001881 if (mAppStopped) {
1882 pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped);
1883 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001884 if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001885 || allDrawn || mLastAllDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001886 pw.print(prefix); pw.print("mNumInterestingWindows=");
1887 pw.print(mNumInterestingWindows);
1888 pw.print(" mNumDrawnWindows="); pw.print(mNumDrawnWindows);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001889 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -07001890 pw.print(" allDrawn="); pw.print(allDrawn);
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001891 pw.print(" lastAllDrawn="); pw.print(mLastAllDrawn);
Craig Mautner6fbda632012-07-03 09:26:39 -07001892 pw.println(")");
1893 }
1894 if (inPendingTransaction) {
1895 pw.print(prefix); pw.print("inPendingTransaction=");
1896 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001897 }
Craig Mautner799bc1d2015-01-14 10:33:48 -08001898 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001899 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
1900 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -08001901 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -08001902 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001903 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001904 if (startingWindow != null || startingSurface != null
Wale Ogunwale6c459212017-05-17 08:56:03 -07001905 || startingDisplayed || startingMoved || mHiddenSetFromTransferredStartingWindow) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001906 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001907 pw.print(" startingSurface="); pw.print(startingSurface);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001908 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
Wale Ogunwale6c459212017-05-17 08:56:03 -07001909 pw.print(" startingMoved="); pw.print(startingMoved);
1910 pw.println(" mHiddenSetFromTransferredStartingWindow="
1911 + mHiddenSetFromTransferredStartingWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001912 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01001913 if (!mFrozenBounds.isEmpty()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -08001914 pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds);
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001915 pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig);
Chong Zhangd78ddb42016-03-02 17:01:14 -08001916 }
1917 if (mPendingRelaunchCount != 0) {
1918 pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount);
Jorim Jaggi0429f352015-12-22 16:29:16 +01001919 }
Wale Ogunwale9c64cb62017-04-12 13:39:59 -07001920 if (getController() != null) {
1921 pw.print(prefix); pw.print("controller="); pw.println(getController());
1922 }
Wale Ogunwalee287e192017-04-21 09:30:12 -07001923 if (mRemovingFromDisplay) {
1924 pw.println(prefix + "mRemovingFromDisplay=" + mRemovingFromDisplay);
1925 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001926 }
1927
1928 @Override
1929 void setHidden(boolean hidden) {
1930 super.setHidden(hidden);
Winson Chunge55c0192017-08-24 14:50:48 -07001931
1932 if (hidden) {
1933 // Once the app window is hidden, reset the last saved PiP snap fraction
1934 mDisplayContent.mPinnedStackControllerLocked.resetReentrySnapFraction(this);
1935 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001936 scheduleAnimation();
1937 }
1938
1939 @Override
1940 void prepareSurfaces() {
1941 // isSelfAnimating also returns true when we are about to start a transition, so we need
1942 // to check super here.
1943 final boolean reallyAnimating = super.isSelfAnimating();
1944 final boolean show = !isHidden() || reallyAnimating;
1945 if (show && !mLastSurfaceShowing) {
1946 mPendingTransaction.show(mSurfaceControl);
1947 } else if (!show && mLastSurfaceShowing) {
1948 mPendingTransaction.hide(mSurfaceControl);
Jorim Jaggi4d1835d2017-08-31 17:28:27 +02001949 }
Jorim Jaggi988f6682017-11-17 17:46:43 +01001950 if (mThumbnail != null) {
1951 mThumbnail.setShowing(mPendingTransaction, show);
1952 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001953 mLastSurfaceShowing = show;
1954 super.prepareSurfaces();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001955 }
1956
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001957 boolean isFreezingScreen() {
1958 return mFreezingScreen;
1959 }
1960
1961 @Override
1962 boolean needsZBoost() {
1963 return mNeedsZBoost || super.needsZBoost();
1964 }
1965
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07001966 @CallSuper
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001967 @Override
Adrian Roos4921ccf2017-09-28 16:54:06 +02001968 public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07001969 final long token = proto.start(fieldId);
1970 writeNameToProto(proto, NAME);
Adrian Roos4921ccf2017-09-28 16:54:06 +02001971 super.writeToProto(proto, WINDOW_TOKEN, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07001972 proto.end(token);
1973 }
1974
1975 void writeNameToProto(ProtoOutputStream proto, long fieldId) {
1976 if (appToken == null) {
1977 return;
1978 }
1979 try {
1980 proto.write(fieldId, appToken.getName());
1981 } catch (RemoteException e) {
1982 // This shouldn't happen, but in this case fall back to outputting nothing
1983 Slog.e(TAG, e.toString());
1984 }
1985 }
1986
1987 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001988 public String toString() {
1989 if (stringName == null) {
1990 StringBuilder sb = new StringBuilder();
1991 sb.append("AppWindowToken{");
1992 sb.append(Integer.toHexString(System.identityHashCode(this)));
1993 sb.append(" token="); sb.append(token); sb.append('}');
1994 stringName = sb.toString();
1995 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001996 return stringName + ((mIsExiting) ? " mIsExiting=" : "");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001997 }
Jeff Browne9bdb312012-04-05 15:30:10 -07001998}