blob: 8540feb7ece3b979660092b7afdeb14a248ba82e [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;
Jorim Jaggif84e2f62018-01-16 14:17:59 +010037import static android.view.WindowManager.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;
Jorim Jaggif84e2f62018-01-16 14:17:59 +010094import android.view.RemoteAnimationDefinition;
Robert Carr6914f082017-03-20 19:04:30 -070095import android.view.SurfaceControl;
Tony Mak64b8d562017-12-28 17:44:02 +000096import android.view.SurfaceControl.Transaction;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080097import android.view.WindowManager;
Jorim Jaggi87fdbcb2017-08-17 13:41:11 +020098import android.view.WindowManager.LayoutParams;
Tony Mak64b8d562017-12-28 17:44:02 +000099import android.view.animation.Animation;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800100
Tony Mak64b8d562017-12-28 17:44:02 +0000101import com.android.internal.R;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800102import com.android.internal.util.ToBooleanFunction;
103import com.android.server.input.InputApplicationHandle;
Adrian Roose99bc052017-11-20 17:55:31 +0100104import com.android.server.policy.WindowManagerPolicy.StartingSurface;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800105import com.android.server.wm.WindowManagerService.H;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800106
107import java.io.PrintWriter;
Jorim Jaggi0429f352015-12-22 16:29:16 +0100108import java.util.ArrayDeque;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800109import java.util.ArrayList;
110
111class AppTokenList extends ArrayList<AppWindowToken> {
112}
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800113
114/**
115 * Version of WindowToken that is specifically for a particular application (or
116 * really activity) that is displaying windows.
117 */
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700118class AppWindowToken extends WindowToken implements WindowManagerService.AppFreezeListener {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800119 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppWindowToken" : TAG_WM;
120
Jorim Jaggi619c9f72017-12-19 18:04:29 +0100121 /**
122 * Value to increment the z-layer when boosting a layer during animations. BOOST in l33tsp34k.
123 */
124 private static final int Z_BOOST_BASE = 800570000;
125
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800126 // Non-null only for application tokens.
127 final IApplicationToken appToken;
128
Wale Ogunwale72919d22016-12-08 18:58:50 -0800129 final boolean mVoiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700130
Wale Ogunwale51362492016-09-08 17:49:17 -0700131 /** @see WindowContainer#fillsParent() */
132 private boolean mFillsParent;
Craig Mautner4c5eb222013-11-18 12:59:05 -0800133 boolean layoutConfigChanges;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800134 boolean mShowForAllUsers;
135 int mTargetSdk;
Craig Mautnera2c77052012-03-26 12:14:43 -0700136
Bryce Lee6d410262017-02-28 15:30:17 -0800137 // Flag set while reparenting to prevent actions normally triggered by an individual parent
138 // change.
139 private boolean mReparenting;
140
Wale Ogunwalee287e192017-04-21 09:30:12 -0700141 // True if we are current in the process of removing this app token from the display
142 private boolean mRemovingFromDisplay = false;
143
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800144 // The input dispatching timeout for this application token in nanoseconds.
Wale Ogunwale72919d22016-12-08 18:58:50 -0800145 long mInputDispatchingTimeoutNanos;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800146
147 // These are used for determining when all windows associated with
148 // an activity have been drawn, so they can be made visible together
149 // at the same time.
Craig Mautner764983d2012-03-22 11:37:36 -0700150 // initialize so that it doesn't match mTransactionSequence which is an int.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700151 private long mLastTransactionSequence = Long.MIN_VALUE;
152 private int mNumInterestingWindows;
153 private int mNumDrawnWindows;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800154 boolean inPendingTransaction;
155 boolean allDrawn;
Jorim Jaggib0fc8172017-11-23 17:04:08 +0000156 private boolean mLastAllDrawn;
157
Craig Mautner7636dfb2012-11-16 15:24:11 -0800158 // Set to true when this app creates a surface while in the middle of an animation. In that
159 // case do not clear allDrawn until the animation completes.
160 boolean deferClearAllDrawn;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800161
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800162 // Is this window's surface needed? This is almost like hidden, except
163 // it will sometimes be true a little earlier: when the token has
164 // been shown, but is still waiting for its app transition to execute
165 // before making its windows shown.
166 boolean hiddenRequested;
167
168 // Have we told the window clients to hide themselves?
Wale Ogunwale89973222017-04-23 18:39:45 -0700169 private boolean mClientHidden;
170
171 // If true we will defer setting mClientHidden to true and reporting to the client that it is
172 // hidden.
173 boolean mDeferHidingClient;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800174
175 // Last visibility state we reported to the app token.
176 boolean reportedVisible;
177
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700178 // Last drawn state we reported to the app token.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700179 private boolean reportedDrawn;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700180
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800181 // Set to true when the token has been removed from the window mgr.
182 boolean removed;
183
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800184 // Information about an application starting window if displayed.
185 StartingData startingData;
186 WindowState startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800187 StartingSurface startingSurface;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800188 boolean startingDisplayed;
189 boolean startingMoved;
Jorim Jaggi60f9c972018-02-01 19:21:07 +0100190
Wale Ogunwale6c459212017-05-17 08:56:03 -0700191 // True if the hidden state of this token was forced to false due to a transferred starting
192 // window.
193 private boolean mHiddenSetFromTransferredStartingWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800194 boolean firstWindowDrawn;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700195 private final WindowState.UpdateReportedVisibilityResults mReportedVisibilityResults =
196 new WindowState.UpdateReportedVisibilityResults();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800197
198 // Input application handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700199 final InputApplicationHandle mInputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800200
Wale Ogunwale571771c2016-08-26 13:18:50 -0700201 // TODO: Have a WindowContainer state for tracking exiting/deferred removal.
Craig Mautner799bc1d2015-01-14 10:33:48 -0800202 boolean mIsExiting;
Craig Mautner9ef471f2014-02-07 13:11:47 -0800203
Craig Mautnerbb742462014-07-07 15:28:55 -0700204 boolean mLaunchTaskBehind;
Craig Mautner8746a472014-07-24 15:12:54 -0700205 boolean mEnteringAnimation;
Craig Mautnerbb742462014-07-07 15:28:55 -0700206
Wale Ogunwale72919d22016-12-08 18:58:50 -0800207 private boolean mAlwaysFocusable;
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800208
Robert Carre12aece2016-02-02 22:43:27 -0800209 boolean mAppStopped;
Robert Carrfd10cd12016-06-29 16:41:50 -0700210 int mRotationAnimationHint;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700211 private int mPendingRelaunchCount;
Robert Carre12aece2016-02-02 22:43:27 -0800212
Jorim Jaggife762342016-10-13 14:33:27 +0200213 private boolean mLastContainsShowWhenLockedWindow;
214 private boolean mLastContainsDismissKeyguardWindow;
215
Jorim Jaggi0429f352015-12-22 16:29:16 +0100216 ArrayDeque<Rect> mFrozenBounds = new ArrayDeque<>();
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700217 ArrayDeque<Configuration> mFrozenMergedConfig = new ArrayDeque<>();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100218
Wale Ogunwale6c459212017-05-17 08:56:03 -0700219 private boolean mDisablePreviewScreenshots;
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +0100220
Wale Ogunwale034a8ec2017-09-02 17:14:40 -0700221 private Task mLastParent;
Robert Carred3e83b2017-04-21 13:26:55 -0700222
chaviwd3bf08d2017-08-01 17:24:59 -0700223 /**
224 * See {@link #canTurnScreenOn()}
225 */
226 private boolean mCanTurnScreenOn = true;
227
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200228 /**
229 * If we are running an animation, this determines the transition type. Must be one of
230 * AppTransition.TRANSIT_* constants.
231 */
232 private int mTransit;
233
234 /**
235 * If we are running an animation, this determines the flags during this animation. Must be a
236 * bitwise combination of AppTransition.TRANSIT_FLAG_* constants.
237 */
238 private int mTransitFlags;
239
240 /** Whether our surface was set to be showing in the last call to {@link #prepareSurfaces} */
Jorim Jaggifd1891462017-12-29 15:41:36 +0100241 private boolean mLastSurfaceShowing = true;
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200242
Jorim Jaggi988f6682017-11-17 17:46:43 +0100243 private AppWindowThumbnail mThumbnail;
244
Jorim Jaggib0fc8172017-11-23 17:04:08 +0000245 /** Have we been asked to have this token keep the screen frozen? */
246 private boolean mFreezingScreen;
247
248 /** Whether this token should be boosted at the top of all app window tokens. */
249 private boolean mNeedsZBoost;
Adrian Roos4d18a2e2017-12-19 19:08:05 +0100250 private Letterbox mLetterbox;
Jorim Jaggib0fc8172017-11-23 17:04:08 +0000251
chaviw23ee71c2017-12-18 11:29:41 -0800252 private final Point mTmpPoint = new Point();
chaviw23012112017-12-20 15:29:04 -0800253 private final Rect mTmpRect = new Rect();
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100254 private RemoteAnimationDefinition mRemoteAnimationDefinition;
Jorim Jaggi6de61012018-03-19 14:53:23 +0100255 private AnimatingAppWindowTokenRegistry mAnimatingAppWindowTokenRegistry;
chaviw23ee71c2017-12-18 11:29:41 -0800256
Wale Ogunwale72919d22016-12-08 18:58:50 -0800257 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
258 DisplayContent dc, long inputDispatchingTimeoutNanos, boolean fullscreen,
259 boolean showForAllUsers, int targetSdk, int orientation, int rotationAnimationHint,
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800260 int configChanges, boolean launchTaskBehind, boolean alwaysFocusable,
Bryce Leef3c6a472017-11-14 14:53:06 -0800261 AppWindowContainerController controller) {
262 this(service, token, voiceInteraction, dc, fullscreen);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800263 setController(controller);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800264 mInputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800265 mShowForAllUsers = showForAllUsers;
266 mTargetSdk = targetSdk;
267 mOrientation = orientation;
268 layoutConfigChanges = (configChanges & (CONFIG_SCREEN_SIZE | CONFIG_ORIENTATION)) != 0;
269 mLaunchTaskBehind = launchTaskBehind;
270 mAlwaysFocusable = alwaysFocusable;
271 mRotationAnimationHint = rotationAnimationHint;
272
273 // Application tokens start out hidden.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200274 setHidden(true);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800275 hiddenRequested = true;
276 }
277
278 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
Bryce Leef3c6a472017-11-14 14:53:06 -0800279 DisplayContent dc, boolean fillsParent) {
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800280 super(service, token != null ? token.asBinder() : null, TYPE_APPLICATION, true, dc,
281 false /* ownerCanManageAppTokens */);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700282 appToken = token;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800283 mVoiceInteraction = voiceInteraction;
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800284 mFillsParent = fillsParent;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800285 mInputApplicationHandle = new InputApplicationHandle(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800286 }
287
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800288 void onFirstWindowDrawn(WindowState win, WindowStateAnimator winAnimator) {
289 firstWindowDrawn = true;
290
291 // We now have a good window to show, remove dead placeholders
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700292 removeDeadWindows();
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800293
Jorim Jaggi02886a82016-12-06 09:10:06 -0800294 if (startingWindow != null) {
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800295 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, "Finish starting "
296 + win.mToken + ": first real window is shown, no animation");
297 // If this initial window is animating, stop it -- we will do an animation to reveal
298 // it from behind the starting window, so there is no need for it to also be doing its
299 // own stuff.
Jorim Jaggia5e10572017-11-15 14:36:26 +0100300 win.cancelAnimation();
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800301 if (getController() != null) {
302 getController().removeStartingWindow();
303 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800304 }
305 updateReportedVisibilityLocked();
306 }
307
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800308 void updateReportedVisibilityLocked() {
309 if (appToken == null) {
310 return;
311 }
312
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700313 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700314 final int count = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800315
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700316 mReportedVisibilityResults.reset();
317
318 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700319 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700320 win.updateReportedVisibility(mReportedVisibilityResults);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800321 }
322
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700323 int numInteresting = mReportedVisibilityResults.numInteresting;
324 int numVisible = mReportedVisibilityResults.numVisible;
325 int numDrawn = mReportedVisibilityResults.numDrawn;
326 boolean nowGone = mReportedVisibilityResults.nowGone;
327
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700328 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200329 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting && !isHidden();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700330 if (!nowGone) {
331 // If the app is not yet gone, then it can only become visible/drawn.
332 if (!nowDrawn) {
333 nowDrawn = reportedDrawn;
334 }
335 if (!nowVisible) {
336 nowVisible = reportedVisible;
337 }
338 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800339 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800340 + numInteresting + " visible=" + numVisible);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800341 final AppWindowContainerController controller = getController();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700342 if (nowDrawn != reportedDrawn) {
343 if (nowDrawn) {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800344 if (controller != null) {
345 controller.reportWindowsDrawn();
346 }
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700347 }
348 reportedDrawn = nowDrawn;
349 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800350 if (nowVisible != reportedVisible) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700351 if (DEBUG_VISIBILITY) Slog.v(TAG,
352 "Visibility changed in " + this + ": vis=" + nowVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800353 reportedVisible = nowVisible;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800354 if (controller != null) {
355 if (nowVisible) {
356 controller.reportWindowsVisible();
357 } else {
358 controller.reportWindowsGone();
359 }
360 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800361 }
362 }
363
Wale Ogunwale89973222017-04-23 18:39:45 -0700364 boolean isClientHidden() {
365 return mClientHidden;
366 }
367
368 void setClientHidden(boolean hideClient) {
369 if (mClientHidden == hideClient || (hideClient && mDeferHidingClient)) {
370 return;
371 }
Jorim Jaggi067b5bf2018-02-23 17:42:39 +0100372 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setClientHidden: " + this
373 + " clientHidden=" + hideClient + " Callers=" + Debug.getCallers(5));
Wale Ogunwale89973222017-04-23 18:39:45 -0700374 mClientHidden = hideClient;
375 sendAppVisibilityToClients();
376 }
377
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700378 boolean setVisibility(WindowManager.LayoutParams lp,
379 boolean visible, int transit, boolean performLayout, boolean isVoiceInteraction) {
380
381 boolean delayed = false;
382 inPendingTransaction = false;
Wale Ogunwale9e4721f2017-05-23 19:37:30 -0700383 // Reset the state of mHiddenSetFromTransferredStartingWindow since visibility is actually
384 // been set by the app now.
385 mHiddenSetFromTransferredStartingWindow = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700386
387 // Allow for state changes and animation to be applied if:
388 // * token is transitioning visibility state
389 // * or the token was marked as hidden and is exiting before we had a chance to play the
390 // transition animation
391 // * or this is an opening app and windows are being replaced.
392 boolean visibilityChanged = false;
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200393 if (isHidden() == visible || (isHidden() && mIsExiting) || (visible && waitingForReplacement())) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700394 final AccessibilityController accessibilityController = mService.mAccessibilityController;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700395 boolean changed = false;
396 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200397 "Changing app " + this + " hidden=" + isHidden() + " performLayout=" + performLayout);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700398
399 boolean runningAppAnimation = false;
400
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100401 if (transit != WindowManager.TRANSIT_UNSET) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200402 if (applyAnimationLocked(lp, transit, visible, isVoiceInteraction)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700403 delayed = runningAppAnimation = true;
404 }
405 final WindowState window = findMainWindow();
406 //TODO (multidisplay): Magnification is supported only for the default display.
407 if (window != null && accessibilityController != null
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700408 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700409 accessibilityController.onAppWindowTransitionLocked(window, transit);
410 }
411 changed = true;
412 }
413
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700414 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700415 for (int i = 0; i < windowsCount; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700416 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700417 changed |= win.onAppVisibilityChanged(visible, runningAppAnimation);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700418 }
419
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200420 setHidden(!visible);
421 hiddenRequested = !visible;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700422 visibilityChanged = true;
423 if (!visible) {
424 stopFreezingScreen(true, true);
425 } else {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700426 // If we are being set visible, and the starting window is not yet displayed,
427 // then make sure it doesn't get displayed.
428 if (startingWindow != null && !startingWindow.isDrawnLw()) {
429 startingWindow.mPolicyVisibility = false;
430 startingWindow.mPolicyVisibilityAfterAnim = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700431 }
Jorim Jaggi38d44ec2017-06-14 16:04:59 -0700432
433 // We are becoming visible, so better freeze the screen with the windows that are
434 // getting visible so we also wait for them.
435 forAllWindows(mService::makeWindowFreezingScreenIfNeededLocked, true);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700436 }
437
438 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setVisibility: " + this
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200439 + ": hidden=" + isHidden() + " hiddenRequested=" + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700440
441 if (changed) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700442 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700443 if (performLayout) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700444 mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700445 false /*updateInputWindows*/);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700446 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700447 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700448 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700449 }
450 }
451
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200452 if (isReallyAnimating()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700453 delayed = true;
Jorim Jaggiab9fcb22018-03-15 23:46:12 +0100454 } else {
455
456 // We aren't animating anything, but exiting windows rely on the animation finished
457 // callback being called in case the AppWindowToken was pretending to be animating,
458 // which we might have done because we were in closing/opening apps list.
459 onAnimationFinished();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700460 }
461
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700462 for (int i = mChildren.size() - 1; i >= 0 && !delayed; i--) {
Jorim Jaggia5e10572017-11-15 14:36:26 +0100463 if ((mChildren.get(i)).isSelfOrChildAnimating()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700464 delayed = true;
465 }
466 }
467
468 if (visibilityChanged) {
469 if (visible && !delayed) {
470 // The token was made immediately visible, there will be no entrance animation.
471 // We need to inform the client the enter animation was finished.
472 mEnteringAnimation = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700473 mService.mActivityManagerAppTransitionNotifier.onAppTransitionFinishedLocked(token);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700474 }
Robert Carr61b81112017-07-17 18:08:15 -0700475
Jorim Jaggi110839b2018-01-22 12:49:04 +0100476 // If we're becoming visible, immediately change client visibility as well although it
477 // usually gets changed in AppWindowContainerController.setVisibility already. However,
478 // there seem to be some edge cases where we change our visibility but client visibility
479 // never gets updated.
480 // If we're becoming invisible, update the client visibility if we are not running an
481 // animation. Otherwise, we'll update client visibility in onAnimationFinished.
Jorim Jaggi3cad57f2018-02-20 18:32:01 +0100482 if (visible || !isReallyAnimating()) {
Jorim Jaggi110839b2018-01-22 12:49:04 +0100483 setClientHidden(!visible);
Jorim Jaggi4876b4a2018-01-11 15:43:49 +0100484 }
485
chaviwa953fcf2018-03-01 12:00:39 -0800486 if (!mService.mClosingApps.contains(this) && !mService.mOpeningApps.contains(this)) {
487 // The token is not closing nor opening, so even if there is an animation set, that
488 // doesn't mean that it goes through the normal app transition cycle so we have
489 // to inform the docked controller about visibility change.
490 // TODO(multi-display): notify docked divider on all displays where visibility was
491 // affected.
492 mService.getDefaultDisplayContentLocked().getDockedDividerController()
493 .notifyAppVisibilityChanged();
494
495 // Take the screenshot before possibly hiding the WSA, otherwise the screenshot
496 // will not be taken.
497 mService.mTaskSnapshotController.notifyAppVisibilityChanged(this, visible);
498 }
499
Robert Carre7cc44d2017-03-20 19:04:30 -0700500 // If we are hidden but there is no delay needed we immediately
501 // apply the Surface transaction so that the ActivityManager
Robert Carr61b81112017-07-17 18:08:15 -0700502 // can have some guarantee on the Surface state following
503 // setting the visibility. This captures cases like dismissing
504 // the docked or pinned stack where there is no app transition.
505 //
506 // In the case of a "Null" animation, there will be
507 // no animation but there will still be a transition set.
508 // We still need to delay hiding the surface such that it
509 // can be synchronized with showing the next surface in the transition.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200510 if (isHidden() && !delayed && !mService.mAppTransition.isTransitionSet()) {
Robert Carr6914f082017-03-20 19:04:30 -0700511 SurfaceControl.openTransaction();
512 for (int i = mChildren.size() - 1; i >= 0; i--) {
513 mChildren.get(i).mWinAnimator.hide("immediately hidden");
514 }
515 SurfaceControl.closeTransaction();
516 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700517 }
518
519 return delayed;
520 }
521
Jorim Jaggi87fdbcb2017-08-17 13:41:11 +0200522 /**
523 * @return The to top most child window for which {@link LayoutParams#isFullscreen()} returns
524 * true.
525 */
526 WindowState getTopFullscreenWindow() {
527 for (int i = mChildren.size() - 1; i >= 0; i--) {
528 final WindowState win = mChildren.get(i);
529 if (win != null && win.mAttrs.isFullscreen()) {
530 return win;
531 }
532 }
533 return null;
534 }
535
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800536 WindowState findMainWindow() {
Matthew Ng53e66b22018-01-12 17:13:13 -0800537 return findMainWindow(true);
538 }
539
540 /**
541 * Finds the main window that either has type base application or application starting if
542 * requested.
543 *
544 * @param includeStartingApp Allow to search application-starting windows to also be returned.
545 * @return The main window of type base application or application starting if requested.
546 */
547 WindowState findMainWindow(boolean includeStartingApp) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700548 WindowState candidate = null;
Matthew Ng53e66b22018-01-12 17:13:13 -0800549 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700550 final WindowState win = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700551 final int type = win.mAttrs.type;
552 // No need to loop through child window as base application and starting types can't be
553 // child windows.
Matthew Ng53e66b22018-01-12 17:13:13 -0800554 if (type == TYPE_BASE_APPLICATION
555 || (includeStartingApp && type == TYPE_APPLICATION_STARTING)) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700556 // In cases where there are multiple windows, we prefer the non-exiting window. This
Sungsoo Lim0d3d1f82015-12-02 14:47:59 +0900557 // happens for example when replacing windows during an activity relaunch. When
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700558 // constructing the animation, we want the new window, not the exiting one.
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800559 if (win.mAnimatingExit) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700560 candidate = win;
561 } else {
562 return win;
563 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800564 }
565 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700566 return candidate;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800567 }
568
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800569 boolean windowsAreFocusable() {
Wale Ogunwale3382ab12017-07-27 08:55:03 -0700570 return getWindowConfiguration().canReceiveKeys() || mAlwaysFocusable;
Wale Ogunwaled045c822015-12-02 09:14:28 -0800571 }
572
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800573 AppWindowContainerController getController() {
574 final WindowContainerController controller = super.getController();
575 return controller != null ? (AppWindowContainerController) controller : null;
576 }
577
Wale Ogunwale571771c2016-08-26 13:18:50 -0700578 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -0700579 boolean isVisible() {
Wale Ogunwalee471be62016-10-03 07:53:55 -0700580 // If the app token isn't hidden then it is considered visible and there is no need to check
581 // its children windows to see if they are visible.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200582 return !isHidden();
Wale Ogunwale44f21802016-09-02 12:49:48 -0700583 }
584
585 @Override
Wale Ogunwalee287e192017-04-21 09:30:12 -0700586 void removeImmediately() {
587 onRemovedFromDisplay();
588 super.removeImmediately();
589 }
590
591 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -0700592 void removeIfPossible() {
Craig Mautnere3119b72015-01-20 15:02:36 -0800593 mIsExiting = false;
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800594 removeAllWindowsIfPossible();
Bryce Lee6d410262017-02-28 15:30:17 -0800595 removeImmediately();
Craig Mautnere3119b72015-01-20 15:02:36 -0800596 }
597
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700598 @Override
599 boolean checkCompleteDeferredRemoval() {
600 if (mIsExiting) {
601 removeIfPossible();
602 }
603 return super.checkCompleteDeferredRemoval();
604 }
605
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700606 void onRemovedFromDisplay() {
Wale Ogunwalee287e192017-04-21 09:30:12 -0700607 if (mRemovingFromDisplay) {
608 return;
609 }
610 mRemovingFromDisplay = true;
611
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700612 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app token: " + this);
613
Wale Ogunwale72919d22016-12-08 18:58:50 -0800614 boolean delayed = setVisibility(null, false, TRANSIT_UNSET, true, mVoiceInteraction);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700615
616 mService.mOpeningApps.remove(this);
Jorim Jaggi45ca0542017-05-30 16:16:01 -0700617 mService.mUnknownAppVisibilityController.appRemovedOrHidden(this);
Jorim Jaggi10abe2f2017-01-03 16:44:46 +0100618 mService.mTaskSnapshotController.onAppRemoved(this);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700619 waitingToShow = false;
620 if (mService.mClosingApps.contains(this)) {
621 delayed = true;
622 } else if (mService.mAppTransition.isTransitionSet()) {
623 mService.mClosingApps.add(this);
624 delayed = true;
625 }
626
627 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app " + this + " delayed=" + delayed
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200628 + " animation=" + getAnimation() + " animating=" + isSelfAnimating());
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700629
630 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM, "removeAppToken: "
631 + this + " delayed=" + delayed + " Callers=" + Debug.getCallers(4));
632
Jorim Jaggi19be6052017-08-03 18:33:43 +0200633 if (startingData != null && getController() != null) {
634 getController().removeStartingWindow();
635 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800636
Winson Chung87e5d552017-04-05 11:49:38 -0700637 // If this window was animating, then we need to ensure that the app transition notifies
638 // that animations have completed in WMS.handleAnimatingStoppedAndTransitionLocked(), so
639 // add to that list now
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200640 if (isSelfAnimating()) {
Winson Chung87e5d552017-04-05 11:49:38 -0700641 mService.mNoAnimationNotifyOnTransitionFinished.add(token);
642 }
643
Wale Ogunwalee287e192017-04-21 09:30:12 -0700644 final TaskStack stack = getStack();
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700645 if (delayed && !isEmpty()) {
646 // set the token aside because it has an active animation to be finished
647 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM,
648 "removeAppToken make exiting: " + this);
Wale Ogunwalee287e192017-04-21 09:30:12 -0700649 if (stack != null) {
650 stack.mExitingAppTokens.add(this);
651 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700652 mIsExiting = true;
653 } else {
654 // Make sure there is no animation running on this token, so any windows associated
655 // with it will be removed as soon as their animations are complete
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200656 cancelAnimation();
Wale Ogunwale3106ae012017-05-16 08:56:37 -0700657 if (stack != null) {
658 stack.mExitingAppTokens.remove(this);
659 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700660 removeIfPossible();
661 }
662
663 removed = true;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700664 stopFreezingScreen(true, true);
Bryce Lee6d410262017-02-28 15:30:17 -0800665
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700666 if (mService.mFocusedApp == this) {
667 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "Removing focused app token:" + this);
668 mService.mFocusedApp = null;
669 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
670 mService.mInputMonitor.setFocusedAppLw(null);
671 }
672
673 if (!delayed) {
674 updateReportedVisibilityLocked();
675 }
Wale Ogunwalee287e192017-04-21 09:30:12 -0700676
677 mRemovingFromDisplay = false;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700678 }
679
Chong Zhange05bcb12016-07-26 17:47:29 -0700680 void clearAnimatingFlags() {
Chong Zhangb0d26702016-08-12 16:03:29 -0700681 boolean wallpaperMightChange = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700682 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700683 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700684 wallpaperMightChange |= win.clearAnimatingFlags();
Chong Zhange05bcb12016-07-26 17:47:29 -0700685 }
Chong Zhangb0d26702016-08-12 16:03:29 -0700686 if (wallpaperMightChange) {
687 requestUpdateWallpaperIfNeeded();
688 }
Chong Zhange05bcb12016-07-26 17:47:29 -0700689 }
690
Robert Carre12aece2016-02-02 22:43:27 -0800691 void destroySurfaces() {
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700692 destroySurfaces(false /*cleanupOnResume*/);
693 }
694
695 /**
696 * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure
697 * the client has finished with them.
698 *
699 * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If
700 * set to true, destroy only surfaces of removed windows, and clear relevant flags of the
701 * others so that they are ready to be reused. If set to false (common case), destroy all
702 * surfaces that's eligible, if the app is already stopped.
703 */
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700704 private void destroySurfaces(boolean cleanupOnResume) {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700705 boolean destroyedSomething = false;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100706
707 // Copying to a different list as multiple children can be removed.
Jorim Jaggi59f3e922018-01-05 15:40:32 +0100708 final ArrayList<WindowState> children = new ArrayList<>(mChildren);
Jorim Jaggia5e10572017-11-15 14:36:26 +0100709 for (int i = children.size() - 1; i >= 0; i--) {
710 final WindowState win = children.get(i);
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700711 destroyedSomething |= win.destroySurface(cleanupOnResume, mAppStopped);
Robert Carre12aece2016-02-02 22:43:27 -0800712 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700713 if (destroyedSomething) {
714 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700715 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Adrian Roos4d18a2e2017-12-19 19:08:05 +0100716 updateLetterbox(null);
Robert Carre12aece2016-02-02 22:43:27 -0800717 }
718 }
719
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800720 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700721 * Notify that the app is now resumed, and it was not stopped before, perform a clean
722 * up of the surfaces
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800723 */
Jorim Jaggibae01b12017-04-11 16:29:10 -0700724 void notifyAppResumed(boolean wasStopped) {
Chong Zhangad24f962016-08-25 12:12:33 -0700725 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped
Jorim Jaggibae01b12017-04-11 16:29:10 -0700726 + " " + this);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700727 mAppStopped = false;
chaviwd3bf08d2017-08-01 17:24:59 -0700728 // Allow the window to turn the screen on once the app is resumed again.
729 setCanTurnScreenOn(true);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700730 if (!wasStopped) {
731 destroySurfaces(true /*cleanupOnResume*/);
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800732 }
Robert Carre12aece2016-02-02 22:43:27 -0800733 }
734
Chong Zhangbef461f2015-10-27 11:38:24 -0700735 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700736 * Notify that the app has stopped, and it is okay to destroy any surfaces which were
737 * keeping alive in case they were still being used.
738 */
739 void notifyAppStopped() {
740 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this);
741 mAppStopped = true;
742 destroySurfaces();
743 // Remove any starting window that was added for this app if they are still around.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800744 if (getController() != null) {
745 getController().removeStartingWindow();
746 }
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700747 }
748
Chong Zhang92147042016-05-09 12:47:11 -0700749 void clearAllDrawn() {
750 allDrawn = false;
751 deferClearAllDrawn = false;
Chong Zhangbef461f2015-10-27 11:38:24 -0700752 }
753
Bryce Lee6d410262017-02-28 15:30:17 -0800754 Task getTask() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800755 return (Task) getParent();
Bryce Lee6d410262017-02-28 15:30:17 -0800756 }
757
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800758 TaskStack getStack() {
759 final Task task = getTask();
760 if (task != null) {
761 return task.mStack;
762 } else {
763 return null;
764 }
765 }
766
Bryce Lee6d410262017-02-28 15:30:17 -0800767 @Override
768 void onParentSet() {
769 super.onParentSet();
770
Robert Carred3e83b2017-04-21 13:26:55 -0700771 final Task task = getTask();
772
Bryce Lee6d410262017-02-28 15:30:17 -0800773 // When the associated task is {@code null}, the {@link AppWindowToken} can no longer
774 // access visual elements like the {@link DisplayContent}. We must remove any associations
775 // such as animations.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800776 if (!mReparenting) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800777 if (task == null) {
778 // It is possible we have been marked as a closing app earlier. We must remove ourselves
779 // from this list so we do not participate in any future animations.
780 mService.mClosingApps.remove(this);
Robert Carred3e83b2017-04-21 13:26:55 -0700781 } else if (mLastParent != null && mLastParent.mStack != null) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800782 task.mStack.mExitingAppTokens.remove(this);
783 }
Bryce Lee6d410262017-02-28 15:30:17 -0800784 }
Jorim Jaggi6de61012018-03-19 14:53:23 +0100785 final TaskStack stack = getStack();
786
787 // If we reparent, make sure to remove ourselves from the old animation registry.
788 if (mAnimatingAppWindowTokenRegistry != null) {
789 mAnimatingAppWindowTokenRegistry.notifyFinished(this);
790 }
791 mAnimatingAppWindowTokenRegistry = stack != null
792 ? stack.getAnimatingAppWindowTokenRegistry()
793 : null;
794
Robert Carred3e83b2017-04-21 13:26:55 -0700795 mLastParent = task;
Bryce Lee6d410262017-02-28 15:30:17 -0800796 }
797
Wale Ogunwalefa854eb2016-09-20 13:43:52 -0700798 void postWindowRemoveStartingWindowCleanup(WindowState win) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700799 // TODO: Something smells about the code below...Is there a better way?
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700800 if (startingWindow == win) {
801 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800802 if (getController() != null) {
803 getController().removeStartingWindow();
804 }
Wale Ogunwale6c459212017-05-17 08:56:03 -0700805 } else if (mChildren.size() == 0) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700806 // If this is the last window and we had requested a starting transition window,
807 // well there is no point now.
Jorim Jaggi02886a82016-12-06 09:10:06 -0800808 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingData");
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700809 startingData = null;
Wale Ogunwale6c459212017-05-17 08:56:03 -0700810 if (mHiddenSetFromTransferredStartingWindow) {
811 // We set the hidden state to false for the token from a transferred starting window.
812 // We now reset it back to true since the starting window was the last window in the
813 // token.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200814 setHidden(true);
Wale Ogunwale6c459212017-05-17 08:56:03 -0700815 }
Jorim Jaggi829b9cd2017-01-23 16:20:53 +0100816 } else if (mChildren.size() == 1 && startingSurface != null && !isRelaunching()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700817 // If this is the last window except for a starting transition window,
818 // we need to get rid of the starting transition.
Jorim Jaggie4b0f282017-05-17 15:10:29 +0200819 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Last window, removing starting window "
820 + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800821 if (getController() != null) {
822 getController().removeStartingWindow();
823 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700824 }
825 }
826
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700827 void removeDeadWindows() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700828 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700829 WindowState win = mChildren.get(winNdx);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800830 if (win.mAppDied) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700831 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700832 "removeDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800833 // Set mDestroying, we don't want any animation or delayed removal here.
834 win.mDestroying = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700835 // Also removes child windows.
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700836 win.removeIfPossible();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800837 }
838 }
839 }
840
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700841 boolean hasWindowsAlive() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700842 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700843 // No need to loop through child windows as the answer should be the same as that of the
844 // parent window.
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700845 if (!(mChildren.get(i)).mAppDied) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700846 return true;
847 }
848 }
849 return false;
850 }
851
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700852 void setWillReplaceWindows(boolean animate) {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700853 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
854 "Marking app token " + this + " with replacing windows.");
Robert Carra1eb4392015-12-10 12:43:51 -0800855
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700856 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700857 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700858 w.setWillReplaceWindow(animate);
Robert Carra1eb4392015-12-10 12:43:51 -0800859 }
Robert Carra1eb4392015-12-10 12:43:51 -0800860 }
861
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700862 void setWillReplaceChildWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700863 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this
Robert Carr23fa16b2016-01-13 13:19:58 -0800864 + " with replacing child windows.");
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700865 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700866 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700867 w.setWillReplaceChildWindows();
Robert Carr23fa16b2016-01-13 13:19:58 -0800868 }
869 }
870
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700871 void clearWillReplaceWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700872 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
873 "Resetting app token " + this + " of replacing window marks.");
Chong Zhangf596cd52016-01-05 13:42:44 -0800874
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700875 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700876 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700877 w.clearWillReplaceWindow();
Chong Zhangf596cd52016-01-05 13:42:44 -0800878 }
879 }
880
Chong Zhang4d7369a2016-04-25 16:09:14 -0700881 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700882 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700883 final WindowState w = mChildren.get(i);
Chong Zhang4d7369a2016-04-25 16:09:14 -0700884 w.requestUpdateWallpaperIfNeeded();
885 }
886 }
887
Chong Zhangd78ddb42016-03-02 17:01:14 -0800888 boolean isRelaunching() {
889 return mPendingRelaunchCount > 0;
890 }
891
Robert Carr68375192017-06-13 12:41:53 -0700892 boolean shouldFreezeBounds() {
893 final Task task = getTask();
894
895 // For freeform windows, we can't freeze the bounds at the moment because this would make
896 // the resizing unresponsive.
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700897 if (task == null || task.inFreeformWindowingMode()) {
Robert Carr68375192017-06-13 12:41:53 -0700898 return false;
899 }
900
901 // We freeze the bounds while drag resizing to deal with the time between
902 // the divider/drag handle being released, and the handling it's new
903 // configuration. If we are relaunched outside of the drag resizing state,
904 // we need to be careful not to do this.
905 return getTask().isDragResizing();
906 }
907
Chong Zhangd78ddb42016-03-02 17:01:14 -0800908 void startRelaunching() {
Robert Carr68375192017-06-13 12:41:53 -0700909 if (shouldFreezeBounds()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -0800910 freezeBounds();
911 }
Robert Carrd5c7dd62017-03-08 10:39:30 -0800912
913 // In the process of tearing down before relaunching, the app will
914 // try and clean up it's child surfaces. We need to prevent this from
915 // happening, so we sever the children, transfering their ownership
916 // from the client it-self to the parent surface (owned by us).
917 for (int i = mChildren.size() - 1; i >= 0; i--) {
918 final WindowState w = mChildren.get(i);
919 w.mWinAnimator.detachChildren();
920 }
921
Chong Zhangd78ddb42016-03-02 17:01:14 -0800922 mPendingRelaunchCount++;
923 }
924
925 void finishRelaunching() {
Robert Carr68375192017-06-13 12:41:53 -0700926 unfreezeBounds();
927
Chong Zhangd78ddb42016-03-02 17:01:14 -0800928 if (mPendingRelaunchCount > 0) {
929 mPendingRelaunchCount--;
Bryce Lee081554b2017-05-25 07:52:12 -0700930 } else {
931 // Update keyguard flags upon finishing relaunch.
932 checkKeyguardFlagsChanged();
Chong Zhangd78ddb42016-03-02 17:01:14 -0800933 }
934 }
935
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700936 void clearRelaunching() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700937 if (mPendingRelaunchCount == 0) {
938 return;
939 }
Robert Carr68375192017-06-13 12:41:53 -0700940 unfreezeBounds();
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700941 mPendingRelaunchCount = 0;
942 }
943
Wale Ogunwale07bcab72016-10-14 15:30:09 -0700944 /**
945 * Returns true if the new child window we are adding to this token is considered greater than
946 * the existing child window in this token in terms of z-order.
947 */
948 @Override
949 protected boolean isFirstChildWindowGreaterThanSecond(WindowState newWindow,
950 WindowState existingWindow) {
951 final int type1 = newWindow.mAttrs.type;
952 final int type2 = existingWindow.mAttrs.type;
953
954 // Base application windows should be z-ordered BELOW all other windows in the app token.
955 if (type1 == TYPE_BASE_APPLICATION && type2 != TYPE_BASE_APPLICATION) {
956 return false;
957 } else if (type1 != TYPE_BASE_APPLICATION && type2 == TYPE_BASE_APPLICATION) {
958 return true;
959 }
960
961 // Starting windows should be z-ordered ABOVE all other windows in the app token.
962 if (type1 == TYPE_APPLICATION_STARTING && type2 != TYPE_APPLICATION_STARTING) {
963 return true;
964 } else if (type1 != TYPE_APPLICATION_STARTING && type2 == TYPE_APPLICATION_STARTING) {
965 return false;
966 }
967
968 // Otherwise the new window is greater than the existing window.
969 return true;
970 }
971
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700972 @Override
Robert Carra1eb4392015-12-10 12:43:51 -0800973 void addWindow(WindowState w) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700974 super.addWindow(w);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700975
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700976 boolean gotReplacementWindow = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700977 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700978 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700979 gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w);
980 }
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700981
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700982 // if we got a replacement window, reset the timeout to give drawing more time
983 if (gotReplacementWindow) {
984 mService.scheduleWindowReplacementTimeouts(this);
Robert Carra1eb4392015-12-10 12:43:51 -0800985 }
Jorim Jaggife762342016-10-13 14:33:27 +0200986 checkKeyguardFlagsChanged();
987 }
988
989 @Override
990 void removeChild(WindowState child) {
991 super.removeChild(child);
992 checkKeyguardFlagsChanged();
Adrian Roos4d18a2e2017-12-19 19:08:05 +0100993 updateLetterbox(child);
Robert Carra1eb4392015-12-10 12:43:51 -0800994 }
995
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700996 private boolean waitingForReplacement() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700997 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700998 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700999 if (candidate.waitingForReplacement()) {
Robert Carra1eb4392015-12-10 12:43:51 -08001000 return true;
1001 }
1002 }
1003 return false;
1004 }
1005
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001006 void onWindowReplacementTimeout() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001007 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001008 (mChildren.get(i)).onWindowReplacementTimeout();
Robert Carra1eb4392015-12-10 12:43:51 -08001009 }
1010 }
1011
Winson Chung30480042017-01-26 10:55:34 -08001012 void reparent(Task task, int position) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001013 final Task currentTask = getTask();
1014 if (task == currentTask) {
Winson Chung30480042017-01-26 10:55:34 -08001015 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001016 "window token=" + this + " already child of task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -08001017 }
Bryce Lee6d410262017-02-28 15:30:17 -08001018
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001019 if (currentTask.mStack != task.mStack) {
Bryce Lee6d410262017-02-28 15:30:17 -08001020 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001021 "window token=" + this + " current task=" + currentTask
Bryce Lee6d410262017-02-28 15:30:17 -08001022 + " belongs to a different stack than " + task);
1023 }
1024
Winson Chung30480042017-01-26 10:55:34 -08001025 if (DEBUG_ADD_REMOVE) Slog.i(TAG, "reParentWindowToken: removing window token=" + this
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001026 + " from task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -08001027 final DisplayContent prevDisplayContent = getDisplayContent();
1028
Bryce Lee6d410262017-02-28 15:30:17 -08001029 mReparenting = true;
1030
Winson Chung30480042017-01-26 10:55:34 -08001031 getParent().removeChild(this);
1032 task.addChild(this, position);
1033
Bryce Lee6d410262017-02-28 15:30:17 -08001034 mReparenting = false;
1035
Winson Chung30480042017-01-26 10:55:34 -08001036 // Relayout display(s).
1037 final DisplayContent displayContent = task.getDisplayContent();
1038 displayContent.setLayoutNeeded();
1039 if (prevDisplayContent != displayContent) {
1040 onDisplayChanged(displayContent);
1041 prevDisplayContent.setLayoutNeeded();
1042 }
1043 }
1044
Jorim Jaggi0429f352015-12-22 16:29:16 +01001045 /**
1046 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
1047 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
1048 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
1049 * with a queue.
1050 */
Chong Zhangd78ddb42016-03-02 17:01:14 -08001051 private void freezeBounds() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001052 final Task task = getTask();
1053 mFrozenBounds.offer(new Rect(task.mPreparedFrozenBounds));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001054
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001055 if (task.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) {
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001056 // We didn't call prepareFreezingBounds on the task, so use the current value.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001057 mFrozenMergedConfig.offer(new Configuration(task.getConfiguration()));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001058 } else {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001059 mFrozenMergedConfig.offer(new Configuration(task.mPreparedFrozenMergedConfig));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001060 }
Andrii Kulianb10330d2016-09-16 13:51:46 -07001061 // Calling unset() to make it equal to Configuration.EMPTY.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001062 task.mPreparedFrozenMergedConfig.unset();
Jorim Jaggi0429f352015-12-22 16:29:16 +01001063 }
1064
1065 /**
1066 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
1067 */
Chong Zhangd78ddb42016-03-02 17:01:14 -08001068 private void unfreezeBounds() {
Robert Carr68375192017-06-13 12:41:53 -07001069 if (mFrozenBounds.isEmpty()) {
1070 return;
Wale Ogunwale37dbafc2016-06-27 10:15:20 -07001071 }
Robert Carr68375192017-06-13 12:41:53 -07001072 mFrozenBounds.remove();
Wale Ogunwale37dbafc2016-06-27 10:15:20 -07001073 if (!mFrozenMergedConfig.isEmpty()) {
1074 mFrozenMergedConfig.remove();
1075 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001076 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001077 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001078 win.onUnfreezeBounds();
Jorim Jaggi4846ee32016-01-07 17:39:12 +01001079 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001080 mService.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +01001081 }
1082
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001083 void setAppLayoutChanges(int changes, String reason) {
1084 if (!mChildren.isEmpty()) {
1085 final DisplayContent dc = getDisplayContent();
1086 dc.pendingLayoutChanges |= changes;
1087 if (DEBUG_LAYOUT_REPEATS) {
1088 mService.mWindowPlacerLocked.debugLayoutRepeats(reason, dc.pendingLayoutChanges);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001089 }
1090 }
1091 }
1092
1093 void removeReplacedWindowIfNeeded(WindowState replacement) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001094 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001095 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001096 if (win.removeReplacedWindowIfNeeded(replacement)) {
1097 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001098 }
1099 }
1100 }
1101
1102 void startFreezingScreen() {
1103 if (DEBUG_ORIENTATION) logWithStack(TAG, "Set freezing of " + appToken + ": hidden="
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001104 + isHidden() + " freezing=" + mFreezingScreen + " hiddenRequested="
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001105 + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001106 if (!hiddenRequested) {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001107 if (!mFreezingScreen) {
1108 mFreezingScreen = true;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001109 mService.registerAppFreezeListener(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001110 mService.mAppsFreezingScreen++;
1111 if (mService.mAppsFreezingScreen == 1) {
Robert Carrae606b42018-02-15 15:36:23 -08001112 mService.startFreezingDisplayLocked(0, 0, getDisplayContent());
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001113 mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT);
1114 mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001115 }
1116 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001117 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001118 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001119 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001120 w.onStartFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001121 }
1122 }
1123 }
1124
1125 void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001126 if (!mFreezingScreen) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001127 return;
1128 }
1129 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + this + " force=" + force);
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001130 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001131 boolean unfrozeWindows = false;
1132 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001133 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001134 unfrozeWindows |= w.onStopFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001135 }
1136 if (force || unfrozeWindows) {
1137 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this);
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001138 mFreezingScreen = false;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001139 mService.unregisterAppFreezeListener(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001140 mService.mAppsFreezingScreen--;
1141 mService.mLastFinishedFreezeSource = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001142 }
1143 if (unfreezeSurfaceNow) {
1144 if (unfrozeWindows) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001145 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001146 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001147 mService.stopFreezingDisplayLocked();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001148 }
1149 }
1150
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001151 @Override
1152 public void onAppFreezeTimeout() {
1153 Slog.w(TAG_WM, "Force clearing freeze: " + this);
1154 stopFreezingScreen(true, true);
1155 }
1156
Jorim Jaggi60f9c972018-02-01 19:21:07 +01001157 /**
1158 * Tries to transfer the starting window from a token that's above ourselves in the task but
1159 * not visible anymore. This is a common scenario apps use: Trampoline activity T start main
1160 * activity M in the same task. Now, when reopening the task, T starts on top of M but then
1161 * immediately finishes after, so we have to transfer T to M.
1162 */
1163 void transferStartingWindowFromHiddenAboveTokenIfNeeded() {
1164 final Task task = getTask();
1165 for (int i = task.mChildren.size() - 1; i >= 0; i--) {
1166 final AppWindowToken fromToken = task.mChildren.get(i);
1167 if (fromToken == this) {
1168 return;
1169 }
1170 if (fromToken.hiddenRequested && transferStartingWindow(fromToken.token)) {
1171 return;
1172 }
1173 }
1174 }
1175
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001176 boolean transferStartingWindow(IBinder transferFrom) {
Wale Ogunwale02319a62016-09-26 15:21:22 -07001177 final AppWindowToken fromToken = getDisplayContent().getAppWindowToken(transferFrom);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001178 if (fromToken == null) {
1179 return false;
1180 }
1181
1182 final WindowState tStartingWindow = fromToken.startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001183 if (tStartingWindow != null && fromToken.startingSurface != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001184 // In this case, the starting icon has already been displayed, so start
1185 // letting windows get shown immediately without any more transitions.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001186 mService.mSkipAppTransitionAnimation = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001187
1188 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow
1189 + " from " + fromToken + " to " + this);
1190
1191 final long origId = Binder.clearCallingIdentity();
Peter Visontay3556a3b2017-11-01 17:23:17 +00001192 try {
1193 // Transfer the starting window over to the new token.
1194 startingData = fromToken.startingData;
1195 startingSurface = fromToken.startingSurface;
1196 startingDisplayed = fromToken.startingDisplayed;
1197 fromToken.startingDisplayed = false;
1198 startingWindow = tStartingWindow;
1199 reportedVisible = fromToken.reportedVisible;
1200 fromToken.startingData = null;
1201 fromToken.startingSurface = null;
1202 fromToken.startingWindow = null;
1203 fromToken.startingMoved = true;
1204 tStartingWindow.mToken = this;
1205 tStartingWindow.mAppToken = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001206
Peter Visontay3556a3b2017-11-01 17:23:17 +00001207 if (DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1208 "Removing starting " + tStartingWindow + " from " + fromToken);
1209 fromToken.removeChild(tStartingWindow);
1210 fromToken.postWindowRemoveStartingWindowCleanup(tStartingWindow);
1211 fromToken.mHiddenSetFromTransferredStartingWindow = false;
1212 addWindow(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001213
Peter Visontay3556a3b2017-11-01 17:23:17 +00001214 // Propagate other interesting state between the tokens. If the old token is displayed,
1215 // we should immediately force the new one to be displayed. If it is animating, we need
1216 // to move that animation to the new one.
1217 if (fromToken.allDrawn) {
1218 allDrawn = true;
1219 deferClearAllDrawn = fromToken.deferClearAllDrawn;
1220 }
1221 if (fromToken.firstWindowDrawn) {
1222 firstWindowDrawn = true;
1223 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001224 if (!fromToken.isHidden()) {
1225 setHidden(false);
Peter Visontay3556a3b2017-11-01 17:23:17 +00001226 hiddenRequested = false;
1227 mHiddenSetFromTransferredStartingWindow = true;
1228 }
1229 setClientHidden(fromToken.mClientHidden);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001230
Jorim Jaggi980c9de2017-11-17 01:41:37 +01001231 transferAnimation(fromToken);
1232
1233 // When transferring an animation, we no longer need to apply an animation to the
1234 // the token we transfer the animation over. Thus, remove the animation from
1235 // pending opening apps.
1236 mService.mOpeningApps.remove(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001237
Peter Visontay3556a3b2017-11-01 17:23:17 +00001238 mService.updateFocusedWindowLocked(
1239 UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/);
1240 getDisplayContent().setLayoutNeeded();
1241 mService.mWindowPlacerLocked.performSurfacePlacement();
1242 } finally {
1243 Binder.restoreCallingIdentity(origId);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001244 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001245 return true;
1246 } else if (fromToken.startingData != null) {
1247 // The previous app was getting ready to show a
1248 // starting window, but hasn't yet done so. Steal it!
1249 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1250 "Moving pending starting from " + fromToken + " to " + this);
1251 startingData = fromToken.startingData;
1252 fromToken.startingData = null;
1253 fromToken.startingMoved = true;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001254 if (getController() != null) {
1255 getController().scheduleAddStartingWindow();
1256 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001257 return true;
1258 }
1259
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001260 // TODO: Transfer thumbnail
1261
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001262 return false;
1263 }
1264
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001265 boolean isLastWindow(WindowState win) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001266 return mChildren.size() == 1 && mChildren.get(0) == win;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001267 }
1268
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001269 @Override
1270 void onAppTransitionDone() {
1271 sendingToBottom = false;
1272 }
1273
Wale Ogunwale51362492016-09-08 17:49:17 -07001274 /**
1275 * We override because this class doesn't want its children affecting its reported orientation
1276 * in anyway.
1277 */
1278 @Override
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001279 int getOrientation(int candidate) {
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001280 if (candidate == SCREEN_ORIENTATION_BEHIND) {
1281 // Allow app to specify orientation regardless of its visibility state if the current
1282 // candidate want us to use orientation behind. I.e. the visible app on-top of this one
1283 // wants us to use the orientation of the app behind it.
1284 return mOrientation;
1285 }
1286
Bryce Lee61fbcbc2017-03-10 14:14:03 -08001287 // The {@link AppWindowToken} should only specify an orientation when it is not closing or
1288 // going to the bottom. Allowing closing {@link AppWindowToken} to participate can lead to
1289 // an Activity in another task being started in the wrong orientation during the transition.
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001290 if (!(sendingToBottom || mService.mClosingApps.contains(this))
Bryce Lee00d586d2017-07-28 20:48:43 -07001291 && (isVisible() || mService.mOpeningApps.contains(this) || isOnTop())) {
Bryce Leea163b762017-01-24 11:05:01 -08001292 return mOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001293 }
Bryce Leea163b762017-01-24 11:05:01 -08001294
1295 return SCREEN_ORIENTATION_UNSET;
Wale Ogunwale51362492016-09-08 17:49:17 -07001296 }
1297
Wale Ogunwaleb198b742016-12-01 08:44:09 -08001298 /** Returns the app's preferred orientation regardless of its currently visibility state. */
1299 int getOrientationIgnoreVisibility() {
1300 return mOrientation;
1301 }
1302
Craig Mautnerdbb79912012-03-01 18:59:14 -08001303 @Override
Winson Chunge55c0192017-08-24 14:50:48 -07001304 public void onConfigurationChanged(Configuration newParentConfig) {
1305 final int prevWinMode = getWindowingMode();
1306 super.onConfigurationChanged(newParentConfig);
1307 final int winMode = getWindowingMode();
1308
1309 if (prevWinMode == winMode) {
1310 return;
1311 }
1312
1313 if (prevWinMode != WINDOWING_MODE_UNDEFINED && winMode == WINDOWING_MODE_PINNED) {
1314 // Entering PiP from fullscreen, reset the snap fraction
1315 mDisplayContent.mPinnedStackControllerLocked.resetReentrySnapFraction(this);
1316 } else if (prevWinMode == WINDOWING_MODE_PINNED && winMode != WINDOWING_MODE_UNDEFINED) {
1317 // Leaving PiP to fullscreen, save the snap fraction based on the pre-animation bounds
1318 // for the next re-entry into PiP (assuming the activity is not hidden or destroyed)
1319 final TaskStack pinnedStack = mDisplayContent.getPinnedStack();
1320 if (pinnedStack != null) {
1321 mDisplayContent.mPinnedStackControllerLocked.saveReentrySnapFraction(this,
1322 pinnedStack.mPreAnimationBounds);
1323 }
1324 }
1325 }
1326
1327 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001328 void checkAppWindowsReadyToShow() {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001329 if (allDrawn == mLastAllDrawn) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001330 return;
1331 }
1332
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001333 mLastAllDrawn = allDrawn;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001334 if (!allDrawn) {
1335 return;
1336 }
1337
1338 // The token has now changed state to having all windows shown... what to do, what to do?
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001339 if (mFreezingScreen) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001340 showAllWindowsLocked();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001341 stopFreezingScreen(false, true);
1342 if (DEBUG_ORIENTATION) Slog.i(TAG,
1343 "Setting mOrientationChangeComplete=true because wtoken " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001344 + " numInteresting=" + mNumInterestingWindows + " numDrawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001345 // This will set mOrientationChangeComplete and cause a pass through layout.
1346 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001347 "checkAppWindowsReadyToShow: freezingScreen");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001348 } else {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001349 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001350
1351 // We can now show all of the drawn windows!
1352 if (!mService.mOpeningApps.contains(this)) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001353 showAllWindowsLocked();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001354 }
1355 }
1356 }
1357
Matthew Ng5d23afa2017-06-21 16:16:24 -07001358 /**
Bryce Leed390deb2017-06-22 13:14:28 -07001359 * Returns whether the drawn window states of this {@link AppWindowToken} has considered every
1360 * child {@link WindowState}. A child is considered if it has been passed into
1361 * {@link #updateDrawnWindowStates(WindowState)} after being added. This is used to determine
1362 * whether states, such as {@code allDrawn}, can be set, which relies on state variables such as
1363 * {@code mNumInterestingWindows}, which depend on all {@link WindowState}s being considered.
1364 *
1365 * @return {@code true} If all children have been considered, {@code false}.
1366 */
1367 private boolean allDrawnStatesConsidered() {
Bryce Lee6311c4b2017-07-06 14:09:29 -07001368 for (int i = mChildren.size() - 1; i >= 0; --i) {
1369 final WindowState child = mChildren.get(i);
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001370 if (child.mightAffectAllDrawn() && !child.getDrawnStateEvaluated()) {
Bryce Leed390deb2017-06-22 13:14:28 -07001371 return false;
1372 }
1373 }
1374 return true;
1375 }
1376
1377 /**
Matthew Ng5d23afa2017-06-21 16:16:24 -07001378 * Determines if the token has finished drawing. This should only be called from
1379 * {@link DisplayContent#applySurfaceChangesTransaction}
1380 */
Matthew Ng498c71d2017-04-18 13:55:45 -07001381 void updateAllDrawn() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001382 if (!allDrawn) {
Matthew Ng498c71d2017-04-18 13:55:45 -07001383 // Number of drawn windows can be less when a window is being relaunched, wait for
Bryce Leed390deb2017-06-22 13:14:28 -07001384 // all windows to be launched and drawn for this token be considered all drawn.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001385 final int numInteresting = mNumInterestingWindows;
Bryce Leed390deb2017-06-22 13:14:28 -07001386
1387 // We must make sure that all present children have been considered (determined by
1388 // {@link #allDrawnStatesConsidered}) before evaluating whether everything has been
1389 // drawn.
1390 if (numInteresting > 0 && allDrawnStatesConsidered()
1391 && mNumDrawnWindows >= numInteresting && !isRelaunching()) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001392 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawn: " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001393 + " interesting=" + numInteresting + " drawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001394 allDrawn = true;
1395 // Force an additional layout pass where
1396 // WindowStateAnimator#commitFinishDrawingLocked() will call performShowLocked().
Matthew Ng498c71d2017-04-18 13:55:45 -07001397 if (mDisplayContent != null) {
1398 mDisplayContent.setLayoutNeeded();
1399 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001400 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Robert Carrecc06b32017-04-18 14:25:10 -07001401
Winson Chunge7ba6862017-05-24 12:13:33 -07001402 // Notify the pinned stack upon all windows drawn. If there was an animation in
1403 // progress then this signal will resume that animation.
Wale Ogunwale61911492017-10-11 08:50:50 -07001404 final TaskStack pinnedStack = mDisplayContent.getPinnedStack();
Winson Chunge7ba6862017-05-24 12:13:33 -07001405 if (pinnedStack != null) {
1406 pinnedStack.onAllWindowsDrawn();
Robert Carrecc06b32017-04-18 14:25:10 -07001407 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001408 }
1409 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001410 }
1411
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001412 /**
1413 * Updated this app token tracking states for interesting and drawn windows based on the window.
1414 *
1415 * @return Returns true if the input window is considered interesting and drawn while all the
1416 * windows in this app token where not considered drawn as of the last pass.
1417 */
1418 boolean updateDrawnWindowStates(WindowState w) {
Bryce Leed390deb2017-06-22 13:14:28 -07001419 w.setDrawnStateEvaluated(true /*evaluated*/);
1420
Jorim Jaggie4b0f282017-05-17 15:10:29 +02001421 if (DEBUG_STARTING_WINDOW_VERBOSE && w == startingWindow) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001422 Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" + w.isOnScreen()
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001423 + " allDrawn=" + allDrawn + " freezingScreen=" + mFreezingScreen);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001424 }
1425
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001426 if (allDrawn && !mFreezingScreen) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001427 return false;
1428 }
1429
1430 if (mLastTransactionSequence != mService.mTransactionSequence) {
1431 mLastTransactionSequence = mService.mTransactionSequence;
Matthew Ng53e66b22018-01-12 17:13:13 -08001432 mNumDrawnWindows = 0;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001433 startingDisplayed = false;
Matthew Ng53e66b22018-01-12 17:13:13 -08001434
1435 // There is the main base application window, even if it is exiting, wait for it
1436 mNumInterestingWindows = findMainWindow(false /* includeStartingApp */) != null ? 1 : 0;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001437 }
1438
1439 final WindowStateAnimator winAnimator = w.mWinAnimator;
1440
1441 boolean isInterestingAndDrawn = false;
1442
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001443 if (!allDrawn && w.mightAffectAllDrawn()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001444 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
1445 Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw()
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001446 + ", isAnimationSet=" + isSelfAnimating());
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001447 if (!w.isDrawnLw()) {
1448 Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController
1449 + " pv=" + w.mPolicyVisibility
1450 + " mDrawState=" + winAnimator.drawStateToString()
1451 + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001452 + " a=" + isSelfAnimating());
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001453 }
1454 }
1455
1456 if (w != startingWindow) {
1457 if (w.isInteresting()) {
Matthew Ng53e66b22018-01-12 17:13:13 -08001458 // Add non-main window as interesting since the main app has already been added
1459 if (findMainWindow(false /* includeStartingApp */) != w) {
1460 mNumInterestingWindows++;
1461 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001462 if (w.isDrawnLw()) {
1463 mNumDrawnWindows++;
1464
1465 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, "tokenMayBeDrawn: "
1466 + this + " w=" + w + " numInteresting=" + mNumInterestingWindows
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001467 + " freezingScreen=" + mFreezingScreen
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001468 + " mAppFreezing=" + w.mAppFreezing);
1469
1470 isInterestingAndDrawn = true;
1471 }
1472 }
1473 } else if (w.isDrawnLw()) {
Jorim Jaggi3878ca32017-02-02 17:13:05 -08001474 if (getController() != null) {
1475 getController().reportStartingWindowDrawn();
1476 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001477 startingDisplayed = true;
1478 }
1479 }
1480
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001481 return isInterestingAndDrawn;
1482 }
1483
Adrian Roos4d18a2e2017-12-19 19:08:05 +01001484 void updateLetterbox(WindowState winHint) {
1485 final WindowState w = findMainWindow();
1486 if (w != winHint && winHint != null && w != null) {
1487 return;
1488 }
1489 final boolean needsLetterbox = w != null && w.isLetterboxedAppWindow()
1490 && fillsParent() && w.hasDrawnLw();
1491 if (needsLetterbox) {
1492 if (mLetterbox == null) {
1493 mLetterbox = new Letterbox(() -> makeChildSurface(null));
1494 }
1495 mLetterbox.setDimensions(mPendingTransaction, getParent().getBounds(), w.mFrame);
1496 } else if (mLetterbox != null) {
1497 final SurfaceControl.Transaction t = new SurfaceControl.Transaction();
Adrian Roos2dfb7852018-01-15 13:41:37 +01001498 // Make sure we have a transaction here, in case we're called outside of a transaction.
1499 // This does not use mPendingTransaction, because SurfaceAnimator uses a
1500 // global transaction in onAnimationEnd.
Adrian Roos4d18a2e2017-12-19 19:08:05 +01001501 SurfaceControl.openTransaction();
1502 try {
1503 mLetterbox.hide(t);
1504 } finally {
Adrian Roos4d18a2e2017-12-19 19:08:05 +01001505 SurfaceControl.mergeToGlobalTransaction(t);
1506 SurfaceControl.closeTransaction();
1507 }
1508 }
1509 }
1510
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001511 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001512 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001513 // For legacy reasons we process the TaskStack.mExitingAppTokens first in DisplayContent
1514 // before the non-exiting app tokens. So, we skip the exiting app tokens here.
1515 // TODO: Investigate if we need to continue to do this or if we can just process them
1516 // in-order.
1517 if (mIsExiting && !waitingForReplacement()) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001518 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001519 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001520 return forAllWindowsUnchecked(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001521 }
1522
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001523 boolean forAllWindowsUnchecked(ToBooleanFunction<WindowState> callback,
1524 boolean traverseTopToBottom) {
1525 return super.forAllWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001526 }
1527
1528 @Override
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001529 AppWindowToken asAppWindowToken() {
1530 // I am an app window token!
1531 return this;
1532 }
1533
1534 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -07001535 boolean fillsParent() {
1536 return mFillsParent;
1537 }
1538
1539 void setFillsParent(boolean fillsParent) {
1540 mFillsParent = fillsParent;
1541 }
1542
Jorim Jaggife762342016-10-13 14:33:27 +02001543 boolean containsDismissKeyguardWindow() {
Bryce Lee081554b2017-05-25 07:52:12 -07001544 // Window state is transient during relaunch. We are not guaranteed to be frozen during the
1545 // entirety of the relaunch.
1546 if (isRelaunching()) {
1547 return mLastContainsDismissKeyguardWindow;
1548 }
1549
Jorim Jaggife762342016-10-13 14:33:27 +02001550 for (int i = mChildren.size() - 1; i >= 0; i--) {
1551 if ((mChildren.get(i).mAttrs.flags & FLAG_DISMISS_KEYGUARD) != 0) {
1552 return true;
1553 }
1554 }
1555 return false;
1556 }
1557
1558 boolean containsShowWhenLockedWindow() {
Bryce Lee081554b2017-05-25 07:52:12 -07001559 // When we are relaunching, it is possible for us to be unfrozen before our previous
1560 // windows have been added back. Using the cached value ensures that our previous
1561 // showWhenLocked preference is honored until relaunching is complete.
1562 if (isRelaunching()) {
1563 return mLastContainsShowWhenLockedWindow;
1564 }
1565
Jorim Jaggife762342016-10-13 14:33:27 +02001566 for (int i = mChildren.size() - 1; i >= 0; i--) {
1567 if ((mChildren.get(i).mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
1568 return true;
1569 }
1570 }
Bryce Lee081554b2017-05-25 07:52:12 -07001571
Jorim Jaggife762342016-10-13 14:33:27 +02001572 return false;
1573 }
1574
1575 void checkKeyguardFlagsChanged() {
1576 final boolean containsDismissKeyguard = containsDismissKeyguardWindow();
1577 final boolean containsShowWhenLocked = containsShowWhenLockedWindow();
1578 if (containsDismissKeyguard != mLastContainsDismissKeyguardWindow
1579 || containsShowWhenLocked != mLastContainsShowWhenLockedWindow) {
1580 mService.notifyKeyguardFlagsChanged(null /* callback */);
1581 }
1582 mLastContainsDismissKeyguardWindow = containsDismissKeyguard;
1583 mLastContainsShowWhenLockedWindow = containsShowWhenLocked;
1584 }
1585
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001586 WindowState getImeTargetBelowWindow(WindowState w) {
1587 final int index = mChildren.indexOf(w);
1588 if (index > 0) {
1589 final WindowState target = mChildren.get(index - 1);
1590 if (target.canBeImeTarget()) {
1591 return target;
1592 }
1593 }
1594 return null;
1595 }
1596
Winson Chungbe9be7f2017-06-28 10:55:22 -07001597 int getLowestAnimLayer() {
1598 for (int i = 0; i < mChildren.size(); i++) {
1599 final WindowState w = mChildren.get(i);
1600 if (w.mRemoved) {
1601 continue;
1602 }
1603 return w.mWinAnimator.mAnimLayer;
1604 }
1605 return Integer.MAX_VALUE;
1606 }
1607
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001608 WindowState getHighestAnimLayerWindow(WindowState currentTarget) {
1609 WindowState candidate = null;
1610 for (int i = mChildren.indexOf(currentTarget); i >= 0; i--) {
1611 final WindowState w = mChildren.get(i);
1612 if (w.mRemoved) {
1613 continue;
1614 }
1615 if (candidate == null || w.mWinAnimator.mAnimLayer >
1616 candidate.mWinAnimator.mAnimLayer) {
1617 candidate = w;
1618 }
1619 }
1620 return candidate;
1621 }
1622
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001623 /**
1624 * See {@link Activity#setDisablePreviewScreenshots}.
1625 */
1626 void setDisablePreviewScreenshots(boolean disable) {
Wale Ogunwale6c459212017-05-17 08:56:03 -07001627 mDisablePreviewScreenshots = disable;
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001628 }
1629
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001630 /**
chaviwd3bf08d2017-08-01 17:24:59 -07001631 * Sets whether the current launch can turn the screen on. See {@link #canTurnScreenOn()}
1632 */
1633 void setCanTurnScreenOn(boolean canTurnScreenOn) {
1634 mCanTurnScreenOn = canTurnScreenOn;
1635 }
1636
1637 /**
1638 * Indicates whether the current launch can turn the screen on. This is to prevent multiple
1639 * relayouts from turning the screen back on. The screen should only turn on at most
1640 * once per activity resume.
1641 *
1642 * @return true if the screen can be turned on.
1643 */
1644 boolean canTurnScreenOn() {
1645 return mCanTurnScreenOn;
1646 }
1647
1648 /**
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001649 * Retrieves whether we'd like to generate a snapshot that's based solely on the theme. This is
1650 * the case when preview screenshots are disabled {@link #setDisablePreviewScreenshots} or when
1651 * we can't take a snapshot for other reasons, for example, if we have a secure window.
1652 *
1653 * @return True if we need to generate an app theme snapshot, false if we'd like to take a real
1654 * screenshot.
1655 */
1656 boolean shouldUseAppThemeSnapshot() {
Wale Ogunwale6c459212017-05-17 08:56:03 -07001657 return mDisablePreviewScreenshots || forAllWindows(w -> (w.mAttrs.flags & FLAG_SECURE) != 0,
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001658 true /* topToBottom */);
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001659 }
1660
chaviw23ee71c2017-12-18 11:29:41 -08001661 @Override
Jorim Jaggi596a1992017-12-29 14:48:02 +01001662 public SurfaceControl getAnimationLeashParent() {
Robert Carrb9506032018-02-13 13:54:00 -08001663 // All normal app transitions take place in an animation layer which is below the pinned
1664 // stack but may be above the parent stacks of the given animating apps.
1665 // For transitions in the pinned stack (menu activity) we just let them occur as a child
1666 // of the pinned stack.
1667 if (!inPinnedWindowingMode()) {
1668 return getAppAnimationLayer();
1669 } else {
1670 return getStack().getSurfaceControl();
1671 }
chaviw23ee71c2017-12-18 11:29:41 -08001672 }
1673
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001674 boolean applyAnimationLocked(WindowManager.LayoutParams lp, int transit, boolean enter,
1675 boolean isVoiceInteraction) {
1676
1677 if (mService.mDisableTransitionAnimation) {
1678 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1679 Slog.v(TAG_WM, "applyAnimation: transition animation is disabled. atoken=" + this);
1680 }
1681 cancelAnimation();
1682 return false;
1683 }
1684
1685 // Only apply an animation if the display isn't frozen. If it is frozen, there is no reason
1686 // to animate and it can cause strange artifacts when we unfreeze the display if some
1687 // different animation is running.
1688 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "AWT#applyAnimationLocked");
1689 if (okToAnimate()) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001690 final AnimationAdapter adapter;
1691 final TaskStack stack = getStack();
1692 mTmpPoint.set(0, 0);
1693 mTmpRect.setEmpty();
1694 if (stack != null) {
1695 stack.getRelativePosition(mTmpPoint);
1696 stack.getBounds(mTmpRect);
1697 mTmpRect.offsetTo(0, 0);
1698 }
1699 if (mService.mAppTransition.getRemoteAnimationController() != null) {
1700 adapter = mService.mAppTransition.getRemoteAnimationController()
1701 .createAnimationAdapter(this, mTmpPoint, mTmpRect);
1702 } else {
1703 final Animation a = loadAnimation(lp, transit, enter, isVoiceInteraction);
1704 if (a != null) {
1705 adapter = new LocalAnimationAdapter(
1706 new WindowAnimationSpec(a, mTmpPoint, mTmpRect,
1707 mService.mAppTransition.canSkipFirstFrame(),
1708 mService.mAppTransition.getAppStackClipMode()),
1709 mService.mSurfaceAnimationRunner);
1710 if (a.getZAdjustment() == Animation.ZORDER_TOP) {
1711 mNeedsZBoost = true;
1712 }
1713 mTransit = transit;
1714 mTransitFlags = mService.mAppTransition.getTransitFlags();
1715 } else {
1716 adapter = null;
chaviw23ee71c2017-12-18 11:29:41 -08001717 }
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001718 }
1719 if (adapter != null) {
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001720 startAnimation(getPendingTransaction(), adapter, !isVisible());
Jorim Jaggi82c17862018-02-21 17:50:18 +01001721 if (adapter.getShowWallpaper()) {
1722 mDisplayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
1723 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001724 }
1725 } else {
1726 cancelAnimation();
1727 }
1728 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
1729
1730 return isReallyAnimating();
1731 }
1732
1733 private Animation loadAnimation(WindowManager.LayoutParams lp, int transit, boolean enter,
1734 boolean isVoiceInteraction) {
1735 final DisplayContent displayContent = getTask().getDisplayContent();
1736 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
1737 final int width = displayInfo.appWidth;
1738 final int height = displayInfo.appHeight;
1739 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG_WM,
1740 "applyAnimation: atoken=" + this);
1741
1742 // Determine the visible rect to calculate the thumbnail clip
1743 final WindowState win = findMainWindow();
1744 final Rect frame = new Rect(0, 0, width, height);
1745 final Rect displayFrame = new Rect(0, 0,
1746 displayInfo.logicalWidth, displayInfo.logicalHeight);
1747 final Rect insets = new Rect();
1748 final Rect stableInsets = new Rect();
1749 Rect surfaceInsets = null;
1750 final boolean freeform = win != null && win.inFreeformWindowingMode();
1751 if (win != null) {
1752 // Containing frame will usually cover the whole screen, including dialog windows.
1753 // For freeform workspace windows it will not cover the whole screen and it also
1754 // won't exactly match the final freeform window frame (e.g. when overlapping with
1755 // the status bar). In that case we need to use the final frame.
1756 if (freeform) {
1757 frame.set(win.mFrame);
Adrian Roos4d18a2e2017-12-19 19:08:05 +01001758 } else if (win.isLetterboxedAppWindow()) {
1759 frame.set(getTask().getBounds());
Winson Chungc1674272018-02-21 10:15:17 -08001760 } else if (win.isDockedResizing()) {
1761 // If we are animating while docked resizing, then use the stack bounds as the
1762 // animation target (which will be different than the task bounds)
1763 frame.set(getTask().getParent().getBounds());
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001764 } else {
1765 frame.set(win.mContainingFrame);
1766 }
1767 surfaceInsets = win.getAttrs().surfaceInsets;
Adrian Roos20e07892018-02-23 19:12:01 +01001768 // XXX(b/72757033): These are insets relative to the window frame, but we're really
1769 // interested in the insets relative to the frame we chose in the if-blocks above.
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001770 insets.set(win.mContentInsets);
1771 stableInsets.set(win.mStableInsets);
1772 }
1773
1774 if (mLaunchTaskBehind) {
1775 // Differentiate the two animations. This one which is briefly on the screen
1776 // gets the !enter animation, and the other activity which remains on the
1777 // screen gets the enter animation. Both appear in the mOpeningApps set.
1778 enter = false;
1779 }
1780 if (DEBUG_APP_TRANSITIONS) Slog.d(TAG_WM, "Loading animation for app transition."
1781 + " transit=" + AppTransition.appTransitionToString(transit) + " enter=" + enter
1782 + " frame=" + frame + " insets=" + insets + " surfaceInsets=" + surfaceInsets);
1783 final Configuration displayConfig = displayContent.getConfiguration();
1784 final Animation a = mService.mAppTransition.loadAnimation(lp, transit, enter,
1785 displayConfig.uiMode, displayConfig.orientation, frame, displayFrame, insets,
1786 surfaceInsets, stableInsets, isVoiceInteraction, freeform, getTask().mTaskId);
1787 if (a != null) {
1788 if (DEBUG_ANIM) logWithStack(TAG, "Loaded animation " + a + " for " + this);
1789 final int containingWidth = frame.width();
1790 final int containingHeight = frame.height();
1791 a.initialize(containingWidth, containingHeight, width, height);
1792 a.scaleCurrentDuration(mService.getTransitionAnimationScaleLocked());
1793 }
1794 return a;
1795 }
1796
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001797 @Override
Jorim Jaggi6de61012018-03-19 14:53:23 +01001798 public boolean shouldDeferAnimationFinish(Runnable endDeferFinishCallback) {
1799 return mAnimatingAppWindowTokenRegistry != null
1800 && mAnimatingAppWindowTokenRegistry.notifyAboutToFinish(
1801 this, endDeferFinishCallback);
1802 }
1803
1804 @Override
1805 public void onAnimationLeashDestroyed(Transaction t) {
1806 super.onAnimationLeashDestroyed(t);
1807 if (mAnimatingAppWindowTokenRegistry != null) {
1808 mAnimatingAppWindowTokenRegistry.notifyFinished(this);
1809 }
1810 }
1811
1812 @Override
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001813 protected void setLayer(Transaction t, int layer) {
1814 if (!mSurfaceAnimator.hasLeash()) {
1815 t.setLayer(mSurfaceControl, layer);
1816 }
1817 }
1818
1819 @Override
1820 protected void setRelativeLayer(Transaction t, SurfaceControl relativeTo, int layer) {
1821 if (!mSurfaceAnimator.hasLeash()) {
1822 t.setRelativeLayer(mSurfaceControl, relativeTo, layer);
1823 }
1824 }
1825
1826 @Override
1827 protected void reparentSurfaceControl(Transaction t, SurfaceControl newParent) {
1828 if (!mSurfaceAnimator.hasLeash()) {
1829 t.reparent(mSurfaceControl, newParent.getHandle());
1830 }
1831 }
1832
1833 @Override
1834 public void onAnimationLeashCreated(Transaction t, SurfaceControl leash) {
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001835 // The leash is parented to the animation layer. We need to preserve the z-order by using
1836 // the prefix order index, but we boost if necessary.
Robert Carrb9506032018-02-13 13:54:00 -08001837 int layer = 0;
1838 if (!inPinnedWindowingMode()) {
1839 layer = getPrefixOrderIndex();
1840 } else {
1841 // Pinned stacks have animations take place within themselves rather than an animation
1842 // layer so we need to preserve the order relative to the stack (e.g. the order of our
1843 // task/parent).
1844 layer = getParent().getPrefixOrderIndex();
1845 }
1846
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001847 if (mNeedsZBoost) {
1848 layer += Z_BOOST_BASE;
1849 }
1850 leash.setLayer(layer);
Robert Carr2f8aa392018-01-31 14:46:51 -08001851
1852 final DisplayContent dc = getDisplayContent();
1853 dc.assignStackOrdering(t);
Jorim Jaggi6de61012018-03-19 14:53:23 +01001854 if (mAnimatingAppWindowTokenRegistry != null) {
1855 mAnimatingAppWindowTokenRegistry.notifyStarting(this);
1856 }
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001857 }
1858
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001859 /**
1860 * This must be called while inside a transaction.
1861 */
1862 void showAllWindowsLocked() {
1863 forAllWindows(windowState -> {
1864 if (DEBUG_VISIBILITY) Slog.v(TAG, "performing show on: " + windowState);
1865 windowState.performShowLocked();
1866 }, false /* traverseTopToBottom */);
Jorim Jaggia5e10572017-11-15 14:36:26 +01001867 }
1868
1869 @Override
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001870 protected void onAnimationFinished() {
1871 super.onAnimationFinished();
1872
1873 mTransit = TRANSIT_UNSET;
1874 mTransitFlags = 0;
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001875 mNeedsZBoost = false;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001876
1877 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM | FINISH_LAYOUT_REDO_WALLPAPER,
1878 "AppWindowToken");
1879
Jorim Jaggi988f6682017-11-17 17:46:43 +01001880 clearThumbnail();
Jorim Jaggi3cad57f2018-02-20 18:32:01 +01001881 setClientHidden(hiddenRequested);
Jorim Jaggi988f6682017-11-17 17:46:43 +01001882
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001883 if (mService.mInputMethodTarget != null && mService.mInputMethodTarget.mAppToken == this) {
1884 getDisplayContent().computeImeTarget(true /* updateImeTarget */);
1885 }
1886
1887 if (DEBUG_ANIM) Slog.v(TAG, "Animation done in " + this
1888 + ": reportedVisible=" + reportedVisible
1889 + " okToDisplay=" + okToDisplay()
1890 + " okToAnimate=" + okToAnimate()
1891 + " startingDisplayed=" + startingDisplayed);
1892
1893 // WindowState.onExitAnimationDone might modify the children list, so make a copy and then
1894 // traverse the copy.
1895 final ArrayList<WindowState> children = new ArrayList<>(mChildren);
1896 children.forEach(WindowState::onExitAnimationDone);
1897
1898 mService.mAppTransition.notifyAppTransitionFinishedLocked(token);
1899 scheduleAnimation();
1900 }
1901
1902 @Override
1903 boolean isAppAnimating() {
1904 return isSelfAnimating();
1905 }
1906
1907 @Override
1908 boolean isSelfAnimating() {
1909 // If we are about to start a transition, we also need to be considered animating.
1910 return isWaitingForTransitionStart() || isReallyAnimating();
1911 }
1912
1913 /**
1914 * @return True if and only if we are actually running an animation. Note that
1915 * {@link #isSelfAnimating} also returns true if we are waiting for an animation to
1916 * start.
1917 */
1918 private boolean isReallyAnimating() {
1919 return super.isSelfAnimating();
1920 }
1921
Jorim Jaggi988f6682017-11-17 17:46:43 +01001922 @Override
1923 void cancelAnimation() {
1924 super.cancelAnimation();
1925 clearThumbnail();
1926 }
1927
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001928 boolean isWaitingForTransitionStart() {
1929 return mService.mAppTransition.isTransitionSet()
1930 && (mService.mOpeningApps.contains(this) || mService.mClosingApps.contains(this));
1931 }
1932
1933 public int getTransit() {
1934 return mTransit;
1935 }
1936
1937 int getTransitFlags() {
1938 return mTransitFlags;
1939 }
1940
Jorim Jaggi988f6682017-11-17 17:46:43 +01001941 void attachThumbnailAnimation() {
1942 if (!isReallyAnimating()) {
1943 return;
1944 }
1945 final int taskId = getTask().mTaskId;
1946 final GraphicBuffer thumbnailHeader =
1947 mService.mAppTransition.getAppTransitionThumbnailHeader(taskId);
1948 if (thumbnailHeader == null) {
1949 if (DEBUG_APP_TRANSITIONS) Slog.d(TAG, "No thumbnail header bitmap for: " + taskId);
1950 return;
1951 }
1952 clearThumbnail();
1953 mThumbnail = new AppWindowThumbnail(getPendingTransaction(), this, thumbnailHeader);
1954 mThumbnail.startAnimation(getPendingTransaction(), loadThumbnailAnimation(thumbnailHeader));
1955 }
1956
Tony Mak64b8d562017-12-28 17:44:02 +00001957 /**
1958 * Attaches a surface with a thumbnail for the
1959 * {@link android.app.ActivityOptions#ANIM_OPEN_CROSS_PROFILE_APPS} animation.
1960 */
1961 void attachCrossProfileAppsThumbnailAnimation() {
1962 if (!isReallyAnimating()) {
1963 return;
1964 }
1965 clearThumbnail();
1966
1967 final WindowState win = findMainWindow();
1968 if (win == null) {
1969 return;
1970 }
1971 final Rect frame = win.mFrame;
1972 final int thumbnailDrawableRes = getTask().mUserId == mService.mCurrentUserId
1973 ? R.drawable.ic_account_circle
1974 : R.drawable.ic_corp_badge_no_background;
1975 final GraphicBuffer thumbnail =
1976 mService.mAppTransition
1977 .createCrossProfileAppsThumbnail(thumbnailDrawableRes, frame);
1978 if (thumbnail == null) {
1979 return;
1980 }
1981 mThumbnail = new AppWindowThumbnail(getPendingTransaction(), this, thumbnail);
1982 final Animation animation =
1983 mService.mAppTransition.createCrossProfileAppsThumbnailAnimationLocked(win.mFrame);
1984 mThumbnail.startAnimation(getPendingTransaction(), animation, new Point(frame.left,
1985 frame.top));
1986 }
1987
Jorim Jaggi988f6682017-11-17 17:46:43 +01001988 private Animation loadThumbnailAnimation(GraphicBuffer thumbnailHeader) {
1989 final DisplayInfo displayInfo = mDisplayContent.getDisplayInfo();
1990
1991 // If this is a multi-window scenario, we use the windows frame as
1992 // destination of the thumbnail header animation. If this is a full screen
1993 // window scenario, we use the whole display as the target.
1994 WindowState win = findMainWindow();
1995 Rect appRect = win != null ? win.getContentFrameLw() :
1996 new Rect(0, 0, displayInfo.appWidth, displayInfo.appHeight);
1997 Rect insets = win != null ? win.mContentInsets : null;
1998 final Configuration displayConfig = mDisplayContent.getConfiguration();
1999 return mService.mAppTransition.createThumbnailAspectScaleAnimationLocked(
2000 appRect, insets, thumbnailHeader, getTask().mTaskId, displayConfig.uiMode,
2001 displayConfig.orientation);
2002 }
2003
2004 private void clearThumbnail() {
2005 if (mThumbnail == null) {
2006 return;
2007 }
2008 mThumbnail.destroy();
2009 mThumbnail = null;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002010 }
2011
Jorim Jaggif84e2f62018-01-16 14:17:59 +01002012 void registerRemoteAnimations(RemoteAnimationDefinition definition) {
2013 mRemoteAnimationDefinition = definition;
2014 }
2015
2016 RemoteAnimationDefinition getRemoteAnimationDefinition() {
2017 return mRemoteAnimationDefinition;
2018 }
2019
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002020 @Override
2021 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
2022 super.dump(pw, prefix, dumpAll);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002023 if (appToken != null) {
Wale Ogunwale72919d22016-12-08 18:58:50 -08002024 pw.println(prefix + "app=true mVoiceInteraction=" + mVoiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002025 }
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08002026 pw.print(prefix); pw.print("task="); pw.println(getTask());
Wale Ogunwale51362492016-09-08 17:49:17 -07002027 pw.print(prefix); pw.print(" mFillsParent="); pw.print(mFillsParent);
2028 pw.print(" mOrientation="); pw.println(mOrientation);
Wale Ogunwale89973222017-04-23 18:39:45 -07002029 pw.println(prefix + "hiddenRequested=" + hiddenRequested + " mClientHidden=" + mClientHidden
2030 + ((mDeferHidingClient) ? " mDeferHidingClient=" + mDeferHidingClient : "")
2031 + " reportedDrawn=" + reportedDrawn + " reportedVisible=" + reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -07002032 if (paused) {
2033 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002034 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -08002035 if (mAppStopped) {
2036 pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped);
2037 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07002038 if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002039 || allDrawn || mLastAllDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07002040 pw.print(prefix); pw.print("mNumInterestingWindows=");
2041 pw.print(mNumInterestingWindows);
2042 pw.print(" mNumDrawnWindows="); pw.print(mNumDrawnWindows);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002043 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -07002044 pw.print(" allDrawn="); pw.print(allDrawn);
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002045 pw.print(" lastAllDrawn="); pw.print(mLastAllDrawn);
Craig Mautner6fbda632012-07-03 09:26:39 -07002046 pw.println(")");
2047 }
2048 if (inPendingTransaction) {
2049 pw.print(prefix); pw.print("inPendingTransaction=");
2050 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002051 }
Craig Mautner799bc1d2015-01-14 10:33:48 -08002052 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002053 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
2054 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -08002055 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -08002056 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002057 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08002058 if (startingWindow != null || startingSurface != null
Wale Ogunwale6c459212017-05-17 08:56:03 -07002059 || startingDisplayed || startingMoved || mHiddenSetFromTransferredStartingWindow) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002060 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08002061 pw.print(" startingSurface="); pw.print(startingSurface);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002062 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
Wale Ogunwale6c459212017-05-17 08:56:03 -07002063 pw.print(" startingMoved="); pw.print(startingMoved);
2064 pw.println(" mHiddenSetFromTransferredStartingWindow="
2065 + mHiddenSetFromTransferredStartingWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002066 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01002067 if (!mFrozenBounds.isEmpty()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -08002068 pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds);
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002069 pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig);
Chong Zhangd78ddb42016-03-02 17:01:14 -08002070 }
2071 if (mPendingRelaunchCount != 0) {
2072 pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount);
Jorim Jaggi0429f352015-12-22 16:29:16 +01002073 }
Wale Ogunwale9c64cb62017-04-12 13:39:59 -07002074 if (getController() != null) {
2075 pw.print(prefix); pw.print("controller="); pw.println(getController());
2076 }
Wale Ogunwalee287e192017-04-21 09:30:12 -07002077 if (mRemovingFromDisplay) {
2078 pw.println(prefix + "mRemovingFromDisplay=" + mRemovingFromDisplay);
2079 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002080 }
2081
2082 @Override
2083 void setHidden(boolean hidden) {
2084 super.setHidden(hidden);
Winson Chunge55c0192017-08-24 14:50:48 -07002085
2086 if (hidden) {
2087 // Once the app window is hidden, reset the last saved PiP snap fraction
2088 mDisplayContent.mPinnedStackControllerLocked.resetReentrySnapFraction(this);
2089 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002090 scheduleAnimation();
2091 }
2092
2093 @Override
2094 void prepareSurfaces() {
2095 // isSelfAnimating also returns true when we are about to start a transition, so we need
2096 // to check super here.
2097 final boolean reallyAnimating = super.isSelfAnimating();
2098 final boolean show = !isHidden() || reallyAnimating;
2099 if (show && !mLastSurfaceShowing) {
2100 mPendingTransaction.show(mSurfaceControl);
2101 } else if (!show && mLastSurfaceShowing) {
2102 mPendingTransaction.hide(mSurfaceControl);
Jorim Jaggi4d1835d2017-08-31 17:28:27 +02002103 }
Jorim Jaggi988f6682017-11-17 17:46:43 +01002104 if (mThumbnail != null) {
2105 mThumbnail.setShowing(mPendingTransaction, show);
2106 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002107 mLastSurfaceShowing = show;
2108 super.prepareSurfaces();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002109 }
2110
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002111 boolean isFreezingScreen() {
2112 return mFreezingScreen;
2113 }
2114
2115 @Override
2116 boolean needsZBoost() {
2117 return mNeedsZBoost || super.needsZBoost();
2118 }
2119
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07002120 @CallSuper
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002121 @Override
Adrian Roos4921ccf2017-09-28 16:54:06 +02002122 public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07002123 final long token = proto.start(fieldId);
2124 writeNameToProto(proto, NAME);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002125 super.writeToProto(proto, WINDOW_TOKEN, trim);
Vishnu Nair04ab4392018-01-10 11:00:06 -08002126 proto.write(LAST_SURFACE_SHOWING, mLastSurfaceShowing);
2127 proto.write(IS_WAITING_FOR_TRANSITION_START, isWaitingForTransitionStart());
2128 proto.write(IS_REALLY_ANIMATING, isReallyAnimating());
2129 if (mThumbnail != null){
2130 mThumbnail.writeToProto(proto, THUMBNAIL);
2131 }
2132 proto.write(FILLS_PARENT, mFillsParent);
2133 proto.write(APP_STOPPED, mAppStopped);
2134 proto.write(HIDDEN_REQUESTED, hiddenRequested);
2135 proto.write(CLIENT_HIDDEN, mClientHidden);
2136 proto.write(DEFER_HIDING_CLIENT, mDeferHidingClient);
2137 proto.write(REPORTED_DRAWN, reportedDrawn);
2138 proto.write(REPORTED_VISIBLE, reportedVisible);
2139 proto.write(NUM_INTERESTING_WINDOWS, mNumInterestingWindows);
2140 proto.write(NUM_DRAWN_WINDOWS, mNumDrawnWindows);
2141 proto.write(ALL_DRAWN, allDrawn);
2142 proto.write(LAST_ALL_DRAWN, mLastAllDrawn);
2143 proto.write(REMOVED, removed);
2144 if (startingWindow != null){
2145 startingWindow.writeIdentifierToProto(proto, STARTING_WINDOW);
2146 }
2147 proto.write(STARTING_DISPLAYED, startingDisplayed);
2148 proto.write(STARTING_MOVED, startingMoved);
2149 proto.write(HIDDEN_SET_FROM_TRANSFERRED_STARTING_WINDOW,
2150 mHiddenSetFromTransferredStartingWindow);
2151 for (Rect bounds : mFrozenBounds) {
2152 bounds.writeToProto(proto, FROZEN_BOUNDS);
2153 }
Steven Timotiusaf03df62017-07-18 16:56:43 -07002154 proto.end(token);
2155 }
2156
2157 void writeNameToProto(ProtoOutputStream proto, long fieldId) {
2158 if (appToken == null) {
2159 return;
2160 }
2161 try {
2162 proto.write(fieldId, appToken.getName());
2163 } catch (RemoteException e) {
2164 // This shouldn't happen, but in this case fall back to outputting nothing
2165 Slog.e(TAG, e.toString());
2166 }
2167 }
2168
2169 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002170 public String toString() {
2171 if (stringName == null) {
2172 StringBuilder sb = new StringBuilder();
2173 sb.append("AppWindowToken{");
2174 sb.append(Integer.toHexString(System.identityHashCode(this)));
2175 sb.append(" token="); sb.append(token); sb.append('}');
2176 stringName = sb.toString();
2177 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07002178 return stringName + ((mIsExiting) ? " mIsExiting=" : "");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002179 }
Adrian Roos20e07892018-02-23 19:12:01 +01002180
2181 Rect getLetterboxInsets() {
2182 if (mLetterbox != null) {
2183 return mLetterbox.getInsets();
2184 } else {
2185 return new Rect();
2186 }
2187 }
Jeff Browne9bdb312012-04-05 15:30:10 -07002188}