blob: 32b722126b8d8af54dbc6f2ac4fb680d5e1f980b [file] [log] [blame]
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server.wm;
18
Wale Ogunwale72919d22016-12-08 18:58:50 -080019import static android.content.pm.ActivityInfo.CONFIG_ORIENTATION;
20import static android.content.pm.ActivityInfo.CONFIG_SCREEN_SIZE;
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -070021import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND;
Wale Ogunwale51362492016-09-08 17:49:17 -070022import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET;
Jorim Jaggif5f9e122017-10-24 18:21:09 +020023import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070024import static android.view.Display.DEFAULT_DISPLAY;
Jorim Jaggife762342016-10-13 14:33:27 +020025import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
Jorim Jaggid635a4a2017-05-03 15:21:26 +020026import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
Jorim Jaggife762342016-10-13 14:33:27 +020027import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
Wale Ogunwaled1c37912016-08-16 03:19:39 -070028import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080029import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070030import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
Adrian Roose99bc052017-11-20 17:55:31 +010031import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
32import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070033import static com.android.server.wm.AppTransition.TRANSIT_UNSET;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080034import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080035import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
36import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070037import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070038import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
39import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
Wale Ogunwale9017ec02016-02-25 08:55:25 -080040import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
Jorim Jaggie4b0f282017-05-17 15:10:29 +020041import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW_VERBOSE;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070042import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TOKEN_MOVEMENT;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080043import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
44import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_MOVEMENT;
45import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
46import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Chong Zhang92147042016-05-09 12:47:11 -070047import static com.android.server.wm.WindowManagerService.H.NOTIFY_ACTIVITY_DRAWN;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070048import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070049import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070050import static com.android.server.wm.WindowManagerService.logWithStack;
Steven Timotiusaf03df62017-07-18 16:56:43 -070051import static com.android.server.wm.proto.AppWindowTokenProto.NAME;
52import static com.android.server.wm.proto.AppWindowTokenProto.WINDOW_TOKEN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080053
Wale Ogunwale0d5609b2017-09-13 05:55:07 -070054import android.annotation.CallSuper;
Jorim Jaggid635a4a2017-05-03 15:21:26 +020055import android.app.Activity;
Jorim Jaggi26c8c422016-05-09 19:57:25 -070056import android.content.res.Configuration;
Jorim Jaggi988f6682017-11-17 17:46:43 +010057import android.graphics.GraphicBuffer;
Jorim Jaggif5f9e122017-10-24 18:21:09 +020058import android.graphics.Point;
Jorim Jaggi0429f352015-12-22 16:29:16 +010059import android.graphics.Rect;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070060import android.os.Binder;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080061import android.os.Debug;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070062import android.os.IBinder;
Steven Timotiusaf03df62017-07-18 16:56:43 -070063import android.os.RemoteException;
Jorim Jaggif5f9e122017-10-24 18:21:09 +020064import android.os.Trace;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080065import android.util.Slog;
Steven Timotiusaf03df62017-07-18 16:56:43 -070066import android.util.proto.ProtoOutputStream;
Jorim Jaggif5f9e122017-10-24 18:21:09 +020067import android.view.DisplayInfo;
Jorim Jaggi619c9f72017-12-19 18:04:29 +010068import android.view.SurfaceControl.Transaction;
Jorim Jaggif5f9e122017-10-24 18:21:09 +020069import android.view.animation.Animation;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080070import android.view.IApplicationToken;
Robert Carr6914f082017-03-20 19:04:30 -070071import android.view.SurfaceControl;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080072import android.view.WindowManager;
Jorim Jaggi87fdbcb2017-08-17 13:41:11 +020073import android.view.WindowManager.LayoutParams;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080074
75import com.android.internal.util.ToBooleanFunction;
76import com.android.server.input.InputApplicationHandle;
Adrian Roose99bc052017-11-20 17:55:31 +010077import com.android.server.policy.WindowManagerPolicy.StartingSurface;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080078import com.android.server.wm.WindowManagerService.H;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080079
80import java.io.PrintWriter;
Jorim Jaggi0429f352015-12-22 16:29:16 +010081import java.util.ArrayDeque;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080082import java.util.ArrayList;
Jorim Jaggia5e10572017-11-15 14:36:26 +010083import java.util.LinkedList;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080084
85class AppTokenList extends ArrayList<AppWindowToken> {
86}
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080087
88/**
89 * Version of WindowToken that is specifically for a particular application (or
90 * really activity) that is displaying windows.
91 */
Wale Ogunwale3f4433d2016-08-18 20:42:42 -070092class AppWindowToken extends WindowToken implements WindowManagerService.AppFreezeListener {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080093 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppWindowToken" : TAG_WM;
94
Jorim Jaggi619c9f72017-12-19 18:04:29 +010095 /**
96 * Value to increment the z-layer when boosting a layer during animations. BOOST in l33tsp34k.
97 */
98 private static final int Z_BOOST_BASE = 800570000;
99
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800100 // Non-null only for application tokens.
101 final IApplicationToken appToken;
102
Wale Ogunwale72919d22016-12-08 18:58:50 -0800103 final boolean mVoiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700104
Wale Ogunwale51362492016-09-08 17:49:17 -0700105 /** @see WindowContainer#fillsParent() */
106 private boolean mFillsParent;
Craig Mautner4c5eb222013-11-18 12:59:05 -0800107 boolean layoutConfigChanges;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800108 boolean mShowForAllUsers;
109 int mTargetSdk;
Craig Mautnera2c77052012-03-26 12:14:43 -0700110
Bryce Lee6d410262017-02-28 15:30:17 -0800111 // Flag set while reparenting to prevent actions normally triggered by an individual parent
112 // change.
113 private boolean mReparenting;
114
Wale Ogunwalee287e192017-04-21 09:30:12 -0700115 // True if we are current in the process of removing this app token from the display
116 private boolean mRemovingFromDisplay = false;
117
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800118 // The input dispatching timeout for this application token in nanoseconds.
Wale Ogunwale72919d22016-12-08 18:58:50 -0800119 long mInputDispatchingTimeoutNanos;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800120
121 // These are used for determining when all windows associated with
122 // an activity have been drawn, so they can be made visible together
123 // at the same time.
Craig Mautner764983d2012-03-22 11:37:36 -0700124 // initialize so that it doesn't match mTransactionSequence which is an int.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700125 private long mLastTransactionSequence = Long.MIN_VALUE;
126 private int mNumInterestingWindows;
127 private int mNumDrawnWindows;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800128 boolean inPendingTransaction;
129 boolean allDrawn;
Jorim Jaggib0fc8172017-11-23 17:04:08 +0000130 private boolean mLastAllDrawn;
131
Craig Mautner7636dfb2012-11-16 15:24:11 -0800132 // Set to true when this app creates a surface while in the middle of an animation. In that
133 // case do not clear allDrawn until the animation completes.
134 boolean deferClearAllDrawn;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800135
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800136 // Is this window's surface needed? This is almost like hidden, except
137 // it will sometimes be true a little earlier: when the token has
138 // been shown, but is still waiting for its app transition to execute
139 // before making its windows shown.
140 boolean hiddenRequested;
141
142 // Have we told the window clients to hide themselves?
Wale Ogunwale89973222017-04-23 18:39:45 -0700143 private boolean mClientHidden;
144
145 // If true we will defer setting mClientHidden to true and reporting to the client that it is
146 // hidden.
147 boolean mDeferHidingClient;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800148
149 // Last visibility state we reported to the app token.
150 boolean reportedVisible;
151
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700152 // Last drawn state we reported to the app token.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700153 private boolean reportedDrawn;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700154
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800155 // Set to true when the token has been removed from the window mgr.
156 boolean removed;
157
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800158 // Information about an application starting window if displayed.
159 StartingData startingData;
160 WindowState startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800161 StartingSurface startingSurface;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800162 boolean startingDisplayed;
163 boolean startingMoved;
Wale Ogunwale6c459212017-05-17 08:56:03 -0700164 // True if the hidden state of this token was forced to false due to a transferred starting
165 // window.
166 private boolean mHiddenSetFromTransferredStartingWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800167 boolean firstWindowDrawn;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700168 private final WindowState.UpdateReportedVisibilityResults mReportedVisibilityResults =
169 new WindowState.UpdateReportedVisibilityResults();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800170
171 // Input application handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700172 final InputApplicationHandle mInputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800173
Wale Ogunwale571771c2016-08-26 13:18:50 -0700174 // TODO: Have a WindowContainer state for tracking exiting/deferred removal.
Craig Mautner799bc1d2015-01-14 10:33:48 -0800175 boolean mIsExiting;
Craig Mautner9ef471f2014-02-07 13:11:47 -0800176
Craig Mautnerbb742462014-07-07 15:28:55 -0700177 boolean mLaunchTaskBehind;
Craig Mautner8746a472014-07-24 15:12:54 -0700178 boolean mEnteringAnimation;
Craig Mautnerbb742462014-07-07 15:28:55 -0700179
Wale Ogunwale72919d22016-12-08 18:58:50 -0800180 private boolean mAlwaysFocusable;
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800181
Robert Carre12aece2016-02-02 22:43:27 -0800182 boolean mAppStopped;
Robert Carrfd10cd12016-06-29 16:41:50 -0700183 int mRotationAnimationHint;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700184 private int mPendingRelaunchCount;
Robert Carre12aece2016-02-02 22:43:27 -0800185
Jorim Jaggife762342016-10-13 14:33:27 +0200186 private boolean mLastContainsShowWhenLockedWindow;
187 private boolean mLastContainsDismissKeyguardWindow;
188
Jorim Jaggi0429f352015-12-22 16:29:16 +0100189 ArrayDeque<Rect> mFrozenBounds = new ArrayDeque<>();
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700190 ArrayDeque<Configuration> mFrozenMergedConfig = new ArrayDeque<>();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100191
Wale Ogunwale6c459212017-05-17 08:56:03 -0700192 private boolean mDisablePreviewScreenshots;
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +0100193
Wale Ogunwale034a8ec2017-09-02 17:14:40 -0700194 private Task mLastParent;
Robert Carred3e83b2017-04-21 13:26:55 -0700195
chaviwd3bf08d2017-08-01 17:24:59 -0700196 /**
197 * See {@link #canTurnScreenOn()}
198 */
199 private boolean mCanTurnScreenOn = true;
200
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200201 /**
202 * If we are running an animation, this determines the transition type. Must be one of
203 * AppTransition.TRANSIT_* constants.
204 */
205 private int mTransit;
206
207 /**
208 * If we are running an animation, this determines the flags during this animation. Must be a
209 * bitwise combination of AppTransition.TRANSIT_FLAG_* constants.
210 */
211 private int mTransitFlags;
212
213 /** Whether our surface was set to be showing in the last call to {@link #prepareSurfaces} */
Jorim Jaggifd1891462017-12-29 15:41:36 +0100214 private boolean mLastSurfaceShowing = true;
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200215
Jorim Jaggi988f6682017-11-17 17:46:43 +0100216 private AppWindowThumbnail mThumbnail;
217
Jorim Jaggib0fc8172017-11-23 17:04:08 +0000218 /** Have we been asked to have this token keep the screen frozen? */
219 private boolean mFreezingScreen;
220
221 /** Whether this token should be boosted at the top of all app window tokens. */
222 private boolean mNeedsZBoost;
223
chaviw23ee71c2017-12-18 11:29:41 -0800224 private final Point mTmpPoint = new Point();
chaviw23012112017-12-20 15:29:04 -0800225 private final Rect mTmpRect = new Rect();
chaviw23ee71c2017-12-18 11:29:41 -0800226
Wale Ogunwale72919d22016-12-08 18:58:50 -0800227 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
228 DisplayContent dc, long inputDispatchingTimeoutNanos, boolean fullscreen,
229 boolean showForAllUsers, int targetSdk, int orientation, int rotationAnimationHint,
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800230 int configChanges, boolean launchTaskBehind, boolean alwaysFocusable,
Bryce Leef3c6a472017-11-14 14:53:06 -0800231 AppWindowContainerController controller) {
232 this(service, token, voiceInteraction, dc, fullscreen);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800233 setController(controller);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800234 mInputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800235 mShowForAllUsers = showForAllUsers;
236 mTargetSdk = targetSdk;
237 mOrientation = orientation;
238 layoutConfigChanges = (configChanges & (CONFIG_SCREEN_SIZE | CONFIG_ORIENTATION)) != 0;
239 mLaunchTaskBehind = launchTaskBehind;
240 mAlwaysFocusable = alwaysFocusable;
241 mRotationAnimationHint = rotationAnimationHint;
242
243 // Application tokens start out hidden.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200244 setHidden(true);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800245 hiddenRequested = true;
246 }
247
248 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
Bryce Leef3c6a472017-11-14 14:53:06 -0800249 DisplayContent dc, boolean fillsParent) {
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800250 super(service, token != null ? token.asBinder() : null, TYPE_APPLICATION, true, dc,
251 false /* ownerCanManageAppTokens */);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700252 appToken = token;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800253 mVoiceInteraction = voiceInteraction;
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800254 mFillsParent = fillsParent;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800255 mInputApplicationHandle = new InputApplicationHandle(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800256 }
257
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800258 void onFirstWindowDrawn(WindowState win, WindowStateAnimator winAnimator) {
259 firstWindowDrawn = true;
260
261 // We now have a good window to show, remove dead placeholders
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700262 removeDeadWindows();
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800263
Jorim Jaggi02886a82016-12-06 09:10:06 -0800264 if (startingWindow != null) {
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800265 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, "Finish starting "
266 + win.mToken + ": first real window is shown, no animation");
267 // If this initial window is animating, stop it -- we will do an animation to reveal
268 // it from behind the starting window, so there is no need for it to also be doing its
269 // own stuff.
Jorim Jaggia5e10572017-11-15 14:36:26 +0100270 win.cancelAnimation();
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800271 if (getController() != null) {
272 getController().removeStartingWindow();
273 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800274 }
275 updateReportedVisibilityLocked();
276 }
277
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800278 void updateReportedVisibilityLocked() {
279 if (appToken == null) {
280 return;
281 }
282
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700283 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700284 final int count = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800285
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700286 mReportedVisibilityResults.reset();
287
288 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700289 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700290 win.updateReportedVisibility(mReportedVisibilityResults);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800291 }
292
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700293 int numInteresting = mReportedVisibilityResults.numInteresting;
294 int numVisible = mReportedVisibilityResults.numVisible;
295 int numDrawn = mReportedVisibilityResults.numDrawn;
296 boolean nowGone = mReportedVisibilityResults.nowGone;
297
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700298 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200299 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting && !isHidden();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700300 if (!nowGone) {
301 // If the app is not yet gone, then it can only become visible/drawn.
302 if (!nowDrawn) {
303 nowDrawn = reportedDrawn;
304 }
305 if (!nowVisible) {
306 nowVisible = reportedVisible;
307 }
308 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800309 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800310 + numInteresting + " visible=" + numVisible);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800311 final AppWindowContainerController controller = getController();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700312 if (nowDrawn != reportedDrawn) {
313 if (nowDrawn) {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800314 if (controller != null) {
315 controller.reportWindowsDrawn();
316 }
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700317 }
318 reportedDrawn = nowDrawn;
319 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800320 if (nowVisible != reportedVisible) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700321 if (DEBUG_VISIBILITY) Slog.v(TAG,
322 "Visibility changed in " + this + ": vis=" + nowVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800323 reportedVisible = nowVisible;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800324 if (controller != null) {
325 if (nowVisible) {
326 controller.reportWindowsVisible();
327 } else {
328 controller.reportWindowsGone();
329 }
330 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800331 }
332 }
333
Wale Ogunwale89973222017-04-23 18:39:45 -0700334 boolean isClientHidden() {
335 return mClientHidden;
336 }
337
338 void setClientHidden(boolean hideClient) {
339 if (mClientHidden == hideClient || (hideClient && mDeferHidingClient)) {
340 return;
341 }
342 mClientHidden = hideClient;
343 sendAppVisibilityToClients();
344 }
345
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700346 boolean setVisibility(WindowManager.LayoutParams lp,
347 boolean visible, int transit, boolean performLayout, boolean isVoiceInteraction) {
348
349 boolean delayed = false;
350 inPendingTransaction = false;
Wale Ogunwale9e4721f2017-05-23 19:37:30 -0700351 // Reset the state of mHiddenSetFromTransferredStartingWindow since visibility is actually
352 // been set by the app now.
353 mHiddenSetFromTransferredStartingWindow = false;
Wale Ogunwale89973222017-04-23 18:39:45 -0700354 setClientHidden(!visible);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700355
356 // Allow for state changes and animation to be applied if:
357 // * token is transitioning visibility state
358 // * or the token was marked as hidden and is exiting before we had a chance to play the
359 // transition animation
360 // * or this is an opening app and windows are being replaced.
361 boolean visibilityChanged = false;
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200362 if (isHidden() == visible || (isHidden() && mIsExiting) || (visible && waitingForReplacement())) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700363 final AccessibilityController accessibilityController = mService.mAccessibilityController;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700364 boolean changed = false;
365 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200366 "Changing app " + this + " hidden=" + isHidden() + " performLayout=" + performLayout);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700367
368 boolean runningAppAnimation = false;
369
370 if (transit != AppTransition.TRANSIT_UNSET) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200371 if (applyAnimationLocked(lp, transit, visible, isVoiceInteraction)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700372 delayed = runningAppAnimation = true;
373 }
374 final WindowState window = findMainWindow();
375 //TODO (multidisplay): Magnification is supported only for the default display.
376 if (window != null && accessibilityController != null
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700377 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700378 accessibilityController.onAppWindowTransitionLocked(window, transit);
379 }
380 changed = true;
381 }
382
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700383 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700384 for (int i = 0; i < windowsCount; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700385 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700386 changed |= win.onAppVisibilityChanged(visible, runningAppAnimation);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700387 }
388
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200389 setHidden(!visible);
390 hiddenRequested = !visible;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700391 visibilityChanged = true;
392 if (!visible) {
393 stopFreezingScreen(true, true);
394 } else {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700395 // If we are being set visible, and the starting window is not yet displayed,
396 // then make sure it doesn't get displayed.
397 if (startingWindow != null && !startingWindow.isDrawnLw()) {
398 startingWindow.mPolicyVisibility = false;
399 startingWindow.mPolicyVisibilityAfterAnim = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700400 }
Jorim Jaggi38d44ec2017-06-14 16:04:59 -0700401
402 // We are becoming visible, so better freeze the screen with the windows that are
403 // getting visible so we also wait for them.
404 forAllWindows(mService::makeWindowFreezingScreenIfNeededLocked, true);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700405 }
406
407 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setVisibility: " + this
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200408 + ": hidden=" + isHidden() + " hiddenRequested=" + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700409
410 if (changed) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700411 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700412 if (performLayout) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700413 mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700414 false /*updateInputWindows*/);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700415 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700416 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700417 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700418 }
419 }
420
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200421 if (isReallyAnimating()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700422 delayed = true;
423 }
424
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700425 for (int i = mChildren.size() - 1; i >= 0 && !delayed; i--) {
Jorim Jaggia5e10572017-11-15 14:36:26 +0100426 if ((mChildren.get(i)).isSelfOrChildAnimating()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700427 delayed = true;
428 }
429 }
430
431 if (visibilityChanged) {
432 if (visible && !delayed) {
433 // The token was made immediately visible, there will be no entrance animation.
434 // We need to inform the client the enter animation was finished.
435 mEnteringAnimation = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700436 mService.mActivityManagerAppTransitionNotifier.onAppTransitionFinishedLocked(token);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700437 }
Robert Carr61b81112017-07-17 18:08:15 -0700438
Robert Carre7cc44d2017-03-20 19:04:30 -0700439 // If we are hidden but there is no delay needed we immediately
440 // apply the Surface transaction so that the ActivityManager
Robert Carr61b81112017-07-17 18:08:15 -0700441 // can have some guarantee on the Surface state following
442 // setting the visibility. This captures cases like dismissing
443 // the docked or pinned stack where there is no app transition.
444 //
445 // In the case of a "Null" animation, there will be
446 // no animation but there will still be a transition set.
447 // We still need to delay hiding the surface such that it
448 // can be synchronized with showing the next surface in the transition.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200449 if (isHidden() && !delayed && !mService.mAppTransition.isTransitionSet()) {
Robert Carr6914f082017-03-20 19:04:30 -0700450 SurfaceControl.openTransaction();
451 for (int i = mChildren.size() - 1; i >= 0; i--) {
452 mChildren.get(i).mWinAnimator.hide("immediately hidden");
453 }
454 SurfaceControl.closeTransaction();
455 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700456
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700457 if (!mService.mClosingApps.contains(this) && !mService.mOpeningApps.contains(this)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700458 // The token is not closing nor opening, so even if there is an animation set, that
459 // doesn't mean that it goes through the normal app transition cycle so we have
460 // to inform the docked controller about visibility change.
Andrii Kulian1e32e022016-09-16 15:29:34 -0700461 // TODO(multi-display): notify docked divider on all displays where visibility was
462 // affected.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700463 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700464 .notifyAppVisibilityChanged();
Jorim Jaggi8b702ed2017-01-20 16:59:03 +0100465 mService.mTaskSnapshotController.notifyAppVisibilityChanged(this, visible);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700466 }
467 }
468
469 return delayed;
470 }
471
Jorim Jaggi87fdbcb2017-08-17 13:41:11 +0200472 /**
473 * @return The to top most child window for which {@link LayoutParams#isFullscreen()} returns
474 * true.
475 */
476 WindowState getTopFullscreenWindow() {
477 for (int i = mChildren.size() - 1; i >= 0; i--) {
478 final WindowState win = mChildren.get(i);
479 if (win != null && win.mAttrs.isFullscreen()) {
480 return win;
481 }
482 }
483 return null;
484 }
485
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800486 WindowState findMainWindow() {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700487 WindowState candidate = null;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700488 int j = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800489 while (j > 0) {
490 j--;
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700491 final WindowState win = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700492 final int type = win.mAttrs.type;
493 // No need to loop through child window as base application and starting types can't be
494 // child windows.
495 if (type == TYPE_BASE_APPLICATION || type == TYPE_APPLICATION_STARTING) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700496 // In cases where there are multiple windows, we prefer the non-exiting window. This
Sungsoo Lim0d3d1f82015-12-02 14:47:59 +0900497 // happens for example when replacing windows during an activity relaunch. When
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700498 // constructing the animation, we want the new window, not the exiting one.
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800499 if (win.mAnimatingExit) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700500 candidate = win;
501 } else {
502 return win;
503 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800504 }
505 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700506 return candidate;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800507 }
508
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800509 boolean windowsAreFocusable() {
Wale Ogunwale3382ab12017-07-27 08:55:03 -0700510 return getWindowConfiguration().canReceiveKeys() || mAlwaysFocusable;
Wale Ogunwaled045c822015-12-02 09:14:28 -0800511 }
512
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800513 AppWindowContainerController getController() {
514 final WindowContainerController controller = super.getController();
515 return controller != null ? (AppWindowContainerController) controller : null;
516 }
517
Wale Ogunwale571771c2016-08-26 13:18:50 -0700518 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -0700519 boolean isVisible() {
Wale Ogunwalee471be62016-10-03 07:53:55 -0700520 // If the app token isn't hidden then it is considered visible and there is no need to check
521 // its children windows to see if they are visible.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200522 return !isHidden();
Wale Ogunwale44f21802016-09-02 12:49:48 -0700523 }
524
525 @Override
Wale Ogunwalee287e192017-04-21 09:30:12 -0700526 void removeImmediately() {
527 onRemovedFromDisplay();
528 super.removeImmediately();
529 }
530
531 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -0700532 void removeIfPossible() {
Craig Mautnere3119b72015-01-20 15:02:36 -0800533 mIsExiting = false;
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800534 removeAllWindowsIfPossible();
Bryce Lee6d410262017-02-28 15:30:17 -0800535 removeImmediately();
Craig Mautnere3119b72015-01-20 15:02:36 -0800536 }
537
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700538 @Override
539 boolean checkCompleteDeferredRemoval() {
540 if (mIsExiting) {
541 removeIfPossible();
542 }
543 return super.checkCompleteDeferredRemoval();
544 }
545
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700546 void onRemovedFromDisplay() {
Wale Ogunwalee287e192017-04-21 09:30:12 -0700547 if (mRemovingFromDisplay) {
548 return;
549 }
550 mRemovingFromDisplay = true;
551
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700552 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app token: " + this);
553
Wale Ogunwale72919d22016-12-08 18:58:50 -0800554 boolean delayed = setVisibility(null, false, TRANSIT_UNSET, true, mVoiceInteraction);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700555
556 mService.mOpeningApps.remove(this);
Jorim Jaggi45ca0542017-05-30 16:16:01 -0700557 mService.mUnknownAppVisibilityController.appRemovedOrHidden(this);
Jorim Jaggi10abe2f2017-01-03 16:44:46 +0100558 mService.mTaskSnapshotController.onAppRemoved(this);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700559 waitingToShow = false;
560 if (mService.mClosingApps.contains(this)) {
561 delayed = true;
562 } else if (mService.mAppTransition.isTransitionSet()) {
563 mService.mClosingApps.add(this);
564 delayed = true;
565 }
566
567 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app " + this + " delayed=" + delayed
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200568 + " animation=" + getAnimation() + " animating=" + isSelfAnimating());
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700569
570 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM, "removeAppToken: "
571 + this + " delayed=" + delayed + " Callers=" + Debug.getCallers(4));
572
Jorim Jaggi19be6052017-08-03 18:33:43 +0200573 if (startingData != null && getController() != null) {
574 getController().removeStartingWindow();
575 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800576
Winson Chung87e5d552017-04-05 11:49:38 -0700577 // If this window was animating, then we need to ensure that the app transition notifies
578 // that animations have completed in WMS.handleAnimatingStoppedAndTransitionLocked(), so
579 // add to that list now
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200580 if (isSelfAnimating()) {
Winson Chung87e5d552017-04-05 11:49:38 -0700581 mService.mNoAnimationNotifyOnTransitionFinished.add(token);
582 }
583
Wale Ogunwalee287e192017-04-21 09:30:12 -0700584 final TaskStack stack = getStack();
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700585 if (delayed && !isEmpty()) {
586 // set the token aside because it has an active animation to be finished
587 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM,
588 "removeAppToken make exiting: " + this);
Wale Ogunwalee287e192017-04-21 09:30:12 -0700589 if (stack != null) {
590 stack.mExitingAppTokens.add(this);
591 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700592 mIsExiting = true;
593 } else {
594 // Make sure there is no animation running on this token, so any windows associated
595 // with it will be removed as soon as their animations are complete
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200596 cancelAnimation();
Wale Ogunwale3106ae012017-05-16 08:56:37 -0700597 if (stack != null) {
598 stack.mExitingAppTokens.remove(this);
599 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700600 removeIfPossible();
601 }
602
603 removed = true;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700604 stopFreezingScreen(true, true);
Bryce Lee6d410262017-02-28 15:30:17 -0800605
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700606 if (mService.mFocusedApp == this) {
607 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "Removing focused app token:" + this);
608 mService.mFocusedApp = null;
609 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
610 mService.mInputMonitor.setFocusedAppLw(null);
611 }
612
613 if (!delayed) {
614 updateReportedVisibilityLocked();
615 }
Wale Ogunwalee287e192017-04-21 09:30:12 -0700616
617 mRemovingFromDisplay = false;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700618 }
619
Chong Zhange05bcb12016-07-26 17:47:29 -0700620 void clearAnimatingFlags() {
Chong Zhangb0d26702016-08-12 16:03:29 -0700621 boolean wallpaperMightChange = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700622 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700623 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700624 wallpaperMightChange |= win.clearAnimatingFlags();
Chong Zhange05bcb12016-07-26 17:47:29 -0700625 }
Chong Zhangb0d26702016-08-12 16:03:29 -0700626 if (wallpaperMightChange) {
627 requestUpdateWallpaperIfNeeded();
628 }
Chong Zhange05bcb12016-07-26 17:47:29 -0700629 }
630
Robert Carre12aece2016-02-02 22:43:27 -0800631 void destroySurfaces() {
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700632 destroySurfaces(false /*cleanupOnResume*/);
633 }
634
635 /**
636 * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure
637 * the client has finished with them.
638 *
639 * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If
640 * set to true, destroy only surfaces of removed windows, and clear relevant flags of the
641 * others so that they are ready to be reused. If set to false (common case), destroy all
642 * surfaces that's eligible, if the app is already stopped.
643 */
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700644 private void destroySurfaces(boolean cleanupOnResume) {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700645 boolean destroyedSomething = false;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100646
647 // Copying to a different list as multiple children can be removed.
Jorim Jaggi59f3e922018-01-05 15:40:32 +0100648 final ArrayList<WindowState> children = new ArrayList<>(mChildren);
Jorim Jaggia5e10572017-11-15 14:36:26 +0100649 for (int i = children.size() - 1; i >= 0; i--) {
650 final WindowState win = children.get(i);
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700651 destroyedSomething |= win.destroySurface(cleanupOnResume, mAppStopped);
Robert Carre12aece2016-02-02 22:43:27 -0800652 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700653 if (destroyedSomething) {
654 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700655 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Robert Carre12aece2016-02-02 22:43:27 -0800656 }
657 }
658
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800659 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700660 * Notify that the app is now resumed, and it was not stopped before, perform a clean
661 * up of the surfaces
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800662 */
Jorim Jaggibae01b12017-04-11 16:29:10 -0700663 void notifyAppResumed(boolean wasStopped) {
Chong Zhangad24f962016-08-25 12:12:33 -0700664 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped
Jorim Jaggibae01b12017-04-11 16:29:10 -0700665 + " " + this);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700666 mAppStopped = false;
chaviwd3bf08d2017-08-01 17:24:59 -0700667 // Allow the window to turn the screen on once the app is resumed again.
668 setCanTurnScreenOn(true);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700669 if (!wasStopped) {
670 destroySurfaces(true /*cleanupOnResume*/);
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800671 }
Robert Carre12aece2016-02-02 22:43:27 -0800672 }
673
Chong Zhangbef461f2015-10-27 11:38:24 -0700674 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700675 * Notify that the app has stopped, and it is okay to destroy any surfaces which were
676 * keeping alive in case they were still being used.
677 */
678 void notifyAppStopped() {
679 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this);
680 mAppStopped = true;
681 destroySurfaces();
682 // Remove any starting window that was added for this app if they are still around.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800683 if (getController() != null) {
684 getController().removeStartingWindow();
685 }
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700686 }
687
Chong Zhang92147042016-05-09 12:47:11 -0700688 void clearAllDrawn() {
689 allDrawn = false;
690 deferClearAllDrawn = false;
Chong Zhangbef461f2015-10-27 11:38:24 -0700691 }
692
Bryce Lee6d410262017-02-28 15:30:17 -0800693 Task getTask() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800694 return (Task) getParent();
Bryce Lee6d410262017-02-28 15:30:17 -0800695 }
696
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800697 TaskStack getStack() {
698 final Task task = getTask();
699 if (task != null) {
700 return task.mStack;
701 } else {
702 return null;
703 }
704 }
705
Bryce Lee6d410262017-02-28 15:30:17 -0800706 @Override
707 void onParentSet() {
708 super.onParentSet();
709
Robert Carred3e83b2017-04-21 13:26:55 -0700710 final Task task = getTask();
711
Bryce Lee6d410262017-02-28 15:30:17 -0800712 // When the associated task is {@code null}, the {@link AppWindowToken} can no longer
713 // access visual elements like the {@link DisplayContent}. We must remove any associations
714 // such as animations.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800715 if (!mReparenting) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800716 if (task == null) {
717 // It is possible we have been marked as a closing app earlier. We must remove ourselves
718 // from this list so we do not participate in any future animations.
719 mService.mClosingApps.remove(this);
Robert Carred3e83b2017-04-21 13:26:55 -0700720 } else if (mLastParent != null && mLastParent.mStack != null) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800721 task.mStack.mExitingAppTokens.remove(this);
722 }
Bryce Lee6d410262017-02-28 15:30:17 -0800723 }
Robert Carred3e83b2017-04-21 13:26:55 -0700724 mLastParent = task;
Bryce Lee6d410262017-02-28 15:30:17 -0800725 }
726
Wale Ogunwalefa854eb2016-09-20 13:43:52 -0700727 void postWindowRemoveStartingWindowCleanup(WindowState win) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700728 // TODO: Something smells about the code below...Is there a better way?
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700729 if (startingWindow == win) {
730 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800731 if (getController() != null) {
732 getController().removeStartingWindow();
733 }
Wale Ogunwale6c459212017-05-17 08:56:03 -0700734 } else if (mChildren.size() == 0) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700735 // If this is the last window and we had requested a starting transition window,
736 // well there is no point now.
Jorim Jaggi02886a82016-12-06 09:10:06 -0800737 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingData");
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700738 startingData = null;
Wale Ogunwale6c459212017-05-17 08:56:03 -0700739 if (mHiddenSetFromTransferredStartingWindow) {
740 // We set the hidden state to false for the token from a transferred starting window.
741 // We now reset it back to true since the starting window was the last window in the
742 // token.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200743 setHidden(true);
Wale Ogunwale6c459212017-05-17 08:56:03 -0700744 }
Jorim Jaggi829b9cd2017-01-23 16:20:53 +0100745 } else if (mChildren.size() == 1 && startingSurface != null && !isRelaunching()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700746 // If this is the last window except for a starting transition window,
747 // we need to get rid of the starting transition.
Jorim Jaggie4b0f282017-05-17 15:10:29 +0200748 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Last window, removing starting window "
749 + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800750 if (getController() != null) {
751 getController().removeStartingWindow();
752 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700753 }
754 }
755
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700756 void removeDeadWindows() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700757 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700758 WindowState win = mChildren.get(winNdx);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800759 if (win.mAppDied) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700760 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700761 "removeDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800762 // Set mDestroying, we don't want any animation or delayed removal here.
763 win.mDestroying = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700764 // Also removes child windows.
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700765 win.removeIfPossible();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800766 }
767 }
768 }
769
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700770 boolean hasWindowsAlive() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700771 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700772 // No need to loop through child windows as the answer should be the same as that of the
773 // parent window.
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700774 if (!(mChildren.get(i)).mAppDied) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700775 return true;
776 }
777 }
778 return false;
779 }
780
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700781 void setWillReplaceWindows(boolean animate) {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700782 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
783 "Marking app token " + this + " with replacing windows.");
Robert Carra1eb4392015-12-10 12:43:51 -0800784
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700785 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700786 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700787 w.setWillReplaceWindow(animate);
Robert Carra1eb4392015-12-10 12:43:51 -0800788 }
Robert Carra1eb4392015-12-10 12:43:51 -0800789 }
790
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700791 void setWillReplaceChildWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700792 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this
Robert Carr23fa16b2016-01-13 13:19:58 -0800793 + " with replacing child windows.");
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700794 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700795 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700796 w.setWillReplaceChildWindows();
Robert Carr23fa16b2016-01-13 13:19:58 -0800797 }
798 }
799
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700800 void clearWillReplaceWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700801 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
802 "Resetting app token " + this + " of replacing window marks.");
Chong Zhangf596cd52016-01-05 13:42:44 -0800803
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700804 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700805 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700806 w.clearWillReplaceWindow();
Chong Zhangf596cd52016-01-05 13:42:44 -0800807 }
808 }
809
Chong Zhang4d7369a2016-04-25 16:09:14 -0700810 void requestUpdateWallpaperIfNeeded() {
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);
Chong Zhang4d7369a2016-04-25 16:09:14 -0700813 w.requestUpdateWallpaperIfNeeded();
814 }
815 }
816
Chong Zhangd78ddb42016-03-02 17:01:14 -0800817 boolean isRelaunching() {
818 return mPendingRelaunchCount > 0;
819 }
820
Robert Carr68375192017-06-13 12:41:53 -0700821 boolean shouldFreezeBounds() {
822 final Task task = getTask();
823
824 // For freeform windows, we can't freeze the bounds at the moment because this would make
825 // the resizing unresponsive.
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700826 if (task == null || task.inFreeformWindowingMode()) {
Robert Carr68375192017-06-13 12:41:53 -0700827 return false;
828 }
829
830 // We freeze the bounds while drag resizing to deal with the time between
831 // the divider/drag handle being released, and the handling it's new
832 // configuration. If we are relaunched outside of the drag resizing state,
833 // we need to be careful not to do this.
834 return getTask().isDragResizing();
835 }
836
Chong Zhangd78ddb42016-03-02 17:01:14 -0800837 void startRelaunching() {
Robert Carr68375192017-06-13 12:41:53 -0700838 if (shouldFreezeBounds()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -0800839 freezeBounds();
840 }
Robert Carrd5c7dd62017-03-08 10:39:30 -0800841
842 // In the process of tearing down before relaunching, the app will
843 // try and clean up it's child surfaces. We need to prevent this from
844 // happening, so we sever the children, transfering their ownership
845 // from the client it-self to the parent surface (owned by us).
846 for (int i = mChildren.size() - 1; i >= 0; i--) {
847 final WindowState w = mChildren.get(i);
848 w.mWinAnimator.detachChildren();
849 }
850
Chong Zhangd78ddb42016-03-02 17:01:14 -0800851 mPendingRelaunchCount++;
852 }
853
854 void finishRelaunching() {
Robert Carr68375192017-06-13 12:41:53 -0700855 unfreezeBounds();
856
Chong Zhangd78ddb42016-03-02 17:01:14 -0800857 if (mPendingRelaunchCount > 0) {
858 mPendingRelaunchCount--;
Bryce Lee081554b2017-05-25 07:52:12 -0700859 } else {
860 // Update keyguard flags upon finishing relaunch.
861 checkKeyguardFlagsChanged();
Chong Zhangd78ddb42016-03-02 17:01:14 -0800862 }
863 }
864
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700865 void clearRelaunching() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700866 if (mPendingRelaunchCount == 0) {
867 return;
868 }
Robert Carr68375192017-06-13 12:41:53 -0700869 unfreezeBounds();
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700870 mPendingRelaunchCount = 0;
871 }
872
Wale Ogunwale07bcab72016-10-14 15:30:09 -0700873 /**
874 * Returns true if the new child window we are adding to this token is considered greater than
875 * the existing child window in this token in terms of z-order.
876 */
877 @Override
878 protected boolean isFirstChildWindowGreaterThanSecond(WindowState newWindow,
879 WindowState existingWindow) {
880 final int type1 = newWindow.mAttrs.type;
881 final int type2 = existingWindow.mAttrs.type;
882
883 // Base application windows should be z-ordered BELOW all other windows in the app token.
884 if (type1 == TYPE_BASE_APPLICATION && type2 != TYPE_BASE_APPLICATION) {
885 return false;
886 } else if (type1 != TYPE_BASE_APPLICATION && type2 == TYPE_BASE_APPLICATION) {
887 return true;
888 }
889
890 // Starting windows should be z-ordered ABOVE all other windows in the app token.
891 if (type1 == TYPE_APPLICATION_STARTING && type2 != TYPE_APPLICATION_STARTING) {
892 return true;
893 } else if (type1 != TYPE_APPLICATION_STARTING && type2 == TYPE_APPLICATION_STARTING) {
894 return false;
895 }
896
897 // Otherwise the new window is greater than the existing window.
898 return true;
899 }
900
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700901 @Override
Robert Carra1eb4392015-12-10 12:43:51 -0800902 void addWindow(WindowState w) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700903 super.addWindow(w);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700904
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700905 boolean gotReplacementWindow = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700906 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700907 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700908 gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w);
909 }
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700910
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700911 // if we got a replacement window, reset the timeout to give drawing more time
912 if (gotReplacementWindow) {
913 mService.scheduleWindowReplacementTimeouts(this);
Robert Carra1eb4392015-12-10 12:43:51 -0800914 }
Jorim Jaggife762342016-10-13 14:33:27 +0200915 checkKeyguardFlagsChanged();
916 }
917
918 @Override
919 void removeChild(WindowState child) {
920 super.removeChild(child);
921 checkKeyguardFlagsChanged();
Robert Carra1eb4392015-12-10 12:43:51 -0800922 }
923
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700924 private boolean waitingForReplacement() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700925 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700926 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700927 if (candidate.waitingForReplacement()) {
Robert Carra1eb4392015-12-10 12:43:51 -0800928 return true;
929 }
930 }
931 return false;
932 }
933
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700934 void onWindowReplacementTimeout() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700935 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700936 (mChildren.get(i)).onWindowReplacementTimeout();
Robert Carra1eb4392015-12-10 12:43:51 -0800937 }
938 }
939
Winson Chung30480042017-01-26 10:55:34 -0800940 void reparent(Task task, int position) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800941 final Task currentTask = getTask();
942 if (task == currentTask) {
Winson Chung30480042017-01-26 10:55:34 -0800943 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800944 "window token=" + this + " already child of task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -0800945 }
Bryce Lee6d410262017-02-28 15:30:17 -0800946
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800947 if (currentTask.mStack != task.mStack) {
Bryce Lee6d410262017-02-28 15:30:17 -0800948 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800949 "window token=" + this + " current task=" + currentTask
Bryce Lee6d410262017-02-28 15:30:17 -0800950 + " belongs to a different stack than " + task);
951 }
952
Winson Chung30480042017-01-26 10:55:34 -0800953 if (DEBUG_ADD_REMOVE) Slog.i(TAG, "reParentWindowToken: removing window token=" + this
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800954 + " from task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -0800955 final DisplayContent prevDisplayContent = getDisplayContent();
956
Bryce Lee6d410262017-02-28 15:30:17 -0800957 mReparenting = true;
958
Winson Chung30480042017-01-26 10:55:34 -0800959 getParent().removeChild(this);
960 task.addChild(this, position);
961
Bryce Lee6d410262017-02-28 15:30:17 -0800962 mReparenting = false;
963
Winson Chung30480042017-01-26 10:55:34 -0800964 // Relayout display(s).
965 final DisplayContent displayContent = task.getDisplayContent();
966 displayContent.setLayoutNeeded();
967 if (prevDisplayContent != displayContent) {
968 onDisplayChanged(displayContent);
969 prevDisplayContent.setLayoutNeeded();
970 }
971 }
972
Jorim Jaggi0429f352015-12-22 16:29:16 +0100973 /**
974 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
975 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
976 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
977 * with a queue.
978 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800979 private void freezeBounds() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800980 final Task task = getTask();
981 mFrozenBounds.offer(new Rect(task.mPreparedFrozenBounds));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700982
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800983 if (task.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) {
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700984 // We didn't call prepareFreezingBounds on the task, so use the current value.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800985 mFrozenMergedConfig.offer(new Configuration(task.getConfiguration()));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700986 } else {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800987 mFrozenMergedConfig.offer(new Configuration(task.mPreparedFrozenMergedConfig));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700988 }
Andrii Kulianb10330d2016-09-16 13:51:46 -0700989 // Calling unset() to make it equal to Configuration.EMPTY.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800990 task.mPreparedFrozenMergedConfig.unset();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100991 }
992
993 /**
994 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
995 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800996 private void unfreezeBounds() {
Robert Carr68375192017-06-13 12:41:53 -0700997 if (mFrozenBounds.isEmpty()) {
998 return;
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700999 }
Robert Carr68375192017-06-13 12:41:53 -07001000 mFrozenBounds.remove();
Wale Ogunwale37dbafc2016-06-27 10:15:20 -07001001 if (!mFrozenMergedConfig.isEmpty()) {
1002 mFrozenMergedConfig.remove();
1003 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001004 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001005 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001006 win.onUnfreezeBounds();
Jorim Jaggi4846ee32016-01-07 17:39:12 +01001007 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001008 mService.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +01001009 }
1010
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001011 void setAppLayoutChanges(int changes, String reason) {
1012 if (!mChildren.isEmpty()) {
1013 final DisplayContent dc = getDisplayContent();
1014 dc.pendingLayoutChanges |= changes;
1015 if (DEBUG_LAYOUT_REPEATS) {
1016 mService.mWindowPlacerLocked.debugLayoutRepeats(reason, dc.pendingLayoutChanges);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001017 }
1018 }
1019 }
1020
1021 void removeReplacedWindowIfNeeded(WindowState replacement) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001022 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001023 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001024 if (win.removeReplacedWindowIfNeeded(replacement)) {
1025 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001026 }
1027 }
1028 }
1029
1030 void startFreezingScreen() {
1031 if (DEBUG_ORIENTATION) logWithStack(TAG, "Set freezing of " + appToken + ": hidden="
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001032 + isHidden() + " freezing=" + mFreezingScreen + " hiddenRequested="
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001033 + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001034 if (!hiddenRequested) {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001035 if (!mFreezingScreen) {
1036 mFreezingScreen = true;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001037 mService.registerAppFreezeListener(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001038 mService.mAppsFreezingScreen++;
1039 if (mService.mAppsFreezingScreen == 1) {
Bryce Lee8f853582017-06-05 17:25:59 -07001040 mService.startFreezingDisplayLocked(false, 0, 0, getDisplayContent());
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001041 mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT);
1042 mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001043 }
1044 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001045 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001046 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001047 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001048 w.onStartFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001049 }
1050 }
1051 }
1052
1053 void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001054 if (!mFreezingScreen) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001055 return;
1056 }
1057 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + this + " force=" + force);
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001058 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001059 boolean unfrozeWindows = false;
1060 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001061 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001062 unfrozeWindows |= w.onStopFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001063 }
1064 if (force || unfrozeWindows) {
1065 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this);
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001066 mFreezingScreen = false;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001067 mService.unregisterAppFreezeListener(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001068 mService.mAppsFreezingScreen--;
1069 mService.mLastFinishedFreezeSource = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001070 }
1071 if (unfreezeSurfaceNow) {
1072 if (unfrozeWindows) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001073 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001074 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001075 mService.stopFreezingDisplayLocked();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001076 }
1077 }
1078
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001079 @Override
1080 public void onAppFreezeTimeout() {
1081 Slog.w(TAG_WM, "Force clearing freeze: " + this);
1082 stopFreezingScreen(true, true);
1083 }
1084
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001085 boolean transferStartingWindow(IBinder transferFrom) {
Wale Ogunwale02319a62016-09-26 15:21:22 -07001086 final AppWindowToken fromToken = getDisplayContent().getAppWindowToken(transferFrom);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001087 if (fromToken == null) {
1088 return false;
1089 }
1090
1091 final WindowState tStartingWindow = fromToken.startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001092 if (tStartingWindow != null && fromToken.startingSurface != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001093 // In this case, the starting icon has already been displayed, so start
1094 // letting windows get shown immediately without any more transitions.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001095 mService.mSkipAppTransitionAnimation = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001096
1097 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow
1098 + " from " + fromToken + " to " + this);
1099
1100 final long origId = Binder.clearCallingIdentity();
Peter Visontay3556a3b2017-11-01 17:23:17 +00001101 try {
1102 // Transfer the starting window over to the new token.
1103 startingData = fromToken.startingData;
1104 startingSurface = fromToken.startingSurface;
1105 startingDisplayed = fromToken.startingDisplayed;
1106 fromToken.startingDisplayed = false;
1107 startingWindow = tStartingWindow;
1108 reportedVisible = fromToken.reportedVisible;
1109 fromToken.startingData = null;
1110 fromToken.startingSurface = null;
1111 fromToken.startingWindow = null;
1112 fromToken.startingMoved = true;
1113 tStartingWindow.mToken = this;
1114 tStartingWindow.mAppToken = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001115
Peter Visontay3556a3b2017-11-01 17:23:17 +00001116 if (DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1117 "Removing starting " + tStartingWindow + " from " + fromToken);
1118 fromToken.removeChild(tStartingWindow);
1119 fromToken.postWindowRemoveStartingWindowCleanup(tStartingWindow);
1120 fromToken.mHiddenSetFromTransferredStartingWindow = false;
1121 addWindow(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001122
Peter Visontay3556a3b2017-11-01 17:23:17 +00001123 // Propagate other interesting state between the tokens. If the old token is displayed,
1124 // we should immediately force the new one to be displayed. If it is animating, we need
1125 // to move that animation to the new one.
1126 if (fromToken.allDrawn) {
1127 allDrawn = true;
1128 deferClearAllDrawn = fromToken.deferClearAllDrawn;
1129 }
1130 if (fromToken.firstWindowDrawn) {
1131 firstWindowDrawn = true;
1132 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001133 if (!fromToken.isHidden()) {
1134 setHidden(false);
Peter Visontay3556a3b2017-11-01 17:23:17 +00001135 hiddenRequested = false;
1136 mHiddenSetFromTransferredStartingWindow = true;
1137 }
1138 setClientHidden(fromToken.mClientHidden);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001139
Jorim Jaggi980c9de2017-11-17 01:41:37 +01001140 transferAnimation(fromToken);
1141
1142 // When transferring an animation, we no longer need to apply an animation to the
1143 // the token we transfer the animation over. Thus, remove the animation from
1144 // pending opening apps.
1145 mService.mOpeningApps.remove(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001146
Peter Visontay3556a3b2017-11-01 17:23:17 +00001147 mService.updateFocusedWindowLocked(
1148 UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/);
1149 getDisplayContent().setLayoutNeeded();
1150 mService.mWindowPlacerLocked.performSurfacePlacement();
1151 } finally {
1152 Binder.restoreCallingIdentity(origId);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001153 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001154 return true;
1155 } else if (fromToken.startingData != null) {
1156 // The previous app was getting ready to show a
1157 // starting window, but hasn't yet done so. Steal it!
1158 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1159 "Moving pending starting from " + fromToken + " to " + this);
1160 startingData = fromToken.startingData;
1161 fromToken.startingData = null;
1162 fromToken.startingMoved = true;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001163 if (getController() != null) {
1164 getController().scheduleAddStartingWindow();
1165 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001166 return true;
1167 }
1168
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001169 // TODO: Transfer thumbnail
1170
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001171 return false;
1172 }
1173
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001174 boolean isLastWindow(WindowState win) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001175 return mChildren.size() == 1 && mChildren.get(0) == win;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001176 }
1177
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001178 @Override
1179 void onAppTransitionDone() {
1180 sendingToBottom = false;
1181 }
1182
Wale Ogunwale51362492016-09-08 17:49:17 -07001183 /**
1184 * We override because this class doesn't want its children affecting its reported orientation
1185 * in anyway.
1186 */
1187 @Override
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001188 int getOrientation(int candidate) {
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001189 if (candidate == SCREEN_ORIENTATION_BEHIND) {
1190 // Allow app to specify orientation regardless of its visibility state if the current
1191 // candidate want us to use orientation behind. I.e. the visible app on-top of this one
1192 // wants us to use the orientation of the app behind it.
1193 return mOrientation;
1194 }
1195
Bryce Lee61fbcbc2017-03-10 14:14:03 -08001196 // The {@link AppWindowToken} should only specify an orientation when it is not closing or
1197 // going to the bottom. Allowing closing {@link AppWindowToken} to participate can lead to
1198 // an Activity in another task being started in the wrong orientation during the transition.
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001199 if (!(sendingToBottom || mService.mClosingApps.contains(this))
Bryce Lee00d586d2017-07-28 20:48:43 -07001200 && (isVisible() || mService.mOpeningApps.contains(this) || isOnTop())) {
Bryce Leea163b762017-01-24 11:05:01 -08001201 return mOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001202 }
Bryce Leea163b762017-01-24 11:05:01 -08001203
1204 return SCREEN_ORIENTATION_UNSET;
Wale Ogunwale51362492016-09-08 17:49:17 -07001205 }
1206
Wale Ogunwaleb198b742016-12-01 08:44:09 -08001207 /** Returns the app's preferred orientation regardless of its currently visibility state. */
1208 int getOrientationIgnoreVisibility() {
1209 return mOrientation;
1210 }
1211
Craig Mautnerdbb79912012-03-01 18:59:14 -08001212 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001213 void checkAppWindowsReadyToShow() {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001214 if (allDrawn == mLastAllDrawn) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001215 return;
1216 }
1217
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001218 mLastAllDrawn = allDrawn;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001219 if (!allDrawn) {
1220 return;
1221 }
1222
1223 // The token has now changed state to having all windows shown... what to do, what to do?
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001224 if (mFreezingScreen) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001225 showAllWindowsLocked();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001226 stopFreezingScreen(false, true);
1227 if (DEBUG_ORIENTATION) Slog.i(TAG,
1228 "Setting mOrientationChangeComplete=true because wtoken " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001229 + " numInteresting=" + mNumInterestingWindows + " numDrawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001230 // This will set mOrientationChangeComplete and cause a pass through layout.
1231 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001232 "checkAppWindowsReadyToShow: freezingScreen");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001233 } else {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001234 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001235
1236 // We can now show all of the drawn windows!
1237 if (!mService.mOpeningApps.contains(this)) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001238 showAllWindowsLocked();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001239 }
1240 }
1241 }
1242
Matthew Ng5d23afa2017-06-21 16:16:24 -07001243 /**
Bryce Leed390deb2017-06-22 13:14:28 -07001244 * Returns whether the drawn window states of this {@link AppWindowToken} has considered every
1245 * child {@link WindowState}. A child is considered if it has been passed into
1246 * {@link #updateDrawnWindowStates(WindowState)} after being added. This is used to determine
1247 * whether states, such as {@code allDrawn}, can be set, which relies on state variables such as
1248 * {@code mNumInterestingWindows}, which depend on all {@link WindowState}s being considered.
1249 *
1250 * @return {@code true} If all children have been considered, {@code false}.
1251 */
1252 private boolean allDrawnStatesConsidered() {
Bryce Lee6311c4b2017-07-06 14:09:29 -07001253 for (int i = mChildren.size() - 1; i >= 0; --i) {
1254 final WindowState child = mChildren.get(i);
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001255 if (child.mightAffectAllDrawn() && !child.getDrawnStateEvaluated()) {
Bryce Leed390deb2017-06-22 13:14:28 -07001256 return false;
1257 }
1258 }
1259 return true;
1260 }
1261
1262 /**
Matthew Ng5d23afa2017-06-21 16:16:24 -07001263 * Determines if the token has finished drawing. This should only be called from
1264 * {@link DisplayContent#applySurfaceChangesTransaction}
1265 */
Matthew Ng498c71d2017-04-18 13:55:45 -07001266 void updateAllDrawn() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001267 if (!allDrawn) {
Matthew Ng498c71d2017-04-18 13:55:45 -07001268 // Number of drawn windows can be less when a window is being relaunched, wait for
Bryce Leed390deb2017-06-22 13:14:28 -07001269 // all windows to be launched and drawn for this token be considered all drawn.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001270 final int numInteresting = mNumInterestingWindows;
Bryce Leed390deb2017-06-22 13:14:28 -07001271
1272 // We must make sure that all present children have been considered (determined by
1273 // {@link #allDrawnStatesConsidered}) before evaluating whether everything has been
1274 // drawn.
1275 if (numInteresting > 0 && allDrawnStatesConsidered()
1276 && mNumDrawnWindows >= numInteresting && !isRelaunching()) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001277 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawn: " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001278 + " interesting=" + numInteresting + " drawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001279 allDrawn = true;
1280 // Force an additional layout pass where
1281 // WindowStateAnimator#commitFinishDrawingLocked() will call performShowLocked().
Matthew Ng498c71d2017-04-18 13:55:45 -07001282 if (mDisplayContent != null) {
1283 mDisplayContent.setLayoutNeeded();
1284 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001285 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Robert Carrecc06b32017-04-18 14:25:10 -07001286
Winson Chunge7ba6862017-05-24 12:13:33 -07001287 // Notify the pinned stack upon all windows drawn. If there was an animation in
1288 // progress then this signal will resume that animation.
Wale Ogunwale61911492017-10-11 08:50:50 -07001289 final TaskStack pinnedStack = mDisplayContent.getPinnedStack();
Winson Chunge7ba6862017-05-24 12:13:33 -07001290 if (pinnedStack != null) {
1291 pinnedStack.onAllWindowsDrawn();
Robert Carrecc06b32017-04-18 14:25:10 -07001292 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001293 }
1294 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001295 }
1296
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001297 /**
1298 * Updated this app token tracking states for interesting and drawn windows based on the window.
1299 *
1300 * @return Returns true if the input window is considered interesting and drawn while all the
1301 * windows in this app token where not considered drawn as of the last pass.
1302 */
1303 boolean updateDrawnWindowStates(WindowState w) {
Bryce Leed390deb2017-06-22 13:14:28 -07001304 w.setDrawnStateEvaluated(true /*evaluated*/);
1305
Jorim Jaggie4b0f282017-05-17 15:10:29 +02001306 if (DEBUG_STARTING_WINDOW_VERBOSE && w == startingWindow) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001307 Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" + w.isOnScreen()
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001308 + " allDrawn=" + allDrawn + " freezingScreen=" + mFreezingScreen);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001309 }
1310
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001311 if (allDrawn && !mFreezingScreen) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001312 return false;
1313 }
1314
1315 if (mLastTransactionSequence != mService.mTransactionSequence) {
1316 mLastTransactionSequence = mService.mTransactionSequence;
1317 mNumInterestingWindows = mNumDrawnWindows = 0;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001318 startingDisplayed = false;
1319 }
1320
1321 final WindowStateAnimator winAnimator = w.mWinAnimator;
1322
1323 boolean isInterestingAndDrawn = false;
1324
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001325 if (!allDrawn && w.mightAffectAllDrawn()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001326 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
1327 Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw()
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001328 + ", isAnimationSet=" + isSelfAnimating());
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001329 if (!w.isDrawnLw()) {
1330 Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController
1331 + " pv=" + w.mPolicyVisibility
1332 + " mDrawState=" + winAnimator.drawStateToString()
1333 + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001334 + " a=" + isSelfAnimating());
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001335 }
1336 }
1337
1338 if (w != startingWindow) {
1339 if (w.isInteresting()) {
1340 mNumInterestingWindows++;
1341 if (w.isDrawnLw()) {
1342 mNumDrawnWindows++;
1343
1344 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, "tokenMayBeDrawn: "
1345 + this + " w=" + w + " numInteresting=" + mNumInterestingWindows
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001346 + " freezingScreen=" + mFreezingScreen
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001347 + " mAppFreezing=" + w.mAppFreezing);
1348
1349 isInterestingAndDrawn = true;
1350 }
1351 }
1352 } else if (w.isDrawnLw()) {
Jorim Jaggi3878ca32017-02-02 17:13:05 -08001353 if (getController() != null) {
1354 getController().reportStartingWindowDrawn();
1355 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001356 startingDisplayed = true;
1357 }
1358 }
1359
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001360 return isInterestingAndDrawn;
1361 }
1362
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001363 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001364 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001365 // For legacy reasons we process the TaskStack.mExitingAppTokens first in DisplayContent
1366 // before the non-exiting app tokens. So, we skip the exiting app tokens here.
1367 // TODO: Investigate if we need to continue to do this or if we can just process them
1368 // in-order.
1369 if (mIsExiting && !waitingForReplacement()) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001370 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001371 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001372 return forAllWindowsUnchecked(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001373 }
1374
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001375 boolean forAllWindowsUnchecked(ToBooleanFunction<WindowState> callback,
1376 boolean traverseTopToBottom) {
1377 return super.forAllWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001378 }
1379
1380 @Override
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001381 AppWindowToken asAppWindowToken() {
1382 // I am an app window token!
1383 return this;
1384 }
1385
1386 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -07001387 boolean fillsParent() {
1388 return mFillsParent;
1389 }
1390
1391 void setFillsParent(boolean fillsParent) {
1392 mFillsParent = fillsParent;
1393 }
1394
Jorim Jaggife762342016-10-13 14:33:27 +02001395 boolean containsDismissKeyguardWindow() {
Bryce Lee081554b2017-05-25 07:52:12 -07001396 // Window state is transient during relaunch. We are not guaranteed to be frozen during the
1397 // entirety of the relaunch.
1398 if (isRelaunching()) {
1399 return mLastContainsDismissKeyguardWindow;
1400 }
1401
Jorim Jaggife762342016-10-13 14:33:27 +02001402 for (int i = mChildren.size() - 1; i >= 0; i--) {
1403 if ((mChildren.get(i).mAttrs.flags & FLAG_DISMISS_KEYGUARD) != 0) {
1404 return true;
1405 }
1406 }
1407 return false;
1408 }
1409
1410 boolean containsShowWhenLockedWindow() {
Bryce Lee081554b2017-05-25 07:52:12 -07001411 // When we are relaunching, it is possible for us to be unfrozen before our previous
1412 // windows have been added back. Using the cached value ensures that our previous
1413 // showWhenLocked preference is honored until relaunching is complete.
1414 if (isRelaunching()) {
1415 return mLastContainsShowWhenLockedWindow;
1416 }
1417
Jorim Jaggife762342016-10-13 14:33:27 +02001418 for (int i = mChildren.size() - 1; i >= 0; i--) {
1419 if ((mChildren.get(i).mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
1420 return true;
1421 }
1422 }
Bryce Lee081554b2017-05-25 07:52:12 -07001423
Jorim Jaggife762342016-10-13 14:33:27 +02001424 return false;
1425 }
1426
1427 void checkKeyguardFlagsChanged() {
1428 final boolean containsDismissKeyguard = containsDismissKeyguardWindow();
1429 final boolean containsShowWhenLocked = containsShowWhenLockedWindow();
1430 if (containsDismissKeyguard != mLastContainsDismissKeyguardWindow
1431 || containsShowWhenLocked != mLastContainsShowWhenLockedWindow) {
1432 mService.notifyKeyguardFlagsChanged(null /* callback */);
1433 }
1434 mLastContainsDismissKeyguardWindow = containsDismissKeyguard;
1435 mLastContainsShowWhenLockedWindow = containsShowWhenLocked;
1436 }
1437
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001438 WindowState getImeTargetBelowWindow(WindowState w) {
1439 final int index = mChildren.indexOf(w);
1440 if (index > 0) {
1441 final WindowState target = mChildren.get(index - 1);
1442 if (target.canBeImeTarget()) {
1443 return target;
1444 }
1445 }
1446 return null;
1447 }
1448
Winson Chungbe9be7f2017-06-28 10:55:22 -07001449 int getLowestAnimLayer() {
1450 for (int i = 0; i < mChildren.size(); i++) {
1451 final WindowState w = mChildren.get(i);
1452 if (w.mRemoved) {
1453 continue;
1454 }
1455 return w.mWinAnimator.mAnimLayer;
1456 }
1457 return Integer.MAX_VALUE;
1458 }
1459
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001460 WindowState getHighestAnimLayerWindow(WindowState currentTarget) {
1461 WindowState candidate = null;
1462 for (int i = mChildren.indexOf(currentTarget); i >= 0; i--) {
1463 final WindowState w = mChildren.get(i);
1464 if (w.mRemoved) {
1465 continue;
1466 }
1467 if (candidate == null || w.mWinAnimator.mAnimLayer >
1468 candidate.mWinAnimator.mAnimLayer) {
1469 candidate = w;
1470 }
1471 }
1472 return candidate;
1473 }
1474
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001475 /**
1476 * See {@link Activity#setDisablePreviewScreenshots}.
1477 */
1478 void setDisablePreviewScreenshots(boolean disable) {
Wale Ogunwale6c459212017-05-17 08:56:03 -07001479 mDisablePreviewScreenshots = disable;
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001480 }
1481
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001482 /**
chaviwd3bf08d2017-08-01 17:24:59 -07001483 * Sets whether the current launch can turn the screen on. See {@link #canTurnScreenOn()}
1484 */
1485 void setCanTurnScreenOn(boolean canTurnScreenOn) {
1486 mCanTurnScreenOn = canTurnScreenOn;
1487 }
1488
1489 /**
1490 * Indicates whether the current launch can turn the screen on. This is to prevent multiple
1491 * relayouts from turning the screen back on. The screen should only turn on at most
1492 * once per activity resume.
1493 *
1494 * @return true if the screen can be turned on.
1495 */
1496 boolean canTurnScreenOn() {
1497 return mCanTurnScreenOn;
1498 }
1499
1500 /**
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001501 * Retrieves whether we'd like to generate a snapshot that's based solely on the theme. This is
1502 * the case when preview screenshots are disabled {@link #setDisablePreviewScreenshots} or when
1503 * we can't take a snapshot for other reasons, for example, if we have a secure window.
1504 *
1505 * @return True if we need to generate an app theme snapshot, false if we'd like to take a real
1506 * screenshot.
1507 */
1508 boolean shouldUseAppThemeSnapshot() {
Wale Ogunwale6c459212017-05-17 08:56:03 -07001509 return mDisablePreviewScreenshots || forAllWindows(w -> (w.mAttrs.flags & FLAG_SECURE) != 0,
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001510 true /* topToBottom */);
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001511 }
1512
chaviw23ee71c2017-12-18 11:29:41 -08001513 @Override
1514 public SurfaceControl.Builder makeAnimationLeash() {
1515 return super.makeAnimationLeash()
1516 .setParent(getAppAnimationLayer());
1517 }
1518
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001519 boolean applyAnimationLocked(WindowManager.LayoutParams lp, int transit, boolean enter,
1520 boolean isVoiceInteraction) {
1521
1522 if (mService.mDisableTransitionAnimation) {
1523 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1524 Slog.v(TAG_WM, "applyAnimation: transition animation is disabled. atoken=" + this);
1525 }
1526 cancelAnimation();
1527 return false;
1528 }
1529
1530 // Only apply an animation if the display isn't frozen. If it is frozen, there is no reason
1531 // to animate and it can cause strange artifacts when we unfreeze the display if some
1532 // different animation is running.
1533 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "AWT#applyAnimationLocked");
1534 if (okToAnimate()) {
1535 final Animation a = loadAnimation(lp, transit, enter, isVoiceInteraction);
1536 if (a != null) {
chaviw23ee71c2017-12-18 11:29:41 -08001537 final TaskStack stack = getStack();
1538 mTmpPoint.set(0, 0);
chaviw23012112017-12-20 15:29:04 -08001539 mTmpRect.setEmpty();
chaviw23ee71c2017-12-18 11:29:41 -08001540 if (stack != null) {
1541 stack.getRelativePosition(mTmpPoint);
chaviw23012112017-12-20 15:29:04 -08001542 stack.getBounds(mTmpRect);
chaviw23ee71c2017-12-18 11:29:41 -08001543 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001544 final AnimationAdapter adapter = new LocalAnimationAdapter(
chaviw23012112017-12-20 15:29:04 -08001545 new WindowAnimationSpec(a, mTmpPoint, mTmpRect,
1546 mService.mAppTransition.canSkipFirstFrame(),
1547 mService.mAppTransition.getAppStackClipMode()),
Jorim Jaggi2e3c31d2017-11-20 19:49:00 +01001548 mService.mSurfaceAnimationRunner);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001549 if (a.getZAdjustment() == Animation.ZORDER_TOP) {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001550 mNeedsZBoost = true;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001551 }
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001552 startAnimation(getPendingTransaction(), adapter, !isVisible());
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001553 mTransit = transit;
1554 mTransitFlags = mService.mAppTransition.getTransitFlags();
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001555 }
1556 } else {
1557 cancelAnimation();
1558 }
1559 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
1560
1561 return isReallyAnimating();
1562 }
1563
1564 private Animation loadAnimation(WindowManager.LayoutParams lp, int transit, boolean enter,
1565 boolean isVoiceInteraction) {
1566 final DisplayContent displayContent = getTask().getDisplayContent();
1567 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
1568 final int width = displayInfo.appWidth;
1569 final int height = displayInfo.appHeight;
1570 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG_WM,
1571 "applyAnimation: atoken=" + this);
1572
1573 // Determine the visible rect to calculate the thumbnail clip
1574 final WindowState win = findMainWindow();
1575 final Rect frame = new Rect(0, 0, width, height);
1576 final Rect displayFrame = new Rect(0, 0,
1577 displayInfo.logicalWidth, displayInfo.logicalHeight);
1578 final Rect insets = new Rect();
1579 final Rect stableInsets = new Rect();
1580 Rect surfaceInsets = null;
1581 final boolean freeform = win != null && win.inFreeformWindowingMode();
1582 if (win != null) {
1583 // Containing frame will usually cover the whole screen, including dialog windows.
1584 // For freeform workspace windows it will not cover the whole screen and it also
1585 // won't exactly match the final freeform window frame (e.g. when overlapping with
1586 // the status bar). In that case we need to use the final frame.
1587 if (freeform) {
1588 frame.set(win.mFrame);
1589 } else {
1590 frame.set(win.mContainingFrame);
1591 }
1592 surfaceInsets = win.getAttrs().surfaceInsets;
1593 insets.set(win.mContentInsets);
1594 stableInsets.set(win.mStableInsets);
1595 }
1596
1597 if (mLaunchTaskBehind) {
1598 // Differentiate the two animations. This one which is briefly on the screen
1599 // gets the !enter animation, and the other activity which remains on the
1600 // screen gets the enter animation. Both appear in the mOpeningApps set.
1601 enter = false;
1602 }
1603 if (DEBUG_APP_TRANSITIONS) Slog.d(TAG_WM, "Loading animation for app transition."
1604 + " transit=" + AppTransition.appTransitionToString(transit) + " enter=" + enter
1605 + " frame=" + frame + " insets=" + insets + " surfaceInsets=" + surfaceInsets);
1606 final Configuration displayConfig = displayContent.getConfiguration();
1607 final Animation a = mService.mAppTransition.loadAnimation(lp, transit, enter,
1608 displayConfig.uiMode, displayConfig.orientation, frame, displayFrame, insets,
1609 surfaceInsets, stableInsets, isVoiceInteraction, freeform, getTask().mTaskId);
1610 if (a != null) {
1611 if (DEBUG_ANIM) logWithStack(TAG, "Loaded animation " + a + " for " + this);
1612 final int containingWidth = frame.width();
1613 final int containingHeight = frame.height();
1614 a.initialize(containingWidth, containingHeight, width, height);
1615 a.scaleCurrentDuration(mService.getTransitionAnimationScaleLocked());
1616 }
1617 return a;
1618 }
1619
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001620 @Override
1621 protected void setLayer(Transaction t, int layer) {
1622 if (!mSurfaceAnimator.hasLeash()) {
1623 t.setLayer(mSurfaceControl, layer);
1624 }
1625 }
1626
1627 @Override
1628 protected void setRelativeLayer(Transaction t, SurfaceControl relativeTo, int layer) {
1629 if (!mSurfaceAnimator.hasLeash()) {
1630 t.setRelativeLayer(mSurfaceControl, relativeTo, layer);
1631 }
1632 }
1633
1634 @Override
1635 protected void reparentSurfaceControl(Transaction t, SurfaceControl newParent) {
1636 if (!mSurfaceAnimator.hasLeash()) {
1637 t.reparent(mSurfaceControl, newParent.getHandle());
1638 }
1639 }
1640
1641 @Override
1642 public void onAnimationLeashCreated(Transaction t, SurfaceControl leash) {
1643
1644 // The leash is parented to the animation layer. We need to preserve the z-order by using
1645 // the prefix order index, but we boost if necessary.
1646 int layer = getPrefixOrderIndex();
1647 if (mNeedsZBoost) {
1648 layer += Z_BOOST_BASE;
1649 }
1650 leash.setLayer(layer);
1651 }
1652
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001653 /**
1654 * This must be called while inside a transaction.
1655 */
1656 void showAllWindowsLocked() {
1657 forAllWindows(windowState -> {
1658 if (DEBUG_VISIBILITY) Slog.v(TAG, "performing show on: " + windowState);
1659 windowState.performShowLocked();
1660 }, false /* traverseTopToBottom */);
Jorim Jaggia5e10572017-11-15 14:36:26 +01001661 }
1662
1663 @Override
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001664 protected void onAnimationFinished() {
1665 super.onAnimationFinished();
1666
1667 mTransit = TRANSIT_UNSET;
1668 mTransitFlags = 0;
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001669 mNeedsZBoost = false;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001670
1671 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM | FINISH_LAYOUT_REDO_WALLPAPER,
1672 "AppWindowToken");
1673
Jorim Jaggi988f6682017-11-17 17:46:43 +01001674 clearThumbnail();
1675
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001676 if (mService.mInputMethodTarget != null && mService.mInputMethodTarget.mAppToken == this) {
1677 getDisplayContent().computeImeTarget(true /* updateImeTarget */);
1678 }
1679
1680 if (DEBUG_ANIM) Slog.v(TAG, "Animation done in " + this
1681 + ": reportedVisible=" + reportedVisible
1682 + " okToDisplay=" + okToDisplay()
1683 + " okToAnimate=" + okToAnimate()
1684 + " startingDisplayed=" + startingDisplayed);
1685
1686 // WindowState.onExitAnimationDone might modify the children list, so make a copy and then
1687 // traverse the copy.
1688 final ArrayList<WindowState> children = new ArrayList<>(mChildren);
1689 children.forEach(WindowState::onExitAnimationDone);
1690
1691 mService.mAppTransition.notifyAppTransitionFinishedLocked(token);
1692 scheduleAnimation();
1693 }
1694
1695 @Override
1696 boolean isAppAnimating() {
1697 return isSelfAnimating();
1698 }
1699
1700 @Override
1701 boolean isSelfAnimating() {
1702 // If we are about to start a transition, we also need to be considered animating.
1703 return isWaitingForTransitionStart() || isReallyAnimating();
1704 }
1705
1706 /**
1707 * @return True if and only if we are actually running an animation. Note that
1708 * {@link #isSelfAnimating} also returns true if we are waiting for an animation to
1709 * start.
1710 */
1711 private boolean isReallyAnimating() {
1712 return super.isSelfAnimating();
1713 }
1714
Jorim Jaggi988f6682017-11-17 17:46:43 +01001715 @Override
1716 void cancelAnimation() {
1717 super.cancelAnimation();
1718 clearThumbnail();
1719 }
1720
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001721 boolean isWaitingForTransitionStart() {
1722 return mService.mAppTransition.isTransitionSet()
1723 && (mService.mOpeningApps.contains(this) || mService.mClosingApps.contains(this));
1724 }
1725
1726 public int getTransit() {
1727 return mTransit;
1728 }
1729
1730 int getTransitFlags() {
1731 return mTransitFlags;
1732 }
1733
Jorim Jaggi988f6682017-11-17 17:46:43 +01001734 void attachThumbnailAnimation() {
1735 if (!isReallyAnimating()) {
1736 return;
1737 }
1738 final int taskId = getTask().mTaskId;
1739 final GraphicBuffer thumbnailHeader =
1740 mService.mAppTransition.getAppTransitionThumbnailHeader(taskId);
1741 if (thumbnailHeader == null) {
1742 if (DEBUG_APP_TRANSITIONS) Slog.d(TAG, "No thumbnail header bitmap for: " + taskId);
1743 return;
1744 }
1745 clearThumbnail();
1746 mThumbnail = new AppWindowThumbnail(getPendingTransaction(), this, thumbnailHeader);
1747 mThumbnail.startAnimation(getPendingTransaction(), loadThumbnailAnimation(thumbnailHeader));
1748 }
1749
1750 private Animation loadThumbnailAnimation(GraphicBuffer thumbnailHeader) {
1751 final DisplayInfo displayInfo = mDisplayContent.getDisplayInfo();
1752
1753 // If this is a multi-window scenario, we use the windows frame as
1754 // destination of the thumbnail header animation. If this is a full screen
1755 // window scenario, we use the whole display as the target.
1756 WindowState win = findMainWindow();
1757 Rect appRect = win != null ? win.getContentFrameLw() :
1758 new Rect(0, 0, displayInfo.appWidth, displayInfo.appHeight);
1759 Rect insets = win != null ? win.mContentInsets : null;
1760 final Configuration displayConfig = mDisplayContent.getConfiguration();
1761 return mService.mAppTransition.createThumbnailAspectScaleAnimationLocked(
1762 appRect, insets, thumbnailHeader, getTask().mTaskId, displayConfig.uiMode,
1763 displayConfig.orientation);
1764 }
1765
1766 private void clearThumbnail() {
1767 if (mThumbnail == null) {
1768 return;
1769 }
1770 mThumbnail.destroy();
1771 mThumbnail = null;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001772 }
1773
1774 @Override
1775 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
1776 super.dump(pw, prefix, dumpAll);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001777 if (appToken != null) {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001778 pw.println(prefix + "app=true mVoiceInteraction=" + mVoiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001779 }
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001780 pw.print(prefix); pw.print("task="); pw.println(getTask());
Wale Ogunwale51362492016-09-08 17:49:17 -07001781 pw.print(prefix); pw.print(" mFillsParent="); pw.print(mFillsParent);
1782 pw.print(" mOrientation="); pw.println(mOrientation);
Wale Ogunwale89973222017-04-23 18:39:45 -07001783 pw.println(prefix + "hiddenRequested=" + hiddenRequested + " mClientHidden=" + mClientHidden
1784 + ((mDeferHidingClient) ? " mDeferHidingClient=" + mDeferHidingClient : "")
1785 + " reportedDrawn=" + reportedDrawn + " reportedVisible=" + reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -07001786 if (paused) {
1787 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001788 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001789 if (mAppStopped) {
1790 pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped);
1791 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001792 if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001793 || allDrawn || mLastAllDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001794 pw.print(prefix); pw.print("mNumInterestingWindows=");
1795 pw.print(mNumInterestingWindows);
1796 pw.print(" mNumDrawnWindows="); pw.print(mNumDrawnWindows);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001797 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -07001798 pw.print(" allDrawn="); pw.print(allDrawn);
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001799 pw.print(" lastAllDrawn="); pw.print(mLastAllDrawn);
Craig Mautner6fbda632012-07-03 09:26:39 -07001800 pw.println(")");
1801 }
1802 if (inPendingTransaction) {
1803 pw.print(prefix); pw.print("inPendingTransaction=");
1804 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001805 }
Craig Mautner799bc1d2015-01-14 10:33:48 -08001806 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001807 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
1808 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -08001809 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -08001810 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001811 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001812 if (startingWindow != null || startingSurface != null
Wale Ogunwale6c459212017-05-17 08:56:03 -07001813 || startingDisplayed || startingMoved || mHiddenSetFromTransferredStartingWindow) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001814 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001815 pw.print(" startingSurface="); pw.print(startingSurface);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001816 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
Wale Ogunwale6c459212017-05-17 08:56:03 -07001817 pw.print(" startingMoved="); pw.print(startingMoved);
1818 pw.println(" mHiddenSetFromTransferredStartingWindow="
1819 + mHiddenSetFromTransferredStartingWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001820 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01001821 if (!mFrozenBounds.isEmpty()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -08001822 pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds);
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001823 pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig);
Chong Zhangd78ddb42016-03-02 17:01:14 -08001824 }
1825 if (mPendingRelaunchCount != 0) {
1826 pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount);
Jorim Jaggi0429f352015-12-22 16:29:16 +01001827 }
Wale Ogunwale9c64cb62017-04-12 13:39:59 -07001828 if (getController() != null) {
1829 pw.print(prefix); pw.print("controller="); pw.println(getController());
1830 }
Wale Ogunwalee287e192017-04-21 09:30:12 -07001831 if (mRemovingFromDisplay) {
1832 pw.println(prefix + "mRemovingFromDisplay=" + mRemovingFromDisplay);
1833 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001834 }
1835
1836 @Override
1837 void setHidden(boolean hidden) {
1838 super.setHidden(hidden);
1839 scheduleAnimation();
1840 }
1841
1842 @Override
1843 void prepareSurfaces() {
1844 // isSelfAnimating also returns true when we are about to start a transition, so we need
1845 // to check super here.
1846 final boolean reallyAnimating = super.isSelfAnimating();
1847 final boolean show = !isHidden() || reallyAnimating;
1848 if (show && !mLastSurfaceShowing) {
1849 mPendingTransaction.show(mSurfaceControl);
1850 } else if (!show && mLastSurfaceShowing) {
1851 mPendingTransaction.hide(mSurfaceControl);
Jorim Jaggi4d1835d2017-08-31 17:28:27 +02001852 }
Jorim Jaggi988f6682017-11-17 17:46:43 +01001853 if (mThumbnail != null) {
1854 mThumbnail.setShowing(mPendingTransaction, show);
1855 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001856 mLastSurfaceShowing = show;
1857 super.prepareSurfaces();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001858 }
1859
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001860 boolean isFreezingScreen() {
1861 return mFreezingScreen;
1862 }
1863
1864 @Override
1865 boolean needsZBoost() {
1866 return mNeedsZBoost || super.needsZBoost();
1867 }
1868
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07001869 @CallSuper
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001870 @Override
Adrian Roos4921ccf2017-09-28 16:54:06 +02001871 public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07001872 final long token = proto.start(fieldId);
1873 writeNameToProto(proto, NAME);
Adrian Roos4921ccf2017-09-28 16:54:06 +02001874 super.writeToProto(proto, WINDOW_TOKEN, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07001875 proto.end(token);
1876 }
1877
1878 void writeNameToProto(ProtoOutputStream proto, long fieldId) {
1879 if (appToken == null) {
1880 return;
1881 }
1882 try {
1883 proto.write(fieldId, appToken.getName());
1884 } catch (RemoteException e) {
1885 // This shouldn't happen, but in this case fall back to outputting nothing
1886 Slog.e(TAG, e.toString());
1887 }
1888 }
1889
1890 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001891 public String toString() {
1892 if (stringName == null) {
1893 StringBuilder sb = new StringBuilder();
1894 sb.append("AppWindowToken{");
1895 sb.append(Integer.toHexString(System.identityHashCode(this)));
1896 sb.append(" token="); sb.append(token); sb.append('}');
1897 stringName = sb.toString();
1898 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001899 return stringName + ((mIsExiting) ? " mIsExiting=" : "");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001900 }
Jeff Browne9bdb312012-04-05 15:30:10 -07001901}