blob: af7523c59f9cb158135bad116af9a292c372a310 [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();
225
Wale Ogunwale72919d22016-12-08 18:58:50 -0800226 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
227 DisplayContent dc, long inputDispatchingTimeoutNanos, boolean fullscreen,
228 boolean showForAllUsers, int targetSdk, int orientation, int rotationAnimationHint,
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800229 int configChanges, boolean launchTaskBehind, boolean alwaysFocusable,
Bryce Leef3c6a472017-11-14 14:53:06 -0800230 AppWindowContainerController controller) {
231 this(service, token, voiceInteraction, dc, fullscreen);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800232 setController(controller);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800233 mInputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800234 mShowForAllUsers = showForAllUsers;
235 mTargetSdk = targetSdk;
236 mOrientation = orientation;
237 layoutConfigChanges = (configChanges & (CONFIG_SCREEN_SIZE | CONFIG_ORIENTATION)) != 0;
238 mLaunchTaskBehind = launchTaskBehind;
239 mAlwaysFocusable = alwaysFocusable;
240 mRotationAnimationHint = rotationAnimationHint;
241
242 // Application tokens start out hidden.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200243 setHidden(true);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800244 hiddenRequested = true;
245 }
246
247 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
Bryce Leef3c6a472017-11-14 14:53:06 -0800248 DisplayContent dc, boolean fillsParent) {
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800249 super(service, token != null ? token.asBinder() : null, TYPE_APPLICATION, true, dc,
250 false /* ownerCanManageAppTokens */);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700251 appToken = token;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800252 mVoiceInteraction = voiceInteraction;
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800253 mFillsParent = fillsParent;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800254 mInputApplicationHandle = new InputApplicationHandle(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800255 }
256
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800257 void onFirstWindowDrawn(WindowState win, WindowStateAnimator winAnimator) {
258 firstWindowDrawn = true;
259
260 // We now have a good window to show, remove dead placeholders
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700261 removeDeadWindows();
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800262
Jorim Jaggi02886a82016-12-06 09:10:06 -0800263 if (startingWindow != null) {
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800264 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, "Finish starting "
265 + win.mToken + ": first real window is shown, no animation");
266 // If this initial window is animating, stop it -- we will do an animation to reveal
267 // it from behind the starting window, so there is no need for it to also be doing its
268 // own stuff.
Jorim Jaggia5e10572017-11-15 14:36:26 +0100269 win.cancelAnimation();
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800270 if (getController() != null) {
271 getController().removeStartingWindow();
272 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800273 }
274 updateReportedVisibilityLocked();
275 }
276
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800277 void updateReportedVisibilityLocked() {
278 if (appToken == null) {
279 return;
280 }
281
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700282 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700283 final int count = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800284
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700285 mReportedVisibilityResults.reset();
286
287 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700288 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700289 win.updateReportedVisibility(mReportedVisibilityResults);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800290 }
291
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700292 int numInteresting = mReportedVisibilityResults.numInteresting;
293 int numVisible = mReportedVisibilityResults.numVisible;
294 int numDrawn = mReportedVisibilityResults.numDrawn;
295 boolean nowGone = mReportedVisibilityResults.nowGone;
296
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700297 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200298 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting && !isHidden();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700299 if (!nowGone) {
300 // If the app is not yet gone, then it can only become visible/drawn.
301 if (!nowDrawn) {
302 nowDrawn = reportedDrawn;
303 }
304 if (!nowVisible) {
305 nowVisible = reportedVisible;
306 }
307 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800308 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800309 + numInteresting + " visible=" + numVisible);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800310 final AppWindowContainerController controller = getController();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700311 if (nowDrawn != reportedDrawn) {
312 if (nowDrawn) {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800313 if (controller != null) {
314 controller.reportWindowsDrawn();
315 }
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700316 }
317 reportedDrawn = nowDrawn;
318 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800319 if (nowVisible != reportedVisible) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700320 if (DEBUG_VISIBILITY) Slog.v(TAG,
321 "Visibility changed in " + this + ": vis=" + nowVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800322 reportedVisible = nowVisible;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800323 if (controller != null) {
324 if (nowVisible) {
325 controller.reportWindowsVisible();
326 } else {
327 controller.reportWindowsGone();
328 }
329 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800330 }
331 }
332
Wale Ogunwale89973222017-04-23 18:39:45 -0700333 boolean isClientHidden() {
334 return mClientHidden;
335 }
336
337 void setClientHidden(boolean hideClient) {
338 if (mClientHidden == hideClient || (hideClient && mDeferHidingClient)) {
339 return;
340 }
341 mClientHidden = hideClient;
342 sendAppVisibilityToClients();
343 }
344
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700345 boolean setVisibility(WindowManager.LayoutParams lp,
346 boolean visible, int transit, boolean performLayout, boolean isVoiceInteraction) {
347
348 boolean delayed = false;
349 inPendingTransaction = false;
Wale Ogunwale9e4721f2017-05-23 19:37:30 -0700350 // Reset the state of mHiddenSetFromTransferredStartingWindow since visibility is actually
351 // been set by the app now.
352 mHiddenSetFromTransferredStartingWindow = false;
Wale Ogunwale89973222017-04-23 18:39:45 -0700353 setClientHidden(!visible);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700354
355 // Allow for state changes and animation to be applied if:
356 // * token is transitioning visibility state
357 // * or the token was marked as hidden and is exiting before we had a chance to play the
358 // transition animation
359 // * or this is an opening app and windows are being replaced.
360 boolean visibilityChanged = false;
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200361 if (isHidden() == visible || (isHidden() && mIsExiting) || (visible && waitingForReplacement())) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700362 final AccessibilityController accessibilityController = mService.mAccessibilityController;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700363 boolean changed = false;
364 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200365 "Changing app " + this + " hidden=" + isHidden() + " performLayout=" + performLayout);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700366
367 boolean runningAppAnimation = false;
368
369 if (transit != AppTransition.TRANSIT_UNSET) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200370 if (applyAnimationLocked(lp, transit, visible, isVoiceInteraction)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700371 delayed = runningAppAnimation = true;
372 }
373 final WindowState window = findMainWindow();
374 //TODO (multidisplay): Magnification is supported only for the default display.
375 if (window != null && accessibilityController != null
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700376 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700377 accessibilityController.onAppWindowTransitionLocked(window, transit);
378 }
379 changed = true;
380 }
381
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700382 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700383 for (int i = 0; i < windowsCount; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700384 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700385 changed |= win.onAppVisibilityChanged(visible, runningAppAnimation);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700386 }
387
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200388 setHidden(!visible);
389 hiddenRequested = !visible;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700390 visibilityChanged = true;
391 if (!visible) {
392 stopFreezingScreen(true, true);
393 } else {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700394 // If we are being set visible, and the starting window is not yet displayed,
395 // then make sure it doesn't get displayed.
396 if (startingWindow != null && !startingWindow.isDrawnLw()) {
397 startingWindow.mPolicyVisibility = false;
398 startingWindow.mPolicyVisibilityAfterAnim = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700399 }
Jorim Jaggi38d44ec2017-06-14 16:04:59 -0700400
401 // We are becoming visible, so better freeze the screen with the windows that are
402 // getting visible so we also wait for them.
403 forAllWindows(mService::makeWindowFreezingScreenIfNeededLocked, true);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700404 }
405
406 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setVisibility: " + this
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200407 + ": hidden=" + isHidden() + " hiddenRequested=" + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700408
409 if (changed) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700410 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700411 if (performLayout) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700412 mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700413 false /*updateInputWindows*/);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700414 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700415 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700416 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700417 }
418 }
419
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200420 if (isReallyAnimating()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700421 delayed = true;
422 }
423
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700424 for (int i = mChildren.size() - 1; i >= 0 && !delayed; i--) {
Jorim Jaggia5e10572017-11-15 14:36:26 +0100425 if ((mChildren.get(i)).isSelfOrChildAnimating()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700426 delayed = true;
427 }
428 }
429
430 if (visibilityChanged) {
431 if (visible && !delayed) {
432 // The token was made immediately visible, there will be no entrance animation.
433 // We need to inform the client the enter animation was finished.
434 mEnteringAnimation = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700435 mService.mActivityManagerAppTransitionNotifier.onAppTransitionFinishedLocked(token);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700436 }
Robert Carr61b81112017-07-17 18:08:15 -0700437
Robert Carre7cc44d2017-03-20 19:04:30 -0700438 // If we are hidden but there is no delay needed we immediately
439 // apply the Surface transaction so that the ActivityManager
Robert Carr61b81112017-07-17 18:08:15 -0700440 // can have some guarantee on the Surface state following
441 // setting the visibility. This captures cases like dismissing
442 // the docked or pinned stack where there is no app transition.
443 //
444 // In the case of a "Null" animation, there will be
445 // no animation but there will still be a transition set.
446 // We still need to delay hiding the surface such that it
447 // can be synchronized with showing the next surface in the transition.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200448 if (isHidden() && !delayed && !mService.mAppTransition.isTransitionSet()) {
Robert Carr6914f082017-03-20 19:04:30 -0700449 SurfaceControl.openTransaction();
450 for (int i = mChildren.size() - 1; i >= 0; i--) {
451 mChildren.get(i).mWinAnimator.hide("immediately hidden");
452 }
453 SurfaceControl.closeTransaction();
454 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700455
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700456 if (!mService.mClosingApps.contains(this) && !mService.mOpeningApps.contains(this)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700457 // The token is not closing nor opening, so even if there is an animation set, that
458 // doesn't mean that it goes through the normal app transition cycle so we have
459 // to inform the docked controller about visibility change.
Andrii Kulian1e32e022016-09-16 15:29:34 -0700460 // TODO(multi-display): notify docked divider on all displays where visibility was
461 // affected.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700462 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700463 .notifyAppVisibilityChanged();
Jorim Jaggi8b702ed2017-01-20 16:59:03 +0100464 mService.mTaskSnapshotController.notifyAppVisibilityChanged(this, visible);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700465 }
466 }
467
468 return delayed;
469 }
470
Jorim Jaggi87fdbcb2017-08-17 13:41:11 +0200471 /**
472 * @return The to top most child window for which {@link LayoutParams#isFullscreen()} returns
473 * true.
474 */
475 WindowState getTopFullscreenWindow() {
476 for (int i = mChildren.size() - 1; i >= 0; i--) {
477 final WindowState win = mChildren.get(i);
478 if (win != null && win.mAttrs.isFullscreen()) {
479 return win;
480 }
481 }
482 return null;
483 }
484
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800485 WindowState findMainWindow() {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700486 WindowState candidate = null;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700487 int j = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800488 while (j > 0) {
489 j--;
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700490 final WindowState win = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700491 final int type = win.mAttrs.type;
492 // No need to loop through child window as base application and starting types can't be
493 // child windows.
494 if (type == TYPE_BASE_APPLICATION || type == TYPE_APPLICATION_STARTING) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700495 // In cases where there are multiple windows, we prefer the non-exiting window. This
Sungsoo Lim0d3d1f82015-12-02 14:47:59 +0900496 // happens for example when replacing windows during an activity relaunch. When
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700497 // constructing the animation, we want the new window, not the exiting one.
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800498 if (win.mAnimatingExit) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700499 candidate = win;
500 } else {
501 return win;
502 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800503 }
504 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700505 return candidate;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800506 }
507
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800508 boolean windowsAreFocusable() {
Wale Ogunwale3382ab12017-07-27 08:55:03 -0700509 return getWindowConfiguration().canReceiveKeys() || mAlwaysFocusable;
Wale Ogunwaled045c822015-12-02 09:14:28 -0800510 }
511
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800512 AppWindowContainerController getController() {
513 final WindowContainerController controller = super.getController();
514 return controller != null ? (AppWindowContainerController) controller : null;
515 }
516
Wale Ogunwale571771c2016-08-26 13:18:50 -0700517 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -0700518 boolean isVisible() {
Wale Ogunwalee471be62016-10-03 07:53:55 -0700519 // If the app token isn't hidden then it is considered visible and there is no need to check
520 // its children windows to see if they are visible.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200521 return !isHidden();
Wale Ogunwale44f21802016-09-02 12:49:48 -0700522 }
523
524 @Override
Wale Ogunwalee287e192017-04-21 09:30:12 -0700525 void removeImmediately() {
526 onRemovedFromDisplay();
527 super.removeImmediately();
528 }
529
530 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -0700531 void removeIfPossible() {
Craig Mautnere3119b72015-01-20 15:02:36 -0800532 mIsExiting = false;
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800533 removeAllWindowsIfPossible();
Bryce Lee6d410262017-02-28 15:30:17 -0800534 removeImmediately();
Craig Mautnere3119b72015-01-20 15:02:36 -0800535 }
536
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700537 @Override
538 boolean checkCompleteDeferredRemoval() {
539 if (mIsExiting) {
540 removeIfPossible();
541 }
542 return super.checkCompleteDeferredRemoval();
543 }
544
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700545 void onRemovedFromDisplay() {
Wale Ogunwalee287e192017-04-21 09:30:12 -0700546 if (mRemovingFromDisplay) {
547 return;
548 }
549 mRemovingFromDisplay = true;
550
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700551 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app token: " + this);
552
Wale Ogunwale72919d22016-12-08 18:58:50 -0800553 boolean delayed = setVisibility(null, false, TRANSIT_UNSET, true, mVoiceInteraction);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700554
555 mService.mOpeningApps.remove(this);
Jorim Jaggi45ca0542017-05-30 16:16:01 -0700556 mService.mUnknownAppVisibilityController.appRemovedOrHidden(this);
Jorim Jaggi10abe2f2017-01-03 16:44:46 +0100557 mService.mTaskSnapshotController.onAppRemoved(this);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700558 waitingToShow = false;
559 if (mService.mClosingApps.contains(this)) {
560 delayed = true;
561 } else if (mService.mAppTransition.isTransitionSet()) {
562 mService.mClosingApps.add(this);
563 delayed = true;
564 }
565
566 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app " + this + " delayed=" + delayed
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200567 + " animation=" + getAnimation() + " animating=" + isSelfAnimating());
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700568
569 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM, "removeAppToken: "
570 + this + " delayed=" + delayed + " Callers=" + Debug.getCallers(4));
571
Jorim Jaggi19be6052017-08-03 18:33:43 +0200572 if (startingData != null && getController() != null) {
573 getController().removeStartingWindow();
574 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800575
Winson Chung87e5d552017-04-05 11:49:38 -0700576 // If this window was animating, then we need to ensure that the app transition notifies
577 // that animations have completed in WMS.handleAnimatingStoppedAndTransitionLocked(), so
578 // add to that list now
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200579 if (isSelfAnimating()) {
Winson Chung87e5d552017-04-05 11:49:38 -0700580 mService.mNoAnimationNotifyOnTransitionFinished.add(token);
581 }
582
Wale Ogunwalee287e192017-04-21 09:30:12 -0700583 final TaskStack stack = getStack();
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700584 if (delayed && !isEmpty()) {
585 // set the token aside because it has an active animation to be finished
586 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM,
587 "removeAppToken make exiting: " + this);
Wale Ogunwalee287e192017-04-21 09:30:12 -0700588 if (stack != null) {
589 stack.mExitingAppTokens.add(this);
590 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700591 mIsExiting = true;
592 } else {
593 // Make sure there is no animation running on this token, so any windows associated
594 // with it will be removed as soon as their animations are complete
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200595 cancelAnimation();
Wale Ogunwale3106ae012017-05-16 08:56:37 -0700596 if (stack != null) {
597 stack.mExitingAppTokens.remove(this);
598 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700599 removeIfPossible();
600 }
601
602 removed = true;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700603 stopFreezingScreen(true, true);
Bryce Lee6d410262017-02-28 15:30:17 -0800604
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700605 if (mService.mFocusedApp == this) {
606 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "Removing focused app token:" + this);
607 mService.mFocusedApp = null;
608 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
609 mService.mInputMonitor.setFocusedAppLw(null);
610 }
611
612 if (!delayed) {
613 updateReportedVisibilityLocked();
614 }
Wale Ogunwalee287e192017-04-21 09:30:12 -0700615
616 mRemovingFromDisplay = false;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700617 }
618
Chong Zhange05bcb12016-07-26 17:47:29 -0700619 void clearAnimatingFlags() {
Chong Zhangb0d26702016-08-12 16:03:29 -0700620 boolean wallpaperMightChange = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700621 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700622 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700623 wallpaperMightChange |= win.clearAnimatingFlags();
Chong Zhange05bcb12016-07-26 17:47:29 -0700624 }
Chong Zhangb0d26702016-08-12 16:03:29 -0700625 if (wallpaperMightChange) {
626 requestUpdateWallpaperIfNeeded();
627 }
Chong Zhange05bcb12016-07-26 17:47:29 -0700628 }
629
Robert Carre12aece2016-02-02 22:43:27 -0800630 void destroySurfaces() {
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700631 destroySurfaces(false /*cleanupOnResume*/);
632 }
633
634 /**
635 * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure
636 * the client has finished with them.
637 *
638 * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If
639 * set to true, destroy only surfaces of removed windows, and clear relevant flags of the
640 * others so that they are ready to be reused. If set to false (common case), destroy all
641 * surfaces that's eligible, if the app is already stopped.
642 */
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700643 private void destroySurfaces(boolean cleanupOnResume) {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700644 boolean destroyedSomething = false;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100645
646 // Copying to a different list as multiple children can be removed.
647 // TODO: Not sure why this is needed.
648 final LinkedList<WindowState> children = new LinkedList<>(mChildren);
649 for (int i = children.size() - 1; i >= 0; i--) {
650 final WindowState win = children.get(i);
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700651 destroyedSomething |= win.destroySurface(cleanupOnResume, mAppStopped);
Robert Carre12aece2016-02-02 22:43:27 -0800652 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700653 if (destroyedSomething) {
654 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700655 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Robert Carre12aece2016-02-02 22:43:27 -0800656 }
657 }
658
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800659 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700660 * Notify that the app is now resumed, and it was not stopped before, perform a clean
661 * up of the surfaces
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800662 */
Jorim Jaggibae01b12017-04-11 16:29:10 -0700663 void notifyAppResumed(boolean wasStopped) {
Chong Zhangad24f962016-08-25 12:12:33 -0700664 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped
Jorim Jaggibae01b12017-04-11 16:29:10 -0700665 + " " + this);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700666 mAppStopped = false;
chaviwd3bf08d2017-08-01 17:24:59 -0700667 // Allow the window to turn the screen on once the app is resumed again.
668 setCanTurnScreenOn(true);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700669 if (!wasStopped) {
670 destroySurfaces(true /*cleanupOnResume*/);
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800671 }
Robert Carre12aece2016-02-02 22:43:27 -0800672 }
673
Chong Zhangbef461f2015-10-27 11:38:24 -0700674 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700675 * Notify that the app has stopped, and it is okay to destroy any surfaces which were
676 * keeping alive in case they were still being used.
677 */
678 void notifyAppStopped() {
679 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this);
680 mAppStopped = true;
681 destroySurfaces();
682 // Remove any starting window that was added for this app if they are still around.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800683 if (getController() != null) {
684 getController().removeStartingWindow();
685 }
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700686 }
687
Chong Zhang92147042016-05-09 12:47:11 -0700688 void clearAllDrawn() {
689 allDrawn = false;
690 deferClearAllDrawn = false;
Chong Zhangbef461f2015-10-27 11:38:24 -0700691 }
692
Bryce Lee6d410262017-02-28 15:30:17 -0800693 Task getTask() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800694 return (Task) getParent();
Bryce Lee6d410262017-02-28 15:30:17 -0800695 }
696
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800697 TaskStack getStack() {
698 final Task task = getTask();
699 if (task != null) {
700 return task.mStack;
701 } else {
702 return null;
703 }
704 }
705
Bryce Lee6d410262017-02-28 15:30:17 -0800706 @Override
707 void onParentSet() {
708 super.onParentSet();
709
Robert Carred3e83b2017-04-21 13:26:55 -0700710 final Task task = getTask();
711
Bryce Lee6d410262017-02-28 15:30:17 -0800712 // When the associated task is {@code null}, the {@link AppWindowToken} can no longer
713 // access visual elements like the {@link DisplayContent}. We must remove any associations
714 // such as animations.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800715 if (!mReparenting) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800716 if (task == null) {
717 // It is possible we have been marked as a closing app earlier. We must remove ourselves
718 // from this list so we do not participate in any future animations.
719 mService.mClosingApps.remove(this);
Robert Carred3e83b2017-04-21 13:26:55 -0700720 } else if (mLastParent != null && mLastParent.mStack != null) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800721 task.mStack.mExitingAppTokens.remove(this);
722 }
Bryce Lee6d410262017-02-28 15:30:17 -0800723 }
Robert Carred3e83b2017-04-21 13:26:55 -0700724 mLastParent = task;
Bryce Lee6d410262017-02-28 15:30:17 -0800725 }
726
Wale Ogunwalefa854eb2016-09-20 13:43:52 -0700727 void postWindowRemoveStartingWindowCleanup(WindowState win) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700728 // TODO: Something smells about the code below...Is there a better way?
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700729 if (startingWindow == win) {
730 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800731 if (getController() != null) {
732 getController().removeStartingWindow();
733 }
Wale Ogunwale6c459212017-05-17 08:56:03 -0700734 } else if (mChildren.size() == 0) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700735 // If this is the last window and we had requested a starting transition window,
736 // well there is no point now.
Jorim Jaggi02886a82016-12-06 09:10:06 -0800737 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingData");
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700738 startingData = null;
Wale Ogunwale6c459212017-05-17 08:56:03 -0700739 if (mHiddenSetFromTransferredStartingWindow) {
740 // We set the hidden state to false for the token from a transferred starting window.
741 // We now reset it back to true since the starting window was the last window in the
742 // token.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200743 setHidden(true);
Wale Ogunwale6c459212017-05-17 08:56:03 -0700744 }
Jorim Jaggi829b9cd2017-01-23 16:20:53 +0100745 } else if (mChildren.size() == 1 && startingSurface != null && !isRelaunching()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700746 // If this is the last window except for a starting transition window,
747 // we need to get rid of the starting transition.
Jorim Jaggie4b0f282017-05-17 15:10:29 +0200748 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Last window, removing starting window "
749 + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800750 if (getController() != null) {
751 getController().removeStartingWindow();
752 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700753 }
754 }
755
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700756 void removeDeadWindows() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700757 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700758 WindowState win = mChildren.get(winNdx);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800759 if (win.mAppDied) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700760 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700761 "removeDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800762 // Set mDestroying, we don't want any animation or delayed removal here.
763 win.mDestroying = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700764 // Also removes child windows.
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700765 win.removeIfPossible();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800766 }
767 }
768 }
769
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700770 boolean hasWindowsAlive() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700771 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700772 // No need to loop through child windows as the answer should be the same as that of the
773 // parent window.
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700774 if (!(mChildren.get(i)).mAppDied) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700775 return true;
776 }
777 }
778 return false;
779 }
780
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700781 void setWillReplaceWindows(boolean animate) {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700782 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
783 "Marking app token " + this + " with replacing windows.");
Robert Carra1eb4392015-12-10 12:43:51 -0800784
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700785 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700786 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700787 w.setWillReplaceWindow(animate);
Robert Carra1eb4392015-12-10 12:43:51 -0800788 }
Robert Carra1eb4392015-12-10 12:43:51 -0800789 }
790
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700791 void setWillReplaceChildWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700792 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this
Robert Carr23fa16b2016-01-13 13:19:58 -0800793 + " with replacing child windows.");
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700794 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700795 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700796 w.setWillReplaceChildWindows();
Robert Carr23fa16b2016-01-13 13:19:58 -0800797 }
798 }
799
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700800 void clearWillReplaceWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700801 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
802 "Resetting app token " + this + " of replacing window marks.");
Chong Zhangf596cd52016-01-05 13:42:44 -0800803
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700804 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700805 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700806 w.clearWillReplaceWindow();
Chong Zhangf596cd52016-01-05 13:42:44 -0800807 }
808 }
809
Chong Zhang4d7369a2016-04-25 16:09:14 -0700810 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700811 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700812 final WindowState w = mChildren.get(i);
Chong Zhang4d7369a2016-04-25 16:09:14 -0700813 w.requestUpdateWallpaperIfNeeded();
814 }
815 }
816
Chong Zhangd78ddb42016-03-02 17:01:14 -0800817 boolean isRelaunching() {
818 return mPendingRelaunchCount > 0;
819 }
820
Robert Carr68375192017-06-13 12:41:53 -0700821 boolean shouldFreezeBounds() {
822 final Task task = getTask();
823
824 // For freeform windows, we can't freeze the bounds at the moment because this would make
825 // the resizing unresponsive.
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700826 if (task == null || task.inFreeformWindowingMode()) {
Robert Carr68375192017-06-13 12:41:53 -0700827 return false;
828 }
829
830 // We freeze the bounds while drag resizing to deal with the time between
831 // the divider/drag handle being released, and the handling it's new
832 // configuration. If we are relaunched outside of the drag resizing state,
833 // we need to be careful not to do this.
834 return getTask().isDragResizing();
835 }
836
Chong Zhangd78ddb42016-03-02 17:01:14 -0800837 void startRelaunching() {
Robert Carr68375192017-06-13 12:41:53 -0700838 if (shouldFreezeBounds()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -0800839 freezeBounds();
840 }
Robert Carrd5c7dd62017-03-08 10:39:30 -0800841
842 // In the process of tearing down before relaunching, the app will
843 // try and clean up it's child surfaces. We need to prevent this from
844 // happening, so we sever the children, transfering their ownership
845 // from the client it-self to the parent surface (owned by us).
846 for (int i = mChildren.size() - 1; i >= 0; i--) {
847 final WindowState w = mChildren.get(i);
848 w.mWinAnimator.detachChildren();
849 }
850
Chong Zhangd78ddb42016-03-02 17:01:14 -0800851 mPendingRelaunchCount++;
852 }
853
854 void finishRelaunching() {
Robert Carr68375192017-06-13 12:41:53 -0700855 unfreezeBounds();
856
Chong Zhangd78ddb42016-03-02 17:01:14 -0800857 if (mPendingRelaunchCount > 0) {
858 mPendingRelaunchCount--;
Bryce Lee081554b2017-05-25 07:52:12 -0700859 } else {
860 // Update keyguard flags upon finishing relaunch.
861 checkKeyguardFlagsChanged();
Chong Zhangd78ddb42016-03-02 17:01:14 -0800862 }
863 }
864
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700865 void clearRelaunching() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700866 if (mPendingRelaunchCount == 0) {
867 return;
868 }
Robert Carr68375192017-06-13 12:41:53 -0700869 unfreezeBounds();
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700870 mPendingRelaunchCount = 0;
871 }
872
Wale Ogunwale07bcab72016-10-14 15:30:09 -0700873 /**
874 * Returns true if the new child window we are adding to this token is considered greater than
875 * the existing child window in this token in terms of z-order.
876 */
877 @Override
878 protected boolean isFirstChildWindowGreaterThanSecond(WindowState newWindow,
879 WindowState existingWindow) {
880 final int type1 = newWindow.mAttrs.type;
881 final int type2 = existingWindow.mAttrs.type;
882
883 // Base application windows should be z-ordered BELOW all other windows in the app token.
884 if (type1 == TYPE_BASE_APPLICATION && type2 != TYPE_BASE_APPLICATION) {
885 return false;
886 } else if (type1 != TYPE_BASE_APPLICATION && type2 == TYPE_BASE_APPLICATION) {
887 return true;
888 }
889
890 // Starting windows should be z-ordered ABOVE all other windows in the app token.
891 if (type1 == TYPE_APPLICATION_STARTING && type2 != TYPE_APPLICATION_STARTING) {
892 return true;
893 } else if (type1 != TYPE_APPLICATION_STARTING && type2 == TYPE_APPLICATION_STARTING) {
894 return false;
895 }
896
897 // Otherwise the new window is greater than the existing window.
898 return true;
899 }
900
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700901 @Override
Robert Carra1eb4392015-12-10 12:43:51 -0800902 void addWindow(WindowState w) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700903 super.addWindow(w);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700904
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700905 boolean gotReplacementWindow = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700906 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700907 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700908 gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w);
909 }
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700910
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700911 // if we got a replacement window, reset the timeout to give drawing more time
912 if (gotReplacementWindow) {
913 mService.scheduleWindowReplacementTimeouts(this);
Robert Carra1eb4392015-12-10 12:43:51 -0800914 }
Jorim Jaggife762342016-10-13 14:33:27 +0200915 checkKeyguardFlagsChanged();
916 }
917
918 @Override
919 void removeChild(WindowState child) {
920 super.removeChild(child);
921 checkKeyguardFlagsChanged();
Robert Carra1eb4392015-12-10 12:43:51 -0800922 }
923
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700924 private boolean waitingForReplacement() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700925 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700926 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700927 if (candidate.waitingForReplacement()) {
Robert Carra1eb4392015-12-10 12:43:51 -0800928 return true;
929 }
930 }
931 return false;
932 }
933
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700934 void onWindowReplacementTimeout() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700935 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700936 (mChildren.get(i)).onWindowReplacementTimeout();
Robert Carra1eb4392015-12-10 12:43:51 -0800937 }
938 }
939
Winson Chung30480042017-01-26 10:55:34 -0800940 void reparent(Task task, int position) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800941 final Task currentTask = getTask();
942 if (task == currentTask) {
Winson Chung30480042017-01-26 10:55:34 -0800943 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800944 "window token=" + this + " already child of task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -0800945 }
Bryce Lee6d410262017-02-28 15:30:17 -0800946
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800947 if (currentTask.mStack != task.mStack) {
Bryce Lee6d410262017-02-28 15:30:17 -0800948 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800949 "window token=" + this + " current task=" + currentTask
Bryce Lee6d410262017-02-28 15:30:17 -0800950 + " belongs to a different stack than " + task);
951 }
952
Winson Chung30480042017-01-26 10:55:34 -0800953 if (DEBUG_ADD_REMOVE) Slog.i(TAG, "reParentWindowToken: removing window token=" + this
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800954 + " from task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -0800955 final DisplayContent prevDisplayContent = getDisplayContent();
956
Bryce Lee6d410262017-02-28 15:30:17 -0800957 mReparenting = true;
958
Winson Chung30480042017-01-26 10:55:34 -0800959 getParent().removeChild(this);
960 task.addChild(this, position);
961
Bryce Lee6d410262017-02-28 15:30:17 -0800962 mReparenting = false;
963
Winson Chung30480042017-01-26 10:55:34 -0800964 // Relayout display(s).
965 final DisplayContent displayContent = task.getDisplayContent();
966 displayContent.setLayoutNeeded();
967 if (prevDisplayContent != displayContent) {
968 onDisplayChanged(displayContent);
969 prevDisplayContent.setLayoutNeeded();
970 }
971 }
972
Jorim Jaggi0429f352015-12-22 16:29:16 +0100973 /**
974 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
975 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
976 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
977 * with a queue.
978 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800979 private void freezeBounds() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800980 final Task task = getTask();
981 mFrozenBounds.offer(new Rect(task.mPreparedFrozenBounds));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700982
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800983 if (task.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) {
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700984 // We didn't call prepareFreezingBounds on the task, so use the current value.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800985 mFrozenMergedConfig.offer(new Configuration(task.getConfiguration()));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700986 } else {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800987 mFrozenMergedConfig.offer(new Configuration(task.mPreparedFrozenMergedConfig));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700988 }
Andrii Kulianb10330d2016-09-16 13:51:46 -0700989 // Calling unset() to make it equal to Configuration.EMPTY.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800990 task.mPreparedFrozenMergedConfig.unset();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100991 }
992
993 /**
994 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
995 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800996 private void unfreezeBounds() {
Robert Carr68375192017-06-13 12:41:53 -0700997 if (mFrozenBounds.isEmpty()) {
998 return;
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700999 }
Robert Carr68375192017-06-13 12:41:53 -07001000 mFrozenBounds.remove();
Wale Ogunwale37dbafc2016-06-27 10:15:20 -07001001 if (!mFrozenMergedConfig.isEmpty()) {
1002 mFrozenMergedConfig.remove();
1003 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001004 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001005 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001006 win.onUnfreezeBounds();
Jorim Jaggi4846ee32016-01-07 17:39:12 +01001007 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001008 mService.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +01001009 }
1010
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001011 void setAppLayoutChanges(int changes, String reason) {
1012 if (!mChildren.isEmpty()) {
1013 final DisplayContent dc = getDisplayContent();
1014 dc.pendingLayoutChanges |= changes;
1015 if (DEBUG_LAYOUT_REPEATS) {
1016 mService.mWindowPlacerLocked.debugLayoutRepeats(reason, dc.pendingLayoutChanges);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001017 }
1018 }
1019 }
1020
1021 void removeReplacedWindowIfNeeded(WindowState replacement) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001022 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001023 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001024 if (win.removeReplacedWindowIfNeeded(replacement)) {
1025 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001026 }
1027 }
1028 }
1029
1030 void startFreezingScreen() {
1031 if (DEBUG_ORIENTATION) logWithStack(TAG, "Set freezing of " + appToken + ": hidden="
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001032 + isHidden() + " freezing=" + mFreezingScreen + " hiddenRequested="
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001033 + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001034 if (!hiddenRequested) {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001035 if (!mFreezingScreen) {
1036 mFreezingScreen = true;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001037 mService.registerAppFreezeListener(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001038 mService.mAppsFreezingScreen++;
1039 if (mService.mAppsFreezingScreen == 1) {
Bryce Lee8f853582017-06-05 17:25:59 -07001040 mService.startFreezingDisplayLocked(false, 0, 0, getDisplayContent());
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001041 mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT);
1042 mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001043 }
1044 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001045 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001046 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001047 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001048 w.onStartFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001049 }
1050 }
1051 }
1052
1053 void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001054 if (!mFreezingScreen) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001055 return;
1056 }
1057 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + this + " force=" + force);
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001058 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001059 boolean unfrozeWindows = false;
1060 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001061 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001062 unfrozeWindows |= w.onStopFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001063 }
1064 if (force || unfrozeWindows) {
1065 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this);
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001066 mFreezingScreen = false;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001067 mService.unregisterAppFreezeListener(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001068 mService.mAppsFreezingScreen--;
1069 mService.mLastFinishedFreezeSource = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001070 }
1071 if (unfreezeSurfaceNow) {
1072 if (unfrozeWindows) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001073 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001074 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001075 mService.stopFreezingDisplayLocked();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001076 }
1077 }
1078
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001079 @Override
1080 public void onAppFreezeTimeout() {
1081 Slog.w(TAG_WM, "Force clearing freeze: " + this);
1082 stopFreezingScreen(true, true);
1083 }
1084
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001085 boolean transferStartingWindow(IBinder transferFrom) {
Wale Ogunwale02319a62016-09-26 15:21:22 -07001086 final AppWindowToken fromToken = getDisplayContent().getAppWindowToken(transferFrom);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001087 if (fromToken == null) {
1088 return false;
1089 }
1090
1091 final WindowState tStartingWindow = fromToken.startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001092 if (tStartingWindow != null && fromToken.startingSurface != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001093 // In this case, the starting icon has already been displayed, so start
1094 // letting windows get shown immediately without any more transitions.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001095 mService.mSkipAppTransitionAnimation = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001096
1097 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow
1098 + " from " + fromToken + " to " + this);
1099
1100 final long origId = Binder.clearCallingIdentity();
Peter Visontay3556a3b2017-11-01 17:23:17 +00001101 try {
1102 // Transfer the starting window over to the new token.
1103 startingData = fromToken.startingData;
1104 startingSurface = fromToken.startingSurface;
1105 startingDisplayed = fromToken.startingDisplayed;
1106 fromToken.startingDisplayed = false;
1107 startingWindow = tStartingWindow;
1108 reportedVisible = fromToken.reportedVisible;
1109 fromToken.startingData = null;
1110 fromToken.startingSurface = null;
1111 fromToken.startingWindow = null;
1112 fromToken.startingMoved = true;
1113 tStartingWindow.mToken = this;
1114 tStartingWindow.mAppToken = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001115
Peter Visontay3556a3b2017-11-01 17:23:17 +00001116 if (DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1117 "Removing starting " + tStartingWindow + " from " + fromToken);
1118 fromToken.removeChild(tStartingWindow);
1119 fromToken.postWindowRemoveStartingWindowCleanup(tStartingWindow);
1120 fromToken.mHiddenSetFromTransferredStartingWindow = false;
1121 addWindow(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001122
Peter Visontay3556a3b2017-11-01 17:23:17 +00001123 // Propagate other interesting state between the tokens. If the old token is displayed,
1124 // we should immediately force the new one to be displayed. If it is animating, we need
1125 // to move that animation to the new one.
1126 if (fromToken.allDrawn) {
1127 allDrawn = true;
1128 deferClearAllDrawn = fromToken.deferClearAllDrawn;
1129 }
1130 if (fromToken.firstWindowDrawn) {
1131 firstWindowDrawn = true;
1132 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001133 if (!fromToken.isHidden()) {
1134 setHidden(false);
Peter Visontay3556a3b2017-11-01 17:23:17 +00001135 hiddenRequested = false;
1136 mHiddenSetFromTransferredStartingWindow = true;
1137 }
1138 setClientHidden(fromToken.mClientHidden);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001139
Jorim Jaggi980c9de2017-11-17 01:41:37 +01001140 transferAnimation(fromToken);
1141
1142 // When transferring an animation, we no longer need to apply an animation to the
1143 // the token we transfer the animation over. Thus, remove the animation from
1144 // pending opening apps.
1145 mService.mOpeningApps.remove(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001146
Peter Visontay3556a3b2017-11-01 17:23:17 +00001147 mService.updateFocusedWindowLocked(
1148 UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/);
1149 getDisplayContent().setLayoutNeeded();
1150 mService.mWindowPlacerLocked.performSurfacePlacement();
1151 } finally {
1152 Binder.restoreCallingIdentity(origId);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001153 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001154 return true;
1155 } else if (fromToken.startingData != null) {
1156 // The previous app was getting ready to show a
1157 // starting window, but hasn't yet done so. Steal it!
1158 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1159 "Moving pending starting from " + fromToken + " to " + this);
1160 startingData = fromToken.startingData;
1161 fromToken.startingData = null;
1162 fromToken.startingMoved = true;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001163 if (getController() != null) {
1164 getController().scheduleAddStartingWindow();
1165 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001166 return true;
1167 }
1168
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001169 // TODO: Transfer thumbnail
1170
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001171 return false;
1172 }
1173
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001174 boolean isLastWindow(WindowState win) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001175 return mChildren.size() == 1 && mChildren.get(0) == win;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001176 }
1177
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001178 @Override
1179 void onAppTransitionDone() {
1180 sendingToBottom = false;
1181 }
1182
Wale Ogunwale51362492016-09-08 17:49:17 -07001183 /**
1184 * We override because this class doesn't want its children affecting its reported orientation
1185 * in anyway.
1186 */
1187 @Override
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001188 int getOrientation(int candidate) {
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001189 if (candidate == SCREEN_ORIENTATION_BEHIND) {
1190 // Allow app to specify orientation regardless of its visibility state if the current
1191 // candidate want us to use orientation behind. I.e. the visible app on-top of this one
1192 // wants us to use the orientation of the app behind it.
1193 return mOrientation;
1194 }
1195
Bryce Lee61fbcbc2017-03-10 14:14:03 -08001196 // The {@link AppWindowToken} should only specify an orientation when it is not closing or
1197 // going to the bottom. Allowing closing {@link AppWindowToken} to participate can lead to
1198 // an Activity in another task being started in the wrong orientation during the transition.
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001199 if (!(sendingToBottom || mService.mClosingApps.contains(this))
Bryce Lee00d586d2017-07-28 20:48:43 -07001200 && (isVisible() || mService.mOpeningApps.contains(this) || isOnTop())) {
Bryce Leea163b762017-01-24 11:05:01 -08001201 return mOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001202 }
Bryce Leea163b762017-01-24 11:05:01 -08001203
1204 return SCREEN_ORIENTATION_UNSET;
Wale Ogunwale51362492016-09-08 17:49:17 -07001205 }
1206
Wale Ogunwaleb198b742016-12-01 08:44:09 -08001207 /** Returns the app's preferred orientation regardless of its currently visibility state. */
1208 int getOrientationIgnoreVisibility() {
1209 return mOrientation;
1210 }
1211
Craig Mautnerdbb79912012-03-01 18:59:14 -08001212 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001213 void checkAppWindowsReadyToShow() {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001214 if (allDrawn == mLastAllDrawn) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001215 return;
1216 }
1217
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001218 mLastAllDrawn = allDrawn;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001219 if (!allDrawn) {
1220 return;
1221 }
1222
1223 // The token has now changed state to having all windows shown... what to do, what to do?
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001224 if (mFreezingScreen) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001225 showAllWindowsLocked();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001226 stopFreezingScreen(false, true);
1227 if (DEBUG_ORIENTATION) Slog.i(TAG,
1228 "Setting mOrientationChangeComplete=true because wtoken " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001229 + " numInteresting=" + mNumInterestingWindows + " numDrawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001230 // This will set mOrientationChangeComplete and cause a pass through layout.
1231 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001232 "checkAppWindowsReadyToShow: freezingScreen");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001233 } else {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001234 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001235
1236 // We can now show all of the drawn windows!
1237 if (!mService.mOpeningApps.contains(this)) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001238 showAllWindowsLocked();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001239 }
1240 }
1241 }
1242
Matthew Ng5d23afa2017-06-21 16:16:24 -07001243 /**
Bryce Leed390deb2017-06-22 13:14:28 -07001244 * Returns whether the drawn window states of this {@link AppWindowToken} has considered every
1245 * child {@link WindowState}. A child is considered if it has been passed into
1246 * {@link #updateDrawnWindowStates(WindowState)} after being added. This is used to determine
1247 * whether states, such as {@code allDrawn}, can be set, which relies on state variables such as
1248 * {@code mNumInterestingWindows}, which depend on all {@link WindowState}s being considered.
1249 *
1250 * @return {@code true} If all children have been considered, {@code false}.
1251 */
1252 private boolean allDrawnStatesConsidered() {
Bryce Lee6311c4b2017-07-06 14:09:29 -07001253 for (int i = mChildren.size() - 1; i >= 0; --i) {
1254 final WindowState child = mChildren.get(i);
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001255 if (child.mightAffectAllDrawn() && !child.getDrawnStateEvaluated()) {
Bryce Leed390deb2017-06-22 13:14:28 -07001256 return false;
1257 }
1258 }
1259 return true;
1260 }
1261
1262 /**
Matthew Ng5d23afa2017-06-21 16:16:24 -07001263 * Determines if the token has finished drawing. This should only be called from
1264 * {@link DisplayContent#applySurfaceChangesTransaction}
1265 */
Matthew Ng498c71d2017-04-18 13:55:45 -07001266 void updateAllDrawn() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001267 if (!allDrawn) {
Matthew Ng498c71d2017-04-18 13:55:45 -07001268 // Number of drawn windows can be less when a window is being relaunched, wait for
Bryce Leed390deb2017-06-22 13:14:28 -07001269 // all windows to be launched and drawn for this token be considered all drawn.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001270 final int numInteresting = mNumInterestingWindows;
Bryce Leed390deb2017-06-22 13:14:28 -07001271
1272 // We must make sure that all present children have been considered (determined by
1273 // {@link #allDrawnStatesConsidered}) before evaluating whether everything has been
1274 // drawn.
1275 if (numInteresting > 0 && allDrawnStatesConsidered()
1276 && mNumDrawnWindows >= numInteresting && !isRelaunching()) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001277 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawn: " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001278 + " interesting=" + numInteresting + " drawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001279 allDrawn = true;
1280 // Force an additional layout pass where
1281 // WindowStateAnimator#commitFinishDrawingLocked() will call performShowLocked().
Matthew Ng498c71d2017-04-18 13:55:45 -07001282 if (mDisplayContent != null) {
1283 mDisplayContent.setLayoutNeeded();
1284 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001285 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Robert Carrecc06b32017-04-18 14:25:10 -07001286
Winson Chunge7ba6862017-05-24 12:13:33 -07001287 // Notify the pinned stack upon all windows drawn. If there was an animation in
1288 // progress then this signal will resume that animation.
Wale Ogunwale61911492017-10-11 08:50:50 -07001289 final TaskStack pinnedStack = mDisplayContent.getPinnedStack();
Winson Chunge7ba6862017-05-24 12:13:33 -07001290 if (pinnedStack != null) {
1291 pinnedStack.onAllWindowsDrawn();
Robert Carrecc06b32017-04-18 14:25:10 -07001292 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001293 }
1294 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001295 }
1296
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001297 /**
1298 * Updated this app token tracking states for interesting and drawn windows based on the window.
1299 *
1300 * @return Returns true if the input window is considered interesting and drawn while all the
1301 * windows in this app token where not considered drawn as of the last pass.
1302 */
1303 boolean updateDrawnWindowStates(WindowState w) {
Bryce Leed390deb2017-06-22 13:14:28 -07001304 w.setDrawnStateEvaluated(true /*evaluated*/);
1305
Jorim Jaggie4b0f282017-05-17 15:10:29 +02001306 if (DEBUG_STARTING_WINDOW_VERBOSE && w == startingWindow) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001307 Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" + w.isOnScreen()
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001308 + " allDrawn=" + allDrawn + " freezingScreen=" + mFreezingScreen);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001309 }
1310
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001311 if (allDrawn && !mFreezingScreen) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001312 return false;
1313 }
1314
1315 if (mLastTransactionSequence != mService.mTransactionSequence) {
1316 mLastTransactionSequence = mService.mTransactionSequence;
1317 mNumInterestingWindows = mNumDrawnWindows = 0;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001318 startingDisplayed = false;
1319 }
1320
1321 final WindowStateAnimator winAnimator = w.mWinAnimator;
1322
1323 boolean isInterestingAndDrawn = false;
1324
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001325 if (!allDrawn && w.mightAffectAllDrawn()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001326 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
1327 Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw()
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001328 + ", isAnimationSet=" + isSelfAnimating());
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001329 if (!w.isDrawnLw()) {
1330 Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController
1331 + " pv=" + w.mPolicyVisibility
1332 + " mDrawState=" + winAnimator.drawStateToString()
1333 + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001334 + " a=" + isSelfAnimating());
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001335 }
1336 }
1337
1338 if (w != startingWindow) {
1339 if (w.isInteresting()) {
1340 mNumInterestingWindows++;
1341 if (w.isDrawnLw()) {
1342 mNumDrawnWindows++;
1343
1344 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, "tokenMayBeDrawn: "
1345 + this + " w=" + w + " numInteresting=" + mNumInterestingWindows
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001346 + " freezingScreen=" + mFreezingScreen
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001347 + " mAppFreezing=" + w.mAppFreezing);
1348
1349 isInterestingAndDrawn = true;
1350 }
1351 }
1352 } else if (w.isDrawnLw()) {
Jorim Jaggi3878ca32017-02-02 17:13:05 -08001353 if (getController() != null) {
1354 getController().reportStartingWindowDrawn();
1355 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001356 startingDisplayed = true;
1357 }
1358 }
1359
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001360 return isInterestingAndDrawn;
1361 }
1362
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001363 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001364 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001365 // For legacy reasons we process the TaskStack.mExitingAppTokens first in DisplayContent
1366 // before the non-exiting app tokens. So, we skip the exiting app tokens here.
1367 // TODO: Investigate if we need to continue to do this or if we can just process them
1368 // in-order.
1369 if (mIsExiting && !waitingForReplacement()) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001370 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001371 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001372 return forAllWindowsUnchecked(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001373 }
1374
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001375 boolean forAllWindowsUnchecked(ToBooleanFunction<WindowState> callback,
1376 boolean traverseTopToBottom) {
1377 return super.forAllWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001378 }
1379
1380 @Override
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001381 AppWindowToken asAppWindowToken() {
1382 // I am an app window token!
1383 return this;
1384 }
1385
1386 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -07001387 boolean fillsParent() {
1388 return mFillsParent;
1389 }
1390
1391 void setFillsParent(boolean fillsParent) {
1392 mFillsParent = fillsParent;
1393 }
1394
Jorim Jaggife762342016-10-13 14:33:27 +02001395 boolean containsDismissKeyguardWindow() {
Bryce Lee081554b2017-05-25 07:52:12 -07001396 // Window state is transient during relaunch. We are not guaranteed to be frozen during the
1397 // entirety of the relaunch.
1398 if (isRelaunching()) {
1399 return mLastContainsDismissKeyguardWindow;
1400 }
1401
Jorim Jaggife762342016-10-13 14:33:27 +02001402 for (int i = mChildren.size() - 1; i >= 0; i--) {
1403 if ((mChildren.get(i).mAttrs.flags & FLAG_DISMISS_KEYGUARD) != 0) {
1404 return true;
1405 }
1406 }
1407 return false;
1408 }
1409
1410 boolean containsShowWhenLockedWindow() {
Bryce Lee081554b2017-05-25 07:52:12 -07001411 // When we are relaunching, it is possible for us to be unfrozen before our previous
1412 // windows have been added back. Using the cached value ensures that our previous
1413 // showWhenLocked preference is honored until relaunching is complete.
1414 if (isRelaunching()) {
1415 return mLastContainsShowWhenLockedWindow;
1416 }
1417
Jorim Jaggife762342016-10-13 14:33:27 +02001418 for (int i = mChildren.size() - 1; i >= 0; i--) {
1419 if ((mChildren.get(i).mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
1420 return true;
1421 }
1422 }
Bryce Lee081554b2017-05-25 07:52:12 -07001423
Jorim Jaggife762342016-10-13 14:33:27 +02001424 return false;
1425 }
1426
1427 void checkKeyguardFlagsChanged() {
1428 final boolean containsDismissKeyguard = containsDismissKeyguardWindow();
1429 final boolean containsShowWhenLocked = containsShowWhenLockedWindow();
1430 if (containsDismissKeyguard != mLastContainsDismissKeyguardWindow
1431 || containsShowWhenLocked != mLastContainsShowWhenLockedWindow) {
1432 mService.notifyKeyguardFlagsChanged(null /* callback */);
1433 }
1434 mLastContainsDismissKeyguardWindow = containsDismissKeyguard;
1435 mLastContainsShowWhenLockedWindow = containsShowWhenLocked;
1436 }
1437
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001438 WindowState getImeTargetBelowWindow(WindowState w) {
1439 final int index = mChildren.indexOf(w);
1440 if (index > 0) {
1441 final WindowState target = mChildren.get(index - 1);
1442 if (target.canBeImeTarget()) {
1443 return target;
1444 }
1445 }
1446 return null;
1447 }
1448
Winson Chungbe9be7f2017-06-28 10:55:22 -07001449 int getLowestAnimLayer() {
1450 for (int i = 0; i < mChildren.size(); i++) {
1451 final WindowState w = mChildren.get(i);
1452 if (w.mRemoved) {
1453 continue;
1454 }
1455 return w.mWinAnimator.mAnimLayer;
1456 }
1457 return Integer.MAX_VALUE;
1458 }
1459
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001460 WindowState getHighestAnimLayerWindow(WindowState currentTarget) {
1461 WindowState candidate = null;
1462 for (int i = mChildren.indexOf(currentTarget); i >= 0; i--) {
1463 final WindowState w = mChildren.get(i);
1464 if (w.mRemoved) {
1465 continue;
1466 }
1467 if (candidate == null || w.mWinAnimator.mAnimLayer >
1468 candidate.mWinAnimator.mAnimLayer) {
1469 candidate = w;
1470 }
1471 }
1472 return candidate;
1473 }
1474
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001475 /**
1476 * See {@link Activity#setDisablePreviewScreenshots}.
1477 */
1478 void setDisablePreviewScreenshots(boolean disable) {
Wale Ogunwale6c459212017-05-17 08:56:03 -07001479 mDisablePreviewScreenshots = disable;
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001480 }
1481
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001482 /**
chaviwd3bf08d2017-08-01 17:24:59 -07001483 * Sets whether the current launch can turn the screen on. See {@link #canTurnScreenOn()}
1484 */
1485 void setCanTurnScreenOn(boolean canTurnScreenOn) {
1486 mCanTurnScreenOn = canTurnScreenOn;
1487 }
1488
1489 /**
1490 * Indicates whether the current launch can turn the screen on. This is to prevent multiple
1491 * relayouts from turning the screen back on. The screen should only turn on at most
1492 * once per activity resume.
1493 *
1494 * @return true if the screen can be turned on.
1495 */
1496 boolean canTurnScreenOn() {
1497 return mCanTurnScreenOn;
1498 }
1499
1500 /**
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001501 * Retrieves whether we'd like to generate a snapshot that's based solely on the theme. This is
1502 * the case when preview screenshots are disabled {@link #setDisablePreviewScreenshots} or when
1503 * we can't take a snapshot for other reasons, for example, if we have a secure window.
1504 *
1505 * @return True if we need to generate an app theme snapshot, false if we'd like to take a real
1506 * screenshot.
1507 */
1508 boolean shouldUseAppThemeSnapshot() {
Wale Ogunwale6c459212017-05-17 08:56:03 -07001509 return mDisablePreviewScreenshots || forAllWindows(w -> (w.mAttrs.flags & FLAG_SECURE) != 0,
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001510 true /* topToBottom */);
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001511 }
1512
chaviw23ee71c2017-12-18 11:29:41 -08001513 @Override
1514 public SurfaceControl.Builder makeAnimationLeash() {
1515 return super.makeAnimationLeash()
1516 .setParent(getAppAnimationLayer());
1517 }
1518
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001519 boolean applyAnimationLocked(WindowManager.LayoutParams lp, int transit, boolean enter,
1520 boolean isVoiceInteraction) {
1521
1522 if (mService.mDisableTransitionAnimation) {
1523 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1524 Slog.v(TAG_WM, "applyAnimation: transition animation is disabled. atoken=" + this);
1525 }
1526 cancelAnimation();
1527 return false;
1528 }
1529
1530 // Only apply an animation if the display isn't frozen. If it is frozen, there is no reason
1531 // to animate and it can cause strange artifacts when we unfreeze the display if some
1532 // different animation is running.
1533 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "AWT#applyAnimationLocked");
1534 if (okToAnimate()) {
1535 final Animation a = loadAnimation(lp, transit, enter, isVoiceInteraction);
1536 if (a != null) {
chaviw23ee71c2017-12-18 11:29:41 -08001537 final TaskStack stack = getStack();
1538 mTmpPoint.set(0, 0);
1539 if (stack != null) {
1540 stack.getRelativePosition(mTmpPoint);
1541 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001542 final AnimationAdapter adapter = new LocalAnimationAdapter(
chaviw23ee71c2017-12-18 11:29:41 -08001543 new WindowAnimationSpec(a, mTmpPoint,
Jorim Jaggi2e3c31d2017-11-20 19:49:00 +01001544 mService.mAppTransition.canSkipFirstFrame()),
1545 mService.mSurfaceAnimationRunner);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001546 if (a.getZAdjustment() == Animation.ZORDER_TOP) {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001547 mNeedsZBoost = true;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001548 }
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001549 startAnimation(getPendingTransaction(), adapter, !isVisible());
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001550 mTransit = transit;
1551 mTransitFlags = mService.mAppTransition.getTransitFlags();
1552 // TODO: Skip first frame and app stack clip mode.
1553 }
1554 } else {
1555 cancelAnimation();
1556 }
1557 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
1558
1559 return isReallyAnimating();
1560 }
1561
1562 private Animation loadAnimation(WindowManager.LayoutParams lp, int transit, boolean enter,
1563 boolean isVoiceInteraction) {
1564 final DisplayContent displayContent = getTask().getDisplayContent();
1565 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
1566 final int width = displayInfo.appWidth;
1567 final int height = displayInfo.appHeight;
1568 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG_WM,
1569 "applyAnimation: atoken=" + this);
1570
1571 // Determine the visible rect to calculate the thumbnail clip
1572 final WindowState win = findMainWindow();
1573 final Rect frame = new Rect(0, 0, width, height);
1574 final Rect displayFrame = new Rect(0, 0,
1575 displayInfo.logicalWidth, displayInfo.logicalHeight);
1576 final Rect insets = new Rect();
1577 final Rect stableInsets = new Rect();
1578 Rect surfaceInsets = null;
1579 final boolean freeform = win != null && win.inFreeformWindowingMode();
1580 if (win != null) {
1581 // Containing frame will usually cover the whole screen, including dialog windows.
1582 // For freeform workspace windows it will not cover the whole screen and it also
1583 // won't exactly match the final freeform window frame (e.g. when overlapping with
1584 // the status bar). In that case we need to use the final frame.
1585 if (freeform) {
1586 frame.set(win.mFrame);
1587 } else {
1588 frame.set(win.mContainingFrame);
1589 }
1590 surfaceInsets = win.getAttrs().surfaceInsets;
1591 insets.set(win.mContentInsets);
1592 stableInsets.set(win.mStableInsets);
1593 }
1594
1595 if (mLaunchTaskBehind) {
1596 // Differentiate the two animations. This one which is briefly on the screen
1597 // gets the !enter animation, and the other activity which remains on the
1598 // screen gets the enter animation. Both appear in the mOpeningApps set.
1599 enter = false;
1600 }
1601 if (DEBUG_APP_TRANSITIONS) Slog.d(TAG_WM, "Loading animation for app transition."
1602 + " transit=" + AppTransition.appTransitionToString(transit) + " enter=" + enter
1603 + " frame=" + frame + " insets=" + insets + " surfaceInsets=" + surfaceInsets);
1604 final Configuration displayConfig = displayContent.getConfiguration();
1605 final Animation a = mService.mAppTransition.loadAnimation(lp, transit, enter,
1606 displayConfig.uiMode, displayConfig.orientation, frame, displayFrame, insets,
1607 surfaceInsets, stableInsets, isVoiceInteraction, freeform, getTask().mTaskId);
1608 if (a != null) {
1609 if (DEBUG_ANIM) logWithStack(TAG, "Loaded animation " + a + " for " + this);
1610 final int containingWidth = frame.width();
1611 final int containingHeight = frame.height();
1612 a.initialize(containingWidth, containingHeight, width, height);
1613 a.scaleCurrentDuration(mService.getTransitionAnimationScaleLocked());
1614 }
1615 return a;
1616 }
1617
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001618 @Override
1619 protected void setLayer(Transaction t, int layer) {
1620 if (!mSurfaceAnimator.hasLeash()) {
1621 t.setLayer(mSurfaceControl, layer);
1622 }
1623 }
1624
1625 @Override
1626 protected void setRelativeLayer(Transaction t, SurfaceControl relativeTo, int layer) {
1627 if (!mSurfaceAnimator.hasLeash()) {
1628 t.setRelativeLayer(mSurfaceControl, relativeTo, layer);
1629 }
1630 }
1631
1632 @Override
1633 protected void reparentSurfaceControl(Transaction t, SurfaceControl newParent) {
1634 if (!mSurfaceAnimator.hasLeash()) {
1635 t.reparent(mSurfaceControl, newParent.getHandle());
1636 }
1637 }
1638
1639 @Override
1640 public void onAnimationLeashCreated(Transaction t, SurfaceControl leash) {
1641
1642 // The leash is parented to the animation layer. We need to preserve the z-order by using
1643 // the prefix order index, but we boost if necessary.
1644 int layer = getPrefixOrderIndex();
1645 if (mNeedsZBoost) {
1646 layer += Z_BOOST_BASE;
1647 }
1648 leash.setLayer(layer);
1649 }
1650
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001651 /**
1652 * This must be called while inside a transaction.
1653 */
1654 void showAllWindowsLocked() {
1655 forAllWindows(windowState -> {
1656 if (DEBUG_VISIBILITY) Slog.v(TAG, "performing show on: " + windowState);
1657 windowState.performShowLocked();
1658 }, false /* traverseTopToBottom */);
Jorim Jaggia5e10572017-11-15 14:36:26 +01001659 }
1660
1661 @Override
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001662 protected void onAnimationFinished() {
1663 super.onAnimationFinished();
1664
1665 mTransit = TRANSIT_UNSET;
1666 mTransitFlags = 0;
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001667 mNeedsZBoost = false;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001668
1669 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM | FINISH_LAYOUT_REDO_WALLPAPER,
1670 "AppWindowToken");
1671
Jorim Jaggi988f6682017-11-17 17:46:43 +01001672 clearThumbnail();
1673
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001674 if (mService.mInputMethodTarget != null && mService.mInputMethodTarget.mAppToken == this) {
1675 getDisplayContent().computeImeTarget(true /* updateImeTarget */);
1676 }
1677
1678 if (DEBUG_ANIM) Slog.v(TAG, "Animation done in " + this
1679 + ": reportedVisible=" + reportedVisible
1680 + " okToDisplay=" + okToDisplay()
1681 + " okToAnimate=" + okToAnimate()
1682 + " startingDisplayed=" + startingDisplayed);
1683
1684 // WindowState.onExitAnimationDone might modify the children list, so make a copy and then
1685 // traverse the copy.
1686 final ArrayList<WindowState> children = new ArrayList<>(mChildren);
1687 children.forEach(WindowState::onExitAnimationDone);
1688
1689 mService.mAppTransition.notifyAppTransitionFinishedLocked(token);
1690 scheduleAnimation();
1691 }
1692
1693 @Override
1694 boolean isAppAnimating() {
1695 return isSelfAnimating();
1696 }
1697
1698 @Override
1699 boolean isSelfAnimating() {
1700 // If we are about to start a transition, we also need to be considered animating.
1701 return isWaitingForTransitionStart() || isReallyAnimating();
1702 }
1703
1704 /**
1705 * @return True if and only if we are actually running an animation. Note that
1706 * {@link #isSelfAnimating} also returns true if we are waiting for an animation to
1707 * start.
1708 */
1709 private boolean isReallyAnimating() {
1710 return super.isSelfAnimating();
1711 }
1712
Jorim Jaggi988f6682017-11-17 17:46:43 +01001713 @Override
1714 void cancelAnimation() {
1715 super.cancelAnimation();
1716 clearThumbnail();
1717 }
1718
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001719 boolean isWaitingForTransitionStart() {
1720 return mService.mAppTransition.isTransitionSet()
1721 && (mService.mOpeningApps.contains(this) || mService.mClosingApps.contains(this));
1722 }
1723
1724 public int getTransit() {
1725 return mTransit;
1726 }
1727
1728 int getTransitFlags() {
1729 return mTransitFlags;
1730 }
1731
Jorim Jaggi988f6682017-11-17 17:46:43 +01001732 void attachThumbnailAnimation() {
1733 if (!isReallyAnimating()) {
1734 return;
1735 }
1736 final int taskId = getTask().mTaskId;
1737 final GraphicBuffer thumbnailHeader =
1738 mService.mAppTransition.getAppTransitionThumbnailHeader(taskId);
1739 if (thumbnailHeader == null) {
1740 if (DEBUG_APP_TRANSITIONS) Slog.d(TAG, "No thumbnail header bitmap for: " + taskId);
1741 return;
1742 }
1743 clearThumbnail();
1744 mThumbnail = new AppWindowThumbnail(getPendingTransaction(), this, thumbnailHeader);
1745 mThumbnail.startAnimation(getPendingTransaction(), loadThumbnailAnimation(thumbnailHeader));
1746 }
1747
1748 private Animation loadThumbnailAnimation(GraphicBuffer thumbnailHeader) {
1749 final DisplayInfo displayInfo = mDisplayContent.getDisplayInfo();
1750
1751 // If this is a multi-window scenario, we use the windows frame as
1752 // destination of the thumbnail header animation. If this is a full screen
1753 // window scenario, we use the whole display as the target.
1754 WindowState win = findMainWindow();
1755 Rect appRect = win != null ? win.getContentFrameLw() :
1756 new Rect(0, 0, displayInfo.appWidth, displayInfo.appHeight);
1757 Rect insets = win != null ? win.mContentInsets : null;
1758 final Configuration displayConfig = mDisplayContent.getConfiguration();
1759 return mService.mAppTransition.createThumbnailAspectScaleAnimationLocked(
1760 appRect, insets, thumbnailHeader, getTask().mTaskId, displayConfig.uiMode,
1761 displayConfig.orientation);
1762 }
1763
1764 private void clearThumbnail() {
1765 if (mThumbnail == null) {
1766 return;
1767 }
1768 mThumbnail.destroy();
1769 mThumbnail = null;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001770 }
1771
1772 @Override
1773 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
1774 super.dump(pw, prefix, dumpAll);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001775 if (appToken != null) {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001776 pw.println(prefix + "app=true mVoiceInteraction=" + mVoiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001777 }
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001778 pw.print(prefix); pw.print("task="); pw.println(getTask());
Wale Ogunwale51362492016-09-08 17:49:17 -07001779 pw.print(prefix); pw.print(" mFillsParent="); pw.print(mFillsParent);
1780 pw.print(" mOrientation="); pw.println(mOrientation);
Wale Ogunwale89973222017-04-23 18:39:45 -07001781 pw.println(prefix + "hiddenRequested=" + hiddenRequested + " mClientHidden=" + mClientHidden
1782 + ((mDeferHidingClient) ? " mDeferHidingClient=" + mDeferHidingClient : "")
1783 + " reportedDrawn=" + reportedDrawn + " reportedVisible=" + reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -07001784 if (paused) {
1785 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001786 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001787 if (mAppStopped) {
1788 pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped);
1789 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001790 if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001791 || allDrawn || mLastAllDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001792 pw.print(prefix); pw.print("mNumInterestingWindows=");
1793 pw.print(mNumInterestingWindows);
1794 pw.print(" mNumDrawnWindows="); pw.print(mNumDrawnWindows);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001795 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -07001796 pw.print(" allDrawn="); pw.print(allDrawn);
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001797 pw.print(" lastAllDrawn="); pw.print(mLastAllDrawn);
Craig Mautner6fbda632012-07-03 09:26:39 -07001798 pw.println(")");
1799 }
1800 if (inPendingTransaction) {
1801 pw.print(prefix); pw.print("inPendingTransaction=");
1802 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001803 }
Craig Mautner799bc1d2015-01-14 10:33:48 -08001804 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001805 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
1806 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -08001807 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -08001808 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001809 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001810 if (startingWindow != null || startingSurface != null
Wale Ogunwale6c459212017-05-17 08:56:03 -07001811 || startingDisplayed || startingMoved || mHiddenSetFromTransferredStartingWindow) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001812 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001813 pw.print(" startingSurface="); pw.print(startingSurface);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001814 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
Wale Ogunwale6c459212017-05-17 08:56:03 -07001815 pw.print(" startingMoved="); pw.print(startingMoved);
1816 pw.println(" mHiddenSetFromTransferredStartingWindow="
1817 + mHiddenSetFromTransferredStartingWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001818 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01001819 if (!mFrozenBounds.isEmpty()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -08001820 pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds);
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001821 pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig);
Chong Zhangd78ddb42016-03-02 17:01:14 -08001822 }
1823 if (mPendingRelaunchCount != 0) {
1824 pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount);
Jorim Jaggi0429f352015-12-22 16:29:16 +01001825 }
Wale Ogunwale9c64cb62017-04-12 13:39:59 -07001826 if (getController() != null) {
1827 pw.print(prefix); pw.print("controller="); pw.println(getController());
1828 }
Wale Ogunwalee287e192017-04-21 09:30:12 -07001829 if (mRemovingFromDisplay) {
1830 pw.println(prefix + "mRemovingFromDisplay=" + mRemovingFromDisplay);
1831 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001832 }
1833
1834 @Override
1835 void setHidden(boolean hidden) {
1836 super.setHidden(hidden);
1837 scheduleAnimation();
1838 }
1839
1840 @Override
1841 void prepareSurfaces() {
1842 // isSelfAnimating also returns true when we are about to start a transition, so we need
1843 // to check super here.
1844 final boolean reallyAnimating = super.isSelfAnimating();
1845 final boolean show = !isHidden() || reallyAnimating;
1846 if (show && !mLastSurfaceShowing) {
1847 mPendingTransaction.show(mSurfaceControl);
1848 } else if (!show && mLastSurfaceShowing) {
1849 mPendingTransaction.hide(mSurfaceControl);
Jorim Jaggi4d1835d2017-08-31 17:28:27 +02001850 }
Jorim Jaggi988f6682017-11-17 17:46:43 +01001851 if (mThumbnail != null) {
1852 mThumbnail.setShowing(mPendingTransaction, show);
1853 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001854 mLastSurfaceShowing = show;
1855 super.prepareSurfaces();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001856 }
1857
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001858 boolean isFreezingScreen() {
1859 return mFreezingScreen;
1860 }
1861
1862 @Override
1863 boolean needsZBoost() {
1864 return mNeedsZBoost || super.needsZBoost();
1865 }
1866
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07001867 @CallSuper
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001868 @Override
Adrian Roos4921ccf2017-09-28 16:54:06 +02001869 public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07001870 final long token = proto.start(fieldId);
1871 writeNameToProto(proto, NAME);
Adrian Roos4921ccf2017-09-28 16:54:06 +02001872 super.writeToProto(proto, WINDOW_TOKEN, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07001873 proto.end(token);
1874 }
1875
1876 void writeNameToProto(ProtoOutputStream proto, long fieldId) {
1877 if (appToken == null) {
1878 return;
1879 }
1880 try {
1881 proto.write(fieldId, appToken.getName());
1882 } catch (RemoteException e) {
1883 // This shouldn't happen, but in this case fall back to outputting nothing
1884 Slog.e(TAG, e.toString());
1885 }
1886 }
1887
1888 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001889 public String toString() {
1890 if (stringName == null) {
1891 StringBuilder sb = new StringBuilder();
1892 sb.append("AppWindowToken{");
1893 sb.append(Integer.toHexString(System.identityHashCode(this)));
1894 sb.append(" token="); sb.append(token); sb.append('}');
1895 stringName = sb.toString();
1896 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001897 return stringName + ((mIsExiting) ? " mIsExiting=" : "");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001898 }
Jeff Browne9bdb312012-04-05 15:30:10 -07001899}