blob: b24a8cac3cefe8055e60b3423a236b6fabc6046a [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} */
214 private boolean mLastSurfaceShowing;
215
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.
648 // TODO: Not sure why this is needed.
649 final LinkedList<WindowState> children = new LinkedList<>(mChildren);
650 for (int i = children.size() - 1; i >= 0; i--) {
651 final WindowState win = children.get(i);
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700652 destroyedSomething |= win.destroySurface(cleanupOnResume, mAppStopped);
Robert Carre12aece2016-02-02 22:43:27 -0800653 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700654 if (destroyedSomething) {
655 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700656 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Robert Carre12aece2016-02-02 22:43:27 -0800657 }
658 }
659
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800660 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700661 * Notify that the app is now resumed, and it was not stopped before, perform a clean
662 * up of the surfaces
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800663 */
Jorim Jaggibae01b12017-04-11 16:29:10 -0700664 void notifyAppResumed(boolean wasStopped) {
Chong Zhangad24f962016-08-25 12:12:33 -0700665 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped
Jorim Jaggibae01b12017-04-11 16:29:10 -0700666 + " " + this);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700667 mAppStopped = false;
chaviwd3bf08d2017-08-01 17:24:59 -0700668 // Allow the window to turn the screen on once the app is resumed again.
669 setCanTurnScreenOn(true);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700670 if (!wasStopped) {
671 destroySurfaces(true /*cleanupOnResume*/);
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800672 }
Robert Carre12aece2016-02-02 22:43:27 -0800673 }
674
Chong Zhangbef461f2015-10-27 11:38:24 -0700675 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700676 * Notify that the app has stopped, and it is okay to destroy any surfaces which were
677 * keeping alive in case they were still being used.
678 */
679 void notifyAppStopped() {
680 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this);
681 mAppStopped = true;
682 destroySurfaces();
683 // Remove any starting window that was added for this app if they are still around.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800684 if (getController() != null) {
685 getController().removeStartingWindow();
686 }
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700687 }
688
Chong Zhang92147042016-05-09 12:47:11 -0700689 void clearAllDrawn() {
690 allDrawn = false;
691 deferClearAllDrawn = false;
Chong Zhangbef461f2015-10-27 11:38:24 -0700692 }
693
Bryce Lee6d410262017-02-28 15:30:17 -0800694 Task getTask() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800695 return (Task) getParent();
Bryce Lee6d410262017-02-28 15:30:17 -0800696 }
697
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800698 TaskStack getStack() {
699 final Task task = getTask();
700 if (task != null) {
701 return task.mStack;
702 } else {
703 return null;
704 }
705 }
706
Bryce Lee6d410262017-02-28 15:30:17 -0800707 @Override
708 void onParentSet() {
709 super.onParentSet();
710
Robert Carred3e83b2017-04-21 13:26:55 -0700711 final Task task = getTask();
712
Bryce Lee6d410262017-02-28 15:30:17 -0800713 // When the associated task is {@code null}, the {@link AppWindowToken} can no longer
714 // access visual elements like the {@link DisplayContent}. We must remove any associations
715 // such as animations.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800716 if (!mReparenting) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800717 if (task == null) {
718 // It is possible we have been marked as a closing app earlier. We must remove ourselves
719 // from this list so we do not participate in any future animations.
720 mService.mClosingApps.remove(this);
Robert Carred3e83b2017-04-21 13:26:55 -0700721 } else if (mLastParent != null && mLastParent.mStack != null) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800722 task.mStack.mExitingAppTokens.remove(this);
723 }
Bryce Lee6d410262017-02-28 15:30:17 -0800724 }
Robert Carred3e83b2017-04-21 13:26:55 -0700725 mLastParent = task;
Bryce Lee6d410262017-02-28 15:30:17 -0800726 }
727
Wale Ogunwalefa854eb2016-09-20 13:43:52 -0700728 void postWindowRemoveStartingWindowCleanup(WindowState win) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700729 // TODO: Something smells about the code below...Is there a better way?
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700730 if (startingWindow == win) {
731 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800732 if (getController() != null) {
733 getController().removeStartingWindow();
734 }
Wale Ogunwale6c459212017-05-17 08:56:03 -0700735 } else if (mChildren.size() == 0) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700736 // If this is the last window and we had requested a starting transition window,
737 // well there is no point now.
Jorim Jaggi02886a82016-12-06 09:10:06 -0800738 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingData");
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700739 startingData = null;
Wale Ogunwale6c459212017-05-17 08:56:03 -0700740 if (mHiddenSetFromTransferredStartingWindow) {
741 // We set the hidden state to false for the token from a transferred starting window.
742 // We now reset it back to true since the starting window was the last window in the
743 // token.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200744 setHidden(true);
Wale Ogunwale6c459212017-05-17 08:56:03 -0700745 }
Jorim Jaggi829b9cd2017-01-23 16:20:53 +0100746 } else if (mChildren.size() == 1 && startingSurface != null && !isRelaunching()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700747 // If this is the last window except for a starting transition window,
748 // we need to get rid of the starting transition.
Jorim Jaggie4b0f282017-05-17 15:10:29 +0200749 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Last window, removing starting window "
750 + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800751 if (getController() != null) {
752 getController().removeStartingWindow();
753 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700754 }
755 }
756
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700757 void removeDeadWindows() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700758 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700759 WindowState win = mChildren.get(winNdx);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800760 if (win.mAppDied) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700761 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700762 "removeDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800763 // Set mDestroying, we don't want any animation or delayed removal here.
764 win.mDestroying = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700765 // Also removes child windows.
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700766 win.removeIfPossible();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800767 }
768 }
769 }
770
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700771 boolean hasWindowsAlive() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700772 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700773 // No need to loop through child windows as the answer should be the same as that of the
774 // parent window.
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700775 if (!(mChildren.get(i)).mAppDied) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700776 return true;
777 }
778 }
779 return false;
780 }
781
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700782 void setWillReplaceWindows(boolean animate) {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700783 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
784 "Marking app token " + this + " with replacing windows.");
Robert Carra1eb4392015-12-10 12:43:51 -0800785
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700786 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700787 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700788 w.setWillReplaceWindow(animate);
Robert Carra1eb4392015-12-10 12:43:51 -0800789 }
Robert Carra1eb4392015-12-10 12:43:51 -0800790 }
791
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700792 void setWillReplaceChildWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700793 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this
Robert Carr23fa16b2016-01-13 13:19:58 -0800794 + " with replacing child windows.");
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700795 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700796 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700797 w.setWillReplaceChildWindows();
Robert Carr23fa16b2016-01-13 13:19:58 -0800798 }
799 }
800
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700801 void clearWillReplaceWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700802 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
803 "Resetting app token " + this + " of replacing window marks.");
Chong Zhangf596cd52016-01-05 13:42:44 -0800804
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700805 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700806 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700807 w.clearWillReplaceWindow();
Chong Zhangf596cd52016-01-05 13:42:44 -0800808 }
809 }
810
Chong Zhang4d7369a2016-04-25 16:09:14 -0700811 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700812 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700813 final WindowState w = mChildren.get(i);
Chong Zhang4d7369a2016-04-25 16:09:14 -0700814 w.requestUpdateWallpaperIfNeeded();
815 }
816 }
817
Chong Zhangd78ddb42016-03-02 17:01:14 -0800818 boolean isRelaunching() {
819 return mPendingRelaunchCount > 0;
820 }
821
Robert Carr68375192017-06-13 12:41:53 -0700822 boolean shouldFreezeBounds() {
823 final Task task = getTask();
824
825 // For freeform windows, we can't freeze the bounds at the moment because this would make
826 // the resizing unresponsive.
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700827 if (task == null || task.inFreeformWindowingMode()) {
Robert Carr68375192017-06-13 12:41:53 -0700828 return false;
829 }
830
831 // We freeze the bounds while drag resizing to deal with the time between
832 // the divider/drag handle being released, and the handling it's new
833 // configuration. If we are relaunched outside of the drag resizing state,
834 // we need to be careful not to do this.
835 return getTask().isDragResizing();
836 }
837
Chong Zhangd78ddb42016-03-02 17:01:14 -0800838 void startRelaunching() {
Robert Carr68375192017-06-13 12:41:53 -0700839 if (shouldFreezeBounds()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -0800840 freezeBounds();
841 }
Robert Carrd5c7dd62017-03-08 10:39:30 -0800842
843 // In the process of tearing down before relaunching, the app will
844 // try and clean up it's child surfaces. We need to prevent this from
845 // happening, so we sever the children, transfering their ownership
846 // from the client it-self to the parent surface (owned by us).
847 for (int i = mChildren.size() - 1; i >= 0; i--) {
848 final WindowState w = mChildren.get(i);
849 w.mWinAnimator.detachChildren();
850 }
851
Chong Zhangd78ddb42016-03-02 17:01:14 -0800852 mPendingRelaunchCount++;
853 }
854
855 void finishRelaunching() {
Robert Carr68375192017-06-13 12:41:53 -0700856 unfreezeBounds();
857
Chong Zhangd78ddb42016-03-02 17:01:14 -0800858 if (mPendingRelaunchCount > 0) {
859 mPendingRelaunchCount--;
Bryce Lee081554b2017-05-25 07:52:12 -0700860 } else {
861 // Update keyguard flags upon finishing relaunch.
862 checkKeyguardFlagsChanged();
Chong Zhangd78ddb42016-03-02 17:01:14 -0800863 }
864 }
865
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700866 void clearRelaunching() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700867 if (mPendingRelaunchCount == 0) {
868 return;
869 }
Robert Carr68375192017-06-13 12:41:53 -0700870 unfreezeBounds();
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700871 mPendingRelaunchCount = 0;
872 }
873
Wale Ogunwale07bcab72016-10-14 15:30:09 -0700874 /**
875 * Returns true if the new child window we are adding to this token is considered greater than
876 * the existing child window in this token in terms of z-order.
877 */
878 @Override
879 protected boolean isFirstChildWindowGreaterThanSecond(WindowState newWindow,
880 WindowState existingWindow) {
881 final int type1 = newWindow.mAttrs.type;
882 final int type2 = existingWindow.mAttrs.type;
883
884 // Base application windows should be z-ordered BELOW all other windows in the app token.
885 if (type1 == TYPE_BASE_APPLICATION && type2 != TYPE_BASE_APPLICATION) {
886 return false;
887 } else if (type1 != TYPE_BASE_APPLICATION && type2 == TYPE_BASE_APPLICATION) {
888 return true;
889 }
890
891 // Starting windows should be z-ordered ABOVE all other windows in the app token.
892 if (type1 == TYPE_APPLICATION_STARTING && type2 != TYPE_APPLICATION_STARTING) {
893 return true;
894 } else if (type1 != TYPE_APPLICATION_STARTING && type2 == TYPE_APPLICATION_STARTING) {
895 return false;
896 }
897
898 // Otherwise the new window is greater than the existing window.
899 return true;
900 }
901
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700902 @Override
Robert Carra1eb4392015-12-10 12:43:51 -0800903 void addWindow(WindowState w) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700904 super.addWindow(w);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700905
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700906 boolean gotReplacementWindow = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700907 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700908 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700909 gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w);
910 }
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700911
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700912 // if we got a replacement window, reset the timeout to give drawing more time
913 if (gotReplacementWindow) {
914 mService.scheduleWindowReplacementTimeouts(this);
Robert Carra1eb4392015-12-10 12:43:51 -0800915 }
Jorim Jaggife762342016-10-13 14:33:27 +0200916 checkKeyguardFlagsChanged();
917 }
918
919 @Override
920 void removeChild(WindowState child) {
921 super.removeChild(child);
922 checkKeyguardFlagsChanged();
Robert Carra1eb4392015-12-10 12:43:51 -0800923 }
924
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700925 private boolean waitingForReplacement() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700926 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700927 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700928 if (candidate.waitingForReplacement()) {
Robert Carra1eb4392015-12-10 12:43:51 -0800929 return true;
930 }
931 }
932 return false;
933 }
934
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700935 void onWindowReplacementTimeout() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700936 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700937 (mChildren.get(i)).onWindowReplacementTimeout();
Robert Carra1eb4392015-12-10 12:43:51 -0800938 }
939 }
940
Winson Chung30480042017-01-26 10:55:34 -0800941 void reparent(Task task, int position) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800942 final Task currentTask = getTask();
943 if (task == currentTask) {
Winson Chung30480042017-01-26 10:55:34 -0800944 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800945 "window token=" + this + " already child of task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -0800946 }
Bryce Lee6d410262017-02-28 15:30:17 -0800947
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800948 if (currentTask.mStack != task.mStack) {
Bryce Lee6d410262017-02-28 15:30:17 -0800949 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800950 "window token=" + this + " current task=" + currentTask
Bryce Lee6d410262017-02-28 15:30:17 -0800951 + " belongs to a different stack than " + task);
952 }
953
Winson Chung30480042017-01-26 10:55:34 -0800954 if (DEBUG_ADD_REMOVE) Slog.i(TAG, "reParentWindowToken: removing window token=" + this
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800955 + " from task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -0800956 final DisplayContent prevDisplayContent = getDisplayContent();
957
Bryce Lee6d410262017-02-28 15:30:17 -0800958 mReparenting = true;
959
Winson Chung30480042017-01-26 10:55:34 -0800960 getParent().removeChild(this);
961 task.addChild(this, position);
962
Bryce Lee6d410262017-02-28 15:30:17 -0800963 mReparenting = false;
964
Winson Chung30480042017-01-26 10:55:34 -0800965 // Relayout display(s).
966 final DisplayContent displayContent = task.getDisplayContent();
967 displayContent.setLayoutNeeded();
968 if (prevDisplayContent != displayContent) {
969 onDisplayChanged(displayContent);
970 prevDisplayContent.setLayoutNeeded();
971 }
972 }
973
Jorim Jaggi0429f352015-12-22 16:29:16 +0100974 /**
975 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
976 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
977 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
978 * with a queue.
979 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800980 private void freezeBounds() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800981 final Task task = getTask();
982 mFrozenBounds.offer(new Rect(task.mPreparedFrozenBounds));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700983
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800984 if (task.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) {
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700985 // We didn't call prepareFreezingBounds on the task, so use the current value.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800986 mFrozenMergedConfig.offer(new Configuration(task.getConfiguration()));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700987 } else {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800988 mFrozenMergedConfig.offer(new Configuration(task.mPreparedFrozenMergedConfig));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700989 }
Andrii Kulianb10330d2016-09-16 13:51:46 -0700990 // Calling unset() to make it equal to Configuration.EMPTY.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800991 task.mPreparedFrozenMergedConfig.unset();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100992 }
993
994 /**
995 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
996 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800997 private void unfreezeBounds() {
Robert Carr68375192017-06-13 12:41:53 -0700998 if (mFrozenBounds.isEmpty()) {
999 return;
Wale Ogunwale37dbafc2016-06-27 10:15:20 -07001000 }
Robert Carr68375192017-06-13 12:41:53 -07001001 mFrozenBounds.remove();
Wale Ogunwale37dbafc2016-06-27 10:15:20 -07001002 if (!mFrozenMergedConfig.isEmpty()) {
1003 mFrozenMergedConfig.remove();
1004 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001005 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001006 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001007 win.onUnfreezeBounds();
Jorim Jaggi4846ee32016-01-07 17:39:12 +01001008 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001009 mService.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +01001010 }
1011
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001012 void setAppLayoutChanges(int changes, String reason) {
1013 if (!mChildren.isEmpty()) {
1014 final DisplayContent dc = getDisplayContent();
1015 dc.pendingLayoutChanges |= changes;
1016 if (DEBUG_LAYOUT_REPEATS) {
1017 mService.mWindowPlacerLocked.debugLayoutRepeats(reason, dc.pendingLayoutChanges);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001018 }
1019 }
1020 }
1021
1022 void removeReplacedWindowIfNeeded(WindowState replacement) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001023 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001024 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001025 if (win.removeReplacedWindowIfNeeded(replacement)) {
1026 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001027 }
1028 }
1029 }
1030
1031 void startFreezingScreen() {
1032 if (DEBUG_ORIENTATION) logWithStack(TAG, "Set freezing of " + appToken + ": hidden="
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001033 + isHidden() + " freezing=" + mFreezingScreen + " hiddenRequested="
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001034 + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001035 if (!hiddenRequested) {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001036 if (!mFreezingScreen) {
1037 mFreezingScreen = true;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001038 mService.registerAppFreezeListener(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001039 mService.mAppsFreezingScreen++;
1040 if (mService.mAppsFreezingScreen == 1) {
Bryce Lee8f853582017-06-05 17:25:59 -07001041 mService.startFreezingDisplayLocked(false, 0, 0, getDisplayContent());
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001042 mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT);
1043 mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001044 }
1045 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001046 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001047 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001048 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001049 w.onStartFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001050 }
1051 }
1052 }
1053
1054 void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001055 if (!mFreezingScreen) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001056 return;
1057 }
1058 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + this + " force=" + force);
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001059 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001060 boolean unfrozeWindows = false;
1061 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001062 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001063 unfrozeWindows |= w.onStopFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001064 }
1065 if (force || unfrozeWindows) {
1066 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this);
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001067 mFreezingScreen = false;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001068 mService.unregisterAppFreezeListener(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001069 mService.mAppsFreezingScreen--;
1070 mService.mLastFinishedFreezeSource = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001071 }
1072 if (unfreezeSurfaceNow) {
1073 if (unfrozeWindows) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001074 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001075 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001076 mService.stopFreezingDisplayLocked();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001077 }
1078 }
1079
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001080 @Override
1081 public void onAppFreezeTimeout() {
1082 Slog.w(TAG_WM, "Force clearing freeze: " + this);
1083 stopFreezingScreen(true, true);
1084 }
1085
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001086 boolean transferStartingWindow(IBinder transferFrom) {
Wale Ogunwale02319a62016-09-26 15:21:22 -07001087 final AppWindowToken fromToken = getDisplayContent().getAppWindowToken(transferFrom);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001088 if (fromToken == null) {
1089 return false;
1090 }
1091
1092 final WindowState tStartingWindow = fromToken.startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001093 if (tStartingWindow != null && fromToken.startingSurface != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001094 // In this case, the starting icon has already been displayed, so start
1095 // letting windows get shown immediately without any more transitions.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001096 mService.mSkipAppTransitionAnimation = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001097
1098 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow
1099 + " from " + fromToken + " to " + this);
1100
1101 final long origId = Binder.clearCallingIdentity();
Peter Visontay3556a3b2017-11-01 17:23:17 +00001102 try {
1103 // Transfer the starting window over to the new token.
1104 startingData = fromToken.startingData;
1105 startingSurface = fromToken.startingSurface;
1106 startingDisplayed = fromToken.startingDisplayed;
1107 fromToken.startingDisplayed = false;
1108 startingWindow = tStartingWindow;
1109 reportedVisible = fromToken.reportedVisible;
1110 fromToken.startingData = null;
1111 fromToken.startingSurface = null;
1112 fromToken.startingWindow = null;
1113 fromToken.startingMoved = true;
1114 tStartingWindow.mToken = this;
1115 tStartingWindow.mAppToken = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001116
Peter Visontay3556a3b2017-11-01 17:23:17 +00001117 if (DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1118 "Removing starting " + tStartingWindow + " from " + fromToken);
1119 fromToken.removeChild(tStartingWindow);
1120 fromToken.postWindowRemoveStartingWindowCleanup(tStartingWindow);
1121 fromToken.mHiddenSetFromTransferredStartingWindow = false;
1122 addWindow(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001123
Peter Visontay3556a3b2017-11-01 17:23:17 +00001124 // Propagate other interesting state between the tokens. If the old token is displayed,
1125 // we should immediately force the new one to be displayed. If it is animating, we need
1126 // to move that animation to the new one.
1127 if (fromToken.allDrawn) {
1128 allDrawn = true;
1129 deferClearAllDrawn = fromToken.deferClearAllDrawn;
1130 }
1131 if (fromToken.firstWindowDrawn) {
1132 firstWindowDrawn = true;
1133 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001134 if (!fromToken.isHidden()) {
1135 setHidden(false);
Peter Visontay3556a3b2017-11-01 17:23:17 +00001136 hiddenRequested = false;
1137 mHiddenSetFromTransferredStartingWindow = true;
1138 }
1139 setClientHidden(fromToken.mClientHidden);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001140
Jorim Jaggi980c9de2017-11-17 01:41:37 +01001141 transferAnimation(fromToken);
1142
1143 // When transferring an animation, we no longer need to apply an animation to the
1144 // the token we transfer the animation over. Thus, remove the animation from
1145 // pending opening apps.
1146 mService.mOpeningApps.remove(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001147
Peter Visontay3556a3b2017-11-01 17:23:17 +00001148 mService.updateFocusedWindowLocked(
1149 UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/);
1150 getDisplayContent().setLayoutNeeded();
1151 mService.mWindowPlacerLocked.performSurfacePlacement();
1152 } finally {
1153 Binder.restoreCallingIdentity(origId);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001154 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001155 return true;
1156 } else if (fromToken.startingData != null) {
1157 // The previous app was getting ready to show a
1158 // starting window, but hasn't yet done so. Steal it!
1159 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1160 "Moving pending starting from " + fromToken + " to " + this);
1161 startingData = fromToken.startingData;
1162 fromToken.startingData = null;
1163 fromToken.startingMoved = true;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001164 if (getController() != null) {
1165 getController().scheduleAddStartingWindow();
1166 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001167 return true;
1168 }
1169
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001170 // TODO: Transfer thumbnail
1171
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001172 return false;
1173 }
1174
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001175 boolean isLastWindow(WindowState win) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001176 return mChildren.size() == 1 && mChildren.get(0) == win;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001177 }
1178
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001179 @Override
1180 void onAppTransitionDone() {
1181 sendingToBottom = false;
1182 }
1183
Wale Ogunwale51362492016-09-08 17:49:17 -07001184 /**
1185 * We override because this class doesn't want its children affecting its reported orientation
1186 * in anyway.
1187 */
1188 @Override
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001189 int getOrientation(int candidate) {
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001190 if (candidate == SCREEN_ORIENTATION_BEHIND) {
1191 // Allow app to specify orientation regardless of its visibility state if the current
1192 // candidate want us to use orientation behind. I.e. the visible app on-top of this one
1193 // wants us to use the orientation of the app behind it.
1194 return mOrientation;
1195 }
1196
Bryce Lee61fbcbc2017-03-10 14:14:03 -08001197 // The {@link AppWindowToken} should only specify an orientation when it is not closing or
1198 // going to the bottom. Allowing closing {@link AppWindowToken} to participate can lead to
1199 // an Activity in another task being started in the wrong orientation during the transition.
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001200 if (!(sendingToBottom || mService.mClosingApps.contains(this))
Bryce Lee00d586d2017-07-28 20:48:43 -07001201 && (isVisible() || mService.mOpeningApps.contains(this) || isOnTop())) {
Bryce Leea163b762017-01-24 11:05:01 -08001202 return mOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001203 }
Bryce Leea163b762017-01-24 11:05:01 -08001204
1205 return SCREEN_ORIENTATION_UNSET;
Wale Ogunwale51362492016-09-08 17:49:17 -07001206 }
1207
Wale Ogunwaleb198b742016-12-01 08:44:09 -08001208 /** Returns the app's preferred orientation regardless of its currently visibility state. */
1209 int getOrientationIgnoreVisibility() {
1210 return mOrientation;
1211 }
1212
Craig Mautnerdbb79912012-03-01 18:59:14 -08001213 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001214 void checkAppWindowsReadyToShow() {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001215 if (allDrawn == mLastAllDrawn) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001216 return;
1217 }
1218
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001219 mLastAllDrawn = allDrawn;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001220 if (!allDrawn) {
1221 return;
1222 }
1223
1224 // The token has now changed state to having all windows shown... what to do, what to do?
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001225 if (mFreezingScreen) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001226 showAllWindowsLocked();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001227 stopFreezingScreen(false, true);
1228 if (DEBUG_ORIENTATION) Slog.i(TAG,
1229 "Setting mOrientationChangeComplete=true because wtoken " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001230 + " numInteresting=" + mNumInterestingWindows + " numDrawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001231 // This will set mOrientationChangeComplete and cause a pass through layout.
1232 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001233 "checkAppWindowsReadyToShow: freezingScreen");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001234 } else {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001235 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001236
1237 // We can now show all of the drawn windows!
1238 if (!mService.mOpeningApps.contains(this)) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001239 showAllWindowsLocked();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001240 }
1241 }
1242 }
1243
Matthew Ng5d23afa2017-06-21 16:16:24 -07001244 /**
Bryce Leed390deb2017-06-22 13:14:28 -07001245 * Returns whether the drawn window states of this {@link AppWindowToken} has considered every
1246 * child {@link WindowState}. A child is considered if it has been passed into
1247 * {@link #updateDrawnWindowStates(WindowState)} after being added. This is used to determine
1248 * whether states, such as {@code allDrawn}, can be set, which relies on state variables such as
1249 * {@code mNumInterestingWindows}, which depend on all {@link WindowState}s being considered.
1250 *
1251 * @return {@code true} If all children have been considered, {@code false}.
1252 */
1253 private boolean allDrawnStatesConsidered() {
Bryce Lee6311c4b2017-07-06 14:09:29 -07001254 for (int i = mChildren.size() - 1; i >= 0; --i) {
1255 final WindowState child = mChildren.get(i);
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001256 if (child.mightAffectAllDrawn() && !child.getDrawnStateEvaluated()) {
Bryce Leed390deb2017-06-22 13:14:28 -07001257 return false;
1258 }
1259 }
1260 return true;
1261 }
1262
1263 /**
Matthew Ng5d23afa2017-06-21 16:16:24 -07001264 * Determines if the token has finished drawing. This should only be called from
1265 * {@link DisplayContent#applySurfaceChangesTransaction}
1266 */
Matthew Ng498c71d2017-04-18 13:55:45 -07001267 void updateAllDrawn() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001268 if (!allDrawn) {
Matthew Ng498c71d2017-04-18 13:55:45 -07001269 // Number of drawn windows can be less when a window is being relaunched, wait for
Bryce Leed390deb2017-06-22 13:14:28 -07001270 // all windows to be launched and drawn for this token be considered all drawn.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001271 final int numInteresting = mNumInterestingWindows;
Bryce Leed390deb2017-06-22 13:14:28 -07001272
1273 // We must make sure that all present children have been considered (determined by
1274 // {@link #allDrawnStatesConsidered}) before evaluating whether everything has been
1275 // drawn.
1276 if (numInteresting > 0 && allDrawnStatesConsidered()
1277 && mNumDrawnWindows >= numInteresting && !isRelaunching()) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001278 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawn: " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001279 + " interesting=" + numInteresting + " drawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001280 allDrawn = true;
1281 // Force an additional layout pass where
1282 // WindowStateAnimator#commitFinishDrawingLocked() will call performShowLocked().
Matthew Ng498c71d2017-04-18 13:55:45 -07001283 if (mDisplayContent != null) {
1284 mDisplayContent.setLayoutNeeded();
1285 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001286 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Robert Carrecc06b32017-04-18 14:25:10 -07001287
Winson Chunge7ba6862017-05-24 12:13:33 -07001288 // Notify the pinned stack upon all windows drawn. If there was an animation in
1289 // progress then this signal will resume that animation.
Wale Ogunwale61911492017-10-11 08:50:50 -07001290 final TaskStack pinnedStack = mDisplayContent.getPinnedStack();
Winson Chunge7ba6862017-05-24 12:13:33 -07001291 if (pinnedStack != null) {
1292 pinnedStack.onAllWindowsDrawn();
Robert Carrecc06b32017-04-18 14:25:10 -07001293 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001294 }
1295 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001296 }
1297
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001298 /**
1299 * Updated this app token tracking states for interesting and drawn windows based on the window.
1300 *
1301 * @return Returns true if the input window is considered interesting and drawn while all the
1302 * windows in this app token where not considered drawn as of the last pass.
1303 */
1304 boolean updateDrawnWindowStates(WindowState w) {
Bryce Leed390deb2017-06-22 13:14:28 -07001305 w.setDrawnStateEvaluated(true /*evaluated*/);
1306
Jorim Jaggie4b0f282017-05-17 15:10:29 +02001307 if (DEBUG_STARTING_WINDOW_VERBOSE && w == startingWindow) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001308 Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" + w.isOnScreen()
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001309 + " allDrawn=" + allDrawn + " freezingScreen=" + mFreezingScreen);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001310 }
1311
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001312 if (allDrawn && !mFreezingScreen) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001313 return false;
1314 }
1315
1316 if (mLastTransactionSequence != mService.mTransactionSequence) {
1317 mLastTransactionSequence = mService.mTransactionSequence;
1318 mNumInterestingWindows = mNumDrawnWindows = 0;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001319 startingDisplayed = false;
1320 }
1321
1322 final WindowStateAnimator winAnimator = w.mWinAnimator;
1323
1324 boolean isInterestingAndDrawn = false;
1325
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001326 if (!allDrawn && w.mightAffectAllDrawn()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001327 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
1328 Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw()
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001329 + ", isAnimationSet=" + isSelfAnimating());
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001330 if (!w.isDrawnLw()) {
1331 Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController
1332 + " pv=" + w.mPolicyVisibility
1333 + " mDrawState=" + winAnimator.drawStateToString()
1334 + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001335 + " a=" + isSelfAnimating());
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001336 }
1337 }
1338
1339 if (w != startingWindow) {
1340 if (w.isInteresting()) {
1341 mNumInterestingWindows++;
1342 if (w.isDrawnLw()) {
1343 mNumDrawnWindows++;
1344
1345 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, "tokenMayBeDrawn: "
1346 + this + " w=" + w + " numInteresting=" + mNumInterestingWindows
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001347 + " freezingScreen=" + mFreezingScreen
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001348 + " mAppFreezing=" + w.mAppFreezing);
1349
1350 isInterestingAndDrawn = true;
1351 }
1352 }
1353 } else if (w.isDrawnLw()) {
Jorim Jaggi3878ca32017-02-02 17:13:05 -08001354 if (getController() != null) {
1355 getController().reportStartingWindowDrawn();
1356 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001357 startingDisplayed = true;
1358 }
1359 }
1360
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001361 return isInterestingAndDrawn;
1362 }
1363
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001364 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001365 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001366 // For legacy reasons we process the TaskStack.mExitingAppTokens first in DisplayContent
1367 // before the non-exiting app tokens. So, we skip the exiting app tokens here.
1368 // TODO: Investigate if we need to continue to do this or if we can just process them
1369 // in-order.
1370 if (mIsExiting && !waitingForReplacement()) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001371 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001372 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001373 return forAllWindowsUnchecked(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001374 }
1375
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001376 boolean forAllWindowsUnchecked(ToBooleanFunction<WindowState> callback,
1377 boolean traverseTopToBottom) {
1378 return super.forAllWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001379 }
1380
1381 @Override
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001382 AppWindowToken asAppWindowToken() {
1383 // I am an app window token!
1384 return this;
1385 }
1386
1387 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -07001388 boolean fillsParent() {
1389 return mFillsParent;
1390 }
1391
1392 void setFillsParent(boolean fillsParent) {
1393 mFillsParent = fillsParent;
1394 }
1395
Jorim Jaggife762342016-10-13 14:33:27 +02001396 boolean containsDismissKeyguardWindow() {
Bryce Lee081554b2017-05-25 07:52:12 -07001397 // Window state is transient during relaunch. We are not guaranteed to be frozen during the
1398 // entirety of the relaunch.
1399 if (isRelaunching()) {
1400 return mLastContainsDismissKeyguardWindow;
1401 }
1402
Jorim Jaggife762342016-10-13 14:33:27 +02001403 for (int i = mChildren.size() - 1; i >= 0; i--) {
1404 if ((mChildren.get(i).mAttrs.flags & FLAG_DISMISS_KEYGUARD) != 0) {
1405 return true;
1406 }
1407 }
1408 return false;
1409 }
1410
1411 boolean containsShowWhenLockedWindow() {
Bryce Lee081554b2017-05-25 07:52:12 -07001412 // When we are relaunching, it is possible for us to be unfrozen before our previous
1413 // windows have been added back. Using the cached value ensures that our previous
1414 // showWhenLocked preference is honored until relaunching is complete.
1415 if (isRelaunching()) {
1416 return mLastContainsShowWhenLockedWindow;
1417 }
1418
Jorim Jaggife762342016-10-13 14:33:27 +02001419 for (int i = mChildren.size() - 1; i >= 0; i--) {
1420 if ((mChildren.get(i).mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
1421 return true;
1422 }
1423 }
Bryce Lee081554b2017-05-25 07:52:12 -07001424
Jorim Jaggife762342016-10-13 14:33:27 +02001425 return false;
1426 }
1427
1428 void checkKeyguardFlagsChanged() {
1429 final boolean containsDismissKeyguard = containsDismissKeyguardWindow();
1430 final boolean containsShowWhenLocked = containsShowWhenLockedWindow();
1431 if (containsDismissKeyguard != mLastContainsDismissKeyguardWindow
1432 || containsShowWhenLocked != mLastContainsShowWhenLockedWindow) {
1433 mService.notifyKeyguardFlagsChanged(null /* callback */);
1434 }
1435 mLastContainsDismissKeyguardWindow = containsDismissKeyguard;
1436 mLastContainsShowWhenLockedWindow = containsShowWhenLocked;
1437 }
1438
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001439 WindowState getImeTargetBelowWindow(WindowState w) {
1440 final int index = mChildren.indexOf(w);
1441 if (index > 0) {
1442 final WindowState target = mChildren.get(index - 1);
1443 if (target.canBeImeTarget()) {
1444 return target;
1445 }
1446 }
1447 return null;
1448 }
1449
Winson Chungbe9be7f2017-06-28 10:55:22 -07001450 int getLowestAnimLayer() {
1451 for (int i = 0; i < mChildren.size(); i++) {
1452 final WindowState w = mChildren.get(i);
1453 if (w.mRemoved) {
1454 continue;
1455 }
1456 return w.mWinAnimator.mAnimLayer;
1457 }
1458 return Integer.MAX_VALUE;
1459 }
1460
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001461 WindowState getHighestAnimLayerWindow(WindowState currentTarget) {
1462 WindowState candidate = null;
1463 for (int i = mChildren.indexOf(currentTarget); i >= 0; i--) {
1464 final WindowState w = mChildren.get(i);
1465 if (w.mRemoved) {
1466 continue;
1467 }
1468 if (candidate == null || w.mWinAnimator.mAnimLayer >
1469 candidate.mWinAnimator.mAnimLayer) {
1470 candidate = w;
1471 }
1472 }
1473 return candidate;
1474 }
1475
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001476 /**
1477 * See {@link Activity#setDisablePreviewScreenshots}.
1478 */
1479 void setDisablePreviewScreenshots(boolean disable) {
Wale Ogunwale6c459212017-05-17 08:56:03 -07001480 mDisablePreviewScreenshots = disable;
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001481 }
1482
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001483 /**
chaviwd3bf08d2017-08-01 17:24:59 -07001484 * Sets whether the current launch can turn the screen on. See {@link #canTurnScreenOn()}
1485 */
1486 void setCanTurnScreenOn(boolean canTurnScreenOn) {
1487 mCanTurnScreenOn = canTurnScreenOn;
1488 }
1489
1490 /**
1491 * Indicates whether the current launch can turn the screen on. This is to prevent multiple
1492 * relayouts from turning the screen back on. The screen should only turn on at most
1493 * once per activity resume.
1494 *
1495 * @return true if the screen can be turned on.
1496 */
1497 boolean canTurnScreenOn() {
1498 return mCanTurnScreenOn;
1499 }
1500
1501 /**
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001502 * Retrieves whether we'd like to generate a snapshot that's based solely on the theme. This is
1503 * the case when preview screenshots are disabled {@link #setDisablePreviewScreenshots} or when
1504 * we can't take a snapshot for other reasons, for example, if we have a secure window.
1505 *
1506 * @return True if we need to generate an app theme snapshot, false if we'd like to take a real
1507 * screenshot.
1508 */
1509 boolean shouldUseAppThemeSnapshot() {
Wale Ogunwale6c459212017-05-17 08:56:03 -07001510 return mDisablePreviewScreenshots || forAllWindows(w -> (w.mAttrs.flags & FLAG_SECURE) != 0,
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001511 true /* topToBottom */);
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001512 }
1513
chaviw23ee71c2017-12-18 11:29:41 -08001514 @Override
1515 public SurfaceControl.Builder makeAnimationLeash() {
1516 return super.makeAnimationLeash()
1517 .setParent(getAppAnimationLayer());
1518 }
1519
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001520 boolean applyAnimationLocked(WindowManager.LayoutParams lp, int transit, boolean enter,
1521 boolean isVoiceInteraction) {
1522
1523 if (mService.mDisableTransitionAnimation) {
1524 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1525 Slog.v(TAG_WM, "applyAnimation: transition animation is disabled. atoken=" + this);
1526 }
1527 cancelAnimation();
1528 return false;
1529 }
1530
1531 // Only apply an animation if the display isn't frozen. If it is frozen, there is no reason
1532 // to animate and it can cause strange artifacts when we unfreeze the display if some
1533 // different animation is running.
1534 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "AWT#applyAnimationLocked");
1535 if (okToAnimate()) {
1536 final Animation a = loadAnimation(lp, transit, enter, isVoiceInteraction);
1537 if (a != null) {
chaviw23ee71c2017-12-18 11:29:41 -08001538 final TaskStack stack = getStack();
1539 mTmpPoint.set(0, 0);
chaviw23012112017-12-20 15:29:04 -08001540 mTmpRect.setEmpty();
chaviw23ee71c2017-12-18 11:29:41 -08001541 if (stack != null) {
1542 stack.getRelativePosition(mTmpPoint);
chaviw23012112017-12-20 15:29:04 -08001543 stack.getBounds(mTmpRect);
chaviw23ee71c2017-12-18 11:29:41 -08001544 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001545 final AnimationAdapter adapter = new LocalAnimationAdapter(
chaviw23012112017-12-20 15:29:04 -08001546 new WindowAnimationSpec(a, mTmpPoint, mTmpRect,
1547 mService.mAppTransition.canSkipFirstFrame(),
1548 mService.mAppTransition.getAppStackClipMode()),
Jorim Jaggi2e3c31d2017-11-20 19:49:00 +01001549 mService.mSurfaceAnimationRunner);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001550 if (a.getZAdjustment() == Animation.ZORDER_TOP) {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001551 mNeedsZBoost = true;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001552 }
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001553 startAnimation(getPendingTransaction(), adapter, !isVisible());
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001554 mTransit = transit;
1555 mTransitFlags = mService.mAppTransition.getTransitFlags();
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001556 }
1557 } else {
1558 cancelAnimation();
1559 }
1560 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
1561
1562 return isReallyAnimating();
1563 }
1564
1565 private Animation loadAnimation(WindowManager.LayoutParams lp, int transit, boolean enter,
1566 boolean isVoiceInteraction) {
1567 final DisplayContent displayContent = getTask().getDisplayContent();
1568 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
1569 final int width = displayInfo.appWidth;
1570 final int height = displayInfo.appHeight;
1571 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG_WM,
1572 "applyAnimation: atoken=" + this);
1573
1574 // Determine the visible rect to calculate the thumbnail clip
1575 final WindowState win = findMainWindow();
1576 final Rect frame = new Rect(0, 0, width, height);
1577 final Rect displayFrame = new Rect(0, 0,
1578 displayInfo.logicalWidth, displayInfo.logicalHeight);
1579 final Rect insets = new Rect();
1580 final Rect stableInsets = new Rect();
1581 Rect surfaceInsets = null;
1582 final boolean freeform = win != null && win.inFreeformWindowingMode();
1583 if (win != null) {
1584 // Containing frame will usually cover the whole screen, including dialog windows.
1585 // For freeform workspace windows it will not cover the whole screen and it also
1586 // won't exactly match the final freeform window frame (e.g. when overlapping with
1587 // the status bar). In that case we need to use the final frame.
1588 if (freeform) {
1589 frame.set(win.mFrame);
1590 } else {
1591 frame.set(win.mContainingFrame);
1592 }
1593 surfaceInsets = win.getAttrs().surfaceInsets;
1594 insets.set(win.mContentInsets);
1595 stableInsets.set(win.mStableInsets);
1596 }
1597
1598 if (mLaunchTaskBehind) {
1599 // Differentiate the two animations. This one which is briefly on the screen
1600 // gets the !enter animation, and the other activity which remains on the
1601 // screen gets the enter animation. Both appear in the mOpeningApps set.
1602 enter = false;
1603 }
1604 if (DEBUG_APP_TRANSITIONS) Slog.d(TAG_WM, "Loading animation for app transition."
1605 + " transit=" + AppTransition.appTransitionToString(transit) + " enter=" + enter
1606 + " frame=" + frame + " insets=" + insets + " surfaceInsets=" + surfaceInsets);
1607 final Configuration displayConfig = displayContent.getConfiguration();
1608 final Animation a = mService.mAppTransition.loadAnimation(lp, transit, enter,
1609 displayConfig.uiMode, displayConfig.orientation, frame, displayFrame, insets,
1610 surfaceInsets, stableInsets, isVoiceInteraction, freeform, getTask().mTaskId);
1611 if (a != null) {
1612 if (DEBUG_ANIM) logWithStack(TAG, "Loaded animation " + a + " for " + this);
1613 final int containingWidth = frame.width();
1614 final int containingHeight = frame.height();
1615 a.initialize(containingWidth, containingHeight, width, height);
1616 a.scaleCurrentDuration(mService.getTransitionAnimationScaleLocked());
1617 }
1618 return a;
1619 }
1620
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001621 @Override
1622 protected void setLayer(Transaction t, int layer) {
1623 if (!mSurfaceAnimator.hasLeash()) {
1624 t.setLayer(mSurfaceControl, layer);
1625 }
1626 }
1627
1628 @Override
1629 protected void setRelativeLayer(Transaction t, SurfaceControl relativeTo, int layer) {
1630 if (!mSurfaceAnimator.hasLeash()) {
1631 t.setRelativeLayer(mSurfaceControl, relativeTo, layer);
1632 }
1633 }
1634
1635 @Override
1636 protected void reparentSurfaceControl(Transaction t, SurfaceControl newParent) {
1637 if (!mSurfaceAnimator.hasLeash()) {
1638 t.reparent(mSurfaceControl, newParent.getHandle());
1639 }
1640 }
1641
1642 @Override
1643 public void onAnimationLeashCreated(Transaction t, SurfaceControl leash) {
1644
1645 // The leash is parented to the animation layer. We need to preserve the z-order by using
1646 // the prefix order index, but we boost if necessary.
1647 int layer = getPrefixOrderIndex();
1648 if (mNeedsZBoost) {
1649 layer += Z_BOOST_BASE;
1650 }
1651 leash.setLayer(layer);
1652 }
1653
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001654 /**
1655 * This must be called while inside a transaction.
1656 */
1657 void showAllWindowsLocked() {
1658 forAllWindows(windowState -> {
1659 if (DEBUG_VISIBILITY) Slog.v(TAG, "performing show on: " + windowState);
1660 windowState.performShowLocked();
1661 }, false /* traverseTopToBottom */);
Jorim Jaggia5e10572017-11-15 14:36:26 +01001662 }
1663
1664 @Override
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001665 protected void onAnimationFinished() {
1666 super.onAnimationFinished();
1667
1668 mTransit = TRANSIT_UNSET;
1669 mTransitFlags = 0;
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001670 mNeedsZBoost = false;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001671
1672 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM | FINISH_LAYOUT_REDO_WALLPAPER,
1673 "AppWindowToken");
1674
Jorim Jaggi988f6682017-11-17 17:46:43 +01001675 clearThumbnail();
1676
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001677 if (mService.mInputMethodTarget != null && mService.mInputMethodTarget.mAppToken == this) {
1678 getDisplayContent().computeImeTarget(true /* updateImeTarget */);
1679 }
1680
1681 if (DEBUG_ANIM) Slog.v(TAG, "Animation done in " + this
1682 + ": reportedVisible=" + reportedVisible
1683 + " okToDisplay=" + okToDisplay()
1684 + " okToAnimate=" + okToAnimate()
1685 + " startingDisplayed=" + startingDisplayed);
1686
1687 // WindowState.onExitAnimationDone might modify the children list, so make a copy and then
1688 // traverse the copy.
1689 final ArrayList<WindowState> children = new ArrayList<>(mChildren);
1690 children.forEach(WindowState::onExitAnimationDone);
1691
1692 mService.mAppTransition.notifyAppTransitionFinishedLocked(token);
1693 scheduleAnimation();
1694 }
1695
1696 @Override
1697 boolean isAppAnimating() {
1698 return isSelfAnimating();
1699 }
1700
1701 @Override
1702 boolean isSelfAnimating() {
1703 // If we are about to start a transition, we also need to be considered animating.
1704 return isWaitingForTransitionStart() || isReallyAnimating();
1705 }
1706
1707 /**
1708 * @return True if and only if we are actually running an animation. Note that
1709 * {@link #isSelfAnimating} also returns true if we are waiting for an animation to
1710 * start.
1711 */
1712 private boolean isReallyAnimating() {
1713 return super.isSelfAnimating();
1714 }
1715
Jorim Jaggi988f6682017-11-17 17:46:43 +01001716 @Override
1717 void cancelAnimation() {
1718 super.cancelAnimation();
1719 clearThumbnail();
1720 }
1721
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001722 boolean isWaitingForTransitionStart() {
1723 return mService.mAppTransition.isTransitionSet()
1724 && (mService.mOpeningApps.contains(this) || mService.mClosingApps.contains(this));
1725 }
1726
1727 public int getTransit() {
1728 return mTransit;
1729 }
1730
1731 int getTransitFlags() {
1732 return mTransitFlags;
1733 }
1734
Jorim Jaggi988f6682017-11-17 17:46:43 +01001735 void attachThumbnailAnimation() {
1736 if (!isReallyAnimating()) {
1737 return;
1738 }
1739 final int taskId = getTask().mTaskId;
1740 final GraphicBuffer thumbnailHeader =
1741 mService.mAppTransition.getAppTransitionThumbnailHeader(taskId);
1742 if (thumbnailHeader == null) {
1743 if (DEBUG_APP_TRANSITIONS) Slog.d(TAG, "No thumbnail header bitmap for: " + taskId);
1744 return;
1745 }
1746 clearThumbnail();
1747 mThumbnail = new AppWindowThumbnail(getPendingTransaction(), this, thumbnailHeader);
1748 mThumbnail.startAnimation(getPendingTransaction(), loadThumbnailAnimation(thumbnailHeader));
1749 }
1750
1751 private Animation loadThumbnailAnimation(GraphicBuffer thumbnailHeader) {
1752 final DisplayInfo displayInfo = mDisplayContent.getDisplayInfo();
1753
1754 // If this is a multi-window scenario, we use the windows frame as
1755 // destination of the thumbnail header animation. If this is a full screen
1756 // window scenario, we use the whole display as the target.
1757 WindowState win = findMainWindow();
1758 Rect appRect = win != null ? win.getContentFrameLw() :
1759 new Rect(0, 0, displayInfo.appWidth, displayInfo.appHeight);
1760 Rect insets = win != null ? win.mContentInsets : null;
1761 final Configuration displayConfig = mDisplayContent.getConfiguration();
1762 return mService.mAppTransition.createThumbnailAspectScaleAnimationLocked(
1763 appRect, insets, thumbnailHeader, getTask().mTaskId, displayConfig.uiMode,
1764 displayConfig.orientation);
1765 }
1766
1767 private void clearThumbnail() {
1768 if (mThumbnail == null) {
1769 return;
1770 }
1771 mThumbnail.destroy();
1772 mThumbnail = null;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001773 }
1774
1775 @Override
1776 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
1777 super.dump(pw, prefix, dumpAll);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001778 if (appToken != null) {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001779 pw.println(prefix + "app=true mVoiceInteraction=" + mVoiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001780 }
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001781 pw.print(prefix); pw.print("task="); pw.println(getTask());
Wale Ogunwale51362492016-09-08 17:49:17 -07001782 pw.print(prefix); pw.print(" mFillsParent="); pw.print(mFillsParent);
1783 pw.print(" mOrientation="); pw.println(mOrientation);
Wale Ogunwale89973222017-04-23 18:39:45 -07001784 pw.println(prefix + "hiddenRequested=" + hiddenRequested + " mClientHidden=" + mClientHidden
1785 + ((mDeferHidingClient) ? " mDeferHidingClient=" + mDeferHidingClient : "")
1786 + " reportedDrawn=" + reportedDrawn + " reportedVisible=" + reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -07001787 if (paused) {
1788 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001789 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001790 if (mAppStopped) {
1791 pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped);
1792 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001793 if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001794 || allDrawn || mLastAllDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001795 pw.print(prefix); pw.print("mNumInterestingWindows=");
1796 pw.print(mNumInterestingWindows);
1797 pw.print(" mNumDrawnWindows="); pw.print(mNumDrawnWindows);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001798 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -07001799 pw.print(" allDrawn="); pw.print(allDrawn);
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001800 pw.print(" lastAllDrawn="); pw.print(mLastAllDrawn);
Craig Mautner6fbda632012-07-03 09:26:39 -07001801 pw.println(")");
1802 }
1803 if (inPendingTransaction) {
1804 pw.print(prefix); pw.print("inPendingTransaction=");
1805 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001806 }
Craig Mautner799bc1d2015-01-14 10:33:48 -08001807 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001808 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
1809 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -08001810 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -08001811 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001812 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001813 if (startingWindow != null || startingSurface != null
Wale Ogunwale6c459212017-05-17 08:56:03 -07001814 || startingDisplayed || startingMoved || mHiddenSetFromTransferredStartingWindow) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001815 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001816 pw.print(" startingSurface="); pw.print(startingSurface);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001817 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
Wale Ogunwale6c459212017-05-17 08:56:03 -07001818 pw.print(" startingMoved="); pw.print(startingMoved);
1819 pw.println(" mHiddenSetFromTransferredStartingWindow="
1820 + mHiddenSetFromTransferredStartingWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001821 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01001822 if (!mFrozenBounds.isEmpty()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -08001823 pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds);
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001824 pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig);
Chong Zhangd78ddb42016-03-02 17:01:14 -08001825 }
1826 if (mPendingRelaunchCount != 0) {
1827 pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount);
Jorim Jaggi0429f352015-12-22 16:29:16 +01001828 }
Wale Ogunwale9c64cb62017-04-12 13:39:59 -07001829 if (getController() != null) {
1830 pw.print(prefix); pw.print("controller="); pw.println(getController());
1831 }
Wale Ogunwalee287e192017-04-21 09:30:12 -07001832 if (mRemovingFromDisplay) {
1833 pw.println(prefix + "mRemovingFromDisplay=" + mRemovingFromDisplay);
1834 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001835 }
1836
1837 @Override
1838 void setHidden(boolean hidden) {
1839 super.setHidden(hidden);
1840 scheduleAnimation();
1841 }
1842
1843 @Override
1844 void prepareSurfaces() {
1845 // isSelfAnimating also returns true when we are about to start a transition, so we need
1846 // to check super here.
1847 final boolean reallyAnimating = super.isSelfAnimating();
1848 final boolean show = !isHidden() || reallyAnimating;
1849 if (show && !mLastSurfaceShowing) {
1850 mPendingTransaction.show(mSurfaceControl);
1851 } else if (!show && mLastSurfaceShowing) {
1852 mPendingTransaction.hide(mSurfaceControl);
Jorim Jaggi4d1835d2017-08-31 17:28:27 +02001853 }
Jorim Jaggi988f6682017-11-17 17:46:43 +01001854 if (mThumbnail != null) {
1855 mThumbnail.setShowing(mPendingTransaction, show);
1856 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001857 mLastSurfaceShowing = show;
1858 super.prepareSurfaces();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001859 }
1860
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001861 boolean isFreezingScreen() {
1862 return mFreezingScreen;
1863 }
1864
1865 @Override
1866 boolean needsZBoost() {
1867 return mNeedsZBoost || super.needsZBoost();
1868 }
1869
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07001870 @CallSuper
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001871 @Override
Adrian Roos4921ccf2017-09-28 16:54:06 +02001872 public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07001873 final long token = proto.start(fieldId);
1874 writeNameToProto(proto, NAME);
Adrian Roos4921ccf2017-09-28 16:54:06 +02001875 super.writeToProto(proto, WINDOW_TOKEN, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07001876 proto.end(token);
1877 }
1878
1879 void writeNameToProto(ProtoOutputStream proto, long fieldId) {
1880 if (appToken == null) {
1881 return;
1882 }
1883 try {
1884 proto.write(fieldId, appToken.getName());
1885 } catch (RemoteException e) {
1886 // This shouldn't happen, but in this case fall back to outputting nothing
1887 Slog.e(TAG, e.toString());
1888 }
1889 }
1890
1891 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001892 public String toString() {
1893 if (stringName == null) {
1894 StringBuilder sb = new StringBuilder();
1895 sb.append("AppWindowToken{");
1896 sb.append(Integer.toHexString(System.identityHashCode(this)));
1897 sb.append(" token="); sb.append(token); sb.append('}');
1898 stringName = sb.toString();
1899 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001900 return stringName + ((mIsExiting) ? " mIsExiting=" : "");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001901 }
Jeff Browne9bdb312012-04-05 15:30:10 -07001902}