blob: 43ca81d40ec4fb84abbf8bc65ac18a0e897dc568 [file] [log] [blame]
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server.wm;
18
Winson Chunge55c0192017-08-24 14:50:48 -070019import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
20import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;
Wale Ogunwale72919d22016-12-08 18:58:50 -080021import static android.content.pm.ActivityInfo.CONFIG_ORIENTATION;
22import static android.content.pm.ActivityInfo.CONFIG_SCREEN_SIZE;
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -070023import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND;
Wale Ogunwale51362492016-09-08 17:49:17 -070024import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET;
Jorim Jaggif5f9e122017-10-24 18:21:09 +020025import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070026import static android.view.Display.DEFAULT_DISPLAY;
Adrian Roos4d18a2e2017-12-19 19:08:05 +010027import static android.view.SurfaceControl.HIDDEN;
Jorim Jaggife762342016-10-13 14:33:27 +020028import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
Jorim Jaggid635a4a2017-05-03 15:21:26 +020029import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
Jorim Jaggife762342016-10-13 14:33:27 +020030import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
Wale Ogunwaled1c37912016-08-16 03:19:39 -070031import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080032import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070033import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
Tony Mak64b8d562017-12-28 17:44:02 +000034
Adrian Roose99bc052017-11-20 17:55:31 +010035import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
36import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070037import static com.android.server.wm.AppTransition.TRANSIT_UNSET;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080038import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080039import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
40import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070041import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070042import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
43import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
Wale Ogunwale9017ec02016-02-25 08:55:25 -080044import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
Jorim Jaggie4b0f282017-05-17 15:10:29 +020045import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW_VERBOSE;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070046import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TOKEN_MOVEMENT;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080047import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
48import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_MOVEMENT;
49import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
50import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Chong Zhang92147042016-05-09 12:47:11 -070051import static com.android.server.wm.WindowManagerService.H.NOTIFY_ACTIVITY_DRAWN;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070052import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070053import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070054import static com.android.server.wm.WindowManagerService.logWithStack;
Vishnu Nair04ab4392018-01-10 11:00:06 -080055import static com.android.server.wm.proto.AppWindowTokenProto.ALL_DRAWN;
56import static com.android.server.wm.proto.AppWindowTokenProto.APP_STOPPED;
57import static com.android.server.wm.proto.AppWindowTokenProto.CLIENT_HIDDEN;
58import static com.android.server.wm.proto.AppWindowTokenProto.DEFER_HIDING_CLIENT;
59import static com.android.server.wm.proto.AppWindowTokenProto.FILLS_PARENT;
60import static com.android.server.wm.proto.AppWindowTokenProto.FROZEN_BOUNDS;
61import static com.android.server.wm.proto.AppWindowTokenProto.HIDDEN_REQUESTED;
62import static com.android.server.wm.proto.AppWindowTokenProto.HIDDEN_SET_FROM_TRANSFERRED_STARTING_WINDOW;
63import static com.android.server.wm.proto.AppWindowTokenProto.IS_REALLY_ANIMATING;
64import static com.android.server.wm.proto.AppWindowTokenProto.IS_WAITING_FOR_TRANSITION_START;
65import static com.android.server.wm.proto.AppWindowTokenProto.LAST_ALL_DRAWN;
66import static com.android.server.wm.proto.AppWindowTokenProto.LAST_SURFACE_SHOWING;
Steven Timotiusaf03df62017-07-18 16:56:43 -070067import static com.android.server.wm.proto.AppWindowTokenProto.NAME;
Vishnu Nair04ab4392018-01-10 11:00:06 -080068import static com.android.server.wm.proto.AppWindowTokenProto.NUM_DRAWN_WINDOWS;
69import static com.android.server.wm.proto.AppWindowTokenProto.NUM_INTERESTING_WINDOWS;
70import static com.android.server.wm.proto.AppWindowTokenProto.REMOVED;
71import static com.android.server.wm.proto.AppWindowTokenProto.REPORTED_DRAWN;
72import static com.android.server.wm.proto.AppWindowTokenProto.REPORTED_VISIBLE;
73import static com.android.server.wm.proto.AppWindowTokenProto.STARTING_DISPLAYED;
74import static com.android.server.wm.proto.AppWindowTokenProto.STARTING_MOVED;
75import static com.android.server.wm.proto.AppWindowTokenProto.STARTING_WINDOW;
76import static com.android.server.wm.proto.AppWindowTokenProto.THUMBNAIL;
Steven Timotiusaf03df62017-07-18 16:56:43 -070077import static com.android.server.wm.proto.AppWindowTokenProto.WINDOW_TOKEN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080078
Wale Ogunwale0d5609b2017-09-13 05:55:07 -070079import android.annotation.CallSuper;
Jorim Jaggid635a4a2017-05-03 15:21:26 +020080import android.app.Activity;
Jorim Jaggi26c8c422016-05-09 19:57:25 -070081import android.content.res.Configuration;
Jorim Jaggi988f6682017-11-17 17:46:43 +010082import android.graphics.GraphicBuffer;
Jorim Jaggif5f9e122017-10-24 18:21:09 +020083import android.graphics.Point;
Jorim Jaggi0429f352015-12-22 16:29:16 +010084import android.graphics.Rect;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070085import android.os.Binder;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080086import android.os.Debug;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070087import android.os.IBinder;
Steven Timotiusaf03df62017-07-18 16:56:43 -070088import android.os.RemoteException;
Jorim Jaggif5f9e122017-10-24 18:21:09 +020089import android.os.Trace;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080090import android.util.Slog;
Steven Timotiusaf03df62017-07-18 16:56:43 -070091import android.util.proto.ProtoOutputStream;
Jorim Jaggif5f9e122017-10-24 18:21:09 +020092import android.view.DisplayInfo;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080093import android.view.IApplicationToken;
Robert Carr6914f082017-03-20 19:04:30 -070094import android.view.SurfaceControl;
Tony Mak64b8d562017-12-28 17:44:02 +000095import android.view.SurfaceControl.Transaction;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080096import android.view.WindowManager;
Jorim Jaggi87fdbcb2017-08-17 13:41:11 +020097import android.view.WindowManager.LayoutParams;
Tony Mak64b8d562017-12-28 17:44:02 +000098import android.view.animation.Animation;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080099
Tony Mak64b8d562017-12-28 17:44:02 +0000100import com.android.internal.R;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800101import com.android.internal.util.ToBooleanFunction;
102import com.android.server.input.InputApplicationHandle;
Adrian Roose99bc052017-11-20 17:55:31 +0100103import com.android.server.policy.WindowManagerPolicy.StartingSurface;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800104import com.android.server.wm.WindowManagerService.H;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800105
106import java.io.PrintWriter;
Jorim Jaggi0429f352015-12-22 16:29:16 +0100107import java.util.ArrayDeque;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800108import java.util.ArrayList;
109
110class AppTokenList extends ArrayList<AppWindowToken> {
111}
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800112
113/**
114 * Version of WindowToken that is specifically for a particular application (or
115 * really activity) that is displaying windows.
116 */
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700117class AppWindowToken extends WindowToken implements WindowManagerService.AppFreezeListener {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800118 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppWindowToken" : TAG_WM;
119
Jorim Jaggi619c9f72017-12-19 18:04:29 +0100120 /**
121 * Value to increment the z-layer when boosting a layer during animations. BOOST in l33tsp34k.
122 */
123 private static final int Z_BOOST_BASE = 800570000;
124
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800125 // Non-null only for application tokens.
126 final IApplicationToken appToken;
127
Wale Ogunwale72919d22016-12-08 18:58:50 -0800128 final boolean mVoiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700129
Wale Ogunwale51362492016-09-08 17:49:17 -0700130 /** @see WindowContainer#fillsParent() */
131 private boolean mFillsParent;
Craig Mautner4c5eb222013-11-18 12:59:05 -0800132 boolean layoutConfigChanges;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800133 boolean mShowForAllUsers;
134 int mTargetSdk;
Craig Mautnera2c77052012-03-26 12:14:43 -0700135
Bryce Lee6d410262017-02-28 15:30:17 -0800136 // Flag set while reparenting to prevent actions normally triggered by an individual parent
137 // change.
138 private boolean mReparenting;
139
Wale Ogunwalee287e192017-04-21 09:30:12 -0700140 // True if we are current in the process of removing this app token from the display
141 private boolean mRemovingFromDisplay = false;
142
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800143 // The input dispatching timeout for this application token in nanoseconds.
Wale Ogunwale72919d22016-12-08 18:58:50 -0800144 long mInputDispatchingTimeoutNanos;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800145
146 // These are used for determining when all windows associated with
147 // an activity have been drawn, so they can be made visible together
148 // at the same time.
Craig Mautner764983d2012-03-22 11:37:36 -0700149 // initialize so that it doesn't match mTransactionSequence which is an int.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700150 private long mLastTransactionSequence = Long.MIN_VALUE;
151 private int mNumInterestingWindows;
152 private int mNumDrawnWindows;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800153 boolean inPendingTransaction;
154 boolean allDrawn;
Jorim Jaggib0fc8172017-11-23 17:04:08 +0000155 private boolean mLastAllDrawn;
156
Craig Mautner7636dfb2012-11-16 15:24:11 -0800157 // Set to true when this app creates a surface while in the middle of an animation. In that
158 // case do not clear allDrawn until the animation completes.
159 boolean deferClearAllDrawn;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800160
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800161 // Is this window's surface needed? This is almost like hidden, except
162 // it will sometimes be true a little earlier: when the token has
163 // been shown, but is still waiting for its app transition to execute
164 // before making its windows shown.
165 boolean hiddenRequested;
166
167 // Have we told the window clients to hide themselves?
Wale Ogunwale89973222017-04-23 18:39:45 -0700168 private boolean mClientHidden;
169
170 // If true we will defer setting mClientHidden to true and reporting to the client that it is
171 // hidden.
172 boolean mDeferHidingClient;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800173
174 // Last visibility state we reported to the app token.
175 boolean reportedVisible;
176
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700177 // Last drawn state we reported to the app token.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700178 private boolean reportedDrawn;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700179
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800180 // Set to true when the token has been removed from the window mgr.
181 boolean removed;
182
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800183 // Information about an application starting window if displayed.
184 StartingData startingData;
185 WindowState startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800186 StartingSurface startingSurface;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800187 boolean startingDisplayed;
188 boolean startingMoved;
Wale Ogunwale6c459212017-05-17 08:56:03 -0700189 // True if the hidden state of this token was forced to false due to a transferred starting
190 // window.
191 private boolean mHiddenSetFromTransferredStartingWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800192 boolean firstWindowDrawn;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700193 private final WindowState.UpdateReportedVisibilityResults mReportedVisibilityResults =
194 new WindowState.UpdateReportedVisibilityResults();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800195
196 // Input application handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700197 final InputApplicationHandle mInputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800198
Wale Ogunwale571771c2016-08-26 13:18:50 -0700199 // TODO: Have a WindowContainer state for tracking exiting/deferred removal.
Craig Mautner799bc1d2015-01-14 10:33:48 -0800200 boolean mIsExiting;
Craig Mautner9ef471f2014-02-07 13:11:47 -0800201
Craig Mautnerbb742462014-07-07 15:28:55 -0700202 boolean mLaunchTaskBehind;
Craig Mautner8746a472014-07-24 15:12:54 -0700203 boolean mEnteringAnimation;
Craig Mautnerbb742462014-07-07 15:28:55 -0700204
Wale Ogunwale72919d22016-12-08 18:58:50 -0800205 private boolean mAlwaysFocusable;
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800206
Robert Carre12aece2016-02-02 22:43:27 -0800207 boolean mAppStopped;
Robert Carrfd10cd12016-06-29 16:41:50 -0700208 int mRotationAnimationHint;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700209 private int mPendingRelaunchCount;
Robert Carre12aece2016-02-02 22:43:27 -0800210
Jorim Jaggife762342016-10-13 14:33:27 +0200211 private boolean mLastContainsShowWhenLockedWindow;
212 private boolean mLastContainsDismissKeyguardWindow;
213
Jorim Jaggi0429f352015-12-22 16:29:16 +0100214 ArrayDeque<Rect> mFrozenBounds = new ArrayDeque<>();
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700215 ArrayDeque<Configuration> mFrozenMergedConfig = new ArrayDeque<>();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100216
Wale Ogunwale6c459212017-05-17 08:56:03 -0700217 private boolean mDisablePreviewScreenshots;
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +0100218
Wale Ogunwale034a8ec2017-09-02 17:14:40 -0700219 private Task mLastParent;
Robert Carred3e83b2017-04-21 13:26:55 -0700220
chaviwd3bf08d2017-08-01 17:24:59 -0700221 /**
222 * See {@link #canTurnScreenOn()}
223 */
224 private boolean mCanTurnScreenOn = true;
225
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200226 /**
227 * If we are running an animation, this determines the transition type. Must be one of
228 * AppTransition.TRANSIT_* constants.
229 */
230 private int mTransit;
231
232 /**
233 * If we are running an animation, this determines the flags during this animation. Must be a
234 * bitwise combination of AppTransition.TRANSIT_FLAG_* constants.
235 */
236 private int mTransitFlags;
237
238 /** Whether our surface was set to be showing in the last call to {@link #prepareSurfaces} */
Jorim Jaggifd1891462017-12-29 15:41:36 +0100239 private boolean mLastSurfaceShowing = true;
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200240
Jorim Jaggi988f6682017-11-17 17:46:43 +0100241 private AppWindowThumbnail mThumbnail;
242
Jorim Jaggib0fc8172017-11-23 17:04:08 +0000243 /** Have we been asked to have this token keep the screen frozen? */
244 private boolean mFreezingScreen;
245
246 /** Whether this token should be boosted at the top of all app window tokens. */
247 private boolean mNeedsZBoost;
Adrian Roos4d18a2e2017-12-19 19:08:05 +0100248 private Letterbox mLetterbox;
Jorim Jaggib0fc8172017-11-23 17:04:08 +0000249
chaviw23ee71c2017-12-18 11:29:41 -0800250 private final Point mTmpPoint = new Point();
chaviw23012112017-12-20 15:29:04 -0800251 private final Rect mTmpRect = new Rect();
chaviw23ee71c2017-12-18 11:29:41 -0800252
Wale Ogunwale72919d22016-12-08 18:58:50 -0800253 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
254 DisplayContent dc, long inputDispatchingTimeoutNanos, boolean fullscreen,
255 boolean showForAllUsers, int targetSdk, int orientation, int rotationAnimationHint,
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800256 int configChanges, boolean launchTaskBehind, boolean alwaysFocusable,
Bryce Leef3c6a472017-11-14 14:53:06 -0800257 AppWindowContainerController controller) {
258 this(service, token, voiceInteraction, dc, fullscreen);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800259 setController(controller);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800260 mInputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800261 mShowForAllUsers = showForAllUsers;
262 mTargetSdk = targetSdk;
263 mOrientation = orientation;
264 layoutConfigChanges = (configChanges & (CONFIG_SCREEN_SIZE | CONFIG_ORIENTATION)) != 0;
265 mLaunchTaskBehind = launchTaskBehind;
266 mAlwaysFocusable = alwaysFocusable;
267 mRotationAnimationHint = rotationAnimationHint;
268
269 // Application tokens start out hidden.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200270 setHidden(true);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800271 hiddenRequested = true;
272 }
273
274 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
Bryce Leef3c6a472017-11-14 14:53:06 -0800275 DisplayContent dc, boolean fillsParent) {
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800276 super(service, token != null ? token.asBinder() : null, TYPE_APPLICATION, true, dc,
277 false /* ownerCanManageAppTokens */);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700278 appToken = token;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800279 mVoiceInteraction = voiceInteraction;
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800280 mFillsParent = fillsParent;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800281 mInputApplicationHandle = new InputApplicationHandle(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800282 }
283
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800284 void onFirstWindowDrawn(WindowState win, WindowStateAnimator winAnimator) {
285 firstWindowDrawn = true;
286
287 // We now have a good window to show, remove dead placeholders
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700288 removeDeadWindows();
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800289
Jorim Jaggi02886a82016-12-06 09:10:06 -0800290 if (startingWindow != null) {
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800291 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, "Finish starting "
292 + win.mToken + ": first real window is shown, no animation");
293 // If this initial window is animating, stop it -- we will do an animation to reveal
294 // it from behind the starting window, so there is no need for it to also be doing its
295 // own stuff.
Jorim Jaggia5e10572017-11-15 14:36:26 +0100296 win.cancelAnimation();
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800297 if (getController() != null) {
298 getController().removeStartingWindow();
299 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800300 }
301 updateReportedVisibilityLocked();
302 }
303
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800304 void updateReportedVisibilityLocked() {
305 if (appToken == null) {
306 return;
307 }
308
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700309 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700310 final int count = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800311
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700312 mReportedVisibilityResults.reset();
313
314 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700315 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700316 win.updateReportedVisibility(mReportedVisibilityResults);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800317 }
318
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700319 int numInteresting = mReportedVisibilityResults.numInteresting;
320 int numVisible = mReportedVisibilityResults.numVisible;
321 int numDrawn = mReportedVisibilityResults.numDrawn;
322 boolean nowGone = mReportedVisibilityResults.nowGone;
323
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700324 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200325 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting && !isHidden();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700326 if (!nowGone) {
327 // If the app is not yet gone, then it can only become visible/drawn.
328 if (!nowDrawn) {
329 nowDrawn = reportedDrawn;
330 }
331 if (!nowVisible) {
332 nowVisible = reportedVisible;
333 }
334 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800335 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800336 + numInteresting + " visible=" + numVisible);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800337 final AppWindowContainerController controller = getController();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700338 if (nowDrawn != reportedDrawn) {
339 if (nowDrawn) {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800340 if (controller != null) {
341 controller.reportWindowsDrawn();
342 }
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700343 }
344 reportedDrawn = nowDrawn;
345 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800346 if (nowVisible != reportedVisible) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700347 if (DEBUG_VISIBILITY) Slog.v(TAG,
348 "Visibility changed in " + this + ": vis=" + nowVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800349 reportedVisible = nowVisible;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800350 if (controller != null) {
351 if (nowVisible) {
352 controller.reportWindowsVisible();
353 } else {
354 controller.reportWindowsGone();
355 }
356 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800357 }
358 }
359
Wale Ogunwale89973222017-04-23 18:39:45 -0700360 boolean isClientHidden() {
361 return mClientHidden;
362 }
363
364 void setClientHidden(boolean hideClient) {
365 if (mClientHidden == hideClient || (hideClient && mDeferHidingClient)) {
366 return;
367 }
368 mClientHidden = hideClient;
369 sendAppVisibilityToClients();
370 }
371
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700372 boolean setVisibility(WindowManager.LayoutParams lp,
373 boolean visible, int transit, boolean performLayout, boolean isVoiceInteraction) {
374
375 boolean delayed = false;
376 inPendingTransaction = false;
Wale Ogunwale9e4721f2017-05-23 19:37:30 -0700377 // Reset the state of mHiddenSetFromTransferredStartingWindow since visibility is actually
378 // been set by the app now.
379 mHiddenSetFromTransferredStartingWindow = false;
Wale Ogunwale89973222017-04-23 18:39:45 -0700380 setClientHidden(!visible);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700381
382 // Allow for state changes and animation to be applied if:
383 // * token is transitioning visibility state
384 // * or the token was marked as hidden and is exiting before we had a chance to play the
385 // transition animation
386 // * or this is an opening app and windows are being replaced.
387 boolean visibilityChanged = false;
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200388 if (isHidden() == visible || (isHidden() && mIsExiting) || (visible && waitingForReplacement())) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700389 final AccessibilityController accessibilityController = mService.mAccessibilityController;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700390 boolean changed = false;
391 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200392 "Changing app " + this + " hidden=" + isHidden() + " performLayout=" + performLayout);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700393
394 boolean runningAppAnimation = false;
395
396 if (transit != AppTransition.TRANSIT_UNSET) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200397 if (applyAnimationLocked(lp, transit, visible, isVoiceInteraction)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700398 delayed = runningAppAnimation = true;
399 }
400 final WindowState window = findMainWindow();
401 //TODO (multidisplay): Magnification is supported only for the default display.
402 if (window != null && accessibilityController != null
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700403 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700404 accessibilityController.onAppWindowTransitionLocked(window, transit);
405 }
406 changed = true;
407 }
408
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700409 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700410 for (int i = 0; i < windowsCount; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700411 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700412 changed |= win.onAppVisibilityChanged(visible, runningAppAnimation);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700413 }
414
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200415 setHidden(!visible);
416 hiddenRequested = !visible;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700417 visibilityChanged = true;
418 if (!visible) {
419 stopFreezingScreen(true, true);
420 } else {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700421 // If we are being set visible, and the starting window is not yet displayed,
422 // then make sure it doesn't get displayed.
423 if (startingWindow != null && !startingWindow.isDrawnLw()) {
424 startingWindow.mPolicyVisibility = false;
425 startingWindow.mPolicyVisibilityAfterAnim = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700426 }
Jorim Jaggi38d44ec2017-06-14 16:04:59 -0700427
428 // We are becoming visible, so better freeze the screen with the windows that are
429 // getting visible so we also wait for them.
430 forAllWindows(mService::makeWindowFreezingScreenIfNeededLocked, true);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700431 }
432
433 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setVisibility: " + this
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200434 + ": hidden=" + isHidden() + " hiddenRequested=" + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700435
436 if (changed) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700437 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700438 if (performLayout) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700439 mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700440 false /*updateInputWindows*/);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700441 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700442 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700443 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700444 }
445 }
446
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200447 if (isReallyAnimating()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700448 delayed = true;
449 }
450
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700451 for (int i = mChildren.size() - 1; i >= 0 && !delayed; i--) {
Jorim Jaggia5e10572017-11-15 14:36:26 +0100452 if ((mChildren.get(i)).isSelfOrChildAnimating()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700453 delayed = true;
454 }
455 }
456
457 if (visibilityChanged) {
458 if (visible && !delayed) {
459 // The token was made immediately visible, there will be no entrance animation.
460 // We need to inform the client the enter animation was finished.
461 mEnteringAnimation = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700462 mService.mActivityManagerAppTransitionNotifier.onAppTransitionFinishedLocked(token);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700463 }
Robert Carr61b81112017-07-17 18:08:15 -0700464
Robert Carre7cc44d2017-03-20 19:04:30 -0700465 // If we are hidden but there is no delay needed we immediately
466 // apply the Surface transaction so that the ActivityManager
Robert Carr61b81112017-07-17 18:08:15 -0700467 // can have some guarantee on the Surface state following
468 // setting the visibility. This captures cases like dismissing
469 // the docked or pinned stack where there is no app transition.
470 //
471 // In the case of a "Null" animation, there will be
472 // no animation but there will still be a transition set.
473 // We still need to delay hiding the surface such that it
474 // can be synchronized with showing the next surface in the transition.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200475 if (isHidden() && !delayed && !mService.mAppTransition.isTransitionSet()) {
Robert Carr6914f082017-03-20 19:04:30 -0700476 SurfaceControl.openTransaction();
477 for (int i = mChildren.size() - 1; i >= 0; i--) {
478 mChildren.get(i).mWinAnimator.hide("immediately hidden");
479 }
480 SurfaceControl.closeTransaction();
481 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700482
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700483 if (!mService.mClosingApps.contains(this) && !mService.mOpeningApps.contains(this)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700484 // The token is not closing nor opening, so even if there is an animation set, that
485 // doesn't mean that it goes through the normal app transition cycle so we have
486 // to inform the docked controller about visibility change.
Andrii Kulian1e32e022016-09-16 15:29:34 -0700487 // TODO(multi-display): notify docked divider on all displays where visibility was
488 // affected.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700489 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700490 .notifyAppVisibilityChanged();
Jorim Jaggi8b702ed2017-01-20 16:59:03 +0100491 mService.mTaskSnapshotController.notifyAppVisibilityChanged(this, visible);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700492 }
493 }
494
495 return delayed;
496 }
497
Jorim Jaggi87fdbcb2017-08-17 13:41:11 +0200498 /**
499 * @return The to top most child window for which {@link LayoutParams#isFullscreen()} returns
500 * true.
501 */
502 WindowState getTopFullscreenWindow() {
503 for (int i = mChildren.size() - 1; i >= 0; i--) {
504 final WindowState win = mChildren.get(i);
505 if (win != null && win.mAttrs.isFullscreen()) {
506 return win;
507 }
508 }
509 return null;
510 }
511
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800512 WindowState findMainWindow() {
Matthew Ng53e66b22018-01-12 17:13:13 -0800513 return findMainWindow(true);
514 }
515
516 /**
517 * Finds the main window that either has type base application or application starting if
518 * requested.
519 *
520 * @param includeStartingApp Allow to search application-starting windows to also be returned.
521 * @return The main window of type base application or application starting if requested.
522 */
523 WindowState findMainWindow(boolean includeStartingApp) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700524 WindowState candidate = null;
Matthew Ng53e66b22018-01-12 17:13:13 -0800525 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700526 final WindowState win = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700527 final int type = win.mAttrs.type;
528 // No need to loop through child window as base application and starting types can't be
529 // child windows.
Matthew Ng53e66b22018-01-12 17:13:13 -0800530 if (type == TYPE_BASE_APPLICATION
531 || (includeStartingApp && type == TYPE_APPLICATION_STARTING)) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700532 // In cases where there are multiple windows, we prefer the non-exiting window. This
Sungsoo Lim0d3d1f82015-12-02 14:47:59 +0900533 // happens for example when replacing windows during an activity relaunch. When
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700534 // constructing the animation, we want the new window, not the exiting one.
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800535 if (win.mAnimatingExit) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700536 candidate = win;
537 } else {
538 return win;
539 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800540 }
541 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700542 return candidate;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800543 }
544
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800545 boolean windowsAreFocusable() {
Wale Ogunwale3382ab12017-07-27 08:55:03 -0700546 return getWindowConfiguration().canReceiveKeys() || mAlwaysFocusable;
Wale Ogunwaled045c822015-12-02 09:14:28 -0800547 }
548
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800549 AppWindowContainerController getController() {
550 final WindowContainerController controller = super.getController();
551 return controller != null ? (AppWindowContainerController) controller : null;
552 }
553
Wale Ogunwale571771c2016-08-26 13:18:50 -0700554 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -0700555 boolean isVisible() {
Wale Ogunwalee471be62016-10-03 07:53:55 -0700556 // If the app token isn't hidden then it is considered visible and there is no need to check
557 // its children windows to see if they are visible.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200558 return !isHidden();
Wale Ogunwale44f21802016-09-02 12:49:48 -0700559 }
560
561 @Override
Wale Ogunwalee287e192017-04-21 09:30:12 -0700562 void removeImmediately() {
563 onRemovedFromDisplay();
564 super.removeImmediately();
565 }
566
567 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -0700568 void removeIfPossible() {
Craig Mautnere3119b72015-01-20 15:02:36 -0800569 mIsExiting = false;
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800570 removeAllWindowsIfPossible();
Bryce Lee6d410262017-02-28 15:30:17 -0800571 removeImmediately();
Craig Mautnere3119b72015-01-20 15:02:36 -0800572 }
573
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700574 @Override
575 boolean checkCompleteDeferredRemoval() {
576 if (mIsExiting) {
577 removeIfPossible();
578 }
579 return super.checkCompleteDeferredRemoval();
580 }
581
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700582 void onRemovedFromDisplay() {
Wale Ogunwalee287e192017-04-21 09:30:12 -0700583 if (mRemovingFromDisplay) {
584 return;
585 }
586 mRemovingFromDisplay = true;
587
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700588 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app token: " + this);
589
Wale Ogunwale72919d22016-12-08 18:58:50 -0800590 boolean delayed = setVisibility(null, false, TRANSIT_UNSET, true, mVoiceInteraction);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700591
592 mService.mOpeningApps.remove(this);
Jorim Jaggi45ca0542017-05-30 16:16:01 -0700593 mService.mUnknownAppVisibilityController.appRemovedOrHidden(this);
Jorim Jaggi10abe2f2017-01-03 16:44:46 +0100594 mService.mTaskSnapshotController.onAppRemoved(this);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700595 waitingToShow = false;
596 if (mService.mClosingApps.contains(this)) {
597 delayed = true;
598 } else if (mService.mAppTransition.isTransitionSet()) {
599 mService.mClosingApps.add(this);
600 delayed = true;
601 }
602
603 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app " + this + " delayed=" + delayed
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200604 + " animation=" + getAnimation() + " animating=" + isSelfAnimating());
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700605
606 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM, "removeAppToken: "
607 + this + " delayed=" + delayed + " Callers=" + Debug.getCallers(4));
608
Jorim Jaggi19be6052017-08-03 18:33:43 +0200609 if (startingData != null && getController() != null) {
610 getController().removeStartingWindow();
611 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800612
Winson Chung87e5d552017-04-05 11:49:38 -0700613 // If this window was animating, then we need to ensure that the app transition notifies
614 // that animations have completed in WMS.handleAnimatingStoppedAndTransitionLocked(), so
615 // add to that list now
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200616 if (isSelfAnimating()) {
Winson Chung87e5d552017-04-05 11:49:38 -0700617 mService.mNoAnimationNotifyOnTransitionFinished.add(token);
618 }
619
Wale Ogunwalee287e192017-04-21 09:30:12 -0700620 final TaskStack stack = getStack();
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700621 if (delayed && !isEmpty()) {
622 // set the token aside because it has an active animation to be finished
623 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM,
624 "removeAppToken make exiting: " + this);
Wale Ogunwalee287e192017-04-21 09:30:12 -0700625 if (stack != null) {
626 stack.mExitingAppTokens.add(this);
627 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700628 mIsExiting = true;
629 } else {
630 // Make sure there is no animation running on this token, so any windows associated
631 // with it will be removed as soon as their animations are complete
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200632 cancelAnimation();
Wale Ogunwale3106ae012017-05-16 08:56:37 -0700633 if (stack != null) {
634 stack.mExitingAppTokens.remove(this);
635 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700636 removeIfPossible();
637 }
638
639 removed = true;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700640 stopFreezingScreen(true, true);
Bryce Lee6d410262017-02-28 15:30:17 -0800641
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700642 if (mService.mFocusedApp == this) {
643 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "Removing focused app token:" + this);
644 mService.mFocusedApp = null;
645 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
646 mService.mInputMonitor.setFocusedAppLw(null);
647 }
648
649 if (!delayed) {
650 updateReportedVisibilityLocked();
651 }
Wale Ogunwalee287e192017-04-21 09:30:12 -0700652
653 mRemovingFromDisplay = false;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700654 }
655
Chong Zhange05bcb12016-07-26 17:47:29 -0700656 void clearAnimatingFlags() {
Chong Zhangb0d26702016-08-12 16:03:29 -0700657 boolean wallpaperMightChange = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700658 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700659 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700660 wallpaperMightChange |= win.clearAnimatingFlags();
Chong Zhange05bcb12016-07-26 17:47:29 -0700661 }
Chong Zhangb0d26702016-08-12 16:03:29 -0700662 if (wallpaperMightChange) {
663 requestUpdateWallpaperIfNeeded();
664 }
Chong Zhange05bcb12016-07-26 17:47:29 -0700665 }
666
Robert Carre12aece2016-02-02 22:43:27 -0800667 void destroySurfaces() {
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700668 destroySurfaces(false /*cleanupOnResume*/);
669 }
670
671 /**
672 * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure
673 * the client has finished with them.
674 *
675 * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If
676 * set to true, destroy only surfaces of removed windows, and clear relevant flags of the
677 * others so that they are ready to be reused. If set to false (common case), destroy all
678 * surfaces that's eligible, if the app is already stopped.
679 */
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700680 private void destroySurfaces(boolean cleanupOnResume) {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700681 boolean destroyedSomething = false;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100682
683 // Copying to a different list as multiple children can be removed.
Jorim Jaggi59f3e922018-01-05 15:40:32 +0100684 final ArrayList<WindowState> children = new ArrayList<>(mChildren);
Jorim Jaggia5e10572017-11-15 14:36:26 +0100685 for (int i = children.size() - 1; i >= 0; i--) {
686 final WindowState win = children.get(i);
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700687 destroyedSomething |= win.destroySurface(cleanupOnResume, mAppStopped);
Robert Carre12aece2016-02-02 22:43:27 -0800688 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700689 if (destroyedSomething) {
690 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700691 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Adrian Roos4d18a2e2017-12-19 19:08:05 +0100692 updateLetterbox(null);
Robert Carre12aece2016-02-02 22:43:27 -0800693 }
694 }
695
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800696 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700697 * Notify that the app is now resumed, and it was not stopped before, perform a clean
698 * up of the surfaces
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800699 */
Jorim Jaggibae01b12017-04-11 16:29:10 -0700700 void notifyAppResumed(boolean wasStopped) {
Chong Zhangad24f962016-08-25 12:12:33 -0700701 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped
Jorim Jaggibae01b12017-04-11 16:29:10 -0700702 + " " + this);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700703 mAppStopped = false;
chaviwd3bf08d2017-08-01 17:24:59 -0700704 // Allow the window to turn the screen on once the app is resumed again.
705 setCanTurnScreenOn(true);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700706 if (!wasStopped) {
707 destroySurfaces(true /*cleanupOnResume*/);
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800708 }
Robert Carre12aece2016-02-02 22:43:27 -0800709 }
710
Chong Zhangbef461f2015-10-27 11:38:24 -0700711 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700712 * Notify that the app has stopped, and it is okay to destroy any surfaces which were
713 * keeping alive in case they were still being used.
714 */
715 void notifyAppStopped() {
716 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this);
717 mAppStopped = true;
718 destroySurfaces();
719 // Remove any starting window that was added for this app if they are still around.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800720 if (getController() != null) {
721 getController().removeStartingWindow();
722 }
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700723 }
724
Chong Zhang92147042016-05-09 12:47:11 -0700725 void clearAllDrawn() {
726 allDrawn = false;
727 deferClearAllDrawn = false;
Chong Zhangbef461f2015-10-27 11:38:24 -0700728 }
729
Bryce Lee6d410262017-02-28 15:30:17 -0800730 Task getTask() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800731 return (Task) getParent();
Bryce Lee6d410262017-02-28 15:30:17 -0800732 }
733
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800734 TaskStack getStack() {
735 final Task task = getTask();
736 if (task != null) {
737 return task.mStack;
738 } else {
739 return null;
740 }
741 }
742
Bryce Lee6d410262017-02-28 15:30:17 -0800743 @Override
744 void onParentSet() {
745 super.onParentSet();
746
Robert Carred3e83b2017-04-21 13:26:55 -0700747 final Task task = getTask();
748
Bryce Lee6d410262017-02-28 15:30:17 -0800749 // When the associated task is {@code null}, the {@link AppWindowToken} can no longer
750 // access visual elements like the {@link DisplayContent}. We must remove any associations
751 // such as animations.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800752 if (!mReparenting) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800753 if (task == null) {
754 // It is possible we have been marked as a closing app earlier. We must remove ourselves
755 // from this list so we do not participate in any future animations.
756 mService.mClosingApps.remove(this);
Robert Carred3e83b2017-04-21 13:26:55 -0700757 } else if (mLastParent != null && mLastParent.mStack != null) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800758 task.mStack.mExitingAppTokens.remove(this);
759 }
Bryce Lee6d410262017-02-28 15:30:17 -0800760 }
Robert Carred3e83b2017-04-21 13:26:55 -0700761 mLastParent = task;
Bryce Lee6d410262017-02-28 15:30:17 -0800762 }
763
Wale Ogunwalefa854eb2016-09-20 13:43:52 -0700764 void postWindowRemoveStartingWindowCleanup(WindowState win) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700765 // TODO: Something smells about the code below...Is there a better way?
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700766 if (startingWindow == win) {
767 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800768 if (getController() != null) {
769 getController().removeStartingWindow();
770 }
Wale Ogunwale6c459212017-05-17 08:56:03 -0700771 } else if (mChildren.size() == 0) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700772 // If this is the last window and we had requested a starting transition window,
773 // well there is no point now.
Jorim Jaggi02886a82016-12-06 09:10:06 -0800774 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingData");
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700775 startingData = null;
Wale Ogunwale6c459212017-05-17 08:56:03 -0700776 if (mHiddenSetFromTransferredStartingWindow) {
777 // We set the hidden state to false for the token from a transferred starting window.
778 // We now reset it back to true since the starting window was the last window in the
779 // token.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200780 setHidden(true);
Wale Ogunwale6c459212017-05-17 08:56:03 -0700781 }
Jorim Jaggi829b9cd2017-01-23 16:20:53 +0100782 } else if (mChildren.size() == 1 && startingSurface != null && !isRelaunching()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700783 // If this is the last window except for a starting transition window,
784 // we need to get rid of the starting transition.
Jorim Jaggie4b0f282017-05-17 15:10:29 +0200785 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Last window, removing starting window "
786 + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800787 if (getController() != null) {
788 getController().removeStartingWindow();
789 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700790 }
791 }
792
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700793 void removeDeadWindows() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700794 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700795 WindowState win = mChildren.get(winNdx);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800796 if (win.mAppDied) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700797 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700798 "removeDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800799 // Set mDestroying, we don't want any animation or delayed removal here.
800 win.mDestroying = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700801 // Also removes child windows.
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700802 win.removeIfPossible();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800803 }
804 }
805 }
806
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700807 boolean hasWindowsAlive() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700808 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700809 // No need to loop through child windows as the answer should be the same as that of the
810 // parent window.
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700811 if (!(mChildren.get(i)).mAppDied) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700812 return true;
813 }
814 }
815 return false;
816 }
817
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700818 void setWillReplaceWindows(boolean animate) {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700819 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
820 "Marking app token " + this + " with replacing windows.");
Robert Carra1eb4392015-12-10 12:43:51 -0800821
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700822 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700823 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700824 w.setWillReplaceWindow(animate);
Robert Carra1eb4392015-12-10 12:43:51 -0800825 }
Robert Carra1eb4392015-12-10 12:43:51 -0800826 }
827
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700828 void setWillReplaceChildWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700829 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this
Robert Carr23fa16b2016-01-13 13:19:58 -0800830 + " with replacing child windows.");
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700831 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700832 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700833 w.setWillReplaceChildWindows();
Robert Carr23fa16b2016-01-13 13:19:58 -0800834 }
835 }
836
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700837 void clearWillReplaceWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700838 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
839 "Resetting app token " + this + " of replacing window marks.");
Chong Zhangf596cd52016-01-05 13:42:44 -0800840
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700841 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700842 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700843 w.clearWillReplaceWindow();
Chong Zhangf596cd52016-01-05 13:42:44 -0800844 }
845 }
846
Chong Zhang4d7369a2016-04-25 16:09:14 -0700847 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700848 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700849 final WindowState w = mChildren.get(i);
Chong Zhang4d7369a2016-04-25 16:09:14 -0700850 w.requestUpdateWallpaperIfNeeded();
851 }
852 }
853
Chong Zhangd78ddb42016-03-02 17:01:14 -0800854 boolean isRelaunching() {
855 return mPendingRelaunchCount > 0;
856 }
857
Robert Carr68375192017-06-13 12:41:53 -0700858 boolean shouldFreezeBounds() {
859 final Task task = getTask();
860
861 // For freeform windows, we can't freeze the bounds at the moment because this would make
862 // the resizing unresponsive.
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700863 if (task == null || task.inFreeformWindowingMode()) {
Robert Carr68375192017-06-13 12:41:53 -0700864 return false;
865 }
866
867 // We freeze the bounds while drag resizing to deal with the time between
868 // the divider/drag handle being released, and the handling it's new
869 // configuration. If we are relaunched outside of the drag resizing state,
870 // we need to be careful not to do this.
871 return getTask().isDragResizing();
872 }
873
Chong Zhangd78ddb42016-03-02 17:01:14 -0800874 void startRelaunching() {
Robert Carr68375192017-06-13 12:41:53 -0700875 if (shouldFreezeBounds()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -0800876 freezeBounds();
877 }
Robert Carrd5c7dd62017-03-08 10:39:30 -0800878
879 // In the process of tearing down before relaunching, the app will
880 // try and clean up it's child surfaces. We need to prevent this from
881 // happening, so we sever the children, transfering their ownership
882 // from the client it-self to the parent surface (owned by us).
883 for (int i = mChildren.size() - 1; i >= 0; i--) {
884 final WindowState w = mChildren.get(i);
885 w.mWinAnimator.detachChildren();
886 }
887
Chong Zhangd78ddb42016-03-02 17:01:14 -0800888 mPendingRelaunchCount++;
889 }
890
891 void finishRelaunching() {
Robert Carr68375192017-06-13 12:41:53 -0700892 unfreezeBounds();
893
Chong Zhangd78ddb42016-03-02 17:01:14 -0800894 if (mPendingRelaunchCount > 0) {
895 mPendingRelaunchCount--;
Bryce Lee081554b2017-05-25 07:52:12 -0700896 } else {
897 // Update keyguard flags upon finishing relaunch.
898 checkKeyguardFlagsChanged();
Chong Zhangd78ddb42016-03-02 17:01:14 -0800899 }
900 }
901
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700902 void clearRelaunching() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700903 if (mPendingRelaunchCount == 0) {
904 return;
905 }
Robert Carr68375192017-06-13 12:41:53 -0700906 unfreezeBounds();
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700907 mPendingRelaunchCount = 0;
908 }
909
Wale Ogunwale07bcab72016-10-14 15:30:09 -0700910 /**
911 * Returns true if the new child window we are adding to this token is considered greater than
912 * the existing child window in this token in terms of z-order.
913 */
914 @Override
915 protected boolean isFirstChildWindowGreaterThanSecond(WindowState newWindow,
916 WindowState existingWindow) {
917 final int type1 = newWindow.mAttrs.type;
918 final int type2 = existingWindow.mAttrs.type;
919
920 // Base application windows should be z-ordered BELOW all other windows in the app token.
921 if (type1 == TYPE_BASE_APPLICATION && type2 != TYPE_BASE_APPLICATION) {
922 return false;
923 } else if (type1 != TYPE_BASE_APPLICATION && type2 == TYPE_BASE_APPLICATION) {
924 return true;
925 }
926
927 // Starting windows should be z-ordered ABOVE all other windows in the app token.
928 if (type1 == TYPE_APPLICATION_STARTING && type2 != TYPE_APPLICATION_STARTING) {
929 return true;
930 } else if (type1 != TYPE_APPLICATION_STARTING && type2 == TYPE_APPLICATION_STARTING) {
931 return false;
932 }
933
934 // Otherwise the new window is greater than the existing window.
935 return true;
936 }
937
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700938 @Override
Robert Carra1eb4392015-12-10 12:43:51 -0800939 void addWindow(WindowState w) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700940 super.addWindow(w);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700941
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700942 boolean gotReplacementWindow = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700943 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700944 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700945 gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w);
946 }
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700947
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700948 // if we got a replacement window, reset the timeout to give drawing more time
949 if (gotReplacementWindow) {
950 mService.scheduleWindowReplacementTimeouts(this);
Robert Carra1eb4392015-12-10 12:43:51 -0800951 }
Jorim Jaggife762342016-10-13 14:33:27 +0200952 checkKeyguardFlagsChanged();
953 }
954
955 @Override
956 void removeChild(WindowState child) {
957 super.removeChild(child);
958 checkKeyguardFlagsChanged();
Adrian Roos4d18a2e2017-12-19 19:08:05 +0100959 updateLetterbox(child);
Robert Carra1eb4392015-12-10 12:43:51 -0800960 }
961
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700962 private boolean waitingForReplacement() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700963 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700964 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700965 if (candidate.waitingForReplacement()) {
Robert Carra1eb4392015-12-10 12:43:51 -0800966 return true;
967 }
968 }
969 return false;
970 }
971
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700972 void onWindowReplacementTimeout() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700973 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700974 (mChildren.get(i)).onWindowReplacementTimeout();
Robert Carra1eb4392015-12-10 12:43:51 -0800975 }
976 }
977
Winson Chung30480042017-01-26 10:55:34 -0800978 void reparent(Task task, int position) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800979 final Task currentTask = getTask();
980 if (task == currentTask) {
Winson Chung30480042017-01-26 10:55:34 -0800981 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800982 "window token=" + this + " already child of task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -0800983 }
Bryce Lee6d410262017-02-28 15:30:17 -0800984
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800985 if (currentTask.mStack != task.mStack) {
Bryce Lee6d410262017-02-28 15:30:17 -0800986 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800987 "window token=" + this + " current task=" + currentTask
Bryce Lee6d410262017-02-28 15:30:17 -0800988 + " belongs to a different stack than " + task);
989 }
990
Winson Chung30480042017-01-26 10:55:34 -0800991 if (DEBUG_ADD_REMOVE) Slog.i(TAG, "reParentWindowToken: removing window token=" + this
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800992 + " from task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -0800993 final DisplayContent prevDisplayContent = getDisplayContent();
994
Bryce Lee6d410262017-02-28 15:30:17 -0800995 mReparenting = true;
996
Winson Chung30480042017-01-26 10:55:34 -0800997 getParent().removeChild(this);
998 task.addChild(this, position);
999
Bryce Lee6d410262017-02-28 15:30:17 -08001000 mReparenting = false;
1001
Winson Chung30480042017-01-26 10:55:34 -08001002 // Relayout display(s).
1003 final DisplayContent displayContent = task.getDisplayContent();
1004 displayContent.setLayoutNeeded();
1005 if (prevDisplayContent != displayContent) {
1006 onDisplayChanged(displayContent);
1007 prevDisplayContent.setLayoutNeeded();
1008 }
1009 }
1010
Jorim Jaggi0429f352015-12-22 16:29:16 +01001011 /**
1012 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
1013 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
1014 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
1015 * with a queue.
1016 */
Chong Zhangd78ddb42016-03-02 17:01:14 -08001017 private void freezeBounds() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001018 final Task task = getTask();
1019 mFrozenBounds.offer(new Rect(task.mPreparedFrozenBounds));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001020
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001021 if (task.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) {
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001022 // We didn't call prepareFreezingBounds on the task, so use the current value.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001023 mFrozenMergedConfig.offer(new Configuration(task.getConfiguration()));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001024 } else {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001025 mFrozenMergedConfig.offer(new Configuration(task.mPreparedFrozenMergedConfig));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001026 }
Andrii Kulianb10330d2016-09-16 13:51:46 -07001027 // Calling unset() to make it equal to Configuration.EMPTY.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001028 task.mPreparedFrozenMergedConfig.unset();
Jorim Jaggi0429f352015-12-22 16:29:16 +01001029 }
1030
1031 /**
1032 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
1033 */
Chong Zhangd78ddb42016-03-02 17:01:14 -08001034 private void unfreezeBounds() {
Robert Carr68375192017-06-13 12:41:53 -07001035 if (mFrozenBounds.isEmpty()) {
1036 return;
Wale Ogunwale37dbafc2016-06-27 10:15:20 -07001037 }
Robert Carr68375192017-06-13 12:41:53 -07001038 mFrozenBounds.remove();
Wale Ogunwale37dbafc2016-06-27 10:15:20 -07001039 if (!mFrozenMergedConfig.isEmpty()) {
1040 mFrozenMergedConfig.remove();
1041 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001042 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001043 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001044 win.onUnfreezeBounds();
Jorim Jaggi4846ee32016-01-07 17:39:12 +01001045 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001046 mService.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +01001047 }
1048
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001049 void setAppLayoutChanges(int changes, String reason) {
1050 if (!mChildren.isEmpty()) {
1051 final DisplayContent dc = getDisplayContent();
1052 dc.pendingLayoutChanges |= changes;
1053 if (DEBUG_LAYOUT_REPEATS) {
1054 mService.mWindowPlacerLocked.debugLayoutRepeats(reason, dc.pendingLayoutChanges);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001055 }
1056 }
1057 }
1058
1059 void removeReplacedWindowIfNeeded(WindowState replacement) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001060 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001061 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001062 if (win.removeReplacedWindowIfNeeded(replacement)) {
1063 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001064 }
1065 }
1066 }
1067
1068 void startFreezingScreen() {
1069 if (DEBUG_ORIENTATION) logWithStack(TAG, "Set freezing of " + appToken + ": hidden="
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001070 + isHidden() + " freezing=" + mFreezingScreen + " hiddenRequested="
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001071 + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001072 if (!hiddenRequested) {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001073 if (!mFreezingScreen) {
1074 mFreezingScreen = true;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001075 mService.registerAppFreezeListener(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001076 mService.mAppsFreezingScreen++;
1077 if (mService.mAppsFreezingScreen == 1) {
Bryce Lee8f853582017-06-05 17:25:59 -07001078 mService.startFreezingDisplayLocked(false, 0, 0, getDisplayContent());
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001079 mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT);
1080 mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001081 }
1082 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001083 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001084 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001085 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001086 w.onStartFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001087 }
1088 }
1089 }
1090
1091 void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001092 if (!mFreezingScreen) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001093 return;
1094 }
1095 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + this + " force=" + force);
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001096 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001097 boolean unfrozeWindows = false;
1098 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001099 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001100 unfrozeWindows |= w.onStopFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001101 }
1102 if (force || unfrozeWindows) {
1103 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this);
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001104 mFreezingScreen = false;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001105 mService.unregisterAppFreezeListener(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001106 mService.mAppsFreezingScreen--;
1107 mService.mLastFinishedFreezeSource = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001108 }
1109 if (unfreezeSurfaceNow) {
1110 if (unfrozeWindows) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001111 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001112 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001113 mService.stopFreezingDisplayLocked();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001114 }
1115 }
1116
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001117 @Override
1118 public void onAppFreezeTimeout() {
1119 Slog.w(TAG_WM, "Force clearing freeze: " + this);
1120 stopFreezingScreen(true, true);
1121 }
1122
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001123 boolean transferStartingWindow(IBinder transferFrom) {
Wale Ogunwale02319a62016-09-26 15:21:22 -07001124 final AppWindowToken fromToken = getDisplayContent().getAppWindowToken(transferFrom);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001125 if (fromToken == null) {
1126 return false;
1127 }
1128
1129 final WindowState tStartingWindow = fromToken.startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001130 if (tStartingWindow != null && fromToken.startingSurface != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001131 // In this case, the starting icon has already been displayed, so start
1132 // letting windows get shown immediately without any more transitions.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001133 mService.mSkipAppTransitionAnimation = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001134
1135 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow
1136 + " from " + fromToken + " to " + this);
1137
1138 final long origId = Binder.clearCallingIdentity();
Peter Visontay3556a3b2017-11-01 17:23:17 +00001139 try {
1140 // Transfer the starting window over to the new token.
1141 startingData = fromToken.startingData;
1142 startingSurface = fromToken.startingSurface;
1143 startingDisplayed = fromToken.startingDisplayed;
1144 fromToken.startingDisplayed = false;
1145 startingWindow = tStartingWindow;
1146 reportedVisible = fromToken.reportedVisible;
1147 fromToken.startingData = null;
1148 fromToken.startingSurface = null;
1149 fromToken.startingWindow = null;
1150 fromToken.startingMoved = true;
1151 tStartingWindow.mToken = this;
1152 tStartingWindow.mAppToken = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001153
Peter Visontay3556a3b2017-11-01 17:23:17 +00001154 if (DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1155 "Removing starting " + tStartingWindow + " from " + fromToken);
1156 fromToken.removeChild(tStartingWindow);
1157 fromToken.postWindowRemoveStartingWindowCleanup(tStartingWindow);
1158 fromToken.mHiddenSetFromTransferredStartingWindow = false;
1159 addWindow(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001160
Peter Visontay3556a3b2017-11-01 17:23:17 +00001161 // Propagate other interesting state between the tokens. If the old token is displayed,
1162 // we should immediately force the new one to be displayed. If it is animating, we need
1163 // to move that animation to the new one.
1164 if (fromToken.allDrawn) {
1165 allDrawn = true;
1166 deferClearAllDrawn = fromToken.deferClearAllDrawn;
1167 }
1168 if (fromToken.firstWindowDrawn) {
1169 firstWindowDrawn = true;
1170 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001171 if (!fromToken.isHidden()) {
1172 setHidden(false);
Peter Visontay3556a3b2017-11-01 17:23:17 +00001173 hiddenRequested = false;
1174 mHiddenSetFromTransferredStartingWindow = true;
1175 }
1176 setClientHidden(fromToken.mClientHidden);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001177
Jorim Jaggi980c9de2017-11-17 01:41:37 +01001178 transferAnimation(fromToken);
1179
1180 // When transferring an animation, we no longer need to apply an animation to the
1181 // the token we transfer the animation over. Thus, remove the animation from
1182 // pending opening apps.
1183 mService.mOpeningApps.remove(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001184
Peter Visontay3556a3b2017-11-01 17:23:17 +00001185 mService.updateFocusedWindowLocked(
1186 UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/);
1187 getDisplayContent().setLayoutNeeded();
1188 mService.mWindowPlacerLocked.performSurfacePlacement();
1189 } finally {
1190 Binder.restoreCallingIdentity(origId);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001191 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001192 return true;
1193 } else if (fromToken.startingData != null) {
1194 // The previous app was getting ready to show a
1195 // starting window, but hasn't yet done so. Steal it!
1196 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1197 "Moving pending starting from " + fromToken + " to " + this);
1198 startingData = fromToken.startingData;
1199 fromToken.startingData = null;
1200 fromToken.startingMoved = true;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001201 if (getController() != null) {
1202 getController().scheduleAddStartingWindow();
1203 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001204 return true;
1205 }
1206
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001207 // TODO: Transfer thumbnail
1208
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001209 return false;
1210 }
1211
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001212 boolean isLastWindow(WindowState win) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001213 return mChildren.size() == 1 && mChildren.get(0) == win;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001214 }
1215
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001216 @Override
1217 void onAppTransitionDone() {
1218 sendingToBottom = false;
1219 }
1220
Wale Ogunwale51362492016-09-08 17:49:17 -07001221 /**
1222 * We override because this class doesn't want its children affecting its reported orientation
1223 * in anyway.
1224 */
1225 @Override
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001226 int getOrientation(int candidate) {
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001227 if (candidate == SCREEN_ORIENTATION_BEHIND) {
1228 // Allow app to specify orientation regardless of its visibility state if the current
1229 // candidate want us to use orientation behind. I.e. the visible app on-top of this one
1230 // wants us to use the orientation of the app behind it.
1231 return mOrientation;
1232 }
1233
Bryce Lee61fbcbc2017-03-10 14:14:03 -08001234 // The {@link AppWindowToken} should only specify an orientation when it is not closing or
1235 // going to the bottom. Allowing closing {@link AppWindowToken} to participate can lead to
1236 // an Activity in another task being started in the wrong orientation during the transition.
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001237 if (!(sendingToBottom || mService.mClosingApps.contains(this))
Bryce Lee00d586d2017-07-28 20:48:43 -07001238 && (isVisible() || mService.mOpeningApps.contains(this) || isOnTop())) {
Bryce Leea163b762017-01-24 11:05:01 -08001239 return mOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001240 }
Bryce Leea163b762017-01-24 11:05:01 -08001241
1242 return SCREEN_ORIENTATION_UNSET;
Wale Ogunwale51362492016-09-08 17:49:17 -07001243 }
1244
Wale Ogunwaleb198b742016-12-01 08:44:09 -08001245 /** Returns the app's preferred orientation regardless of its currently visibility state. */
1246 int getOrientationIgnoreVisibility() {
1247 return mOrientation;
1248 }
1249
Craig Mautnerdbb79912012-03-01 18:59:14 -08001250 @Override
Winson Chunge55c0192017-08-24 14:50:48 -07001251 public void onConfigurationChanged(Configuration newParentConfig) {
1252 final int prevWinMode = getWindowingMode();
1253 super.onConfigurationChanged(newParentConfig);
1254 final int winMode = getWindowingMode();
1255
1256 if (prevWinMode == winMode) {
1257 return;
1258 }
1259
1260 if (prevWinMode != WINDOWING_MODE_UNDEFINED && winMode == WINDOWING_MODE_PINNED) {
1261 // Entering PiP from fullscreen, reset the snap fraction
1262 mDisplayContent.mPinnedStackControllerLocked.resetReentrySnapFraction(this);
1263 } else if (prevWinMode == WINDOWING_MODE_PINNED && winMode != WINDOWING_MODE_UNDEFINED) {
1264 // Leaving PiP to fullscreen, save the snap fraction based on the pre-animation bounds
1265 // for the next re-entry into PiP (assuming the activity is not hidden or destroyed)
1266 final TaskStack pinnedStack = mDisplayContent.getPinnedStack();
1267 if (pinnedStack != null) {
1268 mDisplayContent.mPinnedStackControllerLocked.saveReentrySnapFraction(this,
1269 pinnedStack.mPreAnimationBounds);
1270 }
1271 }
1272 }
1273
1274 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001275 void checkAppWindowsReadyToShow() {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001276 if (allDrawn == mLastAllDrawn) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001277 return;
1278 }
1279
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001280 mLastAllDrawn = allDrawn;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001281 if (!allDrawn) {
1282 return;
1283 }
1284
1285 // The token has now changed state to having all windows shown... what to do, what to do?
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001286 if (mFreezingScreen) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001287 showAllWindowsLocked();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001288 stopFreezingScreen(false, true);
1289 if (DEBUG_ORIENTATION) Slog.i(TAG,
1290 "Setting mOrientationChangeComplete=true because wtoken " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001291 + " numInteresting=" + mNumInterestingWindows + " numDrawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001292 // This will set mOrientationChangeComplete and cause a pass through layout.
1293 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001294 "checkAppWindowsReadyToShow: freezingScreen");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001295 } else {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001296 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001297
1298 // We can now show all of the drawn windows!
1299 if (!mService.mOpeningApps.contains(this)) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001300 showAllWindowsLocked();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001301 }
1302 }
1303 }
1304
Matthew Ng5d23afa2017-06-21 16:16:24 -07001305 /**
Bryce Leed390deb2017-06-22 13:14:28 -07001306 * Returns whether the drawn window states of this {@link AppWindowToken} has considered every
1307 * child {@link WindowState}. A child is considered if it has been passed into
1308 * {@link #updateDrawnWindowStates(WindowState)} after being added. This is used to determine
1309 * whether states, such as {@code allDrawn}, can be set, which relies on state variables such as
1310 * {@code mNumInterestingWindows}, which depend on all {@link WindowState}s being considered.
1311 *
1312 * @return {@code true} If all children have been considered, {@code false}.
1313 */
1314 private boolean allDrawnStatesConsidered() {
Bryce Lee6311c4b2017-07-06 14:09:29 -07001315 for (int i = mChildren.size() - 1; i >= 0; --i) {
1316 final WindowState child = mChildren.get(i);
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001317 if (child.mightAffectAllDrawn() && !child.getDrawnStateEvaluated()) {
Bryce Leed390deb2017-06-22 13:14:28 -07001318 return false;
1319 }
1320 }
1321 return true;
1322 }
1323
1324 /**
Matthew Ng5d23afa2017-06-21 16:16:24 -07001325 * Determines if the token has finished drawing. This should only be called from
1326 * {@link DisplayContent#applySurfaceChangesTransaction}
1327 */
Matthew Ng498c71d2017-04-18 13:55:45 -07001328 void updateAllDrawn() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001329 if (!allDrawn) {
Matthew Ng498c71d2017-04-18 13:55:45 -07001330 // Number of drawn windows can be less when a window is being relaunched, wait for
Bryce Leed390deb2017-06-22 13:14:28 -07001331 // all windows to be launched and drawn for this token be considered all drawn.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001332 final int numInteresting = mNumInterestingWindows;
Bryce Leed390deb2017-06-22 13:14:28 -07001333
1334 // We must make sure that all present children have been considered (determined by
1335 // {@link #allDrawnStatesConsidered}) before evaluating whether everything has been
1336 // drawn.
1337 if (numInteresting > 0 && allDrawnStatesConsidered()
1338 && mNumDrawnWindows >= numInteresting && !isRelaunching()) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001339 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawn: " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001340 + " interesting=" + numInteresting + " drawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001341 allDrawn = true;
1342 // Force an additional layout pass where
1343 // WindowStateAnimator#commitFinishDrawingLocked() will call performShowLocked().
Matthew Ng498c71d2017-04-18 13:55:45 -07001344 if (mDisplayContent != null) {
1345 mDisplayContent.setLayoutNeeded();
1346 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001347 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Robert Carrecc06b32017-04-18 14:25:10 -07001348
Winson Chunge7ba6862017-05-24 12:13:33 -07001349 // Notify the pinned stack upon all windows drawn. If there was an animation in
1350 // progress then this signal will resume that animation.
Wale Ogunwale61911492017-10-11 08:50:50 -07001351 final TaskStack pinnedStack = mDisplayContent.getPinnedStack();
Winson Chunge7ba6862017-05-24 12:13:33 -07001352 if (pinnedStack != null) {
1353 pinnedStack.onAllWindowsDrawn();
Robert Carrecc06b32017-04-18 14:25:10 -07001354 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001355 }
1356 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001357 }
1358
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001359 /**
1360 * Updated this app token tracking states for interesting and drawn windows based on the window.
1361 *
1362 * @return Returns true if the input window is considered interesting and drawn while all the
1363 * windows in this app token where not considered drawn as of the last pass.
1364 */
1365 boolean updateDrawnWindowStates(WindowState w) {
Bryce Leed390deb2017-06-22 13:14:28 -07001366 w.setDrawnStateEvaluated(true /*evaluated*/);
1367
Jorim Jaggie4b0f282017-05-17 15:10:29 +02001368 if (DEBUG_STARTING_WINDOW_VERBOSE && w == startingWindow) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001369 Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" + w.isOnScreen()
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001370 + " allDrawn=" + allDrawn + " freezingScreen=" + mFreezingScreen);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001371 }
1372
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001373 if (allDrawn && !mFreezingScreen) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001374 return false;
1375 }
1376
1377 if (mLastTransactionSequence != mService.mTransactionSequence) {
1378 mLastTransactionSequence = mService.mTransactionSequence;
Matthew Ng53e66b22018-01-12 17:13:13 -08001379 mNumDrawnWindows = 0;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001380 startingDisplayed = false;
Matthew Ng53e66b22018-01-12 17:13:13 -08001381
1382 // There is the main base application window, even if it is exiting, wait for it
1383 mNumInterestingWindows = findMainWindow(false /* includeStartingApp */) != null ? 1 : 0;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001384 }
1385
1386 final WindowStateAnimator winAnimator = w.mWinAnimator;
1387
1388 boolean isInterestingAndDrawn = false;
1389
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001390 if (!allDrawn && w.mightAffectAllDrawn()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001391 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
1392 Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw()
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001393 + ", isAnimationSet=" + isSelfAnimating());
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001394 if (!w.isDrawnLw()) {
1395 Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController
1396 + " pv=" + w.mPolicyVisibility
1397 + " mDrawState=" + winAnimator.drawStateToString()
1398 + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001399 + " a=" + isSelfAnimating());
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001400 }
1401 }
1402
1403 if (w != startingWindow) {
1404 if (w.isInteresting()) {
Matthew Ng53e66b22018-01-12 17:13:13 -08001405 // Add non-main window as interesting since the main app has already been added
1406 if (findMainWindow(false /* includeStartingApp */) != w) {
1407 mNumInterestingWindows++;
1408 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001409 if (w.isDrawnLw()) {
1410 mNumDrawnWindows++;
1411
1412 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, "tokenMayBeDrawn: "
1413 + this + " w=" + w + " numInteresting=" + mNumInterestingWindows
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001414 + " freezingScreen=" + mFreezingScreen
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001415 + " mAppFreezing=" + w.mAppFreezing);
1416
1417 isInterestingAndDrawn = true;
1418 }
1419 }
1420 } else if (w.isDrawnLw()) {
Jorim Jaggi3878ca32017-02-02 17:13:05 -08001421 if (getController() != null) {
1422 getController().reportStartingWindowDrawn();
1423 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001424 startingDisplayed = true;
1425 }
1426 }
1427
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001428 return isInterestingAndDrawn;
1429 }
1430
Adrian Roos4d18a2e2017-12-19 19:08:05 +01001431 void updateLetterbox(WindowState winHint) {
1432 final WindowState w = findMainWindow();
1433 if (w != winHint && winHint != null && w != null) {
1434 return;
1435 }
1436 final boolean needsLetterbox = w != null && w.isLetterboxedAppWindow()
1437 && fillsParent() && w.hasDrawnLw();
1438 if (needsLetterbox) {
1439 if (mLetterbox == null) {
1440 mLetterbox = new Letterbox(() -> makeChildSurface(null));
1441 }
1442 mLetterbox.setDimensions(mPendingTransaction, getParent().getBounds(), w.mFrame);
1443 } else if (mLetterbox != null) {
1444 final SurfaceControl.Transaction t = new SurfaceControl.Transaction();
Adrian Roos2dfb7852018-01-15 13:41:37 +01001445 // Make sure we have a transaction here, in case we're called outside of a transaction.
1446 // This does not use mPendingTransaction, because SurfaceAnimator uses a
1447 // global transaction in onAnimationEnd.
Adrian Roos4d18a2e2017-12-19 19:08:05 +01001448 SurfaceControl.openTransaction();
1449 try {
1450 mLetterbox.hide(t);
1451 } finally {
Adrian Roos4d18a2e2017-12-19 19:08:05 +01001452 SurfaceControl.mergeToGlobalTransaction(t);
1453 SurfaceControl.closeTransaction();
1454 }
1455 }
1456 }
1457
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001458 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001459 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001460 // For legacy reasons we process the TaskStack.mExitingAppTokens first in DisplayContent
1461 // before the non-exiting app tokens. So, we skip the exiting app tokens here.
1462 // TODO: Investigate if we need to continue to do this or if we can just process them
1463 // in-order.
1464 if (mIsExiting && !waitingForReplacement()) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001465 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001466 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001467 return forAllWindowsUnchecked(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001468 }
1469
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001470 boolean forAllWindowsUnchecked(ToBooleanFunction<WindowState> callback,
1471 boolean traverseTopToBottom) {
1472 return super.forAllWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001473 }
1474
1475 @Override
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001476 AppWindowToken asAppWindowToken() {
1477 // I am an app window token!
1478 return this;
1479 }
1480
1481 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -07001482 boolean fillsParent() {
1483 return mFillsParent;
1484 }
1485
1486 void setFillsParent(boolean fillsParent) {
1487 mFillsParent = fillsParent;
1488 }
1489
Jorim Jaggife762342016-10-13 14:33:27 +02001490 boolean containsDismissKeyguardWindow() {
Bryce Lee081554b2017-05-25 07:52:12 -07001491 // Window state is transient during relaunch. We are not guaranteed to be frozen during the
1492 // entirety of the relaunch.
1493 if (isRelaunching()) {
1494 return mLastContainsDismissKeyguardWindow;
1495 }
1496
Jorim Jaggife762342016-10-13 14:33:27 +02001497 for (int i = mChildren.size() - 1; i >= 0; i--) {
1498 if ((mChildren.get(i).mAttrs.flags & FLAG_DISMISS_KEYGUARD) != 0) {
1499 return true;
1500 }
1501 }
1502 return false;
1503 }
1504
1505 boolean containsShowWhenLockedWindow() {
Bryce Lee081554b2017-05-25 07:52:12 -07001506 // When we are relaunching, it is possible for us to be unfrozen before our previous
1507 // windows have been added back. Using the cached value ensures that our previous
1508 // showWhenLocked preference is honored until relaunching is complete.
1509 if (isRelaunching()) {
1510 return mLastContainsShowWhenLockedWindow;
1511 }
1512
Jorim Jaggife762342016-10-13 14:33:27 +02001513 for (int i = mChildren.size() - 1; i >= 0; i--) {
1514 if ((mChildren.get(i).mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
1515 return true;
1516 }
1517 }
Bryce Lee081554b2017-05-25 07:52:12 -07001518
Jorim Jaggife762342016-10-13 14:33:27 +02001519 return false;
1520 }
1521
1522 void checkKeyguardFlagsChanged() {
1523 final boolean containsDismissKeyguard = containsDismissKeyguardWindow();
1524 final boolean containsShowWhenLocked = containsShowWhenLockedWindow();
1525 if (containsDismissKeyguard != mLastContainsDismissKeyguardWindow
1526 || containsShowWhenLocked != mLastContainsShowWhenLockedWindow) {
1527 mService.notifyKeyguardFlagsChanged(null /* callback */);
1528 }
1529 mLastContainsDismissKeyguardWindow = containsDismissKeyguard;
1530 mLastContainsShowWhenLockedWindow = containsShowWhenLocked;
1531 }
1532
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001533 WindowState getImeTargetBelowWindow(WindowState w) {
1534 final int index = mChildren.indexOf(w);
1535 if (index > 0) {
1536 final WindowState target = mChildren.get(index - 1);
1537 if (target.canBeImeTarget()) {
1538 return target;
1539 }
1540 }
1541 return null;
1542 }
1543
Winson Chungbe9be7f2017-06-28 10:55:22 -07001544 int getLowestAnimLayer() {
1545 for (int i = 0; i < mChildren.size(); i++) {
1546 final WindowState w = mChildren.get(i);
1547 if (w.mRemoved) {
1548 continue;
1549 }
1550 return w.mWinAnimator.mAnimLayer;
1551 }
1552 return Integer.MAX_VALUE;
1553 }
1554
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001555 WindowState getHighestAnimLayerWindow(WindowState currentTarget) {
1556 WindowState candidate = null;
1557 for (int i = mChildren.indexOf(currentTarget); i >= 0; i--) {
1558 final WindowState w = mChildren.get(i);
1559 if (w.mRemoved) {
1560 continue;
1561 }
1562 if (candidate == null || w.mWinAnimator.mAnimLayer >
1563 candidate.mWinAnimator.mAnimLayer) {
1564 candidate = w;
1565 }
1566 }
1567 return candidate;
1568 }
1569
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001570 /**
1571 * See {@link Activity#setDisablePreviewScreenshots}.
1572 */
1573 void setDisablePreviewScreenshots(boolean disable) {
Wale Ogunwale6c459212017-05-17 08:56:03 -07001574 mDisablePreviewScreenshots = disable;
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001575 }
1576
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001577 /**
chaviwd3bf08d2017-08-01 17:24:59 -07001578 * Sets whether the current launch can turn the screen on. See {@link #canTurnScreenOn()}
1579 */
1580 void setCanTurnScreenOn(boolean canTurnScreenOn) {
1581 mCanTurnScreenOn = canTurnScreenOn;
1582 }
1583
1584 /**
1585 * Indicates whether the current launch can turn the screen on. This is to prevent multiple
1586 * relayouts from turning the screen back on. The screen should only turn on at most
1587 * once per activity resume.
1588 *
1589 * @return true if the screen can be turned on.
1590 */
1591 boolean canTurnScreenOn() {
1592 return mCanTurnScreenOn;
1593 }
1594
1595 /**
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001596 * Retrieves whether we'd like to generate a snapshot that's based solely on the theme. This is
1597 * the case when preview screenshots are disabled {@link #setDisablePreviewScreenshots} or when
1598 * we can't take a snapshot for other reasons, for example, if we have a secure window.
1599 *
1600 * @return True if we need to generate an app theme snapshot, false if we'd like to take a real
1601 * screenshot.
1602 */
1603 boolean shouldUseAppThemeSnapshot() {
Wale Ogunwale6c459212017-05-17 08:56:03 -07001604 return mDisablePreviewScreenshots || forAllWindows(w -> (w.mAttrs.flags & FLAG_SECURE) != 0,
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001605 true /* topToBottom */);
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001606 }
1607
chaviw23ee71c2017-12-18 11:29:41 -08001608 @Override
Jorim Jaggi596a1992017-12-29 14:48:02 +01001609 public SurfaceControl getAnimationLeashParent() {
1610 return getAppAnimationLayer();
chaviw23ee71c2017-12-18 11:29:41 -08001611 }
1612
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001613 boolean applyAnimationLocked(WindowManager.LayoutParams lp, int transit, boolean enter,
1614 boolean isVoiceInteraction) {
1615
1616 if (mService.mDisableTransitionAnimation) {
1617 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1618 Slog.v(TAG_WM, "applyAnimation: transition animation is disabled. atoken=" + this);
1619 }
1620 cancelAnimation();
1621 return false;
1622 }
1623
1624 // Only apply an animation if the display isn't frozen. If it is frozen, there is no reason
1625 // to animate and it can cause strange artifacts when we unfreeze the display if some
1626 // different animation is running.
1627 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "AWT#applyAnimationLocked");
1628 if (okToAnimate()) {
1629 final Animation a = loadAnimation(lp, transit, enter, isVoiceInteraction);
1630 if (a != null) {
chaviw23ee71c2017-12-18 11:29:41 -08001631 final TaskStack stack = getStack();
1632 mTmpPoint.set(0, 0);
chaviw23012112017-12-20 15:29:04 -08001633 mTmpRect.setEmpty();
chaviw23ee71c2017-12-18 11:29:41 -08001634 if (stack != null) {
1635 stack.getRelativePosition(mTmpPoint);
chaviw23012112017-12-20 15:29:04 -08001636 stack.getBounds(mTmpRect);
chaviw977482a2017-12-28 11:35:53 -08001637 mTmpRect.offsetTo(0, 0);
chaviw23ee71c2017-12-18 11:29:41 -08001638 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001639 final AnimationAdapter adapter = new LocalAnimationAdapter(
chaviw23012112017-12-20 15:29:04 -08001640 new WindowAnimationSpec(a, mTmpPoint, mTmpRect,
1641 mService.mAppTransition.canSkipFirstFrame(),
1642 mService.mAppTransition.getAppStackClipMode()),
Jorim Jaggi2e3c31d2017-11-20 19:49:00 +01001643 mService.mSurfaceAnimationRunner);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001644 if (a.getZAdjustment() == Animation.ZORDER_TOP) {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001645 mNeedsZBoost = true;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001646 }
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001647 startAnimation(getPendingTransaction(), adapter, !isVisible());
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001648 mTransit = transit;
1649 mTransitFlags = mService.mAppTransition.getTransitFlags();
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001650 }
1651 } else {
1652 cancelAnimation();
1653 }
1654 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
1655
1656 return isReallyAnimating();
1657 }
1658
1659 private Animation loadAnimation(WindowManager.LayoutParams lp, int transit, boolean enter,
1660 boolean isVoiceInteraction) {
1661 final DisplayContent displayContent = getTask().getDisplayContent();
1662 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
1663 final int width = displayInfo.appWidth;
1664 final int height = displayInfo.appHeight;
1665 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG_WM,
1666 "applyAnimation: atoken=" + this);
1667
1668 // Determine the visible rect to calculate the thumbnail clip
1669 final WindowState win = findMainWindow();
1670 final Rect frame = new Rect(0, 0, width, height);
1671 final Rect displayFrame = new Rect(0, 0,
1672 displayInfo.logicalWidth, displayInfo.logicalHeight);
1673 final Rect insets = new Rect();
1674 final Rect stableInsets = new Rect();
1675 Rect surfaceInsets = null;
1676 final boolean freeform = win != null && win.inFreeformWindowingMode();
1677 if (win != null) {
1678 // Containing frame will usually cover the whole screen, including dialog windows.
1679 // For freeform workspace windows it will not cover the whole screen and it also
1680 // won't exactly match the final freeform window frame (e.g. when overlapping with
1681 // the status bar). In that case we need to use the final frame.
1682 if (freeform) {
1683 frame.set(win.mFrame);
Adrian Roos4d18a2e2017-12-19 19:08:05 +01001684 } else if (win.isLetterboxedAppWindow()) {
1685 frame.set(getTask().getBounds());
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001686 } else {
1687 frame.set(win.mContainingFrame);
1688 }
1689 surfaceInsets = win.getAttrs().surfaceInsets;
1690 insets.set(win.mContentInsets);
1691 stableInsets.set(win.mStableInsets);
1692 }
1693
1694 if (mLaunchTaskBehind) {
1695 // Differentiate the two animations. This one which is briefly on the screen
1696 // gets the !enter animation, and the other activity which remains on the
1697 // screen gets the enter animation. Both appear in the mOpeningApps set.
1698 enter = false;
1699 }
1700 if (DEBUG_APP_TRANSITIONS) Slog.d(TAG_WM, "Loading animation for app transition."
1701 + " transit=" + AppTransition.appTransitionToString(transit) + " enter=" + enter
1702 + " frame=" + frame + " insets=" + insets + " surfaceInsets=" + surfaceInsets);
1703 final Configuration displayConfig = displayContent.getConfiguration();
1704 final Animation a = mService.mAppTransition.loadAnimation(lp, transit, enter,
1705 displayConfig.uiMode, displayConfig.orientation, frame, displayFrame, insets,
1706 surfaceInsets, stableInsets, isVoiceInteraction, freeform, getTask().mTaskId);
1707 if (a != null) {
1708 if (DEBUG_ANIM) logWithStack(TAG, "Loaded animation " + a + " for " + this);
1709 final int containingWidth = frame.width();
1710 final int containingHeight = frame.height();
1711 a.initialize(containingWidth, containingHeight, width, height);
1712 a.scaleCurrentDuration(mService.getTransitionAnimationScaleLocked());
1713 }
1714 return a;
1715 }
1716
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001717 @Override
1718 protected void setLayer(Transaction t, int layer) {
1719 if (!mSurfaceAnimator.hasLeash()) {
1720 t.setLayer(mSurfaceControl, layer);
1721 }
1722 }
1723
1724 @Override
1725 protected void setRelativeLayer(Transaction t, SurfaceControl relativeTo, int layer) {
1726 if (!mSurfaceAnimator.hasLeash()) {
1727 t.setRelativeLayer(mSurfaceControl, relativeTo, layer);
1728 }
1729 }
1730
1731 @Override
1732 protected void reparentSurfaceControl(Transaction t, SurfaceControl newParent) {
1733 if (!mSurfaceAnimator.hasLeash()) {
1734 t.reparent(mSurfaceControl, newParent.getHandle());
1735 }
1736 }
1737
1738 @Override
1739 public void onAnimationLeashCreated(Transaction t, SurfaceControl leash) {
1740
1741 // The leash is parented to the animation layer. We need to preserve the z-order by using
1742 // the prefix order index, but we boost if necessary.
1743 int layer = getPrefixOrderIndex();
1744 if (mNeedsZBoost) {
1745 layer += Z_BOOST_BASE;
1746 }
1747 leash.setLayer(layer);
1748 }
1749
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001750 /**
1751 * This must be called while inside a transaction.
1752 */
1753 void showAllWindowsLocked() {
1754 forAllWindows(windowState -> {
1755 if (DEBUG_VISIBILITY) Slog.v(TAG, "performing show on: " + windowState);
1756 windowState.performShowLocked();
1757 }, false /* traverseTopToBottom */);
Jorim Jaggia5e10572017-11-15 14:36:26 +01001758 }
1759
1760 @Override
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001761 protected void onAnimationFinished() {
1762 super.onAnimationFinished();
1763
1764 mTransit = TRANSIT_UNSET;
1765 mTransitFlags = 0;
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001766 mNeedsZBoost = false;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001767
1768 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM | FINISH_LAYOUT_REDO_WALLPAPER,
1769 "AppWindowToken");
1770
Jorim Jaggi988f6682017-11-17 17:46:43 +01001771 clearThumbnail();
1772
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001773 if (mService.mInputMethodTarget != null && mService.mInputMethodTarget.mAppToken == this) {
1774 getDisplayContent().computeImeTarget(true /* updateImeTarget */);
1775 }
1776
1777 if (DEBUG_ANIM) Slog.v(TAG, "Animation done in " + this
1778 + ": reportedVisible=" + reportedVisible
1779 + " okToDisplay=" + okToDisplay()
1780 + " okToAnimate=" + okToAnimate()
1781 + " startingDisplayed=" + startingDisplayed);
1782
1783 // WindowState.onExitAnimationDone might modify the children list, so make a copy and then
1784 // traverse the copy.
1785 final ArrayList<WindowState> children = new ArrayList<>(mChildren);
1786 children.forEach(WindowState::onExitAnimationDone);
1787
1788 mService.mAppTransition.notifyAppTransitionFinishedLocked(token);
1789 scheduleAnimation();
1790 }
1791
1792 @Override
1793 boolean isAppAnimating() {
1794 return isSelfAnimating();
1795 }
1796
1797 @Override
1798 boolean isSelfAnimating() {
1799 // If we are about to start a transition, we also need to be considered animating.
1800 return isWaitingForTransitionStart() || isReallyAnimating();
1801 }
1802
1803 /**
1804 * @return True if and only if we are actually running an animation. Note that
1805 * {@link #isSelfAnimating} also returns true if we are waiting for an animation to
1806 * start.
1807 */
1808 private boolean isReallyAnimating() {
1809 return super.isSelfAnimating();
1810 }
1811
Jorim Jaggi988f6682017-11-17 17:46:43 +01001812 @Override
1813 void cancelAnimation() {
1814 super.cancelAnimation();
1815 clearThumbnail();
1816 }
1817
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001818 boolean isWaitingForTransitionStart() {
1819 return mService.mAppTransition.isTransitionSet()
1820 && (mService.mOpeningApps.contains(this) || mService.mClosingApps.contains(this));
1821 }
1822
1823 public int getTransit() {
1824 return mTransit;
1825 }
1826
1827 int getTransitFlags() {
1828 return mTransitFlags;
1829 }
1830
Jorim Jaggi988f6682017-11-17 17:46:43 +01001831 void attachThumbnailAnimation() {
1832 if (!isReallyAnimating()) {
1833 return;
1834 }
1835 final int taskId = getTask().mTaskId;
1836 final GraphicBuffer thumbnailHeader =
1837 mService.mAppTransition.getAppTransitionThumbnailHeader(taskId);
1838 if (thumbnailHeader == null) {
1839 if (DEBUG_APP_TRANSITIONS) Slog.d(TAG, "No thumbnail header bitmap for: " + taskId);
1840 return;
1841 }
1842 clearThumbnail();
1843 mThumbnail = new AppWindowThumbnail(getPendingTransaction(), this, thumbnailHeader);
1844 mThumbnail.startAnimation(getPendingTransaction(), loadThumbnailAnimation(thumbnailHeader));
1845 }
1846
Tony Mak64b8d562017-12-28 17:44:02 +00001847 /**
1848 * Attaches a surface with a thumbnail for the
1849 * {@link android.app.ActivityOptions#ANIM_OPEN_CROSS_PROFILE_APPS} animation.
1850 */
1851 void attachCrossProfileAppsThumbnailAnimation() {
1852 if (!isReallyAnimating()) {
1853 return;
1854 }
1855 clearThumbnail();
1856
1857 final WindowState win = findMainWindow();
1858 if (win == null) {
1859 return;
1860 }
1861 final Rect frame = win.mFrame;
1862 final int thumbnailDrawableRes = getTask().mUserId == mService.mCurrentUserId
1863 ? R.drawable.ic_account_circle
1864 : R.drawable.ic_corp_badge_no_background;
1865 final GraphicBuffer thumbnail =
1866 mService.mAppTransition
1867 .createCrossProfileAppsThumbnail(thumbnailDrawableRes, frame);
1868 if (thumbnail == null) {
1869 return;
1870 }
1871 mThumbnail = new AppWindowThumbnail(getPendingTransaction(), this, thumbnail);
1872 final Animation animation =
1873 mService.mAppTransition.createCrossProfileAppsThumbnailAnimationLocked(win.mFrame);
1874 mThumbnail.startAnimation(getPendingTransaction(), animation, new Point(frame.left,
1875 frame.top));
1876 }
1877
Jorim Jaggi988f6682017-11-17 17:46:43 +01001878 private Animation loadThumbnailAnimation(GraphicBuffer thumbnailHeader) {
1879 final DisplayInfo displayInfo = mDisplayContent.getDisplayInfo();
1880
1881 // If this is a multi-window scenario, we use the windows frame as
1882 // destination of the thumbnail header animation. If this is a full screen
1883 // window scenario, we use the whole display as the target.
1884 WindowState win = findMainWindow();
1885 Rect appRect = win != null ? win.getContentFrameLw() :
1886 new Rect(0, 0, displayInfo.appWidth, displayInfo.appHeight);
1887 Rect insets = win != null ? win.mContentInsets : null;
1888 final Configuration displayConfig = mDisplayContent.getConfiguration();
1889 return mService.mAppTransition.createThumbnailAspectScaleAnimationLocked(
1890 appRect, insets, thumbnailHeader, getTask().mTaskId, displayConfig.uiMode,
1891 displayConfig.orientation);
1892 }
1893
1894 private void clearThumbnail() {
1895 if (mThumbnail == null) {
1896 return;
1897 }
1898 mThumbnail.destroy();
1899 mThumbnail = null;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001900 }
1901
1902 @Override
1903 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
1904 super.dump(pw, prefix, dumpAll);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001905 if (appToken != null) {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001906 pw.println(prefix + "app=true mVoiceInteraction=" + mVoiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001907 }
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001908 pw.print(prefix); pw.print("task="); pw.println(getTask());
Wale Ogunwale51362492016-09-08 17:49:17 -07001909 pw.print(prefix); pw.print(" mFillsParent="); pw.print(mFillsParent);
1910 pw.print(" mOrientation="); pw.println(mOrientation);
Wale Ogunwale89973222017-04-23 18:39:45 -07001911 pw.println(prefix + "hiddenRequested=" + hiddenRequested + " mClientHidden=" + mClientHidden
1912 + ((mDeferHidingClient) ? " mDeferHidingClient=" + mDeferHidingClient : "")
1913 + " reportedDrawn=" + reportedDrawn + " reportedVisible=" + reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -07001914 if (paused) {
1915 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001916 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001917 if (mAppStopped) {
1918 pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped);
1919 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001920 if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001921 || allDrawn || mLastAllDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001922 pw.print(prefix); pw.print("mNumInterestingWindows=");
1923 pw.print(mNumInterestingWindows);
1924 pw.print(" mNumDrawnWindows="); pw.print(mNumDrawnWindows);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001925 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -07001926 pw.print(" allDrawn="); pw.print(allDrawn);
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001927 pw.print(" lastAllDrawn="); pw.print(mLastAllDrawn);
Craig Mautner6fbda632012-07-03 09:26:39 -07001928 pw.println(")");
1929 }
1930 if (inPendingTransaction) {
1931 pw.print(prefix); pw.print("inPendingTransaction=");
1932 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001933 }
Craig Mautner799bc1d2015-01-14 10:33:48 -08001934 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001935 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
1936 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -08001937 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -08001938 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001939 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001940 if (startingWindow != null || startingSurface != null
Wale Ogunwale6c459212017-05-17 08:56:03 -07001941 || startingDisplayed || startingMoved || mHiddenSetFromTransferredStartingWindow) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001942 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001943 pw.print(" startingSurface="); pw.print(startingSurface);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001944 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
Wale Ogunwale6c459212017-05-17 08:56:03 -07001945 pw.print(" startingMoved="); pw.print(startingMoved);
1946 pw.println(" mHiddenSetFromTransferredStartingWindow="
1947 + mHiddenSetFromTransferredStartingWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001948 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01001949 if (!mFrozenBounds.isEmpty()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -08001950 pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds);
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001951 pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig);
Chong Zhangd78ddb42016-03-02 17:01:14 -08001952 }
1953 if (mPendingRelaunchCount != 0) {
1954 pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount);
Jorim Jaggi0429f352015-12-22 16:29:16 +01001955 }
Wale Ogunwale9c64cb62017-04-12 13:39:59 -07001956 if (getController() != null) {
1957 pw.print(prefix); pw.print("controller="); pw.println(getController());
1958 }
Wale Ogunwalee287e192017-04-21 09:30:12 -07001959 if (mRemovingFromDisplay) {
1960 pw.println(prefix + "mRemovingFromDisplay=" + mRemovingFromDisplay);
1961 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001962 }
1963
1964 @Override
1965 void setHidden(boolean hidden) {
1966 super.setHidden(hidden);
Winson Chunge55c0192017-08-24 14:50:48 -07001967
1968 if (hidden) {
1969 // Once the app window is hidden, reset the last saved PiP snap fraction
1970 mDisplayContent.mPinnedStackControllerLocked.resetReentrySnapFraction(this);
1971 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001972 scheduleAnimation();
1973 }
1974
1975 @Override
1976 void prepareSurfaces() {
1977 // isSelfAnimating also returns true when we are about to start a transition, so we need
1978 // to check super here.
1979 final boolean reallyAnimating = super.isSelfAnimating();
1980 final boolean show = !isHidden() || reallyAnimating;
1981 if (show && !mLastSurfaceShowing) {
1982 mPendingTransaction.show(mSurfaceControl);
1983 } else if (!show && mLastSurfaceShowing) {
1984 mPendingTransaction.hide(mSurfaceControl);
Jorim Jaggi4d1835d2017-08-31 17:28:27 +02001985 }
Jorim Jaggi988f6682017-11-17 17:46:43 +01001986 if (mThumbnail != null) {
1987 mThumbnail.setShowing(mPendingTransaction, show);
1988 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001989 mLastSurfaceShowing = show;
1990 super.prepareSurfaces();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001991 }
1992
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001993 boolean isFreezingScreen() {
1994 return mFreezingScreen;
1995 }
1996
1997 @Override
1998 boolean needsZBoost() {
1999 return mNeedsZBoost || super.needsZBoost();
2000 }
2001
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07002002 @CallSuper
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002003 @Override
Adrian Roos4921ccf2017-09-28 16:54:06 +02002004 public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07002005 final long token = proto.start(fieldId);
2006 writeNameToProto(proto, NAME);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002007 super.writeToProto(proto, WINDOW_TOKEN, trim);
Vishnu Nair04ab4392018-01-10 11:00:06 -08002008 proto.write(LAST_SURFACE_SHOWING, mLastSurfaceShowing);
2009 proto.write(IS_WAITING_FOR_TRANSITION_START, isWaitingForTransitionStart());
2010 proto.write(IS_REALLY_ANIMATING, isReallyAnimating());
2011 if (mThumbnail != null){
2012 mThumbnail.writeToProto(proto, THUMBNAIL);
2013 }
2014 proto.write(FILLS_PARENT, mFillsParent);
2015 proto.write(APP_STOPPED, mAppStopped);
2016 proto.write(HIDDEN_REQUESTED, hiddenRequested);
2017 proto.write(CLIENT_HIDDEN, mClientHidden);
2018 proto.write(DEFER_HIDING_CLIENT, mDeferHidingClient);
2019 proto.write(REPORTED_DRAWN, reportedDrawn);
2020 proto.write(REPORTED_VISIBLE, reportedVisible);
2021 proto.write(NUM_INTERESTING_WINDOWS, mNumInterestingWindows);
2022 proto.write(NUM_DRAWN_WINDOWS, mNumDrawnWindows);
2023 proto.write(ALL_DRAWN, allDrawn);
2024 proto.write(LAST_ALL_DRAWN, mLastAllDrawn);
2025 proto.write(REMOVED, removed);
2026 if (startingWindow != null){
2027 startingWindow.writeIdentifierToProto(proto, STARTING_WINDOW);
2028 }
2029 proto.write(STARTING_DISPLAYED, startingDisplayed);
2030 proto.write(STARTING_MOVED, startingMoved);
2031 proto.write(HIDDEN_SET_FROM_TRANSFERRED_STARTING_WINDOW,
2032 mHiddenSetFromTransferredStartingWindow);
2033 for (Rect bounds : mFrozenBounds) {
2034 bounds.writeToProto(proto, FROZEN_BOUNDS);
2035 }
Steven Timotiusaf03df62017-07-18 16:56:43 -07002036 proto.end(token);
2037 }
2038
2039 void writeNameToProto(ProtoOutputStream proto, long fieldId) {
2040 if (appToken == null) {
2041 return;
2042 }
2043 try {
2044 proto.write(fieldId, appToken.getName());
2045 } catch (RemoteException e) {
2046 // This shouldn't happen, but in this case fall back to outputting nothing
2047 Slog.e(TAG, e.toString());
2048 }
2049 }
2050
2051 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002052 public String toString() {
2053 if (stringName == null) {
2054 StringBuilder sb = new StringBuilder();
2055 sb.append("AppWindowToken{");
2056 sb.append(Integer.toHexString(System.identityHashCode(this)));
2057 sb.append(" token="); sb.append(token); sb.append('}');
2058 stringName = sb.toString();
2059 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07002060 return stringName + ((mIsExiting) ? " mIsExiting=" : "");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002061 }
Jeff Browne9bdb312012-04-05 15:30:10 -07002062}